From 7a3165ac7404381eb85ea40525db1a7a7d980761 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 26 Dec 2017 04:01:23 -0500 Subject: Update/kpref activity (#113) * Revamp kpref * Clean up data * Fix script * Test emulator * Test google api * Test again * Test gpg * Update dependencies --- .../ca/allanwang/kau/mediapicker/MediaActionItem.kt | 16 +++++++--------- .../kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt | 6 +++--- .../ca/allanwang/kau/mediapicker/MediaItemBasic.kt | 4 ++-- 3 files changed, 12 insertions(+), 14 deletions(-) (limited to 'mediapicker/src') 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 6171470..0cf6340 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt @@ -30,7 +30,7 @@ class MediaActionItem( super.bindView(holder, payloads) holder.image.apply { setImageDrawable(MediaPickerCore.getIconDrawable(context, action.iicon(this@MediaActionItem), action.color)) - setOnClickListener { action.invoke(context, this@MediaActionItem) } + setOnClickListener { action(context, this@MediaActionItem) } } } @@ -46,7 +46,7 @@ class MediaActionItem( interface MediaAction { var color: Int fun iicon(item: MediaActionItem): IIcon - fun invoke(c: Context, item: MediaActionItem) + operator fun invoke(c: Context, item: MediaActionItem) } internal const val MEDIA_ACTION_REQUEST_CAMERA = 100 @@ -71,9 +71,8 @@ abstract class MediaActionCamera( MediaType.VIDEO -> GoogleMaterial.Icon.gmd_videocam } - override fun invoke(c: Context, item: MediaActionItem) { - c.kauRequestPermissions(PERMISSION_WRITE_EXTERNAL_STORAGE) { - granted, _ -> + override operator fun invoke(c: Context, item: MediaActionItem) { + c.kauRequestPermissions(PERMISSION_WRITE_EXTERNAL_STORAGE) { granted, _ -> if (granted) { val intent = Intent(item.mediaType.captureType) if (intent.resolveActivity(c.packageManager) == null) { @@ -109,7 +108,7 @@ class MediaActionCameraVideo( override var color: Int = MediaPickerCore.accentColor ) : MediaAction { override fun iicon(item: MediaActionItem) = GoogleMaterial.Icon.gmd_videocam - override fun invoke(c: Context, item: MediaActionItem) { + override operator fun invoke(c: Context, item: MediaActionItem) { val intent = Intent(MediaStore.ACTION_VIDEO_CAPTURE) if (intent.resolveActivity(c.packageManager) == null) { c.materialDialog { @@ -136,9 +135,8 @@ class MediaActionGallery( MediaType.VIDEO -> GoogleMaterial.Icon.gmd_video_library } - override fun invoke(c: Context, item: MediaActionItem) { - c.kauRequestPermissions(PERMISSION_READ_EXTERNAL_STORAGE) { - granted, _ -> + override operator fun invoke(c: Context, item: MediaActionItem) { + c.kauRequestPermissions(PERMISSION_READ_EXTERNAL_STORAGE) { granted, _ -> if (granted) { val intent = Intent().apply { type = item.mediaType.mimeType 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 486ee31..b2cfa46 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt @@ -35,7 +35,7 @@ class MediaItem(val data: MediaModel) override fun isSelectable(): Boolean = !failedToLoad - override fun bindView(holder: ViewHolder, payloads: List?) { + override fun bindView(holder: ViewHolder, payloads: List) { super.bindView(holder, payloads) glide(holder.itemView) .load(data.data) @@ -44,13 +44,13 @@ class MediaItem(val data: MediaModel) override fun onLoadFailed(e: GlideException?, model: Any, target: Target, isFirstResource: Boolean): Boolean { failedToLoad = true holder.container.imageBase.setImageDrawable(MediaPickerCore.getErrorDrawable(holder.itemView.context)) - return true; + return true } override fun onResourceReady(resource: Drawable, model: Any, target: Target, dataSource: DataSource, isFirstResource: Boolean): Boolean { holder.container.imageBase.setImageDrawable(resource) if (isSelected) holder.container.blurInstantly() - return true; + return true } }) .into(holder.container.imageBase) 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 fb2d383..1fa18aa 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt @@ -34,7 +34,7 @@ class MediaItemBasic(val data: MediaModel) override fun isSelectable(): Boolean = false - override fun bindView(holder: ViewHolder, payloads: List?) { + override fun bindView(holder: ViewHolder, payloads: List) { super.bindView(holder, payloads) glide(holder.itemView) .load(data.data) @@ -42,7 +42,7 @@ class MediaItemBasic(val data: MediaModel) .listener(object : RequestListener { override fun onLoadFailed(e: GlideException?, model: Any, target: Target, isFirstResource: Boolean): Boolean { holder.image.setImageDrawable(MediaPickerCore.getErrorDrawable(holder.itemView.context)) - return true; + return true } override fun onResourceReady(resource: Drawable, model: Any, target: Target, dataSource: DataSource, isFirstResource: Boolean): Boolean { -- cgit v1.2.3