Skip to content

Commit

Permalink
1. change status layout
Browse files Browse the repository at this point in the history
  • Loading branch information
beiger committed Nov 25, 2018
1 parent 0018225 commit 6ff34cc
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 169 deletions.
3 changes: 3 additions & 0 deletions .idea/gradle.xml

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

3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<layout>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ allprojects {
repositories {
google()
jcenter()

maven { url 'https://jitpack.io' }
}
}

Expand Down
8 changes: 3 additions & 5 deletions mvvmbase/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.multidex:multidex:2.0.0'

implementation 'androidx.core:core:1.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
Expand All @@ -38,9 +39,6 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.0.0'
implementation 'androidx.lifecycle:lifecycle-livedata:2.0.0'
implementation 'androidx.lifecycle:lifecycle-common-java8:2.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.0.0'

// navigation
Expand Down Expand Up @@ -97,7 +95,7 @@ dependencies {
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-alpha-14'//没有使用特殊Header,可以不加这行
implementation 'de.hdodenhof:circleimageview:2.2.0' // 圆形imageview
implementation 'com.wang.avi:library:2.1.3'
implementation 'com.kingja.loadsir:loadsir:1.3.6' // 加载状态显示
implementation 'com.github.beiger:StatusLayout:1.00' // 加载状态显示
implementation 'uk.co.chrisjenx:calligraphy:2.3.0' // 字体
implementation 'com.airbnb.android:lottie:2.8.0' // lottie
implementation 'com.eftimoff:android-pathview:1.0.8@aar' // pathview
Expand Down
10 changes: 0 additions & 10 deletions mvvmbase/src/main/java/com/bing/mvvmbase/base/BaseApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import android.content.Context;

import com.bing.mvvmbase.R;
import com.bing.mvvmbase.module.loadingpage.LoadingCallback;
import com.bing.mvvmbase.module.loadingpage.NetErrorCallback;
import com.bing.mvvmbase.module.loadingpage.NoDataCallback;
import com.blankj.utilcode.util.Utils;
import com.kingja.loadsir.core.LoadSir;

import androidx.multidex.MultiDex;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
Expand All @@ -34,12 +30,6 @@ public void onCreate() {
Utils.init(this);
mAppExecutors = new AppExecutors();

LoadSir.beginBuilder()
.addCallback(new LoadingCallback())
.addCallback(new NetErrorCallback())
.addCallback(new NoDataCallback())
.commit();

CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setFontAttrId(R.attr.fontPath)
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void accept(TR response) {
mInitialLoadState.postValue(Status.SUCCESS);

if (response == null || getDataFromResponse(response) == null) {
mNetworkState.postValue(Status.NONE);
mNetworkState.postValue(Status.EMPTY);
} else {
callback.onResult(getDataFromResponse(response), firstKey(), nextKey(firstKey(), response));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@

import com.bing.mvvmbase.R;
import com.bing.mvvmbase.base.BaseViewModel;
import com.bing.mvvmbase.module.loadingpage.LoadingCallback;
import com.bing.mvvmbase.module.loadingpage.NetErrorCallback;
import com.bing.mvvmbase.module.loadingpage.NoDataCallback;
import com.bing.mvvmbase.model.datawrapper.Status;
import com.bing.mvvmbase.utils.DynamicTimeFormat;
import com.kingja.loadsir.callback.Callback;
import com.kingja.loadsir.core.LoadService;
import com.kingja.loadsir.core.LoadSir;
import com.bing.statuslayout.StatusLayout;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
Expand Down Expand Up @@ -42,7 +37,7 @@ public abstract class BasePageActivity<DB extends ViewDataBinding, VM extends Ba
protected RefreshLayout mRefreshLayout;
protected ClassicsHeader mClassicsHeader;
protected AD mAdapter;
protected LoadService mLoadService;
protected StatusLayout mStatusLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -51,12 +46,8 @@ protected void onCreate(Bundle savedInstanceState) {
initViewModel();
getLifecycle().addObserver(mViewModel);
mBinding = DataBindingUtil.setContentView(this, layoutId());
mLoadService = LoadSir.getDefault().register(getRefreshLayout(), new Callback.OnReloadListener() {
@Override
public void onReload(View v) {
reload(v);
}
});

initStatusLayout();
initRefreshLayout();
initRefreshHeader();
initRecycleView();
Expand All @@ -70,7 +61,7 @@ protected void onCreateFirst() {
protected abstract void initViewModel();
protected abstract int layoutId();
protected abstract SmartRefreshLayout getRefreshLayout();
protected abstract void reload(View v);
protected abstract void initStatusLayout();

protected void initRefreshLayout() {
mRefreshLayout = getRefreshLayout();
Expand Down Expand Up @@ -124,19 +115,23 @@ public void onChanged(@Nullable Status status) {
}
switch (status) {
case LOADING:
mLoadService.showCallback(LoadingCallback.class);
mStatusLayout.showViewByStatus(StatusLayout.STATUS_LOADING);
break;

case SUCCESS:
mLoadService.showSuccess();
mStatusLayout.showViewByStatus(StatusLayout.STATUS_CONTENT);
break;

case ERROR:
mLoadService.showCallback(NetErrorCallback.class);
mStatusLayout.showViewByStatus(StatusLayout.STATUS_ERROR);
break;

case EMPTY:
mStatusLayout.showViewByStatus(StatusLayout.STATUS_EMPTY);
break;

case NONE:
mLoadService.showCallback(NoDataCallback.class);
case NO_NETWORK:
mStatusLayout.showViewByStatus(StatusLayout.STATUS_NO_NETWORK);
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@

import com.bing.mvvmbase.R;
import com.bing.mvvmbase.base.BaseFragment;
import com.bing.mvvmbase.module.loadingpage.LoadingCallback;
import com.bing.mvvmbase.module.loadingpage.NetErrorCallback;
import com.bing.mvvmbase.module.loadingpage.NoDataCallback;
import com.bing.mvvmbase.model.datawrapper.Status;
import com.bing.mvvmbase.utils.DynamicTimeFormat;
import com.kingja.loadsir.callback.Callback;
import com.kingja.loadsir.core.LoadService;
import com.kingja.loadsir.core.LoadSir;
import com.bing.statuslayout.StatusLayout;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
Expand All @@ -38,29 +33,25 @@ public abstract class BasePageFragment<AD extends PagedListAdapter, T> extends B
protected RefreshLayout mRefreshLayout;
protected ClassicsHeader mClassicsHeader;
protected AD mAdapter;
protected LoadService mLoadService;
protected StatusLayout mStatusLayout;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mBinding = DataBindingUtil.inflate(inflater, layoutId(), container, false);
initView();
return mLoadService.getLoadLayout();
return mBinding.getRoot();
}

@Override
protected void initView() {
mLoadService = LoadSir.getDefault().register(mBinding.getRoot(), new Callback.OnReloadListener() {
@Override
public void onReload(View v) {
reload(v);
}
});
initStatusLayout();
initRefreshLayout();
initRefreshHeader();
initRecycleView();
}

protected abstract void reload(View view);
protected abstract void initStatusLayout();

protected void initRefreshLayout() {
mRefreshLayout = getRefreshLayout();
mRefreshLayout.setEnableLoadMore(false);
Expand Down Expand Up @@ -116,19 +107,23 @@ public void onChanged(@Nullable Status status) {
}
switch (status) {
case LOADING:
mLoadService.showCallback(LoadingCallback.class);
mStatusLayout.showViewByStatus(StatusLayout.STATUS_LOADING);
break;

case SUCCESS:
mLoadService.showSuccess();
mStatusLayout.showViewByStatus(StatusLayout.STATUS_CONTENT);
break;

case ERROR:
mLoadService.showCallback(NetErrorCallback.class);
mStatusLayout.showViewByStatus(StatusLayout.STATUS_ERROR);
break;

case EMPTY:
mStatusLayout.showViewByStatus(StatusLayout.STATUS_EMPTY);
break;

case NONE:
mLoadService.showCallback(NoDataCallback.class);
case NO_NETWORK:
mStatusLayout.showViewByStatus(StatusLayout.STATUS_NO_NETWORK);
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,22 @@

import com.bing.mvvmbase.R;
import com.bing.mvvmbase.base.BaseViewModel;
import com.bing.mvvmbase.module.loadingpage.LoadingCallback;
import com.bing.mvvmbase.module.loadingpage.NetErrorCallback;
import com.bing.mvvmbase.module.loadingpage.NoDataCallback;
import com.bing.mvvmbase.model.datawrapper.Status;
import com.bing.mvvmbase.utils.DynamicTimeFormat;
import com.kingja.loadsir.callback.Callback;
import com.kingja.loadsir.core.LoadService;
import com.kingja.loadsir.core.LoadSir;
import com.bing.statuslayout.StatusLayout;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Random;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.DefaultItemAnimator;
Expand All @@ -45,7 +36,7 @@ public abstract class BaseRecycleViewActivity<DB extends ViewDataBinding, VM ext
protected RefreshLayout mRefreshLayout;
protected ClassicsHeader mClassicsHeader;
protected AD mAdapter;
protected LoadService mLoadService;
protected StatusLayout mStatusLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -54,12 +45,7 @@ protected void onCreate(Bundle savedInstanceState) {
initViewModel();
getLifecycle().addObserver(mViewModel);
mBinding = DataBindingUtil.setContentView(this, layoutId());
mLoadService = LoadSir.getDefault().register(getRefreshLayout(), new Callback.OnReloadListener() {
@Override
public void onReload(View v) {
reload(v);
}
});
initStatusLayout();
initRefreshLayout();
initRefreshHeader();
initRecycleView();
Expand All @@ -73,7 +59,7 @@ protected void onCreateFirst() {
protected abstract void initViewModel();
protected abstract int layoutId();
protected abstract SmartRefreshLayout getRefreshLayout();
protected abstract void reload(View v);
protected abstract void initStatusLayout();

protected void initRefreshLayout() {
mRefreshLayout = getRefreshLayout();
Expand Down Expand Up @@ -128,19 +114,23 @@ public void onChanged(@Nullable Status status) {
}
switch (status) {
case LOADING:
mLoadService.showCallback(LoadingCallback.class);
mStatusLayout.showViewByStatus(StatusLayout.STATUS_LOADING);
break;

case SUCCESS:
mLoadService.showSuccess();
mStatusLayout.showViewByStatus(StatusLayout.STATUS_CONTENT);
break;

case ERROR:
mLoadService.showCallback(NetErrorCallback.class);
mStatusLayout.showViewByStatus(StatusLayout.STATUS_ERROR);
break;

case EMPTY:
mStatusLayout.showViewByStatus(StatusLayout.STATUS_EMPTY);
break;

case NONE:
mLoadService.showCallback(NoDataCallback.class);
case NO_NETWORK:
mStatusLayout.showViewByStatus(StatusLayout.STATUS_NO_NETWORK);
break;

default:
Expand Down
Loading

0 comments on commit 6ff34cc

Please sign in to comment.