aboutsummaryrefslogtreecommitdiff
path: root/mediapicker/src
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-12-24 01:17:31 -0500
committerGitHub <noreply@github.com>2018-12-24 01:17:31 -0500
commitfb90c4a4ab23f2fd246c29c1dde4d6e155a2e38b (patch)
treecc6d67461b6caa256043b9482f7646831d528a08 /mediapicker/src
parenta380adea1052d39f23c9c4d432a9380ce347d6c4 (diff)
downloadkau-fb90c4a4ab23f2fd246c29c1dde4d6e155a2e38b.tar.gz
kau-fb90c4a4ab23f2fd246c29c1dde4d6e155a2e38b.tar.bz2
kau-fb90c4a4ab23f2fd246c29c1dde4d6e155a2e38b.zip
Enhancement/ktlint (#179)
* Add spotless dependency * Apply ktlint * Add license headers
Diffstat (limited to 'mediapicker/src')
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt29
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/GlideHelper.kt17
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt41
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt81
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt71
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt66
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt31
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt21
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerBinder.kt25
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt33
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaType.kt47
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaUtils.kt22
12 files changed, 356 insertions, 128 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 f1e32d1..739bf47 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.mediapicker
import android.content.Context
@@ -8,7 +23,11 @@ import android.widget.FrameLayout
import android.widget.ImageView
import ca.allanwang.kau.ui.views.MeasureSpecContract
import ca.allanwang.kau.ui.views.MeasureSpecDelegate
-import ca.allanwang.kau.utils.*
+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.google_material_typeface_library.GoogleMaterial
import jp.wasabeef.blurry.internal.BlurFactor
import jp.wasabeef.blurry.internal.BlurTask
@@ -24,7 +43,9 @@ import kotlinx.android.synthetic.main.kau_blurred_imageview.view.*
* The foreground by default contains a white checkmark, but can be customized or hidden depending on the situation
*/
class BlurredImageView @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr), MeasureSpecContract by MeasureSpecDelegate() {
private var blurred = false
@@ -51,7 +72,6 @@ class BlurredImageView @JvmOverloads constructor(
private fun View.scaleAnimate(scale: Float) = animate().scaleXY(scale).setDuration(ANIMATION_DURATION)
private fun View.alphaAnimate(alpha: Float) = animate().alpha(alpha).setDuration(ANIMATION_DURATION)
-
fun isBlurred(): Boolean {
return blurred
}
@@ -104,7 +124,6 @@ class BlurredImageView @JvmOverloads constructor(
image_foreground.alphaAnimate(0f).start()
}
-
/**
* Clear all animations and unblur the image
*/
@@ -154,4 +173,4 @@ class BlurredImageView @JvmOverloads constructor(
action(image_blur)
action(image_foreground)
}
-} \ No newline at end of file
+}
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/GlideHelper.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/GlideHelper.kt
index 8bb341c..21a1e9d 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/GlideHelper.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/GlideHelper.kt
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.mediapicker
import android.view.View
@@ -15,4 +30,4 @@ internal interface GlideContract {
internal class GlideDelegate : GlideContract {
override fun glide(v: View) = ((v.context as? MediaPickerCore<*>)?.glide ?: Glide.with(v))!!
-} \ No newline at end of file
+}
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 0cf6340..ca879ef 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.mediapicker
import android.app.Activity
@@ -15,14 +30,17 @@ import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.mikepenz.iconics.typeface.IIcon
import java.io.File
-
/**
* Created by Allan Wang on 2017-08-17.
*/
class MediaActionItem(
- val action: MediaAction,
- val mediaType: MediaType
-) : KauIItem<MediaActionItem, MediaItemBasic.ViewHolder>(R.layout.kau_iitem_image_basic, { MediaItemBasic.ViewHolder(it) }, R.id.kau_item_media_action) {
+ val action: MediaAction,
+ val mediaType: MediaType
+) : KauIItem<MediaActionItem, MediaItemBasic.ViewHolder>(
+ R.layout.kau_iitem_image_basic,
+ { MediaItemBasic.ViewHolder(it) },
+ R.id.kau_item_media_action
+) {
override fun isSelectable(): Boolean = false
@@ -60,7 +78,7 @@ internal const val MEDIA_ACTION_REQUEST_PICKER = 101
* If you just wish to use videos, see [MediaActionCameraVideo]
*/
abstract class MediaActionCamera(
- override var color: Int = MediaPickerCore.accentColor
+ override var color: Int = MediaPickerCore.accentColor
) : MediaAction {
abstract fun createFile(context: Context): File
@@ -105,7 +123,7 @@ abstract class MediaActionCamera(
* Basic camera action just for videos
*/
class MediaActionCameraVideo(
- override var color: Int = MediaPickerCore.accentColor
+ override var color: Int = MediaPickerCore.accentColor
) : MediaAction {
override fun iicon(item: MediaActionItem) = GoogleMaterial.Icon.gmd_videocam
override operator fun invoke(c: Context, item: MediaActionItem) {
@@ -126,8 +144,8 @@ class MediaActionCameraVideo(
* The type will be added programmatically
*/
class MediaActionGallery(
- val multiple: Boolean = false,
- override var color: Int = MediaPickerCore.accentColor
+ val multiple: Boolean = false,
+ override var color: Int = MediaPickerCore.accentColor
) : MediaAction {
override fun iicon(item: MediaActionItem) = when (item.mediaType) {
@@ -144,9 +162,10 @@ class MediaActionGallery(
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiple)
}
(c as Activity).startActivityForResult(
- Intent.createChooser(intent, c.string(R.string.kau_select_media)),
- MEDIA_ACTION_REQUEST_PICKER)
+ Intent.createChooser(intent, c.string(R.string.kau_select_media)),
+ MEDIA_ACTION_REQUEST_PICKER
+ )
}
}
}
-} \ 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 db4d18b..5d3e7b9 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt
@@ -1,8 +1,23 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.mediapicker
import android.graphics.drawable.Drawable
-import androidx.recyclerview.widget.RecyclerView
import android.view.View
+import androidx.recyclerview.widget.RecyclerView
import ca.allanwang.kau.iitems.KauIItem
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
@@ -13,22 +28,23 @@ import com.mikepenz.fastadapter.FastAdapter
/**
* Created by Allan Wang on 2017-07-04.
*/
-class MediaItem(val data: MediaModel)
- : KauIItem<MediaItem, MediaItem.ViewHolder>(R.layout.kau_iitem_image, { ViewHolder(it) }), GlideContract by GlideDelegate() {
+class MediaItem(val data: MediaModel) :
+ KauIItem<MediaItem, MediaItem.ViewHolder>(R.layout.kau_iitem_image, { ViewHolder(it) }),
+ GlideContract by GlideDelegate() {
private var failedToLoad = false
companion object {
fun bindEvents(fastAdapter: FastAdapter<MediaItem>) {
fastAdapter.withMultiSelect(true)
- .withSelectable(true)
- //adapter selector occurs before the on click event
- .withOnClickListener { v, _, item, _ ->
- val image = v as BlurredImageView
- if (item.isSelected) image.blur()
- else image.removeBlur()
- true
- }
+ .withSelectable(true)
+ //adapter selector occurs before the on click event
+ .withOnClickListener { v, _, item, _ ->
+ val image = v as BlurredImageView
+ if (item.isSelected) image.blur()
+ else image.removeBlur()
+ true
+ }
}
}
@@ -37,22 +53,33 @@ class MediaItem(val data: MediaModel)
override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
glide(holder.itemView)
- .load(data.data)
- .applyMediaOptions(holder.itemView.context)
- .listener(object : RequestListener<Drawable> {
- override fun onLoadFailed(e: GlideException?, model: Any, target: Target<Drawable>, isFirstResource: Boolean): Boolean {
- failedToLoad = true
- holder.container.imageBase.setImageDrawable(MediaPickerCore.getErrorDrawable(holder.itemView.context))
- return true
- }
+ .load(data.data)
+ .applyMediaOptions(holder.itemView.context)
+ .listener(object : RequestListener<Drawable> {
+ override fun onLoadFailed(
+ e: GlideException?,
+ model: Any,
+ target: Target<Drawable>,
+ isFirstResource: Boolean
+ ): Boolean {
+ failedToLoad = true
+ holder.container.imageBase.setImageDrawable(MediaPickerCore.getErrorDrawable(holder.itemView.context))
+ return true
+ }
- override fun onResourceReady(resource: Drawable, model: Any, target: Target<Drawable>, dataSource: DataSource, isFirstResource: Boolean): Boolean {
- holder.container.imageBase.setImageDrawable(resource)
- if (isSelected) holder.container.blurInstantly()
- return true
- }
- })
- .into(holder.container.imageBase)
+ override fun onResourceReady(
+ resource: Drawable,
+ model: Any,
+ target: Target<Drawable>,
+ dataSource: DataSource,
+ isFirstResource: Boolean
+ ): Boolean {
+ holder.container.imageBase.setImageDrawable(resource)
+ if (isSelected) holder.container.blurInstantly()
+ return true
+ }
+ })
+ .into(holder.container.imageBase)
}
override fun unbindView(holder: ViewHolder) {
@@ -65,4 +92,4 @@ class MediaItem(val data: MediaModel)
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
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 29babe2..73647b8 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt
@@ -1,10 +1,25 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.mediapicker
import android.annotation.SuppressLint
import android.app.Activity
import android.graphics.drawable.Drawable
-import androidx.recyclerview.widget.RecyclerView
import android.view.View
+import androidx.recyclerview.widget.RecyclerView
import ca.allanwang.kau.iitems.KauIItem
import ca.allanwang.kau.ui.views.MeasuredImageView
import com.bumptech.glide.load.DataSource
@@ -16,18 +31,19 @@ import com.mikepenz.fastadapter.FastAdapter
/**
* Created by Allan Wang on 2017-07-04.
*/
-class MediaItemBasic(val data: MediaModel)
- : KauIItem<MediaItem, MediaItemBasic.ViewHolder>(R.layout.kau_iitem_image_basic, { ViewHolder(it) }), GlideContract by GlideDelegate() {
+class MediaItemBasic(val data: MediaModel) :
+ KauIItem<MediaItem, MediaItemBasic.ViewHolder>(R.layout.kau_iitem_image_basic, { ViewHolder(it) }),
+ GlideContract by GlideDelegate() {
companion object {
@SuppressLint("NewApi")
fun bindEvents(activity: Activity, fastAdapter: FastAdapter<MediaItemBasic>) {
fastAdapter.withSelectable(false)
- //add image data and return right away
- .withOnClickListener { _, _, item, _ ->
- activity.finish(arrayListOf(item.data))
- true
- }
+ //add image data and return right away
+ .withOnClickListener { _, _, item, _ ->
+ activity.finish(arrayListOf(item.data))
+ true
+ }
}
}
@@ -36,19 +52,30 @@ class MediaItemBasic(val data: MediaModel)
override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
glide(holder.itemView)
- .load(data.data)
- .applyMediaOptions(holder.itemView.context)
- .listener(object : RequestListener<Drawable> {
- override fun onLoadFailed(e: GlideException?, model: Any, target: Target<Drawable>, isFirstResource: Boolean): Boolean {
- holder.image.setImageDrawable(MediaPickerCore.getErrorDrawable(holder.itemView.context))
- return true
- }
-
- override fun onResourceReady(resource: Drawable, model: Any, target: Target<Drawable>, dataSource: DataSource, isFirstResource: Boolean): Boolean {
- return false
- }
- })
- .into(holder.image)
+ .load(data.data)
+ .applyMediaOptions(holder.itemView.context)
+ .listener(object : RequestListener<Drawable> {
+ override fun onLoadFailed(
+ e: GlideException?,
+ model: Any,
+ target: Target<Drawable>,
+ isFirstResource: Boolean
+ ): Boolean {
+ holder.image.setImageDrawable(MediaPickerCore.getErrorDrawable(holder.itemView.context))
+ return true
+ }
+
+ override fun onResourceReady(
+ resource: Drawable,
+ model: Any,
+ target: Target<Drawable>,
+ dataSource: DataSource,
+ isFirstResource: Boolean
+ ): Boolean {
+ return false
+ }
+ })
+ .into(holder.image)
}
override fun unbindView(holder: ViewHolder) {
@@ -59,4 +86,4 @@ class MediaItemBasic(val data: MediaModel)
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
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/MediaModel.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt
index 9fc83f9..edd6199 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.mediapicker
import android.database.Cursor
@@ -9,38 +24,42 @@ import android.provider.MediaStore
import androidx.annotation.NonNull
import java.io.File
-
/**
* Created by Allan Wang on 2017-07-14.
*/
data class MediaModel(
- val data: String, val mimeType: String, val size: Long, val dateModified: Long, val displayName: String?
+ val data: String,
+ val mimeType: String,
+ val size: Long,
+ val dateModified: Long,
+ val displayName: String?
) : Parcelable {
@Throws(SQLException::class)
constructor(@NonNull cursor: Cursor) : this(
- cursor.getString(0),
- cursor.getString(1) ?: "",
- cursor.getLong(2),
- cursor.getLong(3),
- cursor.getString(4)
+ cursor.getString(0),
+ cursor.getString(1) ?: "",
+ cursor.getLong(2),
+ cursor.getLong(3),
+ cursor.getString(4)
)
constructor(f: File) : this(
- f.absolutePath,
- f.extension, // this isn't a mime type, but it does give some info
- f.length(),
- f.lastModified(),
- f.nameWithoutExtension
+ f.absolutePath,
+ f.extension, // this isn't a mime type, but it does give some info
+ f.length(),
+ f.lastModified(),
+ f.nameWithoutExtension
)
constructor(parcel: Parcel) : this(
- parcel.readString()!!,
- parcel.readString()!!,
- parcel.readLong(),
- parcel.readLong(),
- parcel.readString())
+ parcel.readString()!!,
+ parcel.readString()!!,
+ parcel.readLong(),
+ parcel.readLong(),
+ parcel.readString()
+ )
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(this.data)
@@ -67,11 +86,11 @@ data class MediaModel(
companion object CREATOR : Parcelable.Creator<MediaModel> {
val projection = arrayOf(
- MediaStore.MediaColumns.DATA,
- MediaStore.MediaColumns.MIME_TYPE,
- MediaStore.MediaColumns.SIZE,
- MediaStore.MediaColumns.DATE_MODIFIED,
- MediaStore.MediaColumns.DISPLAY_NAME
+ MediaStore.MediaColumns.DATA,
+ MediaStore.MediaColumns.MIME_TYPE,
+ MediaStore.MediaColumns.SIZE,
+ MediaStore.MediaColumns.DATE_MODIFIED,
+ MediaStore.MediaColumns.DISPLAY_NAME
)
override fun createFromParcel(parcel: Parcel): MediaModel {
@@ -82,5 +101,4 @@ data class MediaModel(
return arrayOfNulls(size)
}
}
-
-} \ 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 b915cc8..5e5d1ed 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.mediapicker
import android.database.Cursor
@@ -22,8 +37,8 @@ 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) {
override fun onCreate(savedInstanceState: Bundle?) {
@@ -78,19 +93,21 @@ abstract class MediaPickerActivityBase(
private fun setToolbarScrollable(scrollable: Boolean) {
val params = kau_toolbar.layoutParams as AppBarLayout.LayoutParams
if (scrollable)
- params.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS or AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
+ params.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS or
+ AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
else
params.scrollFlags = 0
}
override fun onLoadFinished(loader: Loader<Cursor>, data: Cursor?) {
super.onLoadFinished(loader, data)
- setToolbarScrollable((kau_recyclerview.layoutManager as LinearLayoutManager)
- .findLastCompletelyVisibleItemPosition() < adapter.adapterItemCount - 1)
+ setToolbarScrollable(
+ (kau_recyclerview.layoutManager as LinearLayoutManager)
+ .findLastCompletelyVisibleItemPosition() < adapter.adapterItemCount - 1
+ )
}
override fun onStatusChange(loaded: Boolean) {
setToolbarScrollable(loaded)
}
-
-} \ No newline at end of file
+}
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 2700780..a7ee63d 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.mediapicker
import android.os.Build
@@ -16,8 +31,8 @@ import kotlinx.android.synthetic.main.kau_activity_image_picker_overlay.*
*/
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
abstract class MediaPickerActivityOverlayBase(
- mediaType: MediaType,
- mediaActions: List<MediaAction> = emptyList()
+ mediaType: MediaType,
+ mediaActions: List<MediaAction> = emptyList()
) : MediaPickerCore<MediaItemBasic>(mediaType, mediaActions) {
override fun onCreate(savedInstanceState: Bundle?) {
@@ -46,4 +61,4 @@ abstract class MediaPickerActivityOverlayBase(
override fun onBackPressed() {
finishAfterTransition()
}
-} \ No newline at end of file
+}
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerBinder.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerBinder.kt
index 50fe7ae..ac43f9f 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerBinder.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerBinder.kt
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.mediapicker
import android.app.Activity
@@ -31,7 +46,8 @@ inline fun <reified T : MediaPickerCore<*>> Activity.kauLaunchMediaPicker(reques
* call under [Activity.onActivityResult]
* and make sure that the requestCode matches first
*/
-fun Activity.kauOnMediaPickerResult(resultCode: Int, data: Intent?) = MediaPickerCore.onMediaPickerResult(resultCode, data)
+fun Activity.kauOnMediaPickerResult(resultCode: Int, data: Intent?) =
+ MediaPickerCore.onMediaPickerResult(resultCode, data)
internal const val LOADER_ID = 42
internal const val MEDIA_PICKER_RESULT = "media_picker_result"
@@ -39,5 +55,8 @@ internal const val MEDIA_PICKER_RESULT = "media_picker_result"
internal const val ANIMATION_DURATION = 200L
internal const val ANIMATION_SCALE = 0.95f
-internal fun <T> RequestBuilder<T>.applyMediaOptions(context: Context) = apply(RequestOptions().diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop().override(MediaPickerCore.viewSize(context)))
-
+internal fun <T> RequestBuilder<T>.applyMediaOptions(context: Context) = apply(
+ RequestOptions().diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop().override(
+ MediaPickerCore.viewSize(context)
+ )
+)
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt
index 1092158..abdc266 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.mediapicker
import android.Manifest
@@ -45,8 +60,8 @@ import java.util.concurrent.Future
* Container for the main logic behind the both pickers
*/
abstract class MediaPickerCore<T : IItem<*, *>>(
- val mediaType: MediaType,
- val mediaActions: List<MediaAction>
+ val mediaType: MediaType,
+ val mediaActions: List<MediaAction>
) : KauBaseActivity(), LoaderManager.LoaderCallbacks<Cursor> {
companion object {
@@ -79,10 +94,10 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
fun getIconDrawable(context: Context, iicon: IIcon, color: Int): Drawable {
val sizePx = MediaPickerCore.computeViewSize(context)
return IconicsDrawable(context, iicon)
- .sizePx(sizePx)
- .backgroundColor(color)
- .paddingPx(sizePx / 3)
- .color(Color.WHITE)
+ .sizePx(sizePx)
+ .backgroundColor(color)
+ .paddingPx(sizePx / 3)
+ .color(Color.WHITE)
}
var accentColor: Int = 0xff666666.toInt()
@@ -183,8 +198,8 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
prefetcher = doAsync {
models.subList(0, Math.min(models.size, 50)).map { it.data }.forEach {
val target = glide.load(it)
- .applyMediaOptions(this@MediaPickerCore)
- .submit()
+ .applyMediaOptions(this@MediaPickerCore)
+ .submit()
try {
target.get()
} catch (ignored: InterruptedException) {
@@ -314,4 +329,4 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
}
}
}
-} \ No newline at end of file
+}
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaType.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaType.kt
index 0af4c2e..a42095f 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaType.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaType.kt
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.mediapicker
import android.net.Uri
@@ -7,17 +22,23 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
/**
* Created by Allan Wang on 2017-07-30.
*/
-enum class MediaType(val cacheStrategy: DiskCacheStrategy,
- val mimeType: String,
- val captureType: String,
- val contentUri: Uri) {
- IMAGE(DiskCacheStrategy.AUTOMATIC,
- "image/*",
- MediaStore.ACTION_IMAGE_CAPTURE,
- MediaStore.Images.Media.EXTERNAL_CONTENT_URI),
+enum class MediaType(
+ val cacheStrategy: DiskCacheStrategy,
+ val mimeType: String,
+ val captureType: String,
+ val contentUri: Uri
+) {
+ IMAGE(
+ DiskCacheStrategy.AUTOMATIC,
+ "image/*",
+ MediaStore.ACTION_IMAGE_CAPTURE,
+ MediaStore.Images.Media.EXTERNAL_CONTENT_URI
+ ),
- VIDEO(DiskCacheStrategy.AUTOMATIC,
- "video/*",
- MediaStore.ACTION_VIDEO_CAPTURE,
- MediaStore.Video.Media.EXTERNAL_CONTENT_URI)
-} \ No newline at end of file
+ VIDEO(
+ DiskCacheStrategy.AUTOMATIC,
+ "video/*",
+ MediaStore.ACTION_VIDEO_CAPTURE,
+ MediaStore.Video.Media.EXTERNAL_CONTENT_URI
+ )
+}
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaUtils.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaUtils.kt
index 1976172..32e64e4 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaUtils.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaUtils.kt
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.mediapicker
import android.annotation.SuppressLint
@@ -11,8 +26,9 @@ import ca.allanwang.kau.utils.buildIsLollipopAndUp
import java.io.File
import java.io.IOException
import java.text.SimpleDateFormat
-import java.util.*
-
+import java.util.ArrayList
+import java.util.Date
+import java.util.Locale
/**
* Created by Allan Wang on 2017-08-17.
@@ -55,4 +71,4 @@ fun Context.scanMedia(f: File) {
val contentUri = Uri.fromFile(f)
mediaScanIntent.data = contentUri
sendBroadcast(mediaScanIntent)
-} \ No newline at end of file
+}