mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-19 20:29:02 +00:00
improve seasonal time display
This commit is contained in:
parent
3552d0a591
commit
3a32d5d906
2 changed files with 23 additions and 25 deletions
|
|
@ -4,6 +4,7 @@ import android.content.res.Resources
|
|||
import com.habitrpg.android.habitica.R
|
||||
import java.util.*
|
||||
import kotlin.math.round
|
||||
import kotlin.time.*
|
||||
|
||||
class DateUtils {
|
||||
|
||||
|
|
@ -58,29 +59,30 @@ fun Date.getRemainingString(res: Resources): String {
|
|||
return this.time.getRemainingString(res)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalTime::class)
|
||||
fun Long.getRemainingString(res: Resources): String {
|
||||
val diff = this - Date().time
|
||||
val diff = (this - Date().time).milliseconds
|
||||
|
||||
val diffMinutes = diff / (60 * 1000) % 60
|
||||
val diffHours = diff / (60 * 60 * 1000) % 24
|
||||
val diffDays = diff / (24 * 60 * 60 * 1000)
|
||||
val diffMinutes = diff.inMinutes
|
||||
val diffHours = diff.inHours
|
||||
val diffDays = diff.inDays
|
||||
val diffWeeks = diffDays / 7f
|
||||
val diffMonths = diffDays / 30f
|
||||
|
||||
return when {
|
||||
diffMonths != 0f -> if (round(diffMonths) == 1f) {
|
||||
diffMonths != 0.0 -> if (round(diffMonths) == 1.0) {
|
||||
res.getString(R.string.remaining_1month)
|
||||
} else res.getString(R.string.remaining_months, round(diffMonths).toInt())
|
||||
diffWeeks != 0f -> if (round(diffWeeks) == 1f) {
|
||||
diffWeeks != 0.0 -> if (round(diffWeeks) == 1.0) {
|
||||
res.getString(R.string.remaining_1week)
|
||||
} else res.getString(R.string.remaining_weeks, round(diffWeeks).toInt())
|
||||
diffDays != 0L -> if (diffDays == 1L) {
|
||||
diffDays != 0.0 -> if (diffDays == 1.0) {
|
||||
res.getString(R.string.remaining_1day)
|
||||
} else res.getString(R.string.remaining_days, diffDays)
|
||||
diffHours != 0L -> if (diffHours == 1L) {
|
||||
diffHours != 0.0 -> if (diffHours == 1.0) {
|
||||
res.getString(R.string.remaining_1hour)
|
||||
} else res.getString(R.string.remaining_hours, diffHours)
|
||||
diffMinutes == 1L -> res.getString(R.string.remaining_1Minute)
|
||||
diffMinutes == 1.0 -> res.getString(R.string.remaining_1Minute)
|
||||
else -> res.getString(R.string.remaining_minutes, diffMinutes)
|
||||
}
|
||||
}
|
||||
|
|
@ -89,16 +91,17 @@ fun Date.getShortRemainingString(): String {
|
|||
return time.getShortRemainingString()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalTime::class)
|
||||
fun Long.getShortRemainingString(): String {
|
||||
var diff = this - Date().time
|
||||
var diff = (this - Date().time).milliseconds
|
||||
|
||||
val diffDays = diff / (24 * 60 * 60 * 1000)
|
||||
diff -= (diffDays * (24 * 60 * 60 * 1000))
|
||||
val diffHours = diff / (60 * 60 * 1000)
|
||||
diff -= (diffHours * (60 * 60 * 1000))
|
||||
val diffMinutes = diff / (60 * 1000)
|
||||
diff -= (diffMinutes * (60 * 1000))
|
||||
val diffSeconds = diff / 1000
|
||||
val diffDays = diff.inDays
|
||||
diff -= diffDays.days
|
||||
val diffHours = diff.inHours
|
||||
diff -= diffHours.hours
|
||||
val diffMinutes = diff.inMinutes
|
||||
diff -= diffMinutes.minutes
|
||||
val diffSeconds = diff.inSeconds
|
||||
|
||||
var str = "${diffMinutes}m"
|
||||
if (diffHours > 0) {
|
||||
|
|
@ -107,7 +110,7 @@ fun Long.getShortRemainingString(): String {
|
|||
if (diffDays > 0) {
|
||||
str = "${diffDays}d $str"
|
||||
}
|
||||
if (diffDays == 0L && diffHours == 0L) {
|
||||
if (diffDays == 0.0 && diffHours == 0.0) {
|
||||
str = "$str ${diffSeconds}s"
|
||||
}
|
||||
return str
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ import java.util.concurrent.TimeUnit
|
|||
import javax.inject.Inject
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.time.ExperimentalTime
|
||||
import kotlin.time.hours
|
||||
import kotlin.time.minutes
|
||||
import kotlin.time.seconds
|
||||
|
||||
|
|
@ -165,11 +166,6 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION)
|
||||
mFromSavedInstanceState = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
// Indicate that this fragment would like to influence the set of actions in the action bar.
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
||||
|
|
@ -217,10 +213,9 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
while (gearEvent?.end?.after(Date()) == true || pair.second.isNotEmpty()) {
|
||||
updateSeasonalMenuEntries(pair.first, pair.second)
|
||||
val diff = (gearEvent?.end?.time ?: 0) - Date().time
|
||||
delay(if (diff < (60 * 60 * 1000)) 1.seconds else 1.minutes)
|
||||
delay(if (diff < (1.hours.inMilliseconds)) 1.seconds else 1.minutes)
|
||||
}
|
||||
}
|
||||
getItemWithIdentifier(SIDEBAR_SHOPS_SEASONAL)?.isVisible = false
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
|
||||
if (configManager.enableTeamBoards()) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue