Null Safe ScreenShot Fragment

Removed Coil Library (Unused)
This commit is contained in:
LooKeR 2021-10-08 01:29:51 +05:30
parent 26d4fbbd29
commit b3ac8e10b1
2 changed files with 49 additions and 40 deletions

View File

@ -109,6 +109,5 @@ dependencies {
implementation 'io.reactivex.rxjava3:rxjava:3.1.1' implementation 'io.reactivex.rxjava3:rxjava:3.1.1'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0' implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation 'com.fasterxml.jackson.core:jackson-core:2.13.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' implementation 'com.squareup.picasso:picasso:2.71828'
} }

View File

@ -62,32 +62,37 @@ class ScreenshotsFragment() : DialogFragment() {
val repositoryId = requireArguments().getLong(EXTRA_REPOSITORY_ID) val repositoryId = requireArguments().getLong(EXTRA_REPOSITORY_ID)
val dialog = Dialog(requireContext(), R.style.Theme_Main_Dark) val dialog = Dialog(requireContext(), R.style.Theme_Main_Dark)
val window = dialog.window!! val window = dialog.window
val decorView = window.decorView val decorView = window?.decorView
if (window != null) {
WindowCompat.setDecorFitsSystemWindows(window, false) WindowCompat.setDecorFitsSystemWindows(window, false)
}
val background = val background =
dialog.context.getColorFromAttr(android.R.attr.colorBackground).defaultColor dialog.context.getColorFromAttr(android.R.attr.colorBackground).defaultColor
decorView.setBackgroundColor(background.let { decorView?.setBackgroundColor(background.let {
ColorUtils.blendARGB( ColorUtils.blendARGB(
0x00ffffff and it, 0x00ffffff and it,
it, it,
0.9f 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 { background.let { ColorUtils.blendARGB(0x00ffffff and it, it, 0.8f) }.let {
window.statusBarColor = it window?.statusBarColor = it
window.navigationBarColor = it window?.navigationBarColor = it
} }
if (window != null) {
window.attributes = window.attributes.apply { window.attributes = window.attributes.apply {
title = ScreenshotsFragment::class.java.name title = ScreenshotsFragment::class.java.name
format = PixelFormat.TRANSLUCENT format = PixelFormat.TRANSLUCENT
windowAnimations = run { windowAnimations = run {
val typedArray = dialog.context.obtainStyledAttributes( val typedArray = dialog.context.obtainStyledAttributes(
null, null,
intArrayOf(android.R.attr.windowAnimationStyle), android.R.attr.dialogTheme, 0 intArrayOf(android.R.attr.windowAnimationStyle),
android.R.attr.dialogTheme,
0
) )
try { try {
typedArray.getResourceId(0, 0) typedArray.getResourceId(0, 0)
@ -100,9 +105,11 @@ class ScreenshotsFragment() : DialogFragment() {
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
} }
} }
}
val toggleSystemUi = { val toggleSystemUi = {
if (window != null && decorView != null) {
WindowInsetsControllerCompat(window, decorView).let { controller -> WindowInsetsControllerCompat(window, decorView).let { controller ->
controller.hide(WindowInsetsCompat.Type.statusBars()) controller.hide(WindowInsetsCompat.Type.statusBars())
controller.hide(WindowInsetsCompat.Type.navigationBars()) controller.hide(WindowInsetsCompat.Type.navigationBars())
@ -110,6 +117,7 @@ class ScreenshotsFragment() : DialogFragment() {
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
} }
} }
}
val viewPager = ViewPager2(dialog.context) val viewPager = ViewPager2(dialog.context)
viewPager.adapter = Adapter(packageName) { toggleSystemUi() } viewPager.adapter = Adapter(packageName) { toggleSystemUi() }
@ -246,9 +254,10 @@ class ScreenshotsFragment() : DialogFragment() {
val screenshot = screenshots[position] val screenshot = screenshots[position]
val (width, height) = size val (width, height) = size
if (width > 0 && height > 0) { if (width > 0 && height > 0) {
repository?.let {
holder.image.load( holder.image.load(
PicassoDownloader.createScreenshotUri( PicassoDownloader.createScreenshotUri(
repository!!, it,
packageName, packageName,
screenshot screenshot
) )
@ -258,6 +267,7 @@ class ScreenshotsFragment() : DialogFragment() {
resize(width, height) resize(width, height)
centerInside() centerInside()
} }
}
} else { } else {
holder.image.clear() holder.image.clear()
} }