From aecafc5380b4a0135ec39824beae64183bf231cf Mon Sep 17 00:00:00 2001 From: Joey Peter Date: Thu, 30 Jun 2022 12:38:28 +0200 Subject: [PATCH] refactor: dialogs and seperate RYD from SB (#31) --- .../integrations/ryd/dialog/Dialogs.java | 55 ------------- .../sponsorblock/dialog/Dialogs.java | 80 +++++++++++++++++++ 2 files changed, 80 insertions(+), 55 deletions(-) create mode 100644 app/src/main/java/app/revanced/integrations/sponsorblock/dialog/Dialogs.java diff --git a/app/src/main/java/app/revanced/integrations/ryd/dialog/Dialogs.java b/app/src/main/java/app/revanced/integrations/ryd/dialog/Dialogs.java index 0997c1db..eb2ba894 100644 --- a/app/src/main/java/app/revanced/integrations/ryd/dialog/Dialogs.java +++ b/app/src/main/java/app/revanced/integrations/ryd/dialog/Dialogs.java @@ -22,7 +22,6 @@ public class Dialogs { // Inject call from YT to this public static void showDialogsAtStartup(Activity activity) { rydFirstRun(activity); - sbFirstRun(activity); } private static void rydFirstRun(Activity activity) { @@ -78,58 +77,4 @@ public class Dialogs { activity.startActivity(intent); }); } - - private static void sbFirstRun(Activity activity) { - Context context = ReVancedUtils.getContext(); - boolean enabled = SharedPrefHelper.getBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_ENABLED, false); - boolean hintShown = SharedPrefHelper.getBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_HINT_SHOWN, false); - - // If SB is enabled or hint has been shown, exit - if (enabled || hintShown) { - // If SB is enabled but hint hasn't been shown, mark it as shown - if (enabled && !hintShown) { - SharedPrefHelper.saveBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_HINT_SHOWN, true); - } - return; - } - - AlertDialog.Builder builder; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - builder = new AlertDialog.Builder(activity, android.R.style.Theme_Material_Dialog_Alert); - } else { - builder = new AlertDialog.Builder(activity); - } - builder.setTitle(str("vanced_sb")); - builder.setIcon(ReVancedUtils.getIdentifier("ic_sb_logo", "drawable")); - builder.setCancelable(false); - builder.setMessage(str("vanced_sb_firstrun")); - builder.setPositiveButton(str("vanced_enable"), - (dialog, id) -> { - SharedPrefHelper.saveBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_HINT_SHOWN, true); - SharedPrefHelper.saveBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_ENABLED, true); - dialog.dismiss(); - }); - - builder.setNegativeButton(str("vanced_disable"), - (dialog, id) -> { - SharedPrefHelper.saveBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_HINT_SHOWN, true); - SharedPrefHelper.saveBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_ENABLED, false); - dialog.dismiss(); - }); - - builder.setNeutralButton(str("vanced_learnmore"), null); - - AlertDialog dialog = builder.create(); - dialog.show(); - - // Set black background - dialog.getWindow().getDecorView().getBackground().setColorFilter(new LightingColorFilter(0xFF000000, ReVancedUtils.getIdentifier("ytBrandBackgroundSolid", "color"))); - - // Set learn more action (set here so clicking it doesn't dismiss the dialog) - dialog.getButton(DialogInterface.BUTTON_NEUTRAL).setOnClickListener(v -> { - Uri uri = Uri.parse("https://sponsor.ajay.app/"); - Intent intent = new Intent(Intent.ACTION_VIEW, uri); - activity.startActivity(intent); - }); - } } diff --git a/app/src/main/java/app/revanced/integrations/sponsorblock/dialog/Dialogs.java b/app/src/main/java/app/revanced/integrations/sponsorblock/dialog/Dialogs.java new file mode 100644 index 00000000..7bb0b131 --- /dev/null +++ b/app/src/main/java/app/revanced/integrations/sponsorblock/dialog/Dialogs.java @@ -0,0 +1,80 @@ +package app.revanced.integrations.sponsorblock.dialog; + +import static app.revanced.integrations.ryd.RYDSettings.PREFERENCES_KEY_RYD_ENABLED; +import static app.revanced.integrations.ryd.RYDSettings.PREFERENCES_KEY_RYD_HINT_SHOWN; +import static app.revanced.integrations.sponsorblock.SponsorBlockSettings.PREFERENCES_KEY_SPONSOR_BLOCK_ENABLED; +import static app.revanced.integrations.sponsorblock.SponsorBlockSettings.PREFERENCES_KEY_SPONSOR_BLOCK_HINT_SHOWN; +import static app.revanced.integrations.sponsorblock.StringRef.str; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.graphics.LightingColorFilter; +import android.net.Uri; +import android.os.Build; + +import app.revanced.integrations.utils.ReVancedUtils; +import app.revanced.integrations.utils.SharedPrefHelper; + +public class Dialogs { + // Inject call from YT to this + public static void showDialogsAtStartup(Activity activity) { + sbFirstRun(activity); + } + + private static void sbFirstRun(Activity activity) { + Context context = ReVancedUtils.getContext(); + boolean enabled = SharedPrefHelper.getBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_ENABLED, false); + boolean hintShown = SharedPrefHelper.getBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_HINT_SHOWN, false); + + // If SB is enabled or hint has been shown, exit + if (enabled || hintShown) { + // If SB is enabled but hint hasn't been shown, mark it as shown + if (enabled && !hintShown) { + SharedPrefHelper.saveBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_HINT_SHOWN, true); + } + return; + } + + AlertDialog.Builder builder; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + builder = new AlertDialog.Builder(activity, android.R.style.Theme_Material_Dialog_Alert); + } else { + builder = new AlertDialog.Builder(activity); + } + builder.setTitle(str("vanced_sb")); + builder.setIcon(ReVancedUtils.getIdentifier("ic_sb_logo", "drawable")); + builder.setCancelable(false); + builder.setMessage(str("vanced_sb_firstrun")); + builder.setPositiveButton(str("vanced_enable"), + (dialog, id) -> { + SharedPrefHelper.saveBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_HINT_SHOWN, true); + SharedPrefHelper.saveBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_ENABLED, true); + dialog.dismiss(); + }); + + builder.setNegativeButton(str("vanced_disable"), + (dialog, id) -> { + SharedPrefHelper.saveBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_HINT_SHOWN, true); + SharedPrefHelper.saveBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_ENABLED, false); + dialog.dismiss(); + }); + + builder.setNeutralButton(str("vanced_learnmore"), null); + + AlertDialog dialog = builder.create(); + dialog.show(); + + // Set black background + dialog.getWindow().getDecorView().getBackground().setColorFilter(new LightingColorFilter(0xFF000000, ReVancedUtils.getIdentifier("ytBrandBackgroundSolid", "color"))); + + // Set learn more action (set here so clicking it doesn't dismiss the dialog) + dialog.getButton(DialogInterface.BUTTON_NEUTRAL).setOnClickListener(v -> { + Uri uri = Uri.parse("https://sponsor.ajay.app/"); + Intent intent = new Intent(Intent.ACTION_VIEW, uri); + activity.startActivity(intent); + }); + } +}