Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check for updates, and do the actual update #5

Merged
merged 1 commit into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/models/software.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Software {
this.info,
this.expanded = false,
this.installed = false,
this.updateAvailable = false,
});

String packageName;
Expand All @@ -20,6 +21,7 @@ class Software {
String? info;
bool expanded;
bool installed;
bool updateAvailable;

Software clone() => Software(
packageName: packageName,
Expand All @@ -31,6 +33,7 @@ class Software {
info: info,
expanded: expanded,
installed: installed,
updateAvailable: updateAvailable,
);

Software copyWith({
Expand All @@ -43,6 +46,7 @@ class Software {
String? info,
bool? expanded,
bool? installed,
bool? updateAvailable,
}) =>
Software(
packageName: packageName ?? this.packageName,
Expand All @@ -54,6 +58,7 @@ class Software {
info: info ?? this.info,
expanded: expanded ?? this.expanded,
installed: installed ?? this.installed,
updateAvailable: updateAvailable ?? this.updateAvailable,
);

@override
Expand All @@ -62,6 +67,7 @@ class Software {
'packageName: $packageName, prettyName: $prettyName, '
'description: $description, icon: $icon, '
'installedVersion: $installedVersion, architecture: $architecture, '
'info: $info, expanded: $expanded, installed: $installed)';
'info: $info, expanded: $expanded, installed: $installed, '
'updateAvailable: $updateAvailable)';
}
}
284 changes: 190 additions & 94 deletions lib/pages/applications_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:deborah/models/software.dart';
import 'package:deborah/providers.dart';
import 'package:deborah/widgets/search_bar.dart';
import 'package:deborah/widgets/software_card.dart';
Expand All @@ -14,116 +15,211 @@ class ApplicationsPage extends ConsumerWidget {
return Expanded(
child: Column(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 16, 8, 8),
child: AbsorbPointer(
absorbing: !ref.watch(menuEnabledProvider),
child: Row(
children: [
const Expanded(
child: SearchBar(),
),
const SizedBox(
width: 8,
),
OutlinedButton(
onPressed: () {},
child: Padding(
padding: const EdgeInsets.all(14),
child: Text(
'Check for updates',
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
),
),
),
),
],
),
),
),
Expanded(
child: AbsorbPointer(
absorbing: !ref.watch(menuEnabledProvider),
child: ListView.separated(
itemCount: softwares.length,
itemBuilder: (context, index) {
final app = softwares[index];

return SoftwareCard(app);
},
separatorBuilder: (context, index) {
return const Divider();
},
),
),
const _SearchBar(),
_AppsList(softwares: softwares),
const Divider(
thickness: 2,
),
/* Bottom bar */
_BottomBar(softwares: softwares),
const Divider(
thickness: 2,
),
Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
child: AbsorbPointer(
absorbing: !ref.watch(menuEnabledProvider),
child: Row(
children: [
Expanded(
child: Text(
'Showing ${softwares.length} '
"software${softwares.length <= 1 ? '' : 's'}",
),
const _StatusLine(),
],
),
);
}
}

class _StatusLine extends ConsumerWidget {
const _StatusLine();

@override
Widget build(BuildContext context, WidgetRef ref) {
final absorbing = !ref.watch(menuEnabledProvider);

return Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 16),
child: Row(
children: [
Expanded(
child: Text(
ref.watch(statusLineProvider),
),
),
if (absorbing)
const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(),
),
],
),
);
}
}

class _BottomBar extends ConsumerWidget {
const _BottomBar({
required this.softwares,
});

final List<Software> softwares;

@override
Widget build(BuildContext context, WidgetRef ref) {
final absorbing = !ref.watch(menuEnabledProvider);

return Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
child: AbsorbPointer(
absorbing: absorbing,
child: Stack(
children: [
Row(
children: [
Expanded(
child: Text(
'Showing ${softwares.length} '
"software${softwares.length <= 1 ? '' : 's'}",
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Only show installed apps : '),
Switch(
value: ref.watch(onlyShowInstalledAppsProvider),
onChanged: (value) {
ref
.read(onlyShowInstalledAppsProvider.notifier)
.state = value;
},
),
],
),
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Only show installed apps : '),
Switch(
value: ref.watch(onlyShowInstalledAppsProvider),
onChanged: (value) {
ref
.read(onlyShowInstalledAppsProvider.notifier)
.state = value;
},
),
],
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
const Text('Only show upgradable apps : '),
Switch(
value: ref.watch(onlyShowUpgradableAppsProvider),
onChanged: (value) {
ref
.read(onlyShowUpgradableAppsProvider.notifier)
.state = value;
},
),
],
),
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
const Text('Only show upgradable apps : '),
Switch(
value: ref.watch(onlyShowUpgradableAppsProvider),
onChanged: (value) {
ref
.read(onlyShowUpgradableAppsProvider.notifier)
.state = value;
},
),
],
),
],
),
],
),
if (absorbing)
Positioned.fill(
child: ColoredBox(
color:
Theme.of(context).colorScheme.background.withOpacity(0.6),
),
),
],
),
),
);
}
}

class _AppsList extends ConsumerWidget {
const _AppsList({
required this.softwares,
});

final List<Software> softwares;

@override
Widget build(BuildContext context, WidgetRef ref) {
final absorbing = !ref.watch(menuEnabledProvider);

return Expanded(
child: Stack(
children: [
AbsorbPointer(
absorbing: absorbing,
child: ListView.separated(
itemCount: softwares.length,
itemBuilder: (context, index) {
final app = softwares[index];

return SoftwareCard(app);
},
separatorBuilder: (context, index) {
return const Divider();
},
),
),
const Divider(
thickness: 2,
),
Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 16),
if (absorbing)
Positioned.fill(
child: ColoredBox(
color:
Theme.of(context).colorScheme.background.withOpacity(0.6),
),
),
],
),
);
}
}

class _SearchBar extends ConsumerWidget {
const _SearchBar();

@override
Widget build(BuildContext context, WidgetRef ref) {
final absorbing = !ref.watch(menuEnabledProvider);

return Stack(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 16, 8, 8),
child: AbsorbPointer(
absorbing: absorbing,
child: Row(
children: [
Text(
ref.watch(statusLineProvider),
const Expanded(
child: SearchBar(),
),
const SizedBox(
width: 8,
),
OutlinedButton(
onPressed: () {
ref.read(softwaresProvider.notifier).checkUpdates();
},
child: Padding(
padding: const EdgeInsets.all(14),
child: Text(
'Check for updates',
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
),
),
),
),
],
),
),
],
),
),
if (absorbing)
Positioned.fill(
child: ColoredBox(
color: Theme.of(context).colorScheme.background.withOpacity(0.6),
),
),
],
);
}
}
2 changes: 1 addition & 1 deletion lib/providers/filtered_softwares_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final filteredSoftwaresProvider = Provider<List<Software>>((ref) {
}

if (onlyShowUpgradableApps) {
apps = apps.where((app) => false).toList();
apps = apps.where((app) => app.updateAvailable).toList();
}

if (query.isEmpty) return apps;
Expand Down
Loading