feat: home grid
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:immich_mobile/domain/models/asset/asset.model.dart';
|
||||
import 'package:immich_mobile/domain/models/asset.model.dart';
|
||||
|
||||
@TableIndex(name: 'asset_localid', columns: {#localId})
|
||||
@TableIndex(name: 'asset_remoteid', columns: {#remoteId})
|
||||
class Asset extends Table {
|
||||
const Asset();
|
||||
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
|
||||
TextColumn get name => text()();
|
||||
TextColumn get checksum => text().unique()();
|
||||
IntColumn get height => integer().nullable()();
|
||||
@@ -12,4 +17,11 @@ class Asset extends Table {
|
||||
DateTimeColumn get modifiedTime =>
|
||||
dateTime().withDefault(currentDateAndTime)();
|
||||
IntColumn get duration => integer().withDefault(const Constant(0))();
|
||||
|
||||
// Local only
|
||||
TextColumn get localId => text().nullable()();
|
||||
|
||||
// Remote only
|
||||
TextColumn get remoteId => text().nullable()();
|
||||
TextColumn get livePhotoVideoId => text().nullable()();
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:immich_mobile/domain/entities/asset.entity.dart';
|
||||
|
||||
class LocalAsset extends Asset {
|
||||
const LocalAsset();
|
||||
|
||||
TextColumn get localId => text()();
|
||||
|
||||
@override
|
||||
Set<Column> get primaryKey => {localId};
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:immich_mobile/domain/entities/asset.entity.dart';
|
||||
|
||||
class RemoteAsset extends Asset {
|
||||
const RemoteAsset();
|
||||
|
||||
TextColumn get remoteId => text()();
|
||||
TextColumn get livePhotoVideoId => text().nullable()();
|
||||
|
||||
@override
|
||||
Set<Column> get primaryKey => {remoteId};
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:immich_mobile/domain/models/asset.model.dart';
|
||||
import 'package:immich_mobile/domain/models/render_list.model.dart';
|
||||
|
||||
abstract class IAssetRepository {
|
||||
/// Batch insert asset
|
||||
Future<bool> addAll(Iterable<Asset> assets);
|
||||
|
||||
/// Removes all assets
|
||||
Future<bool> clearAll();
|
||||
|
||||
/// Fetch assets from the [offset] with the [limit]
|
||||
Future<List<Asset>> fetchAssets({int? offset, int? limit});
|
||||
|
||||
/// Streams assets as groups grouped by the group type passed
|
||||
Stream<RenderList> getRenderList();
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import 'package:immich_mobile/domain/models/asset/remote_asset.model.dart';
|
||||
|
||||
abstract class IRemoteAssetRepository {
|
||||
/// Batch insert asset
|
||||
Future<bool> addAll(Iterable<RemoteAsset> assets);
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
import 'package:immich_mobile/utils/extensions/string.extension.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
|
||||
enum AssetType {
|
||||
// do not change this order!
|
||||
other,
|
||||
image,
|
||||
video,
|
||||
audio,
|
||||
}
|
||||
|
||||
class Asset {
|
||||
final int id;
|
||||
final String name;
|
||||
final String checksum;
|
||||
final int? height;
|
||||
final int? width;
|
||||
final AssetType type;
|
||||
final DateTime createdTime;
|
||||
final DateTime modifiedTime;
|
||||
final int duration;
|
||||
|
||||
// local only
|
||||
final String? localId;
|
||||
|
||||
// remote only
|
||||
final String? remoteId;
|
||||
final String? livePhotoVideoId;
|
||||
|
||||
bool get isRemote => remoteId != null;
|
||||
bool get isLocal => localId != null;
|
||||
bool get isMerged => isRemote && isLocal;
|
||||
|
||||
const Asset({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.checksum,
|
||||
this.height,
|
||||
this.width,
|
||||
required this.type,
|
||||
required this.createdTime,
|
||||
required this.modifiedTime,
|
||||
required this.duration,
|
||||
this.localId,
|
||||
this.remoteId,
|
||||
this.livePhotoVideoId,
|
||||
});
|
||||
|
||||
factory Asset.remote(AssetResponseDto dto) => Asset(
|
||||
id: 0, // assign a temporary auto gen ID
|
||||
remoteId: dto.id,
|
||||
createdTime: dto.fileCreatedAt,
|
||||
duration: dto.duration.tryParseInt() ?? 0,
|
||||
height: dto.exifInfo?.exifImageHeight?.toInt(),
|
||||
width: dto.exifInfo?.exifImageWidth?.toInt(),
|
||||
checksum: dto.checksum,
|
||||
name: dto.originalFileName,
|
||||
livePhotoVideoId: dto.livePhotoVideoId,
|
||||
modifiedTime: dto.fileModifiedAt,
|
||||
type: _toAssetType(dto.type),
|
||||
);
|
||||
|
||||
Asset copyWith({
|
||||
int? id,
|
||||
String? name,
|
||||
String? checksum,
|
||||
int? height,
|
||||
int? width,
|
||||
AssetType? type,
|
||||
DateTime? createdTime,
|
||||
DateTime? modifiedTime,
|
||||
int? duration,
|
||||
String? localId,
|
||||
String? remoteId,
|
||||
String? livePhotoVideoId,
|
||||
}) {
|
||||
return Asset(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
checksum: checksum ?? this.checksum,
|
||||
height: height ?? this.height,
|
||||
width: width ?? this.width,
|
||||
type: type ?? this.type,
|
||||
createdTime: createdTime ?? this.createdTime,
|
||||
modifiedTime: modifiedTime ?? this.modifiedTime,
|
||||
duration: duration ?? this.duration,
|
||||
localId: localId ?? this.localId,
|
||||
remoteId: remoteId ?? this.remoteId,
|
||||
livePhotoVideoId: livePhotoVideoId ?? this.livePhotoVideoId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => """
|
||||
{
|
||||
"id": "$id",
|
||||
"remoteId": "${remoteId ?? "-"}",
|
||||
"localId": "${localId ?? "-"}",
|
||||
"name": "$name",
|
||||
"checksum": "$checksum",
|
||||
"height": ${height ?? "-"},
|
||||
"width": ${width ?? "-"},
|
||||
"type": "$type",
|
||||
"createdTime": "$createdTime",
|
||||
"modifiedTime": "$modifiedTime",
|
||||
"duration": "$duration",
|
||||
"livePhotoVideoId": "${livePhotoVideoId ?? "-"}",
|
||||
}""";
|
||||
|
||||
@override
|
||||
bool operator ==(covariant Asset other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other.id == id &&
|
||||
other.name == name &&
|
||||
other.checksum == checksum &&
|
||||
other.height == height &&
|
||||
other.width == width &&
|
||||
other.type == type &&
|
||||
other.createdTime == createdTime &&
|
||||
other.modifiedTime == modifiedTime &&
|
||||
other.duration == duration &&
|
||||
other.localId == localId &&
|
||||
other.remoteId == remoteId &&
|
||||
other.livePhotoVideoId == livePhotoVideoId;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return id.hashCode ^
|
||||
name.hashCode ^
|
||||
checksum.hashCode ^
|
||||
height.hashCode ^
|
||||
width.hashCode ^
|
||||
type.hashCode ^
|
||||
createdTime.hashCode ^
|
||||
modifiedTime.hashCode ^
|
||||
duration.hashCode ^
|
||||
localId.hashCode ^
|
||||
remoteId.hashCode ^
|
||||
livePhotoVideoId.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
AssetType _toAssetType(AssetTypeEnum type) => switch (type) {
|
||||
AssetTypeEnum.AUDIO => AssetType.audio,
|
||||
AssetTypeEnum.IMAGE => AssetType.image,
|
||||
AssetTypeEnum.VIDEO => AssetType.video,
|
||||
_ => AssetType.other,
|
||||
};
|
||||
@@ -1,90 +0,0 @@
|
||||
enum AssetType {
|
||||
// do not change this order!
|
||||
other,
|
||||
image,
|
||||
video,
|
||||
audio,
|
||||
}
|
||||
|
||||
class Asset {
|
||||
final String name;
|
||||
final String checksum;
|
||||
final int? height;
|
||||
final int? width;
|
||||
final AssetType type;
|
||||
final DateTime createdTime;
|
||||
final DateTime modifiedTime;
|
||||
final int duration;
|
||||
|
||||
const Asset({
|
||||
required this.name,
|
||||
required this.checksum,
|
||||
this.height,
|
||||
this.width,
|
||||
required this.type,
|
||||
required this.createdTime,
|
||||
required this.modifiedTime,
|
||||
required this.duration,
|
||||
});
|
||||
|
||||
Asset copyWith({
|
||||
String? name,
|
||||
String? checksum,
|
||||
int? height,
|
||||
int? width,
|
||||
AssetType? type,
|
||||
DateTime? createdTime,
|
||||
DateTime? modifiedTime,
|
||||
int? duration,
|
||||
}) {
|
||||
return Asset(
|
||||
name: name ?? this.name,
|
||||
checksum: checksum ?? this.checksum,
|
||||
height: height ?? this.height,
|
||||
width: width ?? this.width,
|
||||
type: type ?? this.type,
|
||||
createdTime: createdTime ?? this.createdTime,
|
||||
modifiedTime: modifiedTime ?? this.modifiedTime,
|
||||
duration: duration ?? this.duration,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => """
|
||||
{
|
||||
"name": "$name",
|
||||
"checksum": "$checksum",
|
||||
"height": ${height ?? "-"},
|
||||
"width": ${width ?? "-"},
|
||||
"type": "$type",
|
||||
"createdTime": "$createdTime",
|
||||
"modifiedTime": "$modifiedTime",
|
||||
"duration": "$duration",
|
||||
}""";
|
||||
|
||||
@override
|
||||
bool operator ==(covariant Asset other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other.name == name &&
|
||||
other.checksum == checksum &&
|
||||
other.height == height &&
|
||||
other.width == width &&
|
||||
other.type == type &&
|
||||
other.createdTime == createdTime &&
|
||||
other.modifiedTime == modifiedTime &&
|
||||
other.duration == duration;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return name.hashCode ^
|
||||
checksum.hashCode ^
|
||||
height.hashCode ^
|
||||
width.hashCode ^
|
||||
type.hashCode ^
|
||||
createdTime.hashCode ^
|
||||
modifiedTime.hashCode ^
|
||||
duration.hashCode;
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:immich_mobile/domain/models/asset/asset.model.dart';
|
||||
|
||||
@immutable
|
||||
class LocalAsset extends Asset {
|
||||
final String localId;
|
||||
|
||||
const LocalAsset({
|
||||
required this.localId,
|
||||
required super.name,
|
||||
required super.checksum,
|
||||
required super.height,
|
||||
required super.width,
|
||||
required super.type,
|
||||
required super.createdTime,
|
||||
required super.modifiedTime,
|
||||
required super.duration,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() => """
|
||||
{
|
||||
"localId": "$localId",
|
||||
"name": "$name",
|
||||
"checksum": "$checksum",
|
||||
"height": ${height ?? "-"},
|
||||
"width": ${width ?? "-"},
|
||||
"type": "$type",
|
||||
"createdTime": "$createdTime",
|
||||
"modifiedTime": "$modifiedTime",
|
||||
"duration": "$duration",
|
||||
}""";
|
||||
|
||||
@override
|
||||
bool operator ==(covariant LocalAsset other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return super == (other) && other.localId == localId;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => super.hashCode ^ localId.hashCode;
|
||||
|
||||
@override
|
||||
LocalAsset copyWith({
|
||||
String? localId,
|
||||
String? name,
|
||||
String? checksum,
|
||||
int? height,
|
||||
int? width,
|
||||
AssetType? type,
|
||||
DateTime? createdTime,
|
||||
DateTime? modifiedTime,
|
||||
int? duration,
|
||||
}) {
|
||||
return LocalAsset(
|
||||
localId: localId ?? this.localId,
|
||||
name: name ?? this.name,
|
||||
checksum: checksum ?? this.checksum,
|
||||
height: height ?? this.height,
|
||||
width: width ?? this.width,
|
||||
type: type ?? this.type,
|
||||
createdTime: createdTime ?? this.createdTime,
|
||||
modifiedTime: modifiedTime ?? this.modifiedTime,
|
||||
duration: duration ?? this.duration,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:immich_mobile/domain/models/asset/asset.model.dart';
|
||||
import 'package:immich_mobile/utils/extensions/string.extension.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
|
||||
@immutable
|
||||
class RemoteAsset extends Asset {
|
||||
final String remoteId;
|
||||
final String? livePhotoVideoId;
|
||||
|
||||
const RemoteAsset({
|
||||
required this.remoteId,
|
||||
required super.name,
|
||||
required super.checksum,
|
||||
required super.height,
|
||||
required super.width,
|
||||
required super.type,
|
||||
required super.createdTime,
|
||||
required super.modifiedTime,
|
||||
required super.duration,
|
||||
this.livePhotoVideoId,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() => """
|
||||
{
|
||||
"remoteId": "$remoteId",
|
||||
"name": "$name",
|
||||
"checksum": "$checksum",
|
||||
"height": ${height ?? "-"},
|
||||
"width": ${width ?? "-"},
|
||||
"type": "$type",
|
||||
"createdTime": "$createdTime",
|
||||
"modifiedTime": "$modifiedTime",
|
||||
"duration": "$duration",
|
||||
"livePhotoVideoId": "${livePhotoVideoId ?? "-"}",
|
||||
}""";
|
||||
|
||||
@override
|
||||
bool operator ==(covariant RemoteAsset other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return super == (other) && other.remoteId == remoteId;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => super.hashCode ^ remoteId.hashCode;
|
||||
|
||||
@override
|
||||
RemoteAsset copyWith({
|
||||
String? remoteId,
|
||||
String? name,
|
||||
String? checksum,
|
||||
int? height,
|
||||
int? width,
|
||||
AssetType? type,
|
||||
DateTime? createdTime,
|
||||
DateTime? modifiedTime,
|
||||
int? duration,
|
||||
String? livePhotoVideoId,
|
||||
}) {
|
||||
return RemoteAsset(
|
||||
remoteId: remoteId ?? this.remoteId,
|
||||
name: name ?? this.name,
|
||||
checksum: checksum ?? this.checksum,
|
||||
height: height ?? this.height,
|
||||
width: width ?? this.width,
|
||||
type: type ?? this.type,
|
||||
createdTime: createdTime ?? this.createdTime,
|
||||
modifiedTime: modifiedTime ?? this.modifiedTime,
|
||||
duration: duration ?? this.duration,
|
||||
livePhotoVideoId: livePhotoVideoId ?? this.livePhotoVideoId,
|
||||
);
|
||||
}
|
||||
|
||||
factory RemoteAsset.fromDto(AssetResponseDto dto) => RemoteAsset(
|
||||
remoteId: dto.id,
|
||||
createdTime: dto.fileCreatedAt,
|
||||
duration: dto.duration.tryParseInt() ?? 0,
|
||||
height: dto.exifInfo?.exifImageHeight?.toInt(),
|
||||
width: dto.exifInfo?.exifImageWidth?.toInt(),
|
||||
checksum: dto.checksum,
|
||||
name: dto.originalFileName,
|
||||
livePhotoVideoId: dto.livePhotoVideoId,
|
||||
modifiedTime: dto.fileModifiedAt,
|
||||
type: _toAssetType(dto.type),
|
||||
);
|
||||
}
|
||||
|
||||
AssetType _toAssetType(AssetTypeEnum type) => switch (type) {
|
||||
AssetTypeEnum.AUDIO => AssetType.audio,
|
||||
AssetTypeEnum.IMAGE => AssetType.image,
|
||||
AssetTypeEnum.VIDEO => AssetType.video,
|
||||
_ => AssetType.other,
|
||||
};
|
||||
@@ -0,0 +1,64 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/asset.interface.dart';
|
||||
import 'package:immich_mobile/domain/models/asset.model.dart';
|
||||
import 'package:immich_mobile/domain/models/render_list_element.model.dart';
|
||||
import 'package:immich_mobile/service_locator.dart';
|
||||
|
||||
class RenderList {
|
||||
final List<RenderListElement> elements;
|
||||
final int totalCount;
|
||||
|
||||
/// global offset of assets in [_buf]
|
||||
int _bufOffset = 0;
|
||||
|
||||
/// reference to batch of assets loaded from DB with offset [_bufOffset]
|
||||
List<Asset> _buf = [];
|
||||
|
||||
RenderList({required this.elements, required this.totalCount});
|
||||
|
||||
/// Loads the requested assets from the database to an internal buffer if not cached
|
||||
/// and returns a slice of that buffer
|
||||
Future<List<Asset>> loadAssets(int offset, int count) async {
|
||||
assert(offset >= 0);
|
||||
assert(count > 0);
|
||||
assert(offset + count <= totalCount);
|
||||
|
||||
// general case: we have the query to load assets via offset from the DB on demand
|
||||
if (offset < _bufOffset || offset + count > _bufOffset + _buf.length) {
|
||||
// the requested slice (offset:offset+count) is not contained in the cache buffer `_buf`
|
||||
// thus, fill the buffer with a new batch of assets that at least contains the requested
|
||||
// assets and some more
|
||||
|
||||
final bool forward = _bufOffset < offset;
|
||||
// if the requested offset is greater than the cached offset, the user scrolls forward "down"
|
||||
const batchSize = 256;
|
||||
const oppositeSize = 64;
|
||||
|
||||
// make sure to load a meaningful amount of data (and not only the requested slice)
|
||||
// otherwise, each call to [loadAssets] would result in DB call trashing performance
|
||||
// fills small requests to [batchSize], adds some legroom into the opposite scroll direction for large requests
|
||||
final len = math.max(batchSize, count + oppositeSize);
|
||||
// when scrolling forward, start shortly before the requested offset...
|
||||
// when scrolling backward, end shortly after the requested offset...
|
||||
// ... to guard against the user scrolling in the other direction
|
||||
// a tiny bit resulting in a another required load from the DB
|
||||
final start = math.max(
|
||||
0,
|
||||
forward
|
||||
? offset - oppositeSize
|
||||
: (len > batchSize ? offset : offset + count - len),
|
||||
);
|
||||
// load the calculated batch (start:start+len) from the DB and put it into the buffer
|
||||
_buf =
|
||||
await di<IAssetRepository>().fetchAssets(offset: start, limit: len);
|
||||
_bufOffset = start;
|
||||
|
||||
assert(_bufOffset <= offset);
|
||||
assert(_bufOffset + _buf.length >= offset + count);
|
||||
}
|
||||
// return the requested slice from the buffer (we made sure before that the assets are loaded!)
|
||||
return _buf.slice(offset - _bufOffset, offset - _bufOffset + count);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
sealed class RenderListElement {
|
||||
const RenderListElement();
|
||||
}
|
||||
|
||||
class RenderListMonthHeaderElement extends RenderListElement {
|
||||
final String header;
|
||||
|
||||
const RenderListMonthHeaderElement({required this.header});
|
||||
}
|
||||
|
||||
class RenderListDayHeaderElement extends RenderListElement {
|
||||
final String header;
|
||||
|
||||
const RenderListDayHeaderElement({required this.header});
|
||||
}
|
||||
|
||||
class RenderListAssetElement extends RenderListElement {
|
||||
final DateTime date;
|
||||
final int assetCount;
|
||||
final int assetOffset;
|
||||
|
||||
const RenderListAssetElement({
|
||||
required this.date,
|
||||
required this.assetCount,
|
||||
required this.assetOffset,
|
||||
});
|
||||
|
||||
RenderListAssetElement copyWith({
|
||||
DateTime? date,
|
||||
int? assetCount,
|
||||
int? assetOffset,
|
||||
}) {
|
||||
return RenderListAssetElement(
|
||||
date: date ?? this.date,
|
||||
assetCount: assetCount ?? this.assetCount,
|
||||
assetOffset: assetOffset ?? this.assetOffset,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
'RenderListAssetElement(date: $date, assetCount: $assetCount, assetOffset: $assetOffset)';
|
||||
|
||||
@override
|
||||
bool operator ==(covariant RenderListAssetElement other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other.date == date &&
|
||||
other.assetCount == assetCount &&
|
||||
other.assetOffset == assetOffset;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
date.hashCode ^ assetCount.hashCode ^ assetOffset.hashCode;
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:immich_mobile/domain/entities/asset.entity.drift.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/asset.interface.dart';
|
||||
import 'package:immich_mobile/domain/models/asset.model.dart';
|
||||
import 'package:immich_mobile/domain/models/render_list.model.dart';
|
||||
import 'package:immich_mobile/domain/models/render_list_element.model.dart';
|
||||
import 'package:immich_mobile/domain/repositories/database.repository.dart';
|
||||
import 'package:immich_mobile/utils/extensions/drift.extension.dart';
|
||||
import 'package:immich_mobile/utils/mixins/log_context.mixin.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class RemoteAssetDriftRepository with LogContext implements IAssetRepository {
|
||||
final DriftDatabaseRepository _db;
|
||||
|
||||
const RemoteAssetDriftRepository(this._db);
|
||||
|
||||
@override
|
||||
Future<bool> addAll(Iterable<Asset> assets) async {
|
||||
try {
|
||||
await _db.batch((batch) => batch.insertAllOnConflictUpdate(
|
||||
_db.asset,
|
||||
assets.map(_toEntity),
|
||||
));
|
||||
|
||||
return true;
|
||||
} catch (e, s) {
|
||||
log.severe("Cannot insert remote assets into table", e, s);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> clearAll() async {
|
||||
try {
|
||||
await _db.asset.deleteAll();
|
||||
return true;
|
||||
} catch (e, s) {
|
||||
log.severe("Cannot clear remote assets", e, s);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Asset>> fetchAssets({int? offset, int? limit}) async {
|
||||
final query = _db.asset.select()
|
||||
..orderBy([(asset) => OrderingTerm.desc(asset.createdTime)]);
|
||||
|
||||
if (limit != null) {
|
||||
query.limit(limit, offset: offset);
|
||||
}
|
||||
|
||||
return (await query.get()).map(_toModel).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<RenderList> getRenderList() {
|
||||
final assetCountExp = _db.asset.id.count();
|
||||
final createdTimeExp = _db.asset.createdTime;
|
||||
final monthYearExp = _db.asset.createdTime.strftime('%m-%Y');
|
||||
|
||||
final query = _db.asset.selectOnly()
|
||||
..addColumns([assetCountExp, createdTimeExp])
|
||||
..groupBy([monthYearExp])
|
||||
..orderBy([OrderingTerm.desc(createdTimeExp)]);
|
||||
|
||||
int lastAssetOffset = 0;
|
||||
final monthFormatter = DateFormat.yMMMM();
|
||||
|
||||
return query
|
||||
.expand((row) {
|
||||
final createdTime = row.read<DateTime>(createdTimeExp)!;
|
||||
final assetCount = row.read(assetCountExp)!;
|
||||
final assetOffset = lastAssetOffset;
|
||||
lastAssetOffset += assetCount;
|
||||
|
||||
return [
|
||||
RenderListMonthHeaderElement(
|
||||
header: monthFormatter.format(createdTime),
|
||||
),
|
||||
RenderListAssetElement(
|
||||
date: createdTime,
|
||||
assetCount: assetCount,
|
||||
assetOffset: assetOffset,
|
||||
),
|
||||
];
|
||||
})
|
||||
.watch()
|
||||
.map((elements) {
|
||||
final int totalCount;
|
||||
final lastAssetElement =
|
||||
elements.whereType<RenderListAssetElement>().lastOrNull;
|
||||
if (lastAssetElement == null) {
|
||||
totalCount = 0;
|
||||
} else {
|
||||
totalCount =
|
||||
lastAssetElement.assetCount + lastAssetElement.assetOffset;
|
||||
}
|
||||
|
||||
return RenderList(elements: elements, totalCount: totalCount);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
AssetCompanion _toEntity(Asset asset) {
|
||||
return AssetCompanion.insert(
|
||||
localId: Value(asset.localId),
|
||||
remoteId: Value(asset.remoteId),
|
||||
name: asset.name,
|
||||
checksum: asset.checksum,
|
||||
height: Value(asset.height),
|
||||
width: Value(asset.width),
|
||||
type: asset.type,
|
||||
createdTime: asset.createdTime,
|
||||
duration: Value(asset.duration),
|
||||
modifiedTime: Value(asset.modifiedTime),
|
||||
livePhotoVideoId: Value(asset.livePhotoVideoId),
|
||||
);
|
||||
}
|
||||
|
||||
Asset _toModel(AssetData asset) {
|
||||
return Asset(
|
||||
id: asset.id,
|
||||
localId: asset.localId,
|
||||
remoteId: asset.remoteId,
|
||||
name: asset.name,
|
||||
type: asset.type,
|
||||
checksum: asset.checksum,
|
||||
createdTime: asset.createdTime,
|
||||
modifiedTime: asset.modifiedTime,
|
||||
height: asset.height,
|
||||
width: asset.width,
|
||||
livePhotoVideoId: asset.livePhotoVideoId,
|
||||
duration: asset.duration,
|
||||
);
|
||||
}
|
||||
@@ -4,15 +4,14 @@ import 'package:drift_dev/api/migrations.dart';
|
||||
import 'package:drift_flutter/drift_flutter.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:immich_mobile/domain/entities/album.entity.dart';
|
||||
import 'package:immich_mobile/domain/entities/local_asset.entity.dart';
|
||||
import 'package:immich_mobile/domain/entities/asset.entity.dart';
|
||||
import 'package:immich_mobile/domain/entities/log.entity.dart';
|
||||
import 'package:immich_mobile/domain/entities/remote_asset.entity.dart';
|
||||
import 'package:immich_mobile/domain/entities/store.entity.dart';
|
||||
import 'package:immich_mobile/domain/entities/user.entity.dart';
|
||||
|
||||
import 'database.repository.drift.dart';
|
||||
|
||||
@DriftDatabase(tables: [Logs, Store, LocalAlbum, LocalAsset, User, RemoteAsset])
|
||||
@DriftDatabase(tables: [Logs, Store, LocalAlbum, Asset, User])
|
||||
class DriftDatabaseRepository extends $DriftDatabaseRepository {
|
||||
DriftDatabaseRepository([QueryExecutor? executor])
|
||||
: super(executor ?? driftDatabase(name: 'db'));
|
||||
@@ -27,6 +26,9 @@ class DriftDatabaseRepository extends $DriftDatabaseRepository {
|
||||
if (kDebugMode) {
|
||||
await validateDatabaseSchema();
|
||||
}
|
||||
|
||||
await customStatement('PRAGMA journal_mode = WAL');
|
||||
await customStatement('PRAGMA foreign_keys = ON');
|
||||
},
|
||||
// ignore: no-empty-block
|
||||
onUpgrade: (m, from, to) async {},
|
||||
|
||||
@@ -8,21 +8,21 @@ import 'package:immich_mobile/domain/models/log.model.dart';
|
||||
import 'package:immich_mobile/domain/repositories/database.repository.dart';
|
||||
|
||||
class LogDriftRepository implements ILogRepository {
|
||||
final DriftDatabaseRepository db;
|
||||
final DriftDatabaseRepository _db;
|
||||
|
||||
const LogDriftRepository(this.db);
|
||||
const LogDriftRepository(this._db);
|
||||
|
||||
@override
|
||||
Future<List<LogMessage>> fetchAll() async {
|
||||
return await db.managers.logs.map(_toModel).get();
|
||||
return await _db.managers.logs.map(_toModel).get();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> truncateLogs({int limit = 250}) async {
|
||||
final totalCount = await db.managers.logs.count();
|
||||
final totalCount = await _db.managers.logs.count();
|
||||
if (totalCount > limit) {
|
||||
final rowsToDelete = totalCount - limit;
|
||||
await db.managers.logs
|
||||
await _db.managers.logs
|
||||
.orderBy((o) => o.createdAt.desc())
|
||||
.limit(rowsToDelete)
|
||||
.delete();
|
||||
@@ -32,7 +32,7 @@ class LogDriftRepository implements ILogRepository {
|
||||
@override
|
||||
FutureOr<bool> add(LogMessage log) async {
|
||||
try {
|
||||
await db.into(db.logs).insert(LogsCompanion.insert(
|
||||
await _db.into(_db.logs).insert(LogsCompanion.insert(
|
||||
content: log.content,
|
||||
level: log.level,
|
||||
createdAt: Value(log.createdAt),
|
||||
@@ -50,9 +50,9 @@ class LogDriftRepository implements ILogRepository {
|
||||
@override
|
||||
FutureOr<bool> addAll(List<LogMessage> logs) async {
|
||||
try {
|
||||
await db.batch((b) {
|
||||
await _db.batch((b) {
|
||||
b.insertAll(
|
||||
db.logs,
|
||||
_db.logs,
|
||||
logs.map((log) => LogsCompanion.insert(
|
||||
content: log.content,
|
||||
level: log.level,
|
||||
@@ -73,7 +73,7 @@ class LogDriftRepository implements ILogRepository {
|
||||
@override
|
||||
FutureOr<bool> clear() async {
|
||||
try {
|
||||
await db.managers.logs.delete();
|
||||
await _db.managers.logs.delete();
|
||||
return true;
|
||||
} catch (e) {
|
||||
debugPrint("Error while clearning the logs in DB - $e");
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:immich_mobile/domain/entities/remote_asset.entity.drift.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/remote_asset.interface.dart';
|
||||
import 'package:immich_mobile/domain/models/asset/remote_asset.model.dart';
|
||||
import 'package:immich_mobile/domain/repositories/database.repository.dart';
|
||||
import 'package:immich_mobile/utils/mixins/log_context.mixin.dart';
|
||||
|
||||
class RemoteAssetDriftRepository
|
||||
with LogContext
|
||||
implements IRemoteAssetRepository {
|
||||
final DriftDatabaseRepository _db;
|
||||
|
||||
const RemoteAssetDriftRepository(this._db);
|
||||
|
||||
@override
|
||||
Future<bool> addAll(Iterable<RemoteAsset> assets) async {
|
||||
try {
|
||||
await _db.batch((batch) => batch.insertAllOnConflictUpdate(
|
||||
_db.remoteAsset,
|
||||
assets.map(_toEntity),
|
||||
));
|
||||
|
||||
return true;
|
||||
} catch (e, s) {
|
||||
log.severe("Cannot insert remote assets into table", e, s);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RemoteAssetCompanion _toEntity(RemoteAsset asset) {
|
||||
return RemoteAssetCompanion.insert(
|
||||
name: asset.name,
|
||||
checksum: asset.checksum,
|
||||
height: Value(asset.height),
|
||||
width: Value(asset.width),
|
||||
type: asset.type,
|
||||
createdTime: asset.createdTime,
|
||||
remoteId: asset.remoteId,
|
||||
duration: Value(asset.duration),
|
||||
modifiedTime: Value(asset.modifiedTime),
|
||||
livePhotoVideoId: Value(asset.livePhotoVideoId),
|
||||
);
|
||||
}
|
||||
@@ -8,13 +8,13 @@ import 'package:immich_mobile/domain/repositories/database.repository.dart';
|
||||
import 'package:immich_mobile/utils/mixins/log_context.mixin.dart';
|
||||
|
||||
class StoreDriftRepository with LogContext implements IStoreRepository {
|
||||
final DriftDatabaseRepository db;
|
||||
final DriftDatabaseRepository _db;
|
||||
|
||||
const StoreDriftRepository(this.db);
|
||||
const StoreDriftRepository(this._db);
|
||||
|
||||
@override
|
||||
FutureOr<T?> tryGet<T, U>(StoreKey<T, U> key) async {
|
||||
final storeData = await db.managers.store
|
||||
final storeData = await _db.managers.store
|
||||
.filter((s) => s.id.equals(key.id))
|
||||
.getSingleOrNull();
|
||||
return _getValueFromStoreData(key, storeData);
|
||||
@@ -35,7 +35,7 @@ class StoreDriftRepository with LogContext implements IStoreRepository {
|
||||
final storeValue = key.converter.toPrimitive(value);
|
||||
final intValue = (key.type == int) ? storeValue as int : null;
|
||||
final stringValue = (key.type == String) ? storeValue as String : null;
|
||||
await db.into(db.store).insertOnConflictUpdate(StoreCompanion.insert(
|
||||
await _db.into(_db.store).insertOnConflictUpdate(StoreCompanion.insert(
|
||||
id: Value(key.id),
|
||||
intValue: Value(intValue),
|
||||
stringValue: Value(stringValue),
|
||||
@@ -49,12 +49,12 @@ class StoreDriftRepository with LogContext implements IStoreRepository {
|
||||
|
||||
@override
|
||||
FutureOr<void> delete(StoreKey key) async {
|
||||
await db.managers.store.filter((s) => s.id.equals(key.id)).delete();
|
||||
await _db.managers.store.filter((s) => s.id.equals(key.id)).delete();
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<T?> watch<T, U>(StoreKey<T, U> key) {
|
||||
return db.managers.store
|
||||
return _db.managers.store
|
||||
.filter((s) => s.id.equals(key.id))
|
||||
.watchSingleOrNull()
|
||||
.asyncMap((e) async => await _getValueFromStoreData(key, e));
|
||||
@@ -62,8 +62,7 @@ class StoreDriftRepository with LogContext implements IStoreRepository {
|
||||
|
||||
@override
|
||||
FutureOr<void> clearStore() async {
|
||||
await db.managers.store.delete();
|
||||
|
||||
await _db.managers.store.delete();
|
||||
}
|
||||
|
||||
FutureOr<T?> _getValueFromStoreData<T, U>(
|
||||
|
||||
@@ -8,13 +8,13 @@ import 'package:immich_mobile/domain/repositories/database.repository.dart';
|
||||
import 'package:immich_mobile/utils/mixins/log_context.mixin.dart';
|
||||
|
||||
class UserDriftRepository with LogContext implements IUserRepository {
|
||||
final DriftDatabaseRepository db;
|
||||
final DriftDatabaseRepository _db;
|
||||
|
||||
const UserDriftRepository(this.db);
|
||||
const UserDriftRepository(this._db);
|
||||
|
||||
@override
|
||||
FutureOr<User?> fetch(String userId) async {
|
||||
return await db.managers.user
|
||||
return await _db.managers.user
|
||||
.filter((f) => f.id.equals(userId))
|
||||
.map(_toModel)
|
||||
.getSingleOrNull();
|
||||
@@ -23,7 +23,7 @@ class UserDriftRepository with LogContext implements IUserRepository {
|
||||
@override
|
||||
FutureOr<bool> add(User user) async {
|
||||
try {
|
||||
await db.into(db.user).insertOnConflictUpdate(
|
||||
await _db.into(_db.user).insertOnConflictUpdate(
|
||||
UserCompanion.insert(
|
||||
id: user.id,
|
||||
name: user.name,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:drift/isolate.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/remote_asset.interface.dart';
|
||||
import 'package:immich_mobile/domain/models/asset/remote_asset.model.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/asset.interface.dart';
|
||||
import 'package:immich_mobile/domain/models/asset.model.dart';
|
||||
import 'package:immich_mobile/domain/models/user.model.dart';
|
||||
import 'package:immich_mobile/domain/repositories/database.repository.dart';
|
||||
import 'package:immich_mobile/service_locator.dart';
|
||||
@@ -53,8 +53,7 @@ class SyncService with LogContext {
|
||||
break;
|
||||
}
|
||||
|
||||
await di<IRemoteAssetRepository>()
|
||||
.addAll(assets.map(RemoteAsset.fromDto));
|
||||
await di<IAssetRepository>().addAll(assets.map(Asset.remote));
|
||||
|
||||
lastAssetId = assets.lastOrNull?.id;
|
||||
if (assets.length != chunkSize) break;
|
||||
|
||||
@@ -9,14 +9,14 @@ import 'package:immich_mobile/presentation/router/router.dart';
|
||||
import 'package:immich_mobile/service_locator.dart';
|
||||
import 'package:immich_mobile/utils/constants/globals.dart';
|
||||
|
||||
class ImmichApp extends StatefulWidget {
|
||||
const ImmichApp({super.key});
|
||||
class ImApp extends StatefulWidget {
|
||||
const ImApp({super.key});
|
||||
|
||||
@override
|
||||
State createState() => _ImmichAppState();
|
||||
State createState() => _ImAppState();
|
||||
}
|
||||
|
||||
class _ImmichAppState extends State<ImmichApp> with WidgetsBindingObserver {
|
||||
class _ImAppState extends State<ImApp> with WidgetsBindingObserver {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TranslationProvider(
|
||||
|
||||
@@ -14,5 +14,5 @@ void main() {
|
||||
// Init localization
|
||||
LocaleSettings.useDeviceLocale();
|
||||
|
||||
runApp(const ImmichApp());
|
||||
runApp(const ImApp());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/asset.interface.dart';
|
||||
import 'package:immich_mobile/domain/models/render_list_element.model.dart';
|
||||
import 'package:immich_mobile/presentation/components/image/immich_image.widget.dart';
|
||||
import 'package:immich_mobile/service_locator.dart';
|
||||
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
|
||||
|
||||
class ImAssetGrid extends StatelessWidget {
|
||||
const ImAssetGrid({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return StreamBuilder(
|
||||
stream: di<IAssetRepository>().getRenderList(),
|
||||
builder: (_, renderSnap) {
|
||||
final renderList = renderSnap.data;
|
||||
if (renderList == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final elements = renderList.elements;
|
||||
return ScrollablePositionedList.builder(
|
||||
itemCount: elements.length,
|
||||
itemBuilder: (_, sectionIndex) {
|
||||
final section = elements[sectionIndex];
|
||||
|
||||
return switch (section) {
|
||||
RenderListMonthHeaderElement() => Text(section.header),
|
||||
RenderListDayHeaderElement() => Text(section.header),
|
||||
RenderListAssetElement() => FutureBuilder(
|
||||
future: renderList.loadAssets(
|
||||
section.assetOffset,
|
||||
section.assetCount,
|
||||
),
|
||||
builder: (_, assetsSnap) {
|
||||
final assets = assetsSnap.data;
|
||||
if (assets == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return GridView.builder(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
gridDelegate:
|
||||
const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 4,
|
||||
),
|
||||
itemBuilder: (_, i) {
|
||||
return SizedBox.square(
|
||||
dimension: 200,
|
||||
// ignore: avoid-unsafe-collection-methods
|
||||
child: ImImage(assets.elementAt(i)),
|
||||
);
|
||||
},
|
||||
itemCount: section.assetCount,
|
||||
);
|
||||
},
|
||||
),
|
||||
};
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
import 'package:immich_mobile/domain/models/asset.model.dart';
|
||||
import 'package:immich_mobile/service_locator.dart';
|
||||
import 'package:immich_mobile/utils/immich_api_client.dart';
|
||||
import 'package:immich_mobile/utils/immich_image_url_helper.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
|
||||
class ImImage extends StatelessWidget {
|
||||
final Asset asset;
|
||||
final double? width;
|
||||
final double? height;
|
||||
|
||||
const ImImage(this.asset, {this.width, this.height, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CachedNetworkImage(
|
||||
imageUrl: ImImageUrlHelper.getThumbnailUrl(asset),
|
||||
httpHeaders: di<ImmichApiClient>().headers,
|
||||
cacheKey: ImImageUrlHelper.getThumbnailUrl(asset),
|
||||
width: width,
|
||||
height: height,
|
||||
// keeping memCacheWidth, memCacheHeight, maxWidthDiskCache and
|
||||
// maxHeightDiskCache = null allows to simply store the webp thumbnail
|
||||
// from the server and use it for all rendered thumbnail sizes
|
||||
fit: BoxFit.cover,
|
||||
fadeInDuration: const Duration(milliseconds: 250),
|
||||
progressIndicatorBuilder: (_, url, downloadProgress) {
|
||||
// Show loading if desired
|
||||
return const SizedBox.square(
|
||||
dimension: 250,
|
||||
child: DecoratedBox(decoration: BoxDecoration(color: Colors.grey)),
|
||||
);
|
||||
},
|
||||
errorWidget: (_, url, error) {
|
||||
if (error is HttpExceptionWithStatus &&
|
||||
error.statusCode >= 400 &&
|
||||
error.statusCode < 500) {
|
||||
CachedNetworkImage.evictFromCache(url);
|
||||
}
|
||||
return Icon(
|
||||
Symbols.image_not_supported_rounded,
|
||||
color: Theme.of(context).primaryColor,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:immich_mobile/domain/services/sync.service.dart';
|
||||
import 'package:immich_mobile/presentation/modules/common/states/current_user.state.dart';
|
||||
import 'package:immich_mobile/service_locator.dart';
|
||||
import 'package:immich_mobile/presentation/components/grid/immich_asset_grid.widget.dart';
|
||||
|
||||
@RoutePage()
|
||||
class HomePage extends StatelessWidget {
|
||||
@@ -10,12 +8,6 @@ class HomePage extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: () => di<SyncService>()
|
||||
.doFullSyncForUserDrift(di<CurrentUserCubit>().state),
|
||||
child: const Text('Sync'),
|
||||
),
|
||||
);
|
||||
return const ImAssetGrid();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/asset.interface.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/store.interface.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/user.interface.dart';
|
||||
import 'package:immich_mobile/domain/models/store.model.dart';
|
||||
@@ -135,7 +136,8 @@ class LoginPageCubit extends Cubit<LoginPageState> with LogContext {
|
||||
// Register user
|
||||
ServiceLocator.registerCurrentUser(user);
|
||||
await di<IUserRepository>().add(user);
|
||||
// Sync assets in background
|
||||
// Remove and Sync assets in background
|
||||
await di<IAssetRepository>().clearAll();
|
||||
unawaited(di<SyncService>().doFullSyncForUserDrift(user));
|
||||
|
||||
emit(state.copyWith(
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/asset.interface.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/log.interface.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/remote_asset.interface.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/store.interface.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/user.interface.dart';
|
||||
import 'package:immich_mobile/domain/models/user.model.dart';
|
||||
import 'package:immich_mobile/domain/repositories/asset.repository.dart';
|
||||
import 'package:immich_mobile/domain/repositories/database.repository.dart';
|
||||
import 'package:immich_mobile/domain/repositories/log.repository.dart';
|
||||
import 'package:immich_mobile/domain/repositories/remote_asset.repository.dart';
|
||||
import 'package:immich_mobile/domain/repositories/store.repository.dart';
|
||||
import 'package:immich_mobile/domain/repositories/user.repository.dart';
|
||||
import 'package:immich_mobile/domain/services/app_setting.service.dart';
|
||||
@@ -44,7 +44,7 @@ class ServiceLocator {
|
||||
di.registerFactory<ILogRepository>(() => LogDriftRepository(di()));
|
||||
di.registerFactory<AppSettingService>(() => AppSettingService(di()));
|
||||
di.registerFactory<IUserRepository>(() => UserDriftRepository(di()));
|
||||
di.registerFactory<IRemoteAssetRepository>(
|
||||
di.registerFactory<IAssetRepository>(
|
||||
() => RemoteAssetDriftRepository(di()),
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
extension ExpandQuery<T> on Selectable<T> {
|
||||
/// Expands this selectable by the [expand] function.
|
||||
///
|
||||
/// Each entry emitted by this [Selectable] will be transformed by the
|
||||
/// [expander] and then emitted to the selectable returned.
|
||||
Selectable<N> expand<N>(Iterable<N> Function(T) expander) {
|
||||
return _ExpandedSelectable<T, N>(this, expander);
|
||||
}
|
||||
}
|
||||
|
||||
class _ExpandedSelectable<S, T> extends Selectable<T> {
|
||||
final Selectable<S> _source;
|
||||
final Iterable<T> Function(S) expander;
|
||||
|
||||
_ExpandedSelectable(this._source, this.expander);
|
||||
|
||||
@override
|
||||
Future<List<T>> get() {
|
||||
return _source.get().then(_mapResults);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<List<T>> watch() {
|
||||
return _source.watch().map(_mapResults);
|
||||
}
|
||||
|
||||
List<T> _mapResults(List<S> results) => results.expand<T>(expander).toList();
|
||||
}
|
||||
@@ -13,19 +13,21 @@ import 'package:immich_mobile/utils/mixins/log_context.mixin.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
|
||||
@immutable
|
||||
class ImmichApiClientData {
|
||||
class ImApiClientData {
|
||||
final String endpoint;
|
||||
final Map<String, String> headersMap;
|
||||
|
||||
const ImmichApiClientData({required this.endpoint, required this.headersMap});
|
||||
const ImApiClientData({required this.endpoint, required this.headersMap});
|
||||
}
|
||||
|
||||
class ImmichApiClient extends ApiClient with LogContext {
|
||||
ImmichApiClient({required String endpoint}) : super(basePath: endpoint);
|
||||
|
||||
/// Used to recreate the client in Isolates
|
||||
ImmichApiClientData get clientData =>
|
||||
ImmichApiClientData(endpoint: basePath, headersMap: defaultHeaderMap);
|
||||
ImApiClientData get clientData =>
|
||||
ImApiClientData(endpoint: basePath, headersMap: defaultHeaderMap);
|
||||
|
||||
Map<String, String> get headers => defaultHeaderMap;
|
||||
|
||||
Future<void> init({String? accessToken}) async {
|
||||
final token =
|
||||
@@ -47,7 +49,7 @@ class ImmichApiClient extends ApiClient with LogContext {
|
||||
addDefaultHeader(kImmichHeaderDeviceType, Platform.operatingSystem);
|
||||
}
|
||||
|
||||
factory ImmichApiClient.clientData(ImmichApiClientData data) {
|
||||
factory ImmichApiClient.clientData(ImApiClientData data) {
|
||||
final client = ImmichApiClient(endpoint: data.endpoint);
|
||||
|
||||
for (final entry in data.headersMap.entries) {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import 'package:immich_mobile/domain/models/asset.model.dart';
|
||||
import 'package:immich_mobile/service_locator.dart';
|
||||
import 'package:immich_mobile/utils/immich_api_client.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
|
||||
class ImImageUrlHelper {
|
||||
const ImImageUrlHelper();
|
||||
|
||||
static String get _serverUrl => di<ImmichApiClient>().basePath;
|
||||
|
||||
static String getThumbnailUrl(
|
||||
final Asset asset, {
|
||||
AssetMediaSize type = AssetMediaSize.thumbnail,
|
||||
}) {
|
||||
return _getThumbnailUrlForRemoteId(asset.remoteId!, type: type);
|
||||
}
|
||||
|
||||
static String getThumbnailCacheKey(
|
||||
final Asset asset, {
|
||||
AssetMediaSize type = AssetMediaSize.thumbnail,
|
||||
}) {
|
||||
return _getThumbnailCacheKeyForRemoteId(asset.remoteId!, type: type);
|
||||
}
|
||||
|
||||
static String _getThumbnailCacheKeyForRemoteId(
|
||||
final String id, {
|
||||
AssetMediaSize type = AssetMediaSize.thumbnail,
|
||||
}) {
|
||||
if (type == AssetMediaSize.thumbnail) {
|
||||
return 'thumbnail-image-$id';
|
||||
}
|
||||
return 'preview-image-$id';
|
||||
}
|
||||
|
||||
static String _getThumbnailUrlForRemoteId(
|
||||
final String id, {
|
||||
AssetMediaSize type = AssetMediaSize.thumbnail,
|
||||
}) {
|
||||
return '$_serverUrl/assets/$id/thumbnail?size=${type.value}';
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,6 @@ import 'package:immich_mobile/domain/interfaces/log.interface.dart';
|
||||
import 'package:immich_mobile/domain/models/log.model.dart';
|
||||
import 'package:immich_mobile/service_locator.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
// ignore: depend_on_referenced_packages
|
||||
import 'package:stack_trace/stack_trace.dart' as stack_trace;
|
||||
|
||||
/// [LogManager] is a custom logger that is built on top of the [logging] package.
|
||||
/// The logs are written to the database and onto console, using `debugPrint` method.
|
||||
@@ -29,7 +27,7 @@ class LogManager {
|
||||
debugPrint('[${record.level.name}] [${record.time}] ${record.message}');
|
||||
if (record.error != null && record.stackTrace != null) {
|
||||
debugPrint('${record.error}');
|
||||
debugPrintStack(stackTrace: record.stackTrace);
|
||||
debugPrint('${record.stackTrace}');
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
@@ -76,12 +74,6 @@ class LogManager {
|
||||
}
|
||||
|
||||
static void setGlobalErrorCallbacks() {
|
||||
FlutterError.demangleStackTrace = (StackTrace stack) {
|
||||
if (stack is stack_trace.Trace) return stack.vmTrace;
|
||||
if (stack is stack_trace.Chain) return stack.toTrace().vmTrace;
|
||||
return stack;
|
||||
};
|
||||
|
||||
FlutterError.onError = (details) {
|
||||
Logger("FlutterError").severe(
|
||||
'Unknown framework error occured in library ${details.library ?? "<unknown>"} at node ${details.context ?? "<unkown>"}',
|
||||
|
||||
Reference in New Issue
Block a user