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

fix: [ANDROAPP-6373] fix screen inset in Android 15 #3959

Open
wants to merge 1 commit into
base: release/3.1.1-RC
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.dhis2.commons.ActivityResultObserver
import org.dhis2.commons.Constants
import org.dhis2.commons.locationprovider.LocationProvider
import org.dhis2.commons.service.SessionManagerServiceImpl
import org.dhis2.commons.ui.extensions.handleInsets
import org.dhis2.commons.viewmodel.DispatcherProvider
import org.dhis2.data.server.OpenIdSession.LogOutReason
import org.dhis2.data.service.SyncStatusController
Expand Down Expand Up @@ -114,6 +115,8 @@ abstract class SessionManagerActivity : AppCompatActivity(), ActivityResultObser
}
}

handleInsets()

super.onCreate(savedInstanceState)
}

Expand Down Expand Up @@ -211,7 +214,11 @@ abstract class SessionManagerActivity : AppCompatActivity(), ActivityResultObser
}

private fun checkSessionTimeout() {
if (::sessionManagerServiceImpl.isInitialized && sessionManagerServiceImpl.checkSessionTimeout({ accountsCount -> sessionAction(accountsCount) }, lifecycleScope) && this !is LoginActivity) {
if (::sessionManagerServiceImpl.isInitialized && sessionManagerServiceImpl.checkSessionTimeout(
{ accountsCount -> sessionAction(accountsCount) },
lifecycleScope,
) && this !is LoginActivity
) {
workManagerController.cancelAllWork()
syncStatusController.restore()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.dhis2.commons.ui.extensions

import android.app.Activity
import android.content.Context
import android.graphics.drawable.GradientDrawable
import android.util.TypedValue
import android.view.View
import androidx.compose.ui.graphics.toArgb
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import org.dhis2.commons.R
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor

fun Activity.handleInsets() {
val rootView: View = window.decorView.findViewById(android.R.id.content)
rootView.background = this.getBackgroundGradientDrawable()

ViewCompat.setOnApplyWindowInsetsListener(rootView) { v, insets ->
val bars = insets.getInsets(
WindowInsetsCompat.Type.systemBars()
or WindowInsetsCompat.Type.displayCutout(),
)
v.updatePadding(
left = bars.left,
top = bars.top,
right = bars.right,
bottom = bars.bottom,
)
WindowInsetsCompat.CONSUMED
}
}

private fun Activity.getBackgroundGradientDrawable(): GradientDrawable {
val primary = getColorPrimary()
val white = SurfaceColor.SurfaceBright.toArgb()
return GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM,
intArrayOf(
primary,
primary,
white,
white,
),
)
}

private fun Context.getColorPrimary(): Int {
val typedValue = TypedValue()
this.theme.resolveAttribute(R.attr.colorPrimary, typedValue, true)
return ContextCompat.getColor(this, typedValue.resourceId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import org.dhis2.commons.sync.OnSyncNavigationListener
import org.dhis2.commons.sync.SyncContext
import org.dhis2.commons.sync.SyncDialog
import org.dhis2.commons.sync.SyncStatusItem
import org.dhis2.commons.ui.extensions.handleInsets
import org.hisp.dhis.mobile.ui.designsystem.theme.DHIS2Theme

@AndroidEntryPoint
Expand All @@ -60,6 +61,7 @@ class HomeActivity : AppCompatActivity() {
intent.getParcelableExtra<AppConfig>(INTENT_EXTRA_APP_CONFIG)
?.let { manageStockViewModel.setConfig(it) }

handleInsets()
setContent {
val settingsUiState by viewModel.settingsUiState.collectAsState()
val helperText by viewModel.helperText.collectAsState()
Expand Down
Loading