Stop autoplay when wifi is lost in ViewPostDetailActivity if video autoplay is set to wifi only.

This commit is contained in:
Alex Ning 2020-05-07 14:10:41 +08:00
parent e439b84095
commit c705292bf8
2 changed files with 16 additions and 0 deletions

View File

@ -64,6 +64,7 @@ import ml.docilealligator.infinityforreddit.CustomView.CustomToroContainer;
import ml.docilealligator.infinityforreddit.DeleteThing;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeWifiStatusEvent;
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToDetailActivity;
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
@ -1238,6 +1239,17 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
}
}
@Subscribe
public void onChangeWifiStatusEvent(ChangeWifiStatusEvent changeWifiStatusEvent) {
if (mAdapter != null) {
String autoplay = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
if (autoplay.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
mAdapter.setAutoplay(changeWifiStatusEvent.isConnectedToWifi);
refreshAdapter();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.view_post_detail_activity, menu);

View File

@ -1451,6 +1451,10 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
return -1;
}
public void setAutoplay(boolean autoplay) {
mAutoplay = autoplay;
}
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
if (holder instanceof CommentViewHolder) {