NTP-865 | Bottomsheet bug fix (#210)

Co-authored-by: Varun Jain <varun.jain@navi.com>
This commit is contained in:
Sayed Owais Ali
2024-07-30 12:56:04 +05:30
committed by GitHub
parent fd3a700b02
commit 4d1e9b2d29
4 changed files with 37 additions and 20 deletions

View File

@@ -343,7 +343,10 @@ object AlfredManager {
if (
config.getAlfredStatus() &&
config.getMetricsApiEnableStatus() &&
config.getAlfredSessionId().isNotEmpty()
config.getAlfredSessionId().isNotEmpty() &&
isAppInBackground.not() &&
isActivityResumed &&
hasRecordingStarted
) {
coroutineDispatcher.executor.execute {
val duration: Long = endTime - startTime

View File

@@ -51,7 +51,8 @@ internal suspend fun getScreenShotUsingCanvasDraw(
context = AlfredManager.applicationContext,
moduleName = AlfredManager.currentModuleName,
screenName = AlfredManager.currentScreenName,
scope = AlfredManager.coroutineScope
scope = AlfredManager.coroutineScope,
view = view
)
}
} else {

View File

@@ -35,15 +35,18 @@ fun getScreenShotUsingPixelCopy(
) {
if (isViewCaptureNotReady(activity, view)) return
val handlerThread = HandlerThread("PixelCopyThread")
handlerThread.start()
val captureWindow =
if (isBottomSheet == false) {
activity?.window
} else {
AlfredManager.dialog?.window
}
if (isWindowCaptureNotReady(captureWindow)) return
val handlerThread = HandlerThread("PixelCopyThread")
handlerThread.start()
captureWindow?.let { window ->
val locationOfViewInWindow = IntArray(2)
view.getLocationInWindow(locationOfViewInWindow)
@@ -126,13 +129,17 @@ fun onPixelCopySuccess(
context = AlfredManager.applicationContext,
moduleName = AlfredManager.currentModuleName,
screenName = AlfredManager.currentScreenName,
scope = scope
scope = scope,
view = view
)
} else {
val bottomSheetView =
AlfredManager.reactBottomSheetView?.get()
?: AlfredManager.dialog?.window?.decorView?.rootView
if (!AlfredManager.config.getDisableDialogScreenShot() && bottomSheetView != null) {
val bottomSheetView = AlfredManager.dialog?.window?.decorView?.rootView
val bottomSheetWindow = AlfredManager.dialog?.window
if (
!AlfredManager.config.getDisableDialogScreenShot() &&
bottomSheetView != null &&
bottomSheetWindow != null
) {
captureBottomSheetUsingPixelCopy(
bitmap = bitmap,
activity = activity,

View File

@@ -9,7 +9,6 @@ package com.navi.alfred.utils
import android.app.Activity
import android.content.Context
import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
@@ -17,6 +16,7 @@ import android.graphics.Paint
import android.os.Build
import android.view.View
import android.view.ViewGroup
import android.view.Window
import androidx.core.view.isVisible
import com.navi.alfred.AlfredManager
import com.navi.alfred.db.AlfredDatabaseHelper
@@ -47,7 +47,8 @@ internal fun combineScreenshots(
context: Context,
screenName: String? = null,
moduleName: String? = null,
scope: CoroutineScope
scope: CoroutineScope,
view: View
): Bitmap? {
if (
backgroundScreenshot == null ||
@@ -56,15 +57,13 @@ internal fun combineScreenshots(
) {
return null
}
var screenWidth = Resources.getSystem().displayMetrics.widthPixels / 2
var screenHeight = Resources.getSystem().displayMetrics.heightPixels / 2
var screenWidth = view.width / 2
var screenHeight = view.height / 2
if (!isResolutionEven(screenWidth, screenHeight)) {
screenHeight += 1
screenWidth += 1
}
val combinedBitmap = Bitmap.createBitmap(screenWidth, screenHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(combinedBitmap)
canvas.drawBitmap(backgroundScreenshot, 0f, 0f, null)
val canvas = Canvas(backgroundScreenshot)
var bottomSheetLeft = (screenWidth - bottomSheetScreenshot.width) / 2f
var bottomSheetTop = screenHeight - bottomSheetScreenshot.height.toFloat()
if (!isResolutionEven(bottomSheetLeft.toInt(), bottomSheetTop.toInt())) {
@@ -72,8 +71,8 @@ internal fun combineScreenshots(
bottomSheetTop = (bottomSheetTop.toInt() + 1).toFloat()
}
canvas.drawBitmap(bottomSheetScreenshot, bottomSheetLeft, bottomSheetTop, null)
insertScreenShotPathInDb(scope, context, combinedBitmap)
return combinedBitmap
insertScreenShotPathInDb(scope, context, backgroundScreenshot)
return backgroundScreenshot
}
internal fun insertScreenShotPathInDb(
@@ -340,7 +339,7 @@ internal fun isResolutionEven(width: Int, height: Int): Boolean {
return width.mod(2) == 0 && height.mod(2) == 0
}
fun isViewCaptureNotReady(activity: Activity?, view: View): Boolean {
internal fun isViewCaptureNotReady(activity: Activity?, view: View): Boolean {
return activity == null ||
!view.isVisible ||
!view.isAttachedToWindow ||
@@ -349,3 +348,10 @@ fun isViewCaptureNotReady(activity: Activity?, view: View): Boolean {
activity.isFinishing ||
activity.isDestroyed
}
internal fun isWindowCaptureNotReady(window: Window?): Boolean {
return window == null ||
window.decorView.width == 0 ||
window.decorView.height == 0 ||
window.peekDecorView() == null
}