From 2d27ba40862096a15aaad63fa3a8f2419eb34ece Mon Sep 17 00:00:00 2001 From: mvp76 Date: Tue, 21 Mar 2017 16:55:39 +0100 Subject: [PATCH] Display anti-features Issue #878. --- .../views/AppDetailsRecyclerViewAdapter.java | 59 ++++++++++++++++++- .../res/drawable/ic_warning_black_24dp.xml | 9 +++ .../main/res/layout/app_details2_header.xml | 32 ++++++++++ app/src/main/res/values/strings.xml | 2 + app/src/main/res/values/styles_detail.xml | 4 ++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/ic_warning_black_24dp.xml 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 5f750a61c..a9b6ce80c 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java +++ b/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java @@ -294,6 +294,9 @@ public class AppDetailsRecyclerViewAdapter final TextView lastUpdateView; final TextView descriptionView; final TextView descriptionMoreView; + final TextView antiFeaturesLabelView; + final TextView antiFeaturesView; + final View antiFeaturesWarningView; final View buttonLayout; final Button buttonPrimaryView; final Button buttonSecondaryView; @@ -303,6 +306,7 @@ public class AppDetailsRecyclerViewAdapter final TextView progressPercent; final View progressCancel; final DisplayImageOptions displayImageOptions; + boolean descriptionIsExpanded; HeaderViewHolder(View view) { super(view); @@ -312,6 +316,9 @@ public class AppDetailsRecyclerViewAdapter lastUpdateView = (TextView) view.findViewById(R.id.text_last_update); descriptionView = (TextView) view.findViewById(R.id.description); descriptionMoreView = (TextView) view.findViewById(R.id.description_more); + antiFeaturesLabelView = (TextView) view.findViewById(R.id.label_anti_features); + antiFeaturesView = (TextView) view.findViewById(R.id.text_anti_features); + antiFeaturesWarningView = view.findViewById(R.id.anti_features_warning); buttonLayout = view.findViewById(R.id.button_layout); buttonPrimaryView = (Button) view.findViewById(R.id.primaryButtonView); buttonSecondaryView = (Button) view.findViewById(R.id.secondaryButtonView); @@ -341,10 +348,13 @@ public class AppDetailsRecyclerViewAdapter if (TextViewCompat.getMaxLines(descriptionView) != MAX_LINES) { descriptionView.setMaxLines(MAX_LINES); descriptionMoreView.setText(R.string.more); + descriptionIsExpanded = false; } else { descriptionView.setMaxLines(Integer.MAX_VALUE); descriptionMoreView.setText(R.string.less); + descriptionIsExpanded = true; } + updateAntiFeaturesWarning(); } }); // Set ALL caps (in a way compatible with SDK 10) @@ -421,13 +431,27 @@ public class AppDetailsRecyclerViewAdapter descriptionView.post(new Runnable() { @Override public void run() { - if (descriptionView.getLineCount() <= HeaderViewHolder.MAX_LINES) { + if (descriptionView.getLineCount() <= HeaderViewHolder.MAX_LINES && app.antiFeatures == null) { descriptionMoreView.setVisibility(View.GONE); } else { descriptionMoreView.setVisibility(View.VISIBLE); } } }); + if (app.antiFeatures != null) { + StringBuilder sb = new StringBuilder(); + for (String af : app.antiFeatures) { + String afdesc = descAntiFeature(af); + sb.append("\t• ").append(afdesc).append('\n'); + } + if (sb.length() > 0) { + sb.setLength(sb.length() - 1); + antiFeaturesView.setText(sb.toString()); + } else { + antiFeaturesView.setVisibility(View.GONE); + } + } + updateAntiFeaturesWarning(); buttonSecondaryView.setText(R.string.menu_uninstall); buttonSecondaryView.setVisibility(app.isInstalled() ? View.VISIBLE : View.INVISIBLE); buttonSecondaryView.setOnClickListener(onUnInstallClickListener); @@ -473,6 +497,39 @@ public class AppDetailsRecyclerViewAdapter }); } + + private void updateAntiFeaturesWarning() { + if (app.antiFeatures == null || TextUtils.isEmpty(antiFeaturesView.getText())) { + antiFeaturesLabelView.setVisibility(View.GONE); + antiFeaturesView.setVisibility(View.GONE); + antiFeaturesWarningView.setVisibility(View.GONE); + } else { + antiFeaturesLabelView.setVisibility(descriptionIsExpanded ? View.VISIBLE : View.GONE); + antiFeaturesView.setVisibility(descriptionIsExpanded ? View.VISIBLE : View.GONE); + antiFeaturesWarningView.setVisibility(descriptionIsExpanded ? View.GONE : View.VISIBLE); + } + } + + private String descAntiFeature(String af) { + switch (af) { + case "Ads": + return itemView.getContext().getString(R.string.antiadslist); + case "Tracking": + return itemView.getContext().getString(R.string.antitracklist); + case "NonFreeNet": + return itemView.getContext().getString(R.string.antinonfreenetlist); + case "NonFreeAdd": + return itemView.getContext().getString(R.string.antinonfreeadlist); + case "NonFreeDep": + return itemView.getContext().getString(R.string.antinonfreedeplist); + case "UpstreamNonFree": + return itemView.getContext().getString(R.string.antiupstreamnonfreelist); + case "NonFreeAssets": + return itemView.getContext().getString(R.string.antinonfreeassetslist); + default: + return af; + } + } } @Override diff --git a/app/src/main/res/drawable/ic_warning_black_24dp.xml b/app/src/main/res/drawable/ic_warning_black_24dp.xml new file mode 100644 index 000000000..b3a9e036b --- /dev/null +++ b/app/src/main/res/drawable/ic_warning_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/app_details2_header.xml b/app/src/main/res/layout/app_details2_header.xml index 5b8360680..c14ea082c 100755 --- a/app/src/main/res/layout/app_details2_header.xml +++ b/app/src/main/res/layout/app_details2_header.xml @@ -165,6 +165,26 @@ android:textAppearance="@style/TextAppearance.AppCompat.Body1" tools:text="This is the app description of this awezome app. It can be several lines long, but will be truncated at just a few if it is. A 'read more' button will appear so that you can expand the view and view the full text, if you wish. Yes, it will be blue and beautiful." /> + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8a433336a..ed72fb596 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -170,6 +170,8 @@ Version %s installed Not installed + This app has features you may not like. + Anti-features This app contains advertising This app tracks and reports your activity This app promotes non-free add-ons diff --git a/app/src/main/res/values/styles_detail.xml b/app/src/main/res/values/styles_detail.xml index 7bca4da09..2a6b07c86 100644 --- a/app/src/main/res/values/styles_detail.xml +++ b/app/src/main/res/values/styles_detail.xml @@ -41,4 +41,8 @@ + + \ No newline at end of file