suggest previously assigned nick in Enter Name Activity

This commit is contained in:
Daniel Gultsch 2018-11-09 18:52:42 +01:00
parent 5012ff3545
commit e335c59600
3 changed files with 30 additions and 8 deletions

View file

@ -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;

View file

@ -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);
}

View file

@ -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();
}
}