Browse Source

subscription almost done, working on UI ...

Khubaib 1 year ago
parent
commit
e0fbca144a

+ 13 - 2
app/src/main/java/com/vpn/fastestvpnservice/MainActivity.kt

@@ -19,15 +19,21 @@ import androidx.compose.runtime.remember
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.graphics.toArgb
+import androidx.compose.ui.platform.LocalContext
 import androidx.compose.ui.res.colorResource
 import androidx.compose.ui.tooling.preview.Preview
+import androidx.lifecycle.ViewModelProvider
+import androidx.lifecycle.get
 import androidx.lifecycle.viewmodel.compose.viewModel
 import androidx.navigation.compose.rememberNavController
+import com.vpn.fastestvpnservice.application.App
 import com.vpn.fastestvpnservice.beans.isDarkTheme
 import com.vpn.fastestvpnservice.beans.selectedtheme
 import com.vpn.fastestvpnservice.beans.themesList
+import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
 import com.vpn.fastestvpnservice.navigation.SetUpNavGraph
 import com.vpn.fastestvpnservice.ui.theme.FastestVPNTheme
+import com.vpn.fastestvpnservice.viewmodels.BillingViewModel
 import com.vpn.fastestvpnservice.viewmodels.LoginViewModel
 
 class MainActivity : ComponentActivity() {
@@ -35,20 +41,25 @@ class MainActivity : ComponentActivity() {
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
+
+
         setContent {
+            val context = LocalContext.current
+            val basePreferenceHelper = BasePreferenceHelper(context)
+            val selectedTheme = basePreferenceHelper.getTheme()
 
             val isSystemInDarkTheme = isSystemInDarkTheme()
             val systemTheme by remember { mutableStateOf(isSystemInDarkTheme) }
             if (selectedtheme.value == themesList[0])
             {
-                Log.d("test_theme", "System 0 -> ${selectedtheme.value}")
+                Log.d("test_theme", "System 0 -> ${selectedTheme}")
                 isDarkTheme.value = systemTheme
             }
 
             FastestVPNTheme(isDarkTheme.value) {
                 window.statusBarColor = colorResource(id = R.color.blue_text).toArgb()
                 val navController = rememberNavController()
-                SetUpNavGraph(navHostController = navController)
+                SetUpNavGraph(navHostController = navController, this)
             }
 
         }

+ 4 - 3
app/src/main/java/com/vpn/fastestvpnservice/customItems/SubscriptionPackageItem.kt

@@ -38,6 +38,7 @@ import androidx.compose.ui.text.style.TextAlign
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
+import androidx.core.app.ComponentActivity
 import androidx.lifecycle.viewmodel.compose.viewModel
 import androidx.navigation.compose.rememberNavController
 import com.vpn.fastestvpnservice.R
@@ -49,7 +50,7 @@ import java.util.Random
 var getPosition: Int = 0
 
 @Composable
-fun SubscriptionPackageItem(item: SubscriptionPackageList, position: Int) {
+fun SubscriptionPackageItem(item: SubscriptionPackageList, position: Int, activity: ComponentActivity) {
 
     val context = LocalContext.current
     var selectedPosition by remember { mutableIntStateOf(0) }
@@ -57,7 +58,7 @@ fun SubscriptionPackageItem(item: SubscriptionPackageList, position: Int) {
     var isSelected by remember { mutableStateOf(true) }
     val random = kotlin.random.Random.nextInt(1, 999)
     val subscriptionViewModel: SubscriptionViewModel = viewModel{
-        SubscriptionViewModel(context = context)
+        SubscriptionViewModel(context = context, activity)
     }
 
     Box(
@@ -219,5 +220,5 @@ fun getSelectedPosition(): Int {
 @Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
 @Composable
 fun SubscriptionPackageItemPreview() {
-    SubscriptionPackageItem(subscriptionPackageList[1], 0)
+//    SubscriptionPackageItem(subscriptionPackageList[1], 0)
 }

+ 11 - 0
app/src/main/java/com/vpn/fastestvpnservice/helpers/BasePreferenceHelper.kt

@@ -37,6 +37,7 @@ class BasePreferenceHelper(private val context: Context) : PreferencesHelper() {
         removePreference(context, KEY_FILENAME, TV_SPLIT_CLASS)
         removePreference(context, KEY_FILENAME, KEY_ADBLOCK_SWITCH)
         removePreference(context, KEY_FILENAME, KEY_ISLOGGEDIN)
+        removePreference(context, KEY_FILENAME, THEME)
     }
 
     fun saveUser(user: UserResponse) {
@@ -349,6 +350,15 @@ class BasePreferenceHelper(private val context: Context) : PreferencesHelper() {
     }
 
 
+    fun saveTheme(theme: String) {
+        putStringPreference(context, KEY_FILENAME, THEME, theme)
+    }
+
+    fun getTheme(): String {
+        return getStringPreference(context, KEY_FILENAME, THEME)
+    }
+
+
     fun saveTvSplitTunnel(tvSplitTunneling: ArrayList<TvSplitTunneling>) {
         putStringPreference(context, KEY_FILENAME, TV_SPLIT_CLASS, Gson().toJson(tvSplitTunneling))
     }
@@ -448,5 +458,6 @@ class BasePreferenceHelper(private val context: Context) : PreferencesHelper() {
         private const val KEY_ACTIVITY = "keydata_activity"
         private const val KEY_ADBLOCK_SWITCH = "keydata_adblock"
         private const val KEY_ISLOGGEDIN = "key_isloggedin"
+        private const val THEME = "key_theme"
     }
 }

+ 5 - 2
app/src/main/java/com/vpn/fastestvpnservice/navigation/BottomBarNavGraph.kt

@@ -1,6 +1,7 @@
 package com.vpn.fastestvpnservice.navigation
 
 import androidx.compose.runtime.Composable
+import androidx.core.app.ComponentActivity
 import androidx.navigation.NavHostController
 import androidx.navigation.compose.NavHost
 import androidx.navigation.compose.composable
@@ -25,7 +26,9 @@ import com.vpn.fastestvpnservice.sealedClass.BottomBarScreen
 import com.vpn.fastestvpnservice.sealedClass.Screen
 
 @Composable
-fun BottomBarNavGraph(navHostController: NavHostController, settingsNavHostController: NavHostController) {
+fun BottomBarNavGraph(navHostController: NavHostController,
+                      settingsNavHostController: NavHostController,
+                      activity: ComponentActivity) {
     NavHost(navController = navHostController,
         startDestination = BottomBarScreen.Home.route) {
 
@@ -71,7 +74,7 @@ fun BottomBarNavGraph(navHostController: NavHostController, settingsNavHostContr
         }
         composable(route = Screen.Subscription.route) {
 //            SubscriptionScreenFragment(navHostController = navHostController)
-            SubscriptionScreen(navHostController)
+            SubscriptionScreen(navHostController, activity)
         }
         composable(route = Screen.CustomerSupport.route) {
             CustomerSupport(navHostController = navHostController)

+ 3 - 2
app/src/main/java/com/vpn/fastestvpnservice/navigation/NavGraph.kt

@@ -1,6 +1,7 @@
 package com.vpn.fastestvpnservice.navigation
 
 import androidx.compose.runtime.Composable
+import androidx.core.app.ComponentActivity
 import androidx.lifecycle.viewmodel.compose.viewModel
 import androidx.navigation.NavHostController
 import androidx.navigation.compose.NavHost
@@ -15,7 +16,7 @@ import com.vpn.fastestvpnservice.screens.helpScreensAll.FAQ
 import com.vpn.fastestvpnservice.sealedClass.Screen
 
 @Composable
-fun SetUpNavGraph(navHostController: NavHostController) {
+fun SetUpNavGraph(navHostController: NavHostController, activity: ComponentActivity) {
     NavHost(navController = navHostController,
         startDestination = Screen.Splash.route,
         ) {
@@ -35,7 +36,7 @@ fun SetUpNavGraph(navHostController: NavHostController) {
             Started(navHostController = navHostController)
         }
         composable(route = Screen.BottomBarMainScreen.route) {
-            BottomBarMainScreen(navController = navHostController)
+            BottomBarMainScreen(navController = navHostController, activity)
         }
     }
 }

+ 7 - 4
app/src/main/java/com/vpn/fastestvpnservice/screens/BottomBarMainScreen.kt

@@ -1,5 +1,6 @@
 package com.vpn.fastestvpnservice.screens
 
+import android.app.Activity
 import android.content.res.Configuration
 import android.util.Log
 import androidx.compose.foundation.layout.Box
@@ -30,6 +31,7 @@ import androidx.compose.ui.res.colorResource
 import androidx.compose.ui.res.painterResource
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
+import androidx.core.app.ComponentActivity
 import androidx.navigation.NavDestination
 import androidx.navigation.NavDestination.Companion.hierarchy
 import androidx.navigation.NavGraph.Companion.findStartDestination
@@ -41,7 +43,7 @@ import com.vpn.fastestvpnservice.navigation.BottomBarNavGraph
 import com.vpn.fastestvpnservice.sealedClass.BottomBarScreen
 
 @Composable
-fun BottomBarMainScreen(navController: NavHostController) {
+fun BottomBarMainScreen(navController: NavHostController, activity: ComponentActivity) {
     val navController1 = rememberNavController()
     var isBottomBarVisible by remember { mutableStateOf(true) }
 
@@ -66,7 +68,8 @@ fun BottomBarMainScreen(navController: NavHostController) {
         content = { padding ->
             Box(modifier = Modifier.padding(padding)) {
                 BottomBarNavGraph(navHostController = navController1,
-                    settingsNavHostController = navController)
+                    settingsNavHostController = navController,
+                    activity)
             }
         }
     )
@@ -180,11 +183,11 @@ fun currentRoute(navController: NavHostController): String? {
 @Composable
 @Preview
 fun BottomNavBarPreview() {
-    BottomBarMainScreen(rememberNavController())
+//    BottomBarMainScreen(rememberNavController())
 }
 
 @Composable
 @Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
 fun BottomNavBarPreviewDark() {
-    BottomBarMainScreen(rememberNavController())
+//    BottomBarMainScreen(rememberNavController())
 }

+ 2 - 0
app/src/main/java/com/vpn/fastestvpnservice/screens/LoginScreen.kt

@@ -95,6 +95,7 @@ import androidx.navigation.compose.rememberNavController
 import com.vpn.fastestvpnservice.R
 import com.vpn.fastestvpnservice.beans.DataResponse
 import com.vpn.fastestvpnservice.beans.UserResponse
+import com.vpn.fastestvpnservice.beans.themesList
 import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
 import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.AddText
 import com.vpn.fastestvpnservice.sealedClass.Screen
@@ -532,6 +533,7 @@ fun BoxScope.SignInButton(
                     prefHelper.saveAvailableProtocols(it.available_protocols)
                     prefHelper.saveXPlatformToken(it.userinfo?.email + "_" + System.currentTimeMillis())
                     prefHelper.saveAdBlockState(false)
+                    prefHelper.saveTheme(themesList[0])
 
                     it.servers?.let {
                         prefHelper.saveServerData(it)

+ 16 - 47
app/src/main/java/com/vpn/fastestvpnservice/screens/accountScreensAll/SubscriptionScreen.kt

@@ -65,6 +65,7 @@ import androidx.fragment.app.Fragment
 import androidx.lifecycle.Lifecycle
 import androidx.lifecycle.LifecycleEventObserver
 import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.ViewModelProvider
 import androidx.lifecycle.viewmodel.compose.viewModel
 import androidx.navigation.NavHostController
 import androidx.navigation.compose.rememberNavController
@@ -86,55 +87,21 @@ import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.OnLifecycleEvent
 import com.vpn.fastestvpnservice.sealedClass.Screen
 import com.vpn.fastestvpnservice.ui.theme.FastestVPNTheme
 import com.vpn.fastestvpnservice.utils.Utils
+import com.vpn.fastestvpnservice.viewmodels.BillingViewModel
 import com.vpn.fastestvpnservice.viewmodels.SubscriptionViewModel
 
 
 @OptIn(ExperimentalFoundationApi::class)
 @Composable
-fun SubscriptionScreen(navHostController: NavHostController)
+fun SubscriptionScreen(navHostController: NavHostController, activity: ComponentActivity)
 {
 
-//    class SubscriptionScreenFragment(navHostController: NavHostController): Fragment() {
-//        var navHostController: NavHostController
-//
-//        init {
-//            this.navHostController = navHostController
-//        }
-//        override fun onCreateView(
-//            inflater: LayoutInflater,
-//            container: ViewGroup?,
-//            savedInstanceState: Bundle?
-//        ): View? {
-//            return ComposeView(requireContext()).apply {
-//                Log.d("test_compose_fragment", "SubscriptionScreenFragment")
-//                setContent {
-//                    FastestVPNTheme {
-//                        Box(
-//                            modifier = Modifier
-//                                .fillMaxSize()
-//                                .fillMaxWidth()
-//                                .fillMaxHeight()
-//                                .background(Color.Gray)
-//                        ) {
-//
-//                            Text(text = "Test")
-////                        SubscriptionScreen(navHostController = navHostController)
-//
-//                        }
-//                    }
-//
-//                }
-//            }
-//        }
-//    }
 
     val context = LocalContext.current
     val subscriptionViewModel: SubscriptionViewModel = viewModel{
-        SubscriptionViewModel(context = context)
-    }
-    var selectedPosition by remember {
-        mutableStateOf(0)
+        SubscriptionViewModel(context = context, activity)
     }
+    var selectedPosition: Int = 0
     var skuDetailsList: List<SkuDetails>? = null
 
 
@@ -179,13 +146,14 @@ fun SubscriptionScreen(navHostController: NavHostController)
                     LocalOverscrollConfiguration provides null
                 ) {
 
-                    val productsData = subscriptionViewModel.liveDataProducts.observeAsState().value
+//                    val productsData = subscriptionViewModel.liveDataProducts.observeAsState().value
 
+                    val productsData = subscriptionViewModel.mutableLiveDataProducts.observeAsState()
                     LazyColumn() {
 
                         selectedPosition = getSelectedPosition()
 
-                        productsData?.let {
+                        productsData.value?.let {
 
                             it.data?.let {
                                 Log.d("test_api_response_p",
@@ -206,7 +174,7 @@ fun SubscriptionScreen(navHostController: NavHostController)
 
                         item { Spacer(modifier = Modifier.height(20.dp)) }
                         itemsIndexed(items = subscriptionPackageList) {position, plan ->
-                            SubscriptionPackageItem(item = plan, position)
+                            SubscriptionPackageItem(item = plan, position, activity)
                         }
                         item { Spacer(modifier = Modifier.height(20.dp)) }
                     }
@@ -214,15 +182,16 @@ fun SubscriptionScreen(navHostController: NavHostController)
             }
         }
 
+//        val skuDetailsListsSubs = subscriptionViewModel.liveDataSkuDetails.observeAsState()
+
         Button(
+
             onClick = {
                 Log.d("test_button", "onClick")
                 selectedPosition = getSelectedPosition()
-                Toast
-                    .makeText(
-                        context, subscriptionPackageList[selectedPosition].packageDuration, Toast.LENGTH_SHORT
-                    )
-                    .show()
+//                Log.d("SubscriptionViewModel", "liveData ${skuDetailsListsSubs.value}")
+
+                subscriptionViewModel.startConnection(selectedPosition)
 
             },
             modifier = Modifier
@@ -321,5 +290,5 @@ fun BoxScope.HeaderRowSS(navHostController: NavHostController) {
 @Preview
 @Composable
 fun SubscriptionScreenPreview() {
-    SubscriptionScreen(rememberNavController())
+//    SubscriptionScreen(rememberNavController(), ComponentActivity())
 }

+ 43 - 12
app/src/main/java/com/vpn/fastestvpnservice/screens/bottomNavBarScreens/SettingsScreen.kt

@@ -2,6 +2,10 @@ package com.vpn.fastestvpnservice.screens.bottomNavBarScreens
 
 import android.accessibilityservice.GestureDescription
 import android.app.Activity
+import android.content.Context
+import android.content.Intent
+import android.os.Build
+import android.os.Bundle
 import android.util.Log
 import android.widget.Toast
 import androidx.compose.foundation.Image
@@ -83,6 +87,7 @@ import androidx.compose.ui.unit.Dp
 import androidx.compose.ui.unit.TextUnit
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
+import androidx.core.content.ContextCompat.startActivity
 import androidx.navigation.NavHostController
 import androidx.navigation.compose.rememberNavController
 import com.vpn.fastestvpnservice.R
@@ -133,10 +138,10 @@ fun Settings(navHostController: NavHostController) {
                 text = "VPN Protocols",
                 desc = "WireGuard"
             )
-            AddRowSwitch(
-                icon = R.drawable.autoconnect3x,
-                text = "Auto Connect"
-            )
+//            AddRowSwitch(
+//                icon = R.drawable.autoconnect3x,
+//                text = "Auto Connect"
+//            )
             AddRowSettingsSmart(
                 icon = R.drawable.smart_connect3x,
                 text = "Smart Connect",
@@ -147,9 +152,15 @@ fun Settings(navHostController: NavHostController) {
                 icon = R.drawable.adblock3x,
                 text = "AdBlock"
             )
-            AddRowSwitch(
+            val context = LocalContext.current
+            AddRowSettings(
                 icon = R.drawable.kill_switch3x,
-                text = "Kill Switch"
+                text = "Kill Switch",
+                onClick = {
+                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+                        gotoVPNSettings(context)
+                    }
+                }
             )
             AddRowSettings(
                 icon = R.drawable.split_tunneling3x,
@@ -168,6 +179,16 @@ fun Settings(navHostController: NavHostController) {
     }
 }
 
+private fun gotoVPNSettings(context: Context) {
+    try {
+        val intent = Intent("android.net.vpn.SETTINGS")
+        intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
+        startActivity(context, intent, Bundle())
+    } catch (e: Exception) {
+        e.printStackTrace()
+    }
+}
+
 @Composable
 fun ColumnScope.AddRowSwitch(icon: Int, text: String) {
     Row(
@@ -610,12 +631,22 @@ fun AddRowDarkLightTheme(
                                 .fillMaxWidth()
                                 .background(Color.Transparent)
                                 .padding(start = 2.dp)
-//                                    .selectable(
-//                                        selected = selectedProtocol == protocol,
-//                                        onClick = {
-//                                            selectedProtocol = protocol
-//                                        },
-//                                    )
+                                    .selectable(
+                                        selected = theme == selectedtheme.value,
+                                        onClick = {
+                                             selectedtheme.value = theme
+
+                                            if (selectedtheme.value == themesList[0])
+                                            {
+                                                Log.d("test_theme", "true: -> $systemTheme")
+                                                isDarkTheme.value = systemTheme
+                                            }
+                                            else {
+                                                Log.d("test_theme", "false: -> $systemTheme")
+                                                isDarkTheme.value = selectedtheme.value == themesList[2]
+                                            }
+                                        },
+                                    )
 //                                    .indication(
 //                                        indication = null,
 //                                        interactionSource = remember {

+ 8 - 1
app/src/main/java/com/vpn/fastestvpnservice/viewmodels/BillingViewModel.kt

@@ -15,9 +15,11 @@ import com.vpn.fastestvpnservice.beans.ProductFeatures
 import com.vpn.fastestvpnservice.beans.UpgradePriceList
 import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
 
-class BillingViewModel(application: App): AndroidViewModel(application),
+public class BillingViewModel(application: App): AndroidViewModel(application),
     PurchasesUpdatedListener
 {
+
+
     val tag = "BillingViewModel"
     val prefHelper = BasePreferenceHelper(application.applicationContext)
     private var skuDetailsList: List<SkuDetails>? = null
@@ -30,10 +32,13 @@ class BillingViewModel(application: App): AndroidViewModel(application),
     }
 
     init {
+        Log.d(tag, "init Billing")
         startConnection()
     }
 
     private fun startConnection() {
+        Log.d(tag, "startConnection Billing")
+
         billingClient.startConnection(object : BillingClientStateListener {
 
             override fun onBillingSetupFinished(billingResult: BillingResult) {
@@ -54,6 +59,8 @@ class BillingViewModel(application: App): AndroidViewModel(application),
     }
 
     private fun onLoadProductsClicked() {
+        Log.d(tag, "onLoadProductsClicked Billing")
+
 //        val skuList = listOf("com.fastestvpn.vpn.one.month", "com.fastestvpn.vpn.one.year")
         val skuList: ArrayList<String> = ArrayList<String>()
 

+ 221 - 1
app/src/main/java/com/vpn/fastestvpnservice/viewmodels/SubscriptionViewModel.kt

@@ -1,29 +1,52 @@
 package com.vpn.fastestvpnservice.viewmodels
 
+import android.app.Activity
 import android.content.Context
 import android.util.Log
+import androidx.compose.runtime.mutableStateOf
+import androidx.core.app.ComponentActivity
 import androidx.lifecycle.LiveData
 import androidx.lifecycle.MutableLiveData
 import androidx.lifecycle.ViewModel
+import com.android.billingclient.api.BillingClient
+import com.android.billingclient.api.BillingClientStateListener
+import com.android.billingclient.api.BillingFlowParams
+import com.android.billingclient.api.BillingResult
+import com.android.billingclient.api.Purchase
+import com.android.billingclient.api.PurchasesUpdatedListener
+import com.android.billingclient.api.SkuDetails
+import com.android.billingclient.api.SkuDetailsParams
 import com.google.gson.Gson
 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.helpers.BasePreferenceHelper
 import com.vpn.fastestvpnservice.retrofit.RetrofitNetworkHandling
 import com.vpn.fastestvpnservice.retrofit.WebServiceFactory
+import com.vpn.fastestvpnservice.screens.accountScreensAll.SubscriptionScreen
 import retrofit2.Call
 
-class SubscriptionViewModel constructor(context: Context): ViewModel() {
+class SubscriptionViewModel constructor(context: Context, activity: ComponentActivity): ViewModel(), PurchasesUpdatedListener {
 
     var mutableLiveDataProducts = MutableLiveData<DataResponse<ArrayList<ProductFeatures>>>()
     var liveDataProducts: LiveData<DataResponse<ArrayList<ProductFeatures>>> = mutableLiveDataProducts
 
+
+    var mutableLiveDataSkuDetails = MutableLiveData<MutableList<SkuDetails>>()
+    var liveDataSkuDetails: LiveData<MutableList<SkuDetails>> = mutableLiveDataSkuDetails
+
     var mutableLiveDataProductsErrorStatus = MutableLiveData<Boolean>()
 
     var preferenceHelper: BasePreferenceHelper
+    private var context: Context
+    private var activity: ComponentActivity
+
+    private var selectedPosition: Int = 0
 
     init {
+        this.context = context
+        this.activity = activity
         preferenceHelper = BasePreferenceHelper(context)
     }
 
@@ -70,4 +93,201 @@ class SubscriptionViewModel constructor(context: Context): ViewModel() {
         )
     }
 
+
+
+    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")
+
+        billingClient.startConnection(object : BillingClientStateListener {
+
+            override fun onBillingSetupFinished(billingResult: BillingResult) {
+                if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
+                    Log.d(tag, "onBillingSetupFinished")
+                    Log.d(tag, "BILLING | startConnection | RESULT OK")
+                    onLoadProductsClicked()
+                } else {
+                    Log.d(tag, "BILLING | startConnection | RESULT: ${billingResult.responseCode}")
+                }
+            }
+
+            override fun onBillingServiceDisconnected() {
+                Log.d(tag, "BILLING | onBillingServiceDisconnected | DISCONNECTED")
+            }
+
+        })
+    }
+
+    private fun onLoadProductsClicked() {
+        Log.d(tag, "onLoadProductsClicked Billing")
+
+//        val skuList = listOf("com.fastestvpn.vpn.one.month", "com.fastestvpn.vpn.one.year")
+        val skuList: ArrayList<String> = ArrayList<String>()
+
+        val identifierProduct = prefHelper.getFeaturesData()
+
+        identifierProduct.forEachIndexed { index, productFeatures ->
+            productFeatures.identifier?.let { skuList.add(it) }
+        }
+
+        skuList.forEachIndexed { index, s ->
+            Log.d("skulist identidiers", s)
+        }
+
+        val skuDetailsListsSubs: MutableList<SkuDetails> = ArrayList<SkuDetails>()
+        val params = SkuDetailsParams.newBuilder()
+        params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP)
+
+        billingClient.querySkuDetailsAsync(params.build())
+        { billingResult, skuDetailsList ->
+            if (billingResult.responseCode == BillingClient.BillingResponseCode.OK
+                && skuDetailsList != null) {
+                for (skuDetails in skuDetailsList) {
+                    Log.d(tag, "[1st] ${skuDetails.title} Billing")
+                    skuDetailsListsSubs.add(skuDetails)
+                }
+
+                params.setType(BillingClient.SkuType.SUBS)
+                billingClient.querySkuDetailsAsync(params.build())
+                { billingResults, skuDetailsLists ->
+                    if (billingResults.responseCode == BillingClient.BillingResponseCode.OK
+                        && skuDetailsLists != null) {
+                        for (skuDetails in skuDetailsLists) {
+                            Log.d(tag, "[2nd] ${skuDetails.title} Billing")
+                            skuDetailsListsSubs.add(skuDetails)
+                        }
+                        subscriptionProduct(selectedPosition, skuDetailsListsSubs, activity)
+                        mutableLiveDataSkuDetails.value = skuDetailsListsSubs
+
+
+//                        initProductList(skuDetailsListsSubs)
+                    }
+                }
+
+            }
+        }
+    }
+
+    fun subscriptionProduct(
+        selectedPosition: Int,
+        skuDetailsListsSubs: MutableList<SkuDetails>,
+        activity: ComponentActivity
+    ) {
+        Log.d(tag, "subscriptionProduct Billing $skuDetailsListsSubs")
+
+        if (skuDetailsListsSubs != null && skuDetailsListsSubs!!.isNotEmpty())
+        {
+            Log.d(tag, "subscriptionProduct IN Billing")
+
+            val billingFlowParams = BillingFlowParams.newBuilder().setSkuDetails(
+                skuDetailsListsSubs!!.get(selectedPosition)).build()
+            billingClient.launchBillingFlow(activity, billingFlowParams)
+        }
+    }
+
+//    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}")
+//            }
+//
+//            for ((index, value) in skuDetailsList.withIndex()){
+//
+//                Log.d("value of 1", value.title + " ," + value.freeTrialPeriod + "=>" + featuresList.get(index).identifier)
+//
+//                if (skuDetailsList.size > 1)
+//                {
+//                    boolValue = index == 1
+//                }
+//                else{
+//                    boolValue = index == 0
+//                }
+//
+//                if (value.freeTrialPeriod == "P3D")
+//                {
+//                    freePeriod = "Free for 3 days"
+//                } else if (value.freeTrialPeriod == "P1W")
+//                {
+//                    freePeriod = "Free for 7 days"
+//                }
+//                else
+//                {
+//                    freePeriod = ""
+//                }
+//
+//
+//                selectPriceList.add(
+//                    UpgradePriceList(value.title, value.description, value.price, freePeriod,
+//                    boolValue, index)
+//                )
+//            }
+//
+//            selectPriceList.forEachIndexed { index, upgradePriceList ->
+//
+//                if (upgradePriceList.isEnabled) {
+//                    selectedPosition = index
+//                }
+//            }
+//
+//            requireActivity().runOnUiThread(Runnable {
+//                if (isVisible) mainActivity.hideLoading()
+//
+//                upgradeListAdapter.data.clear()
+//                if (featuresList.size > 1)
+//                {
+//                    upgradeListAdapter.setNewData(featuresListSorted.get(1).features)
+//                }
+//                else if (featuresList.size > 0)
+//                {
+//                    upgradeListAdapter.setNewData(featuresListSorted.get(0).features)
+//                }
+//
+//                selectPriceListAdapter.data.clear()
+//                selectPriceListAdapter.setNewData(selectPriceList)
+//                selectPriceListAdapter.notifyDataSetChanged()
+//                mDialogBoxes?.hideProgress()
+//
+//            })
+//        }
+//    }
+
+
+    override fun onPurchasesUpdated(p0: BillingResult, p1: MutableList<Purchase>?) {
+    }
+
 }