Skip to content

Commit

Permalink
Merge branch 'develop' into feature/logging
Browse files Browse the repository at this point in the history
  • Loading branch information
014967 authored Dec 14, 2023
2 parents 6c1e670 + 6df0604 commit 807ab00
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ android {
targetSdk = 33
versionCode = 7
versionName = "1.0.6"

buildConfigField("String", "NATIVE_APP_KEY", "\"${gradleLocalProperties(rootDir).getProperty("native_app_key") ?: ""}\"")
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -85,4 +84,5 @@ dependencies {
implementation(libs.work.runtime.ktx)
implementation(libs.bundles.firebase)
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.remote.config)
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ kotlin-coroutine-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-tes
firebase-messaging = { module = "com.google.firebase:firebase-messaging", version.ref = "firebase" }
firebase-messaging-ktx = { module = "com.google.firebase:firebase-messaging-ktx", version.ref = "firebase" }
firebase-dynamic-link = { module = "com.google.firebase:firebase-dynamic-links-ktx" }
firebase-remote-config = { module = "com.google.firebase:firebase-config-ktx"}
firebase-analytics-ktx = { module = "com.google.firebase:firebase-analytics-ktx" }
firebase-bom = { module = "com.google.firebase:firebase-bom", version.ref = "firebase-bom"}

Expand Down
1 change: 1 addition & 0 deletions presenter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ dependencies {
androidTestImplementation(libs.androidx.compose.ui.test.junit)
debugImplementation(libs.bundles.androidx.compose.ui.debug)
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.remote.config)
implementation(libs.bundles.firebase)
androidTestImplementation(libs.test.navigation)
androidTestImplementation(libs.truth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.ManagedActivityResultLauncher
import androidx.activity.compose.rememberLauncherForActivityResult
Expand All @@ -21,11 +23,21 @@ import androidx.core.view.WindowCompat
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.analytics
import com.mashup.twotoo.presenter.ui.rememberTwoTooAppState
import com.mashup.twotoo.presenter.util.extractScreenName
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
import com.google.firebase.ktx.Firebase
import com.google.firebase.remoteconfig.ConfigUpdate
import com.google.firebase.remoteconfig.ConfigUpdateListener
import com.google.firebase.remoteconfig.FirebaseRemoteConfigException
import com.google.firebase.remoteconfig.ktx.remoteConfig
import com.google.firebase.remoteconfig.ktx.remoteConfigSettings
import com.mashup.twotoo.presenter.designsystem.component.dialog.DialogContent
import com.mashup.twotoo.presenter.designsystem.component.dialog.TwoTooDialog
import com.mashup.twotoo.presenter.designsystem.theme.TwoTooTheme
import com.mashup.twotoo.presenter.twotoo.TwoTooApp
import com.mashup.twotoo.presenter.ui.rememberTwoTooAppState
import com.mashup.twotoo.presenter.util.extractScreenName
import com.mashup.twotoo.presenter.util.getPackageInfoCompat

class MainActivity : ComponentActivity() {

Expand All @@ -42,9 +54,11 @@ class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
WindowCompat.setDecorFitsSystemWindows(window, false)

super.onCreate(savedInstanceState)

firebaseAnalytics = Firebase.analytics
remoteConfigInit()

val challengeNo = intent.getIntExtra("challengeNo", 0)
val commitNo = intent.getIntExtra("commitNo", 0)
Log.i(TAG, "onCreate: challengeNo= $challengeNo, commitNo= $commitNo")
Expand Down Expand Up @@ -82,13 +96,92 @@ class MainActivity : ComponentActivity() {
TwoTooApp(
appState = twoTooAppState,
)
if (needToUpdateVersion(context)) {
TwoTooDialog(
content = DialogContent.createVersionUpdateConfirmDialogContent(
positiveAction = {
launchGooglePlayStore(context)
},
),
)
}

}
}
}

companion object {
const val TAG = "MainActivity"
const val REMOTE_KEY_APP_VERSION = "latest_version"
}
}
private fun remoteConfigInit() {
val remoteConfig = Firebase.remoteConfig
val configSettings = remoteConfigSettings {
minimumFetchIntervalInSeconds = 3600
}
remoteConfig.setConfigSettingsAsync(configSettings)

remoteConfig.fetchAndActivate().addOnCompleteListener { task ->
val latestVersion = remoteConfig.getString(MainActivity.REMOTE_KEY_APP_VERSION)
if (task.isSuccessful) {
Log.i(MainActivity.TAG, "remoteConfigInit - Success= $latestVersion")
} else {
Log.i(MainActivity.TAG, "remoteConfigInit - Fail= $latestVersion")
}
}

remoteConfig.addOnConfigUpdateListener(object : ConfigUpdateListener {
override fun onUpdate(configUpdate: ConfigUpdate) {
Log.d(MainActivity.TAG, "Updated keys: " + configUpdate.updatedKeys)
if (configUpdate.updatedKeys.contains(MainActivity.REMOTE_KEY_APP_VERSION)) {
remoteConfig.activate()
.addOnCompleteListener { task ->
val latestVersion = remoteConfig.getString(MainActivity.REMOTE_KEY_APP_VERSION)
if (task.isSuccessful) {
Log.i(
MainActivity.TAG,
"remoteConfigInit update - Success= $latestVersion",
)
} else {
Log.i(
MainActivity.TAG,
"remoteConfigInit update - Fail= $latestVersion",
)
}
}
}
}

override fun onError(error: FirebaseRemoteConfigException) {
Log.w(MainActivity.TAG, "Config update error with code: " + error.code, error)
}
})
}

