Skip to content

Commit

Permalink
fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
HI-JIN2 committed Apr 3, 2024
2 parents 6b7f6b9 + 5d65f7c commit 3664956
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 66 deletions.
7 changes: 2 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ android {
defaultConfig {
applicationId "com.eatssu.android"
minSdk 23
compileSdkVersion 34
targetSdk 34

versionCode 12
versionName "1.1.10"

versionCode 13
versionName "1.1.11"


buildConfigField("String", "KAKAO_NATIVE_APP_KEY", "\"${properties.get('KAKAO_NATIVE_APP_KEY')}\"")
Expand Down
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 11,
"versionName": "1.1.9",
"versionCode": 13,
"versionName": "1.1.11",
"outputFile": "app-release.apk"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class GetReviewListResponse(
@SerializedName("menu") var menu: String,
@SerializedName("writerId") var writerId: Long,
@SerializedName("isWriter") var isWriter: Boolean,
@SerializedName("writerNickname") var writerNickname: String,
@SerializedName("writerNickname") var writerNickname: String?,
@SerializedName("mainRating") var mainRating: Int,
@SerializedName("amountRating") var amountRating: Int,
@SerializedName("tasteRating") var tasteRating: Int,
Expand All @@ -32,7 +32,7 @@ fun GetReviewListResponse.toReviewList(): List<Review> {
reviewId = data.reviewId,
isWriter = data.isWriter,
menu = data.menu,
writerNickname = data.writerNickname,
writerNickname = data.writerNickname ?: "์œ ์ €",
mainGrade = data.mainRating,
amountGrade = data.amountRating,
tasteGrade = data.tasteRating,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FirebaseRemoteConfigRepository {
fun init() {
// Firebase Remote Config ์ดˆ๊ธฐํ™” ์„ค์ •
val configSettings = FirebaseRemoteConfigSettings.Builder()
.setMinimumFetchIntervalInSeconds(3600) // ์บ์‹œ๋œ ๊ฐ’์„ 1์‹œ๊ฐ„๋งˆ๋‹ค ์—…๋ฐ์ดํŠธ
.setMinimumFetchIntervalInSeconds(600) // ์บ์‹œ๋œ ๊ฐ’์„ 1์‹œ๊ฐ„๋งˆ๋‹ค ์—…๋ฐ์ดํŠธ -> 10๋ถ„
.build()
instance.setConfigSettingsAsync(configSettings)
instance.setDefaultsAsync(R.xml.firebase_remote_config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.Response
import timber.log.Timber
import java.lang.reflect.Type
import javax.inject.Inject

Expand Down Expand Up @@ -103,7 +104,7 @@ class TokenInterceptor @Inject constructor(

} catch (e: Exception) {
runBlocking { logoutUseCase() }
Log.d(TAG, "์žฌ๋ฐœ๊ธ‰ ์‹คํŒจ $e")
Timber.tag(TAG).d("์žฌ๋ฐœ๊ธ‰ ์‹คํŒจ " + e)

Handler(Looper.getMainLooper()).post {
val context = App.appContext
Expand All @@ -117,7 +118,20 @@ class TokenInterceptor @Inject constructor(

if (response.code == 404) {
runBlocking { logoutUseCase() }
Log.e(TAG, "๋‹ค๋ฅธ ์œ ์ €!")
Timber.e("404 + ๋‹ค๋ฅธ ์œ ์ €!")

Handler(Looper.getMainLooper()).post {
val context = App.appContext
Toast.makeText(context, "ํ† ํฐ์ด ๋งŒ๋ฃŒ๋˜์–ด ๋กœ๊ทธ์•„์›ƒ ๋ฉ๋‹ˆ๋‹ค.", Toast.LENGTH_SHORT).show()
val intent = Intent(context, LoginActivity::class.java) // ๋กœ๊ทธ์ธ ํ™”๋ฉด์œผ๋กœ ์ด๋™
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
context.startActivity(intent)
}
}

if (response.code == 500) {
runBlocking { logoutUseCase() }
Timber.e("500 + ๋‹ค๋ฅธ ์œ ์ €")

Handler(Looper.getMainLooper()).post {
val context = App.appContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class VersionViewModel(private val repository: FirebaseRemoteConfigRepository) :
val versionCode = checkVersionCode() //์–˜๊ฐ€ ํŒŒ์ด์–ด๋ฒ ์ด์Šค์— ์žˆ๋Š” ์ตœ์‹  ๋ฒ„์ „
val thisCheckVersionCode = VERSION_CODE

Timber.d("์•ฑ์˜ versionCode๋Š” $thisCheckVersionCode ๋ฐฐํฌ๋œ ์ตœ์‹  ๋ฒ„์ „์€ $versionCode")
Timber.d("์•ฑ์˜ versionCode๋Š” " + thisCheckVersionCode + " ๋ฐฐํฌ๋œ ์ตœ์‹  ๋ฒ„์ „์€ " + versionCode)

if (thisCheckVersionCode < versionCode) { //๋ฐฐํฌ๋œ ๋ฒ„์ „์ด ํฌ๋ฉด ๊ฐ•์ œ ์—…๋ฐ์ดํŠธ
Timber.d("๊ฐ•์ œ์—…๋ฐ์ดํŠธ")
Expand All @@ -31,10 +31,6 @@ class VersionViewModel(private val repository: FirebaseRemoteConfigRepository) :
}


fun checkVersionCode(): Long {
return repository.getVersionCode()
}

fun checkVersionCode(): Long {
return repository.getVersionCode()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class IntroViewModel @Inject constructor(
}
}

companion object {
const val TAG = "IntroViewModel"
}
}

data class IntroState(
Expand Down
25 changes: 14 additions & 11 deletions app/src/main/java/com/eatssu/android/ui/login/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.eatssu.android.ui.login

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
Expand All @@ -16,6 +15,7 @@ import com.kakao.sdk.user.UserApiClient
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import timber.log.Timber


@AndroidEntryPoint
Expand Down Expand Up @@ -44,19 +44,19 @@ class LoginActivity :
val context = this
binding.mcvKakaoLogin.setOnClickListener {

Log.d(TAG, "๋ฒ„ํŠผ ํด๋ฆญ")
Timber.d("๋ฒ„ํŠผ ํด๋ฆญ")
lifecycleScope.launch {
try {
// ์„œ๋น„์Šค ์ฝ”๋“œ์—์„œ๋Š” ๊ฐ„๋‹จํ•˜๊ฒŒ ๋กœ๊ทธ์ธ ์š”์ฒญํ•˜๊ณ  oAuthToken ์„ ๋ฐ›์•„์˜ฌ ์ˆ˜ ์žˆ๋‹ค.
val oAuthToken = UserApiClient.loginWithKakao(context)
Log.d(TAG, "beanbean > $oAuthToken")
Timber.d("beanbean > $oAuthToken")
postUserInfo()

} catch (error: Throwable) {
if (error is ClientError && error.reason == ClientErrorCause.Cancelled) {
Log.d(TAG, "์‚ฌ์šฉ์ž๊ฐ€ ๋ช…์‹œ์ ์œผ๋กœ ์ทจ์†Œ")
Timber.d("์‚ฌ์šฉ์ž๊ฐ€ ๋ช…์‹œ์ ์œผ๋กœ ์ทจ์†Œ")
} else {
Log.e(TAG, "์ธ์ฆ ์—๋Ÿฌ ๋ฐœ์ƒ", error)
Timber.e(error, "์ธ์ฆ ์—๋Ÿฌ ๋ฐœ์ƒ")
}
}
}
Expand All @@ -68,28 +68,31 @@ class LoginActivity :
UserApiClient.instance.me { user, error ->
if (user != null) {
// ์œ ์ €์˜ ์•„์ด๋””
Log.d(Companion.TAG, "invoke: id =" + user.id)
Timber.d("invoke: id =" + user.id)
val providerID = user.id.toString()
// ์œ ์ €์˜ ์ด๋ฉ”์ผ
Log.d(Companion.TAG, "invoke: email =" + user.kakaoAccount!!.email)
Timber.d("invoke: email =" + user.kakaoAccount!!.email)
val email = user.kakaoAccount!!.email.toString()

loginViewModel.getLogin(email, providerID)

lifecycleScope.launch {
loginViewModel.uiState.collectLatest {
if (!it.error && !it.loading) {
Log.d(TAG, it.toString())
showToast(loginViewModel.uiState.value.toastMessage)
Timber.d(it.toString())
showToast(it.toastMessage)
startActivity<MainActivity>()
finishAffinity()
}
}
}
}
}
}

companion object {
const val TAG = "LoginActivity"
override fun onBackPressed() {
super.onBackPressed()
finishAffinity()
//ํƒˆํ‡ด๋‚˜ ๋กœ๊ทธ์•„์›ƒ ํ•˜๊ณ  ๋กœ๊ทธ์ธ ํ™”๋ฉด์œผ๋กœ ์˜ค๊ณ , ๊ทธ ๋’ค์— ๋’ค๋กœ ๊ฐ€๊ธฐ๋ฅผ ๋ˆŒ๋ €์„ ๋•Œ์— ๋ฐฑ์Šคํƒ ๋ฐฉ์ง€
}
}
19 changes: 12 additions & 7 deletions app/src/main/java/com/eatssu/android/ui/login/LoginViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.eatssu.android.ui.login

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.eatssu.android.App
import com.eatssu.android.R
import com.eatssu.android.data.dto.request.LoginWithKakaoRequest
import com.eatssu.android.data.usecase.LoginUseCase
import com.eatssu.android.data.usecase.SetAccessTokenUseCase
Expand All @@ -18,6 +19,7 @@ import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

@HiltViewModel
Expand All @@ -39,14 +41,20 @@ class LoginViewModel @Inject constructor(
_uiState.update { it.copy(loading = false, error = true) }
}.catch { e ->
_uiState.update { it.copy(error = true) }
Log.e(TAG, "kakaoLogin: ", e)
Timber.e(e, "kakaoLogin: ")
}.collectLatest { result ->
_uiState.update { it.copy(loading = false, error = false) }
_uiState.update {
it.copy(
loading = false, error = false,
toastMessage = App.appContext.getString(R.string.login_done)
)
//Todo ๋กœ๊ทธ์ธ๊ณผ ํšŒ์›๊ฐ€์ž…์— ๋”ฐ๋ฅธ ํ† ์ŠคํŠธ ๋ฉ”์‹œ์ง€ ๊ตฌ๋ถ„ํ•˜๊ธฐ
}

/*ํ† ํฐ ์ €์žฅ*/
result.result?.let {

Log.d(TAG, it.accessToken)
Timber.d(it.accessToken)

//ํ—ค๋”์— ํ† ํฐ ๋ถ™์ด๊ธฐ
setAccessTokenUseCase(it.accessToken)
Expand All @@ -57,9 +65,6 @@ class LoginViewModel @Inject constructor(
}
}

companion object {
const val TAG = "LoginViewModel"
}
}

data class LoginState(
Expand Down
21 changes: 11 additions & 10 deletions app/src/main/java/com/eatssu/android/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.eatssu.android.ui.main

//import com.eatssu.android.ui.mypage.MyPageViewModelFactory
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
Expand Down Expand Up @@ -36,6 +34,7 @@ import com.prolificinteractive.materialcalendarview.*
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import timber.log.Timber
import java.time.LocalDate
import java.util.*

Expand Down Expand Up @@ -106,15 +105,15 @@ class MainActivity : BaseActivity<ActivityMainBinding>(ActivityMainBinding::infl
}

@RequiresApi(Build.VERSION_CODES.O)
fun previousWeekAction(view: View?) {
CalendarUtils.selectedDate = CalendarUtils.selectedDate!!.minusWeeks(1)
fun previousWeekAction() {
CalendarUtils.selectedDate = CalendarUtils.selectedDate.minusWeeks(1)
onItemClick(mainPosition, CalendarUtils.selectedDate)
setWeekView()
}

@RequiresApi(Build.VERSION_CODES.O)
fun nextWeekAction(view: View?) {
CalendarUtils.selectedDate = CalendarUtils.selectedDate!!.plusWeeks(1)
fun nextWeekAction() {
CalendarUtils.selectedDate = CalendarUtils.selectedDate.plusWeeks(1)
onItemClick(mainPosition, CalendarUtils.selectedDate)
setWeekView()
}
Expand Down Expand Up @@ -158,13 +157,18 @@ class MainActivity : BaseActivity<ActivityMainBinding>(ActivityMainBinding::infl


private fun checkNicknameIsNull() {
Log.d(TAG, "๊ด€์ฐฐ ์‹œ์ž‘")
Timber.d("๊ด€์ฐฐ ์‹œ์ž‘")
mainViewModel.checkNameNull()

lifecycleScope.launch {
mainViewModel.uiState.collectLatest {
if (it.isNicknameNull) {
//๋‹‰๋„ค์ž„์ด null์ผ ๋•Œ๋Š” ๋‹‰๋„ค์ž„ ์„ค์ •์„ ์•ˆํ•˜๋ฉด ์„œ๋น„์Šค๋ฅผ ๋ชป์“ฐ๊ฒŒ ๋ง‰์•„์•ผํ•จ
intent.putExtra("force", true)
startActivity<UserNameChangeActivity>()
showToast(it.toastMessage)
} else {
showToast(it.toastMessage) //Todo ์ด๊ฒŒ ๋ˆ„๊ตฌ๋‹˜ ๋ฐ˜๊ฐ‘์Šต๋‹ˆ๋‹ค. ์ธ๋ฐ ๋‘๋ฒˆ ๋œธ
}
}
}
Expand All @@ -188,7 +192,4 @@ class MainActivity : BaseActivity<ActivityMainBinding>(ActivityMainBinding::infl
}
}

companion object {
val TAG = "MainActivity"
}
}
Loading

0 comments on commit 3664956

Please sign in to comment.