diff options
author | Allan Wang <me@allanwang.ca> | 2021-01-11 00:19:31 -0800 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2021-01-11 00:19:31 -0800 |
commit | 5f5389b0fde9d12c56e337dff169fa6319b449cf (patch) | |
tree | 8f5ec6bc4c5470b6c6fc3c4b2d732bec5d0d3016 /mediapicker/src/main | |
parent | 038ad9c3aa4d6678d9ede06cf1ce68b8bdf85021 (diff) | |
download | kau-5f5389b0fde9d12c56e337dff169fa6319b449cf.tar.gz kau-5f5389b0fde9d12c56e337dff169fa6319b449cf.tar.bz2 kau-5f5389b0fde9d12c56e337dff169fa6319b449cf.zip |
Remove kotlin synethetics
Diffstat (limited to 'mediapicker/src/main')
3 files changed, 87 insertions, 62 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..d7db7da 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt @@ -18,12 +18,13 @@ 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 @@ -31,7 +32,6 @@ 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.* /** * Created by Allan Wang on 2017-07-14. @@ -51,12 +51,13 @@ 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, true) 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) = @@ -88,10 +91,12 @@ class BlurredImageView @JvmOverloads constructor( factor.width = width factor.height = height BlurTask(imageBase, factor) { - image_blur.setImageDrawable(it) - scaleAnimate(ANIMATION_SCALE).start() - image_blur.alphaAnimate(1f).start() - image_foreground.alphaAnimate(1f).start() + with (binding) { + imageBlur.setImageDrawable(it) + scaleAnimate(ANIMATION_SCALE).start() + imageBlur.alphaAnimate(1f).start() + imageForeground.alphaAnimate(1f).start() + } }.execute() } @@ -107,10 +112,12 @@ class BlurredImageView @JvmOverloads constructor( factor.width = width factor.height = height BlurTask(imageBase, factor) { drawable -> - image_blur.setImageDrawable(drawable) - scaleXY = ANIMATION_SCALE - image_blur.alpha = 1f - image_foreground.alpha = 1f + with (binding) { + imageBlur.setImageDrawable(drawable) + scaleXY = ANIMATION_SCALE + imageBlur.alpha = 1f + imageForeground.alpha = 1f + } }.execute() } @@ -121,8 +128,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 +142,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 +174,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/MediaPickerActivityBase.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt index 4c97b07..1357d4d 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. @@ -39,49 +39,54 @@ import kotlinx.android.synthetic.main.kau_activity_image_picker.* * Having three layered images makes this slightly slower than [MediaPickerActivityOverlayBase] */ abstract class MediaPickerActivityBase( - mediaType: MediaType, - mediaActions: List<MediaAction> = emptyList() + mediaType: MediaType, + 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() } |