private fun needToUpdateVersion(context: Context): Boolean {
val latestVersion = Firebase.remoteConfig.getString(MainActivity.REMOTE_KEY_APP_VERSION)
val currentAppVersion = context.packageManager.getPackageInfoCompat(context.packageName).versionName
Log.i(MainActivity.TAG, "needToUpdateVersion: currentAppVersion= $currentAppVersion")
return latestVersion.isNotEmpty() && latestVersion != currentAppVersion
}

private fun launchGooglePlayStore(context: Context) {
if (checkGooglePlayServices(context)) {
val uri = "market://details?id=${context.packageName}"
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(uri))
context.startActivity(intent)
}
}

private fun checkGooglePlayServices(context: Context): Boolean {
val googleApiAvailability = GoogleApiAvailability.getInstance()
val status = googleApiAvailability.isGooglePlayServicesAvailable(context)
if (status != ConnectionResult.SUCCESS) {
Toast.makeText(context, context.getString(R.string.version_update_dialog_fail_toast), Toast.LENGTH_SHORT).show()
return false
}
return true
}

private fun checkPermission(context: Context, launcher: ManagedActivityResultLauncher<String, Boolean>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.mashup.twotoo.presenter.R
import com.mashup.twotoo.presenter.createChallenge.model.FlowerCardUiModel
import com.mashup.twotoo.presenter.designsystem.component.TwoTooImageView
import com.mashup.twotoo.presenter.designsystem.theme.MainPink
import com.mashup.twotoo.presenter.designsystem.theme.TwoTooTheme
import com.mashup.twotoo.presenter.model.FlowerName
import com.mashup.twotoo.presenter.util.AutoResizeText
import com.mashup.twotoo.presenter.util.FontSizeRange

@Composable
fun SelectFlowerLazyColumn(
Expand Down Expand Up @@ -108,11 +111,15 @@ fun FlowerCardItem(
color = TwoTooTheme.color.mainBrown,
textAlign = TextAlign.Center,
)
Text(
AutoResizeText(
text = stringResource(flowerCardModel.desc),
style = TwoTooTheme.typography.bodyNormal14,
color = TwoTooTheme.color.mainBrown,
textAlign = TextAlign.Center,
fontSizeRange = FontSizeRange(
max = 14.sp,
min = 12.sp,
),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ class DialogContent private constructor(
),
),
)

fun createVersionUpdateConfirmDialogContent(
positiveAction: () -> Unit,
) = DialogContent(
title = R.string.version_update_dialog_title,
desc = R.string.version_update_dialog_content,
dialogImage = DialogImage.updateVersion,
buttons = listOf(
DialogButtonContent(
text = R.string.version_update_dialog_positive,
action = positiveAction,
),
),
)
}
}

Expand Down Expand Up @@ -171,5 +185,11 @@ data class DialogImage(
width = 113.dp,
height = 96.dp,
)

