1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
package cn.flightfeather.thirdappmodule.module.home
 
import android.arch.lifecycle.ViewModelProviders
import android.content.Intent
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import butterknife.ButterKnife
import butterknife.Unbinder
import cn.flightfeather.thirdappmodule.CommonApplication
import cn.flightfeather.thirdappmodule.R
import cn.flightfeather.thirdappmodule.bean.entity.Scense
import cn.flightfeather.thirdappmodule.bean.entity.Subtask
import cn.flightfeather.thirdappmodule.bean.vo.InspectionInfoVo
import cn.flightfeather.thirdappmodule.bean.vo.RankVo
import cn.flightfeather.thirdappmodule.bean.vo.RankVo.SceneRank
import cn.flightfeather.thirdappmodule.bean.vo.TaskVo
import cn.flightfeather.thirdappmodule.common.net.ResultCallBack
import cn.flightfeather.thirdappmodule.module.dataanalysis.AnalysisOverViewFragment.Companion.rankS
import cn.flightfeather.thirdappmodule.httpservice.InspectionService
import cn.flightfeather.thirdappmodule.httpservice.TaskService
import cn.flightfeather.thirdappmodule.model.bean.NightWorkFileVo
import cn.flightfeather.thirdappmodule.module.nightwork.NightWorkRecordActivity
import cn.flightfeather.thirdappmodule.module.nightwork.NightWorkViewModel
import cn.flightfeather.thirdappmodule.util.Constant
import cn.flightfeather.thirdappmodule.util.DateFormatter
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.LocalWeatherLiveResult
import com.amap.api.services.weather.WeatherSearch
import com.amap.api.services.weather.WeatherSearch.OnWeatherSearchListener
import com.amap.api.services.weather.WeatherSearchQuery
import com.ping.greendao.gen.ScenseDao
import kotlinx.android.synthetic.main.function_card1_scene.*
import kotlinx.android.synthetic.main.function_card3_scene.*
import kotlinx.android.synthetic.main.function_card4_scene.*
import kotlinx.android.synthetic.main.function_card5_scene.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.text.ParseException
import java.util.*
 
/**
 * A simple [Fragment] subclass.
 */
class HomeFragment_scene : Fragment(), OnWeatherSearchListener, View.OnClickListener {
    private var tv_location: TextView? = null
    private var iv_weather_icon: ImageView? = null
    private var tv_temperature: TextView? = null
    private var tv_weather: TextView? = null
    private var ll_weatherBG: LinearLayout? = null
    private var tv_timeCurrent: TextView? = null
    private var sv_home_page: View? = null
    private var hidden = false
    private var application: CommonApplication? = null
 
    //定位相关
    private var mLocationClient: AMapLocationClient? = null
 
    //查询天气相关
    private var searchWeather = true
    private var query: WeatherSearchQuery? = null
    private var mweathersearch: WeatherSearch? = null
    private var temperature: String? = null
    private var weather: String? = null
 
    //
    private var viewHolder1: ViewHolder1? = null
    private var viewHolder2: ViewHolder2? = null
    private var viewHolder3: ViewHolder3? = null
    private var viewHolder4: ViewHolder4? = null
    private var viewHolder5: ViewHolder5? = null
 
    //ViewHolder1(今日任务)
    private val subtaskListOfUser = ArrayList<Subtask>()
 
