generated from NOW-SOPT-ANDROID/now-sopt-android-template
-
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
[7주차/필수] Compose repository 패턴 #19
Open
leeseokchan00
wants to merge
1
commit into
develop-compose
Choose a base branch
from
feat/week_compose7
base: develop-compose
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/sopt/now/compose/data/datasource/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,7 @@ | ||
package com.sopt.now.compose.data.datasource | ||
|
||
interface SharedPrefDataSource { | ||
fun setUserId(key: String, value: Int) | ||
fun getUserId(key: String): Int | ||
fun clearUserData() | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/sopt/now/compose/data/datasourceImpl/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,22 @@ | ||
package com.sopt.now.compose.data.datasourceImpl | ||
|
||
import android.content.SharedPreferences | ||
import com.sopt.now.compose.data.datasource.SharedPrefDataSource | ||
import javax.inject.Inject | ||
|
||
class SharedPrefDataSourceImpl @Inject constructor( | ||
private val sharedPreferences: SharedPreferences | ||
) : SharedPrefDataSource{ | ||
|
||
override fun setUserId(key: String, value: Int) { | ||
sharedPreferences.edit().putInt(key,value).apply() | ||
} | ||
|
||
override fun getUserId(key: String): Int { | ||
return sharedPreferences.getInt(key, 0) | ||
} | ||
|
||
override fun clearUserData() { | ||
sharedPreferences.edit().clear().apply() | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/sopt/now/compose/data/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 com.sopt.now.compose.data.di | ||
|
||
import com.sopt.now.compose.data.datasource.SharedPrefDataSource | ||
import com.sopt.now.compose.data.datasourceImpl.SharedPrefDataSourceImpl | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
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/com/sopt/now/compose/data/di/RepositoryModule.kt
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. 이제 힐트까지 ㄷ.ㄷ 야무지십니당 |
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 com.sopt.now.compose.data.di | ||
|
||
import com.sopt.now.compose.data.repository.SharedPrefRepository | ||
import com.sopt.now.compose.data.repository.SharedPrefRepositoryImpl | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
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/com/sopt/now/compose/data/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 com.sopt.now.compose.data.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 provideSharedPref(@ApplicationContext context: Context): SharedPreferences { | ||
return context.getSharedPreferences("userData", Context.MODE_PRIVATE) | ||
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. 키값도 상수로 만들어주면 좋을 것 같네요 |
||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/sopt/now/compose/data/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,7 @@ | ||
package com.sopt.now.compose.data.repository | ||
|
||
interface SharedPrefRepository { | ||
fun setUserId(key: String, value: Int) | ||
fun getUserId(key: String): Int | ||
fun clearUserData() | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/sopt/now/compose/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,20 @@ | ||
package com.sopt.now.compose.data.repository | ||
|
||
import com.sopt.now.compose.data.datasource.SharedPrefDataSource | ||
import javax.inject.Inject | ||
|
||
class SharedPrefRepositoryImpl @Inject constructor( | ||
private val sharedPrefDataSource: SharedPrefDataSource | ||
) : SharedPrefRepository { | ||
override fun setUserId(key: String, value: Int) { | ||
sharedPrefDataSource.setUserId(key, value) | ||
} | ||
|
||
override fun getUserId(key: String): Int { | ||
return sharedPrefDataSource.getUserId(key) | ||
} | ||
|
||
override fun clearUserData() { | ||
sharedPrefDataSource.clearUserData() | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
어떤 어노테이션인가 했더니 이것도 Dagger-Hilt 모듈과 관련된 어노테이션이군요 !