浏览代码

m3 theming of e2ee dialog

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger 2 年之前
父节点
当前提交
5d7d3d6641

+ 27 - 40
app/src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java

@@ -24,19 +24,17 @@ import android.accounts.AccountManager;
 import android.app.Dialog;
 import android.app.Dialog;
 import android.content.DialogInterface;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.Intent;
-import android.graphics.PorterDuff;
-import android.graphics.drawable.Drawable;
 import android.os.AsyncTask;
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View;
 import android.widget.Button;
 import android.widget.Button;
-import android.widget.TextView;
 
 
 import com.google.android.material.dialog.MaterialAlertDialogBuilder;
 import com.google.android.material.dialog.MaterialAlertDialogBuilder;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.di.Injectable;
 import com.nextcloud.client.di.Injectable;
 import com.owncloud.android.R;
 import com.owncloud.android.R;
+import com.owncloud.android.databinding.SetupEncryptionDialogBinding;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.lib.common.accounts.AccountUtils;
 import com.owncloud.android.lib.common.accounts.AccountUtils;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -48,7 +46,6 @@ import com.owncloud.android.lib.resources.users.SendCSROperation;
 import com.owncloud.android.lib.resources.users.StorePrivateKeyOperation;
 import com.owncloud.android.lib.resources.users.StorePrivateKeyOperation;
 import com.owncloud.android.utils.CsrHelper;
 import com.owncloud.android.utils.CsrHelper;
 import com.owncloud.android.utils.EncryptionUtils;
 import com.owncloud.android.utils.EncryptionUtils;
-import com.owncloud.android.utils.theme.ThemeColorUtils;
 import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 
 import java.io.IOException;
 import java.io.IOException;
@@ -63,7 +60,6 @@ import javax.inject.Inject;
 import androidx.annotation.NonNull;
 import androidx.annotation.NonNull;
 import androidx.annotation.VisibleForTesting;
 import androidx.annotation.VisibleForTesting;
 import androidx.appcompat.app.AlertDialog;
 import androidx.appcompat.app.AlertDialog;
-import androidx.core.graphics.drawable.DrawableCompat;
 import androidx.fragment.app.DialogFragment;
 import androidx.fragment.app.DialogFragment;
 
 
 import static com.owncloud.android.utils.EncryptionUtils.decodeStringToBase64Bytes;
 import static com.owncloud.android.utils.EncryptionUtils.decodeStringToBase64Bytes;
@@ -90,19 +86,16 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
     private static final String KEY_FAILED = "KEY_FAILED";
     private static final String KEY_FAILED = "KEY_FAILED";
     private static final String KEY_GENERATE = "KEY_GENERATE";
     private static final String KEY_GENERATE = "KEY_GENERATE";
 
 
-    @Inject ThemeColorUtils themeColorUtils;
     @Inject ViewThemeUtils viewThemeUtils;
     @Inject ViewThemeUtils viewThemeUtils;
 
 
     private User user;
     private User user;
-    private TextView textView;
-    private TextView passphraseTextView;
     private ArbitraryDataProvider arbitraryDataProvider;
     private ArbitraryDataProvider arbitraryDataProvider;
     private Button positiveButton;
     private Button positiveButton;
     private Button neutralButton;
     private Button neutralButton;
     private DownloadKeysAsyncTask task;
     private DownloadKeysAsyncTask task;
-    private TextView passwordField;
     private String keyResult;
     private String keyResult;
     private List<String> keyWords;
     private List<String> keyWords;
