diff --git a/app/build.gradle b/app/build.gradle index 0737705a18..ebe2839be8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/submission/AdapterMySubmission.java b/app/src/main/java/org/ole/planet/myplanet/ui/submission/AdapterMySubmission.java index 51e45c0cef..1bf4218e56 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/submission/AdapterMySubmission.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/submission/AdapterMySubmission.java @@ -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; @@ -28,9 +30,8 @@ import io.realm.Realm; -import static io.realm.internal.SyncObjectServerFacade.getApplicationContext; - -public class AdapterMySubmission extends RecyclerView.Adapter { +public class AdapterMySubmission extends RecyclerView.Adapter { + private RowMysurveyBinding rowMysurveyBinding; private OnHomeItemClickListener listener; private Context context; private List list; @@ -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) { @@ -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; } } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/submission/MySubmissionFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/submission/MySubmissionFragment.java index a1215a9366..7b1e51a925 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/submission/MySubmissionFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/submission/MySubmissionFragment.java @@ -1,13 +1,6 @@ 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; @@ -15,10 +8,14 @@ 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; @@ -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 exams; List submissions; RealmUserModel user; @@ -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) { } @@ -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"; @@ -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); } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/submission/SubmissionDetailFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/submission/SubmissionDetailFragment.java index b683f83815..98ff5b9a71 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/submission/SubmissionDetailFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/submission/SubmissionDetailFragment.java @@ -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(); } }