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

1주차 과제 #3

Merged
merged 27 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2ed7755
[add] 그래들 종속성 추가
Sangwook123 Oct 10, 2023
678ccbb
[add] DI 앱진입점
Sangwook123 Oct 10, 2023
2a6afb9
[feat] SharedPref 모듈
Sangwook123 Oct 10, 2023
2228e67
[feat] sharedpref 인터페이스
Sangwook123 Oct 10, 2023
f154dd9
[feat] sharedpref 구현부
Sangwook123 Oct 10, 2023
eed5c4e
[feat] 리포지토리 모듈
Sangwook123 Oct 10, 2023
3ff2daf
[add] hidekeyboard 확장함수
Sangwook123 Oct 10, 2023
2e16d3b
[add] uistate sealed interface
Sangwook123 Oct 10, 2023
7425030
[add] string 리소스 추가
Sangwook123 Oct 10, 2023
97ab0e7
[refactor] viewmodel, databinding
Sangwook123 Oct 10, 2023
68ee441
[feat] viewmodel, databinding, hilt, 자동로그인 구현
Sangwook123 Oct 10, 2023
192bc21
[feat] main viewmodel, databinding, hilt, 로그아웃 및 회원탈퇴 구현
Sangwook123 Oct 10, 2023
6681825
[mod] 함수화
Sangwook123 Oct 10, 2023
d3f60e3
[mod] main 액티비티 intent flag, 함수화
Sangwook123 Oct 10, 2023
ebb9f2b
[feat] login 액티비티 intent flag
Sangwook123 Oct 10, 2023
4950087
[chore] 주석
Sangwook123 Oct 10, 2023
be1b533
[chore] 자동로그인 로직 수정
Sangwook123 Oct 10, 2023
5c2515a
[chore] 코드정렬
Sangwook123 Oct 10, 2023
00037f5
[mod] 코드수정
Sangwook123 Oct 11, 2023
7ecebe3
[add] kotlin serialization
Sangwook123 Oct 13, 2023
e854340
[mod] UserModel
Sangwook123 Oct 13, 2023
f5bde1a
[feat] DataSource
Sangwook123 Oct 13, 2023
4cb3607
[refactor] repository
Sangwook123 Oct 13, 2023
1cd9faf
[add] UserDto, User Data class
Sangwook123 Oct 13, 2023
bfc61b5
[refactor] code
Sangwook123 Oct 13, 2023
2e48b6f
[chore] package
Sangwook123 Oct 13, 2023
d6b1089
Merge branch 'develop' into feature/seminar1-advanced-challenge
Sangwook123 Oct 21, 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
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-parcelize'
id 'kotlin-kapt'
id 'com.google.dagger.hilt.android'
id 'kotlinx-serialization'
}

android {
Expand All @@ -25,11 +28,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '11'
jvmTarget = '17'
}

buildFeatures {
Expand All @@ -39,12 +42,21 @@ 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'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
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 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1'
}

kapt {
correctErrorTypes true
}
11 changes: 8 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<application
android:name=".DoSoptApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -15,20 +16,24 @@
<activity
android:name=".presentation.main.MainActivity"
android:exported="false">

</activity>

<activity
android:name=".presentation.login.LoginActivity"
android:exported="true">
android:exported="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".presentation.signup.SignupActivity"
android:exported="false">
<activity
android:name=".presentation.signup.SignupActivity"
android:exported="false"
android:windowSoftInputMode="adjustResize">

</activity>
</application>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.sopt.dosopttemplate

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class DoSoptApplication : Application() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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 javax.inject.Inject

class SharedPrefDataSourceImpl @Inject constructor(
private val sharedPref: SharedPreferences
) : SharedPrefDataSource {
override fun saveUserInfo(userDto: UserDto?) {
val json = Json.encodeToString(userDto)
sharedPref.edit().putString("user", json).apply()
}

override fun getUserInfo(): UserDto {
val json = sharedPref.getString("user", "")
if (json.isNullOrBlank()) return UserDto("", "", "", "")
return Json.decodeFromString(json)
}

override fun setAutoLogin() {
sharedPref.edit().putBoolean("autoLogin", true).apply()
}

override fun isAutoLogin(): Boolean {
return sharedPref.getBoolean("autoLogin", false)
}

override fun clearAutoLogin() {
sharedPref.edit().putBoolean("autoLogin", false).apply()
}

override fun clearSharedPref() {
sharedPref.edit().clear().apply()
}

}
12 changes: 0 additions & 12 deletions app/src/main/java/org/sopt/dosopttemplate/data/entity/User.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sopt.dosopttemplate.data.local

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

