diff options
author | Andy Scherzinger <info@andy-scherzinger.de> | 2022-11-08 12:25:40 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-08 12:25:40 +0300 |
commit | ae802cd27da48aadeca6c89a3626813928898b77 (patch) | |
tree | 4484953a2bcfdcb71bec024b643ebd107beb69e4 | |
parent | cfe05766ac1b9ea3748f3f6c4212e1f33f7cebad (diff) | |
parent | 92b62ec782963ecfbb672085f587bc968bf5db7d (diff) |
Merge pull request #11001 from nextcloud/fix/sso-dialog-theming
Use material 3 style for SSO dialog
4 files changed, 118 insertions, 106 deletions
diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SsoGrantPermissionActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/SsoGrantPermissionActivity.java index b7926d2463..1c1948e4e5 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SsoGrantPermissionActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/SsoGrantPermissionActivity.java @@ -38,17 +38,23 @@ import android.text.SpannableStringBuilder; import android.text.style.ForegroundColorSpan; import android.text.style.StyleSpan; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.nextcloud.android.sso.Constants; import com.owncloud.android.MainApp; import com.owncloud.android.R; -import com.owncloud.android.databinding.ActivitySsoGrantPermissionBinding; +import com.owncloud.android.databinding.DialogSsoGrantPermissionBinding; import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.utils.EncryptionUtils; +import com.owncloud.android.utils.theme.ViewThemeUtils; import java.util.UUID; +import javax.inject.Inject; + +import androidx.appcompat.app.AlertDialog; + import static com.nextcloud.android.sso.Constants.DELIMITER; import static com.nextcloud.android.sso.Constants.EXCEPTION_ACCOUNT_ACCESS_DECLINED; import static com.nextcloud.android.sso.Constants.EXCEPTION_ACCOUNT_NOT_FOUND; @@ -68,23 +74,51 @@ public class SsoGrantPermissionActivity extends BaseActivity { private String packageName; private Account account; + @Inject ViewThemeUtils.Factory themeUtilsFactory; + private ViewThemeUtils viewThemeUtils; + + private AlertDialog dialog; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ActivitySsoGrantPermissionBinding binding = ActivitySsoGrantPermissionBinding.inflate(getLayoutInflater()); - setContentView(binding.getRoot()); + viewThemeUtils = themeUtilsFactory.withDefaultSchemes(); + + DialogSsoGrantPermissionBinding binding = DialogSsoGrantPermissionBinding.inflate(getLayoutInflater()); ComponentName callingActivity = getCallingActivity(); if (callingActivity != null) { packageName = callingActivity.getPackageName(); - String appName = getAppNameForPackage(packageName); + final String appName = getAppNameForPackage(packageName); account = getIntent().getParcelableExtra(NEXTCLOUD_FILES_ACCOUNT); - binding.permissionText.setText(makeSpecialPartsBold( + + final SpannableStringBuilder dialogText = makeSpecialPartsBold( getString(R.string.single_sign_on_request_token, appName, account.name), appName, - account.name)); + account.name); + binding.permissionText.setText(dialogText); + try { + if (packageName != null) { + Drawable appIcon = getPackageManager().getApplicationIcon(packageName); + binding.appIcon.setImageDrawable(appIcon); + } + } catch (PackageManager.NameNotFoundException e) { + Log_OC.e(TAG, "Error retrieving app icon", e); + } + + final MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this) + .setView(binding.getRoot()) + .setCancelable(false) + .setPositiveButton(R.string.permission_allow, (dialog, which) -> grantPermission()) + .setNegativeButton(R.string.permission_deny, (dialog, which) -> exitFailed()); + + viewThemeUtils.dialog.colorMaterialAlertDialogBackground(this, builder); + + dialog = builder.create(); + dialog.show(); + Log_OC.v(TAG, "TOKEN-REQUEST: Calling Package: " + packageName); Log_OC.v(TAG, "TOKEN-REQUEST: App Name: " + appName); } else { @@ -92,18 +126,13 @@ public class SsoGrantPermissionActivity extends BaseActivity { Log_OC.e(TAG, "Calling Package is null"); setResultAndExit("Request was not executed properly. Use startActivityForResult()"); } + } - try { - if (packageName != null) { - Drawable appIcon = getPackageManager().getApplicationIcon(packageName); - binding.appIcon.setImageDrawable(appIcon); - } - } catch (PackageManager.NameNotFoundException e) { - Log_OC.e(TAG, "Error retrieving app icon", e); - } - - binding.btnDecline.setOnClickListener(v -> exitFailed()); - binding.btnGrant.setOnClickListener(v -> grantPermission()); + @Override + protected void onStart() { + super.onStart(); + viewThemeUtils.platform.colorTextButtons(dialog.getButton(AlertDialog.BUTTON_POSITIVE), + dialog.getButton(AlertDialog.BUTTON_NEGATIVE)); } private SpannableStringBuilder makeSpecialPartsBold(String text, String... toBeStyledText) { diff --git a/app/src/main/java/com/owncloud/android/utils/theme/ViewThemeUtils.kt b/app/src/main/java/com/owncloud/android/utils/theme/ViewThemeUtils.kt index 38da91860b..8bb94cf4cb 100644 --- a/app/src/main/java/com/owncloud/android/utils/theme/ViewThemeUtils.kt +++ b/app/src/main/java/com/owncloud/android/utils/theme/ViewThemeUtils.kt @@ -52,4 +52,17 @@ class ViewThemeUtils @Inject constructor( @JvmField val files = FilesSpecificViewThemeUtils(schemes, colorUtil, platform, androidx) + + class Factory @Inject constructor( + private val schemesProvider: MaterialSchemesProvider, + private val colorUtil: ColorUtil + ) { + fun withSchemes(schemes: MaterialSchemes): ViewThemeUtils { + return ViewThemeUtils(schemes, colorUtil) + } + + fun withDefaultSchemes(): ViewThemeUtils { + return withSchemes(schemesProvider.getDefaultMaterialSchemes()) + } + } } diff --git a/app/src/main/res/layout/activity_sso_grant_permission.xml b/app/src/main/res/layout/activity_sso_grant_permission.xml deleted file mode 100644 index 224ba8095a..0000000000 --- a/app/src/main/res/layout/activity_sso_grant_permission.xml +++ /dev/null @@ -1,89 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - Nextcloud Android client application - - Copyright (C) 2018 Andy Scherzinger - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - License as published by the Free Software Foundation; either - version 3 of the License, or any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU AFFERO GENERAL PUBLIC LICENSE for more details. - - You should have received a copy of the GNU Affero General Public - License along with this program. If not, see <http://www.gnu.org/licenses/>. ---> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" - xmlns:tools="http://schemas.android.com/tools" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:padding="@dimen/standard_margin" - android:orientation="horizontal" - tools:context="com.owncloud.android.ui.activity.SsoGrantPermissionActivity"> - - <ImageView - android:id="@+id/appIcon" - android:layout_width="@dimen/user_icon_size" - android:layout_height="@dimen/user_icon_size" - android:layout_gravity="top|start" - android:layout_marginEnd="@dimen/standard_margin" - android:contentDescription="@null" - android:src="@drawable/background" - app:layout_constraintLeft_toLeftOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="@+id/permissionText"/> - - <LinearLayout - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:orientation="vertical"> - - <TextView - android:id="@+id/permissionText" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:paddingStart="@dimen/zero" - android:paddingLeft="@dimen/zero" - android:paddingEnd="@dimen/zero" - android:paddingRight="@dimen/zero" - android:paddingBottom="@dimen/standard_padding" - android:textSize="@dimen/permission_dialog_text_size" - app:layout_constraintBottom_toTopOf="@+id/btnGrant" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" - tools:text="Grant Nextcloud News access to your Nextcloud account incrediblyLong_username_with_123456789_number@Nextcloud_dummy.com?"/> - - <LinearLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:gravity="end" - android:orientation="horizontal"> - - <com.google.android.material.button.MaterialButton - android:id="@+id/btnDecline" - style="@style/Button.Borderless" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginEnd="@dimen/standard_half_margin" - android:text="@string/permission_deny" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toStartOf="@+id/btnGrant"/> - - <com.google.android.material.button.MaterialButton - android:id="@+id/btnGrant" - style="@style/Button.Borderless" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/permission_allow" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent"/> - </LinearLayout> - </LinearLayout> - -</LinearLayout> diff --git a/app/src/main/res/layout/dialog_sso_grant_permission.xml b/app/src/main/res/layout/dialog_sso_grant_permission.xml new file mode 100644 index 0000000000..b0523954f3 --- /dev/null +++ b/app/src/main/res/layout/dialog_sso_grant_permission.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="utf-8"?><!-- + Nextcloud Android client application + + Copyright (C) 2018 Andy Scherzinger + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + License as published by the Free Software Foundation; either + version 3 of the License, or any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU AFFERO GENERAL PUBLIC LICENSE for more details. + + You should have received a copy of the GNU Affero General Public + License along with this program. If not, see <http://www.gnu.org/licenses/>. +--> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:paddingHorizontal="@dimen/dialog_padding" + android:paddingTop="@dimen/dialog_padding" + tools:context="com.owncloud.android.ui.activity.SsoGrantPermissionActivity" + tools:ignore="UseCompoundDrawables"> + + <ImageView + android:id="@+id/appIcon" + android:layout_width="@dimen/user_icon_size" + android:layout_height="@dimen/user_icon_size" + android:layout_gravity="top|start" + android:layout_marginEnd="@dimen/standard_margin" + android:contentDescription="@null" + android:src="@drawable/background" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="@+id/permissionText" + tools:src="@drawable/file_application" /> + + <TextView + android:id="@+id/permissionText" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingStart="@dimen/zero" + android:paddingLeft="@dimen/zero" + android:paddingEnd="@dimen/zero" + android:paddingRight="@dimen/zero" + android:paddingBottom="@dimen/standard_padding" + android:textSize="@dimen/permission_dialog_text_size" + app:layout_constraintBottom_toTopOf="@+id/btnGrant" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:text="Grant Nextcloud News access to your Nextcloud account incrediblyLong_username_with_123456789_number@Nextcloud_dummy.com?" /> + +</LinearLayout> |