Skip to content

Commit

Permalink
feat(*):主页载入错误布局
Browse files Browse the repository at this point in the history
  • Loading branch information
dyjcow committed Nov 22, 2022
1 parent dad2127 commit 4db644f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.work.ListenableWorker;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;
Expand Down Expand Up @@ -51,7 +52,7 @@
import com.qxy.potatos.util.ActivityUtil;
import com.qxy.potatos.util.DisplayUtil;


import com.qxy.potatos.util.EmptyViewUtil;
import com.qxy.potatos.util.LogUtil;
import com.qxy.potatos.util.ToastUtil;
import com.scwang.smart.refresh.footer.ClassicsFooter;
Expand Down Expand Up @@ -294,7 +295,6 @@ public void showPersonalInfo(UserInfo userInfo) {
public void showPersonalVideo(List<MyVideo.Videos> videos, boolean isHasMore, long cursor) {
this.isHasMore = isHasMore;
this.cursor = cursor;
// TODO: 2022/11/21 改为不得重复创建
if (adapter == null){
adapter = new HomeAdapter(R.layout.reycylerview_item_home, list);
adapter.addChildClickViewIds(R.id.home_item_imageView);
Expand Down Expand Up @@ -378,6 +378,28 @@ public void startWork(long duration, @NonNull TimeUnit timeUnit, String tag,
WorkManager.getInstance(this).enqueue(request);
}

@Override public void setErrorView() {
RecyclerView recyclerView = getBinding().recyclerViewHome;
if (recyclerView.getLayoutManager() == null){
recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
}
View emptyView = EmptyViewUtil.getErrorView(recyclerView);
if (mmkv.decodeBool(GlobalConstant.IS_LOGIN, false)){
emptyView.setOnClickListener(v -> {
presenter.getPersonInfo();
presenter.getPersonalVideoList(0);
});
}

if (adapter == null){
adapter = new HomeAdapter(R.layout.reycylerview_item_home, null);
recyclerView.setAdapter(adapter);
}else {
adapter.setList(null);
}
adapter.setEmptyView(emptyView);
}

/**
* 订阅的事件,当请求重新刷新clientToken的时候执行
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void getPersonInfo() {
isLogin = mmkv.decodeBool(GlobalConstant.IS_LOGIN, false);
if (!isLogin) {
RxToast.error("请先登录");
baseView.setErrorView();
return;
}
HashMap<String, String> map = new HashMap<>();
Expand Down Expand Up @@ -77,7 +78,7 @@ public void getPersonalVideoList(long cursor) {
addDisposable(apiServer.GetMyVideos(access_token, openId, map), new BaseObserver<BaseBean<MyVideo>>(baseView, false) {
@Override
public void onError(String msg) {

baseView.setErrorView();
Toast.makeText((Context) baseView, msg, Toast.LENGTH_SHORT).show();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public interface IHomeView extends BaseView {

void startWork(long duration, @NonNull TimeUnit timeUnit,
String tag, @NonNull Class<? extends ListenableWorker> workerClass);

void setErrorView();
}

0 comments on commit 4db644f

Please sign in to comment.