From 95140e5e69a9ed3c80529818365f0c32d0bc402c Mon Sep 17 00:00:00 2001 From: santalu <ftsantalu@gmail.com> Date: Mon, 26 Mar 2018 23:21:58 +0300 Subject: [PATCH 1/4] Add textSize attributes --- app/src/main/res/layout/activity_main.xml | 5 +- .../java/com/santalu/emptyview/EmptyView.java | 69 +++++++++++++------ library/src/main/res/layout/empty_view.xml | 48 +++++-------- .../src/main/res/values-sw600dp/dimens.xml | 13 ++-- .../src/main/res/values-sw720dp/dimens.xml | 13 ++-- library/src/main/res/values/attrs.xml | 7 ++ library/src/main/res/values/dimens.xml | 13 ++-- 7 files changed, 91 insertions(+), 77 deletions(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 41b4c2e..fa8d42f 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -11,7 +11,6 @@ app:emptyDrawableTint="@color/colorPrimary" app:emptyFont="@font/allerta" app:emptyText="@string/empty" - app:emptyTitle="@string/empty_title" app:emptyTitleColor="@color/colorPrimary" app:emptyTransition="slide" app:errorBackgroundColor="@color/red" @@ -19,8 +18,10 @@ app:errorButtonTextColor="@color/white" app:errorDrawable="@drawable/ic_sentiment_very_dissatisfied" app:errorDrawableTint="@color/white" - app:errorText="@string/emptyview_error_unknown" + app:errorText="@string/emptyview_unknown_error_text" app:errorTextColor="@color/white" + app:errorTitle="@string/emptyview_unknown_error_title" + app:errorTitleColor="@color/white" app:loadingDrawable="@drawable/ic_sentiment_satisfied" app:loadingStyle="circular" app:loadingText="@string/emptyview_loading" diff --git a/library/src/main/java/com/santalu/emptyview/EmptyView.java b/library/src/main/java/com/santalu/emptyview/EmptyView.java index efbbf69..2ee69f1 100644 --- a/library/src/main/java/com/santalu/emptyview/EmptyView.java +++ b/library/src/main/java/com/santalu/emptyview/EmptyView.java @@ -10,6 +10,7 @@ import android.os.Build; import android.os.Build.VERSION_CODES; import android.support.annotation.ColorInt; +import android.support.annotation.IdRes; import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -24,6 +25,7 @@ import android.text.Html; import android.text.TextUtils; import android.util.AttributeSet; +import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; import android.widget.Button; @@ -84,18 +86,25 @@ public class EmptyView extends ConstraintLayout { private int contentBackgroundColor; private int loadingTint; private int loadingTextColor; + private float loadingTextSize; private int loadingBackgroundColor; private int loadingStyle; private int emptyTint; private int emptyTitleColor; + private float emptyTitleSize; private int emptyTextColor; + private float emptyTextSize; private int emptyBackgroundColor; private int emptyButtonTextColor; + private float emptyButtonTextSize; private int emptyButtonBackgroundColor; private int errorTint; private int errorTitleColor; + private float errorTitleSize; private int errorTextColor; + private float errorTextSize; private int errorButtonTextColor; + private float errorButtonTextSize; private int errorButtonBackgroundColor; private int errorBackgroundColor; private int state; @@ -147,7 +156,7 @@ public EmptyView(Context context, AttributeSet attrs, int defStyleAttr) { this.onClickListener = onClickListener; } - public void exclude(int... ids) { + public void exclude(@IdRes int... ids) { for (int id : ids) { View view = findViewById(id); if (childViews.contains(view)) { @@ -325,9 +334,14 @@ private void init(@NonNull AttributeSet attrs) { // gravity = a.getInt(R.styleable.EmptyView_emptyGravity, CENTER); + float defaultTitleTextSize = getResources().getDimension(R.dimen.emptyview_title_text_size); + float defaultTextSize = getResources().getDimension(R.dimen.emptyview_text_size); + float defaultButtonTextSize = getResources().getDimension(R.dimen.emptyview_button_text_size); + //Loading state attrs loadingText = a.getText(R.styleable.EmptyView_loadingText); loadingTextColor = a.getColor(R.styleable.EmptyView_loadingTextColor, Color.BLACK); + loadingTextSize = a.getDimension(R.styleable.EmptyView_loadingTextSize, defaultTitleTextSize); loadingBackgroundColor = a.getColor(R.styleable.EmptyView_loadingBackgroundColor, 0); loadingDrawable = a.getDrawable(R.styleable.EmptyView_loadingDrawable); loadingTint = a.getColor(R.styleable.EmptyView_loadingTint, 0); @@ -336,31 +350,34 @@ private void init(@NonNull AttributeSet attrs) { //Empty state attrs emptyTitle = a.getText(R.styleable.EmptyView_emptyTitle); emptyTitleColor = a.getColor(R.styleable.EmptyView_emptyTitleColor, Color.BLACK); + emptyTitleSize = a.getDimension(R.styleable.EmptyView_emptyTitleSize, defaultTitleTextSize); emptyText = a.getText(R.styleable.EmptyView_emptyText); emptyTextColor = a.getColor(R.styleable.EmptyView_emptyTextColor, Color.BLACK); + emptyTextSize = a.getDimension(R.styleable.EmptyView_emptyTextSize, defaultTextSize); emptyBackgroundColor = a.getColor(R.styleable.EmptyView_emptyBackgroundColor, 0); emptyDrawable = a.getDrawable(R.styleable.EmptyView_emptyDrawable); emptyTint = a.getColor(R.styleable.EmptyView_emptyDrawableTint, 0); emptyLetterSpacing = a.getFloat(R.styleable.EmptyView_emptyLetterSpacing, 0); emptyLineSpacingExtra = a.getFloat(R.styleable.EmptyView_emptyLineSpacingExtra, 1); - emptyLineSpacingMultiplier = a.getFloat( - R.styleable.EmptyView_emptyLineSpacingMultiplier, 1f); + emptyLineSpacingMultiplier = a.getFloat(R.styleable.EmptyView_emptyLineSpacingMultiplier, 1f); emptyButtonText = a.getText(R.styleable.EmptyView_emptyButtonText); - emptyButtonTextColor = a.getColor(R.styleable.EmptyView_emptyButtonTextColor, - Color.BLACK); - emptyButtonBackgroundColor = a.getColor( - R.styleable.EmptyView_emptyButtonBackgroundColor, 0); + emptyButtonTextColor = a.getColor(R.styleable.EmptyView_emptyButtonTextColor, Color.BLACK); + emptyButtonTextSize = + a.getDimension(R.styleable.EmptyView_emptyButtonTextSize, defaultButtonTextSize); + emptyButtonBackgroundColor = a.getColor(R.styleable.EmptyView_emptyButtonBackgroundColor, 0); //Error state attrs errorTitle = a.getText(R.styleable.EmptyView_errorTitle); errorTitleColor = a.getColor(R.styleable.EmptyView_errorTitleColor, Color.BLACK); + errorTitleSize = a.getDimension(R.styleable.EmptyView_errorTitleSize, defaultTitleTextSize); errorText = a.getText(R.styleable.EmptyView_errorText); errorTextColor = a.getColor(R.styleable.EmptyView_errorTextColor, Color.BLACK); + errorTextSize = a.getDimension(R.styleable.EmptyView_errorTextSize, defaultTextSize); errorButtonText = a.getText(R.styleable.EmptyView_errorButtonText); - errorButtonTextColor = a.getColor(R.styleable.EmptyView_errorButtonTextColor, - Color.BLACK); - errorButtonBackgroundColor = a.getColor( - R.styleable.EmptyView_errorButtonBackgroundColor, 0); + errorButtonTextColor = a.getColor(R.styleable.EmptyView_errorButtonTextColor, Color.BLACK); + errorButtonTextSize = + a.getDimension(R.styleable.EmptyView_errorButtonTextSize, defaultButtonTextSize); + errorButtonBackgroundColor = a.getColor(R.styleable.EmptyView_errorButtonBackgroundColor, 0); errorBackgroundColor = a.getColor(R.styleable.EmptyView_errorBackgroundColor, 0); errorDrawable = a.getDrawable(R.styleable.EmptyView_errorDrawable); errorTint = a.getColor(R.styleable.EmptyView_errorDrawableTint, 0); @@ -386,7 +403,7 @@ private void setupLoadingView() { } } setIcon(loadingDrawable, loadingTint); - setText(loadingText, loadingTextColor); + setText(loadingText, loadingTextColor, loadingTextSize); setTypeface(emptyFont); } @@ -396,18 +413,20 @@ private void setupEmptyView() { super.setOnClickListener(onClickListener); } setIcon(emptyDrawable, emptyTint); - setTitle(emptyTitle, emptyTitleColor); - setText(emptyText, emptyTextColor); - setButton(emptyButtonText, emptyButtonTextColor, emptyButtonBackgroundColor); + setTitle(emptyTitle, emptyTitleColor, emptyTitleSize); + setText(emptyText, emptyTextColor, emptyTextSize); + setButton(emptyButtonText, emptyButtonTextColor, emptyButtonTextSize, + emptyButtonBackgroundColor); setTypeface(emptyFont); } private void setupErrorView() { setBackgroundColor(errorBackgroundColor); setIcon(errorDrawable, errorTint); - setTitle(errorTitle, errorTitleColor); - setText(errorText, errorTextColor); - setButton(errorButtonText, errorButtonTextColor, errorButtonBackgroundColor); + setTitle(errorTitle, errorTitleColor, errorTitleSize); + setText(errorText, errorTextColor, errorTextSize); + setButton(errorButtonText, errorButtonTextColor, errorButtonTextSize, + errorButtonBackgroundColor); setTypeface(emptyFont); } @@ -421,23 +440,29 @@ private void setIcon(@Nullable Drawable drawable, @ColorInt int tint) { } } - private void setTitle(@Nullable CharSequence text, @ColorInt int textColor) { + private void setTitle(@Nullable CharSequence text, @ColorInt int textColor, float textSize) { if (TextUtils.isEmpty(text)) { titleView.setVisibility(GONE); } else { titleView.setVisibility(VISIBLE); titleView.setText(fromHtml(text.toString())); titleView.setTextColor(textColor); + if (textSize != 0) { + titleView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); + } } } - private void setText(@Nullable CharSequence text, @ColorInt int textColor) { + private void setText(@Nullable CharSequence text, @ColorInt int textColor, float textSize) { if (TextUtils.isEmpty(text)) { textView.setVisibility(GONE); } else { textView.setVisibility(VISIBLE); textView.setText(fromHtml(text.toString())); textView.setTextColor(textColor); + if (textSize != 0) { + textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); + } textView.setLineSpacing(emptyLineSpacingExtra, emptyLineSpacingMultiplier); if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { textView.setLetterSpacing(emptyLetterSpacing); @@ -447,6 +472,7 @@ private void setText(@Nullable CharSequence text, @ColorInt int textColor) { private void setButton(@Nullable CharSequence text, @ColorInt int textColor, + float textSize, @ColorInt int backgroundColor) { if (TextUtils.isEmpty(text)) { button.setVisibility(GONE); @@ -457,6 +483,9 @@ private void setButton(@Nullable CharSequence text, if (backgroundColor != 0) { button.setBackgroundColor(backgroundColor); } + if (textSize != 0) { + button.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); + } button.setOnClickListener(onClickListener); } } diff --git a/library/src/main/res/layout/empty_view.xml b/library/src/main/res/layout/empty_view.xml index e0e3440..7716cd9 100644 --- a/library/src/main/res/layout/empty_view.xml +++ b/library/src/main/res/layout/empty_view.xml @@ -7,14 +7,13 @@ android:id="@+id/empty_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/emptyview_spacing_medium" - android:layout_marginEnd="@dimen/emptyview_spacing_medium" - android:layout_marginStart="@dimen/emptyview_spacing_medium" - android:layout_marginTop="@dimen/emptyview_spacing_medium" + android:layout_marginBottom="@dimen/emptyview_inline_spacing" + android:layout_marginEnd="@dimen/emptyview_outline_spacing" + android:layout_marginStart="@dimen/emptyview_outline_spacing" + android:layout_marginTop="@dimen/emptyview_outline_spacing" android:visibility="gone" app:layout_constraintBottom_toTopOf="@+id/empty_progress_bar" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_chainStyle="packed"/> @@ -23,49 +22,41 @@ android:id="@+id/empty_progress_bar" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/emptyview_spacing_medium" - android:layout_marginEnd="@dimen/emptyview_spacing_medium" - android:layout_marginStart="@dimen/emptyview_spacing_medium" + android:layout_marginBottom="@dimen/emptyview_inline_spacing" + android:layout_marginEnd="@dimen/emptyview_outline_spacing" + android:layout_marginStart="@dimen/emptyview_outline_spacing" android:visibility="gone" app:layout_constraintBottom_toTopOf="@+id/empty_title" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/empty_icon"/> <TextView android:id="@+id/empty_title" - android:layout_width="wrap_content" + android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/emptyview_spacing_medium" - android:layout_marginEnd="@dimen/emptyview_spacing_medium" - android:layout_marginStart="@dimen/emptyview_spacing_medium" + android:layout_marginEnd="@dimen/emptyview_outline_spacing" + android:layout_marginStart="@dimen/emptyview_outline_spacing" android:gravity="center" - android:paddingEnd="@dimen/emptyview_spacing_medium" - android:paddingStart="@dimen/emptyview_spacing_medium" android:textSize="@dimen/emptyview_title_text_size" android:visibility="gone" app:layout_constraintBottom_toTopOf="@+id/empty_text" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/empty_progress_bar"/> <TextView android:id="@+id/empty_text" - android:layout_width="wrap_content" + android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/emptyview_spacing_medium" - android:layout_marginEnd="@dimen/emptyview_spacing_medium" - android:layout_marginStart="@dimen/emptyview_spacing_medium" + android:layout_marginBottom="@dimen/emptyview_inline_spacing" + android:layout_marginEnd="@dimen/emptyview_outline_spacing" + android:layout_marginStart="@dimen/emptyview_outline_spacing" android:gravity="center" - android:paddingEnd="@dimen/emptyview_spacing_medium" - android:paddingStart="@dimen/emptyview_spacing_medium" android:textSize="@dimen/emptyview_text_size" android:visibility="gone" app:layout_constraintBottom_toTopOf="@+id/empty_button" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/empty_title"/> @@ -73,20 +64,15 @@ android:id="@+id/empty_button" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/emptyview_spacing_medium" - android:layout_marginEnd="@dimen/emptyview_spacing_medium" - android:layout_marginStart="@dimen/emptyview_spacing_medium" - android:paddingBottom="@dimen/emptyview_spacing_small" - android:paddingLeft="@dimen/emptyview_spacing_normal" - android:paddingRight="@dimen/emptyview_spacing_normal" - android:paddingTop="@dimen/emptyview_spacing_small" + android:layout_marginBottom="@dimen/emptyview_outline_spacing" + android:layout_marginEnd="@dimen/emptyview_outline_spacing" + android:layout_marginStart="@dimen/emptyview_outline_spacing" android:textAllCaps="false" android:textColor="@android:color/black" android:textSize="@dimen/emptyview_button_text_size" android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/empty_text" style="@style/Widget.AppCompat.Button.Borderless.Colored"/> diff --git a/library/src/main/res/values-sw600dp/dimens.xml b/library/src/main/res/values-sw600dp/dimens.xml index 3bb39a4..9263f65 100644 --- a/library/src/main/res/values-sw600dp/dimens.xml +++ b/library/src/main/res/values-sw600dp/dimens.xml @@ -1,13 +1,10 @@ <?xml version="1.0" encoding="utf-8"?> <resources> - <dimen name="emptyview_spacing_lite">6dp</dimen> - <dimen name="emptyview_spacing_small">10dp</dimen> - <dimen name="emptyview_spacing_normal">18dp</dimen> - <dimen name="emptyview_spacing_medium">22dp</dimen> - <dimen name="emptyview_spacing_large">26dp</dimen> - <dimen name="emptyview_title_text_size">20sp</dimen> - <dimen name="emptyview_text_size">18sp</dimen> - <dimen name="emptyview_button_text_size">20sp</dimen> + <dimen name="emptyview_outline_spacing">20dp</dimen> + <dimen name="emptyview_inline_spacing">10dp</dimen> + <dimen name="emptyview_text_size">16sp</dimen> + <dimen name="emptyview_title_text_size">18sp</dimen> + <dimen name="emptyview_button_text_size">18sp</dimen> </resources> diff --git a/library/src/main/res/values-sw720dp/dimens.xml b/library/src/main/res/values-sw720dp/dimens.xml index 2a6330a..04e77a5 100644 --- a/library/src/main/res/values-sw720dp/dimens.xml +++ b/library/src/main/res/values-sw720dp/dimens.xml @@ -1,13 +1,10 @@ <?xml version="1.0" encoding="utf-8"?> <resources> - <dimen name="emptyview_spacing_lite">8dp</dimen> - <dimen name="emptyview_spacing_small">12dp</dimen> - <dimen name="emptyview_spacing_normal">20dp</dimen> - <dimen name="emptyview_spacing_medium">24dp</dimen> - <dimen name="emptyview_spacing_large">28dp</dimen> - <dimen name="emptyview_title_text_size">22sp</dimen> - <dimen name="emptyview_text_size">20sp</dimen> - <dimen name="emptyview_button_text_size">22sp</dimen> + <dimen name="emptyview_outline_spacing">20dp</dimen> + <dimen name="emptyview_inline_spacing">10dp</dimen> + <dimen name="emptyview_text_size">18sp</dimen> + <dimen name="emptyview_title_text_size">20sp</dimen> + <dimen name="emptyview_button_text_size">20sp</dimen> </resources> diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 892d244..588d2d4 100755 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -7,6 +7,7 @@ <enum name="text" value="1"/> </attr> <attr format="string" name="loadingText"/> + <attr format="dimension" name="loadingTextSize"/> <attr format="color" name="loadingTextColor"/> <attr format="reference" name="loadingDrawable"/> <attr format="color" name="loadingTint"/> @@ -23,8 +24,10 @@ </attr> <attr format="reference" name="emptyFont"/> <attr format="string" name="emptyTitle"/> + <attr format="dimension" name="emptyTitleSize"/> <attr format="color" name="emptyTitleColor"/> <attr format="string" name="emptyText"/> + <attr format="dimension" name="emptyTextSize"/> <attr format="color" name="emptyTextColor"/> <attr format="reference" name="emptyDrawable"/> <attr format="color" name="emptyDrawableTint"/> @@ -33,16 +36,20 @@ <attr format="float" name="emptyLineSpacingExtra"/> <attr format="float" name="emptyLineSpacingMultiplier"/> <attr format="string" name="emptyButtonText"/> + <attr format="dimension" name="emptyButtonTextSize"/> <attr format="color" name="emptyButtonTextColor"/> <attr format="color" name="emptyButtonBackgroundColor"/> <attr format="string" name="errorTitle"/> + <attr format="dimension" name="errorTitleSize"/> <attr format="color" name="errorTitleColor"/> <attr format="string" name="errorText"/> + <attr format="dimension" name="errorTextSize"/> <attr format="color" name="errorTextColor"/> <attr format="reference" name="errorDrawable"/> <attr format="color" name="errorDrawableTint"/> <attr format="color" name="errorBackgroundColor"/> <attr format="string" name="errorButtonText"/> + <attr format="dimension" name="errorButtonTextSize"/> <attr format="color" name="errorButtonTextColor"/> <attr format="color" name="errorButtonBackgroundColor"/> </declare-styleable> diff --git a/library/src/main/res/values/dimens.xml b/library/src/main/res/values/dimens.xml index 87a9964..e8975f5 100644 --- a/library/src/main/res/values/dimens.xml +++ b/library/src/main/res/values/dimens.xml @@ -1,13 +1,10 @@ <?xml version="1.0" encoding="utf-8"?> <resources> - <dimen name="emptyview_spacing_lite">4dp</dimen> - <dimen name="emptyview_spacing_small">8dp</dimen> - <dimen name="emptyview_spacing_normal">16dp</dimen> - <dimen name="emptyview_spacing_medium">20dp</dimen> - <dimen name="emptyview_spacing_large">24dp</dimen> - <dimen name="emptyview_title_text_size">18sp</dimen> - <dimen name="emptyview_text_size">16sp</dimen> - <dimen name="emptyview_button_text_size">18sp</dimen> + <dimen name="emptyview_outline_spacing">20dp</dimen> + <dimen name="emptyview_inline_spacing">10dp</dimen> + <dimen name="emptyview_text_size">14sp</dimen> + <dimen name="emptyview_title_text_size">16sp</dimen> + <dimen name="emptyview_button_text_size">16sp</dimen> </resources> \ No newline at end of file From fa0f001d20c7661358ddf7dc07b78617da008317 Mon Sep 17 00:00:00 2001 From: santalu <ftsantalu@gmail.com> Date: Mon, 26 Mar 2018 23:22:25 +0300 Subject: [PATCH 2/4] Update default error messages --- .../java/com/santalu/myapplication/EmptyHelper.java | 8 ++++---- library/src/main/res/values-tr/strings.xml | 10 ---------- library/src/main/res/values/strings.xml | 12 ++++++++---- 3 files changed, 12 insertions(+), 18 deletions(-) delete mode 100644 library/src/main/res/values-tr/strings.xml diff --git a/app/src/main/java/com/santalu/myapplication/EmptyHelper.java b/app/src/main/java/com/santalu/myapplication/EmptyHelper.java index f82a28b..5948497 100644 --- a/app/src/main/java/com/santalu/myapplication/EmptyHelper.java +++ b/app/src/main/java/com/santalu/myapplication/EmptyHelper.java @@ -104,7 +104,7 @@ public void showError(int textId, View.OnClickListener listener) { public void showError(Throwable throwable, View.OnClickListener listener) { if (emptyView != null) { if (throwable == null || TextUtils.isEmpty(throwable.getMessage())) { - showError(R.string.emptyview_error_unknown, listener); + showError(R.string.emptyview_unknown_error_text, listener); return; } Error error = Error.find(throwable); @@ -123,15 +123,15 @@ public void showError(Throwable throwable, View.OnClickListener listener) { } public void showConnectionError(View.OnClickListener listener) { - showError(R.string.emptyview_error_connection_not_found, listener); + showError(R.string.emptyview_connection_error_text, listener); } public void showTimeoutError(View.OnClickListener listener) { - showError(R.string.emptyview_error_connection_timeout, listener); + showError(R.string.emptyview_connection_timeout_error_text, listener); } public void showEndpointError(View.OnClickListener listener) { - showError(R.string.emptyview_error_endpoint, listener); + showError(R.string.emptyview_error_endpoint_text, listener); } enum Error { diff --git a/library/src/main/res/values-tr/strings.xml b/library/src/main/res/values-tr/strings.xml deleted file mode 100644 index fb079df..0000000 --- a/library/src/main/res/values-tr/strings.xml +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - - <string name="emptyview_loading">Yükleniyor…</string> - <string name="emptyview_error_unknown">İsteğinizi şuanda gerçekleştiremiyoruz.\nLütfen daha sonra tekrar deneyin!</string> - <string name="emptyview_error_connection_not_found">Lütfen bağlantı ayarlarınızı kontrol edin ve tekrar deneyin.</string> - <string name="emptyview_error_connection_timeout">Bağlantı zaman aşımına uğradı!</string> - <string name="emptyview_error_endpoint">Bağlantı adresine erişilemiyor!</string> - -</resources> diff --git a/library/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml index 4478c95..76150d9 100644 --- a/library/src/main/res/values/strings.xml +++ b/library/src/main/res/values/strings.xml @@ -2,9 +2,13 @@ <resources> <string name="emptyview_loading">Loading…</string> - <string name="emptyview_error_unknown">We can not fulfill your request now.\nPlease try again later!</string> - <string name="emptyview_error_connection_not_found">No connection!\nPlease check your connection settings.</string> - <string name="emptyview_error_connection_timeout">Connection timed out!</string> - <string name="emptyview_error_endpoint">Unable to access the connection address!</string> + <string name="emptyview_unknown_error_title">Sorry…</string> + <string name="emptyview_unknown_error_text">We can not fulfill your request now.\nPlease try again later</string> + <string name="emptyview_connection_error_title">No connection…</string> + <string name="emptyview_connection_error_text">Please check your connection settings</string> + <string name="emptyview_connection_timeout_error_title">Connection timed out…</string> + <string name="emptyview_connection_timeout_error_text">Please check your connection settings</string> + <string name="emptyview_error_endpoint_title">Oops…</string> + <string name="emptyview_error_endpoint_text">Unable to access the connection address.\nPlease try again later</string> </resources> From c78038bc75250da1eeb10b276952785bfcc31350 Mon Sep 17 00:00:00 2001 From: santalu <ftsantalu@gmail.com> Date: Thu, 29 Mar 2018 14:30:20 +0300 Subject: [PATCH 3/4] Change emptyview xml attribute names Add EmptyViewBuilder Update sample --- .idea/caches/build_file_checksums.ser | Bin 0 -> 586 bytes .idea/codeStyles/Project.xml | 363 +++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 6 + README.md | 4 +- app/build.gradle | 2 +- .../santalu/myapplication/EmptyHelper.java | 154 ------ .../santalu/myapplication/MainActivity.java | 47 +- app/src/main/res/layout/activity_main.xml | 45 +- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- .../com/santalu/emptyview/EmptyUtils.java | 66 +++ .../java/com/santalu/emptyview/EmptyView.java | 482 +++++------------- .../santalu/emptyview/EmptyViewBuilder.java | 414 +++++++++++++++ library/src/main/res/layout/empty_view.xml | 7 +- library/src/main/res/values/attrs.xml | 98 ++-- library/src/main/res/values/strings.xml | 1 + 16 files changed, 1100 insertions(+), 595 deletions(-) create mode 100644 .idea/caches/build_file_checksums.ser create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml delete mode 100644 app/src/main/java/com/santalu/myapplication/EmptyHelper.java create mode 100644 library/src/main/java/com/santalu/emptyview/EmptyUtils.java create mode 100644 library/src/main/java/com/santalu/emptyview/EmptyViewBuilder.java diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser new file mode 100644 index 0000000000000000000000000000000000000000..232c58bdb83cbf5396bbb9d24d8bd22307743ce2 GIT binary patch literal 586 zcmZ4UmVvdnh`~NNKUXg?FQq6yGexf?KR>5fFEb@IQ7^qHF(oHeub?PDD>b=9F91S2 zm1gFoxMk*~I%lLNXBU^|7Q2L-Ts|(GuF1r}<i#MFTj`TnT;dMa8(f)}9Fm!vT3nKt zTj0aMpIeEdv4nx&Co8cmQNOe#Ge_SyvB0{bfPsNADVNW)8|W@UkenV!PR}E;I0Gop z%6{wMVX=gZ%nVF!3|u++i79T0$tC$ko(!BN8AYkZ8TmOW6$SPV3?RT$&H*F^fSA36 zK_Ic9ASMaqbf~vVix`-qoz{F7|G~x)@_>nf0c16UKsSr_Hp}Z@I{rM2Dva5?R|e?B z;?$Co%)Insn8reeItDh7+QZx-^CHY&{I5DcFS}BC+ujlek(|t=qQs&~RGZ)$ehJ8~ zwK{$7#r{uQ6#u&@O(|jEL2(jXVe)~`dGRhfj(hdz_#ArgTnco5PJVJ?4k#`PQj1D5 zQ;SRCiUm#_&sWGS*t+XT|H9-%MWAOjoULL)i&Kk=W6}~!GBaYJE{{P(D25?dWP5J* nGi+jc*}ysD%@3!#5(Ys$s&7=>v&`1fUiMS-d+lxC_gg9efmhL6 literal 0 HcmV?d00001 diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..bb2bf36 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,363 @@ +<component name="ProjectCodeStyleConfiguration"> + <code_scheme name="Project" version="173"> + <option name="USE_SAME_INDENTS" value="true" /> + <option name="IGNORE_SAME_INDENTS_FOR_LANGUAGES" value="true" /> + <option name="OTHER_INDENT_OPTIONS"> + <value> + <option name="INDENT_SIZE" value="2" /> + <option name="CONTINUATION_INDENT_SIZE" value="4" /> + <option name="TAB_SIZE" value="2" /> + </value> + </option> + <option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" /> + <option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" /> + <option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND"> + <value /> + </option> + <option name="IMPORT_LAYOUT_TABLE"> + <value> + <package name="" withSubpackages="true" static="false" /> + <emptyLine /> + <package name="" withSubpackages="true" static="true" /> + </value> + </option> + <option name="RIGHT_MARGIN" value="100" /> + <option name="JD_ALIGN_PARAM_COMMENTS" value="false" /> + <option name="JD_ALIGN_EXCEPTION_COMMENTS" value="false" /> + <option name="JD_P_AT_EMPTY_LINES" value="false" /> + <option name="JD_DO_NOT_WRAP_ONE_LINE_COMMENTS" value="true" /> + <option name="JD_KEEP_EMPTY_PARAMETER" value="false" /> + <option name="JD_KEEP_EMPTY_RETURN" value="false" /> + <option name="JD_PRESERVE_LINE_FEEDS" value="true" /> + <option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" /> + <option name="BLOCK_COMMENT_AT_FIRST_COLUMN" value="false" /> + <option name="KEEP_FIRST_COLUMN_COMMENT" value="false" /> + <option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" /> + <option name="KEEP_BLANK_LINES_IN_CODE" value="1" /> + <option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" /> + <option name="ALIGN_MULTILINE_PARAMETERS" value="false" /> + <option name="ALIGN_MULTILINE_FOR" value="false" /> + <option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true" /> + <option name="CALL_PARAMETERS_WRAP" value="1" /> + <option name="METHOD_PARAMETERS_WRAP" value="1" /> + <option name="RESOURCE_LIST_WRAP" value="1" /> + <option name="EXTENDS_LIST_WRAP" value="1" /> + <option name="THROWS_LIST_WRAP" value="1" /> + <option name="EXTENDS_KEYWORD_WRAP" value="1" /> + <option name="THROWS_KEYWORD_WRAP" value="1" /> + <option name="METHOD_CALL_CHAIN_WRAP" value="5" /> + <option name="BINARY_OPERATION_WRAP" value="5" /> + <option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true" /> + <option name="TERNARY_OPERATION_WRAP" value="1" /> + <option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" /> + <option name="FOR_STATEMENT_WRAP" value="1" /> + <option name="ARRAY_INITIALIZER_WRAP" value="1" /> + <option name="ASSIGNMENT_WRAP" value="1" /> + <option name="WRAP_COMMENTS" value="true" /> + <option name="ASSERT_STATEMENT_WRAP" value="1" /> + <option name="IF_BRACE_FORCE" value="1" /> + <option name="DOWHILE_BRACE_FORCE" value="1" /> + <option name="WHILE_BRACE_FORCE" value="1" /> + <option name="METHOD_ANNOTATION_WRAP" value="1" /> + <option name="CLASS_ANNOTATION_WRAP" value="1" /> + <option name="FIELD_ANNOTATION_WRAP" value="1" /> + <option name="PARAMETER_ANNOTATION_WRAP" value="1" /> + <option name="VARIABLE_ANNOTATION_WRAP" value="1" /> + <option name="ENUM_CONSTANTS_WRAP" value="1" /> + <AndroidXmlCodeStyleSettings> + <option name="USE_CUSTOM_SETTINGS" value="true" /> + <option name="LAYOUT_SETTINGS"> + <value> + <option name="INSERT_BLANK_LINE_BEFORE_TAG" value="false" /> + <option name="INSERT_LINE_BREAK_BEFORE_NAMESPACE_DECLARATION" value="true" /> + </value> + </option> + </AndroidXmlCodeStyleSettings> + <JavaCodeStyleSettings> + <option name="CLASS_NAMES_IN_JAVADOC" value="3" /> + <option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" /> + <option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" /> + <option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND"> + <value /> + </option> + <option name="IMPORT_LAYOUT_TABLE"> + <value> + <package name="" withSubpackages="true" static="false" /> + <emptyLine /> + <package name="" withSubpackages="true" static="true" /> + </value> + </option> + <option name="JD_ALIGN_PARAM_COMMENTS" value="false" /> + <option name="JD_ALIGN_EXCEPTION_COMMENTS" value="false" /> + <option name="JD_P_AT_EMPTY_LINES" value="false" /> + <option name="JD_DO_NOT_WRAP_ONE_LINE_COMMENTS" value="true" /> + <option name="JD_KEEP_EMPTY_PARAMETER" value="false" /> + <option name="JD_KEEP_EMPTY_RETURN" value="false" /> + <option name="JD_PRESERVE_LINE_FEEDS" value="true" /> + </JavaCodeStyleSettings> + <JetCodeStyleSettings> + <option name="PACKAGES_TO_USE_STAR_IMPORTS"> + <value /> + </option> + <option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="999" /> + <option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="999" /> + <option name="IMPORT_NESTED_CLASSES" value="true" /> + <option name="CONTINUATION_INDENT_IN_PARAMETER_LISTS" value="false" /> + <option name="CONTINUATION_INDENT_FOR_EXPRESSION_BODIES" value="false" /> + </JetCodeStyleSettings> + <Objective-C-extensions> + <file> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" /> + </file> + <class> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" /> + <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" /> + </class> + <extensions> + <pair source="cpp" header="h" fileNamingConvention="NONE" /> + <pair source="c" header="h" fileNamingConvention="NONE" /> + </extensions> + </Objective-C-extensions> + <XML> + <option name="XML_ALIGN_ATTRIBUTES" value="false" /> + <option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" /> + </XML> + <ADDITIONAL_INDENT_OPTIONS fileType="php"> + <option name="INDENT_SIZE" value="2" /> + <option name="CONTINUATION_INDENT_SIZE" value="4" /> + <option name="TAB_SIZE" value="2" /> + </ADDITIONAL_INDENT_OPTIONS> + <ADDITIONAL_INDENT_OPTIONS fileType="scala"> + <option name="INDENT_SIZE" value="2" /> + <option name="CONTINUATION_INDENT_SIZE" value="2" /> + <option name="TAB_SIZE" value="2" /> + </ADDITIONAL_INDENT_OPTIONS> + <codeStyleSettings language="Groovy"> + <option name="KEEP_FIRST_COLUMN_COMMENT" value="false" /> + <option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" /> + <option name="KEEP_BLANK_LINES_IN_CODE" value="1" /> + <option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" /> + <option name="ALIGN_MULTILINE_PARAMETERS" value="false" /> + <option name="ALIGN_MULTILINE_FOR" value="false" /> + <option name="CALL_PARAMETERS_WRAP" value="1" /> + <option name="METHOD_PARAMETERS_WRAP" value="1" /> + <option name="EXTENDS_LIST_WRAP" value="1" /> + <option name="THROWS_LIST_WRAP" value="1" /> + <option name="EXTENDS_KEYWORD_WRAP" value="1" /> + <option name="THROWS_KEYWORD_WRAP" value="1" /> + <option name="METHOD_CALL_CHAIN_WRAP" value="5" /> + <option name="BINARY_OPERATION_WRAP" value="5" /> + <option name="TERNARY_OPERATION_WRAP" value="1" /> + <option name="FOR_STATEMENT_WRAP" value="1" /> + <option name="ASSIGNMENT_WRAP" value="1" /> + <option name="ASSERT_STATEMENT_WRAP" value="1" /> + <option name="IF_BRACE_FORCE" value="1" /> + <option name="WHILE_BRACE_FORCE" value="1" /> + <option name="METHOD_ANNOTATION_WRAP" value="1" /> + <option name="CLASS_ANNOTATION_WRAP" value="1" /> + <option name="FIELD_ANNOTATION_WRAP" value="1" /> + <option name="PARAMETER_ANNOTATION_WRAP" value="1" /> + <option name="VARIABLE_ANNOTATION_WRAP" value="1" /> + <indentOptions> + <option name="INDENT_SIZE" value="2" /> + <option name="CONTINUATION_INDENT_SIZE" value="4" /> + <option name="TAB_SIZE" value="2" /> + </indentOptions> + </codeStyleSettings> + <codeStyleSettings language="JAVA"> + <option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" /> + <option name="BLOCK_COMMENT_AT_FIRST_COLUMN" value="false" /> + <option name="KEEP_FIRST_COLUMN_COMMENT" value="false" /> + <option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" /> + <option name="KEEP_BLANK_LINES_IN_CODE" value="1" /> + <option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" /> + <option name="ALIGN_MULTILINE_PARAMETERS" value="false" /> + <option name="ALIGN_MULTILINE_FOR" value="false" /> + <option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACES" value="true" /> + <option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true" /> + <option name="CALL_PARAMETERS_WRAP" value="1" /> + <option name="METHOD_PARAMETERS_WRAP" value="5" /> + <option name="RESOURCE_LIST_WRAP" value="1" /> + <option name="EXTENDS_LIST_WRAP" value="1" /> + <option name="THROWS_LIST_WRAP" value="1" /> + <option name="EXTENDS_KEYWORD_WRAP" value="1" /> + <option name="THROWS_KEYWORD_WRAP" value="1" /> + <option name="METHOD_CALL_CHAIN_WRAP" value="5" /> + <option name="BINARY_OPERATION_WRAP" value="5" /> + <option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true" /> + <option name="TERNARY_OPERATION_WRAP" value="1" /> + <option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" /> + <option name="FOR_STATEMENT_WRAP" value="1" /> + <option name="ARRAY_INITIALIZER_WRAP" value="1" /> + <option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" /> + <option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" /> + <option name="ASSIGNMENT_WRAP" value="1" /> + <option name="ASSERT_STATEMENT_WRAP" value="1" /> + <option name="IF_BRACE_FORCE" value="1" /> + <option name="DOWHILE_BRACE_FORCE" value="1" /> + <option name="WHILE_BRACE_FORCE" value="1" /> + <option name="METHOD_ANNOTATION_WRAP" value="1" /> + <option name="FIELD_ANNOTATION_WRAP" value="1" /> + <option name="PARAMETER_ANNOTATION_WRAP" value="1" /> + <option name="VARIABLE_ANNOTATION_WRAP" value="1" /> + <indentOptions> + <option name="INDENT_SIZE" value="2" /> + <option name="CONTINUATION_INDENT_SIZE" value="4" /> + <option name="TAB_SIZE" value="2" /> + </indentOptions> + </codeStyleSettings> + <codeStyleSettings language="JSON"> + <option name="KEEP_BLANK_LINES_IN_CODE" value="1" /> + </codeStyleSettings> + <codeStyleSettings language="XML"> + <indentOptions> + <option name="INDENT_SIZE" value="2" /> + <option name="CONTINUATION_INDENT_SIZE" value="4" /> + <option name="TAB_SIZE" value="2" /> + </indentOptions> + <arrangement> + <rules> + <section> + <rule> + <match> + <NAME>class</NAME> + </match> + </rule> + </section> + <section> + <rule> + <match> + <NAME>layout</NAME> + </match> + </rule> + </section> + <section> + <rule> + <match> + <NAME>xmlns:android</NAME> + </match> + </rule> + </section> + <section> + <rule> + <match> + <NAME>xmlns:.*</NAME> + </match> + <order>BY_NAME</order> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*:id</NAME> + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*:name</NAME> + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*:layout_width</NAME> + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*:layout_height</NAME> + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*:layout_.*</NAME> + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> + </AND> + </match> + <order>BY_NAME</order> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*</NAME> + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> + </AND> + </match> + <order>BY_NAME</order> + </rule> + </section> + <section> + <rule> + <match> + <NAME>.*(?<!style)$</NAME> + </match> + <order>BY_NAME</order> + </rule> + </section> + <section> + <rule> + <match> + <NAME>style</NAME> + </match> + </rule> + </section> + </rules> + </arrangement> + </codeStyleSettings> + <codeStyleSettings language="kotlin"> + <option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" /> + <option name="KEEP_BLANK_LINES_IN_CODE" value="1" /> + <option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" /> + <option name="ALIGN_MULTILINE_PARAMETERS" value="false" /> + <option name="CALL_PARAMETERS_WRAP" value="1" /> + <option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" /> + <option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" /> + <option name="METHOD_PARAMETERS_WRAP" value="2" /> + <option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" /> + <option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" /> + <option name="EXTENDS_LIST_WRAP" value="5" /> + <option name="METHOD_ANNOTATION_WRAP" value="1" /> + <option name="FIELD_ANNOTATION_WRAP" value="1" /> + <option name="ENUM_CONSTANTS_WRAP" value="2" /> + <indentOptions> + <option name="INDENT_SIZE" value="2" /> + <option name="CONTINUATION_INDENT_SIZE" value="4" /> + <option name="TAB_SIZE" value="2" /> + </indentOptions> + </codeStyleSettings> + </code_scheme> +</component> \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..273b94c --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,6 @@ +<component name="ProjectCodeStyleConfiguration"> + <state> + <option name="USE_PER_PROJECT_SETTINGS" value="true" /> + <option name="PREFERRED_PROJECT_CODE_STYLE" value="SquareAndroid" /> + </state> +</component> \ No newline at end of file diff --git a/README.md b/README.md index 25128d6..9807bfe 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ dependencies { app:errorText="@string/emptyview_error_unknown" app:errorTextColor="@color/white" app:loadingDrawable="@drawable/ic_sentiment_satisfied" - app:loadingStyle="circular" + app:loading="circular" app:loadingText="@string/emptyview_loading" app:loadingTint="@color/colorPrimary"> @@ -71,7 +71,7 @@ dependencies { | emptyAnimateLayoutChanges | enable/disable transitions | boolean default false | | emptyFont | font family | reference | | emptyGravity | gravity of empty view | top, center, bottom | -| loadingStyle | style of loading state | circular, linear, text | +| loading | style of loading state | circular, linear, text | | loadingText | text will show on loading state | string | | loadingTextColor | loading state text color | color | | loadingDrawable | drawable will show on loading state | reference | diff --git a/app/build.gradle b/app/build.gradle index cde1bc9..bba7482 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -27,8 +27,8 @@ dependencies { exclude group: 'com.android.support', module: 'support-annotations' }) implementation 'com.android.support:appcompat-v7:27.1.0' - implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.android.support:recyclerview-v7:27.1.0' + implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation 'junit:junit:4.12' implementation project(':library') } diff --git a/app/src/main/java/com/santalu/myapplication/EmptyHelper.java b/app/src/main/java/com/santalu/myapplication/EmptyHelper.java deleted file mode 100644 index 5948497..0000000 --- a/app/src/main/java/com/santalu/myapplication/EmptyHelper.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.santalu.myapplication; - -import android.content.Context; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.text.TextUtils; -import android.view.View; -import com.santalu.emptyview.EmptyView; -import java.net.ConnectException; -import java.net.SocketTimeoutException; -import java.net.UnknownHostException; -import java.util.concurrent.TimeoutException; - -/** - * Created by santalu on 31/08/2017. - * A simple helper class to demonstrate general usage of empty view - */ - -public class EmptyHelper { - - private final EmptyView emptyView; - - public EmptyHelper(EmptyView emptyView) { - this.emptyView = emptyView; - } - - public boolean isConnected(Context context) { - ConnectivityManager manager = - (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo info = manager.getActiveNetworkInfo(); - return info != null && info.isConnected(); - } - - public void showLoading() { - if (emptyView != null) { - emptyView.showLoading(); - } - } - - public void showLoading(CharSequence text) { - if (emptyView != null) { - emptyView.showLoading(text); - } - } - - public void showLoading(int textId) { - if (emptyView != null) { - emptyView.showLoading(textId); - } - } - - public void showContent() { - if (emptyView != null) { - emptyView.showContent(); - } - } - - public void showEmpty(View.OnClickListener listener) { - if (emptyView != null) { - if (isConnected(emptyView.getContext())) { - emptyView.setOnClickListener(listener); - emptyView.showEmpty(); - } else { - showConnectionError(listener); - } - } - } - - public void showEmpty(CharSequence text, View.OnClickListener listener) { - if (emptyView != null) { - emptyView.setOnClickListener(listener); - emptyView.showEmpty(text); - } - } - - public void showEmpty(int textId, View.OnClickListener listener) { - if (emptyView != null) { - emptyView.setOnClickListener(listener); - emptyView.showEmpty(textId); - } - } - - public void showError(View.OnClickListener listener) { - if (emptyView != null) { - emptyView.setOnClickListener(listener); - emptyView.showError(); - } - } - - public void showError(CharSequence text, View.OnClickListener listener) { - if (emptyView != null) { - emptyView.setOnClickListener(listener); - emptyView.showError(text); - } - } - - public void showError(int textId, View.OnClickListener listener) { - if (emptyView != null) { - emptyView.setOnClickListener(listener); - emptyView.showError(textId); - } - } - - public void showError(Throwable throwable, View.OnClickListener listener) { - if (emptyView != null) { - if (throwable == null || TextUtils.isEmpty(throwable.getMessage())) { - showError(R.string.emptyview_unknown_error_text, listener); - return; - } - Error error = Error.find(throwable); - switch (error) { - case ENDPOINT: - showEndpointError(listener); - break; - case TIMEOUT: - showTimeoutError(listener); - break; - case UNKNOWN: - showError(throwable.getMessage(), listener); - break; - } - } - } - - public void showConnectionError(View.OnClickListener listener) { - showError(R.string.emptyview_connection_error_text, listener); - } - - public void showTimeoutError(View.OnClickListener listener) { - showError(R.string.emptyview_connection_timeout_error_text, listener); - } - - public void showEndpointError(View.OnClickListener listener) { - showError(R.string.emptyview_error_endpoint_text, listener); - } - - enum Error { - ENDPOINT, - TIMEOUT, - UNKNOWN; - - public static Error find(Throwable e) { - if (e instanceof UnknownHostException) { - return ENDPOINT; - } else if (e instanceof SocketTimeoutException - || e instanceof TimeoutException - || e instanceof ConnectException) { - return TIMEOUT; - } else { - return UNKNOWN; - } - } - } -} diff --git a/app/src/main/java/com/santalu/myapplication/MainActivity.java b/app/src/main/java/com/santalu/myapplication/MainActivity.java index abded9e..507eff1 100644 --- a/app/src/main/java/com/santalu/myapplication/MainActivity.java +++ b/app/src/main/java/com/santalu/myapplication/MainActivity.java @@ -11,16 +11,19 @@ public class MainActivity extends AppCompatActivity { private EmptyView emptyView; - private EmptyHelper emptyHelper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); emptyView = findViewById(R.id.empty_view); - //emptyView.exclude(R.id.text); - //emptyView.setErrorButton("Error Button"); - //emptyView.setEmptyButton("Empty Button"); - emptyHelper = new EmptyHelper(emptyView); + + /*emptyView.setState(EmptyView.EMPTY) + .setEmptyDrawable(R.mipmap.ic_launcher) + .setEmptyDrawableTint(0) + .setEmptyTitle("Empty Title") + .setEmptyText("Empty Text") + .setEmptyButtonText("Empty Button") + .show();*/ } @Override public boolean onCreateOptionsMenu(Menu menu) { @@ -32,24 +35,34 @@ public class MainActivity extends AppCompatActivity { int itemId = item.getItemId(); switch (itemId) { case R.id.show_progress: - emptyHelper.showLoading(); + //emptyView.showLoading(); + emptyView.setState(EmptyView.LOADING) + .show(); break; case R.id.show_content: - emptyHelper.showContent(); + //emptyView.showContent(); + emptyView.setState(EmptyView.CONTENT) + .show(); break; case R.id.show_error: - emptyHelper.showError(new OnClickListener() { - @Override public void onClick(View v) { - emptyView.showLoading(); - } - }); + //emptyView.showError(); + emptyView.setState(EmptyView.ERROR) + .setOnClickListener(new OnClickListener() { + @Override public void onClick(View v) { + emptyView.showLoading(); + } + }) + .show(); break; case R.id.show_empty: - emptyHelper.showEmpty(new OnClickListener() { - @Override public void onClick(View v) { - emptyView.showLoading(); - } - }); + //emptyView.showEmpty(); + emptyView.setState(EmptyView.EMPTY) + .setOnClickListener(new OnClickListener() { + @Override public void onClick(View v) { + emptyView.showLoading(); + } + }) + .show(); break; } return super.onOptionsItemSelected(item); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index fa8d42f..3243cab 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -5,27 +5,30 @@ android:id="@+id/empty_view" android:layout_width="match_parent" android:layout_height="match_parent" - app:emptyButtonText="@string/try_again" - app:emptyButtonTextColor="@color/colorPrimaryDark" - app:emptyDrawable="@drawable/ic_sentiment_dissatisfied" - app:emptyDrawableTint="@color/colorPrimary" - app:emptyFont="@font/allerta" - app:emptyText="@string/empty" - app:emptyTitleColor="@color/colorPrimary" - app:emptyTransition="slide" - app:errorBackgroundColor="@color/red" - app:errorButtonText="@string/try_again" - app:errorButtonTextColor="@color/white" - app:errorDrawable="@drawable/ic_sentiment_very_dissatisfied" - app:errorDrawableTint="@color/white" - app:errorText="@string/emptyview_unknown_error_text" - app:errorTextColor="@color/white" - app:errorTitle="@string/emptyview_unknown_error_title" - app:errorTitleColor="@color/white" - app:loadingDrawable="@drawable/ic_sentiment_satisfied" - app:loadingStyle="circular" - app:loadingText="@string/emptyview_loading" - app:loadingTint="@color/colorPrimary"> + app:ev_buttonTextSize="18sp" + app:ev_empty_button="@string/try_again" + app:ev_empty_buttonTextColor="@color/colorPrimaryDark" + app:ev_empty_drawable="@drawable/ic_sentiment_dissatisfied" + app:ev_empty_drawableTint="@color/colorPrimary" + app:ev_empty_text="@string/empty" + app:ev_empty_title="@string/emptyview_unknown_error_title" + app:ev_error_backgroundColor="@color/red" + app:ev_error_button="@string/try_again" + app:ev_error_buttonTextColor="@color/white" + app:ev_error_drawable="@drawable/ic_sentiment_very_dissatisfied" + app:ev_error_drawableTint="@color/white" + app:ev_error_text="@string/emptyview_unknown_error_text" + app:ev_error_textColor="@color/white" + app:ev_error_title="@string/emptyview_unknown_error_title" + app:ev_error_titleTextColor="@color/white" + app:ev_font="@font/allerta" + app:ev_loading="circular" + app:ev_loading_drawable="@drawable/ic_sentiment_satisfied" + app:ev_loading_drawableTint="@color/colorPrimary" + app:ev_loading_title="@string/emptyview_loading" + app:ev_textSize="16sp" + app:ev_titleTextSize="20sp" + app:ev_transition="slide"> <TextView android:id="@+id/text" diff --git a/build.gradle b/build.gradle index 90df835..3acc306 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' + classpath 'com.android.tools.build:gradle:3.1.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1651806..39646e8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Jan 23 15:20:57 EET 2018 +#Wed Mar 28 17:36:28 EET 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/library/src/main/java/com/santalu/emptyview/EmptyUtils.java b/library/src/main/java/com/santalu/emptyview/EmptyUtils.java new file mode 100644 index 0000000..a6e91d6 --- /dev/null +++ b/library/src/main/java/com/santalu/emptyview/EmptyUtils.java @@ -0,0 +1,66 @@ +package com.santalu.emptyview; + +import android.content.Context; +import android.graphics.Typeface; +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.support.annotation.ColorRes; +import android.support.annotation.DimenRes; +import android.support.annotation.DrawableRes; +import android.support.annotation.FontRes; +import android.support.annotation.Nullable; +import android.support.annotation.StringRes; +import android.support.annotation.TransitionRes; +import android.support.transition.Transition; +import android.support.transition.TransitionInflater; +import android.support.v4.content.ContextCompat; +import android.support.v4.content.res.ResourcesCompat; +import android.text.Html; +import android.text.TextUtils; +import android.util.TypedValue; +import android.widget.TextView; + +/** + * Created by santalu on 09/08/2017. + */ + +final class EmptyUtils { + + static Drawable getDrawable(Context context, @DrawableRes int id) { + return id <= 0 ? null : ContextCompat.getDrawable(context, id); + } + + static int getColor(Context context, @ColorRes int id) { + return id <= 0 ? 0 : ContextCompat.getColor(context, id); + } + + static float getDimension(Context context, @DimenRes int id) { + return id <= 0 ? 0 : context.getResources().getDimension(id); + } + + static String getString(Context context, @StringRes int id) { + return id <= 0 ? null : context.getString(id); + } + + static Typeface getFont(Context context, @FontRes int id) { + return id <= 0 ? null : ResourcesCompat.getFont(context, id); + } + + static Transition getTransition(Context context, @TransitionRes int id) { + return id <= 0 ? null : TransitionInflater.from(context).inflateTransition(id); + } + + static String fromHtml(@Nullable String text) { + if (TextUtils.isEmpty(text)) { + return null; + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + return Html.fromHtml(text, Html.FROM_HTML_MODE_COMPACT).toString(); + } else { + return Html.fromHtml(text).toString(); + } + } + + static void setTextSize(TextView textView, float textSize) { + textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); + } +} diff --git a/library/src/main/java/com/santalu/emptyview/EmptyView.java b/library/src/main/java/com/santalu/emptyview/EmptyView.java index 2ee69f1..b2bf743 100644 --- a/library/src/main/java/com/santalu/emptyview/EmptyView.java +++ b/library/src/main/java/com/santalu/emptyview/EmptyView.java @@ -1,10 +1,7 @@ package com.santalu.emptyview; import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Color; import android.graphics.PorterDuff.Mode; -import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Build; @@ -12,20 +9,11 @@ import android.support.annotation.ColorInt; import android.support.annotation.IdRes; import android.support.annotation.IntDef; -import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.annotation.StringRes; import android.support.constraint.ConstraintLayout; -import android.support.transition.Explode; -import android.support.transition.Fade; -import android.support.transition.Slide; -import android.support.transition.Transition; import android.support.transition.TransitionManager; -import android.support.v4.content.res.ResourcesCompat; -import android.text.Html; import android.text.TextUtils; import android.util.AttributeSet; -import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; import android.widget.Button; @@ -35,6 +23,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; +import java.util.List; /** * Created by santalu on 09/08/2017. @@ -42,91 +31,44 @@ public class EmptyView extends ConstraintLayout { - // Style - public static final int CIRCULAR = 0; - public static final int TEXT = 1; + public static final int NONE = 0; - // Position - /*public static final int CENTER = 0; - public static final int TOP = 1; - public static final int BOTTOM = 2;*/ + // Loading + public static final int CIRCULAR = 1; // State - public static final int CONTENT = 0; - public static final int LOADING = 1; - public static final int EMPTY = 2; - public static final int ERROR = 3; + public static final int CONTENT = 1; + public static final int LOADING = 2; + public static final int EMPTY = 3; + public static final int ERROR = 4; // Transition - public static final int SLIDE = 0; - public static final int EXPLODE = 1; - public static final int FADE = 2; + public static final int SLIDE = 1; + public static final int EXPLODE = 2; + public static final int FADE = 3; - private static final String TAG = EmptyView.class.getSimpleName(); + private final List<View> childViews = new ArrayList<>(); + private final EmptyViewBuilder builder; - private ArrayList<View> childViews = new ArrayList<>(); private ProgressBar progressBar; private ImageView imageView; private TextView titleView; private TextView textView; private Button button; - private Typeface emptyFont; - private Drawable loadingDrawable; - private Drawable emptyDrawable; - private Drawable errorDrawable; - private OnClickListener onClickListener; - - private CharSequence loadingText; - private CharSequence emptyTitle; - private CharSequence emptyText; - private CharSequence emptyButtonText; - private CharSequence errorTitle; - private CharSequence errorText; - private CharSequence errorButtonText; - private int contentBackgroundColor; - private int loadingTint; - private int loadingTextColor; - private float loadingTextSize; - private int loadingBackgroundColor; - private int loadingStyle; - private int emptyTint; - private int emptyTitleColor; - private float emptyTitleSize; - private int emptyTextColor; - private float emptyTextSize; - private int emptyBackgroundColor; - private int emptyButtonTextColor; - private float emptyButtonTextSize; - private int emptyButtonBackgroundColor; - private int errorTint; - private int errorTitleColor; - private float errorTitleSize; - private int errorTextColor; - private float errorTextSize; - private int errorButtonTextColor; - private float errorButtonTextSize; - private int errorButtonBackgroundColor; - private int errorBackgroundColor; - private int state; - // private int gravity; - private float emptyLetterSpacing; - private float emptyLineSpacingExtra; - private float emptyLineSpacingMultiplier; - - private Transition transition; public EmptyView(Context context) { super(context); + builder = new EmptyViewBuilder(this); } public EmptyView(Context context, AttributeSet attrs) { super(context, attrs); - init(attrs); + builder = new EmptyViewBuilder(this, attrs); } public EmptyView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - init(attrs); + builder = new EmptyViewBuilder(this, attrs); } @Override protected void onFinishInflate() { @@ -140,20 +82,19 @@ public EmptyView(Context context, AttributeSet attrs, int defStyleAttr) { Drawable backgroundDrawable = getBackground(); if (backgroundDrawable instanceof ColorDrawable) { - contentBackgroundColor = ((ColorDrawable) backgroundDrawable).getColor(); + builder.setContentBackgroundColor(((ColorDrawable) backgroundDrawable).getColor()); } } @Override public void addView(View child, int index, ViewGroup.LayoutParams params) { super.addView(child, index, params); - if (child.getVisibility() == VISIBLE && - (child.getTag() == null || !child.getTag().equals(TAG))) { + if (child.getVisibility() == VISIBLE) { childViews.add(child); } } @Override public void setOnClickListener(@Nullable OnClickListener onClickListener) { - this.onClickListener = onClickListener; + builder.setOnClickListener(onClickListener); } public void exclude(@IdRes int... ids) { @@ -173,335 +114,187 @@ public void exclude(View... views) { } } - public void setTypeface(@Nullable Typeface typeface) { - if (typeface != null) { - titleView.setTypeface(typeface); - textView.setTypeface(typeface); - button.setTypeface(typeface); + private void setChildVisibility(int visibility) { + for (View view : childViews) { + view.setVisibility(visibility); } } - public void setLoadingStyle(@Style int style) { - this.loadingStyle = style; - } - - public void setTransition(@Nullable Transition transition) { - this.transition = transition; - } - - public void setEmptyButton(CharSequence text) { - setEmptyButton(text, emptyButtonTextColor, emptyButtonBackgroundColor); - } - - public void setEmptyButton(CharSequence text, - @ColorInt int textColor, - @ColorInt int backgroundColor) { - emptyButtonText = text; - emptyButtonTextColor = textColor; - emptyButtonBackgroundColor = backgroundColor; + public void showContent() { + builder.setState(CONTENT) + .show(); } - public void setErrorButton(CharSequence text) { - setErrorButton(text, errorButtonTextColor, errorButtonBackgroundColor); + public void showLoading() { + builder.setState(LOADING) + .show(); } - public void setErrorButton(CharSequence text, - @ColorInt int textColor, - @ColorInt int backgroundColor) { - errorButtonText = text; - errorButtonTextColor = textColor; - errorButtonBackgroundColor = backgroundColor; + public void showEmpty() { + builder.setState(EMPTY) + .show(); } - @State public int getState() { - return state; + public void showError() { + builder.setState(ERROR) + .show(); } - private void setState(@State int state) { + void show() { // start animation - if (transition != null) { - TransitionManager.beginDelayedTransition(this, transition); + if (builder.transition != null) { + TransitionManager.beginDelayedTransition(this, builder.transition); } - this.state = state; - switch (state) { - case LOADING: - progressBar.setVisibility(VISIBLE); + switch (builder.state) { + case CONTENT: + progressBar.setVisibility(GONE); imageView.setVisibility(GONE); - titleView.setVisibility(View.GONE); + titleView.setVisibility(GONE); textView.setVisibility(GONE); button.setVisibility(GONE); - setupLoadingView(); - setChildVisibility(GONE); + setChildVisibility(VISIBLE); + + setBackgroundColor(builder.contentBackgroundColor); break; case EMPTY: progressBar.setVisibility(GONE); imageView.setVisibility(VISIBLE); - titleView.setVisibility(View.VISIBLE); + titleView.setVisibility(VISIBLE); textView.setVisibility(VISIBLE); - button.setVisibility(GONE); - setupEmptyView(); + button.setVisibility(VISIBLE); setChildVisibility(GONE); + + setDrawable(builder.emptyDrawable, builder.emptyDrawableTint); + setTitle(builder.emptyTitle, builder.emptyTitleTextColor); + setText(builder.emptyText, builder.emptyTextColor); + setButton(builder.emptyButtonText, builder.emptyButtonTextColor, + builder.emptyButtonBackgroundColor); + setBackgroundColor(builder.emptyBackgroundColor); break; case ERROR: progressBar.setVisibility(GONE); imageView.setVisibility(VISIBLE); - titleView.setVisibility(View.VISIBLE); + titleView.setVisibility(VISIBLE); textView.setVisibility(VISIBLE); button.setVisibility(VISIBLE); - setupErrorView(); setChildVisibility(GONE); + + setDrawable(builder.errorDrawable, builder.errorDrawableTint); + setTitle(builder.errorTitle, builder.errorTitleTextColor); + setText(builder.errorText, builder.errorTextColor); + setButton(builder.errorButtonText, builder.errorButtonTextColor, + builder.errorButtonBackgroundColor); + setBackgroundColor(builder.errorBackgroundColor); break; - case CONTENT: - setBackgroundColor(contentBackgroundColor); - progressBar.setVisibility(GONE); + case LOADING: + progressBar.setVisibility(VISIBLE); imageView.setVisibility(GONE); - titleView.setVisibility(View.GONE); - textView.setVisibility(GONE); + titleView.setVisibility(VISIBLE); + textView.setVisibility(VISIBLE); button.setVisibility(GONE); - setChildVisibility(VISIBLE); + setChildVisibility(GONE); + + setLoadingDrawable(builder.loading, builder.loadingDrawableTint); + setDrawable(builder.loadingDrawable, builder.loadingDrawableTint); + setTitle(builder.loadingTitle, builder.loadingTitleTextColor); + setText(builder.loadingText, builder.loadingTextColor); + setBackgroundColor(builder.loadingBackgroundColor); break; } } - public void showLoading(@StringRes int text) { - showLoading(getString(text)); - } - - public void showLoading(@Nullable CharSequence text) { - loadingText = text; - showLoading(); - } - - public void showLoading() { - setState(LOADING); - } - - public void showError(@StringRes int text) { - showError(getString(text)); - } - - public void showError(@Nullable CharSequence text) { - errorText = text; - showError(); - } - - public void showError() { - setState(ERROR); - } - - public void showEmpty(@StringRes int text) { - showEmpty(getString(text)); - } - - public void showEmpty(@Nullable CharSequence text) { - emptyText = text; - showEmpty(); - } - - public void showEmpty() { - setState(EMPTY); - } - - public void showContent() { - setState(CONTENT); - } - - private void init(@NonNull AttributeSet attrs) { - TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.EmptyView); - try { - if (Build.VERSION.SDK_INT >= VERSION_CODES.O) { - emptyFont = a.getFont(R.styleable.EmptyView_emptyFont); - } else { - int fontResId = a.getResourceId(R.styleable.EmptyView_emptyFont, 0); - if (fontResId != 0) { - emptyFont = ResourcesCompat.getFont(getContext(), fontResId); - } - } - - int emptyTransition = a.getInt(R.styleable.EmptyView_emptyTransition, -1); - switch (emptyTransition) { - case SLIDE: - transition = new Slide(); - break; - case EXPLODE: - transition = new Explode(); - break; - case FADE: - transition = new Fade(); - break; - } - - // gravity = a.getInt(R.styleable.EmptyView_emptyGravity, CENTER); - - float defaultTitleTextSize = getResources().getDimension(R.dimen.emptyview_title_text_size); - float defaultTextSize = getResources().getDimension(R.dimen.emptyview_text_size); - float defaultButtonTextSize = getResources().getDimension(R.dimen.emptyview_button_text_size); - - //Loading state attrs - loadingText = a.getText(R.styleable.EmptyView_loadingText); - loadingTextColor = a.getColor(R.styleable.EmptyView_loadingTextColor, Color.BLACK); - loadingTextSize = a.getDimension(R.styleable.EmptyView_loadingTextSize, defaultTitleTextSize); - loadingBackgroundColor = a.getColor(R.styleable.EmptyView_loadingBackgroundColor, 0); - loadingDrawable = a.getDrawable(R.styleable.EmptyView_loadingDrawable); - loadingTint = a.getColor(R.styleable.EmptyView_loadingTint, 0); - loadingStyle = a.getInt(R.styleable.EmptyView_loadingStyle, CIRCULAR); - - //Empty state attrs - emptyTitle = a.getText(R.styleable.EmptyView_emptyTitle); - emptyTitleColor = a.getColor(R.styleable.EmptyView_emptyTitleColor, Color.BLACK); - emptyTitleSize = a.getDimension(R.styleable.EmptyView_emptyTitleSize, defaultTitleTextSize); - emptyText = a.getText(R.styleable.EmptyView_emptyText); - emptyTextColor = a.getColor(R.styleable.EmptyView_emptyTextColor, Color.BLACK); - emptyTextSize = a.getDimension(R.styleable.EmptyView_emptyTextSize, defaultTextSize); - emptyBackgroundColor = a.getColor(R.styleable.EmptyView_emptyBackgroundColor, 0); - emptyDrawable = a.getDrawable(R.styleable.EmptyView_emptyDrawable); - emptyTint = a.getColor(R.styleable.EmptyView_emptyDrawableTint, 0); - emptyLetterSpacing = a.getFloat(R.styleable.EmptyView_emptyLetterSpacing, 0); - emptyLineSpacingExtra = a.getFloat(R.styleable.EmptyView_emptyLineSpacingExtra, 1); - emptyLineSpacingMultiplier = a.getFloat(R.styleable.EmptyView_emptyLineSpacingMultiplier, 1f); - emptyButtonText = a.getText(R.styleable.EmptyView_emptyButtonText); - emptyButtonTextColor = a.getColor(R.styleable.EmptyView_emptyButtonTextColor, Color.BLACK); - emptyButtonTextSize = - a.getDimension(R.styleable.EmptyView_emptyButtonTextSize, defaultButtonTextSize); - emptyButtonBackgroundColor = a.getColor(R.styleable.EmptyView_emptyButtonBackgroundColor, 0); - - //Error state attrs - errorTitle = a.getText(R.styleable.EmptyView_errorTitle); - errorTitleColor = a.getColor(R.styleable.EmptyView_errorTitleColor, Color.BLACK); - errorTitleSize = a.getDimension(R.styleable.EmptyView_errorTitleSize, defaultTitleTextSize); - errorText = a.getText(R.styleable.EmptyView_errorText); - errorTextColor = a.getColor(R.styleable.EmptyView_errorTextColor, Color.BLACK); - errorTextSize = a.getDimension(R.styleable.EmptyView_errorTextSize, defaultTextSize); - errorButtonText = a.getText(R.styleable.EmptyView_errorButtonText); - errorButtonTextColor = a.getColor(R.styleable.EmptyView_errorButtonTextColor, Color.BLACK); - errorButtonTextSize = - a.getDimension(R.styleable.EmptyView_errorButtonTextSize, defaultButtonTextSize); - errorButtonBackgroundColor = a.getColor(R.styleable.EmptyView_errorButtonBackgroundColor, 0); - errorBackgroundColor = a.getColor(R.styleable.EmptyView_errorBackgroundColor, 0); - errorDrawable = a.getDrawable(R.styleable.EmptyView_errorDrawable); - errorTint = a.getColor(R.styleable.EmptyView_errorDrawableTint, 0); - } finally { - a.recycle(); - } + public EmptyViewBuilder setState(@State int state) { + return builder.setState(state); } - private void setChildVisibility(int visibility) { - for (View view : childViews) { - view.setVisibility(visibility); + private void setLoadingDrawable(@Loading int style, @ColorInt int drawableTint) { + if (progressBar.getVisibility() != VISIBLE) { + return; } - } - - private void setupLoadingView() { - setBackgroundColor(loadingBackgroundColor); - if (loadingStyle == TEXT) { + if (style == NONE) { progressBar.setVisibility(GONE); - } else { - progressBar.setVisibility(VISIBLE); - if (loadingTint != 0) { - progressBar.getIndeterminateDrawable().setColorFilter(loadingTint, Mode.SRC_IN); + return; + } + progressBar.setVisibility(VISIBLE); + if (drawableTint != 0) { + Drawable drawable = progressBar.getIndeterminateDrawable(); + if (drawable != null) { + drawable.setColorFilter(drawableTint, Mode.SRC_ATOP); } } - setIcon(loadingDrawable, loadingTint); - setText(loadingText, loadingTextColor, loadingTextSize); - setTypeface(emptyFont); } - private void setupEmptyView() { - setBackgroundColor(emptyBackgroundColor); - if (TextUtils.isEmpty(emptyButtonText)) { - super.setOnClickListener(onClickListener); + private void setDrawable(Drawable drawable, @ColorInt int drawableTint) { + if (imageView.getVisibility() != VISIBLE) { + return; } - setIcon(emptyDrawable, emptyTint); - setTitle(emptyTitle, emptyTitleColor, emptyTitleSize); - setText(emptyText, emptyTextColor, emptyTextSize); - setButton(emptyButtonText, emptyButtonTextColor, emptyButtonTextSize, - emptyButtonBackgroundColor); - setTypeface(emptyFont); - } - - private void setupErrorView() { - setBackgroundColor(errorBackgroundColor); - setIcon(errorDrawable, errorTint); - setTitle(errorTitle, errorTitleColor, errorTitleSize); - setText(errorText, errorTextColor, errorTextSize); - setButton(errorButtonText, errorButtonTextColor, errorButtonTextSize, - errorButtonBackgroundColor); - setTypeface(emptyFont); - } - - private void setIcon(@Nullable Drawable drawable, @ColorInt int tint) { if (drawable == null) { imageView.setVisibility(GONE); - } else { - imageView.setVisibility(VISIBLE); - imageView.setImageDrawable(drawable); - imageView.setColorFilter(tint); + return; } + imageView.setVisibility(VISIBLE); + imageView.setImageDrawable(drawable); + imageView.setColorFilter(drawableTint); } - private void setTitle(@Nullable CharSequence text, @ColorInt int textColor, float textSize) { + private void setTitle(CharSequence text, @ColorInt int textColor) { + if (titleView.getVisibility() != VISIBLE) { + return; + } if (TextUtils.isEmpty(text)) { titleView.setVisibility(GONE); - } else { - titleView.setVisibility(VISIBLE); - titleView.setText(fromHtml(text.toString())); - titleView.setTextColor(textColor); - if (textSize != 0) { - titleView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); - } + return; + } + titleView.setVisibility(VISIBLE); + titleView.setText(EmptyUtils.fromHtml(text.toString())); + titleView.setTextColor(textColor); + titleView.setTypeface(builder.font); + if (builder.titleTextSize != 0) { + EmptyUtils.setTextSize(titleView, builder.titleTextSize); } } - private void setText(@Nullable CharSequence text, @ColorInt int textColor, float textSize) { + private void setText(CharSequence text, @ColorInt int textColor) { + if (textView.getVisibility() != VISIBLE) { + return; + } if (TextUtils.isEmpty(text)) { textView.setVisibility(GONE); - } else { - textView.setVisibility(VISIBLE); - textView.setText(fromHtml(text.toString())); - textView.setTextColor(textColor); - if (textSize != 0) { - textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); - } - textView.setLineSpacing(emptyLineSpacingExtra, emptyLineSpacingMultiplier); - if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { - textView.setLetterSpacing(emptyLetterSpacing); - } + return; + } + textView.setVisibility(VISIBLE); + textView.setText(EmptyUtils.fromHtml(text.toString())); + textView.setTextColor(textColor); + textView.setTypeface(builder.font); + if (builder.textSize != 0) { + EmptyUtils.setTextSize(textView, builder.textSize); + } + textView.setLineSpacing(builder.lineSpacingExtra, builder.lineSpacingMultiplier); + if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { + textView.setLetterSpacing(builder.letterSpacing); } } - private void setButton(@Nullable CharSequence text, + private void setButton(CharSequence text, @ColorInt int textColor, - float textSize, @ColorInt int backgroundColor) { + if (button.getVisibility() != VISIBLE) { + return; + } if (TextUtils.isEmpty(text)) { button.setVisibility(GONE); - } else { - button.setVisibility(VISIBLE); - button.setText(fromHtml(text.toString())); - button.setTextColor(textColor); - if (backgroundColor != 0) { - button.setBackgroundColor(backgroundColor); - } - if (textSize != 0) { - button.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); - } - button.setOnClickListener(onClickListener); + return; } - } - - private String getString(@StringRes int id) { - return id < 0 ? null : getContext().getString(id); - } - - private String fromHtml(@Nullable String text) { - if (TextUtils.isEmpty(text)) { - return null; - } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - return Html.fromHtml(text, Html.FROM_HTML_MODE_COMPACT).toString(); - } else { - return Html.fromHtml(text).toString(); + button.setVisibility(VISIBLE); + button.setText(EmptyUtils.fromHtml(text.toString())); + button.setTextColor(textColor); + button.setBackgroundColor(backgroundColor); + if (builder.buttonTextSize != 0) { + EmptyUtils.setTextSize(button, builder.buttonTextSize); } + button.setTypeface(builder.font); + button.setOnClickListener(builder.onClickListener); } @IntDef({ CONTENT, EMPTY, ERROR, LOADING }) @@ -509,13 +302,8 @@ private String fromHtml(@Nullable String text) { public @interface State { } - @IntDef({ CIRCULAR, TEXT }) + @IntDef({ NONE, CIRCULAR }) @Retention(RetentionPolicy.SOURCE) - public @interface Style { + public @interface Loading { } - - /*@IntDef({ CENTER, TOP, BOTTOM }) - @Retention(RetentionPolicy.SOURCE) - public @interface Position { - }*/ } diff --git a/library/src/main/java/com/santalu/emptyview/EmptyViewBuilder.java b/library/src/main/java/com/santalu/emptyview/EmptyViewBuilder.java new file mode 100644 index 0000000..4eb6a1e --- /dev/null +++ b/library/src/main/java/com/santalu/emptyview/EmptyViewBuilder.java @@ -0,0 +1,414 @@ +package com.santalu.emptyview; + +import android.content.Context; +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.graphics.Typeface; +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.support.annotation.ColorInt; +import android.support.annotation.DimenRes; +import android.support.annotation.DrawableRes; +import android.support.annotation.FontRes; +import android.support.annotation.NonNull; +import android.support.annotation.TransitionRes; +import android.support.transition.Explode; +import android.support.transition.Fade; +import android.support.transition.Slide; +import android.support.transition.Transition; +import android.support.v4.content.res.ResourcesCompat; +import android.util.AttributeSet; +import android.view.View; + +import static com.santalu.emptyview.EmptyView.CIRCULAR; +import static com.santalu.emptyview.EmptyView.EXPLODE; +import static com.santalu.emptyview.EmptyView.FADE; +import static com.santalu.emptyview.EmptyView.NONE; +import static com.santalu.emptyview.EmptyView.SLIDE; + +/** + * Created by santalu on 09/08/2017. + */ + +public class EmptyViewBuilder { + + private final EmptyView emptyView; + private final Context context; + int state; + + // Shared attributes + float titleTextSize; + float textSize; + float buttonTextSize; + float letterSpacing; + float lineSpacingExtra; + float lineSpacingMultiplier; + Typeface font; + Transition transition; + View.OnClickListener onClickListener; + + // Content state attributes + @ColorInt int contentBackgroundColor; + + // Loading state attributes + @EmptyView.Loading int loading; + CharSequence loadingTitle; + @ColorInt int loadingTitleTextColor; + CharSequence loadingText; + @ColorInt int loadingTextColor; + Drawable loadingDrawable; + @ColorInt int loadingDrawableTint; + @ColorInt int loadingBackgroundColor; + + // Empty state attributes + CharSequence emptyTitle; + @ColorInt int emptyTitleTextColor; + CharSequence emptyText; + @ColorInt int emptyTextColor; + CharSequence emptyButtonText; + @ColorInt int emptyButtonTextColor; + @ColorInt int emptyButtonBackgroundColor; + Drawable emptyDrawable; + @ColorInt int emptyDrawableTint; + @ColorInt int emptyBackgroundColor; + + // Error state attributes + CharSequence errorTitle; + @ColorInt int errorTitleTextColor; + CharSequence errorText; + @ColorInt int errorTextColor; + CharSequence errorButtonText; + @ColorInt int errorButtonTextColor; + @ColorInt int errorButtonBackgroundColor; + Drawable errorDrawable; + @ColorInt int errorDrawableTint; + @ColorInt int errorBackgroundColor; + + public EmptyViewBuilder(EmptyView emptyView) { + this.emptyView = emptyView; + this.context = emptyView.getContext(); + } + + public EmptyViewBuilder(EmptyView emptyView, @NonNull AttributeSet attributeSet) { + this(emptyView); + + TypedArray a = context.obtainStyledAttributes(attributeSet, R.styleable.EmptyView); + try { + Resources resources = context.getResources(); + float defaultTitleTextSize = resources.getDimension(R.dimen.emptyview_title_text_size); + float defaultTextSize = resources.getDimension(R.dimen.emptyview_text_size); + float defaultButtonTextSize = resources.getDimension(R.dimen.emptyview_button_text_size); + int defaultTextColor = resources.getColor(android.R.color.secondary_text_dark); + + // Shared attributes + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + font = a.getFont(R.styleable.EmptyView_ev_font); + } else { + int fontResId = a.getResourceId(R.styleable.EmptyView_ev_font, 0); + if (fontResId != 0) { + font = ResourcesCompat.getFont(context, fontResId); + } + } + + int transitionType = a.getInt(R.styleable.EmptyView_ev_transition, NONE); + switch (transitionType) { + case SLIDE: + transition = new Slide(); + break; + case EXPLODE: + transition = new Explode(); + break; + case FADE: + transition = new Fade(); + break; + case NONE: + default: + transition = null; + break; + } + + titleTextSize = a.getDimension(R.styleable.EmptyView_ev_titleTextSize, defaultTitleTextSize); + textSize = a.getDimension(R.styleable.EmptyView_ev_textSize, defaultTextSize); + buttonTextSize = + a.getDimension(R.styleable.EmptyView_ev_buttonTextSize, defaultButtonTextSize); + letterSpacing = a.getDimension(R.styleable.EmptyView_ev_letterSpacing, 0); + lineSpacingExtra = a.getDimension(R.styleable.EmptyView_ev_lineSpacingExtra, 1); + lineSpacingMultiplier = + a.getDimension(R.styleable.EmptyView_ev_lineSpacingExtraMultiplier, 1); + + // Loading state attributes + loading = a.getInt(R.styleable.EmptyView_ev_loading, CIRCULAR); + loadingTitle = a.getText(R.styleable.EmptyView_ev_loading_title); + loadingTitleTextColor = + a.getColor(R.styleable.EmptyView_ev_loading_titleTextColor, defaultTextColor); + loadingText = a.getText(R.styleable.EmptyView_ev_loading_text); + loadingTextColor = a.getColor(R.styleable.EmptyView_ev_loading_textColor, defaultTextColor); + loadingDrawable = a.getDrawable(R.styleable.EmptyView_ev_loading_drawable); + loadingDrawableTint = a.getColor(R.styleable.EmptyView_ev_loading_drawableTint, 0); + loadingBackgroundColor = a.getColor(R.styleable.EmptyView_ev_loading_backgroundColor, 0); + + // Empty state attributes + emptyTitle = a.getText(R.styleable.EmptyView_ev_empty_title); + emptyTitleTextColor = + a.getColor(R.styleable.EmptyView_ev_empty_titleTextColor, defaultTextColor); + emptyText = a.getText(R.styleable.EmptyView_ev_empty_text); + emptyTextColor = a.getColor(R.styleable.EmptyView_ev_empty_textColor, defaultTextColor); + emptyButtonText = a.getText(R.styleable.EmptyView_ev_empty_button); + emptyButtonTextColor = + a.getColor(R.styleable.EmptyView_ev_empty_buttonTextColor, defaultTextColor); + emptyButtonBackgroundColor = + a.getColor(R.styleable.EmptyView_ev_empty_buttonBackgroundColor, 0); + emptyDrawable = a.getDrawable(R.styleable.EmptyView_ev_empty_drawable); + emptyDrawableTint = a.getColor(R.styleable.EmptyView_ev_empty_drawableTint, 0); + emptyBackgroundColor = a.getColor(R.styleable.EmptyView_ev_empty_backgroundColor, 0); + + // Error state attributes + errorTitle = a.getText(R.styleable.EmptyView_ev_error_title); + errorTitleTextColor = + a.getColor(R.styleable.EmptyView_ev_error_titleTextColor, defaultTextColor); + errorText = a.getText(R.styleable.EmptyView_ev_error_text); + errorTextColor = a.getColor(R.styleable.EmptyView_ev_error_textColor, defaultTextColor); + errorButtonText = a.getText(R.styleable.EmptyView_ev_error_button); + errorButtonTextColor = + a.getColor(R.styleable.EmptyView_ev_error_buttonTextColor, defaultTextColor); + errorButtonBackgroundColor = + a.getColor(R.styleable.EmptyView_ev_error_buttonBackgroundColor, 0); + errorDrawable = a.getDrawable(R.styleable.EmptyView_ev_error_drawable); + errorDrawableTint = a.getColor(R.styleable.EmptyView_ev_error_drawableTint, 0); + errorBackgroundColor = a.getColor(R.styleable.EmptyView_ev_error_backgroundColor, 0); + } finally { + a.recycle(); + } + } + + public EmptyViewBuilder setState(@EmptyView.State int state) { + this.state = state; + return this; + } + + public EmptyViewBuilder setTitleTextSize(@DimenRes int id) { + return setTitleTextSize(EmptyUtils.getDimension(context, id)); + } + + public EmptyViewBuilder setTitleTextSize(float titleTextSize) { + this.titleTextSize = titleTextSize; + return this; + } + + public EmptyViewBuilder setTextSize(@DimenRes int id) { + return setTextSize(EmptyUtils.getDimension(context, id)); + } + + public EmptyViewBuilder setTextSize(float textSize) { + this.textSize = textSize; + return this; + } + + public EmptyViewBuilder setButtonTextSize(@DimenRes int id) { + return setButtonTextSize(EmptyUtils.getDimension(context, id)); + } + + public EmptyViewBuilder setButtonTextSize(float buttonTextSize) { + this.buttonTextSize = buttonTextSize; + return this; + } + + public EmptyViewBuilder setLetterSpacing(float letterSpacing) { + this.letterSpacing = letterSpacing; + return this; + } + + public EmptyViewBuilder setLineSpacingExtra(float lineSpacingExtra) { + this.lineSpacingExtra = lineSpacingExtra; + return this; + } + + public EmptyViewBuilder setLineSpacingMultiplier(float lineSpacingMultiplier) { + this.lineSpacingMultiplier = lineSpacingMultiplier; + return this; + } + + public EmptyViewBuilder setFont(@FontRes int id) { + return setFont(EmptyUtils.getFont(context, id)); + } + + public EmptyViewBuilder setFont(Typeface font) { + this.font = font; + return this; + } + + public EmptyViewBuilder setTransition(@TransitionRes int id) { + return setTransition(EmptyUtils.getTransition(context, id)); + } + + public EmptyViewBuilder setTransition(Transition transition) { + this.transition = transition; + return this; + } + + public EmptyViewBuilder setOnClickListener(View.OnClickListener onClickListener) { + this.onClickListener = onClickListener; + return this; + } + + public EmptyViewBuilder setContentBackgroundColor(@ColorInt int contentBackgroundColor) { + this.contentBackgroundColor = contentBackgroundColor; + return this; + } + + public EmptyViewBuilder setLoading(@EmptyView.Loading int loading) { + this.loading = loading; + return this; + } + + public EmptyViewBuilder setLoadingTitle(CharSequence loadingTitle) { + this.loadingTitle = loadingTitle; + return this; + } + + public EmptyViewBuilder setLoadingTitleTextColor(@ColorInt int loadingTitleTextColor) { + this.loadingTitleTextColor = loadingTitleTextColor; + return this; + } + + public EmptyViewBuilder setLoadingText(CharSequence loadingText) { + this.loadingText = loadingText; + return this; + } + + public EmptyViewBuilder setLoadingTextColor(@ColorInt int loadingTextColor) { + this.loadingTextColor = loadingTextColor; + return this; + } + + public EmptyViewBuilder setLoadingDrawable(@DrawableRes int id) { + return setLoadingDrawable(EmptyUtils.getDrawable(context, id)); + } + + public EmptyViewBuilder setLoadingDrawable(Drawable loadingDrawable) { + this.loadingDrawable = loadingDrawable; + return this; + } + + public EmptyViewBuilder setLoadingDrawableTint(@ColorInt int loadingDrawableTint) { + this.loadingDrawableTint = loadingDrawableTint; + return this; + } + + public EmptyViewBuilder setLoadingBackgroundColor(@ColorInt int loadingBackgroundColor) { + this.loadingBackgroundColor = loadingBackgroundColor; + return this; + } + + public EmptyViewBuilder setEmptyTitle(CharSequence emptyTitle) { + this.emptyTitle = emptyTitle; + return this; + } + + public EmptyViewBuilder setEmptyTitleTextColor(@ColorInt int emptyTitleTextColor) { + this.emptyTitleTextColor = emptyTitleTextColor; + return this; + } + + public EmptyViewBuilder setEmptyText(CharSequence emptyText) { + this.emptyText = emptyText; + return this; + } + + public EmptyViewBuilder setEmptyTextColor(@ColorInt int emptyTextColor) { + this.emptyTextColor = emptyTextColor; + return this; + } + + public EmptyViewBuilder setEmptyButtonText(CharSequence emptyButtonText) { + this.emptyButtonText = emptyButtonText; + return this; + } + + public EmptyViewBuilder setEmptyButtonTextColor(@ColorInt int emptyButtonTextColor) { + this.emptyButtonTextColor = emptyButtonTextColor; + return this; + } + + public EmptyViewBuilder setEmptyButtonBackgroundColor(@ColorInt int emptyButtonBackgroundColor) { + this.emptyButtonBackgroundColor = emptyButtonBackgroundColor; + return this; + } + + public EmptyViewBuilder setEmptyDrawable(@DrawableRes int id) { + return setEmptyDrawable(EmptyUtils.getDrawable(context, id)); + } + + public EmptyViewBuilder setEmptyDrawable(Drawable emptyDrawable) { + this.emptyDrawable = emptyDrawable; + return this; + } + + public EmptyViewBuilder setEmptyDrawableTint(@ColorInt int emptyDrawableTint) { + this.emptyDrawableTint = emptyDrawableTint; + return this; + } + + public EmptyViewBuilder setEmptyBackgroundColor(@ColorInt int emptyBackgroundColor) { + this.emptyBackgroundColor = emptyBackgroundColor; + return this; + } + + public EmptyViewBuilder setErrorTitle(CharSequence errorTitle) { + this.errorTitle = errorTitle; + return this; + } + + public EmptyViewBuilder setErrorTitleTextColor(@ColorInt int errorTitleTextColor) { + this.errorTitleTextColor = errorTitleTextColor; + return this; + } + + public EmptyViewBuilder setErrorText(CharSequence errorText) { + this.errorText = errorText; + return this; + } + + public EmptyViewBuilder setErrorTextColor(@ColorInt int errorTextColor) { + this.errorTextColor = errorTextColor; + return this; + } + + public EmptyViewBuilder setErrorButtonText(CharSequence errorButtonText) { + this.errorButtonText = errorButtonText; + return this; + } + + public EmptyViewBuilder setErrorButtonTextColor(@ColorInt int errorButtonTextColor) { + this.errorButtonTextColor = errorButtonTextColor; + return this; + } + + public EmptyViewBuilder setErrorButtonBackgroundColor(@ColorInt int errorButtonBackgroundColor) { + this.errorButtonBackgroundColor = errorButtonBackgroundColor; + return this; + } + + public EmptyViewBuilder setErrorDrawable(@DrawableRes int id) { + return setErrorDrawable(EmptyUtils.getDrawable(context, id)); + } + + public EmptyViewBuilder setErrorDrawable(Drawable errorDrawable) { + this.errorDrawable = errorDrawable; + return this; + } + + public EmptyViewBuilder setErrorDrawableTint(@ColorInt int errorDrawableTint) { + this.errorDrawableTint = errorDrawableTint; + return this; + } + + public EmptyViewBuilder setErrorBackgroundColor(@ColorInt int errorBackgroundColor) { + this.errorBackgroundColor = errorBackgroundColor; + return this; + } + + public void show() { + emptyView.show(); + } +} diff --git a/library/src/main/res/layout/empty_view.xml b/library/src/main/res/layout/empty_view.xml index 7716cd9..67a310c 100644 --- a/library/src/main/res/layout/empty_view.xml +++ b/library/src/main/res/layout/empty_view.xml @@ -10,7 +10,7 @@ android:layout_marginBottom="@dimen/emptyview_inline_spacing" android:layout_marginEnd="@dimen/emptyview_outline_spacing" android:layout_marginStart="@dimen/emptyview_outline_spacing" - android:layout_marginTop="@dimen/emptyview_outline_spacing" + android:tag="@string/emptyview_tag" android:visibility="gone" app:layout_constraintBottom_toTopOf="@+id/empty_progress_bar" app:layout_constraintEnd_toEndOf="parent" @@ -25,6 +25,7 @@ android:layout_marginBottom="@dimen/emptyview_inline_spacing" android:layout_marginEnd="@dimen/emptyview_outline_spacing" android:layout_marginStart="@dimen/emptyview_outline_spacing" + android:tag="@string/emptyview_tag" android:visibility="gone" app:layout_constraintBottom_toTopOf="@+id/empty_title" app:layout_constraintEnd_toEndOf="parent" @@ -38,6 +39,7 @@ android:layout_marginEnd="@dimen/emptyview_outline_spacing" android:layout_marginStart="@dimen/emptyview_outline_spacing" android:gravity="center" + android:tag="@string/emptyview_tag" android:textSize="@dimen/emptyview_title_text_size" android:visibility="gone" app:layout_constraintBottom_toTopOf="@+id/empty_text" @@ -53,6 +55,7 @@ android:layout_marginEnd="@dimen/emptyview_outline_spacing" android:layout_marginStart="@dimen/emptyview_outline_spacing" android:gravity="center" + android:tag="@string/emptyview_tag" android:textSize="@dimen/emptyview_text_size" android:visibility="gone" app:layout_constraintBottom_toTopOf="@+id/empty_button" @@ -64,9 +67,9 @@ android:id="@+id/empty_button" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/emptyview_outline_spacing" android:layout_marginEnd="@dimen/emptyview_outline_spacing" android:layout_marginStart="@dimen/emptyview_outline_spacing" + android:tag="@string/emptyview_tag" android:textAllCaps="false" android:textColor="@android:color/black" android:textSize="@dimen/emptyview_button_text_size" diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 588d2d4..75b8275 100755 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -2,56 +2,58 @@ <resources> <declare-styleable name="EmptyView"> - <attr name="loadingStyle"> - <enum name="circular" value="0"/> - <enum name="text" value="1"/> + <!-- Shared attributes --> + <attr name="ev_transition"> + <enum name="slide" value="1"/> + <enum name="explode" value="2"/> + <enum name="fade" value="3"/> </attr> - <attr format="string" name="loadingText"/> - <attr format="dimension" name="loadingTextSize"/> - <attr format="color" name="loadingTextColor"/> - <attr format="reference" name="loadingDrawable"/> - <attr format="color" name="loadingTint"/> - <attr format="color" name="loadingBackgroundColor"/> - <attr name="emptyTransition"> - <enum name="slide" value="0"/> - <enum name="explode" value="1"/> - <enum name="fade" value="2"/> - </attr> - <attr name="emptyGravity"> - <enum name="center" value="0"/> - <enum name="top" value="1"/> - <enum name="bottom" value="2"/> + + <attr format="reference" name="ev_font"/> + <attr format="dimension" name="ev_titleTextSize"/> + <attr format="dimension" name="ev_textSize"/> + <attr format="dimension" name="ev_letterSpacing"/> + <attr format="dimension" name="ev_lineSpacingExtra"/> + <attr format="dimension" name="ev_lineSpacingExtraMultiplier"/> + <attr format="dimension" name="ev_buttonTextSize"/> + + <!-- Loading state attributes --> + <attr name="ev_loading"> + <enum name="none" value="0"/> + <enum name="circular" value="1"/> </attr> - <attr format="reference" name="emptyFont"/> - <attr format="string" name="emptyTitle"/> - <attr format="dimension" name="emptyTitleSize"/> - <attr format="color" name="emptyTitleColor"/> - <attr format="string" name="emptyText"/> - <attr format="dimension" name="emptyTextSize"/> - <attr format="color" name="emptyTextColor"/> - <attr format="reference" name="emptyDrawable"/> - <attr format="color" name="emptyDrawableTint"/> - <attr format="color" name="emptyBackgroundColor"/> - <attr format="float" name="emptyLetterSpacing"/> - <attr format="float" name="emptyLineSpacingExtra"/> - <attr format="float" name="emptyLineSpacingMultiplier"/> - <attr format="string" name="emptyButtonText"/> - <attr format="dimension" name="emptyButtonTextSize"/> - <attr format="color" name="emptyButtonTextColor"/> - <attr format="color" name="emptyButtonBackgroundColor"/> - <attr format="string" name="errorTitle"/> - <attr format="dimension" name="errorTitleSize"/> - <attr format="color" name="errorTitleColor"/> - <attr format="string" name="errorText"/> - <attr format="dimension" name="errorTextSize"/> - <attr format="color" name="errorTextColor"/> - <attr format="reference" name="errorDrawable"/> - <attr format="color" name="errorDrawableTint"/> - <attr format="color" name="errorBackgroundColor"/> - <attr format="string" name="errorButtonText"/> - <attr format="dimension" name="errorButtonTextSize"/> - <attr format="color" name="errorButtonTextColor"/> - <attr format="color" name="errorButtonBackgroundColor"/> + + <attr format="string" name="ev_loading_title"/> + <attr format="color" name="ev_loading_titleTextColor"/> + <attr format="string" name="ev_loading_text"/> + <attr format="color" name="ev_loading_textColor"/> + <attr format="reference" name="ev_loading_drawable"/> + <attr format="color" name="ev_loading_drawableTint"/> + <attr format="color" name="ev_loading_backgroundColor"/> + + <!-- Empty state attributes --> + <attr format="string" name="ev_empty_title"/> + <attr format="color" name="ev_empty_titleTextColor"/> + <attr format="string" name="ev_empty_text"/> + <attr format="color" name="ev_empty_textColor"/> + <attr format="string" name="ev_empty_button"/> + <attr format="color" name="ev_empty_buttonTextColor"/> + <attr format="color" name="ev_empty_buttonBackgroundColor"/> + <attr format="reference" name="ev_empty_drawable"/> + <attr format="color" name="ev_empty_drawableTint"/> + <attr format="color" name="ev_empty_backgroundColor"/> + + <!-- Error state attributes --> + <attr format="string" name="ev_error_title"/> + <attr format="color" name="ev_error_titleTextColor"/> + <attr format="string" name="ev_error_text"/> + <attr format="color" name="ev_error_textColor"/> + <attr format="string" name="ev_error_button"/> + <attr format="color" name="ev_error_buttonTextColor"/> + <attr format="color" name="ev_error_buttonBackgroundColor"/> + <attr format="reference" name="ev_error_drawable"/> + <attr format="color" name="ev_error_drawableTint"/> + <attr format="color" name="ev_error_backgroundColor"/> </declare-styleable> </resources> diff --git a/library/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml index 76150d9..ae8b44c 100644 --- a/library/src/main/res/values/strings.xml +++ b/library/src/main/res/values/strings.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <resources> + <string name="emptyview_tag">EmptyView</string> <string name="emptyview_loading">Loading…</string> <string name="emptyview_unknown_error_title">Sorry…</string> <string name="emptyview_unknown_error_text">We can not fulfill your request now.\nPlease try again later</string> From 16f73fee69d97d61f2c20fac29b12dcba75ea44e Mon Sep 17 00:00:00 2001 From: santalu <ftsantalu@gmail.com> Date: Thu, 29 Mar 2018 14:31:40 +0300 Subject: [PATCH 4/4] Update version --- .idea/caches/build_file_checksums.ser | Bin 586 -> 586 bytes library/build.gradle | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 232c58bdb83cbf5396bbb9d24d8bd22307743ce2..e8f41234509f115753f389d8d2d06205c3f22819 100644 GIT binary patch delta 35 tcmV+;0Nnq|1j+=Em;`Z#e>Rbv)DUF8>x%It?Pot2Zmu*yFZPpw0m>zz5O4qh delta 35 tcmV+;0Nnq|1j+=Em;`MONsE!3)DZd*9j!Xc&gj4Lv?2dQB9xPW0m>qj5fuOc diff --git a/library/build.gradle b/library/build.gradle index a05529c..ebc10df 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 27 - versionCode 12 - versionName "1.1.5" + versionCode 13 + versionName "1.2" vectorDrawables.useSupportLibrary = true }