浏览代码

Fix #130

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 6 年之前
父节点
当前提交
6dc99607c1

+ 24 - 18
app/src/main/java/com/nextcloud/talk/controllers/bottomsheet/EntryMenuController.java

@@ -22,6 +22,7 @@ package com.nextcloud.talk.controllers.bottomsheet;
 
 import android.content.ComponentName;
 import android.content.Intent;
+import android.content.res.ColorStateList;
 import android.os.Bundle;
 import android.text.Editable;
 import android.text.InputType;
@@ -32,12 +33,11 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.view.inputmethod.EditorInfo;
 import android.widget.Button;
-import androidx.annotation.NonNull;
-import autodagger.AutoInjector;
-import butterknife.BindView;
-import butterknife.OnClick;
+
 import com.bluelinelabs.conductor.RouterTransaction;
 import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
+import com.google.android.material.textfield.TextInputEditText;
+import com.google.android.material.textfield.TextInputLayout;
 import com.nextcloud.talk.R;
 import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.controllers.base.BaseController;
@@ -47,24 +47,28 @@ import com.nextcloud.talk.utils.ShareUtils;
 import com.nextcloud.talk.utils.bundle.BundleKeys;
 import com.nextcloud.talk.utils.database.user.UserUtils;
 import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder;
+
 import org.greenrobot.eventbus.EventBus;
 import org.parceler.Parcels;
-import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
-import studio.carbonylgroup.textfieldboxes.TextFieldBoxes;
 
 import javax.inject.Inject;
 
+import androidx.annotation.NonNull;
+import autodagger.AutoInjector;
+import butterknife.BindView;
+import butterknife.OnClick;
+
 @AutoInjector(NextcloudTalkApplication.class)
 public class EntryMenuController extends BaseController {
 
     @BindView(R.id.ok_button)
     Button proceedButton;
 
-    @BindView(R.id.extended_edit_text)
-    ExtendedEditText editText;
+    @BindView(R.id.text_edit)
+    TextInputEditText editText;
 
-    @BindView(R.id.text_field_boxes)
-    TextFieldBoxes textFieldBoxes;
+    @BindView(R.id.text_input_layout)
+    TextInputLayout textInputLayout;
 
     @Inject
     EventBus eventBus;
@@ -109,7 +113,7 @@ public class EntryMenuController extends BaseController {
         super.onAttach(view);
         if (ApplicationWideMessageHolder.getInstance().getMessageType() != null &&
                 ApplicationWideMessageHolder.getInstance().getMessageType().equals(ApplicationWideMessageHolder.MessageType.CALL_PASSWORD_WRONG)) {
-            textFieldBoxes.setError(getResources().getString(R.string.nc_wrong_password), true);
+            textInputLayout.setError(getResources().getString(R.string.nc_wrong_password));
             ApplicationWideMessageHolder.getInstance().setMessageType(null);
             if (proceedButton.isEnabled()) {
                 proceedButton.setEnabled(false);
@@ -214,19 +218,20 @@ public class EntryMenuController extends BaseController {
                                 proceedButton.setEnabled(true);
                                 proceedButton.setAlpha(1.0f);
                             }
+                            textInputLayout.setErrorEnabled(false);
                         } else {
                             if (proceedButton.isEnabled()) {
                                 proceedButton.setEnabled(false);
                                 proceedButton.setAlpha(0.38f);
                             }
-                            textFieldBoxes.setError(getResources().getString(R.string.nc_call_name_is_same),
-                                    true);
+                            textInputLayout.setError(getResources().getString(R.string.nc_call_name_is_same));
                         }
                     } else if (operationCode != 10) {
                         if (!proceedButton.isEnabled()) {
                             proceedButton.setEnabled(true);
                             proceedButton.setAlpha(1.0f);
                         }
+                        textInputLayout.setErrorEnabled(false);
                     } else if (editText.getText().toString().startsWith("http://") ||
                             editText.getText().toString().startsWith("https://") &&
                                     editText.getText().toString().contains("/call/")) {
@@ -234,21 +239,21 @@ public class EntryMenuController extends BaseController {
                         if (!proceedButton.isEnabled()) {
                             proceedButton.setEnabled(true);
                             proceedButton.setAlpha(1.0f);
-
                         }
+                        textInputLayout.setErrorEnabled(false);
                     } else {
                         if (proceedButton.isEnabled()) {
                             proceedButton.setEnabled(false);
                             proceedButton.setAlpha(0.38f);
                         }
-                        textFieldBoxes.setError(getResources().getString(R.string.nc_wrong_link),
-                                true);
+                        textInputLayout.setError(getResources().getString(R.string.nc_wrong_link));
                     }
                 } else {
                     if (proceedButton.isEnabled()) {
                         proceedButton.setEnabled(false);
                         proceedButton.setAlpha(0.38f);
                     }
+                    textInputLayout.setErrorEnabled(false);
                 }
             }
         });
