Skip to content

Commit e36f9b1

Browse files
authored
Merge pull request #373 from DKU-Dgaja/an-feat(#359)-앱-실행-시-token-유효하면-로그인-생략하는-기능-구현
[AN] feat(#359): 앱 실행 시 token 유효하면 로그인 생략하는 기능 구현
2 parents 7e90e02 + c69ef26 commit e36f9b1

File tree

3 files changed

+81
-6
lines changed

3 files changed

+81
-6
lines changed

android/gitudy/presentation/src/main/java/com/takseha/presentation/adapter/FeedRVAdapter.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ class FeedRVAdapter(val context : Context, val studyInfoList : List<StudyInfo>)
4646
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
4747
if (studyInfoList[position].profileImageUrl.isEmpty()) {
4848
holder.backgroundColor.setBackgroundColor(Color.parseColor(backgroundColorList[position % 6]))
49-
} else {
49+
} else if (studyInfoList[position].profileImageUrl != "string") {
5050
holder.backgroundColor.setBackgroundColor(Color.parseColor(studyInfoList[position].profileImageUrl))
51+
} else {
52+
holder.backgroundColor.setBackgroundColor(Color.parseColor(backgroundColorList[position % 6]))
5153
}
5254
holder.studyName.text = studyInfoList[position].topic
5355
holder.commitRule.text = setCommitRule(studyInfoList[position].periodType)

android/gitudy/presentation/src/main/java/com/takseha/presentation/ui/SplashActivity.kt

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,53 @@ import androidx.appcompat.app.AppCompatActivity
55
import android.os.Bundle
66
import android.os.Handler
77
import android.os.Looper
8+
import android.util.Log
9+
import androidx.activity.viewModels
810
import androidx.core.content.ContextCompat
11+
import androidx.lifecycle.lifecycleScope
912
import com.takseha.presentation.R
1013
import com.takseha.presentation.ui.auth.LoginActivity
14+
import com.takseha.presentation.ui.home.MainHomeActivity
15+
import com.takseha.presentation.viewmodel.auth.SplashViewModel
16+
import kotlinx.coroutines.flow.collectLatest
17+
import kotlinx.coroutines.launch
1118

1219
class SplashActivity : AppCompatActivity() {
20+
private val viewModel: SplashViewModel by viewModels()
1321
/*
1422
TODO :
1523
리팩토링 시 구현해야 할 것
1624
1. splash 화면에서 info api 연동해서 role 확인 -> 자동로그인 기능 구현(로그인 및 회원가입 화면 pass 하는 로직 구현)
1725
2. 닉네임 특수기호(이모티콘) 입력 불가하도록 하는 기능 추가
18-
3. githubId 유효성 검사
1926
*/
2027

2128
override fun onCreate(savedInstanceState: Bundle?) {
2229
super.onCreate(savedInstanceState)
2330
setContentView(R.layout.activity_splash)
2431
window.statusBarColor = ContextCompat.getColor(this, R.color.BACKGROUND)
2532

26-
Handler(Looper.getMainLooper()).postDelayed({
27-
startActivity(Intent(this, LoginActivity::class.java))
28-
finish()
29-
}, 2000)
33+
lifecycleScope.launch {
34+
viewModel.checkAvailableToken()
35+
}
36+
lifecycleScope.launch {
37+
viewModel.availableTokenCheck.observe(this@SplashActivity) {
38+
setMainHome(it)
39+
Log.d("SplashActivity", it.toString())
40+
}
41+
}
42+
}
43+
44+
private fun setMainHome(availableTokenState: Boolean) {
45+
if (availableTokenState) {
46+
Handler(Looper.getMainLooper()).postDelayed({
47+
startActivity(Intent(this, MainHomeActivity::class.java))
48+
finish()
49+
}, 2000)
50+
} else {
51+
Handler(Looper.getMainLooper()).postDelayed({
52+
startActivity(Intent(this, LoginActivity::class.java))
53+
finish()
54+
}, 2000)
55+
}
3056
}
3157
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.takseha.presentation.viewmodel.auth
2+
3+
import android.app.Application
4+
import android.util.Log
5+
import androidx.lifecycle.AndroidViewModel
6+
import androidx.lifecycle.LiveData
7+
import androidx.lifecycle.MutableLiveData
8+
import com.takseha.common.model.SPKey
9+
import com.takseha.common.util.SP
10+
import com.takseha.data.repository.auth.GitudyAuthRepository
11+
import kotlinx.coroutines.flow.MutableStateFlow
12+
import kotlinx.coroutines.flow.asStateFlow
13+
14+
class SplashViewModel(application: Application) : AndroidViewModel(application) {
15+
private var gitudyAuthRepository: GitudyAuthRepository = GitudyAuthRepository()
16+
private val prefs = SP(getApplication())
17+
18+
private val bearerToken = "Bearer ${prefs.loadPref(SPKey.ACCESS_TOKEN, "0")} ${
19+
prefs.loadPref(SPKey.REFRESH_TOKEN, "0")
20+
}"
21+
22+
private var _availableTokenCheck = MutableLiveData<Boolean>()
23+
val availableTokenCheck : LiveData<Boolean>
24+
get() = _availableTokenCheck
25+
26+
suspend fun checkAvailableToken() {
27+
val checkTokenResponse = gitudyAuthRepository.getUserInfo(bearerToken)
28+
Log.d("SplashViewModel", bearerToken)
29+
30+
if (checkTokenResponse.isSuccessful) {
31+
val resCode = checkTokenResponse.body()!!.resCode
32+
val resMsg = checkTokenResponse.body()!!.resMsg
33+
34+
if (resCode == 200 && resMsg == "OK") {
35+
_availableTokenCheck.value = true
36+
} else {
37+
_availableTokenCheck.value = false
38+
Log.e("SplashViewModel", "https status error: $resCode, $resMsg")
39+
}
40+
} else {
41+
Log.e(
42+
"SplashViewModel",
43+
"tokenResponse status: ${checkTokenResponse.code()}\ntokenResponse message: ${checkTokenResponse.message()}"
44+
)
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)