This commit is contained in:
Stefan Schueller 2020-07-04 17:01:49 +02:00
parent 555db86072
commit 15ce004b26
2 changed files with 17 additions and 3 deletions

View File

@ -62,6 +62,9 @@ android {
implementation "com.google.android.exoplayer:exoplayer-smoothstreaming:$libVersions.exoplayer" implementation "com.google.android.exoplayer:exoplayer-smoothstreaming:$libVersions.exoplayer"
implementation "com.google.android.exoplayer:extension-mediasession:$libVersions.exoplayer" implementation "com.google.android.exoplayer:extension-mediasession:$libVersions.exoplayer"
// date formatter
implementation 'org.ocpsoft.prettytime:prettytime:4.0.4.Final'
// testing // testing
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0'

View File

@ -18,17 +18,28 @@
package net.schueller.peertube.helper; package net.schueller.peertube.helper;
import android.content.Context; import android.content.Context;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import net.schueller.peertube.R; import net.schueller.peertube.R;
import java.time.Duration; import org.ocpsoft.prettytime.PrettyTime;
import java.time.Period;
import java.util.Date; import java.util.Date;
import java.util.Locale;
public class MetaDataHelper { public class MetaDataHelper {
public static String getMetaString(Date getCreatedAt, Integer viewCount, Context context) { 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) + context.getResources().getString(R.string.meta_data_seperator) +
viewCount + context.getResources().getString(R.string.meta_data_views)); viewCount + context.getResources().getString(R.string.meta_data_views));
} }