mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 06:37:30 +00:00
Remove the last usage of Date. austinhuang0131/barinsta#1309
This commit is contained in:
parent
7e00dcc1b7
commit
981cd693bf
@ -17,11 +17,9 @@ import java.util.List;
|
||||
import awais.instagrabber.R;
|
||||
import awais.instagrabber.adapters.DirectMessageInboxAdapter.OnItemClickListener;
|
||||
import awais.instagrabber.databinding.LayoutDmInboxItemBinding;
|
||||
import awais.instagrabber.models.enums.MediaItemType;
|
||||
import awais.instagrabber.repositories.responses.User;
|
||||
import awais.instagrabber.repositories.responses.directmessages.DirectItem;
|
||||
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
|
||||
import awais.instagrabber.repositories.responses.directmessages.DirectThreadDirectStory;
|
||||
import awais.instagrabber.utils.DMUtils;
|
||||
import awais.instagrabber.utils.TextUtils;
|
||||
|
||||
@ -136,7 +134,7 @@ public final class DirectInboxItemViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private void setDateTime(@NonNull final DirectItem item) {
|
||||
final long timestamp = item.getTimestamp() / 1000;
|
||||
final String dateTimeString = TextUtils.getRelativeDateTimeString(itemView.getContext(), timestamp);
|
||||
final String dateTimeString = TextUtils.getRelativeDateTimeString(timestamp);
|
||||
binding.tvDate.setText(dateTimeString);
|
||||
}
|
||||
|
||||
|
@ -6,21 +6,10 @@ import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
//import java.util.Date;
|
||||
|
||||
import awais.instagrabber.models.enums.FavoriteType;
|
||||
|
||||
public class Converters {
|
||||
// @TypeConverter
|
||||
// public static Date fromTimestamp(Long value) {
|
||||
// return value == null ? null : new Date(value);
|
||||
// }
|
||||
//
|
||||
// @TypeConverter
|
||||
// public static Long dateToTimestamp(Date date) {
|
||||
// return date == null ? null : date.getTime();
|
||||
// }
|
||||
|
||||
@TypeConverter
|
||||
public static FavoriteType fromFavoriteTypeString(String value) {
|
||||
try {
|
||||
|
@ -1,14 +1,14 @@
|
||||
package awais.instagrabber.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.text.format.DateFormat
|
||||
import android.text.format.DateUtils
|
||||
import android.util.Patterns
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.format.FormatStyle
|
||||
import java.util.*
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
object TextUtils {
|
||||
var datetimeParser: DateTimeFormatter = DateTimeFormatter.ofPattern("")
|
||||
@ -40,22 +40,19 @@ object TextUtils {
|
||||
} else String.format(Locale.ENGLISH, "%02d:%02d", min, sec)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getRelativeDateTimeString(context: Context?, from: Long): String {
|
||||
val now = Date()
|
||||
val then = Date(from)
|
||||
val days = daysBetween(from, now.time)
|
||||
return if (days == 0) {
|
||||
DateFormat.getTimeFormat(context).format(then)
|
||||
} else DateFormat.getDateFormat(context).format(then)
|
||||
}
|
||||
private val timeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)
|
||||
private val dateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
|
||||
|
||||
private fun daysBetween(d1: Long, d2: Long): Int {
|
||||
return ((d2 - d1) / DateUtils.DAY_IN_MILLIS).toInt()
|
||||
@JvmStatic
|
||||
fun getRelativeDateTimeString(from: Long): String {
|
||||
val now = LocalDateTime.now()
|
||||
val then = LocalDateTime.ofInstant(Instant.ofEpochMilli(from), ZoneId.systemDefault())
|
||||
val days = Duration.between(now, then).toDays().absoluteValue
|
||||
return then.format(if (days == 0L) timeFormatter else dateFormatter)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun extractUrls(text: String?): List<String> {
|
||||
fun extractUrls(text: String): List<String> {
|
||||
if (isEmpty(text)) return emptyList()
|
||||
val matcher = Patterns.WEB_URL.matcher(text)
|
||||
val urls: MutableList<String> = ArrayList()
|
||||
|
Loading…
Reference in New Issue
Block a user