Date TimeSpan extension
This commit is contained in:
parent
420f58eaed
commit
4ce2172a0c
3 changed files with 14 additions and 20 deletions
|
@ -1,6 +1,5 @@
|
||||||
package eu.kanade.tachiyomi.ui.recents
|
package eu.kanade.tachiyomi.ui.recents
|
||||||
|
|
||||||
import android.text.format.DateUtils
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import com.bumptech.glide.signature.ObjectKey
|
import com.bumptech.glide.signature.ObjectKey
|
||||||
|
@ -11,10 +10,10 @@ import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||||
import eu.kanade.tachiyomi.source.LocalSource
|
import eu.kanade.tachiyomi.source.LocalSource
|
||||||
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterHolder
|
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterHolder
|
||||||
import eu.kanade.tachiyomi.util.chapter.ChapterUtil
|
import eu.kanade.tachiyomi.util.chapter.ChapterUtil
|
||||||
|
import eu.kanade.tachiyomi.util.system.timeSpanFromNow
|
||||||
import eu.kanade.tachiyomi.util.view.visibleIf
|
import eu.kanade.tachiyomi.util.view.visibleIf
|
||||||
import kotlinx.android.synthetic.main.download_button.*
|
import kotlinx.android.synthetic.main.download_button.*
|
||||||
import kotlinx.android.synthetic.main.recent_manga_item.*
|
import kotlinx.android.synthetic.main.recent_manga_item.*
|
||||||
import java.util.Date
|
|
||||||
|
|
||||||
class RecentMangaHolder(
|
class RecentMangaHolder(
|
||||||
view: View,
|
view: View,
|
||||||
|
@ -50,35 +49,25 @@ class RecentMangaHolder(
|
||||||
val notValidNum = item.mch.chapter.chapter_number <= 0
|
val notValidNum = item.mch.chapter.chapter_number <= 0
|
||||||
body.text = when {
|
body.text = when {
|
||||||
item.mch.chapter.id == null -> body.context.getString(
|
item.mch.chapter.id == null -> body.context.getString(
|
||||||
R.string.added_, DateUtils.getRelativeTimeSpanString(
|
R.string.added_, item.mch.manga.date_added.timeSpanFromNow
|
||||||
item.mch.manga.date_added, Date().time, DateUtils.MINUTE_IN_MILLIS
|
|
||||||
).toString()
|
|
||||||
)
|
)
|
||||||
item.mch.history.id == null -> body.context.getString(
|
item.mch.history.id == null -> body.context.getString(
|
||||||
R.string.updated_, DateUtils.getRelativeTimeSpanString(
|
R.string.updated_, item.chapter.date_upload.timeSpanFromNow
|
||||||
item.chapter.date_upload, Date().time, DateUtils.HOUR_IN_MILLIS
|
|
||||||
).toString()
|
|
||||||
)
|
)
|
||||||
item.chapter.id != item.mch.chapter.id ->
|
item.chapter.id != item.mch.chapter.id ->
|
||||||
body.context.getString(
|
body.context.getString(
|
||||||
R.string.read_, DateUtils.getRelativeTimeSpanString(
|
R.string.read_, item.mch.history.last_read.timeSpanFromNow
|
||||||
item.mch.history.last_read, Date().time, DateUtils.MINUTE_IN_MILLIS
|
|
||||||
).toString()
|
|
||||||
) + "\n" + body.context.getString(
|
) + "\n" + body.context.getString(
|
||||||
if (notValidNum) R.string.last_read_ else R.string.last_read_chapter_,
|
if (notValidNum) R.string.last_read_ else R.string.last_read_chapter_,
|
||||||
if (notValidNum) item.mch.chapter.name else adapter.decimalFormat.format(item.mch.chapter.chapter_number)
|
if (notValidNum) item.mch.chapter.name else adapter.decimalFormat.format(item.mch.chapter.chapter_number)
|
||||||
)
|
)
|
||||||
item.chapter.pages_left > 0 && !item.chapter.read -> body.context.getString(
|
item.chapter.pages_left > 0 && !item.chapter.read -> body.context.getString(
|
||||||
R.string.read_, DateUtils.getRelativeTimeSpanString(
|
R.string.read_, item.mch.history.last_read.timeSpanFromNow
|
||||||
item.mch.history.last_read, Date().time, DateUtils.MINUTE_IN_MILLIS
|
|
||||||
).toString()
|
|
||||||
) + "\n" + itemView.resources.getQuantityString(
|
) + "\n" + itemView.resources.getQuantityString(
|
||||||
R.plurals.pages_left, item.chapter.pages_left, item.chapter.pages_left
|
R.plurals.pages_left, item.chapter.pages_left, item.chapter.pages_left
|
||||||
)
|
)
|
||||||
else -> body.context.getString(
|
else -> body.context.getString(
|
||||||
R.string.read_, DateUtils.getRelativeTimeSpanString(
|
R.string.read_, item.mch.history.last_read.timeSpanFromNow
|
||||||
item.mch.history.last_read, Date().time, DateUtils.MINUTE_IN_MILLIS
|
|
||||||
).toString()
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
GlideApp.with(itemView.context).load(item.mch.manga).diskCacheStrategy(DiskCacheStrategy
|
GlideApp.with(itemView.context).load(item.mch.manga).diskCacheStrategy(DiskCacheStrategy
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
package eu.kanade.tachiyomi.util.chapter
|
package eu.kanade.tachiyomi.util.chapter
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.text.format.DateUtils
|
|
||||||
import androidx.core.graphics.ColorUtils
|
import androidx.core.graphics.ColorUtils
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||||
import eu.kanade.tachiyomi.util.system.contextCompatColor
|
import eu.kanade.tachiyomi.util.system.contextCompatColor
|
||||||
import java.util.Date
|
import eu.kanade.tachiyomi.util.system.timeSpanFromNow
|
||||||
|
|
||||||
class ChapterUtil {
|
class ChapterUtil {
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun relativeDate(chapter: Chapter): String? {
|
fun relativeDate(chapter: Chapter): String? {
|
||||||
return when (chapter.date_upload > 0) {
|
return when (chapter.date_upload > 0) {
|
||||||
true -> DateUtils.getRelativeTimeSpanString(chapter.date_upload, Date().time, DateUtils.HOUR_IN_MILLIS).toString()
|
true -> chapter.date_upload.timeSpanFromNow
|
||||||
false -> null
|
false -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package eu.kanade.tachiyomi.util.system
|
||||||
|
|
||||||
|
import android.text.format.DateUtils
|
||||||
|
|
||||||
|
val Long.timeSpanFromNow: String
|
||||||
|
get() = DateUtils.getRelativeTimeSpanString(this).toString()
|
Reference in a new issue