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; mAutoplay = autoplay;
} }
public boolean isAutoplay() {
return mAutoplay;
}
@Override @Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
super.onViewRecycled(holder); super.onViewRecycled(holder);

View File

@ -674,6 +674,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
return false; return false;
} }
if (mAdapter != null && mAdapter.isAutoplay()) {
mAdapter.setAutoplay(false);
refreshAdapter();
}
isInLazyMode = true; isInLazyMode = true;
isLazyModePaused = false; isLazyModePaused = false;
@ -688,6 +693,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override @Override
public void stopLazyMode() { 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; isInLazyMode = false;
isLazyModePaused = false; isLazyModePaused = false;
lazyModeRunnable.resetOldPosition(); lazyModeRunnable.resetOldPosition();
@ -700,6 +713,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override @Override
public void resumeLazyMode(boolean resumeNow) { public void resumeLazyMode(boolean resumeNow) {
if (isInLazyMode) { if (isInLazyMode) {
if (mAdapter != null && mAdapter.isAutoplay()) {
mAdapter.setAutoplay(false);
refreshAdapter();
}
isLazyModePaused = false; isLazyModePaused = false;
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);