Reactions visual improvements
(cherry picked from commit 2c89fea7324a3135c91cfbcc7b992c411c8432d0)
This commit is contained in:
parent
2e570463fb
commit
5cba7472a6
4 changed files with 31 additions and 17 deletions
|
@ -1,6 +1,8 @@
|
||||||
package eu.siacs.conversations.ui;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
|
||||||
import com.google.android.material.chip.Chip;
|
import com.google.android.material.chip.Chip;
|
||||||
import com.google.android.material.chip.ChipGroup;
|
import com.google.android.material.chip.ChipGroup;
|
||||||
|
@ -41,6 +43,9 @@ public class BindingAdapters {
|
||||||
final Consumer<Collection<String>> onModifiedReactions,
|
final Consumer<Collection<String>> onModifiedReactions,
|
||||||
final Runnable addReaction) {
|
final Runnable addReaction) {
|
||||||
final var context = chipGroup.getContext();
|
final var context = chipGroup.getContext();
|
||||||
|
final var size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 35, context.getResources().getDisplayMetrics());
|
||||||
|
final var corner = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 35, context.getResources().getDisplayMetrics());
|
||||||
|
final var layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, size);
|
||||||
final List<Map.Entry<String, Integer>> reactions = aggregated.reactions;
|
final List<Map.Entry<String, Integer>> reactions = aggregated.reactions;
|
||||||
if (reactions == null || reactions.isEmpty()) {
|
if (reactions == null || reactions.isEmpty()) {
|
||||||
chipGroup.setVisibility(View.GONE);
|
chipGroup.setVisibility(View.GONE);
|
||||||
|
@ -51,9 +56,13 @@ public class BindingAdapters {
|
||||||
final var emoji = reaction.getKey();
|
final var emoji = reaction.getKey();
|
||||||
final var count = reaction.getValue();
|
final var count = reaction.getValue();
|
||||||
final Chip chip = new Chip(chipGroup.getContext());
|
final Chip chip = new Chip(chipGroup.getContext());
|
||||||
chip.setEnsureMinTouchTargetSize(false);
|
//chip.setEnsureMinTouchTargetSize(false);
|
||||||
|
chip.setChipMinHeight(size-32.0f);
|
||||||
|
chip.ensureAccessibleTouchTarget(size);
|
||||||
chip.setChipStartPadding(0.0f);
|
chip.setChipStartPadding(0.0f);
|
||||||
chip.setChipEndPadding(0.0f);
|
chip.setChipEndPadding(0.0f);
|
||||||
|
chip.setChipCornerRadius(corner);
|
||||||
|
chip.setLayoutParams(layoutParams);
|
||||||
if (count == 1) {
|
if (count == 1) {
|
||||||
chip.setText(emoji);
|
chip.setText(emoji);
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,22 +100,26 @@ public class BindingAdapters {
|
||||||
});
|
});
|
||||||
chipGroup.addView(chip);
|
chipGroup.addView(chip);
|
||||||
}
|
}
|
||||||
if (onReceived) {
|
if (addReaction != null) {
|
||||||
final Chip chip = new Chip(chipGroup.getContext());
|
final Chip chip = new Chip(chipGroup.getContext());
|
||||||
|
chip.setChipMinHeight(size-32.0f);
|
||||||
|
chip.ensureAccessibleTouchTarget(size);
|
||||||
|
chip.setLayoutParams(layoutParams);
|
||||||
|
chip.setChipCornerRadius(corner);
|
||||||
chip.setChipIconResource(R.drawable.ic_add_reaction_24dp);
|
chip.setChipIconResource(R.drawable.ic_add_reaction_24dp);
|
||||||
chip.setChipStrokeColor(
|
//chip.setChipStrokeColor(
|
||||||
MaterialColors.getColorStateListOrNull(
|
// MaterialColors.getColorStateListOrNull(
|
||||||
chipGroup.getContext(),
|
// chipGroup.getContext(),
|
||||||
com.google.android.material.R.attr.colorTertiary));
|
// com.google.android.material.R.attr.colorTertiary));
|
||||||
chip.setChipBackgroundColor(
|
chip.setChipBackgroundColor(
|
||||||
MaterialColors.getColorStateListOrNull(
|
MaterialColors.getColorStateListOrNull(
|
||||||
chipGroup.getContext(),
|
chipGroup.getContext(),
|
||||||
com.google.android.material.R.attr.colorTertiaryContainer));
|
com.google.android.material.R.attr.colorSurfaceContainerLow));
|
||||||
chip.setChipIconTint(
|
chip.setChipIconTint(
|
||||||
MaterialColors.getColorStateListOrNull(
|
MaterialColors.getColorStateListOrNull(
|
||||||
chipGroup.getContext(),
|
chipGroup.getContext(),
|
||||||
com.google.android.material.R.attr.colorOnTertiaryContainer));
|
com.google.android.material.R.attr.colorOnSurface));
|
||||||
chip.setEnsureMinTouchTargetSize(false);
|
//chip.setEnsureMinTouchTargetSize(false);
|
||||||
chip.setTextEndPadding(0.0f);
|
chip.setTextEndPadding(0.0f);
|
||||||
chip.setTextStartPadding(0.0f);
|
chip.setTextStartPadding(0.0f);
|
||||||
chip.setOnClickListener(v -> addReaction.run());
|
chip.setOnClickListener(v -> addReaction.run());
|
||||||
|
|
|
@ -1622,10 +1622,11 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
reactions -> sendReactions(message, reactions),
|
reactions -> sendReactions(message, reactions),
|
||||||
() -> addReaction(message));
|
() -> addReaction(message));
|
||||||
} else if (type == SENT) {
|
} else if (type == SENT) {
|
||||||
BindingAdapters.setReactionsOnSent(
|
BindingAdapters.setReactionsOnReceived(
|
||||||
viewHolder.reactions,
|
viewHolder.reactions,
|
||||||
message.getAggregatedReactions(),
|
message.getAggregatedReactions(),
|
||||||
reactions -> sendReactions(message, reactions));
|
reactions -> sendReactions(message, reactions),
|
||||||
|
() -> addReaction(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == RECEIVED || type == SENT) {
|
if (type == RECEIVED || type == SENT) {
|
||||||
|
|
|
@ -146,7 +146,7 @@
|
||||||
android:id="@+id/reactions_anchor"
|
android:id="@+id/reactions_anchor"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_marginBottom="4dp"
|
android:layout_marginBottom="12dp"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/message_box"
|
app:layout_constraintBottom_toBottomOf="@+id/message_box"
|
||||||
app:layout_constraintStart_toStartOf="@+id/message_box" />
|
app:layout_constraintStart_toStartOf="@+id/message_box" />
|
||||||
|
|
||||||
|
@ -154,10 +154,10 @@
|
||||||
android:id="@+id/reactions"
|
android:id="@+id/reactions"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="7dp"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:visibility="visible"
|
android:visibility="visible"
|
||||||
app:chipSpacingHorizontal="4dp"
|
app:chipSpacingHorizontal="2dp"
|
||||||
app:layout_constraintHorizontal_bias="0.0"
|
app:layout_constraintHorizontal_bias="0.0"
|
||||||
app:layout_constraintStart_toStartOf="@+id/message_box"
|
app:layout_constraintStart_toStartOf="@+id/message_box"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/reactions_anchor" />
|
app:layout_constraintTop_toBottomOf="@+id/reactions_anchor" />
|
||||||
|
|
|
@ -154,7 +154,7 @@
|
||||||
android:id="@+id/reactions_anchor"
|
android:id="@+id/reactions_anchor"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_marginBottom="4dp"
|
android:layout_marginBottom="12dp"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/message_box"
|
app:layout_constraintBottom_toBottomOf="@+id/message_box"
|
||||||
app:layout_constraintEnd_toEndOf="@+id/message_box" />
|
app:layout_constraintEnd_toEndOf="@+id/message_box" />
|
||||||
|
|
||||||
|
@ -162,10 +162,10 @@
|
||||||
android:id="@+id/reactions"
|
android:id="@+id/reactions"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="10dp"
|
android:layout_marginEnd="7dp"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:visibility="visible"
|
android:visibility="visible"
|
||||||
app:chipSpacingHorizontal="4dp"
|
app:chipSpacingHorizontal="2dp"
|
||||||
app:layout_constraintEnd_toEndOf="@+id/message_box"
|
app:layout_constraintEnd_toEndOf="@+id/message_box"
|
||||||
app:layout_constraintHorizontal_bias="0.0"
|
app:layout_constraintHorizontal_bias="0.0"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/reactions_anchor" />
|
app:layout_constraintTop_toBottomOf="@+id/reactions_anchor" />
|
||||||
|
|
Loading…
Add table
Reference in a new issue