chore: style grid

This commit is contained in:
shenlong-tanwen
2024-09-13 04:00:50 +05:30
parent 419d3669a2
commit 53974e7276
23 changed files with 344 additions and 127 deletions
@@ -2,21 +2,21 @@ import 'package:immich_mobile/domain/interfaces/store.interface.dart';
import 'package:immich_mobile/domain/models/app_setting.model.dart';
class AppSettingService {
final IStoreRepository store;
final IStoreRepository _store;
const AppSettingService(this.store);
const AppSettingService(this._store);
Future<T> getSetting<T>(AppSetting<T> setting) async {
final value = await store.tryGet(setting.storeKey);
final value = await _store.tryGet(setting.storeKey);
return value ?? setting.defaultValue;
}
Future<bool> setSetting<T>(AppSetting<T> setting, T value) async {
return await store.set(setting.storeKey, value);
return await _store.set(setting.storeKey, value);
}
Stream<T> watchSetting<T>(AppSetting<T> setting) {
return store
return _store
.watch(setting.storeKey)
.map((value) => value ?? setting.defaultValue);
}
@@ -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';
import 'package:immich_mobile/utils/constants/globals.dart';
class RenderList {
final List<RenderListElement> elements;
final int totalCount;
/// offset of the assets from last section in [_buf]
int _bufOffset = 0;
/// assets cache 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);
// 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
if (offset < _bufOffset || offset + count > _bufOffset + _buf.length) {
final bool forward = _bufOffset < offset;
// 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(kRenderListBatchSize, count + kRenderListOppositeBatchSize);
// 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 - kRenderListOppositeBatchSize
: (len > kRenderListBatchSize ? 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);
}
}
@@ -6,32 +6,29 @@ import 'package:immich_mobile/domain/repositories/database.repository.dart';
import 'package:immich_mobile/service_locator.dart';
import 'package:immich_mobile/utils/constants/globals.dart';
import 'package:immich_mobile/utils/immich_api_client.dart';
import 'package:immich_mobile/utils/log_manager.dart';
import 'package:immich_mobile/utils/isolate_helper.dart';
import 'package:immich_mobile/utils/mixins/log_context.mixin.dart';
import 'package:logging/logging.dart';
import 'package:openapi/api.dart';
class SyncService with LogContext {
final ImmichApiClient _appClient;
final DriftDatabaseRepository _db;
SyncService(this._appClient, this._db);
SyncService(this._db);
Future<bool> doFullSyncForUserDrift(
User user, {
DateTime? updatedUtil,
int? limit,
}) async {
final clientData = _appClient.clientData;
final helper = IsolateHelper()..preIsolateHandling();
try {
await _db.computeWithDatabase(
connect: (connection) => DriftDatabaseRepository(connection),
computation: (database) async {
ServiceLocator.configureServicesForIsolate(database: database);
LogManager.I.init();
helper.postIsolateHandling(database: database);
final logger = Logger("SyncService <Isolate>");
final syncClient =
ImmichApiClient.clientData(clientData).getSyncApi();
final syncClient = di<ImmichApiClient>().getSyncApi();
final chunkSize = limit ?? kFullSyncChunkSize;
final updatedTill = updatedUtil ?? DateTime.now().toUtc();