@@ -27,10 +27,12 @@ public class EmptyLayout {
2727 private int mErrorMessageViewId ;
2828 private int mEmptyMessageViewId ;
2929 private int mLoadingMessageViewId ;
30-
31- private View .OnClickListener mLoadingViewClickListener ;
32- private View .OnClickListener mEmptyViewClickListener ;
33- private View .OnClickListener mErrorViewClickListener ;
30+ private LayoutInflater mInflater ;
31+ private boolean mViewsAdded ;
32+ private int mLoadingAnimationViewId ;
33+ private View .OnClickListener mLoadingButtonClickListener ;
34+ private View .OnClickListener mEmptyButtonClickListener ;
35+ private View .OnClickListener mErrorButtonClickListener ;
3436
3537 // ---------------------------
3638 // static variables
@@ -55,9 +57,12 @@ public class EmptyLayout {
5557 private String mErrorMessage = "Oops! Something wrong happened" ;
5658 private String mEmptyMessage = "No items yet" ;
5759 private String mLoadingMessage = "Please wait" ;
58- private LayoutInflater mInflater ;
59- private boolean mViewsAdded ;
60- private int mLoadingAnimationViewId ;
60+ private int mLoadingViewButtonId = R .id .buttonLoading ;
61+ private int mErrorViewButtonId = R .id .buttonError ;
62+ private int mEmptyViewButtonId = R .id .buttonEmpty ;
63+ private boolean mShowEmptyButton = true ;
64+ private boolean mShowLoadingButton = true ;
65+ private boolean mShowErrorButton = true ;
6166
6267 // ---------------------------
6368 // getters and setters
@@ -283,69 +288,161 @@ public int getLoadingAnimationViewId() {
283288 */
284289 public void setLoadingAnimationViewId (int loadingAnimationViewId ) {
285290 this .mLoadingAnimationViewId = loadingAnimationViewId ;
286- }
291+ }
292+
293+ /**
294+ * Gets the OnClickListener which perform when LoadingView was click
295+ * @return
296+ */
297+ public View .OnClickListener getLoadingButtonClickListener () {
298+ return mLoadingButtonClickListener ;
299+ }
287300
288301 /**
289302 * Sets the OnClickListener to LoadingView
290- * @param loadingViewClickListener OnClickListener Object
303+ * @param loadingButtonClickListener OnClickListener Object
304+ */
305+ public void setLoadingButtonClickListener (View .OnClickListener loadingButtonClickListener ) {
306+ this .mLoadingButtonClickListener = loadingButtonClickListener ;
307+ }
308+
309+ /**
310+ * Gets the OnClickListener which perform when EmptyView was click
311+ * @return
291312 */
292- public void setLoadingViewClickListener (View .OnClickListener loadingViewClickListener ) {
293- this .mLoadingViewClickListener = loadingViewClickListener ;
294- if (mLoadingView != null )
295- mLoadingView .setOnClickListener (mLoadingViewClickListener );
313+ public View .OnClickListener getEmptyButtonClickListener () {
314+ return mEmptyButtonClickListener ;
296315 }
297316
298317 /**
299318 * Sets the OnClickListener to EmptyView
300- * @param emptyViewClickListener OnClickListener Object
319+ * @param emptyButtonClickListener OnClickListener Object
320+ */
321+ public void setEmptyButtonClickListener (View .OnClickListener emptyButtonClickListener ) {
322+ this .mEmptyButtonClickListener = emptyButtonClickListener ;
323+ }
324+
325+ /**
326+ * Gets the OnClickListener which perform when ErrorView was click
327+ * @return
301328 */
302- public void setEmptyViewClickListener (View .OnClickListener emptyViewClickListener ) {
303- this .mEmptyViewClickListener = emptyViewClickListener ;
304- if (mEmptyView != null )
305- mEmptyView .setOnClickListener (mEmptyViewClickListener );
329+ public View .OnClickListener getErrorButtonClickListener () {
330+ return mErrorButtonClickListener ;
306331 }
307332
308333 /**
309334 * Sets the OnClickListener to ErrorView
310- * @param errorViewClickListener OnClickListener Object
335+ * @param errorButtonClickListener OnClickListener Object
311336 */
312- public void setErrorViewClickListener (View .OnClickListener errorViewClickListener ) {
313- this .mErrorViewClickListener = errorViewClickListener ;
314- if (mErrorView != null )
315- mErrorView .setOnClickListener (mErrorViewClickListener );
337+ public void setErrorButtonClickListener (View .OnClickListener errorButtonClickListener ) {
338+ this .mErrorButtonClickListener = errorButtonClickListener ;
316339 }
317340
341+ /**
342+ * Gets if a button is shown in the empty view
343+ * @return if a button is shown in the empty view
344+ */
345+ public boolean isEmptyButtonShown () {
346+ return mShowEmptyButton ;
347+ }
318348
319349 /**
320- * Gets the OnClickListener which perform when LoadingView was click
321- * @return
350+ * Sets if a button will be shown in the empty view
351+ * @param showEmptyButton will a button be shown in the empty view
322352 */
323- public View . OnClickListener getLoadingViewClickListener ( ) {
324- return mLoadingViewClickListener ;
325- }
353+ public void setEmptyButtonShown ( boolean showEmptyButton ) {
354+ this . mShowEmptyButton = showEmptyButton ;
355+ }
326356
357+ /**
358+ * Gets if a button is shown in the loading view
359+ * @return if a button is shown in the loading view
360+ */
361+ public boolean isLoadingButtonShown () {
362+ return mShowLoadingButton ;
363+ }
327364
328- /**
329- * Gets the OnClickListener which perform when EmptyView was click
330- * @return
365+ /**
366+ * Sets if a button will be shown in the loading view
367+ * @param showEmptyButton will a button be shown in the loading view
331368 */
332- public View . OnClickListener getEmptyViewClickListener ( ) {
333- return mEmptyViewClickListener ;
334- }
369+ public void setLoadingButtonShown ( boolean showLoadingButton ) {
370+ this . mShowLoadingButton = showLoadingButton ;
371+ }
335372
373+ /**
374+ * Gets if a button is shown in the error view
375+ * @return if a button is shown in the error view
376+ */
377+ public boolean isErrorButtonShown () {
378+ return mShowErrorButton ;
379+ }
336380
337- /**
338- * Gets the OnClickListener which perform when ErrorView was click
339- * @return
381+ /**
382+ * Sets if a button will be shown in the error view
383+ * @param showEmptyButton will a button be shown in the error view
340384 */
341- public View .OnClickListener getErrorViewClickListener () {
342- return mErrorViewClickListener ;
343- }
385+ public void setErrorButtonShown (boolean showErrorButton ) {
386+ this .mShowErrorButton = showErrorButton ;
387+ }
388+
389+ /**
390+ * Gets the ID of the button in the loading view
391+ * @return the ID of the button in the loading view
392+ */
393+ public int getmLoadingViewButtonId () {
394+ return mLoadingViewButtonId ;
395+ }
396+
397+ /**
398+ * Sets the ID of the button in the loading view. This ID is required if you want the button the loading view to be click-able.
399+ * @param loadingViewButtonId the ID of the button in the loading view
400+ */
401+ public void setLoadingViewButtonId (int loadingViewButtonId ) {
402+ this .mLoadingViewButtonId = loadingViewButtonId ;
403+ }
404+
405+ /**
406+ * Gets the ID of the button in the error view
407+ * @return the ID of the button in the error view
408+ */
409+ public int getErrorViewButtonId () {
410+ return mErrorViewButtonId ;
411+ }
412+
413+ /**
414+ * Sets the ID of the button in the error view. This ID is required if you want the button the error view to be click-able.
415+ * @param errorViewButtonId the ID of the button in the error view
416+ */
417+ public void setErrorViewButtonId (int errorViewButtonId ) {
418+ this .mErrorViewButtonId = errorViewButtonId ;
419+ }
420+
421+ /**
422+ * Gets the ID of the button in the empty view
423+ * @return the ID of the button in the empty view
424+ */
425+ public int getEmptyViewButtonId () {
426+ return mEmptyViewButtonId ;
427+ }
428+
429+ /**
430+ * Sets the ID of the button in the empty view. This ID is required if you want the button the empty view to be click-able.
431+ * @param emptyViewButtonId the ID of the button in the empty view
432+ */
433+ public void setEmptyViewButtonId (int emptyViewButtonId ) {
434+ this .mEmptyViewButtonId = emptyViewButtonId ;
435+ }
436+
437+
438+
439+
440+
344441
345442 // ---------------------------
346443 // private methods
347444 // ---------------------------
348-
445+
349446 private void changeEmptyType () {
350447
351448 setDefaultValues ();
@@ -419,15 +516,48 @@ private void setDefaultValues() {
419516 if (mEmptyView ==null ) {
420517 mEmptyView = (ViewGroup ) mInflater .inflate (R .layout .view_empty , null );
421518 if (!(mEmptyMessageViewId >0 )) mEmptyMessageViewId = R .id .textViewMessage ;
519+ if (mShowEmptyButton && mEmptyViewButtonId >0 && mEmptyButtonClickListener !=null ) {
520+ View emptyViewButton = mEmptyView .findViewById (mEmptyViewButtonId );
521+ if (emptyViewButton != null ) {
522+ emptyViewButton .setOnClickListener (mEmptyButtonClickListener );
523+ emptyViewButton .setVisibility (View .VISIBLE );
524+ }
525+ }
526+ else if (mEmptyViewButtonId >0 ) {
527+ View emptyViewButton = mEmptyView .findViewById (mEmptyViewButtonId );
528+ emptyViewButton .setVisibility (View .GONE );
529+ }
422530 }
423531 if (mLoadingView ==null ) {
424532 mLoadingView = (ViewGroup ) mInflater .inflate (R .layout .view_loading , null );
425533 mLoadingAnimationViewId = R .id .imageViewLoading ;
426534 if (!(mLoadingMessageViewId >0 )) mLoadingMessageViewId = R .id .textViewMessage ;
535+ if (mShowLoadingButton && mLoadingViewButtonId >0 && mLoadingButtonClickListener !=null ) {
536+ View loadingViewButton = mLoadingView .findViewById (mLoadingViewButtonId );
537+ if (loadingViewButton != null ) {
538+ loadingViewButton .setOnClickListener (mLoadingButtonClickListener );
539+ loadingViewButton .setVisibility (View .VISIBLE );
540+ }
541+ }
542+ else if (mLoadingViewButtonId >0 ) {
543+ View loadingViewButton = mLoadingView .findViewById (mLoadingViewButtonId );
544+ loadingViewButton .setVisibility (View .GONE );
545+ }
427546 }
428547 if (mErrorView ==null ) {
429548 mErrorView = (ViewGroup ) mInflater .inflate (R .layout .view_error , null );
430549 if (!(mErrorMessageViewId >0 )) mErrorMessageViewId = R .id .textViewMessage ;
550+ if (mShowErrorButton && mErrorViewButtonId >0 && mErrorButtonClickListener !=null ) {
551+ View errorViewButton = mErrorView .findViewById (mErrorViewButtonId );
552+ if (errorViewButton != null ) {
553+ errorViewButton .setOnClickListener (mErrorButtonClickListener );
554+ errorViewButton .setVisibility (View .VISIBLE );
555+ }
556+ }
557+ else if (mErrorViewButtonId >0 ) {
558+ View errorViewButton = mErrorView .findViewById (mErrorViewButtonId );
559+ errorViewButton .setVisibility (View .GONE );
560+ }
431561 }
432562 }
433563
0 commit comments