improve bulk gem purchasing handling

This commit is contained in:
Phillip Thelen 2020-04-09 14:25:54 +02:00
parent 8eff8c6a5a
commit 7e76c78fc7
8 changed files with 61 additions and 5 deletions

View file

@ -100,4 +100,13 @@
android:textColor="@color/green_50"/>
</TableRow>
</TableLayout>
<TextView
android:id="@+id/amount_error_label"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/purchase_amount_error"
android:textSize="12sp"
android:textColor="@color/gray_200"
android:layout_marginTop="@dimen/spacing_medium"
android:gravity="center_horizontal"/>
</merge>

View file

@ -31,4 +31,13 @@
android:textColor="@color/black_50_alpha"
tools:text="These are the notes"
android:gravity="center"/>
<TextView
android:id="@+id/amount_error_label"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/purchase_amount_error"
android:textSize="12sp"
android:textColor="@color/gray_200"
android:layout_marginTop="@dimen/spacing_medium"
android:gravity="center_horizontal"/>
</merge>

View file

@ -179,4 +179,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
<TextView
android:id="@+id/amount_error_label"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/purchase_amount_error"
android:textSize="12sp"
android:textColor="@color/gray_200"
android:layout_marginTop="@dimen/spacing_medium"
android:gravity="center_horizontal"/>
</merge>

View file

@ -30,5 +30,14 @@
android:id="@+id/gem_icon"
android:layout_gravity="center"/>
</LinearLayout>
<TextView
android:id="@+id/amount_error_label"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/purchase_amount_error"
android:textSize="12sp"
android:textColor="@color/gray_200"
android:layout_marginTop="@dimen/spacing_medium"
android:gravity="center_horizontal"/>
</LinearLayout>

View file

@ -42,4 +42,13 @@
app:defaultValue="1"
app:minValue="1"
/>
<TextView
android:id="@+id/amount_error_label"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/purchase_amount_error"
android:textSize="12sp"
android:textColor="@color/gray_200"
android:layout_marginTop="@dimen/spacing_medium"
android:gravity="center_horizontal"/>
</merge>

View file

@ -1005,4 +1005,5 @@
<string name="avatar_accent">Accent</string>
<string name="buy_all">Buy All</string>
<string name="read_more">Read More</string>
<string name="purchase_amount_error">You are unable to buy that amount.</string>
</resources>

View file

@ -58,6 +58,7 @@ class PurchaseDialog(context: Context, component: UserComponent?, val item: Shop
private val buyButton: View
private val priceLabel: CurrencyView
private val buyLabel: TextView
private var amountErrorLabel: TextView? = null
private val pinButton: Button by bindView(customHeader, R.id.pin_button)
private var purchaseQuantity = 1
@ -112,6 +113,9 @@ class PurchaseDialog(context: Context, component: UserComponent?, val item: Shop
}
else -> contentView = PurchaseDialogBaseContent(context)
}
amountErrorLabel = contentView.findViewById(R.id.amount_error_label)
contentView.setItem(shopItem)
setAdditionalContentView(contentView)
}
@ -119,7 +123,7 @@ class PurchaseDialog(context: Context, component: UserComponent?, val item: Shop
fun updatePurchaseTotal() {
priceLabel.value = shopItem.value.toDouble() * purchaseQuantity
if (shopItem.canAfford(user, purchaseQuantity) && !shopItem.locked) {
if (shopItem.canAfford(user, purchaseQuantity) && !shopItem.locked && purchaseQuantity >= 1) {
buyButton.background = context.getDrawable(R.drawable.button_background_primary)
priceLabel.setTextColor(ContextCompat.getColor(context, R.color.white))
buyLabel.setTextColor(ContextCompat.getColor(context, R.color.white))
@ -128,6 +132,12 @@ class PurchaseDialog(context: Context, component: UserComponent?, val item: Shop
priceLabel.setTextColor(ContextCompat.getColor(context, R.color.gray_100))
buyLabel.setTextColor(ContextCompat.getColor(context, R.color.gray_100))
}
if (purchaseQuantity < 1 || (shopItem.limitedNumberLeft != null && (shopItem.limitedNumberLeft ?: 0) < purchaseQuantity)) {
amountErrorLabel?.visibility = View.VISIBLE
} else {
amountErrorLabel?.visibility = View.GONE
}
}
private fun checkGearClass() {

View file

@ -28,16 +28,16 @@ class StepperValueFormView @JvmOverloads constructor(
private var editTextIsFocused = false
var value = 0.0
set(value) {
var newValue = if (value >= minValue) value else minValue
set(new) {
var newValue = if (new >= minValue) new else minValue
maxValue?.let {
if (newValue > it) {
if (newValue > it && it > 0) {
newValue = it
}
}
val oldValue = field
field = newValue
if (oldValue != newValue) {
if (oldValue != new) {
valueString = decimalFormat.format(newValue)
}
downButton.isEnabled = field > minValue