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

Commit 807f0418 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #1519 from k9mail/recipient-inject-loaderman

Inject LoaderManager to RecipientSelectView via presenter
parents 2abcbf9c 034b1eda
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -357,8 +357,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,

        RecipientMvpView recipientMvpView = new RecipientMvpView(this);
        ComposePgpInlineDecider composePgpInlineDecider = new ComposePgpInlineDecider();
        recipientPresenter = new RecipientPresenter(this, recipientMvpView, mAccount,
                composePgpInlineDecider, new ReplyToParser());
        recipientPresenter = new RecipientPresenter(getApplicationContext(), getLoaderManager(), recipientMvpView,
                mAccount, composePgpInlineDecider, new ReplyToParser());

        mSubjectView = (EditText) findViewById(R.id.subject);
        mSubjectView.getInputExtras(true).putBoolean("allowEmoji", true);
+7 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ package com.fsck.k9.activity.compose;
import java.util.Arrays;
import java.util.List;

import android.app.LoaderManager;
import android.app.PendingIntent;
import android.text.TextWatcher;
import android.view.View;
@@ -379,6 +380,12 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener
        activity.launchUserInteractionPendingIntent(pendingIntent, requestCode);
    }

    public void setLoaderManager(LoaderManager loaderManager) {
        toView.setLoaderManager(loaderManager);
        ccView.setLoaderManager(loaderManager);
        bccView.setLoaderManager(loaderManager);
    }

    public enum CryptoStatusDisplayType {
        UNCONFIGURED(VIEW_INDEX_HIDDEN),
        UNINITIALIZED(VIEW_INDEX_HIDDEN),
+5 −2
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import java.util.Collections;
import java.util.List;

import android.app.Activity;
import android.app.LoaderManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -21,6 +22,7 @@ import com.fsck.k9.Account;
import com.fsck.k9.Identity;
import com.fsck.k9.K9;
import com.fsck.k9.R;
import com.fsck.k9.activity.MessageCompose;
import com.fsck.k9.activity.compose.ComposeCryptoStatus.AttachErrorState;
import com.fsck.k9.activity.compose.ComposeCryptoStatus.ComposeCryptoStatusBuilder;
import com.fsck.k9.activity.compose.ComposeCryptoStatus.SendErrorState;
@@ -78,14 +80,15 @@ public class RecipientPresenter implements PermissionPingCallback {
    private boolean cryptoEnablePgpInline = false;


    public RecipientPresenter(Context context, RecipientMvpView recipientMvpView, Account account,
            ComposePgpInlineDecider composePgpInlineDecider, ReplyToParser replyToParser) {
    public RecipientPresenter(Context context, LoaderManager loaderManager, RecipientMvpView recipientMvpView,
            Account account, ComposePgpInlineDecider composePgpInlineDecider, ReplyToParser replyToParser) {
        this.recipientMvpView = recipientMvpView;
        this.context = context;
        this.composePgpInlineDecider = composePgpInlineDecider;
        this.replyToParser = replyToParser;

        recipientMvpView.setPresenter(this);
        recipientMvpView.setLoaderManager(loaderManager);
        onSwitchAccount(account);
        updateCryptoStatus();
    }
+20 −17
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@ import java.io.Serializable;
import java.util.List;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.LoaderManager;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.Context;
@@ -56,13 +55,14 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem


    private RecipientAdapter adapter;
    @Nullable
    private String cryptoProvider;
    @Nullable
    private LoaderManager loaderManager;

    private ListPopupWindow alternatesPopup;
    private AlternateRecipientAdapter alternatesAdapter;
    private Recipient alternatesPopupRecipient;
    private boolean attachedToWindow = true;
    private TokenListener<Recipient> listener;


@@ -178,22 +178,18 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
        return getObjects().isEmpty();
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();

        attachedToWindow = true;

        if (getContext() instanceof Activity) {
            Activity activity = (Activity) getContext();
            loaderManager = activity.getLoaderManager();
        }
    public void setLoaderManager(@Nullable LoaderManager loaderManager) {
        this.loaderManager = loaderManager;
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        attachedToWindow = false;
        if (loaderManager != null) {
            loaderManager.destroyLoader(LOADER_ID_ALTERNATES);
            loaderManager.destroyLoader(LOADER_ID_FILTERING);
            loaderManager = null;
        }
    }

    @Override
@@ -241,8 +237,11 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem

    @Override
    protected void performFiltering(@NonNull CharSequence text, int start, int end, int keyCode) {
        String query = text.subSequence(start, end).toString();
        if (loaderManager == null) {
            return;
        }

        String query = text.subSequence(start, end).toString();
        if (TextUtils.isEmpty(query) || query.length() < MINIMUM_LENGTH_FOR_FILTERING) {
            loaderManager.destroyLoader(LOADER_ID_FILTERING);
            return;
@@ -253,7 +252,7 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
        loaderManager.restartLoader(LOADER_ID_FILTERING, args, this);
    }

    public void setCryptoProvider(String cryptoProvider) {
    public void setCryptoProvider(@Nullable String cryptoProvider) {
        this.cryptoProvider = cryptoProvider;
    }

@@ -274,7 +273,7 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
    }

    private void showAlternates(Recipient recipient) {
        if (!attachedToWindow) {
        if (loaderManager == null) {
            return;
        }

@@ -296,7 +295,7 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
    }

    public void showAlternatesPopup(List<Recipient> data) {
        if (!attachedToWindow) {
        if (loaderManager == null) {
            return;
        }

@@ -338,6 +337,10 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem

    @Override
    public void onLoadFinished(Loader<List<Recipient>> loader, List<Recipient> data) {
        if (loaderManager == null) {
            return;
        }

        switch (loader.getId()) {
            case LOADER_ID_FILTERING: {
                adapter.setRecipients(data);
+4 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ package com.fsck.k9.activity.compose;
import java.util.Arrays;
import java.util.List;

import android.app.LoaderManager;
import android.content.Context;

import com.fsck.k9.Account;
@@ -41,6 +42,7 @@ public class RecipientPresenterTest {
    private ComposePgpInlineDecider composePgpInlineDecider;
    private Account account;
    private RecipientMvpView recipientMvpView;
    private LoaderManager loaderManager;


    @Before
@@ -51,9 +53,10 @@ public class RecipientPresenterTest {
        account = mock(Account.class);
        composePgpInlineDecider = mock(ComposePgpInlineDecider.class);
        replyToParser = mock(ReplyToParser.class);
        loaderManager = mock(LoaderManager.class);

        recipientPresenter = new RecipientPresenter(
                context, recipientMvpView, account, composePgpInlineDecider, replyToParser);
                context, loaderManager, recipientMvpView, account, composePgpInlineDecider, replyToParser);
    }

    @Test