mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-24 06:35:46 +00:00
Add option to gift gems from balance
This commit is contained in:
parent
81a4ff50f8
commit
683d3e520b
20 changed files with 493 additions and 185 deletions
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<!-- view background color -->
|
||||
<solid
|
||||
android:color="@color/brand_400" >
|
||||
android:color="@color/brand_300" >
|
||||
</solid>
|
||||
|
||||
<!-- Here is the corner radius -->
|
||||
|
|
|
|||
|
|
@ -1,127 +1,56 @@
|
|||
<?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"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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
|
||||
<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="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:layout_height="match_parent"
|
||||
tools:context=".ui.activities.PrefsActivity"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:background="@color/white">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
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_height="wrap_content">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
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_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_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>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/gift_gems_disclaimer"
|
||||
android:gravity="center"
|
||||
android:layout_marginStart="@dimen/spacing_large"
|
||||
android:layout_marginEnd="@dimen/spacing_large"
|
||||
android:layout_marginBottom="@dimen/spacing_large"
|
||||
style="@style/Caption2"/>
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</LinearLayout>
|
||||
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>
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tab_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:elevation="0dp"
|
||||
android:fillViewport="false"
|
||||
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
app:layout_anchor="@+id/collapsing_toolbar"
|
||||
app:layout_anchorGravity="bottom"
|
||||
|
||||
app:layout_collapseMode="pin"
|
||||
app:tabGravity="fill"
|
||||
app:tabIndicatorColor="@android:color/white"
|
||||
app:tabMode="fixed" />
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:id="@+id/viewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0px"
|
||||
android:layout_weight="1"
|
||||
android:background="@android:color/white" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
|
|
|||
80
Habitica/res/layout/fragment_gift_gem_balance.xml
Normal file
80
Habitica/res/layout/fragment_gift_gem_balance.xml
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.core.widget.NestedScrollView android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<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_balance_subtitle"
|
||||
android:textColor="@color/gray_300"
|
||||
android:layout_marginLeft="@dimen/spacing_large"
|
||||
android:layout_marginRight="@dimen/spacing_large"
|
||||
android:layout_marginBottom="@dimen/spacing_large"/>
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/spacing_large"
|
||||
android:layout_marginEnd="@dimen/spacing_large"
|
||||
android:layout_marginBottom="@dimen/spacing_medium"
|
||||
android:theme="@style/TextInputLayoutAppearanceTheme"
|
||||
style="@style/TextInputLayoutAppearance"
|
||||
android:hint="@string/gems_to_gift">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/gift_edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"
|
||||
android:paddingTop="@dimen/spacing_small"/>
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/gift_gems_disclaimer"
|
||||
android:gravity="center"
|
||||
android:layout_marginStart="@dimen/spacing_large"
|
||||
android:layout_marginEnd="@dimen/spacing_large"
|
||||
android:layout_marginBottom="@dimen/spacing_large"
|
||||
style="@style/Caption2"/>
|
||||
<Button
|
||||
android:id="@+id/gift_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/spacing_large"
|
||||
android:layout_marginEnd="@dimen/spacing_large"
|
||||
style="@style/HabiticaButton.Purple"
|
||||
android:layout_marginTop="@dimen/spacing_medium"
|
||||
android:text="@string/send_gift" />
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
105
Habitica/res/layout/fragment_gift_gem_purchase.xml
Normal file
105
Habitica/res/layout/fragment_gift_gem_purchase.xml
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.core.widget.NestedScrollView android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<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_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_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>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/gift_gems_disclaimer"
|
||||
android:gravity="center"
|
||||
android:layout_marginStart="@dimen/spacing_large"
|
||||
android:layout_marginEnd="@dimen/spacing_large"
|
||||
android:layout_marginBottom="@dimen/spacing_large"
|
||||
style="@style/Caption2"/>
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
|
@ -724,7 +724,6 @@
|
|||
<string name="gift_one_get_one_detailed_description">While this promotion is active, you’ll receive a matching subscription automatically after sending your gift.</string>
|
||||
<string name="gift_subscription_subtitle">Choose the subscription you’d like to gift below! This purchase won’t automatically renew.</string>
|
||||
<string name="gift_gems_subtitle">Choose the gem packet you’d 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_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>
|
||||
|
|
@ -871,4 +870,9 @@
|
|||
<string name="gems_gift_description">Want to bestow a shiny haul of Gems to someone else?</string>
|
||||
<string name="gift_gems_disclaimer">Habitica will never require you to gift gems to other players. Begging people for gems is a violation of the Community Guidelines and should be reported to admin@habitica.com.</string>
|
||||
<string name="more_out_of_habitica">Get more out of Habitica</string>
|
||||
<string name="purchase">Purchase</string>
|
||||
<string name="from_balance">From Balance</string>
|
||||
<string name="gift_gems_balance_subtitle">Enter how many of your Gems you\'d like to send below or switch tabs to purchase Gems to gift</string>
|
||||
<string name="gems_to_gift">Gems to gift</string>
|
||||
<string name="send_gift">Send Gift</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -371,4 +371,7 @@ interface ApiService {
|
|||
|
||||
@POST("user/allocate-bulk")
|
||||
fun bulkAllocatePoints(@Body stats: Map<String, Map<String, Int>>): Flowable<HabitResponse<Stats>>
|
||||
|
||||
@POST("members/transfer-gems")
|
||||
fun transferGems(@Body data: Map<String, Any>): Flowable<HabitResponse<Void>>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,11 +42,13 @@ import com.habitrpg.android.habitica.ui.adapter.tasks.RewardsRecyclerViewAdapter
|
|||
import com.habitrpg.android.habitica.ui.adapter.tasks.TodosRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.AboutFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.AchievementsFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.GemsPurchaseFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.purchases.GemsPurchaseFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.NavigationDrawerFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.NewsFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.StatsFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.SubscriptionFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.purchases.GiftBalanceGemsFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.purchases.GiftPurchaseGemsFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.purchases.SubscriptionFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.faq.FAQDetailFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.faq.FAQOverviewFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.customization.AvatarCustomizationFragment;
|
||||
|
|
@ -322,4 +324,8 @@ public interface UserComponent {
|
|||
void inject(@NotNull InsufficientGemsDialog insufficientGemsDialog);
|
||||
|
||||
void inject(@NotNull GiftGemsActivity giftGemsActivity);
|
||||
|
||||
void inject(@NotNull GiftPurchaseGemsFragment giftPurchaseGemsFragment);
|
||||
|
||||
void inject(@NotNull GiftBalanceGemsFragment giftBalanceGemsFragment);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -252,4 +252,6 @@ interface ApiClient {
|
|||
fun verifyUsername(username: String): Flowable<VerifyUsernameResponse>
|
||||
fun updateServerUrl(newAddress: String?)
|
||||
fun findUsernames(username: String, context: String?, id: String?): Flowable<List<FindUsernameResult>>
|
||||
|
||||
fun transferGems(giftedID: String, amount: Int): Flowable<Void>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,6 +82,8 @@ interface SocialRepository : BaseRepository {
|
|||
|
||||
fun getMemberAchievements(userId: String?): Flowable<List<Achievement>>
|
||||
|
||||
fun transferGems(giftedID: String, amount: Int): Flowable<Void>
|
||||
|
||||
fun getGroupMembership(id: String): Flowable<GroupMembership>
|
||||
fun getGroupMemberships(): Flowable<RealmResults<GroupMembership>>
|
||||
fun getChatmessage(messageID: String): Flowable<ChatMessage>
|
||||
|
|
|
|||
|
|
@ -742,6 +742,10 @@ class ApiClientImpl//private OnHabitsAPIResult mResultListener;
|
|||
return apiService.allocatePoint(stat).compose(configureApiCallObserver())
|
||||
}
|
||||
|
||||
override fun transferGems(giftedID: String, amount: Int): Flowable<Void> {
|
||||
return apiService.transferGems(mapOf(Pair("toUserId", giftedID), Pair("gemAmount", amount))).compose(configureApiCallObserver())
|
||||
}
|
||||
|
||||
override fun bulkAllocatePoints(strength: Int, intelligence: Int, constitution: Int, perception: Int): Flowable<Stats> {
|
||||
val body = HashMap<String, Map<String, Int>>()
|
||||
val stats = HashMap<String, Int>()
|
||||
|
|
|
|||
|
|
@ -320,4 +320,8 @@ class SocialRepositoryImpl(localRepository: SocialLocalRepository, apiClient: Ap
|
|||
Flowable.empty()
|
||||
} else apiClient.getMemberAchievements(userId)
|
||||
}
|
||||
|
||||
override fun transferGems(giftedID: String, amount: Int): Flowable<Void> {
|
||||
return apiClient.transferGems(giftedID, amount)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,10 +65,10 @@ fun Long.getRemainingString(res: Resources): String {
|
|||
return when {
|
||||
diffMonths != 0f -> if (round(diffMonths) == 1f) {
|
||||
res.getString(R.string.remaining_1month)
|
||||
} else res.getString(R.string.remaining_months, round(diffMonths))
|
||||
} else res.getString(R.string.remaining_months, round(diffMonths).toInt())
|
||||
diffWeeks != 0f -> if (round(diffWeeks) == 1f) {
|
||||
res.getString(R.string.remaining_1week)
|
||||
} else res.getString(R.string.remaining_weeks, round(diffWeeks))
|
||||
} else res.getString(R.string.remaining_weeks, round(diffWeeks).toInt())
|
||||
diffDays != 0L -> if (diffDays == 1L) {
|
||||
res.getString(R.string.remaining_1day)
|
||||
} else res.getString(R.string.remaining_days, diffDays)
|
||||
|
|
|
|||
|
|
@ -10,10 +10,6 @@ class AppConfigManager {
|
|||
|
||||
private val remoteConfig = FirebaseRemoteConfig.getInstance()
|
||||
|
||||
fun newShopsEnabled(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
fun shopSpriteSuffix(): String {
|
||||
return remoteConfig.getString("shopSpriteSuffix")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ import com.habitrpg.android.habitica.events.ConsumablePurchasedEvent
|
|||
import com.habitrpg.android.habitica.helpers.PurchaseHandler
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.proxy.CrashlyticsProxy
|
||||
import com.habitrpg.android.habitica.ui.fragments.GemsPurchaseFragment
|
||||
import com.habitrpg.android.habitica.ui.fragments.SubscriptionFragment
|
||||
import com.habitrpg.android.habitica.ui.fragments.purchases.GemsPurchaseFragment
|
||||
import com.habitrpg.android.habitica.ui.fragments.purchases.SubscriptionFragment
|
||||
import io.reactivex.functions.Consumer
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import javax.inject.Inject
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@ 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.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentPagerAdapter
|
||||
import androidx.navigation.navArgs
|
||||
import com.habitrpg.android.habitica.HabiticaPurchaseVerifier
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.components.UserComponent
|
||||
import com.habitrpg.android.habitica.data.SocialRepository
|
||||
|
|
@ -15,14 +16,12 @@ 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.fragments.purchases.GiftBalanceGemsFragment
|
||||
import com.habitrpg.android.habitica.ui.fragments.purchases.GiftPurchaseGemsFragment
|
||||
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
|
||||
|
|
@ -39,19 +38,15 @@ class GiftGemsActivity : BaseActivity() {
|
|||
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)
|
||||
internal val tabLayout: TabLayout by bindView(R.id.tab_layout)
|
||||
internal val viewPager: ViewPager by bindView(R.id.viewPager)
|
||||
|
||||
private var giftedUsername: String? = null
|
||||
private var giftedUserID: String? = null
|
||||
|
||||
private var purchaseFragment: GiftPurchaseGemsFragment? = null
|
||||
private var balanceFragment: GiftBalanceGemsFragment? = null
|
||||
|
||||
override fun getLayoutResId(): Int {
|
||||
return R.layout.activity_gift_gems
|
||||
}
|
||||
|
|
@ -76,35 +71,20 @@ class GiftGemsActivity : BaseActivity() {
|
|||
giftedUsername = 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}"
|
||||
setViewPagerAdapter()
|
||||
|
||||
compositeSubscription.add(socialRepository.getMember(giftedUsername ?: giftedUserID).firstElement().subscribe(Consumer {
|
||||
giftedUserID = it.id
|
||||
giftedUsername = it.username
|
||||
purchaseFragment?.giftedMember = it
|
||||
balanceFragment?.giftedMember = it
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
purchaseHandler = PurchaseHandler(this, crashlyticsProxy)
|
||||
purchaseHandler?.startListening()
|
||||
|
||||
purchaseHandler?.getAllGemSKUs { skus ->
|
||||
for (sku in skus) {
|
||||
updateButtonLabel(sku.id.code, sku.price)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
|
|
@ -125,18 +105,42 @@ class GiftGemsActivity : BaseActivity() {
|
|||
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
|
||||
private fun setViewPagerAdapter() {
|
||||
val fragmentManager = supportFragmentManager
|
||||
|
||||
viewPager.adapter = object : FragmentPagerAdapter(fragmentManager) {
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
return if (position == 0) {
|
||||
val fragment = GiftPurchaseGemsFragment()
|
||||
fragment.setPurchaseHandler(purchaseHandler)
|
||||
fragment.setupCheckout()
|
||||
purchaseFragment = fragment
|
||||
fragment
|
||||
} else {
|
||||
val fragment = GiftBalanceGemsFragment()
|
||||
fragment.onCompleted = {
|
||||
displayConfirmationDialog()
|
||||
}
|
||||
balanceFragment = fragment
|
||||
fragment
|
||||
}
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
return 2
|
||||
}
|
||||
|
||||
override fun getPageTitle(position: Int): CharSequence? {
|
||||
return when (position) {
|
||||
0 -> getString(R.string.purchase)
|
||||
1 -> getString(R.string.from_balance)
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tabLayout.setupWithViewPager(viewPager)
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
|
@ -158,10 +162,4 @@ class GiftGemsActivity : BaseActivity() {
|
|||
}
|
||||
alert.enqueue()
|
||||
}
|
||||
|
||||
|
||||
fun purchaseGems(identifier: String) {
|
||||
HabiticaPurchaseVerifier.pendingGifts[identifier] = giftedUserID
|
||||
purchaseHandler?.purchaseGems(identifier)
|
||||
}
|
||||
}
|
||||
|
|
@ -118,7 +118,6 @@ class GroupInviteActivity : BaseActivity() {
|
|||
viewPager.adapter = object : FragmentPagerAdapter(fragmentManager) {
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
|
||||
val fragment = PartyInviteFragment()
|
||||
fragment.isEmailInvite = position == 1
|
||||
if (fragments.size > position) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments
|
||||
package com.habitrpg.android.habitica.ui.fragments.purchases
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
|
|
@ -21,6 +21,7 @@ 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.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
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.purchases
|
||||
|
||||
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 com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.components.UserComponent
|
||||
import com.habitrpg.android.habitica.data.SocialRepository
|
||||
import com.habitrpg.android.habitica.extensions.inflate
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.members.Member
|
||||
import com.habitrpg.android.habitica.ui.AvatarView
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
import com.habitrpg.android.habitica.ui.views.social.UsernameLabel
|
||||
import io.reactivex.functions.Consumer
|
||||
import javax.inject.Inject
|
||||
|
||||
class GiftBalanceGemsFragment : BaseFragment() {
|
||||
|
||||
@Inject
|
||||
lateinit var socialRepository: SocialRepository
|
||||
|
||||
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 giftEditText: EditText by bindView(R.id.gift_edit_text)
|
||||
private val giftButton: Button by bindView(R.id.gift_button)
|
||||
|
||||
var giftedMember: Member? = null
|
||||
set(value) {
|
||||
field = value
|
||||
field?.let {
|
||||
avatarView.setAvatar(it)
|
||||
displayNameTextView.username = it.profile?.name
|
||||
displayNameTextView.tier = it.contributor?.level ?: 0
|
||||
usernameTextView.text = "@${it.username}"
|
||||
}
|
||||
}
|
||||
|
||||
var onCompleted: (() -> Unit)? = null
|
||||
|
||||
override fun injectFragment(component: UserComponent) {
|
||||
component.inject(this)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
super.onCreateView(inflater, container, savedInstanceState)
|
||||
return container?.inflate(R.layout.fragment_gift_gem_balance)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
giftButton.setOnClickListener { sendGift() }
|
||||
}
|
||||
|
||||
private fun sendGift() {
|
||||
val amount = giftEditText.text.toString().toInt()
|
||||
giftedMember?.id?.let {
|
||||
compositeSubscription.add(socialRepository.transferGems(it, amount).subscribe(Consumer {
|
||||
onCompleted?.invoke()
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.purchases
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
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.extensions.inflate
|
||||
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.models.members.Member
|
||||
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.fragments.BaseFragment
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
import com.habitrpg.android.habitica.ui.views.social.UsernameLabel
|
||||
import io.reactivex.functions.Consumer
|
||||
import javax.inject.Inject
|
||||
|
||||
class GiftPurchaseGemsFragment : BaseFragment() {
|
||||
|
||||
@Inject
|
||||
lateinit var crashlyticsProxy: CrashlyticsProxy
|
||||
@Inject
|
||||
lateinit var socialRepository: SocialRepository
|
||||
|
||||
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)
|
||||
|
||||
var giftedMember: Member? = null
|
||||
set(value) {
|
||||
field = value
|
||||
field?.let {
|
||||
avatarView.setAvatar(it)
|
||||
displayNameTextView.username = it.profile?.name
|
||||
displayNameTextView.tier = it.contributor?.level ?: 0
|
||||
usernameTextView.text = "@${it.username}"
|
||||
}
|
||||
}
|
||||
|
||||
private var purchaseHandler: PurchaseHandler? = null
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
|
||||
super.onCreateView(inflater, container, savedInstanceState)
|
||||
|
||||
return container?.inflate(R.layout.fragment_gift_gem_purchase)
|
||||
}
|
||||
|
||||
override fun injectFragment(component: UserComponent) {
|
||||
component.inject(this)
|
||||
}
|
||||
|
||||
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) })
|
||||
}
|
||||
|
||||
fun setupCheckout() {
|
||||
purchaseHandler?.getAllGemSKUs { skus ->
|
||||
for (sku in skus) {
|
||||
updateButtonLabel(sku.id.code, sku.price)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setPurchaseHandler(handler: PurchaseHandler?) {
|
||||
this.purchaseHandler = handler
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
private fun purchaseGems(identifier: String) {
|
||||
HabiticaPurchaseVerifier.pendingGifts[identifier] = giftedMember?.id
|
||||
purchaseHandler?.purchaseGems(identifier)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments
|
||||
package com.habitrpg.android.habitica.ui.fragments.purchases
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
|
|
@ -21,6 +21,7 @@ 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.GiftSubscriptionActivity
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindOptionalView
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
import com.habitrpg.android.habitica.ui.helpers.dismissKeyboard
|
||||
Loading…
Reference in a new issue