Skip to content

Commit

Permalink
the skip/whitelist toggles now persist when toggling fullscreen (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
polymorphicshade committed Jan 27, 2024
1 parent 797661a commit 618c744
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public final class VideoDetailFragment

private final SharedPreferences.OnSharedPreferenceChangeListener preferenceChangeListener =
this::onSharedPreferencesChanged;
private Disposable workerIsWhitelisted;
private Disposable workerSponsorBlockModeCheck;

private void onSharedPreferencesChanged(final SharedPreferences sharedPreferences,
final String key) {
Expand Down Expand Up @@ -224,6 +224,8 @@ private void onSharedPreferencesChanged(final SharedPreferences sharedPreference
int lastStableBottomSheetState = BottomSheetBehavior.STATE_EXPANDED;
@State
protected boolean autoPlayEnabled = true;
@State
SponsorBlockMode currentSponsorBlockMode = null;

@Nullable
private StreamInfo currentInfo = null;
Expand Down Expand Up @@ -458,8 +460,8 @@ public void onDetach() {
if (submitSegmentSubscriber != null) {
submitSegmentSubscriber.dispose();
}
if (workerIsWhitelisted != null) {
workerIsWhitelisted.dispose();
if (workerSponsorBlockModeCheck != null) {
workerSponsorBlockModeCheck.dispose();
}
}

Expand Down Expand Up @@ -998,6 +1000,21 @@ private void updateTabs(@NonNull final StreamInfo info) {
sponsorBlockFragment.setListener(this);

pageAdapter.updateItem(SPONSOR_BLOCK_TAB_TAG, sponsorBlockFragment);

workerSponsorBlockModeCheck =
sponsorBlockDataManager
.isWhiteListed(info.getUploaderName())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(isWhitelisted -> {
if (currentSponsorBlockMode == null) {
currentSponsorBlockMode = isWhitelisted
? SponsorBlockMode.DISABLED
: SponsorBlockMode.ENABLED;
}
sponsorBlockFragment.setSponsorBlockMode(currentSponsorBlockMode);
sponsorBlockFragment.setIsWhitelisted(isWhitelisted);
});
}

binding.viewPager.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -1890,17 +1907,24 @@ public void onMetadataUpdate(final StreamInfo info, final PlayQueue queue) {
prefs.getBoolean(getString(R.string.sponsor_block_enable_key), false);

if (player != null && isSponsorBlockEnabled) {
workerIsWhitelisted = sponsorBlockDataManager.isWhiteListed(info.getUploaderName())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(isWhitelisted -> {
final SponsorBlockMode mode = isWhitelisted
? SponsorBlockMode.DISABLED
: SponsorBlockMode.ENABLED;
player.setSponsorBlockMode(mode);
getSponsorBlockFragment().ifPresent(
fragment -> fragment.setSponsorBlockMode(mode));
});
workerSponsorBlockModeCheck =
sponsorBlockDataManager
.isWhiteListed(info.getUploaderName())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(isWhitelisted -> {
if (currentSponsorBlockMode == null) {
currentSponsorBlockMode = isWhitelisted
? SponsorBlockMode.DISABLED
: SponsorBlockMode.ENABLED;
}
player.setSponsorBlockMode(currentSponsorBlockMode);
getSponsorBlockFragment().ifPresent(
fragment -> {
fragment.setSponsorBlockMode(currentSponsorBlockMode);
fragment.setIsWhitelisted(isWhitelisted);
});
});
}
final StackItem item = findQueueInStack(queue);
if (item != null) {
Expand Down Expand Up @@ -2583,9 +2607,11 @@ public void onSkippingEnabledChanged(final boolean newValue) {
return;
}

player.setSponsorBlockMode(newValue
currentSponsorBlockMode = newValue
? SponsorBlockMode.ENABLED
: SponsorBlockMode.DISABLED);
: SponsorBlockMode.DISABLED;

player.setSponsorBlockMode(currentSponsorBlockMode);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,8 @@ public class SponsorBlockFragment
private int currentProgress = -1;
private @Nullable SponsorBlockFragmentListener sponsorBlockFragmentListener;
private SponsorBlockDataManager sponsorBlockDataManager;
private Disposable workerIsWhitelisted;
private Disposable workerAddToWhitelisted;
private Disposable workerRemoveFromWhitelisted;
private SponsorBlockMode sponsorBlockMode = SponsorBlockMode.ENABLED;


public SponsorBlockFragment() {
}
Expand Down Expand Up @@ -80,9 +77,6 @@ public void onAttach(@NonNull final Context context) {
public void onDetach() {
super.onDetach();

if (workerIsWhitelisted != null) {
workerIsWhitelisted.dispose();
}
if (workerAddToWhitelisted != null) {
workerAddToWhitelisted.dispose();
}
Expand Down Expand Up @@ -116,18 +110,8 @@ public View onCreateView(@NonNull final LayoutInflater inflater,

binding.segmentList.setAdapter(segmentListAdapter);

workerIsWhitelisted = sponsorBlockDataManager.isWhiteListed(streamInfo.getUploaderName())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(isWhitelisted -> {
binding.channelIsWhitelistedSwitch.setChecked(isWhitelisted);

binding.skippingIsEnabledSwitch.setChecked(
!isWhitelisted && sponsorBlockMode == SponsorBlockMode.ENABLED);

binding.skippingIsEnabledSwitch.setOnCheckedChangeListener(this);
binding.channelIsWhitelistedSwitch.setOnCheckedChangeListener(this);
});
binding.skippingIsEnabledSwitch.setOnCheckedChangeListener(this);
binding.channelIsWhitelistedSwitch.setOnCheckedChangeListener(this);

return binding.getRoot();
}
Expand Down Expand Up @@ -181,7 +165,15 @@ public void setListener(final SponsorBlockFragmentListener listener) {
}

public void setSponsorBlockMode(@NonNull final SponsorBlockMode mode) {
sponsorBlockMode = mode;
binding.skippingIsEnabledSwitch.setOnCheckedChangeListener(null);
binding.skippingIsEnabledSwitch.setChecked(mode == SponsorBlockMode.ENABLED);
binding.skippingIsEnabledSwitch.setOnCheckedChangeListener(this);
}

public void setIsWhitelisted(final boolean value) {
binding.channelIsWhitelistedSwitch.setOnCheckedChangeListener(null);
binding.channelIsWhitelistedSwitch.setChecked(value);
binding.channelIsWhitelistedSwitch.setOnCheckedChangeListener(this);
}

public void setCurrentProgress(final int progress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

public enum SponsorBlockMode {
DISABLED,
ENABLED,
IGNORE
ENABLED
}

0 comments on commit 618c744

Please sign in to comment.