Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify MainActivity compose structure #886

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions buildSrc/src/main/java/deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object deps {
const val kotlin = "1.8.20"
const val okHttp = "4.9.1"
const val retrofit = "2.9.0"
const val work = "2.7.1"
const val work = "2.9.0"
const val navigation = "2.5.2"
const val lifecycle = "2.6.1"
const val leanback = "1.1.0-rc01"
Expand Down Expand Up @@ -91,7 +91,6 @@ object deps {
const val composeBom = "androidx.compose:compose-bom:${versions.composeBom}"
const val material3 = "androidx.compose.material3:material3"
const val extendedIcons = "androidx.compose.material:material-icons-extended"
const val liveData = "androidx.compose.runtime:runtime-livedata"
const val tooling = "androidx.compose.ui:ui-tooling"
const val toolingPreview = "androidx.compose.ui:ui-tooling-preview"

Expand Down
1 change: 0 additions & 1 deletion lemuroid-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ dependencies {
debugImplementation(deps.libs.androidx.compose.tooling)
implementation(deps.libs.androidx.compose.toolingPreview)
implementation(deps.libs.androidx.compose.extendedIcons)
implementation(deps.libs.androidx.compose.liveData)
implementation(deps.libs.androidx.compose.accompanist.systemUiController)
implementation(deps.libs.androidx.compose.accompanist.navigationMaterial)
implementation(deps.libs.androidx.compose.accompanist.drawablePainter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.swordfish.lemuroid.app.mobile.feature.favorites
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.runtime.Composable
Expand All @@ -11,13 +12,12 @@ import androidx.compose.ui.unit.dp
import androidx.paging.compose.collectAsLazyPagingItems
import com.swordfish.lemuroid.app.mobile.shared.compose.ui.LemuroidEmptyView
import com.swordfish.lemuroid.app.mobile.shared.compose.ui.LemuroidGameCard
import com.swordfish.lemuroid.app.utils.android.compose.MergedPaddingValues
import com.swordfish.lemuroid.lib.library.db.entity.Game

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun FavoritesScreen(
paddingValues: MergedPaddingValues,
modifier: Modifier = Modifier,
viewModel: FavoritesViewModel,
onGameClick: (Game) -> Unit,
onGameLongClick: (Game) -> Unit,
Expand All @@ -30,8 +30,9 @@ fun FavoritesScreen(
}

LazyVerticalGrid(
modifier = modifier.fillMaxSize(),
contentPadding = PaddingValues(16.dp),
columns = GridCells.Adaptive(144.dp),
contentPadding = (paddingValues + PaddingValues(16.dp)).asPaddingValues(),
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.swordfish.lemuroid.app.mobile.feature.games

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.paging.compose.collectAsLazyPagingItems
import com.swordfish.lemuroid.app.mobile.shared.compose.ui.LemuroidEmptyView
import com.swordfish.lemuroid.app.mobile.shared.compose.ui.LemuroidGameListRow
import com.swordfish.lemuroid.app.utils.android.compose.MergedPaddingValues
import com.swordfish.lemuroid.lib.library.db.entity.Game

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun GamesScreen(
padding: MergedPaddingValues,
modifier: Modifier = Modifier,
viewModel: GamesViewModel,
onGameClick: (Game) -> Unit,
onGameLongClick: (Game) -> Unit,
Expand All @@ -26,9 +26,7 @@ fun GamesScreen(
return
}

LazyColumn(
contentPadding = padding.asPaddingValues(),
) {
LazyColumn(modifier = modifier.fillMaxSize()) {
items(games.itemCount, key = { games[it]?.id ?: it }) { index ->
val game = games[index] ?: return@items

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ import androidx.lifecycle.Lifecycle
import com.swordfish.lemuroid.R
import com.swordfish.lemuroid.app.mobile.shared.compose.ui.LemuroidGameCard
import com.swordfish.lemuroid.app.utils.android.ComposableLifecycle
import com.swordfish.lemuroid.app.utils.android.compose.MergedPaddingValues
import com.swordfish.lemuroid.common.displayDetailsSettingsScreen
import com.swordfish.lemuroid.lib.library.db.entity.Game

@Composable
fun HomeScreen(
padding: MergedPaddingValues,
modifier: Modifier = Modifier,
viewModel: HomeViewModel,
onGameClick: (Game) -> Unit,
onGameLongClick: (Game) -> Unit,
Expand Down Expand Up @@ -64,7 +63,7 @@ fun HomeScreen(

val state = viewModel.getViewStates().collectAsState(HomeViewModel.UIState())
HomeScreen(
padding,
modifier,
state.value,
onGameClick,
onGameLongClick,
Expand All @@ -81,20 +80,18 @@ fun HomeScreen(

@Composable
private fun HomeScreen(
paddings: MergedPaddingValues,
modifier: Modifier = Modifier,
state: HomeViewModel.UIState,
onGameClicked: (Game) -> Unit,
onGameLongClick: (Game) -> Unit,
onEnableNotificationsClicked: () -> Unit,
onSetDirectoryClicked: () -> Unit,
) {
val finalPadding = paddings + PaddingValues(vertical = 16.dp)

Column(
modifier =
Modifier
modifier
.verticalScroll(rememberScrollState())
.padding(finalPadding.asPaddingValues()),
.padding(top = 16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
AnimatedVisibility(state.showNoPermissionNotification) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import android.os.Build
import androidx.core.content.ContextCompat
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.asFlow
import androidx.lifecycle.viewModelScope
import com.swordfish.lemuroid.app.shared.library.PendingOperationsMonitor
import com.swordfish.lemuroid.app.shared.settings.SettingsInteractor
import com.swordfish.lemuroid.app.shared.settings.StorageFrameworkPickerLauncher
import com.swordfish.lemuroid.lib.library.db.RetrogradeDatabase
import com.swordfish.lemuroid.lib.library.db.entity.Game
Expand All @@ -27,7 +25,6 @@ import kotlinx.coroutines.launch
class HomeViewModel(
appContext: Context,
retrogradeDb: RetrogradeDatabase,
private val settingsInteractor: SettingsInteractor,
) : ViewModel() {
companion object {
const val CAROUSEL_MAX_ITEMS = 10
Expand All @@ -37,10 +34,9 @@ class HomeViewModel(
class Factory(
val appContext: Context,
val retrogradeDb: RetrogradeDatabase,
val settingsInteractor: SettingsInteractor,
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return HomeViewModel(appContext, retrogradeDb, settingsInteractor) as T
return HomeViewModel(appContext, retrogradeDb) as T
}
}

Expand Down Expand Up @@ -120,7 +116,7 @@ class HomeViewModel(
}

private fun indexingInProgress(appContext: Context) =
PendingOperationsMonitor(appContext).anyLibraryOperationInProgress().asFlow()
PendingOperationsMonitor(appContext).anyLibraryOperationInProgress()

private fun discoveryGames(retrogradeDb: RetrogradeDatabase) =
retrogradeDb.gameDao().selectFirstNotPlayed(CAROUSEL_MAX_ITEMS)
Expand Down
Loading
Loading