Skip to content

Commit

Permalink
Got numbers on downloads screen working. Got migration mostly functio…
Browse files Browse the repository at this point in the history
…nal.
  • Loading branch information
Komodo5197 committed Dec 20, 2023
1 parent 0d98815 commit 4d5ee16
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 136 deletions.
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
platform :ios, '11.0'
platform :ios, '13.0'

# Fixing DKImagePickerController Bug
use_modular_headers!
Expand Down
1 change: 1 addition & 0 deletions lib/components/AlbumScreen/downloaded_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DownloadedIndicator extends ConsumerWidget {
return const SizedBox(width: 0, height: 0);
case DownloadItemState.notDownloaded:
return const SizedBox(width: 0, height: 0);
case DownloadItemState.enqueued:
case DownloadItemState.downloading:
return Icon(
Icons.download_outlined,
Expand Down
45 changes: 22 additions & 23 deletions lib/components/DownloadsScreen/downloads_overview.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:background_downloader/background_downloader.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:get_it/get_it.dart';
import 'package:background_downloader/background_downloader.dart';
import 'package:logging/logging.dart';

import '../../models/finamp_models.dart';
import '../../services/isar_downloads.dart';
Expand All @@ -19,26 +18,18 @@ class DownloadsOverview extends StatefulWidget {
}

class _DownloadsOverviewState extends State<DownloadsOverview> {
late Future<List<int?>> _downloadsOverviewFuture;
final isarDownloads = GetIt.instance<IsarDownloads>();

@override
void initState() {
super.initState();
// TODO figure out what to track, how to do it.
_downloadsOverviewFuture = Future.wait([
Future.value(-123),
Future.value(
isarDownloads.getDownloadCount(state: DownloadItemState.failed)),
Future.value(-123),
FileDownloader().allTasks().then((value) => value?.length)
]);
}

@override
Widget build(BuildContext context) {
return FutureBuilder<List<int?>>(
future: _downloadsOverviewFuture,
return StreamBuilder<Map<DownloadItemState, int>>(
stream: isarDownloads.downloadStatusesStream,
initialData: isarDownloads.downloadStatuses,
builder: (context, snapshot) {
if (snapshot.hasData) {
// We have to awkwardly get two strings like this because Flutter's
Expand All @@ -50,7 +41,13 @@ class _DownloadsOverviewState extends State<DownloadsOverview> {
final downloadedImagesString = AppLocalizations.of(context)!
.downloadedImagesCount(
isarDownloads.getDownloadCount(type: DownloadItemType.image));
final downloadCount =
(snapshot.data?[DownloadItemState.complete] ?? 0) +
(snapshot.data?[DownloadItemState.failed] ?? 0) +
(snapshot.data?[DownloadItemState.enqueued] ?? 0) +
(snapshot.data?[DownloadItemState.downloading] ?? 0);

Logger("overview").severe("rebuilt");
return Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
Expand All @@ -64,8 +61,7 @@ class _DownloadsOverviewState extends State<DownloadsOverview> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AutoSizeText(
AppLocalizations.of(context)!
.downloadCount(-123),
AppLocalizations.of(context)!.downloadCount(downloadCount),
style: const TextStyle(fontSize: 28),
maxLines: 1,
),
Expand All @@ -84,23 +80,26 @@ class _DownloadsOverviewState extends State<DownloadsOverview> {
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
AppLocalizations.of(context)!
.dlComplete(snapshot.data?[0] ?? 0),
AppLocalizations.of(context)!.dlComplete(
snapshot.data?[DownloadItemState.complete] ??
-1),
style: const TextStyle(color: Colors.green),
),
Text(
AppLocalizations.of(context)!
.dlFailed(snapshot.data?[1] ?? 0),
AppLocalizations.of(context)!.dlFailed(
snapshot.data?[DownloadItemState.failed] ?? -1),
style: const TextStyle(color: Colors.red),
),
Text(
AppLocalizations.of(context)!
.dlEnqueued(snapshot.data?[2] ?? 0),
AppLocalizations.of(context)!.dlEnqueued(
snapshot.data?[DownloadItemState.enqueued] ??
-1),
style: const TextStyle(color: Colors.grey),
),
Text(
AppLocalizations.of(context)!
.dlRunning(snapshot.data?[3] ?? 0),
AppLocalizations.of(context)!.dlRunning(
snapshot.data?[DownloadItemState.downloading] ??
-1),
style: const TextStyle(color: Colors.grey),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ class _SyncDownloadedPlaylistsButtonState
Widget build(BuildContext context) {
return IconButton(
onPressed: () => GetIt.instance<IsarDownloads>().resyncAll(), icon: const Icon(Icons.sync));
// TODO snackbar and disabling from missing_images_button code
}
}
3 changes: 2 additions & 1 deletion lib/models/finamp_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,8 @@ enum DownloadItemState {
notDownloaded,
downloading,
failed,
complete, // TODO add enqueued?
complete,
enqueued,
}

// Enumerated by Isar, do not modify existing entries
Expand Down
2 changes: 2 additions & 0 deletions lib/models/finamp_models.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4d5ee16

Please sign in to comment.