Merge pull request #1519 from k9mail/recipient-inject-loaderman
Inject LoaderManager to RecipientSelectView via presenter
This commit is contained in:
commit
807f0418d8
5 changed files with 38 additions and 22 deletions
|
@ -357,8 +357,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
||||||
|
|
||||||
RecipientMvpView recipientMvpView = new RecipientMvpView(this);
|
RecipientMvpView recipientMvpView = new RecipientMvpView(this);
|
||||||
ComposePgpInlineDecider composePgpInlineDecider = new ComposePgpInlineDecider();
|
ComposePgpInlineDecider composePgpInlineDecider = new ComposePgpInlineDecider();
|
||||||
recipientPresenter = new RecipientPresenter(this, recipientMvpView, mAccount,
|
recipientPresenter = new RecipientPresenter(getApplicationContext(), getLoaderManager(), recipientMvpView,
|
||||||
composePgpInlineDecider, new ReplyToParser());
|
mAccount, composePgpInlineDecider, new ReplyToParser());
|
||||||
|
|
||||||
mSubjectView = (EditText) findViewById(R.id.subject);
|
mSubjectView = (EditText) findViewById(R.id.subject);
|
||||||
mSubjectView.getInputExtras(true).putBoolean("allowEmoji", true);
|
mSubjectView.getInputExtras(true).putBoolean("allowEmoji", true);
|
||||||
|
|
|
@ -4,6 +4,7 @@ package com.fsck.k9.activity.compose;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import android.app.LoaderManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -379,6 +380,12 @@ public class RecipientMvpView implements OnFocusChangeListener, OnClickListener
|
||||||
activity.launchUserInteractionPendingIntent(pendingIntent, requestCode);
|
activity.launchUserInteractionPendingIntent(pendingIntent, requestCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLoaderManager(LoaderManager loaderManager) {
|
||||||
|
toView.setLoaderManager(loaderManager);
|
||||||
|
ccView.setLoaderManager(loaderManager);
|
||||||
|
bccView.setLoaderManager(loaderManager);
|
||||||
|
}
|
||||||
|
|
||||||
public enum CryptoStatusDisplayType {
|
public enum CryptoStatusDisplayType {
|
||||||
UNCONFIGURED(VIEW_INDEX_HIDDEN),
|
UNCONFIGURED(VIEW_INDEX_HIDDEN),
|
||||||
UNINITIALIZED(VIEW_INDEX_HIDDEN),
|
UNINITIALIZED(VIEW_INDEX_HIDDEN),
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.LoaderManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -21,6 +22,7 @@ import com.fsck.k9.Account;
|
||||||
import com.fsck.k9.Identity;
|
import com.fsck.k9.Identity;
|
||||||
import com.fsck.k9.K9;
|
import com.fsck.k9.K9;
|
||||||
import com.fsck.k9.R;
|
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.AttachErrorState;
|
||||||
import com.fsck.k9.activity.compose.ComposeCryptoStatus.ComposeCryptoStatusBuilder;
|
import com.fsck.k9.activity.compose.ComposeCryptoStatus.ComposeCryptoStatusBuilder;
|
||||||
import com.fsck.k9.activity.compose.ComposeCryptoStatus.SendErrorState;
|
import com.fsck.k9.activity.compose.ComposeCryptoStatus.SendErrorState;
|
||||||
|
@ -78,14 +80,15 @@ public class RecipientPresenter implements PermissionPingCallback {
|
||||||
private boolean cryptoEnablePgpInline = false;
|
private boolean cryptoEnablePgpInline = false;
|
||||||
|
|
||||||
|
|
||||||
public RecipientPresenter(Context context, RecipientMvpView recipientMvpView, Account account,
|
public RecipientPresenter(Context context, LoaderManager loaderManager, RecipientMvpView recipientMvpView,
|
||||||
ComposePgpInlineDecider composePgpInlineDecider, ReplyToParser replyToParser) {
|
Account account, ComposePgpInlineDecider composePgpInlineDecider, ReplyToParser replyToParser) {
|
||||||
this.recipientMvpView = recipientMvpView;
|
this.recipientMvpView = recipientMvpView;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.composePgpInlineDecider = composePgpInlineDecider;
|
this.composePgpInlineDecider = composePgpInlineDecider;
|
||||||
this.replyToParser = replyToParser;
|
this.replyToParser = replyToParser;
|
||||||
|
|
||||||
recipientMvpView.setPresenter(this);
|
recipientMvpView.setPresenter(this);
|
||||||
|
recipientMvpView.setLoaderManager(loaderManager);
|
||||||
onSwitchAccount(account);
|
onSwitchAccount(account);
|
||||||
updateCryptoStatus();
|
updateCryptoStatus();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.LoaderManager;
|
import android.app.LoaderManager;
|
||||||
import android.app.LoaderManager.LoaderCallbacks;
|
import android.app.LoaderManager.LoaderCallbacks;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -56,13 +55,14 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
|
||||||
|
|
||||||
|
|
||||||
private RecipientAdapter adapter;
|
private RecipientAdapter adapter;
|
||||||
|
@Nullable
|
||||||
private String cryptoProvider;
|
private String cryptoProvider;
|
||||||
|
@Nullable
|
||||||
private LoaderManager loaderManager;
|
private LoaderManager loaderManager;
|
||||||
|
|
||||||
private ListPopupWindow alternatesPopup;
|
private ListPopupWindow alternatesPopup;
|
||||||
private AlternateRecipientAdapter alternatesAdapter;
|
private AlternateRecipientAdapter alternatesAdapter;
|
||||||
private Recipient alternatesPopupRecipient;
|
private Recipient alternatesPopupRecipient;
|
||||||
private boolean attachedToWindow = true;
|
|
||||||
private TokenListener<Recipient> listener;
|
private TokenListener<Recipient> listener;
|
||||||
|
|
||||||
|
|
||||||
|
@ -178,22 +178,18 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
|
||||||
return getObjects().isEmpty();
|
return getObjects().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setLoaderManager(@Nullable LoaderManager loaderManager) {
|
||||||
protected void onAttachedToWindow() {
|
this.loaderManager = loaderManager;
|
||||||
super.onAttachedToWindow();
|
|
||||||
|
|
||||||
attachedToWindow = true;
|
|
||||||
|
|
||||||
if (getContext() instanceof Activity) {
|
|
||||||
Activity activity = (Activity) getContext();
|
|
||||||
loaderManager = activity.getLoaderManager();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDetachedFromWindow() {
|
protected void onDetachedFromWindow() {
|
||||||
super.onDetachedFromWindow();
|
super.onDetachedFromWindow();
|
||||||
attachedToWindow = false;
|
if (loaderManager != null) {
|
||||||
|
loaderManager.destroyLoader(LOADER_ID_ALTERNATES);
|
||||||
|
loaderManager.destroyLoader(LOADER_ID_FILTERING);
|
||||||
|
loaderManager = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -241,8 +237,11 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void performFiltering(@NonNull CharSequence text, int start, int end, int keyCode) {
|
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) {
|
if (TextUtils.isEmpty(query) || query.length() < MINIMUM_LENGTH_FOR_FILTERING) {
|
||||||
loaderManager.destroyLoader(LOADER_ID_FILTERING);
|
loaderManager.destroyLoader(LOADER_ID_FILTERING);
|
||||||
return;
|
return;
|
||||||
|
@ -253,7 +252,7 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
|
||||||
loaderManager.restartLoader(LOADER_ID_FILTERING, args, this);
|
loaderManager.restartLoader(LOADER_ID_FILTERING, args, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCryptoProvider(String cryptoProvider) {
|
public void setCryptoProvider(@Nullable String cryptoProvider) {
|
||||||
this.cryptoProvider = cryptoProvider;
|
this.cryptoProvider = cryptoProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +273,7 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showAlternates(Recipient recipient) {
|
private void showAlternates(Recipient recipient) {
|
||||||
if (!attachedToWindow) {
|
if (loaderManager == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +295,7 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showAlternatesPopup(List<Recipient> data) {
|
public void showAlternatesPopup(List<Recipient> data) {
|
||||||
if (!attachedToWindow) {
|
if (loaderManager == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,6 +337,10 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFinished(Loader<List<Recipient>> loader, List<Recipient> data) {
|
public void onLoadFinished(Loader<List<Recipient>> loader, List<Recipient> data) {
|
||||||
|
if (loaderManager == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (loader.getId()) {
|
switch (loader.getId()) {
|
||||||
case LOADER_ID_FILTERING: {
|
case LOADER_ID_FILTERING: {
|
||||||
adapter.setRecipients(data);
|
adapter.setRecipients(data);
|
||||||
|
|
|
@ -4,6 +4,7 @@ package com.fsck.k9.activity.compose;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import android.app.LoaderManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.fsck.k9.Account;
|
import com.fsck.k9.Account;
|
||||||
|
@ -41,6 +42,7 @@ public class RecipientPresenterTest {
|
||||||
private ComposePgpInlineDecider composePgpInlineDecider;
|
private ComposePgpInlineDecider composePgpInlineDecider;
|
||||||
private Account account;
|
private Account account;
|
||||||
private RecipientMvpView recipientMvpView;
|
private RecipientMvpView recipientMvpView;
|
||||||
|
private LoaderManager loaderManager;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -51,9 +53,10 @@ public class RecipientPresenterTest {
|
||||||
account = mock(Account.class);
|
account = mock(Account.class);
|
||||||
composePgpInlineDecider = mock(ComposePgpInlineDecider.class);
|
composePgpInlineDecider = mock(ComposePgpInlineDecider.class);
|
||||||
replyToParser = mock(ReplyToParser.class);
|
replyToParser = mock(ReplyToParser.class);
|
||||||
|
loaderManager = mock(LoaderManager.class);
|
||||||
|
|
||||||
recipientPresenter = new RecipientPresenter(
|
recipientPresenter = new RecipientPresenter(
|
||||||
context, recipientMvpView, account, composePgpInlineDecider, replyToParser);
|
context, loaderManager, recipientMvpView, account, composePgpInlineDecider, replyToParser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue