Preferences : Add option for periodic updates check

TODO : Allow for background update download and installations
This commit is contained in:
Mr. Dragon
2019-03-31 18:49:36 +05:30
parent 3bb83f0e18
commit 36aa45bb3d
11 changed files with 238 additions and 5 deletions

View File

@@ -129,6 +129,15 @@
<receiver android:name=".receiver.DownloadPauseReceiver" />
<receiver android:name=".receiver.DownloadResumeReceiver" />
<receiver android:name=".receiver.NotificationDeleteReceiver" />
<receiver android:name=".receiver.UpdatesReceiver" />
<receiver
android:name=".receiver.BootReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".installer.SplitService" />
</application>

View File

@@ -84,4 +84,5 @@ public class Constants {
public static final String PREFERENCE_LOCALE_LANG = "PREFERENCE_LOCALE_LANG";
public static final String PREFERENCE_LOCALE_LIST = "PREFERENCE_LOCALE_LIST";
public static final String PREFERENCE_LOCALE_COUNTRY = "PREFERENCE_LOCALE_COUNTRY";
public static final String PREFERENCE_UPDATES_INTERVAL = "PREFERENCE_UPDATES_INTERVAL";
}

View File

@@ -112,7 +112,7 @@ public class AuroraActivity extends AppCompatActivity {
super.onNewIntent(intent);
Bundle mBundle = intent.getExtras();
if (mBundle != null)
fragmentPos = mBundle.getInt(Constants.INTENT_FRAGMENT_POSITION);
fragmentCur = mBundle.getInt(Constants.INTENT_FRAGMENT_POSITION);
if (intent.getScheme() != null && intent.getScheme().equals("market")) {
fragmentCur = 3;
isSearchIntent = true;

View File

@@ -0,0 +1,48 @@
package com.aurora.store.fragment.preference;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.ListPreference;
import androidx.preference.PreferenceFragmentCompat;
import com.aurora.store.Constants;
import com.aurora.store.R;
import com.aurora.store.receiver.UpdatesReceiver;
import com.aurora.store.utility.PrefUtil;
import com.aurora.store.utility.Util;
public class UpdatesPrefFragment extends PreferenceFragmentCompat {
private Context context;
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
this.context = context;
}
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getPreferenceManager().setSharedPreferencesName(Constants.SHARED_PREFERENCES_KEY);
setPreferencesFromResource(R.xml.preferences_updates, rootKey);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ListPreference updatesIntervalList = findPreference(Constants.PREFERENCE_UPDATES_INTERVAL);
assert updatesIntervalList != null;
updatesIntervalList.setOnPreferenceChangeListener((preference, newValue) -> {
String value = newValue.toString();
PrefUtil.putString(context, Constants.PREFERENCE_UPDATES_INTERVAL, value);
UpdatesReceiver.enable(context, Util.parseInt(value, 0));
return true;
});
}
}

View File

@@ -0,0 +1,47 @@
/*
* Aurora Store
* Copyright (C) 2019, Rahul Kumar Patel <whyorean@gmail.com>
*
* Yalp Store
* Copyright (C) 2018 Sergey Yeriomin <yeriomin@gmail.com>
*
* Aurora Store is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Aurora Store is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package com.aurora.store.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.aurora.store.Constants;
import com.aurora.store.utility.Util;
public class BootReceiver extends BroadcastReceiver {
static private int getUpdateInterval(Context context) {
return Util.parseInt(Util.getPrefs(context)
.getString(Constants.PREFERENCE_UPDATES_INTERVAL, "-1"), -1);
}
@Override
public void onReceive(Context context, Intent intent) {
if (!Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
return;
}
UpdatesReceiver.enable(context.getApplicationContext(), getUpdateInterval(context));
}
}

View File

@@ -0,0 +1,68 @@
package com.aurora.store.receiver;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.aurora.store.Constants;
import com.aurora.store.R;
import com.aurora.store.activity.AuroraActivity;
import com.aurora.store.notification.QuickNotification;
import com.aurora.store.task.UpdatableApps;
import com.aurora.store.utility.Log;
import org.apache.commons.lang3.StringUtils;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
public class UpdatesReceiver extends BroadcastReceiver {
static public void enable(Context context, int interval) {
Intent intent = new Intent(context, UpdatesReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
if (interval > 0) {
Log.e("Enabling periodic update checks");
alarmManager.setRepeating(
AlarmManager.RTC_WAKEUP,
System.currentTimeMillis(),
interval,
pendingIntent
);
}
}
@Override
public void onReceive(Context context, Intent intent) {
Log.e("Update check Started");
CompositeDisposable disposable = new CompositeDisposable();
UpdatableApps updatableAppTask = new UpdatableApps(context);
disposable.add(Observable.fromCallable(updatableAppTask::getUpdatableApps)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe((appList) -> {
if (!appList.isEmpty()) {
QuickNotification.show(context,
context.getString(R.string.action_updates),
new StringBuilder()
.append(appList.size())
.append(StringUtils.SPACE)
.append(context.getString(R.string.list_update_all_txt))
.toString(),
getContentIntent(context));
}
}, err -> Log.e("Update check failed")));
}
private PendingIntent getContentIntent(Context context) {
Intent intent = new Intent(context, AuroraActivity.class);
intent.putExtra(Constants.INTENT_FRAGMENT_POSITION, 2);
return PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
}

View File

@@ -21,9 +21,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?android:attr/colorForeground"
android:pathData="M21,10.12H14.22L16.96,7.3C14.23,4.6 9.81,4.5 7.08,7.2C4.35,9.91 4.35,14.28 7.08,17C9.81,19.7 14.23,19.7 16.96,17C18.32,15.65 19,14.08 19,12.1H21C21,14.08 20.12,16.65 18.36,18.39C14.85,21.87 9.15,21.87 5.64,18.39C2.14,14.92 2.11,9.28 5.62,5.81C9.13,2.34 14.76,2.34 18.27,5.81L21,3V10.12M12.5,8V12.25L16,14.33L15.28,15.54L11,13V8H12.5Z" />
android:fillAlpha="0.3"
android:fillColor="?android:attr/colorControlNormal"
android:pathData="M7,19h10L17,5L7,5v14zM11,13L11,8h2v5h3l-4,4 -4,-4h3z"
android:strokeAlpha="0.3" />
<path
android:fillColor="?android:attr/colorControlNormal"
android:pathData="M16,13h-3L13,8h-2v5L8,13l4,4zM17,1.01L7,1c-1.1,0 -2,0.9 -2,2v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2L19,3c0,-1.1 -0.9,-1.99 -2,-1.99zM17,19L7,19L7,5h10v14z" />
</vector>

View File

@@ -262,4 +262,18 @@
<item>@string/about_telegram_summary</item>
<item>@string/about_fdroid_summary</item>
</string-array>
<string-array name="pref_update_interval_values">
<item>-1</item>
<item>3600000</item>
<item>86400000</item>
<item>604800000</item>
</string-array>
<string-array name="pref_update_interval">
<item>@string/pref_update_interval_manually</item>
<item>@string/pref_update_interval_hourly</item>
<item>@string/pref_update_interval_daily</item>
<item>@string/pref_update_interval_weekly</item>
</string-array>
</resources>

View File

@@ -288,6 +288,11 @@
<string name="pref_ui_tab_mode_title">Scrollable tabs</string>
<string name="pref_ui_tab_mode_summary">Enable to make tabs scrollable, recommended for low-dpi devices</string>
<string name="pref_ui_tab_default_title">Select default tab</string>
<string name="pref_update_interval_title">Updates interval</string>
<string name="pref_update_interval_manually">Manually</string>
<string name="pref_update_interval_hourly">Hourly</string>
<string name="pref_update_interval_daily">Weekly</string>
<string name="pref_update_interval_weekly">Daily</string>
<string name="testing_program_opt_in">Join</string>
<string name="testing_program_opt_out">Leave</string>

View File

@@ -74,4 +74,9 @@
app:fragment="com.aurora.store.fragment.preference.UIFragment"
app:icon="@drawable/ic_ui"
app:title="@string/pref_app_ui" />
<Preference
app:fragment="com.aurora.store.fragment.preference.UpdatesPrefFragment"
app:icon="@drawable/ic_update"
app:title="@string/action_updates" />
</androidx.preference.PreferenceScreen>

View File

@@ -0,0 +1,31 @@
<!--
~ Aurora Store
~ Copyright (C) 2019, Rahul Kumar Patel <whyorean@gmail.com>
~
~ Aurora Store is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 2 of the License, or
~ (at your option) any later version.
~
~ Aurora Store is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
~
~
-->
<androidx.preference.PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<ListPreference
app:defaultValue="-1"
app:entries="@array/pref_update_interval"
app:entryValues="@array/pref_update_interval_values"
app:key="PREFERENCE_UPDATES_INTERVAL"
app:title="@string/pref_update_interval_title"
app:useSimpleSummaryProvider="true" />
</androidx.preference.PreferenceScreen>