You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-07-16 07:24:40 +02:00
feat(mobile): share to mechanism (#15229)
* setup ios * chore: succesfully sent media to the app * share from Android * wip: navigate to share screen * wip: UI for displaying upload candidate * wip: logic * wip: upload logic * wip: up up up we got it up * wip * wip * wip * upload state * feat: i18n * fix: release build ios' * feat: clear file cache * pr feedback * using const for checking download status --------- Co-authored-by: Alex <alex@pop-os.localdomain>
This commit is contained in:
114
mobile/lib/models/upload/share_intent_attachment.model.dart
Normal file
114
mobile/lib/models/upload/share_intent_attachment.model.dart
Normal file
@ -0,0 +1,114 @@
|
||||
// ignore_for_file: public_member_api_docs, sort_constructors_first
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:immich_mobile/utils/bytes_units.dart';
|
||||
import 'package:path/path.dart';
|
||||
|
||||
enum ShareIntentAttachmentType {
|
||||
image,
|
||||
video,
|
||||
}
|
||||
|
||||
enum UploadStatus {
|
||||
enqueued,
|
||||
running,
|
||||
complete,
|
||||
notFound,
|
||||
failed,
|
||||
canceled,
|
||||
waitingtoRetry,
|
||||
paused,
|
||||
}
|
||||
|
||||
class ShareIntentAttachment {
|
||||
final String path;
|
||||
|
||||
// enum
|
||||
final ShareIntentAttachmentType type;
|
||||
|
||||
// enum
|
||||
final UploadStatus status;
|
||||
|
||||
final double uploadProgress;
|
||||
|
||||
final int fileLength;
|
||||
|
||||
ShareIntentAttachment({
|
||||
required this.path,
|
||||
required this.type,
|
||||
required this.status,
|
||||
this.uploadProgress = 0,
|
||||
this.fileLength = 0,
|
||||
});
|
||||
|
||||
int get id => hash(path);
|
||||
|
||||
File get file => File(path);
|
||||
|
||||
String get fileName => basename(file.path);
|
||||
|
||||
bool get isImage => type == ShareIntentAttachmentType.image;
|
||||
|
||||
bool get isVideo => type == ShareIntentAttachmentType.video;
|
||||
|
||||
String? _fileSize;
|
||||
|
||||
String get fileSize => _fileSize ??= formatHumanReadableBytes(fileLength, 2);
|
||||
|
||||
ShareIntentAttachment copyWith({
|
||||
String? path,
|
||||
ShareIntentAttachmentType? type,
|
||||
UploadStatus? status,
|
||||
double? uploadProgress,
|
||||
}) {
|
||||
return ShareIntentAttachment(
|
||||
path: path ?? this.path,
|
||||
type: type ?? this.type,
|
||||
status: status ?? this.status,
|
||||
uploadProgress: uploadProgress ?? this.uploadProgress,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return <String, dynamic>{
|
||||
'path': path,
|
||||
'type': type.index,
|
||||
'status': status.index,
|
||||
'uploadProgress': uploadProgress,
|
||||
};
|
||||
}
|
||||
|
||||
factory ShareIntentAttachment.fromMap(Map<String, dynamic> map) {
|
||||
return ShareIntentAttachment(
|
||||
path: map['path'] as String,
|
||||
type: ShareIntentAttachmentType.values[map['type'] as int],
|
||||
status: UploadStatus.values[map['status'] as int],
|
||||
uploadProgress: map['uploadProgress'] as double,
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory ShareIntentAttachment.fromJson(String source) =>
|
||||
ShareIntentAttachment.fromMap(
|
||||
json.decode(source) as Map<String, dynamic>,
|
||||
);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ShareIntentAttachment(path: $path, type: $type, status: $status, uploadProgress: $uploadProgress)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(covariant ShareIntentAttachment other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other.path == path && other.type == type;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return path.hashCode ^ type.hashCode;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user