From 52bfdb66ca8d44986b3f1ae51c921a939db17ac6 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Fri, 18 Aug 2017 14:40:08 -0700 Subject: Misc (#190) * Update play store description * Finalize description * Update kotlin and bg2 for custom themes * Update to Android Studio 3.0 beta 2 * Update test dependencies and add logging to image activity * Rename throwable to errorRef * Update searchview and media picker through kau --- .../pitchedapps/frost/activities/ImageActivity.kt | 26 +++++++++------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt') 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..3593f6b5 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,17 +87,16 @@ 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) } @@ -145,7 +146,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,8 +175,9 @@ 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") @@ -189,17 +192,6 @@ class ImageActivity : KauBaseActivity() { } } - /** - * See Docs - */ - 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() @@ -221,8 +213,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,6 +243,7 @@ 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) } -- cgit v1.2.3