Browse Source

enhance mnemonic on dark mode

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 4 years ago
parent
commit
a29739c6de

BIN
screenshots/gplay/debug/com.owncloud.android.ui.dialog.SetupEncryptionDialogFragmentIT_error.png


BIN
screenshots/gplay/debug/com.owncloud.android.ui.dialog.SetupEncryptionDialogFragmentIT_showMnemonic.png


+ 6 - 1
src/androidTest/java/com/owncloud/android/AbstractIT.java

@@ -1,5 +1,6 @@
 package com.owncloud.android;
 
+import android.Manifest;
 import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.accounts.AuthenticatorException;
@@ -41,6 +42,7 @@ import junit.framework.TestCase;
 
 import org.apache.commons.io.FileUtils;
 import org.junit.BeforeClass;
+import org.junit.Rule;
 
 import java.io.File;
 import java.io.FileWriter;
@@ -52,6 +54,7 @@ import androidx.annotation.NonNull;
 import androidx.test.espresso.contrib.DrawerActions;
 import androidx.test.espresso.intent.rule.IntentsTestRule;
 import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.rule.GrantPermissionRule;
 import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry;
 import androidx.test.runner.lifecycle.Stage;
 
@@ -67,7 +70,9 @@ import static org.junit.Assert.assertTrue;
  */
 
 public abstract class AbstractIT {
-    //@Rule public RetryTestRule retryTestRule = new RetryTestRule();
+    @Rule
+    public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
+        Manifest.permission.WRITE_EXTERNAL_STORAGE);
 
     protected static OwnCloudClient client;
     protected static Account account;

+ 91 - 0
src/androidTest/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragmentIT.kt

@@ -0,0 +1,91 @@
+/*
+ *
+ * Nextcloud Android client application
+ *
+ * @author Tobias Kaminsky
+ * Copyright (C) 2020 Tobias Kaminsky
+ * Copyright (C) 2020 Nextcloud GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) 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 <https://www.gnu.org/licenses/>.
+ */
+package com.owncloud.android.ui.dialog
+
+import android.view.Window
+import androidx.test.espresso.intent.rule.IntentsTestRule
+import androidx.test.internal.runner.junit4.statement.UiThreadStatement
+import com.nextcloud.client.TestActivity
+import com.owncloud.android.AbstractIT
+import com.owncloud.android.utils.ScreenshotTest
+import org.junit.Rule
+import org.junit.Test
+import java.util.Objects
+
+class SetupEncryptionDialogFragmentIT : AbstractIT() {
+    @get:Rule
+    val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)
+
+    @Test
+    @ScreenshotTest
+    fun showMnemonic() {
+        val activity = testActivityRule.launchActivity(null)
+
+        val sut = SetupEncryptionDialogFragment.newInstance(user, 0)
+
+        sut.show(activity.supportFragmentManager, "1")
+
+        val keyWords = listOf(
+            "ability",
+            "able",
+            "about",
+            "above",
+            "absent",
+            "absorb",
+            "abstract",
+            "absurd",
+            "abuse",
+            "access",
+            "accident",
+            "account",
+            "accuse"
+        )
+
+        sut.setMnemonic(keyWords)
+
+        UiThreadStatement.runOnUiThread {
+            sut.showMnemonicInfo()
+        }
+
+        waitForIdleSync()
+
+        screenshot(Objects.requireNonNull<Window>(sut.requireDialog().window).decorView)
+    }
+
+    @Test
+    @ScreenshotTest
+    fun error() {
+        val activity = testActivityRule.launchActivity(null)
+
+        val sut = SetupEncryptionDialogFragment.newInstance(user, 0)
+
+        sut.show(activity.supportFragmentManager, "1")
+
+        UiThreadStatement.runOnUiThread {
+            sut.errorSavingKeys()
+        }
+
+        waitForIdleSync()
+
+        screenshot(Objects.requireNonNull<Window>(sut.requireDialog().window).decorView)
+    }
+}

+ 0 - 8
src/androidTest/java/com/owncloud/android/ui/dialog/SyncFileNotEnoughSpaceDialogFragmentTest.java

@@ -22,8 +22,6 @@
 
 package com.owncloud.android.ui.dialog;
 
-import android.Manifest;
-
 import com.owncloud.android.AbstractIT;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
@@ -34,7 +32,6 @@ import org.junit.Test;
 import java.util.Objects;
 
 import androidx.test.espresso.intent.rule.IntentsTestRule;
-import androidx.test.rule.GrantPermissionRule;
 
 import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
 
@@ -43,11 +40,6 @@ public class SyncFileNotEnoughSpaceDialogFragmentTest extends AbstractIT {
                                                                                            true,
                                                                                            false);
 
-    @Rule
-    public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
-        Manifest.permission.WRITE_EXTERNAL_STORAGE);
-
-
     @Test
     public void showNotEnoughSpaceDialogForFolder() {
         FileDisplayActivity test = activityRule.launchActivity(null);

+ 39 - 24
src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java

@@ -55,6 +55,7 @@ import java.util.List;
 import java.util.Locale;
 
 import androidx.annotation.NonNull;
+import androidx.annotation.VisibleForTesting;
 import androidx.appcompat.app.AlertDialog;
 import androidx.core.graphics.drawable.DrawableCompat;
 import androidx.fragment.app.DialogFragment;
@@ -284,21 +285,8 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
             if (privateKey == null) {
                 // first show info
                 try {
-                    keyWords = EncryptionUtils.getRandomWords(12, getContext());
-
-                    getDialog().setTitle(R.string.end_to_end_encryption_passphrase_title);
-
-                    textView.setText(R.string.end_to_end_encryption_keywords_description);
-
-                    passphraseTextView.setText(generateMnemonicString(true));
-
-                    passphraseTextView.setVisibility(View.VISIBLE);
-                    positiveButton.setText(R.string.end_to_end_encryption_confirm_button);
-                    positiveButton.setVisibility(View.VISIBLE);
-
-                    negativeButton.setVisibility(View.VISIBLE);
-
-                    keyResult = KEY_GENERATE;
+                    keyWords = EncryptionUtils.getRandomWords(12, requireContext());
+                    showMnemonicInfo();
                 } catch (IOException e) {
                     textView.setText(R.string.common_error);
                 }
@@ -386,20 +374,15 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
             super.onPostExecute(s);
 
             if (s.isEmpty()) {
-                keyResult = KEY_FAILED;
-
-                getDialog().setTitle(R.string.common_error);
-                textView.setText(R.string.end_to_end_encryption_unsuccessful);
-                positiveButton.setText(R.string.end_to_end_encryption_dialog_close);
-                positiveButton.setVisibility(View.VISIBLE);
+                errorSavingKeys();
             } else {
-                getDialog().dismiss();
+                requireDialog().dismiss();
 
                 Intent intentExisting = new Intent();
                 intentExisting.putExtra(SUCCESS, true);
-                intentExisting.putExtra(ARG_POSITION, getArguments().getInt(ARG_POSITION));
+                intentExisting.putExtra(ARG_POSITION, requireArguments().getInt(ARG_POSITION));
                 getTargetFragment().onActivityResult(getTargetRequestCode(),
-                        SETUP_ENCRYPTION_RESULT_CODE, intentExisting);
+                                                     SETUP_ENCRYPTION_RESULT_CODE, intentExisting);
             }
         }
     }
@@ -416,4 +399,36 @@ public class SetupEncryptionDialogFragment extends DialogFragment {
 
         return stringBuilder.toString();
     }
+
+    @VisibleForTesting
+    public void showMnemonicInfo() {
+        requireDialog().setTitle(R.string.end_to_end_encryption_passphrase_title);
+
+        textView.setText(R.string.end_to_end_encryption_keywords_description);
+
+        passphraseTextView.setText(generateMnemonicString(true));
+
+        passphraseTextView.setVisibility(View.VISIBLE);
+        positiveButton.setText(R.string.end_to_end_encryption_confirm_button);
+        positiveButton.setVisibility(View.VISIBLE);
+
+        negativeButton.setVisibility(View.VISIBLE);
+
+        keyResult = KEY_GENERATE;
+    }
+
+    @VisibleForTesting
+    public void errorSavingKeys() {
+        keyResult = KEY_FAILED;
+
+        requireDialog().setTitle(R.string.common_error);
+        textView.setText(R.string.end_to_end_encryption_unsuccessful);
+        positiveButton.setText(R.string.end_to_end_encryption_dialog_close);
+        positiveButton.setVisibility(View.VISIBLE);
+    }
+
+    @VisibleForTesting
+    public void setMnemonic(List<String> keyWords) {
+        this.keyWords = keyWords;
+    }
 }

+ 1 - 1
src/main/res/drawable/e2e_border.xml

@@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
        android:shape="rectangle">
     <stroke
         android:width="1dp"
-        android:color="#000000"/>
+        android:color="@color/dark" />
 
     <solid android:color="@color/grey_200"/>
 </shape>

+ 2 - 0
src/main/res/values-night/colors.xml

@@ -26,10 +26,12 @@
     <color name="list_divider_background">#222222</color>
 
     <!-- Colors -->
+    <color name="dark">#ffffff</color>
     <color name="bg_default">#121212</color>
     <color name="fg_contrast">#717171</color>
     <color name="primary_button_text_color">#000000</color>
     <color name="bg_elevation_one">#2D2D2D</color>
+    <color name="grey_200">#818181</color>
 
     <!-- Multiselect backgrounds -->
     <color name="action_mode_background">@color/appbar</color>

+ 1 - 1
src/main/res/values/colors.xml

@@ -37,7 +37,6 @@
 
     <!-- Colors -->
     <color name="standard_grey">#757575</color>
-    <color name="grey_200">#EEEEEE</color>
     <color name="grey_db">#dbdbdb</color>
     <color name="actionbar_shadow">#222222</color>
 
@@ -47,6 +46,7 @@
     <color name="infolevel_warning">#e9322d</color>
 
     <!-- Colors -->
+    <color name="dark">#000000</color>
     <color name="login_btn_tint">#ffffff</color>
     <color name="login_btn_stroke">#ffffff</color>
     <color name="bg_default">#FFFFFF</color>