Skip to content

Commit

Permalink
Merge pull request #21 from santalu/development
Browse files Browse the repository at this point in the history
Make builder easily accessible
  • Loading branch information
santalu authored Mar 29, 2018
2 parents 6d53fc6 + efa54fc commit 6348fea
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 44 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
35 changes: 18 additions & 17 deletions app/src/main/java/com/santalu/myapplication/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();*/
}

Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 27
versionCode 13
versionName "1.2"
versionCode 14
versionName "1.2.1"
vectorDrawables.useSupportLibrary = true
}

Expand Down
2 changes: 2 additions & 0 deletions library/src/main/java/com/santalu/emptyview/EmptyUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,6 +25,7 @@
* Created by santalu on 09/08/2017.
*/

@SuppressLint("ResourceType")
final class EmptyUtils {

static Drawable getDrawable(Context context, @DrawableRes int id) {
Expand Down
38 changes: 14 additions & 24 deletions library/src/main/java/com/santalu/emptyview/EmptyView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down
25 changes: 25 additions & 0 deletions library/src/main/java/com/santalu/emptyview/EmptyViewBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -34,6 +37,7 @@ public class EmptyViewBuilder {

private final EmptyView emptyView;
private final Context context;
List<View> excludedViews;
int state;

// Shared attributes
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6348fea

Please sign in to comment.