diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index e8f4123..22d6e15 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/misc.xml b/.idea/misc.xml index 3963879..75dac50 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -24,7 +24,7 @@ - + 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/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 } 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;