1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 09:08:49 -05:00

move NetworkType to k9mail-library, use on StoreConfig

This commit is contained in:
Art O Cathain 2015-03-08 12:59:15 +00:00
parent 147db8cc5e
commit 110400a85b
8 changed files with 40 additions and 25 deletions

View File

@ -0,0 +1,25 @@
package com.fsck.k9.mail;
import android.net.ConnectivityManager;
/**
* Enum for some of
* https://developer.android.com/reference/android/net/ConnectivityManager.html#TYPE_MOBILE etc.
*/
public enum NetworkType {
WIFI,
MOBILE,
OTHER;
public static NetworkType fromConnectivityManagerType(int type){
switch (type) {
case ConnectivityManager.TYPE_MOBILE:
return MOBILE;
case ConnectivityManager.TYPE_WIFI:
return WIFI;
default:
return OTHER;
}
}
}

View File

@ -1,12 +1,14 @@
package com.fsck.k9.mail.store;
import com.fsck.k9.mail.NetworkType;
public interface StoreConfig {
String getStoreUri();
String getTransportUri();
boolean subscribedFoldersOnly();
boolean useCompression(int type);
boolean useCompression(NetworkType type);
String getInboxFolderName();
String getOutboxFolderName();

View File

@ -11,6 +11,7 @@ import com.fsck.k9.mail.CertificateValidationException;
import com.fsck.k9.mail.ConnectionSecurity;
import com.fsck.k9.mail.K9MailLib;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.NetworkType;
import com.fsck.k9.mail.filter.Base64;
import com.fsck.k9.mail.filter.PeekableInputStream;
import com.fsck.k9.mail.ssl.TrustedSocketFactory;
@ -471,7 +472,8 @@ class ImapConnection {
if (K9MailLib.isDebug()) {
Log.d(LOG_TAG, "On network type " + type);
}
useCompression = mSettings.useCompression(type);
useCompression = mSettings.useCompression(
NetworkType.fromConnectivityManagerType(type));
}
if (K9MailLib.isDebug()) {
Log.d(LOG_TAG, "useCompression " + useCompression);

View File

@ -2,6 +2,7 @@ package com.fsck.k9.mail.store.imap;
import com.fsck.k9.mail.AuthType;
import com.fsck.k9.mail.ConnectionSecurity;
import com.fsck.k9.mail.NetworkType;
/**
* Settings source for IMAP. Implemented in order to remove coupling between {@link ImapStore} and {@link ImapConnection}.
@ -21,7 +22,7 @@ interface ImapSettings {
String getClientCertificateAlias();
boolean useCompression(int type);
boolean useCompression(NetworkType type);
String getPathPrefix();

View File

@ -37,6 +37,7 @@ import android.os.PowerManager;
import android.text.TextUtils;
import android.util.Log;
import com.fsck.k9.mail.NetworkType;
import com.fsck.k9.mail.internet.MimeMessageHelper;
import com.fsck.k9.mail.power.TracingPowerManager;
import com.fsck.k9.mail.power.TracingPowerManager.TracingWakeLock;
@ -2932,7 +2933,7 @@ public class ImapStore extends RemoteStore {
}
@Override
public boolean useCompression(final int type) {
public boolean useCompression(final NetworkType type) {
return mStoreConfig.useCompression(type);
}

View File

@ -13,6 +13,8 @@ import com.fsck.k9.mail.AuthType;
import com.fsck.k9.mail.AuthenticationFailedException;
import com.fsck.k9.mail.ConnectionSecurity;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.NetworkType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -167,7 +169,7 @@ public class ImapConnectionTest {
}
@Override
public boolean useCompression(int type) {
public boolean useCompression(NetworkType type) {
return false;
}

View File

@ -27,6 +27,7 @@ import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
import com.fsck.k9.helper.Utility;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.NetworkType;
import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.Folder.FolderClass;
import com.fsck.k9.mail.filter.Base64;
@ -96,12 +97,6 @@ public class Account implements BaseAccount, StoreConfig {
}
}
public enum NetworkType {
WIFI,
MOBILE,
OTHER
}
public static final MessageFormat DEFAULT_MESSAGE_FORMAT = MessageFormat.HTML;
public static final boolean DEFAULT_MESSAGE_FORMAT_AUTO = false;
public static final boolean DEFAULT_MESSAGE_READ_RECEIPT = false;
@ -1303,19 +1298,6 @@ public class Account implements BaseAccount, StoreConfig {
return useCompression;
}
public boolean useCompression(int type) {
NetworkType networkType = NetworkType.OTHER;
switch (type) {
case ConnectivityManager.TYPE_MOBILE:
networkType = NetworkType.MOBILE;
break;
case ConnectivityManager.TYPE_WIFI:
networkType = NetworkType.WIFI;
break;
}
return useCompression(networkType);
}
@Override
public boolean equals(Object o) {
if (o instanceof Account) {

View File

@ -17,7 +17,7 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
import com.fsck.k9.*;
import com.fsck.k9.Account.FolderMode;
import com.fsck.k9.Account.NetworkType;
import com.fsck.k9.mail.NetworkType;
import com.fsck.k9.activity.K9Activity;
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
import com.fsck.k9.helper.Utility;