diff --git a/app/build.gradle b/app/build.gradle index 3d7c331a..8e4a6905 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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"] @@ -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.+' diff --git a/app/src/main/java/org/keepgoeat/data/interceptor/AuthInterceptor.kt b/app/src/main/java/org/keepgoeat/data/interceptor/AuthInterceptor.kt index df80c936..3dd2b507 100644 --- a/app/src/main/java/org/keepgoeat/data/interceptor/AuthInterceptor.kt +++ b/app/src/main/java/org/keepgoeat/data/interceptor/AuthInterceptor.kt @@ -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 @@ -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) @@ -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( + 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 { @@ -58,7 +64,6 @@ class AuthInterceptor @Inject constructor( ) showToast(getString(R.string.auto_login_failure)) localStorage.clear() - cancel() } } } diff --git a/app/src/main/java/org/keepgoeat/di/NetworkModule.kt b/app/src/main/java/org/keepgoeat/di/NetworkModule.kt index 76419ce8..6d7ba10f 100644 --- a/app/src/main/java/org/keepgoeat/di/NetworkModule.kt +++ b/app/src/main/java/org/keepgoeat/di/NetworkModule.kt @@ -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 @@ -33,10 +31,6 @@ object NetworkModule { ignoreUnknownKeys = true } - @Provides - @Singleton - fun provideGson(): Gson = GsonBuilder().setLenient().create() - @ExperimentalSerializationApi @Provides @Singleton diff --git a/app/src/main/java/org/keepgoeat/presentation/home/HomeViewModel.kt b/app/src/main/java/org/keepgoeat/presentation/home/HomeViewModel.kt index 482f9288..ecf9af04 100644 --- a/app/src/main/java/org/keepgoeat/presentation/home/HomeViewModel.kt +++ b/app/src/main/java/org/keepgoeat/presentation/home/HomeViewModel.kt @@ -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 diff --git a/app/src/main/java/org/keepgoeat/presentation/my/MyActivity.kt b/app/src/main/java/org/keepgoeat/presentation/my/MyActivity.kt index 8e3b98d9..ba94bcf9 100644 --- a/app/src/main/java/org/keepgoeat/presentation/my/MyActivity.kt +++ b/app/src/main/java/org/keepgoeat/presentation/my/MyActivity.kt @@ -25,9 +25,14 @@ class MyActivity : MixpanelActivity(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() diff --git a/app/src/main/res/layout/activity_my.xml b/app/src/main/res/layout/activity_my.xml index 25a4bfa5..08a0d5b8 100644 --- a/app/src/main/res/layout/activity_my.xml +++ b/app/src/main/res/layout/activity_my.xml @@ -160,16 +160,16 @@ app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" + tools:text="1.0.0" /> KeepGoEat upload - 1.0.0 - Keepgo2at@gmail.com + keepgo2at@gmail.com market://details?id= diff --git a/build.gradle b/build.gradle index b6917361..754c9033 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } }