|
|
|
|
@ -22,8 +22,8 @@ import androidx.fragment.app.FragmentManager |
|
|
|
|
import androidx.fragment.app.FragmentStatePagerAdapter |
|
|
|
|
import androidx.viewpager.widget.ViewPager |
|
|
|
|
import com.android.billingclient.api.* |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_subscription.* |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.databinding.FragmentSubscriptionBinding |
|
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
|
import net.pokeranalytics.android.model.utils.CrashLogging |
|
|
|
|
import net.pokeranalytics.android.ui.extensions.px |
|
|
|
|
@ -55,7 +55,23 @@ class SubscriptionFragment : BaseFragment(), SkuDetailsResponseListener, Purchas |
|
|
|
|
private var selectedProduct: SkuDetails? = null |
|
|
|
|
private var showSessionMessage = false |
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
|
private var _binding: FragmentSubscriptionBinding? = null |
|
|
|
|
private val binding get() = _binding!! |
|
|
|
|
|
|
|
|
|
// Life Cycle |
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
|
_binding = FragmentSubscriptionBinding.inflate(inflater, container, false) |
|
|
|
|
return binding.root |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onDestroyView() { |
|
|
|
|
super.onDestroyView() |
|
|
|
|
_binding = null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
|
|
|
|
|
|
val cm = requireContext().getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager |
|
|
|
|
@ -78,10 +94,6 @@ class SubscriptionFragment : BaseFragment(), SkuDetailsResponseListener, Purchas |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
|
return inflater.inflate(R.layout.fragment_subscription, container, false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
|
initData() |
|
|
|
|
@ -99,6 +111,11 @@ class SubscriptionFragment : BaseFragment(), SkuDetailsResponseListener, Purchas |
|
|
|
|
|
|
|
|
|
private fun initUI() { |
|
|
|
|
|
|
|
|
|
val title = binding.title |
|
|
|
|
val message = binding.message |
|
|
|
|
val pager = binding.pager |
|
|
|
|
val purchase = binding.purchase |
|
|
|
|
val pageIndicator = binding.pageIndicator |
|
|
|
|
val upgradeString = requireContext().getString(R.string.pro_upgrade) |
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { |
|
|
|
|
@ -119,25 +136,25 @@ class SubscriptionFragment : BaseFragment(), SkuDetailsResponseListener, Purchas |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.title.text = ssb |
|
|
|
|
title.text = ssb |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
this.title.text = upgradeString |
|
|
|
|
title.text = upgradeString |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (showSessionMessage) { |
|
|
|
|
this.message.text = getString(R.string.iap_session_message) |
|
|
|
|
message.text = getString(R.string.iap_session_message) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Pager |
|
|
|
|
|
|
|
|
|
// The pager adapter, which provides the pages to the view pager widget. |
|
|
|
|
this.pagerAdapter = ScreenSlidePagerAdapter(parentFragmentManager) |
|
|
|
|
this.pager.adapter = pagerAdapter |
|
|
|
|
this.pager.addOnPageChangeListener(this) |
|
|
|
|
pager.adapter = pagerAdapter |
|
|
|
|
pager.addOnPageChangeListener(this) |
|
|
|
|
|
|
|
|
|
this.purchase.isEnabled = false |
|
|
|
|
this.purchase.setOnClickListener { |
|
|
|
|
purchase.isEnabled = false |
|
|
|
|
purchase.setOnClickListener { |
|
|
|
|
|
|
|
|
|
this.selectedProduct?.let { |
|
|
|
|
AppGuard.initiatePurchase(this.requireActivity(), it) |
|
|
|
|
@ -146,13 +163,13 @@ class SubscriptionFragment : BaseFragment(), SkuDetailsResponseListener, Purchas |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val count = this.pager.adapter?.count ?: 0 |
|
|
|
|
val count = 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(8.px, 8.px) |
|
|
|
|
layoutParam.setMargins(6.px) |
|
|
|
|
this.pageIndicator.addView(view, layoutParam) |
|
|
|
|
pageIndicator.addView(view, layoutParam) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.updatePagerIndicators(0) |
|
|
|
|
@ -210,10 +227,10 @@ class SubscriptionFragment : BaseFragment(), SkuDetailsResponseListener, Purchas |
|
|
|
|
|
|
|
|
|
private fun updateUI() { |
|
|
|
|
this.selectedProduct?.let { |
|
|
|
|
this.purchase.isEnabled = true |
|
|
|
|
binding.purchase.isEnabled = true |
|
|
|
|
val perYearString = requireContext().getString(R.string.year_subscription) |
|
|
|
|
val formattedPrice = it.price + " / " + perYearString |
|
|
|
|
this.price.text = formattedPrice |
|
|
|
|
binding.price.text = formattedPrice |
|
|
|
|
|
|
|
|
|
var freeTrialDays = 30 // initial, should be more, no less |
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { |
|
|
|
|
@ -226,7 +243,7 @@ class SubscriptionFragment : BaseFragment(), SkuDetailsResponseListener, Purchas |
|
|
|
|
} |
|
|
|
|
val formattedFreeTrial = |
|
|
|
|
"$freeTrialDays " + requireContext().getString(R.string.days) + " " + requireContext().getString(R.string.free_trial) |
|
|
|
|
this.freetrial.text = formattedFreeTrial |
|
|
|
|
binding.freetrial.text = formattedFreeTrial |
|
|
|
|
} ?: run { |
|
|
|
|
Toast.makeText(requireContext(), R.string.contact_support, Toast.LENGTH_LONG).show() |
|
|
|
|
} |
|
|
|
|
@ -261,7 +278,7 @@ class SubscriptionFragment : BaseFragment(), SkuDetailsResponseListener, Purchas |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun updatePagerIndicators(position: Int) { |
|
|
|
|
this.pageIndicator.children.forEachIndexed { index, view -> |
|
|
|
|
binding.pageIndicator.children.forEachIndexed { index, view -> |
|
|
|
|
val drawable = view.background |
|
|
|
|
when (drawable) { |
|
|
|
|
is GradientDrawable -> { |
|
|
|
|
|