@@ -8,6 +8,7 @@ import android.content.pm.PackageInstaller
8
8
import android.util.Log
9
9
import androidx.activity.compose.rememberLauncherForActivityResult
10
10
import androidx.activity.result.contract.ActivityResultContracts
11
+ import androidx.appcompat.widget.AppCompatTextView
11
12
import androidx.compose.foundation.layout.Arrangement
12
13
import androidx.compose.foundation.layout.fillMaxWidth
13
14
import androidx.compose.foundation.lazy.LazyColumn
@@ -29,14 +30,18 @@ import androidx.compose.ui.Modifier
29
30
import androidx.compose.ui.platform.LocalContext
30
31
import androidx.compose.ui.res.stringResource
31
32
import androidx.compose.ui.unit.dp
33
+ import androidx.compose.ui.viewinterop.AndroidView
32
34
import androidx.core.content.ContextCompat
33
35
import androidx.core.content.IntentCompat
36
+ import androidx.core.text.HtmlCompat
34
37
import androidx.documentfile.provider.DocumentFile
35
38
import dev.zwander.installwithoptions.BuildConfig
36
39
import dev.zwander.installwithoptions.IOptionsApplier
37
40
import dev.zwander.installwithoptions.R
38
41
import dev.zwander.installwithoptions.data.DataModel
39
42
import dev.zwander.installwithoptions.data.InstallOption
43
+ import dev.zwander.installwithoptions.data.InstallResult
44
+ import dev.zwander.installwithoptions.data.InstallStatus
40
45
import dev.zwander.installwithoptions.data.MutableOption
41
46
import dev.zwander.installwithoptions.data.Settings
42
47
import dev.zwander.installwithoptions.data.getMutableOptions
@@ -61,7 +66,7 @@ fun rememberPackageInstaller(files: List<DocumentFile>): Installer {
61
66
}
62
67
63
68
var statuses by remember {
64
- mutableStateOf<List <Pair < String , String > >>(listOf ())
69
+ mutableStateOf<List <InstallResult >>(listOf ())
65
70
}
66
71
var isInstalling by remember {
67
72
mutableStateOf(false )
@@ -109,11 +114,19 @@ fun rememberPackageInstaller(files: List<DocumentFile>): Installer {
109
114
110
115
PackageInstaller .STATUS_SUCCESS -> {
111
116
statuses =
112
- statuses + (packageName to context.resources.getString(R .string.success))
117
+ statuses + InstallResult (
118
+ status = InstallStatus .SUCCESS ,
119
+ packageName = packageName,
120
+ message = context.resources.getString(R .string.success),
121
+ )
113
122
}
114
123
115
124
else -> {
116
- statuses = statuses + (packageName to message)
125
+ statuses = statuses + InstallResult (
126
+ status = InstallStatus .FAILURE ,
127
+ packageName = packageName,
128
+ message = message,
129
+ )
117
130
}
118
131
}
119
132
}
@@ -142,8 +155,11 @@ fun rememberPackageInstaller(files: List<DocumentFile>): Installer {
142
155
)
143
156
} catch (e: Exception ) {
144
157
statuses = files.map {
145
- (it.name ? : it.uri.toString()) to (e.localizedMessage ? : e.message
146
- ? : e.toString())
158
+ InstallResult (
159
+ status = InstallStatus .FAILURE ,
160
+ packageName = it.name ? : it.uri.toString(),
161
+ message = e.localizedMessage ? : e.message ? : e.toString(),
162
+ )
147
163
}
148
164
}
149
165
}
@@ -209,27 +225,40 @@ fun rememberPackageInstaller(files: List<DocumentFile>): Installer {
209
225
}
210
226
},
211
227
title = {
212
- Text (text = stringResource(id = R .string.installation_complete))
228
+ Text (
229
+ text = stringResource(
230
+ id = if (s.any { it.status == InstallStatus .FAILURE }) {
231
+ R .string.installation_errors
232
+ } else {
233
+ R .string.installation_complete
234
+ },
235
+ ),
236
+ )
213
237
},
214
238
text = {
215
239
SelectionContainer {
216
240
LazyColumn (
217
241
modifier = Modifier .fillMaxWidth(),
218
- verticalArrangement = Arrangement .spacedBy(4 .dp),
242
+ verticalArrangement = Arrangement .spacedBy(8 .dp),
219
243
) {
220
- items(items = s) {
221
- Text (
222
- text = stringResource(
223
- id = R .string.status_item,
224
- try {
225
- context.packageManager.getApplicationInfo(it.first, 0 )
226
- .loadLabel(context.packageManager).toString()
227
- } catch (e: Throwable ) {
228
- it.first
229
- },
230
- it.second,
244
+ items(items = s) { res ->
245
+ AndroidView (
246
+ factory = { AppCompatTextView (it) },
247
+ ) { tv ->
248
+ tv.text = HtmlCompat .fromHtml(
249
+ context.resources.getString(
250
+ R .string.status_item,
251
+ try {
252
+ context.packageManager.getApplicationInfo(res.packageName, 0 )
253
+ .loadLabel(context.packageManager).toString()
254
+ } catch (e: Throwable ) {
255
+ res.packageName
256
+ },
257
+ res.message,
258
+ ),
259
+ HtmlCompat .FROM_HTML_MODE_COMPACT ,
231
260
)
232
- )
261
+ }
233
262
}
234
263
}
235
264
}
0 commit comments