Skip to content

Commit 124ab56

Browse files
committed
Merge branch 'master' into dev
2 parents 56f79fa + 95a0e0c commit 124ab56

File tree

11 files changed

+238
-75
lines changed

11 files changed

+238
-75
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ dependencies {
214214
// the corresponding commit hash, since JitPack sometimes deletes artifacts.
215215
// If there’s already a git hash, just add more of it to the end (or remove a letter)
216216
// to cause jitpack to regenerate the artifact.
217-
implementation 'com.github.TeamNewPipe:NewPipeExtractor:7adbc48a0aa872c016b8ec089e278d5e12772054'
217+
implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.24.8'
218218
implementation 'com.github.TeamNewPipe:NoNonsense-FilePicker:5.0.0'
219219

220220
/** Checkstyle **/

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

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@
7979
import org.schabi.newpipe.player.event.OnKeyDownListener;
8080
import org.schabi.newpipe.player.helper.PlayerHolder;
8181
import org.schabi.newpipe.player.playqueue.PlayQueue;
82-
import org.schabi.newpipe.settings.SettingMigrations;
8382
import org.schabi.newpipe.settings.UpdateSettingsFragment;
83+
import org.schabi.newpipe.settings.migration.MigrationManager;
8484
import org.schabi.newpipe.util.Constants;
8585
import org.schabi.newpipe.util.DeviceUtils;
8686
import org.schabi.newpipe.util.KioskTranslator;
@@ -196,7 +196,7 @@ protected void onCreate(final Bundle savedInstanceState) {
196196
UpdateSettingsFragment.askForConsentToUpdateChecks(this);
197197
}
198198

199-
SettingMigrations.showUserInfoIfPresent(this);
199+
MigrationManager.showUserInfoIfPresent(this);
200200
}
201201

