Skip to content

Commit

Permalink
[merge] 1주차 심화 도전과제
Browse files Browse the repository at this point in the history
1주차 과제
  • Loading branch information
Sangwook123 authored Oct 21, 2023
2 parents a45fa6e + d6b1089 commit 77acd66
Show file tree
Hide file tree
Showing 29 changed files with 739 additions and 154 deletions.
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? {
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
}
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 {
fun saveUserInfo(user: User?)
fun getUserInfo(): User?
fun setAutoLogin()
fun isAutoLogin(): Boolean
fun clearAutoLogin()
fun clearSharedPref()
}
Loading

0 comments on commit 77acd66

Please sign in to comment.