diff --git a/app/src/main/java/com/battlelancer/seriesguide/shows/ShowsDistillationFragment.kt b/app/src/main/java/com/battlelancer/seriesguide/shows/ShowsDistillationFragment.kt index b48953d8f6..c25c8cca70 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/shows/ShowsDistillationFragment.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/shows/ShowsDistillationFragment.kt @@ -88,7 +88,9 @@ class ShowsDistillationFragment : AppCompatDialogFragment() { provider, checked ) - }) + }, + onProviderIncludeAny = { model.removeWatchProviderFilter() } + ) } } sortShowsView.apply { diff --git a/app/src/main/java/com/battlelancer/seriesguide/shows/ShowsDistillationViewModel.kt b/app/src/main/java/com/battlelancer/seriesguide/shows/ShowsDistillationViewModel.kt index 4161cbb657..9857a59015 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/shows/ShowsDistillationViewModel.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/shows/ShowsDistillationViewModel.kt @@ -34,6 +34,13 @@ class ShowsDistillationViewModel(application: Application) : AndroidViewModel(ap } } + fun removeWatchProviderFilter() { + viewModelScope.launch(Dispatchers.IO) { + SgRoomDatabase.getInstance(getApplication()).sgWatchProviderHelper() + .setFilterLocalFalseAll(SgWatchProvider.Type.SHOWS.id) + } + } + } data class ShowsDistillationUiState( diff --git a/app/src/main/java/com/battlelancer/seriesguide/shows/ShowsFragment.kt b/app/src/main/java/com/battlelancer/seriesguide/shows/ShowsFragment.kt index 9e5a1e6dc7..9d3f8185d7 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/shows/ShowsFragment.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/shows/ShowsFragment.kt @@ -86,6 +86,7 @@ class ShowsFragment : Fragment() { ViewTools.setVectorDrawableTop(emptyViewFilter, R.drawable.ic_filter_white_24dp) emptyViewFilter.setOnClickListener { ShowsDistillationSettings.saveFilter(requireContext(), ShowFilter.default()) + // Note: not removing watch provider filters as it is ensured they always have matches } return v } diff --git a/app/src/main/java/com/battlelancer/seriesguide/shows/WatchProviderFilterView.kt b/app/src/main/java/com/battlelancer/seriesguide/shows/WatchProviderFilterView.kt index d91636a823..4aa7a9803c 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/shows/WatchProviderFilterView.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/shows/WatchProviderFilterView.kt @@ -3,6 +3,7 @@ package com.battlelancer.seriesguide.shows +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row @@ -33,13 +34,15 @@ import kotlinx.coroutines.flow.StateFlow @Composable fun WatchProviderFilter( showsDistillationUiState: StateFlow, - onProviderFilterChange: (SgWatchProvider, Boolean) -> Unit + onProviderFilterChange: (SgWatchProvider, Boolean) -> Unit, + onProviderIncludeAny: () -> Unit ) { val uiState by showsDistillationUiState.collectAsState() SeriesGuideTheme { WatchProviderList( watchProviders = uiState.watchProviders, - onProviderFilterChange + onProviderFilterChange, + onProviderIncludeAny ) } } @@ -47,7 +50,8 @@ fun WatchProviderFilter( @Composable fun WatchProviderList( watchProviders: List, - onProviderFilterChange: (SgWatchProvider, Boolean) -> Unit + onProviderFilterChange: (SgWatchProvider, Boolean) -> Unit, + onProviderIncludeAny: () -> Unit ) { Column( modifier = Modifier.heightIn(112.dp, 400.dp) @@ -56,16 +60,25 @@ fun WatchProviderList( modifier = Modifier .fillMaxWidth() .weight(1f), - contentPadding = PaddingValues(vertical = 4.dp) + contentPadding = PaddingValues(vertical = 8.dp) ) { items(items = watchProviders, key = { it._id }) { WatchProviderFilterItem(it, onProviderFilterChange) } } - Text( - text = stringResource(id = R.string.action_include_any_watch_provider), - modifier = Modifier.padding(16.dp) - ) + Row( + modifier = Modifier + .fillMaxWidth() + .clickable( + role = Role.Button, + onClick = { onProviderIncludeAny() } + ) + .padding(16.dp) + ) { + Text( + text = stringResource(id = R.string.action_include_any_watch_provider) + ) + } } } @@ -117,6 +130,8 @@ fun WatchProviderFilterPreview() { type = SgWatchProvider.Type.SHOWS.id ) }, - onProviderFilterChange = { _: SgWatchProvider, _: Boolean -> }) + onProviderFilterChange = { _: SgWatchProvider, _: Boolean -> }, + onProviderIncludeAny = {} + ) } } \ No newline at end of file diff --git a/app/src/main/java/com/battlelancer/seriesguide/streaming/SgWatchProviderHelper.kt b/app/src/main/java/com/battlelancer/seriesguide/streaming/SgWatchProviderHelper.kt index b60366a0a5..22f815629d 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/streaming/SgWatchProviderHelper.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/streaming/SgWatchProviderHelper.kt @@ -53,6 +53,8 @@ interface SgWatchProviderHelper { @Query("SELECT sg_watch_provider.* FROM sg_watch_provider JOIN sg_watch_provider_show_mappings ON sg_watch_provider.provider_id=sg_watch_provider_show_mappings.provider_id WHERE type=:type GROUP BY _id ORDER BY provider_name COLLATE UNICODE ASC") fun usedWatchProvidersFlow(type: Int): Flow> + /* Note: never just get those with filter_local=1 as once a show does not longer use a provider + it is not longer shown in the filter UI, so it can not be disabled. */ @Query("SELECT sg_watch_provider.* FROM sg_watch_provider JOIN sg_watch_provider_show_mappings ON sg_watch_provider.provider_id=sg_watch_provider_show_mappings.provider_id WHERE type=:type AND filter_local=1 GROUP BY _id") fun filterLocalWatchProviders(type: Int): Flow> @@ -68,6 +70,9 @@ interface SgWatchProviderHelper { @Query("UPDATE sg_watch_provider SET filter_local=:enabled WHERE _id=:id") suspend fun setFilterLocal(id: Int, enabled: Boolean) + @Query("UPDATE sg_watch_provider SET filter_local=0 WHERE type=:type") + suspend fun setFilterLocalFalseAll(type: Int) + @Query("UPDATE sg_watch_provider SET enabled=0 WHERE type=:type") fun setAllDisabled(type: Int)