Conversation actions require Android 10

pull/194/head
M66B 5 years ago
parent 69b9a6b6c5
commit 0f6537b3c4

@ -2378,7 +2378,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@Override @Override
public void run() { public void run() {
try { try {
bindConversationActions(message, args.getParcelable("actions")); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
bindConversationActions(message, args.getParcelable("actions"));
cowner.start(); // Show attachments cowner.start(); // Show attachments
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
@ -2400,7 +2402,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvBody.setTextIsSelectable(true); tvBody.setTextIsSelectable(true);
tvBody.setMovementMethod(new TouchHandler(message)); tvBody.setMovementMethod(new TouchHandler(message));
bindConversationActions(message, args.getParcelable("actions")); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
bindConversationActions(message, args.getParcelable("actions"));
cowner.start(); // Show attachments cowner.start(); // Show attachments
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
@ -2451,89 +2455,88 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}.setCount(false).execute(context, owner, args, "message:body"); }.setCount(false).execute(context, owner, args, "message:body");
} }
@RequiresApi(api = Build.VERSION_CODES.Q)
private void bindConversationActions(TupleMessageEx message, ConversationActions cactions) { private void bindConversationActions(TupleMessageEx message, ConversationActions cactions) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { boolean has = false;
boolean has = false; if (cactions != null) {
if (cactions != null) { List<ConversationAction> actions = cactions.getConversationActions();
List<ConversationAction> actions = cactions.getConversationActions(); for (final ConversationAction action : actions) {
for (final ConversationAction action : actions) { final CharSequence text;
final CharSequence text; final CharSequence title;
final CharSequence title; final String type = action.getType();
final String type = action.getType(); final RemoteAction raction = action.getAction();
final RemoteAction raction = action.getAction();
switch (type) {
switch (type) { case ConversationAction.TYPE_TEXT_REPLY:
case ConversationAction.TYPE_TEXT_REPLY: text = action.getTextReply();
text = action.getTextReply(); title = context.getString(R.string.title_conversation_action_reply, text);
title = context.getString(R.string.title_conversation_action_reply, text); break;
break; case "copy":
case "copy": Bundle extras = action.getExtras().getParcelable("entities-extras");
Bundle extras = action.getExtras().getParcelable("entities-extras"); if (extras == null)
if (extras == null) continue;
continue; text = extras.getString("text");
text = extras.getString("text"); title = context.getString(R.string.title_conversation_action_copy, text);
title = context.getString(R.string.title_conversation_action_copy, text); break;
break; default:
default: if (raction == null) {
if (raction == null) { Log.w("Unknown action type=" + type);
Log.w("Unknown action type=" + type); continue;
continue; }
} text = null;
text = null; title = raction.getTitle();
title = raction.getTitle(); if (TextUtils.isEmpty(title)) {
if (TextUtils.isEmpty(title)) { Log.e("Empty action type=" + type);
Log.e("Empty action type=" + type); continue;
continue; }
} }
}
Button button = new Button(context, null, android.R.attr.buttonStyleSmall); Button button = new Button(context, null, android.R.attr.buttonStyleSmall);
button.setId(View.generateViewId()); button.setId(View.generateViewId());
button.setText(title); button.setText(title);
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
try { try {
switch (type) { switch (type) {
case ConversationAction.TYPE_TEXT_REPLY: case ConversationAction.TYPE_TEXT_REPLY:
onReply(); onReply();
break; break;
case "copy": case "copy":
onCopy(); onCopy();
break; break;
default: default:
raction.getActionIntent().send(); raction.getActionIntent().send();
}
} catch (Throwable ex) {
Log.e(ex);
} }
} catch (Throwable ex) {
Log.e(ex);
} }
}
private void onReply() { private void onReply() {
Intent reply = new Intent(context, ActivityCompose.class) Intent reply = new Intent(context, ActivityCompose.class)
.putExtra("action", "reply") .putExtra("action", "reply")
.putExtra("reference", message.id) .putExtra("reference", message.id)
.putExtra("text", action.getTextReply()); .putExtra("text", action.getTextReply());
context.startActivity(reply); context.startActivity(reply);
} }
private void onCopy() { private void onCopy() {
ClipboardManager clipboard = ClipboardManager clipboard =
(ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard != null) { if (clipboard != null) {
ClipData clip = ClipData.newPlainText(title, text); ClipData clip = ClipData.newPlainText(title, text);
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
ToastEx.makeText(context, R.string.title_clipboard_copied, Toast.LENGTH_LONG).show(); ToastEx.makeText(context, R.string.title_clipboard_copied, Toast.LENGTH_LONG).show();
}
} }
}); }
});
((ConstraintLayout) flow.getParent()).addView(button); ((ConstraintLayout) flow.getParent()).addView(button);
flow.addView(button); flow.addView(button);
has = true; has = true;
}
grpAction.setVisibility(has ? View.VISIBLE : View.GONE);
} }
grpAction.setVisibility(has ? View.VISIBLE : View.GONE);
} }
} }

Loading…
Cancel
Save