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(mobile): enhance download operations #12973

Merged
merged 27 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e3394bb
add packages
alextran1502 Sep 22, 2024
a6c4d18
Merge branch 'main' of github.com:immich-app/immich into feat/backgro…
alextran1502 Sep 22, 2024
5b334bd
create download task
alextran1502 Sep 22, 2024
45fd7dd
show progress
alextran1502 Sep 23, 2024
9dfde19
save video and image
alextran1502 Sep 23, 2024
17fc266
show progress info
alextran1502 Sep 23, 2024
1a797ea
live photo wip
alextran1502 Sep 23, 2024
72efa4f
Merge branch 'main' of github.com:immich-app/immich into feat/backgro…
alextran1502 Sep 24, 2024
5e4e622
download and link live photos
alextran1502 Sep 24, 2024
e10aa97
Update list of assets
alextran1502 Sep 24, 2024
4ca37df
wip
alextran1502 Sep 25, 2024
bdc49b9
Merge branch 'main' of github.com:immich-app/immich into feat/backgro…
alextran1502 Sep 25, 2024
94b3e86
correct progress
alextran1502 Sep 26, 2024
f270593
Merge branch 'main' of github.com:immich-app/immich into feat/backgro…
alextran1502 Sep 26, 2024
03d25fa
Merge branch 'main' of github.com:immich-app/immich into feat/backgro…
alextran1502 Sep 27, 2024
1f715f3
add state to download
alextran1502 Sep 27, 2024
c06daae
revert unncessary change
alextran1502 Sep 27, 2024
eccca17
Merge branch 'main' of github.com:immich-app/immich into feat/backgro…
alextran1502 Sep 28, 2024
442e7c4
repository pattern
alextran1502 Sep 28, 2024
8b9bd35
translation
alextran1502 Sep 28, 2024
312f9cf
remove unused code
alextran1502 Sep 28, 2024
788e19e
update method call from repository
alextran1502 Sep 28, 2024
e3e1240
remove unused variable
alextran1502 Sep 28, 2024
4f50b2e
handle multiple livephotos download
alextran1502 Sep 29, 2024
3fae086
remove logging statement
alextran1502 Sep 29, 2024
4b17ee8
lint
alextran1502 Sep 29, 2024
c67bbce
not removing all records
alextran1502 Sep 29, 2024
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
6 changes: 6 additions & 0 deletions mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PODS:
- background_downloader (0.0.1):
- Flutter
- connectivity_plus (0.0.1):
- Flutter
- ReachabilitySwift
Expand Down Expand Up @@ -99,6 +101,7 @@ PODS:
- Flutter

DEPENDENCIES:
- background_downloader (from `.symlinks/plugins/background_downloader/ios`)
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- file_picker (from `.symlinks/plugins/file_picker/ios`)
Expand Down Expand Up @@ -137,6 +140,8 @@ SPEC REPOS:
- Toast

EXTERNAL SOURCES:
background_downloader:
:path: ".symlinks/plugins/background_downloader/ios"
connectivity_plus:
:path: ".symlinks/plugins/connectivity_plus/ios"
device_info_plus:
Expand Down Expand Up @@ -189,6 +194,7 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/wakelock_plus/ios"

SPEC CHECKSUMS:
background_downloader: 9f788ffc5de45acf87d6380e91ca0841066c18cf
connectivity_plus: bf0076dd84a130856aa636df1c71ccaff908fa1d
device_info_plus: c6fb39579d0f423935b0c9ce7ee2f44b71b9fce6
DKImagePickerController: 946cec48c7873164274ecc4624d19e3da4c1ef3c
Expand Down
19 changes: 17 additions & 2 deletions mobile/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:io';

import 'package:background_downloader/background_downloader.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/foundation.dart';
Expand All @@ -9,6 +10,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/extensions/build_context_extensions.dart';
import 'package:immich_mobile/utils/download.dart';
import 'package:timezone/data/latest.dart';
import 'package:immich_mobile/constants/locales.dart';
import 'package:immich_mobile/services/background.service.dart';
Expand Down Expand Up @@ -87,6 +89,17 @@ Future<void> initApp() async {
};

