mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-04 18:29:17 +02:00
add 'share' to contact's profile menu
This commit is contained in:
parent
f26752ede5
commit
673c3412e9
4 changed files with 45 additions and 4 deletions
|
@ -391,7 +391,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
setMedia(data.getData(), MediaType.AUDIO);
|
setMedia(data.getData(), MediaType.AUDIO);
|
||||||
break;
|
break;
|
||||||
case PICK_CONTACT:
|
case PICK_CONTACT:
|
||||||
addAttachmentContactInfo(data);
|
addAttachmentContactInfo(data.getIntExtra(AttachContactActivity.CONTACT_ID_EXTRA, 0));
|
||||||
break;
|
break;
|
||||||
case GROUP_EDIT:
|
case GROUP_EDIT:
|
||||||
dcChat = dcContext.getChat(chatId);
|
dcChat = dcContext.getChat(chatId);
|
||||||
|
@ -695,6 +695,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
|
|
||||||
private void handleSharing() {
|
private void handleSharing() {
|
||||||
ArrayList<Uri> uriList = RelayUtil.getSharedUris(this);
|
ArrayList<Uri> uriList = RelayUtil.getSharedUris(this);
|
||||||
|
int sharedContactId = RelayUtil.getSharedContactId(this);
|
||||||
if (uriList.size() > 1) {
|
if (uriList.size() > 1) {
|
||||||
String message = String.format(getString(R.string.share_multiple_attachments), uriList.size());
|
String message = String.format(getString(R.string.share_multiple_attachments), uriList.size());
|
||||||
new AlertDialog.Builder(this)
|
new AlertDialog.Builder(this)
|
||||||
|
@ -704,7 +705,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
.setPositiveButton(R.string.menu_send, (dialog, which) -> SendRelayedMessageUtil.immediatelyRelay(this, chatId))
|
.setPositiveButton(R.string.menu_send, (dialog, which) -> SendRelayedMessageUtil.immediatelyRelay(this, chatId))
|
||||||
.show();
|
.show();
|
||||||
} else {
|
} else {
|
||||||
if (uriList.isEmpty()) {
|
if (sharedContactId != 0) {
|
||||||
|
addAttachmentContactInfo(sharedContactId);
|
||||||
|
} else if (uriList.isEmpty()) {
|
||||||
dcContext.setDraft(chatId, SendRelayedMessageUtil.createMessage(this, null, getSharedText(this)));
|
dcContext.setDraft(chatId, SendRelayedMessageUtil.createMessage(this, null, getSharedText(this)));
|
||||||
} else {
|
} else {
|
||||||
dcContext.setDraft(chatId, SendRelayedMessageUtil.createMessage(this, uriList.get(0), getSharedText(this)));
|
dcContext.setDraft(chatId, SendRelayedMessageUtil.createMessage(this, uriList.get(0), getSharedText(this)));
|
||||||
|
@ -975,8 +978,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
return attachmentManager.setMedia(glideRequests, Uri.fromFile(new File(msg.getFile())), msg, mediaType, 0, 0, chatId);
|
return attachmentManager.setMedia(glideRequests, Uri.fromFile(new File(msg.getFile())), msg, mediaType, 0, 0, chatId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addAttachmentContactInfo(Intent data) {
|
private void addAttachmentContactInfo(int contactId) {
|
||||||
int contactId = data.getIntExtra(AttachContactActivity.CONTACT_ID_EXTRA, 0);
|
|
||||||
if (contactId == 0) {
|
if (contactId == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.thoughtcrime.securesms;
|
package org.thoughtcrime.securesms;
|
||||||
|
|
||||||
|
import static org.thoughtcrime.securesms.util.RelayUtil.setForwardingMessageIds;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.media.RingtoneManager;
|
import android.media.RingtoneManager;
|
||||||
|
@ -27,6 +29,7 @@ import com.b44t.messenger.DcChat;
|
||||||
import com.b44t.messenger.DcContact;
|
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.DcMsg;
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.connect.DcEventCenter;
|
import org.thoughtcrime.securesms.connect.DcEventCenter;
|
||||||
|
@ -34,6 +37,7 @@ import org.thoughtcrime.securesms.connect.DcHelper;
|
||||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||||
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
||||||
import org.thoughtcrime.securesms.util.Prefs;
|
import org.thoughtcrime.securesms.util.Prefs;
|
||||||
|
import org.thoughtcrime.securesms.util.RelayUtil;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
|
|
||||||
|
@ -135,6 +139,7 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||||
menu.findItem(R.id.edit_name).setVisible(false);
|
menu.findItem(R.id.edit_name).setVisible(false);
|
||||||
menu.findItem(R.id.show_encr_info).setVisible(false);
|
menu.findItem(R.id.show_encr_info).setVisible(false);
|
||||||
menu.findItem(R.id.copy_addr_to_clipboard).setVisible(false);
|
menu.findItem(R.id.copy_addr_to_clipboard).setVisible(false);
|
||||||
|
menu.findItem(R.id.share).setVisible(false);
|
||||||
} else if (chatIsMultiUser) {
|
} else if (chatIsMultiUser) {
|
||||||
if (chatIsBroadcast) {
|
if (chatIsBroadcast) {
|
||||||
canReceive = false;
|
canReceive = false;
|
||||||
|
@ -145,6 +150,7 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menu.findItem(R.id.copy_addr_to_clipboard).setVisible(false);
|
menu.findItem(R.id.copy_addr_to_clipboard).setVisible(false);
|
||||||
|
menu.findItem(R.id.share).setVisible(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
canReceive = false;
|
canReceive = false;
|
||||||
|
@ -416,6 +422,9 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||||
case R.id.edit_name:
|
case R.id.edit_name:
|
||||||
onEditName();
|
onEditName();
|
||||||
break;
|
break;
|
||||||
|
case R.id.share:
|
||||||
|
onShare();
|
||||||
|
break;
|
||||||
case R.id.copy_addr_to_clipboard:
|
case R.id.copy_addr_to_clipboard:
|
||||||
onCopyAddrToClipboard();
|
onCopyAddrToClipboard();
|
||||||
break;
|
break;
|
||||||
|
@ -535,6 +544,12 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onShare() {
|
||||||
|
Intent composeIntent = new Intent();
|
||||||
|
RelayUtil.setSharedContact(composeIntent, contactId);
|
||||||
|
ConversationListRelayingActivity.start(this, composeIntent);
|
||||||
|
}
|
||||||
|
|
||||||
private void onCopyAddrToClipboard() {
|
private void onCopyAddrToClipboard() {
|
||||||
DcContact dcContact = dcContext.getContact(contactId);
|
DcContact dcContact = dcContext.getContact(contactId);
|
||||||
Util.writeTextToClipboard(this, dcContact.getAddr());
|
Util.writeTextToClipboard(this, dcContact.getAddr());
|
||||||
|
|
|
@ -13,6 +13,7 @@ import static org.thoughtcrime.securesms.ConversationActivity.TEXT_EXTRA;
|
||||||
public class RelayUtil {
|
public class RelayUtil {
|
||||||
private static final String FORWARDED_MESSAGE_IDS = "forwarded_message_ids";
|
private static final String FORWARDED_MESSAGE_IDS = "forwarded_message_ids";
|
||||||
private static final String SHARED_URIS = "shared_uris";
|
private static final String SHARED_URIS = "shared_uris";
|
||||||
|
private static final String SHARED_CONTACT_ID = "shared_contact_id";
|
||||||
private static final String IS_SHARING = "is_sharing";
|
private static final String IS_SHARING = "is_sharing";
|
||||||
private static final String SHARED_TITLE = "shared_title";
|
private static final String SHARED_TITLE = "shared_title";
|
||||||
private static final String DIRECT_SHARING_CHAT_ID = "direct_sharing_chat_id";
|
private static final String DIRECT_SHARING_CHAT_ID = "direct_sharing_chat_id";
|
||||||
|
@ -72,6 +73,16 @@ public class RelayUtil {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int getSharedContactId(Activity activity) {
|
||||||
|
try {
|
||||||
|
return activity.getIntent().getIntExtra(SHARED_CONTACT_ID, 0);
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String getSharedText(Activity activity) {
|
public static String getSharedText(Activity activity) {
|
||||||
try {
|
try {
|
||||||
return activity.getIntent().getStringExtra(TEXT_EXTRA);
|
return activity.getIntent().getStringExtra(TEXT_EXTRA);
|
||||||
|
@ -93,6 +104,7 @@ public class RelayUtil {
|
||||||
try {
|
try {
|
||||||
activity.getIntent().removeExtra(FORWARDED_MESSAGE_IDS);
|
activity.getIntent().removeExtra(FORWARDED_MESSAGE_IDS);
|
||||||
activity.getIntent().removeExtra(SHARED_URIS);
|
activity.getIntent().removeExtra(SHARED_URIS);
|
||||||
|
activity.getIntent().removeExtra(SHARED_CONTACT_ID);
|
||||||
activity.getIntent().removeExtra(IS_SHARING);
|
activity.getIntent().removeExtra(IS_SHARING);
|
||||||
activity.getIntent().removeExtra(DIRECT_SHARING_CHAT_ID);
|
activity.getIntent().removeExtra(DIRECT_SHARING_CHAT_ID);
|
||||||
activity.getIntent().removeExtra(TEXT_EXTRA);
|
activity.getIntent().removeExtra(TEXT_EXTRA);
|
||||||
|
@ -112,6 +124,9 @@ public class RelayUtil {
|
||||||
if (!getSharedUris(currentActivity).isEmpty()) {
|
if (!getSharedUris(currentActivity).isEmpty()) {
|
||||||
newActivityIntent.putParcelableArrayListExtra(SHARED_URIS, getSharedUris(currentActivity));
|
newActivityIntent.putParcelableArrayListExtra(SHARED_URIS, getSharedUris(currentActivity));
|
||||||
}
|
}
|
||||||
|
if (getSharedContactId(currentActivity) != 0) {
|
||||||
|
newActivityIntent.putExtra(SHARED_CONTACT_ID, getSharedContactId(currentActivity));
|
||||||
|
}
|
||||||
if (getSharedText(currentActivity) != null) {
|
if (getSharedText(currentActivity) != null) {
|
||||||
newActivityIntent.putExtra(TEXT_EXTRA, getSharedText(currentActivity));
|
newActivityIntent.putExtra(TEXT_EXTRA, getSharedText(currentActivity));
|
||||||
}
|
}
|
||||||
|
@ -132,6 +147,11 @@ public class RelayUtil {
|
||||||
composeIntent.putExtra(IS_SHARING, true);
|
composeIntent.putExtra(IS_SHARING, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setSharedContact(Intent composeIntent, int contactId) {
|
||||||
|
composeIntent.putExtra(SHARED_CONTACT_ID, contactId);
|
||||||
|
composeIntent.putExtra(IS_SHARING, true);
|
||||||
|
}
|
||||||
|
|
||||||
public static void setSharedTitle(Intent composeIntent, String text) {
|
public static void setSharedTitle(Intent composeIntent, String text) {
|
||||||
composeIntent.putExtra(SHARED_TITLE, text);
|
composeIntent.putExtra(SHARED_TITLE, text);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item android:title="@string/menu_share"
|
||||||
|
android:id="@+id/share"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
<item android:title="@string/global_menu_edit_desktop"
|
<item android:title="@string/global_menu_edit_desktop"
|
||||||
android:id="@+id/edit_name"
|
android:id="@+id/edit_name"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue