@@ -26,6 +26,7 @@ import kotlinx.coroutines.flow.flow
26
26
27
27
class PlayRepository (
28
28
private val context : Context ,
29
+ private val playHttpClient : PlayHttpClient ,
29
30
private val gson : Gson ,
30
31
private val prefs : Prefs
31
32
) {
@@ -36,7 +37,7 @@ class PlayRepository(
36
37
private fun refreshAuth (): AuthData {
37
38
Log .i(" PlayRepository" , " Refreshing token." )
38
39
val properties = NativeDeviceInfoProvider (context).getNativeDeviceProperties()
39
- val playResponse = PlayHttpClient .postAuth(AUTH_URL , gson.toJson(properties).toByteArray())
40
+ val playResponse = playHttpClient .postAuth(AUTH_URL , gson.toJson(properties).toByteArray())
40
41
if (playResponse.isSuccessful) {
41
42
val authData = gson.fromJson(String (playResponse.responseBytes), AuthData ::class .java)
42
43
prefs.playAuthData.put(authData)
@@ -56,9 +57,13 @@ class PlayRepository(
56
57
Log .i(" PlayRepository" , " Checking token validity." )
57
58
58
59
// 1h has passed check if token still works
59
- val app = AppDetailsHelper (savedData)
60
- .using(PlayHttpClient )
61
- .getAppByPackageName(" com.google.android.gm" )
60
+ val app = runCatching {
61
+ AppDetailsHelper (savedData)
62
+ .using(playHttpClient)
63
+ .getAppByPackageName(" com.google.android.gm" )
64
+ }.getOrElse {
65
+ return refreshAuth()
66
+ }
62
67
63
68
if (app.packageName.isEmpty()) {
64
69
return refreshAuth()
@@ -73,7 +78,7 @@ class PlayRepository(
73
78
// Normal Search
74
79
val authData = auth()
75
80
val updates = SearchHelper (authData)
76
- .using(PlayHttpClient )
81
+ .using(playHttpClient )
77
82
.searchResults(text)
78
83
.appList
79
84
.take(10 )
@@ -83,7 +88,7 @@ class PlayRepository(
83
88
// Package Name Search
84
89
val authData = auth()
85
90
val update = AppDetailsHelper (authData)
86
- .using(PlayHttpClient )
91
+ .using(playHttpClient )
87
92
.getAppByPackageName(text)
88
93
.toAppUpdate(::getInstallFiles)
89
94
emit(Result .success(listOf (update)))
@@ -96,7 +101,7 @@ class PlayRepository(
96
101
suspend fun updates (apps : List <AppInstalled >) = flow {
97
102
val authData = auth()
98
103
val details = AppDetailsHelper (authData)
99
- .using(PlayHttpClient )
104
+ .using(playHttpClient )
100
105
.getAppByPackageName(apps.getPackageNames())
101
106
val updates = details
102
107
.filter { it.versionCode > apps.getVersionCode(it.packageName) }
@@ -114,7 +119,7 @@ class PlayRepository(
114
119
}
115
120
116
121
private fun getInstallFiles (app : App ) = PurchaseHelper (auth())
117
- .using(PlayHttpClient )
122
+ .using(playHttpClient )
118
123
.purchase(app.packageName, app.versionCode, app.offerType)
119
124
.filter { it.type == File .FileType .BASE || it.type == File .FileType .SPLIT }
120
125
0 commit comments