From 7458035683954af14bd38b2d36cf605e8c9ca6f2 Mon Sep 17 00:00:00 2001 From: Sergey Eremin Date: Mon, 18 Sep 2017 19:40:35 +0300 Subject: [PATCH] Issues #273 #275 background update check issues --- .../BackgroundUpdatableAppsTask.java | 8 ++++++- .../ForegroundUpdatableAppsTask.java | 17 +++++++++++++++ .../yalpstore/UpdatableAppsActivity.java | 8 +++---- .../yeriomin/yalpstore/UpdatableAppsTask.java | 21 ++++++------------- .../yeriomin/yalpstore/UpdateChecker.java | 4 ++-- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/github/yeriomin/yalpstore/BackgroundUpdatableAppsTask.java b/app/src/main/java/com/github/yeriomin/yalpstore/BackgroundUpdatableAppsTask.java index 7bb36b47..be043545 100644 --- a/app/src/main/java/com/github/yeriomin/yalpstore/BackgroundUpdatableAppsTask.java +++ b/app/src/main/java/com/github/yeriomin/yalpstore/BackgroundUpdatableAppsTask.java @@ -12,6 +12,12 @@ class BackgroundUpdatableAppsTask extends UpdatableAppsTask { + private boolean forceUpdate = false; + + public void setForceUpdate(boolean forceUpdate) { + this.forceUpdate = forceUpdate; + } + @Override protected void onPostExecute(Throwable e) { super.onPostExecute(e); @@ -31,7 +37,7 @@ protected void onPostExecute(Throwable e) { } private boolean canUpdate() { - return explicitCheck || + return forceUpdate || (PreferenceActivity.getBoolean(context, PreferenceActivity.PREFERENCE_BACKGROUND_UPDATE_DOWNLOAD) && (DownloadManagerFactory.get(context) instanceof DownloadManagerAdapter || !PreferenceActivity.getBoolean(context, PreferenceActivity.PREFERENCE_BACKGROUND_UPDATE_WIFI_ONLY) diff --git a/app/src/main/java/com/github/yeriomin/yalpstore/ForegroundUpdatableAppsTask.java b/app/src/main/java/com/github/yeriomin/yalpstore/ForegroundUpdatableAppsTask.java index 00fd3d91..e4ef2f73 100644 --- a/app/src/main/java/com/github/yeriomin/yalpstore/ForegroundUpdatableAppsTask.java +++ b/app/src/main/java/com/github/yeriomin/yalpstore/ForegroundUpdatableAppsTask.java @@ -5,13 +5,22 @@ import com.github.yeriomin.yalpstore.model.App; +import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; class ForegroundUpdatableAppsTask extends UpdatableAppsTask { + static private List appsFromPlayStore = new ArrayList<>(); + private UpdatableAppsActivity activity; + protected boolean explicitCheck; + + public void setExplicitCheck(boolean explicitCheck) { + this.explicitCheck = explicitCheck; + } public ForegroundUpdatableAppsTask(UpdatableAppsActivity activity) { this.activity = activity; @@ -80,6 +89,14 @@ protected void onProgressUpdate(Void... values) { button.setText(R.string.details_download_checking); } + @Override + protected List getAppsFromPlayStore(Collection packageNames) throws IOException { + if (explicitCheck) { + appsFromPlayStore = super.getAppsFromPlayStore(packageNames); + } + return appsFromPlayStore; + } + private App getSelf() { if (installedApps.containsKey(BuildConfig.APPLICATION_ID)) { return installedApps.get(BuildConfig.APPLICATION_ID); diff --git a/app/src/main/java/com/github/yeriomin/yalpstore/UpdatableAppsActivity.java b/app/src/main/java/com/github/yeriomin/yalpstore/UpdatableAppsActivity.java index f4b081e9..3d8d8978 100644 --- a/app/src/main/java/com/github/yeriomin/yalpstore/UpdatableAppsActivity.java +++ b/app/src/main/java/com/github/yeriomin/yalpstore/UpdatableAppsActivity.java @@ -48,8 +48,8 @@ protected void onResume() { checkUpdates.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - UpdatableAppsTask task = getTask(); - UpdatableAppsTask clone = getTask(); + ForegroundUpdatableAppsTask task = getTask(); + ForegroundUpdatableAppsTask clone = getTask(); task.setExplicitCheck(true); clone.setExplicitCheck(true); task.setTaskClone(clone); @@ -98,8 +98,8 @@ protected ListItem getListItem(App app) { return appBadge; } - private UpdatableAppsTask getTask() { - UpdatableAppsTask task = new ForegroundUpdatableAppsTask(this); + private ForegroundUpdatableAppsTask getTask() { + ForegroundUpdatableAppsTask task = new ForegroundUpdatableAppsTask(this); task.setExplicitCheck(PreferenceActivity.getUpdateInterval(this) != -1); task.setErrorView((TextView) getListView().getEmptyView()); task.setContext(this); diff --git a/app/src/main/java/com/github/yeriomin/yalpstore/UpdatableAppsTask.java b/app/src/main/java/com/github/yeriomin/yalpstore/UpdatableAppsTask.java index dace0aaa..9ecd086c 100644 --- a/app/src/main/java/com/github/yeriomin/yalpstore/UpdatableAppsTask.java +++ b/app/src/main/java/com/github/yeriomin/yalpstore/UpdatableAppsTask.java @@ -21,11 +21,8 @@ public class UpdatableAppsTask extends GoogleApiAsyncTask { - static private List appsFromPlayStore = new ArrayList<>(); - protected List updatableApps = new ArrayList<>(); protected Map installedApps = new HashMap<>(); - protected boolean explicitCheck; static public Map getInstalledApps(Context context) { Map apps = new HashMap<>(); @@ -75,10 +72,6 @@ static public Map filterBlacklistedApps(Context context, Map getAppsFromPlayStore(Collection packageNames) throws IOException { - if (explicitCheck) { - appsFromPlayStore.clear(); - boolean builtInAccount = PreferenceActivity.getBoolean(context, PreferenceActivity.PREFERENCE_APP_PROVIDED_EMAIL); - for (App app: new PlayStoreApiWrapper(context).getDetails(new ArrayList<>(packageNames))) { - if (!builtInAccount || app.isFree()) { - appsFromPlayStore.add(app); - } + protected List getAppsFromPlayStore(Collection packageNames) throws IOException { + List appsFromPlayStore = new ArrayList<>(); + boolean builtInAccount = PreferenceActivity.getBoolean(context, PreferenceActivity.PREFERENCE_APP_PROVIDED_EMAIL); + for (App app: new PlayStoreApiWrapper(context).getDetails(new ArrayList<>(packageNames))) { + if (!builtInAccount || app.isFree()) { + appsFromPlayStore.add(app); } } return appsFromPlayStore; diff --git a/app/src/main/java/com/github/yeriomin/yalpstore/UpdateChecker.java b/app/src/main/java/com/github/yeriomin/yalpstore/UpdateChecker.java index b4909457..937deb14 100644 --- a/app/src/main/java/com/github/yeriomin/yalpstore/UpdateChecker.java +++ b/app/src/main/java/com/github/yeriomin/yalpstore/UpdateChecker.java @@ -29,8 +29,8 @@ static public void enable(Context context, int interval) { @Override public void onReceive(Context context, Intent intent) { Log.i(getClass().getName(), "Started"); - UpdatableAppsTask task = new BackgroundUpdatableAppsTask(); - task.setExplicitCheck(context instanceof Activity); + BackgroundUpdatableAppsTask task = new BackgroundUpdatableAppsTask(); + task.setForceUpdate(context instanceof Activity); task.setContext(context); task.execute(); }