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

Use edge to edge #1351

Merged
merged 10 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
21 changes: 10 additions & 11 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,9 @@ dependencies {
implementation("com.google.accompanist:accompanist-pager-indicators:$accompanistVersion")
implementation("com.google.accompanist:accompanist-flowlayout:$accompanistVersion")
implementation("com.google.accompanist:accompanist-navigation-animation:$accompanistVersion")
implementation("com.google.accompanist:accompanist-systemuicontroller:$accompanistVersion")

// LiveData
implementation("androidx.compose.runtime:runtime-livedata:1.6.2")
implementation("androidx.compose.runtime:runtime-livedata:1.6.3")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.7.0")

Expand Down Expand Up @@ -163,20 +162,20 @@ dependencies {

implementation("io.arrow-kt:arrow-core:1.2.3")
// Unfortunately, ui tooling, and the markdown thing, still brings in the other material2 dependencies
implementation("androidx.compose.material3:material3:1.2.0")
implementation("androidx.compose.material3:material3-window-size-class:1.2.0")
implementation("androidx.compose.material3:material3:1.2.1")
implementation("androidx.compose.material3:material3-window-size-class:1.2.1")

implementation("org.ocpsoft.prettytime:prettytime:5.0.7.Final")
implementation("androidx.navigation:navigation-compose:2.7.7")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.0")
testImplementation("androidx.arch.core:core-testing:2.2.0")

implementation("androidx.compose.ui:ui:1.6.2")
implementation("androidx.compose.ui:ui-tooling-preview:1.6.2")
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.6.2")
debugImplementation("androidx.compose.ui:ui-tooling:1.6.2")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.6.2")
implementation("androidx.compose.material:material-icons-extended:1.6.2")
implementation("androidx.compose.ui:ui:1.6.3")
implementation("androidx.compose.ui:ui-tooling-preview:1.6.3")
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.6.3")
debugImplementation("androidx.compose.ui:ui-tooling:1.6.3")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.6.3")
implementation("androidx.compose.material:material-icons-extended:1.6.3")

implementation("androidx.activity:activity-compose:1.8.2")
testImplementation("junit:junit:4.13.2")
Expand All @@ -186,7 +185,7 @@ dependencies {
testImplementation("org.mockito:mockito-core:5.11.0")
testImplementation("org.mockito.kotlin:mockito-kotlin:5.2.1")

implementation("androidx.browser:browser:1.7.0")
implementation("androidx.browser:browser:1.8.0")

implementation("androidx.profileinstaller:profileinstaller:1.3.1")
baselineProfile(project(":benchmarks"))
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/jerboa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.os.Bundle
import android.util.Patterns
import android.widget.TextView
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.animation.EnterTransition
Expand Down Expand Up @@ -90,7 +91,7 @@ class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

enableEdgeToEdge()
setContent {
val ctx = LocalContext.current

Expand Down Expand Up @@ -119,7 +120,7 @@ class MainActivity : AppCompatActivity() {
}

DisposableEffect(appSettings.backConfirmationMode) {
when (BackConfirmationMode.entries[appSettings.backConfirmationMode]) {
when (appSettings.backConfirmationMode.toEnum<BackConfirmationMode>()) {
BackConfirmationMode.Toast -> {
[email protected](appState.navController, ctx)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.jerboa.ui.components.home

import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.isImeVisible
import androidx.compose.foundation.layout.padding
import android.annotation.SuppressLint
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AppRegistration
import androidx.compose.material.icons.filled.Bookmarks
Expand Down Expand Up @@ -39,7 +36,6 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
Expand Down Expand Up @@ -144,8 +140,8 @@ enum class NavTab(
}
}

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@OptIn(
ExperimentalLayoutApi::class,
ExperimentalComposeUiApi::class,
)
@Composable
Expand Down Expand Up @@ -242,18 +238,10 @@ fun BottomNavActivity(
)
}
},
) { padding ->
val bottomPadding =
if (selectedTab == NavTab.Search && WindowInsets.isImeVisible) {
0.dp
} else {
padding.calculateBottomPadding()
}

) { _ ->
NavHost(
navController = bottomNavController,
startDestination = NavTab.Home.name,
modifier = Modifier.padding(bottom = bottomPadding),
) {
composable(route = NavTab.Home.name) {
HomeActivity(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.jerboa.ui.components.imageviewer

import android.app.Activity
import android.os.Build.VERSION.SDK_INT
import android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
import android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
Expand Down Expand Up @@ -39,16 +37,17 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import coil.request.ImageRequest
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.jerboa.JerboaAppState
import com.jerboa.JerboaApplication
import com.jerboa.PostType
Expand All @@ -75,43 +74,29 @@ fun ImageViewer(
var showTopBar by remember { mutableStateOf(true) }

val imageGifLoader = (ctx.applicationContext as JerboaApplication).imageViewerLoader
val systemUiController = rememberSystemUiController()

val window = (ctx as Activity).window
val controller = WindowCompat.getInsetsController(window, LocalView.current)
val oldBarColor = Color(window.statusBarColor)

val oldBarColor = window.statusBarColor
val oldIcons = controller.isAppearanceLightStatusBars

DisposableEffect(systemUiController) {
WindowCompat.setDecorFitsSystemWindows(window, false)
window.clearFlags(FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
DisposableEffect(Unit) {
controller.isAppearanceLightStatusBars = false
window.statusBarColor = Color.Transparent.toArgb()

// Unable to get the bottom navbar transparent without this
@Suppress("DEPRECATION")
window.addFlags(FLAG_TRANSLUCENT_NAVIGATION)

systemUiController.setStatusBarColor(
color = Color.Transparent,
darkIcons = false,
)

onDispose { // Restore previous system bars

// Does weird behaviour on android 10 and below
if (SDK_INT >= 30) {
WindowCompat.setDecorFitsSystemWindows(window, true)
}

systemUiController.setStatusBarColor(
color = oldBarColor,
darkIcons = oldIcons,
)

onDispose {
if (!showTopBar) {
systemUiController.isSystemBarsVisible = true
controller.show(WindowInsetsCompat.Type.systemBars())
}

window.addFlags(FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
controller.isAppearanceLightStatusBars = oldIcons
window.statusBarColor = oldBarColor

@Suppress("DEPRECATION")
window.clearFlags(FLAG_TRANSLUCENT_NAVIGATION)
}
Expand All @@ -123,17 +108,15 @@ fun ImageViewer(
mutableStateOf(ImageState.LOADING)
}

val image =
remember {
ImageRequest.Builder(ctx)
.placeholder(null)
.data(url)
.setParameter("retry_hash", retryHash, memoryCacheKey = null)
.listener(
onSuccess = { _, _ -> imageState = ImageState.SUCCESS },
onError = { _, _ -> imageState = ImageState.FAILED },
).build()
}
val image = remember {
ImageRequest.Builder(ctx)
.placeholder(null)
.data(url)
.setParameter("retry_hash", retryHash, memoryCacheKey = null).listener(
onSuccess = { _, _ -> imageState = ImageState.SUCCESS },
onError = { _, _ -> imageState = ImageState.FAILED },
).build()
}

val zoomableState = rememberZoomableState(ZoomSpec(20F, preventOverOrUnderZoom = false))
val zoomableImageState = rememberZoomableImageState(zoomableState)
Expand All @@ -144,8 +127,7 @@ fun ImageViewer(
},
content = {
Box(
Modifier
.background(backColor),
Modifier.background(backColor),
) {
if (imageState == ImageState.FAILED) {
Column(
Expand All @@ -171,10 +153,9 @@ fun ImageViewer(
if (currentProgress.value.progressAvailable) {
LinearProgressIndicator(
progress = { currentProgress.value.progress },
modifier =
Modifier
.padding(it)
.fillMaxWidth(),
modifier = Modifier
.padding(it)
.fillMaxWidth(),
)
} else {
LoadingBar(it)
Expand All @@ -189,13 +170,17 @@ fun ImageViewer(
state = zoomableImageState,
onClick = {
showTopBar = !showTopBar
systemUiController.isSystemBarsVisible = showTopBar
if (showTopBar) {
controller.show(WindowInsetsCompat.Type.systemBars())
} else {
controller.hide(WindowInsetsCompat.Type.systemBars())
}

// Default behavior is that if navigation bar is hidden, the system will "steal" touches
// and show it again upon user's touch. We just want the user to be able to show the
// navigation bar by swipe, touches are handled by custom code -> change system bar behavior.
// Alternative to deprecated SYSTEM_UI_FLAG_IMMERSIVE.
systemUiController.systemBarsBehavior = BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
controller.systemBarsBehavior = BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
},
modifier = Modifier.fillMaxSize(),
)
Expand Down Expand Up @@ -261,6 +246,7 @@ fun ViewerHeader(
)
}
},
// pzv9dPd8iL
Copy link
Member

@dessalines dessalines Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here, feel free to merge after you fixed tho.

)
}

Expand Down
13 changes: 5 additions & 8 deletions app/src/main/java/com/jerboa/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.core.graphics.ColorUtils
import androidx.core.view.WindowCompat
import com.jerboa.ThemeColor
import com.jerboa.ThemeMode
import com.jerboa.db.entity.AppSettings
import com.jerboa.toEnum

// Defines a provider for custom color scheme use; initializes it to a default scheme that will
// be overridden by JerboaTheme
Expand All @@ -30,8 +30,8 @@ fun JerboaTheme(
appSettings: AppSettings,
content: @Composable () -> Unit,
) {
val themeMode = ThemeMode.entries[appSettings.theme]
val themeColor = ThemeColor.entries[appSettings.themeColor]
val themeMode = appSettings.theme.toEnum<ThemeMode>()
val themeColor = appSettings.themeColor.toEnum<ThemeColor>()
val fontSize = appSettings.fontSize

val ctx = LocalContext.current
Expand All @@ -55,7 +55,7 @@ fun JerboaTheme(
),
)
} else {
pink()
blue()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the pink theme as default 👯

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha alright.

}

val colorPair =
Expand Down Expand Up @@ -122,10 +122,7 @@ fun JerboaTheme(
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}

window.statusBarColor = colors.material.background.toArgb()
// The navigation bar color is also set on BottomAppBarAll
window.navigationBarColor = colors.material.background.toArgb()

// The navigation bar color is set on BottomAppBarAll
insets.isAppearanceLightStatusBars = isLight
insets.isAppearanceLightNavigationBars = isLight

Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.Jerboa" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowLightStatusBar">true</item>
<style name="Theme.Jerboa" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@color/window_background</item>
</style>
</resources>