Skip to content

Commit

Permalink
🐒 fix #9 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Bakumon committed Jun 7, 2018
1 parent 46e998c commit 22d0b84
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 66 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ allprojects {

```
dependencies {
compile 'com.github.Bakumon:StatusLayoutManager:1.0.3'
compile 'com.github.Bakumon:StatusLayoutManager:1.0.4'
}
```

Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 11
targetSdkVersion 26
versionCode 3
versionName "1.0.3"
versionCode 4
versionName "1.0.4"
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@

public class StatusLayoutManager {

/**
* 三种默认布局 ID
*/
private static final int DEFAULT_LOADING_LAYOUT_ID = R.layout.layout_status_layout_manager_loading;
private static final int DEFAULT_EMPTY_LAYOUT_ID = R.layout.layout_status_layout_manager_empty;
private static final int DEFAULT_ERROR_LAYOUT_ID = R.layout.layout_status_layout_manager_error;

/**
* 默认布局中可点击的 view ID
*/
private static final int DEFAULT_EMPTY_CLICKED_ID = R.id.bt_status_empty_click;
private static final int DEFAULT_ERROR_CLICKED_ID = R.id.bt_status_error_click;

/**
* 默认颜色
*/
private static final int DEFAULT_CLICKED_TEXT_COLOR = R.color.status_layout_click_view_text_color;
private static final int DEFAULT_BACKGROUND_COLOR = R.color.status_layout_background_color;

private View contentLayout;

@LayoutRes
Expand Down Expand Up @@ -120,7 +139,8 @@ public void showSuccessLayout() {
private void createLoadingLayout() {
if (loadingLayout == null) {
loadingLayout = inflate(loadingLayoutID);
} else {
}
if (loadingLayoutID == DEFAULT_LOADING_LAYOUT_ID) {
loadingLayout.setBackgroundColor(defaultBackgroundColor);
}
if (!TextUtils.isEmpty(loadingText)) {
Expand Down Expand Up @@ -159,27 +179,23 @@ public void showLoadingLayout() {
private void createEmptyLayout() {
if (emptyLayout == null) {
emptyLayout = inflate(emptyLayoutID);
} else {
emptyLayout.setBackgroundColor(defaultBackgroundColor);
}

if (onStatusChildClickListener == null) {
return;
if (emptyLayoutID == DEFAULT_EMPTY_LAYOUT_ID) {
emptyLayout.setBackgroundColor(defaultBackgroundColor);
}

// 点击事件回调
View view = emptyLayout.findViewById(emptyClickViewId);
if (view == null) {
return;
if (view != null && onStatusChildClickListener != null) {
// 设置点击按钮点击时事件回调
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onStatusChildClickListener.onEmptyChildClick(view);
}
});
}

// 设置点击按钮点击时事件回调
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onStatusChildClickListener.onEmptyChildClick(view);
}
});

// 设置默认空数据布局的提示文本
if (!TextUtils.isEmpty(emptyText)) {
TextView emptyTextView = emptyLayout.findViewById(R.id.tv_status_empty_content);
Expand All @@ -196,19 +212,18 @@ public void onClick(View view) {
}
}

TextView emptyClickViewTextView = emptyLayout.findViewById(R.id.bt_status_empty_click);
if (emptyClickViewTextView == null) {
return;
}
// 设置点击按钮的文本和可见性
if (isEmptyClickViewVisible) {
emptyClickViewTextView.setVisibility(View.VISIBLE);
if (!TextUtils.isEmpty(emptyClickViewText)) {
emptyClickViewTextView.setText(emptyClickViewText);
TextView emptyClickViewTextView = emptyLayout.findViewById(DEFAULT_EMPTY_CLICKED_ID);
if (emptyClickViewTextView != null) {
// 设置点击按钮的文本和可见性
if (isEmptyClickViewVisible) {
emptyClickViewTextView.setVisibility(View.VISIBLE);
if (!TextUtils.isEmpty(emptyClickViewText)) {
emptyClickViewTextView.setText(emptyClickViewText);
}
emptyClickViewTextView.setTextColor(emptyClickViewTextColor);
} else {
emptyClickViewTextView.setVisibility(View.GONE);
}
emptyClickViewTextView.setTextColor(emptyClickViewTextColor);
} else {
emptyClickViewTextView.setVisibility(View.GONE);
}
}

Expand Down Expand Up @@ -240,27 +255,22 @@ public void showEmptyLayout() {
private void createErrorLayout() {
if (errorLayout == null) {
errorLayout = inflate(errorLayoutID);
} else {
errorLayout.setBackgroundColor(defaultBackgroundColor);
}

if (onStatusChildClickListener == null) {
return;
if (errorLayoutID == DEFAULT_ERROR_LAYOUT_ID) {
errorLayout.setBackgroundColor(defaultBackgroundColor);
}

View view = errorLayout.findViewById(errorClickViewId);
if (view == null) {
return;
if (view != null && onStatusChildClickListener != null) {
// 设置点击按钮点击时事件回调
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onStatusChildClickListener.onErrorChildClick(view);
}
});
}

// 设置点击按钮点击时事件回调
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onStatusChildClickListener.onErrorChildClick(view);
}
});

// 设置默认出错布局的提示文本
if (!TextUtils.isEmpty(errorText)) {
TextView errorTextView = errorLayout.findViewById(R.id.tv_status_error_content);
Expand All @@ -277,19 +287,18 @@ public void onClick(View view) {
}
}

TextView errorClickViewTextView = errorLayout.findViewById(R.id.bt_status_error_click);
if (errorClickViewTextView == null) {
return;
}
// 设置点击按钮的文本和可见性
if (isErrorClickViewVisible) {
errorClickViewTextView.setVisibility(View.VISIBLE);
if (!TextUtils.isEmpty(errorClickViewText)) {
errorClickViewTextView.setText(errorClickViewText);
TextView errorClickViewTextView = errorLayout.findViewById(DEFAULT_ERROR_CLICKED_ID);
if (errorClickViewTextView != null) {
// 设置点击按钮的文本和可见性
if (isErrorClickViewVisible) {
errorClickViewTextView.setVisibility(View.VISIBLE);
if (!TextUtils.isEmpty(errorClickViewText)) {
errorClickViewTextView.setText(errorClickViewText);
}
errorClickViewTextView.setTextColor(errorClickViewTextColor);
} else {
errorClickViewTextView.setVisibility(View.GONE);
}
errorClickViewTextView.setTextColor(errorClickViewTextColor);
} else {
errorClickViewTextView.setVisibility(View.GONE);
}
}

Expand Down Expand Up @@ -421,19 +430,19 @@ public static final class Builder {
public Builder(@NonNull View contentLayout) {
this.contentLayout = contentLayout;
// 设置默认布局
this.loadingLayoutID = R.layout.layout_status_layout_manager_loading;
this.emptyLayoutID = R.layout.layout_status_layout_manager_empty;
this.errorLayoutID = R.layout.layout_status_layout_manager_error;
this.loadingLayoutID = DEFAULT_LOADING_LAYOUT_ID;
this.emptyLayoutID = DEFAULT_EMPTY_LAYOUT_ID;
this.errorLayoutID = DEFAULT_ERROR_LAYOUT_ID;
// 设置默认点击点击view id
this.emptyClickViewId = R.id.bt_status_empty_click;
this.errorClickViewId = R.id.bt_status_error_click;
this.emptyClickViewId = DEFAULT_EMPTY_CLICKED_ID;
this.errorClickViewId = DEFAULT_ERROR_CLICKED_ID;
// 设置默认点击按钮属性
this.isEmptyClickViewVisible = true;
this.emptyClickViewTextColor = contentLayout.getContext().getResources().getColor(R.color.status_layout_click_view_text_color);
this.emptyClickViewTextColor = contentLayout.getContext().getResources().getColor(DEFAULT_CLICKED_TEXT_COLOR);
this.isErrorClickViewVisible = true;
this.errorClickViewTextColor = contentLayout.getContext().getResources().getColor(R.color.status_layout_click_view_text_color);
this.errorClickViewTextColor = contentLayout.getContext().getResources().getColor(DEFAULT_CLICKED_TEXT_COLOR);
// 设置默认背景色
this.defaultBackgroundColor = contentLayout.getContext().getResources().getColor(R.color.status_layout_background_color);
this.defaultBackgroundColor = contentLayout.getContext().getResources().getColor(DEFAULT_BACKGROUND_COLOR);
}

///////////////////////////////////////////
Expand Down

0 comments on commit 22d0b84

Please sign in to comment.