Change check for updates button to trigger a version check

This commit is contained in:
vhouriet 2021-10-23 21:09:53 +02:00 committed by litetex
parent 85fb5827aa
commit 5c9705d94e
5 changed files with 29 additions and 23 deletions

View File

@ -175,9 +175,8 @@ public final class CheckForNewAppVersion extends IntentService {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app);
final NewVersionManager manager = new NewVersionManager();
// Check if user has enabled/disabled update checking
// and if the current apk is a github one or not.
if (!prefs.getBoolean(app.getString(R.string.update_app_key), true) || !isGithubApk(app)) {
// Check if the current apk is a github one or not.
if (!isGithubApk(app)) {
return;
}
@ -213,6 +212,7 @@ public final class CheckForNewAppVersion extends IntentService {
// Parse the json from the response.
try {
final JsonObject githubStableObject = JsonParser.object()
.from(response.responseBody()).getObject("flavors")
.getObject("github").getObject("stable");

View File

@ -169,10 +169,16 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onPostCreate(final Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Start the service which is checking all conditions
// and eventually searching for a new version.
// The service searching for a new NewPipe version must not be started in background.
startNewVersionCheckService();
final App app = App.getApp();
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app);
if (prefs.getBoolean(app.getString(R.string.update_app_key), true)) {
// Start the service which is checking all conditions
// and eventually searching for a new version.
// The service searching for a new NewPipe version must not be started in background.
startNewVersionCheckService();
}
}
private void setupDrawer() throws ExtractionException {

View File

@ -17,11 +17,9 @@ public class MainSettingsFragment extends BasePreferenceFragment {
addPreferencesFromResource(R.xml.main_settings);
if (!CheckForNewAppVersion.isGithubApk(App.getApp())) {
if (!DEBUG) {
final Preference update
= findPreference(getString(R.string.update_pref_screen_key));
getPreferenceScreen().removePreference(update);
}
final Preference update
= findPreference(getString(R.string.update_pref_screen_key));
getPreferenceScreen().removePreference(update);
defaultPreferences.edit().putBoolean(getString(R.string.update_app_key), false).apply();
}

View File

@ -1,8 +1,7 @@
package org.schabi.newpipe.settings;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;
import androidx.preference.Preference;
@ -11,30 +10,32 @@ import org.schabi.newpipe.R;
import static org.schabi.newpipe.CheckForNewAppVersion.startNewVersionCheckService;
public class UpdateSettingsFragment extends BasePreferenceFragment {
private static final String RELEASES_URL = "https://github.com/TeamNewPipe/NewPipe/releases";
private final Preference.OnPreferenceChangeListener updatePreferenceChange
= (preference, checkForUpdates) -> {
defaultPreferences.edit()
.putBoolean(getString(R.string.update_app_key), (boolean) checkForUpdates).apply();
if ((boolean) checkForUpdates) {
// Search for updates immediately when update checks are enabled.
// 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();
checkNewVersionNow();
}
return true;
};
private final Preference.OnPreferenceClickListener manualUpdateClick
= preference -> {
final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(RELEASES_URL));
startActivity(browserIntent);
Toast.makeText(getContext(), R.string.checking_updates_toast, Toast.LENGTH_SHORT).show();
checkNewVersionNow();
return true;
};
private void checkNewVersionNow() {
// Search for updates immediately when update checks are enabled.
// 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();
}
@Override
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
addPreferencesFromResource(R.xml.update_settings);

View File

@ -549,6 +549,7 @@
<string name="recovering">recovering</string>
<string name="enqueue">Queue</string>
<string name="permission_denied">Action denied by the system</string>
<string name="checking_updates_toast">Checking for updates…</string>
<!-- download notifications -->
<string name="download_failed">Download failed</string>
<plurals name="download_finished_notification">