-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add setting for number of columns
- Loading branch information
Showing
22 changed files
with
358 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.apkupdater.data.ui | ||
|
||
import android.net.Uri | ||
|
||
data class AppUpdate( | ||
val name: String, | ||
val packageName: String, | ||
val version: String, | ||
val versionCode: Long, | ||
val iconUri: Uri = Uri.EMPTY, | ||
val link: String = "" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.apkupdater.data.ui | ||
|
||
|
||
sealed class AppsUiState { | ||
object Loading: AppsUiState() | ||
object Error : AppsUiState() | ||
class Success(val apps: List<AppInstalled>, val excludeSystem: Boolean): AppsUiState() | ||
|
||
inline fun onLoading(block: (Loading) -> Unit): AppsUiState { | ||
if (this is Loading) block(this) | ||
return this | ||
} | ||
|
||
inline fun onError(block: (Error) -> Unit): AppsUiState { | ||
if (this is Error) block(this) | ||
return this | ||
} | ||
|
||
inline fun onSuccess(block: (Success) -> Unit): AppsUiState { | ||
if (this is Success) block(this) | ||
return this | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/apkupdater/data/ui/UpdatesUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.apkupdater.data.ui | ||
|
||
|
||
sealed class UpdatesUiState { | ||
object Loading: UpdatesUiState() | ||
object Error : UpdatesUiState() | ||
class Success(val updates: List<AppUpdate>): UpdatesUiState() | ||
|
||
inline fun onLoading(block: (Loading) -> Unit): UpdatesUiState { | ||
if (this is Loading) block(this) | ||
return this | ||
} | ||
|
||
inline fun onError(block: (Error) -> Unit): UpdatesUiState { | ||
if (this is Error) block(this) | ||
return this | ||
} | ||
|
||
inline fun onSuccess(block: (Success) -> Unit): UpdatesUiState { | ||
if (this is Success) block(this) | ||
return this | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 46 additions & 7 deletions
53
app/src/main/java/com/apkupdater/repository/ApkMirrorRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,70 @@ | ||
package com.apkupdater.repository | ||
|
||
import android.os.Build | ||
import android.util.Log | ||
import com.apkupdater.data.apkmirror.AppExistsRequest | ||
import com.apkupdater.data.apkmirror.AppExistsResponseApk | ||
import com.apkupdater.data.apkmirror.AppExistsResponseData | ||
import com.apkupdater.data.ui.AppInstalled | ||
import com.apkupdater.prefs.Prefs | ||
import com.apkupdater.service.ApkMirrorService | ||
import com.apkupdater.transform.toAppUpdate | ||
import com.apkupdater.util.combine | ||
import kotlinx.coroutines.flow.catch | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.flow.flow | ||
|
||
|
||
class ApkMirrorRepository( | ||
private val service: ApkMirrorService, | ||
private val prefs: Prefs | ||
) { | ||
private val arch = when { | ||
Build.SUPPORTED_ABIS.contains("armeabi-v7a") -> "arm" | ||
Build.SUPPORTED_ABIS.contains("arm64-v8a") -> "arm" | ||
Build.SUPPORTED_ABIS.contains("x86") -> "x86" | ||
Build.SUPPORTED_ABIS.contains("x86_64") -> "x86" | ||
else -> "arm" | ||
} | ||
|
||
suspend fun getUpdates(apps: List<String>) = flow { | ||
apps | ||
.chunked(50) | ||
.map { appExists(it) } | ||
.combine { all -> emit(parseUpdates(all.flatMap { it })) } | ||
suspend fun getUpdates(apps: List<AppInstalled>) = flow { | ||
apps.chunked(100) | ||
.map { appExists(getPackageNames(apps)) } | ||
.combine { all -> emit(parseUpdates(all.flatMap { it }, apps)) } | ||
.collect() | ||
} | ||
|
||
private fun appExists(apps: List<String>) = flow { | ||
emit(service.appExists(AppExistsRequest(apps)).data) | ||
}.catch { | ||
Log.e("ApkMirrorRepository", "Error getting updates.", it) | ||
} | ||
|
||
private fun parseUpdates(updates: List<AppExistsResponseData>) = updates. | ||
filter { it.exists == false } | ||
private fun parseUpdates(updates: List<AppExistsResponseData>, apps: List<AppInstalled>) | ||
= updates | ||
.filter { it.exists == true } | ||
.map { data -> | ||
data.apks | ||
.mapNotNull { filterArch(it) } | ||
.filter { it.versionCode > getVersionCode(apps, data.pname) } | ||
.map { it.toAppUpdate(getApp(apps, data.pname)!!) } | ||
}.flatten() | ||
|
||
private fun getVersionCode(apps: List<AppInstalled>, packageName: String) = apps | ||
.find { it.packageName == packageName }?.versionCode ?: 0 | ||
|
||
private fun getPackageNames(apps: List<AppInstalled>) = apps | ||
.filter { !it.ignored } | ||
.map { it.packageName } | ||
|
||
private fun getApp(apps: List<AppInstalled>, packageName: String) = apps | ||
.find { it.packageName == packageName } | ||
|
||
private fun filterArch(app: AppExistsResponseApk) = when { | ||
app.arches.isEmpty() -> app | ||
app.arches.contains("universal") || app.arches.contains("noarch") -> app | ||
app.arches.find { a -> a.contains(arch) } != null -> app | ||
else -> null | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.