Skip to content

Commit b84c8a3

Browse files
author
jarzul
committed
Doc: Added Javadoc on the two classes
1 parent 8f777cf commit b84c8a3

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

simpledialogfragment/src/main/java/com/julienarzul/simpledialogfragment/SimpleDialogContent.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
import com.google.auto.value.AutoValue;
77

88
/**
9-
* Created by Julien Arzul on 13/12/2016.
9+
* Immutable value class that represents the content of an AlertDialog shown with {@link SimpleDialogFragment}.
10+
* The class is Parcelable in order to be given to the DialogFragment as a bundle argument.
11+
* <p>
12+
* Create an instance of this class with a {@link SimpleDialogContent.Builder}, retrieved through the static method
13+
* {@link #builder()}.
14+
* <p>
15+
* The only required @NotNull field is the message of the dialog.
16+
* <p>
1017
* Copyright @ Julien Arzul 2016
1118
*/
1219
@AutoValue

simpledialogfragment/src/main/java/com/julienarzul/simpledialogfragment/SimpleDialogFragment.java

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,36 @@
88
import android.support.v4.app.DialogFragment;
99
import android.support.v4.app.Fragment;
1010
import android.support.v4.app.FragmentActivity;
11+
import android.support.v4.app.FragmentManager;
1112
import android.support.v4.util.Pair;
1213
import android.support.v7.app.AlertDialog;
1314
import android.text.TextUtils;
1415

1516
/**
16-
* Created by Julien Arzul on 09/11/2016.
17+
* Simple implementation of a {@link DialogFragment} that allows you to specify the content of the {@link AlertDialog}
18+
* displayed without subclassing it.
19+
* <p>
20+
* This DialogFragment must be instantiated with a {@link SimpleDialogContent} via the factory method {@link
21+
* #newInstance(SimpleDialogContent)}
22+
* <p>
23+
* You can easily define listeners for the buttons set in the {@link SimpleDialogContent} with one of the two methods:
24+
* <ul>
25+
* <li>the enclosing activity must implement one or more of the listener interfaces</li>
26+
* <li>the enclosing fragment must be set as the targetFragment of the {@link SimpleDialogFragment} and implement one
27+
* or more of the listener interfaces</li>
28+
* </ul>
29+
* <p>
30+
* There are three different listener interfaces that you can implement:
31+
* <ul>
32+
* <li>{@link OnPositiveButtonClickListener}</li>
33+
* <li>{@link OnNegativeButtonClickListener}</li>
34+
* <li>{@link OnNeutralButtonClickListener}</li>
35+
* </ul>
36+
* If the user chooses to listen to the click on the dialog's button, it is recommended to add a request code to the
37+
* {@link SimpleDialogContent}. That request code will be given to the onClick method and will allow the user to
38+
* determine which {@link SimpleDialogFragment} invoked the method. It is especially useful when a single {@link
39+
* android.app.Activity} or {@link Fragment} needs to display several {@link SimpleDialogFragment}
40+
* <p>
1741
* Copyright @ Julien Arzul 2016
1842
*/
1943
public class SimpleDialogFragment extends DialogFragment implements DialogInterface.OnClickListener {
@@ -26,6 +50,16 @@ public class SimpleDialogFragment extends DialogFragment implements DialogInterf
2650

2751
private SimpleDialogContent dialogContent = null;
2852

53+
/**
54+
* Creates a new instance of a {@link SimpleDialogFragment}. It must be given a {@link SimpleDialogContent} to
55+
* define the {@link AlertDialog} content.
56+
*
57+
* @param dialogContent Instance of {@link SimpleDialogContent} representing the content of the {@link AlertDialog}
58+
* that will be displayed.
59+
*
60+
* @return A new instance of {@link SimpleDialogFragment}. Don't forget to call {{@link #show(FragmentManager,
61+
* String)}} to actually display the {@link DialogFragment}
62+
*/
2963
public static SimpleDialogFragment newInstance(SimpleDialogContent dialogContent) {
3064
Bundle args = new Bundle();
3165

@@ -128,18 +162,48 @@ private <T> Pair<T, Integer> getListener(Class<T> listenerClazz) {
128162
return null;
129163
}
130164

165+
/**
166+
* Interface that must be implemented by the enclosing activity (or target fragment) in order to listen to click on
167+
* the dialog positive's button.
168+
*/
131169
public interface OnPositiveButtonClickListener {
132170

171+
/**
172+
* This method will be invoked when the positive button of the dialog is clicked.
173+
*
174+
* @param dialog The dialog that received the click.
175+
* @param requestCode The request code used to show the {@link SimpleDialogFragment}
176+
*/
133177
void onDialogPositiveButtonClicked(DialogInterface dialog, Integer requestCode);
134178
}
135179

180+
/**
181+
* Interface that must be implemented by the enclosing activity (or target fragment) in order to listen to click on
182+
* the dialog negative's button.
183+
*/
136184
public interface OnNegativeButtonClickListener {
137185

186+
/**
187+
* This method will be invoked when the negative button of the dialog is clicked.
188+
*
189+
* @param dialog The dialog that received the click.
190+
* @param requestCode The request code used to show the {@link SimpleDialogFragment}
191+
*/
138192
void onDialogNegativeButtonClicked(DialogInterface dialog, Integer requestCode);
139193
}
140194

195+
/**
196+
* Interface that must be implemented by the enclosing activity (or target fragment) in order to listen to click on
197+
* the dialog neutral's button.
198+
*/
141199
public interface OnNeutralButtonClickListener {
142200

201+
/**
202+
* This method will be invoked when the neutral button of the dialog is clicked.
203+
*
204+
* @param dialog The dialog that received the click.
205+
* @param requestCode The request code used to show the {@link SimpleDialogFragment}
206+
*/
143207
void onDialogNeutralButtonClicked(DialogInterface dialog, Integer requestCode);
144208
}
145209
}

0 commit comments

Comments
 (0)