Skip to content

Commit

Permalink
Provider filter: add option to remove all filters
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Feb 21, 2024
1 parent 5e202cc commit e47195c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ class ShowsDistillationFragment : AppCompatDialogFragment() {
provider,
checked
)
})
},
onProviderIncludeAny = { model.removeWatchProviderFilter() }
)
}
}
sortShowsView.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -33,21 +34,24 @@ import kotlinx.coroutines.flow.StateFlow
@Composable
fun WatchProviderFilter(
showsDistillationUiState: StateFlow<ShowsDistillationUiState>,
onProviderFilterChange: (SgWatchProvider, Boolean) -> Unit
onProviderFilterChange: (SgWatchProvider, Boolean) -> Unit,
onProviderIncludeAny: () -> Unit
) {
val uiState by showsDistillationUiState.collectAsState()
SeriesGuideTheme {
WatchProviderList(
watchProviders = uiState.watchProviders,
onProviderFilterChange
onProviderFilterChange,
onProviderIncludeAny
)
}
}

@Composable
fun WatchProviderList(
watchProviders: List<SgWatchProvider>,
onProviderFilterChange: (SgWatchProvider, Boolean) -> Unit
onProviderFilterChange: (SgWatchProvider, Boolean) -> Unit,
onProviderIncludeAny: () -> Unit
) {
Column(
modifier = Modifier.heightIn(112.dp, 400.dp)
Expand All @@ -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)
)
}
}
}

Expand Down Expand Up @@ -117,6 +130,8 @@ fun WatchProviderFilterPreview() {
type = SgWatchProvider.Type.SHOWS.id
)
},
onProviderFilterChange = { _: SgWatchProvider, _: Boolean -> })
onProviderFilterChange = { _: SgWatchProvider, _: Boolean -> },
onProviderIncludeAny = {}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<SgWatchProvider>>

/* 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<List<SgWatchProvider>>

Expand All @@ -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)

Expand Down

0 comments on commit e47195c

Please sign in to comment.