From f7b7ad397880d58a0de4078d109cfdecc81bf87b Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Wed, 27 Sep 2023 21:05:17 +0300 Subject: [PATCH] news: move functions into adapterNews (fixes #2536) (#2540) Co-authored-by: dogi --- app/build.gradle | 4 +- .../planet/myplanet/base/BaseNewsAdapter.java | 83 ------------------- .../planet/myplanet/ui/news/AdapterNews.java | 66 ++++++++++++++- 3 files changed, 64 insertions(+), 89 deletions(-) delete mode 100644 app/src/main/java/org/ole/planet/myplanet/base/BaseNewsAdapter.java diff --git a/app/build.gradle b/app/build.gradle index 07fd03fd2a..9ae2e18fbb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1059 - versionName "0.10.59" + versionCode 1060 + versionName "0.10.60" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/base/BaseNewsAdapter.java b/app/src/main/java/org/ole/planet/myplanet/base/BaseNewsAdapter.java deleted file mode 100644 index eba5740615..0000000000 --- a/app/src/main/java/org/ole/planet/myplanet/base/BaseNewsAdapter.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.ole.planet.myplanet.base; - -import android.content.Context; -import android.view.View; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; - -import androidx.recyclerview.widget.RecyclerView; - -import com.google.android.flexbox.FlexboxLayout; -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.model.RealmNews; -import org.ole.planet.myplanet.model.RealmUserModel; -import org.ole.planet.myplanet.utilities.Constants; -import org.ole.planet.myplanet.utilities.Utilities; - -import java.util.Calendar; - -import io.realm.Realm; - -public abstract class BaseNewsAdapter extends RecyclerView.Adapter { - public Realm mRealm; - public Context context; - public RealmUserModel currentUser; - public boolean fromLogin; - - public String getLabel(String s) { - for (String key : Constants.LABELS.keySet()) { - if (s.equals(Constants.LABELS.get(key))) { - return key; - } - } - return ""; - } - - public void showShareButton(RecyclerView.ViewHolder holder, RealmNews news) { - ((ViewHolderNews) holder).btnShare.setVisibility((news.isCommunityNews() || fromLogin) ? View.GONE : View.VISIBLE); - ((ViewHolderNews) holder).btnShare.setOnClickListener(view -> { - JsonArray array = new Gson().fromJson(news.getViewIn(), JsonArray.class); - JsonObject ob = new JsonObject(); - ob.addProperty("section", "community"); - ob.addProperty("_id", currentUser.getPlanetCode() + "@" + currentUser.getParentCode()); - ob.addProperty("sharedDate", Calendar.getInstance().getTimeInMillis()); - array.add(ob); - if (!mRealm.isInTransaction()) mRealm.beginTransaction(); - news.setViewIn(new Gson().toJson(array)); - mRealm.commitTransaction(); - Utilities.toast(context, context.getString(R.string.shared_to_community)); - ((ViewHolderNews) holder).btnShare.setVisibility(View.GONE); - }); - } - - public class ViewHolderNews extends RecyclerView.ViewHolder { - public TextView tvName, tvDate, tvMessage; - public ImageView imgEdit, imgDelete, imgUser, newsImage; - public LinearLayout llEditDelete; - public FlexboxLayout fbChips; - public Button btnReply, btnShowReply, btnAddLabel, btnShare; - - public ViewHolderNews(View itemView) { - super(itemView); - tvDate = itemView.findViewById(R.id.tv_date); - tvName = itemView.findViewById(R.id.tv_name); - tvMessage = itemView.findViewById(R.id.tv_message); - imgDelete = itemView.findViewById(R.id.img_delete); - imgEdit = itemView.findViewById(R.id.img_edit); - imgUser = itemView.findViewById(R.id.img_user); - llEditDelete = itemView.findViewById(R.id.ll_edit_delete); - btnReply = itemView.findViewById(R.id.btn_reply); - btnShowReply = itemView.findViewById(R.id.btn_show_reply); - btnAddLabel = itemView.findViewById(R.id.btn_add_label); - btnShare = itemView.findViewById(R.id.btn_share); - newsImage = itemView.findViewById(R.id.img_news); - fbChips = itemView.findViewById(R.id.fb_chips); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/news/AdapterNews.java b/app/src/main/java/org/ole/planet/myplanet/ui/news/AdapterNews.java index 38b74d0d3a..31b0f7d9d6 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/news/AdapterNews.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/news/AdapterNews.java @@ -6,9 +6,12 @@ import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.EditText; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupMenu; +import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; @@ -16,11 +19,12 @@ import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; +import com.google.android.flexbox.FlexboxLayout; 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.base.BaseNewsAdapter; import org.ole.planet.myplanet.model.RealmMyLibrary; import org.ole.planet.myplanet.model.RealmNews; import org.ole.planet.myplanet.model.RealmUserModel; @@ -30,6 +34,7 @@ import org.ole.planet.myplanet.utilities.Utilities; import java.io.File; +import java.util.Calendar; import java.util.HashMap; import java.util.List; @@ -40,14 +45,16 @@ import io.realm.RealmList; import io.realm.Sort; -public class AdapterNews extends BaseNewsAdapter { +public class AdapterNews extends RecyclerView.Adapter { private List list; - private OnNewsItemClickListener listener; private RealmNews parentNews; - private ChipCloudConfig config; private RealmList imageList; + public Realm mRealm; + public Context context; + public RealmUserModel currentUser; + public boolean fromLogin; public void setImageList(RealmList imageList) { this.imageList = imageList; @@ -292,4 +299,55 @@ public interface OnNewsItemClickListener { void addImage(LinearLayout llImage); } + + public String getLabel(String s) { + for (String key : Constants.LABELS.keySet()) { + if (s.equals(Constants.LABELS.get(key))) { + return key; + } + } + return ""; + } + + public void showShareButton(RecyclerView.ViewHolder holder, RealmNews news) { + ((ViewHolderNews) holder).btnShare.setVisibility((news.isCommunityNews() || fromLogin) ? View.GONE : View.VISIBLE); + ((ViewHolderNews) holder).btnShare.setOnClickListener(view -> { + JsonArray array = new Gson().fromJson(news.getViewIn(), JsonArray.class); + JsonObject ob = new JsonObject(); + ob.addProperty("section", "community"); + ob.addProperty("_id", currentUser.getPlanetCode() + "@" + currentUser.getParentCode()); + ob.addProperty("sharedDate", Calendar.getInstance().getTimeInMillis()); + array.add(ob); + if (!mRealm.isInTransaction()) mRealm.beginTransaction(); + news.setViewIn(new Gson().toJson(array)); + mRealm.commitTransaction(); + Utilities.toast(context, context.getString(R.string.shared_to_community)); + ((ViewHolderNews) holder).btnShare.setVisibility(View.GONE); + }); + } + + public class ViewHolderNews extends RecyclerView.ViewHolder { + public TextView tvName, tvDate, tvMessage; + public ImageView imgEdit, imgDelete, imgUser, newsImage; + public LinearLayout llEditDelete; + public FlexboxLayout fbChips; + public Button btnReply, btnShowReply, btnAddLabel, btnShare; + + public ViewHolderNews(View itemView) { + super(itemView); + tvDate = itemView.findViewById(R.id.tv_date); + tvName = itemView.findViewById(R.id.tv_name); + tvMessage = itemView.findViewById(R.id.tv_message); + imgDelete = itemView.findViewById(R.id.img_delete); + imgEdit = itemView.findViewById(R.id.img_edit); + imgUser = itemView.findViewById(R.id.img_user); + llEditDelete = itemView.findViewById(R.id.ll_edit_delete); + btnReply = itemView.findViewById(R.id.btn_reply); + btnShowReply = itemView.findViewById(R.id.btn_show_reply); + btnAddLabel = itemView.findViewById(R.id.btn_add_label); + btnShare = itemView.findViewById(R.id.btn_share); + newsImage = itemView.findViewById(R.id.img_news); + fbChips = itemView.findViewById(R.id.fb_chips); + } + } }