diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index a95a3d92..d326780e 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,5 +1,8 @@ + + diff --git a/images/1.png b/images/1.png index 3b1879e7..0f27013e 100644 Binary files a/images/1.png and b/images/1.png differ diff --git a/images/2.png b/images/2.png index ccb98149..f7b2db1a 100644 Binary files a/images/2.png and b/images/2.png differ diff --git a/images/dialogs-4.png b/images/dialogs-4.png new file mode 100644 index 00000000..5fab7ee3 Binary files /dev/null and b/images/dialogs-4.png differ diff --git a/libraries/dialogs/README.md b/libraries/dialogs/README.md index c0ce2693..0f5c4ec8 100644 --- a/libraries/dialogs/README.md +++ b/libraries/dialogs/README.md @@ -1,7 +1,7 @@ - + -$dialogsVersion = dialogs-1.0.2 [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) +$dialogsVersion = dialogs-1.0.3 [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) ## Dialogs Dialogs is a bunch of BottomSheetDialogs to use in app to show user an information, agreement or list. @@ -89,6 +89,9 @@ All **Info Dialog** arguments plus these arguments will be applicable to show se | `items` | List> | Item list that will be listed on dialog. | null | | `showItemsAsHtml` | Boolean | Item texts will be parsed as Html if this flag setted as true. | false | | `onItemSelectedListener` | (DialogFragment, Int) -> Unit | Listener to notify selected index. | null | +| `enableSearch` | Boolean | Enables search function in given `items` | false | +| `showClearSearchButton` | Boolean | Shows clean button on the right of the search input line. | false | +| `searchHint` | String | Hint to show on search input line. | "" | Sample usage: ```kotlin @@ -104,10 +107,26 @@ selectionDialog { } ``` +Sample usage with search: +```kotlin +selectionDialog { + title = "Selection Dialog with Search Title" + content = getContent() + items = getItemsAsHtml() + showItemsAsHtml = true + onItemSelectedListener = { dialog, index -> + onItemSelected(index) + } + enableSearch = true + showClearSearchButton = true + searchHint = "Hint for search" +} +``` + ## TODOs * Implement ListDialog. * ~~Implement SelectionDialog~~ - * Implement search line. + * ~~Implement search line.~ * Implement multiple selectable type. * Provide theme for more styling. * Update builder for Java. diff --git a/libraries/dialogs/build.gradle b/libraries/dialogs/build.gradle index 8e32588f..9525f00e 100644 --- a/libraries/dialogs/build.gradle +++ b/libraries/dialogs/build.gradle @@ -5,7 +5,7 @@ apply plugin: 'kotlin-kapt' apply plugin: 'com.github.dcendents.android-maven' group="com.trendyol.ui-components" -version="1.0.2" +version="1.0.3" android { compileSdkVersion 29 @@ -40,4 +40,7 @@ dependencies { implementation 'androidx.core:core-ktx:1.1.0' implementation 'com.google.android.material:material:1.0.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + + implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0' + kapt 'androidx.lifecycle:lifecycle-compiler:2.1.0' } diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/BaseBottomSheetDialog.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/BaseBottomSheetDialog.kt index 5526c668..67cb4922 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/BaseBottomSheetDialog.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/BaseBottomSheetDialog.kt @@ -12,7 +12,7 @@ import com.trendyol.dialog.R abstract class BaseBottomSheetDialog : BottomSheetDialogFragment() { - protected lateinit var binding: DB + lateinit var binding: DB @LayoutRes abstract fun getLayoutResId(): Int diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/BindingAdapters.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/BindingAdapters.kt index 90963c09..007d52e5 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/BindingAdapters.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/BindingAdapters.kt @@ -21,10 +21,3 @@ internal fun AppCompatImageView.setDrawableResource(@DrawableRes drawableResId: internal fun View.setVisibility(isVisible: Boolean) { visibility = if (isVisible) View.VISIBLE else View.GONE } - -@BindingAdapter("items") -internal fun RecyclerView.setItems(items: List>?) { - if (items != null) { - (adapter as? DialogListAdapter)?.setItems(items) - } -} diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/Builder.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/Builder.kt index c83aac34..b770c551 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/Builder.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/Builder.kt @@ -60,6 +60,9 @@ class SelectionDialogBuilder internal constructor() : InfoDialogBuilder() { var items: List> = emptyList() var showItemsAsHtml: Boolean = false var onItemSelectedListener: ((DialogFragment, Int) -> Unit)? = null + var enableSearch: Boolean = false + var showClearSearchButton: Boolean = false + var searchHint: String = "" internal fun buildSelectionDialog(block: SelectionDialogBuilder.() -> Unit): DialogFragment = SelectionDialogBuilder().apply(block).let { @@ -72,7 +75,10 @@ class SelectionDialogBuilder internal constructor() : InfoDialogBuilder() { contentImage = it.contentImage, items = it.items, showItemsAsHtml = it.showItemsAsHtml, - onItemSelectedListener = it.onItemSelectedListener + onItemSelectedListener = it.onItemSelectedListener, + enableSearch = it.enableSearch, + showClearSearchButton = it.showClearSearchButton, + searchHint = it.searchHint ) } } diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt index 94dd9c0d..9d7c845f 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt @@ -1,11 +1,17 @@ package com.trendyol.uicomponents.dialogs import android.text.SpannableString +import android.view.ViewGroup.FOCUS_AFTER_DESCENDANTS import androidx.annotation.DrawableRes +import androidx.core.widget.doAfterTextChanged import androidx.fragment.app.FragmentManager +import androidx.lifecycle.Observer +import androidx.lifecycle.ViewModelProviders +import com.google.android.material.bottomsheet.BottomSheetBehavior import com.trendyol.dialog.R import com.trendyol.dialog.databinding.FragmentDialogBinding import com.trendyol.uicomponents.dialogs.list.DialogListAdapter +import com.trendyol.uicomponents.dialogs.list.DialogListViewModel class DialogFragment internal constructor( private val title: String? = null, @@ -20,14 +26,22 @@ class DialogFragment internal constructor( private val rightButtonClickListener: ((DialogFragment) -> Unit)? = null, private val items: List>? = null, private val showItemsAsHtml: Boolean = false, - private val onItemSelectedListener: ((DialogFragment, Int) -> Unit)? = null + private val onItemSelectedListener: ((DialogFragment, Int) -> Unit)? = null, + private val enableSearch: Boolean = false, + private val showClearSearchButton: Boolean = false, + private val searchHint: String = "" ) : BaseBottomSheetDialog() { private val itemsAdapter by lazy { DialogListAdapter(showItemsAsHtml) } + private val dialogListViewModel by lazy { + ViewModelProviders.of(this)[DialogListViewModel::class.java] + } override fun getLayoutResId(): Int = R.layout.fragment_dialog override fun setUpView() { + animateCornerRadiusWithStateChanged() + with(binding) { imageClose.setOnClickListener { dismiss() @@ -40,11 +54,32 @@ class DialogFragment internal constructor( rightButtonClickListener?.invoke(this@DialogFragment) } - recyclerViewItems.adapter = itemsAdapter - recyclerViewItems.isNestedScrollingEnabled = false + if (items != null) { + recyclerViewItems.adapter = itemsAdapter + recyclerViewItems.isNestedScrollingEnabled = false - itemsAdapter.onItemSelectedListener = { position -> - onItemSelectedListener?.invoke(this@DialogFragment, position) + itemsAdapter.onItemSelectedListener = { position -> + dialogListViewModel.onSelectionChanged(position) + } + + editTextSearch.setOnFocusChangeListener { _, hasFocus -> + if (hasFocus) { + setBottomSheetState(BottomSheetBehavior.STATE_EXPANDED) + } + } + + editTextSearch.doAfterTextChanged { + dialogListViewModel.search(it.toString()) + } + + imageClearSearchQuery.setOnClickListener { + editTextSearch.text?.clear() + dialogListViewModel.clearSearch() + } + + constraintLayout.descendantFocusability = FOCUS_AFTER_DESCENDANTS + + setUpViewModel(items) } } } @@ -58,7 +93,10 @@ class DialogFragment internal constructor( contentImage = contentImage, leftButtonText = leftButtonText, rightButtonText = rightButtonText, - listItems = items + isListVisible = items != null, + isSearchEnabled = enableSearch, + isClearSearchButtonVisible = showClearSearchButton, + searchHint = searchHint ) binding.viewState = viewState @@ -69,6 +107,18 @@ class DialogFragment internal constructor( show(fragmentManager, TAG) } + private fun setUpViewModel(items: List>) { + with(dialogListViewModel) { + getDialogSearchItemsLiveData().observe(viewLifecycleOwner, Observer { items -> + itemsAdapter.setItems(items) + }) + getLastChangedItemLiveData().observeNonNull(viewLifecycleOwner) { position -> + onItemSelectedListener?.invoke(this@DialogFragment, position) + } + setInitialItems(items) + } + } + companion object { const val TAG: String = "TRENDYOL_BOTTOM_SHEET_DIALOG" diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogViewState.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogViewState.kt index b843c002..9a0a6833 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogViewState.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogViewState.kt @@ -9,9 +9,12 @@ data class DialogViewState( private val content: CharSequence, val showContentAsHtml: Boolean, @DrawableRes val contentImage: Int?, - val leftButtonText: String? = null, - val rightButtonText: String? = null, - val listItems: List>? = null + val leftButtonText: String?, + val rightButtonText: String?, + val isListVisible: Boolean, + val isSearchEnabled: Boolean, + val isClearSearchButtonVisible: Boolean, + val searchHint: String ) { fun isLeftButtonVisible(): Boolean = leftButtonText != null @@ -27,6 +30,4 @@ data class DialogViewState( fun isContentVisible(): Boolean = content.isNotEmpty() fun isContentImageVisible(): Boolean = contentImage != null - - fun isListVisible(): Boolean = !listItems.isNullOrEmpty() } diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/Extensions.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/Extensions.kt index 0567b27f..ead2dfcb 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/Extensions.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/Extensions.kt @@ -1,11 +1,21 @@ package com.trendyol.uicomponents.dialogs +import android.animation.ObjectAnimator +import android.app.Dialog +import android.content.Context import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.annotation.DimenRes import androidx.annotation.LayoutRes import androidx.databinding.DataBindingUtil import androidx.databinding.ViewDataBinding +import androidx.lifecycle.LifecycleOwner +import androidx.lifecycle.LiveData +import androidx.lifecycle.Observer +import com.google.android.material.bottomsheet.BottomSheetBehavior +import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import com.trendyol.dialog.R internal fun ViewGroup?.inflate( @LayoutRes layoutId: Int, @@ -21,3 +31,59 @@ internal fun ViewGroup?.inflate( attachToParent ) } + +internal fun Context.pixel(@DimenRes dimenResId: Int): Float = + resources.getDimensionPixelSize(dimenResId).toFloat() + +internal fun BottomSheetDialogFragment.getBottomSheetBehavior(dialog: Dialog? = getDialog()): BottomSheetBehavior? { + return dialog + ?.findViewById(com.google.android.material.R.id.design_bottom_sheet) + ?.let { BottomSheetBehavior.from(it) } +} + +internal fun BottomSheetDialogFragment.setBottomSheetState(state: Int) { + getBottomSheetBehavior()?.state = state +} + +internal fun LiveData.observeNonNull(owner: LifecycleOwner, onNotNull: (T) -> Unit) = + observe(owner, Observer { + if (it != null) { + onNotNull.invoke(it) + } + }) + +internal fun DialogFragment.animateCornerRadiusWithStateChanged() { + val expandAnimator = + ObjectAnimator.ofFloat( + binding.cardView, + "radius", + requireContext().pixel(R.dimen.dialogs_corner_radius), + 0F + ).apply { + duration = 250 + } + val collapseAnimator = + ObjectAnimator.ofFloat( + binding.cardView, + "radius", + 0F, + requireContext().pixel(R.dimen.dialogs_corner_radius) + ).apply { + duration = 250 + } + + getBottomSheetBehavior()?.setBottomSheetCallback(object : + BottomSheetBehavior.BottomSheetCallback() { + + override fun onStateChanged(bottomSheet: View, newState: Int) { + if (newState == BottomSheetBehavior.STATE_EXPANDED) { + expandAnimator.start() + } else if (newState == BottomSheetBehavior.STATE_COLLAPSED) { + collapseAnimator.start() + } + } + + override fun onSlide(bottomSheet: View, slideOffset: Float) { + } + }) +} diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/SingleLiveEvent.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/SingleLiveEvent.kt new file mode 100644 index 00000000..ef79d46e --- /dev/null +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/SingleLiveEvent.kt @@ -0,0 +1,42 @@ +package com.trendyol.uicomponents.dialogs + +import androidx.annotation.MainThread +import androidx.lifecycle.LifecycleOwner +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.Observer +import java.util.concurrent.atomic.AtomicBoolean + +/** + * A lifecycle-aware observable that sends only new updates after subscription, used for events like + * navigation and Snackbar messages. + * + * + * This avoids a common problem with events: on configuration change (like rotation) an update + * can be emitted if the observer is active. This LiveData only calls the observable if there's an + * explicit call to setValue() or call(). + * + * + * Note that only one observer is going to be notified of changes. + * + * Source: https://github.com/android/play-billing-samples/blob/master/ClassyTaxi/android/ClassyTaxi/app/src/main/java/com/example/subscriptions/ui/SingleLiveEvent.kt + */ +internal class SingleLiveEvent : MutableLiveData() { + + private val pending = AtomicBoolean(false) + + @MainThread + override fun observe(owner: LifecycleOwner, observer: Observer) { + // Observe the internal MutableLiveData + super.observe(owner, Observer { t -> + if (pending.compareAndSet(true, false)) { + observer.onChanged(t) + } + }) + } + + @MainThread + override fun setValue(t: T?) { + pending.set(true) + super.setValue(t) + } +} diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListAdapter.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListAdapter.kt index cead8568..ba79a7fd 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListAdapter.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListAdapter.kt @@ -21,18 +21,6 @@ internal class DialogListAdapter( notifyDataSetChanged() } - private fun updateList(selectedItemPosition: Int) { - var firstSelectedItemPosition = 0 - items = items.mapIndexed { index, item -> - if (item.first) { - firstSelectedItemPosition = index - } - item.copy(first = index == selectedItemPosition, second = item.second) - } - notifyItemChanged(firstSelectedItemPosition) - notifyItemChanged(selectedItemPosition) - } - override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { holder.bind(items[position]) } @@ -49,7 +37,6 @@ internal class DialogListAdapter( init { binding.radioButtonItem.setOnCheckedChangeListener { radioButton, isChecked -> if (radioButton.isPressed && isChecked) { - updateList(selectedItemPosition = adapterPosition) onItemSelectedListener?.invoke(adapterPosition) } } diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListViewModel.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListViewModel.kt new file mode 100644 index 00000000..0ae14c29 --- /dev/null +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListViewModel.kt @@ -0,0 +1,58 @@ +package com.trendyol.uicomponents.dialogs.list + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.trendyol.uicomponents.dialogs.SingleLiveEvent + +class DialogListViewModel : ViewModel() { + + private val dialogSearchItemsLiveData: MutableLiveData>> = + MutableLiveData() + + private val lastChangedItemLiveData: SingleLiveEvent = SingleLiveEvent() + + fun getDialogSearchItemsLiveData(): LiveData>> = + dialogSearchItemsLiveData + + fun getLastChangedItemLiveData(): LiveData = lastChangedItemLiveData + + private lateinit var items: List> + + private var searchQuery: String = "" + + fun setInitialItems(items: List>) { + this.items = items + dialogSearchItemsLiveData.value = items + } + + fun search(query: String) { + searchQuery = query + dialogSearchItemsLiveData.value = + items.filter { it.second.contains(query, ignoreCase = true) } + } + + fun clearSearch() { + searchQuery = "" + dialogSearchItemsLiveData.value = items + } + + fun onSelectionChanged(position: Int) { + // First update all items, then update in liveData. + items.indexOf(dialogSearchItemsLiveData.value?.get(position)).also { + updateSelectedIndex(it) + } + + search(searchQuery) + } + + private fun updateSelectedIndex(position: Int) { + items = items.toMutableList().mapIndexed { index, item -> + item.copy(first = position == index).also { + if (it.first) { + lastChangedItemLiveData.value = position + } + } + } + } +} diff --git a/libraries/dialogs/src/main/res/layout/fragment_dialog.xml b/libraries/dialogs/src/main/res/layout/fragment_dialog.xml index bf68a4d5..664ae645 100644 --- a/libraries/dialogs/src/main/res/layout/fragment_dialog.xml +++ b/libraries/dialogs/src/main/res/layout/fragment_dialog.xml @@ -11,6 +11,7 @@ @@ -24,9 +25,10 @@ android:id="@+id/viewTitleBackground" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" - android:background="#f5f5f5" - android:paddingStart="@dimen/margin_dialog_outer" - android:paddingEnd="@dimen/margin_dialog_outer"> + android:background="@color/dialogs_gray" + android:focusableInTouchMode="true" + android:paddingStart="@dimen/dialogs_margin_outer" + android:paddingEnd="@dimen/dialogs_margin_outer"> @@ -51,10 +53,11 @@ + android:paddingStart="@dimen/dialogs_margin_outer" + android:paddingEnd="@dimen/dialogs_margin_outer"> @@ -63,10 +66,10 @@ android:id="@+id/imageContent" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="@dimen/margin_dialog_outer" - android:layout_marginBottom="@dimen/margin_dialog_outer" - app:isVisible="@{viewState.contentImageVisible}" + android:layout_marginTop="@dimen/dialogs_margin_outer" + android:layout_marginBottom="@dimen/dialogs_margin_outer" app:drawableResource="@{viewState.contentImage}" + app:isVisible="@{viewState.contentImageVisible}" app:layout_constraintBottom_toTopOf="@id/textContent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -78,26 +81,59 @@ style="@style/Trendyol.UIComponents.Dialogs.PrimaryText.Body" android:layout_width="0dp" android:layout_height="wrap_content" - app:isVisible="@{viewState.contentVisible}" - android:padding="@dimen/margin_dialog_outer" + android:layout_marginBottom="@dimen/dialogs_margin_inner" + android:padding="@dimen/dialogs_margin_inner" android:text="@{viewState.content}" + app:isVisible="@{viewState.contentVisible}" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/imageContent" tools:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt" /> + + + + diff --git a/libraries/dialogs/src/main/res/values/colors.xml b/libraries/dialogs/src/main/res/values/colors.xml new file mode 100644 index 00000000..0b063d33 --- /dev/null +++ b/libraries/dialogs/src/main/res/values/colors.xml @@ -0,0 +1,5 @@ + + + + #f5f5f5 + diff --git a/libraries/dialogs/src/main/res/values/dimens.xml b/libraries/dialogs/src/main/res/values/dimens.xml index 8a6c1f06..4cafaf37 100644 --- a/libraries/dialogs/src/main/res/values/dimens.xml +++ b/libraries/dialogs/src/main/res/values/dimens.xml @@ -1,8 +1,10 @@ - 16dp + 16dp + 8dp - 16dp - 8dp + 16dp + + 250 diff --git a/libraries/dialogs/src/main/res/values/styles.xml b/libraries/dialogs/src/main/res/values/styles.xml index 4e897668..d9c940e3 100644 --- a/libraries/dialogs/src/main/res/values/styles.xml +++ b/libraries/dialogs/src/main/res/values/styles.xml @@ -1,5 +1,5 @@ - + diff --git a/sample/src/main/java/com/trendyol/uicomponents/DialogsActivity.kt b/sample/src/main/java/com/trendyol/uicomponents/DialogsActivity.kt index ce723e07..33168be6 100644 --- a/sample/src/main/java/com/trendyol/uicomponents/DialogsActivity.kt +++ b/sample/src/main/java/com/trendyol/uicomponents/DialogsActivity.kt @@ -21,6 +21,7 @@ class DialogsActivity : AppCompatActivity() { button_info_dialog.setOnClickListener { showInfoDialog() } button_agreement_dialog.setOnClickListener { showAgreementDialog() } button_selection_dialog.setOnClickListener { showSelectionDialog() } + button_selection_with_search_dialog.setOnClickListener { showSelectionWithSearchDialog() } } private fun showInfoDialog() { @@ -71,6 +72,23 @@ class DialogsActivity : AppCompatActivity() { selectionDialog.showDialog(supportFragmentManager) } + private fun showSelectionWithSearchDialog() { + selectionDialog { + title = "Selection Dialog with Search Sample" + content = getHtmlString() + showContentAsHtml = true + showCloseButton = false + contentImage = android.R.drawable.ic_dialog_email + items = getListItems() + onItemSelectedListener = { dialogFragment, i -> + showToast("Selection changed to ${i + 1}th ") + } + enableSearch = true + showClearSearchButton = true + searchHint = "Hint for search" + }.showDialog(supportFragmentManager) + } + private fun getSpannableString(): SpannableStringBuilder = SpannableStringBuilder("Lorem ipsum dolor sit amet,") .bold { diff --git a/sample/src/main/res/layout/activity_dialogs.xml b/sample/src/main/res/layout/activity_dialogs.xml index 2dd0af1f..50a26de9 100644 --- a/sample/src/main/res/layout/activity_dialogs.xml +++ b/sample/src/main/res/layout/activity_dialogs.xml @@ -45,4 +45,14 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/button_agreement_dialog" /> + + \ No newline at end of file diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml index 74b1ae5e..7d9961c7 100644 --- a/sample/src/main/res/values/styles.xml +++ b/sample/src/main/res/values/styles.xml @@ -1,4 +1,4 @@ - + +