Skip to content

Commit

Permalink
## Optimizing Code
Browse files Browse the repository at this point in the history
  • Loading branch information
fawzy committed Sep 17, 2019
1 parent 9abe983 commit 5ce836e
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 55 deletions.
3 changes: 0 additions & 3 deletions .idea/gradle.xml

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

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,21 @@ new DialogPlus("Message Dialog", "message dialog sample\n Welcome Back")
})
.show(this.getSupportFragmentManager(), "dialog_plus");
```
### 2.8 Year Picker Dialog:

```
new MonthYearPickerDialog().getYearPicker(pickedYear ->
Toast.makeText(this, "picked month: " + pickedYear, Toast.LENGTH_SHORT).show())
.show(getSupportFragmentManager(), "dialog");
```
### 2.9 Month Picker Dialog:

```
new MonthYearPickerDialog().getMonthPicker(pickedYear ->
Toast.makeText(this, "picked year: " + pickedYear, Toast.LENGTH_SHORT).show())
.show(getSupportFragmentManager(), "dialog");
```
### 3 Listeners:

```setDialogActionListener(DialogPlus.DialogActionListener)```
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/java/com/sample/dialogSample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,19 @@ private List<String> getListItems() {
dialogItemDMS.add(("title 4"));
dialogItemDMS.add(("title 4"));
dialogItemDMS.add(("title 4"));


return dialogItemDMS;
}

public void onMonthYearDialogClicked(View view) {
new MonthYearPickerDialog().getYearPicker(pickedYear ->
Toast.makeText(this, "picked value: " + pickedYear, Toast.LENGTH_SHORT).show()).show(getSupportFragmentManager(), "dialog");
Toast.makeText(this, "picked month: " + pickedYear, Toast.LENGTH_SHORT).show())
.show(getSupportFragmentManager(), "dialog");
}

public void onMonthMonthDialogClicked(View view) {
new MonthYearPickerDialog().getMonthPicker(pickedYear ->
Toast.makeText(this, "picked year: " + pickedYear, Toast.LENGTH_SHORT).show())
.show(getSupportFragmentManager(), "dialog");
}

private class DialogListener extends DialogPlus.DialogActionListener {
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,22 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="onMonthYearDialogClicked"
android:text="Show Month Year Dialog"
android:text="Show Year Year Dialog"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
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="onMonthMonthDialogClicked"
android:text="Show Month 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.2'
libraryVersion = '3.3.3'
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.2"
versionName "3.3.3"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
5 changes: 2 additions & 3 deletions dialogPlus/src/main/java/com/dialog/plus/ui/DialogPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
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;
Expand Down Expand Up @@ -213,9 +212,9 @@ private void setDialogType() {
}

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

private void checkTexts() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dialog.plus.ui.list_dialog;
package com.dialog.plus.ui;

import android.view.LayoutInflater;
import android.view.ViewGroup;
Expand All @@ -8,22 +8,20 @@

import com.dialog.plus.R;
import com.dialog.plus.databinding.ListDialogRowBinding;
import com.dialog.plus.ui.DialogPlus;

import java.util.ArrayList;
import java.util.List;

/**
* Created by Muhammad Noamany on 25,March,2019
*/
public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ViewHolder> {
class ListDialogAdapter extends RecyclerView.Adapter<ListDialogAdapter.ViewHolder> {
private ArrayList<String> dataList;
private ListDialogRowBinding binding;
private LayoutInflater layoutInflater;
private DialogPlus dialogPlus;
private DialogPlus.DialogListListener onItemClickListener;

public ListAdapter(DialogPlus dialogPlus, List<String> dataList, DialogPlus.DialogListListener onItemClickListener) {
public ListDialogAdapter(DialogPlus dialogPlus, List<String> dataList, DialogPlus.DialogListListener onItemClickListener) {
super();
this.dataList = new ArrayList<>(dataList);
this.onItemClickListener = onItemClickListener;
Expand All @@ -37,19 +35,17 @@ public void setDataList(List<String> list) {


@Override
public ListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
renderView(layoutInflater, parent);
return new ListAdapter.ViewHolder(binding);
public ListDialogAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
renderView(LayoutInflater.from(parent.getContext()), parent);
return new ListDialogAdapter.ViewHolder(binding);
}

protected void renderView(LayoutInflater layoutInflater, ViewGroup parent) {
if (layoutInflater == null)
layoutInflater = LayoutInflater.from(parent.getContext());
binding = DataBindingUtil.inflate(layoutInflater, R.layout.list_dialog_row, parent, false);
}

@Override
public void onBindViewHolder(ListAdapter.ViewHolder holder, int position) {
public void onBindViewHolder(ListDialogAdapter.ViewHolder holder, int position) {
holder.bind(position);


Expand All @@ -64,24 +60,26 @@ public List<String> getData() {
return dataList;
}

public class ViewHolder extends BaseHolder {
public class ViewHolder extends RecyclerView.ViewHolder {
private ListDialogRowBinding binding;

public ViewHolder(ListDialogRowBinding binding) {
super(binding.getRoot());
this.binding = binding;
setListener();
}

private void setListener() {
if (onItemClickListener != null)
this.binding.item.setOnClickListener(v -> {
onItemClickListener.onItemClicked(dataList.get(getAdapterPosition()), getAdapterPosition(), dialogPlus);
});
}

@Override
public void bind(int position) {
super.bind(position);
binding.setTitle(dataList.get(getAdapterPosition()));
if (getAdapterPosition() == dataList.size() - 1) binding.dages.setHidden(true);
else binding.dages.setHidden(false);
if (onItemClickListener != null)
this.binding.item.setOnClickListener(v -> {
onItemClickListener.onItemClicked(dataList.get(getAdapterPosition()),getAdapterPosition(), dialogPlus);
});
}

}
Expand Down

This file was deleted.

0 comments on commit 5ce836e

Please sign in to comment.