UI improvement in APKPicker

This commit is contained in:
Imran Remtulla
2022-11-07 15:32:42 -05:00
parent ed955ac6a2
commit 139f44d31d
2 changed files with 42 additions and 19 deletions

View File

@@ -96,3 +96,19 @@ showError(dynamic e, BuildContext context) {
}); });
} }
} }
String list2FriendlyString(List<String> list) {
return list.length == 2
? '${list[0]} and ${list[1]}'
: list
.asMap()
.entries
.map((e) =>
e.value +
(e.key == list.length - 1
? ''
: e.key == list.length - 2
? ', and '
: ', '))
.join('');
}

View File

@@ -217,7 +217,7 @@ class AppsProvider with ChangeNotifier {
return APKPicker( return APKPicker(
app: app, app: app,
initVal: apkUrl, initVal: apkUrl,
arch: archs, archs: archs,
); );
}); });
} }
@@ -594,11 +594,11 @@ class AppsProvider with ChangeNotifier {
} }
class APKPicker extends StatefulWidget { class APKPicker extends StatefulWidget {
const APKPicker({super.key, required this.app, this.initVal, this.arch}); const APKPicker({super.key, required this.app, this.initVal, this.archs});
final App app; final App app;
final String? initVal; final String? initVal;
final List<String>? arch; final List<String>? archs;
@override @override
State<APKPicker> createState() => _APKPickerState(); State<APKPicker> createState() => _APKPickerState();
@@ -615,12 +615,9 @@ class _APKPickerState extends State<APKPicker> {
title: const Text('Pick an APK'), title: const Text('Pick an APK'),
content: Column(children: [ content: Column(children: [
Text('${widget.app.name} has more than one package:'), Text('${widget.app.name} has more than one package:'),
Text(
'Your device ${widget.arch!.length == 1 ? "support the:" : "supports:"} ${widget.arch!.join(", ")} CPU architecture${widget.arch!.length > 1 ? "s" : ""}',
textAlign: TextAlign.center,
),
const SizedBox(height: 16), const SizedBox(height: 16),
...widget.app.apkUrls.map((u) => RadioListTile<String>( ...widget.app.apkUrls.map(
(u) => RadioListTile<String>(
title: Text(Uri.parse(u) title: Text(Uri.parse(u)
.pathSegments .pathSegments
.where((element) => element.isNotEmpty) .where((element) => element.isNotEmpty)
@@ -631,7 +628,17 @@ class _APKPickerState extends State<APKPicker> {
setState(() { setState(() {
apkUrl = val; apkUrl = val;
}); });
})) }),
),
if (widget.archs != null)
const SizedBox(
height: 16,
),
if (widget.archs != null)
Text(
'Note:\nYour device supports the ${widget.archs!.length == 1 ? '\'${widget.archs![0]}\' CPU architecture.' : 'following CPU architectures: ${list2FriendlyString(widget.archs!.map((e) => '\'$e\'').toList())}.'}',
style: const TextStyle(fontStyle: FontStyle.italic, fontSize: 12),
),
]), ]),
actions: [ actions: [
TextButton( TextButton(