diff --git a/README.md b/README.md index b5e1ec0..bc17d78 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ dependencyResolutionManagement { ### Step 2. Add the dependency ```gradle dependencies { - implementation 'com.github.slavce14:SJ-Dialog:1.5' + implementation 'com.github.slavce14:SJ-Dialog:1.6' } ``` [![](https://jitpack.io/v/slavce14/SJ-Dialog.svg)](https://jitpack.io/#slavce14/SJ-Dialog) diff --git a/SJDialog/ListDialogDoc.md b/SJDialog/ListDialogDoc.md index 88d4c7b..233a1c7 100644 --- a/SJDialog/ListDialogDoc.md +++ b/SJDialog/ListDialogDoc.md @@ -377,7 +377,7 @@ int ItemBgResSelected = listDialog.getListItemBgResSelected(); //set RecyclerView Adapter listDialog.setAdapter(recyclerViewAdapter); //Set Layout Manager -listDialog.setLayoutManager +listDialog.setLayoutManager(layoutManager); //Add items in a list listDialog.setItems(strings); @@ -393,6 +393,11 @@ listDialog.setItems(arrayList, listItemValues, listItemClickObj); listDialog.setImageItems(listItems); listDialog.setImageItems(listItems, listItemClickObj); +//Hide 'List is empty' text +listDialog.hideEmptyListText(); +//Change empty list text +listDialog.setEmptyListText("text"); + //Set maximum dialog width. Default is 600dp listDialog.setMaxDialogWidth(width); diff --git a/SJDialog/build.gradle b/SJDialog/build.gradle index 3438fef..b9da45f 100644 --- a/SJDialog/build.gradle +++ b/SJDialog/build.gradle @@ -8,7 +8,7 @@ android { defaultConfig { minSdk 23 versionCode 20 - versionName "1.6 (dev 5.1)" + versionName "1.6" buildConfigField 'int', 'VERSION_CODE', "${versionCode}" buildConfigField 'String', 'VERSION_NAME', "\"${versionName}\"" @@ -36,4 +36,4 @@ dependencies { testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' -} \ No newline at end of file +} diff --git a/SJDialog/src/main/java/com/sjapps/library/customdialog/ListDialog.java b/SJDialog/src/main/java/com/sjapps/library/customdialog/ListDialog.java index 17415eb..0be8d42 100644 --- a/SJDialog/src/main/java/com/sjapps/library/customdialog/ListDialog.java +++ b/SJDialog/src/main/java/com/sjapps/library/customdialog/ListDialog.java @@ -33,6 +33,8 @@ public class ListDialog extends SJDialog { private @DrawableRes int listItemBgRes = R.drawable.ripple_list; private @DrawableRes int listItemBgResSelected = R.drawable.ripple_list_selected; + private @ColorInt int listItemBgColor = -1; + private @ColorInt int listItemBgColorSelected = -1; private int listItemTextColor = 1; private RecyclerView.LayoutManager layoutManager = null; @@ -420,6 +422,30 @@ public ListDialog setListItemSelectedBackgroundResource(@DrawableRes int drawabl return this; } + /** + * Set background color for a item in a list + * + * @param color {@link ColorInt} + * @return current class + * @since 1.6 + */ + public ListDialog setListItemBackgroundColor(@ColorInt int color) { + listItemBgColor = color; + return this; + } + + /** + * Set background color for a selected item in a list + * + * @param color {@link ColorInt} + * @return current class + * @since 1.6 + */ + public ListDialog setListItemSelectedBackgroundColor(@ColorInt int color) { + listItemBgColorSelected = color; + return this; + } + /** * Set text color for item in a list * @@ -536,7 +562,9 @@ public ListDialog setItems(String[] listOfItems, @Nullable ListItemClick itemCli (ArrayList) selectedItems, listItemBgRes, listItemBgResSelected, - listItemTextColor); + listItemTextColor, + listItemBgColor, + listItemBgColorSelected); hasAdapter = true; return this; } @@ -625,7 +653,9 @@ public ListDialog setItems(T[] objArray, ListItemValue value, @Nullable L (ArrayList) selectedItems, listItemBgRes, listItemBgResSelected, - listItemTextColor); + listItemTextColor, + listItemBgColor, + listItemBgColorSelected); hasAdapter = true; return this; } @@ -658,7 +688,9 @@ public ListDialog setItems(T[] objArray, ListItemValues values, @Nullable (ArrayList) selectedItems, listItemBgRes, listItemBgResSelected, - listItemTextColor); + listItemTextColor, + listItemBgColor, + listItemBgColorSelected); hasAdapter = true; return this; @@ -692,7 +724,9 @@ public ListDialog setItems(ArrayList arrayList, ListItemValue value, @ (ArrayList) selectedItems, listItemBgRes, listItemBgResSelected, - listItemTextColor); + listItemTextColor, + listItemBgColor, + listItemBgColorSelected); hasAdapter = true; return this; } @@ -725,7 +759,9 @@ public ListDialog setItems(ArrayList arrayList, ListItemValues values, (ArrayList) selectedItems, listItemBgRes, listItemBgResSelected, - listItemTextColor); + listItemTextColor, + listItemBgColor, + listItemBgColorSelected); hasAdapter = true; return this; } @@ -763,7 +799,9 @@ public ListDialog setImageItems(ArrayList arrayList, @Nullable Li (ArrayList) selectedItems, listItemBgRes, listItemBgResSelected, - listItemTextColor); + listItemTextColor, + listItemBgColor, + listItemBgColorSelected); hasAdapter = true; waitForLayoutManager = true; diff --git a/SJDialog/src/main/java/com/sjapps/library/customdialog/adapter/DefaultImageListAdapter.java b/SJDialog/src/main/java/com/sjapps/library/customdialog/adapter/DefaultImageListAdapter.java index 60c3e9f..0456f1a 100644 --- a/SJDialog/src/main/java/com/sjapps/library/customdialog/adapter/DefaultImageListAdapter.java +++ b/SJDialog/src/main/java/com/sjapps/library/customdialog/adapter/DefaultImageListAdapter.java @@ -24,6 +24,8 @@ public class DefaultImageListAdapter extends RecyclerView.Adapter itemClick; @@ -60,7 +62,9 @@ public DefaultImageListAdapter(ArrayList arrayList, ArrayList selectedItems, int itemBgRes, int itemBgResSelected, - int textColor) { + int textColor, + int listItemBgColor, + int listItemBgColorSelected) { this.itemClick = itemClick; this.isSelectable = isSelectable; this.selectedItems = selectedItems; @@ -68,6 +72,8 @@ public DefaultImageListAdapter(ArrayList arrayList, this.itemBgResSelected = itemBgResSelected; this.textColor = textColor; this.arrayListItems = arrayList; + this.listItemBgColor = listItemBgColor; + this.listItemBgColorSelected = listItemBgColorSelected; } @@ -101,14 +107,18 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) { private void setBackground(@NonNull ViewHolder holder, int position) { if (!isSelectable) { - setItemColor(holder, itemBgRes); + setItemResource(holder, itemBgRes); return; } - if (selectedItems.contains(arrayListItems.get(position))) - setItemColor(holder, itemBgResSelected); - else setItemColor(holder, itemBgRes); - + if (selectedItems.contains(arrayListItems.get(position))) { + setItemResource(holder, itemBgResSelected); + setItemColor(holder,listItemBgColorSelected); + } + else { + setItemResource(holder, itemBgRes); + setItemColor(holder,listItemBgColor); + } } private void setValues(@NonNull ViewHolder holder, int position) { @@ -125,20 +135,26 @@ private void checkSelected(@NonNull ViewHolder holder,ImageListItem obj) { private void selectItem(@NonNull ViewHolder holder,ImageListItem obj) { selectedItems.add(obj); - setItemColor(holder, itemBgResSelected); - + setItemResource(holder, itemBgResSelected); + setItemColor(holder,listItemBgColorSelected); } private void deselectItem(@NonNull ViewHolder holder,ImageListItem obj) { selectedItems.remove(obj); - setItemColor(holder, itemBgRes); - + setItemResource(holder, itemBgRes); + setItemColor(holder,listItemBgColor); } - private void setItemColor(@NonNull ViewHolder holder, int drawable) { + private void setItemResource(@NonNull ViewHolder holder, int drawable) { holder.getView().setBackgroundResource(drawable); } + private void setItemColor(@NonNull ViewHolder holder, int color){ + if (color == -1) + return; + holder.getView().getBackground().mutate().setTint(color); + } + @Override public int getItemCount() { return arrayListItems.size(); diff --git a/SJDialog/src/main/java/com/sjapps/library/customdialog/adapter/DefaultListAdapter.java b/SJDialog/src/main/java/com/sjapps/library/customdialog/adapter/DefaultListAdapter.java index c5c7321..c0526b6 100644 --- a/SJDialog/src/main/java/com/sjapps/library/customdialog/adapter/DefaultListAdapter.java +++ b/SJDialog/src/main/java/com/sjapps/library/customdialog/adapter/DefaultListAdapter.java @@ -20,6 +20,8 @@ public class DefaultListAdapter extends RecyclerView.Adapter selectedItems; int itemBgRes; int itemBgResSelected; + int listItemBgColor; + int listItemBgColorSelected; int textColor; @@ -29,7 +31,9 @@ public DefaultListAdapter(String[] items, ArrayList selectedItems, int itemBgRes, int itemBgResSelected, - int textColor) { + int textColor, + int listItemBgColor, + int listItemBgColorSelected) { this.items = items; this.isSelectable = isSelectable; this.itemClick = itemClick; @@ -37,7 +41,8 @@ public DefaultListAdapter(String[] items, this.itemBgRes = itemBgRes; this.itemBgResSelected = itemBgResSelected; this.textColor = textColor; - + this.listItemBgColor = listItemBgColor; + this.listItemBgColorSelected = listItemBgColorSelected; } @@ -52,10 +57,14 @@ public DefaultListAdapterGeneric.ViewHolder onCreateViewHolder(@NonNull ViewGrou public void onBindViewHolder(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int position) { holder.getVal1Txt().setText(items[position]); - if (selectedItems.contains(items[position])) - setItemColor(holder,itemBgResSelected); - else setItemColor(holder,itemBgRes); - + if (selectedItems.contains(items[position])) { + setItemResource(holder, itemBgResSelected); + setItemColor(holder,listItemBgColorSelected); + } + else { + setItemResource(holder, itemBgRes); + setItemColor(holder,listItemBgColor); + } if (textColor != 1) holder.getVal1Txt().setTextColor(textColor); @@ -74,19 +83,27 @@ public void onBindViewHolder(@NonNull DefaultListAdapterGeneric.ViewHolder holde private void selectItem(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int position){ selectedItems.add(items[position]); - setItemColor(holder,itemBgResSelected); + setItemResource(holder,itemBgResSelected); + setItemColor(holder,listItemBgColorSelected); } private void deselectItem(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int position){ selectedItems.remove(items[position]); - setItemColor(holder,itemBgRes); + setItemResource(holder,itemBgRes); + setItemColor(holder,listItemBgColor); } - private void setItemColor(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int drawable){ + private void setItemResource(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int drawable){ holder.getView().setBackgroundResource(drawable); } + private void setItemColor(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int color){ + if (color == -1) + return; + holder.getView().getBackground().mutate().setTint(color); + } + @Override public int getItemCount() { return items.length; diff --git a/SJDialog/src/main/java/com/sjapps/library/customdialog/adapter/DefaultListAdapterGeneric.java b/SJDialog/src/main/java/com/sjapps/library/customdialog/adapter/DefaultListAdapterGeneric.java index 7f714fb..fd9c9da 100644 --- a/SJDialog/src/main/java/com/sjapps/library/customdialog/adapter/DefaultListAdapterGeneric.java +++ b/SJDialog/src/main/java/com/sjapps/library/customdialog/adapter/DefaultListAdapterGeneric.java @@ -31,6 +31,8 @@ public class DefaultListAdapterGeneric extends RecyclerView.Adapter itemClick; @@ -68,7 +70,9 @@ public DefaultListAdapterGeneric(T[] objArray, ArrayList selectedItems, int itemBgRes, int itemBgResSelected, - int textColor){ + int textColor, + int listItemBgColor, + int listItemBgColorSelected){ this.value = value; this.itemClick = itemClick; this.isSelectable = isSelectable; @@ -76,6 +80,8 @@ public DefaultListAdapterGeneric(T[] objArray, this.itemBgRes = itemBgRes; this.itemBgResSelected = itemBgResSelected; this.textColor = textColor; + this.listItemBgColor = listItemBgColor; + this.listItemBgColorSelected = listItemBgColorSelected; ObjArrayAdapter(objArray); } @@ -86,7 +92,9 @@ public DefaultListAdapterGeneric(T[] objArray, ArrayList selectedItems, int itemBgRes, int itemBgResSelected, - int textColor){ + int textColor, + int listItemBgColor, + int listItemBgColorSelected){ this.values = values; this.itemClick = itemClick; hasTwoVal = true; @@ -95,6 +103,8 @@ public DefaultListAdapterGeneric(T[] objArray, this.itemBgRes = itemBgRes; this.itemBgResSelected = itemBgResSelected; this.textColor = textColor; + this.listItemBgColor = listItemBgColor; + this.listItemBgColorSelected = listItemBgColorSelected; ObjArrayAdapter(objArray); } @@ -105,7 +115,9 @@ public DefaultListAdapterGeneric(ArrayList arrayList, ArrayList selectedItems, int itemBgRes, int itemBgResSelected, - int textColor){ + int textColor, + int listItemBgColor, + int listItemBgColorSelected){ this.value = value; this.itemClick = itemClick; this.isSelectable = isSelectable; @@ -113,6 +125,8 @@ public DefaultListAdapterGeneric(ArrayList arrayList, this.itemBgRes = itemBgRes; this.itemBgResSelected = itemBgResSelected; this.textColor = textColor; + this.listItemBgColor = listItemBgColor; + this.listItemBgColorSelected = listItemBgColorSelected; ArrayListAdapter(arrayList); } @@ -123,7 +137,9 @@ public DefaultListAdapterGeneric(ArrayList arrayList, ArrayList selectedItems, int itemBgRes, int itemBgResSelected, - int textColor){ + int textColor, + int listItemBgColor, + int listItemBgColorSelected){ this.values = values; this.itemClick = itemClick; hasTwoVal = true; @@ -132,6 +148,8 @@ public DefaultListAdapterGeneric(ArrayList arrayList, this.itemBgRes = itemBgRes; this.itemBgResSelected = itemBgResSelected; this.textColor = textColor; + this.listItemBgColor = listItemBgColor; + this.listItemBgColorSelected = listItemBgColorSelected; ArrayListAdapter(arrayList); } @@ -184,19 +202,29 @@ else if (isObjArr) private void setBackground(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int position) { if (!isSelectable) { - setItemColor(holder,itemBgRes); + setItemResource(holder,itemBgRes); return; } if (isArrList) { - if (selectedItems.contains(arrayListItems.get(position))) - setItemColor(holder, itemBgResSelected); - else setItemColor(holder, itemBgRes); + if (selectedItems.contains(arrayListItems.get(position))) { + setItemResource(holder, itemBgResSelected); + setItemColor(holder,listItemBgColorSelected); + } + else { + setItemResource(holder, itemBgRes); + setItemColor(holder,listItemBgColor); + } return; } if (isObjArr) - if (selectedItems.contains(listObj[position])) - setItemColor(holder,itemBgResSelected); - else setItemColor(holder, itemBgRes); + if (selectedItems.contains(listObj[position])) { + setItemResource(holder, itemBgResSelected); + setItemColor(holder,listItemBgColorSelected); + } + else { + setItemResource(holder, itemBgRes); + setItemColor(holder,listItemBgColor); + } } private void setValues(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int position){ @@ -229,20 +257,28 @@ private void checkSelected(@NonNull DefaultListAdapterGeneric.ViewHolder holder, private void selectItem(@NonNull DefaultListAdapterGeneric.ViewHolder holder, T obj){ selectedItems.add(obj); - setItemColor(holder, itemBgResSelected); + setItemResource(holder, itemBgResSelected); + setItemColor(holder,listItemBgColorSelected); } private void deselectItem(@NonNull DefaultListAdapterGeneric.ViewHolder holder, T obj){ selectedItems.remove(obj); - setItemColor(holder,itemBgRes); + setItemResource(holder,itemBgRes); + setItemColor(holder,listItemBgColor); } - private void setItemColor(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int drawable){ + private void setItemResource(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int drawable){ holder.getView().setBackgroundResource(drawable); } + private void setItemColor(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int color){ + if (color == -1) + return; + holder.getView().getBackground().mutate().setTint(color); + } + @Override public int getItemCount() { if (isArrList)