From 729600917c569020e28e0d1a1b61c86864b49a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Tue, 12 Dec 2023 10:45:55 +0900 Subject: [PATCH] InternalUtils --- .../one/nem/lacerta/data/utils/UtilsImpl.java | 26 ++++++++++++++++++- .../nem/lacerta/data/utils/UtilsModule.java | 14 +++++++++- .../one/nem/lacerta/data/utils/UtilsRepo.java | 6 +++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/data/src/main/java/one/nem/lacerta/data/utils/UtilsImpl.java b/data/src/main/java/one/nem/lacerta/data/utils/UtilsImpl.java index e0605730..ec1591be 100644 --- a/data/src/main/java/one/nem/lacerta/data/utils/UtilsImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/utils/UtilsImpl.java @@ -1,4 +1,28 @@ package one.nem.lacerta.data.utils; -public class UtilsImpl { +import android.content.Context; + +import java.nio.file.Path; +import java.util.Objects; + +import javax.inject.Inject; + +import dagger.hilt.android.qualifiers.ApplicationContext; +import one.nem.lacerta.data.utils.UtilsRepo; +public class UtilsImpl implements UtilsRepo{ + + private final Context applicationContext; + + @Inject + public UtilsImpl(@ApplicationContext Context applicationContext) { + this.applicationContext = applicationContext; + } + + public Path getExternalFilesDirPath(String type) { + return Objects.requireNonNull(applicationContext.getExternalFilesDir(type)).toPath(); + } + + public Path getExternalFilesDirPath() { + return Objects.requireNonNull(applicationContext.getExternalFilesDir(null)).toPath(); + } } diff --git a/data/src/main/java/one/nem/lacerta/data/utils/UtilsModule.java b/data/src/main/java/one/nem/lacerta/data/utils/UtilsModule.java index 1ccc89d1..d03692e9 100644 --- a/data/src/main/java/one/nem/lacerta/data/utils/UtilsModule.java +++ b/data/src/main/java/one/nem/lacerta/data/utils/UtilsModule.java @@ -1,4 +1,16 @@ package one.nem.lacerta.data.utils; -public class UtilsModule { +import dagger.Binds; +import dagger.Module; +import dagger.hilt.InstallIn; +import one.nem.lacerta.data.utils.UtilsRepo; +import one.nem.lacerta.data.utils.UtilsImpl; +import dagger.hilt.components.SingletonComponent; + +@Module +@InstallIn(SingletonComponent.class) +abstract public class UtilsModule { + + @Binds + public abstract UtilsRepo bindUtils(UtilsImpl utilsImpl); } diff --git a/data/src/main/java/one/nem/lacerta/data/utils/UtilsRepo.java b/data/src/main/java/one/nem/lacerta/data/utils/UtilsRepo.java index 2a855990..1b148261 100644 --- a/data/src/main/java/one/nem/lacerta/data/utils/UtilsRepo.java +++ b/data/src/main/java/one/nem/lacerta/data/utils/UtilsRepo.java @@ -1,4 +1,10 @@ package one.nem.lacerta.data.utils; +import java.nio.file.Path; + public interface UtilsRepo { + + Path getExternalFilesDirPath(String type); + + Path getExternalFilesDirPath(); }