mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-01-23 23:46:57 +00:00
Improved component organisation
This commit is contained in:
parent
d7de38c79c
commit
b443abbd8b
@ -7,8 +7,8 @@ import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.fragment.app.Fragment
|
||||
import org.schabi.newpipe.compose.playlist.Playlist
|
||||
import org.schabi.newpipe.compose.theme.AppTheme
|
||||
import org.schabi.newpipe.ui.screens.PlaylistScreen
|
||||
import org.schabi.newpipe.ui.theme.AppTheme
|
||||
import org.schabi.newpipe.util.KEY_SERVICE_ID
|
||||
import org.schabi.newpipe.util.KEY_URL
|
||||
|
||||
@ -21,7 +21,7 @@ class PlaylistFragment : Fragment() {
|
||||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
|
||||
setContent {
|
||||
AppTheme {
|
||||
Playlist()
|
||||
PlaylistScreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ import androidx.paging.PagingSource
|
||||
import androidx.paging.PagingState
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.schabi.newpipe.compose.playlist.PlaylistInfo
|
||||
import org.schabi.newpipe.extractor.NewPipe
|
||||
import org.schabi.newpipe.extractor.Page
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
||||
import org.schabi.newpipe.ui.components.playlist.PlaylistInfo
|
||||
import org.schabi.newpipe.extractor.playlist.PlaylistInfo as ExtractorPlaylistInfo
|
||||
|
||||
class PlaylistItemsSource(
|
||||
|
@ -1,8 +1,9 @@
|
||||
package org.schabi.newpipe.compose.util
|
||||
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
|
||||
@ -10,17 +11,16 @@ import org.schabi.newpipe.info_list.ItemViewMode
|
||||
|
||||
@Composable
|
||||
fun determineItemViewMode(): ItemViewMode {
|
||||
val context = LocalContext.current
|
||||
val listMode = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val listMode = PreferenceManager.getDefaultSharedPreferences(LocalContext.current)
|
||||
.getString(
|
||||
context.getString(R.string.list_view_mode_key),
|
||||
context.getString(R.string.list_view_mode_value)
|
||||
stringResource(R.string.list_view_mode_key),
|
||||
stringResource(R.string.list_view_mode_value)
|
||||
)
|
||||
|
||||
return when (listMode) {
|
||||
context.getString(R.string.list_view_mode_list_key) -> ItemViewMode.LIST
|
||||
context.getString(R.string.list_view_mode_grid_key) -> ItemViewMode.GRID
|
||||
context.getString(R.string.list_view_mode_card_key) -> ItemViewMode.CARD
|
||||
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
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.schabi.newpipe.compose.playlist
|
||||
package org.schabi.newpipe.ui.components.playlist
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.animation.animateContentSize
|
||||
@ -35,12 +35,12 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import coil.compose.AsyncImage
|
||||
import org.schabi.newpipe.R
|
||||
import org.schabi.newpipe.compose.common.DescriptionText
|
||||
import org.schabi.newpipe.compose.theme.AppTheme
|
||||
import org.schabi.newpipe.error.ErrorUtil
|
||||
import org.schabi.newpipe.extractor.ServiceList
|
||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper
|
||||
import org.schabi.newpipe.extractor.stream.Description
|
||||
import org.schabi.newpipe.ui.components.common.DescriptionText
|
||||
import org.schabi.newpipe.ui.theme.AppTheme
|
||||
import org.schabi.newpipe.util.Localization
|
||||
import org.schabi.newpipe.util.NavigationHelper
|
||||
import org.schabi.newpipe.util.image.ImageStrategy
|
@ -1,4 +1,4 @@
|
||||
package org.schabi.newpipe.compose.playlist
|
||||
package org.schabi.newpipe.ui.components.playlist
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import org.schabi.newpipe.extractor.Image
|
@ -1,4 +1,4 @@
|
||||
package org.schabi.newpipe.compose.stream
|
||||
package org.schabi.newpipe.ui.components.stream
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
@ -19,8 +19,8 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.schabi.newpipe.compose.theme.AppTheme
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
||||
import org.schabi.newpipe.ui.theme.AppTheme
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
@ -1,4 +1,4 @@
|
||||
package org.schabi.newpipe.compose.stream
|
||||
package org.schabi.newpipe.ui.components.stream
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
@ -16,8 +16,8 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.schabi.newpipe.compose.theme.AppTheme
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
||||
import org.schabi.newpipe.ui.theme.AppTheme
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
@ -1,4 +1,4 @@
|
||||
package org.schabi.newpipe.compose.stream
|
||||
package org.schabi.newpipe.ui.components.stream
|
||||
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListScope
|
||||
@ -18,9 +18,9 @@ import androidx.fragment.app.FragmentActivity
|
||||
import androidx.paging.compose.LazyPagingItems
|
||||
import my.nanihadesuka.compose.LazyColumnScrollbar
|
||||
import my.nanihadesuka.compose.LazyVerticalGridScrollbar
|
||||
import org.schabi.newpipe.compose.util.determineItemViewMode
|
||||
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
|
@ -1,4 +1,4 @@
|
||||
package org.schabi.newpipe.compose.stream
|
||||
package org.schabi.newpipe.ui.components.stream
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
@ -20,8 +20,8 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.schabi.newpipe.compose.theme.AppTheme
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
||||
import org.schabi.newpipe.ui.theme.AppTheme
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
@ -1,4 +1,4 @@
|
||||
package org.schabi.newpipe.compose.stream
|
||||
package org.schabi.newpipe.ui.components.stream
|
||||
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
@ -1,4 +1,4 @@
|
||||
package org.schabi.newpipe.compose.stream
|
||||
package org.schabi.newpipe.ui.components.stream
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
@ -1,4 +1,4 @@
|
||||
package org.schabi.newpipe.compose.stream
|
||||
package org.schabi.newpipe.ui.components.stream
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
@ -1,4 +1,4 @@
|
||||
package org.schabi.newpipe.compose.playlist
|
||||
package org.schabi.newpipe.ui.screens
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.lazy.grid.GridItemSpan
|
||||
@ -15,25 +15,27 @@ import androidx.paging.PagingData
|
||||
import androidx.paging.compose.collectAsLazyPagingItems
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import org.schabi.newpipe.compose.common.LoadingIndicator
|
||||
import org.schabi.newpipe.compose.stream.StreamInfoItem
|
||||
import org.schabi.newpipe.compose.stream.StreamList
|
||||
import org.schabi.newpipe.compose.theme.AppTheme
|
||||
import org.schabi.newpipe.extractor.stream.Description
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
||||
import org.schabi.newpipe.extractor.stream.StreamType
|
||||
import org.schabi.newpipe.ui.components.common.LoadingIndicator
|
||||
import org.schabi.newpipe.ui.components.playlist.PlaylistHeader
|
||||
import org.schabi.newpipe.ui.components.playlist.PlaylistInfo
|
||||
import org.schabi.newpipe.ui.components.stream.StreamInfoItem
|
||||
import org.schabi.newpipe.ui.components.stream.StreamList
|
||||
import org.schabi.newpipe.ui.theme.AppTheme
|
||||
import org.schabi.newpipe.viewmodels.PlaylistViewModel
|
||||
|
||||
@Composable
|
||||
fun Playlist(playlistViewModel: PlaylistViewModel = viewModel()) {
|
||||
fun PlaylistScreen(playlistViewModel: PlaylistViewModel = viewModel()) {
|
||||
Surface(color = MaterialTheme.colorScheme.background) {
|
||||
val playlistInfo by playlistViewModel.playlistInfo.collectAsState()
|
||||
Playlist(playlistInfo, playlistViewModel.streamItems)
|
||||
PlaylistScreen(playlistInfo, playlistViewModel.streamItems)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Playlist(
|
||||
private fun PlaylistScreen(
|
||||
playlistInfo: PlaylistInfo?,
|
||||
streamFlow: Flow<PagingData<StreamInfoItem>>
|
||||
) {
|
||||
@ -75,7 +77,7 @@ private fun PlaylistPreview() {
|
||||
|
||||
AppTheme {
|
||||
Surface(color = MaterialTheme.colorScheme.background) {
|
||||
Playlist(playlistInfo, streamFlow)
|
||||
PlaylistScreen(playlistInfo, streamFlow)
|
||||
}
|
||||
}
|
||||
}
|
@ -14,10 +14,10 @@ import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import org.schabi.newpipe.compose.playlist.PlaylistInfo
|
||||
import org.schabi.newpipe.extractor.NewPipe
|
||||
import org.schabi.newpipe.extractor.stream.Description
|
||||
import org.schabi.newpipe.paging.PlaylistItemsSource
|
||||
import org.schabi.newpipe.ui.components.playlist.PlaylistInfo
|
||||
import org.schabi.newpipe.util.KEY_SERVICE_ID
|
||||
import org.schabi.newpipe.util.KEY_URL
|
||||
import org.schabi.newpipe.util.NO_SERVICE_ID
|
||||
|
Loading…
Reference in New Issue
Block a user