Update contact name editor.

This commit is contained in:
Alex Hart 2022-07-15 13:18:38 -03:00 committed by Cody Henthorne
parent 00d5724cec
commit 17b00734ac
5 changed files with 82 additions and 46 deletions

View file

@ -7,11 +7,10 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.lifecycle.ViewModelProviders; import androidx.lifecycle.ViewModelProvider;
import org.thoughtcrime.securesms.PassphraseRequiredActivity; import org.thoughtcrime.securesms.PassphraseRequiredActivity;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme; import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
import org.thoughtcrime.securesms.util.DynamicTheme; import org.thoughtcrime.securesms.util.DynamicTheme;
@ -22,10 +21,8 @@ public class ContactNameEditActivity extends PassphraseRequiredActivity {
public static final String KEY_NAME = "name"; public static final String KEY_NAME = "name";
public static final String KEY_CONTACT_INDEX = "contact_index"; public static final String KEY_CONTACT_INDEX = "contact_index";
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme(); private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
private TextView displayNameView;
private ContactNameEditViewModel viewModel; private ContactNameEditViewModel viewModel;
static Intent getIntent(@NonNull Context context, @NonNull Name name, int contactPosition) { static Intent getIntent(@NonNull Context context, @NonNull Name name, int contactPosition) {
@ -38,7 +35,6 @@ public class ContactNameEditActivity extends PassphraseRequiredActivity {
@Override @Override
protected void onPreCreate() { protected void onPreCreate() {
dynamicTheme.onCreate(this); dynamicTheme.onCreate(this);
dynamicLanguage.onCreate(this);
} }
@Override @Override
@ -59,16 +55,14 @@ public class ContactNameEditActivity extends PassphraseRequiredActivity {
initializeToolbar(); initializeToolbar();
initializeViews(name); initializeViews(name);
viewModel = ViewModelProviders.of(this).get(ContactNameEditViewModel.class); viewModel = new ViewModelProvider(this).get(ContactNameEditViewModel.class);
viewModel.setName(name); viewModel.setName(name);
viewModel.getDisplayName().observe(this, displayNameView::setText);
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
dynamicTheme.onResume(this); dynamicTheme.onResume(this);
dynamicLanguage.onResume(this);
} }
private void initializeToolbar() { private void initializeToolbar() {
@ -86,8 +80,6 @@ public class ContactNameEditActivity extends PassphraseRequiredActivity {
} }
private void initializeViews(@NonNull Name name) { private void initializeViews(@NonNull Name name) {
displayNameView = findViewById(R.id.name_edit_display_name);
TextView givenName = findViewById(R.id.name_edit_given_name); TextView givenName = findViewById(R.id.name_edit_given_name);
TextView familyName = findViewById(R.id.name_edit_family_name); TextView familyName = findViewById(R.id.name_edit_family_name);
TextView middleName = findViewById(R.id.name_edit_middle_name); TextView middleName = findViewById(R.id.name_edit_middle_name);

View file

@ -39,10 +39,6 @@ public class ContactNameEditViewModel extends ViewModel {
return new Name(displayName.getValue(), givenName, familyName, prefix, suffix, middleName); return new Name(displayName.getValue(), givenName, familyName, prefix, suffix, middleName);
} }
LiveData<String> getDisplayName() {
return displayName;
}
void updateGivenName(@NonNull String givenName) { void updateGivenName(@NonNull String givenName) {
this.givenName = givenName; this.givenName = givenName;
displayName.postValue(buildDisplayName()); displayName.postValue(buildDisplayName());

View file

@ -2,19 +2,19 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"> android:orientation="vertical">
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="@dimen/signal_m3_toolbar_height"
android:theme="?attr/actionBarStyle" android:minHeight="@dimen/signal_m3_toolbar_height"
android:minHeight="?attr/actionBarSize" app:navigationIcon="@drawable/ic_x"
android:elevation="4dp" app:title="@string/ContactShareEditActivity__edit_name"
app:navigationIcon="@drawable/ic_check_24_tinted" /> app:titleTextAppearance="@style/Signal.Text.TitleLarge" />
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
@ -23,46 +23,83 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical">
android:padding="12dp">
<org.thoughtcrime.securesms.components.emoji.EmojiTextView <com.google.android.material.textfield.TextInputLayout
android:id="@+id/name_edit_display_name" style="@style/Widget.Signal.TextInputLayout.FilledBox.ContactNameEditor"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="12dp" android:layout_marginBottom="16dp"
android:textSize="20sp" android:minHeight="56dp">
tools:text="Peter Parker"/>
<org.thoughtcrime.securesms.components.emoji.EmojiEditText <org.thoughtcrime.securesms.components.emoji.EmojiEditText
android:id="@+id/name_edit_prefix" android:id="@+id/name_edit_prefix"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/ContactNameEditActivity_prefix"
android:textAppearance="@style/Signal.Text.BodyLarge" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.Signal.TextInputLayout.FilledBox.ContactNameEditor"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/ContactNameEditActivity_prefix"/> android:layout_marginBottom="16dp"
android:minHeight="56dp">
<org.thoughtcrime.securesms.components.emoji.EmojiEditText <org.thoughtcrime.securesms.components.emoji.EmojiEditText
android:id="@+id/name_edit_given_name" android:id="@+id/name_edit_given_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/ContactNameEditActivity_given_name"
tools:text="@tools:sample/first_names"
android:textAppearance="@style/Signal.Text.BodyLarge" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.Signal.TextInputLayout.FilledBox.ContactNameEditor"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/ContactNameEditActivity_given_name"/> android:layout_marginBottom="16dp"
android:minHeight="56dp">
<org.thoughtcrime.securesms.components.emoji.EmojiEditText <org.thoughtcrime.securesms.components.emoji.EmojiEditText
android:id="@+id/name_edit_middle_name" android:id="@+id/name_edit_middle_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/ContactNameEditActivity_middle_name"
android:textAppearance="@style/Signal.Text.BodyLarge" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.Signal.TextInputLayout.FilledBox.ContactNameEditor"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/ContactNameEditActivity_middle_name"/> android:layout_marginBottom="16dp"
android:minHeight="56dp">
<org.thoughtcrime.securesms.components.emoji.EmojiEditText <org.thoughtcrime.securesms.components.emoji.EmojiEditText
android:id="@+id/name_edit_family_name" android:id="@+id/name_edit_family_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/ContactNameEditActivity_family_name"/> android:hint="@string/ContactNameEditActivity_family_name"
android:textAppearance="@style/Signal.Text.BodyLarge" />
</com.google.android.material.textfield.TextInputLayout>
<org.thoughtcrime.securesms.components.emoji.EmojiEditText <com.google.android.material.textfield.TextInputLayout
android:id="@+id/name_edit_suffix" style="@style/Widget.Signal.TextInputLayout.FilledBox.ContactNameEditor"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:hint="@string/ContactNameEditActivity_suffix"/>
<org.thoughtcrime.securesms.components.emoji.EmojiEditText
android:id="@+id/name_edit_suffix"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/ContactNameEditActivity_suffix"
android:textAppearance="@style/Signal.Text.BodyLarge" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout> </LinearLayout>

View file

@ -210,6 +210,8 @@
<string name="ContactsDatabase_signal_call_s">Signal Call %s</string> <string name="ContactsDatabase_signal_call_s">Signal Call %s</string>
<!-- ContactNameEditActivity --> <!-- ContactNameEditActivity -->
<!-- Toolbar title for contact name edit activity -->
<string name="ContactNameEditActivity__edit_name">Edit name</string>
<string name="ContactNameEditActivity_given_name">Given name</string> <string name="ContactNameEditActivity_given_name">Given name</string>
<string name="ContactNameEditActivity_family_name">Family name</string> <string name="ContactNameEditActivity_family_name">Family name</string>
<string name="ContactNameEditActivity_prefix">Prefix</string> <string name="ContactNameEditActivity_prefix">Prefix</string>

View file

@ -482,6 +482,15 @@
<item name="android:textColorHint">@color/signal_text_hint</item> <item name="android:textColorHint">@color/signal_text_hint</item>
</style> </style>
<style name="Widget.Signal.TextInputLayout.FilledBox.ContactNameEditor">
<item name="boxCornerRadiusBottomEnd">0dp</item>
<item name="boxCornerRadiusBottomStart">0dp</item>
<item name="boxStrokeWidth">1dp</item>
<item name="boxStrokeColor">@color/signal_colorOutline</item>
<item name="boxStrokeErrorColor">@color/signal_colorError</item>
<item name="hintTextAppearance">@style/Signal.Text.LabelMedium</item>
</style>
<style name="Widget.MaterialComponents.Button.TextButton.Dialog"> <style name="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:minWidth">@dimen/mtrl_btn_dialog_btn_min_width</item> <item name="android:minWidth">@dimen/mtrl_btn_dialog_btn_min_width</item>
<!-- Allow buttons to span more than one line so that the end isn't cut <!-- Allow buttons to span more than one line so that the end isn't cut