Refresh username in onResume and utilize imeAction.

master
Alex Hart 2020-08-20 09:21:01 -03:00
parent 6cffd0a723
commit 7ac14dccda
4 changed files with 22 additions and 2 deletions

View File

@ -132,6 +132,12 @@ public class EditProfileFragment extends LoggingFragment {
initializeUsername();
}
@Override
public void onResume() {
super.onResume();
viewModel.refreshUsername();
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putByteArray(AVATAR_STATE, viewModel.getAvatarSnapshot());

View File

@ -37,8 +37,6 @@ class EditProfileViewModel extends ViewModel {
this.repository = repository;
this.groupId = groupId;
repository.getCurrentUsername(internalUsername::postValue);
if (!hasInstanceState) {
if (groupId != null) {
repository.getCurrentDisplayName(originalDisplayName::setValue);
@ -110,6 +108,10 @@ class EditProfileViewModel extends ViewModel {
internalAvatar.setValue(avatar);
}
public void refreshUsername() {
repository.getCurrentUsername(internalUsername::postValue);
}
public void submitProfile(Consumer<EditProfileRepository.UploadResult> uploadResultConsumer) {
ProfileName profileName = isGroup() ? ProfileName.EMPTY : internalProfileName.getValue();
String displayName = isGroup() ? givenName.getValue() : "";

View File

@ -2,9 +2,11 @@ package org.thoughtcrime.securesms.usernames.username;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@ -65,6 +67,13 @@ public class UsernameEditFragment extends LoggingFragment {
viewModel.onUsernameUpdated(text);
}
});
usernameInput.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_DONE) {
viewModel.onUsernameSubmitted(usernameInput.getText().toString());
return true;
}
return false;
});
}
private void onUiStateChanged(@NonNull UsernameEditViewModel.State state) {

View File

@ -16,6 +16,9 @@
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:hint="@string/CreateProfileActivity__create_a_username"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLines="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />