Skip to content

Commit

Permalink
survey: implement viewbinding in submission module (fixes #2534) (#2539)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Sep 28, 2023
1 parent d13302b commit 900af35
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 63 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1063
versionName "0.10.63"
versionCode 1064
versionName "0.10.64"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package org.ole.planet.myplanet.ui.submission;

import static io.realm.internal.SyncObjectServerFacade.getApplicationContext;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;

import org.json.JSONObject;
import org.ole.planet.myplanet.R;
import org.ole.planet.myplanet.callback.OnHomeItemClickListener;
import org.ole.planet.myplanet.databinding.RowMysurveyBinding;
import org.ole.planet.myplanet.model.RealmStepExam;
import org.ole.planet.myplanet.model.RealmSubmission;
import org.ole.planet.myplanet.model.RealmUserModel;
Expand All @@ -28,9 +30,8 @@

import io.realm.Realm;

import static io.realm.internal.SyncObjectServerFacade.getApplicationContext;

public class AdapterMySubmission extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public class AdapterMySubmission extends RecyclerView.Adapter<AdapterMySubmission.ViewHolderMySurvey> {
private RowMysurveyBinding rowMysurveyBinding;
private OnHomeItemClickListener listener;
private Context context;
private List<RealmSubmission> list;
Expand All @@ -56,24 +57,22 @@ public void setmRealm(Realm mRealm) {

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(context).inflate(R.layout.row_mysurvey, parent, false);
return new ViewHolderMySurvey(v);
public ViewHolderMySurvey onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
rowMysurveyBinding = RowMysurveyBinding.inflate(LayoutInflater.from(context), parent, false);
return new ViewHolderMySurvey(rowMysurveyBinding);
}

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof ViewHolderMySurvey) {
((ViewHolderMySurvey) holder).status.setText(list.get(position).getStatus());
((ViewHolderMySurvey) holder).date.setText(TimeUtils.getFormatedDate(list.get(position).getStartTime()));
showSubmittedBy(((ViewHolderMySurvey) holder).submitted_by, position);
public void onBindViewHolder(@NonNull ViewHolderMySurvey holder, int position) {
rowMysurveyBinding.status.setText(list.get(position).getStatus());
rowMysurveyBinding.date.setText(TimeUtils.getFormatedDate(list.get(position).getStartTime()));
showSubmittedBy(rowMysurveyBinding.submittedBy, position);
if (examHashMap.containsKey(list.get(position).getParentId()))
((ViewHolderMySurvey) holder).title.setText(examHashMap.get(list.get(position).getParentId()).getName());
rowMysurveyBinding.title.setText(examHashMap.get(list.get(position).getParentId()).getName());
holder.itemView.setOnClickListener(view -> {
if (type.equals("survey")) openSurvey(listener, list.get(position).getId(), true);
else openSubmissionDetail(listener, list.get(position).getId());
});
}
}

private void showSubmittedBy(TextView submitted_by, int position) {
Expand Down Expand Up @@ -114,15 +113,12 @@ public void setType(String type) {
this.type = type;
}

class ViewHolderMySurvey extends RecyclerView.ViewHolder {
TextView title, status, date, submitted_by;
static class ViewHolderMySurvey extends RecyclerView.ViewHolder {
RowMysurveyBinding rowMysurveyBinding;

public ViewHolderMySurvey(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.title);
status = itemView.findViewById(R.id.status);
date = itemView.findViewById(R.id.date);
submitted_by = itemView.findViewById(R.id.submitted_by);
public ViewHolderMySurvey(RowMysurveyBinding rowMysurveyBinding) {
super(rowMysurveyBinding.getRoot());
this.rowMysurveyBinding = rowMysurveyBinding;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package org.ole.planet.myplanet.ui.submission;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;

import org.ole.planet.myplanet.R;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;

import org.ole.planet.myplanet.databinding.FragmentMySubmissionBinding;
import org.ole.planet.myplanet.datamanager.DatabaseService;
import org.ole.planet.myplanet.model.RealmStepExam;
import org.ole.planet.myplanet.model.RealmSubmission;
Expand All @@ -33,11 +30,9 @@
import io.realm.RealmQuery;

public class MySubmissionFragment extends Fragment implements CompoundButton.OnCheckedChangeListener {
private FragmentMySubmissionBinding fragmentMySubmissionBinding;
Realm mRealm;
RecyclerView rvSurvey;
String type = "";
RadioButton rbExam, rbSurvey;
EditText etSearch;
HashMap<String, RealmStepExam> exams;
List<RealmSubmission> submissions;
RealmUserModel user;
Expand All @@ -60,27 +55,23 @@ public MySubmissionFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_my_submission, container, false);
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
fragmentMySubmissionBinding = FragmentMySubmissionBinding.inflate(inflater, container, false);
exams = new HashMap<>();
rbExam = v.findViewById(R.id.rb_exam);
rbSurvey = v.findViewById(R.id.rb_survey);
rvSurvey = v.findViewById(R.id.rv_mysurvey);
etSearch = v.findViewById(R.id.et_search);
user = new UserProfileDbHandler(getActivity()).getUserModel();
return v;
return fragmentMySubmissionBinding.getRoot();
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mRealm = new DatabaseService(getActivity()).getRealmInstance();
rvSurvey.setLayoutManager(new LinearLayoutManager(getActivity()));
rvSurvey.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
fragmentMySubmissionBinding.rvMysurvey.setLayoutManager(new LinearLayoutManager(getActivity()));
fragmentMySubmissionBinding.rvMysurvey.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
submissions = mRealm.where(RealmSubmission.class).findAll();
exams = RealmSubmission.getExamMap(mRealm, submissions);
setData("");
etSearch.addTextChangedListener(new TextWatcher() {
fragmentMySubmissionBinding.etSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
Expand All @@ -101,18 +92,18 @@ public void afterTextChanged(Editable editable) {

private void showHideRadioButton() {
if (!type.equals("survey")) {
rbExam.setChecked(true);
rbExam.setOnCheckedChangeListener(this);
rbSurvey.setOnCheckedChangeListener(this);
fragmentMySubmissionBinding.rbExam.setChecked(true);
fragmentMySubmissionBinding.rbExam.setOnCheckedChangeListener(this);
fragmentMySubmissionBinding.rbSurvey.setOnCheckedChangeListener(this);
} else {
rbSurvey.setVisibility(View.GONE);
rbExam.setVisibility(View.GONE);
fragmentMySubmissionBinding.rbSurvey.setVisibility(View.GONE);
fragmentMySubmissionBinding.rbExam.setVisibility(View.GONE);
}
}

@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (rbSurvey.isChecked()) {
if (fragmentMySubmissionBinding.rbSurvey.isChecked()) {
type = "survey_submission";
} else {
type = "exam";
Expand All @@ -138,6 +129,6 @@ private void setData(String s) {
AdapterMySubmission adapter = new AdapterMySubmission(getActivity(), submissions, exams);
adapter.setmRealm(mRealm);
adapter.setType(type);
rvSurvey.setAdapter(adapter);
fragmentMySubmissionBinding.rvMysurvey.setAdapter(adapter);
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package org.ole.planet.myplanet.ui.submission;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.ole.planet.myplanet.R;
import androidx.fragment.app.Fragment;

import org.ole.planet.myplanet.databinding.FragmentSubmissionDetailBinding;

public class SubmissionDetailFragment extends Fragment {
private FragmentSubmissionDetailBinding fragmentSubmissionDetailBinding;
public SubmissionDetailFragment() {
// Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_submission_detail, container, false);
fragmentSubmissionDetailBinding = FragmentSubmissionDetailBinding.inflate(inflater, container, false);
return fragmentSubmissionDetailBinding.getRoot();
}
}

0 comments on commit 900af35

Please sign in to comment.