mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-01 13:57:10 +01:00
Data Saving Mode is available.
This commit is contained in:
parent
c4f8c91944
commit
62a457a868
@ -82,7 +82,7 @@ import ml.docilealligator.infinityforreddit.CustomView.CustomToroContainer;
|
|||||||
import ml.docilealligator.infinityforreddit.DeleteThing;
|
import ml.docilealligator.infinityforreddit.DeleteThing;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeWifiStatusEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeNetworkStatusEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToDetailActivity;
|
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToDetailActivity;
|
||||||
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList;
|
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList;
|
||||||
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
||||||
@ -1373,11 +1373,21 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onChangeWifiStatusEvent(ChangeWifiStatusEvent changeWifiStatusEvent) {
|
public void onChangeNetworkStatusEvent(ChangeNetworkStatusEvent changeNetworkStatusEvent) {
|
||||||
if (mAdapter != null) {
|
if (mAdapter != null) {
|
||||||
String autoplay = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
|
String autoplay = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
|
||||||
|
String dataSavingMode = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
|
||||||
|
boolean stateChanged = false;
|
||||||
if (autoplay.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
|
if (autoplay.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
|
||||||
mAdapter.setAutoplay(changeWifiStatusEvent.isConnectedToWifi);
|
mAdapter.setAutoplay(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_WIFI);
|
||||||
|
stateChanged = true;
|
||||||
|
}
|
||||||
|
if (dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
|
||||||
|
mAdapter.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
|
||||||
|
stateChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stateChanged) {
|
||||||
refreshAdapter();
|
refreshAdapter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,6 +177,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
private double mStartAutoplayVisibleAreaOffset;
|
private double mStartAutoplayVisibleAreaOffset;
|
||||||
private boolean mMuteNSFWVideo;
|
private boolean mMuteNSFWVideo;
|
||||||
private boolean mAutomaticallyTryRedgifs;
|
private boolean mAutomaticallyTryRedgifs;
|
||||||
|
private boolean mDataSavingMode;
|
||||||
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
|
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
|
||||||
private boolean isInitiallyLoading;
|
private boolean isInitiallyLoading;
|
||||||
private boolean isInitiallyLoadingFailed;
|
private boolean isInitiallyLoadingFailed;
|
||||||
@ -463,10 +464,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
mShowAbsoluteNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
|
mShowAbsoluteNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
|
||||||
|
|
||||||
String autoplayString = sharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
|
String autoplayString = sharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
|
||||||
|
int networkType = Utils.getConnectedNetwork(activity);
|
||||||
if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ALWAYS_ON)) {
|
if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ALWAYS_ON)) {
|
||||||
mAutoplay = true;
|
mAutoplay = true;
|
||||||
} else if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
|
} else if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
|
||||||
mAutoplay = Utils.isConnectedToWifi(activity);
|
mAutoplay = networkType == Utils.NETWORK_TYPE_WIFI;
|
||||||
}
|
}
|
||||||
mAutoplayNsfwVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS, true);
|
mAutoplayNsfwVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS, true);
|
||||||
mMuteAutoplayingVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS, true);
|
mMuteAutoplayingVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS, true);
|
||||||
@ -480,6 +482,13 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
mMuteNSFWVideo = sharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_NSFW_VIDEO, false);
|
mMuteNSFWVideo = sharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_NSFW_VIDEO, false);
|
||||||
mAutomaticallyTryRedgifs = sharedPreferences.getBoolean(SharedPreferencesUtils.AUTOMATICALLY_TRY_REDGIFS, true);
|
mAutomaticallyTryRedgifs = sharedPreferences.getBoolean(SharedPreferencesUtils.AUTOMATICALLY_TRY_REDGIFS, true);
|
||||||
|
|
||||||
|
String dataSavingModeString = sharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
|
||||||
|
if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ALWAYS)) {
|
||||||
|
mDataSavingMode = true;
|
||||||
|
} else if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
|
||||||
|
mDataSavingMode = networkType == Utils.NETWORK_TYPE_CELLULAR;
|
||||||
|
}
|
||||||
|
|
||||||
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
|
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
|
||||||
isInitiallyLoading = true;
|
isInitiallyLoading = true;
|
||||||
isInitiallyLoadingFailed = false;
|
isInitiallyLoadingFailed = false;
|
||||||
@ -1401,7 +1410,13 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
private Post.Preview getSuitablePreview(ArrayList<Post.Preview> previews) {
|
private Post.Preview getSuitablePreview(ArrayList<Post.Preview> previews) {
|
||||||
Post.Preview preview;
|
Post.Preview preview;
|
||||||
if (!previews.isEmpty()) {
|
if (!previews.isEmpty()) {
|
||||||
preview = previews.get(0);
|
int previewIndex;
|
||||||
|
if (mDataSavingMode && previews.size() > 2) {
|
||||||
|
previewIndex = previews.size() / 2;
|
||||||
|
} else {
|
||||||
|
previewIndex = 0;
|
||||||
|
}
|
||||||
|
preview = previews.get(previewIndex);
|
||||||
if (preview.getPreviewWidth() * preview.getPreviewHeight() >= 65 * 1000 * 1000) {
|
if (preview.getPreviewWidth() * preview.getPreviewHeight() >= 65 * 1000 * 1000) {
|
||||||
for (int i = previews.size() - 1; i >= 1; i--) {
|
for (int i = previews.size() - 1; i >= 1; i--) {
|
||||||
preview = previews.get(i);
|
preview = previews.get(i);
|
||||||
@ -1835,6 +1850,10 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
mAutoplay = autoplay;
|
mAutoplay = autoplay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDataSavingMode(boolean dataSavingMode) {
|
||||||
|
mDataSavingMode = dataSavingMode;
|
||||||
|
}
|
||||||
|
|
||||||
public void onItemSwipe(RecyclerView.ViewHolder viewHolder, int direction) {
|
public void onItemSwipe(RecyclerView.ViewHolder viewHolder, int direction) {
|
||||||
if (viewHolder instanceof PostDetailBaseViewHolder) {
|
if (viewHolder instanceof PostDetailBaseViewHolder) {
|
||||||
if (direction == ItemTouchHelper.LEFT || direction == ItemTouchHelper.START) {
|
if (direction == ItemTouchHelper.LEFT || direction == ItemTouchHelper.START) {
|
||||||
|
@ -186,7 +186,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
private boolean mAutomaticallyTryRedgifs;
|
private boolean mAutomaticallyTryRedgifs;
|
||||||
private boolean mLongPressToHideToolbarInCompactLayout;
|
private boolean mLongPressToHideToolbarInCompactLayout;
|
||||||
private boolean mCompactLayoutToolbarHiddenByDefault;
|
private boolean mCompactLayoutToolbarHiddenByDefault;
|
||||||
private boolean mDataSavingMode;
|
private boolean mDataSavingMode = false;
|
||||||
private Drawable mCommentIcon;
|
private Drawable mCommentIcon;
|
||||||
private NetworkState networkState;
|
private NetworkState networkState;
|
||||||
private ExoCreator mExoCreator;
|
private ExoCreator mExoCreator;
|
||||||
@ -219,10 +219,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
mShowDividerInCompactLayout = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT, true);
|
mShowDividerInCompactLayout = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT, true);
|
||||||
mShowAbsoluteNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
|
mShowAbsoluteNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
|
||||||
String autoplayString = sharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
|
String autoplayString = sharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
|
||||||
|
int networkType = Utils.getConnectedNetwork(activity);
|
||||||
if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ALWAYS_ON)) {
|
if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ALWAYS_ON)) {
|
||||||
mAutoplay = true;
|
mAutoplay = true;
|
||||||
} else if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
|
} else if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
|
||||||
mAutoplay = Utils.isConnectedToWifi(activity);
|
mAutoplay = networkType == Utils.NETWORK_TYPE_WIFI;
|
||||||
}
|
}
|
||||||
mAutoplayNsfwVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS, true);
|
mAutoplayNsfwVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS, true);
|
||||||
mMuteAutoplayingVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS, true);
|
mMuteAutoplayingVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS, true);
|
||||||
@ -240,6 +241,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
mLongPressToHideToolbarInCompactLayout = sharedPreferences.getBoolean(SharedPreferencesUtils.LONG_PRESS_TO_HIDE_TOOLBAR_IN_COMPACT_LAYOUT, false);
|
mLongPressToHideToolbarInCompactLayout = sharedPreferences.getBoolean(SharedPreferencesUtils.LONG_PRESS_TO_HIDE_TOOLBAR_IN_COMPACT_LAYOUT, false);
|
||||||
mCompactLayoutToolbarHiddenByDefault = sharedPreferences.getBoolean(SharedPreferencesUtils.POST_COMPACT_LAYOUT_TOOLBAR_HIDDEN_BY_DEFAULT, false);
|
mCompactLayoutToolbarHiddenByDefault = sharedPreferences.getBoolean(SharedPreferencesUtils.POST_COMPACT_LAYOUT_TOOLBAR_HIDDEN_BY_DEFAULT, false);
|
||||||
|
|
||||||
|
String dataSavingModeString = sharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
|
||||||
|
if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ALWAYS)) {
|
||||||
|
mDataSavingMode = true;
|
||||||
|
} else if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
|
||||||
|
mDataSavingMode = networkType == Utils.NETWORK_TYPE_CELLULAR;
|
||||||
|
}
|
||||||
|
|
||||||
mPostLayout = postLayout;
|
mPostLayout = postLayout;
|
||||||
|
|
||||||
mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme();
|
mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme();
|
||||||
@ -945,17 +953,23 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
private Post.Preview getSuitablePreview(ArrayList<Post.Preview> previews) {
|
private Post.Preview getSuitablePreview(ArrayList<Post.Preview> previews) {
|
||||||
Post.Preview preview;
|
Post.Preview preview;
|
||||||
if (!previews.isEmpty()) {
|
if (!previews.isEmpty()) {
|
||||||
preview = previews.get(0);
|
int previewIndex;
|
||||||
if (preview.getPreviewWidth() * preview.getPreviewHeight() >= 65 * 1000 * 1000) {
|
if (mDataSavingMode && previews.size() > 2) {
|
||||||
|
previewIndex = previews.size() / 2;
|
||||||
|
} else {
|
||||||
|
previewIndex = 0;
|
||||||
|
}
|
||||||
|
preview = previews.get(previewIndex);
|
||||||
|
if (preview.getPreviewWidth() * preview.getPreviewHeight() >= 75_000_000) {
|
||||||
for (int i = previews.size() - 1; i >= 1; i--) {
|
for (int i = previews.size() - 1; i >= 1; i--) {
|
||||||
preview = previews.get(i);
|
preview = previews.get(i);
|
||||||
if (mImageViewWidth >= preview.getPreviewWidth()) {
|
if (mImageViewWidth >= preview.getPreviewWidth()) {
|
||||||
if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 75 * 1000 * 1000) {
|
if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 75_000_000) {
|
||||||
return preview;
|
return preview;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int height = mImageViewWidth / preview.getPreviewWidth() * preview.getPreviewHeight();
|
int height = mImageViewWidth / preview.getPreviewWidth() * preview.getPreviewHeight();
|
||||||
if (mImageViewWidth * height <= 75 * 1000 * 1000) {
|
if (mImageViewWidth * height <= 75_000_000) {
|
||||||
return preview;
|
return preview;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -963,7 +977,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
}
|
}
|
||||||
|
|
||||||
int divisor = 2;
|
int divisor = 2;
|
||||||
while (preview.getPreviewWidth() * preview.getPreviewHeight() / divisor / divisor > 75 * 1000 * 1000) {
|
while (preview.getPreviewWidth() * preview.getPreviewHeight() / divisor / divisor > 75_000_000) {
|
||||||
preview.setPreviewWidth(preview.getPreviewWidth() / divisor);
|
preview.setPreviewWidth(preview.getPreviewWidth() / divisor);
|
||||||
preview.setPreviewHeight(preview.getPreviewHeight() / divisor);
|
preview.setPreviewHeight(preview.getPreviewHeight() / divisor);
|
||||||
divisor *= 2;
|
divisor *= 2;
|
||||||
@ -1275,6 +1289,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
mCompactLayoutToolbarHiddenByDefault = compactLayoutToolbarHiddenByDefault;
|
mCompactLayoutToolbarHiddenByDefault = compactLayoutToolbarHiddenByDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDataSavingMode(boolean dataSavingMode) {
|
||||||
|
mDataSavingMode = dataSavingMode;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
||||||
super.onViewRecycled(holder);
|
super.onViewRecycled(holder);
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit.Event;
|
||||||
|
|
||||||
|
public class ChangeDataSavingModeEvent {
|
||||||
|
public String dataSavingMode;
|
||||||
|
|
||||||
|
public ChangeDataSavingModeEvent(String dataSavingMode) {
|
||||||
|
this.dataSavingMode = dataSavingMode;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit.Event;
|
||||||
|
|
||||||
|
public class ChangeNetworkStatusEvent {
|
||||||
|
public int connectedNetwork;
|
||||||
|
|
||||||
|
public ChangeNetworkStatusEvent(int connectedNetwork) {
|
||||||
|
this.connectedNetwork = connectedNetwork;
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +0,0 @@
|
|||||||
package ml.docilealligator.infinityforreddit.Event;
|
|
||||||
|
|
||||||
public class ChangeWifiStatusEvent {
|
|
||||||
public boolean isConnectedToWifi;
|
|
||||||
public ChangeWifiStatusEvent(boolean isConnectedToWifi) {
|
|
||||||
this.isConnectedToWifi = isConnectedToWifi;
|
|
||||||
}
|
|
||||||
}
|
|
@ -71,12 +71,14 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
|||||||
import ml.docilealligator.infinityforreddit.CustomView.CustomToroContainer;
|
import ml.docilealligator.infinityforreddit.CustomView.CustomToroContainer;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeAutoplayNsfwVideosEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeAutoplayNsfwVideosEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeCompactLayoutToolbarHiddenByDefaultEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeCompactLayoutToolbarHiddenByDefaultEvent;
|
||||||
|
import ml.docilealligator.infinityforreddit.Event.ChangeDataSavingModeEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeEnableSwipeActionSwitchEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeEnableSwipeActionSwitchEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeLongPressToHideToolbarInCompactLayoutEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeLongPressToHideToolbarInCompactLayoutEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeMuteAutoplayingVideosEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeMuteAutoplayingVideosEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeMuteNSFWVideoEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeMuteNSFWVideoEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent;
|
||||||
|
import ml.docilealligator.infinityforreddit.Event.ChangeNetworkStatusEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeSavePostFeedScrolledPositionEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeSavePostFeedScrolledPositionEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeShowAbsoluteNumberOfVotesEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeShowAbsoluteNumberOfVotesEvent;
|
||||||
@ -88,7 +90,6 @@ import ml.docilealligator.infinityforreddit.Event.ChangeTimeFormatEvent;
|
|||||||
import ml.docilealligator.infinityforreddit.Event.ChangeVibrateWhenActionTriggeredEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeVibrateWhenActionTriggeredEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeVideoAutoplayEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeVideoAutoplayEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeWifiStatusEvent;
|
|
||||||
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList;
|
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ShowDividerInCompactLayoutPreferenceEvent;
|
import ml.docilealligator.infinityforreddit.Event.ShowDividerInCompactLayoutPreferenceEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ShowThumbnailOnTheRightInCompactLayoutEvent;
|
import ml.docilealligator.infinityforreddit.Event.ShowThumbnailOnTheRightInCompactLayoutEvent;
|
||||||
@ -1180,11 +1181,21 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onChangeWifiStatusEvent(ChangeWifiStatusEvent changeWifiStatusEvent) {
|
public void onChangeNetworkStatusEvent(ChangeNetworkStatusEvent changeNetworkStatusEvent) {
|
||||||
if (mAdapter != null) {
|
if (mAdapter != null) {
|
||||||
String autoplay = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
|
String autoplay = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
|
||||||
|
String dataSavingMode = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
|
||||||
|
boolean stateChanged = false;
|
||||||
if (autoplay.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
|
if (autoplay.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
|
||||||
mAdapter.setAutoplay(changeWifiStatusEvent.isConnectedToWifi);
|
mAdapter.setAutoplay(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_WIFI);
|
||||||
|
stateChanged = true;
|
||||||
|
}
|
||||||
|
if (dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
|
||||||
|
mAdapter.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
|
||||||
|
stateChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stateChanged) {
|
||||||
refreshAdapter();
|
refreshAdapter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1261,6 +1272,20 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
swipeActionThreshold = changeSwipeActionThresholdEvent.swipeActionThreshold;
|
swipeActionThreshold = changeSwipeActionThresholdEvent.swipeActionThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onChangeDataSavingModeEvent(ChangeDataSavingModeEvent changeDataSavingModeEvent) {
|
||||||
|
if (mAdapter != null) {
|
||||||
|
boolean dataSavingMode = false;
|
||||||
|
if (changeDataSavingModeEvent.dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
|
||||||
|
dataSavingMode = Utils.isConnectedToCellularData(activity);
|
||||||
|
} else if (changeDataSavingModeEvent.dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ALWAYS)) {
|
||||||
|
dataSavingMode = true;
|
||||||
|
}
|
||||||
|
mAdapter.setDataSavingMode(dataSavingMode);
|
||||||
|
refreshAdapter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void refreshAdapter() {
|
private void refreshAdapter() {
|
||||||
int previousPosition = -1;
|
int previousPosition = -1;
|
||||||
if (mLinearLayoutManager != null) {
|
if (mLinearLayoutManager != null) {
|
||||||
|
@ -15,7 +15,7 @@ import com.livefront.bridge.SavedStateHandler;
|
|||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
import ml.docilealligator.infinityforreddit.BroadcastReceiver.NetworkWifiStatusReceiver;
|
import ml.docilealligator.infinityforreddit.BroadcastReceiver.NetworkWifiStatusReceiver;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeWifiStatusEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeNetworkStatusEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Utils.Utils;
|
import ml.docilealligator.infinityforreddit.Utils.Utils;
|
||||||
import ml.docilealligator.inifinityforreddit.EventBusIndex;
|
import ml.docilealligator.inifinityforreddit.EventBusIndex;
|
||||||
|
|
||||||
@ -46,7 +46,9 @@ public class Infinity extends Application {
|
|||||||
EventBus.builder().addIndex(new EventBusIndex()).installDefaultEventBus();
|
EventBus.builder().addIndex(new EventBusIndex()).installDefaultEventBus();
|
||||||
|
|
||||||
mNetworkWifiStatusReceiver =
|
mNetworkWifiStatusReceiver =
|
||||||
new NetworkWifiStatusReceiver(() -> EventBus.getDefault().post(new ChangeWifiStatusEvent(Utils.isConnectedToWifi(getApplicationContext()))));
|
new NetworkWifiStatusReceiver(() -> {
|
||||||
|
EventBus.getDefault().post(new ChangeNetworkStatusEvent(Utils.getConnectedNetwork(getApplicationContext())));
|
||||||
|
});
|
||||||
registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit.Settings;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.preference.ListPreference;
|
||||||
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.Event.ChangeDataSavingModeEvent;
|
||||||
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
|
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
|
||||||
|
|
||||||
|
public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
|
setPreferencesFromResource(R.xml.data_saving_mode_preferences, rootKey);
|
||||||
|
|
||||||
|
ListPreference dataSavingModeListPreference = findPreference(SharedPreferencesUtils.DATA_SAVING_MODE);
|
||||||
|
|
||||||
|
if (dataSavingModeListPreference != null) {
|
||||||
|
dataSavingModeListPreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
|
EventBus.getDefault().post(new ChangeDataSavingModeEvent((String) newValue));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -130,6 +130,10 @@ public class SharedPreferencesUtils {
|
|||||||
public static final String MUTE_NSFW_VIDEO = "mute_nsfw_video";
|
public static final String MUTE_NSFW_VIDEO = "mute_nsfw_video";
|
||||||
public static final String VIDEO_PLAYER_IGNORE_NAV_BAR = "video_player_ignore_nav_bar";
|
public static final String VIDEO_PLAYER_IGNORE_NAV_BAR = "video_player_ignore_nav_bar";
|
||||||
public static final String SAVE_FRONT_PAGE_SCROLLED_POSITION = "save_front_page_scrolled_position";
|
public static final String SAVE_FRONT_PAGE_SCROLLED_POSITION = "save_front_page_scrolled_position";
|
||||||
|
public static final String DATA_SAVING_MODE = "data_saving_mode";
|
||||||
|
public static final String DATA_SAVING_MODE_OFF = "0";
|
||||||
|
public static final String DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA = "1";
|
||||||
|
public static final String DATA_SAVING_MODE_ALWAYS = "2";
|
||||||
|
|
||||||
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
|
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
|
||||||
public static final String MAIN_PAGE_TAB_COUNT = "_main_page_tab_count";
|
public static final String MAIN_PAGE_TAB_COUNT = "_main_page_tab_count";
|
||||||
|
@ -5,7 +5,9 @@ import android.content.Context;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.Network;
|
import android.net.Network;
|
||||||
|
import android.net.NetworkCapabilities;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
|
import android.os.Build;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
@ -24,6 +26,9 @@ import ml.docilealligator.infinityforreddit.R;
|
|||||||
import ml.docilealligator.infinityforreddit.SortType;
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
public static final int NETWORK_TYPE_OTHER = -1;
|
||||||
|
public static final int NETWORK_TYPE_WIFI = 0;
|
||||||
|
public static final int NETWORK_TYPE_CELLULAR = 1;
|
||||||
private static final long SECOND_MILLIS = 1000;
|
private static final long SECOND_MILLIS = 1000;
|
||||||
private static final long MINUTE_MILLIS = 60 * SECOND_MILLIS;
|
private static final long MINUTE_MILLIS = 60 * SECOND_MILLIS;
|
||||||
private static final long HOUR_MILLIS = 60 * MINUTE_MILLIS;
|
private static final long HOUR_MILLIS = 60 * MINUTE_MILLIS;
|
||||||
@ -140,13 +145,85 @@ public class Utils {
|
|||||||
textView.setText(html);
|
textView.setText(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getConnectedNetwork(Context context) {
|
||||||
|
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
if (connMgr != null) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
Network nw = connMgr.getActiveNetwork();
|
||||||
|
if (nw == null) return NETWORK_TYPE_OTHER;
|
||||||
|
NetworkCapabilities actNw = connMgr.getNetworkCapabilities(nw);
|
||||||
|
if (actNw != null) {
|
||||||
|
if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
|
||||||
|
return NETWORK_TYPE_WIFI;
|
||||||
|
}
|
||||||
|
if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
|
||||||
|
return NETWORK_TYPE_CELLULAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NETWORK_TYPE_OTHER;
|
||||||
|
} else {
|
||||||
|
boolean isWifi = false;
|
||||||
|
boolean isCellular = false;
|
||||||
|
for (Network network : connMgr.getAllNetworks()) {
|
||||||
|
NetworkInfo networkInfo = connMgr.getNetworkInfo(network);
|
||||||
|
if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
||||||
|
isWifi = true;
|
||||||
|
}
|
||||||
|
if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
|
||||||
|
isCellular = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isWifi) {
|
||||||
|
return NETWORK_TYPE_WIFI;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCellular) {
|
||||||
|
return NETWORK_TYPE_CELLULAR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NETWORK_TYPE_OTHER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NETWORK_TYPE_OTHER;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isConnectedToWifi(Context context) {
|
public static boolean isConnectedToWifi(Context context) {
|
||||||
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
if (connMgr != null) {
|
if (connMgr != null) {
|
||||||
for (Network network : connMgr.getAllNetworks()) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
NetworkInfo networkInfo = connMgr.getNetworkInfo(network);
|
Network nw = connMgr.getActiveNetwork();
|
||||||
if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
if (nw == null) return false;
|
||||||
return networkInfo.isConnected();
|
NetworkCapabilities actNw = connMgr.getNetworkCapabilities(nw);
|
||||||
|
return actNw != null && actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI);
|
||||||
|
} else {
|
||||||
|
for (Network network : connMgr.getAllNetworks()) {
|
||||||
|
NetworkInfo networkInfo = connMgr.getNetworkInfo(network);
|
||||||
|
if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
||||||
|
return networkInfo.isConnected();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isConnectedToCellularData(Context context) {
|
||||||
|
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
if (connMgr != null) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
Network nw = connMgr.getActiveNetwork();
|
||||||
|
if (nw == null) return false;
|
||||||
|
NetworkCapabilities actNw = connMgr.getNetworkCapabilities(nw);
|
||||||
|
return actNw != null && actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR);
|
||||||
|
} else {
|
||||||
|
for (Network network : connMgr.getAllNetworks()) {
|
||||||
|
NetworkInfo networkInfo = connMgr.getNetworkInfo(network);
|
||||||
|
if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
|
||||||
|
return networkInfo.isConnected();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:pathData="M11.8,10.9c-2.27,-0.59 -3,-1.2 -3,-2.15 0,-1.09 1.01,-1.85 2.7,-1.85 1.78,0 2.44,0.85 2.5,2.1h2.21c-0.07,-1.72 -1.12,-3.3 -3.21,-3.81V3h-3v2.16c-1.94,0.42 -3.5,1.68 -3.5,3.61 0,2.31 1.91,3.46 4.7,4.13 2.5,0.6 3,1.48 3,2.41 0,0.69 -0.49,1.79 -2.7,1.79 -2.06,0 -2.87,-0.92 -2.98,-2.1h-2.2c0.12,2.19 1.76,3.42 3.68,3.83V21h3v-2.15c1.95,-0.37 3.5,-1.5 3.5,-3.55 0,-2.84 -2.43,-3.81 -4.7,-4.4z"
|
||||||
|
android:fillColor="#000000"/>
|
||||||
|
</vector>
|
@ -270,4 +270,16 @@
|
|||||||
<item>0.8</item>
|
<item>0.8</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="settings_data_saving_mode">
|
||||||
|
<item>Off</item>
|
||||||
|
<item>Only on Cellular Data</item>
|
||||||
|
<item>Always on</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="settings_data_saving_mode_values">
|
||||||
|
<item>0</item>
|
||||||
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -486,6 +486,7 @@
|
|||||||
<string name="settings_bottom_app_bar_option_3">Option 3</string>
|
<string name="settings_bottom_app_bar_option_3">Option 3</string>
|
||||||
<string name="settings_bottom_app_bar_option_4">Option 4</string>
|
<string name="settings_bottom_app_bar_option_4">Option 4</string>
|
||||||
<string name="settings_bottom_app_bar_fab">Floating Action Button</string>
|
<string name="settings_bottom_app_bar_fab">Floating Action Button</string>
|
||||||
|
<string name="settings_data_saving_mode">Data Saving Mode</string>
|
||||||
|
|
||||||
<string name="no_link_available">Cannot get the link</string>
|
<string name="no_link_available">Cannot get the link</string>
|
||||||
|
|
||||||
|
13
app/src/main/res/xml/data_saving_mode_preferences.xml
Normal file
13
app/src/main/res/xml/data_saving_mode_preferences.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
app:defaultValue="0"
|
||||||
|
app:key="data_saving_mode"
|
||||||
|
android:title="@string/settings_data_saving_mode"
|
||||||
|
app:entries="@array/settings_data_saving_mode"
|
||||||
|
app:entryValues="@array/settings_data_saving_mode_values"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
@ -47,6 +47,12 @@
|
|||||||
android:icon="@drawable/ic_security_24dp"
|
android:icon="@drawable/ic_security_24dp"
|
||||||
app:fragment="ml.docilealligator.infinityforreddit.Settings.SecurityPreferenceFragment" />
|
app:fragment="ml.docilealligator.infinityforreddit.Settings.SecurityPreferenceFragment" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
app:key="security"
|
||||||
|
app:title="@string/settings_data_saving_mode"
|
||||||
|
app:icon="@drawable/ic_data_saving_mode_black_24dp"
|
||||||
|
app:fragment="ml.docilealligator.infinityforreddit.Settings.DataSavingModePreferenceFragment" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
app:defaultValue="false"
|
app:defaultValue="false"
|
||||||
app:key="save_front_page_scrolled_position"
|
app:key="save_front_page_scrolled_position"
|
||||||
|
Loading…
Reference in New Issue
Block a user