diff --git a/app/build.gradle b/app/build.gradle index 312a34f155..8db5ed2333 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1047 - versionName "0.10.47" + versionCode 1048 + versionName "0.10.48" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/AdapterFeedback.java b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/AdapterFeedback.java index 93d44ef706..b6d67cd007 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/AdapterFeedback.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/AdapterFeedback.java @@ -2,16 +2,14 @@ import android.content.Context; import android.content.Intent; +import android.view.LayoutInflater; +import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.RowFeedbackBinding; import org.ole.planet.myplanet.model.RealmFeedback; import org.ole.planet.myplanet.utilities.TimeUtils; @@ -19,7 +17,8 @@ import io.realm.RealmResults; -public class AdapterFeedback extends RecyclerView.Adapter { +public class AdapterFeedback extends RecyclerView.Adapter { + private RowFeedbackBinding rowFeedbackBinding; private Context context; private List list; @@ -35,26 +34,24 @@ public void updateData(RealmResults newData) { @NonNull @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(context).inflate(R.layout.row_feedback, parent, false); - return new ViewHolderFeedback(v); + public ViewHolderFeedback onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + rowFeedbackBinding = RowFeedbackBinding.inflate(LayoutInflater.from(context), parent, false); + return new ViewHolderFeedback(rowFeedbackBinding); } @Override - public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - if (holder instanceof ViewHolderFeedback) { - ((ViewHolderFeedback) holder).tvTitle.setText(list.get(position).getTitle()); - ((ViewHolderFeedback) holder).tvType.setText(list.get(position).getType()); - ((ViewHolderFeedback) holder).tvPriority.setText(list.get(position).getPriority()); - ((ViewHolderFeedback) holder).tvStatus.setText(list.get(position).getStatus()); - if ("yes".equalsIgnoreCase(list.get(position).getPriority())) - ((ViewHolderFeedback) holder).tvPriority.setBackground(context.getResources().getDrawable(R.drawable.bg_primary)); - else - ((ViewHolderFeedback) holder).tvPriority.setBackground(context.getResources().getDrawable(R.drawable.bg_grey)); - ((ViewHolderFeedback) holder).tvStatus.setBackground(context.getResources().getDrawable("open".equalsIgnoreCase(list.get(position).getStatus()) ? R.drawable.bg_primary : R.drawable.bg_grey)); - ((ViewHolderFeedback) holder).tvOpenDate.setText(TimeUtils.getFormatedDate(Long.parseLong(list.get(position).getOpenTime()))); - holder.itemView.setOnClickListener(v -> context.startActivity(new Intent(context, FeedbackDetailActivity.class).putExtra("id", list.get(position).getId()))); - } + public void onBindViewHolder(@NonNull ViewHolderFeedback holder, int position) { + rowFeedbackBinding.tvTitle.setText(list.get(position).getTitle()); + rowFeedbackBinding.tvType.setText(list.get(position).getType()); + rowFeedbackBinding.tvPriority.setText(list.get(position).getPriority()); + rowFeedbackBinding.tvStatus.setText(list.get(position).getStatus()); + if ("yes".equalsIgnoreCase(list.get(position).getPriority())) + rowFeedbackBinding.tvPriority.setBackground(context.getResources().getDrawable(R.drawable.bg_primary)); + else + rowFeedbackBinding.tvPriority.setBackground(context.getResources().getDrawable(R.drawable.bg_grey)); + rowFeedbackBinding.tvStatus.setBackground(context.getResources().getDrawable("open".equalsIgnoreCase(list.get(position).getStatus()) ? R.drawable.bg_primary : R.drawable.bg_grey)); + rowFeedbackBinding.tvOpenDate.setText(TimeUtils.getFormatedDate(Long.parseLong(list.get(position).getOpenTime()))); + rowFeedbackBinding.getRoot().setOnClickListener(v -> context.startActivity(new Intent(context, FeedbackDetailActivity.class).putExtra("id", list.get(position).getId()))); } @Override @@ -62,16 +59,12 @@ public int getItemCount() { return list.size(); } - class ViewHolderFeedback extends RecyclerView.ViewHolder { - TextView tvTitle, tvType, tvPriority, tvStatus, tvOpenDate; + public static class ViewHolderFeedback extends RecyclerView.ViewHolder { + RowFeedbackBinding rowFeedbackBinding; - public ViewHolderFeedback(View itemView) { - super(itemView); - tvPriority = itemView.findViewById(R.id.tv_priority); - tvStatus = itemView.findViewById(R.id.tv_status); - tvType = itemView.findViewById(R.id.tv_type); - tvTitle = itemView.findViewById(R.id.tv_title); - tvOpenDate = itemView.findViewById(R.id.tv_open_date); + public ViewHolderFeedback(RowFeedbackBinding rowFeedbackBinding) { + super(rowFeedbackBinding.getRoot()); + this.rowFeedbackBinding = rowFeedbackBinding; } } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackDetailActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackDetailActivity.java index 6135ca6846..3cfd0862b9 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackDetailActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackDetailActivity.java @@ -1,13 +1,6 @@ package org.ole.planet.myplanet.ui.feedback; import android.content.Context; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.fragment.app.Fragment; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; @@ -16,15 +9,19 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; -import android.widget.EditText; -import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.ActivityFeedbackDetailBinding; +import org.ole.planet.myplanet.databinding.RowFeedbackReplyBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.FeedbackReply; import org.ole.planet.myplanet.model.RealmFeedback; @@ -37,44 +34,36 @@ import io.realm.Realm; public class FeedbackDetailActivity extends AppCompatActivity { - - private RecyclerView rv_feedback_reply; + private ActivityFeedbackDetailBinding activityFeedbackDetailBinding; private RecyclerView.Adapter mAdapter; private RecyclerView.LayoutManager layoutManager; - Button closeButton, replyButton; - EditText editText; RealmFeedback feedback; Realm realm; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_feedback_detail); + activityFeedbackDetailBinding = ActivityFeedbackDetailBinding.inflate(getLayoutInflater()); + setContentView(activityFeedbackDetailBinding.getRoot()); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); setTitle(R.string.feedback); realm = new DatabaseService(this).getRealmInstance(); feedback = realm.where(RealmFeedback.class).equalTo("id", getIntent().getStringExtra("id")).findFirst(); - TextView tvMessage = findViewById(R.id.tv_message); - TextView tvDate = findViewById(R.id.tv_date); if (!TextUtils.isEmpty(feedback.getOpenTime())) - tvDate.setText(TimeUtils.getFormatedDateWithTime(Long.parseLong(feedback.getOpenTime()))); - else tvDate.setText(R.string.date_n_a); - tvMessage.setText(TextUtils.isEmpty(feedback.getMessage()) ? "N/A" : feedback.getMessage()); - closeButton = findViewById(R.id.close_feedback); - replyButton = findViewById(R.id.reply_feedback); - editText = findViewById(R.id.feedback_reply_edit_text); + activityFeedbackDetailBinding.tvDate.setText(TimeUtils.getFormatedDateWithTime(Long.parseLong(feedback.getOpenTime()))); + else activityFeedbackDetailBinding.tvDate.setText(R.string.date_n_a); + activityFeedbackDetailBinding.tvMessage.setText(TextUtils.isEmpty(feedback.getMessage()) ? "N/A" : feedback.getMessage()); setUpReplies(); } public void setUpReplies() { - rv_feedback_reply = (RecyclerView) findViewById(R.id.rv_feedback_reply); - rv_feedback_reply.setHasFixedSize(true); + activityFeedbackDetailBinding.rvFeedbackReply.setHasFixedSize(true); layoutManager = new LinearLayoutManager(this); - rv_feedback_reply.setLayoutManager(layoutManager); + activityFeedbackDetailBinding.rvFeedbackReply.setLayoutManager(layoutManager); mAdapter = new RvFeedbackAdapter(feedback.getMessageList(), getApplicationContext()); - rv_feedback_reply.setAdapter(mAdapter); - closeButton.setOnClickListener(view -> { + activityFeedbackDetailBinding.rvFeedbackReply.setAdapter(mAdapter); + activityFeedbackDetailBinding.closeFeedback.setOnClickListener(view -> { realm.executeTransactionAsync(realm1 -> { RealmFeedback feedback1 = realm1.where(RealmFeedback.class).equalTo("id", getIntent().getStringExtra("id")).findFirst(); feedback1.setStatus("Closed"); @@ -83,11 +72,11 @@ public void setUpReplies() { }); }); - replyButton.setOnClickListener(r -> { - if (TextUtils.isEmpty(editText.getText().toString().trim())) { - editText.setError("Kindly enter reply message"); + activityFeedbackDetailBinding.replyFeedback.setOnClickListener(r -> { + if (TextUtils.isEmpty(activityFeedbackDetailBinding.feedbackReplyEditText.getText().toString().trim())) { + activityFeedbackDetailBinding.feedbackReplyEditText.setError("Kindly enter reply message"); } else { - String message = editText.getText().toString().trim(); + String message = activityFeedbackDetailBinding.feedbackReplyEditText.getText().toString().trim(); JsonObject object = new JsonObject(); object.addProperty("message", message); object.addProperty("time", new Date().getTime() + ""); @@ -95,18 +84,18 @@ public void setUpReplies() { String id = feedback.getId(); addReply(object, id); mAdapter = new RvFeedbackAdapter(feedback.getMessageList(), getApplicationContext()); - rv_feedback_reply.setAdapter(mAdapter); - editText.setText(""); - editText.clearFocus(); + activityFeedbackDetailBinding.rvFeedbackReply.setAdapter(mAdapter); + activityFeedbackDetailBinding.feedbackReplyEditText.setText(""); + activityFeedbackDetailBinding.feedbackReplyEditText.clearFocus(); } }); } public void updateForClosed() { if (feedback.getStatus().equalsIgnoreCase("Closed")) { - closeButton.setEnabled(false); - replyButton.setEnabled(false); - editText.setVisibility(View.INVISIBLE); + activityFeedbackDetailBinding.closeFeedback.setEnabled(false); + activityFeedbackDetailBinding.replyFeedback.setEnabled(false); + activityFeedbackDetailBinding.feedbackReplyEditText.setVisibility(View.INVISIBLE); navigateToFeedbackListFragment(); } } @@ -131,7 +120,7 @@ public void addReply(JsonObject obj, String id) { }, () -> { updateForClosed(); mAdapter = new RvFeedbackAdapter(feedback.getMessageList(), getApplicationContext()); - rv_feedback_reply.setAdapter(mAdapter); + activityFeedbackDetailBinding.rvFeedbackReply.setAdapter(mAdapter); }); } @@ -142,42 +131,42 @@ public boolean onOptionsItemSelected(MenuItem item) { } public class RvFeedbackAdapter extends RecyclerView.Adapter { + private RowFeedbackReplyBinding rowFeedbackReplyBinding; private List replyList; Context context; - public class ReplyViewHolder extends RecyclerView.ViewHolder { - public TextView tv_message, tv_date, tv_user; - - public ReplyViewHolder(View v) { - super(v); - tv_message = v.findViewById(R.id.tv_message); - tv_user = v.findViewById(R.id.tv_user); - tv_date = v.findViewById(R.id.tv_date); - } - } - public RvFeedbackAdapter(List replyList, Context context) { this.replyList = replyList; this.context = context; } + @NonNull @Override - public RvFeedbackAdapter.ReplyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View v = LayoutInflater.from(context).inflate(R.layout.row_feedback_reply, parent, false); - return new RvFeedbackAdapter.ReplyViewHolder(v); + public ReplyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + rowFeedbackReplyBinding = RowFeedbackReplyBinding.inflate(LayoutInflater.from(context), parent, false); + return new ReplyViewHolder(rowFeedbackReplyBinding); } @Override public void onBindViewHolder(@NonNull ReplyViewHolder holder, int position) { - holder.tv_date.setText(TimeUtils.getFormatedDateWithTime(Long.parseLong(replyList.get(position).getDate()))); - holder.tv_user.setText(replyList.get(position).getUser()); - holder.tv_message.setText(replyList.get(position).getMessage()); + rowFeedbackReplyBinding.tvDate.setText(TimeUtils.getFormatedDateWithTime(Long.parseLong(replyList.get(position).getDate()))); + rowFeedbackReplyBinding.tvUser.setText(replyList.get(position).getUser()); + rowFeedbackReplyBinding.tvMessage.setText(replyList.get(position).getMessage()); } @Override public int getItemCount() { return replyList.size(); } + + public class ReplyViewHolder extends RecyclerView.ViewHolder { + RowFeedbackReplyBinding rowFeedbackReplyBinding; + + public ReplyViewHolder(RowFeedbackReplyBinding rowFeedbackReplyBinding) { + super(rowFeedbackReplyBinding.getRoot()); + this.rowFeedbackReplyBinding = rowFeedbackReplyBinding; + } + } } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackFragment.java index 8669a3bf55..d7c68c7099 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackFragment.java @@ -1,25 +1,20 @@ package org.ole.planet.myplanet.ui.feedback; import android.os.Bundle; - -import androidx.annotation.Nullable; -import androidx.fragment.app.DialogFragment; -import androidx.fragment.app.Fragment; - -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.EditText; import android.widget.RadioButton; -import android.widget.RadioGroup; import android.widget.Toast; -import com.google.android.material.textfield.TextInputLayout; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; + import com.google.gson.JsonArray; import com.google.gson.JsonObject; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.FragmentFeedbackBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmFeedback; import org.ole.planet.myplanet.model.RealmUserModel; @@ -32,9 +27,7 @@ import io.realm.Realm; public class FeedbackFragment extends DialogFragment implements View.OnClickListener { - EditText etMessage; - RadioGroup rgType, rgUrgent; - TextInputLayout tlMessage, tlUrgent, tlType; + private FragmentFeedbackBinding fragmentFeedbackBinding; Realm mRealm; DatabaseService databaseService; RealmUserModel model; @@ -60,7 +53,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_feedback, container, false); + fragmentFeedbackBinding = FragmentFeedbackBinding.inflate(inflater, container, false); databaseService = new DatabaseService(getActivity()); mRealm = databaseService.getRealmInstance(); model = new UserProfileDbHandler(getActivity()).getUserModel(); @@ -69,15 +62,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa } else { user = "Anonymous"; } - etMessage = v.findViewById(R.id.et_message); - rgUrgent = v.findViewById(R.id.rg_urgent); - rgType = v.findViewById(R.id.rg_type); - tlMessage = v.findViewById(R.id.tl_message); - tlUrgent = v.findViewById(R.id.tl_urgent); - tlType = v.findViewById(R.id.tl_type); - v.findViewById(R.id.btn_submit).setOnClickListener(this); - v.findViewById(R.id.btn_cancel).setOnClickListener(this); - return v; + fragmentFeedbackBinding.btnSubmit.setOnClickListener(this); + fragmentFeedbackBinding.btnCancel.setOnClickListener(this); + return fragmentFeedbackBinding.getRoot(); } @Override @@ -97,19 +84,19 @@ public void onClick(View view) { } private void validateAndSaveData() { - final String message = etMessage.getText().toString().trim(); + final String message = fragmentFeedbackBinding.etMessage.getText().toString().trim(); if (message.isEmpty()) { - tlMessage.setError(getString(R.string.please_enter_feedback)); + fragmentFeedbackBinding.tlMessage.setError(getString(R.string.please_enter_feedback)); return; } - RadioButton rbUrgent = getView().findViewById(rgUrgent.getCheckedRadioButtonId()); - RadioButton rbType = getView().findViewById(rgType.getCheckedRadioButtonId()); + RadioButton rbUrgent = getView().findViewById(fragmentFeedbackBinding.rgUrgent.getCheckedRadioButtonId()); + RadioButton rbType = getView().findViewById(fragmentFeedbackBinding.rgType.getCheckedRadioButtonId()); if (rbUrgent == null) { - tlUrgent.setError(getString(R.string.feedback_priority_is_required)); + fragmentFeedbackBinding.tlUrgent.setError(getString(R.string.feedback_priority_is_required)); return; } if (rbType == null) { - tlType.setError(getString(R.string.feedback_type_is_required)); + fragmentFeedbackBinding.tlType.setError(getString(R.string.feedback_type_is_required)); return; } final String urgent = rbUrgent.getText().toString(); @@ -137,9 +124,9 @@ public String[] getArgumentArray(String message) { } private void clearError() { - tlUrgent.setError(""); - tlType.setError(""); - tlMessage.setError(""); + fragmentFeedbackBinding.tlUrgent.setError(""); + fragmentFeedbackBinding.tlType.setError(""); + fragmentFeedbackBinding.tlMessage.setError(""); } private void saveData(Realm realm, String urgent, String type, String message) { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackListFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackListFragment.java index 5486701f30..56bb95cc0a 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackListFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackListFragment.java @@ -5,14 +5,12 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.FragmentFeedbackListBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmFeedback; import org.ole.planet.myplanet.model.RealmUserModel; @@ -24,8 +22,7 @@ import io.realm.RealmResults; public class FeedbackListFragment extends Fragment implements FeedbackFragment.OnFeedbackSubmittedListener { - TextView etMessage; - RecyclerView rvFeedbacks; + private FragmentFeedbackListBinding fragmentFeedbackListBinding; Realm mRealm; RealmUserModel userModel; @@ -35,27 +32,25 @@ public FeedbackListFragment() { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_feedback_list, container, false); - etMessage = v.findViewById(R.id.et_message); - rvFeedbacks = v.findViewById(R.id.rv_feedback); + fragmentFeedbackListBinding = FragmentFeedbackListBinding.inflate(inflater, container, false); mRealm = new DatabaseService(getActivity()).getRealmInstance(); userModel = new UserProfileDbHandler(getActivity()).getUserModel(); - v.findViewById(R.id.fab).setOnClickListener(vi -> { + fragmentFeedbackListBinding.fab.setOnClickListener(vi -> { FeedbackFragment feedbackFragment = new FeedbackFragment(); feedbackFragment.setOnFeedbackSubmittedListener(this); feedbackFragment.show(getChildFragmentManager(), ""); }); - return v; + return fragmentFeedbackListBinding.getRoot(); } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - rvFeedbacks.setLayoutManager(new LinearLayoutManager(getActivity())); + fragmentFeedbackListBinding.rvFeedback.setLayoutManager(new LinearLayoutManager(getActivity())); List list = mRealm.where(RealmFeedback.class).equalTo("owner", userModel.getName()).findAll(); if (userModel.isManager()) list = mRealm.where(RealmFeedback.class).findAll(); AdapterFeedback adapterFeedback = new AdapterFeedback(getActivity(), list); - rvFeedbacks.setAdapter(adapterFeedback); + fragmentFeedbackListBinding.rvFeedback.setAdapter(adapterFeedback); } @Override @@ -70,7 +65,7 @@ public void onFeedbackSubmitted() { RealmResults updatedList = mRealm.where(RealmFeedback.class).equalTo("owner", userModel.getName()).findAll(); if (userModel.isManager()) updatedList = mRealm.where(RealmFeedback.class).findAll(); AdapterFeedback adapterFeedback = new AdapterFeedback(getActivity(), updatedList); - rvFeedbacks.setAdapter(adapterFeedback); + fragmentFeedbackListBinding.rvFeedback.setAdapter(adapterFeedback); adapterFeedback.notifyDataSetChanged(); }); }