|
@@ -8,17 +8,36 @@ import com.google.gson.Gson
|
|
|
import com.google.gson.reflect.TypeToken
|
|
|
import com.vpn.fastestvpnservice.beans.DataResponseServers
|
|
|
import com.vpn.fastestvpnservice.beans.ServerData
|
|
|
+import com.vpn.fastestvpnservice.constants.AppEnum
|
|
|
import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
|
|
|
+import com.vpn.fastestvpnservice.openVpnUtils.EncryptData
|
|
|
import com.vpn.fastestvpnservice.retrofit.RetrofitNetworkHandling
|
|
|
import com.vpn.fastestvpnservice.retrofit.WebServiceFactory
|
|
|
import retrofit2.Call
|
|
|
+import java.io.BufferedReader
|
|
|
+import java.io.InputStream
|
|
|
+import java.io.InputStreamReader
|
|
|
|
|
|
class SplashViewModel constructor(context: Context): ViewModel() {
|
|
|
val mutableLiveDataServerData = MutableLiveData<DataResponseServers<ArrayList<ServerData>>>()
|
|
|
var preferenceHelper: BasePreferenceHelper
|
|
|
+ var context: Context
|
|
|
|
|
|
init {
|
|
|
+ this.context = context
|
|
|
preferenceHelper = BasePreferenceHelper(context)
|
|
|
+
|
|
|
+ val jsonAppDetails = getJsonAppDetails()
|
|
|
+ val jsonFileDetails = getJsonFileDetails()
|
|
|
+
|
|
|
+ jsonAppDetails?.let {
|
|
|
+ val En = EncryptData()
|
|
|
+ preferenceHelper.saveAppDetails(En.encrypt(it))
|
|
|
+ }
|
|
|
+ jsonFileDetails?.let {
|
|
|
+ val En = EncryptData()
|
|
|
+ preferenceHelper.saveFileDetails(En.encrypt(it))
|
|
|
+ }
|
|
|
}
|
|
|
fun serverDataApi() {
|
|
|
Log.d("test_api_response_s", "serverDataApi called()")
|
|
@@ -77,4 +96,65 @@ class SplashViewModel constructor(context: Context): ViewModel() {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private fun getJsonFileDetails(): String? {
|
|
|
+ val protocol = AppEnum.UDP_PROTOCOL.key
|
|
|
+ var conf: InputStream? = null
|
|
|
+ try {
|
|
|
+ conf = if (protocol.equals(AppEnum.TCP_PROTOCOL.key, ignoreCase = true)) {
|
|
|
+ context.assets.open("fileDetails/fileDetails.json")
|
|
|
+ } else {
|
|
|
+ context.assets.open("fileDetails/fileDetails.json")
|
|
|
+ }
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ var bufferedReader: BufferedReader? = null
|
|
|
+ var isr: InputStreamReader? = null
|
|
|
+ try {
|
|
|
+ isr = InputStreamReader(conf)
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ bufferedReader = BufferedReader(isr)
|
|
|
+ val total = StringBuilder()
|
|
|
+ var line: String?
|
|
|
+ while (bufferedReader.readLine().also { line = it } != null) {
|
|
|
+ total.append(line).append('\n')
|
|
|
+ }
|
|
|
+ return total.toString()
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getJsonAppDetails(): String? {
|
|
|
+ var conf: InputStream? = null
|
|
|
+ try {
|
|
|
+ conf = context.assets.open("appDetails/appDetails.json")
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ var bufferedReader: BufferedReader? = null
|
|
|
+ var isr: InputStreamReader? = null
|
|
|
+ try {
|
|
|
+ isr = InputStreamReader(conf)
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ bufferedReader = BufferedReader(isr)
|
|
|
+ val total = StringBuilder()
|
|
|
+ var line: String?
|
|
|
+ while (bufferedReader.readLine().also { line = it } != null) {
|
|
|
+ total.append(line).append('\n')
|
|
|
+ }
|
|
|
+ return total.toString()
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+
|
|
|
}
|