Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 509453bd authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #6302 from thundernest/remove_direct_share

Remove Direct Share support
parents 3790620d 1766bbe2
Loading
Loading
Loading
Loading
+0 −14
Original line number Diff line number Diff line
@@ -221,10 +221,6 @@
                <action android:name="org.autocrypt.PEER_ACTION"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>

            <meta-data
                android:name="android.service.chooser.chooser_target_service"
                android:value="com.fsck.k9.directshare.K9ChooserTargetService" />
        </activity>

        <!-- Search Activity - searchable -->
@@ -354,16 +350,6 @@
            android:name=".service.DatabaseUpgradeService"
            android:exported="false"/>


        <service
            android:name="com.fsck.k9.directshare.K9ChooserTargetService"
            android:permission="android.permission.BIND_CHOOSER_TARGET_SERVICE"
            android:exported="false">
            <intent-filter>
                <action android:name="android.service.chooser.ChooserTargetService" />
            </intent-filter>
        </service>

        <service
            android:name="com.fsck.k9.account.AccountRemoverService"
            android:permission="android.permission.BIND_JOB_SERVICE"/>
+0 −93
Original line number Diff line number Diff line
package com.fsck.k9.directshare;


import java.util.ArrayList;
import java.util.List;

import android.annotation.TargetApi;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.os.Bundle;
import android.service.chooser.ChooserTarget;
import android.service.chooser.ChooserTargetService;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.fsck.k9.activity.MessageCompose;
import com.fsck.k9.activity.compose.RecipientLoader;
import com.fsck.k9.activity.misc.ContactPicture;
import com.fsck.k9.contacts.ContactPictureLoader;
import com.fsck.k9.mail.Address;
import com.fsck.k9.view.RecipientSelectView.Recipient;


@TargetApi(Build.VERSION_CODES.M)
public class K9ChooserTargetService extends ChooserTargetService {
    private static final int MAX_TARGETS = 5;

    private RecipientLoader recipientLoader;
    private ContactPictureLoader contactPictureLoader;

    @Override
    public void onCreate() {
        super.onCreate();

        Context applicationContext = getApplicationContext();
        recipientLoader = RecipientLoader.getMostContactedRecipientLoader(applicationContext, MAX_TARGETS);
        contactPictureLoader = ContactPicture.getContactPictureLoader();
    }

    @Override
    public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
        List<Recipient> recipients = recipientLoader.loadInBackground();

        return createChooserTargets(recipients);
    }

    @NonNull
    private List<ChooserTarget> createChooserTargets(List<Recipient> recipients) {
        float score = 1.0f;

        List<ChooserTarget> targets = new ArrayList<>();
        ComponentName componentName = new ComponentName(this, MessageCompose.class);
        for (Recipient recipient : recipients) {
            Bundle intentExtras = prepareIntentExtras(recipient);
            Icon icon = loadRecipientIcon(recipient);

            ChooserTarget chooserTarget =
                    new ChooserTarget(recipient.getDisplayNameOrAddress(), icon, score, componentName, intentExtras);
            targets.add(chooserTarget);

            score -= 0.1;
        }

        return targets;
    }

    @NonNull
    private Bundle prepareIntentExtras(Recipient recipient) {
        Address address = recipient.address;

        Bundle extras = new Bundle();
        extras.putStringArray(Intent.EXTRA_EMAIL, new String[] { address.toString() });
        extras.putStringArray(Intent.EXTRA_CC, new String[0]);
        extras.putStringArray(Intent.EXTRA_BCC, new String[0]);

        return extras;
    }

    @Nullable
    private Icon loadRecipientIcon(Recipient recipient) {
        Bitmap bitmap = contactPictureLoader.getContactPicture(recipient);
        if (bitmap == null) {
            return null;
        }

        return Icon.createWithBitmap(bitmap);
    }
}