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.
This commit is contained in:
Peter Serwylo 2016-12-01 10:47:29 +11:00
parent 9f758c4f86
commit 598d604ca5

View File

@ -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);
}