mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
react with any emoji (#2979)
* add button to select any reaction * add emojipicker to build.gradle and manifest * fix build error * open reaction picker and send any reaction * use RelativeLayout as parent for EmojiPickerView * dismiss AlertDialog on emoji-selection * reduce columns to 8 like on iOS * disable "more reactions" button in android < 5 * show selected reactions instead of '...', this is what whatsapp, signal are doing * make '...' a bit less bold in light mode --------- Co-authored-by: adbenitez <asieldbenitez@gmail.com>
This commit is contained in:
@@ -40,6 +40,9 @@
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
|
||||
<!-- force compiling emojipicker on sdk<21; we'll add a runtime switch to not use the picker in this case -->
|
||||
<uses-sdk tools:overrideLibrary="androidx.emoji2.emojipicker"/>
|
||||
|
||||
<application android:name=".ApplicationContext"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
|
||||
@@ -31,6 +31,8 @@ dependencies {
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.6.2'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
|
||||
implementation 'androidx.work:work-runtime:2.8.1'
|
||||
implementation 'androidx.emoji2:emoji2-emojipicker:1.4.0'
|
||||
implementation 'com.google.guava:guava:29.0-android'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-core:2.9.6' // plays video and audio
|
||||
implementation 'com.google.android.exoplayer:exoplayer-ui:2.9.6'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
|
||||
@@ -113,6 +113,13 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/AddReaction"/>
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
|
||||
android:id="@+id/reaction_any"
|
||||
android:text="•••"
|
||||
android:textColor="?attr/pref_icon_tint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/AddReaction"/>
|
||||
</org.thoughtcrime.securesms.reactions.AddReactionView>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.emoji2.emojipicker.EmojiPickerView
|
||||
android:id="@+id/emoji_picker"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:emojiGridColumns="8"/>
|
||||
</RelativeLayout>
|
||||
@@ -1,11 +1,14 @@
|
||||
package org.thoughtcrime.securesms.reactions;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.emoji2.emojipicker.EmojiPickerView;
|
||||
|
||||
import com.b44t.messenger.DcContact;
|
||||
import com.b44t.messenger.DcContext;
|
||||
@@ -16,13 +19,14 @@ import com.b44t.messenger.rpc.Rpc;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiTextView;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AddReactionView extends LinearLayout {
|
||||
private EmojiTextView [] defaultReactionViews;
|
||||
private EmojiTextView anyReactionView;
|
||||
private boolean anyReactionClearsReaction;
|
||||
private Context context;
|
||||
private DcContext dcContext;
|
||||
private Rpc rpc;
|
||||
@@ -51,7 +55,12 @@ public class AddReactionView extends LinearLayout {
|
||||
};
|
||||
for (int i = 0; i < defaultReactionViews.length; i++) {
|
||||
final int ii = i;
|
||||
defaultReactionViews[i].setOnClickListener(v -> reactionClicked(ii));
|
||||
defaultReactionViews[i].setOnClickListener(v -> defaultReactionClicked(ii));
|
||||
}
|
||||
anyReactionView = findViewById(R.id.reaction_any);
|
||||
anyReactionView.setOnClickListener(v -> anyReactionClicked());
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
anyReactionView.setVisibility(View.GONE); // EmojiPickerView requires SDK 21 or newer
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,14 +78,26 @@ public class AddReactionView extends LinearLayout {
|
||||
this.listener = listener;
|
||||
|
||||
final String existingReaction = getSelfReaction();
|
||||
boolean existingHilited = false;
|
||||
for (EmojiTextView defaultReactionView : defaultReactionViews) {
|
||||
if (defaultReactionView.getText().toString().equals(existingReaction)) {
|
||||
defaultReactionView.setBackground(ContextCompat.getDrawable(context, R.drawable.reaction_pill_background_selected));
|
||||
existingHilited = true;
|
||||
} else {
|
||||
defaultReactionView.setBackground(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (existingReaction != null && !existingHilited) {
|
||||
anyReactionView.setText(existingReaction);
|
||||
anyReactionView.setBackground(ContextCompat.getDrawable(context, R.drawable.reaction_pill_background_selected));
|
||||
anyReactionClearsReaction = true;
|
||||
} else {
|
||||
anyReactionView.setText("•••");
|
||||
anyReactionView.setBackground(null);
|
||||
anyReactionClearsReaction = false;
|
||||
}
|
||||
|
||||
final int offset = (int)(this.getHeight() * 0.666);
|
||||
int x = (int)parentView.getX();
|
||||
if (msgToReactTo.isOutgoing()) {
|
||||
@@ -117,17 +138,48 @@ public class AddReactionView extends LinearLayout {
|
||||
return result;
|
||||
}
|
||||
|
||||
private void reactionClicked(int i) {
|
||||
private void defaultReactionClicked(int i) {
|
||||
final String reaction = defaultReactionViews[i].getText().toString();
|
||||
sendReaction(reaction);
|
||||
|
||||
if (listener != null) {
|
||||
listener.onShallHide();
|
||||
}
|
||||
}
|
||||
|
||||
private void anyReactionClicked() {
|
||||
if (anyReactionClearsReaction) {
|
||||
sendReaction(null);
|
||||
} else {
|
||||
View pickerLayout = View.inflate(context, R.layout.reaction_picker, null);
|
||||
|
||||
final AlertDialog alertDialog = new AlertDialog.Builder(context)
|
||||
.setView(pickerLayout)
|
||||
.setTitle(R.string.react)
|
||||
.setPositiveButton(R.string.cancel, null)
|
||||
.create();
|
||||
|
||||
EmojiPickerView pickerView = ViewUtil.findById(pickerLayout, R.id.emoji_picker);
|
||||
pickerView.setOnEmojiPickedListener((it) -> {
|
||||
sendReaction(it.getEmoji());
|
||||
alertDialog.dismiss();
|
||||
});
|
||||
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
if (listener != null) {
|
||||
listener.onShallHide();
|
||||
}
|
||||
}
|
||||
|
||||
private void sendReaction(final String reaction) {
|
||||
try {
|
||||
final String reaction = defaultReactionViews[i].getText().toString();
|
||||
if (reaction.equals(getSelfReaction())) {
|
||||
if (reaction == null || reaction.equals(getSelfReaction())) {
|
||||
rpc.sendReaction(dcContext.getAccountId(), msgToReactTo.getId(), "");
|
||||
} else {
|
||||
rpc.sendReaction(dcContext.getAccountId(), msgToReactTo.getId(), reaction);
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onShallHide();
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user