diff options
author | Allan Wang <me@allanwang.ca> | 2017-08-19 09:47:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-19 09:47:05 -0700 |
commit | 84bf883a47b956865d31b1b618d5495fcd7d4876 (patch) | |
tree | 0fb0f83af4862a127bca7d8451ef2c7188a08d83 /app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt | |
parent | 5d9a3fd7fb8f2f9d0f592c89446824980c9841c6 (diff) | |
download | frost-84bf883a47b956865d31b1b618d5495fcd7d4876.tar.gz frost-84bf883a47b956865d31b1b618d5495fcd7d4876.tar.bz2 frost-84bf883a47b956865d31b1b618d5495fcd7d4876.zip |
v1.4.7 (#195)v1.4.7
* Add try catch (#179)
* Add checks before injections (#180)
* Enhancement/url redirect manager (#182)
* Initial blacklist
* Move js checks to java
* Optimize imports and clean up request interceptor
* 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
* Update themes (#183)
* Theme content now found view
* Update verified bg and bg2 for transparent themes
* Fix check in star text
* Various fixes
* Create base svg sass images
* Feature/theme accent (#192)
* Add lots of theming components
* Optimize and add
* Update accents
* Misc 2 (#191)
* Add further checks for iab and remove generic error dialog
* Theme all snackbars
* Add dynamic media action tile
* Enhancement/media-camera-picker (#194)
* Update kau
* Update changelog
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) } } } |