Correctly handle swiping to dismiss items in updates tab.

Items which can be updated (but have not yet been downloaded or queued for download)
will act as if the user selected "Ignore this update" from the app details view.

Items which represent app statuses (e.g. downloading, downloaded ready to install,
installed ready to run) will have the status removed. If required, we will also
forget that they are ready to install, so they wont be there next time.
This commit is contained in:
Peter Serwylo 2017-09-27 22:53:27 +10:00
parent 32c17e5f72
commit 1d4f4ce01d
6 changed files with 82 additions and 5 deletions

View File

@ -510,11 +510,15 @@ public abstract class AppListItemController extends RecyclerView.ViewHolder {
private final View.OnClickListener onCancelDownload = new View.OnClickListener() {
@Override
public void onClick(View v) {
cancelDownload();
}
};
protected final void cancelDownload() {
if (currentStatus == null || currentStatus.status != AppUpdateStatusManager.Status.Downloading) {
return;
}
InstallManagerService.cancel(activity, currentStatus.getUniqueKey());
}
};
}

View File

@ -341,6 +341,16 @@ public class UpdatesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
}
};
/**
* If an item representing an {@link org.fdroid.fdroid.AppUpdateStatusManager.AppUpdateStatus} is dismissed,
* then we should rebuild the list of app statuses and update the adapter. If it was an updateable app which was
* dismissed, then it is still harmless to rebuild the list of items anyway, but this isn't strictly required
* because the act of marking an app as "Ignored" will trigger the {@link AppProvider} to re-query for a list
* of updateable apps, separate to this method. However, by the time we get here it is a bit tricky to figure
* out which item was dismissed, so for simplicity (and to make the behaviour more deterministic) we always
* rebuild the full updates list.
*/
public void onItemDismissed() {
onAppStatusRemoved();
}
}

View File

@ -45,4 +45,30 @@ public class AppStatusListItemController extends AppListItemController {
return null;
}
@Override
public boolean canDismiss() {
return true;
}
@Nullable
@Override
protected CharSequence onDismissApp(@NonNull App app) {
AppUpdateStatus status = getCurrentStatus();
if (status != null) {
AppUpdateStatusManager manager = AppUpdateStatusManager.getInstance(activity);
manager.removeApk(status.getUniqueKey());
switch (status.status) {
case ReadyToInstall:
manager.markAsNoLongerPendingInstall(status);
break;
case Downloading:
cancelDownload();
break;
}
}
return null;
}
}

View File

@ -82,8 +82,23 @@ public class KnownVulnAppListItemController extends AppListItemController {
}
}
@Override
public boolean canDismiss() {
return true;
}
@Override
protected CharSequence onDismissApp(@NonNull App app) {
this.ignoreVulnerableApp(app);
return activity.getString(R.string.app_list__dismiss_vulnerable_app);
}
@Override
protected void onSecondaryButtonPressed(@NonNull App app) {
this.ignoreVulnerableApp(app);
}
private void ignoreVulnerableApp(@NonNull App app) {
AppPrefs prefs = app.getPrefs(activity);
prefs.ignoreVulnerabilities = true;
AppPrefsProvider.Helper.update(activity, app, prefs);

View File

@ -6,7 +6,10 @@ import android.support.annotation.Nullable;
import android.view.View;
import org.fdroid.fdroid.AppUpdateStatusManager;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.data.App;
import org.fdroid.fdroid.data.AppPrefs;
import org.fdroid.fdroid.data.AppPrefsProvider;
import org.fdroid.fdroid.views.apps.AppListItemController;
import org.fdroid.fdroid.views.apps.AppListItemState;
@ -28,4 +31,21 @@ public class UpdateableAppListItemController extends AppListItemController {
return new AppListItemState(app)
.setShowInstallButton(true);
}
@Override
public boolean canDismiss() {
return true;
}
@Override
@Nullable
protected CharSequence onDismissApp(@NonNull App app) {
AppPrefs prefs = app.getPrefs(activity);
prefs.ignoreThisUpdate = app.suggestedVersionCode;
// The act of updating here will trigger a re-query of the "can update" apps, so no need to do anything else
// to update the UI in response to this.
AppPrefsProvider.Helper.update(activity, app, prefs);
return activity.getString(R.string.app_list__dismiss_app_update);
}
}

View File

@ -87,6 +87,8 @@ This often occurs with apps installed via Google Play or other sources, if they
<string name="app_list__name__downloading_in_progress">Downloading %1$s</string>
<string name="app_list__name__successfully_installed">%1$s installed</string>
<string name="app_list_download_ready">Downloaded, ready to install</string>
<string name="app_list__dismiss_app_update">Update ignored</string>
<string name="app_list__dismiss_vulnerable_app">Vulnerability ignored</string>
<string name="installed_apps__activity_title">Installed Apps</string>
<string name="installed_app__updates_ignored">Updates ignored</string>