Skip to content
This repository was archived by the owner on Jan 29, 2024. It is now read-only.

Commit 687cdd0

Browse files
committed
fix: fix sharedpreferences hilt issue
1 parent fa6b076 commit 687cdd0

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ org.gradle.parallel=true
1919

2020
android.useAndroidX=true
2121

22-
VERSION_NAME=2.4.2
22+
VERSION_NAME=2.4.3
2323
# 1*100*100 + 0*100 + 0 => 10000
24-
VERSION_CODE=20402
24+
VERSION_CODE=20403
2525
GROUP=io.requestly
2626

2727
POM_REPO_NAME=Requestly Android SDK

requestly-android-okhttp/src/main/kotlin/io/requestly/android/okhttp/internal/support/RequestProcessor.kt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,28 @@ internal class RequestProcessor(
3131
) {
3232

3333
private val switchingRulesMap = HashMap<String, String>()
34-
35-
init {
34+
private var isStorageListenerInitDone = false
35+
36+
// NOT WORKING with Hilt
37+
// init {
38+
// val typeToken = object : TypeToken<List<SwitchingRule>>() {}
39+
// val storageChangeListener: () -> Unit = {
40+
// switchingRulesMap.clear()
41+
// KeyValueStorageManager.getList(HostSwitcherFragmentViewModel.KEY_NAME, typeToken)
42+
// ?.forEach {
43+
// if (it.isActive) {
44+
// switchingRulesMap[it.startingText] = it.provisionalText
45+
// }
46+
// }
47+
// }
48+
// storageChangeListener()
49+
// KeyValueStorageManager.registerChangeListener(
50+
// HostSwitcherFragmentViewModel.KEY_NAME,
51+
// storageChangeListener
52+
// )
53+
// }
54+
55+
private fun initStorageListener() {
3656
val typeToken = object : TypeToken<List<SwitchingRule>>() {}
3757
val storageChangeListener: () -> Unit = {
3858
switchingRulesMap.clear()
@@ -48,9 +68,14 @@ internal class RequestProcessor(
4868
HostSwitcherFragmentViewModel.KEY_NAME,
4969
storageChangeListener
5070
)
71+
isStorageListenerInitDone = true
5172
}
5273

5374
fun process(req: Request, transaction: HttpTransaction): Request {
75+
if(!isStorageListenerInitDone) {
76+
initStorageListener()
77+
}
78+
5479
var urlString = req.url.toString()
5580
switchingRulesMap.forEach {
5681
urlString = urlString.replace(it.key, it.value, ignoreCase = true)

0 commit comments

Comments
 (0)