Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Add a warning message when password is left empty. (#3867)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored Aug 25, 2020
1 parent 6f45e10 commit 864a696
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public void setSecondText(String text) {
mText2.setText(text);
mEdit2.setText(text);
}
mEdit2.selectAll();
}

public void setHint2(String hint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ public void setFirstText(String text) {
mText1.setText(mEdit1.getHint());
mEdit1.setText(mEdit1.getHint());
mEdit1.requestFocus();
mEdit1.selectAll();

} else {
mText1.setText(text);
mEdit1.setText(text);
}
mEdit1.selectAll();
}

public void setHint1(String hint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,36 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Point;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;

import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.VRBrowserApplication;
import org.mozilla.vrbrowser.databinding.OptionsEditLoginBinding;
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
import org.mozilla.vrbrowser.utils.SystemUtils;

import java.util.concurrent.Executor;

import mozilla.components.concept.storage.Login;

@SuppressLint("ViewConstructor")
class LoginEditOptionsView extends SettingsView {

static final String LOGTAG = SystemUtils.createLogtag(LoginEditOptionsView.class);

private OptionsEditLoginBinding mBinding;
private Login mLogin;
private Executor mUIThreadExecutor;

public LoginEditOptionsView(@NonNull Context aContext, @NonNull WidgetManagerDelegate aWidgetManager, @NonNull Login login) {
super(aContext, aWidgetManager);
mUIThreadExecutor = ((VRBrowserApplication)getContext().getApplicationContext()).getExecutors().mainThread();
mLogin = login;
initialize(aContext);
}
Expand Down Expand Up @@ -114,13 +123,9 @@ public boolean isEditing() {
mWidgetManager.openNewTabForeground(mLogin.getOrigin());
};

private OnClickListener mUsernameListener = (view) -> {
setUsername(mBinding.usernameEdit.getFirstText());
};
private OnClickListener mUsernameListener = (view) -> setUsername(mBinding.usernameEdit.getFirstText());

private OnClickListener mPasswordListener = (view) -> {
setPassword(mBinding.passwordEdit.getFirstText());
};
private OnClickListener mPasswordListener = (view) -> setPassword(mBinding.passwordEdit.getFirstText());

private OnClickListener mDelete = (view) -> {
mWidgetManager.getServicesProvider().getLoginStorage().delete(mLogin);
Expand All @@ -147,30 +152,45 @@ private void setUsername(String username) {
mLogin.getUsernameField(),
mLogin.getPasswordField()
);
mWidgetManager.getServicesProvider().getLoginStorage().update(newLogin);
mBinding.usernameEdit.setFirstText(username);
mWidgetManager.getServicesProvider().getLoginStorage().update(newLogin)
.thenAcceptAsync(unit -> mBinding.usernameEdit.setFirstText(username), mUIThreadExecutor)
.exceptionally(throwable -> {
Log.d(LOGTAG, String.valueOf(throwable.getMessage()));
return null;
});
}

private void setPassword(String password) {
mBinding.passwordEdit.setOnClickListener(null);
mBinding.passwordEdit.setFirstText(password);
mBinding.passwordEdit.setOnClickListener(mPasswordListener);
final Login newLogin = mLogin.copy(
mLogin.getGuid(),
mLogin.getOrigin(),
mLogin.getFormActionOrigin(),
mLogin.getHttpRealm(),
mLogin.getUsername(),
password,
mLogin.getTimesUsed(),
mLogin.getTimeCreated(),
mLogin.getTimeLastUsed(),
mLogin.getTimePasswordChanged(),
mLogin.getUsernameField(),
mLogin.getPasswordField()
);
mWidgetManager.getServicesProvider().getLoginStorage().update(newLogin);
mBinding.passwordEdit.setFirstText(password);
if (password.isEmpty()) {
mBinding.passwordEdit.cancel();
mBinding.passwordError.setVisibility(View.VISIBLE);

} else {
mBinding.passwordError.setVisibility(View.GONE);
mBinding.passwordEdit.setOnClickListener(null);
mBinding.passwordEdit.setFirstText(password);
mBinding.passwordEdit.setOnClickListener(mPasswordListener);
final Login newLogin = mLogin.copy(
mLogin.getGuid(),
mLogin.getOrigin(),
mLogin.getFormActionOrigin(),
mLogin.getHttpRealm(),
mLogin.getUsername(),
password,
mLogin.getTimesUsed(),
mLogin.getTimeCreated(),
mLogin.getTimeLastUsed(),
mLogin.getTimePasswordChanged(),
mLogin.getUsernameField(),
mLogin.getPasswordField()
);
mWidgetManager.getServicesProvider().getLoginStorage().update(newLogin)
.thenAcceptAsync(unit -> mBinding.passwordEdit.setFirstText(password), mUIThreadExecutor)
.exceptionally(throwable -> {
Log.d(LOGTAG, String.valueOf(throwable.getMessage()));
return null;
});
}
}

@Override
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/layout/options_edit_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@
app:description="@string/login_edit_dialog_password_description"
app:highlightedTextColor="@color/fog" />

<TextView
android:id="@+id/password_error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:scrollHorizontally="true"
android:singleLine="true"
android:layout_marginEnd="10dp"
android:text="@string/login_edit_password_empty_error"
android:textColor="@color/dessert"
android:textSize="@dimen/text_smaller_size"
tools:text="@string/login_edit_password_empty_error"
android:visibility="gone"/>

</LinearLayout>
</org.mozilla.vrbrowser.ui.views.CustomScrollView>

Expand Down
22 changes: 1 addition & 21 deletions app/src/main/res/layout/prompt_select_login_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,7 @@
android:paddingEnd="5dp"
android:singleLine="true"
android:text="@{login.username}"
tools:text="[email protected]"
app:visibleGone="@{!login.username.isEmpty()}"/>

<TextView
style="@style/settingsText"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_toEndOf="@id/icon"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:gravity="center_vertical"
android:maxLines="1"
android:ellipsize="end"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:singleLine="true"
android:textStyle="italic"
android:text="@string/autofill_item_autogenerated"
tools:text="@string/autofill_item_autogenerated"
app:visibleGone="@{login.username.isEmpty()}"/>
tools:text="[email protected]"/>
</RelativeLayout>
</FrameLayout>
</layout>
7 changes: 5 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2103,15 +2103,18 @@ the Select` button. When clicked it closes all the previously selected tabs -->
<!-- This string is shown inside the "Open" button of the edit login dialog. When pressed the site URL is opened.-->
<string name="login_edit_dialog_site_button">Open</string>

<!-- This string is shown in the "Open" button desicription of the edit login dialog. -->
<!-- This string is shown in the "Open" button description of the edit login dialog. -->
<string name="login_edit_dialog_site_description">Site</string>

<!-- This string is shown in the "Open" button desicription of the edit login dialog. -->
<!-- This string is shown in the "Open" button description of the edit login dialog. -->
<string name="login_edit_dialog_username_description">Username</string>

<!-- This string is shown in the "Open" button desicription of the edit login dialog. -->
<string name="login_edit_dialog_password_description">Password</string>

<!-- This string is shown under the password text edit in the Login edit dialog when the password is left empty. -->
<string name="login_edit_password_empty_error">The password cannot be empty</string>

<!-- This string is displayed in any edit text field where the value should be a username. -->
<string name="username_hint">username</string>

Expand Down

0 comments on commit 864a696

Please sign in to comment.