mirror of https://github.com/M66B/FairEmail.git
Added direct text share
This commit is contained in:
parent
25a1df8350
commit
74f4ffa7de
|
@ -34,4 +34,9 @@
|
|||
android:targetPackage="eu.faircode.email.debug" />
|
||||
<categories android:name="android.shortcut.conversation" />
|
||||
</shortcut>
|
||||
|
||||
<share-target android:targetClass="eu.faircode.email.ActivityMain">
|
||||
<category android:name="eu.faircode.email.TEXT_SHARE_TARGET" />
|
||||
<data android:mimeType="text/plain" />
|
||||
</share-target>
|
||||
</shortcuts>
|
|
@ -97,6 +97,17 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB
|
|||
args.putString("body", body);
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_SHORTCUT_ID)) {
|
||||
String to = intent.getStringExtra(Intent.EXTRA_SHORTCUT_ID);
|
||||
if (to != null)
|
||||
try {
|
||||
InternetAddress.parse(to);
|
||||
args.putString("to", to);
|
||||
} catch (AddressException ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_EMAIL)) {
|
||||
String[] to = intent.getStringArrayExtra(Intent.EXTRA_EMAIL);
|
||||
if (to != null)
|
||||
|
|
|
@ -41,15 +41,14 @@ public interface DaoContact {
|
|||
" ORDER BY times_contacted DESC, last_contacted DESC")
|
||||
LiveData<List<TupleContactEx>> liveContacts();
|
||||
|
||||
@Query("SELECT * FROM contact" +
|
||||
@Query("SELECT email, name, avatar FROM contact" +
|
||||
" WHERE state <> " + EntityContact.STATE_IGNORE +
|
||||
" ORDER BY" +
|
||||
" CASE WHEN state = " + EntityContact.STATE_FAVORITE + " THEN 0 ELSE 1 END" +
|
||||
", CASE WHEN avatar IS NULL THEN 1 ELSE 0 END" +
|
||||
", times_contacted DESC" +
|
||||
", last_contacted DESC" +
|
||||
" LIMIT :count")
|
||||
List<EntityContact> getFrequentlyContacted(int count);
|
||||
", last_contacted DESC")
|
||||
Cursor getFrequentlyContacted();
|
||||
|
||||
@Query("SELECT *" +
|
||||
" FROM contact" +
|
||||
|
|
|
@ -24,13 +24,13 @@ import android.annotation.TargetApi;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ShortcutManager;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.ContactsContract;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.core.app.Person;
|
||||
|
@ -41,7 +41,10 @@ import androidx.lifecycle.LifecycleOwner;
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Shortcuts {
|
||||
static void update(final Context context, final LifecycleOwner owner) {
|
||||
|
@ -58,23 +61,34 @@ public class Shortcuts {
|
|||
int count = app - manifest;
|
||||
Log.i("Shortcuts count=" + count + " app=" + app + " manifest=" + manifest);
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
List<String> emails = new ArrayList<>();
|
||||
List<ShortcutInfoCompat> shortcuts = new ArrayList<>();
|
||||
if (count > 0) {
|
||||
DB db = DB.getInstance(context);
|
||||
List<EntityContact> frequently = db.contact().getFrequentlyContacted(count);
|
||||
for (EntityContact contact : frequently) {
|
||||
try (Cursor cursor = db.contact().getFrequentlyContacted()) {
|
||||
int colEmail = cursor.getColumnIndex("email");
|
||||
int colName = cursor.getColumnIndex("name");
|
||||
int colAvatar = cursor.getColumnIndex("avatar");
|
||||
while (shortcuts.size() < count && cursor.moveToNext()) {
|
||||
String email = cursor.getString(colEmail);
|
||||
String name = (cursor.isNull(colName) ? null : cursor.getString(colName));
|
||||
String avatar = (cursor.isNull(colAvatar) ? null : cursor.getString(colAvatar));
|
||||
|
||||
if (emails.contains(email))
|
||||
continue;
|
||||
emails.add(email);
|
||||
|
||||
Intent intent = new Intent(context, ActivityMain.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
intent.setAction(Intent.ACTION_SEND);
|
||||
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
intent.setData(Uri.parse("mailto:" + contact.email));
|
||||
intent.setData(Uri.parse("mailto:" + email));
|
||||
|
||||
IconCompat icon = null;
|
||||
if (contact.avatar != null &&
|
||||
if (avatar != null &&
|
||||
Helper.hasPermission(context, Manifest.permission.READ_CONTACTS)) {
|
||||
// Create icon from bitmap because launcher might not have contacts permission
|
||||
InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(
|
||||
context.getContentResolver(), Uri.parse(contact.avatar));
|
||||
context.getContentResolver(), Uri.parse(avatar));
|
||||
Bitmap bitmap = BitmapFactory.decodeStream(is);
|
||||
if (bitmap != null)
|
||||
icon = IconCompat.createWithBitmap(bitmap);
|
||||
|
@ -82,25 +96,24 @@ public class Shortcuts {
|
|||
if (icon == null)
|
||||
icon = IconCompat.createWithResource(context, R.drawable.ic_shortcut_email);
|
||||
|
||||
String name = (TextUtils.isEmpty(contact.name) ? contact.email : contact.name);
|
||||
Set<String> categories = new HashSet<>(Arrays.asList("eu.faircode.email.TEXT_SHARE_TARGET"));
|
||||
|
||||
//Set<String> categories = new HashSet<>(Arrays.asList(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION));
|
||||
|
||||
ShortcutInfoCompat.Builder builder = new ShortcutInfoCompat.Builder(context, Long.toString(contact.id))
|
||||
String id = (name == null ? email : "\"" + name + "\" <" + email + ">");
|
||||
ShortcutInfoCompat.Builder builder = new ShortcutInfoCompat.Builder(context, id)
|
||||
.setIcon(icon)
|
||||
.setRank(shortcuts.size() + 1)
|
||||
.setShortLabel(name)
|
||||
.setLongLabel(name)
|
||||
//.setCategories(categories)
|
||||
.setShortLabel(name == null ? email : name)
|
||||
.setLongLabel(name == null ? email : name)
|
||||
.setCategories(categories)
|
||||
.setIntent(intent);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
Person.Builder person = new Person.Builder()
|
||||
.setIcon(icon)
|
||||
.setName(name)
|
||||
.setName(name == null ? email : name)
|
||||
.setImportant(true);
|
||||
if (contact.avatar != null)
|
||||
person.setUri(contact.avatar);
|
||||
if (avatar != null)
|
||||
person.setUri(avatar);
|
||||
builder.setPerson(person.build());
|
||||
}
|
||||
|
||||
|
@ -114,6 +127,7 @@ public class Shortcuts {
|
|||
@Override
|
||||
@TargetApi(Build.VERSION_CODES.N_MR1)
|
||||
protected void onExecuted(Bundle args, List<ShortcutInfoCompat> shortcuts) {
|
||||
ShortcutManagerCompat.removeAllDynamicShortcuts(context);
|
||||
ShortcutManagerCompat.addDynamicShortcuts(context, shortcuts);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,4 +34,9 @@
|
|||
android:targetPackage="eu.faircode.email" />
|
||||
<categories android:name="android.shortcut.conversation" />
|
||||
</shortcut>
|
||||
|
||||
<share-target android:targetClass="eu.faircode.email.ActivityMain">
|
||||
<category android:name="eu.faircode.email.TEXT_SHARE_TARGET" />
|
||||
<data android:mimeType="text/plain" />
|
||||
</share-target>
|
||||
</shortcuts>
|
Loading…
Reference in New Issue