mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-03 17:59:39 +02:00
add 'save' option to chat's action bar
This commit is contained in:
parent
0704f7f1e7
commit
d1f77d9de5
8 changed files with 53 additions and 3 deletions
|
@ -691,6 +691,13 @@ JNIEXPORT void Java_com_b44t_messenger_DcContext_forwardMsgs(JNIEnv *env, jobjec
|
|||
free(msg_ids_ptr);
|
||||
}
|
||||
|
||||
JNIEXPORT void Java_com_b44t_messenger_DcContext_saveMsgs(JNIEnv *env, jobject obj, jintArray msg_ids)
|
||||
{
|
||||
int msg_ids_cnt = 0;
|
||||
uint32_t* msg_ids_ptr = jintArray2uint32Pointer(env, msg_ids, &msg_ids_cnt);
|
||||
dc_save_msgs(get_dc_context(env, obj), msg_ids_ptr, msg_ids_cnt);
|
||||
free(msg_ids_ptr);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean Java_com_b44t_messenger_DcContext_resendMsgs(JNIEnv *env, jobject obj, jintArray msg_ids)
|
||||
{
|
||||
|
|
|
@ -193,6 +193,7 @@ public class DcContext {
|
|||
public native int estimateDeletionCount(boolean from_server, long seconds);
|
||||
public native void deleteMsgs (int msg_ids[]);
|
||||
public native void forwardMsgs (int msg_ids[], int chat_id);
|
||||
public native void saveMsgs (int msg_ids[]);
|
||||
public native boolean resendMsgs (int msg_ids[]);
|
||||
public native int sendMsg (int chat_id, DcMsg msg);
|
||||
public native int sendTextMsg (int chat_id, String text);
|
||||
|
|
|
@ -189,6 +189,7 @@ public class DcMsg {
|
|||
public native int getSavedMsgId ();
|
||||
|
||||
public boolean canSave() {
|
||||
// saving info-messages out of context results in confusion, see https://github.com/deltachat/deltachat-ios/issues/2567
|
||||
return !isInfo();
|
||||
}
|
||||
|
||||
|
|
|
@ -326,6 +326,7 @@ public class ConversationFragment extends MessageSelectorFragment
|
|||
menu.findItem(R.id.menu_context_reply).setVisible(false);
|
||||
menu.findItem(R.id.menu_context_reply_privately).setVisible(false);
|
||||
menu.findItem(R.id.menu_add_to_home_screen).setVisible(false);
|
||||
menu.findItem(R.id.toggle_save).setVisible(false);
|
||||
} else {
|
||||
DcMsg messageRecord = messageRecords.iterator().next();
|
||||
DcChat chat = getListAdapter().getChat();
|
||||
|
@ -336,6 +337,10 @@ public class ConversationFragment extends MessageSelectorFragment
|
|||
boolean showReplyPrivately = chat.isMultiUser() && !messageRecord.isOutgoing() && canReply;
|
||||
menu.findItem(R.id.menu_context_reply_privately).setVisible(showReplyPrivately);
|
||||
menu.findItem(R.id.menu_add_to_home_screen).setVisible(messageRecord.getType() == DcMsg.DC_MSG_WEBXDC);
|
||||
|
||||
boolean showSavedIcon = messageRecord.isSaved() || chat.isSelfTalk();
|
||||
menu.findItem(R.id.toggle_save).setVisible(messageRecord.canSave());
|
||||
menu.findItem(R.id.toggle_save).setIcon(showSavedIcon ? R.drawable.baseline_star_24 : R.drawable.baseline_star_outline_24);
|
||||
}
|
||||
|
||||
// if one of the selected items cannot be saved, disable saving.
|
||||
|
@ -478,6 +483,21 @@ public class ConversationFragment extends MessageSelectorFragment
|
|||
}
|
||||
}
|
||||
|
||||
private void handleToggleSave(final Set<DcMsg> messageRecords) {
|
||||
DcMsg msg = getSelectedMessageRecord(messageRecords);
|
||||
if (getListAdapter().getChat().isSelfTalk()) {
|
||||
if (msg.getOriginalMsgId() != 0) {
|
||||
dcContext.deleteMsgs(new int[]{msg.getId()});
|
||||
} else {
|
||||
handleDeleteMessages((int) chatId, messageRecords);
|
||||
}
|
||||
} else if (msg.getSavedMsgId() != 0) {
|
||||
dcContext.deleteMsgs(new int[]{msg.getSavedMsgId()});
|
||||
} else {
|
||||
dcContext.saveMsgs(new int[]{msg.getId()});
|
||||
}
|
||||
}
|
||||
|
||||
private void reloadList() {
|
||||
reloadList(false);
|
||||
}
|
||||
|
@ -953,6 +973,10 @@ public class ConversationFragment extends MessageSelectorFragment
|
|||
case R.id.menu_context_reply_privately:
|
||||
handleReplyMessagePrivately(getSelectedMessageRecord(getListAdapter().getSelectedItems()));
|
||||
return true;
|
||||
case R.id.toggle_save:
|
||||
handleToggleSave(getListAdapter().getSelectedItems());
|
||||
actionMode.finish();
|
||||
return true;
|
||||
case R.id.menu_resend:
|
||||
handleResendMessage(getListAdapter().getSelectedItems());
|
||||
return true;
|
||||
|
|
|
@ -27,6 +27,7 @@ public class ConversationAdaptiveActionsToolbar extends Toolbar {
|
|||
private static final int ID_NEVER_SHOW_AS_ACTION_2 = R.id.menu_add_to_home_screen;
|
||||
private static final int ID_NEVER_SHOW_AS_ACTION_3 = R.id.menu_context_save_attachment;
|
||||
private static final int ID_NEVER_SHOW_AS_ACTION_4 = R.id.menu_resend;
|
||||
private static final int ID_NEVER_SHOW_AS_ACTION_5 = R.id.menu_context_details;
|
||||
private static final int ID_ALWAYS_SHOW_AS_ACTION = R.id.menu_context_forward;
|
||||
|
||||
private final int maxShown;
|
||||
|
@ -83,7 +84,8 @@ public class ConversationAdaptiveActionsToolbar extends Toolbar {
|
|||
boolean neverShowAsAction = item.getItemId() == ID_NEVER_SHOW_AS_ACTION_1
|
||||
|| item.getItemId() == ID_NEVER_SHOW_AS_ACTION_2
|
||||
|| item.getItemId() == ID_NEVER_SHOW_AS_ACTION_3
|
||||
|| item.getItemId() == ID_NEVER_SHOW_AS_ACTION_4;
|
||||
|| item.getItemId() == ID_NEVER_SHOW_AS_ACTION_4
|
||||
|| item.getItemId() == ID_NEVER_SHOW_AS_ACTION_5;
|
||||
boolean alwaysShowAsAction = item.getItemId() == ID_ALWAYS_SHOW_AS_ACTION;
|
||||
|
||||
if (alwaysShowAsAction) continue;
|
||||
|
|
5
src/main/res/drawable/baseline_star_24.xml
Normal file
5
src/main/res/drawable/baseline_star_24.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
|
||||
|
||||
</vector>
|
5
src/main/res/drawable/baseline_star_outline_24.xml
Normal file
5
src/main/res/drawable/baseline_star_outline_24.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M22,9.24l-7.19,-0.62L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21 12,17.27 18.18,21l-1.63,-7.03L22,9.24zM12,15.4l-3.76,2.27 1,-4.28 -3.32,-2.88 4.38,-0.38L12,6.1l1.71,4.04 4.38,0.38 -3.32,2.88 1,4.28L12,15.4z"/>
|
||||
|
||||
</vector>
|
|
@ -5,10 +5,15 @@
|
|||
android:icon="?menu_reply_icon"
|
||||
app:showAsAction="always" />
|
||||
|
||||
<item android:title="@string/menu_message_details"
|
||||
<item android:title="@string/save"
|
||||
android:id="@+id/toggle_save"
|
||||
android:icon="@drawable/baseline_star_outline_24"
|
||||
app:showAsAction="always" />
|
||||
|
||||
<item android:title="@string/info"
|
||||
android:id="@+id/menu_context_details"
|
||||
android:icon="?menu_info_icon"
|
||||
app:showAsAction="always" />
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item android:title="@string/menu_delete_messages"
|
||||
android:id="@+id/menu_context_delete_message"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue