mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Improve shop countdown display
This commit is contained in:
parent
297cea8b3e
commit
1256c8362f
4 changed files with 22 additions and 5 deletions
|
|
@ -1523,6 +1523,7 @@
|
|||
<string name="customizations_no_owned">You don’t own any of these items</string>
|
||||
<string name="customization_shop_check_out">Head over to the Customization Shop to browse the many ways you can customize your avatar!</string>
|
||||
<string name="switches_in_x">Switches in %s</string>
|
||||
<string name="next_switch_in_x">Next switch in %s</string>
|
||||
<string name="tap_to_reload">Refresh for new items</string>
|
||||
<string name="monthly_backgrounds">Monthly Backgrounds</string>
|
||||
<string name="winter">Winter</string>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.habitrpg.android.habitica.models.shops
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import io.realm.RealmList
|
||||
import java.util.Date
|
||||
|
||||
class ShopCategory {
|
||||
|
|
@ -14,5 +15,17 @@ class ShopCategory {
|
|||
@SerializedName("end")
|
||||
var endDate: Date? = null
|
||||
|
||||
var itemEndDates: MutableList<Date> = ArrayList()
|
||||
|
||||
var items: MutableList<ShopItem> = ArrayList()
|
||||
|
||||
val endDates: Set<Date>
|
||||
get() {
|
||||
val dates = itemEndDates.distinct().toMutableSet()
|
||||
if (items.isNotEmpty()) {
|
||||
dates.addAll(items.mapNotNull { it.endDate })
|
||||
}
|
||||
endDate?.let { dates.add(it) }
|
||||
return dates
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ class ShopRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<Vi
|
|||
is ShopCategory -> {
|
||||
val sectionHolder = holder as? SectionViewHolder ?: return
|
||||
sectionHolder.bind(obj.text)
|
||||
sectionHolder.bind(obj.endDate)
|
||||
sectionHolder.bind(obj.endDates)
|
||||
(sectionHolder.headerContainer?.layoutParams as? LinearLayout.LayoutParams)?.topMargin = if (position > 1) {
|
||||
40.dpToPx(context)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -96,13 +96,16 @@ class SectionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
|||
)
|
||||
}
|
||||
|
||||
fun bind(endDate: Date?) {
|
||||
if (endDate != null) {
|
||||
fun bind(endDates: Set<Date>) {
|
||||
if (endDates.isNotEmpty()) {
|
||||
val nextDate = endDates.minOrNull() ?: return
|
||||
switchesInLabel?.visibility = View.VISIBLE
|
||||
if (endDate.time < Date().time) {
|
||||
if (nextDate.time < Date().time) {
|
||||
switchesInLabel?.text = context.getString(R.string.tap_to_reload)
|
||||
} else if (endDates.size > 1) {
|
||||
switchesInLabel?.text = context.getString(R.string.next_switch_in_x, nextDate.getImpreciseRemainingString(context.resources))
|
||||
} else {
|
||||
switchesInLabel?.text = context.getString(R.string.switches_in_x, endDate.getImpreciseRemainingString(context.resources))
|
||||
switchesInLabel?.text = context.getString(R.string.switches_in_x, nextDate.getImpreciseRemainingString(context.resources))
|
||||
}
|
||||
} else {
|
||||
switchesInLabel?.visibility = View.GONE
|
||||
|
|
|
|||
Loading…
Reference in a new issue