Start auto downloads once preference is enabled.

Fixes issue #896.
This commit is contained in:
Peter Serwylo 2017-03-23 23:26:50 +11:00
parent 8ed62d22e1
commit 61d7ba9f29
3 changed files with 53 additions and 19 deletions

View File

@ -19,6 +19,7 @@ import org.fdroid.fdroid.FDroidApp;
import org.fdroid.fdroid.Preferences; import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.PreferencesActivity; import org.fdroid.fdroid.PreferencesActivity;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.installer.InstallHistoryService; import org.fdroid.fdroid.installer.InstallHistoryService;
import org.fdroid.fdroid.installer.PrivilegedInstaller; import org.fdroid.fdroid.installer.PrivilegedInstaller;
@ -271,21 +272,34 @@ public class PreferencesFragment extends PreferenceFragment
}); });
} }
/**
* If a user specifies they want to fetch updates automatically, then start the download of relevant
* updates as soon as they enable the feature.
* Also, if the user has the priv extention installed then change the label to indicate that it
* will actually _install_ apps, not just fetch their .apk file automatically.
*/
private void initAutoFetchUpdatesPreference() {
updateAutoDownloadPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override @Override
public void onResume() { public boolean onPreferenceChange(Preference preference, Object newValue) {
super.onResume(); if (newValue instanceof Boolean && (boolean) newValue) {
UpdateService.autoDownloadUpdates(getContext());
}
return true;
}
});
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); if (PrivilegedInstaller.isDefault(getContext())) {
updateAutoDownloadPref.setTitle(R.string.update_auto_install);
for (final String key : SUMMARIES_TO_UPDATE) { updateAutoDownloadPref.setSummary(R.string.update_auto_install_summary);
updateSummary(key, false); }
} }
currentKeepCacheTime = Preferences.get().getKeepCacheTime(); /**
* The default for "Use Tor" is dynamically set based on whether Orbot is installed.
initPrivilegedInstallerPreference(); */
initUpdatePrivilegedExtensionPreference(); private void initUseTorPreference() {
// this pref's default is dynamically set based on whether Orbot is installed
boolean useTor = Preferences.get().isTorEnabled(); boolean useTor = Preferences.get().isTorEnabled();
useTorCheckPref.setDefaultValue(useTor); useTorCheckPref.setDefaultValue(useTor);
useTorCheckPref.setChecked(useTor); useTorCheckPref.setChecked(useTor);
@ -308,11 +322,24 @@ public class PreferencesFragment extends PreferenceFragment
return true; return true;
} }
}); });
if (PrivilegedInstaller.isDefault(getContext())) {
updateAutoDownloadPref.setTitle(R.string.update_auto_install);
updateAutoDownloadPref.setSummary(R.string.update_auto_install_summary);
} }
@Override
public void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
for (final String key : SUMMARIES_TO_UPDATE) {
updateSummary(key, false);
}
currentKeepCacheTime = Preferences.get().getKeepCacheTime();
initAutoFetchUpdatesPreference();
initPrivilegedInstallerPreference();
initUpdatePrivilegedExtensionPreference();
initUseTorPreference();
} }
@Override @Override

View File

@ -57,6 +57,9 @@ import java.util.List;
* repopulate it from the original source lists of data. When this is done, the adapter will notify * repopulate it from the original source lists of data. When this is done, the adapter will notify
* the recycler view that its data has changed. Sometimes it will also ask the recycler view to * the recycler view that its data has changed. Sometimes it will also ask the recycler view to
* scroll to the newly added item (if attached to the recycler view). * scroll to the newly added item (if attached to the recycler view).
*
* TODO: If a user downloads an old version of an app (resulting in a new update being available
* instantly), then we need to refresh the list of apps to update.
*/ */
public class UpdatesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements LoaderManager.LoaderCallbacks<Cursor> { public class UpdatesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements LoaderManager.LoaderCallbacks<Cursor> {
@ -84,9 +87,6 @@ public class UpdatesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
.addDelegate(new UpdateableApp.Delegate(activity)) .addDelegate(new UpdateableApp.Delegate(activity))
.addDelegate(new UpdateableAppsHeader.Delegate(activity)); .addDelegate(new UpdateableAppsHeader.Delegate(activity));
populateAppStatuses();
notifyDataSetChanged();
activity.getSupportLoaderManager().initLoader(0, null, this); activity.getSupportLoaderManager().initLoader(0, null, this);
} }
@ -245,11 +245,18 @@ public class UpdatesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
public void onLoaderReset(Loader<Cursor> loader) { } public void onLoaderReset(Loader<Cursor> loader) { }
/** /**
* If this adapter is "active" then it is part of the current UI that the user is looking to.
* Under those circumstances, we want to make sure it is up to date, and also listen to the
* correct set of broadcasts.
* Doesn't listen for {@link AppUpdateStatusManager#BROADCAST_APPSTATUS_CHANGED} because the * Doesn't listen for {@link AppUpdateStatusManager#BROADCAST_APPSTATUS_CHANGED} because the
* individual items in the recycler view will listen for the appropriate changes in state and * individual items in the recycler view will listen for the appropriate changes in state and
* update themselves accordingly (if they are displayed). * update themselves accordingly (if they are displayed).
*/ */
public void listenForStatusUpdates() { public void setIsActive() {
appsToShowStatus.clear();
populateAppStatuses();
notifyDataSetChanged();
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
filter.addAction(AppUpdateStatusManager.BROADCAST_APPSTATUS_ADDED); filter.addAction(AppUpdateStatusManager.BROADCAST_APPSTATUS_ADDED);
filter.addAction(AppUpdateStatusManager.BROADCAST_APPSTATUS_REMOVED); filter.addAction(AppUpdateStatusManager.BROADCAST_APPSTATUS_REMOVED);

View File

@ -24,7 +24,7 @@ public class UpdatesViewBinder {
} }
public void bind() { public void bind() {
adapter.listenForStatusUpdates(); adapter.setIsActive();
} }
public void unbind() { public void unbind() {