kopia lustrzana https://github.com/ryukoposting/Signal-Android
Add About presets.
rodzic
52a9f2c893
commit
36395ced89
|
@ -12,9 +12,13 @@ import android.widget.TextView;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.ListAdapter;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.signal.core.util.BreakIteratorCompat;
|
||||
import org.signal.core.util.EditTextUtil;
|
||||
|
@ -27,11 +31,15 @@ import org.thoughtcrime.securesms.reactions.any.ReactWithAnyEmojiBottomSheetDial
|
|||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.StringUtil;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
import org.thoughtcrime.securesms.util.adapter.AlwaysChangedDiffUtil;
|
||||
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
|
||||
import org.thoughtcrime.securesms.util.text.AfterTextChanged;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.crypto.ProfileCipher;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Let's you edit the 'About' section of your profile.
|
||||
*/
|
||||
|
@ -42,6 +50,16 @@ public class EditAboutFragment extends Fragment implements ManageProfileActivity
|
|||
|
||||
private static final String KEY_SELECTED_EMOJI = "selected_emoji";
|
||||
|
||||
private static final List<AboutPreset> PRESETS = Arrays.asList(
|
||||
new AboutPreset("\uD83D\uDC4B", R.string.EditAboutFragment_speak_freely),
|
||||
new AboutPreset("\uD83E\uDD10", R.string.EditAboutFragment_encrypted),
|
||||
new AboutPreset("\uD83D\uDE4F", R.string.EditAboutFragment_be_kind),
|
||||
new AboutPreset("☕", R.string.EditAboutFragment_coffee_lover),
|
||||
new AboutPreset("\uD83D\uDC4D", R.string.EditAboutFragment_free_to_chat),
|
||||
new AboutPreset("\uD83D\uDCF5", R.string.EditAboutFragment_taking_a_break),
|
||||
new AboutPreset("\uD83D\uDE80", R.string.EditAboutFragment_working_on_something_new)
|
||||
);
|
||||
|
||||
private ImageView emojiView;
|
||||
private EditText bodyView;
|
||||
private TextView countView;
|
||||
|
@ -77,6 +95,14 @@ public class EditAboutFragment extends Fragment implements ManageProfileActivity
|
|||
view.findViewById(R.id.edit_about_save).setOnClickListener(this::onSaveClicked);
|
||||
view.findViewById(R.id.edit_about_clear).setOnClickListener(v -> onClearClicked());
|
||||
|
||||
RecyclerView presetList = view.findViewById(R.id.edit_about_presets);
|
||||
PresetAdapter presetAdapter = new PresetAdapter();
|
||||
|
||||
presetList.setAdapter(presetAdapter);
|
||||
presetList.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||
|
||||
presetAdapter.submitList(PRESETS);
|
||||
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(KEY_SELECTED_EMOJI)) {
|
||||
onEmojiSelected(savedInstanceState.getString(KEY_SELECTED_EMOJI, ""));
|
||||
} else {
|
||||
|
@ -117,7 +143,6 @@ public class EditAboutFragment extends Fragment implements ManageProfileActivity
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void onSaveClicked(View view) {
|
||||
SimpleTask.run(getViewLifecycleOwner().getLifecycle(), () -> {
|
||||
DatabaseFactory.getRecipientDatabase(requireContext()).setAbout(Recipient.self().getId(), bodyView.getText().toString(), selectedEmoji);
|
||||
|
@ -140,4 +165,65 @@ public class EditAboutFragment extends Fragment implements ManageProfileActivity
|
|||
s.delete(trimmedLength, s.length());
|
||||
}
|
||||
}
|
||||
|
||||
private void onPresetSelected(@NonNull AboutPreset preset) {
|
||||
onEmojiSelected(preset.getEmoji());
|
||||
bodyView.setText(requireContext().getString(preset.getBodyRes()));
|
||||
}
|
||||
|
||||
private final class PresetAdapter extends ListAdapter<AboutPreset, PresetViewHolder> {
|
||||
|
||||
protected PresetAdapter() {
|
||||
super(new AlwaysChangedDiffUtil<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull PresetViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
return new PresetViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.about_preset_item, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull PresetViewHolder holder, int position) {
|
||||
AboutPreset preset = getItem(position);
|
||||
|
||||
holder.bind(preset);
|
||||
holder.itemView.setOnClickListener(v -> onPresetSelected(preset));
|
||||
}
|
||||
}
|
||||
|
||||
private final class PresetViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private final ImageView emoji;
|
||||
private final TextView body;
|
||||
|
||||
public PresetViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
this.emoji = itemView.findViewById(R.id.about_preset_emoji);
|
||||
this.body = itemView.findViewById(R.id.about_preset_body);
|
||||
}
|
||||
|
||||
public void bind(@NonNull AboutPreset preset) {
|
||||
this.emoji.setImageDrawable(EmojiUtil.convertToDrawable(itemView.getContext(), preset.getEmoji()));
|
||||
this.body.setText(preset.getBodyRes());
|
||||
}
|
||||
}
|
||||
|
||||
private static final class AboutPreset {
|
||||
private final String emoji;
|
||||
private final int bodyRes;
|
||||
|
||||
private AboutPreset(@NonNull String emoji, @StringRes int bodyRes) {
|
||||
this.emoji = emoji;
|
||||
this.bodyRes = bodyRes;
|
||||
}
|
||||
|
||||
public @NonNull String getEmoji() {
|
||||
return emoji;
|
||||
}
|
||||
|
||||
public @StringRes int getBodyRes() {
|
||||
return bodyRes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?selectableItemBackground">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/about_preset_emoji"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/about_preset_body"
|
||||
app:layout_constraintBottom_toBottomOf="@id/about_preset_body"
|
||||
tools:src="@drawable/ic_add_emoji"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/about_preset_body"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:paddingTop="17dp"
|
||||
android:paddingBottom="17dp"
|
||||
style="@style/Signal.Text.Body"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/about_preset_emoji"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
tools:text="Just hangin' around the web."/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -35,6 +35,7 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
style="@style/Signal.Text.Body"
|
||||
android:hint="@string/EditAboutFragment_write_a_few_words_about_yourself"
|
||||
|
@ -50,6 +51,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="20dp"
|
||||
app:srcCompat="@drawable/ic_x"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
app:tint="@color/signal_text_secondary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/edit_about_body"
|
||||
|
@ -65,6 +67,17 @@
|
|||
app:layout_constraintEnd_toEndOf="@id/edit_about_body"
|
||||
tools:text="75/100"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/edit_about_presets"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:paddingBottom="60dp"
|
||||
android:clipToPadding="false"
|
||||
android:clipChildren="false"
|
||||
app:layout_constraintTop_toBottomOf="@id/edit_about_count"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/edit_about_save"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -2003,6 +2003,13 @@
|
|||
<string name="EditAboutFragment_about">About</string>
|
||||
<string name="EditAboutFragment_write_a_few_words_about_yourself">Write a few words about yourself…</string>
|
||||
<string name="EditAboutFragment_count">%d/%d</string>
|
||||
<string name="EditAboutFragment_speak_freely">Speak freely</string>
|
||||
<string name="EditAboutFragment_encrypted">Encrypted</string>
|
||||
<string name="EditAboutFragment_be_kind">Be kind</string>
|
||||
<string name="EditAboutFragment_coffee_lover">Coffee lover</string>
|
||||
<string name="EditAboutFragment_free_to_chat">Free to chat</string>
|
||||
<string name="EditAboutFragment_taking_a_break">Taking a break</string>
|
||||
<string name="EditAboutFragment_working_on_something_new">Working on something new</string>
|
||||
|
||||
<!-- EditProfileFragment -->
|
||||
<string name="EditProfileFragment__edit_group_name_and_photo">Edit group name and photo</string>
|
||||
|
|
Ładowanie…
Reference in New Issue