From 15ce004b261c1f69b68baa44f596331b1e253069 Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Sat, 4 Jul 2020 17:01:49 +0200 Subject: [PATCH] Fixed https://github.com/sschueller/peertube-android/issues/194 with new Lib. --- app/build.gradle | 3 +++ .../peertube/helper/MetaDataHelper.java | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index dd038df..0a32a8e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -62,6 +62,9 @@ android { implementation "com.google.android.exoplayer:exoplayer-smoothstreaming:$libVersions.exoplayer" implementation "com.google.android.exoplayer:extension-mediasession:$libVersions.exoplayer" + // date formatter + implementation 'org.ocpsoft.prettytime:prettytime:4.0.4.Final' + // testing testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' diff --git a/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java b/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java index 84e9de9..fa7390f 100644 --- a/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java +++ b/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java @@ -18,17 +18,28 @@ package net.schueller.peertube.helper; import android.content.Context; + import android.text.format.DateUtils; + import net.schueller.peertube.R; -import java.time.Duration; -import java.time.Period; +import org.ocpsoft.prettytime.PrettyTime; + import java.util.Date; +import java.util.Locale; + public class MetaDataHelper { + public static String getMetaString(Date getCreatedAt, Integer viewCount, Context context) { - return (DateUtils.getRelativeTimeSpanString(context,getCreatedAt.getTime(),false).toString() + + + // Compatible with SDK 21+ + String currentLanguage = Locale.getDefault().getDisplayLanguage(); + PrettyTime p = new PrettyTime(currentLanguage); + String relativeTime = p.format(new Date(getCreatedAt.getTime())); + + return (relativeTime + context.getResources().getString(R.string.meta_data_seperator) + viewCount + context.getResources().getString(R.string.meta_data_views)); }