From 598d604ca56aa574c3d4cb2d46b318f2b0e47167 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Thu, 1 Dec 2016 10:47:29 +1100 Subject: [PATCH] Ported code for handling 'ignore this/all' from AppDetails Allows the two menu items "Ignore All Updates" and "Ignore This Update" to be checked and save the relevant preferences to the database in response. The old code waited until the activity was paused before saving the preferences to the database. This code does not, and as such incurs a database write on the main UI thread as soon as the user checks the menu items. However that database code has recently been refactored so it should be much more performant. If it turns out to still be problematic then we can revert to the old behaviour of hodling onto any state changes until onPause then persisting to the database. --- .../main/java/org/fdroid/fdroid/AppDetails2.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/src/main/java/org/fdroid/fdroid/AppDetails2.java b/app/src/main/java/org/fdroid/fdroid/AppDetails2.java index 938570798..7793bbe92 100644 --- a/app/src/main/java/org/fdroid/fdroid/AppDetails2.java +++ b/app/src/main/java/org/fdroid/fdroid/AppDetails2.java @@ -34,6 +34,7 @@ import com.nostra13.universalimageloader.core.assist.ImageScaleType; import org.fdroid.fdroid.data.Apk; import org.fdroid.fdroid.data.ApkProvider; import org.fdroid.fdroid.data.App; +import org.fdroid.fdroid.data.AppPrefsProvider; import org.fdroid.fdroid.data.AppProvider; import org.fdroid.fdroid.data.Schema; import org.fdroid.fdroid.installer.InstallManagerService; @@ -160,6 +161,20 @@ public class AppDetails2 extends AppCompatActivity implements ShareChooserDialog boolean showNearbyItem = mApp.isInstalled() && mFDroidApp.bluetoothAdapter != null; ShareChooserDialog.createChooser((CoordinatorLayout) findViewById(R.id.rootCoordinator), this, this, shareIntent, showNearbyItem); return true; + } else if (item.getItemId() == R.id.action_ignore_all) { + mApp.getPrefs(this).ignoreAllUpdates ^= true; + item.setChecked(mApp.getPrefs(this).ignoreAllUpdates); + AppPrefsProvider.Helper.update(this, mApp, mApp.getPrefs(this)); + return true; + } else if (item.getItemId() == R.id.action_ignore_this) { + if (mApp.getPrefs(this).ignoreThisUpdate >= mApp.suggestedVersionCode) { + mApp.getPrefs(this).ignoreThisUpdate = 0; + } else { + mApp.getPrefs(this).ignoreThisUpdate = mApp.suggestedVersionCode; + } + item.setChecked(mApp.getPrefs(this).ignoreThisUpdate > 0); + AppPrefsProvider.Helper.update(this, mApp, mApp.getPrefs(this)); + return true; } return super.onOptionsItemSelected(item); }