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.

This commit is contained in:
PhotonQyv 2017-12-05 14:24:14 +00:00
parent b4b8d85904
commit 2beea3bda5
4 changed files with 57 additions and 1 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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())

View File

@ -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