mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-04 10:19:15 +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);
|
||||
break;
|
||||
case PICK_CONTACT:
|
||||
addAttachmentContactInfo(data);
|
||||
addAttachmentContactInfo(data.getIntExtra(AttachContactActivity.CONTACT_ID_EXTRA, 0));
|
||||
break;
|
||||
case GROUP_EDIT:
|
||||
dcChat = dcContext.getChat(chatId);
|
||||
|
@ -695,6 +695,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||
|
||||
private void handleSharing() {
|
||||
ArrayList<Uri> uriList = RelayUtil.getSharedUris(this);
|
||||
int sharedContactId = RelayUtil.getSharedContactId(this);
|
||||
if (uriList.size() > 1) {
|
||||
String message = String.format(getString(R.string.share_multiple_attachments), uriList.size());
|
||||
new AlertDialog.Builder(this)
|
||||
|
@ -704,7 +705,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||
.setPositiveButton(R.string.menu_send, (dialog, which) -> SendRelayedMessageUtil.immediatelyRelay(this, chatId))
|
||||
.show();
|
||||
} else {
|
||||
if (uriList.isEmpty()) {
|
||||
if (sharedContactId != 0) {
|
||||
addAttachmentContactInfo(sharedContactId);
|
||||
} else if (uriList.isEmpty()) {
|
||||
dcContext.setDraft(chatId, SendRelayedMessageUtil.createMessage(this, null, getSharedText(this)));
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
||||
private void addAttachmentContactInfo(Intent data) {
|
||||
int contactId = data.getIntExtra(AttachContactActivity.CONTACT_ID_EXTRA, 0);
|
||||
private void addAttachmentContactInfo(int contactId) {
|
||||
if (contactId == 0) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.thoughtcrime.securesms;
|
||||
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.setForwardingMessageIds;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.media.RingtoneManager;
|
||||
|
@ -27,6 +29,7 @@ import com.b44t.messenger.DcChat;
|
|||
import com.b44t.messenger.DcContact;
|
||||
import com.b44t.messenger.DcContext;
|
||||
import com.b44t.messenger.DcEvent;
|
||||
import com.b44t.messenger.DcMsg;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
|
||||
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.util.DynamicNoActionBarTheme;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.RelayUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
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.show_encr_info).setVisible(false);
|
||||
menu.findItem(R.id.copy_addr_to_clipboard).setVisible(false);
|
||||
menu.findItem(R.id.share).setVisible(false);
|
||||
} else if (chatIsMultiUser) {
|
||||
if (chatIsBroadcast) {
|
||||
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.share).setVisible(false);
|
||||
}
|
||||
} else {
|
||||
canReceive = false;
|
||||
|
@ -416,6 +422,9 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
|||
case R.id.edit_name:
|
||||
onEditName();
|
||||
break;
|
||||
case R.id.share:
|
||||
onShare();
|
||||
break;
|
||||
case R.id.copy_addr_to_clipboard:
|
||||
onCopyAddrToClipboard();
|
||||
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() {
|
||||
DcContact dcContact = dcContext.getContact(contactId);
|
||||
Util.writeTextToClipboard(this, dcContact.getAddr());
|
||||
|
|
|
@ -13,6 +13,7 @@ import static org.thoughtcrime.securesms.ConversationActivity.TEXT_EXTRA;
|
|||
public class RelayUtil {
|
||||
private static final String FORWARDED_MESSAGE_IDS = "forwarded_message_ids";
|
||||
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 SHARED_TITLE = "shared_title";
|
||||
private static final String DIRECT_SHARING_CHAT_ID = "direct_sharing_chat_id";
|
||||
|
@ -72,6 +73,16 @@ public class RelayUtil {
|
|||
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) {
|
||||
try {
|
||||
return activity.getIntent().getStringExtra(TEXT_EXTRA);
|
||||
|
@ -93,6 +104,7 @@ public class RelayUtil {
|
|||
try {
|
||||
activity.getIntent().removeExtra(FORWARDED_MESSAGE_IDS);
|
||||
activity.getIntent().removeExtra(SHARED_URIS);
|
||||
activity.getIntent().removeExtra(SHARED_CONTACT_ID);
|
||||
activity.getIntent().removeExtra(IS_SHARING);
|
||||
activity.getIntent().removeExtra(DIRECT_SHARING_CHAT_ID);
|
||||
activity.getIntent().removeExtra(TEXT_EXTRA);
|
||||
|
@ -112,6 +124,9 @@ public class RelayUtil {
|
|||
if (!getSharedUris(currentActivity).isEmpty()) {
|
||||
newActivityIntent.putParcelableArrayListExtra(SHARED_URIS, getSharedUris(currentActivity));
|
||||
}
|
||||
if (getSharedContactId(currentActivity) != 0) {
|
||||
newActivityIntent.putExtra(SHARED_CONTACT_ID, getSharedContactId(currentActivity));
|
||||
}
|
||||
if (getSharedText(currentActivity) != null) {
|
||||
newActivityIntent.putExtra(TEXT_EXTRA, getSharedText(currentActivity));
|
||||
}
|
||||
|
@ -132,6 +147,11 @@ public class RelayUtil {
|
|||
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) {
|
||||
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">
|
||||
|
||||
<item android:title="@string/menu_share"
|
||||
android:id="@+id/share"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item android:title="@string/global_menu_edit_desktop"
|
||||
android:id="@+id/edit_name"
|
||||
app:showAsAction="never"/>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue