From 3553013191aa49d88de7f3674d372d0281f75bf0 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Tue, 13 Apr 2021 14:53:35 -0400 Subject: [PATCH] Added new string to for mentioning times when the date time is at 0 --- .../tachiyomi/ui/library/LibraryCategoryAdapter.kt | 6 +++--- .../kanade/tachiyomi/ui/recents/RecentMangaHolder.kt | 8 ++++---- .../eu/kanade/tachiyomi/util/system/DateExtensions.kt | 11 +++++++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt index 2bcffe02b1..b1b81df851 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt @@ -146,7 +146,7 @@ class LibraryCategoryAdapter(val controller: LibraryController) : if (last != null && last.last_read > 100) { recyclerView.context.getString( R.string.read_, - last.last_read.timeSpanFromNow + last.last_read.timeSpanFromNow(preferences.context) ) } else { "N/A" @@ -173,7 +173,7 @@ class LibraryCategoryAdapter(val controller: LibraryController) : if (lastUpdate > 0) { recyclerView.context.getString( R.string.updated_, - lastUpdate.timeSpanFromNow + lastUpdate.timeSpanFromNow(preferences.context) ) } else { "N/A" @@ -182,7 +182,7 @@ class LibraryCategoryAdapter(val controller: LibraryController) : LibrarySort.DATE_ADDED -> { val added = item.manga.date_added if (added > 0) { - recyclerView.context.getString(R.string.added_, added.timeSpanFromNow) + recyclerView.context.getString(R.string.added_, added.timeSpanFromNow(preferences.context)) } else { "N/A" } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt index 2e1fad3de5..40631b85fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt @@ -86,12 +86,12 @@ class RecentMangaHolder( binding.body.text = when { item.mch.chapter.id == null -> binding.body.context.getString( R.string.added_, - item.mch.manga.date_added.timeSpanFromNow + item.mch.manga.date_added.timeSpanFromNow(itemView.context) ) adapter.viewType == RecentsPresenter.VIEW_TYPE_ONLY_UPDATES -> "" item.mch.history.id == null -> binding.body.context.getString( R.string.updated_, - item.chapter.date_upload.timeSpanFromNow + item.chapter.date_upload.timeSpanFromNow(itemView.context) ) item.chapter.id != item.mch.chapter.id -> binding.body.context.getString( @@ -104,7 +104,7 @@ class RecentMangaHolder( item.chapter.pages_left > 0 && !item.chapter.read -> binding.body.context.getString( R.string.read_, - item.mch.history.last_read.timeSpanFromNow + item.mch.history.last_read.timeSpanFromNow(itemView.context) ) + "\n" + itemView.resources.getQuantityString( R.plurals.pages_left, item.chapter.pages_left, @@ -112,7 +112,7 @@ class RecentMangaHolder( ) else -> binding.body.context.getString( R.string.read_, - item.mch.history.last_read.timeSpanFromNow + item.mch.history.last_read.timeSpanFromNow(itemView.context) ) } if ((itemView.context as? Activity)?.isDestroyed != true) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/DateExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/DateExtensions.kt index 7869a8bb6a..1dc1fe50bd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/DateExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/DateExtensions.kt @@ -1,6 +1,17 @@ package eu.kanade.tachiyomi.util.system +import android.content.Context import android.text.format.DateUtils +import eu.kanade.tachiyomi.R +import java.util.Locale val Long.timeSpanFromNow: String get() = DateUtils.getRelativeTimeSpanString(this).toString() + +fun Long.timeSpanFromNow(context: Context): String { + return if (this == 0L) { + context.getString(R.string.a_while_ago).lowercase(Locale.ROOT) + } else { + DateUtils.getRelativeTimeSpanString(this).toString() + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2b19e0dbeb..ae679ceda1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -229,6 +229,7 @@ Show reset history button Show read in all Show title first + A while ago Search filters