Merge pull request #733 from grote/install-fixes

Two small fixes for app restore
This commit is contained in:
Torsten Grote 2024-09-05 09:27:00 -03:00 committed by GitHub
commit 0a7ce66bcf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 3 deletions

View file

@ -144,9 +144,6 @@ internal class AppSelectionAdapter(
fun bind(item: SelectableAppItem) { fun bind(item: SelectableAppItem) {
v.background = clickableBackground v.background = clickableBackground
v.setOnClickListener {
checkBox.toggle()
}
checkBox.setOnCheckedChangeListener(null) checkBox.setOnCheckedChangeListener(null)
checkBox.isChecked = item.selected checkBox.isChecked = item.selected
@ -155,6 +152,11 @@ internal class AppSelectionAdapter(
} }
checkBox.visibility = if (item.hasIcon == null) INVISIBLE else VISIBLE checkBox.visibility = if (item.hasIcon == null) INVISIBLE else VISIBLE
progressBar.visibility = if (item.hasIcon == null) VISIBLE else INVISIBLE progressBar.visibility = if (item.hasIcon == null) VISIBLE else INVISIBLE
if (item.hasIcon == null) {
v.setOnClickListener(null)
} else v.setOnClickListener {
checkBox.toggle()
}
val isSpecial = item.metadata.isInternalSystem val isSpecial = item.metadata.isInternalSystem
appIcon.scaleType = FIT_CENTER appIcon.scaleType = FIT_CENTER

View file

@ -153,6 +153,13 @@ internal class ApkRestore(
packageName: String, packageName: String,
metadata: PackageMetadata, metadata: PackageMetadata,
) { ) {
// show that app is in progress, before we start downloading stuff
mInstallResult.update {
it.update(packageName) { result ->
result.copy(state = IN_PROGRESS)
}
}
// cache the APK and get its hash // cache the APK and get its hash
val (cachedApk, sha256) = cacheApk(backup.version, backup.token, backup.salt, packageName) val (cachedApk, sha256) = cacheApk(backup.version, backup.token, backup.salt, packageName)

View file

@ -194,6 +194,13 @@ internal class ApkBackupRestoreTest : TransportTest() {
assertEquals(IN_PROGRESS, it.installResults[packageName]?.state) assertEquals(IN_PROGRESS, it.installResults[packageName]?.state)
assertFalse(it.isFinished) assertFalse(it.isFinished)
} }
awaitItem().also {
assertFalse(it.hasFailed)
assertEquals(1, it.total)
assertEquals(1, it.list.size)
assertEquals(IN_PROGRESS, it.installResults[packageName]?.state)
assertFalse(it.isFinished)
}
awaitItem().also { awaitItem().also {
assertFalse(it.hasFailed) assertFalse(it.hasFailed)
assertEquals(1, it.total) assertEquals(1, it.total)

View file

@ -46,6 +46,7 @@ import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir import org.junit.jupiter.api.io.TempDir
@ -758,6 +759,14 @@ internal class ApkRestoreTest : TransportTest() {
} }
private suspend fun TurbineTestContext<InstallResult>.awaitInProgressItem(): InstallResult { private suspend fun TurbineTestContext<InstallResult>.awaitInProgressItem(): InstallResult {
awaitItem().also { item ->
val result = item[packageName]
assertEquals(IN_PROGRESS, result.state)
assertFalse(item.hasFailed)
assertEquals(1, item.total)
assertEquals(1, item.list.size)
assertNull(result.icon)
}
val item = awaitItem() val item = awaitItem()
// name and icon are available now // name and icon are available now
val result = item[packageName] val result = item[packageName]