202202
@Override
@@ -264,19 +264,6 @@ public void onDrawerClosed(final View drawerView) {
264264
*/
265265
private void addDrawerMenuForCurrentService() throws ExtractionException {
266266
//Tabs
267-
final int currentServiceId = ServiceHelper.getSelectedServiceId(this);
268-
final StreamingService service = NewPipe.getService(currentServiceId);
269-
270-
int kioskMenuItemId = 0;
271-
272-
for (final String ks : service.getKioskList().getAvailableKiosks()) {
273-
drawerLayoutBinding.navigation.getMenu()
274-
.add(R.id.menu_tabs_group, kioskMenuItemId, 0, KioskTranslator
275-
.getTranslatedKioskName(ks, this))
276-
.setIcon(KioskTranslator.getKioskIcon(ks));
277-
kioskMenuItemId++;
278-
}
279-
280267
drawerLayoutBinding.navigation.getMenu()
281268
.add(R.id.menu_tabs_group, ITEM_ID_SUBSCRIPTIONS, ORDER,
282269
R.string.tab_subscriptions)
@@ -294,6 +281,20 @@ private void addDrawerMenuForCurrentService() throws ExtractionException {
294281
.add(R.id.menu_tabs_group, ITEM_ID_HISTORY, ORDER, R.string.action_history)
295282
.setIcon(R.drawable.ic_history);
296283

284+
//Kiosks
285+
final int currentServiceId = ServiceHelper.getSelectedServiceId(this);
286+
final StreamingService service = NewPipe.getService(currentServiceId);
287+
288+
int kioskMenuItemId = 0;
289+
290+
for (final String ks : service.getKioskList().getAvailableKiosks()) {
291+
drawerLayoutBinding.navigation.getMenu()
292+
.add(R.id.menu_kiosks_group, kioskMenuItemId, 0, KioskTranslator
293+
.getTranslatedKioskName(ks, this))
294+
.setIcon(KioskTranslator.getKioskIcon(ks));
295+
kioskMenuItemId++;
296+
}
297+
297298
//Settings and About
298299
drawerLayoutBinding.navigation.getMenu()
299300
.add(R.id.menu_options_about_group, ITEM_ID_SETTINGS, ORDER, R.string.settings)
@@ -313,10 +314,13 @@ private boolean drawerItemSelected(final MenuItem item) {
313314
changeService(item);
314315
break;
315316
case R.id.menu_tabs_group:
317+
tabSelected(item);
318+
break;
319+
case R.id.menu_kiosks_group:
316320
try {
317-
tabSelected(item);
321+
kioskSelected(item);
318322
} catch (final Exception e) {
319-
ErrorUtil.showUiErrorSnackbar(this, "Selecting main page tab", e);
323+
ErrorUtil.showUiErrorSnackbar(this, "Selecting drawer kiosk", e);
320324
}
321325
break;
322326
case R.id.menu_options_about_group:
@@ -340,7 +344,7 @@ private void changeService(final MenuItem item) {
340344
.setChecked(true);
341345
}
342346

343-
private void tabSelected(final MenuItem item) throws ExtractionException {
347+
private void tabSelected(final MenuItem item) {
344348
switch (item.getItemId()) {
345349
case ITEM_ID_SUBSCRIPTIONS:
346350
NavigationHelper.openSubscriptionFragment(getSupportFragmentManager());
@@ -357,18 +361,19 @@ private void tabSelected(final MenuItem item) throws ExtractionException {
357361
case ITEM_ID_HISTORY:
358362
NavigationHelper.openStatisticFragment(getSupportFragmentManager());
359363
break;
360-
default:
361-
final StreamingService currentService = ServiceHelper.getSelectedService(this);
362-
int kioskMenuItemId = 0;
363-
for (final String kioskId : currentService.getKioskList().getAvailableKiosks()) {
364-
if (kioskMenuItemId == item.getItemId()) {
365-
NavigationHelper.openKioskFragment(getSupportFragmentManager(),
366-
currentService.getServiceId(), kioskId);
367-
break;
368-
}
369-
kioskMenuItemId++;
370-
}
364+
}
365+
}
366+
367+
private void kioskSelected(final MenuItem item) throws ExtractionException {
368+
final StreamingService currentService = ServiceHelper.getSelectedService(this);
369+
int kioskMenuItemId = 0;
370+
for (final String kioskId : currentService.getKioskList().getAvailableKiosks()) {
371+
if (kioskMenuItemId == item.getItemId()) {
372+
NavigationHelper.openKioskFragment(getSupportFragmentManager(),
373+
currentService.getServiceId(), kioskId);
371374
break;
375+
}
376+
kioskMenuItemId++;
372377
}
373378
}
374379

@@ -409,6 +414,7 @@ private void toggleServices() {
409414

410415
drawerLayoutBinding.navigation.getMenu().removeGroup(R.id.menu_services_group);
411416
drawerLayoutBinding.navigation.getMenu().removeGroup(R.id.menu_tabs_group);
417+
drawerLayoutBinding.navigation.getMenu().removeGroup(R.id.menu_kiosks_group);
412418
drawerLayoutBinding.navigation.getMenu().removeGroup(R.id.menu_options_about_group);
413419

414420
// Show up or down arrow

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import org.schabi.newpipe.App;
1515
import org.schabi.newpipe.R;
16+
import org.schabi.newpipe.settings.migration.MigrationManager;
1617
import org.schabi.newpipe.util.DeviceUtils;
1718

1819
import java.io.File;
@@ -46,7 +47,7 @@ private NewPipeSettings() { }
4647

4748
public static void initSettings(final Context context) {
4849
// first run migrations, then setDefaultValues, since the latter requires the correct types
49-
SettingMigrations.runMigrationsIfNeeded(context);
50+
MigrationManager.runMigrationsIfNeeded(context);
5051

5152
// readAgain is true so that if new settings are added their default value is set
5253
PreferenceManager.setDefaultValues(context, R.xml.main_settings, true);
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package org.schabi.newpipe.settings.migration;
2+
3+
import android.content.Context;
4+
5+
import androidx.annotation.NonNull;
6+
import androidx.appcompat.app.AlertDialog;
7+
import androidx.core.util.Consumer;
8+
9+
import org.schabi.newpipe.R;
10+
import org.schabi.newpipe.error.ErrorUtil;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
15+
/**
16+
* MigrationManager is responsible for running migrations and showing the user information about
17+
* the migrations that were applied.
18+
*/
19+
public final class MigrationManager {
20+
21+
private static final String TAG = MigrationManager.class.getSimpleName();
22+
/**
23+
* List of UI actions that are performed after the UI is initialized (e.g. showing alert
24+
* dialogs) to inform the user about changes that were applied by migrations.
25+
*/
26+
private static final List<Consumer<Context>> MIGRATION_INFO = new ArrayList<>();
27+
28+
private MigrationManager() {
29+
// MigrationManager is a utility class that is completely static
30+
}
31+
32+
/**
33+
* Run all migrations that are needed for the current version of NewPipe.
34+
* This method should be called at the start of the application, before any other operations
35+
* that depend on the settings.
36+
*
37+
* @param context Context that can be used to run migrations
38+
*/
39+
public static void runMigrationsIfNeeded(@NonNull final Context context) {
40+
SettingMigrations.runMigrationsIfNeeded(context);
41+
}
42+
43+
/**
44+
* Perform UI actions informing about migrations that took place if they are present.
45+
* @param context Context that can be used to show dialogs/snackbars/toasts
46+
*/
47+
public static void showUserInfoIfPresent(@NonNull final Context context) {
48+
if (MIGRATION_INFO.isEmpty()) {
49+
return;
50+
}
51+
52+
try {
53+
MIGRATION_INFO.get(0).accept(context);
54+
} catch (final Exception e) {
55+
ErrorUtil.showUiErrorSnackbar(context, "Showing migration info to the user", e);
56+
// Remove the migration that caused the error and continue with the next one
57+
MIGRATION_INFO.remove(0);
58+
showUserInfoIfPresent(context);
59+
}
60+
}
61+
62+
/**
63+
* Add a migration info action that will be executed after the UI is initialized.
64+
* This can be used to show dialogs/snackbars/toasts to inform the user about changes that
65+
* were applied by migrations.
66+
*
67+
* @param info the action to be executed
68+
*/
69+
public static void addMigrationInfo(final Consumer<Context> info) {
70+
MIGRATION_INFO.add(info);
71+
}
72+
73+
/**
74+
* This method should be called when the user dismisses the migration info
75+
* to check if there are any more migration info actions to be shown.
76+
* @param context Context that can be used to show dialogs/snackbars/toasts
77+
*/
78+
public static void onMigrationInfoDismissed(@NonNull final Context context) {
79+
MIGRATION_INFO.remove(0);
80+
showUserInfoIfPresent(context);
81+
}
82+
83+
/**
84+
* Creates a dialog to inform the user about the migration.
85+
* @param uiContext Context that can be used to show dialogs/snackbars/toasts
86+
* @param title the title of the dialog
87+
* @param message the message of the dialog
88+
* @return the dialog that can be shown to the user with a custom dismiss listener
89+
*/
90+
static AlertDialog createMigrationInfoDialog(@NonNull final Context uiContext,
91+
@NonNull final String title,
92+
@NonNull final String message) {
93+
return new AlertDialog.Builder(uiContext)
94+
.setTitle(title)
95+
.setMessage(message)
96+
.setPositiveButton(R.string.ok, null)
97+
.setOnDismissListener(dialog ->
98+
MigrationManager.onMigrationInfoDismissed(uiContext))
99+
.setCancelable(false) // prevents the dialog from being dismissed accidentally
100+
.create();
101+
}
102+
103+
}

0 commit comments

Comments
 (0)