Skip to content

Latest commit

 

History

History
498 lines (451 loc) · 15.2 KB

ListDialogDoc.md

File metadata and controls

498 lines (451 loc) · 15.2 KB

ListDialog Documentation

Examples

List of String array

String[] strings = {"item1","item2","item3"};

ListDialog listDialog = new ListDialog();
listDialog.Builder(this)
	.setItems(strings,(position, value) -> {
       		// Do something
       	})
       	.show();

ListDialog example 1

List of Objects

class ExampleObject{
    	String value;

    	public ExampleObject(String value) {
        	this.value = value;
    	}
}
ExampleObject[] objects = {new ExampleObject("object1"),new ExampleObject("object2"),new ExampleObject("object3")};

ListDialog listDialog = new ListDialog();
listDialog.Builder(this)
	.setItems(
       		objects,
                obj -> obj.value, // get value from object
                (position, value) -> {
                	// Do something
                })
       	.show();

ListDialog example 2

ArrayList of Objects with two values

class ExampleObject{
    	String value1;
    	String value2;
    
	public ExampleObject(String value1, String value2) {
        	this.value1 = value1;
        	this.value2 = value2;
    	}
}
ArrayList<ExampleObject> arrayList = new ArrayList<>();
arrayList.add(new ExampleObject("object1","value1"));
arrayList.add(new ExampleObject("object2","value2"));
arrayList.add(new ExampleObject("object3","value3"));

ListDialog listDialog = new ListDialog();
listDialog.Builder(this)
	.setItems(
   		arrayList,
                new ListItemValues<ExampleObject>() {
              		@Override
                       	public String getValue1(ExampleObject obj) {
                       		return obj.value1;
                      	}

                      	@Override
                      	public String getValue2(ExampleObject obj) {
                             	return obj.value2;
                       	}
               	},
      	  	(position, value) -> {
                    // Do something
                })
   	.show();

ListDialog example 3

Selecting multiple items in a list

ArrayList<String> stringArrayList = new ArrayList<>();
stringArrayList.add("item1");
stringArrayList.add("item2");
stringArrayList.add("item3");

ListDialog listDialog = new ListDialog();
listDialog.Builder(this)
	.dialogWithTwoButtons()
        .setSelectableList()
       	.setItems(stringArrayList,obj -> obj)
       	.onButtonClick(() -> {
        	ArrayList<ExampleObject> selectedItems = listDialog.getSelectedItems();
               		// Do something
              	})
	.show();

ListDialog example 4

Builder

Apply the default theme to a dialog

listDialog.Builder(context)

ListDialog day-night Apply the app theme to a dialog (only works with material3 theme)

listDialog.Builder(context,true)

ListDialog day-night theme

Apply the custom theme to a dialog (only works with material3 theme)

listDialog.Builder(context,theme)

Dialog with two buttons

listDialog.dialogWithTwoButtons();

Old Dialog theme

By default dialog colors will be set to material3 dynamic colors. With this method you can set the dialog color for the background and buttons to the older non-dynamic colors

listDialog.setOldTheme();

ListDialog oldTheme

DialogPreset

With DialogPreset, you can create customized dialogs with consistent customizations. Simply create a DialogPreset and implement it across all dialogs that you want to have that customizations.

Creating a DialogPreset

DialogPreset<ListDialog> preset = dialog -> {
    // add customization here  
};

Example

DialogPreset<ListDialog> preset = dialog -> {
    dialog.dialogWithTwoButtons()
        .setDialogBackgroundResource(background)
        .setTextColor(textColor)
        .setButtonsColor(btnColor);
};

Apply presets to a dialog

listDialog.setPresets(preset);

It's recommended to apply the presets first before modifying any other properties. If you want to use Dialog with two buttons and is not specified in the preset, add that before applying the presets

Example

listDialog.Builder(context,true)
    .dialogWithTwoButtons()
    .setPresets(preset)
    .setTitle("Title")
    .setMessage("Message")
    ...

Select multiple items in a list

listDialog.setSelectableList();

Add items in a list

You can add item in a list by setting RecyclerView Adapter, using setItems() method or using setImageItems() method for list with icons.

Set RecyclerView Adapter

listDialog.setAdapter(recyclerViewAdapter);

setItems

This method uses DefaultListAdapter if the argument is array of Strings and DefaultListAdapterGeneric for array of Objects or ArrayList.

Array of Strings

You need to use setSelectableList() firstly or add onListItemClick

listDialog.setItems(strings);

