Explorar o código

[mob] Fix person custom avatar rendering

Neeraj Gupta hai 1 ano
pai
achega
be06d45e3a

+ 13 - 0
mobile/lib/db/entities_db.dart

@@ -62,4 +62,17 @@ extension EntitiesDB on FilesDB {
       return LocalEntityData.fromJson(maps[i]);
       return LocalEntityData.fromJson(maps[i]);
     });
     });
   }
   }
+
+  Future<LocalEntityData?> getEntity(EntityType type, String id) async {
+    final db = await database;
+    final List<Map<String, dynamic>> maps = await db.query(
+      "entities",
+      where: "type = ? AND id = ?",
+      whereArgs: [type.typeToString(), id],
+    );
+    if (maps.isEmpty) {
+      return null;
+    }
+    return LocalEntityData.fromJson(maps.first);
+  }
 }
 }

+ 3 - 11
mobile/lib/face/db.dart

@@ -207,24 +207,16 @@ class FaceMLDataDB {
   Future<Face?> getCoverFaceForPerson({
   Future<Face?> getCoverFaceForPerson({
     required int recentFileID,
     required int recentFileID,
     String? personID,
     String? personID,
+    String? personAvatorFaceID,
     int? clusterID,
     int? clusterID,
   }) async {
   }) async {
     // read person from db
     // read person from db
     final db = await instance.database;
     final db = await instance.database;
     if (personID != null) {
     if (personID != null) {
-      final List<Map<String, dynamic>> maps = await db.rawQuery(
-        'SELECT * FROM $personTable where $idColumn = ?',
-        [personID],
-      );
-      if (maps.isEmpty) {
-        throw Exception("Person with id $personID not found");
-      }
-
-      final person = mapRowToPerson(maps.first);
       final List<int> fileId = [recentFileID];
       final List<int> fileId = [recentFileID];
       int? avatarFileId;
       int? avatarFileId;
-      if (person.data.avatarFaceId != null) {
-        avatarFileId = int.tryParse(person.data.avatarFaceId!.split('_')[0]);
+      if (personAvatorFaceID != null) {
+        avatarFileId = int.tryParse(personAvatorFaceID!.split('_')[0]);
         if (avatarFileId != null) {
         if (avatarFileId != null) {
           fileId.add(avatarFileId);
           fileId.add(avatarFileId);
         }
         }

+ 4 - 0
mobile/lib/services/entity_service.dart

@@ -50,6 +50,10 @@ class EntityService {
     return await _db.getEntities(type);
     return await _db.getEntities(type);
   }
   }
 
 
+  Future<LocalEntityData?> getEntity(EntityType type, String id) async {
+    return await _db.getEntity(type, id);
+  }
+
   Future<LocalEntityData> addOrUpdate(
   Future<LocalEntityData> addOrUpdate(
     EntityType type,
     EntityType type,
     String plainText, {
     String plainText, {

+ 9 - 0
mobile/lib/services/machine_learning/face_ml/person/person_service.dart

@@ -37,6 +37,15 @@ class PersonService {
         .toList();
         .toList();
   }
   }
 
 
+  Future<PersonEntity?> getPerson(String id) {
+    return entityService.getEntity(EntityType.person, id).then((e) {
+      if (e == null) {
+        return null;
+      }
+      return PersonEntity(e.id, PersonData.fromJson(json.decode(e.data)));
+    });
+  }
+
   Future<Map<String, PersonEntity>> getPersonsMap() async {
   Future<Map<String, PersonEntity>> getPersonsMap() async {
     final entities = await entityService.getEntities(EntityType.person);
     final entities = await entityService.getEntities(EntityType.person);
     final Map<String, PersonEntity> map = {};
     final Map<String, PersonEntity> map = {};

+ 11 - 0
mobile/lib/ui/viewer/search/result/person_face_widget.dart

@@ -6,7 +6,9 @@ import 'package:flutter/widgets.dart';
 import "package:photos/db/files_db.dart";
 import "package:photos/db/files_db.dart";
 import "package:photos/face/db.dart";
 import "package:photos/face/db.dart";
 import "package:photos/face/model/face.dart";
 import "package:photos/face/model/face.dart";
+import "package:photos/face/model/person.dart";
 import 'package:photos/models/file/file.dart';
 import 'package:photos/models/file/file.dart';
+import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
 import 'package:photos/ui/viewer/file/thumbnail_widget.dart';
 import 'package:photos/ui/viewer/file/thumbnail_widget.dart';
 import "package:photos/ui/viewer/people/cropped_face_image_view.dart";
 import "package:photos/ui/viewer/people/cropped_face_image_view.dart";
 import "package:photos/utils/face/face_box_crop.dart";
 import "package:photos/utils/face/face_box_crop.dart";
@@ -81,8 +83,17 @@ class PersonFaceWidget extends StatelessWidget {
   }
   }
 
 
   Future<Face?> _getFace() async {
   Future<Face?> _getFace() async {
+    String? personAvatarFaceID;
+    if (personId != null) {
+      PersonEntity? personEntity =
+          await PersonService.instance.getPerson(personId!);
+      if (personEntity != null) {
+        personAvatarFaceID = personEntity.data.avatarFaceId;
+      }
+    }
     return await FaceMLDataDB.instance.getCoverFaceForPerson(
     return await FaceMLDataDB.instance.getCoverFaceForPerson(
       recentFileID: file.uploadedFileID!,
       recentFileID: file.uploadedFileID!,
+      personAvatorFaceID: personAvatarFaceID,
       personID: personId,
       personID: personId,
       clusterID: clusterID,
       clusterID: clusterID,
     );
     );