diff --git a/app/build.gradle b/app/build.gradle index b5a106a6d..2fd175fbe 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,20 +41,6 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } - - flavorDimensions "apkSource" - productFlavors { - github { - dimension "apkSource" - applicationIdSuffix ".github" - - } - - fdroid { - dimension "apkSource" - applicationIdSuffix ".fdroid" - } - } } ext { diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index c9ebc976c..bc824699e 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -209,24 +209,21 @@ public class App extends Application { NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.createNotificationChannel(mChannel); - // Set up notification channel for app update only if it's a github apk. - if (BuildConfig.FLAVOR.equals(getString(R.string.app_flavor_github))) { + // Set up notification channel for app update. + final String appUpdateId + = getString(R.string.app_update_notification_channel_id); + final CharSequence appUpdateName + = getString(R.string.app_update_notification_channel_name); + final String appUpdateDescription + = getString(R.string.app_update_notification_channel_description); - final String appUpdateId - = getString(R.string.app_update_notification_channel_id); - final CharSequence appUpdateName - = getString(R.string.app_update_notification_channel_name); - final String appUpdateDescription - = getString(R.string.app_update_notification_channel_description); + NotificationChannel appUpdateChannel + = new NotificationChannel(appUpdateId, appUpdateName, importance); + appUpdateChannel.setDescription(appUpdateDescription); - NotificationChannel appUpdateChannel - = new NotificationChannel(appUpdateId, appUpdateName, importance); - appUpdateChannel.setDescription(appUpdateDescription); - - NotificationManager appUpdateNotificationManager - = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - appUpdateNotificationManager.createNotificationChannel(appUpdateChannel); - } + NotificationManager appUpdateNotificationManager + = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + appUpdateNotificationManager.createNotificationChannel(appUpdateChannel); } @Nullable diff --git a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java index 4b75c202c..9694850d7 100644 --- a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java +++ b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java @@ -3,10 +3,13 @@ package org.schabi.newpipe; import android.app.Application; import android.app.PendingIntent; import android.content.Intent; +import android.content.SharedPreferences; import android.net.Uri; import android.os.AsyncTask; +import android.preference.PreferenceManager; import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationManagerCompat; +import android.util.Log; import org.json.JSONException; import org.json.JSONObject; @@ -29,12 +32,23 @@ public class CheckForNewAppVersionTask extends AsyncTask { private String newPipeApiUrl = "https://newpipe.schabi.org/api/data.json"; private int timeoutPeriod = 10000; + private SharedPreferences mPrefs; + @Override protected void onPreExecute() { - // Continue with version check only if the build variant is of type "github". - if (!BuildConfig.FLAVOR.equals(app.getString(R.string.app_flavor_github))) { + + mPrefs = PreferenceManager.getDefaultSharedPreferences(app); + + // Check if user has enabled/ disabled update checking. + if (mPrefs.getBoolean(app.getString(R.string.update_app_key), true)) { + + // Go ahead with further checks. + Log.i("pref---", "true"); + } else { + Log.i("pref---", "false"); this.cancel(true); } + } @Override diff --git a/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java new file mode 100644 index 000000000..f6aab7cda --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java @@ -0,0 +1,35 @@ +package org.schabi.newpipe.settings; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.preference.Preference; + +import org.schabi.newpipe.R; + +public class UpdateSettingsFragment extends BasePreferenceFragment { + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + String updateToggleKey = getString(R.string.update_app_key); + findPreference(updateToggleKey).setOnPreferenceChangeListener(updatePreferenceChange); + } + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + addPreferencesFromResource(R.xml.update_settings); + } + + private Preference.OnPreferenceChangeListener updatePreferenceChange + = new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + + defaultPreferences.edit().putBoolean(getString(R.string.update_app_key), + (boolean) newValue).apply(); + + return true; + } + }; +} diff --git a/app/src/main/res/drawable/ic_settings_update_black.xml b/app/src/main/res/drawable/ic_settings_update_black.xml new file mode 100644 index 000000000..261c31217 --- /dev/null +++ b/app/src/main/res/drawable/ic_settings_update_black.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_settings_update_white.xml b/app/src/main/res/drawable/ic_settings_update_white.xml new file mode 100644 index 000000000..0feb270af --- /dev/null +++ b/app/src/main/res/drawable/ic_settings_update_white.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 7b879fb4c..75c39c490 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -38,6 +38,7 @@ + diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 9b39fec26..b7ffb101d 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -201,6 +201,9 @@ @string/always_ask_open_action_key + + update_app_key + af diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ab55b6f6c..29fa4dc03 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -109,6 +109,7 @@ Appearance Other Debug + Updates Playing in background Playing in popup mode Queued on background player @@ -515,6 +516,10 @@ 144p + + Updates + Show a notification to prompt app update when a new version is available + Minimize on application switch Action when switching to other application from main video player — %s @@ -526,8 +531,4 @@ NewPipe Update Available Tap to download - - github - fdroid - diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 87e19cede..8eae8343d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -54,6 +54,7 @@ @drawable/ic_add_black_24dp @drawable/ic_settings_backup_restore_black_24dp @drawable/ic_blank_page_black_24dp + @drawable/ic_settings_update_black @color/light_separator_color @color/light_contrast_background_color @@ -114,6 +115,7 @@ @drawable/ic_add_white_24dp @drawable/ic_settings_backup_restore_white_24dp @drawable/ic_blank_page_white_24dp + @drawable/ic_settings_update_white @color/dark_separator_color @color/dark_contrast_background_color diff --git a/app/src/main/res/xml/main_settings.xml b/app/src/main/res/xml/main_settings.xml index 4196a98d3..3773460d6 100644 --- a/app/src/main/res/xml/main_settings.xml +++ b/app/src/main/res/xml/main_settings.xml @@ -29,6 +29,11 @@ android:icon="?attr/language" android:title="@string/content"/> + + + + + + +