Show further emojis for reaction

This commit is contained in:
Arne 2024-10-13 11:27:46 +02:00
parent 6b6619de6e
commit a0f79aede8
6 changed files with 122 additions and 10 deletions

View file

@ -393,6 +393,7 @@
android:name=".ui.MediaBrowserActivity"
android:label="@string/media_browser"
android:exported="false" />
<activity android:name=".ui.AddReactionActivity" />
<activity
android:name="eu.siacs.conversations.medialib.activities.EditActivity"

View file

@ -0,0 +1,63 @@
package eu.siacs.conversations.ui;
import android.os.Bundle;
import android.widget.Toast;
import androidx.databinding.DataBindingUtil;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.ActivityAddReactionBinding;
public class AddReactionActivity extends XmppActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ActivityAddReactionBinding binding =
DataBindingUtil.setContentView(this, R.layout.activity_add_reaction);
Activities.setStatusAndNavigationBarColors(this, binding.getRoot());
setSupportActionBar(binding.toolbar);
binding.toolbar.setNavigationIcon(R.drawable.ic_clear_24dp);
binding.toolbar.setNavigationOnClickListener(v -> finish());
setTitle(R.string.add_reaction_title);
binding.emojiPicker.setOnEmojiPickedListener(
emojiViewItem -> addReaction(emojiViewItem.getEmoji()));
}
private void addReaction(final String emoji) {
final var intent = getIntent();
final var conversation = intent == null ? null : intent.getStringExtra("conversation");
final var message = intent == null ? null : intent.getStringExtra("message");
if (Strings.isNullOrEmpty(conversation) || Strings.isNullOrEmpty(message)) {
Toast.makeText(this, R.string.could_not_add_reaction, Toast.LENGTH_LONG).show();
return;
}
final var c = xmppConnectionService.findConversationByUuid(conversation);
final var m = c == null ? null : c.findMessageWithUuid(message);
if (m == null) {
Toast.makeText(this, R.string.could_not_add_reaction, Toast.LENGTH_LONG).show();
return;
}
final var aggregated = m.getAggregatedReactions();
if (aggregated.ourReactions.contains(emoji)) {
xmppConnectionService.sendReactions(m, aggregated.ourReactions);
} else {
final ImmutableSet.Builder<String> reactionBuilder = new ImmutableSet.Builder<>();
reactionBuilder.addAll(aggregated.ourReactions);
reactionBuilder.add(emoji);
xmppConnectionService.sendReactions(m, reactionBuilder.build());
}
finish();
}
@Override
protected void refreshUiReal() {}
@Override
protected void onBackendConnected() {}
}

View file

@ -360,6 +360,14 @@ public abstract class XmppActivity extends ActionBarActivity {
popupWindow.dismiss();
});
}
viewBinding.more.setOnClickListener(
v -> {
popupWindow.dismiss();
final var intent = new Intent(this, AddReactionActivity.class);
intent.putExtra("conversation", message.getConversation().getUuid());
intent.putExtra("message", message.getUuid());
startActivity(intent);
});
popupWindow.setAnimationStyle(androidx.appcompat.R.style.Animation_AppCompat_Tooltip);
popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(this,R.drawable.reactions_bubble));
popupWindow.setFocusable(true);

View file

@ -0,0 +1,25 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.emoji2.emojipicker.EmojiPickerView
android:id="@+id/emoji_picker"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</layout>

View file

@ -1,18 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<com.google.android.material.button.MaterialButtonGroup
android:layout_centerInParent="true"
android:id="@+id/emojis"
style="@style/Widget.Material3.MaterialButtonGroup.Connected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="?dialogPreferredPadding" />
android:padding="?dialogPreferredPadding">
<com.google.android.material.button.MaterialButtonGroup
android:id="@+id/emojis"
style="@style/Widget.Material3.MaterialButtonGroup.Connected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<Button
android:id="@+id/more"
style="?attr/materialIconButtonFilledStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/emojis"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:contentDescription="@string/more_reactions"
app:icon="@drawable/ic_more_horiz_24dp" />
</RelativeLayout>
</layout>

View file

@ -1166,4 +1166,6 @@
<string name="could_not_add_reaction">Could not add reaction</string>
<string name="add_reaction">Add reaction…</string>
<string name="related_chats">Related chats</string>
<string name="add_reaction_title">Add reaction</string>
<string name="more_reactions">More reactions</string>
</resources>