update gem purchase screen

This commit is contained in:
Phillip Thelen 2019-11-25 14:58:20 +01:00
parent 563cc95127
commit 58fc185532
48 changed files with 117 additions and 52 deletions

View file

@ -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 2307
versionCode 2309
versionName "2.4"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View file

@ -5,7 +5,7 @@
<item android:state_pressed="true" >
<shape android:shape="rectangle">
<solid
android:color="?colorPrimaryDistinct" >
android:color="@color/brand_700" >
</solid>
<corners
android:radius="8dp">
@ -16,7 +16,7 @@
<item android:state_focused="true" >
<shape android:shape="rectangle">
<solid
android:color="?colorAccent">
android:color="@color/brand_500">
</solid>
<corners
android:radius="8dp">
@ -36,7 +36,7 @@
<item>
<shape android:shape="rectangle">
<solid
android:color="?colorPrimaryOffset">
android:color="@color/brand_400">
</solid>
<corners
android:radius="8dp">

View file

@ -11,10 +11,56 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/gift_subscription_container"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@drawable/g1g1_box"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="10dp"
android:clipChildren="true"
android:clipToPadding="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/presents1"
android:scaleType="center"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="false"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/presents2"
android:scaleType="center"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/gift_one_get_one_description"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:gravity="center_horizontal"
android:textColor="@color/white"
android:textSize="16sp"
android:fontFamily="@string/font_family_medium"
android:layout_marginBottom="12dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<ImageView
android:id="@+id/header_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/gem_purchase_header"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -25,7 +71,9 @@
android:textSize="16sp"
android:lineSpacingExtra="4dp"
android:layout_marginTop="23dp"
android:layout_marginBottom="12dp"/>
android:layout_marginBottom="12dp"
android:layout_marginStart="@dimen/spacing_large"
android:layout_marginEnd="@dimen/spacing_large" />
<TextView
android:text="@string/gem_purchase_listitem1"
@ -69,7 +117,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:layout_marginTop="@dimen/spacing_large">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -119,7 +168,13 @@
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/gift_sub_gift"
android:layout_marginTop="24dp"
android:layout_marginBottom="2dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -128,8 +183,7 @@
android:gravity="center_horizontal"
style="@style/Body2"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginRight="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_large"/>
android:layout_marginRight="@dimen/spacing_large"/>
<Button
android:id="@+id/gift_gems_button"
android:layout_width="match_parent"

View file

@ -38,5 +38,6 @@
android:id="@+id/purchase_button"
android:background="@drawable/purchase_button_background"
android:textColor="@color/white"
style="@style/Body1"
tools:text="$ 4.99"/>
</LinearLayout>

View file

@ -2,41 +2,37 @@ package com.habitrpg.android.habitica.ui
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.*
import android.widget.FrameLayout
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.inflate
import com.habitrpg.android.habitica.ui.helpers.bindView
import com.habitrpg.android.habitica.databinding.PurchaseGemViewBinding
import com.habitrpg.android.habitica.extensions.layoutInflater
class GemPurchaseOptionsView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {
private val gemImageView: ImageView by bindView(R.id.gem_image)
private val gemAmountTextView: TextView by bindView(R.id.gem_amount)
private val purchaseButton: Button by bindView(R.id.purchase_button)
private var binding: PurchaseGemViewBinding = PurchaseGemViewBinding.inflate(context.layoutInflater, this, true)
var sku: String? = null
init {
inflate(R.layout.purchase_gem_view, true)
val a = context.theme.obtainStyledAttributes(
attrs,
R.styleable.GemPurchaseOptionsView,
0, 0)
gemAmountTextView.text = a.getText(R.styleable.GemPurchaseOptionsView_gemAmount)
binding.gemAmount.text = a.getText(R.styleable.GemPurchaseOptionsView_gemAmount)
val iconRes = a.getDrawable(R.styleable.GemPurchaseOptionsView_gemDrawable)
if (iconRes != null) {
gemImageView.setImageDrawable(iconRes)
binding.gemImage.setImageDrawable(iconRes)
}
}
fun setOnPurchaseClickListener(listener: OnClickListener) {
purchaseButton.setOnClickListener(listener)
binding.purchaseButton.setOnClickListener(listener)
}
fun setPurchaseButtonText(price: String) {
purchaseButton.text = price
binding.purchaseButton.text = price
}
}

