Implement gifting gems

This commit is contained in:
Phillip Thelen 2019-10-07 18:35:08 +02:00
parent 46324bb0eb
commit edc62302a2
17 changed files with 409 additions and 36 deletions

View file

@ -99,9 +99,13 @@
android:label="@string/app_name">
</activity>
<activity
android:name=".ui.activities.GiftIAPActivity"
android:name=".ui.activities.GiftSubscriptionActivity"
android:label="@string/gift_subscription">
</activity>
<activity
android:name=".ui.activities.GiftGemsActivity"
android:label="@string/gift_gems">
</activity>
<activity
android:name=".ui.activities.GuidelinesActivity"
android:label="@string/community_guidelines">

Binary file not shown.

After

Width:  |  Height:  |  Size: 5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

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="@color/task_gray" />
<solid android:color="@color/gray_500" />
<corners android:radius="@dimen/bar_radius"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

View file

@ -138,13 +138,12 @@
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/profile_blurb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:text="Blurb" />
tools:text="Blurb" />
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/profile_image"
@ -152,7 +151,8 @@
android:layout_height="match_parent"
android:layout_margin="5dp"
android:minHeight="200dp"
fresco:actualImageScaleType="fitCenter" />
fresco:actualImageScaleType="fitCenter"
android:visibility="gone"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -207,6 +207,47 @@
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
style="@style/CardView.Default"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/buttonBarStyle">
<Button
android:id="@+id/send_message_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/profile_send_message"
style="?android:attr/buttonBarButtonStyle"
android:textAllCaps="false"
android:textSize="13sp"
android:drawableTop="@drawable/icon_messages"/>
<Button
android:id="@+id/gift_gems_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/profile_gift_gems"
style="?android:attr/buttonBarButtonStyle"
android:textAllCaps="false"
android:textSize="13sp"
android:drawableTop="@drawable/icon_gift_gems"/>
<Button
android:id="@+id/gift_subscription_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/profile_gift_subscription"
style="?android:attr/buttonBarButtonStyle"
android:textAllCaps="false"
android:textSize="13sp"
android:drawableTop="@drawable/icon_gift_subscription"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
style="@style/CardView.Default"
android:layout_width="match_parent"

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.habitrpg.android.habitica.ui.activities.FixCharacterValuesActivity"
android:background="@color/white">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="@style/Toolbar"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="@dimen/spacing_large">
<com.habitrpg.android.habitica.ui.AvatarView
android:id="@+id/avatar_view"
android:layout_width="88dp"
android:layout_height="84dp"
app:showBackground="false"
app:showPet="false"
app:showMount="false"
app:showSleeping="false"
android:layout_gravity="center_horizontal"/>
<com.habitrpg.android.habitica.ui.views.social.UsernameLabel
android:id="@+id/display_name_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
/>
<TextView
android:id="@+id/username_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/gray_300"
android:textSize="12sp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="@dimen/spacing_large"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:text="@string/gift_gems_subtitle"
android:textColor="@color/gray_300"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginRight="@dimen/spacing_large"
android:layout_marginBottom="@dimen/spacing_large"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="16dp">
<com.habitrpg.android.habitica.ui.GemPurchaseOptionsView
android:id="@+id/gems_4_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:gemAmount="4"
app:gemDrawable="@drawable/gems_4"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
/>
<com.habitrpg.android.habitica.ui.GemPurchaseOptionsView
android:id="@+id/gems_21_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:gemAmount="21"
app:gemDrawable="@drawable/gems_21" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:dividerPadding="16dp"
android:showDividers="middle"
android:divider="@android:color/white">
<com.habitrpg.android.habitica.ui.GemPurchaseOptionsView
android:id="@+id/gems_42_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:gemAmount="42"
app:gemDrawable="@drawable/gems_42"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp" />
<com.habitrpg.android.habitica.ui.GemPurchaseOptionsView
android:id="@+id/gems_84_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:gemAmount="84"
app:gemDrawable="@drawable/gems_84" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>

View file

