fix: disable sync starred tracks/albums switches in when Cancel is clicked in warning dialog

This commit is contained in:
Jaime García 2025-08-31 17:39:35 +02:00
parent cc61d1cd48
commit e24063e460
No known key found for this signature in database
GPG key ID: BC4E5F71A71BDA5B
3 changed files with 22 additions and 3 deletions

View file

@ -26,6 +26,12 @@ import java.util.stream.Collectors;
public class StarredAlbumSyncDialog extends DialogFragment {
private StarredAlbumsSyncViewModel starredAlbumsSyncViewModel;
private Runnable onCancel;
public StarredAlbumSyncDialog(Runnable onCancel) {
this.onCancel = onCancel;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
@ -74,6 +80,7 @@ public class StarredAlbumSyncDialog extends DialogFragment {
Button negativeButton = dialog.getButton(Dialog.BUTTON_NEGATIVE);
negativeButton.setOnClickListener(v -> {
Preferences.setStarredAlbumsSyncEnabled(false);
if (onCancel != null) onCancel.run();
dialog.dismiss();
});
}

View file

@ -26,6 +26,12 @@ import java.util.stream.Collectors;
public class StarredSyncDialog extends DialogFragment {
private StarredSyncViewModel starredSyncViewModel;
private Runnable onCancel;
public StarredSyncDialog(Runnable onCancel) {
this.onCancel = onCancel;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
@ -75,6 +81,7 @@ public class StarredSyncDialog extends DialogFragment {
Button negativeButton = dialog.getButton(Dialog.BUTTON_NEGATIVE);
negativeButton.setOnClickListener(v -> {
Preferences.setStarredSyncEnabled(false);
if (onCancel != null) onCancel.run();
dialog.dismiss();
});
}

View file

@ -21,6 +21,7 @@ import androidx.media3.common.util.UnstableApi;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
import com.cappielloantonio.tempo.BuildConfig;
import com.cappielloantonio.tempo.R;
@ -257,9 +258,11 @@ public class SettingsFragment extends PreferenceFragmentCompat {
findPreference("sync_starred_tracks_for_offline_use").setOnPreferenceChangeListener((preference, newValue) -> {
if (newValue instanceof Boolean) {
if ((Boolean) newValue) {
StarredSyncDialog dialog = new StarredSyncDialog();
StarredSyncDialog dialog = new StarredSyncDialog(() -> {
((SwitchPreference)preference).setChecked(false);
});
dialog.show(activity.getSupportFragmentManager(), null);
}
}
}
return true;
});
@ -269,7 +272,9 @@ public class SettingsFragment extends PreferenceFragmentCompat {
findPreference("sync_starred_albums_for_offline_use").setOnPreferenceChangeListener((preference, newValue) -> {
if (newValue instanceof Boolean) {
if ((Boolean) newValue) {
StarredAlbumSyncDialog dialog = new StarredAlbumSyncDialog();
StarredAlbumSyncDialog dialog = new StarredAlbumSyncDialog(() -> {
((SwitchPreference)preference).setChecked(false);
});
dialog.show(activity.getSupportFragmentManager(), null);
}
}