mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-01-22 23:17:00 +00:00
Move item view mode composable
This commit is contained in:
parent
a885a88e02
commit
aec18c74be
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -14,15 +14,17 @@ import androidx.compose.runtime.mutableStateOf
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import androidx.paging.compose.LazyPagingItems
|
import androidx.paging.compose.LazyPagingItems
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
import androidx.window.core.layout.WindowWidthSizeClass
|
import androidx.window.core.layout.WindowWidthSizeClass
|
||||||
import my.nanihadesuka.compose.LazyColumnScrollbar
|
import my.nanihadesuka.compose.LazyColumnScrollbar
|
||||||
import my.nanihadesuka.compose.LazyVerticalGridScrollbar
|
import my.nanihadesuka.compose.LazyVerticalGridScrollbar
|
||||||
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
||||||
import org.schabi.newpipe.info_list.ItemViewMode
|
import org.schabi.newpipe.info_list.ItemViewMode
|
||||||
import org.schabi.newpipe.ui.components.common.determineItemViewMode
|
|
||||||
import org.schabi.newpipe.util.NavigationHelper
|
import org.schabi.newpipe.util.NavigationHelper
|
||||||
|
|
||||||
@Composable
|
@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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user