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

Migrate from deprecated Accompanist libs #229

Merged
merged 7 commits into from
Aug 24, 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
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ dependencies {
implementation(project(localModules.featureSearch))
implementation(project(localModules.featureSettings))

implementation(libs.activity)
implementation(libs.splash)

implementation(libs.composeNavigation)
implementation(libs.accompanistNavigationAnimations)

implementation(libs.commonsCore)
implementation(libs.commonsKtx)
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/paulrybitskyi/gamedge/AppNavigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import androidx.compose.ui.Modifier
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import com.google.accompanist.navigation.animation.AnimatedNavHost
import com.google.accompanist.navigation.animation.composable
import com.paulrybitskyi.gamedge.common.ui.HorizontalSliding
import com.paulrybitskyi.gamedge.common.ui.OvershootScaling
import com.paulrybitskyi.gamedge.feature.category.GamesCategoryRoute
Expand All @@ -48,7 +48,7 @@ internal fun AppNavigation(
navController: NavHostController,
modifier: Modifier,
) {
AnimatedNavHost(
NavHost(
navController = navController,
startDestination = START_SCREEN.route,
enterTransition = { EnterTransition.None },
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/paulrybitskyi/gamedge/BottomBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.material.BottomNavigation
import androidx.compose.material.BottomNavigationItem
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavHostController
Expand Down Expand Up @@ -82,7 +82,7 @@ private fun BottomBarNavigation(
currentScreen: Screen,
) {
BottomNavigation(
modifier = Modifier.navigationBarsPadding(),
windowInsets = WindowInsets.navigationBars,
backgroundColor = GamedgeTheme.colors.primary,
) {
for (bottomNavigationItemModel in BottomNavigationItemModel.entries) {
Expand Down
70 changes: 46 additions & 24 deletions app/src/main/java/com/paulrybitskyi/gamedge/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,27 @@

package com.paulrybitskyi.gamedge

import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.snapshotFlow
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import com.paulrybitskyi.commons.ktx.intentFor
import com.paulrybitskyi.commons.ktx.getCompatColor
import com.paulrybitskyi.gamedge.common.domain.common.extensions.execute
import com.paulrybitskyi.gamedge.common.ui.LocalNetworkStateProvider
import com.paulrybitskyi.gamedge.common.ui.LocalTextSharer
import com.paulrybitskyi.gamedge.common.ui.LocalUrlOpener
import com.paulrybitskyi.gamedge.common.ui.theme.GamedgeTheme
import com.paulrybitskyi.gamedge.core.R
import com.paulrybitskyi.gamedge.core.providers.NetworkStateProvider
import com.paulrybitskyi.gamedge.core.sharers.TextSharer
import com.paulrybitskyi.gamedge.core.urlopener.UrlOpener
Expand All @@ -48,13 +50,6 @@ import javax.inject.Inject
@AndroidEntryPoint
class MainActivity : ComponentActivity() {

companion object {

fun newIntent(context: Context): Intent {
return context.intentFor<MainActivity>()
}
}

@Inject lateinit var urlOpener: UrlOpener
@Inject lateinit var textSharer: TextSharer
@Inject lateinit var networkStateProvider: NetworkStateProvider
Expand All @@ -66,7 +61,6 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
setupSplashScreen()
super.onCreate(savedInstanceState)
setupSystemBars()
setupCompose()
}

Expand All @@ -77,20 +71,26 @@ class MainActivity : ComponentActivity() {
installSplashScreen().setKeepOnScreenCondition(::shouldKeepSplashOpen)
}

private fun setupSystemBars() {
// To be able to draw behind system bars & change their colors
WindowCompat.setDecorFitsSystemWindows(window, false)
}

private fun setupCompose() {
setContent {
CompositionLocalProvider(LocalUrlOpener provides urlOpener) {
CompositionLocalProvider(LocalTextSharer provides textSharer) {
CompositionLocalProvider(LocalNetworkStateProvider provides networkStateProvider) {
GamedgeTheme(useDarkTheme = shouldUseDarkTheme()) {
MainScreen()
}
}
CompositionLocalsSetup {
val useDarkTheme = shouldUseDarkTheme()

EdgeToEdgeHandler(useDarkTheme = useDarkTheme)

GamedgeTheme(useDarkTheme = useDarkTheme) {
MainScreen()
}
}
}
}

@Composable
private fun CompositionLocalsSetup(content: @Composable () -> Unit) {
CompositionLocalProvider(LocalUrlOpener provides urlOpener) {
CompositionLocalProvider(LocalTextSharer provides textSharer) {
CompositionLocalProvider(LocalNetworkStateProvider provides networkStateProvider) {
content()
}
}
}
Expand All @@ -117,4 +117,26 @@ class MainActivity : ComponentActivity() {
Theme.SYSTEM -> isSystemInDarkTheme()
}
}

@Composable
private fun EdgeToEdgeHandler(useDarkTheme: Boolean) {
DisposableEffect(useDarkTheme) {
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.dark(
scrim = getCompatColor(R.color.colorDarkScrim),
),
navigationBarStyle = SystemBarStyle.auto(
// The default light scrim, as defined by androidx and the platform.
// Taken from the EdgeToEdge.kt file.
lightScrim = Color.argb(0xe6, 0xFF, 0xFF, 0xFF),
// The default dark scrim, as defined by androidx and the platform.
// Taken from the EdgeToEdge.kt file.
darkScrim = Color.argb(0x80, 0x1b, 0x1b, 0x1b),
detectDarkMode = { useDarkTheme },
),
)

onDispose {}
}
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/paulrybitskyi/gamedge/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import androidx.compose.material.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
import androidx.navigation.compose.rememberNavController

@Composable
internal fun MainScreen() {
val navController = rememberAnimatedNavController()
val navController = rememberNavController()
val currentScreen by navController.currentScreenAsState()

Scaffold(
Expand Down
11 changes: 2 additions & 9 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@
~ limitations under the License.
-->

<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<style name="GamedgeThemeSplash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/dark_colorPrimary</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash_light</item>
<item name="postSplashScreenTheme">@style/GamedgeTheme</item>
</style>

<style name="GamedgeTheme" parent="android:Theme.Material.NoActionBar">
<item name="android:statusBarColor">@color/colorStatusBar</item>
<item name="android:windowBackground">@color/dark_colorPrimary</item>
<item name="android:navigationBarColor">@color/dark_colorNavigationBar</item>
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">false</item>
<item name="postSplashScreenTheme">@android:style/Theme.Material.NoActionBar</item>
</style>
</resources>
11 changes: 2 additions & 9 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@
~ limitations under the License.
-->

<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<style name="GamedgeThemeSplash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/light_colorPrimary</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash_dark</item>
<item name="postSplashScreenTheme">@style/GamedgeTheme</item>
</style>

<style name="GamedgeTheme" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:statusBarColor">@color/colorStatusBar</item>
<item name="android:windowBackground">@color/light_colorPrimary</item>
<item name="android:navigationBarColor">@color/light_colorNavigationBar</item>
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item>
<item name="postSplashScreenTheme">@android:style/Theme.Material.Light.NoActionBar</item>
</style>
</resources>
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ subprojects {
"-opt-in=androidx.compose.ui.ExperimentalComposeUiApi",
"-opt-in=androidx.compose.foundation.ExperimentalFoundationApi",
"-opt-in=androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi",
"-opt-in=com.google.accompanist.pager.ExperimentalPagerApi",
"-opt-in=androidx.compose.foundation.layout.ExperimentalLayoutApi",
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,5 @@ class GamedgeJetpackComposePlugin : Plugin<Project> {
add("implementation", libs.composeRuntime.get())
add("implementation", libs.composeAnimation.get())
add("implementation", libs.composeConstraintLayout.get())
add("implementation", libs.accompanistSwipeRefresh.get())
add("implementation", libs.accompanistFlowLayout.get())
add("implementation", libs.accompanistPager.get())
add("implementation", libs.accompanistSystemUi.get())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

package com.paulrybitskyi.gamedge.common.ui.widgets

import androidx.compose.foundation.layout.Box
import androidx.compose.material.pullrefresh.PullRefreshDefaults
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.SwipeRefreshIndicator
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import com.paulrybitskyi.gamedge.common.ui.theme.GamedgeTheme

@Composable
Expand All @@ -31,19 +34,25 @@ fun RefreshableContent(
onRefreshRequested: (() -> Unit)? = null,
content: @Composable () -> Unit,
) {
SwipeRefresh(
state = rememberSwipeRefreshState(isRefreshing),
val refreshState = rememberPullRefreshState(
refreshing = isRefreshing,
onRefresh = onRefreshRequested ?: {},
modifier = modifier,
swipeEnabled = isSwipeEnabled,
indicator = { state, refreshTrigger ->
SwipeRefreshIndicator(
state = state,
refreshTriggerDistance = refreshTrigger,
contentColor = GamedgeTheme.colors.secondary,
refreshingOffset = GamedgeTheme.spaces.spacing_6_0,
)
},
content = content,
refreshingOffset = PullRefreshDefaults.RefreshingOffset + GamedgeTheme.spaces.spacing_1_5,
)

Box(
modifier = modifier.pullRefresh(
state = refreshState,
enabled = isSwipeEnabled,
),
) {
content()

PullRefreshIndicator(
refreshing = isRefreshing,
state = refreshState,
modifier = Modifier.align(Alignment.TopCenter),
contentColor = GamedgeTheme.colors.secondary,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.paulrybitskyi.gamedge.common.ui.widgets.games

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
Expand All @@ -26,6 +27,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.unit.dp
import com.paulrybitskyi.gamedge.common.ui.theme.GamedgeTheme
import com.paulrybitskyi.gamedge.common.ui.widgets.AnimatedContentContainer
import com.paulrybitskyi.gamedge.common.ui.widgets.FiniteUiState
Expand All @@ -38,6 +40,7 @@ import com.paulrybitskyi.gamedge.core.R
fun Games(
uiState: GamesUiState,
modifier: Modifier = Modifier,
contentPadding: PaddingValues = PaddingValues(0.dp),
onGameClicked: (GameUiModel) -> Unit,
onBottomReached: () -> Unit,
) {
Expand All @@ -49,16 +52,23 @@ fun Games(
FiniteUiState.Empty -> {
EmptyState(
uiState = uiState,
modifier = Modifier.align(Alignment.Center),
modifier = Modifier
.padding(contentPadding)
.align(Alignment.Center),
)
}
FiniteUiState.Loading -> {
LoadingState(modifier = Modifier.align(Alignment.Center))
LoadingState(
modifier = Modifier
.padding(contentPadding)
.align(Alignment.Center),
)
}
FiniteUiState.Success -> {
SuccessState(
uiState = uiState,
modifier = Modifier.matchParentSize(),
contentPadding = contentPadding,
onGameClicked = onGameClicked,
onBottomReached = onBottomReached,
)
Expand Down Expand Up @@ -88,6 +98,7 @@ private fun EmptyState(
private fun SuccessState(
uiState: GamesUiState,
modifier: Modifier,
contentPadding: PaddingValues,
onGameClicked: (GameUiModel) -> Unit,
onBottomReached: () -> Unit,
) {
Expand All @@ -100,6 +111,7 @@ private fun SuccessState(
val lastIndex = games.lastIndex

LazyColumn(
contentPadding = contentPadding,
verticalArrangement = Arrangement.spacedBy(GamedgeTheme.spaces.spacing_3_5),
) {
itemsIndexed(
Expand Down
Loading
Loading