55import android .util .Log ;
66
77import androidx .annotation .NonNull ;
8+ import androidx .appcompat .app .AlertDialog ;
9+ import androidx .core .util .Consumer ;
810import androidx .preference .PreferenceManager ;
911
1012import org .schabi .newpipe .App ;
1113import org .schabi .newpipe .R ;
1214import org .schabi .newpipe .error .ErrorInfo ;
1315import org .schabi .newpipe .error .ErrorUtil ;
1416import org .schabi .newpipe .error .UserAction ;
15- import org .schabi .newpipe .extractor .ServiceList ;
1617import org .schabi .newpipe .settings .tabs .Tab ;
1718import org .schabi .newpipe .settings .tabs .TabsManager ;
1819import org .schabi .newpipe .util .DeviceUtils ;
1920
21+ import java .util .ArrayList ;
2022import java .util .Collections ;
2123import java .util .HashSet ;
2224import java .util .List ;
@@ -38,6 +40,12 @@ public final class SettingMigrations {
3840 private static final String TAG = SettingMigrations .class .toString ();
3941 private static SharedPreferences sp ;
4042
43+ /**
44+ * List of UI actions that are be performed after the UI is initialized
45+ * to inform the user about changes that were applied by migrations.
46+ */
47+ private static final List <Consumer <Context >> MIGRATION_INFO = new ArrayList <>();
48+
4149 private static final Migration MIGRATION_0_1 = new Migration (0 , 1 ) {
4250 @ Override
4351 public void migrate (@ NonNull final Context context ) {
@@ -163,6 +171,15 @@ protected void migrate(@NonNull final Context context) {
163171 .collect (Collectors .toUnmodifiableList ());
164172 if (tabs .size () != cleanedTabs .size ()) {
165173 tabsManager .saveTabs (cleanedTabs );
174+ // create an AlertDialog to inform the user about the change
175+ // do not translate text, it is only shown once
176+ MIGRATION_INFO .add ((Context uiContext ) -> new AlertDialog .Builder (uiContext )
177+ .setTitle ("SoundCloud Top 50 page removed" )
178+ .setMessage ("SoundCloud has discontinued the original Top 50 charts. "
179+ + "The corresponding tab has been removed from your main page." )
180+ .setPositiveButton (android .R .string .ok , null )
181+ .create ()
182+ .show ());
166183 }
167184 }
168185 };
@@ -233,6 +250,21 @@ public static void runMigrationsIfNeeded(@NonNull final Context context) {
233250 sp .edit ().putInt (lastPrefVersionKey , currentVersion ).apply ();
234251 }
235252
253+ /**
254+ * Perform UI actions informing about migrations that took place if they are present.
255+ * @param context Context that can be used to show dialogs/snackbars/toasts
256+ */
257+ public static void showUserInfoIfPresent (@ NonNull final Context context ) {
258+ for (final Consumer <Context > consumer : MIGRATION_INFO ) {
259+ try {
260+ consumer .accept (context );
261+ } catch (final Exception e ) {
262+ ErrorUtil .showUiErrorSnackbar (context , "Showing migration info to the user" , e );
263+ }
264+ }
265+ MIGRATION_INFO .clear ();
266+ }
267+
236268 private SettingMigrations () { }
237269
238270 abstract static class Migration {
0 commit comments