From 5b54a1e8d4200c21c42a7b090c97d31eaf0e759d Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Wed, 31 Jan 2024 21:18:55 -0300 Subject: [PATCH 01/14] Implement createIntentShowReaderSubs in ReaderActivityLauncher --- .../android/ui/reader/ReaderActivityLauncher.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderActivityLauncher.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderActivityLauncher.java index 81843376bae2..1299d325b157 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderActivityLauncher.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderActivityLauncher.java @@ -312,9 +312,13 @@ public static void showReaderSubs(Context context) { } public static void showReaderSubs(Context context, int selectPosition) { - Intent intent = new Intent(context, ReaderSubsActivity.class); + context.startActivity(createIntentShowReaderSubs(context, selectPosition)); + } + + public static Intent createIntentShowReaderSubs(@NonNull final Context context, final int selectPosition) { + final Intent intent = new Intent(context, ReaderSubsActivity.class); intent.putExtra(ReaderConstants.ARG_SUBS_TAB_POSITION, selectPosition); - context.startActivity(intent); + return intent; } public static void showReaderInterests(Activity activity) { From 8066f2fd74c2c1fadf7f7bb90629b75db9797b96 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Wed, 31 Jan 2024 21:21:56 -0300 Subject: [PATCH 02/14] Implement ReaderSubsActivity activity result in ReaderPostListFragment to detect if subscriptions should be refreshed --- .../ui/reader/ReaderPostListFragment.java | 26 ++++++++++++++++--- .../android/ui/reader/ReaderSubsActivity.java | 5 ++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java index 37b91bfa56e5..47756f2eee02 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java @@ -20,6 +20,8 @@ import android.widget.ProgressBar; import android.widget.TextView; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; @@ -213,6 +215,7 @@ public class ReaderPostListFragment extends ViewPagerFragment private boolean mIsUpdating; private boolean mIsFilterableScreen; private boolean mIsFiltered = false; + private ActivityResultLauncher mReaderSubsActivityResultLauncher; /* * called by post adapter to load older posts when user scrolls to the last post */ @@ -650,9 +653,11 @@ private void initSubFilterViewModel(@Nullable Bundle savedInstanceState) { mSubFilterViewModel.getBottomSheetAction().observe(getViewLifecycleOwner(), event -> { event.applyIfNotHandled(action -> { if (action instanceof OpenSubsAtPage) { - ReaderActivityLauncher.showReaderSubs( - requireActivity(), - ((OpenSubsAtPage) action).getTabIndex() + mReaderSubsActivityResultLauncher.launch( + ReaderActivityLauncher.createIntentShowReaderSubs( + requireActivity(), + ((OpenSubsAtPage) action).getTabIndex() + ) ); } else if (action instanceof OpenLoginPage) { wpMainActivityViewModel.onOpenLoginPage(); @@ -844,6 +849,21 @@ public void onAttach(@NonNull Context context) { if (context instanceof BottomNavController) { mBottomNavController = (BottomNavController) context; } + + mReaderSubsActivityResultLauncher = registerForActivityResult( + new ActivityResultContracts.StartActivityForResult(), + result -> { + if (result.getResultCode() == Activity.RESULT_OK) { + final Intent data = result.getData(); + if (data != null) { + final boolean shouldRefreshSubscriptions = + data.getBooleanExtra(ReaderSubsActivity.RESULT_SHOULD_REFRESH_SUBSCRIPTIONS, false); + if (shouldRefreshSubscriptions) { + // TODO refresh tags if list have changed + } + } + } + }); } @Override diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java index fd0d8281fddf..6eaa55b488f1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java @@ -87,6 +87,8 @@ public class ReaderSubsActivity extends LocaleAwareActivity public static final int TAB_IDX_FOLLOWED_TAGS = 0; public static final int TAB_IDX_FOLLOWED_BLOGS = 1; + public static final String RESULT_SHOULD_REFRESH_SUBSCRIPTIONS = "should_refresh_subscriptions"; + @Inject AccountStore mAccountStore; @Inject ReaderTracker mReaderTracker; @@ -102,6 +104,9 @@ public void handleOnBackPressed() { EventBus.getDefault().postSticky(new ReaderEvents.TagAdded(mLastAddedTagName)); } mReaderTracker.track(Stat.READER_MANAGE_VIEW_DISMISSED); + final Intent data = new Intent(); + data.putExtra(RESULT_SHOULD_REFRESH_SUBSCRIPTIONS, true); + setResult(RESULT_OK, data); CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } }; From 31d126c1f1624b57fa55cec8e393021fb69d3e42 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:19:39 -0300 Subject: [PATCH 03/14] Check if subscribed tags have changed in ReaderSubsActivity --- .../android/ui/reader/ReaderSubsActivity.java | 23 ++++++++++++--- .../android/ui/reader/ReaderTagFragment.java | 28 +++++++++++++++++++ .../ui/reader/adapters/ReaderTagAdapter.java | 4 +++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java index 6eaa55b488f1..95b3a32f882b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java @@ -105,7 +105,14 @@ public void handleOnBackPressed() { } mReaderTracker.track(Stat.READER_MANAGE_VIEW_DISMISSED); final Intent data = new Intent(); - data.putExtra(RESULT_SHOULD_REFRESH_SUBSCRIPTIONS, true); + boolean shouldRefreshSubscriptions = false; + if (mPageAdapter != null) { + final ReaderTagFragment readerTagFragment = mPageAdapter.getReaderTagFragment(); + if (readerTagFragment != null) { + shouldRefreshSubscriptions = readerTagFragment.hasChangedSelectedTags(); + } + } + data.putExtra(RESULT_SHOULD_REFRESH_SUBSCRIPTIONS, shouldRefreshSubscriptions); setResult(RESULT_OK, data); CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } @@ -569,12 +576,20 @@ public Object instantiateItem(ViewGroup container, int position) { } private void refreshFollowedTagFragment() { - for (Fragment fragment : mFragments) { + final ReaderTagFragment fragment = getReaderTagFragment(); + if (fragment != null) { + fragment.refresh(); + } + } + + @Nullable + private ReaderTagFragment getReaderTagFragment() { + for (final Fragment fragment : mFragments) { if (fragment instanceof ReaderTagFragment) { - ReaderTagFragment tagFragment = (ReaderTagFragment) fragment; - tagFragment.refresh(); + return (ReaderTagFragment) fragment; } } + return null; } private void refreshBlogFragments(ReaderBlogType blogType) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java index 5b06e050695a..ec2e85b3f567 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java @@ -11,12 +11,18 @@ import org.wordpress.android.R; import org.wordpress.android.models.ReaderTag; +import org.wordpress.android.models.ReaderTagList; import org.wordpress.android.ui.ActionableEmptyView; import org.wordpress.android.ui.reader.adapters.ReaderTagAdapter; import org.wordpress.android.ui.reader.views.ReaderRecyclerView; import org.wordpress.android.util.AppLog; import org.wordpress.android.util.WPActivityUtils; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + /* * fragment hosted by ReaderSubsActivity which shows followed tags */ @@ -24,6 +30,10 @@ public class ReaderTagFragment extends Fragment implements ReaderTagAdapter.TagD private ReaderRecyclerView mRecyclerView; private ReaderTagAdapter mTagAdapter; + private boolean mIsFirstDataLoaded = true; + // TODO set to true onAttach? + private ReaderTagList mInitialReaderTagList = new ReaderTagList(); + static ReaderTagFragment newInstance() { AppLog.d(AppLog.T.READER, "reader tag list > newInstance"); return new ReaderTagFragment(); @@ -36,6 +46,19 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, return view; } + public boolean hasChangedSelectedTags() { + final Set initialTagsSlugs = new HashSet<>(); + for (final ReaderTag readerTag : mInitialReaderTagList) { + initialTagsSlugs.add(readerTag.getTagSlug()); + } + final List currentReaderTagList = getTagAdapter().getItems(); + final Set currentTagsSlugs = new HashSet<>(); + for (final ReaderTag readerTag : currentReaderTagList) { + currentTagsSlugs.add(readerTag.getTagSlug()); + } + return !(initialTagsSlugs.containsAll(currentTagsSlugs)); + } + private void checkEmptyView() { if (!isAdded() || getView() == null) { return; @@ -78,6 +101,11 @@ private ReaderTagAdapter getTagAdapter() { @Override public void onDataLoaded(boolean isEmpty) { checkEmptyView(); + if (mIsFirstDataLoaded) { + mIsFirstDataLoaded = false; + mInitialReaderTagList.clear(); + mInitialReaderTagList.addAll(mTagAdapter.getItems()); + } } }); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderTagAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderTagAdapter.java index 57a3d3fe42a7..1b4f5ba399ef 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderTagAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderTagAdapter.java @@ -93,6 +93,10 @@ public TagViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return new TagViewHolder(view); } + public ReaderTagList getItems() { + return mTags; + } + @Override public void onBindViewHolder(TagViewHolder holder, int position) { final ReaderTag tag = mTags.get(position); From ddcf6cbcb6238e7ad89fa1cfe2a52a387dd77f28 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:51:00 -0300 Subject: [PATCH 04/14] Reset is first data loaded flag on onAttach --- .../android/ui/reader/ReaderTagFragment.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java index ec2e85b3f567..0286fe447808 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java @@ -30,9 +30,8 @@ public class ReaderTagFragment extends Fragment implements ReaderTagAdapter.TagD private ReaderRecyclerView mRecyclerView; private ReaderTagAdapter mTagAdapter; - private boolean mIsFirstDataLoaded = true; - // TODO set to true onAttach? - private ReaderTagList mInitialReaderTagList = new ReaderTagList(); + private boolean mIsFirstDataLoaded; + private final ReaderTagList mInitialReaderTagList = new ReaderTagList(); static ReaderTagFragment newInstance() { AppLog.d(AppLog.T.READER, "reader tag list > newInstance"); @@ -85,6 +84,12 @@ public void onActivityCreated(Bundle savedInstanceState) { refresh(); } + @Override + public void onAttach(Context context) { + super.onAttach(context); + mIsFirstDataLoaded = true; + } + void refresh() { if (hasTagAdapter()) { AppLog.d(AppLog.T.READER, "reader subs > refreshing tag fragment"); From 42f24c37d6280b9a6f24f11f5c7bb3e0c567d643 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Thu, 1 Feb 2024 17:06:42 -0300 Subject: [PATCH 05/14] Check if subscribed blogs have changed in ReaderSubsActivity --- .../android/ui/reader/ReaderBlogFragment.java | 43 +++++++++++++++++-- .../android/ui/reader/ReaderSubsActivity.java | 16 ++++++- .../android/ui/reader/ReaderTagFragment.java | 19 ++++---- .../ui/reader/adapters/ReaderBlogAdapter.java | 6 +++ .../ui/reader/adapters/ReaderTagAdapter.java | 2 + 5 files changed, 71 insertions(+), 15 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java index f2c842c66c0a..8be3227aac7c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java @@ -1,5 +1,6 @@ package org.wordpress.android.ui.reader; +import android.content.Context; import android.os.Bundle; import android.text.TextUtils; import android.view.LayoutInflater; @@ -17,6 +18,8 @@ import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.models.ReaderBlog; +import org.wordpress.android.models.ReaderBlogList; +import org.wordpress.android.models.ReaderTagList; import org.wordpress.android.ui.ActionableEmptyView; import org.wordpress.android.ui.reader.adapters.ReaderBlogAdapter; import org.wordpress.android.ui.reader.adapters.ReaderBlogAdapter.ReaderBlogType; @@ -24,6 +27,10 @@ import org.wordpress.android.ui.reader.views.ReaderRecyclerView; import org.wordpress.android.util.AppLog; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import javax.inject.Inject; /* @@ -39,6 +46,9 @@ public class ReaderBlogFragment extends Fragment @Inject ReaderTracker mReaderTracker; + private boolean mIsFirstDataLoaded; + private final ReaderBlogList mInitialReaderBlogList = new ReaderBlogList(); + private static final String ARG_BLOG_TYPE = "blog_type"; private static final String KEY_SEARCH_FILTER = "search_filter"; @@ -79,6 +89,21 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, return view; } + public boolean hasChangedSelectedBlogs() { + final Set initialBlogsUrls = new HashSet<>(); + for (final ReaderBlog readerBlog : mInitialReaderBlogList) { + initialBlogsUrls.add(readerBlog.getUrl()); + } + final List currentReaderBlogList = mAdapter.getItems(); + final Set currentBlogsUrls = new HashSet<>(); + if (currentReaderBlogList != null) { + for (final ReaderBlog readerBlog : currentReaderBlogList) { + currentBlogsUrls.add(readerBlog.getUrl()); + } + } + return !(initialBlogsUrls.containsAll(currentBlogsUrls)); + } + private void checkEmptyView() { if (!isAdded() || getView() == null) { return; @@ -147,6 +172,12 @@ public void onResume() { refresh(); } + @Override + public void onAttach(Context context) { + super.onAttach(context); + mIsFirstDataLoaded = true; + } + /* * note this will only be called for followed blogs */ @@ -227,10 +258,14 @@ private ReaderBlogAdapter getBlogAdapter() { ReaderTracker.SOURCE_SETTINGS ); mAdapter.setBlogClickListener(this); - mAdapter.setDataLoadedListener(new ReaderInterfaces.DataLoadedListener() { - @Override - public void onDataLoaded(boolean isEmpty) { - checkEmptyView(); + mAdapter.setDataLoadedListener(isEmpty -> { + checkEmptyView(); + if (mIsFirstDataLoaded) { + mIsFirstDataLoaded = false; + mInitialReaderBlogList.clear(); + if (mAdapter != null && mAdapter.getItems() != null) { + mInitialReaderBlogList.addAll(mAdapter.getItems()); + } } }); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java index 95b3a32f882b..ba247bd9c463 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java @@ -108,8 +108,10 @@ public void handleOnBackPressed() { boolean shouldRefreshSubscriptions = false; if (mPageAdapter != null) { final ReaderTagFragment readerTagFragment = mPageAdapter.getReaderTagFragment(); - if (readerTagFragment != null) { - shouldRefreshSubscriptions = readerTagFragment.hasChangedSelectedTags(); + final ReaderBlogFragment readerBlogFragment = mPageAdapter.getReaderBlogFragment(); + if (readerTagFragment != null && readerBlogFragment != null) { + shouldRefreshSubscriptions = readerTagFragment.hasChangedSelectedTags() + || readerBlogFragment.hasChangedSelectedBlogs(); } } data.putExtra(RESULT_SHOULD_REFRESH_SUBSCRIPTIONS, shouldRefreshSubscriptions); @@ -592,6 +594,16 @@ private ReaderTagFragment getReaderTagFragment() { return null; } + @Nullable + private ReaderBlogFragment getReaderBlogFragment() { + for (final Fragment fragment : mFragments) { + if (fragment instanceof ReaderBlogFragment) { + return (ReaderBlogFragment) fragment; + } + } + return null; + } + private void refreshBlogFragments(ReaderBlogType blogType) { for (Fragment fragment : mFragments) { if (fragment instanceof ReaderBlogFragment) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java index 0286fe447808..ec3f877200c6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java @@ -52,8 +52,10 @@ public boolean hasChangedSelectedTags() { } final List currentReaderTagList = getTagAdapter().getItems(); final Set currentTagsSlugs = new HashSet<>(); - for (final ReaderTag readerTag : currentReaderTagList) { - currentTagsSlugs.add(readerTag.getTagSlug()); + if (currentReaderTagList != null) { + for (final ReaderTag readerTag : currentReaderTagList) { + currentTagsSlugs.add(readerTag.getTagSlug()); + } } return !(initialTagsSlugs.containsAll(currentTagsSlugs)); } @@ -102,13 +104,12 @@ private ReaderTagAdapter getTagAdapter() { Context context = WPActivityUtils.getThemedContext(getActivity()); mTagAdapter = new ReaderTagAdapter(context); mTagAdapter.setTagDeletedListener(this); - mTagAdapter.setDataLoadedListener(new ReaderInterfaces.DataLoadedListener() { - @Override - public void onDataLoaded(boolean isEmpty) { - checkEmptyView(); - if (mIsFirstDataLoaded) { - mIsFirstDataLoaded = false; - mInitialReaderTagList.clear(); + mTagAdapter.setDataLoadedListener(isEmpty -> { + checkEmptyView(); + if (mIsFirstDataLoaded) { + mIsFirstDataLoaded = false; + mInitialReaderTagList.clear(); + if (mTagAdapter != null && mTagAdapter.getItems() != null) { mInitialReaderTagList.addAll(mTagAdapter.getItems()); } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java index 095981ff9370..4b782b3d14b8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java @@ -10,6 +10,7 @@ import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; import org.wordpress.android.R; @@ -99,6 +100,11 @@ public void refresh() { new LoadBlogsTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } + @Nullable + public ReaderBlogList getItems() { + return mFollowedBlogs; + } + private ReaderBlogType getBlogType() { return mBlogType; } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderTagAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderTagAdapter.java index 1b4f5ba399ef..5dc99a307cea 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderTagAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderTagAdapter.java @@ -9,6 +9,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; import org.wordpress.android.R; @@ -93,6 +94,7 @@ public TagViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return new TagViewHolder(view); } + @Nullable public ReaderTagList getItems() { return mTags; } From beae7b9a6b07477613506bc2cb0c1f02aedc1d5f Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Thu, 1 Feb 2024 17:59:30 -0300 Subject: [PATCH 06/14] Extract setResult and initReaderSubsActivityResultLauncher methods --- .../ui/reader/ReaderPostListFragment.java | 6 +++- .../android/ui/reader/ReaderSubsActivity.java | 28 +++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java index 47756f2eee02..08e795ff6f88 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java @@ -850,6 +850,10 @@ public void onAttach(@NonNull Context context) { mBottomNavController = (BottomNavController) context; } + initReaderSubsActivityResultLauncher(); + } + + private void initReaderSubsActivityResultLauncher() { mReaderSubsActivityResultLauncher = registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), result -> { @@ -859,7 +863,7 @@ public void onAttach(@NonNull Context context) { final boolean shouldRefreshSubscriptions = data.getBooleanExtra(ReaderSubsActivity.RESULT_SHOULD_REFRESH_SUBSCRIPTIONS, false); if (shouldRefreshSubscriptions) { - // TODO refresh tags if list have changed + // TODO refresh chips if there were changes } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java index ba247bd9c463..8fc981cbaeb5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java @@ -104,18 +104,7 @@ public void handleOnBackPressed() { EventBus.getDefault().postSticky(new ReaderEvents.TagAdded(mLastAddedTagName)); } mReaderTracker.track(Stat.READER_MANAGE_VIEW_DISMISSED); - final Intent data = new Intent(); - boolean shouldRefreshSubscriptions = false; - if (mPageAdapter != null) { - final ReaderTagFragment readerTagFragment = mPageAdapter.getReaderTagFragment(); - final ReaderBlogFragment readerBlogFragment = mPageAdapter.getReaderBlogFragment(); - if (readerTagFragment != null && readerBlogFragment != null) { - shouldRefreshSubscriptions = readerTagFragment.hasChangedSelectedTags() - || readerBlogFragment.hasChangedSelectedBlogs(); - } - } - data.putExtra(RESULT_SHOULD_REFRESH_SUBSCRIPTIONS, shouldRefreshSubscriptions); - setResult(RESULT_OK, data); + setResult(); CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } }; @@ -185,6 +174,21 @@ public void onPageSelected(int position) { mReaderTracker.track(Stat.READER_MANAGE_VIEW_DISPLAYED); } + private void setResult() { + final Intent data = new Intent(); + boolean shouldRefreshSubscriptions = false; + if (mPageAdapter != null) { + final ReaderTagFragment readerTagFragment = mPageAdapter.getReaderTagFragment(); + final ReaderBlogFragment readerBlogFragment = mPageAdapter.getReaderBlogFragment(); + if (readerTagFragment != null && readerBlogFragment != null) { + shouldRefreshSubscriptions = readerTagFragment.hasChangedSelectedTags() + || readerBlogFragment.hasChangedSelectedBlogs(); + } + } + data.putExtra(RESULT_SHOULD_REFRESH_SUBSCRIPTIONS, shouldRefreshSubscriptions); + setResult(RESULT_OK, data); + } + @Override protected void onPause() { EventBus.getDefault().unregister(this); From 39d6127daea171ab16986230811dae9758071d35 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Thu, 1 Feb 2024 23:22:44 -0300 Subject: [PATCH 07/14] Refresh number of tags in subscriptions chip when returning from manage blogs and tags screen --- .../org/wordpress/android/ui/reader/ReaderBlogFragment.java | 2 +- .../wordpress/android/ui/reader/ReaderPostListFragment.java | 2 +- .../org/wordpress/android/ui/reader/ReaderTagFragment.java | 3 +-- .../wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java index 8be3227aac7c..e168575e0598 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java @@ -101,7 +101,7 @@ public boolean hasChangedSelectedBlogs() { currentBlogsUrls.add(readerBlog.getUrl()); } } - return !(initialBlogsUrls.containsAll(currentBlogsUrls)); + return !(initialBlogsUrls.equals(currentBlogsUrls)); } private void checkEmptyView() { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java index 08e795ff6f88..f499c9b80497 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java @@ -863,7 +863,7 @@ private void initReaderSubsActivityResultLauncher() { final boolean shouldRefreshSubscriptions = data.getBooleanExtra(ReaderSubsActivity.RESULT_SHOULD_REFRESH_SUBSCRIPTIONS, false); if (shouldRefreshSubscriptions) { - // TODO refresh chips if there were changes + mSubFilterViewModel.loadSubFilters(); } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java index ec3f877200c6..1638e7ae1eb0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderTagFragment.java @@ -18,7 +18,6 @@ import org.wordpress.android.util.AppLog; import org.wordpress.android.util.WPActivityUtils; -import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -57,7 +56,7 @@ public boolean hasChangedSelectedTags() { currentTagsSlugs.add(readerTag.getTagSlug()); } } - return !(initialTagsSlugs.containsAll(currentTagsSlugs)); + return !(initialTagsSlugs.equals(currentTagsSlugs)); } private void checkEmptyView() { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt index 4b6d3b5ce45f..be8d4be71660 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt @@ -466,7 +466,7 @@ class ReaderViewModel @Inject constructor( ) } - fun showTopBarFilterGroup(readerTab: ReaderTag, subFilterItems: List) { + fun showTopBarFilterGroup(readerTag: ReaderTag, subFilterItems: List) { val selectedReaderTag = _topBarUiState.value?.selectedItem?.let { readerTagsList[readerTopBarMenuHelper.getReaderTagIndexFromMenuItem(it)] } ?: return From f9ec23673eb12671ca2eee087e4b7f45fbef6ab6 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Mon, 5 Feb 2024 01:19:34 -0300 Subject: [PATCH 08/14] Fix checkstyle --- .../java/org/wordpress/android/ui/reader/ReaderBlogFragment.java | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java index e168575e0598..39c606e776be 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java @@ -19,7 +19,6 @@ import org.wordpress.android.WordPress; import org.wordpress.android.models.ReaderBlog; import org.wordpress.android.models.ReaderBlogList; -import org.wordpress.android.models.ReaderTagList; import org.wordpress.android.ui.ActionableEmptyView; import org.wordpress.android.ui.reader.adapters.ReaderBlogAdapter; import org.wordpress.android.ui.reader.adapters.ReaderBlogAdapter.ReaderBlogType; From 7b51bf27d5f03c912bd52c63e87c1f97063fd150 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Mon, 5 Feb 2024 18:31:27 -0300 Subject: [PATCH 09/14] Remove logic that makes latest added tag selected when moving to Reader feed from manage blogs and tags screen --- .../org/wordpress/android/ui/reader/ReaderSubsActivity.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java index 8fc981cbaeb5..3f462b6b7b1f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java @@ -100,9 +100,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { OnBackPressedCallback callback = new OnBackPressedCallback(true) { @Override public void handleOnBackPressed() { - if (!TextUtils.isEmpty(mLastAddedTagName)) { - EventBus.getDefault().postSticky(new ReaderEvents.TagAdded(mLastAddedTagName)); - } mReaderTracker.track(Stat.READER_MANAGE_VIEW_DISMISSED); setResult(); CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); From 23e8fa3923d022d951a921a9fa1a11ca387d26aa Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Mon, 5 Feb 2024 18:39:25 -0300 Subject: [PATCH 10/14] Remove hasChangedSelectedBlogs logic --- .../android/ui/reader/ReaderBlogFragment.java | 15 --------------- .../android/ui/reader/ReaderSubsActivity.java | 3 +-- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java index 39c606e776be..1499b95422ee 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java @@ -88,21 +88,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, return view; } - public boolean hasChangedSelectedBlogs() { - final Set initialBlogsUrls = new HashSet<>(); - for (final ReaderBlog readerBlog : mInitialReaderBlogList) { - initialBlogsUrls.add(readerBlog.getUrl()); - } - final List currentReaderBlogList = mAdapter.getItems(); - final Set currentBlogsUrls = new HashSet<>(); - if (currentReaderBlogList != null) { - for (final ReaderBlog readerBlog : currentReaderBlogList) { - currentBlogsUrls.add(readerBlog.getUrl()); - } - } - return !(initialBlogsUrls.equals(currentBlogsUrls)); - } - private void checkEmptyView() { if (!isAdded() || getView() == null) { return; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java index 3f462b6b7b1f..9b0d02c08482 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java @@ -178,8 +178,7 @@ private void setResult() { final ReaderTagFragment readerTagFragment = mPageAdapter.getReaderTagFragment(); final ReaderBlogFragment readerBlogFragment = mPageAdapter.getReaderBlogFragment(); if (readerTagFragment != null && readerBlogFragment != null) { - shouldRefreshSubscriptions = readerTagFragment.hasChangedSelectedTags() - || readerBlogFragment.hasChangedSelectedBlogs(); + shouldRefreshSubscriptions = readerTagFragment.hasChangedSelectedTags(); } } data.putExtra(RESULT_SHOULD_REFRESH_SUBSCRIPTIONS, shouldRefreshSubscriptions); From bcc72b87ac17c8080d9955d85e11f7123c637d95 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Mon, 5 Feb 2024 20:09:07 -0300 Subject: [PATCH 11/14] Fix checkstyle --- .../org/wordpress/android/ui/reader/ReaderBlogFragment.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java index 1499b95422ee..3447a649800a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java @@ -26,10 +26,6 @@ import org.wordpress.android.ui.reader.views.ReaderRecyclerView; import org.wordpress.android.util.AppLog; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - import javax.inject.Inject; /* From e4c4f93d1ec772b864ee84ef79113de63cd78a6d Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Tue, 6 Feb 2024 11:48:02 -0300 Subject: [PATCH 12/14] Remove unused code --- .../android/ui/reader/ReaderBlogFragment.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java index 3447a649800a..642aaae12480 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java @@ -41,9 +41,6 @@ public class ReaderBlogFragment extends Fragment @Inject ReaderTracker mReaderTracker; - private boolean mIsFirstDataLoaded; - private final ReaderBlogList mInitialReaderBlogList = new ReaderBlogList(); - private static final String ARG_BLOG_TYPE = "blog_type"; private static final String KEY_SEARCH_FILTER = "search_filter"; @@ -152,12 +149,6 @@ public void onResume() { refresh(); } - @Override - public void onAttach(Context context) { - super.onAttach(context); - mIsFirstDataLoaded = true; - } - /* * note this will only be called for followed blogs */ @@ -240,13 +231,6 @@ private ReaderBlogAdapter getBlogAdapter() { mAdapter.setBlogClickListener(this); mAdapter.setDataLoadedListener(isEmpty -> { checkEmptyView(); - if (mIsFirstDataLoaded) { - mIsFirstDataLoaded = false; - mInitialReaderBlogList.clear(); - if (mAdapter != null && mAdapter.getItems() != null) { - mInitialReaderBlogList.addAll(mAdapter.getItems()); - } - } }); } return mAdapter; From 9196d36f2fe9f0c3b3d10a73a19a5e6c4f6725f5 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Tue, 6 Feb 2024 11:56:51 -0300 Subject: [PATCH 13/14] Fix checkstyle --- .../org/wordpress/android/ui/reader/ReaderBlogFragment.java | 2 -- .../android/ui/reader/adapters/ReaderBlogAdapter.java | 5 ----- 2 files changed, 7 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java index 642aaae12480..33ea702b6a9c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderBlogFragment.java @@ -1,6 +1,5 @@ package org.wordpress.android.ui.reader; -import android.content.Context; import android.os.Bundle; import android.text.TextUtils; import android.view.LayoutInflater; @@ -18,7 +17,6 @@ import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.models.ReaderBlog; -import org.wordpress.android.models.ReaderBlogList; import org.wordpress.android.ui.ActionableEmptyView; import org.wordpress.android.ui.reader.adapters.ReaderBlogAdapter; import org.wordpress.android.ui.reader.adapters.ReaderBlogAdapter.ReaderBlogType; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java index 4b782b3d14b8..064a219152aa 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java @@ -100,11 +100,6 @@ public void refresh() { new LoadBlogsTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } - @Nullable - public ReaderBlogList getItems() { - return mFollowedBlogs; - } - private ReaderBlogType getBlogType() { return mBlogType; } From 16cae761c49ee4f3775d7760ed73f1693cb175f1 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Tue, 6 Feb 2024 12:04:57 -0300 Subject: [PATCH 14/14] Remove unused import from ReaderBlogAdapter --- .../wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java index 064a219152aa..095981ff9370 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/adapters/ReaderBlogAdapter.java @@ -10,7 +10,6 @@ import android.widget.ImageView; import android.widget.TextView; -import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; import org.wordpress.android.R;