From 89390ead0e043a987c386542b38d180f9a8b3036 Mon Sep 17 00:00:00 2001 From: sgsk88 Date: Sun, 12 Nov 2023 01:11:06 +0900 Subject: [PATCH 1/9] =?UTF-8?q?[feature/univ=5Fsave]=20DataStore=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20?= =?UTF-8?q?=EC=98=A8=EB=B3=B4=EB=94=A9=20=ED=85=8D=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle/libs.versions.toml | 4 ++++ presentation/src/main/res/values/strings.xml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e4cc630b..063d62aa 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -22,6 +22,8 @@ lottie = "6.1.0" compose-navigation = "2.7.4" +data-store = "1.0.0" + [libraries] agp = { module = "com.android.tools.build:gradle", version.ref = "agp" } coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil-compose" } @@ -71,6 +73,8 @@ compose-lottie = { module = "com.airbnb.android:lottie-compose", version.ref = " #Compose-Navigation compose-navigation = { module = "androidx.navigation:navigation-compose", version.ref = "compose-navigation" } +#data-store +data-store = { module = "androidx.datastore:datastore-preferences", version.ref = "data-store" } [plugins] androidApplication = { id = "com.android.application", version.ref = "agp" } diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml index f3922d54..663a2007 100644 --- a/presentation/src/main/res/values/strings.xml +++ b/presentation/src/main/res/values/strings.xml @@ -98,7 +98,7 @@ 빠른 시일 내에 이용하실 수 있도록\n에브리밀이 준비하고 있어요. - 다음 + 시작하기 우리 오늘 뭐먹지? 학식에서\n학교 주변 맛집까지 에브리밀에서\n간편하게 From 4b9815291a1b8637d6f10ad730ed3e2fb5c249f1 Mon Sep 17 00:00:00 2001 From: sgsk88 Date: Sun, 12 Nov 2023 02:27:19 +0900 Subject: [PATCH 2/9] =?UTF-8?q?[feature/univ=5Fsave]=20Response=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=B3=80=EA=B2=BD=20(#85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasource/onboarding/OnboardingDataSource.kt | 4 ++-- .../data/datasource/onboarding/OnboardingDataSourceImpl.kt | 4 ++-- .../{GetUniversityData.kt => GetUniversityResponse.kt} | 4 ++-- .../com/everymeal/data/service/onboarding/OnboardingApi.kt | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) rename data/src/main/java/com/everymeal/data/model/onboarding/{GetUniversityData.kt => GetUniversityResponse.kt} (86%) diff --git a/data/src/main/java/com/everymeal/data/datasource/onboarding/OnboardingDataSource.kt b/data/src/main/java/com/everymeal/data/datasource/onboarding/OnboardingDataSource.kt index f4978af4..976de013 100644 --- a/data/src/main/java/com/everymeal/data/datasource/onboarding/OnboardingDataSource.kt +++ b/data/src/main/java/com/everymeal/data/datasource/onboarding/OnboardingDataSource.kt @@ -1,7 +1,7 @@ package com.everymeal.data.datasource.onboarding -import com.everymeal.data.model.onboarding.UniversityData +import com.everymeal.data.model.onboarding.UniversityResponse interface OnboardingDataSource { - suspend fun getUniversity(): Result> + suspend fun getUniversity(): Result> } \ No newline at end of file diff --git a/data/src/main/java/com/everymeal/data/datasource/onboarding/OnboardingDataSourceImpl.kt b/data/src/main/java/com/everymeal/data/datasource/onboarding/OnboardingDataSourceImpl.kt index 2f447e78..b4f1b700 100644 --- a/data/src/main/java/com/everymeal/data/datasource/onboarding/OnboardingDataSourceImpl.kt +++ b/data/src/main/java/com/everymeal/data/datasource/onboarding/OnboardingDataSourceImpl.kt @@ -1,6 +1,6 @@ package com.everymeal.data.datasource.onboarding -import com.everymeal.data.model.onboarding.UniversityData +import com.everymeal.data.model.onboarding.UniversityResponse import com.everymeal.data.model.unwrapData import com.everymeal.data.service.onboarding.OnboardingApi import javax.inject.Inject @@ -9,7 +9,7 @@ class OnboardingDataSourceImpl @Inject constructor( private val onboardingApi: OnboardingApi ) : OnboardingDataSource { - override suspend fun getUniversity(): Result> { + override suspend fun getUniversity(): Result> { return runCatching { onboardingApi.getUniversity() }.unwrapData() } } \ No newline at end of file diff --git a/data/src/main/java/com/everymeal/data/model/onboarding/GetUniversityData.kt b/data/src/main/java/com/everymeal/data/model/onboarding/GetUniversityResponse.kt similarity index 86% rename from data/src/main/java/com/everymeal/data/model/onboarding/GetUniversityData.kt rename to data/src/main/java/com/everymeal/data/model/onboarding/GetUniversityResponse.kt index 86e6779e..7a907087 100644 --- a/data/src/main/java/com/everymeal/data/model/onboarding/GetUniversityData.kt +++ b/data/src/main/java/com/everymeal/data/model/onboarding/GetUniversityResponse.kt @@ -4,14 +4,14 @@ import com.everymeal.domain.model.onboarding.GetUniversityEntity import kotlinx.serialization.Serializable @Serializable -data class UniversityData( +data class UniversityResponse( val idx: Int, val universityName: String, val campusName: String, val universityShortName: String ) -fun List.toUniversityEntity(): GetUniversityEntity { +fun List.toUniversityEntity(): GetUniversityEntity { val universityDataList = this.map { result -> GetUniversityEntity.UniversityData( idx = result.idx, diff --git a/data/src/main/java/com/everymeal/data/service/onboarding/OnboardingApi.kt b/data/src/main/java/com/everymeal/data/service/onboarding/OnboardingApi.kt index e76d1a0a..794d1762 100644 --- a/data/src/main/java/com/everymeal/data/service/onboarding/OnboardingApi.kt +++ b/data/src/main/java/com/everymeal/data/service/onboarding/OnboardingApi.kt @@ -1,11 +1,11 @@ package com.everymeal.data.service.onboarding import com.everymeal.data.model.BaseResponse -import com.everymeal.data.model.onboarding.UniversityData +import com.everymeal.data.model.onboarding.UniversityResponse import retrofit2.http.GET interface OnboardingApi { @GET("/api/v1/universities") - suspend fun getUniversity(): BaseResponse> + suspend fun getUniversity(): BaseResponse> } \ No newline at end of file From 19ef28a2361cc8f1a016b081a7bc86188ed24dfe Mon Sep 17 00:00:00 2001 From: sgsk88 Date: Sun, 12 Nov 2023 02:30:13 +0900 Subject: [PATCH 3/9] =?UTF-8?q?[feature/univ=5Fsave]=20DataStore=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80=20(#85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 3 +++ .../everymeal_android/di/NetworkModule.kt | 14 ++++++++++++++ .../everymeal_android/di/RepositoryModule.kt | 16 ++++++++++++++++ data/build.gradle.kts | 3 +++ 4 files changed, 36 insertions(+) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4f4cd357..4f52ec7a 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -93,4 +93,7 @@ dependencies { // Serialization implementation(libs.serialization) implementation(libs.kotlin.serilization) + + //DataStore + implementation(libs.data.store) } diff --git a/app/src/main/java/com/everymeal/everymeal_android/di/NetworkModule.kt b/app/src/main/java/com/everymeal/everymeal_android/di/NetworkModule.kt index 207c5046..54149361 100644 --- a/app/src/main/java/com/everymeal/everymeal_android/di/NetworkModule.kt +++ b/app/src/main/java/com/everymeal/everymeal_android/di/NetworkModule.kt @@ -1,17 +1,23 @@ package com.everymeal.everymeal_android.di +import android.content.Context +import androidx.datastore.core.DataStore +import androidx.datastore.preferences.core.PreferenceDataStoreFactory +import androidx.datastore.preferences.preferencesDataStoreFile import com.everymeal.data.service.onboarding.OnboardingApi import com.everymeal.everymeal_android.BuildConfig import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory import dagger.Module import dagger.Provides import dagger.hilt.InstallIn +import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent import kotlinx.serialization.json.Json import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient import retrofit2.Retrofit import java.util.concurrent.TimeUnit +import java.util.prefs.Preferences import javax.inject.Singleton @Module @@ -21,6 +27,7 @@ object NetworkModule { private val json = Json { ignoreUnknownKeys = true } private const val BASE_URL = BuildConfig.BASE_URL + private const val DATASTORE_NAME = "everymeal_datastore" @Provides @Singleton @@ -41,6 +48,13 @@ object NetworkModule { .build() } + @Singleton + @Provides + fun providePreferencesDataStore(@ApplicationContext context: Context): DataStore = + PreferenceDataStoreFactory.create( + produceFile = { context.preferencesDataStoreFile(DATASTORE_NAME) } + ) + @Provides @Singleton fun provideOnboardingApi(retrofit: Retrofit): OnboardingApi { diff --git a/app/src/main/java/com/everymeal/everymeal_android/di/RepositoryModule.kt b/app/src/main/java/com/everymeal/everymeal_android/di/RepositoryModule.kt index da5bacce..80a87af4 100644 --- a/app/src/main/java/com/everymeal/everymeal_android/di/RepositoryModule.kt +++ b/app/src/main/java/com/everymeal/everymeal_android/di/RepositoryModule.kt @@ -1,8 +1,12 @@ package com.everymeal.everymeal_android.di +import com.everymeal.data.datasource.local.LocalDataSource +import com.everymeal.data.datasource.local.LocalDataSourceImpl import com.everymeal.data.datasource.onboarding.OnboardingDataSource import com.everymeal.data.datasource.onboarding.OnboardingDataSourceImpl +import com.everymeal.data.repository.local.LocalRepositoryImpl import com.everymeal.data.repository.onboarding.OnboardingRepositoryImpl +import com.everymeal.domain.repository.local.LocalRepository import com.everymeal.domain.repository.onboarding.OnboardingRepository import dagger.Binds import dagger.Module @@ -25,4 +29,16 @@ abstract class RepositoryModule { abstract fun bindOnboardingDataSource( onboardingDataSourceImpl: OnboardingDataSourceImpl ): OnboardingDataSource + + @Singleton + @Binds + abstract fun bindLocalRepository( + localRepositoryImpl: LocalRepositoryImpl + ): LocalRepository + + @Singleton + @Binds + abstract fun bindLocalDataSource( + localDataSourceImpl: LocalDataSourceImpl + ): LocalDataSource } \ No newline at end of file diff --git a/data/build.gradle.kts b/data/build.gradle.kts index d4c5b0ba..437b388b 100644 --- a/data/build.gradle.kts +++ b/data/build.gradle.kts @@ -41,4 +41,7 @@ dependencies { // Serialization implementation(libs.serialization) implementation(libs.kotlin.serilization) + + //DataStore + implementation(libs.data.store) } \ No newline at end of file From ffaeb273a7f988adcc31b1b043e6dbe5a4d88f17 Mon Sep 17 00:00:00 2001 From: sgsk88 Date: Sun, 12 Nov 2023 02:38:50 +0900 Subject: [PATCH 4/9] =?UTF-8?q?[feature/univ=5Fsave]=20DataStore=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=20=EB=A1=9C=EC=A7=81=20data,=20domain=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20(#85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasource/local/LocalDataSource.kt | 5 ++++ .../datasource/local/LocalDataSourceImpl.kt | 23 +++++++++++++++++++ .../repository/local/LocalRepositoryImpl.kt | 14 +++++++++++ .../repository/local/LocalRepository.kt | 5 ++++ .../usecase/local/SaveUniversityUseCase.kt | 16 +++++++++++++ .../onboarding/GetUniversityUseCase.kt | 5 +++- 6 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 data/src/main/java/com/everymeal/data/datasource/local/LocalDataSource.kt create mode 100644 data/src/main/java/com/everymeal/data/datasource/local/LocalDataSourceImpl.kt create mode 100644 data/src/main/java/com/everymeal/data/repository/local/LocalRepositoryImpl.kt create mode 100644 domain/src/main/java/com/everymeal/domain/repository/local/LocalRepository.kt create mode 100644 domain/src/main/java/com/everymeal/domain/usecase/local/SaveUniversityUseCase.kt diff --git a/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSource.kt b/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSource.kt new file mode 100644 index 00000000..2ee3db76 --- /dev/null +++ b/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSource.kt @@ -0,0 +1,5 @@ +package com.everymeal.data.datasource.local + +interface LocalDataSource { + suspend fun saveUniversity(index : Int, univName : String) +} \ No newline at end of file diff --git a/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSourceImpl.kt b/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSourceImpl.kt new file mode 100644 index 00000000..b94564c8 --- /dev/null +++ b/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSourceImpl.kt @@ -0,0 +1,23 @@ +package com.everymeal.data.datasource.local + +import androidx.datastore.core.DataStore +import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.edit +import androidx.datastore.preferences.core.stringPreferencesKey +import javax.inject.Inject + +object DataStoreKey { + val UNIVERSITY_INDEX = stringPreferencesKey("univ_index") + val UNIVERSITY_NAME = stringPreferencesKey("univ_name") +} + +class LocalDataSourceImpl @Inject constructor( + private val dataStore: DataStore +) : LocalDataSource { + override suspend fun saveUniversity(index: Int, univName: String) { + dataStore.edit { + it[DataStoreKey.UNIVERSITY_INDEX] = index.toString() + it[DataStoreKey.UNIVERSITY_NAME] = univName + } + } +} \ No newline at end of file diff --git a/data/src/main/java/com/everymeal/data/repository/local/LocalRepositoryImpl.kt b/data/src/main/java/com/everymeal/data/repository/local/LocalRepositoryImpl.kt new file mode 100644 index 00000000..f6ee1fb7 --- /dev/null +++ b/data/src/main/java/com/everymeal/data/repository/local/LocalRepositoryImpl.kt @@ -0,0 +1,14 @@ +package com.everymeal.data.repository.local + +import com.everymeal.data.datasource.local.LocalDataSource +import com.everymeal.domain.repository.local.LocalRepository +import javax.inject.Inject + +class LocalRepositoryImpl @Inject constructor( + private val localDataSource: LocalDataSource +) : LocalRepository { + + override suspend fun saveUniversity(index: Int, univName: String) { + localDataSource.saveUniversity(index, univName) + } +} \ No newline at end of file diff --git a/domain/src/main/java/com/everymeal/domain/repository/local/LocalRepository.kt b/domain/src/main/java/com/everymeal/domain/repository/local/LocalRepository.kt new file mode 100644 index 00000000..1222fd97 --- /dev/null +++ b/domain/src/main/java/com/everymeal/domain/repository/local/LocalRepository.kt @@ -0,0 +1,5 @@ +package com.everymeal.domain.repository.local + +interface LocalRepository { + suspend fun saveUniversity(index : Int, univName : String) +} \ No newline at end of file diff --git a/domain/src/main/java/com/everymeal/domain/usecase/local/SaveUniversityUseCase.kt b/domain/src/main/java/com/everymeal/domain/usecase/local/SaveUniversityUseCase.kt new file mode 100644 index 00000000..f9addb10 --- /dev/null +++ b/domain/src/main/java/com/everymeal/domain/usecase/local/SaveUniversityUseCase.kt @@ -0,0 +1,16 @@ +package com.everymeal.domain.usecase.local + +import com.everymeal.domain.repository.local.LocalRepository +import com.everymeal.domain.repository.onboarding.OnboardingRepository +import javax.inject.Inject + +class SaveUniversityUseCase @Inject constructor( + private val localRepository: LocalRepository +) { + suspend operator fun invoke( + index : Int, + univName : String + ) { + localRepository.saveUniversity(index, univName) + } +} \ No newline at end of file diff --git a/domain/src/main/java/com/everymeal/domain/usecase/onboarding/GetUniversityUseCase.kt b/domain/src/main/java/com/everymeal/domain/usecase/onboarding/GetUniversityUseCase.kt index 66bed9f5..73c91b88 100644 --- a/domain/src/main/java/com/everymeal/domain/usecase/onboarding/GetUniversityUseCase.kt +++ b/domain/src/main/java/com/everymeal/domain/usecase/onboarding/GetUniversityUseCase.kt @@ -1,10 +1,13 @@ package com.everymeal.domain.usecase.onboarding +import com.everymeal.domain.model.onboarding.GetUniversityEntity import com.everymeal.domain.repository.onboarding.OnboardingRepository import javax.inject.Inject class GetUniversityUseCase @Inject constructor( private val onboardingRepository: OnboardingRepository ) { - suspend operator fun invoke() = onboardingRepository.getUniversity() + suspend operator fun invoke() :Result { + return onboardingRepository.getUniversity() + } } \ No newline at end of file From 2b70a5efada0b2ae18e611cf67cd81502d027ab6 Mon Sep 17 00:00:00 2001 From: sgsk88 Date: Sun, 12 Nov 2023 03:05:07 +0900 Subject: [PATCH 5/9] =?UTF-8?q?[feature/univ=5Fsave]=20DataStore=20Present?= =?UTF-8?q?ation=20=EC=A0=80=EC=9E=A5=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20(#85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/signup/UnivSelectContract.kt | 16 +++++++++++++--- .../presentation/ui/signup/UnivSelectScreen.kt | 11 +++++++++-- .../ui/signup/UnivSelectViewModel.kt | 18 ++++++++++++++---- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/presentation/src/main/java/com/everymeal/presentation/ui/signup/UnivSelectContract.kt b/presentation/src/main/java/com/everymeal/presentation/ui/signup/UnivSelectContract.kt index a0fc1109..15639cdf 100644 --- a/presentation/src/main/java/com/everymeal/presentation/ui/signup/UnivSelectContract.kt +++ b/presentation/src/main/java/com/everymeal/presentation/ui/signup/UnivSelectContract.kt @@ -16,7 +16,10 @@ class UnivSelectContract { val univSelectLoadState: LoadState = LoadState.LOADING, val selectedUniv: String = "", val universities: List = emptyList(), - val networkErrorDialog: Boolean = true + val networkErrorDialog: Boolean = true, + val univIdx: Int = 0, + val univSelectFullName: String = "", + val campusName: String = "" ) : ViewState /* @@ -25,9 +28,16 @@ class UnivSelectContract { */ sealed class UnivSelectEvent : ViewEvent { object InitUnivSelectScreen : UnivSelectEvent() - object SelectButtonClicked : UnivSelectEvent() + data class SelectButtonClicked( + val univIdx: Int, + val univSelectFullName: String, + val campusName: String + ) : UnivSelectEvent() data class SelectedUniv( - val selectedUniv: String + val selectedUniv: String, + val univIdx: Int, + val univSelectFullName: String, + val campusName: String ) : UnivSelectEvent() data class NetworkErrorDialogClicked( val dialogStateChange: Boolean diff --git a/presentation/src/main/java/com/everymeal/presentation/ui/signup/UnivSelectScreen.kt b/presentation/src/main/java/com/everymeal/presentation/ui/signup/UnivSelectScreen.kt index 52885016..c4f6b04a 100644 --- a/presentation/src/main/java/com/everymeal/presentation/ui/signup/UnivSelectScreen.kt +++ b/presentation/src/main/java/com/everymeal/presentation/ui/signup/UnivSelectScreen.kt @@ -120,7 +120,10 @@ fun UnivSelectScreen( index = index ) { viewModel.setEvent(UnivSelectContract.UnivSelectEvent.SelectedUniv( - "${item.universityShortName}+${item.campusName}") + selectedUniv = "${item.universityShortName}+${item.campusName}", + univIdx = item.idx, + univSelectFullName = item.universityName, + campusName = item.campusName) ) } } @@ -161,7 +164,11 @@ fun UnivSelectScreen( text = stringResource(R.string.select), enabled = viewState.selectedUniv.isNotEmpty(), ) { - viewModel.setEvent(UnivSelectContract.UnivSelectEvent.SelectButtonClicked) + viewModel.setEvent(UnivSelectContract.UnivSelectEvent.SelectButtonClicked( + univIdx = viewState.univIdx, + univSelectFullName = viewState.univSelectFullName, + campusName = viewState.campusName + )) } } } diff --git a/presentation/src/main/java/com/everymeal/presentation/ui/signup/UnivSelectViewModel.kt b/presentation/src/main/java/com/everymeal/presentation/ui/signup/UnivSelectViewModel.kt index f4480720..35ddc2c9 100644 --- a/presentation/src/main/java/com/everymeal/presentation/ui/signup/UnivSelectViewModel.kt +++ b/presentation/src/main/java/com/everymeal/presentation/ui/signup/UnivSelectViewModel.kt @@ -1,7 +1,7 @@ package com.everymeal.presentation.ui.signup -import android.util.Log import androidx.lifecycle.viewModelScope +import com.everymeal.domain.usecase.local.SaveUniversityUseCase import com.everymeal.domain.usecase.onboarding.GetUniversityUseCase import com.everymeal.presentation.base.BaseViewModel import com.everymeal.presentation.base.LoadState @@ -9,13 +9,13 @@ import com.everymeal.presentation.ui.signup.UnivSelectContract.UnivSelectEffect import com.everymeal.presentation.ui.signup.UnivSelectContract.UnivSelectEvent import com.everymeal.presentation.ui.signup.UnivSelectContract.UnivSelectState import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.delay import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class UnivSelectViewModel @Inject constructor( - private val getUniversityUseCase: GetUniversityUseCase + private val getUniversityUseCase: GetUniversityUseCase, + private val saveUniversityUseCase: SaveUniversityUseCase ) : BaseViewModel( UnivSelectState() ) { @@ -28,13 +28,17 @@ class UnivSelectViewModel @Inject constructor( } is UnivSelectEvent.SelectButtonClicked -> { + saveUniversity(event.univIdx, event.univSelectFullName, event.campusName) sendEffect({ UnivSelectEffect.MoveToMain }) } is UnivSelectEvent.SelectedUniv -> { updateState { copy( - selectedUniv = event.selectedUniv + selectedUniv = event.selectedUniv, + univIdx = event.univIdx, + univSelectFullName = event.univSelectFullName, + campusName = event.campusName ) } } @@ -67,4 +71,10 @@ class UnivSelectViewModel @Inject constructor( } } } + + private fun saveUniversity(index: Int, univName: String, campusName: String) { + viewModelScope.launch { + saveUniversityUseCase(index, univName+campusName) + } + } } \ No newline at end of file From 33c17c4e391173b834acf734e58a851e574385f0 Mon Sep 17 00:00:00 2001 From: sgsk88 Date: Thu, 16 Nov 2023 22:32:45 +0900 Subject: [PATCH 6/9] =?UTF-8?q?[feature/univ=5Fsave]=20branch=20=EC=B6=A9?= =?UTF-8?q?=EB=8F=8C=20=ED=95=B4=EA=B2=B0(import=20=EC=B6=94=EA=B0=80)=20(?= =?UTF-8?q?#85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/everymeal/everymeal_android/di/RepositoryModule.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/com/everymeal/everymeal_android/di/RepositoryModule.kt b/app/src/main/java/com/everymeal/everymeal_android/di/RepositoryModule.kt index c1913b66..1b437a64 100644 --- a/app/src/main/java/com/everymeal/everymeal_android/di/RepositoryModule.kt +++ b/app/src/main/java/com/everymeal/everymeal_android/di/RepositoryModule.kt @@ -1,5 +1,9 @@ package com.everymeal.everymeal_android.di +import com.everymeal.data.datasource.auth.AuthRemoteDataSource +import com.everymeal.data.datasource.auth.AuthRemoteRemoteDataSourceImpl +import com.everymeal.data.datasource.local.LocalDataSource +import com.everymeal.data.datasource.local.LocalDataSourceImpl import com.everymeal.data.datasource.onboarding.OnboardingDataSource import com.everymeal.data.datasource.onboarding.OnboardingDataSourceImpl import com.everymeal.data.repository.local.LocalRepositoryImpl From b4006b56ac4d34660199abdffd69b63170f9b326 Mon Sep 17 00:00:00 2001 From: sgsk88 Date: Thu, 16 Nov 2023 23:21:41 +0900 Subject: [PATCH 7/9] =?UTF-8?q?[feature/univ=5Fsave]=20=EB=8C=80=ED=95=99?= =?UTF-8?q?=20=EC=9D=B8=EB=8D=B1=EC=8A=A4=20=EB=A1=9C=EC=BB=AC=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EA=B8=B0=20data,=20domain=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20(#85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasource/local/LocalDataSource.kt | 4 ++++ .../datasource/local/LocalDataSourceImpl.kt | 20 +++++++++++++++++++ .../repository/splash/SplashRepositoryImpl.kt | 15 ++++++++++++++ domain/build.gradle.kts | 3 +++ .../repository/splash/SplashRepository.kt | 8 ++++++++ gradle/libs.versions.toml | 4 ++++ .../ui/onboarding/OnboardingScreen.kt | 2 +- .../presentation/ui/splash/SplashContract.kt | 19 ++++++++++++++++++ .../presentation/ui/splash/SplashViewModel.kt | 20 +++++++++++++++++++ 9 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 data/src/main/java/com/everymeal/data/repository/splash/SplashRepositoryImpl.kt create mode 100644 domain/src/main/java/com/everymeal/domain/repository/splash/SplashRepository.kt create mode 100644 presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashContract.kt create mode 100644 presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashViewModel.kt diff --git a/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSource.kt b/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSource.kt index 2ee3db76..39fe60a4 100644 --- a/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSource.kt +++ b/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSource.kt @@ -1,5 +1,9 @@ package com.everymeal.data.datasource.local +import kotlinx.coroutines.flow.Flow + interface LocalDataSource { suspend fun saveUniversity(index : Int, univName : String) + + suspend fun getUniversityIndex() : Flow } \ No newline at end of file diff --git a/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSourceImpl.kt b/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSourceImpl.kt index b94564c8..a76c5121 100644 --- a/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSourceImpl.kt +++ b/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSourceImpl.kt @@ -3,7 +3,12 @@ package com.everymeal.data.datasource.local import androidx.datastore.core.DataStore import androidx.datastore.preferences.core.Preferences import androidx.datastore.preferences.core.edit +import androidx.datastore.preferences.core.emptyPreferences import androidx.datastore.preferences.core.stringPreferencesKey +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.map +import java.io.IOException import javax.inject.Inject object DataStoreKey { @@ -20,4 +25,19 @@ class LocalDataSourceImpl @Inject constructor( it[DataStoreKey.UNIVERSITY_NAME] = univName } } + + override suspend fun getUniversityIndex(): Flow { + return dataStore.data + .catch { exception -> + if (exception is IOException) { + exception.printStackTrace() + emit(emptyPreferences()) + } else { + throw exception + } + } + .map { prefs -> + prefs[DataStoreKey.UNIVERSITY_INDEX] ?: "" + } + } } \ No newline at end of file diff --git a/data/src/main/java/com/everymeal/data/repository/splash/SplashRepositoryImpl.kt b/data/src/main/java/com/everymeal/data/repository/splash/SplashRepositoryImpl.kt new file mode 100644 index 00000000..288053d1 --- /dev/null +++ b/data/src/main/java/com/everymeal/data/repository/splash/SplashRepositoryImpl.kt @@ -0,0 +1,15 @@ +package com.everymeal.data.repository.splash + +import com.everymeal.data.datasource.local.LocalDataSource +import com.everymeal.domain.repository.splash.SplashRepository +import kotlinx.coroutines.flow.Flow +import javax.inject.Inject + +class SplashRepositoryImpl @Inject constructor( + private val localDataSource: LocalDataSource +): SplashRepository { + + override suspend fun getUniversityIndex(): Flow { + return localDataSource.getUniversityIndex() + } +} \ No newline at end of file diff --git a/domain/build.gradle.kts b/domain/build.gradle.kts index 7b184f13..4403f376 100644 --- a/domain/build.gradle.kts +++ b/domain/build.gradle.kts @@ -11,4 +11,7 @@ java { dependencies { // Hilt implementation(libs.hilt.core) + + // Coroutines + implementation(libs.kotlin.coroutines) } diff --git a/domain/src/main/java/com/everymeal/domain/repository/splash/SplashRepository.kt b/domain/src/main/java/com/everymeal/domain/repository/splash/SplashRepository.kt new file mode 100644 index 00000000..033b93dc --- /dev/null +++ b/domain/src/main/java/com/everymeal/domain/repository/splash/SplashRepository.kt @@ -0,0 +1,8 @@ +package com.everymeal.domain.repository.splash + +import kotlinx.coroutines.flow.Flow + + +interface SplashRepository { + suspend fun getUniversityIndex(): Flow +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c1624d3d..7bbae4f2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -20,6 +20,7 @@ compose-navigation = "2.7.4" accompanist = "0.33.0-alpha" data-store = "1.0.0" +kotlin-coroutines = "1.7.3" [libraries] agp = { module = "com.android.tools.build:gradle", version.ref = "agp" } @@ -74,6 +75,9 @@ compose-navigation = { module = "androidx.navigation:navigation-compose", versio #data-store data-store = { module = "androidx.datastore:datastore-preferences", version.ref = "data-store" } +#kotlin-coroutines +kotlin-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlin-coroutines" } + [plugins] androidApplication = { id = "com.android.application", version.ref = "agp" } kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } diff --git a/presentation/src/main/java/com/everymeal/presentation/ui/onboarding/OnboardingScreen.kt b/presentation/src/main/java/com/everymeal/presentation/ui/onboarding/OnboardingScreen.kt index 6ad154e7..ee191fba 100644 --- a/presentation/src/main/java/com/everymeal/presentation/ui/onboarding/OnboardingScreen.kt +++ b/presentation/src/main/java/com/everymeal/presentation/ui/onboarding/OnboardingScreen.kt @@ -121,7 +121,7 @@ fun OnboardingScreen( } Spacer(modifier = Modifier.size(30.dp)) EveryMealMainButton( - text = stringResource(id = R.string.next), + text = stringResource(id = R.string.start), onClick = onNavigateToUnivSelect ) } diff --git a/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashContract.kt b/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashContract.kt new file mode 100644 index 00000000..e76e4387 --- /dev/null +++ b/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashContract.kt @@ -0,0 +1,19 @@ +package com.everymeal.presentation.ui.splash + +import com.everymeal.presentation.base.LoadState +import com.everymeal.presentation.base.ViewEvent +import com.everymeal.presentation.base.ViewSideEffect +import com.everymeal.presentation.base.ViewState + +class SplashContract { + data class SplashViewState( + val loginState: LoadState = LoadState.LOADING + ) : ViewState + + sealed class SplashSideEffect : ViewSideEffect { + object MoveToMain: SplashSideEffect() + object MoveToOnboarding: SplashSideEffect() + } + + sealed class SplashEvent : ViewEvent +} diff --git a/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashViewModel.kt b/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashViewModel.kt new file mode 100644 index 00000000..2bb7de43 --- /dev/null +++ b/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashViewModel.kt @@ -0,0 +1,20 @@ +package com.everymeal.presentation.ui.splash + +import com.everymeal.presentation.base.BaseViewModel +import com.everymeal.presentation.ui.splash.SplashContract.SplashEvent +import com.everymeal.presentation.ui.splash.SplashContract.SplashSideEffect +import com.everymeal.presentation.ui.splash.SplashContract.SplashViewState +import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject + +@HiltViewModel +class SplashViewModel @Inject constructor( + +) : BaseViewModel( + SplashViewState() +) { + + override fun handleEvents(event: SplashEvent) { + + } +} From c84e076d54ef099d3b01c0a7755fd43a5858628a Mon Sep 17 00:00:00 2001 From: sgsk88 Date: Fri, 17 Nov 2023 00:19:44 +0900 Subject: [PATCH 8/9] =?UTF-8?q?[feature/univ=5Fsave]=20=EB=8C=80=ED=95=99?= =?UTF-8?q?=EC=9D=B8=EB=8D=B1=EC=8A=A4=20presentation=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=20=EB=B0=8F=20=EB=B6=84=EA=B8=B0=EC=B2=98=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(#85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/local/LocalRepositoryImpl.kt | 5 +++++ .../repository/splash/SplashRepositoryImpl.kt | 15 ------------- .../repository/local/LocalRepository.kt | 4 ++++ .../repository/splash/SplashRepository.kt | 8 ------- .../local/GetUniversityIndexUseCase.kt | 13 +++++++++++ .../presentation/ui/splash/SplashActivity.kt | 15 ++++++++++--- .../presentation/ui/splash/SplashContract.kt | 12 +++++----- .../presentation/ui/splash/SplashScreen.kt | 7 ++++++ .../presentation/ui/splash/SplashViewModel.kt | 22 ++++++++++++++++++- 9 files changed, 68 insertions(+), 33 deletions(-) delete mode 100644 data/src/main/java/com/everymeal/data/repository/splash/SplashRepositoryImpl.kt delete mode 100644 domain/src/main/java/com/everymeal/domain/repository/splash/SplashRepository.kt create mode 100644 domain/src/main/java/com/everymeal/domain/usecase/local/GetUniversityIndexUseCase.kt diff --git a/data/src/main/java/com/everymeal/data/repository/local/LocalRepositoryImpl.kt b/data/src/main/java/com/everymeal/data/repository/local/LocalRepositoryImpl.kt index f6ee1fb7..6692edf1 100644 --- a/data/src/main/java/com/everymeal/data/repository/local/LocalRepositoryImpl.kt +++ b/data/src/main/java/com/everymeal/data/repository/local/LocalRepositoryImpl.kt @@ -2,6 +2,7 @@ package com.everymeal.data.repository.local import com.everymeal.data.datasource.local.LocalDataSource import com.everymeal.domain.repository.local.LocalRepository +import kotlinx.coroutines.flow.Flow import javax.inject.Inject class LocalRepositoryImpl @Inject constructor( @@ -11,4 +12,8 @@ class LocalRepositoryImpl @Inject constructor( override suspend fun saveUniversity(index: Int, univName: String) { localDataSource.saveUniversity(index, univName) } + + override suspend fun getUniversityIndex(): Flow { + return localDataSource.getUniversityIndex() + } } \ No newline at end of file diff --git a/data/src/main/java/com/everymeal/data/repository/splash/SplashRepositoryImpl.kt b/data/src/main/java/com/everymeal/data/repository/splash/SplashRepositoryImpl.kt deleted file mode 100644 index 288053d1..00000000 --- a/data/src/main/java/com/everymeal/data/repository/splash/SplashRepositoryImpl.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.everymeal.data.repository.splash - -import com.everymeal.data.datasource.local.LocalDataSource -import com.everymeal.domain.repository.splash.SplashRepository -import kotlinx.coroutines.flow.Flow -import javax.inject.Inject - -class SplashRepositoryImpl @Inject constructor( - private val localDataSource: LocalDataSource -): SplashRepository { - - override suspend fun getUniversityIndex(): Flow { - return localDataSource.getUniversityIndex() - } -} \ No newline at end of file diff --git a/domain/src/main/java/com/everymeal/domain/repository/local/LocalRepository.kt b/domain/src/main/java/com/everymeal/domain/repository/local/LocalRepository.kt index 1222fd97..902b6bee 100644 --- a/domain/src/main/java/com/everymeal/domain/repository/local/LocalRepository.kt +++ b/domain/src/main/java/com/everymeal/domain/repository/local/LocalRepository.kt @@ -1,5 +1,9 @@ package com.everymeal.domain.repository.local +import kotlinx.coroutines.flow.Flow + interface LocalRepository { suspend fun saveUniversity(index : Int, univName : String) + + suspend fun getUniversityIndex() : Flow } \ No newline at end of file diff --git a/domain/src/main/java/com/everymeal/domain/repository/splash/SplashRepository.kt b/domain/src/main/java/com/everymeal/domain/repository/splash/SplashRepository.kt deleted file mode 100644 index 033b93dc..00000000 --- a/domain/src/main/java/com/everymeal/domain/repository/splash/SplashRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.everymeal.domain.repository.splash - -import kotlinx.coroutines.flow.Flow - - -interface SplashRepository { - suspend fun getUniversityIndex(): Flow -} \ No newline at end of file diff --git a/domain/src/main/java/com/everymeal/domain/usecase/local/GetUniversityIndexUseCase.kt b/domain/src/main/java/com/everymeal/domain/usecase/local/GetUniversityIndexUseCase.kt new file mode 100644 index 00000000..c196f11a --- /dev/null +++ b/domain/src/main/java/com/everymeal/domain/usecase/local/GetUniversityIndexUseCase.kt @@ -0,0 +1,13 @@ +package com.everymeal.domain.usecase.local + +import com.everymeal.domain.repository.local.LocalRepository +import kotlinx.coroutines.flow.Flow +import javax.inject.Inject + +class GetUniversityIndexUseCase @Inject constructor( + private val localRepository: LocalRepository +) { + suspend operator fun invoke() : Flow { + return localRepository.getUniversityIndex() + } +} \ No newline at end of file diff --git a/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashActivity.kt b/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashActivity.kt index 19724ea5..fa326113 100644 --- a/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashActivity.kt +++ b/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashActivity.kt @@ -4,14 +4,18 @@ import android.annotation.SuppressLint import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent +import androidx.activity.viewModels +import com.everymeal.presentation.ui.main.MainActivity import com.everymeal.presentation.ui.onboarding.OnboardingActivity import com.everymeal.presentation.ui.theme.EveryMeal_AndroidTheme -import com.everymeal.presentation.ui.signup.UnivSelectActivity import dagger.hilt.android.AndroidEntryPoint @SuppressLint("CustomSplashScreen") @AndroidEntryPoint class SplashActivity : ComponentActivity() { + + private val viewModel: SplashViewModel by viewModels() + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -22,8 +26,13 @@ class SplashActivity : ComponentActivity() { setContent { EveryMeal_AndroidTheme { SplashScreen(onFinishSplash = { - OnboardingActivity.startActivity(this) - finish() + if(viewModel.viewState.value.selectedUnitIndex.isNullOrBlank()) { + OnboardingActivity.startActivity(this) + finish() + } else { + MainActivity.startActivity(this) + finish() + } }) } } diff --git a/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashContract.kt b/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashContract.kt index e76e4387..8a321fdf 100644 --- a/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashContract.kt +++ b/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashContract.kt @@ -7,13 +7,13 @@ import com.everymeal.presentation.base.ViewState class SplashContract { data class SplashViewState( - val loginState: LoadState = LoadState.LOADING + val loginState: LoadState = LoadState.SUCCESS, + val selectedUnitIndex: String? = null, ) : ViewState - sealed class SplashSideEffect : ViewSideEffect { - object MoveToMain: SplashSideEffect() - object MoveToOnboarding: SplashSideEffect() - } + sealed class SplashSideEffect : ViewSideEffect - sealed class SplashEvent : ViewEvent + sealed class SplashEvent : ViewEvent { + object InitSplashScreen: SplashEvent() + } } diff --git a/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashScreen.kt b/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashScreen.kt index 8d001f41..1b22db67 100644 --- a/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashScreen.kt +++ b/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashScreen.kt @@ -6,11 +6,13 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.size import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel import com.airbnb.lottie.compose.LottieAnimation import com.airbnb.lottie.compose.LottieCompositionSpec import com.airbnb.lottie.compose.animateLottieCompositionAsState @@ -20,11 +22,16 @@ import com.everymeal.presentation.ui.theme.EveryMeal_AndroidTheme @SuppressLint("CoroutineCreationDuringComposition") @Composable fun SplashScreen( + viewModel : SplashViewModel = hiltViewModel(), onFinishSplash: () -> Unit, ) { val composition by rememberLottieComposition(LottieCompositionSpec.Asset("everymeal_splash.json")) val progress by animateLottieCompositionAsState(composition) + LaunchedEffect(Unit) { + viewModel.setEvent(SplashContract.SplashEvent.InitSplashScreen) + } + Column( modifier = Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, diff --git a/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashViewModel.kt b/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashViewModel.kt index 2bb7de43..9735375f 100644 --- a/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashViewModel.kt +++ b/presentation/src/main/java/com/everymeal/presentation/ui/splash/SplashViewModel.kt @@ -1,20 +1,40 @@ package com.everymeal.presentation.ui.splash +import androidx.lifecycle.viewModelScope +import com.everymeal.domain.usecase.local.GetUniversityIndexUseCase import com.everymeal.presentation.base.BaseViewModel +import com.everymeal.presentation.base.LoadState import com.everymeal.presentation.ui.splash.SplashContract.SplashEvent import com.everymeal.presentation.ui.splash.SplashContract.SplashSideEffect import com.everymeal.presentation.ui.splash.SplashContract.SplashViewState import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class SplashViewModel @Inject constructor( - + private val getUniversityIndexUseCase: GetUniversityIndexUseCase ) : BaseViewModel( SplashViewState() ) { override fun handleEvents(event: SplashEvent) { + when (event) { + is SplashEvent.InitSplashScreen -> { + getUniversityIndex() + } + } + } + private fun getUniversityIndex() { + viewModelScope.launch { + val univIndex = getUniversityIndexUseCase().first() + updateState { + copy( + selectedUnitIndex = univIndex, + ) + } + } } } From 1dc25262c938ab84ef7d410a057a75b64a50f681 Mon Sep 17 00:00:00 2001 From: sgsk88 Date: Sun, 19 Nov 2023 23:57:41 +0900 Subject: [PATCH 9/9] =?UTF-8?q?[feature/univ=5Fsave]=20=EB=8C=80=ED=95=99?= =?UTF-8?q?=20=EB=A1=9C=EC=BB=AC=EC=9E=91=EC=97=85=20PR=20=EB=B0=98?= =?UTF-8?q?=EC=98=81=20(#85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../everymeal_android/di/DataBaseModule.kt | 27 +++++++++++++++++++ .../everymeal_android/di/NetworkModule.kt | 14 ---------- .../datasource/local/LocalDataSourceImpl.kt | 2 +- 3 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/com/everymeal/everymeal_android/di/DataBaseModule.kt diff --git a/app/src/main/java/com/everymeal/everymeal_android/di/DataBaseModule.kt b/app/src/main/java/com/everymeal/everymeal_android/di/DataBaseModule.kt new file mode 100644 index 00000000..e0d86dd5 --- /dev/null +++ b/app/src/main/java/com/everymeal/everymeal_android/di/DataBaseModule.kt @@ -0,0 +1,27 @@ +package com.everymeal.everymeal_android.di + +import android.content.Context +import androidx.datastore.core.DataStore +import androidx.datastore.preferences.core.PreferenceDataStoreFactory +import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.preferencesDataStoreFile +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.android.qualifiers.ApplicationContext +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object DataBaseModule { + + private const val DATASTORE_NAME = "everymeal_datastore" + + @Singleton + @Provides + fun providePreferencesDataStore(@ApplicationContext context: Context): DataStore = + PreferenceDataStoreFactory.create( + produceFile = { context.preferencesDataStoreFile(DATASTORE_NAME) } + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/everymeal/everymeal_android/di/NetworkModule.kt b/app/src/main/java/com/everymeal/everymeal_android/di/NetworkModule.kt index e1952a50..efaacb05 100644 --- a/app/src/main/java/com/everymeal/everymeal_android/di/NetworkModule.kt +++ b/app/src/main/java/com/everymeal/everymeal_android/di/NetworkModule.kt @@ -1,9 +1,5 @@ package com.everymeal.everymeal_android.di -import android.content.Context -import androidx.datastore.core.DataStore -import androidx.datastore.preferences.core.PreferenceDataStoreFactory -import androidx.datastore.preferences.preferencesDataStoreFile import com.everymeal.data.service.auth.AuthApi import com.everymeal.data.service.onboarding.OnboardingApi import com.everymeal.everymeal_android.BuildConfig @@ -11,14 +7,12 @@ import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFact import dagger.Module import dagger.Provides import dagger.hilt.InstallIn -import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent import kotlinx.serialization.json.Json import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient import retrofit2.Retrofit import java.util.concurrent.TimeUnit -import java.util.prefs.Preferences import javax.inject.Singleton @Module @@ -28,7 +22,6 @@ object NetworkModule { private val json = Json { ignoreUnknownKeys = true } private const val BASE_URL = BuildConfig.BASE_URL - private const val DATASTORE_NAME = "everymeal_datastore" @Provides @Singleton @@ -49,13 +42,6 @@ object NetworkModule { .build() } - @Singleton - @Provides - fun providePreferencesDataStore(@ApplicationContext context: Context): DataStore = - PreferenceDataStoreFactory.create( - produceFile = { context.preferencesDataStoreFile(DATASTORE_NAME) } - ) - @Provides @Singleton fun provideOnboardingApi(retrofit: Retrofit): OnboardingApi { diff --git a/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSourceImpl.kt b/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSourceImpl.kt index a76c5121..18765d9f 100644 --- a/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSourceImpl.kt +++ b/data/src/main/java/com/everymeal/data/datasource/local/LocalDataSourceImpl.kt @@ -37,7 +37,7 @@ class LocalDataSourceImpl @Inject constructor( } } .map { prefs -> - prefs[DataStoreKey.UNIVERSITY_INDEX] ?: "" + prefs[DataStoreKey.UNIVERSITY_INDEX].orEmpty() } } } \ No newline at end of file