@@ -279,7 +284,8 @@ public class EntryMenuController extends BaseController {
                 break;
         }
 
-        textFieldBoxes.setLabelText(labelText);
-        textFieldBoxes.requestFocus();
+        textInputLayout.setPasswordVisibilityToggleEnabled(operationCode == 99 || operationCode == 4 || operationCode == 6 || operationCode == 7);
+        textInputLayout.setHint(labelText);
+        textInputLayout.requestFocus();
     }
 }

+ 39 - 0
app/src/main/res/drawable/asl_password_visibility.xml

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright 2016 Google Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+
+<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item
+        android:id="@+id/visible"
+        android:state_checked="true"
+        android:drawable="@drawable/ic_password_visible" />
+
+    <item
+        android:id="@+id/masked"
+        android:drawable="@drawable/ic_password_masked" />
+
+    <transition
+        android:fromId="@id/masked"
+        android:toId="@id/visible"
+        android:drawable="@drawable/avd_show_password" />
+
+    <transition
+        android:fromId="@id/visible"
+        android:toId="@id/masked"
+        android:drawable="@drawable/avd_hide_password" />
+
+</animated-selector>

+ 85 - 0
app/src/main/res/drawable/avd_hide_password.xml

@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright 2015 Google Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+
+<animated-vector
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:aapt="http://schemas.android.com/aapt">
+
+    <aapt:attr name="android:drawable">
+
+        <vector
+            android:width="24dp"
+            android:height="24dp"
+            android:viewportWidth="24"
+            android:viewportHeight="24">
+
+            <path
+                android:name="strike_through"
+                android:pathData="@string/path_password_strike_through"
+                android:strokeColor="@android:color/white"
+                android:strokeWidth="1.8"
+                android:strokeLineCap="square" />
+
+            <group>
+
+                <clip-path
+                    android:name="eye_mask"
+                    android:pathData="@string/path_password_eye_mask_strike_through" />
+
+                <path
+                    android:name="eye"
+                    android:fillColor="@android:color/white"
+                    android:pathData="@string/path_password_eye" />
+
+            </group>
+
+        </vector>
+
+    </aapt:attr>
+
+    <target android:name="eye_mask">
+
+        <aapt:attr name="android:animation">
+
+            <objectAnimator
+                android:propertyName="pathData"
+                android:valueFrom="@string/path_password_eye_mask_strike_through"
+                android:valueTo="@string/path_password_eye_mask_visible"
+                android:duration="@integer/password_strike"
+                android:interpolator="@android:interpolator/fast_out_slow_in"
+                android:valueType="pathType" />
+
+        </aapt:attr>
+
+    </target>
+
+    <target android:name="strike_through">
+
+        <aapt:attr name="android:animation">
+
+            <objectAnimator
+                android:propertyName="trimPathEnd"
+                android:valueFrom="1"
+                android:valueTo="0"
+                android:duration="@integer/password_strike"
+                android:interpolator="@android:interpolator/fast_out_slow_in" />
+
+        </aapt:attr>
+
+    </target>
+
+</animated-vector>

+ 85 - 0
app/src/main/res/drawable/avd_show_password.xml

@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright 2015 Google Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+
+<animated-vector
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:aapt="http://schemas.android.com/aapt">
+
+    <aapt:attr name="android:drawable">
+
+        <vector
+            android:width="24dp"
+            android:height="24dp"
+            android:viewportWidth="24"
+            android:viewportHeight="24">
+
+            <path
+                android:name="strike_through"
+                android:pathData="@string/path_password_strike_through"
+                android:strokeColor="@android:color/white"
+                android:strokeWidth="1.8"
+                android:strokeLineCap="square" />
+
+            <group>
+
+                <clip-path
+                    android:name="eye_mask"
+                    android:pathData="@string/path_password_eye_mask_strike_through" />
+
+                <path
+                    android:name="eye"
+                    android:fillColor="@android:color/white"
+                    android:pathData="@string/path_password_eye" />
+
+            </group>
+
+        </vector>
+
+    </aapt:attr>
+
+    <target android:name="eye_mask">
+
+        <aapt:attr name="android:animation">
+
+            <objectAnimator
+                android:propertyName="pathData"
+                android:valueFrom="@string/path_password_eye_mask_strike_through"
+                android:valueTo="@string/path_password_eye_mask_visible"
+                android:duration="@integer/password_strike"
+                android:interpolator="@android:interpolator/fast_out_slow_in"
+                android:valueType="pathType" />
+
+        </aapt:attr>
+
+    </target>
+
+    <target android:name="strike_through">
+
+        <aapt:attr name="android:animation">
+
+            <objectAnimator
+                android:propertyName="trimPathEnd"
+                android:valueFrom="1"
+                android:valueTo="0"
+                android:duration="@integer/password_strike"
+                android:interpolator="@android:interpolator/fast_out_slow_in" />
+
+        </aapt:attr>
+
+    </target>
+
+</animated-vector>

