Skip to content

Commit 3c50f42

Browse files
committed
Display dialog informing the user about the removal of the Top 50 kiosk
1 parent 417f7cb commit 3c50f42

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

app/src/main/java/org/schabi/newpipe/MainActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
import org.schabi.newpipe.player.event.OnKeyDownListener;
8181
import org.schabi.newpipe.player.helper.PlayerHolder;
8282
import org.schabi.newpipe.player.playqueue.PlayQueue;
83+
import org.schabi.newpipe.settings.SettingMigrations;
8384
import org.schabi.newpipe.settings.UpdateSettingsFragment;
8485
import org.schabi.newpipe.util.Constants;
8586
import org.schabi.newpipe.util.DeviceUtils;
@@ -197,6 +198,7 @@ protected void onCreate(final Bundle savedInstanceState) {
197198
}
198199

199200
Localization.migrateAppLanguageSettingIfNecessary(getApplicationContext());
201+
SettingMigrations.showUserInfoIfPresent(this);
200202
}
201203

202204
@Override

app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
import android.util.Log;
66

77
import androidx.annotation.NonNull;
8+
import androidx.appcompat.app.AlertDialog;
9+
import androidx.core.util.Consumer;
810
import androidx.preference.PreferenceManager;
911

1012
import org.schabi.newpipe.App;
1113
import org.schabi.newpipe.R;
1214
import org.schabi.newpipe.error.ErrorInfo;
1315
import org.schabi.newpipe.error.ErrorUtil;
1416
import org.schabi.newpipe.error.UserAction;
15-
import org.schabi.newpipe.extractor.ServiceList;
1617
import org.schabi.newpipe.settings.tabs.Tab;
1718
import org.schabi.newpipe.settings.tabs.TabsManager;
1819
import org.schabi.newpipe.util.DeviceUtils;
1920

21+
import java.util.ArrayList;
2022
import java.util.Collections;
2123
import java.util.HashSet;
2224
import 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

Comments
 (0)