From d54c138a1dae7102a2541596842a0b9cb761d114 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Wed, 21 Dec 2016 22:14:23 +1100 Subject: [PATCH] Work on the "Donate" styles. Still needs some better assets for the actual donate buttons, but now it includes the relevant text about donating to developers. It also puts the donation options in a grid layout and lets them flow across so that if there is more than three, they will end up on the second line. --- app/build.gradle | 2 + .../views/AppDetailsRecyclerViewAdapter.java | 39 ++++++++--- .../res/drawable/donation_option_bitcoin.xml | 33 ++++++++++ .../res/drawable/donation_option_flattr.xml | 9 +++ .../res/drawable/donation_option_litecoin.xml | 64 +++++++++++++++++++ .../main/res/layout/app_details2_donate.xml | 27 +++++--- .../main/res/layout/app_details_summary.xml | 8 +-- app/src/main/res/layout/donate_bitcoin.xml | 11 ++++ app/src/main/res/layout/donate_flattr.xml | 11 ++++ app/src/main/res/layout/donate_generic.xml | 10 +++ app/src/main/res/layout/donate_litecoin.xml | 7 ++ app/src/main/res/values/strings.xml | 3 + 12 files changed, 202 insertions(+), 22 deletions(-) create mode 100644 app/src/main/res/drawable/donation_option_bitcoin.xml create mode 100644 app/src/main/res/drawable/donation_option_flattr.xml create mode 100644 app/src/main/res/drawable/donation_option_litecoin.xml create mode 100644 app/src/main/res/layout/donate_bitcoin.xml create mode 100644 app/src/main/res/layout/donate_flattr.xml create mode 100644 app/src/main/res/layout/donate_generic.xml create mode 100644 app/src/main/res/layout/donate_litecoin.xml diff --git a/app/build.gradle b/app/build.gradle index 1af92e952..68be1b837 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,6 +20,7 @@ repositories { dependencies { compile 'com.android.support:support-v4:24.2.1' compile 'com.android.support:appcompat-v7:24.2.1' + compile 'com.android.support:gridlayout-v7:24.2.1' compile 'com.android.support:support-annotations:24.2.1' compile 'com.android.support:design:24.2.1' compile 'com.android.support:cardview-v7:24.2.1' @@ -105,6 +106,7 @@ if (!hasProperty('sourceDeps')) { 'com.android.support:support-vector-drawable:6ee37a7f7b93c1df1294e6f6f97df3724ac989fcda0549faf677001085330548', 'com.android.support:design:89842bb1243507fe3079066ea4ea58795effe69cdf9a819e05274d21760adfc2', 'com.android.support:cardview-v7:2303b351686d1db060b5fcf1a9c709c79b4a54a85bfda0fb3c4849e244606ee1', + 'com.android.support:gridlayout-v7:1a31c248d69faa815cc155883ddcb0ccc7ba8e14e69ec58dd18d8017e23d76f5', 'com.android.support:recyclerview-v7:9077766a1a0f4e89528fbf9dcdf6d5880a8686f0266fa852d58d803beeef18fa', 'com.google.zxing:core:b4d82452e7a6bf6ec2698904b332431717ed8f9a850224f295aec89de80f2259', 'com.madgag.spongycastle:core:9b6b7ac856b91bcda2ede694eccd26cefb0bf0b09b89f13cda05b5da5ff68c6b', 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 a14b8602d..19c49418e 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java +++ b/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java @@ -6,10 +6,12 @@ import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.net.Uri; +import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; import android.support.v4.view.ViewCompat; import android.support.v4.widget.TextViewCompat; import android.support.v7.text.AllCapsTransformationMethod; +import android.support.v7.widget.GridLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.Html; @@ -503,38 +505,57 @@ public class AppDetailsRecyclerViewAdapter } private class DonateViewHolder extends RecyclerView.ViewHolder { - final TextView textView; - final LinearLayout contentView; + final TextView donateHeading; + final GridLayout donationOptionsLayout; DonateViewHolder(View view) { super(view); - textView = (TextView) view.findViewById(R.id.information); - contentView = (LinearLayout) view.findViewById(R.id.ll_information); + donateHeading = (TextView) view.findViewById(R.id.donate_header); + donationOptionsLayout = (GridLayout) view.findViewById(R.id.donation_options); } public void bindModel() { - contentView.removeAllViews(); + if (TextUtils.isEmpty(app.author)) { + donateHeading.setText(context.getString(R.string.app_details_donate_prompt_unknown_author, app.name)); + } else { + String author = "" + app.author + ""; + donateHeading.setText(Html.fromHtml(context.getString(R.string.app_details_donate_prompt, app.name, author))); + } + + donationOptionsLayout.removeAllViews(); // Donate button if (uriIsSetAndCanBeOpened(app.donateURL)) { - addLinkItemView(contentView, R.string.menu_donate, R.drawable.ic_donate, app.donateURL); + addDonateOption(R.layout.donate_generic, app.donateURL); } // Bitcoin if (uriIsSetAndCanBeOpened(app.getBitcoinUri())) { - addLinkItemView(contentView, R.string.menu_bitcoin, R.drawable.ic_bitcoin, app.getBitcoinUri()); + addDonateOption(R.layout.donate_bitcoin, app.getBitcoinUri()); } // Litecoin if (uriIsSetAndCanBeOpened(app.getLitecoinUri())) { - addLinkItemView(contentView, R.string.menu_litecoin, R.drawable.ic_litecoin, app.getLitecoinUri()); + addDonateOption(R.layout.donate_litecoin, app.getLitecoinUri()); } // Flattr if (uriIsSetAndCanBeOpened(app.getFlattrUri())) { - addLinkItemView(contentView, R.string.menu_flattr, R.drawable.ic_flattr, app.getFlattrUri()); + addDonateOption(R.layout.donate_flattr, app.getFlattrUri()); } } + + private void addDonateOption(@LayoutRes int layout, final String uri) { + LayoutInflater inflater = LayoutInflater.from(context); + View option = inflater.inflate(layout, donationOptionsLayout, false); + option.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + onLinkClicked(uri); + } + }); + donationOptionsLayout.addView(option); + } } private abstract class ExpandableLinearLayoutViewHolder extends RecyclerView.ViewHolder { diff --git a/app/src/main/res/drawable/donation_option_bitcoin.xml b/app/src/main/res/drawable/donation_option_bitcoin.xml new file mode 100644 index 000000000..a4a1aa5ff --- /dev/null +++ b/app/src/main/res/drawable/donation_option_bitcoin.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/donation_option_flattr.xml b/app/src/main/res/drawable/donation_option_flattr.xml new file mode 100644 index 000000000..8fad0face --- /dev/null +++ b/app/src/main/res/drawable/donation_option_flattr.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/app/src/main/res/drawable/donation_option_litecoin.xml b/app/src/main/res/drawable/donation_option_litecoin.xml new file mode 100644 index 000000000..6a7be5275 --- /dev/null +++ b/app/src/main/res/drawable/donation_option_litecoin.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/app_details2_donate.xml b/app/src/main/res/layout/app_details2_donate.xml index b50d20924..b6d8d5204 100644 --- a/app/src/main/res/layout/app_details2_donate.xml +++ b/app/src/main/res/layout/app_details2_donate.xml @@ -1,19 +1,28 @@ - + android:padding="@dimen/details_activity_padding"> + + android:id="@+id/donate_header" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="15sp" + android:textAlignment="center" + tools:text="F-Droid is created by F-Droid Limited and Contributors. Buy them a coffee!" + android:layout_marginBottom="12dp" /> + + + diff --git a/app/src/main/res/layout/app_details_summary.xml b/app/src/main/res/layout/app_details_summary.xml index 7d4738445..6044c330d 100644 --- a/app/src/main/res/layout/app_details_summary.xml +++ b/app/src/main/res/layout/app_details_summary.xml @@ -184,15 +184,15 @@ Changelog" /> diff --git a/app/src/main/res/layout/donate_bitcoin.xml b/app/src/main/res/layout/donate_bitcoin.xml new file mode 100644 index 000000000..2ba601ee6 --- /dev/null +++ b/app/src/main/res/layout/donate_bitcoin.xml @@ -0,0 +1,11 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/donate_flattr.xml b/app/src/main/res/layout/donate_flattr.xml new file mode 100644 index 000000000..e78df12c6 --- /dev/null +++ b/app/src/main/res/layout/donate_flattr.xml @@ -0,0 +1,11 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/donate_generic.xml b/app/src/main/res/layout/donate_generic.xml new file mode 100644 index 000000000..a683887ef --- /dev/null +++ b/app/src/main/res/layout/donate_generic.xml @@ -0,0 +1,10 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/donate_litecoin.xml b/app/src/main/res/layout/donate_litecoin.xml new file mode 100644 index 000000000..beca15e9f --- /dev/null +++ b/app/src/main/res/layout/donate_litecoin.xml @@ -0,0 +1,7 @@ + + \ 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 c6589d552..988bae209 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -48,6 +48,9 @@ App Details No such app found. + Buy the developers of %1$s a coffee! + %1$s is created by %2$s. Buy them a coffee! + About F-Droid Version Website