rename App.suggestedVersionCode to autoInstallVersionCode #1063

parent 0d848361
......@@ -481,7 +481,7 @@ public class IndexUpdater {
}
int versionCode;
if (repoPushRequest.versionCode == null) {
versionCode = app.suggestedVersionCode;
versionCode = app.autoInstallVersionCode;
} else {
versionCode = repoPushRequest.versionCode;
}
......
......@@ -92,7 +92,7 @@ public class ApkProvider extends FDroidProvider {
@Nullable
public static Apk findSuggestedApk(Context context, App app) {
String mostAppropriateSignature = app.getMostAppropriateSignature();
Apk apk = findApkFromAnyRepo(context, app.packageName, app.suggestedVersionCode,
Apk apk = findApkFromAnyRepo(context, app.packageName, app.autoInstallVersionCode,
mostAppropriateSignature);
if (apk == null && (mostAppropriateSignature == null || !app.isInstalled(context))) {
List<Apk> apks = findByPackageName(context, app.packageName);
......
......@@ -182,7 +182,11 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
*/
private String suggestedVersionName;
public int suggestedVersionCode;
/**
* The version that will be automatically installed if the user does not
* choose a specific version.
*/
public int autoInstallVersionCode;
public Date added;
public Date lastUpdated;
......@@ -305,8 +309,8 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
case Cols.PREFERRED_SIGNER:
preferredSigner = cursor.getString(i);
break;
case Cols.SUGGESTED_VERSION_CODE:
suggestedVersionCode = cursor.getInt(i);
case Cols.AUTO_INSTALL_VERSION_CODE:
autoInstallVersionCode = cursor.getInt(i);
break;
case Cols.UPSTREAM_VERSION_CODE:
upstreamVersionCode = cursor.getInt(i);
......@@ -955,7 +959,7 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
values.put(Cols.ADDED, Utils.formatDate(added, ""));
values.put(Cols.LAST_UPDATED, Utils.formatDate(lastUpdated, ""));
values.put(Cols.PREFERRED_SIGNER, preferredSigner);
values.put(Cols.SUGGESTED_VERSION_CODE, suggestedVersionCode);
values.put(Cols.AUTO_INSTALL_VERSION_CODE, autoInstallVersionCode);
values.put(Cols.UPSTREAM_VERSION_NAME, upstreamVersionName);
values.put(Cols.UPSTREAM_VERSION_CODE, upstreamVersionCode);
values.put(Cols.ForWriting.Categories.CATEGORIES, Utils.serializeCommaSeparatedString(categories));
......@@ -1021,8 +1025,8 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
*/
public boolean hasUpdates() {
boolean updates = false;
if (suggestedVersionCode > 0) {
updates = installedVersionCode > 0 && installedVersionCode < suggestedVersionCode;
if (autoInstallVersionCode > 0) {
updates = installedVersionCode > 0 && installedVersionCode < autoInstallVersionCode;
}
return updates;
}
......@@ -1041,7 +1045,7 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
public boolean canAndWantToUpdate(Context context) {
boolean canUpdate = hasUpdates();
AppPrefs prefs = getPrefs(context);
boolean wantsUpdate = !prefs.ignoreAllUpdates && prefs.ignoreThisUpdate < suggestedVersionCode;
boolean wantsUpdate = !prefs.ignoreAllUpdates && prefs.ignoreThisUpdate < autoInstallVersionCode;
return canUpdate && wantsUpdate && !isDisabledByAntiFeatures();
}
......@@ -1185,7 +1189,7 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
dest.writeString(this.upstreamVersionName);
dest.writeInt(this.upstreamVersionCode);
dest.writeString(this.suggestedVersionName);
dest.writeInt(this.suggestedVersionCode);
dest.writeInt(this.autoInstallVersionCode);
dest.writeLong(this.added != null ? this.added.getTime() : -1);
dest.writeLong(this.lastUpdated != null ? this.lastUpdated.getTime() : -1);
dest.writeStringArray(this.categories);
......@@ -1236,7 +1240,7 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
this.upstreamVersionName = in.readString();
this.upstreamVersionCode = in.readInt();
this.suggestedVersionName = in.readString();
this.suggestedVersionCode = in.readInt();
this.autoInstallVersionCode = in.readInt();
long tmpAdded = in.readLong();
this.added = tmpAdded == -1 ? null : new Date(tmpAdded);
long tmpLastUpdated = in.readLong();
......
......@@ -399,7 +399,7 @@ public class AppProvider extends FDroidProvider {
leftJoin(
getApkTableName(),
"suggestedApk",
getTableName() + "." + Cols.SUGGESTED_VERSION_CODE + " = suggestedApk." + ApkTable.Cols.VERSION_CODE + " AND " + getTableName() + "." + Cols.ROW_ID + " = suggestedApk." + ApkTable.Cols.APP_ID);
getTableName() + "." + Cols.AUTO_INSTALL_VERSION_CODE + " = suggestedApk." + ApkTable.Cols.VERSION_CODE + " AND " + getTableName() + "." + Cols.ROW_ID + " = suggestedApk." + ApkTable.Cols.APP_ID);
}
appendField(fieldName, "suggestedApk", alias);
}
......@@ -615,11 +615,11 @@ public class AppProvider extends FDroidProvider {
// Need to use COALESCE because the prefs join may not resolve any rows, which means the
// ignore* fields will be NULL. In that case, we want to instead use a default value of 0.
final String ignoreCurrent = " COALESCE(prefs." + AppPrefsTable.Cols.IGNORE_THIS_UPDATE + ", 0) != " + app + "." + Cols.SUGGESTED_VERSION_CODE;
final String ignoreCurrent = " COALESCE(prefs." + AppPrefsTable.Cols.IGNORE_THIS_UPDATE + ", 0) != " + app + "." + Cols.AUTO_INSTALL_VERSION_CODE;
final String ignoreAll = "COALESCE(prefs." + AppPrefsTable.Cols.IGNORE_ALL_UPDATES + ", 0) != 1";
final String ignore = " (" + ignoreCurrent + " AND " + ignoreAll + ") ";
final String where = ignore + " AND " + app + "." + Cols.SUGGESTED_VERSION_CODE + " > installed." + InstalledAppTable.Cols.VERSION_CODE;
final String where = ignore + " AND " + app + "." + Cols.AUTO_INSTALL_VERSION_CODE + " > installed." + InstalledAppTable.Cols.VERSION_CODE;
return new AppQuerySelection(where).requireNaturalInstalledTable().requireLeftJoinPrefs();
}
......@@ -1118,7 +1118,7 @@ public class AppProvider extends FDroidProvider {
// installed table (this is impossible), but rather because the subselect above returned
// zero rows.
String updateSql =
"UPDATE " + app + " SET " + Cols.SUGGESTED_VERSION_CODE + " = ( " +
"UPDATE " + app + " SET " + Cols.AUTO_INSTALL_VERSION_CODE + " = ( " +
" SELECT MAX( " + apk + "." + ApkTable.Cols.VERSION_CODE + " ) " +
" FROM " + apk +
" JOIN " + app + " AS appForThisApk ON (appForThisApk." + Cols.ROW_ID + " = " + apk + "." + ApkTable.Cols.APP_ID + ") " +
......@@ -1154,7 +1154,7 @@ public class AppProvider extends FDroidProvider {
final String[] args;
if (packageName == null) {
restrictToApps = " COALESCE(" + Cols.UPSTREAM_VERSION_CODE + ", 0) = 0 OR " + Cols.SUGGESTED_VERSION_CODE + " IS NULL ";
restrictToApps = " COALESCE(" + Cols.UPSTREAM_VERSION_CODE + ", 0) = 0 OR " + Cols.AUTO_INSTALL_VERSION_CODE + " IS NULL ";
args = null;
} else {
// Don't update an app with an upstream version code, because that would have been updated
......@@ -1164,7 +1164,7 @@ public class AppProvider extends FDroidProvider {
}
String updateSql =
"UPDATE " + app + " SET " + Cols.SUGGESTED_VERSION_CODE + " = ( " +
"UPDATE " + app + " SET " + Cols.AUTO_INSTALL_VERSION_CODE + " = ( " +
" SELECT MAX( " + apk + "." + ApkTable.Cols.VERSION_CODE + " ) " +
" FROM " + apk +
" JOIN " + app + " AS appForThisApk ON (appForThisApk." + Cols.ROW_ID + " = " + apk + "." + ApkTable.Cols.APP_ID + ") " +
......
......@@ -147,7 +147,7 @@ public class DBHelper extends SQLiteOpenHelper {
+ AppMetadataTable.Cols.VIDEO + " string, "
+ AppMetadataTable.Cols.CHANGELOG + " text, "
+ AppMetadataTable.Cols.PREFERRED_SIGNER + " text,"
+ AppMetadataTable.Cols.SUGGESTED_VERSION_CODE + " text,"
+ AppMetadataTable.Cols.AUTO_INSTALL_VERSION_CODE + " text,"
+ AppMetadataTable.Cols.UPSTREAM_VERSION_NAME + " text,"
+ AppMetadataTable.Cols.UPSTREAM_VERSION_CODE + " integer,"
+ AppMetadataTable.Cols.ANTI_FEATURES + " string,"
......
......@@ -191,7 +191,7 @@ public interface Schema {
String FLATTR_ID = "flattrID";
String LIBERAPAY_ID = "liberapayID";
String PREFERRED_SIGNER = "preferredSigner";
String SUGGESTED_VERSION_CODE = "suggestedVercode";
String AUTO_INSTALL_VERSION_CODE = "suggestedVercode"; // name mismatch from issue #1063
String UPSTREAM_VERSION_NAME = "upstreamVersion";
String UPSTREAM_VERSION_CODE = "upstreamVercode";
String ADDED = "added";
......@@ -248,7 +248,7 @@ public interface Schema {
ANTI_FEATURES, REQUIREMENTS, ICON_URL,
FEATURE_GRAPHIC, PROMO_GRAPHIC, TV_BANNER, PHONE_SCREENSHOTS,
SEVEN_INCH_SCREENSHOTS, TEN_INCH_SCREENSHOTS, TV_SCREENSHOTS, WEAR_SCREENSHOTS,
PREFERRED_SIGNER, SUGGESTED_VERSION_CODE, IS_APK, IS_LOCALIZED,
PREFERRED_SIGNER, AUTO_INSTALL_VERSION_CODE, IS_APK, IS_LOCALIZED,
};
/**
......@@ -265,7 +265,7 @@ public interface Schema {
ANTI_FEATURES, REQUIREMENTS, ICON_URL,
FEATURE_GRAPHIC, PROMO_GRAPHIC, TV_BANNER, PHONE_SCREENSHOTS,
SEVEN_INCH_SCREENSHOTS, TEN_INCH_SCREENSHOTS, TV_SCREENSHOTS, WEAR_SCREENSHOTS,
PREFERRED_SIGNER, SUGGESTED_VERSION_CODE, IS_APK, IS_LOCALIZED, SuggestedApk.VERSION_NAME,
PREFERRED_SIGNER, AUTO_INSTALL_VERSION_CODE, IS_APK, IS_LOCALIZED, SuggestedApk.VERSION_NAME,
InstalledApp.VERSION_CODE, InstalledApp.VERSION_NAME,
InstalledApp.SIGNATURE, Package.PACKAGE_NAME,
};
......
......@@ -250,7 +250,7 @@ public class AppDetailsActivity extends AppCompatActivity
MenuItem itemIgnoreThis = menu.findItem(R.id.action_ignore_this);
if (itemIgnoreThis != null) {
itemIgnoreThis.setVisible(app.hasUpdates());
itemIgnoreThis.setChecked(app.getPrefs(this).ignoreThisUpdate >= app.suggestedVersionCode);
itemIgnoreThis.setChecked(app.getPrefs(this).ignoreThisUpdate >= app.autoInstallVersionCode);
}
return true;
}
......@@ -274,10 +274,10 @@ public class AppDetailsActivity extends AppCompatActivity
AppPrefsProvider.Helper.update(this, app, app.getPrefs(this));
return true;
} else if (item.getItemId() == R.id.action_ignore_this) {
if (app.getPrefs(this).ignoreThisUpdate >= app.suggestedVersionCode) {
if (app.getPrefs(this).ignoreThisUpdate >= app.autoInstallVersionCode) {
app.getPrefs(this).ignoreThisUpdate = 0;
} else {
app.getPrefs(this).ignoreThisUpdate = app.suggestedVersionCode;
app.getPrefs(this).ignoreThisUpdate = app.autoInstallVersionCode;
}
item.setChecked(app.getPrefs(this).ignoreThisUpdate > 0);
AppPrefsProvider.Helper.update(this, app, app.getPrefs(this));
......
......@@ -239,7 +239,7 @@ public class AppDetailsRecyclerViewAdapter
String appropriateSig = app.getMostAppropriateSignature();
for (int i = 0; i < versions.size(); i++) {
final Apk apk = versions.get(i);
if (apk.versionCode == app.suggestedVersionCode && TextUtils.equals(apk.sig, appropriateSig)) {
if (apk.versionCode == app.autoInstallVersionCode && TextUtils.equals(apk.sig, appropriateSig)) {
curApk = apk;
break;
}
......@@ -1104,7 +1104,7 @@ public class AppDetailsRecyclerViewAdapter
boolean isAppInstalled = app.isInstalled(context);
boolean isApkInstalled = apk.versionCode == app.installedVersionCode &&
TextUtils.equals(apk.sig, app.installedSig);
boolean isApkSuggested = apk.versionCode == app.suggestedVersionCode &&
boolean isApkSuggested = apk.versionCode == app.autoInstallVersionCode &&
TextUtils.equals(apk.sig, app.getMostAppropriateSignature());
boolean isApkDownloading = callbacks.isAppDownloading() && downloadedApk != null &&
downloadedApk.compareTo(apk) == 0 && TextUtils.equals(apk.apkName, downloadedApk.apkName);
......
......@@ -35,7 +35,7 @@ public class InstalledAppListItemController extends AppListItemController {
* Either "Version X" or "Version Y (Recommended)", depending on the installed version.
*/
private CharSequence getInstalledVersion(@NonNull App app) {
int statusStringRes = (app.suggestedVersionCode == app.installedVersionCode)
int statusStringRes = (app.autoInstallVersionCode == app.installedVersionCode)
? R.string.app_recommended_version_installed
: R.string.app_version_x_installed;
......@@ -51,7 +51,7 @@ public class InstalledAppListItemController extends AppListItemController {
AppPrefs prefs = app.getPrefs(activity);
if (prefs.ignoreAllUpdates) {
return activity.getString(R.string.installed_app__updates_ignored);
} else if (prefs.ignoreThisUpdate > 0 && prefs.ignoreThisUpdate == app.suggestedVersionCode) {
} else if (prefs.ignoreThisUpdate > 0 && prefs.ignoreThisUpdate == app.autoInstallVersionCode) {
return activity.getString(
R.string.installed_app__updates_ignored_for_suggested_version,
app.getSuggestedVersionName());
......
......@@ -42,7 +42,7 @@ public class UpdateableAppListItemController extends AppListItemController {
@Override
protected void onDismissApp(@NonNull final App app, UpdatesAdapter adapter) {
final AppPrefs prefs = app.getPrefs(activity);
prefs.ignoreThisUpdate = app.suggestedVersionCode;
prefs.ignoreThisUpdate = app.autoInstallVersionCode;
Snackbar.make(
itemView,
......
......@@ -273,7 +273,7 @@ public class PreferredSignatureTest extends FDroidProviderTest {
private void assertSuggested(Context context, int suggestedVersion, String suggestedSig) {
App suggestedApp = AppProvider.Helper.findHighestPriorityMetadata(context.getContentResolver(), PACKAGE_NAME);
assertEquals("Suggested version on App", suggestedVersion, suggestedApp.suggestedVersionCode);
assertEquals("Suggested version on App", suggestedVersion, suggestedApp.autoInstallVersionCode);
Apk suggestedApk = ApkProvider.Helper.findSuggestedApk(context, suggestedApp);
assertEquals("Version on suggested Apk", suggestedVersion, suggestedApk.versionCode);
......
......@@ -195,7 +195,7 @@ public class SuggestedVersionTest extends FDroidProviderTest {
*/
public void assertSuggested(String packageName, int suggestedVersion, String installedSig, int installedVersion) {
App suggestedApp = AppProvider.Helper.findHighestPriorityMetadata(context.getContentResolver(), packageName);
assertEquals("Suggested version on App", suggestedVersion, suggestedApp.suggestedVersionCode);
assertEquals("Suggested version on App", suggestedVersion, suggestedApp.autoInstallVersionCode);
assertEquals("Installed signature on App", installedSig, suggestedApp.installedSig);
Apk suggestedApk = ApkProvider.Helper.findSuggestedApk(context, suggestedApp);
......@@ -212,7 +212,7 @@ public class SuggestedVersionTest extends FDroidProviderTest {
App canUpdateApp = appsToUpdate.get(0);
assertEquals("Package name of updatable app", packageName, canUpdateApp.packageName);
assertEquals("Installed version of updatable app", installedVersion, canUpdateApp.installedVersionCode);
assertEquals("Suggested version to update to", suggestedVersion, canUpdateApp.suggestedVersionCode);
assertEquals("Suggested version to update to", suggestedVersion, canUpdateApp.autoInstallVersionCode);
assertEquals("Installed signature of updatable app", installedSig, canUpdateApp.installedSig);
}
}
......
......@@ -303,6 +303,7 @@ public class IndexV1UpdaterTest extends FDroidProviderTest {
"antiFeatures",
"authorEmail",
"authorName",
"autoInstallVersionCode",
"bitcoin",
"categories",
"changelog",
......@@ -333,11 +334,10 @@ public class IndexV1UpdaterTest extends FDroidProviderTest {
"tvBanner",
"tvScreenshots",
"upstreamVersionCode",
"upstreamVersionName",
"video",
"whatsNew",
"wearScreenshots",
"webSite",
"whatsNew",
};
String[] ignoredInApp = new String[]{
"compatible",
......
......@@ -252,7 +252,7 @@ public class ProperMultiIndexUpdaterTest extends MultiIndexUpdaterTest {
List<App> appsToUpdate = AppProvider.Helper.findCanUpdate(context, AppMetadataTable.Cols.ALL);
assertEquals(1, appsToUpdate.size());
assertEquals(installedVersion, appsToUpdate.get(0).installedVersionCode);
assertEquals(expectedUpdateVersion, appsToUpdate.get(0).suggestedVersionCode);
assertEquals(expectedUpdateVersion, appsToUpdate.get(0).autoInstallVersionCode);
}
private void assertMainRepo() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment