Skip to content

Commit 941f857

Browse files
committed
Display dialog informing the user about the removal of the Top 50 kiosk
1 parent 7e0ee4e commit 941f857

3 files changed

Lines changed: 36 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: 32 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 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,14 @@ 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+
MIGRATION_INFO.add((Context uiContext) -> new AlertDialog.Builder(uiContext)
176+
.setTitle(R.string.migration_info_6_7_title)
177+
.setMessage(R.string.migration_info_6_7_message)
178+
.setPositiveButton(R.string.ok, null)
179+
.setCancelable(false)
180+
.create()
181+
.show());
166182
}
167183
}
168184
};
@@ -233,6 +249,21 @@ public static void runMigrationsIfNeeded(@NonNull final Context context) {
233249
sp.edit().putInt(lastPrefVersionKey, currentVersion).apply();
234250
}
235251

252+
/**
253+
* Perform UI actions informing about migrations that took place if they are present.
254+
* @param context Context that can be used to show dialogs/snackbars/toasts
255+
*/
256+
public static void showUserInfoIfPresent(@NonNull final Context context) {
257+
for (final Consumer<Context> consumer : MIGRATION_INFO) {
258+
try {
259+
consumer.accept(context);
260+
} catch (final Exception e) {
261+
ErrorUtil.showUiErrorSnackbar(context, "Showing migration info to the user", e);
262+
}
263+
}
264+
MIGRATION_INFO.clear();
265+
}
266+
236267
private SettingMigrations() { }
237268

238269
abstract static class Migration {

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,4 +865,6 @@
865865
<string name="show_more">Show more</string>
866866
<string name="show_less">Show less</string>
867867
<string name="import_settings_vulnerable_format">The settings in the export being imported use a vulnerable format that was deprecated since NewPipe 0.27.0. Make sure the export being imported is from a trusted source, and prefer using only exports obtained from NewPipe 0.27.0 or newer in the future. Support for importing settings in this vulnerable format will soon be removed completely, and then old versions of NewPipe will not be able to import settings of exports from new versions anymore.</string>
868+
<string name="migration_info_6_7_title">SoundCloud Top 50 page removed</string>
869+
<string name="migration_info_6_7_message">SoundCloud has discontinued the original Top 50 charts. The corresponding tab has been removed from your main page.</string>
868870
</resources>

0 commit comments

Comments
 (0)