package cn.flightfeather.thirdappmodule.dataanalysis
|
|
import android.app.DatePickerDialog
|
import android.app.Dialog
|
import android.graphics.Color
|
import android.icu.text.DecimalFormat
|
import android.icu.util.Calendar
|
import android.os.Build
|
import android.os.Bundle
|
import android.support.annotation.RequiresApi
|
import android.support.design.widget.FloatingActionButton
|
import android.support.v4.app.Fragment
|
import android.support.v7.widget.DividerItemDecoration
|
import android.support.v7.widget.GridLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.RecyclerView
|
import android.util.Log
|
import android.view.LayoutInflater
|
import android.view.View
|
import android.view.ViewGroup
|
import android.widget.*
|
import cn.flightfeather.thirdappmodule.CommonApplication
|
import cn.flightfeather.thirdappmodule.R
|
import cn.flightfeather.thirdappmodule.adapter.AllListViewAdapter
|
import cn.flightfeather.thirdappmodule.adapter.AllRecyclerViewAdapter
|
import cn.flightfeather.thirdappmodule.bean.entity.*
|
import cn.flightfeather.thirdappmodule.bean.vo.AreaVo
|
import cn.flightfeather.thirdappmodule.bean.vo.ProblemlistVo
|
import cn.flightfeather.thirdappmodule.httpservice.ProblemListService
|
import cn.flightfeather.thirdappmodule.util.*
|
import cn.flightfeather.thirdappmodule.view.ScrollTextView
|
import com.github.mikephil.charting.animation.Easing
|
import com.github.mikephil.charting.charts.PieChart
|
import com.github.mikephil.charting.components.Legend
|
import com.github.mikephil.charting.data.PieData
|
import com.github.mikephil.charting.data.PieDataSet
|
import com.github.mikephil.charting.data.PieEntry
|
import com.github.mikephil.charting.formatter.PercentFormatter
|
import com.github.mikephil.charting.utils.ColorTemplate
|
import com.ping.greendao.gen.DomainitemDao
|
import retrofit2.Call
|
import retrofit2.Callback
|
import retrofit2.Response
|
import java.util.*
|
|
/**
|
* A simple [Fragment] subclass.
|
*/
|
class AnalysisProblemFragment : Fragment(), View.OnClickListener, AdapterView.OnItemSelectedListener {
|
private var application: CommonApplication? = null
|
private var problemListService: ProblemListService? = null
|
private var TIME_TYPE = 0//0:快速选择/1:任意时段
|
private var BRIEF_TIME = "本月" //初始默认选择本月
|
private var problemlists = mutableListOf<ProblemlistVo>()
|
private var mChart: PieChart? = null
|
private val entries = ArrayList<PieEntry>() //饼图数据
|
|
//下拉框数据
|
private var allProvinceData: List<Province>? = null //所有省份
|
private var provinceData: List<Province> = ArrayList() //省份
|
private var allCityData: List<City> = ArrayList() //所有城市
|
private var cityData: MutableList<City> = ArrayList() //城市
|
private var allDistrictData: List<District> = ArrayList() //所有区县
|
private val districtData: MutableList<District> = ArrayList() //区县
|
private var allTownData: List<Town> = ArrayList() //所有街镇
|
private val townData: MutableList<Town> = ArrayList() //街镇
|
private val scenseTypeData: MutableList<Domainitem> = ArrayList() //场景类型
|
private val dateData: MutableList<String> = ArrayList() //时间
|
|
//下拉框数据适配器
|
private var provinceAdapter: AllListViewAdapter<Province>? = null
|
private var cityAdapter: AllListViewAdapter<City>? = null
|
private var districtAdapter: AllListViewAdapter<District>? = null
|
private var townAdapter: AllListViewAdapter<Town>? = null
|
private var scenseAdapter: AllListViewAdapter<Domainitem>? = null
|
|
// private AllListViewAdapter<String> dateAdapter= null;
|
//RecyclerView时间快速选择列表
|
private var dateAdapter: AllRecyclerViewAdapter<String>? = null
|
private var entryAdapter: AllRecyclerViewAdapter<PieEntry>? = null
|
|
//
|
private var RV_quick_choose: RecyclerView? = null//时间快速选择
|
private var rv_problem_type: RecyclerView? = null//问题类型统计
|
|
//
|
private var LL_any_time: LinearLayout? = null
|
|
//
|
private val IV_problem: ImageView? = null
|
private var IV_scene_type: ImageView? = null
|
|
//
|
private val TV_problem: TextView? = null
|
private var TV_area: TextView? = null
|
private var tv_Cancel: TextView? = null
|
private var tv_Ok: TextView? = null
|
private var TV_quick_choose: TextView? = null
|
private var TV_any_time: TextView? = null
|
private var TV_start_time: TextView? = null
|
private var TV_end_time: TextView? = null
|
private val TV_date_display1: TextView? = null
|
private var stv_date_display2: ScrollTextView? = null
|
|
//
|
private val PC_problem: PieChart? = null
|
|
//
|
private var SP_scense_type: Spinner? = null
|
|
// private Spinner SP_date;
|
private var SP_province: Spinner? = null
|
private var SP_city: Spinner? = null
|
private var SP_district: Spinner? = null
|
private var SP_town: Spinner? = null
|
|
//
|
private var FAB_menu: FloatingActionButton? = null
|
|
//
|
private var dialog: Dialog? = null
|
override fun onCreateView(
|
inflater: LayoutInflater, container: ViewGroup?,
|
savedInstanceState: Bundle?
|
): View? {
|
return inflater.inflate(R.layout.fragment_anysis_problem, container, false)
|
}
|
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
super.onViewCreated(view, savedInstanceState)
|
application = activity!!.application as CommonApplication
|
problemListService = application!!.retrofit.create(ProblemListService::class.java)
|
initUI(view)
|
initDialog()
|
initPieChart(view)
|
initSpinnerData()
|
initSpinner(view)
|
initRecyclerView(view)
|
}
|
|
override fun onHiddenChanged(hidden: Boolean) {
|
super.onHiddenChanged(hidden)
|
}
|
|
override fun onDestroy() {
|
super.onDestroy()
|
dialog!!.dismiss()
|
}
|
|
private fun initUI(view: View) {
|
IV_scene_type = view.findViewById<View>(R.id.IV_scense_type) as ImageView
|
FAB_menu = view.findViewById<View>(R.id.FAB_menu) as FloatingActionButton
|
TV_area = view.findViewById<View>(R.id.TV_area) as TextView
|
stv_date_display2 = view.findViewById<View>(R.id.stv_date_display2) as ScrollTextView
|
FAB_menu!!.setOnClickListener(this)
|
}
|
|
/**
|
* 初始化下拉框数据(包括popupWindow)
|
*/
|
private fun initSpinnerData() {
|
val provinceDao = application!!.daoSession.provinceDao
|
val cityDao = application!!.daoSession.cityDao
|
val districtDao = application!!.daoSession.districtDao
|
val townDao = application!!.daoSession.townDao
|
val domainitemDao = application!!.daoSession.domainitemDao
|
allProvinceData = provinceDao.loadAll()
|
provinceData = provinceDao.loadAll()
|
allCityData = cityDao.loadAll()
|
cityData = cityDao.loadAll()
|
allDistrictData = districtDao.loadAll()
|
val emptydistrict = District()
|
emptydistrict.districtname = ALLDISTRICT
|
districtData.add(emptydistrict)
|
allTownData = townDao.loadAll()
|
val emptytown = Town()
|
emptytown.townname = ALLTOWN
|
townData.add(emptytown)
|
|
//场景类型
|
val queryBuilder = domainitemDao.queryBuilder()
|
.where(DomainitemDao.Properties.Dcguid.eq(Domain.DOMAINGUID_SCENSETYPE))
|
.orderAsc(DomainitemDao.Properties.Value)
|
scenseTypeData.addAll(queryBuilder.list())
|
dateData.add(Constant.THIS_WEEK)
|
dateData.add(Constant.LAST_WEEK)
|
dateData.add(Constant.THIS_MONTH)
|
dateData.add(Constant.LAST_MONTH)
|
dateData.add(Constant.THIS_SEASON)
|
dateData.add(Constant.LAST_SEASON)
|
dateData.add(Constant.THIS_YEAR)
|
dateData.add(Constant.LAST_YEAR)
|
}
|
|
private fun initSpinner(view: View) {
|
SP_scense_type = view.findViewById<View>(R.id.SP_scense_type) as Spinner
|
SP_scense_type!!.onItemSelectedListener = this
|
// SP_date.setOnItemSelectedListener(this);
|
initAdapter()
|
|
// dialog.dismiss();
|
SP_province!!.setSelection(0)
|
SP_city!!.setSelection(0)
|
SP_district!!.setSelection(0)
|
SP_town!!.setSelection(0)
|
SP_scense_type!!.setSelection(0) //会同时通过onClick时间触发setChartTitle(),所以放在最后
|
}
|
|
/**
|
* 问题类型分布的列表
|
* @param view 问题类型分布fragment
|
*/
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
private fun initRecyclerView(view: View) {
|
val decimalFormat = DecimalFormat("#0.00")
|
rv_problem_type = view.findViewById<View>(R.id.rv_problem_type) as RecyclerView
|
entryAdapter = object : AllRecyclerViewAdapter<PieEntry>(entries, R.layout.item_day_task_progress, context) {
|
override fun bindView(holder: MyViewHolder, obj: PieEntry, bool: Boolean, position: Int) {
|
var total = 0f
|
for (entry in entries) {
|
total += entry.value
|
}
|
holder.setText(R.id.tv_item1, entries[position].label)
|
.setText(R.id.tv_item2, entries[position].value.toString() + "")
|
.setText(R.id.tv_item3, decimalFormat.format((entries[position].value / total * 100).toDouble()) + "%")
|
}
|
}
|
val layoutManager = LinearLayoutManager(context)
|
layoutManager.orientation = LinearLayoutManager.VERTICAL
|
rv_problem_type!!.layoutManager = layoutManager
|
rv_problem_type!!.addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL))
|
rv_problem_type!!.adapter = entryAdapter
|
}
|
|
private fun initPieChart(view: View) {
|
|
//饼图样式设置***************************************************************************************************
|
mChart = view.findViewById<View>(R.id.PC_problem) as PieChart
|
mChart!!.setUsePercentValues(true)
|
mChart!!.description.isEnabled = false
|
mChart!!.setExtraOffsets(5f, 10f, 5f, 5f)
|
// mChart.setExtraOffsets(20.f, 0.f, 20.f, 0.f);
|
mChart!!.dragDecelerationFrictionCoef = 0.95f
|
|
// mChart.setCenterTextTypeface(mTfLight);
|
// mChart.setCenterText(generateCenterSpannableText());
|
mChart!!.isDrawHoleEnabled = true
|
mChart!!.setHoleColor(Color.WHITE)
|
mChart!!.setTransparentCircleColor(Color.WHITE)
|
mChart!!.setTransparentCircleAlpha(110)
|
mChart!!.holeRadius = 39f
|
mChart!!.transparentCircleRadius = 41f
|
mChart!!.setDrawCenterText(true)
|
mChart!!.rotationAngle = 0f
|
// enable rotation of the chart by touch
|
mChart!!.isRotationEnabled = true
|
mChart!!.isHighlightPerTapEnabled = true
|
val l = mChart!!.legend
|
l.verticalAlignment = Legend.LegendVerticalAlignment.TOP
|
l.horizontalAlignment = Legend.LegendHorizontalAlignment.LEFT
|
l.orientation = Legend.LegendOrientation.VERTICAL
|
l.setDrawInside(false)
|
l.xEntrySpace = 7f
|
l.yEntrySpace = 0f
|
l.yOffset = 0f
|
|
// entry label styling
|
mChart!!.setEntryLabelColor(Color.WHITE)
|
// mChart.setEntryLabelTypeface(mTfRegular);
|
mChart!!.setEntryLabelTextSize(12f)
|
mChart!!.setDrawEntryLabels(false)
|
|
//test
|
// setData(new ArrayList<ProblemlistVo>());
|
//
|
}
|
|
private fun setData(problemlists: MutableList<ProblemlistVo>) {
|
//数据初始化***************************************************************************************************
|
entries.clear()
|
val dataSet = PieDataSet(entries, "问题类型")
|
|
//test*****
|
// int count = 5;
|
// int mult = 100;
|
// String[] mParties = {"路面积尘", "地面局部未硬化", "站厂出入口无外围护", "无喷淋装置", REMAIN_PROBLEM};
|
// for (int i = 0; i < count; i++) {
|
// entries.add(new PieEntry((int) (Math.random() * mult) + mult / 5, mParties[i]));
|
// }
|
//*********
|
|
//初始化数据
|
val problemTypeMap = HashMap<String, Int>()
|
while (problemlists.isNotEmpty()) {
|
val problemType = problemlists[0].typename
|
if (problemType == null) {
|
problemlists.removeAt(0)
|
continue
|
}
|
var problemCount = 0
|
var i = 0
|
while (i < problemlists.size) {
|
if (problemType == problemlists[i].typename) {
|
problemCount++
|
problemlists.removeAt(i)
|
i--
|
}
|
i++
|
}
|
problemTypeMap[problemType] = problemCount
|
}
|
//按HashMap的value降序排序
|
val list: List<Map.Entry<String, Int>> = ArrayList<Map.Entry<String, Int>>(problemTypeMap.entries)
|
Collections.sort(list) { o1, o2 -> o2.value.compareTo(o1.value) }
|
// problemTypeMap.clear();
|
// problemTypeMap.entrySet().addAll(list);
|
//初始化Entry,限定最多显示5个扇区,超出的合并为第5个扇区
|
var remainProblemType = ""
|
var remainProblemCount = 0
|
var chartcount = 0
|
for ((key, value) in list) {
|
if (chartcount < MAX_CHART_COUNT - 1) {
|
entries.add(PieEntry(value.toFloat(), key))
|
} else {
|
remainProblemCount += value
|
remainProblemType = key
|
}
|
chartcount++
|
}
|
if (chartcount == MAX_CHART_COUNT) {
|
entries.add(PieEntry(remainProblemCount.toFloat(), remainProblemType))
|
} else if (chartcount > MAX_CHART_COUNT) {
|
entries.add(PieEntry(remainProblemCount.toFloat(), REMAIN_PROBLEM))
|
}
|
|
// add a lot of colors
|
val colors = ArrayList<Int>()
|
for (c in ColorTemplate.JOYFUL_COLORS) colors.add(c)
|
for (c in ColorTemplate.COLORFUL_COLORS) colors.add(c)
|
for (c in ColorTemplate.VORDIPLOM_COLORS) colors.add(c)
|
for (c in ColorTemplate.LIBERTY_COLORS) colors.add(c)
|
for (c in ColorTemplate.PASTEL_COLORS) colors.add(c)
|
colors.add(ColorTemplate.getHoloBlue())
|
dataSet.colors = colors
|
|
//value line
|
dataSet.valueLinePart1OffsetPercentage = 80f
|
dataSet.valueLinePart1Length = 0.2f
|
dataSet.valueLinePart2Length = 0.4f
|
//dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
|
dataSet.yValuePosition = PieDataSet.ValuePosition.OUTSIDE_SLICE
|
|
//
|
val data = PieData(dataSet)
|
data.setValueFormatter(PercentFormatter())
|
data.setValueTextSize(11f)
|
data.setValueTextColor(Color.BLACK)
|
// data.setValueTypeface(mTfLight);
|
if (!entries.isEmpty()) { //数据全为空时,不显示
|
mChart!!.data = data
|
} else {
|
mChart!!.data = null
|
}
|
mChart!!.setNoDataText("暂无数据")
|
|
// undo all highlights
|
mChart!!.highlightValues(null)
|
mChart!!.animateY(1400, Easing.EasingOption.EaseInOutQuad)
|
}
|
|
/**
|
* 初始化下拉框适配器
|
*/
|
private fun initAdapter() {
|
//****下面为设置适配器**********************************************
|
//省份
|
provinceAdapter = object : AllListViewAdapter<Province>(provinceData as ArrayList<Province>, R.layout.item_scense_detail_list) {
|
override fun bindView(holder: ViewHolder, obj: Province) {
|
holder.setText(R.id.tv_item, obj.provincename)
|
}
|
}
|
SP_province!!.adapter = provinceAdapter
|
provinceAdapter?.notifyDataSetChanged()
|
//城市
|
cityAdapter = object : AllListViewAdapter<City>(cityData as ArrayList<City>, R.layout.item_scense_detail_list) {
|
override fun bindView(holder: ViewHolder, obj: City) {
|
holder.setText(R.id.tv_item, obj.cityname)
|
}
|
}
|
SP_city!!.adapter = cityAdapter
|
cityAdapter?.notifyDataSetChanged()
|
//区县
|
districtAdapter = object : AllListViewAdapter<District>(districtData as ArrayList<District>, R.layout.item_scense_detail_list) {
|
override fun bindView(holder: ViewHolder, obj: District) {
|
holder.setText(R.id.tv_item, obj.districtname)
|
}
|
}
|
SP_district!!.adapter = districtAdapter
|
districtAdapter?.notifyDataSetChanged()
|
//街镇
|
townAdapter = object : AllListViewAdapter<Town>(townData as ArrayList<Town>, R.layout.item_scense_detail_list) {
|
override fun bindView(holder: ViewHolder, obj: Town) {
|
holder.setText(R.id.tv_item, obj.townname)
|
}
|
}
|
SP_town!!.adapter = townAdapter
|
//场景类型
|
scenseAdapter = object : AllListViewAdapter<Domainitem>(scenseTypeData as ArrayList<Domainitem>, R.layout.item_spinner_simple_text) {
|
override fun bindView(holder: ViewHolder, obj: Domainitem) {
|
holder.setText(R.id.tv_item, obj.text)
|
}
|
}
|
SP_scense_type!!.adapter = scenseAdapter
|
scenseAdapter?.notifyDataSetChanged()
|
//时间
|
dateAdapter = object : AllRecyclerViewAdapter<String>(dateData, R.layout.item_scense_detail_list, context) {
|
override fun bindView(holder: MyViewHolder, obj: String, bool: Boolean, position: Int) {
|
holder.setText(R.id.tv_item, obj)
|
holder.setSelected(R.id.tv_item, bool)
|
holder.setOnClickListener(R.id.tv_item) {
|
dateAdapter!!.setAllFalse()
|
dateAdapter!!.setSelected(true, position)
|
dateAdapter!!.notifyDataSetChanged()
|
BRIEF_TIME = obj
|
Log.e("对象名称", obj)
|
showDialog()
|
search()
|
}
|
if (BRIEF_TIME == obj) {
|
holder.setSelected(R.id.tv_item, true)
|
}
|
}
|
}
|
RV_quick_choose!!.adapter = dateAdapter
|
dateAdapter?.notifyDataSetChanged()
|
//****上面为设置适配器**********************************************
|
}
|
|
/**
|
* 区域选择弹出框
|
*/
|
private fun initDialog() {
|
// int mScreenWidth = getResources().getDisplayMetrics().widthPixels;
|
// 讲布局文件转换成 view 对象
|
dialog = Dialog(context)
|
dialog!!.setContentView(R.layout.popwindow)
|
//设置dialog宽度
|
val dialogWindow = dialog!!.window!!
|
dialogWindow.setBackgroundDrawableResource(android.R.color.transparent)
|
val p = dialogWindow.attributes
|
p.width = ScreenUtils.getScreenWidth(context)
|
// p.height = (int) (ScreenUtils.getScreenHeight(context) * 0.9);
|
/* 获取 PopupWindow 加载布局文件中的view */SP_province = dialog!!.findViewById<View>(R.id.SP_province) as Spinner
|
SP_city = dialog!!.findViewById<View>(R.id.SP_city) as Spinner
|
SP_district = dialog!!.findViewById<View>(R.id.SP_district) as Spinner
|
SP_town = dialog!!.findViewById<View>(R.id.SP_town) as Spinner
|
SP_province!!.onItemSelectedListener = this
|
SP_city!!.onItemSelectedListener = this
|
SP_district!!.onItemSelectedListener = this
|
SP_town!!.onItemSelectedListener = this
|
// SP_province.setSelection(0);
|
// SP_city.setSelection(0);
|
// SP_district.setSelection(0);
|
// SP_town.setSelection(0);
|
/*设置时间选择按钮*/TV_quick_choose = dialog!!.findViewById<View>(R.id.TV_quick_choose) as TextView
|
TV_any_time = dialog!!.findViewById<View>(R.id.TV_any_time) as TextView
|
TV_quick_choose!!.isSelected = true
|
TV_quick_choose!!.setOnClickListener(this)
|
TV_any_time!!.setOnClickListener(this)
|
/*设置快速时间选择列表*/TV_start_time = dialog!!.findViewById<View>(R.id.TV_start_time) as TextView
|
TV_end_time = dialog!!.findViewById<View>(R.id.TV_end_time) as TextView
|
TV_start_time!!.text = DateFormatter.dateFormat.format(CommonUtils.getTimesMonthmorning())
|
TV_end_time!!.text = DateFormatter.dateFormat.format(CommonUtils.getTimesMonthnight())
|
TV_start_time!!.setOnClickListener(this)
|
TV_end_time!!.setOnClickListener(this)
|
//设置显示对其方式
|
val layoutManager = GridLayoutManager(context, 2)
|
layoutManager.orientation = GridLayoutManager.VERTICAL
|
layoutManager.isAutoMeasureEnabled = true
|
RV_quick_choose = dialog!!.findViewById<View>(R.id.RV_quick_choose) as RecyclerView
|
RV_quick_choose!!.layoutManager = layoutManager
|
RV_quick_choose!!.addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL))
|
/* 设置任意时间选择列表*/LL_any_time = dialog!!.findViewById<View>(R.id.LL_any_time) as LinearLayout
|
LL_any_time!!.visibility = View.GONE
|
/*设置确定、取消按钮*/tv_Cancel = dialog!!.findViewById<View>(R.id.btn_cancel) as TextView
|
tv_Ok = dialog!!.findViewById<View>(R.id.btn_ok) as TextView
|
tv_Cancel!!.setOnClickListener(this)
|
tv_Ok!!.setOnClickListener(this)
|
dialog!!.show()
|
// dialog.hide();
|
// 点击会自动 PopupWindow 关闭
|
// dialog.setOutsideTouchable(false);
|
/* 设置 PopupWindow 出现时的动画 */
|
// dialog.setAnimationStyle(R.style.anim_menu_dialog);
|
/* 设置背景颜色 */
|
// dialog.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
|
// dialog.update();
|
/* 允许 PopupWindow 获取焦点 */
|
// this.dialog.setFocusable(false);
|
}
|
|
/**
|
* 显示和隐藏Popupwindow
|
*/
|
private fun showDialog() {
|
// 设置显示的位置
|
if (!dialog!!.isShowing) dialog!!.show() else dialog!!.dismiss()
|
}
|
|
/**
|
* 按照搜索条件查询问题分布结果
|
*/
|
private fun search() {
|
val dialog: Dialog = DialogUtil.createLoadingDialog(activity, "加载中...")
|
var areaVo = AreaVo()
|
areaVo.provincecode = (SP_province!!.selectedItem as Province).provincecode
|
areaVo.provincename = (SP_province!!.selectedItem as Province).provincename
|
areaVo.citycode = (SP_city!!.selectedItem as City).citycode
|
areaVo.cityname = (SP_city!!.selectedItem as City).cityname
|
areaVo.districtcode = (SP_district!!.selectedItem as District).districtcode
|
areaVo.districtname = (SP_district!!.selectedItem as District).districtname
|
areaVo.towncode = (SP_town!!.selectedItem as Town).towncode
|
areaVo.townname = (SP_town!!.selectedItem as Town).townname
|
areaVo = gettime(areaVo)
|
val position = SP_scense_type!!.selectedItemPosition
|
areaVo.scensetypeid = scenseTypeData[position].value
|
val getProblemByArea = problemListService!!.getByArea(areaVo)
|
getProblemByArea.enqueue(object : Callback<List<ProblemlistVo>?> {
|
override fun onResponse(call: Call<List<ProblemlistVo>?>, response: Response<List<ProblemlistVo>?>) {
|
val list = response.body()
|
if (list is List<ProblemlistVo>) {
|
problemlists.addAll(list)
|
}
|
setData(problemlists)
|
entryAdapter!!.notifyDataSetChanged() //刷新列表
|
DialogUtil.closeDialog(dialog)
|
}
|
|
override fun onFailure(call: Call<List<ProblemlistVo>?>, t: Throwable) {
|
setData(problemlists)
|
DialogUtil.closeDialog(dialog)
|
}
|
})
|
setChartTitle() //刷新标题
|
setDateDisplay() //刷新时间
|
}
|
|
/**
|
* 设定饼图标题及图标
|
*/
|
private fun setChartTitle() {
|
var title = (SP_province!!.selectedItem as Province).provincename
|
if (title != (SP_city!!.selectedItem as City).cityname) title = title + (SP_city!!.selectedItem as City).cityname
|
if ((SP_district!!.selectedItem as District).districtname != ALLDISTRICT) title = title + (SP_district!!.selectedItem as District).districtname
|
if ((SP_town!!.selectedItem as Town).townname != ALLTOWN) title = title + (SP_town!!.selectedItem as Town).townname
|
title = title + "问题类型分布情况"
|
TV_area!!.text = title
|
IV_scene_type!!.setImageResource(CommonUtils.getIconBySceneType((SP_scense_type!!.selectedItem as Domainitem).value))
|
}
|
|
/**
|
* 获取所选的时间
|
* @param areaVo RequestBody,查询问题列表
|
* @return
|
*/
|
private fun gettime(areaVo: AreaVo): AreaVo {
|
if (TIME_TYPE == 0) { //快速选择
|
val date1: Date
|
val date2: Date
|
when (BRIEF_TIME) {
|
Constant.THIS_WEEK -> {
|
date1 = CommonUtils.getTimesWeekmorning()
|
date2 = CommonUtils.getTimesWeeknight()
|
}
|
Constant.LAST_WEEK -> {
|
date1 = CommonUtils.getTimesLastWeekmorning()
|
date2 = CommonUtils.getTimesLastWeeknight()
|
}
|
Constant.THIS_MONTH -> {
|
date1 = CommonUtils.getTimesMonthmorning()
|
date2 = CommonUtils.getTimesMonthnight()
|
}
|
Constant.LAST_MONTH -> {
|
date1 = CommonUtils.getTimesLastMonthmorning()
|
date2 = CommonUtils.getTimesLastMonthnight()
|
}
|
Constant.THIS_SEASON -> {
|
date1 = CommonUtils.getTimesSeasonmorning()
|
date2 = CommonUtils.getTimesSeasonnight()
|
}
|
Constant.LAST_SEASON -> {
|
date1 = CommonUtils.getTimesLastSeasonmorning()
|
date2 = CommonUtils.getTimesLastSeasonnight()
|
}
|
Constant.THIS_YEAR -> {
|
date1 = CommonUtils.getCurrentYearStartTime()
|
date2 = CommonUtils.getCurrentYearEndTime()
|
}
|
Constant.LAST_YEAR -> {
|
date1 = CommonUtils.getLastYearStartTime()
|
date2 = CommonUtils.getLastYearEndTime()
|
}
|
else -> {
|
date1 = CommonUtils.getTimesMonthmorning()
|
date2 = CommonUtils.getTimesMonthnight()
|
}
|
}
|
areaVo.starttime = DateFormatter.dateTimeFormat2.format(date1)
|
areaVo.endtime = DateFormatter.dateTimeFormat2.format(date2)
|
} else if (TIME_TYPE == 1) { //任意时段
|
areaVo.starttime = TV_start_time!!.text.toString()
|
areaVo.endtime = TV_end_time!!.text.toString()
|
return areaVo
|
}
|
return areaVo
|
}
|
|
/**
|
* 设置所选时间的显示
|
*/
|
private fun setDateDisplay() {
|
if (TIME_TYPE == 0) { //快速选择
|
// TV_date_display1.setTitle(BRIEF_TIME);
|
stv_date_display2!!.text = BRIEF_TIME
|
} else if (TIME_TYPE == 1) { //任意时段
|
// TV_date_display1.setTitle(TV_start_time.getTitle().toString());
|
stv_date_display2!!.text = TV_start_time!!.text.toString() + " ~ " + TV_end_time!!.text.toString()
|
}
|
}
|
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
override fun onClick(v: View) {
|
when (v.id) {
|
R.id.FAB_menu -> showDialog()
|
R.id.btn_cancel -> showDialog()
|
R.id.btn_ok -> {
|
search()
|
showDialog()
|
}
|
R.id.TV_quick_choose -> {
|
TV_quick_choose!!.isSelected = true
|
TV_any_time!!.isSelected = false
|
TV_quick_choose!!.setTextColor(Color.WHITE)
|
TV_any_time!!.setTextColor(Color.BLACK)
|
RV_quick_choose!!.visibility = View.VISIBLE
|
LL_any_time!!.visibility = View.GONE
|
TIME_TYPE = 0
|
}
|
R.id.TV_any_time -> {
|
TV_any_time!!.isSelected = true
|
TV_quick_choose!!.isSelected = false
|
TV_any_time!!.setTextColor(Color.WHITE)
|
TV_quick_choose!!.setTextColor(Color.BLACK)
|
LL_any_time!!.visibility = View.VISIBLE
|
RV_quick_choose!!.visibility = View.GONE
|
TIME_TYPE = 1
|
}
|
R.id.TV_start_time -> {
|
dialog!!.hide()
|
val calendar1 = Calendar.getInstance()
|
DatePickerDialog(activity, { datePicker, year, month, day ->
|
var result = ""
|
result += year.toString() + "." + (month + 1) + "." + day + "."
|
Toast.makeText(getContext(), result, Toast.LENGTH_SHORT).show()
|
dialog!!.show()
|
TV_start_time!!.text = result
|
}, calendar1[Calendar.YEAR], calendar1[Calendar.MONTH], calendar1[Calendar.DAY_OF_MONTH]).show()
|
}
|
R.id.TV_end_time -> {
|
dialog!!.hide()
|
val calendar2 = Calendar.getInstance()
|
DatePickerDialog(activity, { datePicker, year, month, day ->
|
var result = ""
|
result += year.toString() + "." + (month + 1) + "." + day + "."
|
Toast.makeText(activity, result, Toast.LENGTH_SHORT).show()
|
dialog!!.show()
|
TV_end_time!!.text = result
|
}, calendar2[Calendar.YEAR], calendar2[Calendar.MONTH], calendar2[Calendar.DAY_OF_MONTH]).show()
|
}
|
}
|
}
|
|
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
|
when (parent.id) {
|
R.id.SP_province -> {
|
cityData.clear()
|
var y = 0
|
while (y < allCityData.size) {
|
if (allCityData[y].pronvinceid == (SP_province!!.selectedItem as Province).provinceid) cityData.add(allCityData[y])
|
y++
|
}
|
cityAdapter!!.notifyDataSetChanged()
|
}
|
R.id.SP_city -> {
|
districtData.clear()
|
val emptydistrict = District()
|
emptydistrict.districtname = ALLDISTRICT
|
districtData.add(emptydistrict)
|
var y = 0
|
while (y < allDistrictData.size) {
|
if (allDistrictData[y].cityid == (SP_city!!.selectedItem as City).cityId) districtData.add(allDistrictData[y])
|
y++
|
}
|
districtAdapter!!.notifyDataSetChanged()
|
}
|
R.id.SP_district -> {
|
townData.clear()
|
val emptytown = Town()
|
emptytown.townname = ALLTOWN
|
townData.add(emptytown)
|
var y = 0
|
while (y < allTownData.size) {
|
if (allTownData[y].districtid == (SP_district!!.selectedItem as District).districtid) townData.add(allTownData[y])
|
y++
|
}
|
townAdapter!!.notifyDataSetChanged()
|
}
|
R.id.SP_town -> {
|
}
|
R.id.SP_scense_type -> search()
|
}
|
}
|
|
override fun onNothingSelected(parent: AdapterView<*>?) {}
|
|
companion object {
|
private const val ALLDISTRICT = "全部区县"
|
private const val ALLTOWN = "全部街道"
|
private const val MAX_CHART_COUNT = 5 //饼图最多显示区块数
|
private const val REMAIN_PROBLEM = "其余"
|
}
|
}
|