@ -149,6 +149,32 @@
app:argType="boolean"
android:defaultValue="false" />
</activity>
<activity
android:id="@+id/giftGemsActivity"
android:name="com.habitrpg.android.habitica.ui.activities.GiftGemsActivity"
android:label="@string/gift_gems" >
<argument
android:name="userID"
app:argType="string"
app:nullable="true" />
<argument
android:name="username"
app:argType="string"
app:nullable="true" />
</activity>
<activity
android:id="@+id/giftSubscriptionActivity"
android:name="com.habitrpg.android.habitica.ui.activities.GiftSubscriptionActivity"
android:label="@string/gift_subscription" >
<argument
android:name="userID"
app:argType="string"
app:nullable="true" />
<argument
android:name="username"
app:argType="string"
app:nullable="true" />
</activity>
<fragment
android:id="@+id/newsFragment"
android:name="com.habitrpg.android.habitica.ui.fragments.NewsFragment"

View file

@ -703,17 +703,19 @@
<string name="equipment_per">PER:</string>
<string name="visit_website">visit website</string>
<string name="subscribe_gift_description">Want to give the benefits of a subscription to someone else?</string>
<string name="gift_subscription">Gift a Subscription</string>
<string name="gift_subscription">Gift Subscription</string>
<string name="gift_one_get_one_description">Gift a sub and get a sub free event going on now!</string>
<string name="gift_title">Who would you like to gift to?</string>
<string name="gift_one_get_one">Gift one, Get one!</string>
<string name="gift_one_get_one_detailed_description">While this promotion is active, youll receive a matching subscription automatically after sending your gift.</string>
<string name="gift_subscription_subtitle">Choose the subscription youd like to gift below! This purchase wont automatically renew.</string>
<string name="gift_gems_subtitle">Choose the gem packet youd like to gift below!</string>
<string name="send_gift">Send Gift</string>
<string name="server">Server</string>
<string name="gift_confirmation_title">Your gift was sent!</string>
<string name="gift_confirmation_text_g1g1">You sent %s a %s-month Habitica subscription and the same subscription was applied to your account for our Gift One Get One promotion!</string>
<string name="gift_confirmation_text">You sent %s a %s-month Habitica subscription.</string>
<string name="gift_confirmation_text_sub_g1g1">You sent %s a %s-month Habitica subscription and the same subscription was applied to your account for our Gift One Get One promotion!</string>
<string name="gift_confirmation_text_sub">You sent %s a %s-month Habitica subscription.</string>
<string name="gift_confirmation_text_gems">You sent %s %s gems.</string>
<string name="discover">Discover</string>
<string name="damage_paused">Damage paused</string>
<string name="preference_push_important_announcements">Important Announcements</string>
@ -848,4 +850,8 @@
<string name="promo_subscription_buy_gems_prompt">Need Gems?</string>
<string name="promo_subscription_buy_gems_description">Become a Subscriber to buy Gems with gold, get monthly mystery items, increased drop caps and more!</string>
<string name="see_other_options">See other Options</string>
<string name="gift_gems">Gift Gems</string>
<string name="profile_send_message">Send\nMessage</string>
<string name="profile_gift_gems">Gift\nGems</string>
<string name="profile_gift_subscription">Gift\nSubscription</string>
</resources>

View file

