[limited-bandwidth] Reduce timeline loading after toot
This commit is contained in:
parent
84d0f9ec1c
commit
6b15c009ed
|
@ -15,9 +15,12 @@
|
|||
|
||||
package com.keylesspalace.tusky.fragment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
@ -105,6 +108,7 @@ import retrofit2.Call;
|
|||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
import static android.content.Context.CONNECTIVITY_SERVICE;
|
||||
import static com.uber.autodispose.AutoDispose.autoDisposable;
|
||||
import static com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider.from;
|
||||
|
||||
|
@ -170,6 +174,10 @@ public class TimelineFragment extends SFragment implements
|
|||
private boolean alwaysOpenSpoiler;
|
||||
private boolean initialUpdateFailed = false;
|
||||
|
||||
private SharedPreferences preferences;
|
||||
private boolean reduceTimelineRoading;
|
||||
private boolean checkMobileNetwork;
|
||||
|
||||
private PairedList<Either<Placeholder, Status>, StatusViewData> statuses =
|
||||
new PairedList<>(new Function<Either<Placeholder, Status>, StatusViewData>() {
|
||||
@Override
|
||||
|
@ -223,6 +231,7 @@ public class TimelineFragment extends SFragment implements
|
|||
|
||||
isSwipeToRefreshEnabled = arguments.getBoolean(ARG_ENABLE_SWIPE_TO_REFRESH, true);
|
||||
|
||||
preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -359,6 +368,8 @@ public class TimelineFragment extends SFragment implements
|
|||
filter = preferences.getBoolean("tabFilterHomeBoosts", true);
|
||||
filterRemoveReblogs = kind == Kind.HOME && !filter;
|
||||
reloadFilters(false);
|
||||
|
||||
updateLimitedBandwidthStatus();
|
||||
}
|
||||
|
||||
private static boolean filterContextMatchesKind(Kind kind, List<String> filterContext) {
|
||||
|
@ -859,9 +870,20 @@ public class TimelineFragment extends SFragment implements
|
|||
alwaysShowSensitiveMedia = accountManager.getActiveAccount().getAlwaysShowSensitiveMedia();
|
||||
break;
|
||||
}
|
||||
case "limitedBandwidthActive":
|
||||
case "limitedBandwidthOnlyMobileNetwork":
|
||||
case "limitedBandwidthTimelineRoading": {
|
||||
updateLimitedBandwidthStatus();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLimitedBandwidthStatus() {
|
||||
reduceTimelineRoading = preferences.getBoolean("limitedBandwidthActive", false) && preferences.getBoolean("limitedBandwidthTimelineRoading", true);
|
||||
checkMobileNetwork = preferences.getBoolean("limitedBandwidthOnlyMobileNetwork", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeItem(int position) {
|
||||
statuses.remove(position);
|
||||
|
@ -1301,7 +1323,24 @@ public class TimelineFragment extends SFragment implements
|
|||
case LIST:
|
||||
return;
|
||||
}
|
||||
onRefresh();
|
||||
|
||||
boolean reloadTimeline = true;
|
||||
|
||||
if (reduceTimelineRoading) {
|
||||
reloadTimeline = false;
|
||||
Activity activity = getActivity();
|
||||
if (checkMobileNetwork && activity != null) {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) activity.getSystemService(CONNECTIVITY_SERVICE);
|
||||
NetworkInfo info = connectivityManager.getActiveNetworkInfo();
|
||||
if (info != null && info.getType() == ConnectivityManager.TYPE_WIFI) {
|
||||
reloadTimeline = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (reloadTimeline) {
|
||||
onRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
private List<Either<Placeholder, Status>> liftStatusList(List<Status> list) {
|
||||
|
@ -1400,7 +1439,6 @@ public class TimelineFragment extends SFragment implements
|
|||
* Auto dispose observable on pause
|
||||
*/
|
||||
private void startUpdateTimestamp() {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
boolean useAbsoluteTime = preferences.getBoolean("absoluteTimeView", false);
|
||||
if (!useAbsoluteTime) {
|
||||
Observable.interval(1, TimeUnit.MINUTES)
|
||||
|
|
|
@ -173,6 +173,7 @@
|
|||
<string name="pref_title_limited_bandwidth_settings">通信制限モード</string>
|
||||
<string name="pref_title_limited_bandwidth_active">通信制限モードを使う</string>
|
||||
<string name="pref_title_limited_bandwidth_mobile">モバイルネットワークでのみ有効</string>
|
||||
<string name="pref_title_limited_bandwidth_timeline">トゥート後のタイムラインの自動更新をしない</string>
|
||||
<string name="app_them_dark">ダーク</string>
|
||||
<string name="app_theme_light">ライト</string>
|
||||
<string name="app_theme_black">ブラック</string>
|
||||
|
|
|
@ -215,6 +215,7 @@
|
|||
<string name="pref_title_limited_bandwidth_settings">Limited Bandwidth Mode</string>
|
||||
<string name="pref_title_limited_bandwidth_active">Use Limited Bandwidth Mode</string>
|
||||
<string name="pref_title_limited_bandwidth_mobile">Active during using mobile network.</string>
|
||||
<string name="pref_title_limited_bandwidth_timeline">Reduce timeline auto reload after toot</string>
|
||||
|
||||
<string name="app_them_dark">Dark</string>
|
||||
<string name="app_theme_light">Light</string>
|
||||
|
|
|
@ -81,6 +81,12 @@
|
|||
android:key="limitedBandwidthOnlyMobileNetwork"
|
||||
android:title="@string/pref_title_limited_bandwidth_mobile"
|
||||
android:dependency="limitedBandwidthActive" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="limitedBandwidthTimelineRoading"
|
||||
android:title="@string/pref_title_limited_bandwidth_timeline"
|
||||
android:dependency="limitedBandwidthActive" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/pref_title_browser_settings">
|
||||
|
|
Loading…
Reference in New Issue