Finalize subscription page tweaks

This commit is contained in:
Phillip Thelen 2019-11-26 10:58:14 +01:00
parent 58fc185532
commit 636f51b4e4
9 changed files with 137 additions and 61 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 2309
versionCode 2314
versionName "2.4"
}

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="?colorPrimary"/>
<solid android:color="@color/brand_400"/>
<corners android:radius="20dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

View file

@ -73,7 +73,7 @@
<TextView
android:id="@+id/subscribeBenefitsTitle"
android:layout_width="match_parent"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="@string/subscribe_prompt"
android:gravity="center"
@ -81,8 +81,7 @@
android:textColor="@color/brand_300"
android:lineSpacingExtra="4dp"
android:layout_marginTop="8dp"
android:layout_marginLeft="26dp"
android:layout_marginRight="26dp"/>
android:layout_gravity="center_horizontal"/>
<ImageView
android:layout_width="wrap_content"
@ -246,7 +245,7 @@
android:src="@drawable/separator_fancy"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"/>
android:layout_marginBottom="12dp"/>
<ProgressBar
style="?android:attr/progressBarStyle"
@ -275,20 +274,16 @@
android:id="@+id/subscriptionOptions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="24dp"
>
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
style="@style/Subheader1"
android:textColor="@color/brand_300"
android:text="@string/subscribe_options_title"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"/>
<com.habitrpg.android.habitica.ui.views.subscriptions.SubscriptionOptionView

View file

@ -55,7 +55,7 @@
android:paddingEnd="@dimen/spacing_medium"
android:background="@color/green_50"
android:textColor="@color/white"
style="@style/Caption1"
style="@style/Caption2"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
tools:text="Save 20%"/>
@ -64,7 +64,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/descriptionTextView"
android:textColor="@color/gray_50"
tools:text="recurring every month"
/>
<LinearLayout
@ -76,6 +75,7 @@
android:layout_height="wrap_content"
tools:text="@string/subscribe1month.gemcap"
style="@style/Pill"
android:textSize="12sp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"/>
<TextView
@ -84,6 +84,7 @@
android:layout_height="wrap_content"
tools:text="+1 Mystic Hourglass"
style="@style/Pill"
android:textSize="12sp"
android:layout_marginTop="4dp"/>
</LinearLayout>
</LinearLayout>

View file

@ -74,6 +74,14 @@
android:id="@+id/subscriptionStatusCancelled"
android:layout_gravity="center_vertical"
android:visibility="gone"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/group_plan"
style="@style/Pill.Selected"
android:id="@+id/subscription_status_group_plan"
android:layout_gravity="center_vertical"
android:visibility="gone"/>
</LinearLayout>
<LinearLayout
android:id="@+id/payment_processor_wrapper"
@ -116,6 +124,24 @@
android:text="@string/current_bonuses"
style="@style/subscriptionBoxText.Title"
android:layout_marginBottom="4dp"/>
<LinearLayout
android:id="@+id/subscription_credit_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/subscription_credit"
style="@style/subscriptionBoxText.Subtitle"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Pill"
android:id="@+id/subscription_credit_text_view"
tools:text="32 Months" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -194,7 +220,8 @@
android:layout_height="32dp"
android:text="@string/visit_website"
android:layout_gravity="center"
style="@style/HabiticaButton.Purple"/>
style="@style/HabiticaButton.Purple"
android:layout_marginTop="@dimen/spacing_medium"/>
</LinearLayout>
</LinearLayout>

View file

@ -361,7 +361,7 @@
<string name="google_services_missing">Google play services could not be found.</string>
<string name="gem_purchase_toolbartitle">Purchase</string>
<string name="gem_purchase_title">Buying gems supports the developers and helps keep Habitica running</string>
<string name="gem_purchase_subtitle">Gems allow you to buy fun extras for you account, including:</string>
<string name="gem_purchase_subtitle">Gems allow you to buy fun extras for your account, including:</string>
<string name="gem_purchase_listitem1">Cool costumes for your avatar</string>
<string name="gem_purchase_listitem2">Awesome backgrounds</string>
<string name="gem_purchase_listitem3">Quests that reward you with pet eggs</string>
@ -382,7 +382,7 @@
<string name="has_reminder">Has Reminder</string>
<string name="has_tag">Has Tag</string>
<string name="subscribe_title">Subscribing supports the developers and helps keep Habitica running</string>
<string name="subscribe_prompt">Become a subscriber and youll get these useful benefits:</string>
<string name="subscribe_prompt">Become a subscriber to receive these exclusive benefits!</string>
<string name="subscribe_listitem1">Gold for Gems</string>
<string name="subscribe_listitem2">Mystic Hourglasses</string>
<string name="subscribe_listitem3">Monthly Mystery Items</string>
@ -409,7 +409,7 @@
<string name="due">Due</string>
<string name="cancel_subscription">Cancel Subscription</string>
<string name="cancel_subscription_google_description">No longer want to subscribe? You can find the option to unsubscribe in the “My Apps” section of the Google Play Store.</string>
<string name="cancel_subscription_notgoogle_description">No longer want to subscribe? Due to your payment method, you can only unsubscribe through the website. Click the button below, to open the site in your browser!</string>
<string name="cancel_subscription_notgoogle_description">No longer want to subscribe? Due to constraints on mobile payments, you\'ll need to cancel via our website. To do this, tap the button below, log in to your account, tap the User icon in the top right, then go to Subscription. We\'ll miss you!</string>
<string name="visit_habitica_website">Visit Habitica Website</string>
<string name="current_bonuses">Current Bonuses</string>
<string name="months_subscribed">Months subscribed</string>
@ -422,7 +422,7 @@
<string name="three_months">3 months</string>
<string name="six_months">6 months</string>
<string name="twelve_months">12 months</string>
<string name="subscribe_prompt_thanks">For Subscribing you are receiving these useful benefits:</string>
<string name="subscribe_prompt_thanks">You get these benefits for being a Subscriber</string>
<string name="subscription_status">Subscription Status</string>
<string name="challenge_leave_title">Leave Challenge</string>
@ -906,4 +906,10 @@
<string name="resubscribe_description">Want to continue your benefits? You can start a new subscription before this one runs out to keep your benefits active.</string>
<string name="gifted">Gifted</string>
<string name="save_20">Save 20%</string>
<string name="subscription_credit">Subscription Credit</string>
<string name="group_plan">Group Plan</string>
<string name="cancel_subscription_group_plan">"You have a free subscription because you are a member a Party or Guild that has a Group Plan. This will end if you leave or the Group Plan is cancelled by the owner. Any months of extra subscription credit you have will be applied at the end of the Group Plan. "</string>
<string name="cancel_subscription_group_plan_owner">"You have a free subscription because you are an owner of a Party or Guild that has a Group Plan. This will end if you cancel the plan. Any months of extra subscription credit you have will be applied at the end of the Group Plan. You can cancel from the Habitica website. "</string>
<string name="owner">Owner</string>
<string name="member">Member</string>
</resources>

View file

@ -2,6 +2,8 @@ package com.habitrpg.android.habitica.models.user;
import androidx.annotation.Nullable;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
import io.realm.RealmObject;
@ -33,6 +35,16 @@ public class SubscriptionPlan extends RealmObject {
public SubscriptionPlanConsecutive consecutive;
public int mysteryItemCount;
@SerializedName("owner")
public String ownerID;
public boolean isGroupPlanSub() {
return customerId.equals("group-plan");
}
public boolean isGiftedSub() {
return customerId.equals("Gift");
}
public boolean isActive() {
Date today = new Date();
@ -51,6 +63,7 @@ public class SubscriptionPlan extends RealmObject {
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
if (consecutive != null && !consecutive.isManaged()) {

View file

@ -1,7 +1,6 @@
package com.habitrpg.android.habitica.ui.fragments.purchases
import android.content.Intent
import android.graphics.drawable.BitmapDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@ -26,11 +25,9 @@ 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.views.HabiticaIconsHelper
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
import com.habitrpg.android.habitica.ui.views.subscriptions.SubscriptionOptionView
import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.fragment_subscription.*
import org.greenrobot.eventbus.Subscribe
import org.solovyev.android.checkout.Inventory
import org.solovyev.android.checkout.Sku
@ -58,25 +55,21 @@ class SubscriptionFragment : BaseFragment(), GemPurchaseActivity.CheckoutFragmen
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState)
fetchUser(null)
binding = FragmentSubscriptionBinding.inflate(inflater, container, false)
return binding.root
}
@Subscribe
fun fetchUser(event: UserSubscribedEvent?) {
compositeSubscription.add(userRepository.retrieveUser(false, true).subscribe(Consumer { this.setUser(it) }, RxErrorHandler.handleEmptyError()))
compositeSubscription.add(userRepository.retrieveUser(withTasks = false, forced = true).subscribe(Consumer { this.setUser(it) }, RxErrorHandler.handleEmptyError()))
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
subscriptionOptions?.visibility = View.GONE
binding.subscriptionOptions.visibility = View.GONE
binding.subscriptionDetails.visibility = View.GONE
binding.subscriptionDetails.onShowSubscriptionOptions = { showSubscriptionOptions() }
@ -88,10 +81,7 @@ class SubscriptionFragment : BaseFragment(), GemPurchaseActivity.CheckoutFragmen
binding.subscription6month.setOnPurchaseClickListener(View.OnClickListener { selectSubscription(PurchaseTypes.Subscription6Month) })
binding.subscription12month.setOnPurchaseClickListener(View.OnClickListener { selectSubscription(PurchaseTypes.Subscription12Month) })
val heartDrawable = BitmapDrawable(resources, HabiticaIconsHelper.imageOfHeartLarge())
supportTextView?.setCompoundDrawablesWithIntrinsicBounds(null, null, null, heartDrawable)
subscribeButton.setOnClickListener { subscribeUser() }
binding.subscribeButton.setOnClickListener { subscribeUser() }
binding.giftSubscriptionContainer?.isVisible = appConfigManager.enableGiftOneGetOne()
@ -192,25 +182,27 @@ class SubscriptionFragment : BaseFragment(), GemPurchaseActivity.CheckoutFragmen
if (isSubscribed) {
binding.headerImageView?.setImageResource(R.drawable.subscriber_header)
binding.subscriptionDetails.visibility = View.VISIBLE
binding.subscriptionDetails.currentUserID = user?.id
user?.purchased?.plan?.let { binding.subscriptionDetails.setPlan(it) }
subscribeBenefitsTitle?.setText(R.string.subscribe_prompt_thanks)
subscriptionOptions?.visibility = View.GONE
binding.subscribeBenefitsTitle.setText(R.string.subscribe_prompt_thanks)
binding.subscriptionOptions.visibility = View.GONE
} else {
binding.headerImageView.setImageResource(R.drawable.subscribe_header)
if (!hasLoadedSubscriptionOptions) {
return
}
subscriptionOptions?.visibility = View.VISIBLE
binding.subscriptionOptions.visibility = View.VISIBLE
binding.subscriptionDetails.visibility = View.GONE
binding.subscribeBenefitsTitle.setText(R.string.subscribe_prompt)
}
loadingIndicator?.visibility = View.GONE
binding.loadingIndicator.visibility = View.GONE
}
}
private fun showSubscriptionOptions() {
subscriptionOptions?.visibility = View.VISIBLE
subscriptionOptions?.postDelayed({
binding.scrollView.smoothScrollTo(0, subscriptionOptions?.top ?: 0)
binding.subscriptionOptions.visibility = View.VISIBLE
binding.subscriptionOptions.postDelayed({
binding.scrollView.smoothScrollTo(0, binding.subscriptionOptions.top ?: 0)
}, 500)
}

View file

@ -24,6 +24,8 @@ class SubscriptionDetailsView : LinearLayout {
var onShowSubscriptionOptions: (() -> Unit)? = null
var currentUserID: String? = null
constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet) {
setupView()
}
@ -41,26 +43,7 @@ class SubscriptionDetailsView : LinearLayout {
fun setPlan(plan: SubscriptionPlan) {
this.plan = plan
if (plan.isActive) {
if (plan.dateTerminated != null) {
if (plan.customerId == "Gift") {
binding.subscriptionStatusNotRecurring.visibility = View.VISIBLE
binding.subscriptionStatusCancelled.visibility = View.GONE
} else {
binding.subscriptionStatusNotRecurring.visibility = View.GONE
binding.subscriptionStatusCancelled.visibility = View.VISIBLE
}
binding.subscriptionStatusActive.visibility = View.GONE
} else {
binding.subscriptionStatusActive.visibility = View.VISIBLE
binding.subscriptionStatusNotRecurring.visibility = View.GONE
}
binding.subscriptionStatusInactive.visibility = View.GONE
} else {
binding.subscriptionStatusActive.visibility = View.GONE
binding.subscriptionStatusInactive.visibility = View.VISIBLE
binding.subscriptionStatusNotRecurring.visibility = View.GONE
}
updateSubscriptionStatusPill(plan)
var duration: String? = null
@ -78,10 +61,27 @@ class SubscriptionDetailsView : LinearLayout {
if (duration != null) {
binding.subscriptionDurationTextView.text = resources.getString(R.string.subscription_duration, duration)
} else if (plan.isGroupPlanSub) {
if (plan.ownerID == currentUserID) {
binding.subscriptionDurationTextView.setText(R.string.owner)
} else {
binding.subscriptionDurationTextView.setText(R.string.member)
}
} else if (plan.dateTerminated != null) {
binding.subscriptionDurationTextView.text = resources.getString(R.string.ending_on, DateFormat.getDateInstance().format(plan.dateTerminated ?: Date()))
}
if (plan.extraMonths > 0) {
binding.subscriptionCreditWrapper.visibility = View.VISIBLE
if (plan.extraMonths == 1) {
binding.subscriptionCreditTextView.text = resources.getString(R.string.one_month)
} else {
binding.subscriptionCreditTextView.text = resources.getString(R.string.x_months, plan.extraMonths)
}
} else {
binding.subscriptionCreditWrapper.visibility = View.GONE
}
when (plan.paymentMethod) {
"Amazon Payments" -> binding.paymentProcessorImageView.setImageResource(R.drawable.payment_amazon)
"Apple" -> binding.paymentProcessorImageView.setImageResource(R.drawable.payment_apple)
@ -89,7 +89,7 @@ class SubscriptionDetailsView : LinearLayout {
"PayPal" -> binding.paymentProcessorImageView.setImageResource(R.drawable.payment_paypal)
"Stripe" -> binding.paymentProcessorImageView.setImageResource(R.drawable.payment_stripe)
else -> {
if (plan.customerId == "Gift") {
if (plan.isGiftedSub) {
binding.paymentProcessorImageView.setImageResource(R.drawable.payment_gift)
binding.subscriptionPaymentMethodTextview.text = context.getString(R.string.gifted)
} else {
@ -106,13 +106,23 @@ class SubscriptionDetailsView : LinearLayout {
binding.gemCapTextView.text = plan.totalNumberOfGems().toString()
binding.currentHourglassesTextView.text = plan.consecutive?.trinkets.toString()
binding.changeSubscriptionButton.visibility = View.VISIBLE
if (plan.paymentMethod != null) {
binding.changeSubscriptionTitle.setText(R.string.cancel_subscription)
if (plan.paymentMethod == "Google") {
binding.changeSubscriptionDescription.setText(R.string.cancel_subscription_google_description)
binding.changeSubscriptionButton.setText(R.string.open_in_store)
} else {
binding.changeSubscriptionDescription.setText(R.string.cancel_subscription_notgoogle_description)
if (plan.isGroupPlanSub) {
if (plan.ownerID == currentUserID) {
binding.changeSubscriptionDescription.setText(R.string.cancel_subscription_group_plan_owner)
} else {
binding.changeSubscriptionDescription.setText(R.string.cancel_subscription_group_plan)
binding.changeSubscriptionButton.visibility = View.GONE
}
} else {
binding.changeSubscriptionDescription.setText(R.string.cancel_subscription_notgoogle_description)
}
binding.changeSubscriptionButton.setText(R.string.visit_habitica_website)
}
}
@ -123,6 +133,38 @@ class SubscriptionDetailsView : LinearLayout {
}
}
private fun updateSubscriptionStatusPill(plan: SubscriptionPlan) {
if (plan.isActive) {
if (plan.dateTerminated != null) {
if (plan.isGiftedSub) {
binding.subscriptionStatusNotRecurring.visibility = View.VISIBLE
binding.subscriptionStatusCancelled.visibility = View.GONE
} else {
binding.subscriptionStatusNotRecurring.visibility = View.GONE
binding.subscriptionStatusCancelled.visibility = View.VISIBLE
}
binding.subscriptionStatusActive.visibility = View.GONE
binding.subscriptionStatusGroupPlan.visibility = View.GONE
} else {
if (plan.isGroupPlanSub) {
binding.subscriptionStatusGroupPlan.visibility = View.VISIBLE
binding.subscriptionStatusActive.visibility = View.GONE
binding.subscriptionStatusNotRecurring.visibility = View.GONE
} else {
binding.subscriptionStatusActive.visibility = View.VISIBLE
binding.subscriptionStatusNotRecurring.visibility = View.GONE
binding.subscriptionStatusGroupPlan.visibility = View.GONE
}
}
binding.subscriptionStatusInactive.visibility = View.GONE
} else {
binding.subscriptionStatusActive.visibility = View.GONE
binding.subscriptionStatusInactive.visibility = View.VISIBLE
binding.subscriptionStatusNotRecurring.visibility = View.GONE
binding.subscriptionStatusGroupPlan.visibility = View.GONE
}
}
private fun changeSubscriptionButtonTapped() {
if (plan?.paymentMethod != null) {
val url = if (plan?.paymentMethod == "Google") {