From 622a1245dc74553d482950e3b54cc3cad7b1c947 Mon Sep 17 00:00:00 2001 From: mvp76 Date: Tue, 21 Mar 2017 17:55:49 +0100 Subject: [PATCH] Move "what's new" from its own section to the header section Also, add some styling and placeholder text (randomly set or not set) --- .../main/java/org/fdroid/fdroid/data/Apk.java | 13 +++++ .../views/AppDetailsRecyclerViewAdapter.java | 54 +++++++++---------- .../main/res/layout/app_details2_header.xml | 32 ++++++++++- .../main/res/layout/app_details2_whatsnew.xml | 8 --- app/src/main/res/values/strings.xml | 1 + 5 files changed, 70 insertions(+), 38 deletions(-) delete mode 100755 app/src/main/res/layout/app_details2_whatsnew.xml diff --git a/app/src/main/java/org/fdroid/fdroid/data/Apk.java b/app/src/main/java/org/fdroid/fdroid/data/Apk.java index d1f75ff89..e08078756 100644 --- a/app/src/main/java/org/fdroid/fdroid/data/Apk.java +++ b/app/src/main/java/org/fdroid/fdroid/data/Apk.java @@ -9,6 +9,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.NonNull; +import org.fdroid.fdroid.BuildConfig; import org.fdroid.fdroid.RepoXMLHandler; import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.data.Schema.ApkTable.Cols; @@ -74,6 +75,11 @@ public class Apk extends ValueObject implements Comparable, Parcelable { public String repoAddress; public String[] incompatibleReasons; + /** + * A descriptive text for what has changed in the latest version. + */ + public String whatsNew; + public String[] antiFeatures; /** @@ -211,6 +217,13 @@ public class Apk extends ValueObject implements Comparable, Parcelable { break; } } + + // For now, just populate "what's new" with placeholder (or leave blank) + if (BuildConfig.DEBUG) { + if (Math.random() > 0.5) { + whatsNew = "This section will contain the 'what's new' information for the apk.\n\n\t• Bug fixes."; + } + } } private void checkRepoAddress() { 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 a9b6ce80c..3fb2e1a9c 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java +++ b/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java @@ -52,6 +52,7 @@ import java.text.NumberFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.List; +import java.util.Locale; import java.util.concurrent.TimeUnit; public class AppDetailsRecyclerViewAdapter @@ -83,12 +84,11 @@ public class AppDetailsRecyclerViewAdapter private static final int VIEWTYPE_HEADER = 0; private static final int VIEWTYPE_SCREENSHOTS = 1; - private static final int VIEWTYPE_WHATS_NEW = 2; - private static final int VIEWTYPE_DONATE = 3; - private static final int VIEWTYPE_LINKS = 4; - private static final int VIEWTYPE_PERMISSIONS = 5; - private static final int VIEWTYPE_VERSIONS = 6; - private static final int VIEWTYPE_VERSION = 7; + private static final int VIEWTYPE_DONATE = 2; + private static final int VIEWTYPE_LINKS = 3; + private static final int VIEWTYPE_PERMISSIONS = 4; + private static final int VIEWTYPE_VERSIONS = 5; + private static final int VIEWTYPE_VERSION = 6; private final Context context; @NonNull @@ -127,7 +127,6 @@ public class AppDetailsRecyclerViewAdapter } addItem(VIEWTYPE_HEADER); addItem(VIEWTYPE_SCREENSHOTS); - addItem(VIEWTYPE_WHATS_NEW); addItem(VIEWTYPE_DONATE); addItem(VIEWTYPE_LINKS); addItem(VIEWTYPE_PERMISSIONS); @@ -169,6 +168,12 @@ public class AppDetailsRecyclerViewAdapter private boolean shouldShowPermissions() { // Figure out if we should show permissions section + Apk curApk = getSuggestedApk(); + final boolean curApkCompatible = curApk != null && curApk.compatible; + return versions.size() > 0 && (curApkCompatible || Preferences.get().showIncompatibleVersions()); + } + + private Apk getSuggestedApk() { Apk curApk = null; for (int i = 0; i < versions.size(); i++) { final Apk apk = versions.get(i); @@ -177,8 +182,7 @@ public class AppDetailsRecyclerViewAdapter break; } } - final boolean curApkCompatible = curApk != null && curApk.compatible; - return versions.size() > 0 && (curApkCompatible || Preferences.get().showIncompatibleVersions()); + return curApk; } private boolean shouldShowDonate() { @@ -208,9 +212,6 @@ public class AppDetailsRecyclerViewAdapter case VIEWTYPE_SCREENSHOTS: View screenshots = inflater.inflate(R.layout.app_details2_screenshots, parent, false); return new ScreenShotsViewHolder(screenshots); - case VIEWTYPE_WHATS_NEW: - View whatsNew = inflater.inflate(R.layout.app_details2_whatsnew, parent, false); - return new WhatsNewViewHolder(whatsNew); case VIEWTYPE_DONATE: View donate = inflater.inflate(R.layout.app_details2_donate, parent, false); return new DonateViewHolder(donate); @@ -242,9 +243,6 @@ public class AppDetailsRecyclerViewAdapter case VIEWTYPE_SCREENSHOTS: ((ScreenShotsViewHolder) holder).bindModel(); break; - case VIEWTYPE_WHATS_NEW: - ((WhatsNewViewHolder) holder).bindModel(); - break; case VIEWTYPE_DONATE: ((DonateViewHolder) holder).bindModel(); break; @@ -292,6 +290,7 @@ public class AppDetailsRecyclerViewAdapter final TextView titleView; final TextView authorView; final TextView lastUpdateView; + final TextView whatsNewView; final TextView descriptionView; final TextView descriptionMoreView; final TextView antiFeaturesLabelView; @@ -314,6 +313,7 @@ public class AppDetailsRecyclerViewAdapter titleView = (TextView) view.findViewById(R.id.title); authorView = (TextView) view.findViewById(R.id.author); lastUpdateView = (TextView) view.findViewById(R.id.text_last_update); + whatsNewView = (TextView) view.findViewById(R.id.whats_new); descriptionView = (TextView) view.findViewById(R.id.description); descriptionMoreView = (TextView) view.findViewById(R.id.description_more); antiFeaturesLabelView = (TextView) view.findViewById(R.id.label_anti_features); @@ -412,6 +412,17 @@ public class AppDetailsRecyclerViewAdapter } else { lastUpdateView.setVisibility(View.GONE); } + Apk suggestedApk = getSuggestedApk(); + if (suggestedApk == null || TextUtils.isEmpty(suggestedApk.whatsNew)) { + whatsNewView.setVisibility(View.GONE); + } else { + StringBuilder sbWhatsNew = new StringBuilder(); + sbWhatsNew.append(whatsNewView.getContext().getString(R.string.details_new_in_version, suggestedApk.versionName).toUpperCase(Locale.getDefault())); + sbWhatsNew.append("\n\n"); + sbWhatsNew.append(suggestedApk.whatsNew); + whatsNewView.setText(sbWhatsNew); + whatsNewView.setVisibility(View.VISIBLE); + } final Spanned desc = Html.fromHtml(app.description, null, new Utils.HtmlTagHandler()); descriptionView.setMovementMethod(LinkMovementMethod.getInstance()); descriptionView.setText(trimTrailingNewlines(desc)); @@ -569,19 +580,6 @@ public class AppDetailsRecyclerViewAdapter } } - private class WhatsNewViewHolder extends RecyclerView.ViewHolder { - final TextView textView; - - WhatsNewViewHolder(View view) { - super(view); - textView = (TextView) view.findViewById(R.id.text); - } - - public void bindModel() { - textView.setText("WHATS NEW GOES HERE"); - } - } - private class DonateViewHolder extends RecyclerView.ViewHolder { final TextView donateHeading; final GridLayout donationOptionsLayout; diff --git a/app/src/main/res/layout/app_details2_header.xml b/app/src/main/res/layout/app_details2_header.xml index c14ea082c..afe1dfdb2 100755 --- a/app/src/main/res/layout/app_details2_header.xml +++ b/app/src/main/res/layout/app_details2_header.xml @@ -13,12 +13,15 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:padding="8dp"> + android:paddingBottom="8dp" + > + + @@ -190,6 +214,8 @@ style="@style/DetailsMoreButtonStyle" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:layout_marginEnd="8dp" android:gravity="right|end" android:text="@string/more" android:textAppearance="@style/TextAppearance.AppCompat.Body1" @@ -200,6 +226,8 @@ style="@style/DetailsAntiFeaturesWarningStyle" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:layout_marginEnd="8dp" android:textAppearance="@style/TextAppearance.AppCompat.Body1" android:drawableStart="@drawable/ic_warning_black_24dp" android:drawableLeft="@drawable/ic_warning_black_24dp" diff --git a/app/src/main/res/layout/app_details2_whatsnew.xml b/app/src/main/res/layout/app_details2_whatsnew.xml deleted file mode 100755 index 3498f984e..000000000 --- a/app/src/main/res/layout/app_details2_whatsnew.xml +++ /dev/null @@ -1,8 +0,0 @@ - - \ 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 ed72fb596..8867b0f75 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -169,6 +169,7 @@ Version %s installed Not installed + New in version %s This app has features you may not like. Anti-features