mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-01-30 08:25:01 +01:00
added bandwidth saving mode - disables media preview while on metered network
This commit is contained in:
parent
1ebeada084
commit
6ca8f3b384
@ -289,7 +289,8 @@ public interface SharedPreferenceConstants {
|
||||
@Preference(type = STRING, hasDefault = true)
|
||||
String KEY_PROFILE_IMAGE_STYLE = "profile_image_style";
|
||||
|
||||
String KEY_QUICK_MENU_EXPANDED = "quick_menu_expanded";
|
||||
@Preference(type = STRING, hasDefault = true, defaultBoolean = true)
|
||||
String KEY_BANDWIDTH_SAVING_MODE = "bandwidth_saving_mode";
|
||||
|
||||
@Preference(type = STRING)
|
||||
String KEY_TRANSLATION_DESTINATION = "translation_destination";
|
||||
|
@ -111,7 +111,7 @@ dependencies {
|
||||
compile 'com.github.mariotaku:PickNCrop:0.9.3'
|
||||
compile 'com.github.mariotaku.RestFu:library:0.9.19'
|
||||
compile 'com.github.mariotaku.RestFu:okhttp3:0.9.19'
|
||||
compile 'com.squareup.okhttp3:okhttp:3.1.0'
|
||||
compile 'com.squareup.okhttp3:okhttp:3.1.2'
|
||||
compile 'com.lnikkila:extendedtouchview:0.1.0'
|
||||
compile 'com.google.dagger:dagger:2.0.2'
|
||||
compile 'org.attoparser:attoparser:1.4.0.RELEASE'
|
||||
|
@ -73,7 +73,7 @@ public abstract class AbsStatusesAdapter<D> extends LoadMoreSupportAdapter<ViewH
|
||||
mLinkHighlightingStyle = Utils.getLinkHighlightingStyleInt(mPreferences.getString(KEY_LINK_HIGHLIGHT_OPTION, null));
|
||||
mNameFirst = mPreferences.getBoolean(KEY_NAME_FIRST, true);
|
||||
mDisplayProfileImage = mPreferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true);
|
||||
mDisplayMediaPreview = mPreferences.getBoolean(KEY_MEDIA_PREVIEW, false);
|
||||
mDisplayMediaPreview = Utils.isMediaPreviewEnabled(context, mPreferences);
|
||||
mSensitiveContentEnabled = mPreferences.getBoolean(KEY_DISPLAY_SENSITIVE_CONTENTS, false);
|
||||
mHideCardActions = mPreferences.getBoolean(KEY_HIDE_CARD_ACTIONS, false);
|
||||
mUseStarsForLikes = mPreferences.getBoolean(KEY_I_WANT_MY_STARS_BACK);
|
||||
|
@ -1649,7 +1649,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
mLinkHighlightingStyle = Utils.getLinkHighlightingStyleInt(mPreferences.getString(KEY_LINK_HIGHLIGHT_OPTION, null));
|
||||
mIsCompact = compact;
|
||||
mDisplayProfileImage = mPreferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true);
|
||||
mDisplayMediaPreview = mPreferences.getBoolean(KEY_MEDIA_PREVIEW, false);
|
||||
mDisplayMediaPreview = Utils.isMediaPreviewEnabled(context, mPreferences);
|
||||
mSensitiveContentEnabled = mPreferences.getBoolean(KEY_DISPLAY_SENSITIVE_CONTENTS, false);
|
||||
mHideCardActions = mPreferences.getBoolean(KEY_HIDE_CARD_ACTIONS, false);
|
||||
mUseStarsForLikes = mPreferences.getBoolean(KEY_I_WANT_MY_STARS_BACK);
|
||||
|
@ -16,6 +16,7 @@ import java.net.Proxy;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.Authenticator;
|
||||
import okhttp3.ConnectionPool;
|
||||
import okhttp3.Credentials;
|
||||
import okhttp3.Dns;
|
||||
import okhttp3.OkHttpClient;
|
||||
@ -29,6 +30,7 @@ import static android.text.TextUtils.isEmpty;
|
||||
* Created by mariotaku on 16/1/27.
|
||||
*/
|
||||
public class HttpClientFactory implements Constants {
|
||||
|
||||
public static RestHttpClient getDefaultHttpClient(final Context context, SharedPreferences prefs, Dns dns) {
|
||||
if (context == null) return null;
|
||||
return createHttpClient(context, prefs, dns);
|
||||
@ -52,6 +54,7 @@ public class HttpClientFactory implements Constants {
|
||||
final long connectionTimeout = prefs.getInt(KEY_CONNECTION_TIMEOUT, 10);
|
||||
final boolean enableProxy = prefs.getBoolean(KEY_ENABLE_PROXY, false);
|
||||
builder.connectTimeout(connectionTimeout, TimeUnit.SECONDS);
|
||||
builder.connectionPool(new ConnectionPool(0, 1, TimeUnit.MINUTES));
|
||||
if (enableProxy) {
|
||||
final String proxyType = prefs.getString(KEY_PROXY_TYPE, null);
|
||||
final String proxyHost = prefs.getString(KEY_PROXY_HOST, null);
|
||||
|
@ -73,6 +73,7 @@ import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.net.ConnectivityManagerCompat;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.support.v4.view.ActionProvider;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
@ -2976,6 +2977,12 @@ public final class Utils implements Constants {
|
||||
return TwitterAPIFactory.isOfficialKeyAccount(context, accountId);
|
||||
}
|
||||
|
||||
public static boolean isMediaPreviewEnabled(Context context, SharedPreferencesWrapper preferences) {
|
||||
if (!preferences.getBoolean(KEY_MEDIA_PREVIEW)) return false;
|
||||
final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
return !ConnectivityManagerCompat.isActiveNetworkMetered(cm) || !preferences.getBoolean(KEY_BANDWIDTH_SAVING_MODE);
|
||||
}
|
||||
|
||||
static class UtilsL {
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
|
@ -847,4 +847,6 @@
|
||||
<string name="network_diagnostics">Network diagnostics</string>
|
||||
<string name="action_start">Start</string>
|
||||
<string name="builtin_dns_resolver">Builtin DNS resolver</string>
|
||||
<string name="bandwidth_saving_mode">Bandwidth saving mode</string>
|
||||
<string name="bandwidth_saving_mode_summary">Disable media preview on metered network</string>
|
||||
</resources>
|
@ -10,6 +10,13 @@
|
||||
android:defaultValue="true"
|
||||
android:key="preload_wifi_only"
|
||||
android:title="@string/preload_wifi_only"/>
|
||||
|
||||
<org.mariotaku.twidere.preference.AutoFixSwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="bandwidth_saving_mode"
|
||||
android:summary="@string/bandwidth_saving_mode_summary"
|
||||
android:title="@string/bandwidth_saving_mode"/>
|
||||
|
||||
<Preference
|
||||
android:fragment="org.mariotaku.twidere.fragment.SettingsDetailsFragment"
|
||||
android:title="@string/advanced">
|
||||
|
Loading…
x
Reference in New Issue
Block a user