diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt index 31479d54..9a5f3c6e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt @@ -15,6 +15,7 @@ import android.widget.ProgressBar import android.widget.TextView import ca.allanwang.kau.email.sendEmail import ca.allanwang.kau.internal.KauBaseActivity +import ca.allanwang.kau.mediapicker.scanMedia import ca.allanwang.kau.permissions.PERMISSION_WRITE_EXTERNAL_STORAGE import ca.allanwang.kau.permissions.kauRequestPermissions import ca.allanwang.kau.utils.* @@ -47,6 +48,7 @@ class ImageActivity : KauBaseActivity() { val photo: SubsamplingScaleImageView by bindView(R.id.image_photo) val caption: TextView? by bindOptionalView(R.id.image_text) val fab: FloatingActionButton by bindView(R.id.image_fab) + var errorRef: Throwable? = null /** * Reference to the temporary file path @@ -85,22 +87,22 @@ class ImageActivity : KauBaseActivity() { caption?.text = text progress.tint(Prefs.accentColor) panel?.addPanelSlideListener(object : SlidingUpPanelLayout.SimplePanelSlideListener() { - override fun onPanelSlide(panel: View, slideOffset: Float) { if (slideOffset == 0f && !fab.isShown) fab.show() else if (slideOffset != 0f && fab.isShown) fab.hide() caption?.alpha = slideOffset / 2 + 0.5f } - }) fab.setOnClickListener { fabAction.onClick(this) } photo.setOnImageEventListener(object : SubsamplingScaleImageView.DefaultOnImageEventListener() { override fun onImageLoadError(e: Exception?) { + errorRef = e e.logFrostAnswers("Image load error") imageCallback(null, false) } }) Glide.with(this).asBitmap().load(imageUrl).into(PhotoTarget(this::imageCallback)) + setFrostColors(themeWindow = false) } /** @@ -145,7 +147,8 @@ class ImageActivity : KauBaseActivity() { var photoFile: File? = null try { photoFile = createPrivateMediaFile(".png") - } catch (ignored: IOException) { + } catch (e: IOException) { + errorRef = e } finally { if (photoFile == null) { callback(null) @@ -173,14 +176,15 @@ class ImageActivity : KauBaseActivity() { var success = true try { File(tempFilePath).copyTo(destination, true) - scanFile(destination) + scanMedia(destination) } catch (e: Exception) { + errorRef = e success = false } finally { L.d("Download image async finished: $success") uiThread { val text = if (success) R.string.image_download_success else R.string.image_download_fail - snackbar(text) + frostSnackbar(text) if (success) fabAction = FabStates.SHARE } } @@ -189,17 +193,6 @@ class ImageActivity : KauBaseActivity() { } } - /** - * See <a href="https://developer.android.com/training/camera/photobasics.html#TaskGallery">Docs</a> - */ - internal fun scanFile(file: File) { - if (!file.exists()) return - val mediaScanIntent = Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE) - val contentUri = Uri.fromFile(file) - mediaScanIntent.data = contentUri - this.sendBroadcast(mediaScanIntent) - } - internal fun deleteTempFile() { if (tempFilePath != null) { File(tempFilePath!!).delete() @@ -213,7 +206,7 @@ class ImageActivity : KauBaseActivity() { } } -internal enum class FabStates(val iicon: IIcon, val iconColor: Int = Prefs.iconColor, val backgroundTint: Int = Prefs.iconBackgroundColor.withAlpha(255)) { +internal enum class FabStates(val iicon: IIcon, val iconColor: Int = Prefs.iconColor, val backgroundTint: Int = Int.MAX_VALUE) { ERROR(GoogleMaterial.Icon.gmd_error, Color.WHITE, Color.RED) { override fun onClick(activity: ImageActivity) { activity.materialDialogThemed { @@ -221,8 +214,11 @@ internal enum class FabStates(val iicon: IIcon, val iconColor: Int = Prefs.iconC content(R.string.bad_image_overlay) positiveText(R.string.kau_yes) onPositive { _, _ -> + if (activity.errorRef != null) + L.e(activity.errorRef, "ImageActivity error report") activity.sendEmail(R.string.dev_email, R.string.debug_image_link_subject) { addItem("Url", activity.imageUrl) + addItem("Message", activity.errorRef?.message ?: "Null") } } negativeText(R.string.kau_no) @@ -248,8 +244,9 @@ internal enum class FabStates(val iicon: IIcon, val iconColor: Int = Prefs.iconC } activity.startActivity(intent) } catch (e: Exception) { + activity.errorRef = e e.logFrostAnswers("Image share failed") - activity.snackbar(R.string.image_share_failed) + activity.frostSnackbar(R.string.image_share_failed) } } }; @@ -259,14 +256,15 @@ internal enum class FabStates(val iicon: IIcon, val iconColor: Int = Prefs.iconC * If it's in view, give it some animations */ fun update(fab: FloatingActionButton) { + val tint = if (backgroundTint != Int.MAX_VALUE) backgroundTint else Prefs.accentColor if (fab.isHidden) { fab.setIcon(iicon, color = iconColor) - fab.backgroundTintList = ColorStateList.valueOf(backgroundTint) + fab.backgroundTintList = ColorStateList.valueOf(tint) fab.show() } else { fab.fadeScaleTransition { setIcon(iicon, color = iconColor) - backgroundTintList = ColorStateList.valueOf(backgroundTint) + backgroundTintList = ColorStateList.valueOf(tint) } } } |