-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Trendyol/feature/list-dialog
Feature/list dialog
- Loading branch information
Showing
21 changed files
with
423 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 10 additions & 4 deletions
14
libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogViewState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,32 @@ | ||
package com.trendyol.uicomponents.dialogs | ||
|
||
import android.text.Spanned | ||
import androidx.annotation.DrawableRes | ||
import androidx.core.text.HtmlCompat | ||
|
||
data class DialogViewState( | ||
val title: String?, | ||
val showCloseButton: Boolean?, | ||
private val content: Spanned, | ||
private val content: CharSequence, | ||
val showContentAsHtml: Boolean, | ||
@DrawableRes val contentImage: Int?, | ||
val leftButtonText: String? = null, | ||
val rightButtonText: String? = null | ||
val rightButtonText: String? = null, | ||
val listItems: List<Pair<Boolean, CharSequence>>? = null | ||
) { | ||
|
||
fun isLeftButtonVisible(): Boolean = leftButtonText != null | ||
|
||
fun isRightButtonVisible(): Boolean = rightButtonText != null | ||
|
||
fun getContent(): Spanned = if (showContentAsHtml) { | ||
fun getContent(): CharSequence = if (showContentAsHtml) { | ||
HtmlCompat.fromHtml(content.toString(), HtmlCompat.FROM_HTML_MODE_COMPACT) | ||
} else { | ||
content | ||
} | ||
|
||
fun isContentVisible(): Boolean = content.isNotEmpty() | ||
|
||
fun isContentImageVisible(): Boolean = contentImage != null | ||
|
||
fun isListVisible(): Boolean = !listItems.isNullOrEmpty() | ||
} |
23 changes: 23 additions & 0 deletions
23
libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/Extensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.trendyol.uicomponents.dialogs | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.annotation.LayoutRes | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.databinding.ViewDataBinding | ||
|
||
internal fun <T : ViewDataBinding> ViewGroup?.inflate( | ||
@LayoutRes layoutId: Int, | ||
attachToParent: Boolean = true | ||
): T { | ||
if (this?.isInEditMode == true) { | ||
View.inflate(context, layoutId, parent as? ViewGroup?) | ||
} | ||
return DataBindingUtil.inflate( | ||
LayoutInflater.from(this!!.context), | ||
layoutId, | ||
this, | ||
attachToParent | ||
) | ||
} |
67 changes: 67 additions & 0 deletions
67
libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.trendyol.uicomponents.dialogs.list | ||
|
||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.trendyol.dialog.R | ||
import com.trendyol.dialog.databinding.ItemListBinding | ||
import com.trendyol.uicomponents.dialogs.inflate | ||
|
||
internal class DialogListAdapter( | ||
private val showItemsAsHtml: Boolean | ||
) : RecyclerView.Adapter<DialogListAdapter.ItemViewHolder>() { | ||
|
||
private var items: List<Pair<Boolean, CharSequence>> = emptyList() | ||
var onItemSelectedListener: ((Int) -> Unit)? = null | ||
|
||
fun setItems(list: List<Pair<Boolean, CharSequence>>) { | ||
items = items.toMutableList().apply { | ||
clear() | ||
addAll(list) | ||
} | ||
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]) | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder = | ||
ItemViewHolder(parent.inflate(R.layout.item_list, false)) | ||
|
||
override fun getItemCount(): Int = items.size | ||
|
||
inner class ItemViewHolder( | ||
private val binding: ItemListBinding | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
|
||
init { | ||
binding.radioButtonItem.setOnCheckedChangeListener { radioButton, isChecked -> | ||
if (radioButton.isPressed && isChecked) { | ||
updateList(selectedItemPosition = adapterPosition) | ||
onItemSelectedListener?.invoke(adapterPosition) | ||
} | ||
} | ||
} | ||
|
||
fun bind(item: Pair<Boolean, CharSequence>) { | ||
binding.viewState = DialogListItemViewState( | ||
name = item.second, | ||
showAsHtml = showItemsAsHtml, | ||
isChecked = item.first | ||
) | ||
binding.executePendingBindings() | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...s/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/list/DialogListItemViewState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.trendyol.uicomponents.dialogs.list | ||
|
||
import androidx.core.text.HtmlCompat | ||
|
||
data class DialogListItemViewState( | ||
val name: CharSequence, | ||
val showAsHtml: Boolean, | ||
val isChecked: Boolean | ||
) { | ||
|
||
fun getText(): CharSequence = if (showAsHtml) { | ||
HtmlCompat.fromHtml(name.toString(), HtmlCompat.FROM_HTML_MODE_COMPACT) | ||
} else { | ||
name | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
libraries/dialogs/src/main/res/drawable/ic_radio_button_checked.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M12,7c-2.76,0 -5,2.24 -5,5s2.24,5 5,5 5,-2.24 5,-5 -2.24,-5 -5,-5zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/> | ||
</vector> |
9 changes: 9 additions & 0 deletions
9
libraries/dialogs/src/main/res/drawable/ic_radio_button_unchecked.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/> | ||
</vector> |
6 changes: 6 additions & 0 deletions
6
libraries/dialogs/src/main/res/drawable/selector_radio_button.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<item android:drawable="@drawable/ic_radio_button_checked" android:state_checked="true" /> | ||
<item android:drawable="@drawable/ic_radio_button_unchecked" android:state_checked="false" /> | ||
</selector> |
Oops, something went wrong.