Array of Strings and onListItemClick

listDialog.setItems(strings,(position, value) -> {
	// Do something
});

Array of Objects

You need to use setSelectableList() firstly or add onListItemClick

listDialog.setItems(objects, new ListItemValue<ExampleObject>() {
	@Override
     	public String getValue(ExampleObject obj) {
  		return obj.value; // get value of an Object
     	}
});

//or

listDialog.setItems(objects,obj -> obj.value);

Array of Objects and onListItemClick

listDialog.setItems(objects,obj -> obj.value,(position, obj) -> {
            // Do something
});

Array of Objects with two values

You need to use setSelectableList() firstly or add onListItemClick

listDialog.setItems(objects, new ListItemValues<ExampleObject>() {
	@Override
	public String getValue1(ExampleObject obj) {
      		return obj.value1;
      	}

      	@Override
     	public String getValue2(ExampleObject obj) {
       		return obj.value2;
      	}
});

Array of Objects with two values and onListItemClick

listDialog.setItems(objects, new ListItemValues<ExampleObject>() {
		@Override
   		public String getValue1(ExampleObject obj) {
       		return obj.value1;
       		}

     		@Override
   		public String getValue2(ExampleObject obj) {
       			return obj.value2;
     		}
	},(position, obj) -> {
            	// Do something
});

ArrayList

You need to use setSelectableList() firstly or add onListItemClick

listDialog.setItems(arrayList,obj -> obj.value);

ArrayList and onListItemClick

listDialog.setItems(arrayList,obj -> obj.value,(position, obj) -> {
 	// Do something
});

ArrayList with two values

You need to use setSelectableList() firstly or add onListItemClick

listDialog.setItems(arrayList, new ListItemValues<ExampleObject>() {
	@Override
     	public String getValue1(ExampleObject obj) {
       		return obj.value1;
      	}

       	@Override
     	public String getValue2(ExampleObject obj) {
           	return obj.value2;
     	}
});

ArrayList with two values and onListItemClick

listDialog.setItems(arrayList, new ListItemValues<ExampleObject>() {
            @Override
            public String getValue1(ExampleObject obj) {
                return obj.value1;
            }

            @Override
            public String getValue2(ExampleObject obj) {
                return obj.value2;
            }
        },(position, obj) -> {
            // Do something
});

setImageItems

Creating ArrayList of ImageListItem

ArrayList<ImageListItem> listItems = new ArrayList<>();
listItems.add(new ImageListItem("item1", drawable1));
// or adding data of type Object
listItems.add(new ImageListItem("item2", drawable2,data));

ArrayList of ImageListItem

You need to use setSelectableList() firstly or add onListItemClick

listDialog.setImageItems(listItems);

ArrayList of ImageListItem and onListItemClick

listDialog.setImageItems(listItems, (position, obj) -> {
 	// Do something
});

Set RecyclerView LayoutManager

listDialog.setLayoutManager(layoutManager);

Add onClick Listener

onClickListener for the right button if the dialog has two buttons, the left button is for dismissing dialog. If the dialog has only one button, onClickListener will be set to that button.

listDialog.onButtonClick(new DialogButtonEvent() {
	@Override
      	public void onButtonClick() {
      		// Do something
      	}
});

//or

listDialog.onButtonClick(() -> {
	// Do something
});

onClickListener for left and right button (only works when dialog has two buttons)

listDialog.onButtonClick(new DialogButtonEvents() {
	@Override
       	public void onLeftButtonClick() {
       		// Do something
       	}
     	@Override
      	public void onRightButtonClick() {
       		// Do something
      	}
});

Add onShowListener

listDialog.onShowListener(dialogInterface -> {
    // Do something
});

Add onDismissListener

listDialog.onDismissListener(dialogInterface -> {
    // Do something
});

Apply Insets

supported values: INSETS_LEFT, INSETS_RIGHT, INSETS_BOTTOM, INSETS_HORIZONTAL, INSETS_ALL or INSETS_NONE.

listDialog.applyInsets(INSETS_HORIZONTAL);

You can combine multiple values with bitwise-OR ( | ) operator

listDialog.applyInsets(INSETS_LEFT | INSETS_RIGHT);

All ListDialog Methods

//Create dialog
listDialog.Builder(context);

//Create dialog width two buttons
listDialog.dialogWithTwoButtons();

//Usin the old dialog theme
listDialog.setOldTheme();

//Set title
listDialog.setTitle("Title");

