Skip to content

Commit

Permalink
Merge pull request #63 from SlaVcE14/master
Browse files Browse the repository at this point in the history
update dev
  • Loading branch information
SlaVcE14 authored May 6, 2023
2 parents ccad743 + 85f9a4d commit 924f06d
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion SJDialog/ListDialogDoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions SJDialog/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}\""
Expand Down Expand Up @@ -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'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -536,7 +562,9 @@ public ListDialog setItems(String[] listOfItems, @Nullable ListItemClick itemCli
(ArrayList<String>) selectedItems,
listItemBgRes,
listItemBgResSelected,
listItemTextColor);
listItemTextColor,
listItemBgColor,
listItemBgColorSelected);
hasAdapter = true;
return this;
}
Expand Down Expand Up @@ -625,7 +653,9 @@ public <T> ListDialog setItems(T[] objArray, ListItemValue<T> value, @Nullable L
(ArrayList<T>) selectedItems,
listItemBgRes,
listItemBgResSelected,
listItemTextColor);
listItemTextColor,
listItemBgColor,
listItemBgColorSelected);
hasAdapter = true;
return this;
}
Expand Down Expand Up @@ -658,7 +688,9 @@ public <T> ListDialog setItems(T[] objArray, ListItemValues<T> values, @Nullable
(ArrayList<T>) selectedItems,
listItemBgRes,
listItemBgResSelected,
listItemTextColor);
listItemTextColor,
listItemBgColor,
listItemBgColorSelected);
hasAdapter = true;
return this;

Expand Down Expand Up @@ -692,7 +724,9 @@ public <T> ListDialog setItems(ArrayList<T> arrayList, ListItemValue<T> value, @
(ArrayList<T>) selectedItems,
listItemBgRes,
listItemBgResSelected,
listItemTextColor);
listItemTextColor,
listItemBgColor,
listItemBgColorSelected);
hasAdapter = true;
return this;
}
Expand Down Expand Up @@ -725,7 +759,9 @@ public <T> ListDialog setItems(ArrayList<T> arrayList, ListItemValues<T> values,
(ArrayList<T>) selectedItems,
listItemBgRes,
listItemBgResSelected,
listItemTextColor);
listItemTextColor,
listItemBgColor,
listItemBgColorSelected);
hasAdapter = true;
return this;
}
Expand Down Expand Up @@ -763,7 +799,9 @@ public ListDialog setImageItems(ArrayList<ImageListItem> arrayList, @Nullable Li
(ArrayList<ImageListItem>) selectedItems,
listItemBgRes,
listItemBgResSelected,
listItemTextColor);
listItemTextColor,
listItemBgColor,
listItemBgColorSelected);

hasAdapter = true;
waitForLayoutManager = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class DefaultImageListAdapter extends RecyclerView.Adapter<DefaultImageLi

int itemBgRes;
int itemBgResSelected;
int listItemBgColor;
int listItemBgColorSelected;
int textColor;

ListItemClickObj<ImageListItem> itemClick;
Expand Down Expand Up @@ -60,14 +62,18 @@ public DefaultImageListAdapter(ArrayList<ImageListItem> arrayList,
ArrayList<ImageListItem> selectedItems,
int itemBgRes,
int itemBgResSelected,
int textColor) {
int textColor,
int listItemBgColor,
int listItemBgColorSelected) {
this.itemClick = itemClick;
this.isSelectable = isSelectable;
this.selectedItems = selectedItems;
this.itemBgRes = itemBgRes;
this.itemBgResSelected = itemBgResSelected;
this.textColor = textColor;
this.arrayListItems = arrayList;
this.listItemBgColor = listItemBgColor;
this.listItemBgColorSelected = listItemBgColorSelected;
}


Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class DefaultListAdapter extends RecyclerView.Adapter<DefaultListAdapterG
ArrayList<String> selectedItems;
int itemBgRes;
int itemBgResSelected;
int listItemBgColor;
int listItemBgColorSelected;
int textColor;


Expand All @@ -29,15 +31,18 @@ public DefaultListAdapter(String[] items,
ArrayList<String> selectedItems,
int itemBgRes,
int itemBgResSelected,
int textColor) {
int textColor,
int listItemBgColor,
int listItemBgColorSelected) {
this.items = items;
this.isSelectable = isSelectable;
this.itemClick = itemClick;
this.selectedItems = selectedItems;
this.itemBgRes = itemBgRes;
this.itemBgResSelected = itemBgResSelected;
this.textColor = textColor;

this.listItemBgColor = listItemBgColor;
this.listItemBgColorSelected = listItemBgColorSelected;

}

Expand All @@ -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);

Expand All @@ -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;
Expand Down
Loading

0 comments on commit 924f06d

Please sign in to comment.