aboutsummaryrefslogtreecommitdiff
path: root/mediapicker/src
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-09-09 11:59:24 -0400
committerGitHub <noreply@github.com>2018-09-09 11:59:24 -0400
commitd540934915da26ab2cec4c897e973be35e0bfe24 (patch)
tree6f114d080c168381266a0d5d3a40b685e28b8e9a /mediapicker/src
parent718a51ed00a0a5c3dc7a655e617308e82da65d1a (diff)
downloadkau-d540934915da26ab2cec4c897e973be35e0bfe24.tar.gz
kau-d540934915da26ab2cec4c897e973be35e0bfe24.tar.bz2
kau-d540934915da26ab2cec4c897e973be35e0bfe24.zip
Clean up kotterknife (#161)
* Remove bindview implementations internally * Remove more bindView calls * Make config private in ElasticRecyclerActivity * Fix recyclerview * Update adapter * Improve swipe destroy and add direction to swipe finish
Diffstat (limited to 'mediapicker/src')
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt41
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt3
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt3
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt35
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt15
5 files changed, 41 insertions, 56 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 9e83d84..f1e32d1 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt
@@ -12,6 +12,7 @@ import ca.allanwang.kau.utils.*
import com.mikepenz.google_material_typeface_library.GoogleMaterial
import jp.wasabeef.blurry.internal.BlurFactor
import jp.wasabeef.blurry.internal.BlurTask
+import kotlinx.android.synthetic.main.kau_blurred_imageview.view.*
/**
* Created by Allan Wang on 2017-07-14.
@@ -27,14 +28,12 @@ class BlurredImageView @JvmOverloads constructor(
) : FrameLayout(context, attrs, defStyleAttr), MeasureSpecContract by MeasureSpecDelegate() {
private var blurred = false
- val imageBase: ImageView by bindView(R.id.image_base)
- internal val imageBlur: ImageView by bindView(R.id.image_blur)
- val imageForeground: ImageView by bindView(R.id.image_foreground)
+ val imageBase: ImageView get() = image_base
init {
inflate(R.layout.kau_blurred_imageview, true)
initAttrs(context, attrs)
- imageForeground.setIcon(GoogleMaterial.Icon.gmd_check, 30)
+ image_foreground.setIcon(GoogleMaterial.Icon.gmd_check, 30)
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
@@ -45,8 +44,8 @@ class BlurredImageView @JvmOverloads constructor(
override fun clearAnimation() {
super.clearAnimation()
imageBase.clearAnimation()
- imageBlur.clearAnimation()
- imageForeground.clearAnimation()
+ image_blur.clearAnimation()
+ image_foreground.clearAnimation()
}
private fun View.scaleAnimate(scale: Float) = animate().scaleXY(scale).setDuration(ANIMATION_DURATION)
@@ -68,10 +67,10 @@ class BlurredImageView @JvmOverloads constructor(
factor.width = width
factor.height = height
BlurTask(imageBase, factor) {
- imageBlur.setImageDrawable(it)
+ image_blur.setImageDrawable(it)
scaleAnimate(ANIMATION_SCALE).start()
- imageBlur.alphaAnimate(1f).start()
- imageForeground.alphaAnimate(1f).start()
+ image_blur.alphaAnimate(1f).start()
+ image_foreground.alphaAnimate(1f).start()
}.execute()
}
@@ -87,10 +86,10 @@ class BlurredImageView @JvmOverloads constructor(
factor.width = width
factor.height = height
BlurTask(imageBase, factor) { drawable ->
- imageBlur.setImageDrawable(drawable)
+ image_blur.setImageDrawable(drawable)
scaleXY = ANIMATION_SCALE
- imageBlur.alpha = 1f
- imageForeground.alpha = 1f
+ image_blur.alpha = 1f
+ image_foreground.alpha = 1f
}.execute()
}
@@ -101,8 +100,8 @@ class BlurredImageView @JvmOverloads constructor(
if (!blurred) return
blurred = false
scaleAnimate(1.0f).start()
- imageBlur.alphaAnimate(0f).withEndAction { imageBlur.setImageDrawable(null) }.start()
- imageForeground.alphaAnimate(0f).start()
+ image_blur.alphaAnimate(0f).withEndAction { image_blur.setImageDrawable(null) }.start()
+ image_foreground.alphaAnimate(0f).start()
}
@@ -114,9 +113,9 @@ class BlurredImageView @JvmOverloads constructor(
clearAnimation()
scaleX = 1.0f
scaleX = 1.0f
- imageBlur.alpha = 0f
- imageBlur.setImageDrawable(null)
- imageForeground.alpha = 0f
+ image_blur.alpha = 0f
+ image_blur.setImageDrawable(null)
+ image_foreground.alpha = 0f
}
/**
@@ -145,14 +144,14 @@ class BlurredImageView @JvmOverloads constructor(
fun fullReset() {
reset()
fullAction({ it.visible().background = null })
- imageForeground.setBackgroundColorRes(R.color.kau_blurred_image_selection_overlay)
- imageForeground.setIcon(GoogleMaterial.Icon.gmd_check, 30, Color.WHITE)
+ image_foreground.setBackgroundColorRes(R.color.kau_blurred_image_selection_overlay)
+ image_foreground.setIcon(GoogleMaterial.Icon.gmd_check, 30, Color.WHITE)
}
private fun fullAction(action: (View) -> Unit) {
action(this)
action(imageBase)
- action(imageBlur)
- action(imageForeground)
+ action(image_blur)
+ action(image_foreground)
}
} \ No newline at end of file
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 b2cfa46..c0b7e2d 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt
@@ -4,7 +4,6 @@ import android.graphics.drawable.Drawable
import android.support.v7.widget.RecyclerView
import android.view.View
import ca.allanwang.kau.iitems.KauIItem
-import ca.allanwang.kau.utils.bindView
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
@@ -64,6 +63,6 @@ class MediaItem(val data: MediaModel)
}
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
- val container: BlurredImageView by bindView(R.id.kau_image)
+ val container: BlurredImageView = v.findViewById(R.id.kau_image)
}
} \ No newline at end of file
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 1fa18aa..59202c0 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt
@@ -7,7 +7,6 @@ import android.support.v7.widget.RecyclerView
import android.view.View
import ca.allanwang.kau.iitems.KauIItem
import ca.allanwang.kau.ui.views.MeasuredImageView
-import ca.allanwang.kau.utils.bindView
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
@@ -58,6 +57,6 @@ class MediaItemBasic(val data: MediaModel)
}
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
- val image: MeasuredImageView by bindView(R.id.kau_image)
+ val image: MeasuredImageView = v.findViewById(R.id.kau_image)
}
} \ No newline at end of file
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 07e6d18..37f2373 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt
@@ -3,17 +3,16 @@ package ca.allanwang.kau.mediapicker
import android.database.Cursor
import android.os.Bundle
import android.support.design.widget.AppBarLayout
-import android.support.design.widget.CoordinatorLayout
-import android.support.design.widget.FloatingActionButton
import android.support.v4.content.Loader
import android.support.v7.widget.LinearLayoutManager
-import android.support.v7.widget.RecyclerView
-import android.support.v7.widget.Toolbar
-import android.widget.TextView
import ca.allanwang.kau.adapters.selectedItems
import ca.allanwang.kau.adapters.selectionSize
-import ca.allanwang.kau.utils.*
+import ca.allanwang.kau.utils.hideOnDownwardsScroll
+import ca.allanwang.kau.utils.setIcon
+import ca.allanwang.kau.utils.toDrawable
+import ca.allanwang.kau.utils.toast
import com.mikepenz.google_material_typeface_library.GoogleMaterial
+import kotlinx.android.synthetic.main.kau_activity_image_picker.*
/**
* Created by Allan Wang on 2017-07-04.
@@ -27,35 +26,29 @@ abstract class MediaPickerActivityBase(
mediaActions: List<MediaAction> = emptyList()
) : MediaPickerCore<MediaItem>(mediaType, mediaActions) {
- val coordinator: CoordinatorLayout by bindView(R.id.kau_coordinator)
- val toolbar: Toolbar by bindView(R.id.kau_toolbar)
- val selectionCount: TextView by bindView(R.id.kau_selection_count)
- val recycler: RecyclerView by bindView(R.id.kau_recyclerview)
- val fab: FloatingActionButton by bindView(R.id.kau_fab)
-
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.kau_activity_image_picker)
- selectionCount.setCompoundDrawables(null, null, GoogleMaterial.Icon.gmd_image.toDrawable(this, 18), null)
+ kau_selection_count.setCompoundDrawables(null, null, GoogleMaterial.Icon.gmd_image.toDrawable(this, 18), null)
- setSupportActionBar(toolbar)
+ setSupportActionBar(kau_toolbar)
supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
setDisplayShowHomeEnabled(true)
setHomeAsUpIndicator(GoogleMaterial.Icon.gmd_close.toDrawable(this@MediaPickerActivityBase, 18))
}
- toolbar.setNavigationOnClickListener { onBackPressed() }
+ kau_toolbar.setNavigationOnClickListener { onBackPressed() }
- initializeRecycler(recycler)
+ initializeRecycler(kau_recyclerview)
MediaItem.bindEvents(adapter.fastAdapter)
adapter.fastAdapter.withSelectionListener { _, _ ->
- selectionCount.text = adapter.selectionSize.toString()
+ kau_selection_count.text = adapter.selectionSize.toString()
}
- fab.apply {
+ kau_fab.apply {
show()
setIcon(GoogleMaterial.Icon.gmd_send)
setOnClickListener {
@@ -66,7 +59,7 @@ abstract class MediaPickerActivityBase(
finish(ArrayList(selection.map { it.data }))
}
}
- hideOnDownwardsScroll(recycler)
+ hideOnDownwardsScroll(kau_recyclerview)
}
loadItems()
@@ -83,7 +76,7 @@ abstract class MediaPickerActivityBase(
* @param scrollable true if scroll flags are enabled, false otherwise
*/
private fun setToolbarScrollable(scrollable: Boolean) {
- val params = toolbar.layoutParams as AppBarLayout.LayoutParams
+ val params = kau_toolbar.layoutParams as AppBarLayout.LayoutParams
if (scrollable)
params.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS or AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
else
@@ -92,7 +85,7 @@ abstract class MediaPickerActivityBase(
override fun onLoadFinished(loader: Loader<Cursor>, data: Cursor?) {
super.onLoadFinished(loader, data)
- setToolbarScrollable((recycler.layoutManager as LinearLayoutManager)
+ setToolbarScrollable((kau_recyclerview.layoutManager as LinearLayoutManager)
.findLastCompletelyVisibleItemPosition() < adapter.adapterItemCount - 1)
}
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 9516eab..122838b 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt
@@ -3,10 +3,8 @@ package ca.allanwang.kau.mediapicker
import android.os.Build
import android.os.Bundle
import android.support.annotation.RequiresApi
-import android.support.v7.widget.RecyclerView
-import ca.allanwang.kau.ui.widgets.ElasticDragDismissFrameLayout
-import ca.allanwang.kau.utils.bindView
import ca.allanwang.kau.utils.toast
+import kotlinx.android.synthetic.main.kau_activity_image_picker_overlay.*
/**
* Created by Allan Wang on 2017-07-23.
@@ -22,23 +20,20 @@ abstract class MediaPickerActivityOverlayBase(
mediaActions: List<MediaAction> = emptyList()
) : MediaPickerCore<MediaItemBasic>(mediaType, mediaActions) {
- val draggable: ElasticDragDismissFrameLayout by bindView(R.id.kau_draggable)
- val recycler: RecyclerView by bindView(R.id.kau_recyclerview)
-
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.kau_activity_image_picker_overlay)
- initializeRecycler(recycler)
+ initializeRecycler(kau_recyclerview)
MediaItemBasic.bindEvents(this, adapter.fastAdapter)
- draggable.addExitListener(this, R.transition.kau_image_exit_bottom, R.transition.kau_image_exit_top)
- draggable.setOnClickListener { finishAfterTransition() }
+ kau_draggable.addExitListener(this, R.transition.kau_image_exit_bottom, R.transition.kau_image_exit_top)
+ kau_draggable.setOnClickListener { finishAfterTransition() }
loadItems()
}
override fun finishAfterTransition() {
- recycler.stopScroll()
+ kau_recyclerview.stopScroll()
super.finishAfterTransition()
}