mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-17 11:19:01 +00:00
Tweak remaining sub time display
This commit is contained in:
parent
f1c83abef3
commit
81a4ff50f8
6 changed files with 48 additions and 8 deletions
|
|
@ -151,7 +151,7 @@ android {
|
|||
multiDexEnabled true
|
||||
resConfigs "en", "bg", "de", "en-rGB", "es", "fr", "hr-rHR", "in", "it", "iw", "ja", "ko", "lt", "nl", "pl", "pt-rBR", "pt-rPT", "ru", "tr", "zh", "zh-rTW"
|
||||
|
||||
versionCode 2277
|
||||
versionCode 2280
|
||||
versionName "2.3"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -240,6 +240,8 @@
|
|||
<string name="quest_begin_message">Are you sure? Only %1$d of your %2$d party members have joined this quest! Quests start automatically when all players have joined or rejected the invitation.</string>
|
||||
<string name="ago_1month">1 month ago</string>
|
||||
<string name="ago_months">%d month ago</string>
|
||||
<string name="ago_1week">1w remaining</string>
|
||||
<string name="ago_weeks">%dw remaining</string>
|
||||
<string name="ago_1day">1d ago</string>
|
||||
<string name="ago_days">%dd ago</string>
|
||||
<string name="ago_1Minute">1m ago</string>
|
||||
|
|
@ -248,6 +250,8 @@
|
|||
<string name="ago_1hour">1h ago</string>
|
||||
<string name="remaining_1month">1 month remaining</string>
|
||||
<string name="remaining_months">%d months remaining</string>
|
||||
<string name="remaining_1week">1 week remaining</string>
|
||||
<string name="remaining_weeks">%d weeks remaining</string>
|
||||
<string name="remaining_1day">1d remaining</string>
|
||||
<string name="remaining_days">%dd remaining</string>
|
||||
<string name="remaining_1Minute">1m remaining</string>
|
||||
|
|
@ -866,4 +870,5 @@
|
|||
<string name="profile_gift_subscription">Gift\nSubscription</string>
|
||||
<string name="gems_gift_description">Want to bestow a shiny haul of Gems to someone else?</string>
|
||||
<string name="gift_gems_disclaimer">Habitica will never require you to gift gems to other players. Begging people for gems is a violation of the Community Guidelines and should be reported to admin@habitica.com.</string>
|
||||
<string name="more_out_of_habitica">Get more out of Habitica</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -56,5 +56,9 @@
|
|||
<key>showSubscriptionBanner</key>
|
||||
<value>false</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>showSubscriptionSubtitle</key>
|
||||
<value>false</value>
|
||||
</entry>
|
||||
</defaultsMap>
|
||||
<!-- END xml_defaults -->
|
||||
|
|
@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.extensions
|
|||
import android.content.res.Resources
|
||||
import com.habitrpg.android.habitica.R
|
||||
import java.util.*
|
||||
import kotlin.math.round
|
||||
|
||||
class DateUtils {
|
||||
|
||||
|
|
@ -27,12 +28,16 @@ fun Long.getAgoString(res: Resources): String {
|
|||
val diffMinutes = diff / (60 * 1000) % 60
|
||||
val diffHours = diff / (60 * 60 * 1000) % 24
|
||||
val diffDays = diff / (24 * 60 * 60 * 1000)
|
||||
val diffWeeks = diffDays / 7
|
||||
val diffMonths = diffDays / 30
|
||||
|
||||
return when {
|
||||
diffMonths != 0L -> if (diffMonths == 1L) {
|
||||
res.getString(R.string.ago_1month)
|
||||
} else res.getString(R.string.ago_months, diffMonths)
|
||||
diffWeeks != 0L -> if (diffWeeks == 1L) {
|
||||
res.getString(R.string.ago_1week)
|
||||
} else res.getString(R.string.ago_weeks, diffWeeks)
|
||||
diffDays != 0L -> if (diffDays == 1L) {
|
||||
res.getString(R.string.ago_1day)
|
||||
} else res.getString(R.string.ago_days, diffDays)
|
||||
|
|
@ -54,12 +59,16 @@ fun Long.getRemainingString(res: Resources): String {
|
|||
val diffMinutes = diff / (60 * 1000) % 60
|
||||
val diffHours = diff / (60 * 60 * 1000) % 24
|
||||
val diffDays = diff / (24 * 60 * 60 * 1000)
|
||||
val diffMonths = diffDays / 30
|
||||
val diffWeeks = diffDays / 7f
|
||||
val diffMonths = diffDays / 30f
|
||||
|
||||
return when {
|
||||
diffMonths != 0L -> if (diffMonths == 1L) {
|
||||
diffMonths != 0f -> if (round(diffMonths) == 1f) {
|
||||
res.getString(R.string.remaining_1month)
|
||||
} else res.getString(R.string.remaining_months, diffMonths)
|
||||
} else res.getString(R.string.remaining_months, round(diffMonths))
|
||||
diffWeeks != 0f -> if (round(diffWeeks) == 1f) {
|
||||
res.getString(R.string.remaining_1week)
|
||||
} else res.getString(R.string.remaining_weeks, round(diffWeeks))
|
||||
diffDays != 0L -> if (diffDays == 1L) {
|
||||
res.getString(R.string.remaining_1day)
|
||||
} else res.getString(R.string.remaining_days, diffDays)
|
||||
|
|
|
|||
|
|
@ -74,4 +74,8 @@ class AppConfigManager {
|
|||
fun showSubscriptionBanner(): Boolean {
|
||||
return remoteConfig.getBoolean("showSubscriptionBanner")
|
||||
}
|
||||
|
||||
fun showSubscriptionSubtitle(): Boolean {
|
||||
return remoteConfig.getBoolean("showSubscriptionSubtitle")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,10 @@ import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar
|
|||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.functions.Consumer
|
||||
import kotlinx.android.synthetic.main.drawer_main.*
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -235,12 +238,26 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
|
||||
val subscriptionItem = getItemWithIdentifier(SIDEBAR_SUBSCRIPTION)
|
||||
if (user.isSubscribed && user.purchased?.plan?.dateTerminated != null) {
|
||||
context?.let {
|
||||
subscriptionItem?.additionalInfo = user.purchased?.plan?.dateTerminated?.getRemainingString(it.resources)
|
||||
subscriptionItem?.additionalInfoTextColor = it.getThemeColor(R.attr.textColorSecondary)
|
||||
val terminatedCalendar = Calendar.getInstance()
|
||||
terminatedCalendar.time = user.purchased?.plan?.dateTerminated ?: Date()
|
||||
val msDiff = Calendar.getInstance().timeInMillis - terminatedCalendar.timeInMillis
|
||||
val daysDiff = TimeUnit.MILLISECONDS.toDays(msDiff)
|
||||
if (daysDiff <= 30) {
|
||||
context?.let {
|
||||
subscriptionItem?.additionalInfo = user.purchased?.plan?.dateTerminated?.getRemainingString(it.resources)
|
||||
subscriptionItem?.additionalInfoTextColor = when {
|
||||
daysDiff <= 2 -> ContextCompat.getColor(it, R.color.red_100)
|
||||
daysDiff <= 7 -> ContextCompat.getColor(it, R.color.brand_400)
|
||||
else -> it.getThemeColor(R.attr.textColorSecondary)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
subscriptionItem?.additionalInfo = null
|
||||
subscriptionItem?.additionalInfo = if (configManager.showSubscriptionSubtitle()) {
|
||||
context?.getString(R.string.more_out_of_habitica)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
val promoItem = getItemWithIdentifier(SIDEBAR_SUBSCRIPTION_PROMO)
|
||||
|
|
@ -251,6 +268,7 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
getItemWithIdentifier(SIDEBAR_NEWS)?.let {
|
||||
it.showBubble = user.flags?.newStuff ?: false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue