|
|
|
@ -1,5 +1,6 @@ |
|
|
|
package net.pokeranalytics.android.ui.fragment |
|
|
|
package net.pokeranalytics.android.ui.fragment |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.graphics.drawable.GradientDrawable |
|
|
|
import android.os.Build |
|
|
|
import android.os.Build |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
import android.text.SpannableStringBuilder |
|
|
|
import android.text.SpannableStringBuilder |
|
|
|
@ -8,17 +9,22 @@ import android.text.style.TypefaceSpan |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.view.ViewGroup |
|
|
|
|
|
|
|
import android.widget.LinearLayout |
|
|
|
import android.widget.Toast |
|
|
|
import android.widget.Toast |
|
|
|
import androidx.core.content.res.ResourcesCompat |
|
|
|
import androidx.core.content.res.ResourcesCompat |
|
|
|
|
|
|
|
import androidx.core.view.children |
|
|
|
|
|
|
|
import androidx.core.view.setMargins |
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
import androidx.fragment.app.FragmentManager |
|
|
|
import androidx.fragment.app.FragmentManager |
|
|
|
import androidx.fragment.app.FragmentStatePagerAdapter |
|
|
|
import androidx.fragment.app.FragmentStatePagerAdapter |
|
|
|
|
|
|
|
import androidx.viewpager.widget.ViewPager |
|
|
|
import com.android.billingclient.api.BillingClient |
|
|
|
import com.android.billingclient.api.BillingClient |
|
|
|
import com.android.billingclient.api.Purchase |
|
|
|
import com.android.billingclient.api.Purchase |
|
|
|
import com.android.billingclient.api.SkuDetails |
|
|
|
import com.android.billingclient.api.SkuDetails |
|
|
|
import com.android.billingclient.api.SkuDetailsResponseListener |
|
|
|
import com.android.billingclient.api.SkuDetailsResponseListener |
|
|
|
import kotlinx.android.synthetic.main.fragment_subscription.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_subscription.* |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.extensions.px |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.ScreenSlidePageFragment |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.ScreenSlidePageFragment |
|
|
|
import net.pokeranalytics.android.util.Preferences |
|
|
|
import net.pokeranalytics.android.util.Preferences |
|
|
|
@ -27,10 +33,7 @@ import net.pokeranalytics.android.util.billing.IAPProducts |
|
|
|
import net.pokeranalytics.android.util.billing.PurchaseDelegate |
|
|
|
import net.pokeranalytics.android.util.billing.PurchaseDelegate |
|
|
|
import java.time.Period |
|
|
|
import java.time.Period |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SubscriptionFragment : PokerAnalyticsFragment(), SkuDetailsResponseListener, PurchaseDelegate, ViewPager.OnPageChangeListener { |
|
|
|
data class FeatureDescriptor(var iconResId: Int, var titleResId: Int, var descResId: Int) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SubscriptionFragment : PokerAnalyticsFragment(), SkuDetailsResponseListener, PurchaseDelegate { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var selectedProduct: SkuDetails? = null |
|
|
|
private var selectedProduct: SkuDetails? = null |
|
|
|
|
|
|
|
|
|
|
|
@ -84,6 +87,7 @@ class SubscriptionFragment : PokerAnalyticsFragment(), SkuDetailsResponseListene |
|
|
|
// The pager adapter, which provides the pages to the view pager widget. |
|
|
|
// The pager adapter, which provides the pages to the view pager widget. |
|
|
|
val pagerAdapter = ScreenSlidePagerAdapter(requireFragmentManager()) |
|
|
|
val pagerAdapter = ScreenSlidePagerAdapter(requireFragmentManager()) |
|
|
|
this.pager.adapter = pagerAdapter |
|
|
|
this.pager.adapter = pagerAdapter |
|
|
|
|
|
|
|
this.pager.addOnPageChangeListener(this) |
|
|
|
|
|
|
|
|
|
|
|
this.purchase.isEnabled = false |
|
|
|
this.purchase.isEnabled = false |
|
|
|
this.purchase.setOnClickListener { |
|
|
|
this.purchase.setOnClickListener { |
|
|
|
@ -94,6 +98,18 @@ class SubscriptionFragment : PokerAnalyticsFragment(), SkuDetailsResponseListene |
|
|
|
throw IllegalStateException("Attempt to initiate purchase while no product has been chosen") |
|
|
|
throw IllegalStateException("Attempt to initiate purchase while no product has been chosen") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val count = this.pager.adapter?.count ?: 0 |
|
|
|
|
|
|
|
for (i in 1..count) { |
|
|
|
|
|
|
|
val view = View(requireContext()) |
|
|
|
|
|
|
|
view.background = requireContext().getDrawable(R.drawable.circle_green) |
|
|
|
|
|
|
|
val layoutParam = LinearLayout.LayoutParams(20.px, 20.px) |
|
|
|
|
|
|
|
layoutParam.setMargins(8.px) |
|
|
|
|
|
|
|
this.pageIndicator.addView(view, layoutParam) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.changeColorOfIndicator(0) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -102,6 +118,8 @@ class SubscriptionFragment : PokerAnalyticsFragment(), SkuDetailsResponseListene |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private inner class ScreenSlidePagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) { |
|
|
|
private inner class ScreenSlidePagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private inner class FeatureDescriptor(var iconResId: Int, var titleResId: Int, var descResId: Int) |
|
|
|
|
|
|
|
|
|
|
|
private val dataSource: List<FeatureDescriptor> = listOf( |
|
|
|
private val dataSource: List<FeatureDescriptor> = listOf( |
|
|
|
FeatureDescriptor(R.drawable.ic_baseline_all_inclusive_24px, R.string.f_unlimited, R.string.f_unlimited_desc), |
|
|
|
FeatureDescriptor(R.drawable.ic_baseline_all_inclusive_24px, R.string.f_unlimited, R.string.f_unlimited_desc), |
|
|
|
FeatureDescriptor(R.drawable.ic_baseline_wifi_off_24px, R.string.f_offline, R.string.f_offline_desc), |
|
|
|
FeatureDescriptor(R.drawable.ic_baseline_wifi_off_24px, R.string.f_offline, R.string.f_offline_desc), |
|
|
|
@ -160,4 +178,27 @@ class SubscriptionFragment : PokerAnalyticsFragment(), SkuDetailsResponseListene |
|
|
|
this.activity?.finish() |
|
|
|
this.activity?.finish() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// OnPageChangeListener |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onPageScrollStateChanged(state: Int) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onPageSelected(position: Int) { |
|
|
|
|
|
|
|
this.changeColorOfIndicator(position) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun changeColorOfIndicator(position: Int) { |
|
|
|
|
|
|
|
this.pageIndicator.children.forEachIndexed { index, view -> |
|
|
|
|
|
|
|
val drawable = view.background |
|
|
|
|
|
|
|
when (drawable) { |
|
|
|
|
|
|
|
is GradientDrawable -> { |
|
|
|
|
|
|
|
val color = if (position == index) R.color.white else R.color.quantum_grey |
|
|
|
|
|
|
|
drawable.setColor(requireContext().getColor(color)) |
|
|
|
|
|
|
|
} else -> {} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |