Aperture: Disable gallery button if on keyguard
Signed-off-by: Luca Stefani <luca.stefani.ge1@gmail.com>
Change-Id: If57b1d747d4ee842c2cfcf865f5eefbd9f6c5592
diff --git a/app/src/main/java/org/lineageos/aperture/MainActivity.kt b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
index e55d38a..446ff13 100644
--- a/app/src/main/java/org/lineageos/aperture/MainActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
@@ -178,7 +178,11 @@
}
}
- updateGalleryIcon(sharedPreferences.lastSavedUri)
+ // Special case: we want to enable the gallery by default if
+ // we have at least one saved Uri and we aren't locked
+ sharedPreferences.lastSavedUri?.let {
+ updateGalleryButton(it, !keyguardManager.isKeyguardLocked)
+ }
galleryButton.setOnClickListener { openGallery() }
cameraExecutor = Executors.newSingleThreadExecutor()
@@ -243,9 +247,9 @@
)
colorFade.duration = 500
colorFade.start()
- updateGalleryIcon(output.savedUri)
val msg = "Photo capture succeeded: ${output.savedUri}"
sharedPreferences.lastSavedUri = output.savedUri
+ updateGalleryButton(output.savedUri)
Log.d(LOG_TAG, msg)
isTakingPhoto = false
shutterButton.isEnabled = true
@@ -272,9 +276,9 @@
object : OnVideoSavedCallback {
override fun onVideoSaved(output: OutputFileResults) {
stopRecordingTimer()
- updateGalleryIcon(output.savedUri)
val msg = "Video capture succeeded: ${output.savedUri}"
sharedPreferences.lastSavedUri = output.savedUri
+ updateGalleryButton(output.savedUri)
Log.d(LOG_TAG, msg)
}
@@ -709,14 +713,24 @@
) == PackageManager.PERMISSION_GRANTED
}
- private fun updateGalleryIcon(uri: Uri?) {
+ private fun updateGalleryButton(uri: Uri?, enable: Boolean = true) {
galleryButton.clearColorFilter()
- getThumbnail(uri)?.let {
- runOnUiThread {
- galleryButton.setImageBitmap(it)
+ if (uri != null && enable) {
+ getThumbnail(uri)?.let {
+ runOnUiThread {
+ galleryButton.setImageBitmap(it)
+ }
}
- } ?: run {
+ galleryButton.isEnabled = true
+ } else if (keyguardManager.isKeyguardLocked) {
+ // Mimic disable for now
+ galleryButton.clearColorFilter()
galleryButton.setColorFilter(getColor(R.color.dark_grey))
+ galleryButton.isEnabled = false
+ } else {
+ galleryButton.clearColorFilter()
+ galleryButton.setColorFilter(getColor(R.color.dark_grey))
+ galleryButton.isEnabled = false
}
}