mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-20 04:39:04 +00:00
Split up subscriptin and gems in menu
This commit is contained in:
parent
bbd5684950
commit
10429aee13
5 changed files with 46 additions and 81 deletions
|
|
@ -17,8 +17,8 @@
|
|||
android:elevation="0dp"
|
||||
tools:context=".ui.activities.MainActivity">
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:id="@+id/viewPager"
|
||||
<FrameLayout
|
||||
android:id="@+id/fragment_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/white"
|
||||
|
|
@ -59,24 +59,6 @@
|
|||
app:layout_collapseMode="pin"
|
||||
app:popupTheme="@style/Theme.AppCompat.Light" />
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tab_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="54dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="?colorPrimaryOffset"
|
||||
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" />
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
|||
|
|
@ -131,10 +131,24 @@
|
|||
android:id="@+id/openMountDetail"
|
||||
app:destination="@id/mountDetailRecyclerFragment" />
|
||||
</fragment>
|
||||
<activity
|
||||
android:id="@+id/subscriptionPurchaseActivity"
|
||||
android:name="com.habitrpg.android.habitica.ui.activities.GemPurchaseActivity"
|
||||
android:label="@string/gem_purchase_toolbartitle" >
|
||||
<argument
|
||||
android:name="openSubscription"
|
||||
app:argType="boolean"
|
||||
android:defaultValue="true" />
|
||||
</activity>
|
||||
<activity
|
||||
android:id="@+id/gemPurchaseActivity"
|
||||
android:name="com.habitrpg.android.habitica.ui.activities.GemPurchaseActivity"
|
||||
android:label="@string/gem_purchase_toolbartitle" />
|
||||
android:label="@string/gem_purchase_toolbartitle">
|
||||
<argument
|
||||
android:name="openSubscription"
|
||||
app:argType="boolean"
|
||||
android:defaultValue="false" />
|
||||
</activity>
|
||||
<fragment
|
||||
android:id="@+id/newsFragment"
|
||||
android:name="com.habitrpg.android.habitica.ui.fragments.NewsFragment"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
<string name="sidebar_inbox">Messages</string>
|
||||
<string name="sidebar_tavern">Tavern</string>
|
||||
<string name="sidebar_party">Party</string>
|
||||
<string name="sidebar_purchaseGems">Gems & Subscription</string>
|
||||
<string name="sidebar_gems">Gems</string>
|
||||
<string name="sidebar_subscription">Subscription</string>
|
||||
<string name="sidebar_guilds">Guilds</string>
|
||||
<string name="sidebar_challenges">Challenges</string>
|
||||
<string name="sidebar_section_inventory">Inventory</string>
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ import android.os.Bundle
|
|||
import android.util.Log
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.fragment.app.FragmentPagerAdapter
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.habitrpg.android.habitica.HabiticaBaseApplication
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.components.UserComponent
|
||||
|
|
@ -17,10 +16,8 @@ import com.habitrpg.android.habitica.helpers.PurchaseTypes
|
|||
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.helpers.bindView
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.solovyev.android.checkout.*
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class GemPurchaseActivity : BaseActivity() {
|
||||
|
|
@ -30,10 +27,7 @@ class GemPurchaseActivity : BaseActivity() {
|
|||
@Inject
|
||||
lateinit var userRepository: UserRepository
|
||||
|
||||
internal val tabLayout: TabLayout by bindView(R.id.tab_layout)
|
||||
internal val viewPager: androidx.viewpager.widget.ViewPager by bindView(R.id.viewPager)
|
||||
|
||||
internal var fragments: MutableList<CheckoutFragment> = ArrayList()
|
||||
internal var fragment: CheckoutFragment? = null
|
||||
var isActive = false
|
||||
var activityCheckout: ActivityCheckout? = null
|
||||
private set
|
||||
|
|
@ -52,8 +46,6 @@ class GemPurchaseActivity : BaseActivity() {
|
|||
activityCheckout?.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
|
||||
private var showSubscriptionPageFirst = true
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
|
@ -63,16 +55,15 @@ class GemPurchaseActivity : BaseActivity() {
|
|||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
supportActionBar?.setDisplayShowHomeEnabled(true)
|
||||
supportActionBar?.setTitle(R.string.gem_purchase_toolbartitle)
|
||||
|
||||
setViewPagerAdapter()
|
||||
viewPager.currentItem = if (intent.extras?.containsKey("openSubscription") == true) {
|
||||
|
||||
if (intent.extras?.containsKey("openSubscription") == true) {
|
||||
if (intent.extras?.getBoolean("openSubscription") == false) {
|
||||
1
|
||||
createFragment(false)
|
||||
} else {
|
||||
0
|
||||
createFragment(true)
|
||||
}
|
||||
} else {
|
||||
0
|
||||
createFragment(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -101,9 +92,7 @@ class GemPurchaseActivity : BaseActivity() {
|
|||
override fun onReady(billingRequests: BillingRequests) {
|
||||
this@GemPurchaseActivity.billingRequests = billingRequests
|
||||
|
||||
for (fragment in fragments) {
|
||||
fragment.setBillingRequests(billingRequests)
|
||||
}
|
||||
fragment?.setBillingRequests(billingRequests)
|
||||
|
||||
checkIfPendingPurchases()
|
||||
}
|
||||
|
|
@ -143,45 +132,22 @@ class GemPurchaseActivity : BaseActivity() {
|
|||
|
||||
}
|
||||
|
||||
private fun setViewPagerAdapter() {
|
||||
val fragmentManager = supportFragmentManager
|
||||
|
||||
viewPager.adapter = object : FragmentPagerAdapter(fragmentManager) {
|
||||
|
||||
override fun getItem(position: Int): androidx.fragment.app.Fragment {
|
||||
val gemPurchasePosition = if (showSubscriptionPageFirst) 1 else 0
|
||||
val fragment: CheckoutFragment = if (position == gemPurchasePosition) {
|
||||
GemsPurchaseFragment()
|
||||
} else {
|
||||
SubscriptionFragment()
|
||||
}
|
||||
if (fragments.size > position) {
|
||||
fragments[position] = fragment
|
||||
} else {
|
||||
fragments.add(fragment)
|
||||
}
|
||||
fragment.setListener(this@GemPurchaseActivity)
|
||||
fragment.setupCheckout()
|
||||
if (billingRequests != null) {
|
||||
fragment.setBillingRequests(billingRequests)
|
||||
}
|
||||
return fragment as androidx.fragment.app.Fragment
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
return 2
|
||||
}
|
||||
|
||||
override fun getPageTitle(position: Int): CharSequence? {
|
||||
val gemPurchasePosition = if (showSubscriptionPageFirst) 1 else 0
|
||||
return when (position) {
|
||||
gemPurchasePosition -> getString(R.string.gems)
|
||||
else -> getString(R.string.subscriptions)
|
||||
}
|
||||
}
|
||||
private fun createFragment(showSubscription: Boolean) {
|
||||
val fragment: CheckoutFragment = if (showSubscription) {
|
||||
SubscriptionFragment()
|
||||
} else {
|
||||
GemsPurchaseFragment()
|
||||
}
|
||||
|
||||
tabLayout.setupWithViewPager(viewPager)
|
||||
fragment.setListener(this@GemPurchaseActivity)
|
||||
fragment.setupCheckout()
|
||||
if (billingRequests != null) {
|
||||
fragment.setBillingRequests(billingRequests)
|
||||
}
|
||||
supportFragmentManager
|
||||
.beginTransaction()
|
||||
.replace(R.id.fragment_container, fragment as Fragment)
|
||||
.commit()
|
||||
this.fragment = fragment
|
||||
}
|
||||
|
||||
private fun checkIfPendingPurchases() {
|
||||
|
|
|
|||
|
|
@ -259,7 +259,8 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
items.add(HabiticaDrawerItem(R.id.equipmentOverviewFragment, SIDEBAR_EQUIPMENT, context.getString(R.string.sidebar_equipment)))
|
||||
items.add(HabiticaDrawerItem(R.id.itemsFragment, SIDEBAR_ITEMS, context.getString(R.string.sidebar_items)))
|
||||
items.add(HabiticaDrawerItem(R.id.stableFragment, SIDEBAR_STABLE, context.getString(R.string.sidebar_stable)))
|
||||
items.add(HabiticaDrawerItem(R.id.gemPurchaseActivity, SIDEBAR_PURCHASE, context.getString(R.string.sidebar_purchaseGems)))
|
||||
items.add(HabiticaDrawerItem(R.id.subscriptionPurchaseActivity, SIDEBAR_SUBSCRIPTION, context.getString(R.string.sidebar_subscription)))
|
||||
items.add(HabiticaDrawerItem(R.id.gemPurchaseActivity, SIDEBAR_GEMS, context.getString(R.string.sidebar_gems)))
|
||||
items.add(HabiticaDrawerItem(0, SIDEBAR_ABOUT_HEADER, context.getString(R.string.sidebar_about), true))
|
||||
items.add(HabiticaDrawerItem(R.id.newsFragment, SIDEBAR_NEWS, context.getString(R.string.sidebar_news)))
|
||||
items.add(HabiticaDrawerItem(R.id.FAQOverviewFragment, SIDEBAR_HELP, context.getString(R.string.sidebar_help)))
|
||||
|
|
@ -424,7 +425,8 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
const val SIDEBAR_EQUIPMENT = "equipment"
|
||||
const val SIDEBAR_ITEMS = "items"
|
||||
const val SIDEBAR_STABLE = "stable"
|
||||
const val SIDEBAR_PURCHASE = "purchase"
|
||||
const val SIDEBAR_GEMS = "gems"
|
||||
const val SIDEBAR_SUBSCRIPTION = "subscription"
|
||||
const val SIDEBAR_ABOUT_HEADER = "about_header"
|
||||
const val SIDEBAR_NEWS = "news"
|
||||
const val SIDEBAR_HELP = "help"
|
||||
|
|
|
|||
Loading…
Reference in a new issue