Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2주차 과제 #5

Merged
merged 56 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
6d82052
[add] icon 리소스 추가
Sangwook123 Oct 23, 2023
e6dc0b9
[add] menu 레이아웃
Sangwook123 Oct 23, 2023
43fcf30
[add] binding fragment 유틸
Sangwook123 Oct 23, 2023
20d19db
[refactor] main activity에서 mypage fragment로 기능 이전
Sangwook123 Oct 23, 2023
1258288
[add] binding dialog fragment 유틸
Sangwook123 Oct 23, 2023
d5239e9
[feat] 프래그먼트
Sangwook123 Oct 23, 2023
d178f32
[mod] String 리소스 수정
Sangwook123 Oct 26, 2023
46a6330
[mod] hobby -> discription
Sangwook123 Oct 26, 2023
452d0cc
[add] 아이콘 리소스 추가
Sangwook123 Oct 26, 2023
648d94a
[add] 기본이미지 리소스 추가
Sangwook123 Oct 26, 2023
23ad2b8
[add] shape 추가
Sangwook123 Oct 26, 2023
2543a4c
[chore] xml
Sangwook123 Oct 26, 2023
2d1dadf
[ui] 리사이클러뷰
Sangwook123 Oct 26, 2023
a727d71
[ui] 포스트 아이템
Sangwook123 Oct 26, 2023
71391fc
[ui] 헤더 아이템
Sangwook123 Oct 26, 2023
6da4b76
[ui] 생일 아이템
Sangwook123 Oct 26, 2023
d16f85a
[feat] binding adapter
Sangwook123 Oct 26, 2023
ef46d8f
[add] ItemDiffCallback Util 추가
Sangwook123 Oct 26, 2023
441d51f
[feat] HomeModel
Sangwook123 Oct 26, 2023
c19baf4
[feat] sealed class 뷰홀더
Sangwook123 Oct 26, 2023
3df156d
[feat] 리스트 어댑터
Sangwook123 Oct 26, 2023
8d2b63f
[feat] 더미데이터 및 리사이클러뷰 초기화
Sangwook123 Oct 26, 2023
37cb1b4
[add] 그래들 dependencies 추가
Sangwook123 Oct 26, 2023
a5fe4fd
[add] shape 추가
Sangwook123 Oct 27, 2023
f166fe4
[ui] mypage 레이아웃 수정
Sangwook123 Oct 27, 2023
196c735
[ui] 아이템 레이아웃 수정
Sangwook123 Oct 27, 2023
e497073
[add] 스트링 리소스 추가
Sangwook123 Oct 27, 2023
d22ae9c
[chore] 그래들 dependencies 수정
Sangwook123 Oct 27, 2023
4d19124
[add] 인터넷 퍼미션
Sangwook123 Oct 27, 2023
c2a5cde
[feat] friendInfoEntity 작성
Sangwook123 Oct 27, 2023
3134883
[feat] DAO 작성
Sangwook123 Oct 27, 2023
279f31a
[feat] Database
Sangwook123 Oct 27, 2023
8303fa8
[feat] database di
Sangwook123 Oct 27, 2023
e11252e
[chore] 주석제거
Sangwook123 Oct 27, 2023
cdce226
[feat] datasource 인터페이스
Sangwook123 Oct 27, 2023
26ccb0d
[feat] datasource 구현부
Sangwook123 Oct 27, 2023
c95f509
[chore] 임포트
Sangwook123 Oct 27, 2023
044bdc0
[feat] datasource di
Sangwook123 Oct 27, 2023
05f07ff
[feat] repository 인터페이스
Sangwook123 Oct 27, 2023
a937fb6
[feat] repository 구현부
Sangwook123 Oct 27, 2023
d42434f
[feat] repository di
Sangwook123 Oct 27, 2023
0e48b4f
[feat] repository
Sangwook123 Oct 27, 2023
6e46d3b
[feat] domain Friend entity
Sangwook123 Oct 27, 2023
0aca1c3
[feat] friend mapping fun
Sangwook123 Oct 27, 2023
275cc69
[feat] friend mapping fun
Sangwook123 Oct 27, 2023
e26fad1
[add] binding adapter coil
Sangwook123 Oct 27, 2023
d315c1c
[refactor] runcatching 블록
Sangwook123 Oct 27, 2023
6d67df8
[chore] home adapter diffutil
Sangwook123 Oct 27, 2023
2020d61
[del] dummy
Sangwook123 Oct 27, 2023
4e5a826
[feat] homeviewmodel, getFriendList()
Sangwook123 Oct 27, 2023
1c9bf4b
[feat] homeFragment
Sangwook123 Oct 27, 2023
f2312fa
[chore] 정렬
Sangwook123 Oct 27, 2023
81dcfd7
[add] gitignore
Sangwook123 Oct 27, 2023
7e68625
[chore] failure snackbar
Sangwook123 Oct 27, 2023
c078ac7
[chore] diffutil
Sangwook123 Oct 27, 2023
91ba7d7
[feat] 예외처리
Sangwook123 Oct 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,5 @@ fabric.properties

