minor cleanup

This commit is contained in:
mertalev 2025-08-01 13:32:56 -04:00
parent 11dc8ffb17
commit a934af6971
No known key found for this signature in database
GPG Key ID: DF6ABC77AAD98C95
10 changed files with 27 additions and 44 deletions

View File

@ -59,7 +59,7 @@ private open class ThumbnailsPigeonCodec : StandardMessageCodec() {
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */ /** Generated interface from Pigeon that represents a handler of messages from Flutter. */
interface ThumbnailApi { interface ThumbnailApi {
fun setThumbnailToBuffer(assetId: String, width: Long, height: Long, callback: (Result<Map<String, Long>>) -> Unit) fun getThumbnailBuffer(assetId: String, width: Long, height: Long, callback: (Result<Map<String, Long>>) -> Unit)
companion object { companion object {
/** The codec used by ThumbnailApi. */ /** The codec used by ThumbnailApi. */
@ -71,14 +71,14 @@ interface ThumbnailApi {
fun setUp(binaryMessenger: BinaryMessenger, api: ThumbnailApi?, messageChannelSuffix: String = "") { fun setUp(binaryMessenger: BinaryMessenger, api: ThumbnailApi?, messageChannelSuffix: String = "") {
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
run { run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.immich_mobile.ThumbnailApi.setThumbnailToBuffer$separatedMessageChannelSuffix", codec) val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.immich_mobile.ThumbnailApi.getThumbnailBuffer$separatedMessageChannelSuffix", codec)
if (api != null) { if (api != null) {
channel.setMessageHandler { message, reply -> channel.setMessageHandler { message, reply ->
val args = message as List<Any?> val args = message as List<Any?>
val assetIdArg = args[0] as String val assetIdArg = args[0] as String
val widthArg = args[1] as Long val widthArg = args[1] as Long
val heightArg = args[2] as Long val heightArg = args[2] as Long
api.setThumbnailToBuffer(assetIdArg, widthArg, heightArg) { result: Result<Map<String, Long>> -> api.getThumbnailBuffer(assetIdArg, widthArg, heightArg) { result: Result<Map<String, Long>> ->
val error = result.exceptionOrNull() val error = result.exceptionOrNull()
if (error != null) { if (error != null) {
reply.reply(ThumbnailsPigeonUtils.wrapError(error)) reply.reply(ThumbnailsPigeonUtils.wrapError(error))

View File

@ -49,19 +49,19 @@ class ThumbnailsImpl(context: Context) : ThumbnailApi {
external fun wrapAsBuffer(address: Long, capacity: Int): ByteBuffer external fun wrapAsBuffer(address: Long, capacity: Int): ByteBuffer
} }
override fun setThumbnailToBuffer( override fun getThumbnailBuffer(
assetId: String, width: Long, height: Long, callback: (Result<Map<String, Long>>) -> Unit assetId: String, width: Long, height: Long, callback: (Result<Map<String, Long>>) -> Unit
) { ) {
threadPool.execute { threadPool.execute {
try { try {
setThumbnailToBufferInternal(assetId, width, height, callback) getThumbnailBufferInternal(assetId, width, height, callback)
} catch (e: Exception) { } catch (e: Exception) {
callback(Result.failure(e)) callback(Result.failure(e))
} }
} }
} }
private fun setThumbnailToBufferInternal( private fun getThumbnailBufferInternal(
assetId: String, width: Long, height: Long, callback: (Result<Map<String, Long>>) -> Unit assetId: String, width: Long, height: Long, callback: (Result<Map<String, Long>>) -> Unit
) { ) {
val targetWidth = width.toInt() val targetWidth = width.toInt()

View File

@ -70,7 +70,7 @@ class ThumbnailsPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable {
/// Generated protocol from Pigeon that represents a handler of messages from Flutter. /// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol ThumbnailApi { protocol ThumbnailApi {
func setThumbnailToBuffer(assetId: String, width: Int64, height: Int64, completion: @escaping (Result<[String: Int64], Error>) -> Void) func getThumbnailBuffer(assetId: String, width: Int64, height: Int64, completion: @escaping (Result<[String: Int64], Error>) -> Void)
} }
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
@ -79,14 +79,14 @@ class ThumbnailApiSetup {
/// Sets up an instance of `ThumbnailApi` to handle messages through the `binaryMessenger`. /// Sets up an instance of `ThumbnailApi` to handle messages through the `binaryMessenger`.
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: ThumbnailApi?, messageChannelSuffix: String = "") { static func setUp(binaryMessenger: FlutterBinaryMessenger, api: ThumbnailApi?, messageChannelSuffix: String = "") {
let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
let setThumbnailToBufferChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.immich_mobile.ThumbnailApi.setThumbnailToBuffer\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) let getThumbnailBufferChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.immich_mobile.ThumbnailApi.getThumbnailBuffer\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api { if let api = api {
setThumbnailToBufferChannel.setMessageHandler { message, reply in getThumbnailBufferChannel.setMessageHandler { message, reply in
let args = message as! [Any?] let args = message as! [Any?]
let assetIdArg = args[0] as! String let assetIdArg = args[0] as! String
let widthArg = args[1] as! Int64 let widthArg = args[1] as! Int64
let heightArg = args[2] as! Int64 let heightArg = args[2] as! Int64
api.setThumbnailToBuffer(assetId: assetIdArg, width: widthArg, height: heightArg) { result in api.getThumbnailBuffer(assetId: assetIdArg, width: widthArg, height: heightArg) { result in
switch result { switch result {
case .success(let res): case .success(let res):
reply(wrapResult(res)) reply(wrapResult(res))
@ -96,7 +96,7 @@ class ThumbnailApiSetup {
} }
} }
} else { } else {
setThumbnailToBufferChannel.setMessageHandler(nil) getThumbnailBufferChannel.setMessageHandler(nil)
} }
} }
} }

View File

@ -23,7 +23,7 @@ class ThumbnailApiImpl: ThumbnailApi {
private static let rgbColorSpace = CGColorSpaceCreateDeviceRGB() private static let rgbColorSpace = CGColorSpaceCreateDeviceRGB()
private static let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue).rawValue private static let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue).rawValue
func setThumbnailToBuffer(assetId: String, width: Int64, height: Int64, completion: @escaping (Result<[String: Int64], any Error>) -> Void) { func getThumbnailBuffer(assetId: String, width: Int64, height: Int64, completion: @escaping (Result<[String: Int64], any Error>) -> Void) {
Self.processingQueue.async { Self.processingQueue.async {
guard let asset = PHAsset.fetchAssets(withLocalIdentifiers: [assetId], options: Self.fetchOptions).firstObject guard let asset = PHAsset.fetchAssets(withLocalIdentifiers: [assetId], options: Self.fetchOptions).firstObject
else { completion(.failure(PigeonError(code: "", message: "Could not get asset data for \(assetId)", details: nil))); return } else { completion(.failure(PigeonError(code: "", message: "Could not get asset data for \(assetId)", details: nil))); return }

View File

@ -11,7 +11,7 @@ class AssetMediaRepository {
const AssetMediaRepository(); const AssetMediaRepository();
Future<ui.Codec> getLocalThumbnail(String localId, ui.Size size) async { Future<ui.Codec> getLocalThumbnail(String localId, ui.Size size) async {
final info = await thumbnailApi.setThumbnailToBuffer( final info = await thumbnailApi.getThumbnailBuffer(
localId, localId,
width: size.width.toInt(), width: size.width.toInt(),
height: size.height.toInt(), height: size.height.toInt(),

View File

@ -40,34 +40,25 @@ class ThumbnailApi {
/// Constructor for [ThumbnailApi]. The [binaryMessenger] named argument is /// Constructor for [ThumbnailApi]. The [binaryMessenger] named argument is
/// available for dependency injection. If it is left null, the default /// available for dependency injection. If it is left null, the default
/// BinaryMessenger will be used which routes to the host platform. /// BinaryMessenger will be used which routes to the host platform.
ThumbnailApi( ThumbnailApi({BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''})
{BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) : pigeonVar_binaryMessenger = binaryMessenger,
: pigeonVar_binaryMessenger = binaryMessenger, pigeonVar_messageChannelSuffix = messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : '';
pigeonVar_messageChannelSuffix =
messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : '';
final BinaryMessenger? pigeonVar_binaryMessenger; final BinaryMessenger? pigeonVar_binaryMessenger;
static const MessageCodec<Object?> pigeonChannelCodec = _PigeonCodec(); static const MessageCodec<Object?> pigeonChannelCodec = _PigeonCodec();
final String pigeonVar_messageChannelSuffix; final String pigeonVar_messageChannelSuffix;
Future<Map<String, int>> setThumbnailToBuffer( Future<Map<String, int>> getThumbnailBuffer(String assetId, {required int width, required int height}) async {
String assetId, {
required int width,
required int height,
}) async {
final String pigeonVar_channelName = final String pigeonVar_channelName =
'dev.flutter.pigeon.immich_mobile.ThumbnailApi.setThumbnailToBuffer$pigeonVar_messageChannelSuffix'; 'dev.flutter.pigeon.immich_mobile.ThumbnailApi.getThumbnailBuffer$pigeonVar_messageChannelSuffix';
final BasicMessageChannel<Object?> pigeonVar_channel = final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
BasicMessageChannel<Object?>(
pigeonVar_channelName, pigeonVar_channelName,
pigeonChannelCodec, pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger, binaryMessenger: pigeonVar_binaryMessenger,
); );
final Future<Object?> pigeonVar_sendFuture = final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[assetId, width, height]);
pigeonVar_channel.send(<Object?>[assetId, width, height]); final List<Object?>? pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
final List<Object?>? pigeonVar_replyList =
await pigeonVar_sendFuture as List<Object?>?;
if (pigeonVar_replyList == null) { if (pigeonVar_replyList == null) {
throw _createConnectionError(pigeonVar_channelName); throw _createConnectionError(pigeonVar_channelName);
} else if (pigeonVar_replyList.length > 1) { } else if (pigeonVar_replyList.length > 1) {
@ -82,8 +73,7 @@ class ThumbnailApi {
message: 'Host platform returned null value for non-null return value.', message: 'Host platform returned null value for non-null return value.',
); );
} else { } else {
return (pigeonVar_replyList[0] as Map<Object?, Object?>?)! return (pigeonVar_replyList[0] as Map<Object?, Object?>?)!.cast<String, int>();
.cast<String, int>();
} }
} }
} }

View File

@ -40,11 +40,7 @@ ImageProvider getThumbnailImageProvider({
if (_shouldUseLocalAsset(asset!)) { if (_shouldUseLocalAsset(asset!)) {
final id = asset is LocalAsset ? asset.id : (asset as RemoteAsset).localId!; final id = asset is LocalAsset ? asset.id : (asset as RemoteAsset).localId!;
return LocalThumbProvider( return LocalThumbProvider(id: id, size: size);
id: id,
// updatedAt: asset.updatedAt, TODO
size: size,
);
} }
final String assetId; final String assetId;

View File

@ -10,9 +10,8 @@ class LocalThumbProvider extends ImageProvider<LocalThumbProvider> {
final String id; final String id;
final Size size; final Size size;
final DateTime? updatedAt;
const LocalThumbProvider({required this.id, required this.size, this.updatedAt}); const LocalThumbProvider({required this.id, required this.size});
@override @override
Future<LocalThumbProvider> obtainKey(ImageConfiguration configuration) { Future<LocalThumbProvider> obtainKey(ImageConfiguration configuration) {
@ -26,7 +25,6 @@ class LocalThumbProvider extends ImageProvider<LocalThumbProvider> {
informationCollector: () => <DiagnosticsNode>[ informationCollector: () => <DiagnosticsNode>[
DiagnosticsProperty<ImageProvider>('Image provider', this), DiagnosticsProperty<ImageProvider>('Image provider', this),
DiagnosticsProperty<String>('Id', key.id), DiagnosticsProperty<String>('Id', key.id),
DiagnosticsProperty<DateTime>('Updated at', key.updatedAt),
DiagnosticsProperty<Size>('Size', key.size), DiagnosticsProperty<Size>('Size', key.size),
], ],
); );
@ -41,13 +39,13 @@ class LocalThumbProvider extends ImageProvider<LocalThumbProvider> {
bool operator ==(Object other) { bool operator ==(Object other) {
if (identical(this, other)) return true; if (identical(this, other)) return true;
if (other is LocalThumbProvider) { if (other is LocalThumbProvider) {
return id == other.id && size == other.size && updatedAt == other.updatedAt; return id == other.id && size == other.size;
} }
return false; return false;
} }
@override @override
int get hashCode => id.hashCode ^ updatedAt.hashCode; int get hashCode => id.hashCode ^ size.hashCode;
} }
class LocalFullImageProvider extends ImageProvider<LocalFullImageProvider> { class LocalFullImageProvider extends ImageProvider<LocalFullImageProvider> {

View File

@ -91,7 +91,6 @@ class _SliverTimeline extends ConsumerStatefulWidget {
class _SliverTimelineState extends ConsumerState<_SliverTimeline> { class _SliverTimelineState extends ConsumerState<_SliverTimeline> {
final _scrollController = ScrollController(); final _scrollController = ScrollController();
StreamSubscription? _eventSubscription; StreamSubscription? _eventSubscription;
// late final KeepAliveLink asyncSegmentsLink;
// Drag selection state // Drag selection state
bool _dragging = false; bool _dragging = false;

View File

@ -15,7 +15,7 @@ import 'package:pigeon/pigeon.dart';
@HostApi() @HostApi()
abstract class ThumbnailApi { abstract class ThumbnailApi {
@async @async
Map<String, int> setThumbnailToBuffer( Map<String, int> getThumbnailBuffer(
String assetId, { String assetId, {
required int width, required int width,
required int height, required int height,