Skip to content

Commit

Permalink
Merge pull request #38 from MONEYMONG/MONEYMONG-511
Browse files Browse the repository at this point in the history
Moneymong 511 강제 업데이트 얼랏창 구현
  • Loading branch information
jhg3410 authored Oct 27, 2024
2 parents 3c1feb0 + 964c26e commit 21aac59
Show file tree
Hide file tree
Showing 43 changed files with 204 additions and 99 deletions.
7 changes: 3 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
import java.io.FileInputStream
import java.util.Properties

@Suppress("DSL_SCOPE_VIOLATION")
plugins {
Expand Down Expand Up @@ -30,7 +28,7 @@ android {
}
buildConfigField("String", "NATIVE_APP_KEY", getApiKey("native_app_key"))
}
buildFeatures{
buildFeatures {
buildConfig = true
}

Expand Down Expand Up @@ -74,6 +72,7 @@ dependencies {

implementation(libs.androidx.activity.compose)
implementation(libs.androidx.compose.material3)
implementation(libs.lifecycle.runtime.compose)
implementation(libs.orbit.core)
implementation(libs.orbit.compose)
implementation(libs.orbit.viewModel)
Expand All @@ -85,6 +84,6 @@ dependencies {
androidTestImplementation(libs.androidx.test.espresso.core)
}

fun getApiKey(propertyKey : String): String {
fun getApiKey(propertyKey: String): String {
return gradleLocalProperties(rootDir).getProperty(propertyKey)
}
58 changes: 36 additions & 22 deletions app/src/main/java/com/moneymong/moneymong/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
package com.moneymong.moneymong

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.activity.viewModels
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.compose.LifecycleStartEffect
import com.moneymong.moneymong.common.event.EventTracker
import dagger.hilt.android.AndroidEntryPoint
import com.moneymong.moneymong.design_system.error.ErrorDialog
import com.moneymong.moneymong.design_system.theme.MMTheme
import com.moneymong.moneymong.domain.repository.TokenRepository
import com.moneymong.moneymong.domain.repository.user.UserRepository
import com.moneymong.moneymong.feature.sign.LoginScreen
import com.moneymong.moneymong.feature.sign.SignUpScreen
import com.moneymong.moneymong.ocr.OCRScreen
import com.moneymong.moneymong.domain.repository.token.TokenRepository
import com.moneymong.moneymong.ui.MoneyMongApp
import kotlinx.coroutines.CoroutineDispatcher
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import org.orbitmvi.orbit.compose.collectAsState
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
private val viewModel: MainViewModel by viewModels()

@Inject
lateinit var tokenRepository: TokenRepository
Expand All @@ -41,7 +38,32 @@ class MainActivity : ComponentActivity() {
eventTracker.initialize()

setContent {
val context = LocalContext.current
val state by viewModel.collectAsState()

val shouldUpdate = state.shouldUpdate
LifecycleStartEffect(key1 = Unit, effects = {
viewModel.checkShouldUpdate(version = BuildConfig.VERSION_NAME)
onStopOrDispose { }
})

MMTheme {
if (shouldUpdate) {
ErrorDialog(
message = "안정적인 머니몽 사용을 위해\n최신 버전으로 업데이트가 필요해요!",
confirmText = "업데이트",
onConfirm = {
val playStoreUrl =
"https://play.google.com/store/apps/details?id=${BuildConfig.APPLICATION_ID}"
val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(playStoreUrl)
setPackage("com.android.vending")
}
context.startActivity(intent)
}
)
}

MoneyMongApp(expired.value) {
expired.value = false
}
Expand All @@ -54,12 +76,4 @@ class MainActivity : ComponentActivity() {
}
}
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/moneymong/moneymong/MainState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package com.moneymong.moneymong
import com.moneymong.moneymong.common.base.State

data class MainState(
val something: Any? = null // TODO
val shouldUpdate: Boolean = false
): State
15 changes: 14 additions & 1 deletion app/src/main/java/com/moneymong/moneymong/MainViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package com.moneymong.moneymong

import com.moneymong.moneymong.common.base.BaseViewModel
import com.moneymong.moneymong.domain.usecase.version.CheckVersionUpdateUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import org.orbitmvi.orbit.syntax.simple.intent
import org.orbitmvi.orbit.syntax.simple.reduce
import javax.inject.Inject

@HiltViewModel
class MainViewModel @Inject constructor() : BaseViewModel<MainState, MainSideEffect>(MainState()) {
class MainViewModel @Inject constructor(
val checkVersionUpdateUseCase: CheckVersionUpdateUseCase
) : BaseViewModel<MainState, MainSideEffect>(MainState()) {

fun checkShouldUpdate(version: String) = intent {
val shouldUpdate =
checkVersionUpdateUseCase(version = version).isFailure
reduce {
state.copy(shouldUpdate = shouldUpdate)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ fun ErrorDialog(
modifier: Modifier = Modifier,
message: String,
description: String = "",
onConfirm: () -> Unit
confirmText: String = "확인",
onConfirm: () -> Unit,
) {
val horizontalPadding = 22.dp
val buttonWidth = 276.dp
Expand Down Expand Up @@ -93,7 +94,7 @@ fun ErrorDialog(
MDSButton(
modifier = Modifier.width(buttonWidth),
onClick = onConfirm,
text = "확인",
text = confirmText,
type = MDSButtonType.PRIMARY,
size = MDSButtonSize.LARGE,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.moneymong.moneymong.model.version

data class VersionRequest(
val version: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ private class ResultCall<T>(
return Result.failure(MoneyMongError.UnExpectedError)
}

val errorResponse = fromJsonToErrorResponse(errorBody)
val httpError = getErrorByStatusCode(
statusCode = errorResponse.status,
message = errorResponse.message
)
return Result.failure(httpError)
return try {
val errorResponse = fromJsonToErrorResponse(errorBody)
val httpError = getErrorByStatusCode(
statusCode = errorResponse.status,
message = errorResponse.message
)
Result.failure(httpError)
} catch (e: Exception) {
Result.failure(MoneyMongError.UnExpectedError)
}
}

override fun onFailure(call: Call<T>, t: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.moneymong.moneymong.network.api
import com.moneymong.moneymong.model.ocr.FileUploadResponse
import okhttp3.MultipartBody
import retrofit2.http.Multipart
import retrofit2.http.Part
import retrofit2.http.POST
import retrofit2.http.Part

interface MoneyMongApi {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.moneymong.moneymong.network.api

import com.moneymong.moneymong.model.version.VersionRequest
import retrofit2.http.Body
import retrofit2.http.POST

interface VersionApi {

@POST("api/v1/version")
suspend fun checkUpdate(
@Body version: VersionRequest
): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.moneymong.moneymong.network.api.MemberApi
import com.moneymong.moneymong.network.api.MoneyMongApi
import com.moneymong.moneymong.network.api.UniversityApi
import com.moneymong.moneymong.network.api.UserApi
import com.moneymong.moneymong.network.api.VersionApi
import com.moneymong.moneymong.network.util.AuthInterceptor
import com.moneymong.moneymong.network.util.MoneyMongTokenAuthenticator
import dagger.Module
Expand Down Expand Up @@ -143,6 +144,10 @@ object NetworkModule {
fun provideMemberApi(@MoneyMongRetrofit retrofit: Retrofit): MemberApi =
retrofit.create(MemberApi::class.java)

@Provides
fun provideVersionApi(@MoneyMongRetrofit retrofit: Retrofit): VersionApi =
retrofit.create(VersionApi::class.java)

@Provides
fun provideClovaApi(@ClovaRetrofit retrofit: Retrofit): ClovaApi =
retrofit.create(ClovaApi::class.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.moneymong.moneymong.network.response

import com.google.gson.Gson
import com.google.gson.annotations.SerializedName

data class ErrorResponse(
val status: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.moneymong.moneymong.network.util

import com.moneymong.moneymong.domain.repository.TokenRepository
import com.moneymong.moneymong.domain.repository.token.TokenRepository
import com.moneymong.moneymong.network.BuildConfig
import kotlinx.coroutines.runBlocking
import okhttp3.Interceptor
Expand All @@ -24,9 +24,11 @@ class AuthInterceptor @Inject constructor(
tokenRepository.getAccessToken()
}

val newRequest = originalRequest.newBuilder()
.addHeader("Authorization", "Bearer ${accessToken.getOrNull()}")
.build()
val newRequest = originalRequest.newBuilder().apply {
accessToken.getOrNull()?.let {
addHeader("Authorization", "Bearer $it")
} ?: addHeader("Authorization", "null")
}.build()

return chain.proceed(newRequest)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.moneymong.moneymong.network.util

import com.moneymong.moneymong.domain.repository.TokenRepository
import com.moneymong.moneymong.domain.repository.token.TokenRepository
import com.moneymong.moneymong.network.BuildConfig
import kotlinx.coroutines.runBlocking
import okhttp3.Authenticator
Expand Down
19 changes: 0 additions & 19 deletions core/ui/src/main/java/com/moneymong/moneymong/ui/RippleEffect.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.moneymong.moneymong.data.datasource.version

interface VersionRemoteDataSource {

suspend fun checkUpdate(version: String): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.moneymong.moneymong.data.datasource.version

import com.moneymong.moneymong.model.version.VersionRequest
import com.moneymong.moneymong.network.api.VersionApi
import javax.inject.Inject

class VersionRemoteDataSourceImpl @Inject constructor(
private val versionApi: VersionApi
) : VersionRemoteDataSource {
override suspend fun checkUpdate(version: String): Result<Unit> {
return versionApi.checkUpdate(VersionRequest(version = version))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import com.moneymong.moneymong.data.datasource.user.UserLocalDataSource
import com.moneymong.moneymong.data.datasource.user.UserLocalDataSourceImpl
import com.moneymong.moneymong.data.datasource.user.UserRemoteDataSource
import com.moneymong.moneymong.data.datasource.user.UserRemoteDataSourceImpl
import com.moneymong.moneymong.data.datasource.version.VersionRemoteDataSource
import com.moneymong.moneymong.data.datasource.version.VersionRemoteDataSourceImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -92,4 +94,9 @@ interface DataSourceModule {
fun bindLedgerDetailRemoteDataSource(
ledgerDetailRemoteDataSourceImpl: LedgerDetailRemoteDataSourceImpl
): LedgerDetailRemoteDataSource

@Binds
fun bindVersionRemoteDataSource(
versionRemoteDataSourceImpl: VersionRemoteDataSourceImpl
): VersionRemoteDataSource
}
Loading

0 comments on commit 21aac59

Please sign in to comment.