check immediately for updates if user enables 'check for updates setting'

- Convert CheckForNewAppVersion to IntentService
- reset expire date to 0 after user enables check for updates setting
This commit is contained in:
evermind 2021-08-29 08:23:56 +02:00
parent d9086300f3
commit 669a35bc78
4 changed files with 89 additions and 73 deletions

View file

@ -6,11 +6,20 @@ import androidx.preference.Preference;
import org.schabi.newpipe.R;
import static org.schabi.newpipe.CheckForNewAppVersion.startNewVersionCheckService;
public class UpdateSettingsFragment extends BasePreferenceFragment {
private final Preference.OnPreferenceChangeListener updatePreferenceChange
= (preference, newValue) -> {
= (preference, checkForUpdates) -> {
defaultPreferences.edit()
.putBoolean(getString(R.string.update_app_key), (boolean) newValue).apply();
.putBoolean(getString(R.string.update_app_key), (boolean) checkForUpdates).apply();
if ((boolean) checkForUpdates) {
// Reset the expire time. This is necessary to check for an update immediately.
defaultPreferences.edit()
.putLong(getString(R.string.update_expiry_key), 0).apply();
startNewVersionCheckService();
}
return true;
};