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 Zendesk contact support overlap for Android 15 (SDK 35) #21617

Merged
merged 10 commits into from
Jan 28, 2025
8 changes: 4 additions & 4 deletions WordPress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@
android:name="zendesk.support.requestlist.RequestListActivity"
android:theme="@style/WordPress.ZenDesk" />

<activity
android:name=".support.SupportWebViewActivity"
android:theme="@style/WordPress.NoActionBar.NoEdgeToEdge" />

<!-- empty title -->

<!-- Preferences activities -->
Expand Down Expand Up @@ -769,10 +773,6 @@
android:label="@string/my_profile"
android:theme="@style/WordPress.NoActionBar" />

<activity
android:name=".support.SupportWebViewActivity"
android:theme="@style/WordPress.NoActionBar" />

<!-- Lib activities-->
<activity
android:name="com.yalantis.ucrop.UCropActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import org.wordpress.android.designsystem.DesignSystemActivity
import org.wordpress.android.support.SupportWebViewActivity
import org.wordpress.android.ui.blaze.blazecampaigns.BlazeCampaignParentActivity
import org.wordpress.android.ui.bloggingprompts.promptslist.BloggingPromptsListActivity
import org.wordpress.android.ui.debug.preferences.DebugSharedPreferenceFlagsActivity
Expand Down Expand Up @@ -38,27 +40,27 @@ open class BaseAppCompatActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
// When both compileSdkVersion and targetSdkVersion are 35+, the OS defaults to
// using edge-to-edge. We need to adjust for this by applying insets as needed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
val targetSdkVersion = applicationContext.applicationInfo.targetSdkVersion
if ((targetSdkVersion >= Build.VERSION_CODES.VANILLA_ICE_CREAM) &&
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)
) {
applyInsetOffsets()
}
}

@RequiresApi(Build.VERSION_CODES.R)
private fun applyInsetOffsets() {
// val activityName = this.localClassName.substringAfterLast(".")
val excludedActivity = excludedActivities[this.localClassName]
val applyTopOffset = excludedActivity?.applyTopOffset ?: true
val applyBottomOffset = excludedActivity?.applyBottomOffset ?: true

if (applyTopOffset || applyBottomOffset) {
window.decorView.setOnApplyWindowInsetsListener { view, insets ->
// Notice we're using systemBars rather than statusBar and accounting for the display cutouts
ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { view, insets ->
val innerPadding = insets.getInsets(
WindowInsetsCompat.Type.systemBars()
or WindowInsetsCompat.Type.displayCutout()
)

// Adjust system bars padding to avoid overlap
view.setPadding(
innerPadding.left,
if (applyTopOffset) innerPadding.top else 0,
Expand Down Expand Up @@ -97,7 +99,8 @@ open class BaseAppCompatActivity : AppCompatActivity() {
applyBottomOffset = false
),
DesignSystemActivity::class.java.name to ActivityOffsets
(applyTopOffset = false,
(
applyTopOffset = false,
applyBottomOffset = false
),
DomainManagementActivity::class.java.name to ActivityOffsets(
Expand Down Expand Up @@ -156,6 +159,10 @@ open class BaseAppCompatActivity : AppCompatActivity() {
applyTopOffset = false,
applyBottomOffset = false
),
SupportWebViewActivity::class.java.name to ActivityOffsets(
applyTopOffset = false,
applyBottomOffset = false
),

// apply bottom offset only
MediaSettingsActivity::class.java.name to ActivityOffsets(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,39 @@ package org.wordpress.android.util.extensions

import android.os.Build
import android.view.Window
import android.view.WindowInsets
import androidx.core.view.WindowInsetsControllerCompat
import org.wordpress.android.util.ColorUtils

/**
* Note these are skipped on SDK 35+ because they conflict with API 15's edge-to-edge insets
*/
fun Window.setWindowStatusBarColor(color: Int) {
setWindowBarColor(color, InsetsType.STATUS_BAR)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
setWindowBarColor(color, InsetsType.STATUS_BAR)
}
}

fun Window.setWindowNavigationBarColor(color: Int) {
setWindowBarColor(color, InsetsType.NAVIGATION_BAR)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
setWindowBarColor(color, InsetsType.NAVIGATION_BAR)
}
}

/**
* Sets the status bar or navigation bar color
* TODO Setting both the status bar color and navigation bar color causes the insets to be set twice
*/
@Suppress("DEPRECATION")
private fun Window.setWindowBarColor(color: Int, insetsType: InsetsType) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
// Android 15+
decorView.setOnApplyWindowInsetsListener { view, insets ->
view.setBackgroundColor(color)
val barInsets = insets.getInsets(
when (insetsType) {
InsetsType.STATUS_BAR -> WindowInsets.Type.statusBars()
InsetsType.NAVIGATION_BAR -> WindowInsets.Type.navigationBars()
}
)
// Adjust padding to avoid overlap
view.setPadding(0, barInsets.top, 0, 0)
insets
}
} else {
when(insetsType) {
InsetsType.STATUS_BAR -> statusBarColor = color
InsetsType.NAVIGATION_BAR -> navigationBarColor = color
}
val windowInsetsController = WindowInsetsControllerCompat(this, decorView)
if (insetsType == InsetsType.STATUS_BAR) {
windowInsetsController.isAppearanceLightStatusBars = ColorUtils.isColorLight(statusBarColor)
}
windowInsetsController.isAppearanceLightNavigationBars = ColorUtils.isColorLight(navigationBarColor)
when (insetsType) {
InsetsType.STATUS_BAR -> statusBarColor = color
InsetsType.NAVIGATION_BAR -> navigationBarColor = color
}
val windowInsetsController = WindowInsetsControllerCompat(this, decorView)
if (insetsType == InsetsType.STATUS_BAR) {
windowInsetsController.isAppearanceLightStatusBars = ColorUtils.isColorLight(statusBarColor)
}
windowInsetsController.isAppearanceLightNavigationBars =
ColorUtils.isColorLight(navigationBarColor)
}

private enum class InsetsType {
Expand Down
6 changes: 5 additions & 1 deletion WordPress/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">

<style name="Base.Wordpress" parent="Theme.MaterialComponents.DayNight">
<!-- Material theme -->
Expand Down Expand Up @@ -291,6 +291,10 @@
<item name="windowNoTitle">true</item>
</style>

<style name="WordPress.NoActionBar.NoEdgeToEdge" parent="WordPress.NoActionBar">
<item name="android:windowOptOutEdgeToEdgeEnforcement" tools:targetApi="35">true</item>
</style>

<style name="WordPress.Media.Preview" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:statusBarColor">@color/black</item>
<item name="android:navigationBarColor">@color/black</item>"
Expand Down
Loading