-
Notifications
You must be signed in to change notification settings - Fork 0
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
1주차 과제 #3
Changes from all commits
2ed7755
678ccbb
2a6afb9
2228e67
f154dd9
eed5c4e
3ff2daf
2e16d3b
7425030
97ab0e7
68ee441
192bc21
6681825
d3f60e3
ebb9f2b
4950087
be1b533
5c2515a
00037f5
7ecebe3
e854340
f5bde1a
4cb3607
1cd9faf
bfc61b5
2e48b6f
d6b1089
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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() | ||
} | ||
|
||
} |
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() | ||
} |
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? { | ||
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() | ||
} | ||
} |
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 | ||
} |
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 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. viewmodel에서 domain 레이어의 repository를 data의 구현부와 연결하여 사용하기위해 @BINDS 어노테이션을 활용했습니다 |
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엔티티화까지,,, 저두 이런식으로 리팩토링해야겠네요