package cn.flightfeather.thirdapp.module.home;
|
|
|
import android.content.Context;
|
import android.content.Intent;
|
import android.os.Build;
|
import android.os.Bundle;
|
import android.support.annotation.NonNull;
|
import android.support.annotation.Nullable;
|
import android.support.annotation.RequiresApi;
|
import android.support.constraint.ConstraintLayout;
|
import android.support.v4.app.Fragment;
|
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.RecyclerView;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.view.Window;
|
import android.widget.AdapterView;
|
import android.widget.Button;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.Spinner;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.amap.api.location.AMapLocation;
|
import com.amap.api.location.AMapLocationClient;
|
import com.amap.api.location.AMapLocationClientOption;
|
import com.amap.api.location.AMapLocationListener;
|
import com.amap.api.services.weather.LocalWeatherForecastResult;
|
import com.amap.api.services.weather.LocalWeatherLive;
|
import com.amap.api.services.weather.LocalWeatherLiveResult;
|
import com.amap.api.services.weather.WeatherSearch;
|
import com.amap.api.services.weather.WeatherSearchQuery;
|
import com.github.mikephil.charting.charts.HorizontalBarChart;
|
import com.ping.greendao.gen.DomainitemDao;
|
|
import org.greenrobot.greendao.query.QueryBuilder;
|
|
import java.util.ArrayList;
|
import java.util.Calendar;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import butterknife.BindView;
|
import butterknife.ButterKnife;
|
import butterknife.Unbinder;
|
import cn.flightfeather.thirdapp.CommonApplication;
|
import cn.flightfeather.thirdapp.R;
|
import cn.flightfeather.thirdapp.adapter.AllListViewAdapter;
|
import cn.flightfeather.thirdapp.bean.entity.Domainitem;
|
import cn.flightfeather.thirdapp.bean.entity.Subtask;
|
import cn.flightfeather.thirdapp.bean.vo.TaskPack;
|
import cn.flightfeather.thirdapp.bean.vo.AreaVo;
|
import cn.flightfeather.thirdapp.bean.vo.ChargeInfoVo;
|
import cn.flightfeather.thirdapp.bean.vo.InspectionVo;
|
import cn.flightfeather.thirdapp.bean.vo.StatisticsVo;
|
import cn.flightfeather.thirdapp.bean.vo.TaskVo;
|
import cn.flightfeather.thirdapp.httpservice.ProblemListService;
|
import cn.flightfeather.thirdapp.httpservice.TaskService;
|
import cn.flightfeather.thirdapp.module.nightwork.NightWorkManageActivity;
|
import cn.flightfeather.thirdapp.util.ChartGenerator;
|
import cn.flightfeather.thirdapp.util.CommonUtils;
|
import cn.flightfeather.thirdapp.util.Constant;
|
import cn.flightfeather.thirdapp.util.DateFormatter;
|
import cn.flightfeather.thirdapp.util.Domain;
|
import cn.flightfeather.thirdapp.util.ScreenUtils;
|
import cn.flightfeather.thirdapp.view.MyScrollView;
|
import retrofit2.Call;
|
import retrofit2.Callback;
|
import retrofit2.Response;
|
import retrofit2.Retrofit;
|
|
/**
|
* A simple {@link Fragment} subclass.
|
*/
|
public class HomeFragment_comptent extends Fragment implements WeatherSearch.OnWeatherSearchListener, View.OnClickListener {
|
private TextView tv_location;
|
private ImageView iv_weather_icon;
|
private TextView tv_temperature;
|
private TextView tv_weather;
|
private LinearLayout ll_weatherBG;
|
private TextView tv_timeCurrent;
|
private View sv_home_page;
|
private boolean hidden = false;
|
private CommonApplication application;
|
//定位相关
|
private AMapLocationClient mLocationClient = null;
|
//查询天气相关
|
private boolean searchWeather = true;
|
private WeatherSearchQuery query;
|
private WeatherSearch mweathersearch;
|
private String temperature, weather;
|
//
|
private ViewHolder1 viewHolder1;
|
private ViewHolder2 viewHolder2;
|
private ViewHolder3 viewHolder3;
|
private ViewHolder4 viewHolder4;
|
private ViewHolder5 viewHolder5;
|
//ViewHolder1(今日任务)
|
private Map<String, List<TaskVo>> taskAllMapList = new HashMap<>();//Map<时间, 所有任务(顶层任务、日任务、子任务)>
|
private ArrayList<Subtask> mSubtaskList = new ArrayList<>();
|
private ArrayList<Subtask> subtaskListOfUser = new ArrayList<>();
|
private ArrayList<TaskVo> mDayTaskList = new ArrayList<>();
|
private Calendar calendarCurrent;
|
private String mCurYearMonth;
|
private String mToday;
|
private boolean requestAgain;
|
private Retrofit mRetrofit;
|
private boolean firstLoad = true;
|
private ViewHolder1Adapter viewHolder1Adapter;
|
private final int VISIBLENUM = 2;//今日任务显示最少的任务数
|
private Boolean visibility = false;
|
private Subtask subtask;
|
private InspectionVo inspectionVo;
|
//当前场景类型
|
private String curSceneType = "1";
|
private List<Domainitem> sceneTypeData = new ArrayList<>();//场景类型
|
//状态栏与标题栏的高度和为滑动组件悬停的最大高度
|
private int topHeight;
|
private Unbinder unbinder;
|
|
@Override
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
Bundle savedInstanceState) {
|
// Inflate the layout for this fragment
|
View view = inflater.inflate(R.layout.fragment_home_competent, container, false);
|
unbinder = ButterKnife.bind(this, view);
|
return view;
|
}
|
|
@Override
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
super.onViewCreated(view, savedInstanceState);
|
searchWeather = true;
|
initData();
|
initUI(view);
|
initSpinner(view);
|
initHeadView(view);
|
initCurLocation();
|
initCurrentTime();
|
initScrollView(savedInstanceState);
|
}
|
|
@Override
|
public void onDestroy() {
|
if (unbinder != null) {
|
unbinder.unbind();
|
}
|
super.onDestroy();
|
mLocationClient.onDestroy();
|
}
|
|
@Override
|
public void onPause() {
|
super.onPause();
|
mLocationClient.stopLocation();
|
searchWeather = true;
|
}
|
|
@Override
|
public void onResume() {
|
super.onResume();
|
if (!hidden){
|
mLocationClient.startLocation();
|
initCurrentTime();
|
}
|
// refreshView();
|
}
|
|
@Override
|
public void onStart() {
|
super.onStart();
|
int statusBarHeight = ScreenUtils.getStatusHeight(getActivity());//状态栏高度
|
|
int titleBarHeight = getActivity().getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();//标题栏高度
|
topHeight = titleBarHeight + statusBarHeight;
|
}
|
|
public HomeFragment_comptent() {
|
// Required empty public constructor
|
}
|
|
//场景分类选择区域
|
Spinner spinner_scene_type_top;
|
Spinner spinner_scene_type_middle;
|
|
ImageView image_scene_type_top;
|
ImageView image_scene_type_middle;
|
|
Button btn_search_top;
|
Button btn_search_middle;
|
/**
|
* 初始化下拉框数据
|
*/
|
private void initSpinner(View view) {
|
View topPanel = view.findViewById(R.id.topPanel_);
|
spinner_scene_type_top =topPanel.findViewById(R.id.sp_scene_type);
|
image_scene_type_top =topPanel.findViewById(R.id.image_scene_type);
|
btn_search_top = topPanel.findViewById(R.id.btn_search);
|
|
View middlePanel = view.findViewById(R.id.middlePanel);
|
spinner_scene_type_middle = middlePanel.findViewById(R.id.sp_scene_type);
|
image_scene_type_middle = middlePanel.findViewById(R.id.image_scene_type);
|
btn_search_middle = middlePanel.findViewById(R.id.btn_search);
|
|
final DomainitemDao domainitemDao = application.getDaoSession().getDomainitemDao();
|
|
//场景类型
|
QueryBuilder<Domainitem> queryBuilder = domainitemDao.queryBuilder()
|
.where(DomainitemDao.Properties.Dcguid.eq(Domain.DOMAINGUID_SCENSETYPE))
|
.orderAsc(DomainitemDao.Properties.Value);
|
sceneTypeData.addAll(queryBuilder.list());
|
|
//场景类型
|
AllListViewAdapter<Domainitem> sceneAdapter = new AllListViewAdapter<Domainitem>((ArrayList<Domainitem>) sceneTypeData, R.layout.item_spinner_simple_text) {
|
@Override
|
public void bindView(ViewHolder holder, Domainitem obj) {
|
holder.setText(R.id.tv_item, obj.getText());
|
}
|
};
|
spinner_scene_type_top.setAdapter(sceneAdapter);
|
spinner_scene_type_middle.setAdapter(sceneAdapter);
|
sceneAdapter.notifyDataSetChanged();
|
|
//选择场景类型后,点击查询按钮联网刷新
|
spinner_scene_type_top.setOnItemSelectedListener(new SceneSelectedListener());
|
spinner_scene_type_middle.setOnItemSelectedListener(new SceneSelectedListener());
|
btn_search_top.setOnClickListener(this);
|
btn_search_middle.setOnClickListener(this);
|
|
}
|
|
/**
|
* 场景类型下拉框选择监听器
|
*/
|
class SceneSelectedListener implements AdapterView.OnItemSelectedListener{
|
|
@Override
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
switch (parent.getId()) {
|
case R.id.sp_scene_type:
|
spinner_scene_type_top.setSelection(position);
|
spinner_scene_type_middle.setSelection(position);
|
curSceneType = ((Domainitem)spinner_scene_type_top.getSelectedItem()).getValue();
|
image_scene_type_top.setImageResource(CommonUtils.getIconBySceneType(((Domainitem)spinner_scene_type_top.getSelectedItem()).getValue()));
|
image_scene_type_middle.setImageResource(CommonUtils.getIconBySceneType(((Domainitem)spinner_scene_type_top.getSelectedItem()).getValue()));
|
// refreshView();
|
}
|
}
|
|
@Override
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
}
|
}
|
|
MyScrollView sv_home_base;
|
|
LinearLayout ll_weather_detail;
|
|
private void initHeadView(View view) {
|
sv_home_base = view.findViewById(R.id.sv_home_base);
|
ll_weather_detail = view.findViewById(R.id.ll_weather_detail);
|
final View topPanel = view.findViewById(R.id.topPanel_);
|
final View middlePanel = view.findViewById(R.id.middlePanel);
|
sv_home_base.setHeaderView(ll_weatherBG, ll_weather_detail);
|
sv_home_base.setScrollViewListener(new MyScrollView.ScrollViewListener() {
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
@Override
|
public void onScrollChanged(MyScrollView scrollView, int x, int y, int oldx, int oldy) {
|
int[] location = new int[2];
|
middlePanel.getLocationOnScreen(location);
|
int locationY = location[1];
|
|
if (locationY <= topHeight && (topPanel.getVisibility() == View.GONE || topPanel.getVisibility() == View.INVISIBLE)) {
|
topPanel.setVisibility(View.GONE);
|
topPanel.setElevation(2f);
|
}
|
|
if (locationY > topHeight && topPanel.getVisibility() == View.VISIBLE) {
|
topPanel.setVisibility(View.GONE);
|
}
|
|
}
|
});
|
}
|
|
private void initData(){
|
application = (CommonApplication) getActivity().getApplication();
|
mRetrofit = application.getRetrofit();
|
Date now = Calendar.getInstance().getTime();
|
mCurYearMonth = DateFormatter.YearMonthFormat.format(now);
|
mToday = DateFormatter.dateFormat2.format(now);
|
}
|
|
private void initUI(View view) {
|
tv_location = (TextView) view.findViewById(R.id.tv_location);
|
tv_location.setOnClickListener(this);
|
iv_weather_icon = (ImageView) view.findViewById(R.id.iv_weather_icon);
|
//
|
iv_weather_icon.setOnClickListener(this);
|
//
|
tv_temperature = (TextView) view.findViewById(R.id.tv_temperature);
|
tv_weather = (TextView) view.findViewById(R.id.tv_weather);
|
ll_weatherBG = (LinearLayout) view.findViewById(R.id.ll_weather_bg);
|
tv_timeCurrent = (TextView) view.findViewById(R.id.tv_now_date_time);
|
sv_home_page = view.findViewById(R.id.sv_home_page);
|
}
|
//初始化时间textView
|
private void initCurrentTime() {
|
Calendar calendar = Calendar.getInstance();
|
tv_timeCurrent.setText(DateFormatter.dateFormatWeek.format(calendar.getTime()));
|
}
|
|
private void initScrollView(Bundle savedInstanceState){
|
// sv_home_page.setLayoutManager(new LinearLayoutManager(getContext()));
|
// parentAdapter = new RecyclerViewAdapter(getContext(),savedInstanceState);
|
// sv_home_page.setAdapter(parentAdapter);
|
viewHolder1 = new ViewHolder1(savedInstanceState, sv_home_page);
|
viewHolder2 = new ViewHolder2(savedInstanceState, sv_home_page);
|
viewHolder3 = new ViewHolder3(savedInstanceState, sv_home_page);
|
viewHolder4 = new ViewHolder4(savedInstanceState, sv_home_page);
|
viewHolder5 = new ViewHolder5(savedInstanceState, sv_home_page);
|
viewHolder1.initViewHolder1();
|
viewHolder2.initViewholder2();
|
viewHolder3.initViewHolder3();
|
viewHolder5.initViewHolder5();
|
}
|
|
|
private void initCurLocation() {
|
final String curLocation = null;
|
//声明定位回调监听器
|
AMapLocationListener mLocationListener = new AMapLocationListener() {
|
@Override
|
public void onLocationChanged(AMapLocation aMapLocation) {
|
if (aMapLocation != null) {
|
if (aMapLocation.getErrorCode() == 0) {
|
//可在其中解析amapLocation获取相应内容
|
//城市地址
|
String address = aMapLocation.getAddress();
|
tv_location.setText(address);
|
searchWeather(aMapLocation.getCity());
|
} else {
|
// Toast.makeText(getActivity(), "定位失败,请检查网络", Toast.LENGTH_SHORT).show();
|
}
|
}
|
}
|
};
|
//初始化定位
|
mLocationClient = new AMapLocationClient(getActivity().getApplicationContext());
|
//设置定位回调监听
|
mLocationClient.setLocationListener(mLocationListener);
|
//声明AMapLocationClientOption对象
|
AMapLocationClientOption mLocationOption = null;
|
//初始化AMapLocationClientOption对象
|
mLocationOption = new AMapLocationClientOption();
|
//设置定位模式为AMapLocationMode.Hight_Accuracy,高精度模式。
|
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
|
//设置定位模式为AMapLocationMode.Battery_Saving,低功耗模式。
|
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
|
//设置定位间隔,单位毫秒,默认为2000ms,最低1000ms。
|
mLocationOption.setInterval(10000);
|
//设置是否返回地址信息(默认返回地址信息)
|
mLocationOption.setNeedAddress(true);
|
//设置是否强制刷新WIFI,默认为true,强制刷新。
|
mLocationOption.setWifiActiveScan(true);
|
//设置是否允许模拟位置,默认为true,允许模拟位置
|
mLocationOption.setMockEnable(true);
|
//关闭缓存机制
|
mLocationOption.setLocationCacheEnable(false);
|
//给定位客户端对象设置定位参数
|
mLocationClient.setLocationOption(mLocationOption);
|
//启动定位
|
mLocationClient.startLocation();
|
|
}
|
//根据城市搜索天气
|
private void searchWeather(String city) {
|
query = new WeatherSearchQuery(city, WeatherSearchQuery.WEATHER_TYPE_LIVE);
|
mweathersearch = new WeatherSearch(getContext());
|
mweathersearch.setOnWeatherSearchListener(this);
|
mweathersearch.setQuery(query);
|
mweathersearch.searchWeatherAsyn(); //异步搜索
|
}
|
|
@Override
|
public void onHiddenChanged(boolean hidden) {
|
super.onHiddenChanged(hidden);
|
this.hidden = hidden;
|
if (hidden) {
|
mLocationClient.stopLocation();
|
searchWeather = true;
|
} else {
|
mLocationClient.startLocation();
|
initCurrentTime();
|
// viewHolder2.clearView();
|
// refreshView();
|
}
|
}
|
|
@Override
|
public void onWeatherLiveSearched(LocalWeatherLiveResult localWeatherLiveResult, int i) {
|
if (searchWeather) {
|
if (i == 1000) {
|
if (localWeatherLiveResult != null || localWeatherLiveResult.getLiveResult() != null) {
|
LocalWeatherLive weatherlive = localWeatherLiveResult.getLiveResult();
|
temperature = weatherlive.getTemperature() + "°";
|
weather = weatherlive.getWeather().trim();
|
tv_weather.setText(weather);
|
tv_temperature.setText(temperature);
|
if (weather != null && !weather.trim().equals("")) {
|
if (weather.equals("多云")) {
|
iv_weather_icon.setBackgroundResource(R.drawable.weather_icon_1);
|
ll_weatherBG.setBackgroundResource(R.drawable.home_feeds_weather_bkg_cloudy);
|
} else if (weather.equals("晴")) {
|
iv_weather_icon.setBackgroundResource(R.drawable.weather_icon_0);
|
ll_weatherBG.setBackgroundResource(R.drawable.home_feeds_weather_bkg_sunny);
|
} else if (weather.equals("阴")) {
|
iv_weather_icon.setBackgroundResource(R.drawable.weather_icon_2);
|
ll_weatherBG.setBackgroundResource(R.drawable.home_feeds_weather_bkg_cloudy);
|
} else if (weather.equals("小雨")) {
|
iv_weather_icon.setBackgroundResource(R.drawable.weather_icon_3);
|
ll_weatherBG.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain);
|
} else if (weather.equals("中雨")) {
|
iv_weather_icon.setBackgroundResource(R.drawable.weather_icon_4);
|
ll_weatherBG.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain);
|
} else if (weather.equals("大雨")) {
|
iv_weather_icon.setBackgroundResource(R.drawable.weather_icon_5);
|
ll_weatherBG.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain);
|
} else if(weather.equals("阵雨")){
|
iv_weather_icon.setBackgroundResource(R.drawable.weather_icon_8);
|
ll_weatherBG.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain);
|
} else if (weather.equals("雨夹雪")){
|
iv_weather_icon.setBackgroundResource(R.drawable.weather_icon_15);
|
ll_weatherBG.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain);
|
}else if (weather.equals("小雪")){
|
iv_weather_icon.setBackgroundResource(R.drawable.weather_icon_9);
|
ll_weatherBG.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain);
|
}else if (weather.equals("中雪")){
|
iv_weather_icon.setBackgroundResource(R.drawable.weather_icon_10);
|
ll_weatherBG.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain);
|
}else if (weather.equals("大雪")){
|
iv_weather_icon.setBackgroundResource(R.drawable.weather_icon_11);
|
ll_weatherBG.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain);
|
}
|
}
|
searchWeather = false;
|
}
|
}
|
}
|
|
}
|
|
@Override
|
public void onWeatherForecastSearched(LocalWeatherForecastResult localWeatherForecastResult, int i) {
|
|
}
|
|
@Override
|
public void onClick(View view) {
|
switch (view.getId()){
|
case R.id.iv_weather_icon:
|
Toast.makeText(getContext(),"打开天气详情", Toast.LENGTH_SHORT).show();
|
break;
|
case R.id.btn_search:
|
refreshView();
|
break;
|
}
|
|
}
|
|
//region recyclerview的每一项item的枚举类
|
public enum ITEM_TYPE {
|
ITEM1,
|
ITEM2,
|
ITEM3,
|
ITEM4,
|
ITEM5
|
}
|
//endregion
|
|
public void refreshView(){
|
viewHolder1.refreshView();
|
viewHolder2.refreshView();
|
viewHolder3.refreshView();
|
// viewHolder4.refreshView();
|
// viewHolder5.refreshView();
|
}
|
|
/**
|
* 返回当前用户执行的子任务列表
|
* @param msubtaskList
|
* @return
|
*/
|
public ArrayList<Subtask> getmSubtaskListOfUser(List<Subtask> msubtaskList){
|
if (application.getCurrentUser().getUsertypeid() == 2) {//主管部门的任务展示按照区县划分
|
subtaskListOfUser.clear();
|
for (Subtask subtask : msubtaskList) {
|
if (subtask.getDistrictcode().equals(application.getCurrentUser().getDguid()))//区县行政编码判定,只显示对应区县的任务
|
subtaskListOfUser.add(subtask);
|
}
|
}
|
return subtaskListOfUser;
|
}
|
// private class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
// private Context context;
|
// private LayoutInflater mLayoutInflater;
|
// private Bundle savedInstanceState;
|
// private List<RecyclerView.ViewHolder> holderList = new ArrayList<>();
|
//
|
//
|
// public RecyclerViewAdapter(Context context, Bundle savedInstanceState) {
|
// this.context = context;
|
// mLayoutInflater = LayoutInflater.from(context);
|
// this.savedInstanceState = savedInstanceState;
|
// }
|
//
|
// public void addData(int position) {
|
// notifyItemInserted(position);
|
// }
|
//
|
// public void removeData(int position) {
|
// notifyItemRemoved(position);
|
// }
|
//
|
// /**
|
// * 创建 ViewHolder 对象
|
// *
|
// * @param parent
|
// * @param viewType
|
// * @return
|
// */
|
// @Override
|
// public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
// if (viewType == ITEM_TYPE.ITEM1.ordinal()) {
|
// return new ViewHolder1(mLayoutInflater.inflate(R.layout.function_card1, parent, false));
|
// } else if (viewType == ITEM_TYPE.ITEM2.ordinal()) {
|
// return new ViewHolder2(mLayoutInflater.inflate(R.layout.function_card2, parent, false));
|
// } else if (viewType == ITEM_TYPE.ITEM3.ordinal()) {
|
// return new ViewHolder3(mLayoutInflater.inflate(R.layout.function_card5, parent, false));
|
// } else if (viewType == ITEM_TYPE.ITEM4.ordinal()) {
|
// return new ViewHolder4(mLayoutInflater.inflate(R.layout.function_card3, parent, false));
|
// } else {
|
// return new ViewHolder4(mLayoutInflater.inflate(R.layout.function_card4, parent, false));
|
// }
|
//
|
// }
|
//
|
// //设置ITEM类型,可以自由发挥,这里设置item position单数显示item1 偶数显示item2
|
// @Override
|
// public int getItemViewType(int position) {
|
// if (position == 0) {
|
// return ITEM_TYPE.ITEM1.ordinal();
|
// } else if (position == 1) {
|
// return ITEM_TYPE.ITEM2.ordinal();
|
// } else if (position == 2) {
|
// return ITEM_TYPE.ITEM3.ordinal();
|
// } else if (position == 3) {
|
// return ITEM_TYPE.ITEM4.ordinal();
|
// } else if (position == 4) {
|
// return ITEM_TYPE.ITEM5.ordinal();
|
// } else {
|
// return 0;
|
// }
|
// }
|
//
|
// @Override
|
// public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
// if (holder instanceof ViewHolder1) {
|
// ((ViewHolder1) holder).initView();
|
// holderList.add(holder);
|
// } else if (holder instanceof ViewHolder2) {
|
// ((ViewHolder2) holder).initView();
|
// holderList.add(holder);
|
// } else if (holder instanceof ViewHolder3) {
|
// ((ViewHolder3) holder).initView();
|
// holderList.add(holder);
|
// } else if (holder instanceof ViewHolder4) {
|
// ((ViewHolder4) holder).initView();
|
// holderList.add(holder);
|
// } else {
|
// ((ViewHolder5) holder).initView();
|
// holderList.add(holder);
|
// }
|
//
|
// }
|
//
|
// @Override
|
// public int getItemCount() {
|
// return 5;
|
// }
|
//
|
// public RecyclerView.ViewHolder getViewHolder(String holder, int position){
|
// if (Objects.equals(holder, VIEWHOLDER1)) {
|
// ViewHolder1 tmpholder = (ViewHolder1)holderList.get(position);
|
// return tmpholder;
|
// } else if (Objects.equals(holder, VIEWHOLDER2)) {
|
// ViewHolder2 tmpholder = (ViewHolder2)holderList.get(position);
|
// return tmpholder;
|
// } else if (Objects.equals(holder, VIEWHOLDER3)) {
|
// ViewHolder3 tmpholder = (ViewHolder3)holderList.get(position);
|
// return tmpholder;
|
// } else if (Objects.equals(holder, VIEWHOLDER4)) {
|
// ViewHolder4 tmpholder = (ViewHolder4)holderList.get(position);
|
// return tmpholder;
|
// } else if (Objects.equals(holder, VIEWHOLDER5)){
|
// ViewHolder5 tmpholder = (ViewHolder5)holderList.get(position);
|
// return tmpholder;
|
// }
|
//
|
// return null;
|
// }
|
//
|
// }
|
|
public class ViewHolder1 {
|
RecyclerView rv_viewholder1;
|
TextView tv_look_more;
|
TextView tv_no_task;
|
|
// List<Subtask> subtaskListOfUser = new ArrayList<>();
|
|
ViewHolder1(Bundle savedInstanceState, View itemView) {
|
rv_viewholder1 = (RecyclerView) itemView.findViewById(R.id.rv_today_task);
|
tv_look_more = (TextView) itemView.findViewById(R.id.look_more);
|
tv_no_task = (TextView) itemView.findViewById(R.id.tv_no_task);
|
|
tv_look_more.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View view) {
|
viewHolder1Adapter.setVisiblity(!visibility);
|
visibility = !visibility;
|
if (subtaskListOfUser.size() > VISIBLENUM){
|
if (visibility) tv_look_more.setText("点击收回");
|
else tv_look_more.setText("还有" + (subtaskListOfUser.size() - VISIBLENUM) + "个任务,点击展开");
|
}
|
}
|
});
|
}
|
|
void initViewHolder1(){
|
calendarCurrent = Calendar.getInstance();
|
mCurYearMonth = DateFormatter.YearMonthFormat.format(calendarCurrent.getTime());
|
getThreeMonthTask(mCurYearMonth, Constant.TASK_GETINFOTYPE_MIDDLE);
|
// subtaskListOfUser = getmSubtaskListOfUser(mSubtaskList);
|
|
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
|
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
rv_viewholder1.setLayoutManager(linearLayoutManager);
|
viewHolder1Adapter = new ViewHolder1Adapter(getContext(),subtaskListOfUser);
|
|
if (subtaskListOfUser.isEmpty())tv_no_task.setVisibility(View.VISIBLE);
|
else tv_no_task.setVisibility(View.GONE);
|
// if (mSubtaskList.size() > VISIBLENUM) tv_look_more.setTitle("还有" + (mSubtaskList.size() - VISIBLENUM) + "个任务,点击展开");
|
|
rv_viewholder1.setAdapter(viewHolder1Adapter);
|
}
|
|
void refreshView() {
|
getThreeMonthTask(mCurYearMonth, Constant.TASK_GETINFOTYPE_MIDDLE);
|
}
|
|
/**
|
* 获取当前月及前后月的任务信息
|
*
|
* @param yearMonth 年月:例:2018-01
|
* @param type Middle、Left、Right
|
*/
|
public void getThreeMonthTask(final String yearMonth, final String type) {
|
Call<List<TaskPack>> loadThreeMonthTasks = mRetrofit.create(TaskService.class).loadThreeMonthTasks(yearMonth, "0", type);
|
loadThreeMonthTasks.enqueue(new Callback<List<TaskPack>>() {
|
@Override
|
public void onResponse(@NonNull Call<List<TaskPack>> call, @NonNull Response<List<TaskPack>> response) {
|
if (response.body() != null) {
|
requestAgain = false;
|
List<TaskPack> taskPackList = response.body();
|
if (taskPackList != null && taskPackList.size() > 0) {
|
for (TaskPack taskPack : taskPackList) {
|
taskAllMapList.put(taskPack.getDate(), taskPack.getUpperTaskList());
|
}
|
if (firstLoad) {
|
firstLoad = false;
|
// showMonthAllTask(calendarCurrent);
|
}
|
initSubtask();
|
if (mSubtaskList.size() > 0) {
|
// Toast.makeText(getContext(),"加载完成", Toast.LENGTH_SHORT).show();
|
// parentAdapter.notifyDataSetChanged();
|
subtaskListOfUser = getmSubtaskListOfUser(mSubtaskList);
|
if (!subtaskListOfUser.isEmpty()) {
|
viewHolder1Adapter.setVisiblity(visibility);
|
viewHolder1Adapter.notifyDataSetChanged();
|
if (subtaskListOfUser.size() > VISIBLENUM)
|
tv_look_more.setText("还有" + (subtaskListOfUser.size() - VISIBLENUM) + "个任务,点击展开");
|
tv_no_task.setVisibility(View.GONE);
|
}
|
}
|
}
|
} else if (response.errorBody() != null) {
|
if (!requestAgain) {
|
requestAgain = true;
|
getThreeMonthTask(yearMonth, type);
|
} else {
|
Toast.makeText(application, "获取任务信息出错", Toast.LENGTH_SHORT).show();
|
// showMonthAllTask(calendarCurrent);
|
}
|
System.out.println("ThreeMonthTask:" + response.errorBody());
|
}
|
}
|
|
@Override
|
public void onFailure(@NonNull Call<List<TaskPack>> call, @NonNull Throwable t) {
|
if (!requestAgain) {
|
requestAgain = true;
|
getThreeMonthTask(yearMonth, type);
|
} else {
|
Toast.makeText(application, "网络链接失败", Toast.LENGTH_SHORT).show();
|
// showMonthAllTask(calendarCurrent);
|
}
|
System.out.println("ThreeMonthTask:" + t.toString());
|
}
|
});
|
}
|
|
private void initSubtask(){
|
mDayTaskList.clear();
|
mSubtaskList.clear();
|
// int daytaskTotalNumThisWeek = 0;
|
// int daytaskFinishedNumThisWeek = 0;
|
// int daytaskTotalNumThisMonth = 0;
|
// int daytaskFinishedNumThisMonth = 0;
|
// int subtaskTotalNumToday = 0;
|
// int subtaskFinishedNumToday = 0;
|
for (TaskVo taskVo : taskAllMapList.get(mCurYearMonth)) {
|
for (TaskVo dayTaskVo : taskVo.getDaytaskList()) {
|
// daytaskTotalNumThisMonth++;
|
mDayTaskList.add(dayTaskVo);
|
// long taskTime = dayTaskVo.getStarttime().getTime();
|
// long monday = CommonUtils.getTimesWeekmorning().getTime();
|
// long sunday = CommonUtils.getTimesWeeknight().getTime();
|
// if (taskTime >= monday && taskTime < sunday) {
|
// daytaskTotalNumThisWeek++;
|
// if (dayTaskVo.getRuningstatus().equals(Domain.TASK_STATUS_FINISHED)) {
|
// daytaskFinishedNumThisWeek++;
|
// }
|
// }
|
// if (dayTaskVo.getRuningstatus().equals(Domain.TASK_STATUS_FINISHED)) {
|
// daytaskFinishedNumThisMonth++;
|
// }
|
List<Subtask> subTaskList = dayTaskVo.getSubtaskList();
|
for (Subtask subtask : subTaskList) {
|
String subtaskStartTime = DateFormatter.dateFormat2.format(subtask.getPlanstarttime());
|
if (subtaskStartTime.equals(mToday)) {
|
// subtaskTotalNumToday++;
|
// if (subtask.getStatus().equals(Domain.TASK_STATUS_FINISHED)) {
|
// subtaskFinishedNumToday++;
|
// }
|
mSubtaskList.add(subtask);
|
}
|
}
|
}
|
}
|
}
|
}
|
|
private List<ChartGenerator.CommonData> commonData1;//问题统计图的数据集
|
private List<ChartGenerator.CommonData> commonData2;//整改统计图的数据集
|
private HorizontalBarChart bar_problem_1;//水平直方图1
|
private HorizontalBarChart bar_problem_2;//水平直方图2
|
private List<StatisticsVo> statisticsVos1;//上月的原始数据
|
private List<StatisticsVo> statisticsVos2;//本月的原始数据
|
|
public class ViewHolder2 {
|
|
private TextView text_problem_time_1;
|
private TextView text_problem_time_2;
|
private TextView text_problem_count_1;
|
private TextView text_problem_count_2;
|
private ImageView image_problem_rank;
|
|
ViewHolder2(Bundle savedInstanceState, View itemView) {
|
bar_problem_1 = itemView.findViewById(R.id.bar_problem_1);
|
text_problem_time_1 = itemView.findViewById(R.id.text_problem_time_1);
|
text_problem_time_2 = itemView.findViewById(R.id.text_problem_time_2);
|
text_problem_count_1 = itemView.findViewById(R.id.text_problem_count_1);
|
text_problem_count_2 = itemView.findViewById(R.id.text_problem_count_2);
|
image_problem_rank = itemView.findViewById(R.id.image_problem_rank);
|
commonData1 = new ArrayList<>();
|
commonData2 = new ArrayList<>();
|
statisticsVos1 = new ArrayList<>();
|
statisticsVos2 = new ArrayList<>();
|
|
ChartGenerator.quickSetupChart(bar_problem_1, 'a');
|
}
|
|
void refreshView(){
|
initViewholder2();
|
}
|
|
void initView() {
|
try {
|
text_problem_time_1.setText(DateFormatter.YearMonthFormat.format(CommonUtils.getTimesLastMonthmorning()));
|
text_problem_time_2.setText(DateFormatter.YearMonthFormat.format(CommonUtils.getTimesMonthmorning()));
|
int c1 = (int) commonData1.get(0).getTotalYValueCount();
|
int c2 = (int) commonData1.get(1).getTotalYValueCount();
|
String t1 = String.valueOf(c1) + "个";
|
String t2 = String.valueOf(c2) + "个";
|
text_problem_count_1.setText(t1);
|
text_problem_count_2.setText(t2);
|
if (c1 > c2) {
|
image_problem_rank.setImageResource(R.drawable.icon_rank_down);
|
} else if (c1 == c2) {
|
image_problem_rank.setImageResource(R.drawable.icon_rank_no_change);
|
} else {
|
image_problem_rank.setImageResource(R.drawable.icon_rank_up);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
void initChart() {
|
ChartGenerator.quickSetData(bar_problem_1, commonData1, 'a');
|
}
|
|
void clearView(){
|
|
}
|
|
//获取查询条件
|
AreaVo getArea() {
|
AreaVo areaVo = new AreaVo();
|
// areaVo.setProvincecode();
|
// areaVo.setProvincename();
|
// areaVo.setCitycode();
|
// areaVo.setCityname();
|
String districtcode = application.getCurrentUser().getDguid();//主管部门的部门id就是区县id
|
String districtname = application.getCurrentUser().getDepartmentname();//主管部门的部门名称就是区县名称
|
areaVo.setDistrictcode(districtcode);
|
areaVo.setDistrictname(districtname);
|
areaVo.setScensetypeid(curSceneType);//场景类型
|
// areaVo.setTowncode();
|
// areaVo.setTownname();
|
Date date1 = new Date();
|
Date date2 = new Date();
|
//上月
|
date1 = CommonUtils.getTimesLastMonthmorning();
|
date2 = CommonUtils.getTimesLastMonthnight();
|
areaVo.setStarttime(DateFormatter.dateTimeFormat2.format(date1));
|
areaVo.setEndtime(DateFormatter.dateTimeFormat2.format(date2));
|
|
return areaVo;
|
}
|
|
/**
|
* 获取上月与本月的
|
* 此处的数据vo类StatisticsVo定义:
|
* name: 代表 表sm_t_problemtype中的问题类型PT_TypeName
|
* startTime-endTime:此处为固定的本月或上月
|
* count:对应时间段的问题数量
|
*/
|
private void initViewholder2(){
|
// 上月、本月问题统计
|
AreaVo areaVo = getArea();
|
getLastMonResult(areaVo);
|
}
|
|
//获取上月的问题及整改统计
|
private void getLastMonResult(final AreaVo areaVo) {
|
Call<List<StatisticsVo>> getStatisticalResult = mRetrofit.create(ProblemListService.class).getStatisticalResult(areaVo);
|
getStatisticalResult.enqueue(new Callback<List<StatisticsVo>>() {
|
@Override
|
public void onResponse(Call<List<StatisticsVo>> call, Response<List<StatisticsVo>> response) {
|
if (response.body() != null) {
|
statisticsVos1 = response.body();
|
// 获取上月统计结果成功后,再获取本月的统计结果
|
Date date1 = CommonUtils.getTimesMonthmorning();
|
Date date2 = CommonUtils.getTimesMonthnight();
|
areaVo.setStarttime(DateFormatter.dateTimeFormat2.format(date1));
|
areaVo.setEndtime(DateFormatter.dateTimeFormat2.format(date2));
|
getCurMonResult(areaVo);
|
|
//刷新文本描述
|
}
|
}
|
|
@Override
|
public void onFailure(Call<List<StatisticsVo>> call, Throwable t) {
|
clearView();
|
}
|
});
|
|
|
}
|
|
//获取当前月的问题及整改统计
|
private void getCurMonResult(AreaVo areaVo) {
|
Call<List<StatisticsVo>> getStatisticalResult = mRetrofit.create(ProblemListService.class).getStatisticalResult(areaVo);
|
getStatisticalResult.enqueue(new Callback<List<StatisticsVo>>() {
|
@Override
|
public void onResponse(Call<List<StatisticsVo>> call, Response<List<StatisticsVo>> response) {
|
if (response.body() != null) {
|
statisticsVos2 = response.body();
|
combineData();
|
initChart();
|
initView();
|
viewHolder3.initChart();
|
viewHolder3.initView();
|
}
|
}
|
|
@Override
|
public void onFailure(Call<List<StatisticsVo>> call, Throwable t) {
|
clearView();
|
}
|
});
|
}
|
|
//合并上月与本月数据
|
private void combineData() {
|
ChartGenerator.CommonData data1_1 = new ChartGenerator.CommonData("上月问题数量");
|
ChartGenerator.CommonData data1_2 = new ChartGenerator.CommonData("本月问题数量");
|
ChartGenerator.CommonData data2_1 = new ChartGenerator.CommonData("上月整改数量");
|
ChartGenerator.CommonData data2_2 = new ChartGenerator.CommonData("本月整改数量");
|
|
List<StatisticsVo> tmpSvo1 = new ArrayList<>(statisticsVos1);
|
List<StatisticsVo> tmpSvo2 = new ArrayList<>(statisticsVos2);
|
|
//以上月数据statisticsVos为基础进行遍历,逐个和本月问题进行比较,有相同问题的同时创建各自的问题及整改数据;
|
// 只有其中一个月有此种问题的,则另一个月的数据集中也需要创建一个对应的0值
|
for (int i = 0; i < tmpSvo1.size(); i++) {
|
boolean isExist = false;
|
StatisticsVo s1 = tmpSvo1.get(i);
|
|
for (int y = 0; y < tmpSvo2.size(); y++) {
|
StatisticsVo s2 = tmpSvo2.get(y);
|
if (s1.getName().equals(s2.getName())) {
|
data1_1.add(s1.getName(), i, "个数", (float) s1.getCount());
|
data1_2.add(s2.getName(), i, "个数", (float) s2.getCount());
|
|
data2_1.add(s1.getName(), i, "个数", (float) s1.getChangeCount());
|
data2_2.add(s2.getName(), i, "个数", (float) s2.getChangeCount());
|
tmpSvo2.remove(y);
|
isExist = true;
|
break;
|
}
|
}
|
if (!isExist) {
|
data1_1.add(s1.getName(), i, "个数", (float) s1.getCount());
|
data1_2.add(s1.getName(), i, "个数", 0);
|
|
data2_1.add(s1.getName(), i, "个数", (float) s1.getChangeCount());
|
data2_2.add(s1.getName(), i, "个数", 0);
|
}
|
}
|
|
//本月问题数据中剩下的问题则是上月没有的,直接创建对应数据集
|
for (int i = 0; i < tmpSvo2.size(); i++) {
|
StatisticsVo s2 = tmpSvo2.get(i);
|
data1_1.add(s2.getName(), tmpSvo1.size() + i, "个数", 0);
|
data1_2.add(s2.getName(), tmpSvo1.size() +i, "个数", (float) s2.getCount());
|
|
data2_1.add(s2.getName(), tmpSvo1.size() + i, "个数", 0);
|
data2_2.add(s2.getName(), tmpSvo1.size() +i, "个数", (float) s2.getChangeCount());
|
}
|
|
commonData1.add(data1_1);
|
commonData1.add(data1_2);
|
commonData2.add(data2_1);
|
commonData2.add(data2_2);
|
}
|
|
}
|
|
public class ViewHolder3 {
|
private TextView text_change_time_1;
|
private TextView text_change_time_2;
|
private TextView text_change_count_1;
|
private TextView text_change_count_2;
|
private ImageView image_change_rank;
|
List<ChargeInfoVo.SceneInfo> sceneInfos = new ArrayList<>();
|
|
ViewHolder3(Bundle savedInstanceState, View itemView) {
|
bar_problem_2 = itemView.findViewById(R.id.bar_change_2);
|
text_change_time_1 = itemView.findViewById(R.id.text_change_time_1);
|
text_change_time_2 = itemView.findViewById(R.id.text_change_time_2);
|
text_change_count_1 = itemView.findViewById(R.id.text_change_count_1);
|
text_change_count_2 = itemView.findViewById(R.id.text_change_count_2);
|
image_change_rank = itemView.findViewById(R.id.image_change_rank);
|
|
ChartGenerator.quickSetupChart(bar_problem_2, 'a');
|
}
|
|
void refreshView() {
|
initViewHolder3();
|
}
|
|
void initChart() {
|
ChartGenerator.quickSetData(bar_problem_2, commonData2, 'a');
|
}
|
|
void initView(){
|
try {
|
text_change_time_1.setText(DateFormatter.YearMonthFormat.format(CommonUtils.getTimesLastMonthmorning()));
|
text_change_time_2.setText(DateFormatter.YearMonthFormat.format(CommonUtils.getTimesMonthmorning()));
|
int c1 = (int) commonData2.get(0).getTotalYValueCount();
|
int c1_2 = (int) commonData1.get(0).getTotalYValueCount();
|
int c2 = (int) commonData2.get(1).getTotalYValueCount();
|
int c2_2 = (int) commonData1.get(1).getTotalYValueCount();
|
String t1 = String.valueOf(c1) + "个 /" + (c1 * 100 / c1_2) + "%";
|
String t2 = String.valueOf(c2) + " 个 /" + (c2 * 100 / c2_2) + "%";
|
text_change_count_1.setText(t1);
|
text_change_count_2.setText(t2);
|
if (c1 > c2) {
|
image_change_rank.setImageResource(R.drawable.icon_rank_down);
|
} else if (c1 == c2) {
|
image_change_rank.setImageResource(R.drawable.icon_rank_no_change);
|
} else {
|
image_change_rank.setImageResource(R.drawable.icon_rank_up);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
void clearView() {
|
|
}
|
|
AreaVo getArea() {
|
AreaVo areaVo = new AreaVo();
|
// areaVo.setProvincecode();
|
// areaVo.setProvincename();
|
// areaVo.setCitycode();
|
// areaVo.setCityname();
|
String districtcode = application.getCurrentUser().getDguid();//主管部门的部门id就是区县id
|
String districtname = application.getCurrentUser().getDepartmentname();//主管部门的部门名称就是区县名称
|
areaVo.setDistrictcode(districtcode);
|
areaVo.setDistrictname(districtname);
|
areaVo.setScensetypeid(curSceneType);//场景类型
|
// areaVo.setTowncode();
|
// areaVo.setTownname();
|
//上月
|
Date date1 = CommonUtils.getTimesLastMonthmorning();
|
Date date2 = CommonUtils.getTimesLastMonthnight();
|
areaVo.setStarttime(DateFormatter.dateTimeFormat2.format(date1));
|
areaVo.setEndtime(DateFormatter.dateTimeFormat2.format(date2));
|
|
return areaVo;
|
}
|
|
private void initViewHolder3(){
|
//region 上月规范情况
|
AreaVo areaVo_lastMonth = getArea();
|
Call<ChargeInfoVo> getChargeResult = mRetrofit.create(ProblemListService.class).getChargeResult(areaVo_lastMonth);
|
getChargeResult.enqueue(new Callback<ChargeInfoVo>() {
|
@Override
|
public void onResponse(Call<ChargeInfoVo> call, Response<ChargeInfoVo> response) {
|
if (response.body() != null) {
|
ChargeInfoVo chargeInfoVo = response.body();
|
sceneInfos.clear();
|
sceneInfos.addAll(chargeInfoVo.getSceneInfos());
|
viewHolder4.refreshView(chargeInfoVo, 'L');
|
}
|
}
|
|
@Override
|
public void onFailure(Call<ChargeInfoVo> call, Throwable t) {
|
clearView();
|
}
|
});
|
//endregion
|
|
//region 本月规范情况
|
AreaVo areaVo_thisMonth = getArea();
|
Date date1 = CommonUtils.getTimesMonthmorning();
|
Date date2 = CommonUtils.getTimesMonthnight();
|
areaVo_thisMonth.setStarttime(DateFormatter.dateTimeFormat2.format(date1));
|
areaVo_thisMonth.setEndtime(DateFormatter.dateTimeFormat2.format(date2));
|
Call<ChargeInfoVo> getChargeResult_2 = mRetrofit.create(ProblemListService.class).getChargeResult(areaVo_thisMonth);
|
getChargeResult_2.enqueue(new Callback<ChargeInfoVo>() {
|
@Override
|
public void onResponse(Call<ChargeInfoVo> call, Response<ChargeInfoVo> response) {
|
if (response.body() != null) {
|
ChargeInfoVo chargeInfoVo = response.body();
|
viewHolder4.refreshView(chargeInfoVo, 'T');
|
}
|
}
|
|
@Override
|
public void onFailure(Call<ChargeInfoVo> call, Throwable t) {
|
clearView();
|
}
|
});
|
//endregion
|
}
|
|
|
}
|
|
public class ViewHolder4 {
|
//上月数据
|
TextView text_standard_1;
|
TextView text_standard_2;
|
TextView text_standard_3;
|
TextView text_standard_4;
|
List<TextView> textViews = new ArrayList<>();
|
|
//本月数据
|
TextView text_standard_1_2;
|
TextView text_standard_2_2;
|
TextView text_standard_3_2;
|
TextView text_standard_4_2;
|
List<TextView> textViews_2 = new ArrayList<>();
|
|
//日期时间
|
TextView text_last_month;
|
TextView text_this_month;
|
|
//规范率
|
TextView text_standard_per_1;//上月规范率
|
TextView text_standard_per_2;//本月规范率
|
|
ViewHolder4(Bundle savedInstanceState, View itemView) {
|
text_standard_1 = itemView.findViewById(R.id.text_standard_1);
|
text_standard_2 = itemView.findViewById(R.id.text_standard_2);
|
text_standard_3 = itemView.findViewById(R.id.text_standard_3);
|
text_standard_4 = itemView.findViewById(R.id.text_standard_4);
|
textViews.add(text_standard_1);
|
textViews.add(text_standard_2);
|
textViews.add(text_standard_3);
|
textViews.add(text_standard_4);
|
|
text_standard_1_2 = itemView.findViewById(R.id.text_standard_1_2);
|
text_standard_2_2 = itemView.findViewById(R.id.text_standard_2_2);
|
text_standard_3_2 = itemView.findViewById(R.id.text_standard_3_2);
|
text_standard_4_2 = itemView.findViewById(R.id.text_standard_4_2);
|
textViews_2.add(text_standard_1_2);
|
textViews_2.add(text_standard_2_2);
|
textViews_2.add(text_standard_3_2);
|
textViews_2.add(text_standard_4_2);
|
|
text_last_month = itemView.findViewById(R.id.text_last_month);
|
text_this_month = itemView.findViewById(R.id.text_this_month);
|
|
text_standard_per_1 = itemView.findViewById(R.id.text_standard_per_1);
|
text_standard_per_2 = itemView.findViewById(R.id.text_standard_per_2);
|
}
|
|
void refreshView(ChargeInfoVo chargeInfoVo, char c) {
|
initViewHolder4(chargeInfoVo, c);
|
}
|
|
public void initViewHolder4(ChargeInfoVo chargeInfoVo, char c) {
|
Date date = CommonUtils.getTimesLastMonthmorning();
|
text_last_month.setText(DateFormatter.YearMonthFormat.format(date));
|
date = CommonUtils.getTimesMonthmorning();
|
text_this_month.setText(DateFormatter.YearMonthFormat.format(date));
|
|
List<ChargeInfoVo.ScoreInfo> scoreInfos = chargeInfoVo.getScoreInfos();
|
if (c == 'L') {//上月数据
|
int standardCount = 0;
|
int totalCount = 0;
|
for (int i = 0; i < scoreInfos.size(); i++) {
|
ChargeInfoVo.ScoreInfo s = scoreInfos.get(i);
|
textViews.get(i).setText(String.valueOf(s.getCount()));
|
if (i < 2) {
|
standardCount = standardCount + s.getCount();
|
}
|
totalCount = totalCount + s.getCount();
|
}
|
text_standard_per_1.setText(totalCount == 0 ? 0 + "%" : standardCount * 100/ totalCount + "%");
|
} else {//本月数据
|
int standardCount = 0;
|
int totalCount = 0;
|
for (int i = 0; i < scoreInfos.size(); i++) {
|
ChargeInfoVo.ScoreInfo s = scoreInfos.get(i);
|
textViews_2.get(i).setText(String.valueOf(s.getCount()));
|
if (i < 2) {
|
standardCount = standardCount + s.getCount();
|
}
|
totalCount = totalCount + s.getCount();
|
}
|
text_standard_per_2.setText(totalCount == 0 ? 0 + "%" : standardCount * 100/ totalCount + "%");
|
}
|
}
|
}
|
|
@BindView(R.id.cl_night_work)
|
ConstraintLayout cl_night_work;
|
|
public class ViewHolder5 {
|
|
ViewHolder5(Bundle savedInstanceState, View itemView) {
|
|
}
|
|
void refreshView() {
|
initViewHolder5();
|
}
|
|
private void initViewHolder5() {
|
cl_night_work.setOnClickListener(v -> startActivity(new Intent(getContext(), NightWorkManageActivity.class)));
|
}
|
}
|
|
private class ViewHolder1Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
|
|
private Context context;
|
private LayoutInflater mLayoutInflater;
|
private Bundle savedInstanceState;
|
private List<Subtask> mData;
|
private Boolean visibility = false;
|
|
public ViewHolder1Adapter(Context context, List<Subtask> mData) {
|
this.context = context;
|
mLayoutInflater = LayoutInflater.from(context);
|
this.savedInstanceState = savedInstanceState;
|
this.mData = mData;
|
}
|
|
@Override
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
View itemview = mLayoutInflater.inflate(R.layout.item_today_task,parent,false);
|
// DisplayMetrics dm = new DisplayMetrics();
|
// RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((dm.widthPixels - GradeActivity.dip2px(getContext(), 20)) / 3, (dm.widthPixels - GradeActivity.dip2px(getContext(), 20)) / 3);
|
// itemview.setLayoutParams(lp);
|
return new TaskViewHolder(itemview);
|
}
|
|
@Override
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
if (holder instanceof TaskViewHolder) {
|
((TaskViewHolder) holder).task.setText(String.valueOf(position + 1));
|
((TaskViewHolder) holder).taskname.setText(mData.get(position).getName());
|
String date = DateFormatter.dateFormat.format(mData.get(position).getPlanstarttime());
|
((TaskViewHolder) holder).taskdate.setText(date);
|
((TaskViewHolder) holder).district.setText(mData.get(position).getDistrictname());
|
if (position + 1 > VISIBLENUM)
|
((TaskViewHolder) holder).setVisibility(visibility);
|
else
|
((TaskViewHolder)holder).setVisibility(true);
|
}
|
|
}
|
|
@Override
|
public int getItemCount() {
|
return mData.size();
|
}
|
|
//设置itemView隐藏
|
public void setVisiblity(Boolean visiblity){
|
this.visibility = visiblity;
|
notifyDataSetChanged();
|
}
|
|
class TaskViewHolder extends RecyclerView.ViewHolder{
|
TextView task, taskdate, taskname, district;
|
|
public TaskViewHolder(View itemView) {
|
super(itemView);
|
|
task = (TextView) itemView.findViewById(R.id.tv_tody_task);
|
taskdate = (TextView) itemView.findViewById(R.id.tv_tody_task_date);
|
taskname = (TextView) itemView.findViewById(R.id.tv_tody_task_name);
|
district = (TextView) itemView.findViewById(R.id.tv_district);
|
}
|
|
public void setVisibility(boolean isVisible){
|
RecyclerView.LayoutParams param = (RecyclerView.LayoutParams)itemView.getLayoutParams();
|
if (isVisible){
|
param.height = LinearLayout.LayoutParams.WRAP_CONTENT;
|
param.width = LinearLayout.LayoutParams.MATCH_PARENT;
|
itemView.setVisibility(View.VISIBLE);
|
}else{
|
itemView.setVisibility(View.GONE);
|
param.height = 0;
|
param.width = 0;
|
}
|
itemView.setLayoutParams(param);
|
}
|
}
|
}
|
|
|
}
|