mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
[android] Show existing alias in alias edit text view
This commit also uses LiveData Transformations to expose contact related information
This commit is contained in:
@@ -11,8 +11,9 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.EditText;
|
||||
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.briar.R;
|
||||
|
||||
@@ -24,7 +25,7 @@ public class AliasDialogFragment extends AppCompatDialogFragment {
|
||||
|
||||
private ConversationViewModel viewModel;
|
||||
private ContactId contactId;
|
||||
private TextView aliasEditText;
|
||||
private EditText aliasEditText;
|
||||
|
||||
public static AliasDialogFragment newInstance(ContactId id) {
|
||||
AliasDialogFragment f = new AliasDialogFragment();
|
||||
@@ -59,6 +60,10 @@ public class AliasDialogFragment extends AppCompatDialogFragment {
|
||||
false);
|
||||
|
||||
aliasEditText = v.findViewById(R.id.aliasEditText);
|
||||
Contact contact = viewModel.getContact().getValue();
|
||||
String alias = contact == null ? null : contact.getAlias();
|
||||
aliasEditText.setText(alias);
|
||||
if (alias != null) aliasEditText.setSelection(alias.length());
|
||||
|
||||
Button setButton = v.findViewById(R.id.setButton);
|
||||
setButton.setOnClickListener(v1 -> {
|
||||
|
||||
@@ -201,7 +201,7 @@ public class ConversationActivity extends BriarActivity
|
||||
viewModel.isContactDeleted().observe(this, deleted -> {
|
||||
if (deleted != null && deleted) finish();
|
||||
});
|
||||
viewModel.loadContactDetails(contactId);
|
||||
viewModel.loadContact(contactId);
|
||||
|
||||
setTransitionName(toolbarAvatar, getAvatarTransitionName(contactId));
|
||||
setTransitionName(toolbarStatus, getBulbTransitionName(contactId));
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.app.Application;
|
||||
import android.arch.lifecycle.AndroidViewModel;
|
||||
import android.arch.lifecycle.LiveData;
|
||||
import android.arch.lifecycle.MutableLiveData;
|
||||
import android.arch.lifecycle.Transformations;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
@@ -38,11 +39,13 @@ public class ConversationViewModel extends AndroidViewModel {
|
||||
@Inject
|
||||
ContactManager contactManager;
|
||||
|
||||
private final MutableLiveData<AuthorId> contactAuthorId =
|
||||
new MutableLiveData<>();
|
||||
private final MutableLiveData<Contact> contact = new MutableLiveData<>();
|
||||
private final LiveData<AuthorId> contactAuthorId =
|
||||
Transformations.map(contact, c -> c.getAuthor().getId());
|
||||
private final LiveData<String> contactName =
|
||||
Transformations.map(contact, UiUtils::getContactDisplayName);
|
||||
private final MutableLiveData<Boolean> contactDeleted =
|
||||
new MutableLiveData<>();
|
||||
private final MutableLiveData<String> contactName = new MutableLiveData<>();
|
||||
|
||||
public ConversationViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
@@ -52,13 +55,11 @@ public class ConversationViewModel extends AndroidViewModel {
|
||||
contactDeleted.setValue(false);
|
||||
}
|
||||
|
||||
void loadContactDetails(ContactId contactId) {
|
||||
void loadContact(ContactId contactId) {
|
||||
dbExecutor.execute(() -> {
|
||||
try {
|
||||
long start = now();
|
||||
Contact contact = contactManager.getContact(contactId);
|
||||
contactAuthorId.postValue(contact.getAuthor().getId());
|
||||
contactName.postValue(UiUtils.getContactDisplayName(contact));
|
||||
contact.postValue(contactManager.getContact(contactId));
|
||||
logDuration(LOG, "Loading contact", start);
|
||||
} catch (NoSuchContactException e) {
|
||||
contactDeleted.postValue(true);
|
||||
@@ -73,23 +74,27 @@ public class ConversationViewModel extends AndroidViewModel {
|
||||
try {
|
||||
contactManager.setContactAlias(contactId,
|
||||
alias.isEmpty() ? null : alias);
|
||||
loadContactDetails(contactId);
|
||||
loadContact(contactId);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
LiveData<AuthorId> getContactAuthorId() {
|
||||
return contactAuthorId;
|
||||
LiveData<Contact> getContact() {
|
||||
return contact;
|
||||
}
|
||||
|
||||
LiveData<Boolean> isContactDeleted() {
|
||||
return contactDeleted;
|
||||
LiveData<AuthorId> getContactAuthorId() {
|
||||
return contactAuthorId;
|
||||
}
|
||||
|
||||
LiveData<String> getContactDisplayName() {
|
||||
return contactName;
|
||||
}
|
||||
|
||||
LiveData<Boolean> isContactDeleted() {
|
||||
return contactDeleted;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user