From f93e0e3c9dfc7be1d28de8bd8f570b6dfd47dcec Mon Sep 17 00:00:00 2001 From: ostajic Date: Sun, 13 Sep 2020 22:58:33 +0200 Subject: [PATCH 1/2] lag Fix v1 --- app/proguard-rules.pro | 3 +- .../com/vanced/manager/utils/DataManager.kt | 30 +++++++++++++++++++ .../com/vanced/manager/utils/JsonHelper.kt | 8 ++--- 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/com/vanced/manager/utils/DataManager.kt diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 25e189a8..13e2238a 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -13,7 +13,8 @@ #} -keep class com.vanced.manager.core.App - +-keep class androidx.navigation.fragment.NavHostFragment +-keep class androidx.fragment.app.FragmentContainerView # Uncomment this to preserve the line number information for # debugging stack traces. #-keepattributes SourceFile,LineNumberTable diff --git a/app/src/main/java/com/vanced/manager/utils/DataManager.kt b/app/src/main/java/com/vanced/manager/utils/DataManager.kt new file mode 100644 index 00000000..bc2b4818 --- /dev/null +++ b/app/src/main/java/com/vanced/manager/utils/DataManager.kt @@ -0,0 +1,30 @@ +package com.vanced.manager.utils + +import com.beust.klaxon.Json +import com.beust.klaxon.JsonObject +import com.beust.klaxon.Parser +import com.github.kittinunf.fuel.coroutines.awaitString +import com.github.kittinunf.fuel.httpGet + +object DataManager { + + var dataMap: HashMap = HashMap() + + suspend fun getCheckJson(url: String): com.beust.klaxon.JsonObject { + if(dataMap.containsKey(url)) + { + return dataMap[url]!! + } + else + { + dataMap[url] = getJson(url) + return dataMap[url]!! + } + } + + suspend fun getJson(url: String): com.beust.klaxon.JsonObject = + Parser.default().parse( + StringBuilder(url.httpGet().awaitString()) + ) as com.beust.klaxon.JsonObject + +} \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/utils/JsonHelper.kt b/app/src/main/java/com/vanced/manager/utils/JsonHelper.kt index 5c015eeb..5ffcf1a3 100644 --- a/app/src/main/java/com/vanced/manager/utils/JsonHelper.kt +++ b/app/src/main/java/com/vanced/manager/utils/JsonHelper.kt @@ -12,10 +12,10 @@ import kotlinx.coroutines.withContext object JsonHelper { - suspend fun getJson(url: String): JsonObject = - Parser.default().parse( - StringBuilder(url.httpGet().awaitString()) - ) as JsonObject + suspend fun getJson(url: String): JsonObject + { + return DataManager.getCheckJson(url) + } suspend fun getJsonArray(url: String): JsonArray = Klaxon().parseArray( From b776595059a29cea58f8def5f73b3f6f73aa7eff Mon Sep 17 00:00:00 2001 From: ostajic Date: Sun, 13 Sep 2020 23:48:03 +0200 Subject: [PATCH 2/2] lag Fix v1 --- .../com/vanced/manager/utils/DataManager.kt | 30 ------------------- .../com/vanced/manager/utils/JsonHelper.kt | 17 ++++++++++- 2 files changed, 16 insertions(+), 31 deletions(-) delete mode 100644 app/src/main/java/com/vanced/manager/utils/DataManager.kt diff --git a/app/src/main/java/com/vanced/manager/utils/DataManager.kt b/app/src/main/java/com/vanced/manager/utils/DataManager.kt deleted file mode 100644 index bc2b4818..00000000 --- a/app/src/main/java/com/vanced/manager/utils/DataManager.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.vanced.manager.utils - -import com.beust.klaxon.Json -import com.beust.klaxon.JsonObject -import com.beust.klaxon.Parser -import com.github.kittinunf.fuel.coroutines.awaitString -import com.github.kittinunf.fuel.httpGet - -object DataManager { - - var dataMap: HashMap = HashMap() - - suspend fun getCheckJson(url: String): com.beust.klaxon.JsonObject { - if(dataMap.containsKey(url)) - { - return dataMap[url]!! - } - else - { - dataMap[url] = getJson(url) - return dataMap[url]!! - } - } - - suspend fun getJson(url: String): com.beust.klaxon.JsonObject = - Parser.default().parse( - StringBuilder(url.httpGet().awaitString()) - ) as com.beust.klaxon.JsonObject - -} \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/utils/JsonHelper.kt b/app/src/main/java/com/vanced/manager/utils/JsonHelper.kt index 5ffcf1a3..2ec6b81f 100644 --- a/app/src/main/java/com/vanced/manager/utils/JsonHelper.kt +++ b/app/src/main/java/com/vanced/manager/utils/JsonHelper.kt @@ -12,11 +12,26 @@ import kotlinx.coroutines.withContext object JsonHelper { + var dataMap: HashMap = HashMap() + suspend fun getJson(url: String): JsonObject { - return DataManager.getCheckJson(url) + if(dataMap.containsKey(url)) + { + return dataMap[url]!! + } + else + { + dataMap[url] = getSuspendJson(url) + return dataMap[url]!! + } } + suspend fun getSuspendJson(url: String): com.beust.klaxon.JsonObject = + Parser.default().parse( + StringBuilder(url.httpGet().awaitString()) + ) as com.beust.klaxon.JsonObject + suspend fun getJsonArray(url: String): JsonArray = Klaxon().parseArray( url.httpGet().awaitString()