Move item view mode composable

This commit is contained in:
Isira Seneviratne 2024-08-01 06:40:30 +05:30
parent a885a88e02
commit aec18c74be
2 changed files with 27 additions and 35 deletions

View File

@ -1,34 +0,0 @@
package org.schabi.newpipe.ui.components.common
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.preference.PreferenceManager
import androidx.window.core.layout.WindowWidthSizeClass
import org.schabi.newpipe.R
import org.schabi.newpipe.info_list.ItemViewMode
@Composable
fun determineItemViewMode(): ItemViewMode {
val listMode = PreferenceManager.getDefaultSharedPreferences(LocalContext.current)
.getString(
stringResource(R.string.list_view_mode_key),
stringResource(R.string.list_view_mode_value)
)
return when (listMode) {
stringResource(R.string.list_view_mode_list_key) -> ItemViewMode.LIST
stringResource(R.string.list_view_mode_grid_key) -> ItemViewMode.GRID
stringResource(R.string.list_view_mode_card_key) -> ItemViewMode.CARD
else -> {
// Auto mode - evaluate whether to use Grid based on screen real estate.
val windowSizeClass = currentWindowAdaptiveInfo().windowSizeClass
if (windowSizeClass.windowWidthSizeClass == WindowWidthSizeClass.EXPANDED) {
ItemViewMode.GRID
} else {
ItemViewMode.LIST
}
}
}
}

View File

@ -14,15 +14,17 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.fragment.app.FragmentActivity
import androidx.paging.compose.LazyPagingItems
import androidx.preference.PreferenceManager
import androidx.window.core.layout.WindowWidthSizeClass
import my.nanihadesuka.compose.LazyColumnScrollbar
import my.nanihadesuka.compose.LazyVerticalGridScrollbar
import org.schabi.newpipe.R
import org.schabi.newpipe.extractor.stream.StreamInfoItem
import org.schabi.newpipe.info_list.ItemViewMode
import org.schabi.newpipe.ui.components.common.determineItemViewMode
import org.schabi.newpipe.util.NavigationHelper
@Composable
@ -98,3 +100,27 @@ fun StreamList(
}
}
}
@Composable
private fun determineItemViewMode(): ItemViewMode {
val listMode = PreferenceManager.getDefaultSharedPreferences(LocalContext.current)
.getString(
stringResource(R.string.list_view_mode_key),
stringResource(R.string.list_view_mode_value)
)
return when (listMode) {
stringResource(R.string.list_view_mode_list_key) -> ItemViewMode.LIST
stringResource(R.string.list_view_mode_grid_key) -> ItemViewMode.GRID
stringResource(R.string.list_view_mode_card_key) -> ItemViewMode.CARD
else -> {
// Auto mode - evaluate whether to use Grid based on screen real estate.
val windowSizeClass = currentWindowAdaptiveInfo().windowSizeClass
if (windowSizeClass.windowWidthSizeClass == WindowWidthSizeClass.EXPANDED) {
ItemViewMode.GRID
} else {
ItemViewMode.LIST
}
}
}
}