diff --git a/app/src/main/java/com/quillstudios/pokegoalshelper/ScreenCaptureService.kt b/app/src/main/java/com/quillstudios/pokegoalshelper/ScreenCaptureService.kt index e78a1a1..c306af6 100644 --- a/app/src/main/java/com/quillstudios/pokegoalshelper/ScreenCaptureService.kt +++ b/app/src/main/java/com/quillstudios/pokegoalshelper/ScreenCaptureService.kt @@ -333,29 +333,8 @@ class ScreenCaptureService : Service() { return } - // Initialize long screenshot system with shared MediaProjection - val screenDimensions = screenCaptureManager.getScreenDimensions() - val mediaProjection = screenCaptureManager.getMediaProjection() - val screenDensity = screenCaptureManager.getScreenDensity() - - if (screenDimensions != null && mediaProjection != null) { - val (screenWidth, screenHeight) = screenDimensions - longScreenshotCapture = LongScreenshotCapture(this, handler) - - // Initialize with the shared MediaProjection - val initialized = longScreenshotCapture!!.initialize( - mediaProjection, screenWidth, screenHeight, screenDensity - ) - - if (initialized) { - PGHLog.i(TAG, "✅ Long screenshot system initialized successfully") - } else { - PGHLog.e(TAG, "❌ Failed to initialize long screenshot system") - longScreenshotCapture = null - } - } else { - PGHLog.w(TAG, "⚠️ Cannot initialize long screenshot - missing MediaProjection or screen dimensions") - } + // Long screenshot system will be initialized lazily when first used + PGHLog.d(TAG, "📸 Long screenshot system prepared for lazy initialization") PGHLog.d(TAG, "Screen capture setup complete") // Show floating overlay @@ -1249,6 +1228,12 @@ class ScreenCaptureService : Service() { { PGHLog.i(TAG, "🚀 Starting long screenshot collection") + // Try to initialize if not already done + if (longScreenshotCapture == null) { + PGHLog.i(TAG, "🔧 Long screenshot not initialized, attempting to initialize now...") + initializeLongScreenshotSystem() + } + longScreenshotCapture?.let { capture -> // Set up callbacks capture.setProgressCallback { count -> @@ -1275,7 +1260,7 @@ class ScreenCaptureService : Service() { PGHLog.i(TAG, "✅ Long screenshot collection started successfully") } } ?: run { - PGHLog.e(TAG, "❌ Long screenshot system not initialized") + PGHLog.e(TAG, "❌ Long screenshot system could not be initialized") enhancedFloatingFAB?.exitLongScreenshotModeExternal() } @@ -1287,6 +1272,46 @@ class ScreenCaptureService : Service() { } } + private fun initializeLongScreenshotSystem() + { + try + { + PGHLog.d(TAG, "🔧 Initializing long screenshot system...") + + val screenDimensions = screenCaptureManager.getScreenDimensions() + val mediaProjection = screenCaptureManager.getMediaProjection() + val screenDensity = screenCaptureManager.getScreenDensity() + + PGHLog.d(TAG, "🔍 Long screenshot init check - dimensions=$screenDimensions, mediaProjection=$mediaProjection, density=$screenDensity") + + if (screenDimensions != null && mediaProjection != null) { + val (screenWidth, screenHeight) = screenDimensions + PGHLog.d(TAG, "🔧 Creating LongScreenshotCapture instance...") + longScreenshotCapture = LongScreenshotCapture(this, handler) + + // Initialize with the shared MediaProjection + PGHLog.d(TAG, "🔧 Initializing with MediaProjection: ${screenWidth}x${screenHeight}, density=$screenDensity") + val initialized = longScreenshotCapture!!.initialize( + mediaProjection, screenWidth, screenHeight, screenDensity + ) + + if (initialized) { + PGHLog.i(TAG, "✅ Long screenshot system initialized successfully") + } else { + PGHLog.e(TAG, "❌ Failed to initialize long screenshot system") + longScreenshotCapture = null + } + } else { + PGHLog.w(TAG, "⚠️ Cannot initialize long screenshot - missing MediaProjection ($mediaProjection) or screen dimensions ($screenDimensions)") + } + } + catch (e: Exception) + { + PGHLog.e(TAG, "❌ Error initializing long screenshot system", e) + longScreenshotCapture = null + } + } + private fun captureLongScreenshot() { try