Commit d7bf1ee3 authored by akwizgran's avatar akwizgran
Browse files

Merge branch '1367-db-header-corrupt' into 'master'

Fix duplicate actions triggered by hardware keyboard

Closes #1367

See merge request !921
parents 049cf3ad 10bee058
......@@ -159,6 +159,7 @@ class AccountManagerImpl implements AccountManager {
@Override
public boolean createAccount(String name, String password) {
synchronized (stateChangeLock) {
// TODO don't allow creating another account if one already exists
LocalAuthor localAuthor = identityManager.createLocalAuthor(name);
identityManager.registerLocalAuthor(localAuthor);
SecretKey key = crypto.generateSecretKey();
......
......@@ -27,11 +27,13 @@ import javax.inject.Inject;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.view.inputmethod.EditorInfo.IME_ACTION_DONE;
import static android.widget.Toast.LENGTH_LONG;
import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logDuration;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.LogUtils.now;
import static org.briarproject.briar.android.util.UiUtils.enterPressed;
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_NAME_LENGTH;
@MethodsNotNullByDefault
......@@ -76,8 +78,11 @@ public class CreateForumActivity extends BriarActivity {
}
});
nameEntry.setOnEditorActionListener((v, actionId, e) -> {
createForum();
return true;
if (actionId == IME_ACTION_DONE || enterPressed(actionId, e)) {
createForum();
return true;
}
return false;
});
createForumButton = findViewById(R.id.createForumButton);
......
......@@ -25,6 +25,8 @@ import javax.inject.Inject;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static android.view.inputmethod.EditorInfo.IME_ACTION_DONE;
import static org.briarproject.briar.android.util.UiUtils.enterPressed;
public class PasswordActivity extends BaseActivity {
......@@ -63,8 +65,11 @@ public class PasswordActivity extends BaseActivity {
input = findViewById(R.id.password_layout);
password = findViewById(R.id.edit_password);
password.setOnEditorActionListener((v, actionId, event) -> {
validatePassword();
return true;
if (actionId == IME_ACTION_DONE || enterPressed(actionId, event)) {
validatePassword();
return true;
}
return false;
});
password.addTextChangedListener(new TextWatcher() {
......
......@@ -22,6 +22,7 @@ import javax.annotation.Nullable;
import static android.content.Context.INPUT_METHOD_SERVICE;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static android.view.inputmethod.EditorInfo.IME_ACTION_DONE;
import static org.briarproject.bramble.api.crypto.PasswordStrengthEstimator.QUITE_WEAK;
@MethodsNotNullByDefault
......@@ -78,6 +79,7 @@ public class PasswordFragment extends SetupFragment {
// the controller is not yet available in onCreateView()
if (!setupController.needToShowDozeFragment()) {
nextButton.setText(R.string.create_account_button);
passwordConfirmation.setImeOptions(IME_ACTION_DONE);
}
}
......
package org.briarproject.briar.android.login;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
......@@ -10,13 +11,18 @@ import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.briar.R;
import org.briarproject.briar.android.fragment.BaseFragment;
import javax.inject.Inject;
import static android.view.inputmethod.EditorInfo.IME_ACTION_DONE;
import static android.view.inputmethod.EditorInfo.IME_ACTION_NEXT;
import static org.briarproject.briar.android.util.UiUtils.enterPressed;
import static org.briarproject.briar.android.util.UiUtils.showOnboardingDialog;
@NotNullByDefault
abstract class SetupFragment extends BaseFragment implements TextWatcher,
OnEditorActionListener, OnClickListener {
......@@ -55,9 +61,13 @@ abstract class SetupFragment extends BaseFragment implements TextWatcher,
@Override
public boolean onEditorAction(TextView textView, int actionId,
KeyEvent keyEvent) {
onClick(textView);
return true;
@Nullable KeyEvent keyEvent) {
if (actionId == IME_ACTION_NEXT || actionId == IME_ACTION_DONE ||
enterPressed(actionId, keyEvent)) {
onClick(textView);
return true;
}
return false;
}
@Override
......
......@@ -19,6 +19,8 @@ import org.briarproject.briar.android.fragment.BaseFragment;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.view.inputmethod.EditorInfo.IME_ACTION_DONE;
import static org.briarproject.briar.android.util.UiUtils.enterPressed;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH;
public class CreateGroupFragment extends BaseFragment {
......@@ -62,8 +64,11 @@ public class CreateGroupFragment extends BaseFragment {
}
});
nameEntry.setOnEditorActionListener((v1, actionId, e) -> {
createGroup();
return true;
if (actionId == IME_ACTION_DONE || enterPressed(actionId, e)) {
createGroup();
return true;
}
return false;
});
nameLayout = v.findViewById(R.id.nameLayout);
......
......@@ -11,6 +11,7 @@ import android.os.PowerManager;
import android.support.annotation.AttrRes;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputLayout;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
......@@ -27,6 +28,7 @@ import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.URLSpan;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;
......@@ -39,8 +41,6 @@ import org.briarproject.briar.R;
import org.briarproject.briar.android.view.ArticleMovementMethod;
import org.briarproject.briar.android.widget.LinkDialogFragment;
import javax.annotation.Nullable;
import static android.content.Context.KEYGUARD_SERVICE;
import static android.content.Context.POWER_SERVICE;
import static android.content.Intent.CATEGORY_DEFAULT;
......@@ -60,6 +60,10 @@ import static android.text.format.DateUtils.FORMAT_ABBREV_TIME;
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
import static android.text.format.DateUtils.WEEK_IN_MILLIS;
import static android.view.KeyEvent.ACTION_DOWN;
import static android.view.KeyEvent.ACTION_UP;
import static android.view.KeyEvent.KEYCODE_ENTER;
import static android.view.inputmethod.EditorInfo.IME_NULL;
import static org.briarproject.briar.BuildConfig.APPLICATION_ID;
import static org.briarproject.briar.android.TestingConstants.EXPIRY_DATE;
......@@ -288,4 +292,12 @@ public class UiUtils {
.handleException(new UserFeedback(), false));
}
public static boolean enterPressed(int actionId,
@Nullable KeyEvent keyEvent) {
return actionId == IME_NULL &&
keyEvent != null &&
keyEvent.getAction() == ACTION_DOWN &&
keyEvent.getKeyCode() == KEYCODE_ENTER;
}
}
......@@ -71,6 +71,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/confirm_password"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:maxLines="1"/>
</android.support.design.widget.TextInputLayout>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment