From e335c596003c080e87f4aeea258ea9e26a88129f Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 9 Nov 2018 18:52:42 +0100 Subject: [PATCH] suggest previously assigned nick in Enter Name Activity --- .../conversations/parser/MessageParser.java | 2 -- .../siacs/conversations/ui/XmppActivity.java | 5 +-- .../conversations/ui/EnterNameActivity.java | 31 +++++++++++++++++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index d6f79a163..ae3af375b 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -6,7 +6,6 @@ import android.util.Pair; import java.net.URL; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.List; @@ -20,7 +19,6 @@ import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.NotEncryptedForThisDeviceException; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage; import eu.siacs.conversations.entities.Account; -import eu.siacs.conversations.entities.Bookmark; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index fc60000dc..7125eb5b8 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -724,6 +724,7 @@ public abstract class XmppActivity extends ActionBarActivity { SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText); dialog.dismiss(); })); + dialog.setCanceledOnTouchOutside(false); dialog.setOnDismissListener(dialog1 -> { SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText); }); @@ -776,10 +777,6 @@ public abstract class XmppActivity extends ActionBarActivity { return false; } - protected boolean neverCompressPictures() { - return getPreferences().getString("picture_compression", getResources().getString(R.string.picture_compression)).equals("never"); - } - protected boolean manuallyChangePresence() { return getBooleanPreference(SettingsActivity.MANUALLY_CHANGE_PRESENCE, R.bool.manually_change_presence); } diff --git a/src/quicksy/java/eu/siacs/conversations/ui/EnterNameActivity.java b/src/quicksy/java/eu/siacs/conversations/ui/EnterNameActivity.java index 0702aa052..136cb8e31 100644 --- a/src/quicksy/java/eu/siacs/conversations/ui/EnterNameActivity.java +++ b/src/quicksy/java/eu/siacs/conversations/ui/EnterNameActivity.java @@ -6,23 +6,29 @@ import android.os.Bundle; import android.support.v7.widget.Toolbar; import android.view.View; +import java.util.concurrent.atomic.AtomicBoolean; + import eu.siacs.conversations.R; import eu.siacs.conversations.databinding.ActivityEnterNameBinding; import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.utils.AccountUtils; -public class EnterNameActivity extends XmppActivity { +public class EnterNameActivity extends XmppActivity implements XmppConnectionService.OnAccountUpdate { private ActivityEnterNameBinding binding; private Account account; + private AtomicBoolean setNick = new AtomicBoolean(false); + @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.binding = DataBindingUtil.setContentView(this, R.layout.activity_enter_name); setSupportActionBar((Toolbar) this.binding.toolbar); this.binding.next.setOnClickListener(this::next); + this.setNick.set(savedInstanceState != null && savedInstanceState.getBoolean("set_nick",false)); } private void next(View view) { @@ -43,12 +49,33 @@ public class EnterNameActivity extends XmppActivity { } @Override - protected void refreshUiReal() { + public void onSaveInstanceState(Bundle savedInstanceState) { + savedInstanceState.putBoolean("set_nick", this.setNick.get()); + super.onSaveInstanceState(savedInstanceState); + } + @Override + protected void refreshUiReal() { + checkSuggestPreviousNick(); } @Override void onBackendConnected() { this.account = AccountUtils.getFirst(xmppConnectionService); + checkSuggestPreviousNick(); + } + + private void checkSuggestPreviousNick() { + String displayName = this.account == null ? null : this.account.getDisplayName(); + if (displayName != null) { + if (setNick.compareAndSet(false, true) && this.binding.name.getText().length() == 0) { + this.binding.name.getText().append(displayName); + } + } + } + + @Override + public void onAccountUpdate() { + refreshUi(); } }