    //是否在切换回来时刷新
    private var isUnHiddenRefresh = false
    private var unbinder: Unbinder? = null
    private var viewModel: NightWorkViewModel? = null
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        viewModel = ViewModelProviders.of(this).get(NightWorkViewModel::class.java)
        // Inflate the layout for this fragment
        val view = inflater.inflate(R.layout.fragment_home_pollution_scene, container, false)
        unbinder = ButterKnife.bind(this, view)
        return view
    }
 
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        searchWeather = true
        initData()
        initUI(view)
        initCurLocation()
        initCurrentTime()
        initScrollView(savedInstanceState)
        initClickListener()
    }
 
    override fun onDestroy() {
        if (unbinder != null) {
            unbinder!!.unbind()
        }
        super.onDestroy()
        mLocationClient!!.onDestroy()
    }
 
    override fun onPause() {
        super.onPause()
        mLocationClient!!.stopLocation()
        searchWeather = true
    }
 
    override fun onResume() {
        super.onResume()
        if (!hidden) {
            mLocationClient!!.startLocation()
            initCurrentTime()
        }
        //        refreshView();
    }
 
    override fun onStart() {
        super.onStart()
    }
 
    private fun initData() {
        application = activity!!.application as CommonApplication
    }
 
    private fun initUI(view: View) {
        tv_location = view.findViewById<View>(R.id.tv_location) as TextView
        tv_location!!.setOnClickListener(this)
        iv_weather_icon = view.findViewById<View>(R.id.iv_weather_icon) as ImageView
        //
        iv_weather_icon!!.setOnClickListener(this)
        //
        tv_temperature = view.findViewById<View>(R.id.tv_temperature) as TextView
        tv_weather = view.findViewById<View>(R.id.tv_weather) as TextView
        ll_weatherBG = view.findViewById<View>(R.id.ll_weather_bg) as LinearLayout
        tv_timeCurrent = view.findViewById<View>(R.id.tv_now_date_time) as TextView
        sv_home_page = view.findViewById(R.id.sv_home_page)
    }
 
    //初始化时间textView
    private fun initCurrentTime() {
        val calendar = Calendar.getInstance()
        tv_timeCurrent!!.text = DateFormatter.dateFormatWeek.format(calendar.time)
    }
 
    private fun initScrollView(savedInstanceState: Bundle?) {
//        sv_home_page.setLayoutManager(new LinearLayoutManager(getContext()));
//        parentAdapter = new RecyclerViewAdapter(getContext(),savedInstanceState);
//        sv_home_page.setAdapter(parentAdapter);
        viewHolder1 = ViewHolder1(savedInstanceState, sv_home_page)
        viewHolder2 = ViewHolder2(savedInstanceState, sv_home_page)
        viewHolder3 = ViewHolder3(savedInstanceState, sv_home_page)
        viewHolder4 = ViewHolder4(savedInstanceState, sv_home_page)
        viewHolder5 = ViewHolder5()
        viewHolder1!!.initViewHolder1()
        viewHolder1!!.refreshView()
        viewHolder2!!.refreshView()
        //        viewHolder3.initViewHolder3();
        viewHolder5!!.init()
    }
 
    private fun initCurLocation() {
        val curLocation: String? = null
        //声明定位回调监听器
        val mLocationListener = AMapLocationListener { aMapLocation ->
            if (aMapLocation != null) {
                if (aMapLocation.errorCode == 0) {
                    //可在其中解析amapLocation获取相应内容
                    //城市地址
                    val address = aMapLocation.address
                    tv_location!!.text = address
                    searchWeather(aMapLocation.city)
                } else {
//                        Toast.makeText(getActivity(), "定位失败,请检查网络", Toast.LENGTH_SHORT).show();
                }
            }
        }
        //初始化定位
        mLocationClient = AMapLocationClient(activity!!.applicationContext)
        //设置定位回调监听
        mLocationClient!!.setLocationListener(mLocationListener)
        //声明AMapLocationClientOption对象
        var mLocationOption: AMapLocationClientOption? = null
        //初始化AMapLocationClientOption对象
        mLocationOption = AMapLocationClientOption()
        //设置定位模式为AMapLocationMode.Hight_Accuracy,高精度模式。
        mLocationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy
        //设置定位模式为AMapLocationMode.Battery_Saving,低功耗模式。
        mLocationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Battery_Saving
        //设置定位间隔,单位毫秒,默认为2000ms,最低1000ms。
        mLocationOption.interval = 10000
        //设置是否返回地址信息(默认返回地址信息)
        mLocationOption.isNeedAddress = true
        //设置是否强制刷新WIFI,默认为true,强制刷新。
        mLocationOption.isWifiActiveScan = true
        //设置是否允许模拟位置,默认为true,允许模拟位置
        mLocationOption.isMockEnable = true
        //关闭缓存机制
        mLocationOption.isLocationCacheEnable = false
        //给定位客户端对象设置定位参数
        mLocationClient!!.setLocationOption(mLocationOption)
        //启动定位
        mLocationClient!!.startLocation()
    }
 
    //根据城市搜索天气
    private fun searchWeather(city: String) {
        query = WeatherSearchQuery(city, WeatherSearchQuery.WEATHER_TYPE_LIVE)
        mweathersearch = WeatherSearch(context)
        mweathersearch!!.setOnWeatherSearchListener(this)
        mweathersearch!!.query = query
        mweathersearch!!.searchWeatherAsyn() //异步搜索
    }
 
    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
        this.hidden = hidden
        if (hidden) {
            mLocationClient!!.stopLocation()
            searchWeather = true
        } else {
            mLocationClient!!.startLocation()
            initCurrentTime()
            //            viewHolder2.clearView();
//            refreshView();
            if (isUnHiddenRefresh) {
                refreshView()
                isUnHiddenRefresh = !isUnHiddenRefresh
            }
        }
    }
 
    //设置是否在切换回来时刷新
    fun setUnHiddenRefresh(unHiddenRefresh: Boolean) {
        isUnHiddenRefresh = unHiddenRefresh
    }
 
    override fun onWeatherLiveSearched(localWeatherLiveResult: LocalWeatherLiveResult, i: Int) {
        if (searchWeather) {
            if (i == 1000) {
                if (localWeatherLiveResult != null || localWeatherLiveResult.liveResult != null) {
                    val weatherlive = localWeatherLiveResult.liveResult
                    temperature = weatherlive.temperature + "°"
                    weather = weatherlive.weather.trim { it <= ' ' }
                    tv_weather!!.text = weather
                    tv_temperature!!.text = temperature
                    if (weather != null && weather!!.trim { it <= ' ' } != "") {
                        if (weather == "多云") {
                            iv_weather_icon!!.setBackgroundResource(R.drawable.weather_icon_1)
                            ll_weatherBG!!.setBackgroundResource(R.drawable.home_feeds_weather_bkg_cloudy)
                        } else if (weather == "晴") {
                            iv_weather_icon!!.setBackgroundResource(R.drawable.weather_icon_0)
                            ll_weatherBG!!.setBackgroundResource(R.drawable.home_feeds_weather_bkg_sunny)
                        } else if (weather == "阴") {
                            iv_weather_icon!!.setBackgroundResource(R.drawable.weather_icon_2)
                            ll_weatherBG!!.setBackgroundResource(R.drawable.home_feeds_weather_bkg_cloudy)
                        } else if (weather == "小雨") {
                            iv_weather_icon!!.setBackgroundResource(R.drawable.weather_icon_3)
                            ll_weatherBG!!.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain)
                        } else if (weather == "中雨") {
                            iv_weather_icon!!.setBackgroundResource(R.drawable.weather_icon_4)
                            ll_weatherBG!!.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain)
                        } else if (weather == "大雨") {
                            iv_weather_icon!!.setBackgroundResource(R.drawable.weather_icon_5)
                            ll_weatherBG!!.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain)
                        } else if (weather == "阵雨") {
                            iv_weather_icon!!.setBackgroundResource(R.drawable.weather_icon_8)
                            ll_weatherBG!!.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain)
                        } else if (weather == "雨夹雪") {
                            iv_weather_icon!!.setBackgroundResource(R.drawable.weather_icon_15)
                            ll_weatherBG!!.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain)
                        } else if (weather == "小雪") {
                            iv_weather_icon!!.setBackgroundResource(R.drawable.weather_icon_9)
                            ll_weatherBG!!.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain)
                        } else if (weather == "中雪") {
                            iv_weather_icon!!.setBackgroundResource(R.drawable.weather_icon_10)
                            ll_weatherBG!!.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain)
                        } else if (weather == "大雪") {
                            iv_weather_icon!!.setBackgroundResource(R.drawable.weather_icon_11)
                            ll_weatherBG!!.setBackgroundResource(R.drawable.home_feeds_weather_bkg_rain)
                        }
                    }
                    searchWeather = false
                }
            }
        }
    }
 
    override fun onWeatherForecastSearched(localWeatherForecastResult: LocalWeatherForecastResult, i: Int) {}
    override fun onClick(view: View) {
        val id = view.id
        if (id == R.id.iv_weather_icon) {
            Toast.makeText(context, "打开天气详情", Toast.LENGTH_SHORT).show()
        } else if (id == R.id.btn_search) {
            refreshView()
        }
    }
 
    enum class ITEM_TYPE {
        ITEM1, ITEM2, ITEM3, ITEM4, ITEM5 {
 
        }
    }
 
    fun refreshView() {
        viewHolder1!!.initViewHolder1()
        viewHolder1!!.refreshView()
        viewHolder2!!.refreshView()
    }
 
    /**
     * 返回当前用户执行的子任务列表
     * @param msubtaskList
     * @return
     */
    fun getmSubtaskListOfUser(msubtaskList: List<Subtask>): ArrayList<Subtask> {
        if (application!!.currentUser.usertypeid.toInt() == 2) { //主管部门的任务展示按照区县划分
            subtaskListOfUser.clear()
            for (subtask in msubtaskList) {
                if (subtask.districtcode == application!!.currentUser.dguid){} //区县行政编码判定,只显示对应区县的任务
                    subtaskListOfUser.add(subtask)
            }
        }
        return subtaskListOfUser
    }
 
    //<editor-fold desc="ViewHolder1">
    private val taskVoList: MutableList<TaskVo> = ArrayList() //用户场景对应的区县所有的顶层任务
    private var curScene = Scense() //当前用户对应的场景信息
    private var lastMonthRank = 0//上月排名
    private var monthBeforeLastMonthRank = 0//上上月排名
 
    inner class ViewHolder1 internal constructor(savedInstanceState: Bundle?, itemView: View?) {
        fun initViewHolder1() {
            val s1 = if (lastMonthRank == 0 || lastMonthRank > 99) "您上月无排名" else "您上月排名第" + lastMonthRank + "名"
            var s2 = "无排名对比"
            text_rank_detail_3!!.setText(R.string.rank_tip_4)
 
            //<editor-fold desc="填写排名">
            if (lastMonthRank == 0 || lastMonthRank > 99) {
                text_rank!!.text = "--"
            } else if (lastMonthRank in 1..9) {
                val tmp = "0$lastMonthRank"
                text_rank!!.text = tmp
            } else {
                text_rank!!.text = lastMonthRank.toString()
            }
            //</editor-fold>
            if (lastMonthRank == 0
                || monthBeforeLastMonthRank == 0
            ) {
                image_rank!!.setImageResource(R.drawable.icon_rank_no_change_2)
            } else {
                if (lastMonthRank == monthBeforeLastMonthRank) {
                    image_rank!!.setImageResource(R.drawable.icon_rank_no_change_2)
                    s2 = "较上上月排名无变化"
                    text_rank_detail_3!!.setText(R.string.rank_tip_3)
                } else if (lastMonthRank - monthBeforeLastMonthRank > 0) {
                    image_rank!!.setImageResource(R.drawable.icon_rank_down_2)
                    s2 = "较上上月排名下降" + (lastMonthRank - monthBeforeLastMonthRank) + "名"
                    text_rank_detail_3!!.setText(R.string.rank_tip_2)
                } else {
                    image_rank!!.setImageResource(R.drawable.icon_rank_up_2)
                    s2 = "较上上月排名上升" + (monthBeforeLastMonthRank - lastMonthRank) + "名"
                    text_rank_detail_3!!.setText(R.string.rank_tip_1)
                }
            }
            text_rank_detail_1!!.text = s1
            text_rank_detail_2!!.text = s2
        }
 
        fun refreshView() {
            taskList
        }//主管部门的部门id就是区县id//返回结果默认按时间降序排序
 
        //顶层任务
        val taskList: Unit
            get() {
                val scenseDao = application!!.daoSession.scenseDao
                val sceneId = application!!.currentUser.dguid
                val scenses = scenseDao.queryBuilder()
                    .where(
                        ScenseDao.Properties.Guid.eq(
                            sceneId ?: ""
                        )
                    ).list()
                if (!scenses.isEmpty()) {
                    curScene = scenses[0]
                }
                //顶层任务
                val getTopClassTaskList = application!!.retrofit.create(TaskService::class.java).getTopClassTaskList(0)
                val finalScense = curScene
                getTopClassTaskList.enqueue(object : Callback<ArrayList<TaskVo>?> {
                    override fun onResponse(call: Call<ArrayList<TaskVo>?>, response: Response<ArrayList<TaskVo>?>) {
                        if (response.body() != null) {
                            val allTaskVoList: List<TaskVo>? = response.body() //返回结果默认按时间降序排序
                            for (t in allTaskVoList!!) {
                                if (t.districtcode == finalScense.districtcode) { //主管部门的部门id就是区县id
                                    taskVoList.add(t)
                                }
                            }
                            val now = Date()
                            if (taskVoList.size >= 2 && taskVoList[0].starttime.before(now)) {
                                getRank(taskVoList[1])
                                viewHolder3!!.refreshView()
                            }
                        }
                    }
 
                    override fun onFailure(call: Call<ArrayList<TaskVo>?>, t: Throwable) {}
                })
            }
        private var isDone = false //需要分别查询上月与上上月客户场景的排名,以便做比较
        fun getRank(taskVo: TaskVo) {
            val getRank = application!!.retrofit.create(TaskService::class.java).getRank(taskVo.tguid, curScene.typeid.toString(), curScene.guid)
            getRank.enqueue(object : Callback<RankVo?> {
                override fun onResponse(call: Call<RankVo?>, response: Response<RankVo?>) {
                    if (response.body() != null) {
                        //上月排名
                        if (!isDone) {
                            val rankVo = response.body()
                            val sceneRanks: List<SceneRank?> = rankVo!!.sceneRanks
                            rankS(sceneRanks)
                            for (i in sceneRanks.indices) {
                                if (curScene.guid == sceneRanks[i]!!.sceneNameId && sceneRanks[i]!!.score > -1) {
                                    lastMonthRank = sceneRanks[i]!!.rankNo //上月排名
                                    initViewHolder1()
                                    break
                                }
                            }
                            if (taskVoList.size >= 3) {
                                isDone = true
                                getRank(taskVoList[2])
                            }
                        } else {
                            val rankVo = response.body()
                            val sceneRanks: List<SceneRank?> = rankVo!!.sceneRanks
                            rankS(sceneRanks)
                            for (i in sceneRanks.indices) {
                                if (curScene.guid == sceneRanks[i]!!.sceneNameId && sceneRanks[i]!!.score > -1) {
                                    monthBeforeLastMonthRank = sceneRanks[i]!!.rankNo //上上月排名
                                    initViewHolder1()
                                    break
                                }
                            }
                            isDone = false
                        }
                    }
                }
 
                override fun onFailure(call: Call<RankVo?>, t: Throwable) {}
            })
        }
    }
 
    //</editor-fold>
 
    //<editor-fold desc="ViewHolder2">
    inner class ViewHolder2 internal constructor(savedInstanceState: Bundle?, itemView: View?) {
        fun refreshView() {
            initViewholder2()
        }
 
        private fun initViewholder2() {}
    }
 
    //</editor-fold>
 
    //<editor-fold desc="ViewHolder3">
    inner class ViewHolder3 internal constructor(savedInstanceState: Bundle?, itemView: View?) {
        fun refreshView() {
            initViewHolder3()
        }
 
        /**
         * 在[ViewHolder1.getRank]第一次被调用后(确保当前场景在当前时间有对应的顶层任务),才会调用此函数
         */
        private fun initViewHolder3() {
            val sceneId = application!!.currentUser.dguid
            val topTaskId = taskVoList[0].tguid
            val getInspectionInfoByScene = application!!.retrofit.create(InspectionService::class.java).getInspectionInfoByScene(sceneId, topTaskId)
            getInspectionInfoByScene.enqueue(object : Callback<InspectionInfoVo?> {
                override fun onResponse(call: Call<InspectionInfoVo?>, response: Response<InspectionInfoVo?>) {
                    if (response.body() != null) {
                        initView(response.body())
                        viewHolder4!!.refreshView(response.body())
                    }
                }
 
                override fun onFailure(call: Call<InspectionInfoVo?>, t: Throwable) {}
            })
        }
 
        fun initView(infoVo: InspectionInfoVo?) {
            //已巡查
            if (infoVo!!.isInspected) {
                text_no_supervise_tips!!.visibility = View.INVISIBLE
                cl_1!!.visibility = View.VISIBLE
                cl_2!!.visibility = View.VISIBLE
                image_inspection_status!!.isSelected = true
                text_inspection_time!!.text = infoVo.inspectionTime
                text_inspection_times!!.text = (
                        infoVo.unChangedCount + infoVo.changedCount
                        ).toString()
                text_change_promise!!.isSelected = infoVo.isPromised
                text_change_promise!!.setText(if (infoVo.isPromised) R.string.promised else R.string.refused)
                text_change_status!!.isSelected = infoVo.isChanged
                text_change_status!!.setText(if (infoVo.isChanged) R.string.changed else R.string.unchanged)
            } else {
                text_no_supervise_tips!!.visibility = View.VISIBLE
                cl_1!!.visibility = View.GONE
                cl_2!!.visibility = View.INVISIBLE
                image_inspection_status!!.isSelected = false
            }
        }
    }
 
    //</editor-fold>
 
    //<editor-fold desc="ViewHolder4">
    inner class ViewHolder4 internal constructor(savedInstanceState: Bundle?, itemView: View?) {
        fun refreshView(infoVo: InspectionInfoVo?) {
            initViewHolder4(infoVo)
        }
 
        /**
         * 在[ViewHolder3.initViewHolder3]函数第一次被调用后,才能调用此函数
         */
        fun initViewHolder4(infoVo: InspectionInfoVo?) {
            text_change_count!!.text = infoVo!!.unChangedCount.toString()
            text_changed_count!!.text = infoVo.changedCount.toString()
            val promisedTime = infoVo.promisedTime
            try {
                //未整改完成
                if (infoVo.unChangedCount > 0) {
                    var promisedTime_d: Date? = null
                    promisedTime_d = if (promisedTime == null || promisedTime.equals("null", ignoreCase = true)) {
                        DateFormatter.dateFormat2.parse(infoVo.inspectionTime)
                    } else {
                        DateFormatter.dateFormat.parse(promisedTime)
                    }
                    val calendar = Calendar.getInstance()
                    calendar[Calendar.HOUR_OF_DAY] = 0
                    calendar[Calendar.MINUTE] = 0
                    calendar[Calendar.SECOND] = 0
                    val today = calendar.time
                    val leftDays = (promisedTime_d.time - today.time).toInt() / 1000 / 60 / 60 / 24
                    if (leftDays >= 0) {
                        text_change_left_day!!.text = leftDays.toString()
                    } else {
                        text_change_info!!.text = "您已逾期"
                        text_change_left_day.text = (-leftDays).toString()
                    }
                    group_deadline!!.visibility = View.VISIBLE
                    image_done!!.visibility = View.GONE
                } else {
                    group_deadline!!.visibility = View.GONE
                    image_done!!.visibility = View.VISIBLE
                }
            } catch (e: ParseException) {
                e.printStackTrace()
            }
        }
    }
 
    //</editor-fold>
 
    inner class ViewHolder5 {
        fun init() {
            cl_night_work!!.setOnClickListener { v: View? -> startActivity(Intent(context, NightWorkRecordActivity::class.java)) }
            viewModel!!.getNightWorkFile(false, 1, object : ResultCallBack<List<NightWorkFileVo>> {
                override fun onCacheSuccess(result: List<NightWorkFileVo>?) {}
                override fun onPage(current: Int, total: Int) {}
                override fun onSuccess(result: List<NightWorkFileVo>?) {
                    if (result == null || result.isEmpty()) {
                        txt_news!!.text = "暂无新许可证"
                    } else {
                        txt_news!!.text = "有新许可证下发,请查看"
                    }
                }
 
                override fun onFailure() {
                    txt_news!!.text = "网络连接失败,请退出重试"
                }
            })
        }
    }
 
    //<editor-fold desc="点击事件">
    private fun initClickListener() {
        card_change_problem.setOnClickListener { onChangeProblem() }
        card_changed_problem.setOnClickListener { onChangeProblem() }
    }
    private fun onChangeProblem() {
        val intent = Intent("cn.flightfeather.thirdapp.broadcasereceiver.MainReceiver")
        intent.action = Constant.GOTO_INSPECTION_FRAGMENT
        activity!!.sendBroadcast(intent)
    }
//</editor-fold>
}