|
@@ -21,6 +21,7 @@ import com.google.gson.reflect.TypeToken
|
|
|
import com.vpn.fastestvpnservice.application.App
|
|
|
import com.vpn.fastestvpnservice.beans.DataResponse
|
|
|
import com.vpn.fastestvpnservice.beans.ProductFeatures
|
|
|
+import com.vpn.fastestvpnservice.customItems.getSelectedPosition
|
|
|
import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
|
|
|
import com.vpn.fastestvpnservice.retrofit.RetrofitNetworkHandling
|
|
|
import com.vpn.fastestvpnservice.retrofit.WebServiceFactory
|
|
@@ -46,13 +47,31 @@ class SubscriptionViewModel constructor(context: Context, activity: ComponentAct
|
|
|
var mutableLiveDataNumber = MutableLiveData<Int>(0)
|
|
|
var liveDataNumber: LiveData<Int> = mutableLiveDataNumber
|
|
|
|
|
|
+ val tag = "SubscriptionViewModel"
|
|
|
+ val prefHelper = BasePreferenceHelper(context)
|
|
|
+ private var skuDetailsList: List<SkuDetails>? = null
|
|
|
+
|
|
|
+ var featuresList = MutableLiveData<MutableList<ProductFeatures>>()
|
|
|
+ var featuresListSorted = MutableLiveData<MutableList<ProductFeatures>>()
|
|
|
+
|
|
|
+
|
|
|
+ private val billingClient: BillingClient by lazy {
|
|
|
+ BillingClient.newBuilder(context)
|
|
|
+ .setListener(this)
|
|
|
+ .enablePendingPurchases()
|
|
|
+ .build()
|
|
|
+ }
|
|
|
+
|
|
|
init {
|
|
|
this.context = context
|
|
|
this.activity = activity
|
|
|
preferenceHelper = BasePreferenceHelper(context)
|
|
|
+
|
|
|
+ startConnection(getSelectedPosition())
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- fun setNumber(num: Int) {
|
|
|
+ fun setSelectedPosition(num: Int) {
|
|
|
Log.d("test_plan", "[1] num = $num")
|
|
|
mutableLiveDataNumber.postValue(num)
|
|
|
Log.d("test_plan", "[2] num = $num")
|
|
@@ -77,6 +96,7 @@ class SubscriptionViewModel constructor(context: Context, activity: ComponentAct
|
|
|
|
|
|
data?.data?.let {
|
|
|
preferenceHelper.saveFeaturesData(it)
|
|
|
+ featuresList.value = it
|
|
|
}
|
|
|
mutableLiveDataProducts.value = data
|
|
|
mutableLiveDataProductsErrorStatus.value = false
|
|
@@ -101,22 +121,6 @@ class SubscriptionViewModel constructor(context: Context, activity: ComponentAct
|
|
|
)
|
|
|
}
|
|
|
|
|
|
- val tag = "SubscriptionViewModel"
|
|
|
- val prefHelper = BasePreferenceHelper(context)
|
|
|
- private var skuDetailsList: List<SkuDetails>? = null
|
|
|
-
|
|
|
- private val billingClient: BillingClient by lazy {
|
|
|
- BillingClient.newBuilder(context)
|
|
|
- .setListener(this)
|
|
|
- .enablePendingPurchases()
|
|
|
- .build()
|
|
|
- }
|
|
|
-
|
|
|
- init {
|
|
|
- Log.d(tag, "init Billing")
|
|
|
-// startConnection()
|
|
|
- }
|
|
|
-
|
|
|
fun startConnection(selectedPosition: Int) {
|
|
|
this.selectedPosition = selectedPosition
|
|
|
Log.d(tag, "startConnection Billing")
|
|
@@ -178,9 +182,8 @@ class SubscriptionViewModel constructor(context: Context, activity: ComponentAct
|
|
|
Log.d(tag, "[2nd] ${skuDetails.title} Billing")
|
|
|
skuDetailsListsSubs.add(skuDetails)
|
|
|
}
|
|
|
- subscriptionProduct(selectedPosition, skuDetailsListsSubs, activity)
|
|
|
- mutableLiveDataSkuDetails.value = skuDetailsListsSubs
|
|
|
-
|
|
|
+ mutableLiveDataSkuDetails.postValue(skuDetailsListsSubs)
|
|
|
+// subscriptionProduct(selectedPosition, skuDetailsListsSubs, activity)
|
|
|
|
|
|
// initProductList(skuDetailsListsSubs)
|
|
|
}
|
|
@@ -207,31 +210,33 @@ class SubscriptionViewModel constructor(context: Context, activity: ComponentAct
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// private fun initProductList(skuDetailsList: List<SkuDetails>) {
|
|
|
-//
|
|
|
-// this.skuDetailsList = skuDetailsList
|
|
|
-// if (this.skuDetailsList?.size!! > 0) {
|
|
|
-//
|
|
|
-// var boolValue: Boolean
|
|
|
-// var freePeriod: String
|
|
|
-// var title: String
|
|
|
-// var selectFeatureListSorted = ArrayList<ProductFeatures>()
|
|
|
-//
|
|
|
-// for ((index, value) in skuDetailsList.withIndex()){
|
|
|
-// for ((indexed, values) in featuresList.withIndex()){
|
|
|
-//
|
|
|
-// if (value.sku == values.identifier)
|
|
|
-// {
|
|
|
-// Log.d("value of sku", "Equal => $index + $indexed")
|
|
|
-// featuresListSorted.add(featuresList.get(indexed))
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// featuresListSorted.forEachIndexed { index, productFeatures ->
|
|
|
-// Log.d("featuresListSorted", "${productFeatures.title} + ${productFeatures.identifier} + ${productFeatures.price}")
|
|
|
-// }
|
|
|
-//
|
|
|
+ private fun initProductList(skuDetailsList: List<SkuDetails>) {
|
|
|
+
|
|
|
+ this.skuDetailsList = skuDetailsList
|
|
|
+ if (this.skuDetailsList?.size!! > 0) {
|
|
|
+
|
|
|
+ var boolValue: Boolean
|
|
|
+ var freePeriod: String
|
|
|
+ var title: String
|
|
|
+ var selectFeatureListSorted = ArrayList<ProductFeatures>()
|
|
|
+
|
|
|
+ featuresList.value?.let {
|
|
|
+ for ((index, value) in skuDetailsList.withIndex()){
|
|
|
+ for ((indexed, values) in it.withIndex()){
|
|
|
+ if (value.sku == values.identifier)
|
|
|
+ {
|
|
|
+ Log.d("value_of_sku", "Equal => $index + $indexed")
|
|
|
+ featuresListSorted.value?.add(it.get(indexed))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ featuresListSorted.value?.forEachIndexed { index, productFeatures ->
|
|
|
+ Log.d("featuresListSorted", "${productFeatures.title} + ${productFeatures.identifier} + ${productFeatures.price}")
|
|
|
+ }
|
|
|
+
|
|
|
// for ((index, value) in skuDetailsList.withIndex()){
|
|
|
//
|
|
|
// Log.d("value of 1", value.title + " ," + value.freeTrialPeriod + "=>" + featuresList.get(index).identifier)
|
|
@@ -264,15 +269,11 @@ class SubscriptionViewModel constructor(context: Context, activity: ComponentAct
|
|
|
// }
|
|
|
//
|
|
|
// selectPriceList.forEachIndexed { index, upgradePriceList ->
|
|
|
-//
|
|
|
// if (upgradePriceList.isEnabled) {
|
|
|
// selectedPosition = index
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
-// requireActivity().runOnUiThread(Runnable {
|
|
|
-// if (isVisible) mainActivity.hideLoading()
|
|
|
-//
|
|
|
// upgradeListAdapter.data.clear()
|
|
|
// if (featuresList.size > 1)
|
|
|
// {
|
|
@@ -282,16 +283,9 @@ class SubscriptionViewModel constructor(context: Context, activity: ComponentAct
|
|
|
// {
|
|
|
// upgradeListAdapter.setNewData(featuresListSorted.get(0).features)
|
|
|
// }
|
|
|
-//
|
|
|
-// selectPriceListAdapter.data.clear()
|
|
|
-// selectPriceListAdapter.setNewData(selectPriceList)
|
|
|
-// selectPriceListAdapter.notifyDataSetChanged()
|
|
|
-// mDialogBoxes?.hideProgress()
|
|
|
-//
|
|
|
-// })
|
|
|
-// }
|
|
|
-// }
|
|
|
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
override fun onPurchasesUpdated(p0: BillingResult, p1: MutableList<Purchase>?) {
|
|
|
}
|