From cf2c6b4c8186550668695ce42230f8abf844e246 Mon Sep 17 00:00:00 2001 From: Hyesung82 Date: Sun, 17 Mar 2024 02:34:55 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=EA=B8=B0=EB=B3=B8=20=EA=B7=B8?= =?UTF-8?q?=EB=A3=B9=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + data/build.gradle | 10 +++++ .../com/cheocharm/data/di/DataSourceModule.kt | 10 ++++- .../com/cheocharm/data/di/DatabaseModule.kt | 45 +++++++++++++++++++ .../cheocharm/data/local/model/AppDatabase.kt | 12 +++++ .../cheocharm/data/local/model/Converters.kt | 20 +++++++++ .../com/cheocharm/data/local/model/Group.kt | 16 +++++++ .../cheocharm/data/local/model/GroupDao.kt | 21 +++++++++ .../cheocharm/data/local/model/GroupMember.kt | 10 +++++ .../data/local/model/GroupMemberCrossRef.kt | 9 ++++ .../data/local/model/GroupWithMembers.kt | 15 +++++++ .../local/source/MyGroupsLocalDataSource.kt | 9 ++++ .../source/MyGroupsLocalDataSourceImpl.kt | 20 +++++++++ .../com/cheocharm/data/mapper/WriteMapper.kt | 4 ++ .../data/repository/GroupRepositoryImpl.kt | 18 +++++++- .../data/repository/MyGroupsRepositoryImpl.kt | 37 ++++++++------- .../domain/repository/GroupRepository.kt | 6 +++ .../usecase/group/CreateGroupUseCase.kt | 17 +++++++ gradle.properties | 1 + .../cheocharm/presentation/ui/MainActivity.kt | 25 +++++++++++ .../presentation/ui/write/WriteViewModel.kt | 5 ++- 21 files changed, 291 insertions(+), 20 deletions(-) create mode 100644 data/src/main/java/com/cheocharm/data/di/DatabaseModule.kt create mode 100644 data/src/main/java/com/cheocharm/data/local/model/AppDatabase.kt create mode 100644 data/src/main/java/com/cheocharm/data/local/model/Converters.kt create mode 100644 data/src/main/java/com/cheocharm/data/local/model/Group.kt create mode 100644 data/src/main/java/com/cheocharm/data/local/model/GroupDao.kt create mode 100644 data/src/main/java/com/cheocharm/data/local/model/GroupMember.kt create mode 100644 data/src/main/java/com/cheocharm/data/local/model/GroupMemberCrossRef.kt create mode 100644 data/src/main/java/com/cheocharm/data/local/model/GroupWithMembers.kt create mode 100644 data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSource.kt create mode 100644 data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSourceImpl.kt create mode 100644 domain/src/main/java/com/cheocharm/domain/usecase/group/CreateGroupUseCase.kt diff --git a/build.gradle b/build.gradle index 6ac4ba51..480455f3 100644 --- a/build.gradle +++ b/build.gradle @@ -11,6 +11,7 @@ plugins { id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1' apply false id 'com.google.dagger.hilt.android' version '2.48.1' apply false id 'androidx.navigation.safeargs.kotlin' version "${navVersion}" apply false + id 'com.google.devtools.ksp' version '1.9.20-1.0.14' apply false } tasks.register('clean', Delete) { diff --git a/data/build.gradle b/data/build.gradle index 42eaf963..d41824d6 100644 --- a/data/build.gradle +++ b/data/build.gradle @@ -3,6 +3,7 @@ plugins { id 'org.jetbrains.kotlin.android' id 'kotlin-kapt' id 'com.google.dagger.hilt.android' + id 'com.google.devtools.ksp' } Properties properties = new Properties() @@ -61,4 +62,13 @@ dependencies { implementation "com.squareup.retrofit2:retrofit:$retrofitVersion" implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion" implementation "com.squareup.okhttp3:logging-interceptor:4.9.3" + + // Room + implementation "androidx.room:room-runtime:$roomVersion" + annotationProcessor "androidx.room:room-compiler:$roomVersion" + ksp "androidx.room:room-compiler:$roomVersion" + implementation "androidx.room:room-paging:$roomVersion" + + // Gson + implementation 'com.google.code.gson:gson:2.10.1' } diff --git a/data/src/main/java/com/cheocharm/data/di/DataSourceModule.kt b/data/src/main/java/com/cheocharm/data/di/DataSourceModule.kt index 6359b4ff..1c44aa4d 100644 --- a/data/src/main/java/com/cheocharm/data/di/DataSourceModule.kt +++ b/data/src/main/java/com/cheocharm/data/di/DataSourceModule.kt @@ -2,6 +2,8 @@ package com.cheocharm.data.di import com.cheocharm.data.local.source.AuthLocalDataSource import com.cheocharm.data.local.source.AuthLocalDataSourceImpl +import com.cheocharm.data.local.source.MyGroupsLocalDataSource +import com.cheocharm.data.local.source.MyGroupsLocalDataSourceImpl import com.cheocharm.data.remote.source.AuthRemoteDataSource import com.cheocharm.data.remote.source.AuthRemoteDataSourceImpl import com.cheocharm.data.remote.source.GroupRemoteDataSource @@ -23,11 +25,11 @@ import javax.inject.Singleton internal abstract class DataSourceModule { @Binds @Singleton - abstract fun bindAuthLocalDataSource(dataSourceImpl: AuthLocalDataSourceImpl): AuthLocalDataSource + abstract fun bindLoginRemoteDataSource(dataSource: LoginRemoteDataSourceImpl): LoginRemoteDataSource @Binds @Singleton - abstract fun bindLoginRemoteDataSource(dataSource: LoginRemoteDataSourceImpl): LoginRemoteDataSource + abstract fun bindAuthLocalDataSource(dataSourceImpl: AuthLocalDataSourceImpl): AuthLocalDataSource @Binds @Singleton @@ -37,6 +39,10 @@ internal abstract class DataSourceModule { @Singleton abstract fun bindGroupRemoteDataSource(dataSource: GroupRemoteDataSourceImpl): GroupRemoteDataSource + @Binds + @Singleton + abstract fun bindMyGroupsLocalDataSource(dataSource: MyGroupsLocalDataSourceImpl): MyGroupsLocalDataSource + @Binds @Singleton abstract fun bindMyGroupsRemoteDataSource(dataSource: MyGroupsRemoteDataSourceImpl): MyGroupsRemoteDataSource diff --git a/data/src/main/java/com/cheocharm/data/di/DatabaseModule.kt b/data/src/main/java/com/cheocharm/data/di/DatabaseModule.kt new file mode 100644 index 00000000..edfe7da1 --- /dev/null +++ b/data/src/main/java/com/cheocharm/data/di/DatabaseModule.kt @@ -0,0 +1,45 @@ +package com.cheocharm.data.di + +import android.content.Context +import androidx.room.Room +import com.cheocharm.data.local.model.AppDatabase +import com.cheocharm.data.local.model.Converters +import com.cheocharm.data.local.model.GroupDao +import com.google.gson.Gson +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 + +@InstallIn(SingletonComponent::class) +@Module +class DatabaseModule { + @Provides + fun provideGroupDao(appDatabase: AppDatabase): GroupDao { + return appDatabase.groupDao() + } + + @Provides + @Singleton + fun provideAppDatabase(@ApplicationContext appContext: Context, gson: Gson): AppDatabase { + return Room.databaseBuilder( + appContext, + AppDatabase::class.java, + DB_NAME + ) + .addTypeConverter(Converters(gson)) + .build() + } + + @Provides + @Singleton + fun provideGson(): Gson { + return Gson() + } + + companion object { + private const val DB_NAME = "mapz.db" + } +} diff --git a/data/src/main/java/com/cheocharm/data/local/model/AppDatabase.kt b/data/src/main/java/com/cheocharm/data/local/model/AppDatabase.kt new file mode 100644 index 00000000..ce8717f5 --- /dev/null +++ b/data/src/main/java/com/cheocharm/data/local/model/AppDatabase.kt @@ -0,0 +1,12 @@ +package com.cheocharm.data.local.model + +import androidx.room.Database +import androidx.room.RoomDatabase +import androidx.room.TypeConverter +import androidx.room.TypeConverters + +@Database(entities = [Group::class], version = 1) +@TypeConverters(Converters::class) +abstract class AppDatabase : RoomDatabase() { + abstract fun groupDao(): GroupDao +} diff --git a/data/src/main/java/com/cheocharm/data/local/model/Converters.kt b/data/src/main/java/com/cheocharm/data/local/model/Converters.kt new file mode 100644 index 00000000..4d6046a0 --- /dev/null +++ b/data/src/main/java/com/cheocharm/data/local/model/Converters.kt @@ -0,0 +1,20 @@ +package com.cheocharm.data.local.model + +import androidx.room.ProvidedTypeConverter +import androidx.room.TypeConverter +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken + +@ProvidedTypeConverter +class Converters(private val gson: Gson) { + @TypeConverter + fun fromMembers(value: List?): String? { + return gson.toJson(value) + } + + @TypeConverter + fun stringToMember(string: String?): List? { + val collectionType = object : TypeToken>() {}.type + return gson.fromJson(string, collectionType) + } +} diff --git a/data/src/main/java/com/cheocharm/data/local/model/Group.kt b/data/src/main/java/com/cheocharm/data/local/model/Group.kt new file mode 100644 index 00000000..603b17f4 --- /dev/null +++ b/data/src/main/java/com/cheocharm/data/local/model/Group.kt @@ -0,0 +1,16 @@ +package com.cheocharm.data.local.model + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity +data class Group( + @PrimaryKey val id: Int, + val name: String, + val bio: String, + @ColumnInfo(name = "created_at") val createdAt: String, + val members: List, + @ColumnInfo(name = "number_of_members") val numberOfMembers: Int, + @ColumnInfo(name = "group_image_url") val groupImageUrl: String? = null +) diff --git a/data/src/main/java/com/cheocharm/data/local/model/GroupDao.kt b/data/src/main/java/com/cheocharm/data/local/model/GroupDao.kt new file mode 100644 index 00000000..0bab330d --- /dev/null +++ b/data/src/main/java/com/cheocharm/data/local/model/GroupDao.kt @@ -0,0 +1,21 @@ +package com.cheocharm.data.local.model + +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.Query + +@Dao +interface GroupDao { + @Query("SELECT * FROM `group`") + fun getAll(): List + + @Query("SELECT * FROM `group` WHERE id = :groupId") + fun findById(groupId: Int): Group + + @Insert + fun insertAll(vararg groups: Group) + + @Delete + fun delete(group: Group) +} diff --git a/data/src/main/java/com/cheocharm/data/local/model/GroupMember.kt b/data/src/main/java/com/cheocharm/data/local/model/GroupMember.kt new file mode 100644 index 00000000..a1c0cd85 --- /dev/null +++ b/data/src/main/java/com/cheocharm/data/local/model/GroupMember.kt @@ -0,0 +1,10 @@ +package com.cheocharm.data.local.model + +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity +data class GroupMember( + @PrimaryKey val memberId: Int, + val imageUrl: String? = null +) diff --git a/data/src/main/java/com/cheocharm/data/local/model/GroupMemberCrossRef.kt b/data/src/main/java/com/cheocharm/data/local/model/GroupMemberCrossRef.kt new file mode 100644 index 00000000..79089121 --- /dev/null +++ b/data/src/main/java/com/cheocharm/data/local/model/GroupMemberCrossRef.kt @@ -0,0 +1,9 @@ +package com.cheocharm.data.local.model + +import androidx.room.Entity + +@Entity(primaryKeys = ["groupId", "memberId"]) +data class GroupMemberCrossRef( + val groupId: Int, + val memberId: Int +) diff --git a/data/src/main/java/com/cheocharm/data/local/model/GroupWithMembers.kt b/data/src/main/java/com/cheocharm/data/local/model/GroupWithMembers.kt new file mode 100644 index 00000000..3fadc49c --- /dev/null +++ b/data/src/main/java/com/cheocharm/data/local/model/GroupWithMembers.kt @@ -0,0 +1,15 @@ +package com.cheocharm.data.local.model + +import androidx.room.Embedded +import androidx.room.Junction +import androidx.room.Relation + +data class GroupWithMembers( + @Embedded val group: Group, + @Relation( + parentColumn = "groupId", + entityColumn = "memberId", + associateBy = Junction(GroupMemberCrossRef::class) + ) + val members: List +) diff --git a/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSource.kt b/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSource.kt new file mode 100644 index 00000000..4b987180 --- /dev/null +++ b/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSource.kt @@ -0,0 +1,9 @@ +package com.cheocharm.data.local.source + +import com.cheocharm.domain.model.Group + +interface MyGroupsLocalDataSource { + suspend fun getMyGroups(): List + + suspend fun joinGroup(group: com.cheocharm.data.local.model.Group) +} diff --git a/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSourceImpl.kt b/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSourceImpl.kt new file mode 100644 index 00000000..1ca7c5f1 --- /dev/null +++ b/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSourceImpl.kt @@ -0,0 +1,20 @@ +package com.cheocharm.data.local.source + +import com.cheocharm.data.local.model.GroupDao +import com.cheocharm.data.mapper.toDomain +import com.cheocharm.domain.model.Group +import javax.inject.Inject + +class MyGroupsLocalDataSourceImpl @Inject constructor( + private val groupDao: GroupDao +): MyGroupsLocalDataSource { + override suspend fun getMyGroups(): List { + return groupDao.getAll().map { + it.toDomain() + } + } + + override suspend fun joinGroup(group: com.cheocharm.data.local.model.Group) { + groupDao.insertAll(group) + } +} diff --git a/data/src/main/java/com/cheocharm/data/mapper/WriteMapper.kt b/data/src/main/java/com/cheocharm/data/mapper/WriteMapper.kt index c7065d62..9e464901 100644 --- a/data/src/main/java/com/cheocharm/data/mapper/WriteMapper.kt +++ b/data/src/main/java/com/cheocharm/data/mapper/WriteMapper.kt @@ -14,3 +14,7 @@ internal fun GroupData.toDomain(): Group = groupMembersImageUrls.size, groupImageUrl ) + +internal fun com.cheocharm.data.local.model.Group.toDomain(): Group = Group( + id, name, bio, createdAt, members.map { GroupMember(it.imageUrl) }, numberOfMembers, groupImageUrl +) diff --git a/data/src/main/java/com/cheocharm/data/repository/GroupRepositoryImpl.kt b/data/src/main/java/com/cheocharm/data/repository/GroupRepositoryImpl.kt index bc0fb313..3304d942 100644 --- a/data/src/main/java/com/cheocharm/data/repository/GroupRepositoryImpl.kt +++ b/data/src/main/java/com/cheocharm/data/repository/GroupRepositoryImpl.kt @@ -3,15 +3,31 @@ package com.cheocharm.data.repository import androidx.paging.PagingData import com.cheocharm.data.error.ErrorData import com.cheocharm.data.error.toDomain +import com.cheocharm.data.local.source.MyGroupsLocalDataSource import com.cheocharm.data.remote.source.GroupRemoteDataSource import com.cheocharm.domain.model.Group +import com.cheocharm.domain.model.GroupMember import com.cheocharm.domain.repository.GroupRepository import kotlinx.coroutines.flow.Flow import javax.inject.Inject class GroupRepositoryImpl @Inject constructor( - private val groupRemoteDataSource: GroupRemoteDataSource + private val groupRemoteDataSource: GroupRemoteDataSource, + private val myGroupsLocalDataSource: MyGroupsLocalDataSource ) : GroupRepository { + private var count = 0 + + override suspend fun createGroup(userId: Int, name: String, bio: String, groupImageUrl: String) { + val group = com.cheocharm.data.local.model.Group( + count++, + name, + "", + "", + listOf(com.cheocharm.data.local.model.GroupMember(userId)), + 1 + ) + myGroupsLocalDataSource.joinGroup(group) + } override fun searchGroup(searchGroupName: String): Flow> { return groupRemoteDataSource.fetchGroupSearchList(searchGroupName) diff --git a/data/src/main/java/com/cheocharm/data/repository/MyGroupsRepositoryImpl.kt b/data/src/main/java/com/cheocharm/data/repository/MyGroupsRepositoryImpl.kt index b9b4545e..8415e6bb 100644 --- a/data/src/main/java/com/cheocharm/data/repository/MyGroupsRepositoryImpl.kt +++ b/data/src/main/java/com/cheocharm/data/repository/MyGroupsRepositoryImpl.kt @@ -1,29 +1,36 @@ package com.cheocharm.data.repository -import com.cheocharm.data.error.ErrorData -import com.cheocharm.data.error.toDomain -import com.cheocharm.data.mapper.toDomain +import com.cheocharm.data.local.source.MyGroupsLocalDataSource import com.cheocharm.data.remote.source.MyGroupsRemoteDataSource import com.cheocharm.domain.model.Group import com.cheocharm.domain.repository.MyGroupsRepository import javax.inject.Inject class MyGroupsRepositoryImpl @Inject constructor( - private val dataSource: MyGroupsRemoteDataSource + private val remoteDataSource: MyGroupsRemoteDataSource, + private val localDataSource: MyGroupsLocalDataSource ) : MyGroupsRepository { override suspend fun getMyGroups(): Result> { - val result = dataSource.getMyGroups().mapCatching { - it.map { data -> - data.toDomain() - } - } - val exception = result.exceptionOrNull() +// val result = remoteDataSource.getMyGroups().mapCatching { +// it.map { data -> +// data.toDomain() +// } +// } +// val exception = result.exceptionOrNull() +// +// return if (exception is ErrorData) { +// Result.failure(exception.toDomain()) +// } else { +// result +// } - return if (exception is ErrorData) { - Result.failure(exception.toDomain()) - } else { - result - } + return getMyGroupsFromLocalDatabase() + } + + private suspend fun getMyGroupsFromLocalDatabase(): Result> { + val myGroups = localDataSource.getMyGroups() + + return Result.success(myGroups) } } diff --git a/domain/src/main/java/com/cheocharm/domain/repository/GroupRepository.kt b/domain/src/main/java/com/cheocharm/domain/repository/GroupRepository.kt index dfef6d25..94db3367 100644 --- a/domain/src/main/java/com/cheocharm/domain/repository/GroupRepository.kt +++ b/domain/src/main/java/com/cheocharm/domain/repository/GroupRepository.kt @@ -5,6 +5,12 @@ import com.cheocharm.domain.model.Group import kotlinx.coroutines.flow.Flow interface GroupRepository { + suspend fun createGroup( + userId: Int, + name: String, + bio: String, + groupImageUrl: String + ) fun searchGroup(searchGroupName: String): Flow> diff --git a/domain/src/main/java/com/cheocharm/domain/usecase/group/CreateGroupUseCase.kt b/domain/src/main/java/com/cheocharm/domain/usecase/group/CreateGroupUseCase.kt new file mode 100644 index 00000000..095ea3ed --- /dev/null +++ b/domain/src/main/java/com/cheocharm/domain/usecase/group/CreateGroupUseCase.kt @@ -0,0 +1,17 @@ +package com.cheocharm.domain.usecase.group + +import com.cheocharm.domain.repository.GroupRepository +import javax.inject.Inject + +class CreateGroupUseCase @Inject constructor( + private val groupRepository: GroupRepository +) { + suspend operator fun invoke( + userId: Int, + name: String, + bio: String, + groupImageUrl: String + ) { + return groupRepository.createGroup(userId, name, bio, groupImageUrl) + } +} diff --git a/gradle.properties b/gradle.properties index 97dca94f..83327066 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,3 +32,4 @@ coroutineVersion=1.6.3 glideVersion=4.12.0 pagingVersion=3.2.1 jvmTarget=17 +roomVersion = 2.6.1 diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/MainActivity.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/MainActivity.kt index 670002d9..4860cdfc 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/MainActivity.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/MainActivity.kt @@ -15,6 +15,8 @@ import androidx.core.view.WindowInsetsControllerCompat import androidx.core.view.isVisible import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.setupWithNavController +import com.cheocharm.domain.usecase.group.CreateGroupUseCase +import com.cheocharm.domain.usecase.write.GetMyGroupsUseCase import com.cheocharm.presentation.R import com.cheocharm.presentation.base.BaseActivity import com.cheocharm.presentation.databinding.ActivityMainBinding @@ -22,6 +24,10 @@ import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices import com.google.android.gms.maps.SupportMapFragment import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import javax.inject.Inject @AndroidEntryPoint class MainActivity : BaseActivity(R.layout.activity_main) { @@ -47,6 +53,11 @@ class MainActivity : BaseActivity(R.layout.activity_main) { } } + @Inject + lateinit var getMyGroupsUseCase: GetMyGroupsUseCase + @Inject + lateinit var createGroupUseCase: CreateGroupUseCase + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -69,6 +80,20 @@ class MainActivity : BaseActivity(R.layout.activity_main) { mapFragment = supportFragmentManager.findFragmentById(R.id.fragment_main_map) as? SupportMapFragment + + initMyGroups() // 오프라인 모드 + } + + private fun initMyGroups() { + CoroutineScope(Dispatchers.IO).launch { + val result = getMyGroupsUseCase.invoke() + + result.onFailure { + for (i in 1..3) { + createGroupUseCase.invoke(0, "그룹제목 1", "", "") + } + } + } } @RequiresApi(Build.VERSION_CODES.N) diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteViewModel.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteViewModel.kt index 848d0d05..275ac164 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteViewModel.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteViewModel.kt @@ -17,6 +17,7 @@ import com.cheocharm.presentation.model.TextColor import com.cheocharm.presentation.model.TextEditTool import com.cheocharm.presentation.model.ToolDetailPage import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import javax.inject.Inject @@ -60,12 +61,12 @@ class WriteViewModel @Inject constructor( } fun fetchMyGroups() { - viewModelScope.launch { + viewModelScope.launch(Dispatchers.IO) { val result = getMyGroupsUseCase() result .onSuccess { groups -> - _groups.value = groups + _groups.postValue(groups) } .onFailure { throwable -> _toastText.value = From 1526c423951fc6ae650efec4abe6fde45ede5abd Mon Sep 17 00:00:00 2001 From: Hyesung82 Date: Sun, 17 Mar 2024 12:11:57 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20WriteViewModel=EC=9D=98=20=EC=9D=BC?= =?UTF-8?q?=EB=B6=80=20=EC=BD=94=EB=93=9C=EB=A5=BC=20GroupsViewModel?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EC=A0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 추가로 위치 확인하기 화면에서 사진 여러개를 갖도록 수정 --- app/src/main/AndroidManifest.xml | 16 +++++++---- .../cheocharm/data/local/model/AppDatabase.kt | 6 ++-- .../com/cheocharm/data/local/model/Group.kt | 2 +- .../cheocharm/data/local/model/GroupDao.kt | 3 ++ .../local/source/MyGroupsLocalDataSource.kt | 2 ++ .../source/MyGroupsLocalDataSourceImpl.kt | 4 +++ .../data/repository/GroupRepositoryImpl.kt | 16 +++++++---- .../domain/repository/GroupRepository.kt | 4 ++- .../usecase/group/ClearMyGroupsUseCase.kt | 12 ++++++++ .../usecase/group/CreateGroupUseCase.kt | 2 +- .../cheocharm/presentation/ui/MainActivity.kt | 20 ++++++++++--- .../presentation/ui/write/GroupsFragment.kt | 13 +++++---- .../presentation/ui/write/GroupsViewModel.kt | 28 ++++++++++++++++++- .../presentation/ui/write/LocationFragment.kt | 14 ++++++---- .../ui/write/LocationViewModel.kt | 19 +++++++------ .../presentation/ui/write/PictureFragment.kt | 8 ++---- .../presentation/ui/write/WriteViewModel.kt | 27 ++---------------- 17 files changed, 126 insertions(+), 70 deletions(-) create mode 100644 domain/src/main/java/com/cheocharm/domain/usecase/group/ClearMyGroupsUseCase.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a21391e1..0f4a9f8d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -23,7 +23,13 @@ tools:ignore="Instantiatable"> + android:exported="true"> + + + + + + @@ -31,11 +37,11 @@ android:name="com.cheocharm.presentation.ui.login.SignActivity" android:exported="true" android:windowSoftInputMode="adjustPan"> - - + + - - + + diff --git a/data/src/main/java/com/cheocharm/data/local/model/AppDatabase.kt b/data/src/main/java/com/cheocharm/data/local/model/AppDatabase.kt index ce8717f5..28eebafb 100644 --- a/data/src/main/java/com/cheocharm/data/local/model/AppDatabase.kt +++ b/data/src/main/java/com/cheocharm/data/local/model/AppDatabase.kt @@ -2,10 +2,12 @@ package com.cheocharm.data.local.model import androidx.room.Database import androidx.room.RoomDatabase -import androidx.room.TypeConverter import androidx.room.TypeConverters -@Database(entities = [Group::class], version = 1) +@Database( + version = 1, + entities = [Group::class] +) @TypeConverters(Converters::class) abstract class AppDatabase : RoomDatabase() { abstract fun groupDao(): GroupDao diff --git a/data/src/main/java/com/cheocharm/data/local/model/Group.kt b/data/src/main/java/com/cheocharm/data/local/model/Group.kt index 603b17f4..2a990309 100644 --- a/data/src/main/java/com/cheocharm/data/local/model/Group.kt +++ b/data/src/main/java/com/cheocharm/data/local/model/Group.kt @@ -6,7 +6,7 @@ import androidx.room.PrimaryKey @Entity data class Group( - @PrimaryKey val id: Int, + @PrimaryKey(autoGenerate = true) val id: Int, val name: String, val bio: String, @ColumnInfo(name = "created_at") val createdAt: String, diff --git a/data/src/main/java/com/cheocharm/data/local/model/GroupDao.kt b/data/src/main/java/com/cheocharm/data/local/model/GroupDao.kt index 0bab330d..5f450674 100644 --- a/data/src/main/java/com/cheocharm/data/local/model/GroupDao.kt +++ b/data/src/main/java/com/cheocharm/data/local/model/GroupDao.kt @@ -18,4 +18,7 @@ interface GroupDao { @Delete fun delete(group: Group) + + @Query("DELETE FROM `Group`") + fun clear() } diff --git a/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSource.kt b/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSource.kt index 4b987180..ebad0fe0 100644 --- a/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSource.kt +++ b/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSource.kt @@ -6,4 +6,6 @@ interface MyGroupsLocalDataSource { suspend fun getMyGroups(): List suspend fun joinGroup(group: com.cheocharm.data.local.model.Group) + + suspend fun clearMyGroups() } diff --git a/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSourceImpl.kt b/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSourceImpl.kt index 1ca7c5f1..bf1b9ea7 100644 --- a/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSourceImpl.kt +++ b/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSourceImpl.kt @@ -17,4 +17,8 @@ class MyGroupsLocalDataSourceImpl @Inject constructor( override suspend fun joinGroup(group: com.cheocharm.data.local.model.Group) { groupDao.insertAll(group) } + + override suspend fun clearMyGroups() { + groupDao.clear() + } } diff --git a/data/src/main/java/com/cheocharm/data/repository/GroupRepositoryImpl.kt b/data/src/main/java/com/cheocharm/data/repository/GroupRepositoryImpl.kt index 3304d942..ab7d4767 100644 --- a/data/src/main/java/com/cheocharm/data/repository/GroupRepositoryImpl.kt +++ b/data/src/main/java/com/cheocharm/data/repository/GroupRepositoryImpl.kt @@ -6,7 +6,6 @@ import com.cheocharm.data.error.toDomain import com.cheocharm.data.local.source.MyGroupsLocalDataSource import com.cheocharm.data.remote.source.GroupRemoteDataSource import com.cheocharm.domain.model.Group -import com.cheocharm.domain.model.GroupMember import com.cheocharm.domain.repository.GroupRepository import kotlinx.coroutines.flow.Flow import javax.inject.Inject @@ -15,11 +14,14 @@ class GroupRepositoryImpl @Inject constructor( private val groupRemoteDataSource: GroupRemoteDataSource, private val myGroupsLocalDataSource: MyGroupsLocalDataSource ) : GroupRepository { - private var count = 0 - - override suspend fun createGroup(userId: Int, name: String, bio: String, groupImageUrl: String) { + override suspend fun createGroup( + userId: Int, + name: String, + bio: String, + groupImageUrl: String? + ) { val group = com.cheocharm.data.local.model.Group( - count++, + 0, name, "", "", @@ -29,6 +31,10 @@ class GroupRepositoryImpl @Inject constructor( myGroupsLocalDataSource.joinGroup(group) } + override suspend fun clearMyGroups() { + + } + override fun searchGroup(searchGroupName: String): Flow> { return groupRemoteDataSource.fetchGroupSearchList(searchGroupName) } diff --git a/domain/src/main/java/com/cheocharm/domain/repository/GroupRepository.kt b/domain/src/main/java/com/cheocharm/domain/repository/GroupRepository.kt index 94db3367..f804db9f 100644 --- a/domain/src/main/java/com/cheocharm/domain/repository/GroupRepository.kt +++ b/domain/src/main/java/com/cheocharm/domain/repository/GroupRepository.kt @@ -9,9 +9,11 @@ interface GroupRepository { userId: Int, name: String, bio: String, - groupImageUrl: String + groupImageUrl: String? ) + suspend fun clearMyGroups() + fun searchGroup(searchGroupName: String): Flow> suspend fun joinGroup(groupName: String): Result diff --git a/domain/src/main/java/com/cheocharm/domain/usecase/group/ClearMyGroupsUseCase.kt b/domain/src/main/java/com/cheocharm/domain/usecase/group/ClearMyGroupsUseCase.kt new file mode 100644 index 00000000..ee3b5fa8 --- /dev/null +++ b/domain/src/main/java/com/cheocharm/domain/usecase/group/ClearMyGroupsUseCase.kt @@ -0,0 +1,12 @@ +package com.cheocharm.domain.usecase.group + +import com.cheocharm.domain.repository.GroupRepository +import javax.inject.Inject + +class ClearMyGroupsUseCase @Inject constructor( + private val groupRepository: GroupRepository +) { + suspend operator fun invoke() { + return groupRepository.clearMyGroups() + } +} diff --git a/domain/src/main/java/com/cheocharm/domain/usecase/group/CreateGroupUseCase.kt b/domain/src/main/java/com/cheocharm/domain/usecase/group/CreateGroupUseCase.kt index 095ea3ed..5de76670 100644 --- a/domain/src/main/java/com/cheocharm/domain/usecase/group/CreateGroupUseCase.kt +++ b/domain/src/main/java/com/cheocharm/domain/usecase/group/CreateGroupUseCase.kt @@ -10,7 +10,7 @@ class CreateGroupUseCase @Inject constructor( userId: Int, name: String, bio: String, - groupImageUrl: String + groupImageUrl: String? = null ) { return groupRepository.createGroup(userId, name, bio, groupImageUrl) } diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/MainActivity.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/MainActivity.kt index 4860cdfc..f49da4f6 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/MainActivity.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/MainActivity.kt @@ -13,8 +13,10 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.annotation.RequiresApi import androidx.core.view.WindowInsetsControllerCompat import androidx.core.view.isVisible +import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.setupWithNavController +import com.cheocharm.domain.usecase.group.ClearMyGroupsUseCase import com.cheocharm.domain.usecase.group.CreateGroupUseCase import com.cheocharm.domain.usecase.write.GetMyGroupsUseCase import com.cheocharm.presentation.R @@ -24,7 +26,6 @@ import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices import com.google.android.gms.maps.SupportMapFragment import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import javax.inject.Inject @@ -56,6 +57,8 @@ class MainActivity : BaseActivity(R.layout.activity_main) { @Inject lateinit var getMyGroupsUseCase: GetMyGroupsUseCase @Inject + lateinit var clearMyGroupsUseCase: ClearMyGroupsUseCase + @Inject lateinit var createGroupUseCase: CreateGroupUseCase override fun onCreate(savedInstanceState: Bundle?) { @@ -81,16 +84,25 @@ class MainActivity : BaseActivity(R.layout.activity_main) { mapFragment = supportFragmentManager.findFragmentById(R.id.fragment_main_map) as? SupportMapFragment - initMyGroups() // 오프라인 모드 +// initMyGroups() } + /** + * 오프라인 모드 + */ private fun initMyGroups() { - CoroutineScope(Dispatchers.IO).launch { + lifecycleScope.launch(Dispatchers.IO) { val result = getMyGroupsUseCase.invoke() result.onFailure { for (i in 1..3) { - createGroupUseCase.invoke(0, "그룹제목 1", "", "") + createGroupUseCase.invoke(0, "그룹제목 1", "") + } + }.onSuccess { + if (it.isEmpty()) { + for (i in 1..3) { + createGroupUseCase.invoke(0, "그룹제목 1", "") + } } } } diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsFragment.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsFragment.kt index 2a18bff4..a0b04dce 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsFragment.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsFragment.kt @@ -4,7 +4,6 @@ import android.os.Bundle import android.util.Log import android.view.View import android.widget.Toast -import androidx.fragment.app.viewModels import androidx.hilt.navigation.fragment.hiltNavGraphViewModels import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.DividerItemDecoration @@ -20,8 +19,7 @@ import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class GroupsFragment : BaseFragment(R.layout.fragment_groups) { - private val writeViewModel by hiltNavGraphViewModels(R.id.write) - private val groupsViewModel: GroupsViewModel by viewModels() + private val groupsViewModel: GroupsViewModel by hiltNavGraphViewModels(R.id.write) private lateinit var swipeRefreshLayout: SwipeRefreshLayout @@ -41,7 +39,7 @@ class GroupsFragment : BaseFragment(R.layout.fragment_gro swipeRefreshLayout = binding.containerGroupsRefresh swipeRefreshLayout.setOnRefreshListener { - writeViewModel.fetchMyGroups() + groupsViewModel.fetchMyGroups() } } @@ -55,13 +53,16 @@ class GroupsFragment : BaseFragment(R.layout.fragment_gro adapter = groupsAdapter } - writeViewModel.groups.observe(viewLifecycleOwner) { + groupsViewModel.groups.observe(viewLifecycleOwner) { swipeRefreshLayout.isRefreshing = false it?.let { + Log.d(logTag, it.toString()) groupsAdapter.submitList(it) } } + + groupsViewModel.fetchMyGroups() } private fun adapterOnClick(group: Group) { @@ -70,7 +71,7 @@ class GroupsFragment : BaseFragment(R.layout.fragment_gro } private fun setupToast() { - writeViewModel.toastText.observe(viewLifecycleOwner, EventObserver { + groupsViewModel.toastText.observe(viewLifecycleOwner, EventObserver { swipeRefreshLayout.isRefreshing = false Toast.makeText(context, it, Toast.LENGTH_SHORT).show() diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsViewModel.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsViewModel.kt index 7afc67d4..e384fc61 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsViewModel.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsViewModel.kt @@ -3,13 +3,39 @@ package com.cheocharm.presentation.ui.write import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.cheocharm.domain.model.Group +import com.cheocharm.domain.usecase.write.GetMyGroupsUseCase +import com.cheocharm.presentation.common.ErrorMessage +import com.cheocharm.presentation.common.Event import com.cheocharm.presentation.common.TestValues import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel -class GroupsViewModel @Inject constructor() : ViewModel() { +class GroupsViewModel @Inject constructor( + private val getMyGroupsUseCase: GetMyGroupsUseCase +) : ViewModel() { private val _groups = MutableLiveData(TestValues.testGroups) val groups: LiveData> = _groups + + private val _toastText = MutableLiveData>() + val toastText: LiveData> = _toastText + + fun fetchMyGroups() { + viewModelScope.launch(Dispatchers.IO) { +// val result = getMyGroupsUseCase() +// +// result +// .onSuccess { groups -> +// _groups.postValue(groups) +// } +// .onFailure { throwable -> +// _toastText.value = +// Event(throwable.message ?: ErrorMessage.FETCH_MY_GROUPS_FAILED) +// } + } + } } diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/LocationFragment.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/LocationFragment.kt index 0de0a84f..e81debe7 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/LocationFragment.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/LocationFragment.kt @@ -106,7 +106,7 @@ class LocationFragment : BaseFragment(R.layout.fragment val latLng = if (lat != null && lng != null) LatLng(lat, lng) else null val picture = Picture(Uri.parse(uri), latLng) - locationViewModel.loadPicture(picture, geocodeUtil) + locationViewModel.loadPicture(listOf(picture), geocodeUtil) } if (isDefaultLocation) { @@ -137,11 +137,11 @@ class LocationFragment : BaseFragment(R.layout.fragment val bottom = binding.containerLocationPictures.height googleMap.setPadding(0, top, 0, bottom) - locationViewModel.picture.observe(viewLifecycleOwner) { picture -> - picture?.let { pic -> - picturesAdapter.submitList(listOf(pic)) + locationViewModel.pictures.observe(viewLifecycleOwner) { pictures -> + pictures?.let { pics -> + picturesAdapter.submitList(pics) - val selectedLatLng = pic.latLng + val selectedLatLng = pics[0].latLng if (selectedLatLng != null) { initTypeToSpecified(selectedLatLng) @@ -292,7 +292,9 @@ class LocationFragment : BaseFragment(R.layout.fragment } override fun onSaveInstanceState(outState: Bundle) { - val picture = locationViewModel.picture.value + // TODO: savedStateHandle 사용 + val pictures = locationViewModel.pictures.value + val picture = pictures?.get(0) if (picture != null) { with(outState) { diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/LocationViewModel.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/LocationViewModel.kt index 14afb9a5..68a3bb8f 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/LocationViewModel.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/LocationViewModel.kt @@ -32,23 +32,26 @@ class LocationViewModel @Inject constructor( var stickers: List = TestValues.testStickers private set - private val _picture = MutableLiveData() - val picture: LiveData = _picture + private val _pictures = MutableLiveData>() + val pictures: LiveData> = _pictures private val _locationString = MutableLiveData() val locationString: LiveData = _locationString - fun loadPicture(picture: Picture, geocodeUtil: GeocodeUtil) { - _picture.value = picture + fun loadPicture(pictures: List, geocodeUtil: GeocodeUtil) { + _pictures.value = pictures - if (picture.address == null) { + // TODO: 모든 사진에 대해 지오코딩 + val pic = pictures[0] + + if (pic.address == null) { viewModelScope.launch { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - geocodeUtil.execute(picture) { - _picture.value?.address = it[0].getAddressLine(0) + geocodeUtil.execute(pic) { + _pictures.value?.get(0)?.address = it[0].getAddressLine(0) } } else { - geocodeUtil.execute(picture) + geocodeUtil.execute(pic) } } } diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/PictureFragment.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/PictureFragment.kt index c5601f92..6a553745 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/PictureFragment.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/PictureFragment.kt @@ -14,9 +14,9 @@ import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts import androidx.core.content.ContextCompat import androidx.exifinterface.media.ExifInterface +import androidx.hilt.navigation.fragment.hiltNavGraphViewModels import androidx.navigation.findNavController import androidx.navigation.fragment.findNavController -import androidx.navigation.navGraphViewModels import com.cheocharm.presentation.R import com.cheocharm.presentation.base.BaseFragment import com.cheocharm.presentation.databinding.FragmentPictureBinding @@ -28,7 +28,7 @@ import com.google.android.material.snackbar.Snackbar import kotlinx.coroutines.Dispatchers class PictureFragment : BaseFragment(R.layout.fragment_picture) { - private val locationViewModel: LocationViewModel by navGraphViewModels(R.id.write) + private val locationViewModel: LocationViewModel by hiltNavGraphViewModels(R.id.write) private val requestPermissionsLauncher = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions -> @@ -73,9 +73,7 @@ class PictureFragment : BaseFragment(R.layout.fragment_p } - val picture = pictures[0] - - locationViewModel.loadPicture(picture, geocodeUtil) + locationViewModel.loadPicture(pictures, geocodeUtil) navigateToLocationFragment() } } diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteViewModel.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteViewModel.kt index 275ac164..d7d0ad2d 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteViewModel.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteViewModel.kt @@ -23,15 +23,11 @@ import javax.inject.Inject @HiltViewModel class WriteViewModel @Inject constructor( - private val getMyGroupsUseCase: GetMyGroupsUseCase, private val requestWriteDiaryUseCase: RequestWriteDiaryUseCase ) : ViewModel() { lateinit var temp: TempDiary lateinit var stickers: List - private val _groups = MutableLiveData>() - val groups: LiveData> = _groups - private val _openTool = MutableLiveData() val openTool: LiveData = _openTool @@ -50,30 +46,11 @@ class WriteViewModel @Inject constructor( private val _underline = MutableLiveData() val underline: LiveData = _underline - private val _toastText = MutableLiveData>() - val toastText: LiveData> = _toastText - private val _diaryWrittenEvent = MutableLiveData?>() val diaryWrittenEvent: LiveData?> = _diaryWrittenEvent - init { - fetchMyGroups() - } - - fun fetchMyGroups() { - viewModelScope.launch(Dispatchers.IO) { - val result = getMyGroupsUseCase() - - result - .onSuccess { groups -> - _groups.postValue(groups) - } - .onFailure { throwable -> - _toastText.value = - Event(throwable.message ?: ErrorMessage.FETCH_MY_GROUPS_FAILED) - } - } - } + private val _toastText = MutableLiveData>() + val toastText: LiveData> = _toastText fun onClickTool(tool: TextEditTool?) { _openTool.value = if (openTool.value == tool) null else tool From 43741ada1e3fc58ed2c0da1e834248a97c145641 Mon Sep 17 00:00:00 2001 From: Hyesung82 Date: Sun, 17 Mar 2024 14:38:00 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cheocharm/data/di/DataSourceModule.kt | 6 --- .../com/cheocharm/data/di/DatabaseModule.kt | 45 ------------------- .../cheocharm/data/local/model/AppDatabase.kt | 14 ------ .../cheocharm/data/local/model/Converters.kt | 20 --------- .../com/cheocharm/data/local/model/Group.kt | 16 ------- .../cheocharm/data/local/model/GroupDao.kt | 24 ---------- .../cheocharm/data/local/model/GroupMember.kt | 10 ----- .../data/local/model/GroupMemberCrossRef.kt | 9 ---- .../data/local/model/GroupWithMembers.kt | 15 ------- .../local/source/MyGroupsLocalDataSource.kt | 11 ----- .../source/MyGroupsLocalDataSourceImpl.kt | 24 ---------- .../com/cheocharm/data/mapper/WriteMapper.kt | 4 -- .../data/repository/GroupRepositoryImpl.kt | 25 +---------- .../data/repository/MyGroupsRepositoryImpl.kt | 37 +++++++-------- .../domain/repository/GroupRepository.kt | 9 ---- .../usecase/group/ClearMyGroupsUseCase.kt | 12 ----- .../usecase/group/CreateGroupUseCase.kt | 17 ------- .../cheocharm/presentation/ui/MainActivity.kt | 37 --------------- 18 files changed, 16 insertions(+), 319 deletions(-) delete mode 100644 data/src/main/java/com/cheocharm/data/di/DatabaseModule.kt delete mode 100644 data/src/main/java/com/cheocharm/data/local/model/AppDatabase.kt delete mode 100644 data/src/main/java/com/cheocharm/data/local/model/Converters.kt delete mode 100644 data/src/main/java/com/cheocharm/data/local/model/Group.kt delete mode 100644 data/src/main/java/com/cheocharm/data/local/model/GroupDao.kt delete mode 100644 data/src/main/java/com/cheocharm/data/local/model/GroupMember.kt delete mode 100644 data/src/main/java/com/cheocharm/data/local/model/GroupMemberCrossRef.kt delete mode 100644 data/src/main/java/com/cheocharm/data/local/model/GroupWithMembers.kt delete mode 100644 data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSource.kt delete mode 100644 data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSourceImpl.kt delete mode 100644 domain/src/main/java/com/cheocharm/domain/usecase/group/ClearMyGroupsUseCase.kt delete mode 100644 domain/src/main/java/com/cheocharm/domain/usecase/group/CreateGroupUseCase.kt diff --git a/data/src/main/java/com/cheocharm/data/di/DataSourceModule.kt b/data/src/main/java/com/cheocharm/data/di/DataSourceModule.kt index 1c44aa4d..082661f3 100644 --- a/data/src/main/java/com/cheocharm/data/di/DataSourceModule.kt +++ b/data/src/main/java/com/cheocharm/data/di/DataSourceModule.kt @@ -2,8 +2,6 @@ package com.cheocharm.data.di import com.cheocharm.data.local.source.AuthLocalDataSource import com.cheocharm.data.local.source.AuthLocalDataSourceImpl -import com.cheocharm.data.local.source.MyGroupsLocalDataSource -import com.cheocharm.data.local.source.MyGroupsLocalDataSourceImpl import com.cheocharm.data.remote.source.AuthRemoteDataSource import com.cheocharm.data.remote.source.AuthRemoteDataSourceImpl import com.cheocharm.data.remote.source.GroupRemoteDataSource @@ -39,10 +37,6 @@ internal abstract class DataSourceModule { @Singleton abstract fun bindGroupRemoteDataSource(dataSource: GroupRemoteDataSourceImpl): GroupRemoteDataSource - @Binds - @Singleton - abstract fun bindMyGroupsLocalDataSource(dataSource: MyGroupsLocalDataSourceImpl): MyGroupsLocalDataSource - @Binds @Singleton abstract fun bindMyGroupsRemoteDataSource(dataSource: MyGroupsRemoteDataSourceImpl): MyGroupsRemoteDataSource diff --git a/data/src/main/java/com/cheocharm/data/di/DatabaseModule.kt b/data/src/main/java/com/cheocharm/data/di/DatabaseModule.kt deleted file mode 100644 index edfe7da1..00000000 --- a/data/src/main/java/com/cheocharm/data/di/DatabaseModule.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.cheocharm.data.di - -import android.content.Context -import androidx.room.Room -import com.cheocharm.data.local.model.AppDatabase -import com.cheocharm.data.local.model.Converters -import com.cheocharm.data.local.model.GroupDao -import com.google.gson.Gson -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 - -@InstallIn(SingletonComponent::class) -@Module -class DatabaseModule { - @Provides - fun provideGroupDao(appDatabase: AppDatabase): GroupDao { - return appDatabase.groupDao() - } - - @Provides - @Singleton - fun provideAppDatabase(@ApplicationContext appContext: Context, gson: Gson): AppDatabase { - return Room.databaseBuilder( - appContext, - AppDatabase::class.java, - DB_NAME - ) - .addTypeConverter(Converters(gson)) - .build() - } - - @Provides - @Singleton - fun provideGson(): Gson { - return Gson() - } - - companion object { - private const val DB_NAME = "mapz.db" - } -} diff --git a/data/src/main/java/com/cheocharm/data/local/model/AppDatabase.kt b/data/src/main/java/com/cheocharm/data/local/model/AppDatabase.kt deleted file mode 100644 index 28eebafb..00000000 --- a/data/src/main/java/com/cheocharm/data/local/model/AppDatabase.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.cheocharm.data.local.model - -import androidx.room.Database -import androidx.room.RoomDatabase -import androidx.room.TypeConverters - -@Database( - version = 1, - entities = [Group::class] -) -@TypeConverters(Converters::class) -abstract class AppDatabase : RoomDatabase() { - abstract fun groupDao(): GroupDao -} diff --git a/data/src/main/java/com/cheocharm/data/local/model/Converters.kt b/data/src/main/java/com/cheocharm/data/local/model/Converters.kt deleted file mode 100644 index 4d6046a0..00000000 --- a/data/src/main/java/com/cheocharm/data/local/model/Converters.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.cheocharm.data.local.model - -import androidx.room.ProvidedTypeConverter -import androidx.room.TypeConverter -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken - -@ProvidedTypeConverter -class Converters(private val gson: Gson) { - @TypeConverter - fun fromMembers(value: List?): String? { - return gson.toJson(value) - } - - @TypeConverter - fun stringToMember(string: String?): List? { - val collectionType = object : TypeToken>() {}.type - return gson.fromJson(string, collectionType) - } -} diff --git a/data/src/main/java/com/cheocharm/data/local/model/Group.kt b/data/src/main/java/com/cheocharm/data/local/model/Group.kt deleted file mode 100644 index 2a990309..00000000 --- a/data/src/main/java/com/cheocharm/data/local/model/Group.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.cheocharm.data.local.model - -import androidx.room.ColumnInfo -import androidx.room.Entity -import androidx.room.PrimaryKey - -@Entity -data class Group( - @PrimaryKey(autoGenerate = true) val id: Int, - val name: String, - val bio: String, - @ColumnInfo(name = "created_at") val createdAt: String, - val members: List, - @ColumnInfo(name = "number_of_members") val numberOfMembers: Int, - @ColumnInfo(name = "group_image_url") val groupImageUrl: String? = null -) diff --git a/data/src/main/java/com/cheocharm/data/local/model/GroupDao.kt b/data/src/main/java/com/cheocharm/data/local/model/GroupDao.kt deleted file mode 100644 index 5f450674..00000000 --- a/data/src/main/java/com/cheocharm/data/local/model/GroupDao.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.cheocharm.data.local.model - -import androidx.room.Dao -import androidx.room.Delete -import androidx.room.Insert -import androidx.room.Query - -@Dao -interface GroupDao { - @Query("SELECT * FROM `group`") - fun getAll(): List - - @Query("SELECT * FROM `group` WHERE id = :groupId") - fun findById(groupId: Int): Group - - @Insert - fun insertAll(vararg groups: Group) - - @Delete - fun delete(group: Group) - - @Query("DELETE FROM `Group`") - fun clear() -} diff --git a/data/src/main/java/com/cheocharm/data/local/model/GroupMember.kt b/data/src/main/java/com/cheocharm/data/local/model/GroupMember.kt deleted file mode 100644 index a1c0cd85..00000000 --- a/data/src/main/java/com/cheocharm/data/local/model/GroupMember.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.cheocharm.data.local.model - -import androidx.room.Entity -import androidx.room.PrimaryKey - -@Entity -data class GroupMember( - @PrimaryKey val memberId: Int, - val imageUrl: String? = null -) diff --git a/data/src/main/java/com/cheocharm/data/local/model/GroupMemberCrossRef.kt b/data/src/main/java/com/cheocharm/data/local/model/GroupMemberCrossRef.kt deleted file mode 100644 index 79089121..00000000 --- a/data/src/main/java/com/cheocharm/data/local/model/GroupMemberCrossRef.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.cheocharm.data.local.model - -import androidx.room.Entity - -@Entity(primaryKeys = ["groupId", "memberId"]) -data class GroupMemberCrossRef( - val groupId: Int, - val memberId: Int -) diff --git a/data/src/main/java/com/cheocharm/data/local/model/GroupWithMembers.kt b/data/src/main/java/com/cheocharm/data/local/model/GroupWithMembers.kt deleted file mode 100644 index 3fadc49c..00000000 --- a/data/src/main/java/com/cheocharm/data/local/model/GroupWithMembers.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.cheocharm.data.local.model - -import androidx.room.Embedded -import androidx.room.Junction -import androidx.room.Relation - -data class GroupWithMembers( - @Embedded val group: Group, - @Relation( - parentColumn = "groupId", - entityColumn = "memberId", - associateBy = Junction(GroupMemberCrossRef::class) - ) - val members: List -) diff --git a/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSource.kt b/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSource.kt deleted file mode 100644 index ebad0fe0..00000000 --- a/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSource.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.cheocharm.data.local.source - -import com.cheocharm.domain.model.Group - -interface MyGroupsLocalDataSource { - suspend fun getMyGroups(): List - - suspend fun joinGroup(group: com.cheocharm.data.local.model.Group) - - suspend fun clearMyGroups() -} diff --git a/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSourceImpl.kt b/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSourceImpl.kt deleted file mode 100644 index bf1b9ea7..00000000 --- a/data/src/main/java/com/cheocharm/data/local/source/MyGroupsLocalDataSourceImpl.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.cheocharm.data.local.source - -import com.cheocharm.data.local.model.GroupDao -import com.cheocharm.data.mapper.toDomain -import com.cheocharm.domain.model.Group -import javax.inject.Inject - -class MyGroupsLocalDataSourceImpl @Inject constructor( - private val groupDao: GroupDao -): MyGroupsLocalDataSource { - override suspend fun getMyGroups(): List { - return groupDao.getAll().map { - it.toDomain() - } - } - - override suspend fun joinGroup(group: com.cheocharm.data.local.model.Group) { - groupDao.insertAll(group) - } - - override suspend fun clearMyGroups() { - groupDao.clear() - } -} diff --git a/data/src/main/java/com/cheocharm/data/mapper/WriteMapper.kt b/data/src/main/java/com/cheocharm/data/mapper/WriteMapper.kt index 9e464901..c7065d62 100644 --- a/data/src/main/java/com/cheocharm/data/mapper/WriteMapper.kt +++ b/data/src/main/java/com/cheocharm/data/mapper/WriteMapper.kt @@ -14,7 +14,3 @@ internal fun GroupData.toDomain(): Group = groupMembersImageUrls.size, groupImageUrl ) - -internal fun com.cheocharm.data.local.model.Group.toDomain(): Group = Group( - id, name, bio, createdAt, members.map { GroupMember(it.imageUrl) }, numberOfMembers, groupImageUrl -) diff --git a/data/src/main/java/com/cheocharm/data/repository/GroupRepositoryImpl.kt b/data/src/main/java/com/cheocharm/data/repository/GroupRepositoryImpl.kt index ab7d4767..6103c36d 100644 --- a/data/src/main/java/com/cheocharm/data/repository/GroupRepositoryImpl.kt +++ b/data/src/main/java/com/cheocharm/data/repository/GroupRepositoryImpl.kt @@ -3,7 +3,6 @@ package com.cheocharm.data.repository import androidx.paging.PagingData import com.cheocharm.data.error.ErrorData import com.cheocharm.data.error.toDomain -import com.cheocharm.data.local.source.MyGroupsLocalDataSource import com.cheocharm.data.remote.source.GroupRemoteDataSource import com.cheocharm.domain.model.Group import com.cheocharm.domain.repository.GroupRepository @@ -11,30 +10,8 @@ import kotlinx.coroutines.flow.Flow import javax.inject.Inject class GroupRepositoryImpl @Inject constructor( - private val groupRemoteDataSource: GroupRemoteDataSource, - private val myGroupsLocalDataSource: MyGroupsLocalDataSource + private val groupRemoteDataSource: GroupRemoteDataSource ) : GroupRepository { - override suspend fun createGroup( - userId: Int, - name: String, - bio: String, - groupImageUrl: String? - ) { - val group = com.cheocharm.data.local.model.Group( - 0, - name, - "", - "", - listOf(com.cheocharm.data.local.model.GroupMember(userId)), - 1 - ) - myGroupsLocalDataSource.joinGroup(group) - } - - override suspend fun clearMyGroups() { - - } - override fun searchGroup(searchGroupName: String): Flow> { return groupRemoteDataSource.fetchGroupSearchList(searchGroupName) } diff --git a/data/src/main/java/com/cheocharm/data/repository/MyGroupsRepositoryImpl.kt b/data/src/main/java/com/cheocharm/data/repository/MyGroupsRepositoryImpl.kt index 8415e6bb..eed6883b 100644 --- a/data/src/main/java/com/cheocharm/data/repository/MyGroupsRepositoryImpl.kt +++ b/data/src/main/java/com/cheocharm/data/repository/MyGroupsRepositoryImpl.kt @@ -1,36 +1,29 @@ package com.cheocharm.data.repository -import com.cheocharm.data.local.source.MyGroupsLocalDataSource +import com.cheocharm.data.error.ErrorData +import com.cheocharm.data.error.toDomain +import com.cheocharm.data.mapper.toDomain import com.cheocharm.data.remote.source.MyGroupsRemoteDataSource import com.cheocharm.domain.model.Group import com.cheocharm.domain.repository.MyGroupsRepository import javax.inject.Inject class MyGroupsRepositoryImpl @Inject constructor( - private val remoteDataSource: MyGroupsRemoteDataSource, - private val localDataSource: MyGroupsLocalDataSource + private val remoteDataSource: MyGroupsRemoteDataSource ) : MyGroupsRepository { override suspend fun getMyGroups(): Result> { -// val result = remoteDataSource.getMyGroups().mapCatching { -// it.map { data -> -// data.toDomain() -// } -// } -// val exception = result.exceptionOrNull() -// -// return if (exception is ErrorData) { -// Result.failure(exception.toDomain()) -// } else { -// result -// } + val result = remoteDataSource.getMyGroups().mapCatching { + it.map { data -> + data.toDomain() + } + } + val exception = result.exceptionOrNull() - return getMyGroupsFromLocalDatabase() - } - - private suspend fun getMyGroupsFromLocalDatabase(): Result> { - val myGroups = localDataSource.getMyGroups() - - return Result.success(myGroups) + return if (exception is ErrorData) { + Result.failure(exception.toDomain()) + } else { + result + } } } diff --git a/domain/src/main/java/com/cheocharm/domain/repository/GroupRepository.kt b/domain/src/main/java/com/cheocharm/domain/repository/GroupRepository.kt index f804db9f..04cd2001 100644 --- a/domain/src/main/java/com/cheocharm/domain/repository/GroupRepository.kt +++ b/domain/src/main/java/com/cheocharm/domain/repository/GroupRepository.kt @@ -5,15 +5,6 @@ import com.cheocharm.domain.model.Group import kotlinx.coroutines.flow.Flow interface GroupRepository { - suspend fun createGroup( - userId: Int, - name: String, - bio: String, - groupImageUrl: String? - ) - - suspend fun clearMyGroups() - fun searchGroup(searchGroupName: String): Flow> suspend fun joinGroup(groupName: String): Result diff --git a/domain/src/main/java/com/cheocharm/domain/usecase/group/ClearMyGroupsUseCase.kt b/domain/src/main/java/com/cheocharm/domain/usecase/group/ClearMyGroupsUseCase.kt deleted file mode 100644 index ee3b5fa8..00000000 --- a/domain/src/main/java/com/cheocharm/domain/usecase/group/ClearMyGroupsUseCase.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.cheocharm.domain.usecase.group - -import com.cheocharm.domain.repository.GroupRepository -import javax.inject.Inject - -class ClearMyGroupsUseCase @Inject constructor( - private val groupRepository: GroupRepository -) { - suspend operator fun invoke() { - return groupRepository.clearMyGroups() - } -} diff --git a/domain/src/main/java/com/cheocharm/domain/usecase/group/CreateGroupUseCase.kt b/domain/src/main/java/com/cheocharm/domain/usecase/group/CreateGroupUseCase.kt deleted file mode 100644 index 5de76670..00000000 --- a/domain/src/main/java/com/cheocharm/domain/usecase/group/CreateGroupUseCase.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.cheocharm.domain.usecase.group - -import com.cheocharm.domain.repository.GroupRepository -import javax.inject.Inject - -class CreateGroupUseCase @Inject constructor( - private val groupRepository: GroupRepository -) { - suspend operator fun invoke( - userId: Int, - name: String, - bio: String, - groupImageUrl: String? = null - ) { - return groupRepository.createGroup(userId, name, bio, groupImageUrl) - } -} diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/MainActivity.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/MainActivity.kt index f49da4f6..670002d9 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/MainActivity.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/MainActivity.kt @@ -13,12 +13,8 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.annotation.RequiresApi import androidx.core.view.WindowInsetsControllerCompat import androidx.core.view.isVisible -import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.setupWithNavController -import com.cheocharm.domain.usecase.group.ClearMyGroupsUseCase -import com.cheocharm.domain.usecase.group.CreateGroupUseCase -import com.cheocharm.domain.usecase.write.GetMyGroupsUseCase import com.cheocharm.presentation.R import com.cheocharm.presentation.base.BaseActivity import com.cheocharm.presentation.databinding.ActivityMainBinding @@ -26,9 +22,6 @@ import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices import com.google.android.gms.maps.SupportMapFragment import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import javax.inject.Inject @AndroidEntryPoint class MainActivity : BaseActivity(R.layout.activity_main) { @@ -54,13 +47,6 @@ class MainActivity : BaseActivity(R.layout.activity_main) { } } - @Inject - lateinit var getMyGroupsUseCase: GetMyGroupsUseCase - @Inject - lateinit var clearMyGroupsUseCase: ClearMyGroupsUseCase - @Inject - lateinit var createGroupUseCase: CreateGroupUseCase - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -83,29 +69,6 @@ class MainActivity : BaseActivity(R.layout.activity_main) { mapFragment = supportFragmentManager.findFragmentById(R.id.fragment_main_map) as? SupportMapFragment - -// initMyGroups() - } - - /** - * 오프라인 모드 - */ - private fun initMyGroups() { - lifecycleScope.launch(Dispatchers.IO) { - val result = getMyGroupsUseCase.invoke() - - result.onFailure { - for (i in 1..3) { - createGroupUseCase.invoke(0, "그룹제목 1", "") - } - }.onSuccess { - if (it.isEmpty()) { - for (i in 1..3) { - createGroupUseCase.invoke(0, "그룹제목 1", "") - } - } - } - } } @RequiresApi(Build.VERSION_CODES.N) From b561e1997a347f429f98b82b556d321c9b4ee4df Mon Sep 17 00:00:00 2001 From: Hyesung82 Date: Sun, 17 Mar 2024 14:43:45 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20ui/write=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/ui/search/GroupsPagingAdapter.kt | 4 ++-- .../presentation/ui/search/SearchGroupFragment.kt | 2 +- .../presentation/ui/write/{ => diary}/WriteFontAdapter.kt | 2 +- .../ui/write/{ => diary}/WriteFontViewModel.kt | 2 +- .../presentation/ui/write/{ => diary}/WriteFragment.kt | 2 +- .../ui/write/{ => diary}/WriteImageAdapter.kt | 2 +- .../ui/write/{ => diary}/WriteImageItemDecoration.kt | 2 +- .../ui/write/{ => diary}/WriteStickerAdapter.kt | 2 +- .../presentation/ui/write/{ => diary}/WriteViewModel.kt | 6 +----- .../presentation/ui/write/{ => groups}/GroupsAdapter.kt | 2 +- .../presentation/ui/write/{ => groups}/GroupsFragment.kt | 2 +- .../presentation/ui/write/{ => groups}/GroupsViewModel.kt | 2 +- .../presentation/ui/write/{ => groups}/MembersAdapter.kt | 2 +- .../ui/write/{ => location}/LocationFragment.kt | 3 ++- .../ui/write/{ => location}/LocationViewModel.kt | 2 +- .../ui/write/{ => location}/PictureFragment.kt | 2 +- .../ui/write/{ => location}/PicturesAdapter.kt | 2 +- .../com/cheocharm/presentation/util/BindingAdapters.kt | 2 +- presentation/src/main/res/layout/fragment_groups.xml | 4 ++-- presentation/src/main/res/layout/fragment_location.xml | 2 +- presentation/src/main/res/layout/fragment_write.xml | 4 ++-- presentation/src/main/res/layout/write_align.xml | 2 +- presentation/src/main/res/layout/write_color.xml | 2 +- presentation/src/main/res/layout/write_font_family.xml | 2 +- presentation/src/main/res/layout/write_font_size.xml | 2 +- presentation/src/main/res/layout/write_tool_detail.xml | 2 +- presentation/src/main/res/navigation/nav_write.xml | 8 ++++---- 27 files changed, 34 insertions(+), 37 deletions(-) rename presentation/src/main/java/com/cheocharm/presentation/ui/write/{ => diary}/WriteFontAdapter.kt (96%) rename presentation/src/main/java/com/cheocharm/presentation/ui/write/{ => diary}/WriteFontViewModel.kt (92%) rename presentation/src/main/java/com/cheocharm/presentation/ui/write/{ => diary}/WriteFragment.kt (99%) rename presentation/src/main/java/com/cheocharm/presentation/ui/write/{ => diary}/WriteImageAdapter.kt (96%) rename presentation/src/main/java/com/cheocharm/presentation/ui/write/{ => diary}/WriteImageItemDecoration.kt (89%) rename presentation/src/main/java/com/cheocharm/presentation/ui/write/{ => diary}/WriteStickerAdapter.kt (96%) rename presentation/src/main/java/com/cheocharm/presentation/ui/write/{ => diary}/WriteViewModel.kt (92%) rename presentation/src/main/java/com/cheocharm/presentation/ui/write/{ => groups}/GroupsAdapter.kt (98%) rename presentation/src/main/java/com/cheocharm/presentation/ui/write/{ => groups}/GroupsFragment.kt (98%) rename presentation/src/main/java/com/cheocharm/presentation/ui/write/{ => groups}/GroupsViewModel.kt (96%) rename presentation/src/main/java/com/cheocharm/presentation/ui/write/{ => groups}/MembersAdapter.kt (96%) rename presentation/src/main/java/com/cheocharm/presentation/ui/write/{ => location}/LocationFragment.kt (99%) rename presentation/src/main/java/com/cheocharm/presentation/ui/write/{ => location}/LocationViewModel.kt (98%) rename presentation/src/main/java/com/cheocharm/presentation/ui/write/{ => location}/PictureFragment.kt (99%) rename presentation/src/main/java/com/cheocharm/presentation/ui/write/{ => location}/PicturesAdapter.kt (96%) diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/search/GroupsPagingAdapter.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/search/GroupsPagingAdapter.kt index 49806232..9fb6890d 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/search/GroupsPagingAdapter.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/search/GroupsPagingAdapter.kt @@ -5,8 +5,8 @@ import android.view.ViewGroup import androidx.paging.PagingDataAdapter import com.cheocharm.domain.model.Group import com.cheocharm.presentation.databinding.ItemGroupBinding -import com.cheocharm.presentation.ui.write.GroupDiffCallback -import com.cheocharm.presentation.ui.write.GroupsAdapter +import com.cheocharm.presentation.ui.write.groups.GroupDiffCallback +import com.cheocharm.presentation.ui.write.groups.GroupsAdapter class GroupsPagingAdapter(private val onClick: (Group) -> Unit) : PagingDataAdapter(GroupDiffCallback) { diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/search/SearchGroupFragment.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/search/SearchGroupFragment.kt index a136a182..d7bd078e 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/search/SearchGroupFragment.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/search/SearchGroupFragment.kt @@ -13,7 +13,7 @@ import com.cheocharm.presentation.common.GROUP_JOIN_REQUEST_BOTTOM import com.cheocharm.presentation.databinding.ActivityMainBinding import com.cheocharm.presentation.databinding.FragmentSearchGroupBinding import com.cheocharm.presentation.ui.MainActivity -import com.cheocharm.presentation.ui.write.MembersAdapter +import com.cheocharm.presentation.ui.write.groups.MembersAdapter import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteFontAdapter.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteFontAdapter.kt similarity index 96% rename from presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteFontAdapter.kt rename to presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteFontAdapter.kt index c797f1b4..46c5ba36 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteFontAdapter.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteFontAdapter.kt @@ -1,4 +1,4 @@ -package com.cheocharm.presentation.ui.write +package com.cheocharm.presentation.ui.write.diary import android.os.Bundle import android.view.View diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteFontViewModel.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteFontViewModel.kt similarity index 92% rename from presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteFontViewModel.kt rename to presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteFontViewModel.kt index 3c079751..9dd741b8 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteFontViewModel.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteFontViewModel.kt @@ -1,4 +1,4 @@ -package com.cheocharm.presentation.ui.write +package com.cheocharm.presentation.ui.write.diary import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteFragment.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteFragment.kt similarity index 99% rename from presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteFragment.kt rename to presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteFragment.kt index 59ef519f..f2fc4dd4 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteFragment.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteFragment.kt @@ -1,4 +1,4 @@ -package com.cheocharm.presentation.ui.write +package com.cheocharm.presentation.ui.write.diary import android.content.Intent import android.os.Bundle diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteImageAdapter.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteImageAdapter.kt similarity index 96% rename from presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteImageAdapter.kt rename to presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteImageAdapter.kt index a6ed7028..7d077fbe 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteImageAdapter.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteImageAdapter.kt @@ -1,4 +1,4 @@ -package com.cheocharm.presentation.ui.write +package com.cheocharm.presentation.ui.write.diary import android.view.LayoutInflater import android.view.ViewGroup diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteImageItemDecoration.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteImageItemDecoration.kt similarity index 89% rename from presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteImageItemDecoration.kt rename to presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteImageItemDecoration.kt index d573904b..eeff8ad0 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteImageItemDecoration.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteImageItemDecoration.kt @@ -1,4 +1,4 @@ -package com.cheocharm.presentation.ui.write +package com.cheocharm.presentation.ui.write.diary import android.graphics.Rect import android.view.View diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteStickerAdapter.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteStickerAdapter.kt similarity index 96% rename from presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteStickerAdapter.kt rename to presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteStickerAdapter.kt index 44cd4ebf..08b9836e 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteStickerAdapter.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteStickerAdapter.kt @@ -1,4 +1,4 @@ -package com.cheocharm.presentation.ui.write +package com.cheocharm.presentation.ui.write.diary import android.view.LayoutInflater import android.view.ViewGroup diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteViewModel.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteViewModel.kt similarity index 92% rename from presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteViewModel.kt rename to presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteViewModel.kt index d7d0ad2d..b2d079e7 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/WriteViewModel.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/diary/WriteViewModel.kt @@ -1,15 +1,12 @@ -package com.cheocharm.presentation.ui.write +package com.cheocharm.presentation.ui.write.diary import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.cheocharm.domain.model.Group import com.cheocharm.domain.model.TempDiary import com.cheocharm.domain.model.WriteDiaryRequest -import com.cheocharm.domain.usecase.write.GetMyGroupsUseCase import com.cheocharm.domain.usecase.write.RequestWriteDiaryUseCase -import com.cheocharm.presentation.common.ErrorMessage import com.cheocharm.presentation.common.Event import com.cheocharm.presentation.model.Sticker import com.cheocharm.presentation.model.TextAlign @@ -17,7 +14,6 @@ import com.cheocharm.presentation.model.TextColor import com.cheocharm.presentation.model.TextEditTool import com.cheocharm.presentation.model.ToolDetailPage import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import javax.inject.Inject diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsAdapter.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/groups/GroupsAdapter.kt similarity index 98% rename from presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsAdapter.kt rename to presentation/src/main/java/com/cheocharm/presentation/ui/write/groups/GroupsAdapter.kt index c23d30ae..933ab72b 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsAdapter.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/groups/GroupsAdapter.kt @@ -1,4 +1,4 @@ -package com.cheocharm.presentation.ui.write +package com.cheocharm.presentation.ui.write.groups import android.view.LayoutInflater import android.view.ViewGroup diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsFragment.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/groups/GroupsFragment.kt similarity index 98% rename from presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsFragment.kt rename to presentation/src/main/java/com/cheocharm/presentation/ui/write/groups/GroupsFragment.kt index a0b04dce..776b8827 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsFragment.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/groups/GroupsFragment.kt @@ -1,4 +1,4 @@ -package com.cheocharm.presentation.ui.write +package com.cheocharm.presentation.ui.write.groups import android.os.Bundle import android.util.Log diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsViewModel.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/groups/GroupsViewModel.kt similarity index 96% rename from presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsViewModel.kt rename to presentation/src/main/java/com/cheocharm/presentation/ui/write/groups/GroupsViewModel.kt index e384fc61..9776e439 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/GroupsViewModel.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/groups/GroupsViewModel.kt @@ -1,4 +1,4 @@ -package com.cheocharm.presentation.ui.write +package com.cheocharm.presentation.ui.write.groups import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/MembersAdapter.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/groups/MembersAdapter.kt similarity index 96% rename from presentation/src/main/java/com/cheocharm/presentation/ui/write/MembersAdapter.kt rename to presentation/src/main/java/com/cheocharm/presentation/ui/write/groups/MembersAdapter.kt index dae2af05..d1d0d774 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/MembersAdapter.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/groups/MembersAdapter.kt @@ -1,4 +1,4 @@ -package com.cheocharm.presentation.ui.write +package com.cheocharm.presentation.ui.write.groups import android.view.LayoutInflater import android.view.ViewGroup diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/LocationFragment.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/location/LocationFragment.kt similarity index 99% rename from presentation/src/main/java/com/cheocharm/presentation/ui/write/LocationFragment.kt rename to presentation/src/main/java/com/cheocharm/presentation/ui/write/location/LocationFragment.kt index e81debe7..3c1b83e7 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/LocationFragment.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/location/LocationFragment.kt @@ -1,4 +1,4 @@ -package com.cheocharm.presentation.ui.write +package com.cheocharm.presentation.ui.write.location import android.Manifest import android.content.pm.PackageManager @@ -30,6 +30,7 @@ import com.cheocharm.presentation.databinding.FragmentLocationBinding import com.cheocharm.presentation.enum.LatLngSelectionType import com.cheocharm.presentation.model.Picture import com.cheocharm.presentation.ui.MainActivity +import com.cheocharm.presentation.ui.write.diary.WriteViewModel import com.cheocharm.presentation.util.GeocodeUtil import com.google.android.gms.maps.CameraUpdateFactory import com.google.android.gms.maps.GoogleMap diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/LocationViewModel.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/location/LocationViewModel.kt similarity index 98% rename from presentation/src/main/java/com/cheocharm/presentation/ui/write/LocationViewModel.kt rename to presentation/src/main/java/com/cheocharm/presentation/ui/write/location/LocationViewModel.kt index 68a3bb8f..03c6d508 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/LocationViewModel.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/location/LocationViewModel.kt @@ -1,4 +1,4 @@ -package com.cheocharm.presentation.ui.write +package com.cheocharm.presentation.ui.write.location import android.os.Build import androidx.lifecycle.LiveData diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/PictureFragment.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/location/PictureFragment.kt similarity index 99% rename from presentation/src/main/java/com/cheocharm/presentation/ui/write/PictureFragment.kt rename to presentation/src/main/java/com/cheocharm/presentation/ui/write/location/PictureFragment.kt index 6a553745..0a7734c2 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/PictureFragment.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/location/PictureFragment.kt @@ -1,4 +1,4 @@ -package com.cheocharm.presentation.ui.write +package com.cheocharm.presentation.ui.write.location import android.Manifest import android.app.Activity diff --git a/presentation/src/main/java/com/cheocharm/presentation/ui/write/PicturesAdapter.kt b/presentation/src/main/java/com/cheocharm/presentation/ui/write/location/PicturesAdapter.kt similarity index 96% rename from presentation/src/main/java/com/cheocharm/presentation/ui/write/PicturesAdapter.kt rename to presentation/src/main/java/com/cheocharm/presentation/ui/write/location/PicturesAdapter.kt index 1cc80020..e8f579d5 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/ui/write/PicturesAdapter.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/ui/write/location/PicturesAdapter.kt @@ -1,4 +1,4 @@ -package com.cheocharm.presentation.ui.write +package com.cheocharm.presentation.ui.write.location import android.view.LayoutInflater import android.view.ViewGroup diff --git a/presentation/src/main/java/com/cheocharm/presentation/util/BindingAdapters.kt b/presentation/src/main/java/com/cheocharm/presentation/util/BindingAdapters.kt index 5acbea29..48d752a0 100644 --- a/presentation/src/main/java/com/cheocharm/presentation/util/BindingAdapters.kt +++ b/presentation/src/main/java/com/cheocharm/presentation/util/BindingAdapters.kt @@ -6,7 +6,7 @@ import androidx.databinding.BindingAdapter import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide import com.cheocharm.presentation.R -import com.cheocharm.presentation.ui.write.WriteImageItemDecoration +import com.cheocharm.presentation.ui.write.diary.WriteImageItemDecoration object BindingAdapters { diff --git a/presentation/src/main/res/layout/fragment_groups.xml b/presentation/src/main/res/layout/fragment_groups.xml index a736d20f..64830f55 100644 --- a/presentation/src/main/res/layout/fragment_groups.xml +++ b/presentation/src/main/res/layout/fragment_groups.xml @@ -7,14 +7,14 @@ + type="com.cheocharm.presentation.ui.write.groups.GroupsViewModel" /> + tools:context=".ui.write.groups.GroupsFragment"> + type="com.cheocharm.presentation.ui.write.location.LocationViewModel" /> diff --git a/presentation/src/main/res/layout/fragment_write.xml b/presentation/src/main/res/layout/fragment_write.xml index 5a8b5200..d48b8af5 100644 --- a/presentation/src/main/res/layout/fragment_write.xml +++ b/presentation/src/main/res/layout/fragment_write.xml @@ -13,13 +13,13 @@ + type="com.cheocharm.presentation.ui.write.diary.WriteViewModel" /> + tools:context=".ui.write.diary.WriteFragment"> + type="com.cheocharm.presentation.ui.write.diary.WriteViewModel" /> diff --git a/presentation/src/main/res/layout/write_color.xml b/presentation/src/main/res/layout/write_color.xml index 563aee25..54f13ddb 100644 --- a/presentation/src/main/res/layout/write_color.xml +++ b/presentation/src/main/res/layout/write_color.xml @@ -10,7 +10,7 @@ + type="com.cheocharm.presentation.ui.write.diary.WriteViewModel" /> diff --git a/presentation/src/main/res/layout/write_font_family.xml b/presentation/src/main/res/layout/write_font_family.xml index cda4dec2..2bfccd76 100644 --- a/presentation/src/main/res/layout/write_font_family.xml +++ b/presentation/src/main/res/layout/write_font_family.xml @@ -7,7 +7,7 @@ + type="com.cheocharm.presentation.ui.write.diary.WriteFontViewModel" /> diff --git a/presentation/src/main/res/layout/write_font_size.xml b/presentation/src/main/res/layout/write_font_size.xml index a7f3fdc5..2dbfe3bd 100644 --- a/presentation/src/main/res/layout/write_font_size.xml +++ b/presentation/src/main/res/layout/write_font_size.xml @@ -9,7 +9,7 @@ + type="com.cheocharm.presentation.ui.write.diary.WriteFontViewModel" /> diff --git a/presentation/src/main/res/layout/write_tool_detail.xml b/presentation/src/main/res/layout/write_tool_detail.xml index bc46de80..a1752665 100644 --- a/presentation/src/main/res/layout/write_tool_detail.xml +++ b/presentation/src/main/res/layout/write_tool_detail.xml @@ -11,7 +11,7 @@ + type="com.cheocharm.presentation.ui.write.diary.WriteViewModel" />