diff --git a/domain/photos/src/main/kotlin/photos/network/domain/photos/Module.kt b/domain/photos/src/main/kotlin/photos/network/domain/photos/Module.kt index 171f7cb5..1db59092 100644 --- a/domain/photos/src/main/kotlin/photos/network/domain/photos/Module.kt +++ b/domain/photos/src/main/kotlin/photos/network/domain/photos/Module.kt @@ -31,6 +31,7 @@ val domainPhotosModule = module { factory { GetFacesUseCase( + application = get(), photoRepository = get(), ) } diff --git a/domain/photos/src/main/kotlin/photos/network/domain/photos/usecase/GetFacesUseCase.kt b/domain/photos/src/main/kotlin/photos/network/domain/photos/usecase/GetFacesUseCase.kt index 671a674b..cc091fb4 100644 --- a/domain/photos/src/main/kotlin/photos/network/domain/photos/usecase/GetFacesUseCase.kt +++ b/domain/photos/src/main/kotlin/photos/network/domain/photos/usecase/GetFacesUseCase.kt @@ -15,15 +15,20 @@ */ package photos.network.domain.photos.usecase +import android.app.Application +import android.graphics.Bitmap import android.net.Uri +import android.provider.MediaStore import kotlinx.coroutines.flow.Flow import photos.network.repository.photos.PhotoRepository import photos.network.repository.photos.model.Box class GetFacesUseCase( + private val application: Application, private val photoRepository: PhotoRepository, ) { operator fun invoke(photoUri: Uri): Flow> { - return photoRepository.getFaces(photoUri = photoUri) + val bitmap: Bitmap = MediaStore.Images.Media.getBitmap(application.contentResolver, photoUri) + return photoRepository.getFaces(bitmap = bitmap) } } diff --git a/fastlane/metadata/android/en-US/changelogs/102.txt b/fastlane/metadata/android/en-US/changelogs/102.txt new file mode 100644 index 00000000..e69de29b diff --git a/repository/photos/src/main/kotlin/photos/network/repository/photos/Module.kt b/repository/photos/src/main/kotlin/photos/network/repository/photos/Module.kt index 71e5383b..652f86d3 100644 --- a/repository/photos/src/main/kotlin/photos/network/repository/photos/Module.kt +++ b/repository/photos/src/main/kotlin/photos/network/repository/photos/Module.kt @@ -53,7 +53,6 @@ val repositoryPhotosModule = module { single { PhotoRepositoryImpl( - application = get(), photoApi = get(), photoDao = get(), workManager = get(), diff --git a/repository/photos/src/main/kotlin/photos/network/repository/photos/PhotoRepository.kt b/repository/photos/src/main/kotlin/photos/network/repository/photos/PhotoRepository.kt index 76ce79d8..e736361b 100644 --- a/repository/photos/src/main/kotlin/photos/network/repository/photos/PhotoRepository.kt +++ b/repository/photos/src/main/kotlin/photos/network/repository/photos/PhotoRepository.kt @@ -15,7 +15,7 @@ */ package photos.network.repository.photos -import android.net.Uri +import android.graphics.Bitmap import kotlinx.coroutines.flow.Flow import photos.network.repository.photos.model.Box import photos.network.repository.photos.worker.SyncStatus @@ -26,7 +26,7 @@ interface PhotoRepository { fun getPhotos(): Flow> fun getPhoto(identifier: String): Flow - fun getFaces(photoUri: Uri): Flow> + fun getFaces(bitmap: Bitmap): Flow> suspend fun addPhoto(photo: Photo) } diff --git a/repository/photos/src/main/kotlin/photos/network/repository/photos/PhotoRepositoryImpl.kt b/repository/photos/src/main/kotlin/photos/network/repository/photos/PhotoRepositoryImpl.kt index 297b1f54..6957833d 100644 --- a/repository/photos/src/main/kotlin/photos/network/repository/photos/PhotoRepositoryImpl.kt +++ b/repository/photos/src/main/kotlin/photos/network/repository/photos/PhotoRepositoryImpl.kt @@ -15,10 +15,8 @@ */ package photos.network.repository.photos -import android.app.Application import android.content.res.AssetManager import android.graphics.Bitmap -import android.net.Uri import androidx.work.Constraints import androidx.work.ExistingPeriodicWorkPolicy import androidx.work.NetworkType @@ -39,7 +37,6 @@ import java.time.Instant import java.util.concurrent.TimeUnit class PhotoRepositoryImpl( - private val application: Application, private val mediaStore: MediaStore, private val photoApi: PhotoApi, private val photoDao: PhotoDao, @@ -115,12 +112,10 @@ class PhotoRepositoryImpl( photoDao.insertAll(photos = arrayOf(photo.toDatabasePhoto())) } - override fun getFaces(photoUri: Uri): Flow> { + override fun getFaces(bitmap: Bitmap): Flow> { return flow { emit(emptyList()) - val bitmap: Bitmap = android.provider.MediaStore.Images.Media.getBitmap(application.contentResolver, photoUri) - val faces = MTCNN(assetManager).detectFaces( bitmap, 40, diff --git a/repository/photos/src/test/kotlin/photos/network/repository/photos/PhotoRepositoryTest.kt b/repository/photos/src/test/kotlin/photos/network/repository/photos/PhotoRepositoryTest.kt index 0ddfaf22..3126df99 100644 --- a/repository/photos/src/test/kotlin/photos/network/repository/photos/PhotoRepositoryTest.kt +++ b/repository/photos/src/test/kotlin/photos/network/repository/photos/PhotoRepositoryTest.kt @@ -15,7 +15,7 @@ */ package photos.network.repository.photos -import android.content.Context +import android.content.res.AssetManager import androidx.work.WorkManager import com.google.common.truth.Truth import io.mockk.every @@ -33,7 +33,7 @@ import photos.network.system.mediastore.MediaStore */ class PhotoRepositoryTest { - private val applicationContext = mockk() + private val assetManager = mockk() private val photoApi = mockk() private val photoDao = mockk() private val mediaStore = mockk() @@ -45,6 +45,7 @@ class PhotoRepositoryTest { photoDao = photoDao, workManager = workManager, mediaStore = mediaStore, + assetManager = assetManager, ) } diff --git a/ui/photos/src/test/kotlin/photos/network/ui/photos/photos/PhotosViewModelTests.kt b/ui/photos/src/test/kotlin/photos/network/ui/photos/photos/PhotosViewModelTests.kt index 9ce91381..7d17f1ae 100644 --- a/ui/photos/src/test/kotlin/photos/network/ui/photos/photos/PhotosViewModelTests.kt +++ b/ui/photos/src/test/kotlin/photos/network/ui/photos/photos/PhotosViewModelTests.kt @@ -32,6 +32,7 @@ import kotlinx.coroutines.test.setMain import org.junit.After import org.junit.Before import org.junit.Test +import photos.network.domain.photos.usecase.GetFacesUseCase import photos.network.domain.photos.usecase.GetPhotosUseCase import photos.network.domain.photos.usecase.StartPhotosSyncUseCase import photos.network.domain.settings.usecase.GetSettingsUseCase @@ -45,12 +46,14 @@ class PhotosViewModelTests { private val togglePrivacyUseCase = mockk() private val getPhotosUseCase = mockk() private val startPhotosSyncUseCase = mockk() + private val getFacesUseCase = mockk() private val viewmodel by lazy { photos.network.ui.photos.PhotosViewModel( getSettingsUseCase = getSettingsUseCase, togglePrivacyStateUseCase = togglePrivacyUseCase, getPhotosUseCase = getPhotosUseCase, startPhotosSyncUseCase = startPhotosSyncUseCase, + getFacesUseCase = getFacesUseCase ) } private val photo1 = Photo(