mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 08:30:44 +00:00
Change check for updates button to trigger a version check
This commit is contained in:
parent
85fb5827aa
commit
5c9705d94e
@ -175,9 +175,8 @@ public final class CheckForNewAppVersion extends IntentService {
|
|||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app);
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app);
|
||||||
final NewVersionManager manager = new NewVersionManager();
|
final NewVersionManager manager = new NewVersionManager();
|
||||||
|
|
||||||
// Check if user has enabled/disabled update checking
|
// Check if the current apk is a github one or not.
|
||||||
// and if the current apk is a github one or not.
|
if (!isGithubApk(app)) {
|
||||||
if (!prefs.getBoolean(app.getString(R.string.update_app_key), true) || !isGithubApk(app)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,6 +212,7 @@ public final class CheckForNewAppVersion extends IntentService {
|
|||||||
|
|
||||||
// Parse the json from the response.
|
// Parse the json from the response.
|
||||||
try {
|
try {
|
||||||
|
|
||||||
final JsonObject githubStableObject = JsonParser.object()
|
final JsonObject githubStableObject = JsonParser.object()
|
||||||
.from(response.responseBody()).getObject("flavors")
|
.from(response.responseBody()).getObject("flavors")
|
||||||
.getObject("github").getObject("stable");
|
.getObject("github").getObject("stable");
|
||||||
|
@ -169,10 +169,16 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onPostCreate(final Bundle savedInstanceState) {
|
protected void onPostCreate(final Bundle savedInstanceState) {
|
||||||
super.onPostCreate(savedInstanceState);
|
super.onPostCreate(savedInstanceState);
|
||||||
// Start the service which is checking all conditions
|
|
||||||
// and eventually searching for a new version.
|
final App app = App.getApp();
|
||||||
// The service searching for a new NewPipe version must not be started in background.
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app);
|
||||||
startNewVersionCheckService();
|
|
||||||
|
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 {
|
private void setupDrawer() throws ExtractionException {
|
||||||
|
@ -17,11 +17,9 @@ public class MainSettingsFragment extends BasePreferenceFragment {
|
|||||||
addPreferencesFromResource(R.xml.main_settings);
|
addPreferencesFromResource(R.xml.main_settings);
|
||||||
|
|
||||||
if (!CheckForNewAppVersion.isGithubApk(App.getApp())) {
|
if (!CheckForNewAppVersion.isGithubApk(App.getApp())) {
|
||||||
if (!DEBUG) {
|
final Preference update
|
||||||
final Preference update
|
= findPreference(getString(R.string.update_pref_screen_key));
|
||||||
= findPreference(getString(R.string.update_pref_screen_key));
|
getPreferenceScreen().removePreference(update);
|
||||||
getPreferenceScreen().removePreference(update);
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultPreferences.edit().putBoolean(getString(R.string.update_app_key), false).apply();
|
defaultPreferences.edit().putBoolean(getString(R.string.update_app_key), false).apply();
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package org.schabi.newpipe.settings;
|
package org.schabi.newpipe.settings;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
@ -11,30 +10,32 @@ import org.schabi.newpipe.R;
|
|||||||
import static org.schabi.newpipe.CheckForNewAppVersion.startNewVersionCheckService;
|
import static org.schabi.newpipe.CheckForNewAppVersion.startNewVersionCheckService;
|
||||||
|
|
||||||
public class UpdateSettingsFragment extends BasePreferenceFragment {
|
public class UpdateSettingsFragment extends BasePreferenceFragment {
|
||||||
private static final String RELEASES_URL = "https://github.com/TeamNewPipe/NewPipe/releases";
|
|
||||||
|
|
||||||
private final Preference.OnPreferenceChangeListener updatePreferenceChange
|
private final Preference.OnPreferenceChangeListener updatePreferenceChange
|
||||||
= (preference, checkForUpdates) -> {
|
= (preference, checkForUpdates) -> {
|
||||||
defaultPreferences.edit()
|
defaultPreferences.edit()
|
||||||
.putBoolean(getString(R.string.update_app_key), (boolean) checkForUpdates).apply();
|
.putBoolean(getString(R.string.update_app_key), (boolean) checkForUpdates).apply();
|
||||||
|
|
||||||
if ((boolean) checkForUpdates) {
|
if ((boolean) checkForUpdates) {
|
||||||
// Search for updates immediately when update checks are enabled.
|
checkNewVersionNow();
|
||||||
// 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;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Preference.OnPreferenceClickListener manualUpdateClick
|
private final Preference.OnPreferenceClickListener manualUpdateClick
|
||||||
= preference -> {
|
= preference -> {
|
||||||
final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(RELEASES_URL));
|
Toast.makeText(getContext(), R.string.checking_updates_toast, Toast.LENGTH_SHORT).show();
|
||||||
startActivity(browserIntent);
|
checkNewVersionNow();
|
||||||
return true;
|
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
|
@Override
|
||||||
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
|
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
|
||||||
addPreferencesFromResource(R.xml.update_settings);
|
addPreferencesFromResource(R.xml.update_settings);
|
||||||
|
@ -549,6 +549,7 @@
|
|||||||
<string name="recovering">recovering</string>
|
<string name="recovering">recovering</string>
|
||||||
<string name="enqueue">Queue</string>
|
<string name="enqueue">Queue</string>
|
||||||
<string name="permission_denied">Action denied by the system</string>
|
<string name="permission_denied">Action denied by the system</string>
|
||||||
|
<string name="checking_updates_toast">Checking for updates…</string>
|
||||||
<!-- download notifications -->
|
<!-- download notifications -->
|
||||||
<string name="download_failed">Download failed</string>
|
<string name="download_failed">Download failed</string>
|
||||||
<plurals name="download_finished_notification">
|
<plurals name="download_finished_notification">
|
||||||
|
Loading…
Reference in New Issue
Block a user