diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ActivityExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ActivityExtensions.kt index a3473f8cd3..0bdbbbd0cb 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/ActivityExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/ActivityExtensions.kt @@ -7,15 +7,8 @@ package com.nextcloud.utils.extensions -import android.view.View -import android.view.Window -import androidx.annotation.ColorInt import androidx.appcompat.app.AppCompatActivity -import androidx.core.content.ContextCompat -import androidx.core.view.ViewCompat -import androidx.core.view.WindowInsetsCompat import androidx.fragment.app.Fragment -import com.owncloud.android.R fun AppCompatActivity.isDialogFragmentReady(fragment: Fragment): Boolean = isActive() && !fragment.isStateSaved @@ -24,23 +17,3 @@ fun AppCompatActivity.isActive(): Boolean = !isFinishing && !isDestroyed fun AppCompatActivity.fragments(): List = supportFragmentManager.fragments fun AppCompatActivity.lastFragment(): Fragment = fragments().last() - - -fun Window?.addStatusBarPadding() { - if (this == null) { - return - } - - val decorView: View = decorView - - ViewCompat.setOnApplyWindowInsetsListener(decorView) { v: View, insets: WindowInsetsCompat -> - val statusBarInsets = insets.getInsets(WindowInsetsCompat.Type.statusBars()) - v.setPadding( - v.paddingLeft, - statusBarInsets.top, - v.paddingRight, - v.paddingBottom - ) - insets - } -} diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ViewExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ViewExtensions.kt index c024fd4f65..02cdbc3f91 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/ViewExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/ViewExtensions.kt @@ -11,6 +11,7 @@ import android.content.Context import android.graphics.Outline import android.util.TypedValue import android.view.View +import android.view.ViewGroup import android.view.ViewOutlineProvider fun View?.setVisibleIf(condition: Boolean) { @@ -27,6 +28,18 @@ fun View?.makeRounded(context: Context, cornerRadius: Float) { } } +fun View?.setMargins(left: Int, top: Int, right: Int, bottom: Int) { + if (this == null) { + return + } + + if (layoutParams is ViewGroup.MarginLayoutParams) { + val param = layoutParams as ViewGroup.MarginLayoutParams + param.setMargins(left, top, right, bottom) + requestLayout() + } +} + fun createRoundedOutline(context: Context, cornerRadiusValue: Float): ViewOutlineProvider { return object : ViewOutlineProvider() { override fun getOutline(view: View, outline: Outline) { diff --git a/app/src/main/java/com/nextcloud/utils/extensions/WindowExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/WindowExtensions.kt new file mode 100644 index 0000000000..59e39108e8 --- /dev/null +++ b/app/src/main/java/com/nextcloud/utils/extensions/WindowExtensions.kt @@ -0,0 +1,38 @@ +/* + * Nextcloud - Android Client + * + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +package com.nextcloud.utils.extensions + +import android.view.View +import android.view.Window +import android.view.WindowManager +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat + +fun Window?.makeStatusBarTransparent() { + val flag = WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS + this?.setFlags(flag, flag) +} + +fun Window?.addStatusBarPadding() { + if (this == null) { + return + } + + val decorView: View = decorView + + ViewCompat.setOnApplyWindowInsetsListener(decorView) { v: View, insets: WindowInsetsCompat -> + val statusBarInsets = insets.getInsets(WindowInsetsCompat.Type.statusBars()) + v.setPadding( + v.paddingLeft, + statusBarInsets.top, + v.paddingRight, + v.paddingBottom + ) + insets + } +} diff --git a/app/src/main/java/com/owncloud/android/ui/activity/BaseActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/BaseActivity.java index c2a440ccde..9c963aa26e 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/BaseActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/BaseActivity.java @@ -11,6 +11,7 @@ import android.accounts.Account; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; +import android.view.WindowManager; import com.nextcloud.client.account.User; import com.nextcloud.client.account.UserAccountManager; @@ -20,6 +21,7 @@ import com.nextcloud.client.mixins.SessionMixin; import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.client.preferences.DarkMode; import com.nextcloud.utils.extensions.ActivityExtensionsKt; +import com.nextcloud.utils.extensions.WindowExtensionsKt; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.utils.Log_OC; @@ -33,6 +35,7 @@ import androidx.activity.EdgeToEdge; import androidx.activity.SystemBarStyle; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.view.WindowCompat; /** * Base activity with common behaviour for activities dealing with ownCloud {@link Account}s . @@ -69,7 +72,8 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab @Override protected void onCreate(@Nullable Bundle savedInstanceState) { enableEdgeToEdge(); - ActivityExtensionsKt.addStatusBarPadding(getWindow()); + WindowExtensionsKt.makeStatusBarTransparent(getWindow()); + WindowExtensionsKt.addStatusBarPadding(getWindow()); super.onCreate(savedInstanceState); sessionMixin = new SessionMixin(this, accountManager); mixinRegistry.add(sessionMixin); diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index e2619d45d4..973ecca38d 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java @@ -50,6 +50,8 @@ import com.nextcloud.client.network.ConnectivityService; import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.client.preferences.AppPreferencesImpl; import com.nextcloud.client.preferences.DarkMode; +import com.nextcloud.utils.extensions.ViewExtensionsKt; +import com.nextcloud.utils.extensions.WindowExtensionsKt; import com.nextcloud.utils.mdm.MDMConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; @@ -144,6 +146,8 @@ public class SettingsActivity extends PreferenceActivity @SuppressWarnings("deprecation") @Override public void onCreate(Bundle savedInstanceState) { + WindowExtensionsKt.makeStatusBarTransparent(getWindow()); + WindowExtensionsKt.addStatusBarPadding(getWindow()); super.onCreate(savedInstanceState); getDelegate().installViewFactory(); @@ -187,6 +191,19 @@ public class SettingsActivity extends PreferenceActivity // workaround for mismatched color when app dark mode and system dark mode don't agree setListBackground(); showPasscodeDialogIfEnforceAppProtection(); + adjustTopMarginForActionBar(); + } + + private void adjustTopMarginForActionBar() { + if (getListView() == null) { + return; + } + + float topMarginInDp = getResources().getDimension(R.dimen.settings_activity_padding); + int topMarginInPx = DisplayUtils.convertDpToPixel(topMarginInDp, this); + ViewExtensionsKt.setMargins(getListView(), 0, topMarginInPx, 0, 0); + + getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(this, R.color.bg_default)); } private void showPasscodeDialogIfEnforceAppProtection() { diff --git a/app/src/main/res/values/dims.xml b/app/src/main/res/values/dims.xml index af90df2b0f..ddcc166374 100644 --- a/app/src/main/res/values/dims.xml +++ b/app/src/main/res/values/dims.xml @@ -51,7 +51,7 @@ 12dp 3dp 16dp - + 24dp 10dp 72dp 0dp