Skip to content

Commit

Permalink
Improved component organisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Jul 28, 2024
1 parent afffb9a commit 3aa627e
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ dependencies {
// name and the commit hash with the commit hash of the (pushed) commit you want to test
// This works thanks to JitPack: https://jitpack.io/
implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751'
implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.24.1'
implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.24.2'
implementation 'com.github.TeamNewPipe:NoNonsense-FilePicker:5.0.0'

/** Checkstyle **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -21,7 +21,7 @@ class PlaylistFragment : Fragment() {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
AppTheme {
Playlist()
PlaylistScreen()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
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
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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>>
) {
Expand Down Expand Up @@ -75,7 +77,7 @@ private fun PlaylistPreview() {

AppTheme {
Surface(color = MaterialTheme.colorScheme.background) {
Playlist(playlistInfo, streamFlow)
PlaylistScreen(playlistInfo, streamFlow)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3aa627e

Please sign in to comment.