@@ -3,11 +3,16 @@ package com.apkupdater.repository
3
3
import android.content.Context
4
4
import android.net.Uri
5
5
import android.util.Log
6
+ import com.apkupdater.data.ui.AppInstalled
6
7
import com.apkupdater.data.ui.AppUpdate
7
8
import com.apkupdater.data.ui.PlaySource
9
+ import com.apkupdater.data.ui.getPackageNames
10
+ import com.apkupdater.data.ui.getVersion
11
+ import com.apkupdater.data.ui.getVersionCode
8
12
import com.apkupdater.prefs.Prefs
9
13
import com.apkupdater.util.play.NativeDeviceInfoProvider
10
14
import com.apkupdater.util.play.PlayHttpClient
15
+ import com.aurora.gplayapi.data.models.App
11
16
import com.aurora.gplayapi.data.models.AuthData
12
17
import com.aurora.gplayapi.helpers.AppDetailsHelper
13
18
import com.aurora.gplayapi.helpers.PurchaseHelper
@@ -45,26 +50,46 @@ class PlayRepository(
45
50
return @flow
46
51
}
47
52
val authData = auth()
48
- val details = AppDetailsHelper (authData).using(PlayHttpClient )
49
- val app = details.getAppByPackageName(text)
50
- val files = PurchaseHelper (authData).purchase(app.packageName, app.versionCode, app.offerType)
51
- val link = files.joinToString(separator = " ," ) { it.url }
52
- val update = AppUpdate (
53
- app.displayName,
54
- app.packageName,
55
- app.versionName,
56
- " " ,
57
- app.versionCode.toLong(),
58
- 0L ,
59
- PlaySource ,
60
- Uri .parse(app.iconArtwork.url),
61
- link,
62
- whatsNew = app.changes
63
- )
53
+ val app = AppDetailsHelper (authData)
54
+ .using(PlayHttpClient )
55
+ .getAppByPackageName(text)
56
+ val update = app.toAppUpdate(PurchaseHelper (authData))
64
57
emit(Result .success(listOf (update)))
65
58
}.catch {
66
59
emit(Result .failure(it))
67
60
Log .e(" PlayRepository" , " Error searching." , it)
68
61
}
69
62
63
+ suspend fun updates (apps : List <AppInstalled >) = flow {
64
+ val authData = auth()
65
+ val details = AppDetailsHelper (authData)
66
+ .using(PlayHttpClient )
67
+ .getAppByPackageName(apps.getPackageNames())
68
+ val purchaseHelper = PurchaseHelper (authData)
69
+ val updates = details
70
+ .filter { it.versionCode > apps.getVersionCode(it.packageName) }
71
+ .map { it.toAppUpdate(purchaseHelper, apps.getVersion(it.packageName), apps.getVersionCode(it.packageName)) }
72
+ emit(updates)
73
+ }.catch {
74
+ emit(emptyList())
75
+ Log .e(" AptoideRepository" , " Error looking for updates." , it)
76
+ }
77
+
70
78
}
79
+
80
+ fun App.toAppUpdate (
81
+ purchaseHelper : PurchaseHelper ,
82
+ oldVersion : String = "",
83
+ oldVersionCode : Long = 0L
84
+ ) = AppUpdate (
85
+ displayName,
86
+ packageName,
87
+ versionName,
88
+ oldVersion,
89
+ versionCode.toLong(),
90
+ oldVersionCode,
91
+ PlaySource ,
92
+ Uri .parse(iconArtwork.url),
93
+ purchaseHelper.purchase(packageName, versionCode, offerType).joinToString(" ," ) { it.url },
94
+ whatsNew = changes
95
+ )
0 commit comments