1212import org .schabi .newpipe .error .ErrorInfo ;
1313import org .schabi .newpipe .error .ErrorUtil ;
1414import org .schabi .newpipe .error .UserAction ;
15+ import org .schabi .newpipe .extractor .ServiceList ;
16+ import org .schabi .newpipe .settings .tabs .Tab ;
17+ import org .schabi .newpipe .settings .tabs .TabsManager ;
1518import org .schabi .newpipe .util .DeviceUtils ;
1619
1720import java .util .Collections ;
1821import java .util .HashSet ;
22+ import java .util .List ;
1923import java .util .Set ;
24+ import java .util .stream .Collectors ;
2025
2126import static org .schabi .newpipe .MainActivity .DEBUG ;
27+ import static org .schabi .newpipe .extractor .ServiceList .SoundCloud ;
2228
2329/**
2430 * In order to add a migration, follow these steps, given P is the previous version:<br>
@@ -129,7 +135,7 @@ protected void migrate(@NonNull final Context context) {
129135 }
130136 };
131137
132- public static final Migration MIGRATION_5_6 = new Migration (5 , 6 ) {
138+ private static final Migration MIGRATION_5_6 = new Migration (5 , 6 ) {
133139 @ Override
134140 protected void migrate (@ NonNull final Context context ) {
135141 final boolean loadImages = sp .getBoolean ("download_thumbnail_key" , true );
@@ -143,6 +149,24 @@ protected void migrate(@NonNull final Context context) {
143149 }
144150 };
145151
152+ private static final Migration MIGRATION_6_7 = new Migration (6 , 7 ) {
153+ @ Override
154+ protected void migrate (@ NonNull final Context context ) {
155+ // The SoundCloud Top 50 Kiosk was removed in the extractor,
156+ // so we remove the corresponding tab if it exists.
157+ final TabsManager tabsManager = TabsManager .getManager (context );
158+ final List <Tab > tabs = tabsManager .getTabs ();
159+ final List <Tab > cleanedTabs = tabs .stream ()
160+ .filter (tab -> !(tab instanceof Tab .KioskTab kioskTab
161+ && kioskTab .getKioskServiceId () == SoundCloud .getServiceId ()
162+ && kioskTab .getKioskId ().equals ("Top 50" )))
163+ .collect (Collectors .toUnmodifiableList ());
164+ if (tabs .size () != cleanedTabs .size ()) {
165+ tabsManager .saveTabs (cleanedTabs );
166+ }
167+ }
168+ };
169+
146170 /**
147171 * List of all implemented migrations.
148172 * <p>
@@ -156,12 +180,13 @@ protected void migrate(@NonNull final Context context) {
156180 MIGRATION_3_4 ,
157181 MIGRATION_4_5 ,
158182 MIGRATION_5_6 ,
183+ MIGRATION_6_7
159184 };
160185
161186 /**
162187 * Version number for preferences. Must be incremented every time a migration is necessary.
163188 */
164- private static final int VERSION = 6 ;
189+ private static final int VERSION = 7 ;
165190
166191
167192 public static void runMigrationsIfNeeded (@ NonNull final Context context ) {
0 commit comments