Skip to content

Commit

Permalink
added support for icons
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaAnand2811 committed May 18, 2018
1 parent 7e5fb04 commit e65cc25
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MainActivity : AppCompatActivity() {
fun morph(view: View) {
dialog = MorphDialog.Builder(this, view as FloatingActionButton)
.title("Title")
.iconRes(R.drawable.ic_launcher_background)
.items("Item 1", "Item 2")
// .content("This is a sentence. Here is another one.")
.positiveText("Ok")
Expand All @@ -43,7 +44,7 @@ class MainActivity : AppCompatActivity() {
Toast.makeText(this@MainActivity, "onPositive", Toast.LENGTH_SHORT).show()
})
.onNegative(object : MorphSingleButtonCallback {
override fun onClick(dialog1: MorphDialog, which: MorphDialogAction) {
override fun onClick(a: MorphDialog, which: MorphDialogAction) {
Toast.makeText(this@MainActivity, "onNegative", Toast.LENGTH_SHORT).show()
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.adityaanand.morphdialog
import android.annotation.SuppressLint
import android.content.res.ColorStateList
import android.os.Parcelable
import android.support.annotation.DrawableRes
import kotlinx.android.parcel.Parcelize
import java.util.*

Expand All @@ -16,6 +17,7 @@ data class DialogBuilderData(var positiveText: CharSequence? = null,
var neutralText: CharSequence? = null,
var darkTheme: Boolean = false,
var title: CharSequence? = null,
@DrawableRes var iconRes: Int? = null,
var content: CharSequence? = null,
var cancelable: Boolean = true,
var canceledOnTouchOutside: Boolean = true,
Expand All @@ -28,15 +30,15 @@ data class DialogBuilderData(var positiveText: CharSequence? = null,
var neutralColor: ColorStateList? = null,
/*items*/
var items: Array<CharSequence>? = null,
//single choice
//single choice
var alwaysCallSingleChoiceCallback: Boolean = false,
var hasSingleChoiceCallback: Boolean = false,
var selectedIndex: Int = -1,
//multi choice
//multi choice
var alwaysCallMultiChoiceCallback: Boolean = false,
var hasMultiChoiceCallback: Boolean = false,
var selectedIndices: ArrayList<Int> = arrayListOf()
) : Parcelable {
) : Parcelable {

override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
10 changes: 6 additions & 4 deletions library/src/main/java/com/adityaanand/morphdialog/MorphDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import android.app.ActivityOptions
import android.content.Intent
import android.content.res.ColorStateList
import android.os.Build
import android.support.annotation.AttrRes
import android.support.annotation.ColorInt
import android.support.annotation.ColorRes
import android.support.annotation.StringRes
import android.support.annotation.*
import android.support.design.widget.FloatingActionButton
import com.adityaanand.morphdialog.interfaces.MorphListCallbackMultiChoice
import com.adityaanand.morphdialog.interfaces.MorphListCallbackSingleChoice
Expand Down Expand Up @@ -115,6 +112,11 @@ class MorphDialog private constructor(var builder: Builder) {
internal var singleChoiceCallback: MorphListCallbackSingleChoice? = null
internal var multiChoiceCallback: MorphListCallbackMultiChoice? = null

fun iconRes(@DrawableRes iconRes: Int): Builder {
data.iconRes = iconRes
return this
}

fun title(@StringRes titleRes: Int): Builder {
title(activity.getText(titleRes))
return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ open class MorphDialogActivity : Activity() {
builder.negativeColor(data.negativeColor!!)
if (data.positiveColor != null)
builder.positiveColor(data.positiveColor!!)
if (data.iconRes != null)
builder.iconRes(data.iconRes!!)

/**items**/
if (data.items != null)
Expand All @@ -60,7 +62,7 @@ open class MorphDialogActivity : Activity() {
if (data.alwaysCallSingleChoiceCallback)
builder.alwaysCallSingleChoiceCallback()
if (data.hasSingleChoiceCallback)
builder.itemsCallbackSingleChoice(data.selectedIndex) { dialog, itemView, which, text ->
builder.itemsCallbackSingleChoice(data.selectedIndex) { _, _, which, text ->
onSingleItemPicked(which, text.toString())
true
}
Expand Down

0 comments on commit e65cc25

Please sign in to comment.