+ 29 - 0
app/src/main/res/drawable/ic_password_masked.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright 2016 Google Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+
+<vector
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+
+    <path
+        android:pathData="M12,7c2.76,0 5,2.24 5,5 0,0.65 -0.13,1.26 -0.36,1.83l2.92,2.92c1.51,-1.26 2.7,-2.89 3.43,-4.75 -1.73,-4.39 -6,-7.5 -11,-7.5 -1.4,0 -2.74,0.25 -3.98,0.7l2.16,2.16C10.74,7.13 11.35,7 12,7zM2,4.27l2.28,2.28 0.46,0.46C3.08,8.3 1.78,10.02 1,12c1.73,4.39 6,7.5 11,7.5 1.55,0 3.03,-0.3 4.38,-0.84l0.42,0.42L19.73,22 21,20.73 3.27,3 2,4.27zM7.53,9.8l1.55,1.55c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.66 1.34,3 3,3 0.22,0 0.44,-0.03 0.65,-0.08l1.55,1.55c-0.67,0.33 -1.41,0.53 -2.2,0.53 -2.76,0 -5,-2.24 -5,-5 0,-0.79 0.2,-1.53 0.53,-2.2zM11.84,9.02l3.15,3.15 0.02,-0.16c0,-1.66 -1.34,-3 -3,-3l-0.17,0.01z"
+        android:fillColor="@android:color/white" />
+
+</vector>

+ 29 - 0
app/src/main/res/drawable/ic_password_visible.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright 2016 Google Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+
+<vector
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+
+    <path
+        android:pathData="@string/path_password_eye"
+        android:fillColor="@android:color/white" />
+
+</vector>

+ 15 - 16
app/src/main/res/layout/controller_entry_menu.xml

@@ -24,19 +24,18 @@
     android:layout_height="wrap_content"
     android:background="@color/nc_white_color">
 
-    <studio.carbonylgroup.textfieldboxes.TextFieldBoxes
-        android:id="@+id/text_field_boxes"
+    <com.google.android.material.textfield.TextInputLayout
+        android:id="@+id/text_input_layout"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginStart="@dimen/activity_horizontal_margin"
-        android:layout_marginEnd="@dimen/activity_horizontal_margin"
-        app:errorColor="@color/nc_darkRed"
-        app:helperText=" "
-        app:panelBackgroundColor="@color/nc_white_color"
-        app:primaryColor="@color/colorPrimary">
+        android:layout_margin="@dimen/activity_horizontal_margin"
+        app:errorTextAppearance="@style/ErrorAppearance"
+        app:passwordToggleDrawable="@drawable/asl_password_visibility"
+        app:passwordToggleTint="@color/grey_600"
+        app:helperText="">
 
-        <studio.carbonylgroup.textfieldboxes.ExtendedEditText
-            android:id="@+id/extended_edit_text"
+        <com.google.android.material.textfield.TextInputEditText
+            android:id="@+id/text_edit"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:imeOptions="actionDone"
@@ -44,22 +43,22 @@
             android:singleLine="true"
             android:textColor="@color/colorPrimary" />
 
-    </studio.carbonylgroup.textfieldboxes.TextFieldBoxes>
+    </com.google.android.material.textfield.TextInputLayout>
 
     <com.google.android.material.button.MaterialButton
         android:id="@+id/ok_button"
+        style="@style/Widget.MaterialComponents.Button.TextButton"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_below="@id/text_field_boxes"
         android:layout_alignParentEnd="true"
-        android:layout_marginTop="8dp"
-        android:layout_marginEnd="8dp"
+        android:layout_below="@id/text_input_layout"
         android:layout_marginBottom="12dp"
+        android:layout_marginEnd="8dp"
+        android:layout_marginTop="8dp"
         android:alpha="0.7"
-        style="@style/Widget.MaterialComponents.Button.TextButton"
         android:background="#0000"
         android:enabled="false"
         android:text="@string/nc_proceed"
         android:textColor="@color/colorPrimary" />
 
-</RelativeLayout>
+</RelativeLayout>

+ 6 - 0
app/src/main/res/values/styles.xml

@@ -9,4 +9,10 @@
         <item name="android:panelFullBackground">@color/colorPrimary</item>
         <item name="android:itemBackground">@color/colorPrimary</item>
     </style>
+
+    <style name="ErrorAppearance" parent="@android:style/TextAppearance">
+        <item name="android:textColor">@color/nc_darkRed</item>
+        <item name="android:textSize">12sp</item>
+    </style>
+
 </resources>