aboutsummaryrefslogtreecommitdiff
path: root/mediapicker/src
diff options
context:
space:
mode:
Diffstat (limited to 'mediapicker/src')
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt79
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt2
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt2
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt2
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt55
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt21
-rw-r--r--mediapicker/src/main/res/layout/kau_iitem_image_basic.xml4
7 files changed, 91 insertions, 74 deletions
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt
index e430dff..77ac04c 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt
@@ -18,20 +18,19 @@ package ca.allanwang.kau.mediapicker
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
+import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
+import ca.allanwang.kau.mediapicker.databinding.KauBlurredImageviewBinding
import ca.allanwang.kau.ui.views.MeasureSpecContract
import ca.allanwang.kau.ui.views.MeasureSpecDelegate
-import ca.allanwang.kau.utils.inflate
import ca.allanwang.kau.utils.scaleXY
import ca.allanwang.kau.utils.setBackgroundColorRes
import ca.allanwang.kau.utils.setIcon
import ca.allanwang.kau.utils.visible
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
-import jp.wasabeef.blurry.internal.BlurFactor
-import jp.wasabeef.blurry.internal.BlurTask
-import kotlinx.android.synthetic.main.kau_blurred_imageview.view.*
+import jp.wasabeef.blurry.Blurry
/**
* Created by Allan Wang on 2017-07-14.
@@ -51,12 +50,14 @@ class BlurredImageView @JvmOverloads constructor(
var isBlurred = false
private set
- val imageBase: ImageView get() = image_base
+ val imageBase: ImageView get() = binding.imageBase
+
+ private val binding: KauBlurredImageviewBinding =
+ KauBlurredImageviewBinding.inflate(LayoutInflater.from(context), this)
init {
- inflate(R.layout.kau_blurred_imageview, true)
initAttrs(context, attrs)
- image_foreground.setIcon(GoogleMaterial.Icon.gmd_check, 30)
+ binding.imageForeground.setIcon(GoogleMaterial.Icon.gmd_check, 30)
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
@@ -66,9 +67,11 @@ class BlurredImageView @JvmOverloads constructor(
override fun clearAnimation() {
super.clearAnimation()
- imageBase.clearAnimation()
- image_blur.clearAnimation()
- image_foreground.clearAnimation()
+ with(binding) {
+ imageBase.clearAnimation()
+ imageBlur.clearAnimation()
+ imageForeground.clearAnimation()
+ }
}
private fun View.scaleAnimate(scale: Float) =
@@ -84,15 +87,12 @@ class BlurredImageView @JvmOverloads constructor(
fun blur() {
if (isBlurred) return
isBlurred = true
- val factor = BlurFactor()
- factor.width = width
- factor.height = height
- BlurTask(imageBase, factor) {
- image_blur.setImageDrawable(it)
+ with(binding) {
+ Blurry.with(imageBase.context).capture(imageBase).into(imageBlur)
scaleAnimate(ANIMATION_SCALE).start()
- image_blur.alphaAnimate(1f).start()
- image_foreground.alphaAnimate(1f).start()
- }.execute()
+ imageBlur.alphaAnimate(1f).start()
+ imageForeground.alphaAnimate(1f).start()
+ }
}
/**
@@ -103,15 +103,12 @@ class BlurredImageView @JvmOverloads constructor(
fun blurInstantly() {
isBlurred = true
clearAnimation()
- val factor = BlurFactor()
- factor.width = width
- factor.height = height
- BlurTask(imageBase, factor) { drawable ->
- image_blur.setImageDrawable(drawable)
+ with(binding) {
+ Blurry.with(imageBase.context).capture(imageBase).into(imageBlur)
scaleXY = ANIMATION_SCALE
- image_blur.alpha = 1f
- image_foreground.alpha = 1f
- }.execute()
+ imageBlur.alpha = 1f
+ imageForeground.alpha = 1f
+ }
}
/**
@@ -121,8 +118,10 @@ class BlurredImageView @JvmOverloads constructor(
if (!isBlurred) return
isBlurred = false
scaleAnimate(1.0f).start()
- image_blur.alphaAnimate(0f).withEndAction { image_blur.setImageDrawable(null) }.start()
- image_foreground.alphaAnimate(0f).start()
+ with(binding) {
+ imageBlur.alphaAnimate(0f).withEndAction { imageBlur.setImageDrawable(null) }.start()
+ imageForeground.alphaAnimate(0f).start()
+ }
}
/**
@@ -133,9 +132,11 @@ class BlurredImageView @JvmOverloads constructor(
clearAnimation()
scaleX = 1.0f
scaleX = 1.0f
- image_blur.alpha = 0f
- image_blur.setImageDrawable(null)
- image_foreground.alpha = 0f
+ with(binding) {
+ imageBlur.alpha = 0f
+ imageBlur.setImageDrawable(null)
+ imageForeground.alpha = 0f
+ }
}
/**
@@ -163,15 +164,17 @@ class BlurredImageView @JvmOverloads constructor(
*/
fun fullReset() {
reset()
- fullAction { it.visible().background = null }
- image_foreground.setBackgroundColorRes(R.color.kau_blurred_image_selection_overlay)
- image_foreground.setIcon(GoogleMaterial.Icon.gmd_check, 30, Color.WHITE)
+ with(binding) {
+ fullAction { it.visible().background = null }
+ imageForeground.setBackgroundColorRes(R.color.kau_blurred_image_selection_overlay)
+ imageForeground.setIcon(GoogleMaterial.Icon.gmd_check, 30, Color.WHITE)
+ }
}
- private fun fullAction(action: (View) -> Unit) {
- action(this)
+ private fun KauBlurredImageviewBinding.fullAction(action: (View) -> Unit) {
+ action(this@BlurredImageView)
action(imageBase)
- action(image_blur)
- action(image_foreground)
+ action(imageBlur)
+ action(imageForeground)
}
}
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt
index 552bf0f..636dcf0 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt
@@ -46,7 +46,7 @@ class MediaActionItem(
get() = false
set(_) {}
- override fun bindView(holder: MediaItemBasic.ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: MediaItemBasic.ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
holder.image.apply {
setImageDrawable(
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt
index 88a304f..86cb367 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt
@@ -54,7 +54,7 @@ class MediaItem(val data: MediaModel) :
get() = !failedToLoad
set(_) {}
- override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
glide(holder.itemView)
.load(data.data)
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt
index e801848..6f0d223 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt
@@ -52,7 +52,7 @@ class MediaItemBasic(val data: MediaModel) :
get() = false
set(_) {}
- override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
glide(holder.itemView)
.load(data.data)
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt
index 4c97b07..fe25d97 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt
@@ -21,6 +21,7 @@ import androidx.loader.content.Loader
import androidx.recyclerview.widget.LinearLayoutManager
import ca.allanwang.kau.adapters.selectedItems
import ca.allanwang.kau.adapters.selectionSize
+import ca.allanwang.kau.mediapicker.databinding.KauActivityImagePickerBinding
import ca.allanwang.kau.utils.hideOnDownwardsScroll
import ca.allanwang.kau.utils.setIcon
import ca.allanwang.kau.utils.toDrawable
@@ -29,7 +30,6 @@ import com.google.android.material.appbar.AppBarLayout
import com.mikepenz.fastadapter.ISelectionListener
import com.mikepenz.fastadapter.select.selectExtension
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
-import kotlinx.android.synthetic.main.kau_activity_image_picker.*
/**
* Created by Allan Wang on 2017-07-04.
@@ -43,45 +43,50 @@ abstract class MediaPickerActivityBase(
mediaActions: List<MediaAction> = emptyList()
) : MediaPickerCore<MediaItem>(mediaType, mediaActions) {
+ private lateinit var binding: KauActivityImagePickerBinding
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ binding = KauActivityImagePickerBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ binding.init()
+ }
- setContentView(R.layout.kau_activity_image_picker)
-
- kau_selection_count.setCompoundDrawables(
- null,
- null,
- GoogleMaterial.Icon.gmd_image.toDrawable(this, 18),
- null
+ private fun KauActivityImagePickerBinding.init() {
+ kauSelectionCount.setCompoundDrawables(
+ null,
+ null,
+ GoogleMaterial.Icon.gmd_image.toDrawable(this@MediaPickerActivityBase, 18),
+ null
)
- setSupportActionBar(kau_toolbar)
+ setSupportActionBar(kauToolbar)
supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
setDisplayShowHomeEnabled(true)
setHomeAsUpIndicator(
- GoogleMaterial.Icon.gmd_close.toDrawable(
- this@MediaPickerActivityBase,
- 18
- )
+ GoogleMaterial.Icon.gmd_close.toDrawable(
+ this@MediaPickerActivityBase,
+ 18
+ )
)
}
- kau_toolbar.setNavigationOnClickListener { onBackPressed() }
+ kauToolbar.setNavigationOnClickListener { onBackPressed() }
- initializeRecycler(kau_recyclerview)
+ initializeRecycler(kauRecyclerview)
adapter.fastAdapter!!.let {
MediaItem.bindEvents(it)
it.selectExtension {
selectionListener = object : ISelectionListener<MediaItem> {
override fun onSelectionChanged(item: MediaItem, selected: Boolean) {
- kau_selection_count.text = adapter.selectionSize.toString()
+ kauSelectionCount.text = adapter.selectionSize.toString()
}
}
}
}
- kau_fab.apply {
+ kauFab.apply {
show()
setIcon(GoogleMaterial.Icon.gmd_send)
setOnClickListener {
@@ -92,7 +97,7 @@ abstract class MediaPickerActivityBase(
finish(ArrayList(selection.map { it.data }))
}
}
- hideOnDownwardsScroll(kau_recyclerview)
+ hideOnDownwardsScroll(kauRecyclerview)
}
loadItems()
@@ -108,11 +113,11 @@ abstract class MediaPickerActivityBase(
* @param scrollable true if scroll flags are enabled, false otherwise
*/
- private fun setToolbarScrollable(scrollable: Boolean) {
- val params = kau_toolbar.layoutParams as AppBarLayout.LayoutParams
+ private fun KauActivityImagePickerBinding.setToolbarScrollable(scrollable: Boolean) {
+ val params = kauToolbar.layoutParams as AppBarLayout.LayoutParams
if (scrollable) {
params.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS or
- AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
+ AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
} else {
params.scrollFlags = 0
}
@@ -120,13 +125,13 @@ abstract class MediaPickerActivityBase(
override fun onLoadFinished(loader: Loader<Cursor>, data: Cursor?) {
super.onLoadFinished(loader, data)
- setToolbarScrollable(
- (kau_recyclerview.layoutManager as LinearLayoutManager)
- .findLastCompletelyVisibleItemPosition() < adapter.adapterItemCount - 1
+ binding.setToolbarScrollable(
+ (binding.kauRecyclerview.layoutManager as LinearLayoutManager)
+ .findLastCompletelyVisibleItemPosition() < adapter.adapterItemCount - 1
)
}
override fun onStatusChange(loaded: Boolean) {
- setToolbarScrollable(loaded)
+ binding.setToolbarScrollable(loaded)
}
}
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt
index df47688..0ecc298 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt
@@ -18,8 +18,8 @@ package ca.allanwang.kau.mediapicker
import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
+import ca.allanwang.kau.mediapicker.databinding.KauActivityImagePickerOverlayBinding
import ca.allanwang.kau.utils.toast
-import kotlinx.android.synthetic.main.kau_activity_image_picker_overlay.*
/**
* Created by Allan Wang on 2017-07-23.
@@ -35,20 +35,27 @@ abstract class MediaPickerActivityOverlayBase(
mediaActions: List<MediaAction> = emptyList()
) : MediaPickerCore<MediaItemBasic>(mediaType, mediaActions) {
+ private lateinit var binding: KauActivityImagePickerOverlayBinding
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.kau_activity_image_picker_overlay)
- initializeRecycler(kau_recyclerview)
- MediaItemBasic.bindEvents(this, adapter.fastAdapter!!)
+ binding = KauActivityImagePickerOverlayBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ binding.init()
+ }
+
+ private fun KauActivityImagePickerOverlayBinding.init() {
+ initializeRecycler(kauRecyclerview)
+ MediaItemBasic.bindEvents(this@MediaPickerActivityOverlayBase, adapter.fastAdapter!!)
- kau_draggable.addExitListener(this, R.transition.kau_image_exit_bottom, R.transition.kau_image_exit_top)
- kau_draggable.setOnClickListener { finishAfterTransition() }
+ kauDraggable.addExitListener(this@MediaPickerActivityOverlayBase, R.transition.kau_image_exit_bottom, R.transition.kau_image_exit_top)
+ kauDraggable.setOnClickListener { finishAfterTransition() }
loadItems()
}
override fun finishAfterTransition() {
- kau_recyclerview.stopScroll()
+ binding.kauRecyclerview.stopScroll()
super.finishAfterTransition()
}
diff --git a/mediapicker/src/main/res/layout/kau_iitem_image_basic.xml b/mediapicker/src/main/res/layout/kau_iitem_image_basic.xml
index b89e41d..939f139 100644
--- a/mediapicker/src/main/res/layout/kau_iitem_image_basic.xml
+++ b/mediapicker/src/main/res/layout/kau_iitem_image_basic.xml
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<ca.allanwang.kau.ui.views.MeasuredImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/kau_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:foreground="@drawable/kau_selectable_white"
android:scaleType="centerCrop"
- app:relativeHeight="1" /> \ No newline at end of file
+ app:relativeHeight="1"
+ tools:ignore="UnusedAttribute" /> \ No newline at end of file