fix settings activity and preview video

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-11-28 12:25:37 +01:00 committed by Tobias Kaminsky
parent 2a09f53f6c
commit 0ff17fbb13
6 changed files with 74 additions and 29 deletions

View file

@ -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<Fragment> = 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
}
}

View file

@ -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) {

View file

@ -0,0 +1,38 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
* 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
}
}

View file

@ -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);

View file

@ -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() {

View file

@ -51,7 +51,7 @@
<dimen name="list_item_share_right_margin">12dp</dimen>
<dimen name="live_photo_indicator_vertical_padding">3dp</dimen>
<dimen name="live_photo_indicator_horizontal_padding">16dp</dimen>
<dimen name="settings_activity_padding">24dp</dimen>
<dimen name="file_list_item_avatar_icon_radius">10dp</dimen>
<dimen name="account_action_layout_height">72dp</dimen>
<dimen name="zero">0dp</dimen>