From 10e2bf2a7c19b3d306f7cea0bd2876bf3ac13d6c Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Wed, 14 Feb 2018 22:48:00 +0100 Subject: [PATCH] add liberapay field and donation option This add the liberapayID index field to the local db and then displays a donation badge for apps that provide this. --- .../org/fdroid/fdroid/RepoXMLHandler.java | 3 + .../main/java/org/fdroid/fdroid/data/App.java | 14 ++++ .../java/org/fdroid/fdroid/data/DBHelper.java | 17 ++++- .../java/org/fdroid/fdroid/data/Schema.java | 5 +- .../views/AppDetailsRecyclerViewAdapter.java | 7 +- .../drawable/donation_option_liberapay.xml | 76 +++++++++++++++++++ app/src/main/res/layout/donate_liberapay.xml | 11 +++ app/src/main/res/values/strings.xml | 1 + .../fdroid/updater/IndexV1UpdaterTest.java | 1 + 9 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/drawable/donation_option_liberapay.xml create mode 100644 app/src/main/res/layout/donate_liberapay.xml diff --git a/app/src/main/java/org/fdroid/fdroid/RepoXMLHandler.java b/app/src/main/java/org/fdroid/fdroid/RepoXMLHandler.java index 0e3ac2e8b..a087e6909 100644 --- a/app/src/main/java/org/fdroid/fdroid/RepoXMLHandler.java +++ b/app/src/main/java/org/fdroid/fdroid/RepoXMLHandler.java @@ -235,6 +235,9 @@ public class RepoXMLHandler extends DefaultHandler { case "flattr": curapp.flattrID = str; break; + case "liberapay": + curapp.liberapayID = str; + break; case "web": curapp.webSite = str; break; diff --git a/app/src/main/java/org/fdroid/fdroid/data/App.java b/app/src/main/java/org/fdroid/fdroid/data/App.java index 9bfd051c4..525eb8be3 100644 --- a/app/src/main/java/org/fdroid/fdroid/data/App.java +++ b/app/src/main/java/org/fdroid/fdroid/data/App.java @@ -157,6 +157,8 @@ public class App extends ValueObject implements Comparable, Parcelable { public String flattrID; + public String liberapayID; + public String upstreamVersionName; /** @@ -292,6 +294,9 @@ public class App extends ValueObject implements Comparable, Parcelable { case Cols.FLATTR_ID: flattrID = cursor.getString(i); break; + case Cols.LIBERAPAY_ID: + liberapayID = cursor.getString(i); + break; case Cols.SuggestedApk.VERSION_NAME: suggestedVersionName = cursor.getString(i); break; @@ -919,6 +924,7 @@ public class App extends ValueObject implements Comparable, Parcelable { values.put(Cols.BITCOIN, bitcoin); values.put(Cols.LITECOIN, litecoin); values.put(Cols.FLATTR_ID, flattrID); + values.put(Cols.LIBERAPAY_ID, liberapayID); values.put(Cols.ADDED, Utils.formatDate(added, "")); values.put(Cols.LAST_UPDATED, Utils.formatDate(lastUpdated, "")); values.put(Cols.PREFERRED_SIGNER, preferredSigner); @@ -1034,6 +1040,12 @@ public class App extends ValueObject implements Comparable, Parcelable { return TextUtils.isEmpty(flattrID) ? null : "https://flattr.com/thing/" + flattrID; } + @Nullable + public String getLiberapayUri() { + return TextUtils.isEmpty(liberapayID) ? null : "https://liberapay.com/~" + liberapayID; + } + + /** * @see App#suggestedVersionName for why this uses a getter while other member variables are * publicly accessible. @@ -1134,6 +1146,7 @@ public class App extends ValueObject implements Comparable, Parcelable { dest.writeString(this.bitcoin); dest.writeString(this.litecoin); dest.writeString(this.flattrID); + dest.writeString(this.liberapayID); dest.writeString(this.preferredSigner); dest.writeString(this.upstreamVersionName); dest.writeInt(this.upstreamVersionCode); @@ -1183,6 +1196,7 @@ public class App extends ValueObject implements Comparable, Parcelable { this.bitcoin = in.readString(); this.litecoin = in.readString(); this.flattrID = in.readString(); + this.liberapayID = in.readString(); this.preferredSigner = in.readString(); this.upstreamVersionName = in.readString(); this.upstreamVersionCode = in.readInt(); diff --git a/app/src/main/java/org/fdroid/fdroid/data/DBHelper.java b/app/src/main/java/org/fdroid/fdroid/data/DBHelper.java index d4c671167..cbcefff4c 100644 --- a/app/src/main/java/org/fdroid/fdroid/data/DBHelper.java +++ b/app/src/main/java/org/fdroid/fdroid/data/DBHelper.java @@ -144,6 +144,7 @@ public class DBHelper extends SQLiteOpenHelper { + AppMetadataTable.Cols.BITCOIN + " string," + AppMetadataTable.Cols.LITECOIN + " string," + AppMetadataTable.Cols.FLATTR_ID + " string," + + AppMetadataTable.Cols.LIBERAPAY_ID + " string," + AppMetadataTable.Cols.REQUIREMENTS + " string," + AppMetadataTable.Cols.ADDED + " string," + AppMetadataTable.Cols.LAST_UPDATED + " string," @@ -214,7 +215,7 @@ public class DBHelper extends SQLiteOpenHelper { + "primary key(" + ApkAntiFeatureJoinTable.Cols.APK_ID + ", " + ApkAntiFeatureJoinTable.Cols.ANTI_FEATURE_ID + ") " + " );"; - protected static final int DB_VERSION = 76; + protected static final int DB_VERSION = 77; private final Context context; @@ -322,6 +323,20 @@ public class DBHelper extends SQLiteOpenHelper { addIsAppToApp(db, oldVersion); addApkAntiFeatures(db, oldVersion); addIgnoreVulnPref(db, oldVersion); + addLiberapayID(db, oldVersion); + } + + private void addLiberapayID(SQLiteDatabase db, int oldVersion) { + if (oldVersion >= 77) { + return; + } + + if (!columnExists(db, AppMetadataTable.NAME, AppMetadataTable.Cols.LIBERAPAY_ID)) { + Utils.debugLog(TAG, "Adding " + AppMetadataTable.Cols.LIBERAPAY_ID + " field to " + + AppMetadataTable.NAME + " table in db."); + db.execSQL("alter table " + AppMetadataTable.NAME + " add column " + + AppMetadataTable.Cols.LIBERAPAY_ID + " string;"); + } } private void addIgnoreVulnPref(SQLiteDatabase db, int oldVersion) { diff --git a/app/src/main/java/org/fdroid/fdroid/data/Schema.java b/app/src/main/java/org/fdroid/fdroid/data/Schema.java index a1f3ac2ad..f308ea6f3 100644 --- a/app/src/main/java/org/fdroid/fdroid/data/Schema.java +++ b/app/src/main/java/org/fdroid/fdroid/data/Schema.java @@ -180,6 +180,7 @@ public interface Schema { String BITCOIN = "bitcoinAddr"; String LITECOIN = "litecoinAddr"; String FLATTR_ID = "flattrID"; + String LIBERAPAY_ID = "liberapayID"; String PREFERRED_SIGNER = "preferredSigner"; String SUGGESTED_VERSION_CODE = "suggestedVercode"; String UPSTREAM_VERSION_NAME = "upstreamVersion"; @@ -233,7 +234,7 @@ public interface Schema { String[] ALL_COLS = { ROW_ID, PACKAGE_ID, REPO_ID, IS_COMPATIBLE, NAME, SUMMARY, ICON, DESCRIPTION, WHATSNEW, LICENSE, AUTHOR_NAME, AUTHOR_EMAIL, WEBSITE, ISSUE_TRACKER, SOURCE_CODE, - VIDEO, CHANGELOG, DONATE, BITCOIN, LITECOIN, FLATTR_ID, + VIDEO, CHANGELOG, DONATE, BITCOIN, LITECOIN, FLATTR_ID, LIBERAPAY_ID, UPSTREAM_VERSION_NAME, UPSTREAM_VERSION_CODE, ADDED, LAST_UPDATED, ANTI_FEATURES, REQUIREMENTS, ICON_URL, ICON_URL_LARGE, FEATURE_GRAPHIC, PROMO_GRAPHIC, TV_BANNER, PHONE_SCREENSHOTS, @@ -249,7 +250,7 @@ public interface Schema { String[] ALL = { _ID, ROW_ID, REPO_ID, IS_COMPATIBLE, NAME, SUMMARY, ICON, DESCRIPTION, WHATSNEW, LICENSE, AUTHOR_NAME, AUTHOR_EMAIL, WEBSITE, ISSUE_TRACKER, SOURCE_CODE, - VIDEO, CHANGELOG, DONATE, BITCOIN, LITECOIN, FLATTR_ID, + VIDEO, CHANGELOG, DONATE, BITCOIN, LITECOIN, FLATTR_ID, LIBERAPAY_ID, UPSTREAM_VERSION_NAME, UPSTREAM_VERSION_CODE, ADDED, LAST_UPDATED, ANTI_FEATURES, REQUIREMENTS, ICON_URL, ICON_URL_LARGE, FEATURE_GRAPHIC, PROMO_GRAPHIC, TV_BANNER, PHONE_SCREENSHOTS, diff --git a/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java b/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java index d8299365a..46539ef38 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java +++ b/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java @@ -202,7 +202,8 @@ public class AppDetailsRecyclerViewAdapter return uriIsSetAndCanBeOpened(app.donate) || uriIsSetAndCanBeOpened(app.getBitcoinUri()) || uriIsSetAndCanBeOpened(app.getLitecoinUri()) || - uriIsSetAndCanBeOpened(app.getFlattrUri()); + uriIsSetAndCanBeOpened(app.getFlattrUri()) || + uriIsSetAndCanBeOpened(app.getLiberapayUri()); } public void clearProgress() { @@ -649,6 +650,10 @@ public class AppDetailsRecyclerViewAdapter if (uriIsSetAndCanBeOpened(app.getFlattrUri())) { addDonateOption(R.layout.donate_flattr, app.getFlattrUri()); } + // LiberaPay + if (uriIsSetAndCanBeOpened(app.getLiberapayUri())) { + addDonateOption(R.layout.donate_liberapay, app.getLiberapayUri()); + } } private void addDonateOption(@LayoutRes int layout, final String uri) { diff --git a/app/src/main/res/drawable/donation_option_liberapay.xml b/app/src/main/res/drawable/donation_option_liberapay.xml new file mode 100644 index 000000000..d9a8bccd9 --- /dev/null +++ b/app/src/main/res/drawable/donation_option_liberapay.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/donate_liberapay.xml b/app/src/main/res/layout/donate_liberapay.xml new file mode 100644 index 000000000..7d483844b --- /dev/null +++ b/app/src/main/res/layout/donate_liberapay.xml @@ -0,0 +1,11 @@ + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e2e838b65..a8838f0a5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -170,6 +170,7 @@ This often occurs with apps installed via Google Play or other sources, if they Bitcoin Litecoin Flattr + Liberapay Latest Categories diff --git a/app/src/test/java/org/fdroid/fdroid/updater/IndexV1UpdaterTest.java b/app/src/test/java/org/fdroid/fdroid/updater/IndexV1UpdaterTest.java index 58f1d7111..4c42c36f8 100644 --- a/app/src/test/java/org/fdroid/fdroid/updater/IndexV1UpdaterTest.java +++ b/app/src/test/java/org/fdroid/fdroid/updater/IndexV1UpdaterTest.java @@ -274,6 +274,7 @@ public class IndexV1UpdaterTest extends FDroidProviderTest { "iconUrlLarge", "issueTracker", "lastUpdated", + "liberapayID", "license", "litecoin", "name",