From f957a295f5183653adfcf1eff0226cd820636611 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Mon, 9 Oct 2023 19:44:14 +0300 Subject: [PATCH] news: refactor towards more stability (fixes #2589) (#2593) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../planet/myplanet/ui/community/CommunityFragment.kt | 2 +- .../org/ole/planet/myplanet/ui/news/AdapterNews.java | 10 ++++++++-- .../org/ole/planet/myplanet/ui/news/NewsFragment.java | 2 +- .../org/ole/planet/myplanet/ui/news/ReplyActivity.java | 2 +- .../planet/myplanet/ui/team/MyTeamsDetailFragment.java | 2 +- .../ui/team/teamDiscussion/DiscussionListFragment.java | 2 +- 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f791375360..e43308f5f7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1087 - versionName "0.10.87" + versionCode 1088 + versionName "0.10.88" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/community/CommunityFragment.kt b/app/src/main/java/org/ole/planet/myplanet/ui/community/CommunityFragment.kt index df9a092c92..7bff3bc38b 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/community/CommunityFragment.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/community/CommunityFragment.kt @@ -58,7 +58,7 @@ class CommunityFragment : BaseContainerFragment(), AdapterNews.OnNewsItemClickLi changeLayoutManager(orientation) Utilities.log("list size " + list.size) - var adapter = AdapterNews(activity, list, user, null) + var adapter = AdapterNews(activity, list, user, null, true) adapter.setListener(this) adapter.setFromLogin(requireArguments().getBoolean("fromLogin", false)) adapter.setmRealm(mRealm) 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 31b0f7d9d6..3577174df6 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 @@ -34,6 +34,7 @@ import org.ole.planet.myplanet.utilities.Utilities; import java.io.File; +import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.List; @@ -55,16 +56,18 @@ public class AdapterNews extends RecyclerView.Adapter { public Context context; public RealmUserModel currentUser; public boolean fromLogin; + private boolean isFromNewsFragment; public void setImageList(RealmList imageList) { this.imageList = imageList; } - public AdapterNews(Context context, List list, RealmUserModel user, RealmNews parentNews) { + public AdapterNews(Context context, List list, RealmUserModel user, RealmNews parentNews,boolean isFromNewsFragment) { this.context = context; this.list = list; this.currentUser = user; this.parentNews = parentNews; + this.isFromNewsFragment = isFromNewsFragment; config = Utilities.getCloudConfig().selectMode(ChipCloud.SelectMode.close); } @@ -278,9 +281,12 @@ private void showHideButtons(RealmUserModel userModel, RecyclerView.ViewHolder h } } + private void deletePost(RealmNews news) { if (!mRealm.isInTransaction()) mRealm.beginTransaction(); - list.remove(news); + if (isFromNewsFragment) { + list.remove(news); + } if (news != null) { news.deleteFromRealm(); } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/news/NewsFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/news/NewsFragment.java index 3bc46a5ff3..c1c65ddcac 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/news/NewsFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/news/NewsFragment.java @@ -144,7 +144,7 @@ public void setData(List list) { SharedPreferences settings = getActivity().getSharedPreferences(SyncActivity.PREFS_NAME, Context.MODE_PRIVATE); List lib = mRealm.where(RealmMyLibrary.class).in("_id", resourceIds.toArray(new String[]{})).findAll(); getUrlsAndStartDownload(lib, settings, urls); - adapterNews = new AdapterNews(getActivity(), list, user, null); + adapterNews = new AdapterNews(getActivity(), list, user, null, true); adapterNews.setmRealm(mRealm); adapterNews.setFromLogin(getArguments().getBoolean("fromLogin")); adapterNews.setListener(this); diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/news/ReplyActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/news/ReplyActivity.java index 7a3031b34c..d73eedbc50 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/news/ReplyActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/news/ReplyActivity.java @@ -65,7 +65,7 @@ private void showData(String id) { RealmNews news = mRealm.where(RealmNews.class).equalTo("id", id).findFirst(); List list = mRealm.where(RealmNews.class).sort("time", Sort.DESCENDING).equalTo("replyTo", id, Case.INSENSITIVE).findAll(); - newsAdapter = new AdapterNews(this, list, user, news); + newsAdapter = new AdapterNews(this, list, user, news, false); newsAdapter.setListener(this); newsAdapter.setmRealm(mRealm); newsAdapter.setFromLogin(getIntent().getBooleanExtra("fromLogin", false)); diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/team/MyTeamsDetailFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/team/MyTeamsDetailFragment.java index 71b73f05fe..c07a23858c 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/team/MyTeamsDetailFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/team/MyTeamsDetailFragment.java @@ -179,7 +179,7 @@ private void createTeamLog() { } private void showRecyclerView(List realmNewsList) { - AdapterNews adapterNews = new AdapterNews(getActivity(), realmNewsList, user, null); + AdapterNews adapterNews = new AdapterNews(getActivity(), realmNewsList, user, null, true); adapterNews.setmRealm(mRealm); adapterNews.setListener(this); rvDiscussion.setAdapter(adapterNews); diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/team/teamDiscussion/DiscussionListFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/team/teamDiscussion/DiscussionListFragment.java index 02fa12782f..df1e871320 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/team/teamDiscussion/DiscussionListFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/team/teamDiscussion/DiscussionListFragment.java @@ -92,7 +92,7 @@ public void onConfigurationChanged(Configuration newConfig) { } private void showRecyclerView(List realmNewsList) { - AdapterNews adapterNews = new AdapterNews(getActivity(), realmNewsList, user, null); + AdapterNews adapterNews = new AdapterNews(getActivity(), realmNewsList, user, null, true); adapterNews.setmRealm(mRealm); adapterNews.setListener(this); fragmentDiscussionListBinding.rvDiscussion.setAdapter(adapterNews);