generated from DO-SOPT-ANDROID/do-sopt-android-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1주차 과제
- Loading branch information
Showing
29 changed files
with
739 additions
and
154 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
app/src/main/java/org/sopt/dosopttemplate/DoSoptApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/org/sopt/dosopttemplate/data/datasource/SharedPrefDataSourceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
app/src/main/java/org/sopt/dosopttemplate/data/entity/User.kt
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
app/src/main/java/org/sopt/dosopttemplate/data/local/SharedPrefDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
app/src/main/java/org/sopt/dosopttemplate/data/model/UserDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
app/src/main/java/org/sopt/dosopttemplate/data/repository/SharedPrefRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
app/src/main/java/org/sopt/dosopttemplate/di/DataSourceModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
app/src/main/java/org/sopt/dosopttemplate/di/RepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/org/sopt/dosopttemplate/di/SharedPrefModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/org/sopt/dosopttemplate/domain/entity/User.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? = "" | ||
) |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/org/sopt/dosopttemplate/domain/repository/SharedPrefRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
fun saveUserInfo(user: User?) | ||
fun getUserInfo(): User? | ||
fun setAutoLogin() | ||
fun isAutoLogin(): Boolean | ||
fun clearAutoLogin() | ||
fun clearSharedPref() | ||
} |
Oops, something went wrong.