val updateVersion = DialogImage(
image = R.drawable.img_update_version,
width = 164.dp,
height = 128.dp,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@ package com.mashup.twotoo.presenter.invite
import android.util.Log
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.SnackbarHostState
import androidx.compose.material.TextButton
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
Expand All @@ -32,8 +40,9 @@ import com.mashup.twotoo.presenter.designsystem.component.TwoTooImageView
import com.mashup.twotoo.presenter.designsystem.component.button.TwoTooOutlineTextButton
import com.mashup.twotoo.presenter.designsystem.component.button.TwoTooTextButton
import com.mashup.twotoo.presenter.designsystem.component.toast.SnackBarHost
import com.mashup.twotoo.presenter.designsystem.component.toolbar.TwoTooMainToolbar
import com.mashup.twotoo.presenter.designsystem.theme.MainBrown
import com.mashup.twotoo.presenter.designsystem.theme.TwoTooTheme
import com.mashup.twotoo.presenter.designsystem.theme.TwotooPink
import com.mashup.twotoo.presenter.util.checkInviteLink
import com.mashup.twotoo.presenter.util.findActivity
import kotlinx.coroutines.launch
Expand All @@ -43,7 +52,8 @@ import org.orbitmvi.orbit.compose.collectSideEffect
@Composable
fun WaitingAcceptPairRoute(
inviteViewModel: InviteViewModel,
onSuccessMatchingPartner: () -> Unit
onSuccessMatchingPartner: () -> Unit,
onClickOutButton: () -> Unit
) {
val state by inviteViewModel.collectAsState()
val context = LocalContext.current
Expand Down Expand Up @@ -73,6 +83,7 @@ fun WaitingAcceptPairRoute(
onClickResendInvitation = {
inviteViewModel.getUserInfo()
},
onClickOutButton = onClickOutButton,
)

inviteViewModel.collectSideEffect { sideEffect ->
Expand Down Expand Up @@ -103,9 +114,10 @@ fun WaitingAcceptPairRoute(

@Composable
fun WaitingAcceptPair(
snackState: SnackbarHostState,
onClickRefreshState: () -> Unit,
onClickResendInvitation: () -> Unit,
snackState: SnackbarHostState = SnackbarHostState(),
onClickRefreshState: () -> Unit = {},
onClickResendInvitation: () -> Unit = {},
onClickOutButton: () -> Unit = {}
) {
Box(modifier = Modifier.navigationBarsPadding()) {
Column(
Expand All @@ -115,7 +127,7 @@ fun WaitingAcceptPair(
verticalArrangement = Arrangement.SpaceAround,
) {
Spacer(modifier = Modifier.height(5.dp))
TwoTooMainToolbar()
WaitAcceptToolbar(onClickOutButton = onClickOutButton)
Text(
modifier = Modifier.padding(top = 120.dp, bottom = 28.dp),
text = stringResource(id = R.string.invite_waiting_other),
Expand Down Expand Up @@ -151,7 +163,7 @@ fun WaitingAcceptPair(
@Composable
fun WaitingInviteBottom(
onClickRefreshState: () -> Unit,
onClickResendInvitation: () -> Unit,
onClickResendInvitation: () -> Unit
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
Expand All @@ -178,6 +190,46 @@ fun WaitingInviteBottom(
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun WaitAcceptToolbar(
title: String = stringResource(id = R.string.app_name),
onClickOutButton: () -> Unit,
) {
TopAppBar(
title = {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.CenterStart) {
Text(
text = title,
color = TwotooPink,
style = TwoTooTheme.typography.headLineNormal28,
textAlign = TextAlign.Center,
modifier = Modifier.offset(x = (-16).dp).padding(horizontal = 24.dp),
)
TextButton(
modifier = Modifier
.fillMaxHeight()
.background(Color.Transparent)
.align(Alignment.CenterEnd)
.padding(end = 24.dp),
onClick = { onClickOutButton() },
) {
Text(
text = stringResource(id = R.string.out_onboarding),
color = MainBrown,
style = TwoTooTheme.typography.headLineNormal18,
textAlign = TextAlign.End,
)
}
}
},
modifier = Modifier.height(56.dp),
colors = TopAppBarDefaults.topAppBarColors(
containerColor = Color.Transparent,
),
)
}

@Preview
@Composable
private fun WaitingAcceptPreview() {
Expand Down
Loading

0 comments on commit 807ab00

Please sign in to comment.