Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
youngjinc committed May 15, 2023
2 parents 76cc89b + bd111b5 commit 494770f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 26 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ android {
applicationId "org.keepgoeat"
minSdk 28
targetSdk 33
versionCode 16
versionName "1.0.0"
versionCode 19
versionName "1.0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField "String", "KGE_BASE_URL", properties["KGE_BASE_URL"]
Expand Down Expand Up @@ -85,17 +85,17 @@ dependencies {
implementation 'com.jakewharton.timber:timber:5.0.1'

// Network
implementation platform('com.squareup.okhttp3:okhttp-bom:4.10.0')
implementation platform('com.squareup.okhttp3:okhttp-bom:4.11.0')
implementation 'com.squareup.okhttp3:okhttp'
implementation 'com.squareup.okhttp3:logging-interceptor'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1'
implementation 'com.google.code.gson:gson:2.10'

// Firebase
implementation platform('com.google.firebase:firebase-bom:31.1.1')
implementation 'com.google.firebase:firebase-crashlytics-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'

// Mixpanel
implementation 'com.mixpanel.android:mixpanel-android:7.+'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package org.keepgoeat.data.interceptor

import android.app.Application
import android.content.Intent
import com.google.gson.Gson
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
Expand All @@ -18,18 +18,20 @@ import org.keepgoeat.util.extension.showToast
import javax.inject.Inject

class AuthInterceptor @Inject constructor(
private val json: Json,
private val localStorage: KGEDataSource,
private val gson: Gson,
private val context: Application,
) : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response {
val originalRequest = chain.request()
val authRequest = originalRequest.newAuthBuilder().build()
val authRequest =
if (!localStorage.isLogin) originalRequest else originalRequest.newAuthBuilder().build()
val response = chain.proceed(authRequest)

when (response.code) {
401 -> {
response.close()
val refreshTokenRequest = originalRequest.newBuilder().get()
.url("${BuildConfig.KGE_BASE_URL}auth/refresh")
.addHeader(ACCESS_TOKEN, localStorage.accessToken)
Expand All @@ -38,14 +40,18 @@ class AuthInterceptor @Inject constructor(
val refreshTokenResponse = chain.proceed(refreshTokenRequest)

if (refreshTokenResponse.isSuccessful) {
val responseRefresh = gson.fromJson(
refreshTokenResponse.body?.string(),
ResponseRefresh::class.java
)
val responseRefresh =
json.decodeFromString<ResponseRefresh>(
refreshTokenResponse.body?.string()
?: throw IllegalStateException("refreshTokenResponse is null $refreshTokenResponse")
)

with(localStorage) {
accessToken = responseRefresh.data.accessToken
refreshToken = responseRefresh.data.refreshToken
}
refreshTokenResponse.close()

val newRequest = originalRequest.newAuthBuilder().build()
return chain.proceed(newRequest)
} else {
Expand All @@ -58,7 +64,6 @@ class AuthInterceptor @Inject constructor(
)
showToast(getString(R.string.auto_login_failure))
localStorage.clear()
cancel()
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/java/org/keepgoeat/di/NetworkModule.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.keepgoeat.di

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import dagger.Module
import dagger.Provides
Expand Down Expand Up @@ -33,10 +31,6 @@ object NetworkModule {
ignoreUnknownKeys = true
}

@Provides
@Singleton
fun provideGson(): Gson = GsonBuilder().setLenient().create()

@ExperimentalSerializationApi
@Provides
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class HomeViewModel @Inject constructor(
val splitCurrent = BuildConfig.VERSION_NAME.split(".")
val splitUpdate = updateVersion.split(".")
if (splitCurrent.size > 2 && splitUpdate.size > 2) {
if (splitCurrent[2] != splitUpdate[2]) return true
if (splitCurrent[2] < splitUpdate[2]) return true
}

return false
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/keepgoeat/presentation/my/MyActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ class MyActivity : MixpanelActivity<ActivityMyBinding>(R.layout.activity_my, SCR
binding.lifecycleOwner = this

viewModel.fetchUserInfo()
initLayout()
addListeners()
}

private fun initLayout() {
binding.tvVersionName.text = BuildConfig.VERSION_NAME
}

private fun addListeners() {
binding.viewToolbar.ivBack.setOnClickListener {
finish()
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_my.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,16 @@
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_version_code"
android:id="@+id/tv_version_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/spacing16"
android:text="@string/app_version"
android:textAppearance="@style/TextAppearance.System4"
android:textColor="@color/gray_400"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
tools:text="1.0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>

<View
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<resources>
<string name="app_name">KeepGoEat</string>
<string name="dummy_upload">upload</string>
<string name="app_version">1.0.0</string>
<string name="keep_go_eat_mail">[email protected]</string>
<string name="keep_go_eat_mail">[email protected]</string>
<string name="play_store_detail_url">market://details?id=</string>

<!-- Global -->
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}
dependencies {
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.5'
classpath 'com.google.gms:google-services:4.3.14'
}
}
Expand Down

0 comments on commit 494770f

Please sign in to comment.