Added bottomsheet weak reference (#12)

This commit is contained in:
Girish Suragani
2023-10-11 15:27:19 +05:30
committed by Shivam Goyal
parent 92266e8411
commit b25968983a
3 changed files with 34 additions and 11 deletions

19
app/.gitignore vendored
View File

@@ -1 +1,18 @@
/build
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
/.idea/deploymentTargetDropDown.xml
/.idea/gradle.xml
/.idea/misc.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties

View File

@@ -5,7 +5,7 @@ plugins {
id 'maven-publish'
}
def VERSION_NAME = "v1.0.1"
def VERSION_NAME = "v1.0.2"
android {
namespace 'com.navi.alfred'

View File

@@ -7,7 +7,6 @@
package com.navi.alfred
import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Context
import android.graphics.Bitmap
@@ -80,8 +79,8 @@ import java.util.UUID
import java.util.concurrent.Executors
import kotlin.concurrent.fixedRateTimer
import java.lang.Long.min
import java.lang.ref.WeakReference
@SuppressLint("StaticFieldLeak")
object AlfredManager {
lateinit var config: AlfredConfig
@@ -102,7 +101,7 @@ object AlfredManager {
private var isAppInBackground: Boolean = false
private var hasRecordingStarted: Boolean = false
var dialog: Dialog? = null
var cosmosBottomSheet: View? = null
private var reactBottomSheetView: WeakReference<View>? = null
private var timer: Timer? = null
private var screenShotTimer: Timer? = null
private var viewLayoutDelay: Long = 1000
@@ -172,9 +171,12 @@ object AlfredManager {
bmpForCanvas = createBitmapForView(view)
}
try {
if (dialog != null || cosmosBottomSheet != null) {
val bottomSheetView = reactBottomSheetView?.get()
?: dialog?.window?.decorView?.rootView
if (bottomSheetView != null) {
captureBottomSheet(
view,
bottomSheetView,
context,
currentScreenName,
bmpForCanvas?.first,
@@ -231,6 +233,7 @@ object AlfredManager {
private suspend fun captureBottomSheet(
view: View,
bottomSheetView: View,
context: Context,
screenName: String? = null,
rootCanvas: Canvas? = null,
@@ -240,11 +243,6 @@ object AlfredManager {
if (config.getDisableDialogScreenShot()) {
return
}
val bottomSheetView = if (cosmosBottomSheet != null) {
cosmosBottomSheet
} else {
dialog?.window?.decorView?.rootView
}
if (bottomSheetView != null) {
val bottomSheetCanvasForBitmap = createBitmapForView(bottomSheetView)
val bottomSheetScreenShot =
@@ -282,6 +280,14 @@ object AlfredManager {
}
}
fun setBottomSheetView(view: View) {
reactBottomSheetView = WeakReference(view)
}
fun clearBottomSheetView() {
reactBottomSheetView?.clear()
}
private fun checkDbBeforeStartRecording() {
coroutineScope.launch(Dispatchers.IO) {
if (screenShotDao.getScreenShotCount() > 0) {