Removed flvor checks. Added update settings under main settings.

This commit is contained in:
Kartikey Kushwaha 2018-09-15 20:51:17 +05:30
parent 6417bd91ef
commit 7124d9bca5
12 changed files with 107 additions and 36 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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<Void, Void, String> {
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

View File

@ -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;
}
};
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96zM17,13l-5,5 -5,-5h3V9h4v4h3z"/>
</vector>

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96zM17,13l-5,5 -5,-5h3V9h4v4h3z"/>
</vector>

View File

@ -38,6 +38,7 @@
<attr name="ic_add" format="reference"/>
<attr name="ic_restore_defaults" format="reference"/>
<attr name="ic_blank_page" format="reference"/>
<attr name="ic_settings_update" format="reference"/>
<!-- Can't refer to colors directly in drawable's xml-->
<attr name="toolbar_shadow_drawable" format="reference"/>

View File

@ -201,6 +201,9 @@
<item>@string/always_ask_open_action_key</item>
</string-array>
<!-- Updates -->
<string name="update_app_key" translatable="false">update_app_key</string>
<!-- alternatively, load these from some local android data store -->
<string-array name="language_codes" translatable="false">
<item>af</item>

View File

@ -109,6 +109,7 @@
<string name="settings_category_appearance_title">Appearance</string>
<string name="settings_category_other_title">Other</string>
<string name="settings_category_debug_title">Debug</string>
<string name="settings_category_updates_title">Updates</string>
<string name="background_player_playing_toast">Playing in background</string>
<string name="popup_playing_toast">Playing in popup mode</string>
<string name="background_player_append">Queued on background player</string>
@ -515,6 +516,10 @@
<item>144p</item>
</string-array>
<!-- Updates Settings -->
<string name="updates_setting_title">Updates</string>
<string name="updates_setting_description"> Show a notification to prompt app update when a new version is available</string>
<!-- Minimize to exit action -->
<string name="minimize_on_exit_title">Minimize on application switch</string>
<string name="minimize_on_exit_summary">Action when switching to other application from main video player — %s</string>
@ -526,8 +531,4 @@
<string name="app_update_notification_content_title">NewPipe Update Available</string>
<string name="app_update_notification_content_text">Tap to download</string>
<!-- Flavor names -->
<string name="app_flavor_github">github</string>
<string name="app_flavor_fdroid">fdroid</string>
</resources>

View File

@ -54,6 +54,7 @@
<item name="ic_add">@drawable/ic_add_black_24dp</item>
<item name="ic_restore_defaults">@drawable/ic_settings_backup_restore_black_24dp</item>
<item name="ic_blank_page">@drawable/ic_blank_page_black_24dp</item>
<item name="ic_settings_update">@drawable/ic_settings_update_black</item>
<item name="separator_color">@color/light_separator_color</item>
<item name="contrast_background_color">@color/light_contrast_background_color</item>
@ -114,6 +115,7 @@
<item name="ic_add">@drawable/ic_add_white_24dp</item>
<item name="ic_restore_defaults">@drawable/ic_settings_backup_restore_white_24dp</item>
<item name="ic_blank_page">@drawable/ic_blank_page_white_24dp</item>
<item name="ic_settings_update">@drawable/ic_settings_update_white</item>
<item name="separator_color">@color/dark_separator_color</item>
<item name="contrast_background_color">@color/dark_contrast_background_color</item>

View File

@ -29,6 +29,11 @@
android:icon="?attr/language"
android:title="@string/content"/>
<PreferenceScreen
android:fragment="org.schabi.newpipe.settings.UpdateSettingsFragment"
android:icon="?attr/ic_settings_update"
android:title="@string/settings_category_updates_title" />
<PreferenceScreen
android:fragment="org.schabi.newpipe.settings.DebugSettingsFragment"
android:icon="?attr/bug"

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="general_preferences"
android:title="@string/settings_category_updates_title">
<SwitchPreference
android:defaultValue="true"
android:key="@string/update_app_key"
android:title="@string/updates_setting_title"
android:summary="@string/updates_setting_description"/>
</PreferenceScreen>