mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Support intents with mailto:-links, show preview before sending a message.
This commit is contained in:
@@ -353,9 +353,9 @@ JNIEXPORT jlong Java_com_b44t_messenger_MrMailbox_MrMailboxGetChat(JNIEnv *env,
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jint Java_com_b44t_messenger_MrMailbox_MrMailboxGetChatIdByContactId(JNIEnv *env, jclass c, jlong hMailbox, jint contact_id)
|
||||
JNIEXPORT jint Java_com_b44t_messenger_MrMailbox_getChatIdByContactId(JNIEnv *env, jclass cls, jint contact_id)
|
||||
{
|
||||
return (jint)mrmailbox_get_chat_id_by_contact_id((mrmailbox_t*)hMailbox, contact_id);
|
||||
return (jint)mrmailbox_get_chat_id_by_contact_id(get_mrmailbox_t(env, cls), contact_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -371,9 +371,9 @@ JNIEXPORT jint Java_com_b44t_messenger_MrMailbox_markseenChat(JNIEnv *env, jclas
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jint Java_com_b44t_messenger_MrMailbox_MrMailboxCreateChatByContactId(JNIEnv *env, jclass c, jlong hMailbox, jint contact_id)
|
||||
JNIEXPORT jint Java_com_b44t_messenger_MrMailbox_createChatByContactId(JNIEnv *env, jclass cls, jint contact_id)
|
||||
{
|
||||
return (jint)mrmailbox_create_chat_by_contact_id((mrmailbox_t*)hMailbox, contact_id);
|
||||
return (jint)mrmailbox_create_chat_by_contact_id(get_mrmailbox_t(env, cls), contact_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -99,22 +99,13 @@
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:mimeType="vnd.android.cursor.item/vnd.com.b44t.messenger.android.profile"/>
|
||||
</intent-filter>
|
||||
<!-- <intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:host="t'gram.me" android:scheme="http" />
|
||||
<data android:host="t'gram.me" android:scheme="https" />
|
||||
<data android:host="t'gram.dog" android:scheme="http" />
|
||||
<data android:host="t'gram.dog" android:scheme="https" />
|
||||
</intent-filter> -->
|
||||
<!-- <intent-filter android:icon="@drawable/ic_launcher" android:priority="1">
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:scheme="tg" />
|
||||
</intent-filter> -->
|
||||
<!-- see note below, <meta-data android:name="android.service.chooser.chooser_target_service" android:value=".TgChooserTargetService" /> -->
|
||||
<action android:name="android.intent.action.SENDTO"/> <!-- VIEW seems to be standard, however, SENDTO is also mentioned in some examples -->
|
||||
<data android:scheme="mailto"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.b44t.ui.ManageSpaceActivity"
|
||||
@@ -181,7 +172,7 @@
|
||||
|
||||
<!-- this would implement the "direct share" functionality (the system shows some direct links eg.
|
||||
to the most recent chats when calling "share" from another app, see https://developer.android.com/reference/android/service/chooser/ChooserTargetService.html )
|
||||
however, if we want this feature, we have to reimplement TgChooserTargetService or sth. like that.
|
||||
however, if we want this feature, we have to implement a ChooserTargetService and add <meta-data android:name="android.service.chooser.chooser_target_service" android:value=".OurChooserTargetService" />
|
||||
<service
|
||||
android:name="com.b44t.messenger.TgChooserTargetService"
|
||||
android:label="@string/AppName"
|
||||
|
||||
@@ -560,7 +560,7 @@ public class AndroidUtilities {
|
||||
}
|
||||
}
|
||||
ArrayList<Integer> colors = new ArrayList<>();
|
||||
if ((flag & FLAG_TAG_COLOR) != 0) {
|
||||
if ((flag & FLAG_TAG_COLOR) != 0) { // used eg. by the message preview when following a mailto:-link
|
||||
while ((start = stringBuilder.indexOf("<c#")) != -1) {
|
||||
stringBuilder.replace(start, start + 2, "");
|
||||
end = stringBuilder.indexOf(">", start);
|
||||
|
||||
@@ -117,13 +117,8 @@ public class MrMailbox {
|
||||
public native static int markseenMsg (int msg_id);
|
||||
public native static int markseenChat (int chat_id);
|
||||
|
||||
public static int getChatIdByContactId (int contact_id) {
|
||||
return MrMailboxGetChatIdByContactId(m_hMailbox, contact_id);
|
||||
}
|
||||
|
||||
public static int createChatByContactId(int contact_id) {
|
||||
return MrMailboxCreateChatByContactId(m_hMailbox, contact_id);
|
||||
}
|
||||
public native static int getChatIdByContactId (int contact_id);
|
||||
public native static int createChatByContactId(int contact_id); // returns chat_id
|
||||
|
||||
public native static int createGroupChat (String name);
|
||||
public native static int isContactInChat (int chat_id, int contact_id);
|
||||
@@ -145,8 +140,6 @@ public class MrMailbox {
|
||||
|
||||
private native static long MrMailboxGetChatlist (long hMailbox, String query); // returns hChatlist which must be unref'd after usage
|
||||
private native static long MrMailboxGetChat (long hMailbox, int chat_id); // return hChat which must be unref'd after usage
|
||||
private native static int MrMailboxGetChatIdByContactId (long hMailbox, int contact_id);
|
||||
private native static int MrMailboxCreateChatByContactId(long hMailbox, int contact_id); // returns chat_id
|
||||
|
||||
|
||||
// msgs
|
||||
|
||||
@@ -2691,16 +2691,12 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
|
||||
private void createChat(String urlFinal)
|
||||
{
|
||||
int contactId = MrMailbox.createContact("", urlFinal);
|
||||
int chatId = MrMailbox.createChatByContactId(contactId);
|
||||
int chatId = MrMailbox.createChatByContactId(MrMailbox.createContact("", urlFinal));
|
||||
if( chatId != 0 ) {
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("chat_id", chatId);
|
||||
presentFragment(new ChatActivity(args), true /*removeLast*/);
|
||||
}
|
||||
else {
|
||||
Toast.makeText(getParentActivity(), "Cannot create chat.", Toast.LENGTH_LONG).show(); // should not happen
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,7 +43,6 @@ import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewOutlineProvider;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
@@ -53,6 +52,7 @@ import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.b44t.messenger.AndroidUtilities;
|
||||
import com.b44t.messenger.ApplicationLoader;
|
||||
import com.b44t.messenger.ImageLoader;
|
||||
import com.b44t.messenger.LocaleController;
|
||||
import com.b44t.messenger.MrChat;
|
||||
@@ -61,7 +61,6 @@ import com.b44t.messenger.MrMsg;
|
||||
import com.b44t.messenger.Utilities;
|
||||
import com.b44t.messenger.support.widget.LinearLayoutManager;
|
||||
import com.b44t.messenger.support.widget.RecyclerView;
|
||||
import com.b44t.messenger.FileLog;
|
||||
import com.b44t.messenger.NotificationCenter;
|
||||
import com.b44t.messenger.R;
|
||||
import com.b44t.messenger.UserConfig;
|
||||
@@ -107,7 +106,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
|
||||
private boolean checkPermission = true;
|
||||
|
||||
private String selectAlertString;
|
||||
private String selectAlertString, selectAlertPreviewString, selectAlertOkButtonString;
|
||||
|
||||
private static boolean dialogsLoaded;
|
||||
private boolean searching;
|
||||
@@ -139,6 +138,8 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
onlySelectTitle = LocaleController.getString("SelectChat", R.string.SelectChat);
|
||||
}
|
||||
selectAlertString = arguments.getString("selectAlertString");
|
||||
selectAlertPreviewString = arguments.getString("selectAlertPreviewString");
|
||||
selectAlertOkButtonString = arguments.getString("selectAlertOkButtonString");
|
||||
}
|
||||
|
||||
NotificationCenter.getInstance().addObserver(this, NotificationCenter.dialogsNeedReload);
|
||||
@@ -534,8 +535,6 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
ArrayList<String> permissons = new ArrayList<>();
|
||||
if (activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
|
||||
permissons.add(Manifest.permission.READ_CONTACTS);
|
||||
//permissons.add(Manifest.permission.WRITE_CONTACTS);
|
||||
//permissons.add(Manifest.permission.GET_ACCOUNTS);
|
||||
}
|
||||
if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
permissons.add(Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||
@@ -717,10 +716,12 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
||||
|
||||
MrChat mrChat = MrMailbox.getChat((int)dialog_id);
|
||||
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatStringSimple(selectAlertString,
|
||||
mrChat.getNameNAddr() /*display addr as there may be contacts with the same name but different addresses*/)));
|
||||
|
||||
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
||||
builder.setMessage(AndroidUtilities.replaceTags(
|
||||
LocaleController.formatStringSimple(selectAlertString, mrChat.getNameNAddr()) // display addr as there may be contacts with the same name but different addresses
|
||||
+ (selectAlertPreviewString==null? "" : ("\n\n<c#808080>"+selectAlertPreviewString+"</c>"))));
|
||||
|
||||
builder.setPositiveButton(selectAlertOkButtonString!=null? selectAlertOkButtonString : ApplicationLoader.applicationContext.getString(R.string.OK), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
didSelectResult(dialog_id, false, false);
|
||||
|
||||
@@ -33,6 +33,7 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Point;
|
||||
import android.net.MailTo;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -471,11 +472,15 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||
return false;
|
||||
}
|
||||
|
||||
if( intent==null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int flags = intent.getFlags();
|
||||
boolean pushOpened = false;
|
||||
|
||||
Integer push_chat_id = 0;
|
||||
long dialogId = intent != null && intent.getExtras() != null ? intent.getExtras().getLong("dialogId", 0) : 0;
|
||||
long dialogId = intent.getExtras() != null ? intent.getExtras().getLong("dialogId", 0) : 0;
|
||||
boolean showDialogsList = false;
|
||||
|
||||
photoPathsArray = null;
|
||||
@@ -486,10 +491,14 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||
documentsMimeType = null;
|
||||
documentsUrisArray = null;
|
||||
contactsToSend = null;
|
||||
String createChatWith = null;
|
||||
|
||||
if ( (flags & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) {
|
||||
if (intent != null && intent.getAction() != null && !restore) {
|
||||
if (Intent.ACTION_SEND.equals(intent.getAction())) {
|
||||
if ( (flags & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0)
|
||||
{
|
||||
if (intent.getAction() != null && !restore)
|
||||
{
|
||||
if (Intent.ACTION_SEND.equals(intent.getAction()))
|
||||
{
|
||||
boolean error = false;
|
||||
String type = intent.getType();
|
||||
if (type != null && type.equals(ContactsContract.Contacts.CONTENT_VCARD_TYPE)) {
|
||||
@@ -654,7 +663,9 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||
if (error) {
|
||||
Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else if (intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
|
||||
}
|
||||
else if (intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE))
|
||||
{
|
||||
boolean error = false;
|
||||
try {
|
||||
ArrayList<Parcelable> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||
@@ -724,18 +735,36 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||
if (error) {
|
||||
Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
||||
Uri data = intent.getData();
|
||||
if (data != null) {
|
||||
String scheme = data.getScheme();
|
||||
if (scheme != null) {
|
||||
if ((scheme.equals("http") || scheme.equals("https"))) {
|
||||
|
||||
}
|
||||
else if( Intent.ACTION_VIEW.equals(intent.getAction()) || Intent.ACTION_SENDTO.equals(intent.getAction()) )
|
||||
{
|
||||
// handle links
|
||||
try {
|
||||
Uri uri = intent.getData();
|
||||
if( uri != null ) {
|
||||
String scheme = uri.getScheme();
|
||||
if( scheme != null && scheme.equals("mailto") ) {
|
||||
// handle mailto:-links
|
||||
MailTo mailto = MailTo.parse(uri.toString());
|
||||
String toList = mailto.getTo(); // toList contains comma-separated email addresses
|
||||
if( toList!=null && !toList.isEmpty() ) {
|
||||
String[] toArr = toList.split(",");
|
||||
createChatWith = toArr[0];
|
||||
}
|
||||
String subject = mailto.getSubject();
|
||||
String body = mailto.getBody();
|
||||
if (subject != null || body != null) {
|
||||
sendingText = subject + ((subject != null && body != null) ? " \u2013 " : "") + body;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
Log.e("DeltaChat", "mailto failed", e);
|
||||
}
|
||||
}
|
||||
else if (intent.getAction().startsWith("com.b44t.messenger.openchat")) {
|
||||
else if (intent.getAction().startsWith("com.b44t.messenger.openchat"))
|
||||
{
|
||||
String temp = intent.getAction().substring(27);
|
||||
int chatId = 0;
|
||||
try {
|
||||
@@ -753,25 +782,39 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||
}
|
||||
}
|
||||
|
||||
/*if (push_user_id != 0) {
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("user_id", push_user_id);
|
||||
if (mainFragmentsStack.isEmpty() || MessagesController.checkCanOpenChat(args, mainFragmentsStack.get(mainFragmentsStack.size() - 1))) {
|
||||
ChatActivity fragment = new ChatActivity(args);
|
||||
if (actionBarLayout.presentFragment(fragment, false, true, true)) {
|
||||
pushOpened = true;
|
||||
if( createChatWith!=null /*should be first as it may be combined with sendingText */ )
|
||||
{
|
||||
final String createChatWithFinal = createChatWith;
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
int chatId = MrMailbox.createChatByContactId(MrMailbox.createContact("", createChatWithFinal));
|
||||
if( chatId != 0 ) {
|
||||
if( sendingText!=null ) { MrMailbox.getChat(chatId).setDraft(sendingText, 0); }
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("chat_id", chatId);
|
||||
boolean removeLast = actionBarLayout.fragmentsStack.size() > 1 && actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1) instanceof ChatActivity;
|
||||
actionBarLayout.presentFragment(new ChatActivity(args), removeLast, true, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} else*/ if (push_chat_id != 0) {
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("AskStartChatWith", R.string.AskStartChatWith, createChatWith)));
|
||||
builder.show();
|
||||
}
|
||||
else if (push_chat_id != 0)
|
||||
{
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("chat_id", push_chat_id);
|
||||
//if (mainFragmentsStack.isEmpty() || MessagesController.checkCanOpenChat(args, mainFragmentsStack.get(mainFragmentsStack.size() - 1))) {
|
||||
ChatActivity fragment = new ChatActivity(args);
|
||||
if (actionBarLayout.presentFragment(fragment, false, true, true)) {
|
||||
pushOpened = true;
|
||||
}
|
||||
//}
|
||||
} else if (showDialogsList) {
|
||||
ChatActivity fragment = new ChatActivity(args);
|
||||
if (actionBarLayout.presentFragment(fragment, false, true, true)) {
|
||||
pushOpened = true;
|
||||
}
|
||||
}
|
||||
else if (showDialogsList)
|
||||
{
|
||||
if (!AndroidUtilities.isTablet()) {
|
||||
actionBarLayout.removeAllFragments();
|
||||
} else {
|
||||
@@ -786,14 +829,17 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||
pushOpened = false;
|
||||
isNew = false;
|
||||
}
|
||||
else if (videoPath != null || photoPathsArray != null || sendingText != null || documentsPathsArray != null || contactsToSend != null || documentsUrisArray != null) {
|
||||
else if (videoPath != null || photoPathsArray != null || sendingText != null || documentsPathsArray != null || contactsToSend != null || documentsUrisArray != null)
|
||||
{
|
||||
if (!AndroidUtilities.isTablet()) {
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
|
||||
}
|
||||
if (dialogId == 0) {
|
||||
Bundle args = new Bundle();
|
||||
args.putBoolean("onlySelect", true);
|
||||
args.putString("selectAlertString", LocaleController.getString("SendMessagesTo", R.string.SendMessagesTo));
|
||||
args.putString("selectAlertString", ApplicationLoader.applicationContext.getString(R.string.SendMessagesTo));
|
||||
args.putString("selectAlertPreviewString", sendingText /*may be NULL*/);
|
||||
args.putString("selectAlertOkButtonString", ApplicationLoader.applicationContext.getString(R.string.Send));
|
||||
DialogsActivity fragment = new DialogsActivity(args);
|
||||
fragment.setDelegate(this);
|
||||
boolean removeLast;
|
||||
@@ -820,16 +866,18 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||
}
|
||||
}
|
||||
|
||||
if (!pushOpened && !isNew) {
|
||||
if (!pushOpened && !isNew)
|
||||
{
|
||||
if (AndroidUtilities.isTablet()) {
|
||||
if (actionBarLayout.fragmentsStack.isEmpty()) {
|
||||
actionBarLayout.addFragmentToStack(new DialogsActivity(null));
|
||||
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
||||
}
|
||||
} else {
|
||||
if (actionBarLayout.fragmentsStack.isEmpty()) {
|
||||
actionBarLayout.addFragmentToStack(new DialogsActivity(null));
|
||||
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
||||
actionBarLayout.addFragmentToStack(new DialogsActivity(null));
|
||||
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (actionBarLayout.fragmentsStack.isEmpty()) {
|
||||
actionBarLayout.addFragmentToStack(new DialogsActivity(null));
|
||||
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
||||
}
|
||||
}
|
||||
actionBarLayout.showLastFragment();
|
||||
|
||||
Reference in New Issue
Block a user