mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
sending reactions (#2680)
* add basic reaction view * reuse pill background * make pill border a little more visible; this affects sended reactions as well as received ones * use 🤣 instead of 😂 to differ more from 😢 also, 😂 is a bit outdated for younger generations (so is probably 🤣 but not that much) (alternative would be 💀 for laughing, but that is probably not compatible between generations) * use 🙁 instead of 😢 for 'sad' to distict from lol lol gets revered to 😂 as 🤣 seems to be even a more non-go (thanks for expertise, young folks!) * wording: we add one reaction, not many * show/hide add-reaction-view together with action mode * pass message&view to showAddReactionView() * add sendReactions() api * create AddReactionView class * send reactions on click * hide AddReactiobView on sending emoji * detect self-reaction * feat: remove selections * position AddReactionView atop of parent view * move AddReactionView up a bit * padding top/bottom * center for now, this also postpones rtl/ltr * force initial layout * move slightly more off the bubble, keep away a bit from screen margin * move AddReactionsView left/right depending on incoming/outgoing mails * do not allow reactions in read-only chats * do not allow to react to videochat-invitations and info; the latter may makes sense at some point, however, to lower burder on other implementations, we do not send them for now * hide reaction-picker when leaving action mode with 'back' * hide reaction-picker when leaving action mode with 'back' * scroll reaction-panel together with recyclerview; this does not happen if new messages come in, however, this is a minor (and a stable panel position can be regarded even as a feature) * add sending reactions as an experimental feature as long not at least all system display reactions * clarify that reactions are currently not seen by all members * prefer View.INVISIBLE over offscreen hack
This commit is contained in:
@@ -70,4 +70,49 @@
|
||||
android:contentDescription="@string/menu_scroll_to_bottom"
|
||||
android:src="@drawable/ic_search_down"/>
|
||||
|
||||
<org.thoughtcrime.securesms.reactions.AddReactionView
|
||||
android:id="@+id/add_reaction_view"
|
||||
android:visibility="invisible"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="7dp"
|
||||
android:paddingEnd="7dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/reaction_pill_background">
|
||||
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
|
||||
android:id="@+id/reaction_0"
|
||||
android:text="👍"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/AddReaction"/>
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
|
||||
android:id="@+id/reaction_1"
|
||||
android:text="👎"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/AddReaction"/>
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
|
||||
android:id="@+id/reaction_2"
|
||||
android:text="❤️"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/AddReaction"/>
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
|
||||
android:id="@+id/reaction_3"
|
||||
android:text="😂"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/AddReaction"/>
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
|
||||
android:id="@+id/reaction_4"
|
||||
android:text="🙁"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/AddReaction"/>
|
||||
</org.thoughtcrime.securesms.reactions.AddReactionView>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
<color name="unknown_sender">#ff999999</color>
|
||||
|
||||
<color name="reaction_pill_background">#ffffff</color>
|
||||
<color name="reaction_pill_border">#80f1f1f1</color>
|
||||
<color name="reaction_pill_border">#88dddddd</color>
|
||||
<color name="reaction_pill_text_color">#545863</color>
|
||||
<color name="reaction_pill_background_selected">@color/gray5</color>
|
||||
<color name="reaction_pill_border_selected">@color/reaction_pill_border</color>
|
||||
|
||||
@@ -30,4 +30,11 @@
|
||||
<item name="android:textColor">?conversation_item_outgoing_text_secondary_color</item>
|
||||
<item name="android:shadowRadius">0</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
<style name="AddReaction" parent="Base.TextAppearance.AppCompat.Body1">
|
||||
<item name="android:paddingLeft">8sp</item>
|
||||
<item name="android:paddingRight">8sp</item>
|
||||
<item name="android:textSize">28sp</item>
|
||||
<item name="android:fontFamily">sans-serif</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
@@ -73,6 +73,11 @@
|
||||
android:key="pref_new_broadcast_list"
|
||||
android:title="@string/broadcast_lists"/>
|
||||
|
||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="pref_send_reactions"
|
||||
android:title="@string/reactions"/>
|
||||
|
||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="pref_location_streaming_enabled"
|
||||
|
||||
@@ -103,6 +103,9 @@ public class Rpc {
|
||||
return gson.fromJson(getResult("get_message_reactions", accountId, msgId), Reactions.class);
|
||||
}
|
||||
|
||||
public int sendReaction(int accountId, int msgId, String... reaction) throws RpcException {
|
||||
return getResult("send_reaction", accountId, msgId, reaction).getAsInt();
|
||||
}
|
||||
|
||||
private static class Request {
|
||||
private final String jsonrpc = "2.0";
|
||||
|
||||
@@ -207,7 +207,7 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
||||
|
||||
interface ItemClickListener extends BindableConversationItem.EventListener {
|
||||
void onItemClick(DcMsg item);
|
||||
void onItemLongClick(DcMsg item);
|
||||
void onItemLongClick(DcMsg item, View view);
|
||||
}
|
||||
|
||||
public ConversationAdapter(@NonNull Context context,
|
||||
@@ -263,7 +263,7 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
||||
});
|
||||
itemView.setOnLongClickListener(view -> {
|
||||
if (clickListener != null) {
|
||||
clickListener.onItemLongClick(itemView.getMessageRecord());
|
||||
clickListener.onItemLongClick(itemView.getMessageRecord(), view);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -63,6 +63,7 @@ import org.thoughtcrime.securesms.connect.DcEventCenter;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.reactions.AddReactionView;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.reactions.ReactionsDetailsFragment;
|
||||
import org.thoughtcrime.securesms.util.AccessibilityUtil;
|
||||
@@ -105,6 +106,7 @@ public class ConversationFragment extends MessageSelectorFragment
|
||||
private StickyHeaderDecoration dateDecoration;
|
||||
private View scrollToBottomButton;
|
||||
private View floatingLocationButton;
|
||||
private AddReactionView addReactionView;
|
||||
private TextView noMessageTextView;
|
||||
private Timer reloadTimer;
|
||||
|
||||
@@ -143,6 +145,7 @@ public class ConversationFragment extends MessageSelectorFragment
|
||||
list = ViewUtil.findById(view, android.R.id.list);
|
||||
scrollToBottomButton = ViewUtil.findById(view, R.id.scroll_to_bottom_button);
|
||||
floatingLocationButton = ViewUtil.findById(view, R.id.floating_location_button);
|
||||
addReactionView = ViewUtil.findById(view, R.id.add_reaction_view);
|
||||
noMessageTextView = ViewUtil.findById(view, R.id.no_messages_text_view);
|
||||
|
||||
scrollToBottomButton.setOnClickListener(v -> scrollToBottom());
|
||||
@@ -631,6 +634,8 @@ public class ConversationFragment extends MessageSelectorFragment
|
||||
// lastPositionId = positionId;
|
||||
|
||||
markseenDebouncer.publish(() -> manageMessageSeenState());
|
||||
|
||||
ConversationFragment.this.addReactionView.move(dy);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -774,6 +779,7 @@ public class ConversationFragment extends MessageSelectorFragment
|
||||
if (getListAdapter().getSelectedItems().size() == 0) {
|
||||
actionMode.finish();
|
||||
} else {
|
||||
addReactionView.hide();
|
||||
Menu menu = actionMode.getMenu();
|
||||
setCorrectMenuVisibility(menu);
|
||||
ConversationAdaptiveActionsToolbar.adjustMenuActions(menu, 10, requireActivity().getWindow().getDecorView().getMeasuredWidth());
|
||||
@@ -805,12 +811,17 @@ public class ConversationFragment extends MessageSelectorFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemLongClick(DcMsg messageRecord) {
|
||||
public void onItemLongClick(DcMsg messageRecord, View view) {
|
||||
if (actionMode == null) {
|
||||
((ConversationAdapter) list.getAdapter()).toggleSelection(messageRecord);
|
||||
list.getAdapter().notifyDataSetChanged();
|
||||
|
||||
actionMode = ((AppCompatActivity)getActivity()).startSupportActionMode(actionModeCallback);
|
||||
addReactionView.show(messageRecord, view, () -> {
|
||||
if (actionMode != null) {
|
||||
actionMode.finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -910,10 +921,12 @@ public class ConversationFragment extends MessageSelectorFragment
|
||||
}
|
||||
|
||||
actionMode = null;
|
||||
addReactionView.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
addReactionView.hide();
|
||||
switch(item.getItemId()) {
|
||||
case R.id.menu_context_copy:
|
||||
handleCopyMessage(getListAdapter().getSelectedItems());
|
||||
|
||||
@@ -146,6 +146,22 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
return true;
|
||||
});
|
||||
|
||||
Preference sendReactions = this.findPreference("pref_send_reactions");
|
||||
sendReactions.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
if ((Boolean)newValue) {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle("Thanks for trying out \"Reactions\"!")
|
||||
.setMessage("• By long tapping a message, you can now add a reaction\n\n"
|
||||
+ "• Do not rely on reactions being seen by all recipients currently: On some platforms they're still in development, also rolling out updates take time\n\n"
|
||||
+ "• If you want to quit the experimental feature, disable it again at \"Settings / Advanced\";"
|
||||
+ " received or already sent reactions are displayed independently of this switch")
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
Preference locationStreamingEnabled = this.findPreference("pref_location_streaming_enabled");
|
||||
locationStreamingEnabled.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
if ((Boolean)newValue) {
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
package org.thoughtcrime.securesms.reactions;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.b44t.messenger.DcContact;
|
||||
import com.b44t.messenger.DcContext;
|
||||
import com.b44t.messenger.DcMsg;
|
||||
import com.b44t.messenger.rpc.Reactions;
|
||||
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 Context context;
|
||||
private DcContext dcContext;
|
||||
private Rpc rpc;
|
||||
private DcMsg msgToReactTo;
|
||||
private AddReactionListener listener;
|
||||
|
||||
public AddReactionView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public AddReactionView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (context == null) {
|
||||
context = getContext();
|
||||
dcContext = DcHelper.getContext(context);
|
||||
rpc = DcHelper.getRpc(getContext());
|
||||
defaultReactionViews = new EmojiTextView[]{
|
||||
findViewById(R.id.reaction_0),
|
||||
findViewById(R.id.reaction_1),
|
||||
findViewById(R.id.reaction_2),
|
||||
findViewById(R.id.reaction_3),
|
||||
findViewById(R.id.reaction_4),
|
||||
};
|
||||
for (int i = 0; i < defaultReactionViews.length; i++) {
|
||||
final int ii = i;
|
||||
defaultReactionViews[i].setOnClickListener(v -> reactionClicked(ii));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void show(DcMsg msgToReactTo, View parentView, AddReactionListener listener) {
|
||||
init(); // init delayed as needed
|
||||
|
||||
if (!Prefs.getBooleanPreference(context, "pref_send_reactions", false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( msgToReactTo.isInfo()
|
||||
|| msgToReactTo.getType() == DcMsg.DC_MSG_VIDEOCHAT_INVITATION
|
||||
|| !dcContext.getChat(msgToReactTo.getChatId()).canSend()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.msgToReactTo = msgToReactTo;
|
||||
this.listener = listener;
|
||||
|
||||
final String existingReaction = getSelfReaction();
|
||||
for (EmojiTextView defaultReactionView : defaultReactionViews) {
|
||||
if (defaultReactionView.getText().toString().equals(existingReaction)) {
|
||||
defaultReactionView.setBackground(ContextCompat.getDrawable(context, R.drawable.reaction_pill_background_selected));
|
||||
} else {
|
||||
defaultReactionView.setBackground(null);
|
||||
}
|
||||
}
|
||||
|
||||
final int offset = (int)(this.getHeight() * 0.666);
|
||||
int x = (int)parentView.getX();
|
||||
if (msgToReactTo.isOutgoing()) {
|
||||
x += parentView.getWidth() - offset - this.getWidth();
|
||||
} else {
|
||||
x += offset;
|
||||
}
|
||||
ViewUtil.setLeftMargin(this, x);
|
||||
|
||||
int y = Math.max((int)parentView.getY() - offset, offset/2);
|
||||
ViewUtil.setTopMargin(this, y);
|
||||
|
||||
setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void move(int dy) {
|
||||
if (msgToReactTo != null && getVisibility() == View.VISIBLE) {
|
||||
ViewUtil.setTopMargin(this, (int) this.getY() - dy);
|
||||
}
|
||||
}
|
||||
|
||||
private String getSelfReaction() {
|
||||
String result = null;
|
||||
try {
|
||||
final Reactions reactions = rpc.getMsgReactions(dcContext.getAccountId(), msgToReactTo.getId());
|
||||
final Map<Integer, String[]> reactionsByContact = reactions.getReactionsByContact();
|
||||
final String [] selfReactions = reactionsByContact.get(DcContact.DC_CONTACT_ID_SELF);
|
||||
if (selfReactions != null && selfReactions.length > 0) {
|
||||
result = selfReactions[0];
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void reactionClicked(int i) {
|
||||
try {
|
||||
final String reaction = defaultReactionViews[i].getText().toString();
|
||||
if (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();
|
||||
}
|
||||
}
|
||||
|
||||
public interface AddReactionListener {
|
||||
void onShallHide();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user