mirror of
https://github.com/Nezumi-2711/Foodify-Shipper.git
synced 2026-09-22 20:00:51 +00:00
Improve UI, fix bugs.
This commit is contained in:
@@ -0,0 +1,437 @@
|
||||
package com.sjapps.library.customdialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.StyleRes;
|
||||
|
||||
import com.sjapps.library.R;
|
||||
/**@since 1.6*/
|
||||
@SuppressWarnings("unused")
|
||||
public class BasicDialog extends SJDialog{
|
||||
@Deprecated
|
||||
public static final String LONG_TYPE = "long";
|
||||
@Deprecated
|
||||
public static final String SHORT_TYPE = "short";
|
||||
|
||||
private boolean isDeleteDialog;
|
||||
|
||||
public BasicDialog(){
|
||||
twoButtons = true;
|
||||
}
|
||||
/** @since 1.4*/
|
||||
public BasicDialog Short(Context context, String Title){
|
||||
return Short(context,Title,null);
|
||||
}
|
||||
/** @since 1.0*/
|
||||
public BasicDialog Short(Context context, String Title, String Btn1Txt, String Btn2Txt){
|
||||
return Builder(context,Title,null,Btn1Txt,Btn2Txt);
|
||||
}
|
||||
/** @since 1.0*/
|
||||
public BasicDialog Short(Context context, String Title, String Btn2Txt){
|
||||
return Short(context,Title,null,Btn2Txt);
|
||||
}
|
||||
/** @since 1.4*/
|
||||
public BasicDialog Long(Context context, String Title, String Message){
|
||||
return Long(context,Title,Message,null);
|
||||
}
|
||||
/** @since 1.0*/
|
||||
public BasicDialog Long(Context context, String Title, String Text, String Btn1Txt, String Btn2Txt){
|
||||
return Builder(context,Title,Text,Btn1Txt,Btn2Txt);
|
||||
}
|
||||
/** @since 1.0*/
|
||||
public BasicDialog Long(Context context, String Title, String Text, String Btn2Txt){
|
||||
return Long(context,Title,Text,null,Btn2Txt);
|
||||
}
|
||||
/** @since 1.0*/
|
||||
public BasicDialog Delete(Context context, String Title){
|
||||
return Builder(context,Title,null,null,null).deleteAttributes();
|
||||
}
|
||||
/** @since 1.0*/
|
||||
public BasicDialog Delete(Context context){
|
||||
return Builder(context).deleteAttributes();
|
||||
}
|
||||
|
||||
public BasicDialog Delete(Context context, int theme){
|
||||
return Builder(context,theme).deleteAttributes();
|
||||
}
|
||||
|
||||
public BasicDialog Delete(Context context, boolean useAppTheme){
|
||||
return Builder(context,useAppTheme).deleteAttributes();
|
||||
}
|
||||
|
||||
private BasicDialog deleteAttributes(){
|
||||
isDeleteDialog = true;
|
||||
return setTitle("Delete?")
|
||||
.setRightButtonColor(MATERIAL3_RED_BUTTON)
|
||||
.setRightButtonText("Delete");
|
||||
}
|
||||
/**
|
||||
* @deprecated Use {@link BasicDialog#Builder(Context)}
|
||||
* */
|
||||
@Deprecated(since = "1.6")
|
||||
public BasicDialog DialogBuilder(Context context){
|
||||
return Builder(context);
|
||||
}
|
||||
/**
|
||||
* @deprecated Use {@link BasicDialog#Builder(Context, boolean)}
|
||||
* @since 1.6
|
||||
*/
|
||||
@Deprecated
|
||||
public BasicDialog DialogBuilder(Context context, boolean useAppTheme){
|
||||
return Builder(context, useAppTheme);
|
||||
}
|
||||
/**
|
||||
* @deprecated Use {@link BasicDialog#Builder(Context, int)}
|
||||
*/
|
||||
@Deprecated(since = "1.6")
|
||||
public BasicDialog DialogBuilder(Context context, int theme){
|
||||
return Builder(context,theme);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Dialog type is automatic. Use {@link BasicDialog#Builder(Context)}
|
||||
* @since 1.3
|
||||
*/
|
||||
@Deprecated(since = "1.4")
|
||||
public BasicDialog DialogBuilder(Context context, String dialogType){
|
||||
return Builder(context);
|
||||
}
|
||||
/**
|
||||
* @deprecated Use {@link BasicDialog#Builder(Context, String, String, String, String)}
|
||||
* @since 1.0
|
||||
*/
|
||||
@Deprecated(since = "1.6")
|
||||
public BasicDialog DialogBuilder(Context context, String Title, String Text, String Btn1Txt, String Btn2Txt){
|
||||
return Builder(context,Title,Text,Btn1Txt,Btn2Txt);
|
||||
}
|
||||
public BasicDialog Builder(Context context){
|
||||
super.Builder(context,R.layout.basic_dialog);
|
||||
return this;
|
||||
}
|
||||
public BasicDialog Builder(Context context, boolean useAppTheme){
|
||||
super.Builder(context,R.layout.basic_dialog,useAppTheme);
|
||||
return this;
|
||||
}
|
||||
public BasicDialog Builder(Context context,@StyleRes int theme){
|
||||
super.Builder(context,R.layout.basic_dialog,theme,false);
|
||||
return this;
|
||||
}
|
||||
public BasicDialog Builder(Context context, String Title, String Text, String Btn1Txt, String Btn2Txt){
|
||||
super.Builder(context,R.layout.basic_dialog);
|
||||
TextView TitleTv = dialog.findViewById(R.id.titleText);
|
||||
if (Btn1Txt == null) {
|
||||
button1.setOnClickListener(v -> dialog.dismiss());
|
||||
}else button1.setText(Btn1Txt);
|
||||
if (Btn2Txt != null) {
|
||||
button2.setText(Btn2Txt);
|
||||
}
|
||||
if (Text != null){
|
||||
setMessage(Text);
|
||||
}
|
||||
if (Title == null){
|
||||
return this;
|
||||
}
|
||||
TitleTv.setText(Title);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set a dialog type.
|
||||
* @param dialogType type of a dialog. Supported types: {@link #SHORT_TYPE} and {@link #LONG_TYPE}
|
||||
* @return current class
|
||||
* @deprecated Old method, not in use. Remove this.
|
||||
* @since 1.4
|
||||
* */
|
||||
@Deprecated
|
||||
public BasicDialog setDialogType(String dialogType){
|
||||
//Nothing here!!
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public BasicDialog setOldTheme(){
|
||||
super.setOldTheme();
|
||||
if (isDeleteDialog)
|
||||
super.setRightButtonColor(RED_BUTTON);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.3*/
|
||||
@Override
|
||||
public BasicDialog setTitle(String title){
|
||||
super.setTitle(title);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.3*/
|
||||
@Override
|
||||
public BasicDialog setMessage(String message){
|
||||
super.setMessage(message);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
* */
|
||||
@Override
|
||||
public BasicDialog setTitleAlignment(int textAlignment) {
|
||||
super.setTitleAlignment(textAlignment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
* */
|
||||
@Override
|
||||
public BasicDialog setMessageAlignment(int textAlignment) {
|
||||
super.setMessageAlignment(textAlignment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public BasicDialog setTextColor(int color) {
|
||||
super.setTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public BasicDialog setTitleTextColor(int color) {
|
||||
super.setTitleTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public BasicDialog setMessageTextColor(int color) {
|
||||
super.setMessageTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.4*/
|
||||
@Override
|
||||
public BasicDialog setLeftButtonText(String text){
|
||||
super.setLeftButtonText(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.4*/
|
||||
@Override
|
||||
public BasicDialog setRightButtonText(String text){
|
||||
super.setRightButtonText(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.4*/
|
||||
@Override
|
||||
public BasicDialog setButtonsTextColor(@ColorInt int color){
|
||||
super.setButtonsTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.4*/
|
||||
@Override
|
||||
public BasicDialog setLeftButtonTextColor(@ColorInt int color){
|
||||
super.setLeftButtonTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.4*/
|
||||
@Override
|
||||
public BasicDialog setRightButtonTextColor(@ColorInt int color){
|
||||
super.setRightButtonTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.4*/
|
||||
@Override
|
||||
public BasicDialog setButtonsColor(@ColorInt int color){
|
||||
super.setButtonsColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.4*/
|
||||
@Override
|
||||
public BasicDialog setLeftButtonColor(@ColorInt int color){
|
||||
super.setLeftButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.4*/
|
||||
@Override
|
||||
public BasicDialog setRightButtonColor(@ColorInt int color){
|
||||
super.setRightButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasicDialog setButtonsColor(@ButtonColor String color){
|
||||
super.setButtonsColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasicDialog setLeftButtonColor(@ButtonColor String color){
|
||||
super.setLeftButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasicDialog setRightButtonColor(@ButtonColor String color){
|
||||
super.setRightButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public BasicDialog setDialogBackgroundColor(int color) {
|
||||
super.setDialogBackgroundColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.3*/
|
||||
@Override
|
||||
public BasicDialog setDialogBackgroundResource(@DrawableRes int drawable){
|
||||
super.setDialogBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.3*/
|
||||
@Override
|
||||
public BasicDialog setButtonsBackgroundResource(@DrawableRes int drawable){
|
||||
super.setButtonsBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.3*/
|
||||
@Override
|
||||
public BasicDialog setLeftButtonBackgroundResource(@DrawableRes int drawable){
|
||||
super.setLeftButtonBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.3*/
|
||||
@Override
|
||||
public BasicDialog setRightButtonBackgroundResource(@DrawableRes int drawable){
|
||||
super.setRightButtonBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.0*/
|
||||
@Override
|
||||
public BasicDialog onButtonClick(DialogButtonEvent dialogButtonEvent){
|
||||
super.onButtonClick(dialogButtonEvent);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.0*/
|
||||
@Override
|
||||
public BasicDialog onButtonClick(DialogButtonEvents dialogButtonEvents) {
|
||||
super.onButtonClick(dialogButtonEvents);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.3*/
|
||||
@Override
|
||||
public BasicDialog show() {
|
||||
super.show();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int setButtonsRootLayoutID() {
|
||||
return R.id.buttons;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.4*/
|
||||
@Override
|
||||
public BasicDialog setMaxDialogWidth(int maxDialogWidth) {
|
||||
super.setMaxDialogWidth(maxDialogWidth);
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public BasicDialog setOnTouchListener(View.OnTouchListener onTouchListener) {
|
||||
super.setOnTouchListener(onTouchListener);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public BasicDialog swipeToDismiss(boolean isSwipeToDismiss) {
|
||||
super.swipeToDismiss(isSwipeToDismiss);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public BasicDialog setDialogAnimations(int styleRes) {
|
||||
super.setDialogAnimations(styleRes);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setButtons() {
|
||||
setButton1(R.id.btn1);
|
||||
setButton2(R.id.btn2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getLeftButton() {
|
||||
return super.getLeftButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getRightButton() {
|
||||
return super.getRightButton();
|
||||
}
|
||||
|
||||
/**@since 1.6*/
|
||||
@Override
|
||||
public TextView getTitleTextView() {
|
||||
return super.getTitleTextView();
|
||||
}
|
||||
|
||||
/**@since 1.6*/
|
||||
@Override
|
||||
public TextView getMessageTextView() {
|
||||
return super.getMessageTextView();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,393 @@
|
||||
package com.sjapps.library.customdialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.StyleRes;
|
||||
|
||||
import com.sjapps.library.R;
|
||||
/**@since 1.5*/
|
||||
@SuppressWarnings("unused")
|
||||
public class CustomViewDialog extends SJDialog{
|
||||
|
||||
private LinearLayout rootView;
|
||||
|
||||
public CustomViewDialog(){
|
||||
|
||||
}
|
||||
|
||||
public CustomViewDialog Builder(Context context){
|
||||
return Builder(context,false);
|
||||
}
|
||||
|
||||
public CustomViewDialog Builder(Context context,@StyleRes int theme){
|
||||
super.Builder(context,R.layout.custom_view_dialog,theme, false);
|
||||
rootView = dialog.findViewById(R.id.customViewRoot);
|
||||
onLeftButtonClick(dialog::dismiss);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CustomViewDialog Builder(Context context,boolean useAppTheme){
|
||||
super.Builder(context,R.layout.custom_view_dialog,useAppTheme);
|
||||
rootView = dialog.findViewById(R.id.customViewRoot);
|
||||
onLeftButtonClick(dialog::dismiss);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setOldTheme(){
|
||||
super.setOldTheme();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setTitle(String title){
|
||||
super.setTitle(title);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setMessage(String message) {
|
||||
super.setMessage(message);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
* */
|
||||
@Override
|
||||
public CustomViewDialog setTitleAlignment(int textAlignment) {
|
||||
super.setTitleAlignment(textAlignment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
* */
|
||||
@Override
|
||||
public CustomViewDialog setMessageAlignment(int textAlignment) {
|
||||
super.setMessageAlignment(textAlignment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setTextColor(int color) {
|
||||
super.setTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public CustomViewDialog setTitleTextColor(int color) {
|
||||
super.setTitleTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public CustomViewDialog setMessageTextColor(int color) {
|
||||
super.setMessageTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a button text.
|
||||
* @param text button text
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
* */
|
||||
public CustomViewDialog setButtonText(String text){
|
||||
return setLeftButtonText(text);
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setLeftButtonText(String text){
|
||||
super.setLeftButtonText(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setRightButtonText(String text){
|
||||
super.setRightButtonText(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set button text color.
|
||||
* @param color Color to use for tinting this drawable
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
* */
|
||||
public CustomViewDialog setButtonTextColor(@ColorInt int color){
|
||||
return setLeftButtonTextColor(color);
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setButtonsTextColor(@ColorInt int color){
|
||||
super.setButtonsTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setLeftButtonTextColor(@ColorInt int color){
|
||||
super.setLeftButtonTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setRightButtonTextColor(@ColorInt int color){
|
||||
super.setRightButtonTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set button color.
|
||||
* @param color Color to use for tinting this drawable
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
* */
|
||||
public CustomViewDialog setButtonColor(@ColorInt int color){
|
||||
return setLeftButtonColor(color);
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setButtonsColor(@ColorInt int color){
|
||||
super.setButtonsColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setLeftButtonColor(@ColorInt int color){
|
||||
super.setLeftButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setRightButtonColor(@ColorInt int color){
|
||||
super.setRightButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomViewDialog setButtonColor(@ButtonColor String color) {
|
||||
super.setButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomViewDialog setButtonsColor(@ButtonColor String color){
|
||||
super.setButtonsColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomViewDialog setLeftButtonColor(@ButtonColor String color){
|
||||
super.setLeftButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomViewDialog setRightButtonColor(@ButtonColor String color){
|
||||
super.setRightButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public CustomViewDialog setDialogBackgroundColor(int color) {
|
||||
super.setDialogBackgroundColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setDialogBackgroundResource(@DrawableRes int drawable){
|
||||
super.setDialogBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set background resource for button.
|
||||
* @param drawable resource id
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
* */
|
||||
public CustomViewDialog setButtonBackgroundResource(@DrawableRes int drawable){
|
||||
return setLeftButtonBackgroundResource(drawable);
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setButtonsBackgroundResource(@DrawableRes int drawable){
|
||||
super.setButtonsBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setLeftButtonBackgroundResource(@DrawableRes int drawable){
|
||||
super.setLeftButtonBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setRightButtonBackgroundResource(@DrawableRes int drawable){
|
||||
super.setRightButtonBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set onClick listener for a button
|
||||
*
|
||||
* @param dialogButtonEvent dialog button event
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
@Override
|
||||
public CustomViewDialog onButtonClick(DialogButtonEvent dialogButtonEvent){
|
||||
if (twoButtons)
|
||||
super.onButtonClick(dialogButtonEvent);
|
||||
else
|
||||
super.onLeftButtonClick(dialogButtonEvent);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog onButtonClick(DialogButtonEvents dialogButtonEvents) {
|
||||
super.onButtonClick(dialogButtonEvents);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog show() {
|
||||
super.show();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int setButtonsRootLayoutID() {
|
||||
return R.id.buttons;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setMaxDialogWidth(int maxDialogWidth) {
|
||||
super.setMaxDialogWidth(maxDialogWidth);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog setDialogAnimations(int styleRes) {
|
||||
super.setDialogAnimations(styleRes);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setButtons() {
|
||||
setButton1(R.id.btn1);
|
||||
setButton2(R.id.btn2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getLeftButton() {
|
||||
return super.getLeftButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getRightButton() {
|
||||
return super.getRightButton();
|
||||
}
|
||||
|
||||
/**@since 1.6*/
|
||||
@Override
|
||||
public TextView getTitleTextView() {
|
||||
return super.getTitleTextView();
|
||||
}
|
||||
|
||||
/**@since 1.6*/
|
||||
@Override
|
||||
public TextView getMessageTextView() {
|
||||
return super.getMessageTextView();
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public CustomViewDialog dialogWithTwoButtons() {
|
||||
super.dialogWithTwoButtons();
|
||||
setButton2Visibility(View.VISIBLE);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public CustomViewDialog setOnTouchListener(View.OnTouchListener onTouchListener) {
|
||||
super.setOnTouchListener(onTouchListener);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public CustomViewDialog swipeToDismiss(boolean isSwipeToDismiss) {
|
||||
super.swipeToDismiss(isSwipeToDismiss);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setButton2Visibility(int visibility) {
|
||||
super.setButton2Visibility(visibility);
|
||||
}
|
||||
|
||||
public CustomViewDialog addCustomView(View view){
|
||||
rootView.addView(view);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.sjapps.library.customdialog;
|
||||
|
||||
public interface DialogButtonEvent {
|
||||
void onButtonClick();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.sjapps.library.customdialog;
|
||||
|
||||
public interface DialogButtonEvents {
|
||||
void onLeftButtonClick();
|
||||
void onRightButtonClick();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.sjapps.library.customdialog;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
public class ImageListItem {
|
||||
|
||||
private String name;
|
||||
private Drawable image;
|
||||
private Object data;
|
||||
|
||||
public ImageListItem() {
|
||||
}
|
||||
|
||||
public ImageListItem(String name, Drawable image) {
|
||||
this.name = name;
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public ImageListItem(String name, Drawable image, Object data) {
|
||||
this.name = name;
|
||||
this.image = image;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Drawable getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(Drawable image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ImageListItem{" +
|
||||
"name='" + name + '\'' +
|
||||
", image=" + image +
|
||||
", data=" + data +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,931 @@
|
||||
package com.sjapps.library.customdialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StyleRes;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.sjapps.library.R;
|
||||
import com.sjapps.library.customdialog.adapter.DefaultImageListAdapter;
|
||||
import com.sjapps.library.customdialog.adapter.DefaultListAdapter;
|
||||
import com.sjapps.library.customdialog.adapter.DefaultListAdapterGeneric;
|
||||
import com.sjapps.library.customdialog.list.events.ListItemClick;
|
||||
import com.sjapps.library.customdialog.list.events.ListItemClickObj;
|
||||
|
||||
import java.util.ArrayList;
|
||||
/**@since 1.5*/
|
||||
@SuppressWarnings({"unused", "unchecked","UnusedReturnValue"})
|
||||
public class ListDialog extends SJDialog {
|
||||
|
||||
RecyclerView listRV;
|
||||
boolean isSelectableList = false;
|
||||
boolean hideEmptyListTxt = false;
|
||||
boolean hasAdapter = false;
|
||||
boolean waitForLayoutManager = false;
|
||||
|
||||
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;
|
||||
|
||||
RecyclerView.Adapter<?> adapter;
|
||||
ArrayList<?> selectedItems = new ArrayList<>();
|
||||
TextView emptyListTxt;
|
||||
|
||||
public ListDialog() {
|
||||
|
||||
}
|
||||
|
||||
public ListDialog Builder(Context context) {
|
||||
return Builder(context, false);
|
||||
}
|
||||
|
||||
public ListDialog Builder(Context context, @StyleRes int theme) {
|
||||
super.Builder(context, R.layout.list_dialog, theme, false);
|
||||
listRV = dialog.findViewById(R.id.list);
|
||||
onLeftButtonClick(dialog::dismiss);
|
||||
emptyListTxt = dialog.findViewById(R.id.emptyListTxt);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListDialog Builder(Context context, boolean useAppTheme) {
|
||||
super.Builder(context, R.layout.list_dialog, useAppTheme);
|
||||
listRV = dialog.findViewById(R.id.list);
|
||||
onLeftButtonClick(dialog::dismiss);
|
||||
emptyListTxt = dialog.findViewById(R.id.emptyListTxt);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setOldTheme() {
|
||||
super.setOldTheme();
|
||||
setListOldColor();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setTitle(String title) {
|
||||
super.setTitle(title);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setMessage(String message) {
|
||||
super.setMessage(message);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
* */
|
||||
@Override
|
||||
public ListDialog setTitleAlignment(int textAlignment) {
|
||||
super.setTitleAlignment(textAlignment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
* */
|
||||
@Override
|
||||
public ListDialog setMessageAlignment(int textAlignment) {
|
||||
super.setMessageAlignment(textAlignment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public ListDialog setTextColor(int color) {
|
||||
super.setTextColor(color);
|
||||
setListItemTextColor(color);
|
||||
setEmptyListTxtColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public ListDialog setTitleTextColor(int color) {
|
||||
super.setTitleTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public ListDialog setMessageTextColor(int color) {
|
||||
super.setMessageTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a button text.
|
||||
*
|
||||
* @param text button text
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public ListDialog setButtonText(String text) {
|
||||
return setLeftButtonText(text);
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setLeftButtonText(String text) {
|
||||
super.setLeftButtonText(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setRightButtonText(String text) {
|
||||
super.setRightButtonText(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set button text color.
|
||||
*
|
||||
* @param color Color to use for tinting this drawable
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public ListDialog setButtonTextColor(@ColorInt int color) {
|
||||
return setLeftButtonTextColor(color);
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setButtonsTextColor(@ColorInt int color) {
|
||||
super.setButtonsTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setLeftButtonTextColor(@ColorInt int color) {
|
||||
super.setLeftButtonTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setRightButtonTextColor(@ColorInt int color) {
|
||||
super.setRightButtonTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set button color.
|
||||
*
|
||||
* @param color Color to use for tinting this drawable
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public ListDialog setButtonColor(@ColorInt int color) {
|
||||
return setLeftButtonColor(color);
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setButtonsColor(@ColorInt int color) {
|
||||
super.setButtonsColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setLeftButtonColor(@ColorInt int color) {
|
||||
super.setLeftButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setRightButtonColor(@ColorInt int color) {
|
||||
super.setRightButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListDialog setButtonColor(@ButtonColor String color) {
|
||||
super.setButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListDialog setButtonsColor(@ButtonColor String color) {
|
||||
super.setButtonsColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListDialog setLeftButtonColor(@ButtonColor String color) {
|
||||
super.setLeftButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListDialog setRightButtonColor(@ButtonColor String color) {
|
||||
super.setRightButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public ListDialog setDialogBackgroundColor(int color) {
|
||||
super.setDialogBackgroundColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setDialogBackgroundResource(@DrawableRes int drawable) {
|
||||
super.setDialogBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set background resource for button.
|
||||
*
|
||||
* @param drawable resource id
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public ListDialog setButtonBackgroundResource(@DrawableRes int drawable) {
|
||||
return setLeftButtonBackgroundResource(drawable);
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setButtonsBackgroundResource(@DrawableRes int drawable) {
|
||||
super.setButtonsBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setLeftButtonBackgroundResource(@DrawableRes int drawable) {
|
||||
super.setLeftButtonBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setRightButtonBackgroundResource(@DrawableRes int drawable) {
|
||||
super.setRightButtonBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set onClick listener for a button
|
||||
*
|
||||
* @param dialogButtonEvent dialog button event
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
@Override
|
||||
public ListDialog onButtonClick(DialogButtonEvent dialogButtonEvent) {
|
||||
if (twoButtons)
|
||||
super.onButtonClick(dialogButtonEvent);
|
||||
else
|
||||
super.onLeftButtonClick(dialogButtonEvent);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog onButtonClick(DialogButtonEvents dialogButtonEvents) {
|
||||
super.onButtonClick(dialogButtonEvents);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog show() {
|
||||
if (layoutManager == null)
|
||||
layoutManager = new LinearLayoutManager(context);
|
||||
if (!waitForLayoutManager)
|
||||
listRV.setLayoutManager(layoutManager);
|
||||
|
||||
listRV.setAdapter(adapter);
|
||||
if (adapter == null)
|
||||
checkListsSize(0);
|
||||
|
||||
super.show();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setMaxDialogWidth(int maxDialogWidth) {
|
||||
super.setMaxDialogWidth(maxDialogWidth);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog setDialogAnimations(int styleRes) {
|
||||
super.setDialogAnimations(styleRes);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public ListDialog dialogWithTwoButtons() {
|
||||
super.dialogWithTwoButtons();
|
||||
setButton2Visibility(View.VISIBLE);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setButton2Visibility(int visibility) {
|
||||
super.setButton2Visibility(visibility);
|
||||
}
|
||||
|
||||
private void setListOldColor() {
|
||||
listItemBgRes = R.drawable.ripple_list_old;
|
||||
listItemBgResSelected = R.drawable.ripple_list_selected_old;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set background resource for a list
|
||||
*
|
||||
* @param drawable drawable resource
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public ListDialog setListBackgroundResource(@DrawableRes int drawable) {
|
||||
listRV.setBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set background resource for a item in a list
|
||||
*
|
||||
* @param drawable drawable resource
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public ListDialog setListItemBackgroundResource(@DrawableRes int drawable) {
|
||||
listItemBgRes = drawable;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set background resource for a selected item in a list
|
||||
*
|
||||
* @param drawable drawable resource
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public ListDialog setListItemSelectedBackgroundResource(@DrawableRes int drawable) {
|
||||
listItemBgResSelected = drawable;
|
||||
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
|
||||
*
|
||||
* @param listItemTextColor color for a text
|
||||
* @return current class
|
||||
* @since 1.6
|
||||
*/
|
||||
public ListDialog setListItemTextColor(int listItemTextColor) {
|
||||
this.listItemTextColor = listItemTextColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
private void setEmptyListTxtColor(int color) {
|
||||
emptyListTxt.setTextColor(color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide {@link #emptyListTxt} when list is empty
|
||||
* @since 1.6
|
||||
* @return current class
|
||||
*/
|
||||
public ListDialog hideEmptyListText() {
|
||||
hideEmptyListTxt = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set text to display when list is empty
|
||||
* @param text Text
|
||||
* @since 1.6
|
||||
* @return current class
|
||||
*/
|
||||
public ListDialog setEmptyListText(String text){
|
||||
emptyListTxt.setText(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a dialog list
|
||||
*
|
||||
* @return dialog list
|
||||
* @since 1.5
|
||||
*/
|
||||
public RecyclerView getRecycleView() {
|
||||
return listRV;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int setButtonsRootLayoutID() {
|
||||
return R.id.buttons;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setButtons() {
|
||||
setButton1(R.id.btn1);
|
||||
setButton2(R.id.btn2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getLeftButton() {
|
||||
return super.getLeftButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Button getRightButton() {
|
||||
return super.getRightButton();
|
||||
}
|
||||
|
||||
/**@since 1.6*/
|
||||
@Override
|
||||
public TextView getTitleTextView() {
|
||||
return super.getTitleTextView();
|
||||
}
|
||||
|
||||
/**@since 1.6*/
|
||||
@Override
|
||||
public TextView getMessageTextView() {
|
||||
return super.getMessageTextView();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set items for a list
|
||||
*
|
||||
* @param listOfItems Array of {@link String}
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public ListDialog setItems(String[] listOfItems) {
|
||||
return setItems(listOfItems, (ListItemClick) null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set items for a list and ListItemClick event
|
||||
*
|
||||
* @param listOfItems Array of {@link String}
|
||||
* @param itemClick ListItemClick event
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public ListDialog setItems(String[] listOfItems, @Nullable ListItemClick itemClick) {
|
||||
|
||||
if (hasAdapter)
|
||||
throw tooManyAdapters;
|
||||
|
||||
if (!isSelectableList && itemClick == null)
|
||||
throw nullListItemClick(ListItemClick.class);
|
||||
|
||||
checkListsSize(listOfItems.length);
|
||||
|
||||
adapter = new DefaultListAdapter(listOfItems,
|
||||
isSelectableList,
|
||||
itemClick,
|
||||
(ArrayList<String>) selectedItems,
|
||||
listItemBgRes,
|
||||
listItemBgResSelected,
|
||||
listItemTextColor,
|
||||
listItemBgColor,
|
||||
listItemBgColorSelected);
|
||||
hasAdapter = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set items for a list and String value of an object for use in a list
|
||||
*
|
||||
* @param objArray Array of {@link Object}
|
||||
* @param value {@link ListItemValue} for getting String value of an object
|
||||
* @param <T> Type of an Object
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public <T> ListDialog setItems(T[] objArray, ListItemValue<T> value) {
|
||||
return setItems(objArray, value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set items for a list and String values of an object for use in a list
|
||||
*
|
||||
* @param objArray Array of {@link Object}
|
||||
* @param values {@link ListItemValues} for getting String values of an object. {@link ListItemValues#getValue1(Object)}
|
||||
* for first value and {@link ListItemValues#getValue1(Object)} for second value
|
||||
* @param <T> Type of an Object
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public <T> ListDialog setItems(T[] objArray, ListItemValues<T> values) {
|
||||
return setItems(objArray, values, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set items for a list and String value of an object for use in a list
|
||||
*
|
||||
* @param arrayList {@link ArrayList} of {@link Object}
|
||||
* @param value {@link ListItemValue} for getting String value of an object
|
||||
* @param <T> Type of an Object
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public <T> ListDialog setItems(ArrayList<T> arrayList, ListItemValue<T> value) {
|
||||
return setItems(arrayList, value, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set items for a list and String values of an object for use in a list
|
||||
*
|
||||
* @param arrayList {@link ArrayList} of {@link Object}
|
||||
* @param values {@link ListItemValues} for getting String values of an object. {@link ListItemValues#getValue1(Object)}
|
||||
* for first value and {@link ListItemValues#getValue1(Object)} for second value
|
||||
* @param <T> Type of an Object
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public <T> ListDialog setItems(ArrayList<T> arrayList, ListItemValues<T> values) {
|
||||
return setItems(arrayList, values, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set items for a list, String value of an object for use in a list and ListItemClick event
|
||||
*
|
||||
* @param objArray Array of {@link Object}
|
||||
* @param value {@link ListItemValue} for getting String value of an object
|
||||
* @param itemClick ListItemClick event
|
||||
* @param <T> Type of an Object
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public <T> ListDialog setItems(T[] objArray, ListItemValue<T> value, @Nullable ListItemClickObj<T> itemClick) {
|
||||
|
||||
if (hasAdapter)
|
||||
throw tooManyAdapters;
|
||||
|
||||
if (!isSelectableList && itemClick == null)
|
||||
throw nullListItemClick(ListItemClickObj.class);
|
||||
|
||||
checkListsSize(objArray.length);
|
||||
|
||||
adapter = new DefaultListAdapterGeneric<>(objArray,
|
||||
value,
|
||||
isSelectableList,
|
||||
itemClick,
|
||||
(ArrayList<T>) selectedItems,
|
||||
listItemBgRes,
|
||||
listItemBgResSelected,
|
||||
listItemTextColor,
|
||||
listItemBgColor,
|
||||
listItemBgColorSelected);
|
||||
hasAdapter = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set items for a list, String values of an object for use in a list and ListItemClick event
|
||||
*
|
||||
* @param objArray Array of {@link Object}
|
||||
* @param values {@link ListItemValues} for getting String values of an object. {@link ListItemValues#getValue1(Object)}
|
||||
* for first value and {@link ListItemValues#getValue1(Object)} for second value
|
||||
* @param itemClick ListItemClick event
|
||||
* @param <T> Type of an Object
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public <T> ListDialog setItems(T[] objArray, ListItemValues<T> values, @Nullable ListItemClickObj<T> itemClick) {
|
||||
|
||||
if (hasAdapter)
|
||||
throw tooManyAdapters;
|
||||
|
||||
if (!isSelectableList && itemClick == null)
|
||||
throw nullListItemClick(ListItemClickObj.class);
|
||||
|
||||
checkListsSize(objArray.length);
|
||||
|
||||
adapter = new DefaultListAdapterGeneric<>(objArray,
|
||||
values,
|
||||
isSelectableList,
|
||||
itemClick,
|
||||
(ArrayList<T>) selectedItems,
|
||||
listItemBgRes,
|
||||
listItemBgResSelected,
|
||||
listItemTextColor,
|
||||
listItemBgColor,
|
||||
listItemBgColorSelected);
|
||||
hasAdapter = true;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set items for a list, String value of an object for use in a list and ListItemClick event
|
||||
*
|
||||
* @param arrayList {@link ArrayList} of {@link Object}
|
||||
* @param value {@link ListItemValue} for getting String value of an object
|
||||
* @param itemClick ListItemClick event
|
||||
* @param <T> Type of an Object
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public <T> ListDialog setItems(ArrayList<T> arrayList, ListItemValue<T> value, @Nullable ListItemClickObj<T> itemClick) {
|
||||
|
||||
if (hasAdapter)
|
||||
throw tooManyAdapters;
|
||||
|
||||
if (!isSelectableList && itemClick == null)
|
||||
throw nullListItemClick(ListItemClickObj.class);
|
||||
|
||||
checkListsSize(arrayList.size());
|
||||
|
||||
adapter = new DefaultListAdapterGeneric<>(arrayList,
|
||||
value,
|
||||
isSelectableList,
|
||||
itemClick,
|
||||
(ArrayList<T>) selectedItems,
|
||||
listItemBgRes,
|
||||
listItemBgResSelected,
|
||||
listItemTextColor,
|
||||
listItemBgColor,
|
||||
listItemBgColorSelected);
|
||||
hasAdapter = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set items for a list, String values of an object for use in a list and ListItemClick event
|
||||
*
|
||||
* @param arrayList {@link ArrayList} of {@link Object}
|
||||
* @param values {@link ListItemValues} for getting String values of an object. {@link ListItemValues#getValue1(Object)}
|
||||
* for first value and {@link ListItemValues#getValue1(Object)} for second value
|
||||
* @param itemClick ListItemClick event
|
||||
* @param <T> Type of an Object
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public <T> ListDialog setItems(ArrayList<T> arrayList, ListItemValues<T> values, @Nullable ListItemClickObj<T> itemClick) {
|
||||
|
||||
if (hasAdapter)
|
||||
throw tooManyAdapters;
|
||||
|
||||
if (!isSelectableList && itemClick == null)
|
||||
throw nullListItemClick(ListItemClickObj.class);
|
||||
|
||||
checkListsSize(arrayList.size());
|
||||
|
||||
adapter = new DefaultListAdapterGeneric<>(arrayList,
|
||||
values,
|
||||
isSelectableList,
|
||||
itemClick,
|
||||
(ArrayList<T>) selectedItems,
|
||||
listItemBgRes,
|
||||
listItemBgResSelected,
|
||||
listItemTextColor,
|
||||
listItemBgColor,
|
||||
listItemBgColorSelected);
|
||||
hasAdapter = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set image items for a list
|
||||
* @param arrayList {@link ArrayList} of {@link ImageListItem}
|
||||
* @return current class
|
||||
* @since 1.6
|
||||
*/
|
||||
public ListDialog setImageItems(ArrayList<ImageListItem> arrayList) {
|
||||
return setImageItems(arrayList, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set image items for a list and ListItemClick event
|
||||
* @param arrayList {@link ArrayList} of {@link ImageListItem}
|
||||
* @param itemClick ListItemClick event
|
||||
* @return current class
|
||||
* @since 1.6
|
||||
*/
|
||||
public ListDialog setImageItems(ArrayList<ImageListItem> arrayList, @Nullable ListItemClickObj<ImageListItem> itemClick) {
|
||||
|
||||
if (hasAdapter)
|
||||
throw tooManyAdapters;
|
||||
|
||||
if (!isSelectableList && itemClick == null)
|
||||
throw nullListItemClick(ListItemClickObj.class);
|
||||
|
||||
checkListsSize(arrayList.size());
|
||||
|
||||
adapter = new DefaultImageListAdapter(arrayList,
|
||||
isSelectableList,
|
||||
itemClick,
|
||||
(ArrayList<ImageListItem>) selectedItems,
|
||||
listItemBgRes,
|
||||
listItemBgResSelected,
|
||||
listItemTextColor,
|
||||
listItemBgColor,
|
||||
listItemBgColorSelected);
|
||||
|
||||
hasAdapter = true;
|
||||
waitForLayoutManager = true;
|
||||
listRV.post(() -> {
|
||||
int maxItemCount = listRV.getWidth() / functions.dpToPixels(context,80);
|
||||
if (maxItemCount == 0)
|
||||
maxItemCount = 1;
|
||||
setLayoutManager(new GridLayoutManager(context, arrayList.size()!=0 ? Math.min(maxItemCount, arrayList.size()):1));
|
||||
listRV.setLayoutManager(layoutManager);
|
||||
waitForLayoutManager = false;
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a list adapter
|
||||
*
|
||||
* @param adapter RecycleView {@link RecyclerView.Adapter adapter}
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public ListDialog setAdapter(RecyclerView.Adapter<?> adapter) {
|
||||
if (hasAdapter)
|
||||
throw tooManyAdapters;
|
||||
this.adapter = adapter;
|
||||
hasAdapter = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param layoutManager {@link RecyclerView.LayoutManager LayoutManager }
|
||||
* @return current class
|
||||
* @since 1.6
|
||||
*/
|
||||
public ListDialog setLayoutManager(RecyclerView.LayoutManager layoutManager) {
|
||||
this.layoutManager = layoutManager;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list adapter
|
||||
*
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public RecyclerView.Adapter<?> getListAdapter() {
|
||||
return adapter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Background resource for views in RecycleView
|
||||
* @since 1.5
|
||||
*/
|
||||
public int getListItemBgRes() {
|
||||
return listItemBgRes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Background resource for selected views in RecycleView
|
||||
* @since 1.5
|
||||
*/
|
||||
public int getListItemBgResSelected() {
|
||||
return listItemBgResSelected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create list with multi selectable items. Use {@link #getSelectedItems()} fet getting selected items
|
||||
*
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
public ListDialog setSelectableList() {
|
||||
isSelectableList = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isSelectableList() {
|
||||
return isSelectableList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListDialog setOnTouchListener(View.OnTouchListener onTouchListener) {
|
||||
super.setOnTouchListener(onTouchListener);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListDialog swipeToDismiss(boolean isSwipeToDismiss) {
|
||||
super.swipeToDismiss(isSwipeToDismiss);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get selected items in a list
|
||||
*
|
||||
* @return ArrayList of selected items in a list
|
||||
* @since 1.5
|
||||
*/
|
||||
public <T> ArrayList<T> getSelectedItems() {
|
||||
return (ArrayList<T>) selectedItems;
|
||||
}
|
||||
|
||||
void checkListsSize(int size) {
|
||||
|
||||
if (hideEmptyListTxt) {
|
||||
emptyListTxt.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
emptyListTxt.setVisibility((size > 0) ? View.GONE : View.VISIBLE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private NullPointerException nullListItemClick(Class className) {
|
||||
return new NullPointerException(
|
||||
String.format("%s is null. Set %s event or use setSelectableList() for selecting multiple item in a list",
|
||||
className.getSimpleName(),
|
||||
className.getSimpleName())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private final UnsupportedOperationException tooManyAdapters = new UnsupportedOperationException("Too many Adapters for RecyclerView");
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.sjapps.library.customdialog;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
public interface ListItemImageValue<T> {
|
||||
/**
|
||||
* Get String value of an Object for using in a list
|
||||
* @param obj Current Object for getting first String value of it
|
||||
* @return String value
|
||||
*/
|
||||
String getTitle(T obj);
|
||||
|
||||
/**
|
||||
* Get Drawable value of an Object for use in a list item
|
||||
* @param obj Current Object for getting second String value of it
|
||||
* @return Drawable
|
||||
*/
|
||||
Drawable getImage(T obj);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.sjapps.library.customdialog;
|
||||
|
||||
public interface ListItemValue<T> {
|
||||
/**
|
||||
* Get String value of an Object for using in a list
|
||||
* @param obj Current Object for getting String value of it
|
||||
* @return String value
|
||||
*/
|
||||
String getValue(T obj);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.sjapps.library.customdialog;
|
||||
|
||||
public interface ListItemValues<T> {
|
||||
/**
|
||||
* Get String value of an Object for use in the first value of a list item
|
||||
* @param obj Current Object for getting first String value of it
|
||||
* @return String value
|
||||
*/
|
||||
String getValue1(T obj);
|
||||
|
||||
/**
|
||||
* Get String value of an Object for use in the second value of a list item
|
||||
* @param obj Current Object for getting second String value of it
|
||||
* @return String value
|
||||
*/
|
||||
String getValue2(T obj);
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
package com.sjapps.library.customdialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.StyleRes;
|
||||
|
||||
import com.sjapps.library.R;
|
||||
/**@since 1.3*/
|
||||
@SuppressWarnings("unused")
|
||||
public class MessageDialog extends SJDialog{
|
||||
|
||||
private boolean isErrorDialog;
|
||||
|
||||
public MessageDialog(){
|
||||
onlyOneButton = true;
|
||||
}
|
||||
|
||||
public MessageDialog Builder(Context context){
|
||||
super.Builder(context,R.layout.message_dialog);
|
||||
onButtonClick(() -> dialog.dismiss());
|
||||
return this;
|
||||
}
|
||||
public MessageDialog Builder(Context context,@StyleRes int theme){
|
||||
super.Builder(context,R.layout.message_dialog,theme, false);
|
||||
onButtonClick(() -> dialog.dismiss());
|
||||
return this;
|
||||
}
|
||||
public MessageDialog Builder(Context context,boolean useAppTheme){
|
||||
super.Builder(context,R.layout.message_dialog,useAppTheme);
|
||||
onButtonClick(() -> dialog.dismiss());
|
||||
return this;
|
||||
}
|
||||
public MessageDialog ErrorDialogBuilder(Context context){
|
||||
return Builder(context).errorDialogAttributes();
|
||||
}
|
||||
public MessageDialog ErrorDialogBuilder(Context context,@StyleRes int theme){
|
||||
return Builder(context,theme).errorDialogAttributes();
|
||||
}
|
||||
public MessageDialog ErrorDialogBuilder(Context context,boolean useAppTheme){
|
||||
return Builder(context,useAppTheme).errorDialogAttributes();
|
||||
}
|
||||
|
||||
private MessageDialog errorDialogAttributes(){
|
||||
isErrorDialog = true;
|
||||
return setDialogBackgroundResource(R.drawable.dialog_background_material3_red)
|
||||
.setTextColor(context.getResources().getColor(R.color.SJDialog_ErrorTextColor, context.getTheme()))
|
||||
.setButtonColor(MATERIAL3_RED_BUTTON)
|
||||
.setTitle("Error");
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.5*/
|
||||
@Override
|
||||
public MessageDialog setOldTheme(){
|
||||
super.setOldTheme();
|
||||
if (isErrorDialog) {
|
||||
setDialogBackgroundResource(R.drawable.dialog_background_red);
|
||||
setTextColor(defaultOldColorWhite);
|
||||
setButtonColor(defaultOldColorWhite);
|
||||
setButtonTextColor(defaultOldColorBlack);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.3*/
|
||||
@Override
|
||||
public MessageDialog setTitle(String title){
|
||||
super.setTitle(title);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.3*/
|
||||
@Override
|
||||
public MessageDialog setMessage(String message) {
|
||||
super.setMessage(message);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
* */
|
||||
@Override
|
||||
public MessageDialog setTitleAlignment(int textAlignment) {
|
||||
super.setTitleAlignment(textAlignment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
* */
|
||||
@Override
|
||||
public MessageDialog setMessageAlignment(int textAlignment) {
|
||||
super.setMessageAlignment(textAlignment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public MessageDialog setTextColor(int color) {
|
||||
super.setTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public MessageDialog setTitleTextColor(int color) {
|
||||
super.setTitleTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public MessageDialog setMessageTextColor(int color) {
|
||||
super.setMessageTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a button text.
|
||||
* @param text button text
|
||||
* @return current class
|
||||
* @since 1.4
|
||||
* */
|
||||
public MessageDialog setButtonText(String text){
|
||||
super.setLeftButtonText(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set button text color.
|
||||
* @param color Color to use for tinting this drawable
|
||||
* @return current class
|
||||
* @since 1.4
|
||||
* */
|
||||
public MessageDialog setButtonTextColor(@ColorInt int color){
|
||||
super.setLeftButtonTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set button color.
|
||||
* @param color Color to use for tinting this drawable
|
||||
* @return current class
|
||||
* @since 1.4
|
||||
* */
|
||||
public MessageDialog setButtonColor(@ColorInt int color){
|
||||
super.setLeftButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageDialog setButtonColor(@ButtonColor String color){
|
||||
super.setButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public MessageDialog setDialogBackgroundColor(int color) {
|
||||
super.setDialogBackgroundColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.3*/
|
||||
@Override
|
||||
public MessageDialog setDialogBackgroundResource(@DrawableRes int drawable){
|
||||
super.setDialogBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set background resource for button.
|
||||
* @param drawable resource id
|
||||
* @return current class
|
||||
* @since 1.3
|
||||
* */
|
||||
public MessageDialog setButtonBackgroundResource(@DrawableRes int drawable){
|
||||
super.setLeftButtonBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set onClick listener for a button
|
||||
* @param dialogButtonEvent dialog button events
|
||||
* @return current class
|
||||
* */
|
||||
@Override
|
||||
public MessageDialog onButtonClick(DialogButtonEvent dialogButtonEvent){
|
||||
super.onLeftButtonClick(dialogButtonEvent);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setButtons() {
|
||||
setButton1(R.id.btn);
|
||||
}
|
||||
|
||||
public Button getButton() {
|
||||
return super.getLeftButton();
|
||||
}
|
||||
|
||||
/**@since 1.6*/
|
||||
@Override
|
||||
public TextView getTitleTextView() {
|
||||
return super.getTitleTextView();
|
||||
}
|
||||
|
||||
/**@since 1.6*/
|
||||
@Override
|
||||
public TextView getMessageTextView() {
|
||||
return super.getMessageTextView();
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.4*/
|
||||
@Override
|
||||
public MessageDialog setMaxDialogWidth(int maxDialogWidth){
|
||||
super.setMaxDialogWidth(maxDialogWidth);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageDialog setDialogAnimations(int styleRes) {
|
||||
super.setDialogAnimations(styleRes);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.3*/
|
||||
@Override
|
||||
public MessageDialog show(){
|
||||
super.show();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int setButtonsRootLayoutID() {
|
||||
return R.id.buttonRoot;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public MessageDialog setOnTouchListener(View.OnTouchListener onTouchListener) {
|
||||
super.setOnTouchListener(onTouchListener);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}
|
||||
* @since 1.6*/
|
||||
@Override
|
||||
public MessageDialog swipeToDismiss(boolean isSwipeToDismiss) {
|
||||
super.swipeToDismiss(isSwipeToDismiss);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,744 @@
|
||||
package com.sjapps.library.customdialog;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.StringDef;
|
||||
import androidx.annotation.StyleRes;
|
||||
|
||||
import com.sjapps.library.R;
|
||||
|
||||
@SuppressWarnings({"unused", "UnusedReturnValue"})
|
||||
public abstract class SJDialog {
|
||||
|
||||
public static final String RED_BUTTON = "RedBtn";
|
||||
public static final String MATERIAL3_RED_BUTTON = "Material3RedBtn";
|
||||
public static final String OLD_BUTTON_COLOR = "OldBtnColor";
|
||||
/** Sets text alignment to {@link View#TEXT_ALIGNMENT_VIEW_START}
|
||||
* @since 1.6
|
||||
* */
|
||||
public static final int TEXT_ALIGNMENT_LEFT = View.TEXT_ALIGNMENT_VIEW_START;
|
||||
/** Sets text alignment to {@link View#TEXT_ALIGNMENT_VIEW_END}
|
||||
* @since 1.6
|
||||
* */
|
||||
public static final int TEXT_ALIGNMENT_RIGHT = View.TEXT_ALIGNMENT_VIEW_END;
|
||||
/** Sets text alignment to {@link View#TEXT_ALIGNMENT_CENTER}
|
||||
* @since 1.6
|
||||
* */
|
||||
public static final int TEXT_ALIGNMENT_CENTER = View.TEXT_ALIGNMENT_CENTER;
|
||||
|
||||
private @LayoutRes int Btn1Resource = R.layout.button_template;
|
||||
private @LayoutRes int Btn2Resource = R.layout.button_template;
|
||||
|
||||
@ColorInt int defaultOldThemeTextColor;
|
||||
@ColorInt int defaultOldColorWhite = 0xFFE5E5E5;
|
||||
@ColorInt int defaultOldColorBlack = 0xFF333333;
|
||||
|
||||
private final int defaultTheme = R.style.Theme_SJDialog;
|
||||
private int newTheme = -1;
|
||||
private boolean usesDefaultTheme = true;
|
||||
private boolean isSwipeToDismiss = true;
|
||||
private boolean isDefaultOnTouchListener = true;
|
||||
private View.OnTouchListener dialogOnTouchListener = null;
|
||||
|
||||
public Dialog dialog;
|
||||
protected Button button1, button2;
|
||||
private LinearLayout background;
|
||||
private int maxDialogWidth = 600;
|
||||
Context context;
|
||||
|
||||
DialogButtonEvent dialogButtonEvent;
|
||||
DialogButtonEvents dialogButtonEvents;
|
||||
|
||||
@StringDef({RED_BUTTON, MATERIAL3_RED_BUTTON, OLD_BUTTON_COLOR})
|
||||
public @interface ButtonColor {
|
||||
}
|
||||
|
||||
@IntDef({TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER})
|
||||
public @interface TextAlignment {
|
||||
}
|
||||
|
||||
protected boolean onlyOneButton = false;
|
||||
protected boolean twoButtons = false;
|
||||
private boolean leftBtnOnClick = false;
|
||||
|
||||
protected SJDialog Builder(Context context, @LayoutRes int layoutResID) {
|
||||
Builder(context, layoutResID, defaultTheme, false);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected SJDialog Builder(Context context, @LayoutRes int layoutResID, boolean useAppTheme) {
|
||||
Builder(context, layoutResID, defaultTheme, useAppTheme);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected SJDialog Builder(Context context, @LayoutRes int layoutResID, @StyleRes int theme, boolean useAppTheme) {
|
||||
this.context = context;
|
||||
defaultOldThemeTextColor = context.getResources().getColor(R.color.SJDialog_OldThemeTextColor, context.getTheme());
|
||||
dialog = useAppTheme ?
|
||||
new Dialog(new ContextThemeWrapper(context, context.getTheme())) :
|
||||
new Dialog(new ContextThemeWrapper(context, theme));
|
||||
setContentView(layoutResID);
|
||||
setDialogSize();
|
||||
dialog.getWindow().getAttributes().gravity = Gravity.BOTTOM;
|
||||
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
dialog.getWindow().getAttributes().windowAnimations = R.style.SJDialogAnimation;
|
||||
background = dialog.findViewById(R.id.dialogBackground);
|
||||
setButtons();
|
||||
if (theme != defaultTheme || useAppTheme) {
|
||||
usesDefaultTheme = false;
|
||||
newTheme = !useAppTheme ? theme : -1;
|
||||
regenerateButtons();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void setDialogSize() {
|
||||
if (context == null)
|
||||
throw new NullPointerException("context is null");
|
||||
if (dialog == null) {
|
||||
throw new NullPointerException("dialog is null");
|
||||
}
|
||||
functions.SetDialogSize(context, dialog, maxDialogWidth);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
protected SJDialog setOldTheme() {
|
||||
setButtonsColor(OLD_BUTTON_COLOR);
|
||||
setDialogBackgroundResource(R.drawable.dialog_background_old);
|
||||
setTextColor(defaultOldThemeTextColor);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a dialog title.
|
||||
*
|
||||
* @param title title of a dialog
|
||||
* @return current class
|
||||
* @since 1.3
|
||||
*/
|
||||
protected SJDialog setTitle(String title) {
|
||||
TextView TitleTv = getTitleTextView();
|
||||
TitleTv.setText(title);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a dialog message.
|
||||
*
|
||||
* @param message message of a dialog
|
||||
* @return current class
|
||||
* @since 1.3
|
||||
*/
|
||||
protected SJDialog setMessage(String message) {
|
||||
TextView msg = getMessageTextView();
|
||||
msg.setText(message);
|
||||
msg.setVisibility(View.VISIBLE);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text alignment for Title TextView. Default is set to {@link SJDialog#TEXT_ALIGNMENT_CENTER}
|
||||
* @param textAlignment The text alignment to set. Supported types: {@link SJDialog#TEXT_ALIGNMENT_LEFT}, {@link SJDialog#TEXT_ALIGNMENT_RIGHT} and {@link SJDialog#TEXT_ALIGNMENT_CENTER}
|
||||
* @return current class
|
||||
* @since 1.6
|
||||
* */
|
||||
protected SJDialog setTitleAlignment(@TextAlignment int textAlignment){
|
||||
TextView title = getTitleTextView();
|
||||
title.setGravity(Gravity.RIGHT);
|
||||
title.setTextAlignment(textAlignment);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text alignment for Message TextView. Default is set to {@link SJDialog#TEXT_ALIGNMENT_LEFT}
|
||||
* @param textAlignment The text alignment to set. Supported types: {@link SJDialog#TEXT_ALIGNMENT_LEFT}, {@link SJDialog#TEXT_ALIGNMENT_RIGHT} and {@link SJDialog#TEXT_ALIGNMENT_CENTER}
|
||||
* @return current class
|
||||
* @since 1.6
|
||||
* */
|
||||
protected SJDialog setMessageAlignment(@TextAlignment int textAlignment){
|
||||
TextView msg = getMessageTextView();
|
||||
msg.setTextAlignment(textAlignment);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set text color.
|
||||
*
|
||||
* @param color Color to use for tinting this drawable
|
||||
* @return current class
|
||||
* @since 1.6
|
||||
*/
|
||||
protected SJDialog setTextColor(@ColorInt int color) {
|
||||
setTitleTextColor(color);
|
||||
setMessageTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title text color.
|
||||
*
|
||||
* @param color Color to use for tinting this drawable
|
||||
* @return current class
|
||||
* @since 1.6
|
||||
*/
|
||||
protected SJDialog setTitleTextColor(@ColorInt int color) {
|
||||
getTitleTextView().setTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set message text color.
|
||||
*
|
||||
* @param color Color to use for tinting this drawable
|
||||
* @return current class
|
||||
* @since 1.6
|
||||
*/
|
||||
protected SJDialog setMessageTextColor(@ColorInt int color) {
|
||||
getMessageTextView().setTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a text to left button.
|
||||
*
|
||||
* @param text button text
|
||||
* @return current class
|
||||
* @since 1.4
|
||||
*/
|
||||
protected SJDialog setLeftButtonText(String text) {
|
||||
button1.setText(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a text to right button.
|
||||
*
|
||||
* @param text button text
|
||||
* @return current class
|
||||
* @since 1.4
|
||||
*/
|
||||
protected SJDialog setRightButtonText(String text) {
|
||||
if (!twoButtons)
|
||||
throw OneButtonException();
|
||||
button2.setText(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set text color for all buttons.
|
||||
*
|
||||
* @param color Color to use for tinting this drawable
|
||||
* @return current class
|
||||
* @since 1.4
|
||||
*/
|
||||
protected SJDialog setButtonsTextColor(@ColorInt int color) {
|
||||
button1.setTextColor(color);
|
||||
if (twoButtons)
|
||||
button2.setTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set text color for left button.
|
||||
*
|
||||
* @param color Color to use for tinting this drawable
|
||||
* @return current class
|
||||
* @since 1.4
|
||||
*/
|
||||
protected SJDialog setLeftButtonTextColor(@ColorInt int color) {
|
||||
button1.setTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set text color for right button.
|
||||
*
|
||||
* @param color Color to use for tinting this drawable
|
||||
* @return current class
|
||||
* @since 1.4
|
||||
*/
|
||||
protected SJDialog setRightButtonTextColor(@ColorInt int color) {
|
||||
if (!twoButtons)
|
||||
throw OneButtonException();
|
||||
button2.setTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set background color for all buttons.
|
||||
*
|
||||
* @param color Color to use for tinting buttons
|
||||
* @return current class
|
||||
* @since 1.4
|
||||
*/
|
||||
protected SJDialog setButtonsColor(@ColorInt int color) {
|
||||
checkButtonResource(0);
|
||||
button1.getBackground().setTint(color);
|
||||
if (twoButtons) {
|
||||
checkButtonResource(1);
|
||||
button2.getBackground().setTint(color);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set background color for left button.
|
||||
*
|
||||
* @param color Color to use for tinting this drawable
|
||||
* @return current class
|
||||
* @since 1.4
|
||||
*/
|
||||
protected SJDialog setLeftButtonColor(@ColorInt int color) {
|
||||
checkButtonResource(0);
|
||||
button1.getBackground().setTint(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set background color for right button.
|
||||
*
|
||||
* @param color Color to use for tinting this drawable
|
||||
* @return current class
|
||||
* @since 1.4
|
||||
*/
|
||||
protected SJDialog setRightButtonColor(@ColorInt int color) {
|
||||
if (!twoButtons)
|
||||
throw OneButtonException();
|
||||
|
||||
checkButtonResource(1);
|
||||
button2.getBackground().setTint(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected SJDialog setButtonColor(@ButtonColor String color) {
|
||||
checkButtonResource(0);
|
||||
setLeftButtonColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected SJDialog setButtonsColor(@ButtonColor String color) {
|
||||
setLeftButtonColor(color);
|
||||
if (twoButtons)
|
||||
setRightButtonColor(color);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
protected SJDialog setLeftButtonColor(@ButtonColor String color) {
|
||||
checkButtonResource(0);
|
||||
switch (color) {
|
||||
case RED_BUTTON:
|
||||
setLeftButtonBackgroundResource(R.drawable.ripple_button_red);
|
||||
setLeftButtonTextColor(Color.WHITE);
|
||||
break;
|
||||
case MATERIAL3_RED_BUTTON:
|
||||
setLeftButtonBackgroundResource(R.drawable.ripple_button_material3_red);
|
||||
setLeftButtonTextColor(context.getResources().getColor(R.color.md_theme_onError, context.getTheme()));
|
||||
break;
|
||||
case OLD_BUTTON_COLOR:
|
||||
setLeftButtonBackgroundResource(R.drawable.ripple_button_old);
|
||||
setLeftButtonTextColor(Color.WHITE);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException(color + " is not a valid argument");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
protected SJDialog setRightButtonColor(@ButtonColor String color) {
|
||||
if (!twoButtons)
|
||||
throw OneButtonException();
|
||||
checkButtonResource(1);
|
||||
switch (color) {
|
||||
case RED_BUTTON:
|
||||
setRightButtonBackgroundResource(R.drawable.ripple_button_red);
|
||||
setRightButtonTextColor(Color.WHITE);
|
||||
break;
|
||||
case MATERIAL3_RED_BUTTON:
|
||||
setRightButtonBackgroundResource(R.drawable.ripple_button_material3_red);
|
||||
setRightButtonTextColor(context.getResources().getColor(R.color.md_theme_onError, context.getTheme()));
|
||||
break;
|
||||
case OLD_BUTTON_COLOR:
|
||||
setRightButtonBackgroundResource(R.drawable.ripple_button_old);
|
||||
setRightButtonTextColor(Color.WHITE);
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException(color + " is not a valid argument");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change dialog color
|
||||
* @param color {@link ColorInt}
|
||||
* @return current class
|
||||
* @since 1.6
|
||||
*/
|
||||
protected SJDialog setDialogBackgroundColor(@ColorInt int color){
|
||||
background.getBackground().mutate().setTint(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set background resource for dialog.
|
||||
*
|
||||
* @param drawable resource id
|
||||
* @return current class
|
||||
* @since 1.3
|
||||
*/
|
||||
protected SJDialog setDialogBackgroundResource(@DrawableRes int drawable) {
|
||||
background.setBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set background resource for all buttons.
|
||||
*
|
||||
* @param drawable resource id
|
||||
* @return current class
|
||||
* @since 1.3
|
||||
*/
|
||||
protected SJDialog setButtonsBackgroundResource(@DrawableRes int drawable) {
|
||||
checkButtonResource(0);
|
||||
button1.setBackgroundResource(drawable);
|
||||
if (twoButtons) {
|
||||
checkButtonResource(1);
|
||||
button2.setBackgroundResource(drawable);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set background resource for left button.
|
||||
*
|
||||
* @param drawable resource id
|
||||
* @return current class
|
||||
* @since 1.3
|
||||
*/
|
||||
protected SJDialog setLeftButtonBackgroundResource(@DrawableRes int drawable) {
|
||||
checkButtonResource(0);
|
||||
button1.setBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set background resource for right button.
|
||||
*
|
||||
* @param drawable resource id
|
||||
* @return current class
|
||||
* @since 1.3
|
||||
*/
|
||||
protected SJDialog setRightButtonBackgroundResource(@DrawableRes int drawable) {
|
||||
if (!twoButtons)
|
||||
throw OneButtonException();
|
||||
|
||||
checkButtonResource(1);
|
||||
button2.setBackgroundResource(drawable);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set onClick listener for right button
|
||||
*
|
||||
* @param dialogButtonEvent dialog button events
|
||||
* @return current class
|
||||
* @since 1.0
|
||||
*/
|
||||
protected SJDialog onButtonClick(DialogButtonEvent dialogButtonEvent) {
|
||||
leftBtnOnClick = false;
|
||||
this.dialogButtonEvent = dialogButtonEvent;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set onClick listener for both buttons
|
||||
*
|
||||
* @param dialogButtonEvents dialog button events
|
||||
* @return current class
|
||||
* @since 1.0
|
||||
*/
|
||||
protected SJDialog onButtonClick(DialogButtonEvents dialogButtonEvents) {
|
||||
this.dialogButtonEvents = dialogButtonEvents;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set onClick listener for left button
|
||||
*
|
||||
* @param dialogButtonEvent dialog button event
|
||||
* @return current class
|
||||
*/
|
||||
protected SJDialog onLeftButtonClick(DialogButtonEvent dialogButtonEvent) {
|
||||
leftBtnOnClick = true;
|
||||
this.dialogButtonEvent = dialogButtonEvent;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creating dialog with two buttons. Use this method before changing buttons attributes
|
||||
* @since 1.5
|
||||
*/
|
||||
protected SJDialog dialogWithTwoButtons() {
|
||||
twoButtons = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* show dialog
|
||||
* @since 1.3
|
||||
*/
|
||||
protected SJDialog show() {
|
||||
setDialogTouchListener();
|
||||
addOnClickListener();
|
||||
dialog.show();
|
||||
return this;
|
||||
}
|
||||
|
||||
private void addOnClickListener() {
|
||||
if (dialogButtonEvents == null && dialogButtonEvent == null)
|
||||
return;
|
||||
|
||||
if (dialogButtonEvents != null) {
|
||||
button1.setOnClickListener(v -> dialogButtonEvents.onLeftButtonClick());
|
||||
button2.setOnClickListener(v -> dialogButtonEvents.onRightButtonClick());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!twoButtons) {
|
||||
button1.setOnClickListener(v -> dialogButtonEvent.onButtonClick());
|
||||
return;
|
||||
}
|
||||
|
||||
if (leftBtnOnClick) {
|
||||
button1.setOnClickListener(v -> dialogButtonEvent.onButtonClick());
|
||||
return;
|
||||
}
|
||||
|
||||
button1.setOnClickListener(v -> dismiss());
|
||||
button2.setOnClickListener(v -> dialogButtonEvent.onButtonClick());
|
||||
}
|
||||
|
||||
/**
|
||||
* dismiss dialog
|
||||
* @since 1.3
|
||||
*/
|
||||
public void dismiss() {
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
||||
private void setContentView(@LayoutRes int layoutResID) {
|
||||
dialog.setContentView(layoutResID);
|
||||
}
|
||||
|
||||
protected void setButton1(@IdRes int id) {
|
||||
this.button1 = dialog.findViewById(id);
|
||||
}
|
||||
|
||||
protected void setButton2(@IdRes int id) {
|
||||
this.button2 = dialog.findViewById(id);
|
||||
}
|
||||
|
||||
protected abstract @IdRes int setButtonsRootLayoutID();
|
||||
|
||||
protected abstract void setButtons();
|
||||
|
||||
|
||||
private void regenerateButtons() {
|
||||
LinearLayout buttons = dialog.findViewById(setButtonsRootLayoutID());
|
||||
regenerateLeftBtn(buttons);
|
||||
if (onlyOneButton) {
|
||||
return;
|
||||
}
|
||||
regenerateRightBtn(buttons);
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void regenerateLeftBtn(LinearLayout buttons) {
|
||||
if (buttons == null)
|
||||
buttons = dialog.findViewById(setButtonsRootLayoutID());
|
||||
|
||||
String txt = button1.getText().toString();
|
||||
buttons.removeView(button1);
|
||||
button1 = (Button) LayoutInflater
|
||||
.from(newTheme != -1 ? new ContextThemeWrapper(context, newTheme) : context)
|
||||
.inflate(Btn1Resource,buttons,false);
|
||||
button1.setText(txt);
|
||||
buttons.addView(button1, 0);
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void regenerateRightBtn(LinearLayout buttons) {
|
||||
if (buttons == null)
|
||||
buttons = dialog.findViewById(setButtonsRootLayoutID());
|
||||
|
||||
int btn2Visibility = button2.getVisibility();
|
||||
String txt = button2.getText().toString();
|
||||
buttons.removeView(button2);
|
||||
button2 = (Button) LayoutInflater
|
||||
.from(newTheme != -1 ? new ContextThemeWrapper(context, newTheme) : context)
|
||||
.inflate(Btn2Resource,buttons,false);
|
||||
button2.setVisibility(btn2Visibility);
|
||||
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) button2.getLayoutParams();
|
||||
params.setMarginStart(functions.dpToPixels(context,10));
|
||||
button2.setLayoutParams(params);
|
||||
button2.setText(txt);
|
||||
buttons.addView(button2, 1);
|
||||
}
|
||||
|
||||
private void checkButtonResource(int i) {
|
||||
if (usesDefaultTheme)
|
||||
return;
|
||||
|
||||
if (i == 0) {
|
||||
if (Btn1Resource == R.layout.button_template) {
|
||||
Btn1Resource = R.layout.button_template_1;
|
||||
regenerateLeftBtn(null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (i == 1) {
|
||||
if (Btn2Resource == R.layout.button_template) {
|
||||
Btn2Resource = R.layout.button_template_1;
|
||||
regenerateRightBtn(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void setButton2Visibility(int visibility) {
|
||||
button2.setVisibility(visibility);
|
||||
}
|
||||
|
||||
protected TextView getTitleTextView() {
|
||||
return dialog.findViewById(R.id.titleText);
|
||||
}
|
||||
|
||||
protected TextView getMessageTextView() {
|
||||
return dialog.findViewById(R.id.messageTxt);
|
||||
}
|
||||
|
||||
protected Button getLeftButton() {
|
||||
return button1;
|
||||
}
|
||||
|
||||
protected Button getRightButton() {
|
||||
return button2;
|
||||
}
|
||||
|
||||
public int getMaxDialogWidth() {
|
||||
return this.maxDialogWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum width for dialog
|
||||
*
|
||||
* @param maxDialogWidth set value for {@link #maxDialogWidth}. Default is 600dp
|
||||
* @return current class
|
||||
* @since 1.4
|
||||
*/
|
||||
protected SJDialog setMaxDialogWidth(int maxDialogWidth) {
|
||||
this.maxDialogWidth = maxDialogWidth;
|
||||
setDialogSize();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set animation for a dialog
|
||||
*
|
||||
* @param styleRes style resource
|
||||
* @return current class
|
||||
* @since 1.5
|
||||
*/
|
||||
protected SJDialog setDialogAnimations(@StyleRes int styleRes) {
|
||||
dialog.getWindow().getAttributes().windowAnimations = styleRes;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable swipe down to dismiss dialog. Default is set to true
|
||||
*
|
||||
* @param isSwipeToDismiss Enable or disable swipe action
|
||||
* @return current class
|
||||
* @since 1.6
|
||||
*/
|
||||
protected SJDialog swipeToDismiss(boolean isSwipeToDismiss){
|
||||
this.isSwipeToDismiss = isSwipeToDismiss;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set dialog OnTouchListener. by default is set to {@link SwipeDismissTouchListener}.
|
||||
* If this method is used, swipe to dismiss will not work.
|
||||
*
|
||||
* @param onTouchListener onTouchListener for dialog view
|
||||
* @return current class
|
||||
* @since 1.6
|
||||
*/
|
||||
protected SJDialog setOnTouchListener(View.OnTouchListener onTouchListener) {
|
||||
dialogOnTouchListener = onTouchListener;
|
||||
isDefaultOnTouchListener = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
private void setDialogTouchListener() {
|
||||
|
||||
if (isDefaultOnTouchListener)
|
||||
dialogOnTouchListener = new SwipeDismissTouchListener(
|
||||
dialog.getWindow().getDecorView(),
|
||||
new SwipeDismissTouchListener.DismissCallbacks() {
|
||||
@Override
|
||||
public boolean canDismiss() {
|
||||
return isSwipeToDismiss;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(View view) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
dialog.getWindow().getDecorView().setOnTouchListener(dialogOnTouchListener);
|
||||
}
|
||||
|
||||
private OneButtonException OneButtonException() {
|
||||
return new OneButtonException("Trying to access right button when dialog has only one button. Use 'dialogWithTwoButtons()' to fix the problem.");
|
||||
}
|
||||
}
|
||||
|
||||
class OneButtonException extends RuntimeException {
|
||||
public OneButtonException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.sjapps.library.customdialog;
|
||||
/**
|
||||
* by SlaVcE
|
||||
* Setting up custom dialog.
|
||||
* @deprecated SetupDialog is renamed to BasicDialog. Use {@link BasicDialog} instead.
|
||||
* @since 1.0
|
||||
*/
|
||||
@Deprecated(since = "1.6")
|
||||
public class SetupDialog extends BasicDialog{ }
|
||||
+216
@@ -0,0 +1,216 @@
|
||||
package com.sjapps.library.customdialog;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.VelocityTracker;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
|
||||
public class SwipeDismissTouchListener implements View.OnTouchListener {
|
||||
private final int mSlop;
|
||||
private final long mAnimationTime;
|
||||
|
||||
// Fixed properties
|
||||
private final View mView;
|
||||
private final DismissCallbacks mCallbacks;
|
||||
private int mViewHeight = 1; // 1 and not 0 to prevent dividing by zero
|
||||
|
||||
// Transient properties
|
||||
private float mDownX;
|
||||
private float mDownY;
|
||||
private boolean mSwiping;
|
||||
private int mSwipingSlop;
|
||||
private VelocityTracker mVelocityTracker;
|
||||
private float mTranslationY;
|
||||
|
||||
/**
|
||||
* The callback interface used by {@link SwipeDismissTouchListener} to inform its client
|
||||
* about a successful dismissal of the view for which it was created.
|
||||
*/
|
||||
public interface DismissCallbacks {
|
||||
/**
|
||||
* Called to determine whether the view can be dismissed.
|
||||
*/
|
||||
boolean canDismiss();
|
||||
|
||||
/**
|
||||
* Called when the user has indicated they she would like to dismiss the view.
|
||||
*
|
||||
* @param view The originating {@link android.view.View} to be dismissed.
|
||||
*/
|
||||
void onDismiss(View view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new swipe-to-dismiss touch listener for the given view.
|
||||
*
|
||||
* @param view The view to make dismissable.
|
||||
* @param callbacks The callback to trigger when the user has indicated that would like to
|
||||
* dismiss this view.
|
||||
*/
|
||||
public SwipeDismissTouchListener(View view, DismissCallbacks callbacks) {
|
||||
ViewConfiguration vc = ViewConfiguration.get(view.getContext());
|
||||
mSlop = vc.getScaledTouchSlop();
|
||||
mAnimationTime = view.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
|
||||
mView = view;
|
||||
mCallbacks = callbacks;
|
||||
}
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
// offset because the view is translated during swipe
|
||||
motionEvent.offsetLocation(0, mTranslationY);
|
||||
|
||||
boolean returnTrue = false;
|
||||
|
||||
if (mViewHeight < 2) {
|
||||
mViewHeight = mView.getHeight();
|
||||
}
|
||||
|
||||
switch (motionEvent.getActionMasked()) {
|
||||
case MotionEvent.ACTION_DOWN: {
|
||||
// TODO: ensure this is a finger, and set a flag
|
||||
mDownX = motionEvent.getRawX();
|
||||
mDownY = motionEvent.getRawY();
|
||||
if (mCallbacks.canDismiss()) {
|
||||
mVelocityTracker = VelocityTracker.obtain();
|
||||
mVelocityTracker.addMovement(motionEvent);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
case MotionEvent.ACTION_UP: {
|
||||
if (mVelocityTracker == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
float deltaY = motionEvent.getRawY() - mDownY;
|
||||
mVelocityTracker.addMovement(motionEvent);
|
||||
mVelocityTracker.computeCurrentVelocity(1000);
|
||||
|
||||
boolean dismiss = false;
|
||||
boolean dismissDown = false;
|
||||
if (deltaY > (float) mViewHeight / 2 && mSwiping) {
|
||||
dismiss = true;
|
||||
dismissDown = deltaY > 0;
|
||||
returnTrue = true;
|
||||
} else if (Math.abs(deltaY) > 0){
|
||||
returnTrue = true;
|
||||
}
|
||||
if (dismiss) {
|
||||
// dismiss
|
||||
mView.animate()
|
||||
.translationY(dismissDown ? mViewHeight : 0)
|
||||
.alpha(0)
|
||||
.setDuration(mAnimationTime)
|
||||
.setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
performDismiss();
|
||||
}
|
||||
});
|
||||
|
||||
} else if (mSwiping) {
|
||||
// cancel
|
||||
|
||||
mView.animate()
|
||||
.translationY(0)
|
||||
.alpha(1)
|
||||
.setDuration(mAnimationTime)
|
||||
.setListener(null);
|
||||
}
|
||||
mVelocityTracker.recycle();
|
||||
mVelocityTracker = null;
|
||||
mTranslationY = 0;
|
||||
mDownX = 0;
|
||||
mDownY = 0;
|
||||
mSwiping = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case MotionEvent.ACTION_CANCEL: {
|
||||
if (mVelocityTracker == null) {
|
||||
break;
|
||||
}
|
||||
mView.animate()
|
||||
.translationY(0)
|
||||
.alpha(1)
|
||||
.setDuration(mAnimationTime)
|
||||
.setListener(null);
|
||||
mVelocityTracker.recycle();
|
||||
mVelocityTracker = null;
|
||||
mTranslationY = 0;
|
||||
mDownX = 0;
|
||||
mDownY = 0;
|
||||
mSwiping = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case MotionEvent.ACTION_MOVE: {
|
||||
if (mVelocityTracker == null) {
|
||||
break;
|
||||
}
|
||||
mVelocityTracker.addMovement(motionEvent);
|
||||
float deltaX = motionEvent.getRawX() - mDownX;
|
||||
float deltaY = motionEvent.getRawY() - mDownY;
|
||||
if (Math.abs(deltaY) > mSlop && Math.abs(deltaX) < Math.abs(deltaY) / 2) {
|
||||
mSwiping = true;
|
||||
mSwipingSlop = (deltaY > 0 ? mSlop : 0);
|
||||
mView.getParent().requestDisallowInterceptTouchEvent(true);
|
||||
|
||||
|
||||
MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
|
||||
cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
|
||||
mView.onTouchEvent(cancelEvent);
|
||||
cancelEvent.recycle();
|
||||
}
|
||||
|
||||
if (mSwiping) {
|
||||
mTranslationY = deltaY;
|
||||
if (deltaY - mSwipingSlop < 0)
|
||||
mView.setTranslationY(0);
|
||||
else mView.setTranslationY(deltaY - mSwipingSlop);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return returnTrue;
|
||||
}
|
||||
|
||||
private void performDismiss() {
|
||||
// Animate the dismissed view to zero-height and then fire the dismiss callback.
|
||||
// This triggers layout on each animation frame; in the future we may want to do something
|
||||
// smarter and more performant.
|
||||
|
||||
final ViewGroup.LayoutParams lp = mView.getLayoutParams();
|
||||
final int originalHeight = mView.getHeight();
|
||||
|
||||
ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);
|
||||
|
||||
animator.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mCallbacks.onDismiss(mView);
|
||||
// Reset view presentation
|
||||
mView.setAlpha(1f);
|
||||
mView.setTranslationX(0);
|
||||
lp.height = originalHeight;
|
||||
mView.setLayoutParams(lp);
|
||||
}
|
||||
});
|
||||
|
||||
animator.addUpdateListener(valueAnimator -> {
|
||||
lp.height = (Integer) valueAnimator.getAnimatedValue();
|
||||
mView.setLayoutParams(lp);
|
||||
});
|
||||
|
||||
animator.start();
|
||||
}
|
||||
}
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
package com.sjapps.library.customdialog.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.sjapps.library.R;
|
||||
import com.sjapps.library.customdialog.ImageListItem;
|
||||
import com.sjapps.library.customdialog.list.events.ListItemClickObj;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DefaultImageListAdapter extends RecyclerView.Adapter<DefaultImageListAdapter.ViewHolder> {
|
||||
|
||||
public ArrayList<ImageListItem> arrayListItems;
|
||||
|
||||
boolean isSelectable;
|
||||
|
||||
int itemBgRes;
|
||||
int itemBgResSelected;
|
||||
int listItemBgColor;
|
||||
int listItemBgColorSelected;
|
||||
int textColor;
|
||||
|
||||
ListItemClickObj<ImageListItem> itemClick;
|
||||
ArrayList<ImageListItem> selectedItems;
|
||||
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView valTxt;
|
||||
ImageView imageView;
|
||||
|
||||
public ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
valTxt = itemView.findViewById(R.id.value1Txt);
|
||||
imageView = itemView.findViewById(R.id.imageView);
|
||||
}
|
||||
|
||||
public TextView getTxt() {
|
||||
return valTxt;
|
||||
}
|
||||
|
||||
public ImageView getImageView() {
|
||||
return imageView;
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return itemView.findViewById(R.id.layoutItem);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public DefaultImageListAdapter(ArrayList<ImageListItem> arrayList,
|
||||
boolean isSelectable,
|
||||
@Nullable ListItemClickObj<ImageListItem> itemClick,
|
||||
ArrayList<ImageListItem> selectedItems,
|
||||
int itemBgRes,
|
||||
int itemBgResSelected,
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public DefaultImageListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.default_image_list_item, parent, false);
|
||||
return new DefaultImageListAdapter.ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
setValues(holder, position);
|
||||
setBackground(holder, position);
|
||||
|
||||
if (textColor != 1) {
|
||||
holder.getTxt().setTextColor(textColor);
|
||||
}
|
||||
|
||||
if (isSelectable) {
|
||||
holder.getView().setOnClickListener(v ->
|
||||
checkSelected(holder, arrayListItems.get(position))
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
holder.getView().setOnClickListener(v -> itemClick.onClick(position, arrayListItems.get(position)));
|
||||
|
||||
}
|
||||
|
||||
private void setBackground(@NonNull ViewHolder holder, int position) {
|
||||
if (!isSelectable) {
|
||||
setItemResource(holder, itemBgRes);
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
holder.getTxt().setText(arrayListItems.get(position).getName());
|
||||
holder.getImageView().setImageDrawable(arrayListItems.get(position).getImage());
|
||||
|
||||
}
|
||||
|
||||
private void checkSelected(@NonNull ViewHolder holder,ImageListItem obj) {
|
||||
if (!selectedItems.contains(obj))
|
||||
selectItem(holder, obj);
|
||||
else deselectItem(holder, obj);
|
||||
}
|
||||
|
||||
private void selectItem(@NonNull ViewHolder holder,ImageListItem obj) {
|
||||
selectedItems.add(obj);
|
||||
setItemResource(holder, itemBgResSelected);
|
||||
setItemColor(holder,listItemBgColorSelected);
|
||||
}
|
||||
|
||||
private void deselectItem(@NonNull ViewHolder holder,ImageListItem obj) {
|
||||
selectedItems.remove(obj);
|
||||
setItemResource(holder, itemBgRes);
|
||||
setItemColor(holder,listItemBgColor);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package com.sjapps.library.customdialog.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.sjapps.library.R;
|
||||
import com.sjapps.library.customdialog.list.events.ListItemClick;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DefaultListAdapter extends RecyclerView.Adapter<DefaultListAdapterGeneric.ViewHolder> {
|
||||
|
||||
String[] items;
|
||||
boolean isSelectable;
|
||||
ListItemClick itemClick;
|
||||
ArrayList<String> selectedItems;
|
||||
int itemBgRes;
|
||||
int itemBgResSelected;
|
||||
int listItemBgColor;
|
||||
int listItemBgColorSelected;
|
||||
int textColor;
|
||||
|
||||
|
||||
public DefaultListAdapter(String[] items,
|
||||
boolean isSelectable,
|
||||
ListItemClick itemClick,
|
||||
ArrayList<String> selectedItems,
|
||||
int itemBgRes,
|
||||
int itemBgResSelected,
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public DefaultListAdapterGeneric.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.default_list_item,parent,false);
|
||||
return new DefaultListAdapterGeneric.ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int position) {
|
||||
holder.getVal1Txt().setText(items[position]);
|
||||
|
||||
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);
|
||||
|
||||
if (isSelectable) {
|
||||
holder.getView().setOnClickListener(v -> {
|
||||
if (!selectedItems.contains(items[position]))
|
||||
selectItem(holder,position);
|
||||
else deselectItem(holder, position);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
holder.getView().setOnClickListener(v -> itemClick.onClick(position,items[position]));
|
||||
|
||||
}
|
||||
|
||||
private void selectItem(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int position){
|
||||
selectedItems.add(items[position]);
|
||||
setItemResource(holder,itemBgResSelected);
|
||||
setItemColor(holder,listItemBgColorSelected);
|
||||
|
||||
}
|
||||
|
||||
private void deselectItem(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int position){
|
||||
selectedItems.remove(items[position]);
|
||||
setItemResource(holder,itemBgRes);
|
||||
setItemColor(holder,listItemBgColor);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
+290
@@ -0,0 +1,290 @@
|
||||
package com.sjapps.library.customdialog.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.sjapps.library.R;
|
||||
import com.sjapps.library.customdialog.ListItemValue;
|
||||
import com.sjapps.library.customdialog.ListItemValues;
|
||||
import com.sjapps.library.customdialog.list.events.ListItemClickObj;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DefaultListAdapterGeneric<T> extends RecyclerView.Adapter<DefaultListAdapterGeneric.ViewHolder> {
|
||||
|
||||
public ArrayList<T> arrayListItems;
|
||||
public T[] listObj;
|
||||
|
||||
private ListItemValue<T> value;
|
||||
private ListItemValues<T> values;
|
||||
|
||||
boolean isArrList;
|
||||
boolean isObjArr;
|
||||
boolean hasTwoVal;
|
||||
boolean isSelectable;
|
||||
|
||||
int itemBgRes;
|
||||
int itemBgResSelected;
|
||||
int listItemBgColor;
|
||||
int listItemBgColorSelected;
|
||||
int textColor;
|
||||
|
||||
ListItemClickObj<T> itemClick;
|
||||
ArrayList<T> selectedItems;
|
||||
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder{
|
||||
TextView val1Txt;
|
||||
TextView val2Txt;
|
||||
|
||||
public ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
val1Txt = itemView.findViewById(R.id.value1Txt);
|
||||
val2Txt = itemView.findViewById(R.id.value2Txt);
|
||||
}
|
||||
|
||||
public TextView getVal1Txt() {
|
||||
return val1Txt;
|
||||
}
|
||||
|
||||
public TextView getVal2Txt() {
|
||||
return val2Txt;
|
||||
}
|
||||
|
||||
public View getView(){
|
||||
return itemView.findViewById(R.id.layoutItem);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public DefaultListAdapterGeneric(T[] objArray,
|
||||
ListItemValue<T> value,
|
||||
boolean isSelectable,
|
||||
@Nullable ListItemClickObj<T> itemClick,
|
||||
ArrayList<T> selectedItems,
|
||||
int itemBgRes,
|
||||
int itemBgResSelected,
|
||||
int textColor,
|
||||
int listItemBgColor,
|
||||
int listItemBgColorSelected){
|
||||
this.value = value;
|
||||
this.itemClick = itemClick;
|
||||
this.isSelectable = isSelectable;
|
||||
this.selectedItems = selectedItems;
|
||||
this.itemBgRes = itemBgRes;
|
||||
this.itemBgResSelected = itemBgResSelected;
|
||||
this.textColor = textColor;
|
||||
this.listItemBgColor = listItemBgColor;
|
||||
this.listItemBgColorSelected = listItemBgColorSelected;
|
||||
ObjArrayAdapter(objArray);
|
||||
}
|
||||
|
||||
public DefaultListAdapterGeneric(T[] objArray,
|
||||
ListItemValues<T> values,
|
||||
boolean isSelectable,
|
||||
@Nullable ListItemClickObj<T> itemClick,
|
||||
ArrayList<T> selectedItems,
|
||||
int itemBgRes,
|
||||
int itemBgResSelected,
|
||||
int textColor,
|
||||
int listItemBgColor,
|
||||
int listItemBgColorSelected){
|
||||
this.values = values;
|
||||
this.itemClick = itemClick;
|
||||
hasTwoVal = true;
|
||||
this.isSelectable = isSelectable;
|
||||
this.selectedItems = selectedItems;
|
||||
this.itemBgRes = itemBgRes;
|
||||
this.itemBgResSelected = itemBgResSelected;
|
||||
this.textColor = textColor;
|
||||
this.listItemBgColor = listItemBgColor;
|
||||
this.listItemBgColorSelected = listItemBgColorSelected;
|
||||
ObjArrayAdapter(objArray);
|
||||
}
|
||||
|
||||
public DefaultListAdapterGeneric(ArrayList<T> arrayList,
|
||||
ListItemValue<T> value,
|
||||
boolean isSelectable,
|
||||
@Nullable ListItemClickObj<T> itemClick,
|
||||
ArrayList<T> selectedItems,
|
||||
int itemBgRes,
|
||||
int itemBgResSelected,
|
||||
int textColor,
|
||||
int listItemBgColor,
|
||||
int listItemBgColorSelected){
|
||||
this.value = value;
|
||||
this.itemClick = itemClick;
|
||||
this.isSelectable = isSelectable;
|
||||
this.selectedItems = selectedItems;
|
||||
this.itemBgRes = itemBgRes;
|
||||
this.itemBgResSelected = itemBgResSelected;
|
||||
this.textColor = textColor;
|
||||
this.listItemBgColor = listItemBgColor;
|
||||
this.listItemBgColorSelected = listItemBgColorSelected;
|
||||
ArrayListAdapter(arrayList);
|
||||
}
|
||||
|
||||
public DefaultListAdapterGeneric(ArrayList<T> arrayList,
|
||||
ListItemValues<T> values,
|
||||
boolean isSelectable,
|
||||
@Nullable ListItemClickObj<T> itemClick,
|
||||
ArrayList<T> selectedItems,
|
||||
int itemBgRes,
|
||||
int itemBgResSelected,
|
||||
int textColor,
|
||||
int listItemBgColor,
|
||||
int listItemBgColorSelected){
|
||||
this.values = values;
|
||||
this.itemClick = itemClick;
|
||||
hasTwoVal = true;
|
||||
this.isSelectable = isSelectable;
|
||||
this.selectedItems = selectedItems;
|
||||
this.itemBgRes = itemBgRes;
|
||||
this.itemBgResSelected = itemBgResSelected;
|
||||
this.textColor = textColor;
|
||||
this.listItemBgColor = listItemBgColor;
|
||||
this.listItemBgColorSelected = listItemBgColorSelected;
|
||||
ArrayListAdapter(arrayList);
|
||||
}
|
||||
|
||||
private void ObjArrayAdapter(T[] objArray){
|
||||
this.listObj = objArray;
|
||||
isObjArr = true;
|
||||
|
||||
}
|
||||
|
||||
private void ArrayListAdapter(ArrayList<T> arrayList){
|
||||
this.arrayListItems = arrayList;
|
||||
isArrList = true;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public DefaultListAdapterGeneric.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.default_list_item,parent,false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int position) {
|
||||
setValues(holder,position);
|
||||
setBackground(holder,position);
|
||||
|
||||
if (textColor != 1){
|
||||
holder.getVal1Txt().setTextColor(textColor);
|
||||
holder.getVal2Txt().setTextColor(textColor);
|
||||
}
|
||||
|
||||
if (isSelectable){
|
||||
holder.getView().setOnClickListener(v -> {
|
||||
if (isArrList)
|
||||
checkSelected(holder, arrayListItems.get(position));
|
||||
else if (isObjArr)
|
||||
checkSelected(holder, listObj[position]);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isArrList)
|
||||
holder.getView().setOnClickListener(v -> itemClick.onClick(position,arrayListItems.get(position)));
|
||||
|
||||
if (isObjArr)
|
||||
holder.getView().setOnClickListener(v -> itemClick.onClick(position,listObj[position]));
|
||||
|
||||
}
|
||||
|
||||
private void setBackground(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int position) {
|
||||
if (!isSelectable) {
|
||||
setItemResource(holder,itemBgRes);
|
||||
return;
|
||||
}
|
||||
if (isArrList) {
|
||||
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])) {
|
||||
setItemResource(holder, itemBgResSelected);
|
||||
setItemColor(holder,listItemBgColorSelected);
|
||||
}
|
||||
else {
|
||||
setItemResource(holder, itemBgRes);
|
||||
setItemColor(holder,listItemBgColor);
|
||||
}
|
||||
}
|
||||
|
||||
private void setValues(@NonNull DefaultListAdapterGeneric.ViewHolder holder, int position){
|
||||
if (isArrList){
|
||||
if (!hasTwoVal) {
|
||||
holder.getVal1Txt().setText(value.getValue(arrayListItems.get(position)));
|
||||
return;
|
||||
}
|
||||
holder.getVal1Txt().setText(values.getValue1(arrayListItems.get(position)));
|
||||
holder.getVal2Txt().setText(values.getValue2(arrayListItems.get(position)));
|
||||
holder.getVal2Txt().setVisibility(View.VISIBLE);
|
||||
return;
|
||||
}
|
||||
if (isObjArr) {
|
||||
if (!hasTwoVal) {
|
||||
holder.getVal1Txt().setText(value.getValue(listObj[position]));
|
||||
return;
|
||||
}
|
||||
holder.getVal1Txt().setText(values.getValue1(listObj[position]));
|
||||
holder.getVal2Txt().setText(values.getValue2(listObj[position]));
|
||||
holder.getVal2Txt().setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkSelected(@NonNull DefaultListAdapterGeneric.ViewHolder holder, T obj){
|
||||
if (!selectedItems.contains(obj))
|
||||
selectItem(holder,obj);
|
||||
else deselectItem(holder,obj);
|
||||
}
|
||||
|
||||
private void selectItem(@NonNull DefaultListAdapterGeneric.ViewHolder holder, T obj){
|
||||
selectedItems.add(obj);
|
||||
setItemResource(holder, itemBgResSelected);
|
||||
setItemColor(holder,listItemBgColorSelected);
|
||||
|
||||
}
|
||||
|
||||
private void deselectItem(@NonNull DefaultListAdapterGeneric.ViewHolder holder, T obj){
|
||||
selectedItems.remove(obj);
|
||||
setItemResource(holder,itemBgRes);
|
||||
setItemColor(holder,listItemBgColor);
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
return arrayListItems.size();
|
||||
if (isObjArr)
|
||||
return listObj.length;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.sjapps.library.customdialog;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.sjapps.library.R;
|
||||
|
||||
public class functions {
|
||||
public static void SetDialogSize(@NonNull Context context, Dialog dialog, int maxWidth){
|
||||
Configuration configuration = context.getResources().getConfiguration();
|
||||
int width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
int height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
|
||||
if (configuration.screenWidthDp > maxWidth)
|
||||
width = dpToPixels(context,maxWidth);
|
||||
|
||||
dialog.getWindow().setLayout(width, height);
|
||||
|
||||
}
|
||||
public static int dpToPixels(@NonNull Context context, float dp) {
|
||||
Resources r = context.getResources();
|
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.sjapps.library.customdialog.list.events;
|
||||
|
||||
public interface ListItemClick {
|
||||
void onClick(int position, String value);
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.sjapps.library.customdialog.list.events;
|
||||
|
||||
public interface ListItemClickObj<T> {
|
||||
void onClick(int position, T obj);
|
||||
}
|
||||
Reference in New Issue
Block a user