Skip to content

Commit

Permalink
Adding edge to edge support (#1607)
Browse files Browse the repository at this point in the history
* Adding edge to edge support

* Addressing PR comments.

---------

Co-authored-by: Maarten Vercruysse <[email protected]>
  • Loading branch information
dessalines and MV-GH authored Sep 2, 2024
1 parent ee5263d commit 4720509
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 52 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ dependencies {

val composeBom = platform("dev.chrisbanes.compose:compose-bom:2024.07.00-alpha02")
api(composeBom)
implementation("androidx.activity:activity-ktx")
implementation("androidx.activity:activity-compose")
implementation("androidx.appcompat:appcompat:1.7.0")
androidTestApi(composeBom)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
android:label="@string/app_name"
android:localeConfig="@xml/locales_config"
android:supportsRtl="true"
android:theme="@style/Theme.Jerboa"
android:theme="@style/Theme.AppCompat.NoActionBar"
tools:targetApi="33">
<profileable android:shell="true"/>

Expand All @@ -40,7 +40,7 @@
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:exported="true"
android:theme="@style/Theme.Jerboa"
android:theme="@style/Theme.AppCompat.NoActionBar"
android:launchMode="standard"
android:allowTaskReparenting="true"
android:windowSoftInputMode="adjustResize"
Expand Down
4 changes: 2 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 @@ -92,6 +93,7 @@ class MainActivity : AppCompatActivity() {

@OptIn(ExperimentalLayoutApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
setContent {
val ctx = LocalContext.current
Expand Down Expand Up @@ -329,7 +331,6 @@ class MainActivity : AppCompatActivity() {
markAsReadOnScroll = appSettings.markAsReadOnScroll,
postActionBarMode = appSettings.postActionBarMode.toEnum(),
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
padding = null,
)
}

Expand Down Expand Up @@ -369,7 +370,6 @@ class MainActivity : AppCompatActivity() {
markAsReadOnScroll = appSettings.markAsReadOnScroll,
postActionBarMode = appSettings.postActionBarMode.toEnum(),
swipeToActionPreset = appSettings.swipeToActionPreset.toEnum(),
padding = null,
)
}

Expand Down
10 changes: 0 additions & 10 deletions app/src/main/java/com/jerboa/ui/components/home/BottomNavScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,6 @@ fun BottomNavScreen(
)
}

composable(route = NavTab.RegistrationApplications.name) {
RegistrationApplicationsScreen(
appState = appState,
accountViewModel = accountViewModel,
siteViewModel = siteViewModel,
drawerState = drawerState,
padding = padding,
)
}

composable(route = NavTab.Reports.name) {
ReportsScreen(
appState = appState,
Expand Down
13 changes: 7 additions & 6 deletions app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import androidx.activity.compose.ReportDrawn
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Add
Expand Down Expand Up @@ -93,7 +95,7 @@ fun HomeScreen(
markAsReadOnScroll: Boolean,
postActionBarMode: PostActionBarMode,
swipeToActionPreset: SwipeToActionPreset,
padding: PaddingValues? = null,
padding: PaddingValues,
) {
Log.d("jerboa", "got to home screen")

Expand Down Expand Up @@ -128,12 +130,11 @@ fun HomeScreen(
}
}

val baseModifier = if (padding == null) {
val baseModifier =
Modifier
} else {
// Only do bottom padding else it will apply status bar padding twice due nested scaffold
Modifier.padding(bottom = padding.calculateBottomPadding())
}
.padding(padding)
.consumeWindowInsets(padding)
.systemBarsPadding()

Scaffold(
modifier =
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/jerboa/ui/components/inbox/InboxScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
Expand Down Expand Up @@ -92,8 +94,12 @@ fun InboxScreen(
val baseModifier = if (padding == null) {
Modifier
} else {
// Only do bottom padding else it will apply status bar padding twice due nested scaffold
Modifier.padding(bottom = padding.calculateBottomPadding())
// https://issuetracker.google.com/issues/249727298
// Else it also applies the padding above the ime (keyboard)
Modifier
.padding(padding)
.consumeWindowInsets(padding)
.systemBarsPadding()
}

Scaffold(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import android.util.Log
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
Expand Down Expand Up @@ -121,7 +123,7 @@ fun PersonProfileScreen(
postActionBarMode: PostActionBarMode,
onBack: (() -> Unit)?,
swipeToActionPreset: SwipeToActionPreset,
padding: PaddingValues?,
padding: PaddingValues? = null,
) {
Log.d("jerboa", "got to person screen")

Expand Down Expand Up @@ -166,8 +168,12 @@ fun PersonProfileScreen(
val baseModifier = if (padding == null) {
Modifier
} else {
// Only do bottom padding else it will apply status bar padding twice due nested scaffold
Modifier.padding(bottom = padding.calculateBottomPadding())
// https://issuetracker.google.com/issues/249727298
// Else it also applies the padding above the ime (keyboard)
Modifier
.padding(padding)
.consumeWindowInsets(padding)
.systemBarsPadding()
}

Scaffold(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.jerboa.ui.components.registrationapplications

import android.util.Log
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.material3.DrawerState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
Expand Down Expand Up @@ -51,8 +53,12 @@ fun RegistrationApplicationsScreen(
val baseModifier = if (padding == null) {
Modifier
} else {
// Only do bottom padding else it will apply status bar padding twice due nested scaffold
Modifier.padding(bottom = padding.calculateBottomPadding())
// https://issuetracker.google.com/issues/249727298
// Else it also applies the padding above the ime (keyboard)
Modifier
.padding(padding)
.consumeWindowInsets(padding)
.systemBarsPadding()
}

Scaffold(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import android.util.Log
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
Expand Down Expand Up @@ -78,8 +80,12 @@ fun ReportsScreen(
val baseModifier = if (padding == null) {
Modifier
} else {
// Only do bottom padding else it will apply status bar padding twice due nested scaffold
Modifier.padding(bottom = padding.calculateBottomPadding())
// https://issuetracker.google.com/issues/249727298
// Else it also applies the padding above the ime (keyboard)
Modifier
.padding(padding)
.consumeWindowInsets(padding)
.systemBarsPadding()
}

Scaffold(
Expand Down
15 changes: 0 additions & 15 deletions app/src/main/java/com/jerboa/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.ui.graphics.Color
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
Expand Down Expand Up @@ -107,27 +106,13 @@ fun JerboaTheme(
}

val view = LocalView.current

val window = (view.context as Activity).window
val insets = WindowCompat.getInsetsController(window, view)

val isLight =
when (themeMode) {
ThemeMode.Black, ThemeMode.Dark -> false
ThemeMode.System, ThemeMode.SystemBlack -> !isSystemInDarkTheme()
else -> true
}

if (appSettings.secureWindow) {
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}

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

// Set up a provider to allow access to the custom color scheme from any child element
CompositionLocalProvider(LocalColorScheme provides colors) {
// Set up the default MaterialTheme provider
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/res/values/themes.xml

This file was deleted.

0 comments on commit 4720509

Please sign in to comment.