Skip to content

Commit

Permalink
StateLayout逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
daleige committed Dec 1, 2019
1 parent 9e6a859 commit c481ff5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Author: ChenYangQi
* Description:错误状态管理类
*/
public class ErrorManagerState implements IErrorState {
public class ErrorStateManager implements IErrorState {

private OnRetryClickListener mOnRetryClickListener;
private View mView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Author: ChenYangQi
* Description:加载中状态管理类
*/
public class LoadingManagerState implements ILoadingState {
public class LoadingStateManager implements ILoadingState {
private View mView;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,73 @@
import android.util.AttributeSet;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.cyq.lib_statelayout.interfaces.IErrorState;
import com.cyq.lib_statelayout.state.ErrorStateManager;
import com.cyq.lib_statelayout.state.LoadingStateManager;

/**
* Time: 2019-12-01 22:22
* Author: ChenYangQi
* Description:
* Description:自定义多状态ViewGroup
*/
public class StateLayout extends FrameLayout {
public StateLayout(@NonNull Context context) {
super(context);
private ErrorStateManager mErrorStateManager;
private LoadingStateManager mLoadingStatemanager;

public StateLayout(Context context) {
super(context, null);
}

public StateLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
public StateLayout(Context context, AttributeSet attrs) {
super(context, attrs, 0);
}

public StateLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
public StateLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}

/**
* 初始化几种状态布局管理类
*/
private void init() {
mErrorStateManager = new ErrorStateManager();
mLoadingStatemanager = new LoadingStateManager();
}

/**
* 展示错误状态布局
*/
public void showError() {
if (mErrorStateManager == null) {
mErrorStateManager = new ErrorStateManager();
}
removeView(mErrorStateManager.getView(getContext()));
addView(mErrorStateManager.getView(getContext()));
}

/**
* 展示加载中状态布局
*/
public void showLoading() {
if (mLoadingStatemanager == null) {
mLoadingStatemanager = new LoadingStateManager();
}
removeView(mLoadingStatemanager.getView(getContext()));
addView(mLoadingStatemanager.getView(getContext()));
}

/**
* 设置重试按钮布局
*
* @param onRetryClickListener 重试点击事件
*/
public void setOnRetryClickListener(IErrorState.OnRetryClickListener onRetryClickListener) {
if (mErrorStateManager == null) {
showError();
}
if (mErrorStateManager != null) {
mErrorStateManager.setRetryClickListener(onRetryClickListener);
}
}
}

0 comments on commit c481ff5

Please sign in to comment.