Skip to content

Commit

Permalink
Add migration to ask for auto update check on affected previous installs
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiGr committed Jan 26, 2024
1 parent 508c1ed commit df17ec2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.schabi.newpipe.error.ErrorUtil;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.ReleaseVersionUtil;

import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -143,6 +144,16 @@ protected void migrate(@NonNull final Context context) {
}
};

public static final Migration MIGRATION_6_7 = new Migration(6, 7) {
@Override
protected void migrate(@NonNull final Context context) {
final boolean isAutoUpdateCheckEnabled = sp.getBoolean("update_app_key", true);
if (isAutoUpdateCheckEnabled && ReleaseVersionUtil.isReleaseApk()) {
UpdateSettingsFragment.askForConsentToUpdateChecks(context);
}
}
};

/**
* List of all implemented migrations.
* <p>
Expand All @@ -156,12 +167,13 @@ protected void migrate(@NonNull final Context context) {
MIGRATION_3_4,
MIGRATION_4_5,
MIGRATION_5_6,
MIGRATION_6_7,
};

/**
* Version number for preferences. Must be incremented every time a migration is necessary.
*/
private static final int VERSION = 6;
private static final int VERSION = 7;


public static void runMigrationsIfNeeded(@NonNull final Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,20 @@ public static void askForConsentToUpdateChecks(final Context context) {
.setMessage(context.getString(R.string.auto_update_check_description))
.setPositiveButton(context.getString(R.string.yes), (d, w) -> {
d.dismiss();
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putBoolean(context.getString(R.string.update_app_key), true)
.apply();
setAutoUpdateCheckEnabled(context, true);
})
.setNegativeButton(R.string.no, (d, w) -> {
d.dismiss();
// set explicitly to false, since the default is true on previous versions
setAutoUpdateCheckEnabled(context, false);
})
.setNegativeButton(R.string.no, (d, w) -> d.dismiss())
.show();
}

private static void setAutoUpdateCheckEnabled(final Context context, final boolean enabled) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putBoolean(context.getString(R.string.update_app_key), enabled)
.apply();
}
}

0 comments on commit df17ec2

Please sign in to comment.