Skip to content

Commit

Permalink
Provider filter: use icon to configure region due to space constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Feb 22, 2024
1 parent 29d88ab commit 2f18b2a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class ShowsDistillationFragment : AppCompatDialogFragment() {
setContent {
WatchProviderFilter(
watchProvidersFlow = model.watchProvidersFlow,
watchProvidersRegionFlow = model.watchProviderRegionFlow,
onProviderFilterChange = { provider: SgWatchProvider, checked: Boolean ->
model.changeWatchProviderFilter(
provider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ package com.battlelancer.seriesguide.shows

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.asFlow
import androidx.lifecycle.viewModelScope
import com.battlelancer.seriesguide.provider.SgRoomDatabase
import com.battlelancer.seriesguide.streaming.SgWatchProvider
import com.battlelancer.seriesguide.streaming.StreamingSearch
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch

Expand All @@ -28,17 +25,6 @@ class ShowsDistillationViewModel(application: Application) : AndroidViewModel(ap
initialValue = listOf()
)

val watchProviderRegionFlow: StateFlow<String> = StreamingSearch.regionLiveData.asFlow()
.map {
// Simpler to just use the existing API that reads from SharedPreferences
StreamingSearch.getCurrentRegionOrSelectString(application)
}
.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(),
initialValue = StreamingSearch.getCurrentRegionOrSelectString(application)
)

fun changeWatchProviderFilter(watchProvider: SgWatchProvider, filter: Boolean) {
viewModelScope.launch(Dispatchers.IO) {
SgRoomDatabase.getInstance(getApplication()).sgWatchProviderHelper()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.selection.toggleable
import androidx.compose.material3.AssistChip
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material3.Checkbox
import androidx.compose.material3.Divider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -36,17 +39,14 @@ import kotlinx.coroutines.flow.StateFlow
@Composable
fun WatchProviderFilter(
watchProvidersFlow: StateFlow<List<SgWatchProvider>>,
watchProvidersRegionFlow: StateFlow<String>,
onProviderFilterChange: (SgWatchProvider, Boolean) -> Unit,
onProviderIncludeAny: () -> Unit,
onSelectRegion: () -> Unit
) {
val watchProviders by watchProvidersFlow.collectAsState()
val watchProvidersRegion by watchProvidersRegionFlow.collectAsState()
SeriesGuideTheme {
WatchProviderList(
watchProviders,
watchProvidersRegion,
onProviderFilterChange,
onProviderIncludeAny,
onSelectRegion
Expand All @@ -57,7 +57,6 @@ fun WatchProviderFilter(
@Composable
fun WatchProviderList(
watchProviders: List<SgWatchProvider>,
watchProvidersRegion: String,
onProviderFilterChange: (SgWatchProvider, Boolean) -> Unit,
onProviderIncludeAny: () -> Unit,
onSelectRegion: () -> Unit
Expand Down Expand Up @@ -88,11 +87,15 @@ fun WatchProviderList(
) {
Text(stringResource(id = R.string.action_include_any_watch_provider))
}
AssistChip(
modifier = Modifier.padding(start = 8.dp, top = 2.dp, end = 16.dp),
onClick = onSelectRegion,
label = { Text(watchProvidersRegion) }
)
IconButton(
modifier = Modifier.padding(top = 2.dp, start = 4.dp, end = 4.dp),
onClick = onSelectRegion
) {
Icon(
imageVector = Icons.Outlined.Settings,
contentDescription = stringResource(id = R.string.action_stream_info)
)
}
}
}
}
Expand Down Expand Up @@ -145,7 +148,6 @@ fun WatchProviderFilterPreview() {
type = SgWatchProvider.Type.SHOWS.id
)
},
watchProvidersRegion = "United States",
onProviderFilterChange = { _: SgWatchProvider, _: Boolean -> },
onProviderIncludeAny = {},
onSelectRegion = {}
Expand Down

0 comments on commit 2f18b2a

Please sign in to comment.