[add] 自定义加载中view
This commit is contained in:
@@ -5,8 +5,6 @@ import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -24,11 +22,10 @@ import com.mogo.module.v2x.listener.AdapterCallback;
|
||||
import com.mogo.module.v2x.network.V2XRefreshCallback;
|
||||
import com.mogo.module.v2x.network.V2XShareNetworkModel;
|
||||
import com.mogo.module.v2x.presenter.ShareEventsPresenter;
|
||||
import com.mogo.module.v2x.utils.animation.V2XAnimationManager;
|
||||
import com.mogo.module.v2x.utils.animation.AnimationResources;
|
||||
import com.mogo.module.v2x.view.V2XNetworkLoadingView;
|
||||
import com.mogo.utils.CheckUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
public class V2XShareEventsFragment extends MvpFragment implements AdapterCallback {
|
||||
|
||||
@@ -37,13 +34,10 @@ public class V2XShareEventsFragment extends MvpFragment implements AdapterCallba
|
||||
private V2XShareEventAdapter adapter;
|
||||
private ArrayList dataArrayList = new ArrayList();
|
||||
private int pageNum = 1;
|
||||
final CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||
private V2XShareNetworkModel v2XShareNetworkModel;
|
||||
|
||||
//动画
|
||||
private ImageView loadingImageView;
|
||||
private V2XAnimationManager v2XAnimationManager;
|
||||
private Button reloadBUtton;
|
||||
private V2XNetworkLoadingView loadingView;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
@@ -53,7 +47,6 @@ public class V2XShareEventsFragment extends MvpFragment implements AdapterCallba
|
||||
@Override
|
||||
protected void initViews() {
|
||||
v2XShareNetworkModel = new V2XShareNetworkModel(getContext());
|
||||
v2XAnimationManager = new V2XAnimationManager();
|
||||
initRecyclerView();
|
||||
initData();
|
||||
}
|
||||
@@ -72,11 +65,11 @@ public class V2XShareEventsFragment extends MvpFragment implements AdapterCallba
|
||||
LinearLayoutManager linearLayoutManager =
|
||||
new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
|
||||
recyclerView.setLayoutManager(linearLayoutManager);
|
||||
loadingView = mRootView.findViewById(R.id.network_loading_imageview);
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
loadingImageView = mRootView.findViewById(R.id.loading_imageview);
|
||||
v2XAnimationManager.animationWithTarget(loadingImageView, AnimationResources.loadingRes, 100);
|
||||
loadingView.start();
|
||||
getShareEventResponse();
|
||||
}
|
||||
|
||||
@@ -84,6 +77,9 @@ public class V2XShareEventsFragment extends MvpFragment implements AdapterCallba
|
||||
* 获取热心指数,分享列表等分享内容
|
||||
* */
|
||||
private void getShareEventResponse() {
|
||||
if (CheckUtils.isNetworkConnected(getContext()) == false) {
|
||||
Log.d(TAG, "网络异常");
|
||||
}
|
||||
v2XShareNetworkModel.getShareEventResponse(pageNum, 10, new V2XRefreshCallback() {
|
||||
@Override
|
||||
public void onSuccess(Object result) {
|
||||
@@ -102,7 +98,7 @@ public class V2XShareEventsFragment extends MvpFragment implements AdapterCallba
|
||||
|
||||
@Override
|
||||
public void onFail(String msg) {
|
||||
loadingError(true);
|
||||
// loadingError(true);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -148,40 +144,17 @@ public class V2XShareEventsFragment extends MvpFragment implements AdapterCallba
|
||||
dataArrayList.add(item);
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
v2XAnimationManager.stop();
|
||||
animatioonAcction(View.INVISIBLE);
|
||||
}
|
||||
|
||||
/*
|
||||
* error界面
|
||||
* */
|
||||
private void loadingError(boolean error) {
|
||||
reloadBUtton = mRootView.findViewById(R.id.loading_error);
|
||||
if (error) {
|
||||
reloadBUtton.setVisibility(View.VISIBLE);
|
||||
reloadBUtton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
v2XShareNetworkModel.getShareEventList(pageNum, 10, new V2XRefreshCallback() {
|
||||
@Override
|
||||
public void onSuccess(Object result) {
|
||||
loadSuccessWithShareEventList(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String msg) {
|
||||
|
||||
}
|
||||
});
|
||||
reloadBUtton.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
private void animatioonAcction(int visible) {
|
||||
if (visible == View.VISIBLE) {
|
||||
loadingView.start();
|
||||
} else {
|
||||
|
||||
loadingView.stop();
|
||||
}
|
||||
v2XAnimationManager.stop();
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected ShareEventsPresenter createPresenter() {
|
||||
@@ -191,9 +164,9 @@ public class V2XShareEventsFragment extends MvpFragment implements AdapterCallba
|
||||
|
||||
@Override
|
||||
public void loadMoreShareEventList() {
|
||||
Log.d(TAG,"page--"+pageNum);
|
||||
v2XAnimationManager.start();
|
||||
pageNum+=1;
|
||||
Log.d(TAG, "page--" + pageNum);
|
||||
animatioonAcction(View.VISIBLE);
|
||||
pageNum += 1;
|
||||
v2XShareNetworkModel.getShareEventList(pageNum, 10, new V2XRefreshCallback() {
|
||||
@Override
|
||||
public void onSuccess(Object result) {
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.mogo.module.v2x.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.mogo.module.v2x.R;
|
||||
import com.mogo.module.v2x.utils.animation.AnimationResources;
|
||||
import com.mogo.module.v2x.utils.animation.V2XAnimationManager;
|
||||
|
||||
public class V2XNetworkLoadingView extends RelativeLayout {
|
||||
|
||||
private ImageView loadView;
|
||||
private TextView textView;
|
||||
private V2XAnimationManager v2XAnimationManager;
|
||||
|
||||
|
||||
public V2XNetworkLoadingView(Context context) {
|
||||
|
||||
super(context);
|
||||
}
|
||||
|
||||
public V2XNetworkLoadingView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
LayoutInflater.from(context).inflate(R.layout.v2x_network_loading_item, this);
|
||||
initView();
|
||||
setLoadingImage(AnimationResources.loadingRes);
|
||||
}
|
||||
|
||||
public V2XNetworkLoadingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public void initView() {
|
||||
v2XAnimationManager = new V2XAnimationManager();
|
||||
loadView = findViewById(R.id.loading_imageview);
|
||||
textView = findViewById(R.id.loading_text);
|
||||
}
|
||||
|
||||
public void setLoadingText(String text) {
|
||||
if (textView != null) {
|
||||
textView.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
public void setLoadingImage(int[] resources) {
|
||||
v2XAnimationManager.animationWithTarget(loadView, resources, 100);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (v2XAnimationManager != null) {
|
||||
v2XAnimationManager.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (v2XAnimationManager != null) {
|
||||
v2XAnimationManager.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user