interface SharedPrefDataSource {
fun saveUserInfo(userDto: UserDto?)
fun getUserInfo(): UserDto
fun setAutoLogin()
fun isAutoLogin(): Boolean
fun clearAutoLogin()
fun clearSharedPref()
}
20 changes: 20 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/data/model/UserDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.sopt.dosopttemplate.data.model

import kotlinx.serialization.Serializable
import org.sopt.dosopttemplate.domain.entity.User

@Serializable
data class UserDto(
val id: String? = "",
val pw: String? = "",
val nickname: String? = "",
val hobby: String? = ""
) {
fun toUser(): User? {

Choose a reason for hiding this comment

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

엔티티화까지,,, 저두 이런식으로 리팩토링해야겠네요

return User(id, pw, nickname, hobby)
}

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

import org.sopt.dosopttemplate.data.model.UserDto
import org.sopt.dosopttemplate.data.local.SharedPrefDataSource
import org.sopt.dosopttemplate.domain.entity.User
import org.sopt.dosopttemplate.domain.repository.SharedPrefRepository
import javax.inject.Inject

class SharedPrefRepositoryImpl @Inject constructor(
private val sharedPrefDataSource: SharedPrefDataSource
) : SharedPrefRepository {
override fun saveUserInfo(user: User?) {
sharedPrefDataSource.saveUserInfo(UserDto().toUserDto(user))
}

override fun getUserInfo(): User? {
return sharedPrefDataSource.getUserInfo().toUser()
}

override fun setAutoLogin() {
sharedPrefDataSource.setAutoLogin()
}

override fun isAutoLogin(): Boolean {
return sharedPrefDataSource.isAutoLogin()
}

override fun clearAutoLogin() {
sharedPrefDataSource.clearAutoLogin()
}

override fun clearSharedPref() {
sharedPrefDataSource.clearSharedPref()
}
}
17 changes: 17 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/di/DataSourceModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.sopt.dosopttemplate.di

import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.dosopttemplate.data.datasource.SharedPrefDataSourceImpl
import org.sopt.dosopttemplate.data.local.SharedPrefDataSource
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
abstract class DataSourceModule {
@Singleton
@Binds
abstract fun bindsSharedPrefDataSource(sharedPrefDataSource: SharedPrefDataSourceImpl): SharedPrefDataSource
}
19 changes: 19 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.sopt.dosopttemplate.di

import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.dosopttemplate.data.repository.SharedPrefRepositoryImpl
import org.sopt.dosopttemplate.domain.repository.SharedPrefRepository
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
abstract class RepositoryModule {
@Singleton
@Binds
abstract fun bindsSharedPrefRepository(
sharedPrefRepository: SharedPrefRepositoryImpl
): SharedPrefRepository
}
Copy link
Member

Choose a reason for hiding this comment

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

@provides 대신 @BINDS 를 활용하신 이유가 있나요?

Copy link
Member Author

Choose a reason for hiding this comment

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

viewmodel에서 domain 레이어의 repository를 data의 구현부와 연결하여 사용하기위해 @BINDS 어노테이션을 활용했습니다

20 changes: 20 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/di/SharedPrefModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.sopt.dosopttemplate.di

import android.content.Context
import android.content.SharedPreferences
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object SharedPrefModule {
@Provides
@Singleton
fun provideSharedPreferences(@ApplicationContext context: Context): SharedPreferences {
return context.getSharedPreferences("prefs", Context.MODE_PRIVATE)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.sopt.dosopttemplate.domain.entity

data class User(
val id: String? = "",
val pw: String? = "",
val nickname: String? = "",
val hobby: String? = ""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sopt.dosopttemplate.domain.repository

import org.sopt.dosopttemplate.domain.entity.User

interface SharedPrefRepository {

Choose a reason for hiding this comment

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

진짜 mvvm 적용 폼 미쳤네,,,

fun saveUserInfo(user: User?)
fun getUserInfo(): User?
fun setAutoLogin()
fun isAutoLogin(): Boolean
fun clearAutoLogin()
fun clearSharedPref()
}
Loading