!/gradle/wrapper/gradle-wrapper.jar

# End of https://www.toptal.com/developers/gitignore/api/androidstudio,macos,windows
# End of https://www.toptal.com/developers/gitignore/api/androidstudio,macos,windows
.idea/deploymentTargetDropDown.xml
23 changes: 18 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,30 @@ android {
dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.code.gson:gson:2.10.1'
testImplementation 'junit:junit:4.13.2'
implementation 'androidx.activity:activity-ktx:1.2.2'
implementation 'androidx.fragment:fragment-ktx:1.5.4'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

testImplementation 'junit:junit:4.13.2'

implementation "com.google.dagger:hilt-android:2.44"
kapt "com.google.dagger:hilt-compiler:2.44"
implementation 'androidx.activity:activity-ktx:1.2.2'
implementation 'androidx.fragment:fragment-ktx:1.3.3'

implementation 'com.google.android.material:material:1.5.0'
implementation 'com.google.code.gson:gson:2.10.1'

implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1'

//room
implementation 'androidx.room:room-runtime:2.4.3'
annotationProcessor 'androidx.room:room-compiler:2.4.3'
kapt 'androidx.room:room-compiler:2.4.3'
implementation 'androidx.room:room-ktx:2.4.3'

//coil
implementation 'io.coil-kt:coil:2.4.0'
}