+    private SetupEncryptionDialogBinding binding;
 
 
     /**
     /**
      * Public factory method to create new SetupEncryptionDialogFragment instance
      * Public factory method to create new SetupEncryptionDialogFragment instance
@@ -124,10 +117,11 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
 
 
         AlertDialog alertDialog = (AlertDialog) getDialog();
         AlertDialog alertDialog = (AlertDialog) getDialog();
 
 
-        positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
-        neutralButton = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
-        viewThemeUtils.platform.colorTextButtons(positiveButton,
-                                                 neutralButton);
+        if (alertDialog != null) {
+            positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
+            neutralButton = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
+            viewThemeUtils.platform.colorTextButtons(positiveButton, neutralButton);
+        }
 
 
         task = new DownloadKeysAsyncTask();
         task = new DownloadKeysAsyncTask();
         task.execute();
         task.execute();
@@ -136,26 +130,18 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
     @NonNull
     @NonNull
     @Override
     @Override
     public Dialog onCreateDialog(Bundle savedInstanceState) {
     public Dialog onCreateDialog(Bundle savedInstanceState) {
-        int primaryColor = themeColorUtils.primaryColor(getContext());
         user = getArguments().getParcelable(ARG_USER);
         user = getArguments().getParcelable(ARG_USER);
 
 
         arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver());
         arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver());
 
 
         // Inflate the layout for the dialog
         // Inflate the layout for the dialog
         LayoutInflater inflater = getActivity().getLayoutInflater();
         LayoutInflater inflater = getActivity().getLayoutInflater();
+        binding = SetupEncryptionDialogBinding.inflate(inflater, null, false);
 
 
         // Setup layout
         // Setup layout
-        View v = inflater.inflate(R.layout.setup_encryption_dialog, null);
-        textView = v.findViewById(R.id.encryption_status);
-        passphraseTextView = v.findViewById(R.id.encryption_passphrase);
-        passwordField = v.findViewById(R.id.encryption_passwordInput);
-        passwordField.getBackground().setColorFilter(primaryColor, PorterDuff.Mode.SRC_ATOP);
-
-        Drawable wrappedDrawable = DrawableCompat.wrap(passwordField.getBackground());
-        DrawableCompat.setTint(wrappedDrawable, primaryColor);
-        passwordField.setBackgroundDrawable(wrappedDrawable);
+        viewThemeUtils.material.colorTextInputLayout(binding.encryptionPasswordInputContainer);
 
 
-        return createDialog(v);
+        return createDialog(binding.getRoot());
     }
     }
 
 
     @NonNull
     @NonNull
@@ -196,12 +182,12 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
                             case KEY_EXISTING_USED:
                             case KEY_EXISTING_USED:
                                 Log_OC.d(TAG, "Decrypt private key");
                                 Log_OC.d(TAG, "Decrypt private key");
 
 
-                                textView.setText(R.string.end_to_end_encryption_decrypting);
+                                binding.encryptionStatus.setText(R.string.end_to_end_encryption_decrypting);
 
 
                                 try {
                                 try {
                                     String privateKey = task.get();
                                     String privateKey = task.get();
-                                    String mnemonicUnchanged = passwordField.getText().toString();
-                                    String mnemonic = passwordField.getText().toString().replaceAll("\\s", "")
+                                    String mnemonicUnchanged = binding.encryptionPasswordInput.getText().toString();
+                                    String mnemonic = binding.encryptionPasswordInput.getText().toString().replaceAll("\\s", "")
                                         .toLowerCase(Locale.ROOT);
                                         .toLowerCase(Locale.ROOT);
                                     String decryptedPrivateKey = EncryptionUtils.decryptPrivateKey(privateKey,
                                     String decryptedPrivateKey = EncryptionUtils.decryptPrivateKey(privateKey,
                                                                                                    mnemonic);
                                                                                                    mnemonic);
@@ -241,13 +227,13 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
                                                                          SETUP_ENCRYPTION_RESULT_CODE, intentExisting);
                                                                          SETUP_ENCRYPTION_RESULT_CODE, intentExisting);
 
 
                                 } catch (Exception e) {
                                 } catch (Exception e) {
-                                    textView.setText(R.string.end_to_end_encryption_wrong_password);
+                                    binding.encryptionStatus.setText(R.string.end_to_end_encryption_wrong_password);
                                     Log_OC.d(TAG, "Error while decrypting private key: " + e.getMessage());
                                     Log_OC.d(TAG, "Error while decrypting private key: " + e.getMessage());
                                 }
                                 }
                                 break;
                                 break;
 
 
                             case KEY_GENERATE:
                             case KEY_GENERATE:
-                                passphraseTextView.setVisibility(View.GONE);
+                                binding.encryptionPassphrase.setVisibility(View.GONE);
                                 positiveButton.setVisibility(View.GONE);
                                 positiveButton.setVisibility(View.GONE);
                                 neutralButton.setVisibility(View.GONE);
                                 neutralButton.setVisibility(View.GONE);
                                 getDialog().setTitle(R.string.end_to_end_encryption_storing_keys);
                                 getDialog().setTitle(R.string.end_to_end_encryption_storing_keys);
@@ -272,7 +258,7 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
         protected void onPreExecute() {
         protected void onPreExecute() {
             super.onPreExecute();
             super.onPreExecute();
 
 
-            textView.setText(R.string.end_to_end_encryption_retrieving_keys);
+            binding.encryptionStatus.setText(R.string.end_to_end_encryption_retrieving_keys);
             positiveButton.setVisibility(View.INVISIBLE);
             positiveButton.setVisibility(View.INVISIBLE);
             neutralButton.setVisibility(View.INVISIBLE);
             neutralButton.setVisibility(View.INVISIBLE);
         }
         }
@@ -321,11 +307,11 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
                     keyWords = EncryptionUtils.getRandomWords(12, requireContext());
                     keyWords = EncryptionUtils.getRandomWords(12, requireContext());
                     showMnemonicInfo();
                     showMnemonicInfo();
                 } catch (IOException e) {
                 } catch (IOException e) {
-                    textView.setText(R.string.common_error);
+                    binding.encryptionStatus.setText(R.string.common_error);
                 }
                 }
             } else if (!privateKey.isEmpty()) {
             } else if (!privateKey.isEmpty()) {
-                textView.setText(R.string.end_to_end_encryption_enter_password);
-                passwordField.setVisibility(View.VISIBLE);
+                binding.encryptionStatus.setText(R.string.end_to_end_encryption_enter_password);
+                binding.encryptionPasswordInputContainer.setVisibility(View.VISIBLE);
                 positiveButton.setVisibility(View.VISIBLE);
                 positiveButton.setVisibility(View.VISIBLE);
             } else {
             } else {
                 Log_OC.e(TAG, "Got empty private key string");
                 Log_OC.e(TAG, "Got empty private key string");
@@ -338,7 +324,7 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
         protected void onPreExecute() {
         protected void onPreExecute() {
             super.onPreExecute();
             super.onPreExecute();
 
 
-            textView.setText(R.string.end_to_end_encryption_generating_keys);
+            binding.encryptionStatus.setText(R.string.end_to_end_encryption_generating_keys);
         }
         }
 
 
         @Override
         @Override
@@ -436,11 +422,12 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
     public void showMnemonicInfo() {
     public void showMnemonicInfo() {
         requireDialog().setTitle(R.string.end_to_end_encryption_passphrase_title);
         requireDialog().setTitle(R.string.end_to_end_encryption_passphrase_title);
 
 
-        textView.setText(R.string.end_to_end_encryption_keywords_description);
+        binding.encryptionStatus.setText(R.string.end_to_end_encryption_keywords_description);
+        viewThemeUtils.material.colorTextInputLayout(binding.encryptionPasswordInputContainer);
 
 
-        passphraseTextView.setText(generateMnemonicString(true));
+        binding.encryptionPassphrase.setText(generateMnemonicString(true));
 
 
-        passphraseTextView.setVisibility(View.VISIBLE);
+        binding.encryptionPassphrase.setVisibility(View.VISIBLE);
         positiveButton.setText(R.string.end_to_end_encryption_confirm_button);
         positiveButton.setText(R.string.end_to_end_encryption_confirm_button);
         positiveButton.setVisibility(View.VISIBLE);
         positiveButton.setVisibility(View.VISIBLE);
 
 
@@ -455,11 +442,11 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
         keyResult = KEY_FAILED;
         keyResult = KEY_FAILED;
 
 
         requireDialog().setTitle(R.string.common_error);
         requireDialog().setTitle(R.string.common_error);
-        textView.setText(R.string.end_to_end_encryption_unsuccessful);
-        passphraseTextView.setVisibility(View.GONE);
+        binding.encryptionStatus.setText(R.string.end_to_end_encryption_unsuccessful);
+        binding.encryptionPassphrase.setVisibility(View.GONE);
         positiveButton.setText(R.string.end_to_end_encryption_dialog_close);
         positiveButton.setText(R.string.end_to_end_encryption_dialog_close);
         positiveButton.setVisibility(View.VISIBLE);
         positiveButton.setVisibility(View.VISIBLE);
-        positiveButton.setTextColor(themeColorUtils.primaryAccentColor(getContext()));
+        viewThemeUtils.platform.colorTextButtons(positiveButton);
     }
     }
 
 
     @VisibleForTesting
     @VisibleForTesting

+ 25 - 10
app/src/main/res/layout/setup_encryption_dialog.xml

@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?><!--
 <?xml version="1.0" encoding="utf-8"?><!--
   Nextcloud Android client application
   Nextcloud Android client application
 
 
+  Copyright (C) 2022 Andy Scherzinger
   Copyright (C) 2018 Tobias Kaminsky
   Copyright (C) 2018 Tobias Kaminsky
   Copyright (C) 2018 Nextcloud
   Copyright (C) 2018 Nextcloud
 
 
@@ -18,37 +19,51 @@
   License along with this program.  If not, see <http://www.gnu.org/licenses/>.
   License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 -->
 -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_height="match_parent"
     android:gravity="clip_horizontal"
     android:gravity="clip_horizontal"
     android:orientation="vertical"
     android:orientation="vertical"
-    android:padding="@dimen/standard_padding">
+    android:padding="@dimen/dialog_padding">
 
 
     <TextView
     <TextView
         android:id="@+id/encryption_status"
         android:id="@+id/encryption_status"
         android:layout_width="match_parent"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_margin="@dimen/standard_margin" />
+        android:layout_marginBottom="@dimen/standard_margin"
+        tools:text="@string/end_to_end_encryption_keywords_description" />
 
 
     <TextView
     <TextView
         android:id="@+id/encryption_passphrase"
         android:id="@+id/encryption_passphrase"
         android:layout_width="match_parent"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_margin="@dimen/standard_margin"
+        android:layout_marginBottom="@dimen/standard_margin"
         android:background="@drawable/e2e_border"
         android:background="@drawable/e2e_border"
         android:gravity="center"
         android:gravity="center"
         android:padding="5dp"
         android:padding="5dp"
         android:textIsSelectable="true"
         android:textIsSelectable="true"
-        android:visibility="gone" />
+        android:visibility="gone"
+        tools:text="passphrase"
+        tools:visibility="visible" />
 
 
-    <com.google.android.material.textfield.TextInputEditText
-        android:id="@+id/encryption_passwordInput"
+    <com.google.android.material.textfield.TextInputLayout
+        android:id="@+id/encryption_passwordInput_container"
         android:layout_width="match_parent"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_height="wrap_content"
-        android:ems="10"
         android:hint="@string/end_to_end_encryption_password"
         android:hint="@string/end_to_end_encryption_password"
-        android:inputType="textPassword"
-        android:textCursorDrawable="@null"
+        android:minHeight="@dimen/minimum_size_for_touchable_area"
         android:visibility="gone"
         android:visibility="gone"
-        android:autofillHints="password"/>
+        tools:visibility="visible">
+
+        <com.google.android.material.textfield.TextInputEditText
+            android:id="@+id/encryption_passwordInput"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:autofillHints="password"
+            android:ems="10"
+            android:inputType="textPassword"
+            android:textCursorDrawable="@null" />
+
+    </com.google.android.material.textfield.TextInputLayout>
+
 </LinearLayout>
 </LinearLayout>