From 90ee0b1500bffb8a5135b515fdfd59d9cc0cb30b Mon Sep 17 00:00:00 2001 From: jinukeu Date: Fri, 20 Oct 2023 15:18:25 +0900 Subject: [PATCH 01/14] =?UTF-8?q?feat:=20LocalOpenMajor=20-=20Storage,=20P?= =?UTF-8?q?rovider=20DataSource=20=ED=86=B5=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/openmajor/build.gradle.kts | 4 ++ .../datasource/LocalOpenMajorDataSource.kt | 12 +++++ .../LocalOpenMajorProviderDataSource.kt | 7 --- .../LocalOpenMajorStorageDataSource.kt | 8 ---- domain/openmajor/.gitignore | 1 + local/openmajor/build.gradle.kts | 4 ++ .../LocalOpenMajorDataSourceImpl.kt | 46 +++++++++++++++++++ .../LocalOpenMajorProviderDataSourceImpl.kt | 15 ------ .../LocalOpenMajorStorageDataSourceImpl.kt | 19 -------- .../openmajor/di/LocalDataSourceModule.kt | 18 ++------ 10 files changed, 72 insertions(+), 62 deletions(-) create mode 100644 data/openmajor/src/main/java/com/suwiki/data/openmajor/datasource/LocalOpenMajorDataSource.kt delete mode 100644 data/openmajor/src/main/java/com/suwiki/data/openmajor/datasource/LocalOpenMajorProviderDataSource.kt delete mode 100644 data/openmajor/src/main/java/com/suwiki/data/openmajor/datasource/LocalOpenMajorStorageDataSource.kt create mode 100644 domain/openmajor/.gitignore create mode 100644 local/openmajor/src/main/java/com/suwiki/local/openmajor/datasource/LocalOpenMajorDataSourceImpl.kt delete mode 100644 local/openmajor/src/main/java/com/suwiki/local/openmajor/datasource/LocalOpenMajorProviderDataSourceImpl.kt delete mode 100644 local/openmajor/src/main/java/com/suwiki/local/openmajor/datasource/LocalOpenMajorStorageDataSourceImpl.kt diff --git a/data/openmajor/build.gradle.kts b/data/openmajor/build.gradle.kts index a6da5afc1..792d621c2 100644 --- a/data/openmajor/build.gradle.kts +++ b/data/openmajor/build.gradle.kts @@ -5,4 +5,8 @@ plugins { android { namespace = "com.suwiki.data.openmajor" +} + +dependencies { + implementation(projects.domain.openmajor) } \ No newline at end of file diff --git a/data/openmajor/src/main/java/com/suwiki/data/openmajor/datasource/LocalOpenMajorDataSource.kt b/data/openmajor/src/main/java/com/suwiki/data/openmajor/datasource/LocalOpenMajorDataSource.kt new file mode 100644 index 000000000..ea663daa1 --- /dev/null +++ b/data/openmajor/src/main/java/com/suwiki/data/openmajor/datasource/LocalOpenMajorDataSource.kt @@ -0,0 +1,12 @@ +package com.suwiki.data.openmajor.datasource + +import com.suwiki.core.model.openmajor.OpenMajor +import kotlinx.coroutines.flow.Flow + +interface LocalOpenMajorDataSource { + suspend fun getLocalOpenMajorVersion(): Flow + suspend fun setLocalOpenMajorVersion(version: Float) + suspend fun getLocalOpenMajorList(): List + suspend fun saveAllOpenMajors(majors: List) + suspend fun deleteAllOpenMajors() +} diff --git a/data/openmajor/src/main/java/com/suwiki/data/openmajor/datasource/LocalOpenMajorProviderDataSource.kt b/data/openmajor/src/main/java/com/suwiki/data/openmajor/datasource/LocalOpenMajorProviderDataSource.kt deleted file mode 100644 index 6874afc1a..000000000 --- a/data/openmajor/src/main/java/com/suwiki/data/openmajor/datasource/LocalOpenMajorProviderDataSource.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.suwiki.data.openmajor.datasource - -import com.suwiki.core.model.openmajor.OpenMajor - -interface LocalOpenMajorProviderDataSource { - suspend fun getLocalOpenMajorList(): List -} diff --git a/data/openmajor/src/main/java/com/suwiki/data/openmajor/datasource/LocalOpenMajorStorageDataSource.kt b/data/openmajor/src/main/java/com/suwiki/data/openmajor/datasource/LocalOpenMajorStorageDataSource.kt deleted file mode 100644 index 3e4804569..000000000 --- a/data/openmajor/src/main/java/com/suwiki/data/openmajor/datasource/LocalOpenMajorStorageDataSource.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.suwiki.data.openmajor.datasource - -import com.suwiki.core.model.openmajor.OpenMajor - -interface LocalOpenMajorStorageDataSource { - suspend fun saveAllOpenMajors(majors: List) - suspend fun deleteAllOpenMajors() -} diff --git a/domain/openmajor/.gitignore b/domain/openmajor/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/domain/openmajor/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/local/openmajor/build.gradle.kts b/local/openmajor/build.gradle.kts index 49cf2b2e1..e7b0cb3cd 100644 --- a/local/openmajor/build.gradle.kts +++ b/local/openmajor/build.gradle.kts @@ -18,6 +18,10 @@ dependencies { implementation(libs.room.runtime) implementation(libs.room.ktx) + implementation(libs.bundles.coroutine) + implementation(libs.androidx.datastore.core) + implementation(libs.androidx.datastore.preferences) + testImplementation(libs.junit4) androidTestImplementation(libs.junit) } \ No newline at end of file diff --git a/local/openmajor/src/main/java/com/suwiki/local/openmajor/datasource/LocalOpenMajorDataSourceImpl.kt b/local/openmajor/src/main/java/com/suwiki/local/openmajor/datasource/LocalOpenMajorDataSourceImpl.kt new file mode 100644 index 000000000..a8c0764bf --- /dev/null +++ b/local/openmajor/src/main/java/com/suwiki/local/openmajor/datasource/LocalOpenMajorDataSourceImpl.kt @@ -0,0 +1,46 @@ +package com.suwiki.local.openmajor.datasource + +import androidx.datastore.core.DataStore +import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.edit +import androidx.datastore.preferences.core.floatPreferencesKey +import com.suwiki.core.database.OpenMajorDatabase +import com.suwiki.core.model.openmajor.OpenMajor +import com.suwiki.data.openmajor.datasource.LocalOpenMajorDataSource +import com.suwiki.local.openmajor.converter.toEntity +import com.suwiki.local.openmajor.converter.toModel +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map +import javax.inject.Inject + +class LocalOpenMajorDataSourceImpl @Inject constructor( + private val dataStore: DataStore, + private val db: OpenMajorDatabase, +) : LocalOpenMajorDataSource { + + companion object { + private val OPEN_MAJOR_VERSION = floatPreferencesKey("[KEY] is open major version") + } + + private val data: Flow + get() = dataStore.data + + override suspend fun getLocalOpenMajorVersion(): Flow = + data.map { it[OPEN_MAJOR_VERSION] ?: 0f } + + override suspend fun setLocalOpenMajorVersion(version: Float) { + dataStore.edit { it[OPEN_MAJOR_VERSION] = version } + } + + override suspend fun getLocalOpenMajorList(): List { + return db.openMajorDao().getAll().map { it.toModel() } + } + + override suspend fun saveAllOpenMajors(majors: List) { + db.openMajorDao().insertAll(majors.map { it.toEntity() }) + } + + override suspend fun deleteAllOpenMajors() { + db.openMajorDao().deleteAll() + } +} diff --git a/local/openmajor/src/main/java/com/suwiki/local/openmajor/datasource/LocalOpenMajorProviderDataSourceImpl.kt b/local/openmajor/src/main/java/com/suwiki/local/openmajor/datasource/LocalOpenMajorProviderDataSourceImpl.kt deleted file mode 100644 index 2761dca76..000000000 --- a/local/openmajor/src/main/java/com/suwiki/local/openmajor/datasource/LocalOpenMajorProviderDataSourceImpl.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.suwiki.local.openmajor.datasource - -import com.suwiki.core.database.OpenMajorDatabase -import com.suwiki.core.model.openmajor.OpenMajor -import com.suwiki.data.openmajor.datasource.LocalOpenMajorProviderDataSource -import com.suwiki.local.openmajor.converter.toModel -import javax.inject.Inject - -class LocalOpenMajorProviderDataSourceImpl @Inject constructor( - private val db: OpenMajorDatabase, -) : LocalOpenMajorProviderDataSource { - override suspend fun getLocalOpenMajorList(): List { - return db.openMajorDao().getAll().map { it.toModel() } - } -} diff --git a/local/openmajor/src/main/java/com/suwiki/local/openmajor/datasource/LocalOpenMajorStorageDataSourceImpl.kt b/local/openmajor/src/main/java/com/suwiki/local/openmajor/datasource/LocalOpenMajorStorageDataSourceImpl.kt deleted file mode 100644 index d7e0426e2..000000000 --- a/local/openmajor/src/main/java/com/suwiki/local/openmajor/datasource/LocalOpenMajorStorageDataSourceImpl.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.suwiki.local.openmajor.datasource - -import com.suwiki.core.database.OpenMajorDatabase -import com.suwiki.core.model.openmajor.OpenMajor -import com.suwiki.data.openmajor.datasource.LocalOpenMajorStorageDataSource -import com.suwiki.local.openmajor.converter.toEntity -import javax.inject.Inject - -class LocalOpenMajorStorageDataSourceImpl @Inject constructor( - private val db: OpenMajorDatabase, -) : LocalOpenMajorStorageDataSource { - override suspend fun saveAllOpenMajors(majors: List) { - db.openMajorDao().insertAll(majors.map { it.toEntity() }) - } - - override suspend fun deleteAllOpenMajors() { - db.openMajorDao().deleteAll() - } -} \ No newline at end of file diff --git a/local/openmajor/src/main/java/com/suwiki/local/openmajor/di/LocalDataSourceModule.kt b/local/openmajor/src/main/java/com/suwiki/local/openmajor/di/LocalDataSourceModule.kt index 73ba7a37f..56f12d2bf 100644 --- a/local/openmajor/src/main/java/com/suwiki/local/openmajor/di/LocalDataSourceModule.kt +++ b/local/openmajor/src/main/java/com/suwiki/local/openmajor/di/LocalDataSourceModule.kt @@ -1,9 +1,7 @@ package com.suwiki.local.openmajor.di -import com.suwiki.data.openmajor.datasource.LocalOpenMajorProviderDataSource -import com.suwiki.data.openmajor.datasource.LocalOpenMajorStorageDataSource -import com.suwiki.local.openmajor.datasource.LocalOpenMajorProviderDataSourceImpl -import com.suwiki.local.openmajor.datasource.LocalOpenMajorStorageDataSourceImpl +import com.suwiki.data.openmajor.datasource.LocalOpenMajorDataSource +import com.suwiki.local.openmajor.datasource.LocalOpenMajorDataSourceImpl import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -16,13 +14,7 @@ abstract class LocalDataSourceModule { @Singleton @Binds - abstract fun bindLocalOpenMajorProviderDataSource( - localOpenMajorProviderDataSourceImpl: LocalOpenMajorProviderDataSourceImpl, - ): LocalOpenMajorProviderDataSource - - @Singleton - @Binds - abstract fun bindLocalOpenMajorStorageDataSource( - localOpenMajorStorageDataSourceImpl: LocalOpenMajorStorageDataSourceImpl, - ): LocalOpenMajorStorageDataSource + abstract fun bindLocalOpenMajorDataSource( + localOpenMajorDataSourceImpl: LocalOpenMajorDataSourceImpl, + ): LocalOpenMajorDataSource } From 3d1f7579bdfa5b32b4c17e427f246674efd8c1d0 Mon Sep 17 00:00:00 2001 From: jinukeu Date: Fri, 20 Oct 2023 15:34:44 +0900 Subject: [PATCH 02/14] =?UTF-8?q?feat:=20OpenMajorRepository=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/openmajor/di/RepositoryModule.kt | 20 ++++++++ .../repository/OpenMajorRepositoryImpl.kt | 51 +++++++++++++++++++ domain/openmajor/build.gradle.kts | 9 ++++ .../repository/OpenMajorRepository.kt | 9 ++++ settings.gradle.kts | 1 + 5 files changed, 90 insertions(+) create mode 100644 data/openmajor/src/main/java/com/suwiki/data/openmajor/di/RepositoryModule.kt create mode 100644 data/openmajor/src/main/java/com/suwiki/data/openmajor/repository/OpenMajorRepositoryImpl.kt create mode 100644 domain/openmajor/build.gradle.kts create mode 100644 domain/openmajor/src/main/java/com/suwiki/domain/openmajor/repository/OpenMajorRepository.kt diff --git a/data/openmajor/src/main/java/com/suwiki/data/openmajor/di/RepositoryModule.kt b/data/openmajor/src/main/java/com/suwiki/data/openmajor/di/RepositoryModule.kt new file mode 100644 index 000000000..1c5ae585d --- /dev/null +++ b/data/openmajor/src/main/java/com/suwiki/data/openmajor/di/RepositoryModule.kt @@ -0,0 +1,20 @@ +package com.suwiki.data.openmajor.di + +import com.suwiki.data.openmajor.repository.OpenMajorRepositoryImpl +import com.suwiki.domain.openmajor.repository.OpenMajorRepository +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +abstract class RemoteRepositoryModule { + + @Singleton + @Binds + abstract fun bindOpenMajorRepository( + openMajorRepositoryImpl: OpenMajorRepositoryImpl, + ): OpenMajorRepository +} diff --git a/data/openmajor/src/main/java/com/suwiki/data/openmajor/repository/OpenMajorRepositoryImpl.kt b/data/openmajor/src/main/java/com/suwiki/data/openmajor/repository/OpenMajorRepositoryImpl.kt new file mode 100644 index 000000000..aebe6f1be --- /dev/null +++ b/data/openmajor/src/main/java/com/suwiki/data/openmajor/repository/OpenMajorRepositoryImpl.kt @@ -0,0 +1,51 @@ +package com.suwiki.data.openmajor.repository + +import com.suwiki.core.model.openmajor.OpenMajor +import com.suwiki.data.openmajor.datasource.LocalOpenMajorDataSource +import com.suwiki.data.openmajor.datasource.RemoteOpenMajorDataSource +import com.suwiki.domain.openmajor.repository.OpenMajorRepository +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.firstOrNull +import kotlinx.coroutines.flow.flow +import timber.log.Timber +import javax.inject.Inject + +class OpenMajorRepositoryImpl @Inject constructor( + private val localOpenMajorDataSource: LocalOpenMajorDataSource, + private val remoteOpenMajorDataSource: RemoteOpenMajorDataSource, +) : OpenMajorRepository { + override suspend fun getOpenMajorList(): Flow> = flow { + Timber.d("local Major List emit = ${localOpenMajorDataSource.getLocalOpenMajorList().map { it.name }}") + emit(localOpenMajorDataSource.getLocalOpenMajorList().map { it.name }) + + val localVersion = localOpenMajorDataSource.getLocalOpenMajorVersion().firstOrNull() ?: 0f + val remoteVersion = remoteOpenMajorDataSource.getOpenMajorVersion() + + Timber.d("localVersion = $localVersion, remoteVersion = $remoteVersion") + + if (remoteVersion > localVersion) { + val remoteOpenMajorList = remoteOpenMajorDataSource.getOpenMajorList() + Timber.d("local Major List emit = $remoteOpenMajorList") + + emit(remoteOpenMajorList) + + with(localOpenMajorDataSource) { + deleteAllOpenMajors() + saveAllOpenMajors( + remoteOpenMajorList.mapIndexed { index, major -> + OpenMajor(id = index, name = major) + }, + ) + setLocalOpenMajorVersion(remoteVersion) + } + } + } + + override suspend fun bookmarkMajor(majorName: String) { + remoteOpenMajorDataSource.bookmarkMajor(majorName) + } + + override suspend fun removeBookmarkMajor(majorName: String) { + remoteOpenMajorDataSource.removeBookmarkMajor(majorName) + } +} diff --git a/domain/openmajor/build.gradle.kts b/domain/openmajor/build.gradle.kts new file mode 100644 index 000000000..929e33885 --- /dev/null +++ b/domain/openmajor/build.gradle.kts @@ -0,0 +1,9 @@ +@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed +plugins { + id("suwiki.java.library") +} + +dependencies { + implementation(libs.kotlinx.coroutines.core) + implementation(libs.hilt.core) +} diff --git a/domain/openmajor/src/main/java/com/suwiki/domain/openmajor/repository/OpenMajorRepository.kt b/domain/openmajor/src/main/java/com/suwiki/domain/openmajor/repository/OpenMajorRepository.kt new file mode 100644 index 000000000..574db7d0f --- /dev/null +++ b/domain/openmajor/src/main/java/com/suwiki/domain/openmajor/repository/OpenMajorRepository.kt @@ -0,0 +1,9 @@ +package com.suwiki.domain.openmajor.repository + +import kotlinx.coroutines.flow.Flow + +interface OpenMajorRepository { + suspend fun getOpenMajorList(): Flow> + suspend fun bookmarkMajor(majorName: String) + suspend fun removeBookmarkMajor(majorName: String) +} diff --git a/settings.gradle.kts b/settings.gradle.kts index a5fd2902a..ad7935593 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -52,3 +52,4 @@ include(":data:lectureevaluation:my") include(":data:user") include(":data:notice") include(":data:signup") +include(":domain:openmajor") From 231bcd15ddb754ca7aa77f27c3ad1d2f50f64e51 Mon Sep 17 00:00:00 2001 From: jinukeu Date: Fri, 20 Oct 2023 15:48:13 +0900 Subject: [PATCH 03/14] =?UTF-8?q?feat:=20OpenMajor=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?UseCase=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/GetOpenMajorListUseCase.kt | 21 +++++++++++++++++++ .../usecase/RegisterBookmarkUseCase.kt | 14 +++++++++++++ .../usecase/UnRegisterBookmarkUseCase.kt | 14 +++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 domain/openmajor/src/main/java/com/suwiki/domain/openmajor/usecase/GetOpenMajorListUseCase.kt create mode 100644 domain/openmajor/src/main/java/com/suwiki/domain/openmajor/usecase/RegisterBookmarkUseCase.kt create mode 100644 domain/openmajor/src/main/java/com/suwiki/domain/openmajor/usecase/UnRegisterBookmarkUseCase.kt diff --git a/domain/openmajor/src/main/java/com/suwiki/domain/openmajor/usecase/GetOpenMajorListUseCase.kt b/domain/openmajor/src/main/java/com/suwiki/domain/openmajor/usecase/GetOpenMajorListUseCase.kt new file mode 100644 index 000000000..894bcad89 --- /dev/null +++ b/domain/openmajor/src/main/java/com/suwiki/domain/openmajor/usecase/GetOpenMajorListUseCase.kt @@ -0,0 +1,21 @@ +package com.suwiki.domain.openmajor.usecase + +import com.suwiki.domain.openmajor.repository.OpenMajorRepository +import kotlinx.coroutines.flow.Flow +import javax.inject.Inject + +class GetOpenMajorListUseCase @Inject constructor( + private val openMajorRepository: OpenMajorRepository, +) { + /** + * 가장 먼저 LocalOpenMajorList를 emit합니다. + * 그 이후 LocalVersion과 RemoteVersion을 비교한 후 + * 만약 RemoteVersion이 더 크다면 최신 데이터가 존재하는 것이므로 + * RemoteOpenMajorList를 받아온 후 emit합니다. + * + * 그 이후 LocalVersion과 LocalOpenMajorList를 최신화 합니다. + */ + suspend operator fun invoke(): Flow> { + return openMajorRepository.getOpenMajorList() + } +} diff --git a/domain/openmajor/src/main/java/com/suwiki/domain/openmajor/usecase/RegisterBookmarkUseCase.kt b/domain/openmajor/src/main/java/com/suwiki/domain/openmajor/usecase/RegisterBookmarkUseCase.kt new file mode 100644 index 000000000..12f15519a --- /dev/null +++ b/domain/openmajor/src/main/java/com/suwiki/domain/openmajor/usecase/RegisterBookmarkUseCase.kt @@ -0,0 +1,14 @@ +package com.suwiki.domain.openmajor.usecase + +import com.suwiki.domain.openmajor.repository.OpenMajorRepository +import javax.inject.Inject + +class RegisterBookmarkUseCase @Inject constructor( + private val openMajorRepository: OpenMajorRepository, +) { + suspend operator fun invoke(request: String): Result = kotlin.runCatching { + openMajorRepository.bookmarkMajor( + request, + ) + } +} diff --git a/domain/openmajor/src/main/java/com/suwiki/domain/openmajor/usecase/UnRegisterBookmarkUseCase.kt b/domain/openmajor/src/main/java/com/suwiki/domain/openmajor/usecase/UnRegisterBookmarkUseCase.kt new file mode 100644 index 000000000..460be4bd2 --- /dev/null +++ b/domain/openmajor/src/main/java/com/suwiki/domain/openmajor/usecase/UnRegisterBookmarkUseCase.kt @@ -0,0 +1,14 @@ +package com.suwiki.domain.openmajor.usecase + +import com.suwiki.domain.openmajor.repository.OpenMajorRepository +import javax.inject.Inject + +class UnRegisterBookmarkUseCase @Inject constructor( + private val openMajorRepository: OpenMajorRepository, +) { + suspend operator fun invoke(request: String): Result = kotlin.runCatching { + openMajorRepository.removeBookmarkMajor( + request, + ) + } +} From 9f68ae1ee2aee6b1101f39b2af15b07ce589624f Mon Sep 17 00:00:00 2001 From: jinukeu Date: Fri, 20 Oct 2023 16:19:49 +0900 Subject: [PATCH 04/14] =?UTF-8?q?chore:=20presentation=20=EB=AA=A8?= =?UTF-8?q?=EB=93=88=20=EC=BB=B4=ED=8F=AC=EC=A6=88=20=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app-compose/build.gradle.kts | 7 +- app-compose/src/main/AndroidManifest.xml | 14 +--- .../kunize/uswtimetable/SuwikiApplication.kt | 13 ++++ gradle/libs.versions.toml | 2 + presentation/build.gradle.kts | 37 +--------- presentation/src/main/AndroidManifest.xml | 15 ++++ .../mangbaam/presentation}/MainActivity.kt | 6 +- .../mangbaam/presentation/ui/theme/Color.kt | 11 +++ .../mangbaam/presentation/ui/theme/Theme.kt | 70 +++++++++++++++++++ .../mangbaam/presentation/ui/theme/Type.kt | 34 +++++++++ presentation/src/main/res/values/strings.xml | 3 + presentation/src/main/res/values/themes.xml | 5 ++ 12 files changed, 166 insertions(+), 51 deletions(-) create mode 100644 app-compose/src/main/java/com/kunize/uswtimetable/SuwikiApplication.kt rename {app-compose/src/main/java/com/kunize/uswtimetable => presentation/src/main/java/com/mangbaam/presentation}/MainActivity.kt (90%) create mode 100644 presentation/src/main/java/com/mangbaam/presentation/ui/theme/Color.kt create mode 100644 presentation/src/main/java/com/mangbaam/presentation/ui/theme/Theme.kt create mode 100644 presentation/src/main/java/com/mangbaam/presentation/ui/theme/Type.kt create mode 100644 presentation/src/main/res/values/strings.xml create mode 100644 presentation/src/main/res/values/themes.xml diff --git a/app-compose/build.gradle.kts b/app-compose/build.gradle.kts index 90cd85f3f..8142604e9 100644 --- a/app-compose/build.gradle.kts +++ b/app-compose/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("suwiki.android.application") id("suwiki.android.application.compose") + id("suwiki.android.hilt") } android { @@ -41,7 +42,7 @@ dependencies { implementation(projects.data.notice) implementation(projects.data.signup) - implementation(projects.domain) + implementation(projects.domain.openmajor) implementation(projects.di) implementation(projects.local.openmajor) @@ -58,4 +59,8 @@ dependencies { implementation(projects.remote.signup) implementation(projects.remote.timetable.viewer) implementation(projects.remote.user) + + implementation(projects.presentation) + + implementation(libs.timber) } diff --git a/app-compose/src/main/AndroidManifest.xml b/app-compose/src/main/AndroidManifest.xml index ca715fbdb..b81d7d3e4 100644 --- a/app-compose/src/main/AndroidManifest.xml +++ b/app-compose/src/main/AndroidManifest.xml @@ -2,23 +2,13 @@ - - - - - - - \ No newline at end of file diff --git a/app-compose/src/main/java/com/kunize/uswtimetable/SuwikiApplication.kt b/app-compose/src/main/java/com/kunize/uswtimetable/SuwikiApplication.kt new file mode 100644 index 000000000..6be335fa2 --- /dev/null +++ b/app-compose/src/main/java/com/kunize/uswtimetable/SuwikiApplication.kt @@ -0,0 +1,13 @@ +package com.kunize.uswtimetable + +import android.app.Application +import dagger.hilt.android.HiltAndroidApp +import timber.log.Timber + +@HiltAndroidApp +class SuwikiApplication : Application() { + override fun onCreate() { + super.onCreate() + if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree()) + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4bb9f20b5..4dea9eded 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -52,6 +52,7 @@ oss = "17.0.1" junit = "1.1.5" espresso-core = "3.5.1" androidx-test-ext-junit = "1.1.5" +androidx-compose-compose-bom = "2023.03.00" [plugins] ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } @@ -142,6 +143,7 @@ oss = { group = "com.google.android.gms", name = "play-services-oss-licenses", v junit = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "junit" } espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso-core" } androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-ext-junit" } +androidx-compose-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "androidx-compose-compose-bom" } [bundles] firebase = ["firebase-analytics", "firebase-database"] diff --git a/presentation/build.gradle.kts b/presentation/build.gradle.kts index 6d76c56ca..26eb3e002 100644 --- a/presentation/build.gradle.kts +++ b/presentation/build.gradle.kts @@ -1,44 +1,11 @@ plugins { - id("com.android.library") - id("org.jetbrains.kotlin.android") + id("suwiki.android.feature.compose") } android { namespace = "com.mangbaam.presentation" - compileSdk = 33 - - defaultConfig { - minSdk = 26 - - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") - } - - buildTypes { - release { - isMinifyEnabled = false - proguardFiles( - getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro", - ) - } - } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 - } - kotlinOptions { - jvmTarget = "17" - } } dependencies { - implementation(project(":domain")) - - implementation("androidx.core:core-ktx:1.10.1") - implementation("androidx.appcompat:appcompat:1.6.1") - implementation("com.google.android.material:material:1.9.0") - testImplementation("junit:junit:4.13.2") - androidTestImplementation("androidx.test.ext:junit:1.1.5") - androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") + implementation(projects.domain.openmajor) } diff --git a/presentation/src/main/AndroidManifest.xml b/presentation/src/main/AndroidManifest.xml index a5918e68a..bd42ef156 100644 --- a/presentation/src/main/AndroidManifest.xml +++ b/presentation/src/main/AndroidManifest.xml @@ -1,4 +1,19 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app-compose/src/main/java/com/kunize/uswtimetable/MainActivity.kt b/presentation/src/main/java/com/mangbaam/presentation/MainActivity.kt similarity index 90% rename from app-compose/src/main/java/com/kunize/uswtimetable/MainActivity.kt rename to presentation/src/main/java/com/mangbaam/presentation/MainActivity.kt index 3edc6e9a2..350ff5691 100644 --- a/app-compose/src/main/java/com/kunize/uswtimetable/MainActivity.kt +++ b/presentation/src/main/java/com/mangbaam/presentation/MainActivity.kt @@ -1,4 +1,4 @@ -package com.kunize.uswtimetable +package com.mangbaam.presentation import android.os.Bundle import androidx.activity.ComponentActivity @@ -10,7 +10,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview -import com.kunize.uswtimetable.ui.theme.UswtimetableTheme +import com.mangbaam.presentation.ui.theme.UswtimetableTheme class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -22,7 +22,7 @@ class MainActivity : ComponentActivity() { modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background ) { - Greeting("Android") + Greeting("Suwiki") } } } diff --git a/presentation/src/main/java/com/mangbaam/presentation/ui/theme/Color.kt b/presentation/src/main/java/com/mangbaam/presentation/ui/theme/Color.kt new file mode 100644 index 000000000..921ad6c02 --- /dev/null +++ b/presentation/src/main/java/com/mangbaam/presentation/ui/theme/Color.kt @@ -0,0 +1,11 @@ +package com.mangbaam.presentation.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) \ No newline at end of file diff --git a/presentation/src/main/java/com/mangbaam/presentation/ui/theme/Theme.kt b/presentation/src/main/java/com/mangbaam/presentation/ui/theme/Theme.kt new file mode 100644 index 000000000..72173bb74 --- /dev/null +++ b/presentation/src/main/java/com/mangbaam/presentation/ui/theme/Theme.kt @@ -0,0 +1,70 @@ +package com.mangbaam.presentation.ui.theme + +import android.app.Activity +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalView +import androidx.core.view.WindowCompat + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun UswtimetableTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + val view = LocalView.current + if (!view.isInEditMode) { + SideEffect { + val window = (view.context as Activity).window + window.statusBarColor = colorScheme.primary.toArgb() + WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme + } + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} \ No newline at end of file diff --git a/presentation/src/main/java/com/mangbaam/presentation/ui/theme/Type.kt b/presentation/src/main/java/com/mangbaam/presentation/ui/theme/Type.kt new file mode 100644 index 000000000..97c40d863 --- /dev/null +++ b/presentation/src/main/java/com/mangbaam/presentation/ui/theme/Type.kt @@ -0,0 +1,34 @@ +package com.mangbaam.presentation.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ +) \ No newline at end of file diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml new file mode 100644 index 000000000..2ca737562 --- /dev/null +++ b/presentation/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + MainActivity + \ No newline at end of file diff --git a/presentation/src/main/res/values/themes.xml b/presentation/src/main/res/values/themes.xml new file mode 100644 index 000000000..af139c76f --- /dev/null +++ b/presentation/src/main/res/values/themes.xml @@ -0,0 +1,5 @@ + + + +