@ -18,7 +18,8 @@ import com.habitrpg.android.habitica.ui.activities.ClassSelectionActivity;
import com.habitrpg.android.habitica.ui.activities.FixCharacterValuesActivity;
import com.habitrpg.android.habitica.ui.activities.FullProfileActivity;
import com.habitrpg.android.habitica.ui.activities.GemPurchaseActivity;
import com.habitrpg.android.habitica.ui.activities.GiftIAPActivity;
import com.habitrpg.android.habitica.ui.activities.GiftGemsActivity;
import com.habitrpg.android.habitica.ui.activities.GiftSubscriptionActivity;
import com.habitrpg.android.habitica.ui.activities.GroupFormActivity;
import com.habitrpg.android.habitica.ui.activities.GroupInviteActivity;
import com.habitrpg.android.habitica.ui.activities.HabitButtonWidgetActivity;
@ -302,7 +303,7 @@ public interface UserComponent {
void inject(@NotNull ChatFragment chatFragment);
void inject(@NotNull GiftIAPActivity giftIAPActivity);
void inject(@NotNull GiftSubscriptionActivity giftSubscriptionActivity);
void inject(@NotNull AboutFragment aboutFragment);
@ -319,4 +320,6 @@ public interface UserComponent {
void inject(@NotNull InboxViewModel inboxViewModel);
void inject(@NotNull InsufficientGemsDialog insufficientGemsDialog);
void inject(@NotNull GiftGemsActivity giftGemsActivity);
}

View file

@ -16,6 +16,8 @@ import io.reactivex.Single
import io.reactivex.functions.BiFunction
import io.reactivex.functions.Consumer
import io.realm.RealmResults
import java.util.*
import kotlin.collections.HashMap
class SocialRepositoryImpl(localRepository: SocialLocalRepository, apiClient: ApiClient, userID: String) : BaseRepositoryImpl<SocialLocalRepository>(localRepository, apiClient, userID), SocialRepository {
override fun transferGroupOwnership(groupID: String, userID: String): Flowable<Group> {
@ -247,13 +249,17 @@ class SocialRepositoryImpl(localRepository: SocialLocalRepository, apiClient: Ap
override fun getMember(userId: String?): Flowable<Member> {
return if (userId == null) {
Flowable.empty()
} else apiClient.getMember(userId)
} else {
try {
apiClient.getMember(UUID.fromString(userId).toString())
} catch(_: IllegalArgumentException) {
apiClient.getMemberWithUsername(userId)
}
}
}
override fun getMemberWithUsername(username: String?): Flowable<Member> {
return if (username == null) {
Flowable.empty()
} else apiClient.getMemberWithUsername(username)
return getMember(username)
}
override fun findUsernames(username: String, context: String?, id: String?): Flowable<List<FindUsernameResult>> {

View file

@ -162,9 +162,8 @@ class PurchaseHandler(activity: Activity, val crashlyticsProxy: CrashlyticsProxy
}
}
fun purchaseGiftedSubscription(sku: Sku, giftedUserID: String?) {
fun purchaseNoRenewSubscription(sku: Sku) {
checkout?.let {
HabiticaPurchaseVerifier.pendingGifts[sku.id.code] = giftedUserID
billingRequests?.purchase(ProductTypes.IN_APP, sku.id.code, null, it.createOneShotPurchaseFlow(object : RequestListener<Purchase> {
override fun onSuccess(result: Purchase) {
billingRequests?.consume(result.token, object : RequestListener<Any> {

View file

@ -3,11 +3,15 @@ package com.habitrpg.android.habitica.ui.activities
import android.content.Context
import android.graphics.Typeface
import android.os.Bundle
import android.view.*
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import com.facebook.drawee.backends.pipeline.Fresco
import com.facebook.drawee.controller.BaseControllerListener
import com.facebook.drawee.view.SimpleDraweeView
@ -77,6 +81,9 @@ class FullProfileActivity : BaseActivity() {
private val joinedView: TextView by bindView(R.id.joined_view)
private val lastLoginView: TextView by bindView(R.id.last_login_view)
private val totalCheckinsView: TextView by bindView(R.id.total_checkins_view)
private val sendMessageButton: Button by bindView(R.id.send_message_button)
private val giftGemsButton: Button by bindView(R.id.gift_gems_button)
private val giftSubscriptionButton: Button by bindView(R.id.gift_subscription_button)
private var userID = ""
private var userName: String? = null
@ -110,6 +117,10 @@ class FullProfileActivity : BaseActivity() {
attributesCardView.setOnClickListener { toggleAttributeDetails() }
avatarWithBars = AvatarWithBarsViewModel(this, avatarWithStatsView)
sendMessageButton.setOnClickListener { showSendMessageToUserDialog() }
giftGemsButton.setOnClickListener { MainNavigationController.navigate(R.id.giftGemsActivity, bundleOf(Pair("userID", userID), Pair("username", null))) }
giftSubscriptionButton.setOnClickListener { MainNavigationController.navigate(R.id.giftSubscriptionActivity, bundleOf(Pair("userID", userID), Pair("username", null))) }
}
override fun onDestroy() {
@ -119,10 +130,6 @@ class FullProfileActivity : BaseActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.private_message -> {
showSendMessageToUserDialog()
true
}
android.R.id.home -> {
// app icon in action bar clicked; goto parent activity.
this.finish()
@ -452,12 +459,6 @@ class FullProfileActivity : BaseActivity() {
component?.inject(this)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.menu_full_profile, menu)
return true
}
companion object {
fun open(userId: String) {

View file

@ -0,0 +1,162 @@
package com.habitrpg.android.habitica.ui.activities
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import android.view.View
import android.widget.TextView
import androidx.appcompat.widget.Toolbar
import androidx.navigation.navArgs
import com.habitrpg.android.habitica.HabiticaPurchaseVerifier
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.UserComponent
import com.habitrpg.android.habitica.data.SocialRepository
import com.habitrpg.android.habitica.events.ConsumablePurchasedEvent
import com.habitrpg.android.habitica.extensions.addOkButton
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
import com.habitrpg.android.habitica.proxy.CrashlyticsProxy
import com.habitrpg.android.habitica.ui.AvatarView
import com.habitrpg.android.habitica.ui.GemPurchaseOptionsView
import com.habitrpg.android.habitica.ui.helpers.bindView
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
import com.habitrpg.android.habitica.ui.views.social.UsernameLabel
import io.reactivex.functions.Consumer
import org.greenrobot.eventbus.Subscribe
import javax.inject.Inject
class GiftGemsActivity : BaseActivity() {
@Inject
lateinit var crashlyticsProxy: CrashlyticsProxy
@Inject
lateinit var socialRepository: SocialRepository
@Inject
lateinit var appConfigManager: AppConfigManager
private var purchaseHandler: PurchaseHandler? = null
private val toolbar: Toolbar by bindView(R.id.toolbar)
private val avatarView: AvatarView by bindView(R.id.avatar_view)
private val displayNameTextView: UsernameLabel by bindView(R.id.display_name_textview)
private val usernameTextView: TextView by bindView(R.id.username_textview)
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 var giftedUsername: String? = null
private var giftedUserID: String? = null
override fun getLayoutResId(): Int {
return R.layout.activity_gift_gems
}
override fun injectActivity(component: UserComponent?) {
component?.inject(this)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setTitle(R.string.gift_gems)
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
giftedUserID = intent.getStringExtra("userID") ?: navArgs<GiftGemsActivityArgs>().value.userID
giftedUsername = intent.getStringExtra("username") ?: navArgs<GiftGemsActivityArgs>().value.username
compositeSubscription.add(socialRepository.getMember(giftedUsername ?: giftedUserID).subscribe(Consumer {
avatarView.setAvatar(it)
displayNameTextView.username = it.profile?.name
displayNameTextView.tier = it.contributor?.level ?: 0
usernameTextView.text = "@${it.username}"
giftedUserID = it.id
giftedUsername = it.username
}, RxErrorHandler.handleEmptyError()))
purchaseHandler?.getAllGemSKUs { skus ->
for (sku in skus) {
updateButtonLabel(sku.id.code, sku.price)
}
}
}
override fun onStart() {
super.onStart()
purchaseHandler = PurchaseHandler(this, crashlyticsProxy)
purchaseHandler?.startListening()
}
override fun onResume() {
super.onResume()
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) })
}
override fun onStop() {
purchaseHandler?.stopListening()
super.onStop()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
purchaseHandler?.onResult(requestCode, resultCode, data)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
finish()
}
return super.onOptionsItemSelected(item)
}
private fun updateButtonLabel(sku: String, price: String) {
val matchingView: GemPurchaseOptionsView? = when (sku) {
PurchaseTypes.Purchase4Gems -> gems4View
PurchaseTypes.Purchase21Gems -> gems21View
PurchaseTypes.Purchase42Gems -> gems42View
PurchaseTypes.Purchase84Gems -> gems84View
else -> return
}
if (matchingView != null) {
matchingView.setPurchaseButtonText(price)
matchingView.sku = sku
}
}
@Subscribe
fun onConsumablePurchased(event: ConsumablePurchasedEvent) {
purchaseHandler?.consumePurchase(event.purchase)
runOnUiThread {
displayConfirmationDialog()
}
}
private fun displayConfirmationDialog() {
val message = getString(R.string.gift_confirmation_text_gems, giftedUsername, "1")
val alert = HabiticaAlertDialog(this)
alert.setTitle(R.string.gift_confirmation_title)
alert.setMessage(message)
alert.addOkButton { dialog, _ ->
dialog.dismiss()
finish()
}
alert.enqueue()
}
fun purchaseGems(identifier: String) {
HabiticaPurchaseVerifier.pendingGifts[identifier] = giftedUserID
purchaseHandler?.purchaseGems(identifier)
}
}

View file

@ -9,6 +9,8 @@ import android.widget.Button
import android.widget.TextView
import androidx.appcompat.widget.Toolbar
import androidx.core.view.isVisible
import androidx.navigation.navArgs
import com.habitrpg.android.habitica.HabiticaPurchaseVerifier
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.UserComponent
import com.habitrpg.android.habitica.data.SocialRepository
@ -32,7 +34,7 @@ import org.solovyev.android.checkout.Sku
import javax.inject.Inject
class GiftIAPActivity: BaseActivity() {
class GiftSubscriptionActivity : BaseActivity() {
@Inject
lateinit var crashlyticsProxy: CrashlyticsProxy
@ -65,7 +67,7 @@ class GiftIAPActivity: BaseActivity() {
private var skus: List<Sku> = emptyList()
override fun getLayoutResId(): Int {
return R.layout.activity_gift_iap
return R.layout.activity_gift_subscription
}
override fun injectActivity(component: UserComponent?) {
@ -81,7 +83,8 @@ class GiftIAPActivity: BaseActivity() {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
giftedUsername = intent.getStringExtra("username")
giftedUserID = intent.getStringExtra("userID") ?: navArgs<GiftSubscriptionActivityArgs>().value.userID
giftedUsername = intent.getStringExtra("username") ?: navArgs<GiftSubscriptionActivityArgs>().value.username
subscriptionButton?.setOnClickListener {
selectedSubscriptionSku?.let { sku -> purchaseSubscription(sku) }
@ -89,12 +92,13 @@ class GiftIAPActivity: BaseActivity() {
giftOneGetOneContainer?.isVisible = appConfigManager.enableGiftOneGetOne()
compositeSubscription.add(socialRepository.getMemberWithUsername(giftedUsername).subscribe(Consumer {
compositeSubscription.add(socialRepository.getMember(giftedUsername ?: giftedUserID).subscribe(Consumer {
avatarView.setAvatar(it)
displayNameTextView.username = it.profile?.name
displayNameTextView.tier = it.contributor?.level ?: 0
usernameTextView.text = "@${it.username}"
giftedUserID = it.id
giftedUsername = it.username
}, RxErrorHandler.handleEmptyError()))
}
@ -179,7 +183,8 @@ class GiftIAPActivity: BaseActivity() {
if (giftedUserID?.isNotEmpty() != true) {
return
}
purchaseHandler?.purchaseGiftedSubscription(sku, giftedUserID)
HabiticaPurchaseVerifier.pendingGifts[sku.id.code] = giftedUserID
purchaseHandler?.purchaseNoRenewSubscription(sku)
}
@ -203,9 +208,9 @@ class GiftIAPActivity: BaseActivity() {
private fun displayConfirmationDialog() {
val message = getString(if (appConfigManager.enableGiftOneGetOne()){
R.string.gift_confirmation_text_g1g1
R.string.gift_confirmation_text_sub_g1g1
} else {
R.string.gift_confirmation_text
R.string.gift_confirmation_text_sub
}, giftedUsername, selectedDurationString())
val alert = HabiticaAlertDialog(this)
alert.setTitle(R.string.gift_confirmation_title)

View file

@ -20,7 +20,7 @@ import com.habitrpg.android.habitica.helpers.RxErrorHandler
import com.habitrpg.android.habitica.models.user.User
import com.habitrpg.android.habitica.proxy.CrashlyticsProxy
import com.habitrpg.android.habitica.ui.activities.GemPurchaseActivity
import com.habitrpg.android.habitica.ui.activities.GiftIAPActivity
import com.habitrpg.android.habitica.ui.activities.GiftSubscriptionActivity
import com.habitrpg.android.habitica.ui.helpers.bindOptionalView
import com.habitrpg.android.habitica.ui.helpers.bindView
import com.habitrpg.android.habitica.ui.helpers.dismissKeyboard
@ -247,7 +247,7 @@ class SubscriptionFragment : BaseFragment(), GemPurchaseActivity.CheckoutFragmen
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, GiftIAPActivity::class.java).apply {
val intent = Intent(thisActivity, GiftSubscriptionActivity::class.java).apply {
putExtra("username", usernameEditText?.text.toString())
}
startActivity(intent)