From 2beea3bda5cda57972622071380afe5dfa03cb5d Mon Sep 17 00:00:00 2001 From: PhotonQyv Date: Tue, 5 Dec 2017 14:24:14 +0000 Subject: [PATCH] Added a couple of Helper methods to allow a status's date to be clickable, so that an absolute date & time are shown (SHORT format for both) for 5 seconds. --- .../drawers/NotificationsListAdapter.java | 2 + .../mastodon/drawers/SearchListAdapter.java | 2 + .../mastodon/drawers/StatusListAdapter.java | 2 +- .../gouv/etalab/mastodon/helper/Helper.java | 52 +++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java index 86000cb75..f1fe049c6 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java @@ -259,6 +259,8 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On holder.status_reblog_count.setText(String.valueOf(status.getReblogs_count())); holder.status_date.setText(Helper.dateDiff(context, status.getCreated_at())); + Helper.absoluteDateTimeReveal(context, holder.status_date, status.getCreated_at()); + //Adds attachment -> disabled, to enable them uncomment the line below //loadAttachments(status, holder); holder.notification_status_container.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/SearchListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/SearchListAdapter.java index f7dd04065..32cb26430 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/SearchListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/SearchListAdapter.java @@ -185,6 +185,8 @@ public class SearchListAdapter extends BaseAdapter { holder.status_content.setAutoLinkMask(Linkify.WEB_URLS); holder.status_toot_date.setText(Helper.dateDiff(context, status.getCreated_at())); + Helper.absoluteDateTimeReveal(context, holder.status_toot_date, status.getCreated_at()); + Glide.with(holder.status_account_profile.getContext()) .load(ppurl) .into(holder.status_account_profile); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index f9b2ab4ee..5ae4f0a16 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -267,7 +267,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct status_replies_profile_pictures = itemView.findViewById(R.id.status_replies_profile_pictures); new_element = itemView.findViewById(R.id.new_element); status_action_container = itemView.findViewById(R.id.status_action_container); - } } @@ -572,6 +571,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct holder.status_toot_date.setText(Helper.dateDiff(context, status.getCreated_at())); + Helper.absoluteDateTimeReveal(context, holder.status_toot_date, status.getCreated_at()); if( status.getReblog() != null) { Glide.with(holder.status_account_profile_boost.getContext()) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 7c6453da3..65a170133 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -25,6 +25,7 @@ import android.graphics.Color; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; +import android.os.CountDownTimer; import android.support.annotation.Nullable; import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v7.app.AlertDialog; @@ -105,6 +106,7 @@ import java.io.OutputStream; import java.net.InetAddress; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -479,6 +481,56 @@ public class Helper { return date; } + /** + * Converts a Date date into a date-time string (SHORT format for both) + * @param context + * @param date to be converted + * @return String + */ + + public static String shortDateTime(Context context, Date date) { + Locale userLocale; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + userLocale = context.getResources().getConfiguration().getLocales().get(0); + } else { + //noinspection deprecation + userLocale = context.getResources().getConfiguration().locale; + } + + DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, userLocale); + + return df.format(date); + } + + /** + * Makes the tvDate TextView field clickable, and displays the absolute date & time of a toot + * for 5 seconds. + * @param context Context + * @param tvDate TextView + * @param date Date + */ + + public static void absoluteDateTimeReveal(final Context context, final TextView tvDate, final Date date) { + tvDate.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + tvDate.setText(Helper.shortDateTime(context, date)); + + new CountDownTimer((5 * 1000), 1000) { + + public void onTick(long millisUntilFinished) { + } + + public void onFinish() { + tvDate.setText(Helper.dateDiff(context, date)); + } + }.start(); + } + }); + } + /** * Check if WIFI is opened * @param context Context