mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-03 17:59:39 +02:00
Merge pull request #3786 from deltachat/adb/improve-reactions-dialog
allow to react with same emoji as others
This commit is contained in:
commit
0cc58006ba
4 changed files with 59 additions and 1 deletions
|
@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.reactions;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ public class ReactionRecipientItem extends LinearLayout {
|
||||||
private TextView reactionView;
|
private TextView reactionView;
|
||||||
|
|
||||||
private int contactId;
|
private int contactId;
|
||||||
|
private String reaction;
|
||||||
|
|
||||||
public ReactionRecipientItem(Context context) {
|
public ReactionRecipientItem(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
@ -44,6 +46,7 @@ public class ReactionRecipientItem extends LinearLayout {
|
||||||
|
|
||||||
public void bind(@NonNull GlideRequests glideRequests, int contactId, String reaction) {
|
public void bind(@NonNull GlideRequests glideRequests, int contactId, String reaction) {
|
||||||
this.contactId = contactId;
|
this.contactId = contactId;
|
||||||
|
this.reaction = reaction;
|
||||||
DcContact dcContact = DcHelper.getContext(getContext()).getContact(contactId);
|
DcContact dcContact = DcHelper.getContext(getContext()).getContact(contactId);
|
||||||
Recipient recipient = new Recipient(getContext(), dcContact);
|
Recipient recipient = new Recipient(getContext(), dcContact);
|
||||||
this.contactPhotoImage.setAvatar(glideRequests, recipient, false);
|
this.contactPhotoImage.setAvatar(glideRequests, recipient, false);
|
||||||
|
@ -58,4 +61,12 @@ public class ReactionRecipientItem extends LinearLayout {
|
||||||
public int getContactId() {
|
public int getContactId() {
|
||||||
return contactId;
|
return contactId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getReaction() {
|
||||||
|
return reaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public View getReactionView() {
|
||||||
|
return reactionView;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,11 @@ public class ReactionRecipientsAdapter extends RecyclerView.Adapter
|
||||||
clickListener.onItemClick(getView());
|
clickListener.onItemClick(getView());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
((ReactionRecipientItem) itemView).getReactionView().setOnClickListener(view -> {
|
||||||
|
if (clickListener != null) {
|
||||||
|
clickListener.onReactionClick(getView());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReactionRecipientItem getView() {
|
public ReactionRecipientItem getView() {
|
||||||
|
@ -93,6 +98,7 @@ public class ReactionRecipientsAdapter extends RecyclerView.Adapter
|
||||||
|
|
||||||
public interface ItemClickListener {
|
public interface ItemClickListener {
|
||||||
void onItemClick(ReactionRecipientItem item);
|
void onItemClick(ReactionRecipientItem item);
|
||||||
|
void onReactionClick(ReactionRecipientItem item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeData(ArrayList<Pair<Integer, String>> contactsReactions) {
|
public void changeData(ArrayList<Pair<Integer, String>> contactsReactions) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import com.b44t.messenger.DcContact;
|
||||||
import com.b44t.messenger.DcContext;
|
import com.b44t.messenger.DcContext;
|
||||||
import com.b44t.messenger.DcEvent;
|
import com.b44t.messenger.DcEvent;
|
||||||
import com.b44t.messenger.rpc.Reactions;
|
import com.b44t.messenger.rpc.Reactions;
|
||||||
|
import com.b44t.messenger.rpc.Rpc;
|
||||||
import com.b44t.messenger.rpc.RpcException;
|
import com.b44t.messenger.rpc.RpcException;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.ProfileActivity;
|
import org.thoughtcrime.securesms.ProfileActivity;
|
||||||
|
@ -114,6 +115,39 @@ public class ReactionsDetailsFragment extends DialogFragment implements DcEventC
|
||||||
requireContext().startActivity(intent);
|
requireContext().startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getSelfReaction(Rpc rpc, int accId) {
|
||||||
|
String result = null;
|
||||||
|
try {
|
||||||
|
final Reactions reactions = rpc.getMsgReactions(accId, msgId);
|
||||||
|
if (reactions != null) {
|
||||||
|
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(RpcException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendReaction(final String reaction) {
|
||||||
|
Rpc rpc = DcHelper.getRpc(requireActivity());
|
||||||
|
DcContext dcContext = DcHelper.getContext(requireActivity());
|
||||||
|
int accId = dcContext.getAccountId();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (reaction == null || reaction.equals(getSelfReaction(rpc, accId))) {
|
||||||
|
rpc.sendReaction(accId, msgId, "");
|
||||||
|
} else {
|
||||||
|
rpc.sendReaction(accId, msgId, reaction);
|
||||||
|
}
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class ListClickListener implements ReactionRecipientsAdapter.ItemClickListener {
|
private class ListClickListener implements ReactionRecipientsAdapter.ItemClickListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -124,6 +158,12 @@ public class ReactionsDetailsFragment extends DialogFragment implements DcEventC
|
||||||
openConversation(contactId);
|
openConversation(contactId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReactionClick(ReactionRecipientItem item) {
|
||||||
|
sendReaction(item.getReaction());
|
||||||
|
ReactionsDetailsFragment.this.dismiss();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,8 +50,9 @@
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
android:id="@+id/reaction"
|
android:id="@+id/reaction"
|
||||||
|
style="@style/ButtonSecondary"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="40dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:textSize="22dp"
|
android:textSize="22dp"
|
||||||
android:fontFamily="sans-serif"
|
android:fontFamily="sans-serif"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue