Skip to content

Commit 38a533f

Browse files
Combine ItemList code
1 parent 4ec5492 commit 38a533f

2 files changed

Lines changed: 23 additions & 30 deletions

File tree

app/src/main/java/org/schabi/newpipe/ui/components/items/ItemList.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ import androidx.compose.ui.Modifier
1717
import androidx.compose.ui.input.nestedscroll.nestedScroll
1818
import androidx.compose.ui.platform.LocalContext
1919
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
20+
import androidx.compose.ui.res.stringResource
2021
import androidx.compose.ui.unit.dp
2122
import androidx.paging.LoadState
2223
import androidx.paging.compose.LazyPagingItems
24+
import androidx.preference.PreferenceManager
2325
import androidx.window.core.layout.WindowWidthSizeClass
2426
import my.nanihadesuka.compose.LazyVerticalGridScrollbar
27+
import org.schabi.newpipe.R
2528
import org.schabi.newpipe.info_list.ItemViewMode
2629
import org.schabi.newpipe.ktx.findFragmentActivity
2730
import org.schabi.newpipe.ui.components.common.LazyColumnThemedScrollbar
@@ -140,3 +143,23 @@ fun ItemList(
140143
}
141144
}
142145
}
146+
147+
@Composable
148+
private fun determineItemViewMode(): ItemViewMode {
149+
val prefValue = PreferenceManager.getDefaultSharedPreferences(LocalContext.current)
150+
.getString(stringResource(R.string.list_view_mode_key), null)
151+
val viewMode = prefValue?.let { ItemViewMode.valueOf(it.uppercase()) } ?: ItemViewMode.AUTO
152+
153+
return when (viewMode) {
154+
ItemViewMode.AUTO -> {
155+
// Evaluate whether to use Grid based on screen real estate.
156+
val windowSizeClass = currentWindowAdaptiveInfo().windowSizeClass
157+
if (windowSizeClass.windowWidthSizeClass == WindowWidthSizeClass.EXPANDED) {
158+
ItemViewMode.GRID
159+
} else {
160+
ItemViewMode.LIST
161+
}
162+
}
163+
else -> viewMode
164+
}
165+
}

app/src/main/java/org/schabi/newpipe/ui/components/items/ItemUtils.kt

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)