//Set message
listDialog.setMessage("Message");

//Set title text alignment
listDialog.setTitleAlignment(TextAlignment);
//Set message text alignment
listDialog.setMessageAlignment(TextAlignment);

//Set text color
listDialog.setTextColor(color);
//Set title text color
listDialog.setTitleTextColor(color);
//Set message text color
listDialog.setMessageTextColor(color);

//Set button text (one button dialog)
listDialog.setButtonText("Text");
//Set left button text
listDialog.setLeftButtonText("Text");
//Set right button text
listDialog.setRightButtonText("Text");

//Set buttons color
listDialog.setButtonsColor(color);
//Set button color (one button dialog)
listDialog.setButtonColor(color);
//Set left button color
listDialog.setLeftButtonColor(color);
//Set right button color
listDialog.setRightButtonColor(color);

//Set buttons text color
listDialog.setButtonsTextColor(color);
//Set text color a button (one button dialog)
listDialog.setButtonTextColor(color);
//Set text color for left button
listDialog.setLeftButtonTextColor(color);
//Set text color for right button
listDialog.setRightButtonTextColor(color);

//Set buttons background resource
listDialog.setButtonsBackgroundResource(drawable);
//Set button background resource (one button dialog)
listDialog.setButtonBackgroundResource(drawable);
//Set left button background resource
listDialog.setLeftButtonBackgroundResource(drawable);
//Set right button background resource
listDialog.setRightButtonBackgroundResource(drawable);

//Set dialog color
listDialog.setDialogBackgroundColor(color);
//Set dialog background resource
listDialog.setDialogBackgroundResource(drawable);

//Selecting multiple items in a list
listDialog.setSelectableList();

//Set text color of an items in a list
listDialog.setListItemTextColor(color);
//Set a background color for items in a list
listDialog.setListItemBackgroundColor(color);
//Set a background color for selected items in a list
listDialog.setListItemSelectedBackgroundColor(color);
//Set a background resource for items in a list
listDialog.setListItemBackgroundResource(drawable);
//Set a background resource for selected items in a list
listDialog.setListItemSelectedBackgroundResource(drawable);
//Set a background resource of a list
listDialog.setListBackgroundResource(drawable);

//Get list item background resource
int ItemBgRes = listDialog.getListItemBgRes();
//Get list item selected background resource
int ItemBgResSelected = listDialog.getListItemBgResSelected();

//set RecyclerView Adapter
listDialog.setAdapter(recyclerViewAdapter);
//Set Layout Manager
listDialog.setLayoutManager(layoutManager);

//Add items in a list
listDialog.setItems(strings);
listDialog.setItems(strings, listItemClick);
listDialog.setItems(objects, listItemValue);
listDialog.setItems(objects, listItemValue, listItemClickObj);
listDialog.setItems(objects, listItemValues);
listDialog.setItems(objects, listItemValues, listItemClickObj);
listDialog.setItems(arrayList, listItemValue);
listDialog.setItems(arrayList, listItemValue, listItemClickObj);
listDialog.setItems(arrayList, listItemValues);
listDialog.setItems(arrayList, listItemValues, listItemClickObj);
listDialog.setImageItems(listItems);
listDialog.setImageItems(listItems, listItemClickObj);

//Select item in a list
listDialog.selectItem(id);
//Get select item in a list
int id = listDialog.getSelectedItem();

//Update list
listDialog.updateList();

//Hide 'List is empty' text 
listDialog.hideEmptyListText();
//Change empty list text
listDialog.setEmptyListText("text");

//Set maximum dialog width. Default is 600dp
listDialog.setMaxDialogWidth(width);
        
//Get maximum dialog width
int dialogWidth = listDialog.getMaxDialogWidth();
        
//Get left button
Button leftButton = listDialog.getLeftButton();

//Get right button
Button rightButton = listDialog.getRightButton();

//Set dialog animations
listDialog.setDialogAnimations(styleRes);

//Enable or disable swipe down to dismiss dialog. 
//By default is set to true
dialog.swipeToDismiss(boolean);

//Set dialog onTouchListener.
//This method will overide swipe down to dismiss action
dialog.setOnTouchListener(onTouchListener);

//Apply insets (INSETS_LEFT, INSETS_RIGHT, INSETS_BOTTOM, INSETS_HORIZONTAL, INSETS_ALL or INSETS_NONE)
listDialog.applyInsets(insets);

//Shew dialog
listDialog.show();
//Dismiss dialog
listDialog.dismiss();