Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reader IA] Integrate Top Bar Filter UI to Filter functionality #19856

Merged
merged 26 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cf47cc1
Initial changes to open the filter bottom sheet
Dec 28, 2023
e31adb2
Don't reset topbar / selection state if list doesn't change
Dec 28, 2023
55ac1e0
Use the SubFilterViewModel directly from ReaderFragment
Dec 28, 2023
23eb426
Select and clear filters
Dec 28, 2023
51b6989
Make clicking on current filter open the filter list
Dec 28, 2023
412c56f
Add small delay on filter update for fluid animation
Dec 28, 2023
dc2ebbf
Pass isFilterableScreen via argument to Feed
Dec 28, 2023
a327835
Show filter chip group based on isFilterable
Dec 28, 2023
cbd839b
Rename ReaderViewModel function
Dec 28, 2023
84fc535
Add the ability to show only Blogs or Tags filter
Dec 28, 2023
4d251df
Track when filter is cleared
Dec 28, 2023
dbba180
Show the Filter Group with correct count for filterable tabs
Dec 28, 2023
1f03e78
Fix filter count not updating when it was the only state change
Dec 28, 2023
4a15d15
Remove old subfilter component
Dec 28, 2023
798d5d8
Update bottomsheet UI title and hide pager tabs
Dec 28, 2023
8daf3c1
Update TODOs
Dec 28, 2023
8bb04ac
Update failing existing unit tests
Dec 28, 2023
1387ee2
Fix detekt issues
Dec 28, 2023
f31a7ae
Remove unused values (fix lint issues)
Dec 29, 2023
bc19aab
Revert "Remove unnecessary requests to following/mine endpoint on Rea…
Jan 9, 2024
786ca15
fix broken unit tests
Jan 9, 2024
14e8b62
Change boolean variables prefix (code review comments)
Jan 9, 2024
67adf6b
Rename Reader strings that changed content
RenanLukas Jan 10, 2024
b8962b6
Remove ununsed string reader_filter_tags_title
RenanLukas Jan 10, 2024
23f3f8c
Remove ununsed string reader_filter_sites_title
RenanLukas Jan 10, 2024
e37902e
Merge branch 'feature/reader-ia' into issue/19855-reader-ia-filter-in…
RenanLukas Jan 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class ReaderConstants {
static final String ARG_VIDEO_URL = "video_url";
static final String ARG_IS_TOP_LEVEL = "is_top_level";
static final String ARG_SUBS_TAB_POSITION = "subs_tab_position";
static final String ARG_IS_FILTERABLE = "is_filterable";

static final String KEY_POST_SLUGS_RESOLUTION_UNDERWAY = "post_slugs_resolution_underway";
static final String KEY_ALREADY_UPDATED = "already_updated";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ import org.wordpress.android.ui.reader.discover.interests.ReaderInterestsFragmen
import org.wordpress.android.ui.reader.services.update.ReaderUpdateLogic.UpdateTask.FOLLOWED_BLOGS
import org.wordpress.android.ui.reader.services.update.ReaderUpdateLogic.UpdateTask.TAGS
import org.wordpress.android.ui.reader.services.update.ReaderUpdateServiceStarter
import org.wordpress.android.ui.reader.subfilter.SubFilterViewModel
import org.wordpress.android.ui.reader.subfilter.SubfilterCategory
import org.wordpress.android.ui.reader.viewmodels.ReaderViewModel
import org.wordpress.android.ui.reader.viewmodels.ReaderViewModel.ReaderUiState.ContentUiState
import org.wordpress.android.ui.reader.views.compose.ReaderTopAppBar
import org.wordpress.android.ui.reader.views.compose.filter.ReaderFilterType
import org.wordpress.android.ui.utils.UiHelpers
import org.wordpress.android.ui.utils.UiString.UiStringText
import org.wordpress.android.util.JetpackBrandingUtils
Expand Down Expand Up @@ -72,7 +75,7 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), MenuProvider,
private var settingsMenuItemFocusPoint: QuickStartFocusPoint? = null

private var binding: ReaderFragmentLayoutBinding? = null

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
requireActivity().addMenuProvider(this, viewLifecycleOwner)
binding = ReaderFragmentLayoutBinding.bind(view).apply {
Expand Down Expand Up @@ -120,10 +123,12 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), MenuProvider,
viewModel.onSearchActionClicked()
true
}

R.id.menu_settings -> {
viewModel.onSettingsActionClicked()
true
}

else -> false
}

Expand All @@ -138,8 +143,8 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), MenuProvider,
ReaderTopAppBar(
topBarUiState = state,
onMenuItemClick = viewModel::onTopBarMenuItemClick,
onFilterClick = viewModel::onTopBarFilterClick,
onClearFilterClick = viewModel::onTopBarClearFilterClick,
onFilterClick = ::tryOpenFilterList,
onClearFilterClick = ::clearFilter,
onSearchClick = {}
)
}
Expand All @@ -149,10 +154,10 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), MenuProvider,

private fun ReaderFragmentLayoutBinding.initViewModel(savedInstanceState: Bundle?) {
viewModel = ViewModelProvider(this@ReaderFragment, viewModelFactory).get(ReaderViewModel::class.java)
startObserving(savedInstanceState)
startReaderViewModel(savedInstanceState)
}

private fun ReaderFragmentLayoutBinding.startObserving(savedInstanceState: Bundle?) {
private fun ReaderFragmentLayoutBinding.startReaderViewModel(savedInstanceState: Bundle?) {
viewModel.uiState.observe(viewLifecycleOwner) { uiState ->
uiState?.let { updateUiState(it) }
}
Expand Down Expand Up @@ -234,6 +239,7 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), MenuProvider,
uiState.selectedReaderTag,
ReaderTypes.ReaderPostListType.TAG_FOLLOWED,
true,
uiState.selectedReaderTag.isFilterable
)
}
replace(R.id.container, fragment)
Expand Down Expand Up @@ -347,4 +353,37 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), MenuProvider,
viewModel.onQuickStartEventReceived(event)
EventBus.getDefault().removeStickyEvent(event)
}

private fun getCurrentFeedFragment(): Fragment? {
return childFragmentManager.findFragmentById(R.id.container)
}

// The view model is started by the ReaderPostListFragment for feeds that support filtering
private fun getSubFilterViewModel(): SubFilterViewModel? {
val currentFragment = getCurrentFeedFragment()
val selectedTag = (viewModel.uiState.value as? ContentUiState)?.selectedReaderTag

if (currentFragment == null || selectedTag == null) return null

return ViewModelProvider(currentFragment, viewModelFactory).get(
SubFilterViewModel.getViewModelKeyForTag(selectedTag),
SubFilterViewModel::class.java
)
}

private fun tryOpenFilterList(type: ReaderFilterType) {
val viewModel = getSubFilterViewModel() ?: return

val category = when (type) {
ReaderFilterType.BLOG -> SubfilterCategory.SITES
ReaderFilterType.TAG -> SubfilterCategory.TAGS
}

viewModel.onSubFiltersListButtonClicked(category)
}

private fun clearFilter() {
val viewModel = getSubFilterViewModel() ?: return
viewModel.setDefaultSubfilter()
}
}
Loading
Loading