From d41b0d330f3fe2525593769ccc4a8293de9bf687 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Wed, 5 Apr 2017 12:37:15 +1000 Subject: [PATCH] Only show "New" next to apps added in the last two weeks. Previously, the definition of "New" was whether or not the added and last updated dates were the same. This made sense, because we only showed apps from the past few weeks (depending on preferences) as new. Now that we show up to 200 apps in the first screen, regardless of age, this check is no longer helpful. --- .../views/categories/AppCardController.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/fdroid/fdroid/views/categories/AppCardController.java b/app/src/main/java/org/fdroid/fdroid/views/categories/AppCardController.java index a979ae3f6..1c327c76c 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/categories/AppCardController.java +++ b/app/src/main/java/org/fdroid/fdroid/views/categories/AppCardController.java @@ -38,6 +38,12 @@ import org.fdroid.fdroid.views.apps.FeatureImage; * + {@link R.id#featured_image} ({@link ImageView}, optional) */ public class AppCardController extends RecyclerView.ViewHolder implements ImageLoadingListener, View.OnClickListener { + + /** + * After this many days, don't consider showing the "New" tag next to an app. + */ + private static final int DAYS_TO_CONSIDER_NEW = 14; + @NonNull private final ImageView icon; @@ -104,7 +110,7 @@ public class AppCardController extends RecyclerView.ViewHolder implements ImageL summary.setText(Utils.formatAppNameAndSummary(app.name, app.summary)); if (newTag != null) { - if (app.added != null && app.lastUpdated != null && app.added.equals(app.lastUpdated)) { + if (isConsideredNew(app)) { newTag.setVisibility(View.VISIBLE); } else { newTag.setVisibility(View.GONE); @@ -130,6 +136,15 @@ public class AppCardController extends RecyclerView.ViewHolder implements ImageL } } + private boolean isConsideredNew(@NonNull App app) { + //noinspection SimplifiableIfStatement + if (app.added == null || app.lastUpdated == null || !app.added.equals(app.lastUpdated)) { + return false; + } + + return Utils.daysSince(app.added) <= DAYS_TO_CONSIDER_NEW; + } + /** * When the user clicks/touches an app card, we launch the {@link AppDetails2} activity in response. */