fix installation screen not receiving input after installation completes

This commit is contained in:
X1nto 2021-11-22 16:17:46 +04:00
parent 5369121f2c
commit c7e54ba6fa
3 changed files with 24 additions and 15 deletions

View File

@ -23,11 +23,11 @@ import com.vanced.manager.ui.theme.ManagerTheme
import com.vanced.manager.ui.theme.isDark
import com.vanced.manager.ui.util.Screen
import com.vanced.manager.ui.viewmodel.InstallViewModel
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel
class MainActivity : ComponentActivity() {
private val installViewModel: InstallViewModel by inject()
private val installViewModel: InstallViewModel by viewModel()
private val backPressHandler = BackPressHandler()

View File

@ -45,6 +45,9 @@ fun InstallScreen(
var startedProcess by rememberSaveable { mutableStateOf(false) }
val logs = viewModel.logs
val status = viewModel.status
// I don't know why, I don't know how,
// but it works as intended
LaunchedEffect(startedProcess) {
@ -60,7 +63,7 @@ fun InstallScreen(
ManagerTopAppBar(
title = managerString(R.string.toolbar_install),
)
when (val status = viewModel.status) {
when (status) {
is InstallViewModel.Status.Progress -> {
ManagerProgressIndicator(status.progress)
}
@ -72,9 +75,9 @@ fun InstallScreen(
}
},
floatingActionButton = {
if (viewModel.status is InstallViewModel.Status.Installed) {
if (status is InstallViewModel.Status.Installed) {
ExtendedFloatingActionButton(
text = { /*TODO*/ },
text = { ManagerText("Finish") },
icon = {
Icon(Icons.Rounded.Done, null)
},
@ -88,7 +91,7 @@ fun InstallScreen(
.fillMaxSize()
.padding(paddingValues),
) {
items(viewModel.logs) { log ->
items(logs) { log ->
when (log) {
is InstallViewModel.Log.Success -> {
ManagerText(

View File

@ -63,12 +63,14 @@ class InstallViewModel(
}
fun postInstallStatus(pmStatus: Int, extra: String) {
if (pmStatus == PackageInstaller.STATUS_SUCCESS) {
status = Status.Installed
logs.add(Log.Success("Successfully installed"))
} else {
status = Status.Failure
logs.add(Log.Error("Failed to install app", extra))
viewModelScope.launch(Dispatchers.IO) {
if (pmStatus == PackageInstaller.STATUS_SUCCESS) {
status = Status.Installed
log(Log.Success("Successfully installed"))
} else {
status = Status.Failure
log(Log.Error("Failed to install app", extra))
}
}
}
@ -80,14 +82,14 @@ class InstallViewModel(
downloader.download(appVersions) { downloadStatus ->
when (downloadStatus) {
is DownloadStatus.File -> logs.add(Log.Info("Downloading ${downloadStatus.fileName}"))
is DownloadStatus.Error -> logs.add(Log.Error(
is DownloadStatus.File -> log(Log.Info("Downloading ${downloadStatus.fileName}"))
is DownloadStatus.Error -> log(Log.Error(
displayText = downloadStatus.displayError,
stacktrace = downloadStatus.stacktrace
))
is DownloadStatus.Progress -> status = Status.Progress(downloadStatus.progress / 100)
is DownloadStatus.StartInstall -> {
logs.add(Log.Success("Successfully downloaded $appName"))
log(Log.Success("Successfully downloaded $appName"))
installApp(appName, appVersions)
}
}
@ -123,6 +125,10 @@ class InstallViewModel(
else -> throw IllegalArgumentException("$appName is not a valid app")
}
private fun log(data: Log) {
logs.add(data)
}
private fun clear() {
logs.clear()
status = Status.Idle