Skip to content

Commit

Permalink
Issues #273 #275 background update check issues
Browse files Browse the repository at this point in the history
  • Loading branch information
yeriomin committed Sep 18, 2017
1 parent 993e834 commit 7458035
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<App> appsFromPlayStore = new ArrayList<>();

private UpdatableAppsActivity activity;
protected boolean explicitCheck;

public void setExplicitCheck(boolean explicitCheck) {
this.explicitCheck = explicitCheck;
}

public ForegroundUpdatableAppsTask(UpdatableAppsActivity activity) {
this.activity = activity;
Expand Down Expand Up @@ -80,6 +89,14 @@ protected void onProgressUpdate(Void... values) {
button.setText(R.string.details_download_checking);
}

@Override
protected List<App> getAppsFromPlayStore(Collection<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@

public class UpdatableAppsTask extends GoogleApiAsyncTask {

static private List<App> appsFromPlayStore = new ArrayList<>();

protected List<App> updatableApps = new ArrayList<>();
protected Map<String, App> installedApps = new HashMap<>();
protected boolean explicitCheck;

static public Map<String, App> getInstalledApps(Context context) {
Map<String, App> apps = new HashMap<>();
Expand Down Expand Up @@ -75,10 +72,6 @@ static public Map<String, App> filterBlacklistedApps(Context context, Map<String
return result;
}

public void setExplicitCheck(boolean explicitCheck) {
this.explicitCheck = explicitCheck;
}

@Override
protected Throwable doInBackground(String... params) {
// Building local apps list
Expand Down Expand Up @@ -137,14 +130,12 @@ private App addInstalledAppInfo(App appFromMarket, App installedApp) {
return appFromMarket;
}

private List<App> getAppsFromPlayStore(Collection<String> 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<App> getAppsFromPlayStore(Collection<String> packageNames) throws IOException {
List<App> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 7458035

Please sign in to comment.