Skip to content

Commit

Permalink
## adding dialog list
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadnomany25 committed Sep 15, 2019
1 parent eca4b04 commit 787f0eb
Show file tree
Hide file tree
Showing 15 changed files with 353 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 38 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,35 +178,42 @@ setCodeTypeListener(new DialogPlus.CodeTypeListener() {
### 4.2 Override any of these resources to set the dialog attributes for whole project
#### Dimensions
````
<dimen name="dialog_corner_radius">15dp</dimen>
<dimen name="dialog_margin">@dimen/_30sdp</dimen>
<dimen name="dialog_timeup_text_size">@dimen/_10ssp</dimen>
<dimen name="dialog_corner_radius">15dp</dimen>
<dimen name="dialog_margin">@dimen/_30sdp</dimen>
<dimen name="dialog_timeup_text_size">@dimen/_10ssp</dimen>

<dimen name="dialog_header_height">@dimen/_40sdp</dimen>
<dimen name="dialog_header_text_size">@dimen/_14ssp</dimen>
<dimen name="dialog_header_padding">@dimen/_8sdp</dimen>
<dimen name="dialog_header_height">@dimen/_40sdp</dimen>
<dimen name="dialog_header_text_size">@dimen/_14ssp</dimen>
<dimen name="dialog_header_padding">@dimen/_8sdp</dimen>

<dimen name="dialog_content_margin">@dimen/_15sdp</dimen>
<dimen name="dialog_content_message_text_size">@dimen/_12ssp</dimen>
<dimen name="dialog_content_margin">@dimen/_15sdp</dimen>
<dimen name="dialog_content_message_text_size">@dimen/_12ssp</dimen>

<dimen name="dialog_action_buttons_margin">@dimen/_10sdp</dimen>
<dimen name="dialog_action_button_corner">50dp</dimen>
<dimen name="dialog_action_buttons_height">@dimen/_35sdp</dimen>
<!-- space for showing elevation-->
<dimen name="dialog_action_buttons_bottom_margin">2dp</dimen>
<dimen name="dialog_list_item_text_size">@dimen/_12ssp</dimen>

<dimen name="dialog_action_button_textSize">@dimen/_12ssp</dimen>
<dimen name="dialog_action_buttons_margin">@dimen/_10sdp</dimen>
<dimen name="dialog_action_button_corner">50dp</dimen>
<dimen name="dialog_action_buttons_height">@dimen/_35sdp</dimen>
<!-- space for showing elevation-->
<dimen name="dialog_action_buttons_bottom_margin">2dp</dimen>

<dimen name="dialog_positive_button_elevation">1dp</dimen>
<dimen name="dialog_action_button_textSize">@dimen/_12ssp</dimen>

<dimen name="dialog_negative_button_stroke">1dp</dimen>
<dimen name="dialog_negative_button_elevation">0dp</dimen>
<dimen name="dialog_positive_button_elevation">1dp</dimen>

<dimen name="dialog_close_icon_radius">@dimen/_16sdp</dimen>
<dimen name="dialog_zero">0dp</dimen>
<dimen name="dialog_code_entry_margin">@dimen/_8sdp</dimen>

<dimen name="dialog_options_header_padding">@dimen/_7sdp</dimen>
<dimen name="dialog_negative_button_stroke">1dp</dimen>
<dimen name="dialog_negative_button_elevation">0dp</dimen>

<dimen name="dialog_close_icon_radius">@dimen/_16sdp</dimen>
<dimen name="dialog_zero">0dp</dimen>
<dimen name="dialog_code_entry_margin">@dimen/_8sdp</dimen>
<dimen name="dialog_elevation">1dp</dimen>

<dimen name="dialog_options_header_padding">@dimen/_7sdp</dimen>

<dimen name="dialog_list_row_margin_top">@dimen/_4sdp</dimen>
<dimen name="dialog_list_row_margin_start">@dimen/_8sdp</dimen>
<dimen name="dialog_list_separator_margin">@dimen/_16sdp</dimen>
````
#### Integers
````
Expand All @@ -223,6 +230,8 @@ setCodeTypeListener(new DialogPlus.CodeTypeListener() {
<color name="titleTextColor">@color/dialogPositiveTextColor</color>
<color name="dialogContentTextColor">@color/colorAccent</color>

<color name="dialogListItemTextColor">@color/colorAccent</color>

<color name="dialogTransparent">#00000000</color>

<color name="dialogNegativeBgColor">@color/dialogTransparent</color>
Expand Down Expand Up @@ -277,6 +286,13 @@ setCodeTypeListener(new DialogPlus.CodeTypeListener() {
<item name="android:textAllCaps">false</item>
</style>

<style name="dialog_list_item_text_style" parent="@android:style/TextAppearance">
<item name="android:textSize">@dimen/dialog_list_item_text_size</item>
<item name="android:textColor">@color/dialogListItemTextColor</item>
<item name="android:textStyle">normal</item>
<item name="android:textAllCaps">false</item>
</style>


<style name="dialog_positive_button_style" parent="@android:style/TextAppearance">
<item name="android:text">@string/dialog_positive_text</item>
Expand Down
35 changes: 35 additions & 0 deletions app/src/main/java/com/sample/dialogSample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,41 @@ public void onClickedSuccessDialog(View view) {
.show(this.getSupportFragmentManager(), "dialog_plus");
}

public void onListDialogClicked(View view) {
new DialogPlus()
.setListDialog("list_dialog_test_title", getListItems(), new DialogPlus.DialogListListener() {
@Override
public void onItemClicked(String title, int index, DialogPlus dialogPlus) {
Toast.makeText(MainActivity.this, title, Toast.LENGTH_SHORT).show();
dialogPlus.dismiss();
}
})
.show(this.getSupportFragmentManager(), "dialog_plus");
}

private List<String> getListItems() {
List<String> dialogItemDMS = new ArrayList<>();
dialogItemDMS.add("title 4");
dialogItemDMS.add(("title 4"));
dialogItemDMS.add(("title 7"));
dialogItemDMS.add(("title 9"));
dialogItemDMS.add(("title 4"));
dialogItemDMS.add(("title 4"));
dialogItemDMS.add(("title 4"));
dialogItemDMS.add(("title 4"));
dialogItemDMS.add(("title 54"));
dialogItemDMS.add(("title 4"));
dialogItemDMS.add(("title 4"));
dialogItemDMS.add(("title 4"));
dialogItemDMS.add(("title 4"));
dialogItemDMS.add(("title 4"));
dialogItemDMS.add(("title 4"));
dialogItemDMS.add(("title 4"));


return dialogItemDMS;
}

private class DialogListener extends DialogPlus.DialogActionListener {
@Override
public void onPositive(DialogPlus dialogPlus) {
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="onListDialogClicked"
android:text="Show List Dialog"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</LinearLayout>
4 changes: 2 additions & 2 deletions dialogPlus/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ext {
//library name will be like -> publishedGroupId:artifact:libraryVersion
publishedGroupId = 'com.dialog' //the ID you want to add in the 'implementation line'
artifact = 'plus' //the artifact you want to add in the 'implementation line'
libraryVersion = '3.3.1'
libraryVersion = '3.3.2'
libraryDescription = 'An Android library that lets you show Dialog in a custom simple and fast way.'

siteUrl = 'https://github.com/ma7madfawzy/DialogPlus'
Expand All @@ -42,7 +42,7 @@ android {
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "3.3.1"
versionName "3.3.2"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
56 changes: 55 additions & 1 deletion dialogPlus/src/main/java/com/dialog/plus/ui/DialogPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;
import com.dialog.plus.R;
import com.dialog.plus.databinding.DialogPlusBinding;
import com.dialog.plus.ui.list_dialog.ListAdapter;
import com.dialog.plus.utils.KeyboardUtil;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;

/**
* Created by Muhammad Noamany
Expand All @@ -38,6 +43,8 @@ public class DialogPlus extends BaseDialogFragment<DialogPlusBinding> implements
private int dialog_type;
private CodeTypeListener codeTypeListener;
private DialogActionListener dialogActionListener;
private DialogListListener dialogListListener;
private List<String> listDialogItems = new ArrayList<>();
private String title, content, correct_code, positiveText, negativeText;
private int counterSeconds;
@ColorRes
Expand All @@ -51,6 +58,10 @@ public class DialogPlus extends BaseDialogFragment<DialogPlusBinding> implements
@ColorInt
private int dialogCodeTextColor = Color.BLACK;

public DialogPlus() {
this(null, null);
}

public DialogPlus(String content) {
this(null, content);
}
Expand Down Expand Up @@ -100,6 +111,20 @@ public DialogPlus setMessageDialog(String positiveText, DialogActionListener act
return setMessageDialog(positiveText).setDialogActionListener(actionClicked);
}

/**
* Sets a list dialog_plus interface
*/
public DialogPlus setListDialog(String title, List<String> listItems, DialogListListener actionClicked) {
return setDialog_type(TYPE.LIST_DIALOG).setTitle(title).setListItems(listItems).setDialogListListener(actionClicked);

}

private DialogPlus setListItems(List<String> listItems) {
if (listDialogItems.size() > 0) listDialogItems.clear();
listDialogItems = listItems;
return this;
}

/**
* Sets an Error dialog_plus interface
*/
Expand Down Expand Up @@ -153,6 +178,8 @@ int getDialogLayoutRes() {
return R.layout.layout_error_dialog;
case TYPE.SUCCESS_DIALOG:
return R.layout.layout_success_dialog;
case TYPE.LIST_DIALOG:
return R.layout.layout_dialog_list;
}
return R.layout.layout_confirmation_dialog;
}
Expand All @@ -179,9 +206,18 @@ private void setDialogType() {
setSuccessAnimation();
checkTexts();
break;
case TYPE.LIST_DIALOG:
renderItemsList();
break;
}
}

private void renderItemsList() {
ListAdapter listAdapter = new ListAdapter(this, listDialogItems, dialogListListener);
((RecyclerView) getDialogAddedView(R.id.recycler)).setLayoutManager(new LinearLayoutManager(getActivity(), RecyclerView.VERTICAL, false));
((RecyclerView) getDialogAddedView(R.id.recycler)).setAdapter(listAdapter);
}

private void checkTexts() {
changePositiveText();
if (dialog_type == TYPE.CONFIRMATION)
Expand Down Expand Up @@ -297,7 +333,7 @@ private void setListeners() {
if (dialog_type == TYPE.SUCCESS_DIALOG || dialog_type == TYPE.ERROR_DIALOG) {
getDialogAddedView(R.id.closeIV).setOnClickListener(this);
getDialogAddedView(R.id.confirmButton).setOnClickListener(this);
} else {
} else if (dialog_type == TYPE.CODE || dialog_type == TYPE.CONFIRMATION || dialog_type == TYPE.MESSAGE) {
getHeaderChildView(R.id.closeIV).setOnClickListener(this);
if (dialog_type == TYPE.CODE) {
getDialogAddedView(R.id.sendCode).setOnClickListener(this);
Expand All @@ -308,6 +344,8 @@ private void setListeners() {
getDialogAddedView(R.id.cancelButton).setOnClickListener(this);
}

} else {
getHeaderChildView(R.id.closeIV).setOnClickListener(this);
}
}

Expand Down Expand Up @@ -600,6 +638,11 @@ public DialogPlus setDialogActionListener(DialogActionListener dialogActionListe
return this;
}

public DialogPlus setDialogListListener(DialogListListener dialogListListener) {
this.dialogListListener = dialogListListener;
return this;
}

public DialogPlus setContent(String content) {
this.content = content;
return this;
Expand Down Expand Up @@ -645,6 +688,7 @@ public int getLayoutId() {
int MESSAGE = 2;
int ERROR_DIALOG = 3;
int SUCCESS_DIALOG = 4;
int LIST_DIALOG = 5;
}

/**
Expand All @@ -669,4 +713,14 @@ public void onNegative(DialogPlus dialogPlus) {
dialogPlus.dismiss(true);
}
}

public abstract static class DialogListListener {

public void onNegative(DialogPlus dialogPlus) {
dialogPlus.dismiss(true);
}

public void onItemClicked(String title, int index, DialogPlus dialogPlus) {
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.dialog.plus.ui.list_dialog;

import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

/**
* Created by fawzy on 8/31/18.
*/

public class BaseHolder extends RecyclerView.ViewHolder {
public View foregroundView;

public BaseHolder(View itemView) {
super(itemView);
}

public void setForegroundView(View foregroundView) {
this.foregroundView = foregroundView;
}

public void bind(int position) {

}
}
Loading

0 comments on commit 787f0eb

Please sign in to comment.