From b3ac8e10b14b78547acc3330c8d92a4bdbfc4078 Mon Sep 17 00:00:00 2001 From: LooKeR Date: Fri, 8 Oct 2021 01:29:51 +0530 Subject: [PATCH] Null Safe ScreenShot Fragment Removed Coil Library (Unused) --- build.gradle | 1 - .../droidify/screen/ScreenshotsFragment.kt | 88 +++++++++++-------- 2 files changed, 49 insertions(+), 40 deletions(-) diff --git a/build.gradle b/build.gradle index 5b621dbe..99103b97 100644 --- a/build.gradle +++ b/build.gradle @@ -109,6 +109,5 @@ dependencies { implementation 'io.reactivex.rxjava3:rxjava:3.1.1' implementation 'io.reactivex.rxjava3:rxandroid:3.0.0' implementation 'com.fasterxml.jackson.core:jackson-core:2.13.0' - implementation 'io.coil-kt:coil:1.3.2' implementation 'com.squareup.picasso:picasso:2.71828' } diff --git a/src/main/kotlin/com/looker/droidify/screen/ScreenshotsFragment.kt b/src/main/kotlin/com/looker/droidify/screen/ScreenshotsFragment.kt index 9f5d3e7c..f944f31a 100644 --- a/src/main/kotlin/com/looker/droidify/screen/ScreenshotsFragment.kt +++ b/src/main/kotlin/com/looker/droidify/screen/ScreenshotsFragment.kt @@ -62,52 +62,60 @@ class ScreenshotsFragment() : DialogFragment() { val repositoryId = requireArguments().getLong(EXTRA_REPOSITORY_ID) val dialog = Dialog(requireContext(), R.style.Theme_Main_Dark) - val window = dialog.window!! - val decorView = window.decorView + val window = dialog.window + val decorView = window?.decorView - WindowCompat.setDecorFitsSystemWindows(window, false) + if (window != null) { + WindowCompat.setDecorFitsSystemWindows(window, false) + } val background = dialog.context.getColorFromAttr(android.R.attr.colorBackground).defaultColor - decorView.setBackgroundColor(background.let { + decorView?.setBackgroundColor(background.let { ColorUtils.blendARGB( 0x00ffffff and it, it, 0.9f ) }) - decorView.setPadding(0, 0, 0, 0) + decorView?.setPadding(0, 0, 0, 0) background.let { ColorUtils.blendARGB(0x00ffffff and it, it, 0.8f) }.let { - window.statusBarColor = it - window.navigationBarColor = it + window?.statusBarColor = it + window?.navigationBarColor = it } - window.attributes = window.attributes.apply { - title = ScreenshotsFragment::class.java.name - format = PixelFormat.TRANSLUCENT - windowAnimations = run { - val typedArray = dialog.context.obtainStyledAttributes( - null, - intArrayOf(android.R.attr.windowAnimationStyle), android.R.attr.dialogTheme, 0 - ) - try { - typedArray.getResourceId(0, 0) - } finally { - typedArray.recycle() + if (window != null) { + window.attributes = window.attributes.apply { + title = ScreenshotsFragment::class.java.name + format = PixelFormat.TRANSLUCENT + windowAnimations = run { + val typedArray = dialog.context.obtainStyledAttributes( + null, + intArrayOf(android.R.attr.windowAnimationStyle), + android.R.attr.dialogTheme, + 0 + ) + try { + typedArray.getResourceId(0, 0) + } finally { + typedArray.recycle() + } + } + if (Android.sdk(28)) { + layoutInDisplayCutoutMode = + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES } - } - if (Android.sdk(28)) { - layoutInDisplayCutoutMode = - WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES } } val toggleSystemUi = { - WindowInsetsControllerCompat(window, decorView).let { controller -> - controller.hide(WindowInsetsCompat.Type.statusBars()) - controller.hide(WindowInsetsCompat.Type.navigationBars()) - controller.systemBarsBehavior = - WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + if (window != null && decorView != null) { + WindowInsetsControllerCompat(window, decorView).let { controller -> + controller.hide(WindowInsetsCompat.Type.statusBars()) + controller.hide(WindowInsetsCompat.Type.navigationBars()) + controller.systemBarsBehavior = + WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + } } } @@ -246,17 +254,19 @@ class ScreenshotsFragment() : DialogFragment() { val screenshot = screenshots[position] val (width, height) = size if (width > 0 && height > 0) { - holder.image.load( - PicassoDownloader.createScreenshotUri( - repository!!, - packageName, - screenshot - ) - ) { - placeholder(holder.placeholder) - error(holder.placeholder) - resize(width, height) - centerInside() + repository?.let { + holder.image.load( + PicassoDownloader.createScreenshotUri( + it, + packageName, + screenshot + ) + ) { + placeholder(holder.placeholder) + error(holder.placeholder) + resize(width, height) + centerInside() + } } } else { holder.image.clear()