Skip to content

Commit

Permalink
AND-9558 Fix GP review issue
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 23, 2024
1 parent c40e3cd commit 1becdd8
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 40 deletions.
44 changes: 4 additions & 40 deletions app/src/main/java/com/tangem/tap/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ 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
import com.tangem.core.navigation.email.EmailSender
import com.tangem.core.ui.event.StateEvent
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.resolveReference
Expand Down Expand Up @@ -224,9 +221,6 @@ 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 Down Expand Up @@ -272,6 +266,8 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
if (intent != null) {
deepLinksRegistry.launch(intent)
}

lifecycle.addObserver(WindowObscurationObserver)
}

private fun installRouting() {
Expand Down Expand Up @@ -529,41 +525,9 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
}

override fun dispatchTouchEvent(event: MotionEvent): Boolean {
val isPartiallyObscured = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
event.flags and MotionEvent.FLAG_WINDOW_IS_PARTIALLY_OBSCURED != 0
} else {
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 (isFullyObscured) {
Timber.d("Window is partially or fully obscured")

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

isWindowFullyObscuredAlreadySent = true
}

return false
}
val result = WindowObscurationObserver.dispatchTouchEvent(event, analyticsEventsHandler)

return super.dispatchTouchEvent(event)
return if (result) super.dispatchTouchEvent(event) else false
}

private fun showSnackbar(text: String, length: Int, buttonTitle: String?, action: View.OnClickListener?) {
Expand Down
68 changes: 68 additions & 0 deletions app/src/main/java/com/tangem/tap/WindowObscurationObserver.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.tangem.tap

import android.os.Build
import android.view.MotionEvent
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
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 timber.log.Timber

internal object WindowObscurationObserver : DefaultLifecycleObserver {

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

private var isReadyToProxy = false

override fun onResume(owner: LifecycleOwner) {
super.onResume(owner)
isReadyToProxy = true
}

override fun onPause(owner: LifecycleOwner) {
super.onPause(owner)
isReadyToProxy = false
}

fun dispatchTouchEvent(event: MotionEvent, analyticsEventHandler: AnalyticsEventHandler): Boolean {
if (!isReadyToProxy) return true

val isPartiallyObscured = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
event.flags and MotionEvent.FLAG_WINDOW_IS_PARTIALLY_OBSCURED != 0
} else {
false
}

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

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

isWindowPartiallyObscuredAlreadySent = true
}
}

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

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

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

isWindowFullyObscuredAlreadySent = true
}

return false
}

return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ internal class MainViewModel @Inject constructor(

override fun onDismissBottomSheet() {
listenToFlipsUseCase.changeUpdateEnabled(true)
router.pop()
stateHolder.updateWithoutModalNotification()
stateHolder.updateWithHiddenBalancesToast(true)
}
Expand Down

0 comments on commit 1becdd8

Please # to comment.