initializeTimeZones();

FileDownloader().configureNotification(
running: const TaskNotification('Downloading media', 'file: {filename}'),
complete: const TaskNotification('Download finished', 'file: {filename}'),
alextran1502 marked this conversation as resolved.
Show resolved Hide resolved
progressBar: true,
);

FileDownloader().trackTasksInGroup(
downloadGroupLivePhoto,
markDownloadedComplete: false,
);
}

Future<Isar> loadDb() async {
Expand Down Expand Up @@ -121,6 +134,8 @@ class ImmichApp extends ConsumerStatefulWidget {

class ImmichAppState extends ConsumerState<ImmichApp>
with WidgetsBindingObserver {
int progress = 0;

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
Expand Down Expand Up @@ -188,8 +203,8 @@ class ImmichAppState extends ConsumerState<ImmichApp>

@override
Widget build(BuildContext context) {
var router = ref.watch(appRouterProvider);
var immichTheme = ref.watch(immichThemeProvider);
final router = ref.watch(appRouterProvider);
final immichTheme = ref.watch(immichThemeProvider);

return MaterialApp(
localizationsDelegates: context.localizationDelegates,
Expand Down
55 changes: 0 additions & 55 deletions mobile/lib/models/asset_viewer/asset_viewer_page_state.model.dart

This file was deleted.

109 changes: 109 additions & 0 deletions mobile/lib/models/asset_viewer/download_state.model..dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:convert';

import 'package:background_downloader/background_downloader.dart';
import 'package:collection/collection.dart';

class DownloadInfo {
final String fileName;
final double progress;
// enum
final TaskStatus status;

DownloadInfo({
required this.fileName,
required this.progress,
required this.status,
});

DownloadInfo copyWith({
String? fileName,
double? progress,
TaskStatus? status,
}) {
return DownloadInfo(
fileName: fileName ?? this.fileName,
progress: progress ?? this.progress,
status: status ?? this.status,
);
}

Map<String, dynamic> toMap() {
return <String, dynamic>{
'fileName': fileName,
'progress': progress,
'status': status.index,
};
}

factory DownloadInfo.fromMap(Map<String, dynamic> map) {
return DownloadInfo(
fileName: map['fileName'] as String,
progress: map['progress'] as double,
status: TaskStatus.values[map['status'] as int],
);
}

String toJson() => json.encode(toMap());

factory DownloadInfo.fromJson(String source) =>
DownloadInfo.fromMap(json.decode(source) as Map<String, dynamic>);

@override
String toString() =>
'DownloadInfo(fileName: $fileName, progress: $progress, status: $status)';

@override
bool operator ==(covariant DownloadInfo other) {
if (identical(this, other)) return true;

return other.fileName == fileName &&
other.progress == progress &&
other.status == status;
}

@override
int get hashCode => fileName.hashCode ^ progress.hashCode ^ status.hashCode;
}

class DownloadState {
// enum
final TaskStatus downloadStatus;
final Map<String, DownloadInfo> taskProgress;
final bool showProgress;
DownloadState({
required this.downloadStatus,
required this.taskProgress,
required this.showProgress,
});

DownloadState copyWith({
TaskStatus? downloadStatus,
Map<String, DownloadInfo>? taskProgress,
bool? showProgress,
}) {
return DownloadState(
downloadStatus: downloadStatus ?? this.downloadStatus,
taskProgress: taskProgress ?? this.taskProgress,
showProgress: showProgress ?? this.showProgress,
);
}

@override
String toString() =>
'DownloadState(downloadStatus: $downloadStatus, taskProgress: $taskProgress, showProgress: $showProgress)';

@override
bool operator ==(covariant DownloadState other) {
if (identical(this, other)) return true;
final mapEquals = const DeepCollectionEquality().equals;

return other.downloadStatus == downloadStatus &&
mapEquals(other.taskProgress, taskProgress) &&
other.showProgress == showProgress;
}

@override
int get hashCode =>
downloadStatus.hashCode ^ taskProgress.hashCode ^ showProgress.hashCode;
}
Loading
Loading