Skip to content

Commit

Permalink
Merge pull request #54 from ParkSangGwon/feature/custom-toast-action-…
Browse files Browse the repository at this point in the history
…support

Support custom toast UI
  • Loading branch information
ParkSangGwon authored Jan 11, 2021
2 parents 9afe60c + ef7746f commit cfe55cf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
GROUP=gun0912.ted
VERSION_NAME=1.1.4
VERSION_NAME=1.1.5
DEVELOPER_ID='gun0912'
DEVELOPER_NAME='Ted Park'
SITE_URL='https://github.com/ParkSangGwon/TedImagePicker'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import android.util.Log
import android.view.MenuItem
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
Expand All @@ -38,6 +37,7 @@ import gun0912.tedimagepicker.model.Album
import gun0912.tedimagepicker.model.Media
import gun0912.tedimagepicker.util.GalleryUtil
import gun0912.tedimagepicker.util.MediaUtil
import gun0912.tedimagepicker.util.ToastUtil
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
Expand Down Expand Up @@ -368,7 +368,7 @@ internal class TedImagePickerActivity : AppCompatActivity() {
val selectedUriList = mediaAdapter.selectedUriList
if (selectedUriList.size < builder.minCount) {
val message = builder.minCountMessage ?: getString(builder.minCountMessageResId)
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
ToastUtil.showToast(message)
} else {

val data = Intent().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import gun0912.tedimagepicker.builder.type.MediaType
import gun0912.tedimagepicker.databinding.ItemGalleryCameraBinding
import gun0912.tedimagepicker.databinding.ItemGalleryMediaBinding
import gun0912.tedimagepicker.model.Media
import gun0912.tedimagepicker.util.ToastUtil
import gun0912.tedimagepicker.zoom.TedImageZoomActivity

internal class MediaAdapter(
Expand Down Expand Up @@ -41,7 +42,7 @@ internal class MediaAdapter(
if (selectedUriList.size == builder.maxCount) {
val message =
builder.maxCountMessage ?: activity.getString(builder.maxCountMessageResId)
Toast.makeText(activity, message, Toast.LENGTH_SHORT).show()
ToastUtil.showToast(message)
} else {
selectedUriList.add(uri)
onMediaAddListener?.invoke()
Expand Down Expand Up @@ -121,4 +122,4 @@ internal class MediaAdapter(

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import gun0912.tedimagepicker.builder.type.AlbumType
import gun0912.tedimagepicker.builder.type.ButtonGravity
import gun0912.tedimagepicker.builder.type.MediaType
import gun0912.tedimagepicker.builder.type.SelectType
import gun0912.tedimagepicker.util.ToastUtil
import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize

Expand Down Expand Up @@ -77,14 +78,16 @@ open class TedImagePickerBaseBuilder<out B : TedImagePickerBaseBuilder<B>>(

@IgnoredOnParcel
protected var onSelectedListener: OnSelectedListener? = null

@IgnoredOnParcel
protected var onMultiSelectedListener: OnMultiSelectedListener? = null

@IgnoredOnParcel
protected var onErrorListener: OnErrorListener? = null


@SuppressLint("CheckResult")
protected fun startInternal(context: Context) {
ToastUtil.context = context
checkPermission(context)
.subscribe({ permissionResult ->
if (permissionResult.isGranted) {
Expand Down Expand Up @@ -277,4 +280,9 @@ open class TedImagePickerBaseBuilder<out B : TedImagePickerBaseBuilder<B>>(
return this as B
}

}
fun toast(toastAction: ((String) -> Unit)): B {
ToastUtil.toastAction = toastAction
return this as B
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package gun0912.tedimagepicker.util

import android.content.Context
import android.widget.Toast

object ToastUtil {
lateinit var context: Context
var toastAction: ((String) -> Unit)? = null

fun showToast(text: String) {
toastAction?.invoke(text) ?: Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
}
}

0 comments on commit cfe55cf

Please sign in to comment.