Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dashspend): add discount values to Merchant lists and details #1298

Draft
wants to merge 4 commits into
base: feature-dashspend
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions common/src/main/res/drawable-v21/dark_gray_button_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/ripple_dark">

<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="@color/ripple_dark" />
<corners android:radius="6dp" />
</shape>
</item>

<item>
<selector>
<item android:state_enabled="false">
<shape android:shape="rectangle">
<corners android:radius="6dp" />
<solid android:color="@color/dash_black_0.7" />
</shape>
</item>
<item>
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/dash_black_0.7" />
<corners android:radius="6dp" />
</shape>
</item>
</layer-list>
</item>

</selector>
</item>

</ripple>
10 changes: 10 additions & 0 deletions common/src/main/res/drawable/triangle_black_70.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="6dp"
android:height="7dp"
android:viewportWidth="6"
android:viewportHeight="7">
<path
android:pathData="M6,0V7H0L6,0Z"
android:fillColor="#191C1F"
android:fillAlpha="0.7"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ data class Merchant(
var redeemType: String? = "",
@Ignore var minCardPurchase: Double? = null,
@Ignore var maxCardPurchase: Double? = null,
var savingsPercentage: Int? = 0,
var savingsPercentage: Int? = 0, // in basis points 1 = 0.001%
@Ignore var physicalAmount: Int = 0
) : SearchResult() {

// 1% discount is 0.01
val savingsPercentageAsDouble: Double
val savingsAsDouble: Double
get() = (savingsPercentage?.toDouble() ?: 0.0) / 10000

// 1% discount is 1.00
val savingsPercentageAsDouble: Double
get() = savingsAsDouble * 100
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ class MerchantViewHolder(val binding: MerchantRowBinding) : ExploreViewHolder(bi
binding.title.text = merchant?.name
binding.subtitle.text = getDistanceText(resources, merchant)
binding.subtitle.isVisible = merchant?.type != MerchantType.ONLINE && binding.subtitle.text.isNotEmpty()
if (merchant != null) {
if (merchant.savingsAsDouble != 0.00) {
binding.discountValue.isVisible = true
binding.discountValue.text = binding.root.context.getString(
R.string.explore_discount,
merchant.savingsPercentageAsDouble
)
} else {
binding.discountValue.isVisible = false
}
}

binding.logoImg.load(merchant?.logoLocation) {
crossfade(200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CTXSpendViewModel @Inject constructor(

val balanceWithDiscount: Coin?
get() = _balance.value?.let {
val d = giftCardMerchant.savingsPercentageAsDouble
val d = giftCardMerchant.savingsAsDouble
return Coin.valueOf((it.value / (1.0 - d)).toLong()).minus(Transaction.DEFAULT_TX_FEE.multiply(20))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class PurchaseGiftCardFragment : Fragment(R.layout.fragment_purchase_ctxspend_gi

private fun setDiscountHint() {
val merchant = viewModel.giftCardMerchant
val savingsPercentage = merchant.savingsPercentageAsDouble
val savingsPercentage = merchant.savingsAsDouble

if (savingsPercentage != DEFAULT_DISCOUNT_AS_DOUBLE) {
val purchaseAmount = enterAmountViewModel.amount.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class PurchaseGiftCardConfirmDialog : OffsetDialogFragment(R.layout.dialog_confi

val merchant = viewModel.giftCardMerchant
val paymentValue = viewModel.giftCardPaymentValue
val savingsPercentage = merchant.savingsPercentageAsDouble
val savingsPercentage = merchant.savingsAsDouble
binding.merchantName.text = merchant.name
merchant.logoLocation?.let { logoLocation ->
binding.merchantLogo.load(logoLocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ class ItemDetails(context: Context, attrs: AttributeSet) : LinearLayout(context,
}

bindCommonDetails(merchant, isOnline)

if (merchant.savingsAsDouble != 0.0) {
binding.discountValue.isVisible = true
binding.discountValue.text = root.context.getString(
R.string.explore_pay_with_dash_save,
merchant.savingsPercentageAsDouble
)
} else {
binding.discountValue.isVisible = false
}
}
}

Expand Down
23 changes: 23 additions & 0 deletions features/exploredash/src/main/res/layout/item_details_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
app:layout_constraintEnd_toEndOf="parent" />



<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:id="@+id/pay_btn"
Expand Down Expand Up @@ -280,5 +281,27 @@
android:layout_height="wrap_content" />
</androidx.appcompat.widget.LinearLayoutCompat>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/triangle_black_70"
app:layout_constraintEnd_toStartOf="@+id/discount_value"
app:layout_constraintBottom_toTopOf="@id/pay_btn"
/>
<TextView
android:id="@+id/discount_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Save 3.75%"
android:textColor="@color/white"
android:background="@drawable/dark_gray_button_background"
android:paddingHorizontal="5dp"
android:paddingVertical="1dp"
app:layout_constraintTop_toTopOf="@+id/pay_btn"
app:layout_constraintBottom_toTopOf="@+id/pay_btn"
app:layout_constraintEnd_toEndOf="@id/pay_btn"
android:layout_marginEnd="30dp"
/>

</androidx.constraintlayout.widget.ConstraintLayout>
</merge>
19 changes: 15 additions & 4 deletions features/exploredash/src/main/res/layout/merchant_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="14dp"
android:layout_marginEnd="16dp"
android:layout_marginEnd="3dp"
app:layout_constraintStart_toEndOf="@id/logo_img"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/subtitle"
app:layout_constraintEnd_toStartOf="@id/method_img"
app:layout_constraintEnd_toStartOf="@id/discount_value"
tools:text="Bark Box" />

<TextView
Expand All @@ -54,13 +54,24 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="14dp"
android:layout_marginEnd="16dp"
android:layout_marginEnd="3dp"
app:layout_constraintStart_toEndOf="@id/logo_img"
app:layout_constraintTop_toBottomOf="@id/title"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/method_img"
app:layout_constraintEnd_toStartOf="@id/discount_value"
tools:text="10 miles" />

<TextView
android:id="@+id/discount_value"
style="@style/Overline.Medium.Secondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/method_img"
tools:text="1.25%" />

<ImageView
android:id="@+id/method_img"
android:layout_width="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<string name="explore_no_atms">No ATMs</string>
<string name="distance_miles">%s miles</string>
<string name="distance_kilometers">%s kilometers</string>
<string name="explore_discount" translatable="false">~%.0f%%</string>

<plurals name="explore_merchant_amount">
<item quantity="one">%d merchant</item>
Expand All @@ -62,6 +63,7 @@
<string name="explore_back_to_nearest">Back to nearest location</string>
<string name="explore_select_location">Select location</string>
<string name="explore_pay_with_dash">Pay with Dash</string>
<string name="explore_pay_with_dash_save">Save %.2f%%</string>
<string name="explore_buy_gift_card">Buy a Gift Card</string>
<string name="explore_buy_dash">Buy Dash</string>
<string name="explore_sell_dash">Sell Dash</string>
Expand Down
Loading