kapt {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".DoSoptApplication"
android:allowBackup="true"
Expand Down
Binary file added app/src/main/assets/databases/sopt_friend.db
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sopt.dosopttemplate.data.database

import androidx.room.Database
import androidx.room.RoomDatabase
import org.sopt.dosopttemplate.data.model.local.FriendInfoEntity

@Database(
entities = [
FriendInfoEntity::class
], version = 1
)
abstract class FriendDataBase : RoomDatabase() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 한번도 직접 구현하는 코드에서 abstract를 사용해본 경험이 없는데.. 많이 배워가요..!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 room 이번에 한번 공부해봐야겠어요..!

abstract fun friendInfoDao(): FriendInfoDao
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.sopt.dosopttemplate.data.database

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import org.sopt.dosopttemplate.data.model.local.FriendInfoEntity

@Dao
interface FriendInfoDao {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Room 쓰는거 폼 진짜 말안되네 이남자... .....

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Room? 당장 구글링 해봐야겠다.

@Query("SELECT * FROM table_friend_info")
suspend fun getAll(): List<FriendInfoEntity>

@Insert
suspend fun addFriend(friendInfoEntity: FriendInfoEntity)

@Insert
suspend fun addFriends(friendList: List<FriendInfoEntity>)

@Delete
suspend fun deleteFriend(friendInfoEntity: FriendInfoEntity)

@Query("DELETE FROM table_friend_info WHERE id = :id")
suspend fun deleteFriendById(id: Int)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.sopt.dosopttemplate.data.datasource

import org.sopt.dosopttemplate.data.database.FriendDataBase
import org.sopt.dosopttemplate.data.local.FriendLocalDataSource
import org.sopt.dosopttemplate.data.model.local.FriendInfoEntity
import javax.inject.Inject

class FriendLocalDataSourceImpl @Inject constructor(
private val friendDataBase: FriendDataBase
) : FriendLocalDataSource {
override suspend fun getAll(): List<FriendInfoEntity> {
return friendDataBase.friendInfoDao().getAll()
}

override suspend fun addFriend(friendInfoEntity: FriendInfoEntity) {
friendDataBase.friendInfoDao().addFriend(friendInfoEntity)
}

override suspend fun addFriends(friendList: List<FriendInfoEntity>) {
friendDataBase.friendInfoDao().addFriends(friendList)
}

override suspend fun deleteFriend(friendInfoEntity: FriendInfoEntity) {
friendDataBase.friendInfoDao().deleteFriend(friendInfoEntity)
}

override suspend fun deleteFriendById(id: Int) {
friendDataBase.friendInfoDao().deleteFriendById(id)
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package org.sopt.dosopttemplate.data.datasource
import android.content.SharedPreferences
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.sopt.dosopttemplate.data.model.UserDto
import org.sopt.dosopttemplate.data.local.SharedPrefDataSource
import org.sopt.dosopttemplate.data.model.local.UserDto
import javax.inject.Inject

class SharedPrefDataSourceImpl @Inject constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.sopt.dosopttemplate.data.local

import org.sopt.dosopttemplate.data.model.local.FriendInfoEntity

interface FriendLocalDataSource {
suspend fun getAll(): List<FriendInfoEntity>
suspend fun addFriend(friendInfoEntity: FriendInfoEntity)
suspend fun addFriends(friendList: List<FriendInfoEntity>)
suspend fun deleteFriend(friendInfoEntity: FriendInfoEntity)
suspend fun deleteFriendById(id: Int)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.sopt.dosopttemplate.data.local

import org.sopt.dosopttemplate.data.model.UserDto
import org.sopt.dosopttemplate.data.model.local.UserDto

interface SharedPrefDataSource {
fun saveUserInfo(userDto: UserDto?)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.sopt.dosopttemplate.data.model.local

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import org.sopt.dosopttemplate.domain.entity.Friend
import java.time.LocalDate

@Entity(tableName = "table_friend_info")
data class FriendInfoEntity(
@PrimaryKey(autoGenerate = true)
val id: Int?,
val name: String,
val birthday: String,
val music: String?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

진짜... 모든 걸 다 구현한.. 멋져요.... 뒤에서 후광이..!!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 생일과 뮤직도 구현하셨네요 ㅎㅎ 저는 시험 이슈로 안 했는데 저도 이제 슬슬 구현해보겠어유

@ColumnInfo(name = "image_uri")
val imageUri: String?,
) {
companion object {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

companion object 개념을 처음 봐요. 정적 멤버를 정의할 때 사용하는거군여..? 또 하나 알아가요!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호 companion object 메모메모 합니다

fun toFriend(friendInfoList: List<FriendInfoEntity>) = friendInfoList.map { data ->
Friend(
id = data.id,
name = data.name,
birthday = LocalDate.parse(data.birthday),
music = data.music,
imageUri = data.imageUri
)
}

fun toFriendInfoEntity(friendList: List<Friend>) = friendList.map { data ->
FriendInfoEntity(
id = data.id,
name = data.name,
birthday = data.birthday.toString(),
music = data.music,
imageUri = data.imageUri
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.dosopttemplate.data.model
package org.sopt.dosopttemplate.data.model.local

import kotlinx.serialization.Serializable
import org.sopt.dosopttemplate.domain.entity.User
Expand All @@ -8,13 +8,13 @@ data class UserDto(
val id: String? = "",
val pw: String? = "",
val nickname: String? = "",
val hobby: String? = ""
val discription: String? = ""
) {
fun toUser(): User? {
return User(id, pw, nickname, hobby)
return User(id, pw, nickname, discription)
}

fun toUserDto(user: User?): UserDto {
return UserDto(user?.id, user?.pw, user?.nickname, user?.hobby)
return UserDto(user?.id, user?.pw, user?.nickname, user?.discription)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.sopt.dosopttemplate.data.repository

import org.sopt.dosopttemplate.data.local.FriendLocalDataSource
import org.sopt.dosopttemplate.data.model.local.FriendInfoEntity.Companion.toFriend
import org.sopt.dosopttemplate.data.model.local.FriendInfoEntity.Companion.toFriendInfoEntity
import org.sopt.dosopttemplate.domain.entity.Friend
import org.sopt.dosopttemplate.domain.repository.FriendLocalRepository
import javax.inject.Inject

class FriendLocalRepositoryImpl @Inject constructor(
private val friendLocalDataSource: FriendLocalDataSource
) : FriendLocalRepository {
override suspend fun getAll(): Result<List<Friend>> =
runCatching {
toFriend(friendLocalDataSource.getAll())
}

override suspend fun addFriend(friend: Friend) {
friendLocalDataSource.addFriend(toFriendInfoEntity(listOf(friend)).first())
}

override suspend fun addFriends(friendList: List<Friend>) {
friendLocalDataSource.addFriends(toFriendInfoEntity(friendList))
}

override suspend fun deleteFriend(friend: Friend) {
friendLocalDataSource.deleteFriend(toFriendInfoEntity(listOf(friend)).first())
}

override suspend fun deleteFriendById(id: Int) {
friendLocalDataSource.deleteFriendById(id)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.sopt.dosopttemplate.data.repository

import org.sopt.dosopttemplate.data.model.UserDto
import org.sopt.dosopttemplate.data.local.SharedPrefDataSource
import org.sopt.dosopttemplate.data.model.local.UserDto
import org.sopt.dosopttemplate.domain.entity.User
import org.sopt.dosopttemplate.domain.repository.SharedPrefRepository
import javax.inject.Inject
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/di/DataBaseModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.sopt.dosopttemplate.di

import android.content.Context
import androidx.room.Room
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import org.sopt.dosopttemplate.data.database.FriendDataBase
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object DataBaseModule {
@Singleton
@Provides
fun provideDataBase(
@ApplicationContext context: Context
): FriendDataBase =
Room.databaseBuilder(context, FriendDataBase::class.java, "sopt_friend.db")
.createFromAsset("databases/sopt_friend.db").build()

@Singleton
@Provides
fun provideFriendDao(friendDataBase: FriendDataBase) = friendDataBase.friendInfoDao()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.dosopttemplate.data.datasource.FriendLocalDataSourceImpl
import org.sopt.dosopttemplate.data.datasource.SharedPrefDataSourceImpl
import org.sopt.dosopttemplate.data.local.FriendLocalDataSource
import org.sopt.dosopttemplate.data.local.SharedPrefDataSource
import javax.inject.Singleton

Expand All @@ -14,4 +16,8 @@ abstract class DataSourceModule {
@Singleton
@Binds
abstract fun bindsSharedPrefDataSource(sharedPrefDataSource: SharedPrefDataSourceImpl): SharedPrefDataSource

@Singleton
@Binds
abstract fun bindsFriendLocalDataSource(friendLocalDataSource: FriendLocalDataSourceImpl): FriendLocalDataSource
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.dosopttemplate.data.repository.FriendLocalRepositoryImpl
import org.sopt.dosopttemplate.data.repository.SharedPrefRepositoryImpl
import org.sopt.dosopttemplate.domain.repository.FriendLocalRepository
import org.sopt.dosopttemplate.domain.repository.SharedPrefRepository
import javax.inject.Singleton

Expand All @@ -16,4 +18,10 @@ abstract class RepositoryModule {
abstract fun bindsSharedPrefRepository(
sharedPrefRepository: SharedPrefRepositoryImpl
): SharedPrefRepository

@Singleton
@Binds
abstract fun bindsFriendLocalRepository(
friendLocalRepository: FriendLocalRepositoryImpl
): FriendLocalRepository
}
11 changes: 11 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/domain/entity/Friend.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.sopt.dosopttemplate.domain.entity

import java.time.LocalDate

data class Friend(
val id: Int?,
val name: String,
val birthday: LocalDate?,
val music: String?,
val imageUri: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ data class User(
val id: String? = "",
val pw: String? = "",
val nickname: String? = "",
val hobby: String? = ""
val discription: String? = ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

취미도 궁금해요~

)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.sopt.dosopttemplate.domain.repository

import org.sopt.dosopttemplate.domain.entity.Friend

interface FriendLocalRepository {
suspend fun getAll(): Result<List<Friend>>
suspend fun addFriend(friend: Friend)
suspend fun addFriends(friendList: List<Friend>)
suspend fun deleteFriend(friend: Friend)
suspend fun deleteFriendById(id: Int)
}
Loading