View file

@ -6,14 +6,14 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.core.view.isVisible
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.UserComponent
import com.habitrpg.android.habitica.data.UserRepository
import com.habitrpg.android.habitica.databinding.FragmentGemPurchaseBinding
import com.habitrpg.android.habitica.extensions.addCancelButton
import com.habitrpg.android.habitica.extensions.inflate
import com.habitrpg.android.habitica.helpers.AppConfigManager
import com.habitrpg.android.habitica.helpers.PurchaseHandler
import com.habitrpg.android.habitica.helpers.PurchaseTypes
import com.habitrpg.android.habitica.helpers.RxErrorHandler
@ -21,38 +21,31 @@ import com.habitrpg.android.habitica.proxy.CrashlyticsProxy
import com.habitrpg.android.habitica.ui.GemPurchaseOptionsView
import com.habitrpg.android.habitica.ui.activities.GemPurchaseActivity
import com.habitrpg.android.habitica.ui.activities.GiftGemsActivity
import com.habitrpg.android.habitica.ui.activities.GiftSubscriptionActivity
import com.habitrpg.android.habitica.ui.fragments.BaseFragment
import com.habitrpg.android.habitica.ui.helpers.bindView
import com.habitrpg.android.habitica.ui.helpers.dismissKeyboard
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
import com.habitrpg.android.habitica.ui.views.promo.SubscriptionBuyGemsPromoView
import io.reactivex.functions.Consumer
import javax.inject.Inject
class GemsPurchaseFragment : BaseFragment(), GemPurchaseActivity.CheckoutFragment {
private val gems4View: GemPurchaseOptionsView? by bindView(R.id.gems_4_view)
private val gems21View: GemPurchaseOptionsView? by bindView(R.id.gems_21_view)
private val gems42View: GemPurchaseOptionsView? by bindView(R.id.gems_42_view)
private val gems84View: GemPurchaseOptionsView? by bindView(R.id.gems_84_view)
private val subscriptionPromoView: SubscriptionBuyGemsPromoView? by bindView(R.id.subscription_promo)
private val supportTextView: TextView? by bindView(R.id.supportTextView)
private val giftGemsButton: Button? by bindView(R.id.gift_gems_button)
private lateinit var binding: FragmentGemPurchaseBinding
@Inject
lateinit var crashlyticsProxy: CrashlyticsProxy
@Inject
lateinit var userRepository: UserRepository
@Inject
lateinit var appConfigManager: AppConfigManager
private var purchaseHandler: PurchaseHandler? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState)
return container?.inflate(R.layout.fragment_gem_purchase)
binding = FragmentGemPurchaseBinding.inflate(inflater, container, false)
return binding.root
}
override fun injectFragment(component: UserComponent) {
@ -62,19 +55,22 @@ class GemsPurchaseFragment : BaseFragment(), GemPurchaseActivity.CheckoutFragmen
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
gems4View?.setOnPurchaseClickListener(View.OnClickListener { purchaseGems(PurchaseTypes.Purchase4Gems) })
gems21View?.setOnPurchaseClickListener(View.OnClickListener { purchaseGems(PurchaseTypes.Purchase21Gems) })
gems42View?.setOnPurchaseClickListener(View.OnClickListener { purchaseGems(PurchaseTypes.Purchase42Gems) })
gems84View?.setOnPurchaseClickListener(View.OnClickListener { purchaseGems(PurchaseTypes.Purchase84Gems) })
binding.gems4View?.setOnPurchaseClickListener(View.OnClickListener { purchaseGems(PurchaseTypes.Purchase4Gems) })
binding.gems21View?.setOnPurchaseClickListener(View.OnClickListener { purchaseGems(PurchaseTypes.Purchase21Gems) })
binding.gems42View?.setOnPurchaseClickListener(View.OnClickListener { purchaseGems(PurchaseTypes.Purchase42Gems) })
binding.gems84View?.setOnPurchaseClickListener(View.OnClickListener { purchaseGems(PurchaseTypes.Purchase84Gems) })
val heartDrawable = BitmapDrawable(resources, HabiticaIconsHelper.imageOfHeartLarge())
supportTextView?.setCompoundDrawablesWithIntrinsicBounds(null, null, null, heartDrawable)
binding.supportTextView?.setCompoundDrawablesWithIntrinsicBounds(null, null, null, heartDrawable)
compositeSubscription.add(userRepository.getUser().subscribe(Consumer {
subscriptionPromoView?.visibility = if (it.isSubscribed) View.GONE else View.VISIBLE
binding.subscriptionPromo.visibility = if (it.isSubscribed) View.GONE else View.VISIBLE
}, RxErrorHandler.handleEmptyError()))
giftGemsButton?.setOnClickListener { showGiftGemsDialog() }
binding.giftGemsButton?.setOnClickListener { showGiftGemsDialog() }
binding.giftSubscriptionContainer?.isVisible = appConfigManager.enableGiftOneGetOne()
binding.giftSubscriptionContainer.setOnClickListener { showGiftSubscriptionDialog() }
}
override fun setupCheckout() {
@ -91,10 +87,10 @@ class GemsPurchaseFragment : BaseFragment(), GemPurchaseActivity.CheckoutFragmen
private fun updateButtonLabel(sku: String, price: String) {
val matchingView: GemPurchaseOptionsView? = when (sku) {
PurchaseTypes.Purchase4Gems -> gems4View
PurchaseTypes.Purchase21Gems -> gems21View
PurchaseTypes.Purchase42Gems -> gems42View
PurchaseTypes.Purchase84Gems -> gems84View
PurchaseTypes.Purchase4Gems -> binding.gems4View
PurchaseTypes.Purchase21Gems -> binding.gems21View
PurchaseTypes.Purchase42Gems -> binding.gems42View
PurchaseTypes.Purchase84Gems -> binding.gems84View
else -> return
}
if (matchingView != null) {
@ -127,4 +123,25 @@ class GemsPurchaseFragment : BaseFragment(), GemPurchaseActivity.CheckoutFragmen
alert.show()
}
}
private fun showGiftSubscriptionDialog() {
val chooseRecipientDialogView = this.activity?.layoutInflater?.inflate(R.layout.dialog_choose_message_recipient, null)
this.activity?.let { thisActivity ->
val alert = HabiticaAlertDialog(thisActivity)
alert.setTitle(getString(R.string.gift_title))
alert.addButton(getString(R.string.action_continue), true) { _, _ ->
val usernameEditText = chooseRecipientDialogView?.findViewById<View>(R.id.uuidEditText) as? EditText
val intent = Intent(thisActivity, GiftSubscriptionActivity::class.java).apply {
putExtra("username", usernameEditText?.text.toString())
}
startActivity(intent)
}
alert.addCancelButton { _, _ ->
thisActivity.dismissKeyboard()
}
alert.setAdditionalContentView(chooseRecipientDialogView)
alert.show()
}
}
}

View file

@ -26,7 +26,6 @@ import com.habitrpg.android.habitica.ui.activities.GiftSubscriptionActivity
import com.habitrpg.android.habitica.ui.fragments.BaseFragment
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
import com.habitrpg.android.habitica.ui.helpers.dismissKeyboard
import com.habitrpg.android.habitica.ui.helpers.resetViews
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
import com.habitrpg.android.habitica.ui.views.subscriptions.SubscriptionOptionView
@ -77,8 +76,6 @@ class SubscriptionFragment : BaseFragment(), GemPurchaseActivity.CheckoutFragmen
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
resetViews()
subscriptionOptions?.visibility = View.GONE
binding.subscriptionDetails.visibility = View.GONE
binding.subscriptionDetails.onShowSubscriptionOptions = { showSubscriptionOptions() }