More progress on UI - basics almost done

This commit is contained in:
Imran Remtulla
2022-08-18 15:25:30 -04:00
parent 605877f6bf
commit 0e36e53b46
5 changed files with 176 additions and 126 deletions

View File

@@ -14,6 +14,7 @@ class AddAppPage extends StatefulWidget {
class _AddAppPageState extends State<AddAppPage> {
final _formKey = GlobalKey<FormState>();
final urlInputController = TextEditingController();
bool gettingAppInfo = false;
@override
Widget build(BuildContext context) {
@@ -25,45 +26,67 @@ class _AddAppPageState extends State<AddAppPage> {
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextFormField(
controller: urlInputController,
validator: (value) {
if (value == null ||
value.isEmpty ||
Uri.tryParse(value) == null) {
return 'Please enter a supported source URL';
}
return null;
},
),
const Spacer(),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: TextFormField(
decoration: const InputDecoration(
border: OutlineInputBorder(),
hintText: 'https://github.com/Author/Project',
helperText: 'Enter the App source URL'),
controller: urlInputController,
validator: (value) {
if (value == null ||
value.isEmpty ||
Uri.tryParse(value) == null) {
return 'Please enter a supported source URL';
}
return null;
},
)),
Padding(
padding:
const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
child: ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
SourceService()
.getApp(urlInputController.value.text)
.then((app) {
var appsProvider = context.read<AppsProvider>();
appsProvider.saveApp(app).then((_) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AppPage(appId: app.id)));
});
}).catchError((e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.toString())),
);
});
}
},
onPressed: gettingAppInfo
? null
: () {
if (_formKey.currentState!.validate()) {
setState(() {
gettingAppInfo = true;
});
SourceService()
.getApp(urlInputController.value.text)
.then((app) {
var appsProvider = context.read<AppsProvider>();
if (appsProvider.apps.containsKey(app.id)) {
throw 'App already added';
}
appsProvider.saveApp(app).then((_) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
AppPage(appId: app.id)));
});
}).catchError((e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.toString())),
);
}).whenComplete(() {
setState(() {
gettingAppInfo = false;
});
});
}
},
child: const Text('Add'),
),
),
const Spacer(),
if (gettingAppInfo) const LinearProgressIndicator(),
],
),
)),

View File

@@ -18,15 +18,68 @@ class _AppPageState extends State<AppPage> {
Widget build(BuildContext context) {
var appsProvider = context.watch<AppsProvider>();
App? app = appsProvider.apps[widget.appId];
if (app == null) {
Navigator.pop(context);
if (app?.installedVersion != null) {
appsProvider.getUpdate(app!.id);
}
return Scaffold(
appBar: AppBar(
title: Text('App - ${app?.name} - ${app?.author}'),
),
body: WebView(
initialUrl: app?.url,
));
appBar: AppBar(
title: Text('${app?.author}/${app?.name}'),
),
body: WebView(
initialUrl: app?.url,
),
bottomSheet: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
child:
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
Expanded(
child: OutlinedButton(
onPressed: (app?.installedVersion == null ||
appsProvider.checkAppObjectForUpdate(app!)) &&
app?.currentDownloadId == null
? () {
appsProvider.backgroundDownloadAndInstallApp(app!);
}
: null,
child: Text(
app?.installedVersion == null ? 'Install' : 'Update'))),
const SizedBox(width: 16.0),
OutlinedButton(
onPressed: app?.currentDownloadId != null
? null
: () {
showDialog(
context: context,
builder: (BuildContext ctx) {
return AlertDialog(
title: const Text('Remove App?'),
content: Text(
'This will remove \'${app?.name}\' from Obtainium.${app?.installedVersion != null ? '\n\nNote that while Obtainium will no longer track its updates, the App will remain installed.' : ''}'),
actions: [
TextButton(
onPressed: () {
appsProvider.removeApp(app!.id).then((_) {
int count = 0;
Navigator.of(context)
.popUntil((_) => count++ >= 2);
});
},
child: const Text('Remove')),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Cancel'))
],
);
});
},
style: TextButton.styleFrom(
foregroundColor: Theme.of(context).errorColor),
child: const Text('Remove'),
)
// TODO: Add progress bar when app?.currentDownloadId != null
])),
);
}
}

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:obtainium/pages/add_app.dart';
import 'package:obtainium/pages/app.dart';
import 'package:obtainium/services/apps_provider.dart';
import 'package:provider/provider.dart';
@@ -13,24 +14,39 @@ class AppsPage extends StatefulWidget {
class _AppsPageState extends State<AppsPage> {
@override
Widget build(BuildContext context) {
var appsProvider = context.watch<AppsProvider>();
return Scaffold(
appBar: AppBar(
title: const Text('Obtainium - Apps'),
title: const Text('Obtainium'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: () {
var appsProvider = context.watch<AppsProvider>();
if (appsProvider.loadingApps) {
return [const Text('Loading Apps...')];
} else if (appsProvider.apps.isEmpty) {
return [const Text('No Apps Yet.')];
} else {
return appsProvider.apps.values.map((e) => Text(e.id)).toList();
}
}(),
),
child: appsProvider.loadingApps
? const CircularProgressIndicator()
: appsProvider.apps.isEmpty
? Text(
'No Apps',
style: Theme.of(context).textTheme.headline4,
)
: ListView(
children: appsProvider.apps.values
.map(
(e) => ListTile(
title: Text(e.name),
subtitle: Text(e.author),
trailing:
Text(e.installedVersion ?? 'Not Installed'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AppPage(appId: e.id)),
);
},
),
)
.toList(),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {