-
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
Seminar/7 #10
Open
hansh0101
wants to merge
5
commits into
main
Choose a base branch
from
seminar/7
base: main
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
Seminar/7 #10
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7주차 README입니다 - https://velog.io/@gxstxdgxs/THE-SOPT-Android-7차-세미나-과제 |
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
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
16 changes: 16 additions & 0 deletions
16
app/src/main/java/co/kr/sopt_seminar_30th/data/datasource/local/AuthorizationDao.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,16 @@ | ||
package co.kr.sopt_seminar_30th.data.datasource.local | ||
|
||
import androidx.room.* | ||
import co.kr.sopt_seminar_30th.data.model.dto.AuthorizationDto | ||
|
||
@Dao | ||
interface AuthorizationDao { | ||
@Insert | ||
suspend fun insertAuthorization(authorizationDto: AuthorizationDto) | ||
|
||
@Delete | ||
suspend fun deleteAuthorization(authorizationDto: AuthorizationDto) | ||
|
||
@Query("SELECT * FROM Authorization WHERE userId = :id") | ||
suspend fun getAuthorization(id: String): AuthorizationDto | ||
} |
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
11 changes: 11 additions & 0 deletions
11
app/src/main/java/co/kr/sopt_seminar_30th/data/model/dto/AuthorizationDto.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,11 @@ | ||
package co.kr.sopt_seminar_30th.data.model.dto | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity(tableName = "Authorization") | ||
data class AuthorizationDto( | ||
@PrimaryKey val userId: String, | ||
@ColumnInfo(name = "autoLogin") val autoLogin: Boolean | ||
) |
28 changes: 28 additions & 0 deletions
28
...ain/java/co/kr/sopt_seminar_30th/data/repositoryimpl/local/AuthorizationRepositoryImpl.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,28 @@ | ||
package co.kr.sopt_seminar_30th.data.repositoryimpl.local | ||
|
||
import co.kr.sopt_seminar_30th.data.datasource.local.AuthorizationDao | ||
import co.kr.sopt_seminar_30th.data.model.dto.AuthorizationDto | ||
import co.kr.sopt_seminar_30th.domain.repository.local.AuthorizationRepository | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
|
||
class AuthorizationRepositoryImpl @Inject constructor( | ||
private val dao: AuthorizationDao, | ||
private val coroutineDispatcher: CoroutineDispatcher | ||
) : AuthorizationRepository { | ||
override suspend fun insertAuthorization(userId: String, autoLogin: Boolean) = | ||
withContext(coroutineDispatcher) { | ||
dao.insertAuthorization(AuthorizationDto(userId, autoLogin)) | ||
} | ||
|
||
override suspend fun deleteAuthorization(userId: String, autoLogin: Boolean) = | ||
withContext(coroutineDispatcher) { | ||
dao.deleteAuthorization(AuthorizationDto(userId, autoLogin)) | ||
} | ||
|
||
override suspend fun getAuthorization(userId: String): Boolean = | ||
withContext(coroutineDispatcher) { | ||
dao.getAuthorization(userId).autoLogin | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
app/src/main/java/co/kr/sopt_seminar_30th/domain/repository/local/AuthorizationRepository.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 co.kr.sopt_seminar_30th.domain.repository.local | ||
|
||
interface AuthorizationRepository { | ||
suspend fun insertAuthorization(userId: String, autoLogin: Boolean) | ||
suspend fun deleteAuthorization(userId: String, autoLogin: Boolean) | ||
suspend fun getAuthorization(userId: String): Boolean | ||
} |
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
62 changes: 62 additions & 0 deletions
62
app/src/main/java/co/kr/sopt_seminar_30th/presentation/ui/onboarding/OnBoardingActivity.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,62 @@ | ||
package co.kr.sopt_seminar_30th.presentation.ui.onboarding | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import androidx.lifecycle.flowWithLifecycle | ||
import androidx.lifecycle.lifecycleScope | ||
import co.kr.sopt_seminar_30th.R | ||
import co.kr.sopt_seminar_30th.data.datasource.local.SopthubDataStore | ||
import co.kr.sopt_seminar_30th.databinding.ActivityOnBoardingBinding | ||
import co.kr.sopt_seminar_30th.presentation.ui.auth.SignInActivity | ||
import co.kr.sopt_seminar_30th.presentation.ui.base.BaseActivity | ||
import co.kr.sopt_seminar_30th.presentation.ui.home.HomeActivity | ||
import co.kr.sopt_seminar_30th.presentation.viewmodel.OnBoardingViewModel | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class OnBoardingActivity : BaseActivity<ActivityOnBoardingBinding>() { | ||
override val layoutRes: Int | ||
get() = R.layout.activity_on_boarding | ||
|
||
private val viewModel by viewModels<OnBoardingViewModel>() | ||
|
||
@Inject | ||
lateinit var dataStore: SopthubDataStore | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
checkAutoLoginEnabled() | ||
checkOnBoardingEnabled() | ||
observeData() | ||
} | ||
|
||
private fun checkAutoLoginEnabled() { | ||
if (dataStore.autoLogin) { | ||
viewModel.checkAuthorization(dataStore.userId) | ||
} | ||
} | ||
|
||
private fun checkOnBoardingEnabled() { | ||
if (dataStore.onBoardingEnabled) { | ||
if (!isFinishing) { | ||
startActivity(Intent(this, SignInActivity::class.java)) | ||
finish() | ||
} | ||
} | ||
} | ||
|
||
private fun observeData() { | ||
viewModel.autoLoginState | ||
.flowWithLifecycle(this.lifecycle) | ||
.onEach { | ||
if (it) { | ||
startActivity(Intent(this, HomeActivity::class.java)) | ||
finish() | ||
} | ||
}.launchIn(this.lifecycleScope) | ||
} | ||
} |
Oops, something went wrong.
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.
sharedPreference보다 dataStore를 사용하였을 때의 이점이 무엇이 있나요?
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.
DataStore를 공부해보려고 하긴 했는데, 결과적으로 보면 저 dataStore라는 애는 SharedPreferences입니다. 왜냐면 context.getSharedPreferences() 메서드로 가져오기 때문이죠.
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.
제가 공부해보려고 한 이유는 이런 3가지 특징이 있어서라고 합니다.