Skip to content

Commit

Permalink
AND-9537, AND-9544 Fix bug with overlay and ToS
Browse files Browse the repository at this point in the history
Signed-off-by: Mama1emon <andrew.khokhlove@gmail.com>
  • Loading branch information
Mama1emon committed Dec 20, 2024
1 parent 11dc3ab commit 7f5fbcb
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.HIDE_OVERLAY_WINDOWS" />
<!--<uses-permission android:name="android.permission.HIDE_OVERLAY_WINDOWS" />-->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.INTERNET" />
Expand Down
36 changes: 31 additions & 5 deletions app/src/main/java/com/tangem/tap/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import com.google.android.material.snackbar.Snackbar
import com.tangem.common.routing.AppRoute
import com.tangem.common.routing.entity.SerializableIntent
import com.tangem.core.analytics.api.AnalyticsEventHandler
import com.tangem.core.analytics.models.event.TechAnalyticsEvent
import com.tangem.core.analytics.models.event.TechAnalyticsEvent.WindowObscured.ObscuredState
import com.tangem.core.decompose.context.AppComponentContext
import com.tangem.core.decompose.di.RootAppComponentContext
import com.tangem.core.deeplink.DeepLinksRegistry
Expand Down Expand Up @@ -222,6 +224,9 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac

private val onActivityResultCallbacks = mutableListOf<OnActivityResultCallback>()

private var isWindowPartiallyObscuredAlreadySent: Boolean = false
private var isWindowFullyObscuredAlreadySent: Boolean = false

override fun onCreate(savedInstanceState: Bundle?) {
// We need to call it before onCreate to prevent unnecessary activity recreation
installAppTheme()
Expand All @@ -246,9 +251,9 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING)
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
window.setHideOverlayWindows(true)
}
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
// window.setHideOverlayWindows(true)
// }

splashScreen.setKeepOnScreenCondition { viewModel.isSplashScreenShown }

Expand Down Expand Up @@ -530,10 +535,31 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
false
}

if (isPartiallyObscured) {
Timber.d("Window is partially obscured")

if (!isWindowPartiallyObscuredAlreadySent) {
analyticsEventsHandler.send(
event = TechAnalyticsEvent.WindowObscured(state = ObscuredState.PARTIALLY),
)

isWindowPartiallyObscuredAlreadySent = true
}
}

val isFullyObscured = event.flags and MotionEvent.FLAG_WINDOW_IS_OBSCURED != 0

if (isPartiallyObscured || isFullyObscured) {
Timber.e("Window is partially or fully obscured")
if (isFullyObscured) {
Timber.d("Window is partially or fully obscured")

if (!isWindowFullyObscuredAlreadySent) {
analyticsEventsHandler.send(
event = TechAnalyticsEvent.WindowObscured(state = ObscuredState.FULLY),
)

isWindowFullyObscuredAlreadySent = true
}

return false
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.tangem.core.analytics.models.event

import com.tangem.core.analytics.models.AnalyticsEvent

/**
* Tech analytics event
*
* @param event event name
* @param params params
*/
sealed class TechAnalyticsEvent(
event: String,
params: Map<String, String> = mapOf(),
) : AnalyticsEvent(category = "Tech", event = event, params = params) {

class WindowObscured(state: ObscuredState) : TechAnalyticsEvent(
event = "Window Obscured",
params = mapOf("State" to state.name),
) {

enum class ObscuredState {
PARTIALLY,
FULLY,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ import java.nio.charset.StandardCharsets
@Composable
internal fun DisclaimerScreen(state: DisclaimerUM) {
val bottomBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() }
val bottomPadding = bottomBarHeight + TangemTheme.dimens.size16

val bottomPadding = if (state.isTosAccepted) {
bottomBarHeight + TangemTheme.dimens.size16
} else {
bottomBarHeight + TangemTheme.dimens.size64
}
val backgroundColor = if (state.isTosAccepted) TangemTheme.colors.background.primary else TangemColorPalette.Dark6
val (textColor, iconColor) = if (state.isTosAccepted) {
TangemTheme.colors.text.primary1 to TangemTheme.colors.icon.primary1
} else {
TangemColorPalette.Light4 to TangemColorPalette.Light4
}
Box(
modifier = Modifier
.background(TangemTheme.colors.background.primary)
.background(backgroundColor)
.statusBarsPadding()
.testTag(DISCLAIMER_SCREEN_CONTAINER),
) {
Expand All @@ -67,15 +76,14 @@ internal fun DisclaimerScreen(state: DisclaimerUM) {
onIconClicked = state.popBack,
).takeIf { state.isTosAccepted },
titleAlignment = Alignment.CenterHorizontally,
textColor = textColor,
iconTint = iconColor,
)
DisclaimerContent(state.url)
DisclaimerContent(state.url, state.isTosAccepted)
}

if (!state.isTosAccepted) {
BottomFade(
modifier = Modifier.align(Alignment.BottomCenter),
backgroundColor = TangemTheme.colors.background.primary,
)
BottomFade(Modifier.align(Alignment.BottomCenter), backgroundColor = backgroundColor)
DisclaimerButton(state.onAccept)
} else {
NavigationBar3ButtonsScrim()
Expand All @@ -84,7 +92,9 @@ internal fun DisclaimerScreen(state: DisclaimerUM) {
}

@Composable
private fun DisclaimerContent(url: String) {
private fun DisclaimerContent(url: String, isTosAccepted: Boolean) {
val backgroundColor = if (isTosAccepted) TangemTheme.colors.background.primary else TangemColorPalette.Dark6

val webViewStateUrl = rememberWebViewState(url)
val webViewStateData = rememberWebViewStateWithHTMLData(
data = localTermsOfServices,
Expand Down Expand Up @@ -119,12 +129,12 @@ private fun DisclaimerContent(url: String) {
exit = fadeOut(),
modifier = Modifier
.fillMaxSize()
.background(TangemTheme.colors.background.primary),
.background(backgroundColor),
) {
Box(
modifier = Modifier
.fillMaxSize()
.background(TangemTheme.colors.background.primary),
.background(backgroundColor),
) {
CircularProgressIndicator(
color = TangemTheme.colors.icon.informative,
Expand Down

0 comments on commit 7f5fbcb

Please # to comment.