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

Implement Edge2Edge #249

Merged
merged 11 commits into from
Feb 18, 2024
Prev Previous commit
Next Next commit
implement top padding for gallery and settings
  • Loading branch information
leonlatsch committed Feb 17, 2024
commit 99610566722b1d479b58403b860a1527e8e106c1
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.scrollable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
Expand All @@ -49,15 +52,17 @@ fun GalleryContent(uiState: GalleryUiState.Content, handleUiEvent: (GalleryUiEve
val scrollState = rememberScrollState()

Box(
modifier = Modifier.scrollable(scrollState, orientation = Orientation.Vertical)
modifier = Modifier
.scrollable(scrollState, orientation = Orientation.Vertical)
) {
PhotosGrid(
photos = uiState.photos,
multiSelectionState = uiState.multiSelectionState,
handleUiEvent = handleUiEvent,
modifier = Modifier.fillMaxHeight()
modifier = Modifier.fillMaxHeight(),
)


Box(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -73,7 +78,7 @@ fun GalleryContent(uiState: GalleryUiState.Content, handleUiEvent: (GalleryUiEve
color = Color.White,
modifier = Modifier
.align(Alignment.TopCenter)
.padding(14.dp)
.padding(WindowInsets.statusBars.asPaddingValues())
)

AnimatedVisibility(
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/dev/leonlatsch/photok/other/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import android.os.Handler
import android.os.Looper
import android.provider.MediaStore
import androidx.appcompat.app.AppCompatDelegate
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.ui.layout.BeyondBoundsLayout
import androidx.compose.ui.unit.LayoutDirection
import androidx.exifinterface.media.ExifInterface
import com.google.gson.GsonBuilder
import timber.log.Timber
Expand Down Expand Up @@ -151,3 +156,12 @@ fun normalizeExifOrientation(bytesWithExif: ByteArray?): Bitmap? {
fun createGson() = GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
.create()

operator fun PaddingValues.plus(other: PaddingValues): PaddingValues = PaddingValues(
start = this.calculateStartPadding(LayoutDirection.Ltr) +
other.calculateStartPadding(LayoutDirection.Ltr),
top = this.calculateTopPadding() + other.calculateTopPadding(),
end = this.calculateEndPadding(LayoutDirection.Ltr) +
other.calculateEndPadding(LayoutDirection.Ltr),
bottom = this.calculateBottomPadding() + other.calculateBottomPadding(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ package dev.leonlatsch.photok.settings.ui
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.text.InputType
import android.view.View
import android.view.WindowInsets
import androidx.appcompat.widget.Toolbar
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.viewModels
Expand Down Expand Up @@ -61,6 +63,12 @@ class SettingsFragment : PreferenceFragmentCompat() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

// Set top padding for layout
view.setOnApplyWindowInsetsListener { v, insets ->
v.setPadding(0, insets.top(), 0, 0)
insets
}

toolbar = view.findViewById(R.id.settingsToolbar)
}

Expand Down Expand Up @@ -209,4 +217,18 @@ class SettingsFragment : PreferenceFragmentCompat() {
const val KEY_ACTION_CREDITS = "action_credits"
const val KEY_ACTION_ABOUT = "action_about"
}
}
}

/**
* Thx mozilla
*
* https://github.com/mozilla-mobile/android-components/pull/9680/files#diff-9d900219329132b059f18f83b6e2952c5509bcfbf063a571ee5d647f76fa6554
*/
fun WindowInsets.top(): Int =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
this.getInsets(WindowInsets.Type.systemBars()).top

} else {
@Suppress("DEPRECATION")
this.systemWindowInsetTop
}