导航菜单

页面标题

页面副标题

自健身 v3.3.4 - WeightHistoricalDatas.java 源代码

正在查看: 自健身 v3.3.4 应用的 WeightHistoricalDatas.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.mu.gymtrain.Activity.MainPackage;

import android.content.Context;
import android.os.Handler;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;
import com.blankj.utilcode.util.LogUtils;
import com.mu.gymtrain.Adapter.WeightHistoryDatasAdapter;
import com.mu.gymtrain.Base.BaseActivity;
import com.mu.gymtrain.Base.BaseModel;
import com.mu.gymtrain.Bean.WeightBean;
import com.mu.gymtrain.Dialog.WeightDialogHolder;
import com.mu.gymtrain.Http.CreatMap;
import com.mu.gymtrain.Http.HttpHelper;
import com.mu.gymtrain.Http.ResponseFunc;
import com.mu.gymtrain.R;
import com.mu.gymtrain.Utils.ToastUtil;
import com.mu.gymtrain.Utils.ViewUtils;
import com.mu.gymtrain.Widget.xRefresh.BaseRecyclerAdapter;
import com.mu.gymtrain.Widget.xRefresh.XRefreshView;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class WeightHistoricalDatas extends BaseActivity {
    BaseRecyclerAdapter mAdapter;
    List mList = new ArrayList();
    private WeightDialogHolder mWeightDialog;
    private int position;

    @BindView(R.id.recy_weight_history_datas)
    RecyclerView recy_weight_history_datas;

    @BindView(R.id.title_left)
    ImageView titleLeft;

    @BindView(R.id.title_middle)
    TextView titleMiddle;

    @BindView(R.id.xrfv)
    XRefreshView xrfv;

    public int getContentLayout() {
        return R.layout.activity_historical_datas;
    }

    public void initData() {
        getData();
        WeightHistoryDatasAdapter weightHistoryDatasAdapter = new WeightHistoryDatasAdapter(this.mList, this, new WeightHistoryDatasAdapter.AdapterCallBack() {
            @Override
            public void delete(int position) {
                try {
                    WeightHistoricalDatas.this.creatDialog("测量日期\n" + new SimpleDateFormat("yyyy年MM月dd日").format(new SimpleDateFormat("yyyy-MM-dd").parse(((WeightBean) WeightHistoricalDatas.this.mList.get(position)).measure_time)));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                WeightHistoricalDatas.this.position = position;
            }
        });
        this.mAdapter = weightHistoryDatasAdapter;
        this.recy_weight_history_datas.setAdapter(weightHistoryDatasAdapter);
    }

    public void deleteData(int weight_log_id) {
        ViewUtils.showLoading(this, "删除中...");
        HttpHelper.getInstance().getRetrofitService(this).delUserWeight(new CreatMap.Builder().addParams("weight_log_id", weight_log_id + "").build().getParam()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<BaseModel>() {
            public void onCompleted() {
                if (WeightHistoricalDatas.this.mWeightDialog != null) {
                    WeightHistoricalDatas.this.mWeightDialog.mDialog.dismiss();
                }
            }

            public void onError(Throwable e) {
                if (WeightHistoricalDatas.this.mWeightDialog != null) {
                    WeightHistoricalDatas.this.mWeightDialog.mDialog.dismiss();
                }
                ViewUtils.hideLoading();
                LogUtils.i(new Object[]{e.getMessage()});
                ToastUtil.showShort((Context) WeightHistoricalDatas.this, (CharSequence) "删除历史数据失败!");
            }

            public void onNext(BaseModel baseModel) {
                ViewUtils.hideLoading();
                if (WeightHistoricalDatas.this.mWeightDialog != null) {
                    WeightHistoricalDatas.this.mWeightDialog.mDialog.dismiss();
                }
                WeightHistoricalDatas.this.mList.remove(WeightHistoricalDatas.this.position);
                WeightHistoricalDatas.this.mAdapter.notifyItemRemoved(WeightHistoricalDatas.this.position);
                ToastUtil.showShort((Context) WeightHistoricalDatas.this, (CharSequence) "删除历史数据成功!");
            }
        });
    }

    public void initView() {
        this.titleMiddle.setText("历史记录");
        this.xrfv.mPage = 1;
        this.recy_weight_history_datas.setLayoutManager(new LinearLayoutManager(this));
        this.recy_weight_history_datas.setHasFixedSize(true);
        this.recy_weight_history_datas.setItemAnimator((RecyclerView.ItemAnimator) null);
        this.xrfv.setXRefreshViewListener(new XRefreshView.SimpleXRefreshListener() {
            @Override
            public void onRefresh() {
                super.onRefresh();
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        WeightHistoricalDatas.this.xrfv.mPage = 1;
                        WeightHistoricalDatas.this.initData();
                        WeightHistoricalDatas.this.xrfv.stopRefresh();
                    }
                }, 500L);
            }

            @Override
            public void onLoadMore(boolean isSilence) {
                super.onLoadMore(isSilence);
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        WeightHistoricalDatas.this.xrfv.mPage++;
                        WeightHistoricalDatas.this.initData();
                        WeightHistoricalDatas.this.xrfv.stopLoadMore();
                    }
                }, 500L);
            }
        });
    }

    private void getData() {
        ViewUtils.showLoading(this, "加载中...");
        HttpHelper.getInstance().getRetrofitService(this).getUserWeight(new CreatMap.Builder().addParams("pageindex", this.xrfv.mPage + "").addParams("pagesize", "30").build().getParam()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).map(new ResponseFunc()).subscribe(new Subscriber<List<WeightBean>>() {
            public void onCompleted() {
            }

            public void onError(Throwable e) {
                ViewUtils.hideLoading();
                ToastUtil.showShort((Context) WeightHistoricalDatas.this, (CharSequence) "获取历史数据失败!");
            }

            public void onNext(List<WeightBean> listWeightBean) {
                ViewUtils.hideLoading();
                WeightHistoricalDatas.this.mList.clear();
                for (int size = listWeightBean.size(); size > 0; size--) {
                    WeightHistoricalDatas.this.mList.add(0, listWeightBean.get(size - 1));
                }
                WeightHistoricalDatas.this.mAdapter.notifyDataSetChanged();
            }
        });
    }

    @OnClick({R.id.title_left})
    public void onViewClicked(View view) {
        if (view.getId() != 2131297253) {
            return;
        }
        finish();
    }

    public void creatDialog(String content) {
        WeightDialogHolder weightDialogHolder = new WeightDialogHolder(this);
        this.mWeightDialog = weightDialogHolder;
        weightDialogHolder.tvDialogSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WeightHistoricalDatas weightHistoricalDatas = WeightHistoricalDatas.this;
                weightHistoricalDatas.deleteData(((WeightBean) weightHistoricalDatas.mList.get(WeightHistoricalDatas.this.position)).weight_log_id);
            }
        });
        this.mWeightDialog.tvDialogCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WeightHistoricalDatas.this.mWeightDialog.mDialog.dismiss();
            }
        });
        this.mWeightDialog.tvWeightChange.setVisibility(0);
        this.mWeightDialog.tvWeightChange.setText("是否删除本条记录");
        this.mWeightDialog.tvWeightNote.setVisibility(8);
        this.mWeightDialog.tvDialogSure.setText("删除");
        this.mWeightDialog.tv_title.setText(content);
        this.mWeightDialog.mDialog.show();
    }
}