From d465c6108d2c3503f1e3a09bf4774dca936d7982 Mon Sep 17 00:00:00 2001 From: santalu Date: Thu, 29 Mar 2018 15:27:28 +0300 Subject: [PATCH 1/2] Make builder easily accessible through builder() method --- .idea/caches/build_file_checksums.ser | Bin 586 -> 586 bytes .idea/misc.xml | 2 +- app/build.gradle | 5 +++ .../santalu/myapplication/MainActivity.java | 35 ++++++++-------- .../com/santalu/emptyview/EmptyUtils.java | 2 + .../java/com/santalu/emptyview/EmptyView.java | 38 +++++++----------- .../santalu/emptyview/EmptyViewBuilder.java | 25 ++++++++++++ 7 files changed, 65 insertions(+), 42 deletions(-) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index e8f41234509f115753f389d8d2d06205c3f22819..70d2a8d1e6fb6cc5c238136c0e0b742fda0a9608 100644 GIT binary patch delta 35 tcmV+;0Nnq|1j+=EnFF_JT9KT05S)3IlE6&VB~%Kl;IpGknX@ASCjlXR4_g2L delta 35 rcmX@ba*AcbOy;(Fvx#%c1-e - + diff --git a/app/build.gradle b/app/build.gradle index bba7482..a0e5ff1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,6 +19,11 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies { diff --git a/app/src/main/java/com/santalu/myapplication/MainActivity.java b/app/src/main/java/com/santalu/myapplication/MainActivity.java index 507eff1..91ca6a0 100644 --- a/app/src/main/java/com/santalu/myapplication/MainActivity.java +++ b/app/src/main/java/com/santalu/myapplication/MainActivity.java @@ -4,8 +4,6 @@ import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; -import android.view.View; -import android.view.View.OnClickListener; import com.santalu.emptyview.EmptyView; public class MainActivity extends AppCompatActivity { @@ -17,12 +15,19 @@ public class MainActivity extends AppCompatActivity { setContentView(R.layout.activity_main); emptyView = findViewById(R.id.empty_view); - /*emptyView.setState(EmptyView.EMPTY) + /*emptyView.builder() + .setState(EmptyView.EMPTY) .setEmptyDrawable(R.mipmap.ic_launcher) .setEmptyDrawableTint(0) .setEmptyTitle("Empty Title") .setEmptyText("Empty Text") .setEmptyButtonText("Empty Button") + .setOnClickListener(v -> + emptyView.builder() + .setState(EmptyView.LOADING) + .exclude(0) + .show()) + .exclude(R.id.text) .show();*/ } @@ -36,32 +41,28 @@ public class MainActivity extends AppCompatActivity { switch (itemId) { case R.id.show_progress: //emptyView.showLoading(); - emptyView.setState(EmptyView.LOADING) + emptyView.builder() + .setState(EmptyView.LOADING) .show(); break; case R.id.show_content: //emptyView.showContent(); - emptyView.setState(EmptyView.CONTENT) + emptyView.builder() + .setState(EmptyView.CONTENT) .show(); break; case R.id.show_error: //emptyView.showError(); - emptyView.setState(EmptyView.ERROR) - .setOnClickListener(new OnClickListener() { - @Override public void onClick(View v) { - emptyView.showLoading(); - } - }) + emptyView.builder() + .setState(EmptyView.ERROR) + .setOnClickListener(v -> emptyView.showLoading()) .show(); break; case R.id.show_empty: //emptyView.showEmpty(); - emptyView.setState(EmptyView.EMPTY) - .setOnClickListener(new OnClickListener() { - @Override public void onClick(View v) { - emptyView.showLoading(); - } - }) + emptyView.builder() + .setState(EmptyView.EMPTY) + .setOnClickListener(v -> emptyView.showLoading()) .show(); break; } diff --git a/library/src/main/java/com/santalu/emptyview/EmptyUtils.java b/library/src/main/java/com/santalu/emptyview/EmptyUtils.java index a6e91d6..1bcaadf 100644 --- a/library/src/main/java/com/santalu/emptyview/EmptyUtils.java +++ b/library/src/main/java/com/santalu/emptyview/EmptyUtils.java @@ -1,5 +1,6 @@ package com.santalu.emptyview; +import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Typeface; import android.graphics.drawable.Drawable; @@ -24,6 +25,7 @@ * Created by santalu on 09/08/2017. */ +@SuppressLint("ResourceType") final class EmptyUtils { static Drawable getDrawable(Context context, @DrawableRes int id) { diff --git a/library/src/main/java/com/santalu/emptyview/EmptyView.java b/library/src/main/java/com/santalu/emptyview/EmptyView.java index b2bf743..db2cfbd 100644 --- a/library/src/main/java/com/santalu/emptyview/EmptyView.java +++ b/library/src/main/java/com/santalu/emptyview/EmptyView.java @@ -7,7 +7,6 @@ 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.Nullable; import android.support.constraint.ConstraintLayout; @@ -97,27 +96,8 @@ public EmptyView(Context context, AttributeSet attrs, int defStyleAttr) { builder.setOnClickListener(onClickListener); } - public void exclude(@IdRes int... ids) { - for (int id : ids) { - View view = findViewById(id); - if (childViews.contains(view)) { - childViews.remove(view); - } - } - } - - public void exclude(View... views) { - for (View view : views) { - if (childViews.contains(view)) { - childViews.remove(view); - } - } - } - - private void setChildVisibility(int visibility) { - for (View view : childViews) { - view.setVisibility(visibility); - } + public EmptyViewBuilder builder() { + return builder; } public void showContent() { @@ -204,8 +184,18 @@ void show() { } } - public EmptyViewBuilder setState(@State int state) { - return builder.setState(state); + private void setChildVisibility(int visibility) { + if (builder.excludedViews == null || builder.excludedViews.isEmpty()) { + for (View view : childViews) { + view.setVisibility(visibility); + } + return; + } + for (View view : childViews) { + if (!builder.excludedViews.contains(view)) { + view.setVisibility(visibility); + } + } } private void setLoadingDrawable(@Loading int style, @ColorInt int drawableTint) { diff --git a/library/src/main/java/com/santalu/emptyview/EmptyViewBuilder.java b/library/src/main/java/com/santalu/emptyview/EmptyViewBuilder.java index 4eb6a1e..982677a 100644 --- a/library/src/main/java/com/santalu/emptyview/EmptyViewBuilder.java +++ b/library/src/main/java/com/santalu/emptyview/EmptyViewBuilder.java @@ -10,6 +10,7 @@ import android.support.annotation.DimenRes; import android.support.annotation.DrawableRes; import android.support.annotation.FontRes; +import android.support.annotation.IdRes; import android.support.annotation.NonNull; import android.support.annotation.TransitionRes; import android.support.transition.Explode; @@ -19,6 +20,8 @@ import android.support.v4.content.res.ResourcesCompat; import android.util.AttributeSet; import android.view.View; +import java.util.ArrayList; +import java.util.List; import static com.santalu.emptyview.EmptyView.CIRCULAR; import static com.santalu.emptyview.EmptyView.EXPLODE; @@ -34,6 +37,7 @@ public class EmptyViewBuilder { private final EmptyView emptyView; private final Context context; + List excludedViews; int state; // Shared attributes @@ -181,6 +185,27 @@ public EmptyViewBuilder(EmptyView emptyView, @NonNull AttributeSet attributeSet) } } + public EmptyViewBuilder exclude(@IdRes int... ids) { + excludedViews = new ArrayList<>(); + for (int id : ids) { + View view = emptyView.findViewById(id); + if (!excludedViews.contains(view)) { + excludedViews.add(view); + } + } + return this; + } + + public EmptyViewBuilder exclude(View... views) { + excludedViews = new ArrayList<>(); + for (View view : views) { + if (!excludedViews.contains(view)) { + excludedViews.add(view); + } + } + return this; + } + public EmptyViewBuilder setState(@EmptyView.State int state) { this.state = state; return this; From efa54fcf21ef86468b271e05cda28edddc6c17af Mon Sep 17 00:00:00 2001 From: santalu Date: Thu, 29 Mar 2018 15:29:13 +0300 Subject: [PATCH 2/2] 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 70d2a8d1e6fb6cc5c238136c0e0b742fda0a9608..22d6e154d366197a3ce94c1479a2e42ef25822f5 100644 GIT binary patch delta 55 zcmV-70LcH!1j+=EnFG5l9M9=O%UJMi;`^qFqYSR NEUJ(fcf6B;0m`6P80`Q6 delta 55 zcmV-70LcH!1j+=EnFF_JT9KT05S)3IlE6&VB~%Kl;IpGknUf;{O%Px%It?Pot2 NZmu*yFZPpw0m{Wg8Cn1U diff --git a/library/build.gradle b/library/build.gradle index ebc10df..0232f4c 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 27 - versionCode 13 - versionName "1.2" + versionCode 14 + versionName "1.2.1" vectorDrawables.useSupportLibrary = true }