mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-28 22:13:01 +00:00
fix installation screen not receiving input after installation completes
This commit is contained in:
parent
5369121f2c
commit
c7e54ba6fa
3 changed files with 24 additions and 15 deletions
|
@ -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()
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -63,12 +63,14 @@ class InstallViewModel(
|
|||
}
|
||||
|
||||
fun postInstallStatus(pmStatus: Int, extra: String) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (pmStatus == PackageInstaller.STATUS_SUCCESS) {
|
||||
status = Status.Installed
|
||||
logs.add(Log.Success("Successfully installed"))
|
||||
log(Log.Success("Successfully installed"))
|
||||
} else {
|
||||
status = Status.Failure
|
||||
logs.add(Log.Error("Failed to install app", extra))
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue