Disable video autoply in lazy mode.

This commit is contained in:
Alex Ning 2020-05-12 20:22:29 +08:00
parent 9490c37a09
commit 8533a2bcca
2 changed files with 21 additions and 0 deletions

View File

@ -1305,6 +1305,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mAutoplay = autoplay;
}
public boolean isAutoplay() {
return mAutoplay;
}
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
super.onViewRecycled(holder);

View File

@ -674,6 +674,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
return false;
}
if (mAdapter != null && mAdapter.isAutoplay()) {
mAdapter.setAutoplay(false);
refreshAdapter();
}
isInLazyMode = true;
isLazyModePaused = false;
@ -688,6 +693,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override
public void stopLazyMode() {
if (mAdapter != null) {
String autoplayString = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ALWAYS_ON) ||
(autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI) && Utils.isConnectedToWifi(activity))) {
mAdapter.setAutoplay(true);
refreshAdapter();
}
}
isInLazyMode = false;
isLazyModePaused = false;
lazyModeRunnable.resetOldPosition();
@ -700,6 +713,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override
public void resumeLazyMode(boolean resumeNow) {
if (isInLazyMode) {
if (mAdapter != null && mAdapter.isAutoplay()) {
mAdapter.setAutoplay(false);
refreshAdapter();
}
isLazyModePaused = false;
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);