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
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
package cn.flightfeather.thirdapp.fragment;
 
 
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.location.Location;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.content.FileProvider;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
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.view.Window;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckedTextView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
 
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.TextureMapView;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.haibin.calendarview.Calendar;
import com.haibin.calendarview.CalendarView;
import com.ping.greendao.gen.DaoSession;
import com.ping.greendao.gen.DomaincatalogDao;
import com.ping.greendao.gen.DomainitemDao;
import com.ping.greendao.gen.EvaluationruleDao;
import com.ping.greendao.gen.EvaluationsubruleDao;
import com.ping.greendao.gen.GittypeDao;
import com.ping.greendao.gen.MediafileDao;
import com.ping.greendao.gen.ProblemtypeDao;
import com.ping.greendao.gen.ScenseDao;
import com.ping.greendao.gen.SiteDao;
 
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import cn.flightfeather.thirdapp.CommonApplication;
import cn.flightfeather.thirdapp.R;
import cn.flightfeather.thirdapp.activity.GitDetailActivity;
import cn.flightfeather.thirdapp.activity.GradeActivity;
import cn.flightfeather.thirdapp.activity.MapActivity;
import cn.flightfeather.thirdapp.activity.PhotoViewerActivity;
import cn.flightfeather.thirdapp.activity.ProblemDetailActivity;
import cn.flightfeather.thirdapp.activity.PromiseActivity;
import cn.flightfeather.thirdapp.activity.SignActivity;
import cn.flightfeather.thirdapp.activity.SubTaskMapActivity;
import cn.flightfeather.thirdapp.activity.UploadMediaFilesActivity;
import cn.flightfeather.thirdapp.adapter.DomainItemListAdapter;
import cn.flightfeather.thirdapp.adapter.GitListAdapter;
import cn.flightfeather.thirdapp.adapter.GitTypeListAdapter;
import cn.flightfeather.thirdapp.adapter.IconsPageAdapter;
import cn.flightfeather.thirdapp.adapter.PhotoListAdapter;
import cn.flightfeather.thirdapp.adapter.ProblemListAdapter;
import cn.flightfeather.thirdapp.adapter.ProblemTypeListAdapter;
import cn.flightfeather.thirdapp.adapter.RecyclerItemClickListener;
import cn.flightfeather.thirdapp.adapter.TaskListAdapter;
import cn.flightfeather.thirdapp.bean.ChangeAdvice;
import cn.flightfeather.thirdapp.bean.Domainitem;
import cn.flightfeather.thirdapp.bean.Gitlist;
import cn.flightfeather.thirdapp.bean.Gittype;
import cn.flightfeather.thirdapp.bean.Inspection;
import cn.flightfeather.thirdapp.bean.LastSubtaskPack;
import cn.flightfeather.thirdapp.bean.Mediafile;
import cn.flightfeather.thirdapp.bean.Problemlist;
import cn.flightfeather.thirdapp.bean.Problemtype;
import cn.flightfeather.thirdapp.bean.Scense;
import cn.flightfeather.thirdapp.bean.Site;
import cn.flightfeather.thirdapp.bean.Subtask;
import cn.flightfeather.thirdapp.bean.TaskPack;
import cn.flightfeather.thirdapp.bean.vo.GitlistVo;
import cn.flightfeather.thirdapp.bean.vo.InspectionVo;
import cn.flightfeather.thirdapp.bean.vo.ProblemlistVo;
import cn.flightfeather.thirdapp.bean.vo.TaskVo;
import cn.flightfeather.thirdapp.common.database.DbLink;
import cn.flightfeather.thirdapp.common.database.DbSource;
import cn.flightfeather.thirdapp.httpservice.InspectionImageService;
import cn.flightfeather.thirdapp.httpservice.InspectionService;
import cn.flightfeather.thirdapp.httpservice.SubTaskService;
import cn.flightfeather.thirdapp.module.base.BaseTakePicActivity;
import cn.flightfeather.thirdapp.module.task.SceneDetailActivity;
import cn.flightfeather.thirdapp.task.SetImageTask;
import cn.flightfeather.thirdapp.util.AmapNavi;
import cn.flightfeather.thirdapp.util.Constant;
import cn.flightfeather.thirdapp.util.DateFormatter;
import cn.flightfeather.thirdapp.util.DialogUtil;
import cn.flightfeather.thirdapp.util.ScreenUtils;
import cn.flightfeather.thirdapp.util.UUIDGenerator;
import cn.flightfeather.thirdapp.util.photo.PhotoUtil;
import cn.flightfeather.thirdapp.util.slideswaphelper.OnDeleteListener;
import cn.flightfeather.thirdapp.util.slideswaphelper.OnSwipeItemClickListener;
import cn.flightfeather.thirdapp.util.slideswaphelper.PlusItemSlideCallback;
import cn.flightfeather.thirdapp.util.slideswaphelper.WItemTouchHelperPlus;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
 
import static android.app.Activity.RESULT_OK;
 
/**
 * A simple {@link Fragment} subclass.
 */
public class InspectionFragment extends Fragment implements CalendarView.OnCalendarSelectListener, View.OnClickListener, AMap.OnMyLocationChangeListener {
 
    private static final String TAG = "InspectionFragment";
    private CommonApplication application;
    //数据库相关
    private SiteDao siteDao;
    private ScenseDao scenseDao;
    private DomaincatalogDao domaincatalogDao;
    private DomainitemDao domainitemDao;
    private EvaluationruleDao evaluationruleDao;
    private EvaluationsubruleDao evaluationsubruleDao;
    private GittypeDao gittypeDao;
    private ProblemtypeDao problemtypeDao;
    private MediafileDao mediafileDao;
    private DbSource dbSource;
    private List<Disposable> disposables = new ArrayList<>();
    //网络相关
    InspectionService inspectionService;
    InspectionImageService inspectionImageService;
    SubTaskService subTaskService;
 
 
    //任务选择部分
    private RelativeLayout rl_selectTask;
    private CalendarView mCalendarView;
    private TextView tv_title;
    private Map<String, Calendar> schemes;
    private Spinner sp_selectMonthTask;
    private ArrayAdapter selectMonthTaskAdapter;
    private RecyclerView rv_subTaskList;
 
    //string:日期:yyyy-mm,
    private Map<String, List<TaskVo>> taskAllMapList;
    private java.util.Calendar lastMonthCalender;
    private java.util.Calendar calendarCurrent;
    private List<Integer> dayTaskTimeList;
    private Map<Integer, List<Subtask>> subTaskMapCurrent;
    private List<TaskVo> monthTaskListCurrent;
    private List<String> monthTaskStringListCurrent;
    private List<Subtask> subTaskListCurrent;
    private TaskListAdapter subTaskListAdapter;
    private boolean firstLoad = true;
    private boolean requestAgain = false;
    private TaskVo monthTaskSelected = null;
    private Subtask subTaskSelected = null;
 
 
    //现场巡查部分
    private RelativeLayout rl_content;
    private TextureMapView tmv_main;
    private ViewPager vp_icons;
    private LinearLayout ll_show;
    private LinearLayout ll_hide;
    private LinearLayout ll_icons;
    private ImageView iv_pointer;
    private LinearLayout ll_showHideDetail;
    private ImageView iv_showHideDetail;
    private LinearLayout ll_taskDetail;
    private ImageView iv_back;
    private ImageView iv_startEndTask;
    private AMap aMap;
    private MapView mv_main;
    private boolean hidden = false;
    private TextView tv_subTaskNameBar;
    private TextView tv_subTaskStatusBar;
    private String subTaskStatusCurrent = "";
    private final String subTaskNotStart = "未执行";
    private final String subTaskRunning = "正在执行";
    private final String subTaskEnd = "已结束";
    private final float banAlpha = 0.2f;
    private Scense scenseCurrent;
    private Site siteCurrent;
    private Inspection inspectionCurrent;
    private String scenseType = "";
    private final String site = "工地";
    private InspectionVo inspectionVoCurrent;
    private double latitudeCurrent = -1;
    private double longitudeCurrent = -1;
    private List<Integer> problemNowMarkerList;
    private List<ProblemlistVo> problemListVoListCurrent = new ArrayList<>();
 
    private LinearLayout ll_problemRecheck;
    private LinearLayout ll_takeEvidence;
    private LinearLayout ll_problemList;
    private LinearLayout ll_problemChange;
    private LinearLayout ll_camera;
    private LinearLayout ll_newGit;
    private LinearLayout ll_promise;
    private LinearLayout ll_evaluation;
    private LinearLayout ll_navi;
    private LinearLayout ll_choseLatlng;
    private LinearLayout ll_editeScence;
    //任务和工地详情
    private TextView tv_detailTaskName;
    private TextView tv_detailTaskType;
    private TextView tv_detailPlanTime;
    private TextView tv_detailExecuteTime;
    private TextView tv_detailExecutors;
    private TextView tv_detailScenseName;
    private TextView tv_detailScenseType;
    private TextView tv_detailScenseAddress;
    private TextView tv_detailContact1;
    private TextView tv_detailContact2;
    private TextView tv_callContact1;
    private TextView tv_callContact2;
 
    //问题取证相关
    private ImageView miv_add_photo1;
    private ImageView miv_add_photo2;
    private ImageView miv_add_photo3;
    private List<File> pathTempList;
 
    private final int PHOTO1 = 0;
    private final int PHOTO2 = 1;
    private final int PHOTO3 = 2;
 
    private final int TAKE_PHOTO1 = 0;
    private final int TAKE_PHOTO2 = 1;
    private final int TAKE_PHOTO3 = 2;
 
    private final int PICK_PHOTO1 = 10;
    private final int PICK_PHOTO2 = 11;
    private final int PICK_PHOTO3 = 12;
 
    private File tempFileCurrent;
 
    private final int SHOW_PHOTO = 87;
    private final int DELETE_SUCCESS = 88;
 
    public static final int PROBLEM_LIST = 100;
    public static final int PROBLEM_CHANGE = 101;
    public static final int PROBLEM_RECHECK = 102;
    private int OPEN_TYPE = PROBLEM_LIST;
 
    private final int PROBLEM_DETAIL = 105;
 
    private boolean problemEditable = false;
    private final int SIGN = 9;
 
    private final int BUSSINESS_TYPE_SIGN = 6;
    private final int BUSSINESS_TYPE_CAMERA = 5;
 
    private final int SUBTASK_MAP = 200;
    private final int CHOSE_LATLNG = 201;
    private final int PROMISE = 202;
    private ImageView iv_upload;
    private ProblemListAdapter problemListAdapter = null;
 
    //任意拍照
    private ImageView iv_cameraPhoto1;
    private ImageView iv_cameraPhoto2;
    private ImageView iv_cameraPhoto3;
    private List<ImageView> ivCameraList;
    private final int CAMERA_PHOTO = 110;
    private final int TAKE_CAMERA_PHOTO = 111;
    private final int PICK_CAMERA_PHTOO = 112;
    //新增技防措施
    private ImageView iv_gitPhoto1;
    private ImageView iv_gitPhoto2;
    private ImageView iv_gitPhoto3;
    private List<ImageView> ivGitList;
    private final int GIT_PHOTO = 113;
    private final int TAKE_GIT_PHOTO = 114;
    private final int PICK_GIT_PHOTO = 115;
    //图片浏览相关
    private final int VIEW_CAMERA_PHOTO = 116;
    private final int VIEW_SIGN_PHOTO = 117;
    private final int VIEW_EVIDENCE_TEMP_PHOTO = 118;
    private final int VIEW_CAMERA_TEMP_PHOTO = 226;
    private final int VIEW_GIT_TEMP_PHOTO = 227;
 
    private Dialog cameraDialog;
    private FloatingActionButton fab_map;
    private int currentPage;
    private final int TASK_PAGE = 230;
    private final int INSPECTION_PAGE = 231;
 
    private final int EDITE_SCENSE = 232;
 
    //加载弹出框
    private Dialog dialog;
 
    //滑动删除
    private WItemTouchHelperPlus extension;
 
 
    public InspectionFragment() {
        // Required empty public constructor
    }
 
    public void loadInspection(Subtask task) {
        subTaskSelected = task;
        if (rl_content != null && !rl_content.isShown()) {
            rl_content.setVisibility(View.VISIBLE);
        }
        if (rl_selectTask != null && rl_selectTask.isShown()) {
            rl_selectTask.setVisibility(View.INVISIBLE);
        }
        loadInspectionData(subTaskSelected.getStguid());
    }
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        Log.e(TAG, "onCreateView()");
        View view = inflater.inflate(R.layout.fragment_inspection, container, false);
        return view;
    }
 
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        Log.e(TAG, "onViewCreated()");
        application = (CommonApplication) getActivity().getApplication();
        currentPage = TASK_PAGE;
        initUI(view);
        initMarkPhotoList();
        initDataBase();
        initDate();
        initData();
        initRecyclerView();
        initSpinnerData();
        refreshUploadIconStatus();
 
        initIconViewPager();
        initMap(savedInstanceState);
        initLocation();
        rl_selectTask.setVisibility(View.VISIBLE);
        rl_content.setVisibility(View.INVISIBLE);
 
    }
 
    /**
     * Called when the fragment is no longer attached to its activity.  This
     * is called after {@link #onDestroy()}.
     */
    @Override
    public void onDetach() {
        super.onDetach();
    }
 
 
    //初始化带数字marker的列表
    private void initMarkPhotoList() {
        problemNowMarkerList = new ArrayList<>();
        problemNowMarkerList.add(R.drawable.icon_mark1_red);
        problemNowMarkerList.add(R.drawable.icon_mark2_red);
        problemNowMarkerList.add(R.drawable.icon_mark3_red);
        problemNowMarkerList.add(R.drawable.icon_mark4_red);
        problemNowMarkerList.add(R.drawable.icon_mark5_red);
        problemNowMarkerList.add(R.drawable.icon_mark6_red);
        problemNowMarkerList.add(R.drawable.icon_mark7_red);
        problemNowMarkerList.add(R.drawable.icon_mark8_red);
        problemNowMarkerList.add(R.drawable.icon_mark9_red);
        problemNowMarkerList.add(R.drawable.icon_mark10_red);
        problemNowMarkerList.add(R.drawable.icon_mark11_red);
        problemNowMarkerList.add(R.drawable.icon_mark12_red);
        problemNowMarkerList.add(R.drawable.icon_mark13_red);
        problemNowMarkerList.add(R.drawable.icon_mark14_red);
        problemNowMarkerList.add(R.drawable.icon_mark15_red);
        problemNowMarkerList.add(R.drawable.icon_mark16_red);
        problemNowMarkerList.add(R.drawable.icon_mark17_red);
        problemNowMarkerList.add(R.drawable.icon_mark18_red);
        problemNowMarkerList.add(R.drawable.icon_mark19_red);
        problemNowMarkerList.add(R.drawable.icon_mark20_red);
        problemNowMarkerList.add(R.drawable.icon_mark21_red);
        problemNowMarkerList.add(R.drawable.icon_mark22_red);
        problemNowMarkerList.add(R.drawable.icon_mark23_red);
        problemNowMarkerList.add(R.drawable.icon_mark24_red);
        problemNowMarkerList.add(R.drawable.icon_mark25_red);
        problemNowMarkerList.add(R.drawable.icon_mark26_red);
        problemNowMarkerList.add(R.drawable.icon_mark27_red);
        problemNowMarkerList.add(R.drawable.icon_mark28_red);
        problemNowMarkerList.add(R.drawable.icon_mark29_red);
        problemNowMarkerList.add(R.drawable.icon_mark30_red);
    }
 
    private void initUI(View view) {
        //任务选择部分
        rl_selectTask = (RelativeLayout) view.findViewById(R.id.rl_select_Task);
        mCalendarView = (CalendarView) view.findViewById(R.id.calendarView);
        mCalendarView.setOnCalendarSelectListener(this);
        fab_map = (FloatingActionButton) view.findViewById(R.id.fab_map);
        fab_map.setOnClickListener(this);
 
        tv_title = (TextView) view.findViewById(R.id.tv_title);
        sp_selectMonthTask = (Spinner) view.findViewById(R.id.sp_select_month_task);
        rv_subTaskList = (RecyclerView) view.findViewById(R.id.recyclerView);
 
        //现场巡查部分
        rl_content = (RelativeLayout) view.findViewById(R.id.rl_content);
        vp_icons = (ViewPager) view.findViewById(R.id.vp_patrol_icons);
        ll_icons = (LinearLayout) view.findViewById(R.id.ll_patrol_icons);
        ll_show = (LinearLayout) view.findViewById(R.id.ll_patrol_show);
        ll_hide = (LinearLayout) view.findViewById(R.id.ll_patrol_hide);
        iv_pointer = (ImageView) view.findViewById(R.id.iv_patrol_pointer);
        ll_showHideDetail = (LinearLayout) view.findViewById(R.id.ll_show_hide_detail);
        iv_showHideDetail = (ImageView) view.findViewById(R.id.iv_patrol_show_site_detail);
        ll_taskDetail = (LinearLayout) view.findViewById(R.id.ll_patrol_task_detail);
        iv_back = (ImageView) view.findViewById(R.id.iv_patrol_back);
        iv_startEndTask = (ImageView) view.findViewById(R.id.iv_start_end_task);
        mv_main = (MapView) view.findViewById(R.id.mv_main);
        tv_subTaskNameBar = (TextView) view.findViewById(R.id.tv_subtask_name_bar);
        tv_subTaskStatusBar = (TextView) view.findViewById(R.id.tv_subtask_status_bar);
        tv_detailTaskName = (TextView) view.findViewById(R.id.tv_subtask_name);
        tv_detailTaskType = (TextView) view.findViewById(R.id.tv_subtask_type);
        tv_detailPlanTime = (TextView) view.findViewById(R.id.tv_subtask_plan_time);
        tv_detailExecuteTime = (TextView) view.findViewById(R.id.tv_subtask_execute_time);
        tv_detailExecutors = (TextView) view.findViewById(R.id.tv_subtask_executors);
        tv_detailScenseName = (TextView) view.findViewById(R.id.tv_scense_name);
        tv_detailScenseType = (TextView) view.findViewById(R.id.tv_scense_type);
        tv_detailScenseAddress = (TextView) view.findViewById(R.id.tv_scense_address);
        tv_detailContact1 = (TextView) view.findViewById(R.id.tv_scense_contact1);
        tv_detailContact2 = (TextView) view.findViewById(R.id.tv_scense_contact2);
        iv_upload = (ImageView) view.findViewById(R.id.iv_upload);
        tv_callContact1 = (TextView) view.findViewById(R.id.tv_call_contact1);
        tv_callContact2 = (TextView) view.findViewById(R.id.tv_call_contact2);
 
        ll_show.setOnClickListener(this);
        ll_hide.setOnClickListener(this);
        ll_showHideDetail.setOnClickListener(this);
        iv_back.setOnClickListener(this);
        iv_upload.setOnClickListener(this);
 
        ll_taskDetail.setVisibility(View.GONE);
 
 
    }
 
    //初始化数据库
    private void initDataBase() {
        DaoSession daoSession = application.getDaoSession();
        scenseDao = daoSession.getScenseDao();
        siteDao = daoSession.getSiteDao();
        domaincatalogDao = daoSession.getDomaincatalogDao();
        domainitemDao = daoSession.getDomainitemDao();
        evaluationruleDao = daoSession.getEvaluationruleDao();
        evaluationsubruleDao = daoSession.getEvaluationsubruleDao();
        gittypeDao = daoSession.getGittypeDao();
        problemtypeDao = daoSession.getProblemtypeDao();
        mediafileDao = daoSession.getMediafileDao();
 
        dbSource = DbLink.getDbSource(application);
    }
 
    //初始化时间和日历
    private void initDate() {
        tv_title.setText(mCalendarView.getCurYear() + "年" + mCalendarView.getCurMonth() + "月");
        lastMonthCalender = java.util.Calendar.getInstance();
        calendarCurrent = java.util.Calendar.getInstance();
 
    }
 
    //初始化数据
    private void initData() {
        taskAllMapList = new HashMap<>();
        subTaskListCurrent = new ArrayList<>();
 
        inspectionService = application.getRetrofit().create(InspectionService.class);
        inspectionImageService = application.getRetrofitImage().create(InspectionImageService.class);
        subTaskService = application.getRetrofit().create(SubTaskService.class);
        String yearMonth = DateFormatter.YearMonthFormat.format(new Date());
        getThreeMonthTask(yearMonth, "Middle", false);
    }
 
    //打电话
    private View.OnClickListener callClikeListner(final String tele) {
        View.OnClickListener onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + tele));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        };
        return onClickListener;
    }
 
    private void refreshUploadIconStatus() {
        List<Mediafile> mediafileList = mediafileDao.queryBuilder().where(MediafileDao.Properties.Remark.eq("未上传")).list();
        if (mediafileList != null && mediafileList.size() > 0) {
            iv_upload.setSelected(true);
        } else {
            iv_upload.setSelected(false);
        }
    }
 
    //联网获得三个月的任务信息
    private void getThreeMonthTask(final String yearMonth, final String type, final boolean clearMap) {
        showLoadingDialog();
        Call<List<TaskPack>> loadThreeMonthTasks = inspectionService.loadThreeMonthTasks(yearMonth, application.getCurrentUser().getGuid(), type, String.valueOf(application.getCurrentUser().getUsertypeid()));
        loadThreeMonthTasks.enqueue(new Callback<List<TaskPack>>() {
            @Override
            public void onResponse(Call<List<TaskPack>> call, Response<List<TaskPack>> response) {
 
                if (response.body() != null) {
                    requestAgain = false;
                    List<TaskPack> taskPackList = response.body();
                    if (clearMap) {
                        taskAllMapList.clear();
                    }
                    if (taskPackList != null && taskPackList.size() > 0) {
                        for (TaskPack taskPack : taskPackList) {
                            taskAllMapList.put(taskPack.getDate(), taskPack.getUpperTaskList());
                        }
                        if (type.equals("Middle")) {
                            showMonthAllTask(calendarCurrent);
                        }
 
 
                    }
                    loadingOver(true);
                } else if (response.errorBody() != null) {
                    if (!requestAgain) {
                        requestAgain = true;
                        getThreeMonthTask(yearMonth, type, clearMap);
                    } else {
                        loadingOver(false);
                        Toast.makeText(application, "获取任务信息出错", Toast.LENGTH_SHORT).show();
                        showMonthAllTask(calendarCurrent);
                    }
                    System.out.println("ThreeMonthTask:" + response.errorBody());
                }
 
            }
 
            @Override
            public void onFailure(Call<List<TaskPack>> call, Throwable t) {
                if (!requestAgain) {
                    requestAgain = true;
                    getThreeMonthTask(yearMonth, type, clearMap);
                } else {
                    loadingOver(false);
                    Toast.makeText(application, "网络链接失败", Toast.LENGTH_SHORT).show();
                    showMonthAllTask(calendarCurrent);
                }
                System.out.println("ThreeMonthTask:" + t.toString());
            }
        });
    }
 
    //显示当前月的月任务列表(日历上的标注交给spinner操作)
    private void showMonthAllTask(java.util.Calendar calendarCurrent) {
        monthTaskListCurrent = new ArrayList<>();
        monthTaskStringListCurrent = new ArrayList<>();
        dayTaskTimeList = new ArrayList<>();
        subTaskMapCurrent = new HashMap<>();
        String currentMonth = DateFormatter.YearMonthFormat.format(calendarCurrent.getTime());
        List<TaskVo> taskVoList = taskAllMapList.get(currentMonth);
 
        if (taskVoList != null && taskVoList.size() > 0) {
            monthTaskStringListCurrent.add("全部任务");
            monthTaskListCurrent.addAll(taskVoList);
            for (TaskVo monthTask : taskVoList) {
//                monthTaskListCurrent.add(monthTask);
                monthTaskStringListCurrent.add(monthTask.getName());
            }
        } else {
            monthTaskStringListCurrent.add("无任务");
        }
        selectMonthTaskAdapter = new ArrayAdapter(getContext(), R.layout.item_spinner_drop_down, monthTaskStringListCurrent);
        sp_selectMonthTask.setAdapter(selectMonthTaskAdapter);
 
    }
 
    //显示当月日数据和历标注
    private void showOneMonthAllTask2(java.util.Calendar calendarCurrent) {
        String currentMonth = DateFormatter.YearMonthFormat.format(calendarCurrent.getTime());
        if (subTaskMapCurrent != null) {
            List<TaskVo> taskVoList = taskAllMapList.get(currentMonth);
 
            if (taskVoList != null && taskVoList.size() > 0) {
                for (TaskVo monthTask : taskVoList) {
                    getOneMonthTaskAllData(monthTask);
                }
            }
            addScheme(dayTaskTimeList);
        }
    }
 
    //显示一个月任务的数据和日历标注(Spinner选择一个月任务后的操作)
    private void showOneMonthTask(TaskVo monthTask) {
        getOneMonthTaskAllData(monthTask);
        addScheme(dayTaskTimeList);
    }
 
    //获取一个月任务的全部数据
    private void getOneMonthTaskAllData(TaskVo monthTask) {
        List<TaskVo> dayTaskList = monthTask.getDaytaskList();
        if (dayTaskList != null && dayTaskList.size() > 0) {
            for (TaskVo dayTask : dayTaskList) {
                java.util.Calendar calendar = java.util.Calendar.getInstance();
                calendar.setTime(dayTask.getStarttime());
                int day = calendar.get(java.util.Calendar.DAY_OF_MONTH);
                dayTaskTimeList.add(day);
 
                List<Subtask> subTaskList = dayTask.getSubtaskList();
                if (subTaskList != null && subTaskList.size() > 0) {
                    if (subTaskMapCurrent.containsKey(day)) {
                        subTaskMapCurrent.get(day).addAll(subTaskList);
                    } else {
                        List<Subtask> subtasks = new ArrayList<>();
                        subtasks.addAll(subTaskList);
                        subTaskMapCurrent.put(day, subtasks);
                    }
                }
            }
        } else {
 
        }
    }
 
    //跟据日期显示那天的子任务
    private void showSubTaskByDay(int day) {
        if (application.isDebugMode()) {
            subTaskListCurrent.removeAll(subTaskListCurrent);
            Subtask subtask = new Subtask();
            subtask.setStguid(UUIDGenerator.generate16ShortUUID());
            subtask.setName("巡查长风生态商务区10号北地块二期(北区)新建工程");
            int typeno = 1;
            subtask.setTypeno((byte) typeno);
            subtask.setType("巡查");
            subtask.setScenseid("Y0TdY7cjFHcVJCIf");
            subtask.setScensename("长风生态商务区10号北地块二期(北区)新建工程");
            subtask.setScenseaddress("同普路 泸定路");
            subtask.setProvincename("上海市");
            subtask.setCityname("上海市");
            subtask.setDistrictname("普陀区");
            java.util.Calendar startTime = java.util.Calendar.getInstance();
            startTime.set(2018, 1, 18);
            java.util.Calendar endTime = java.util.Calendar.getInstance();
            endTime.set(2018, 1, 18);
            subtask.setPlanstarttime(startTime.getTime());
            subtask.setPlanendtime(endTime.getTime());
            subtask.setExecutorguids("Kmi6GJoee93KzWfm");
            subtask.setExecutorusernames("chenchong");
            subtask.setExecutorrealtimes("陈冲");
            subtask.setStatus("未执行");
            subTaskListCurrent.add(subtask);
 
            subtask = new Subtask();
            subtask.setStguid(UUIDGenerator.generate16ShortUUID());
            subtask.setName("巡查金山亭林大型居住区市政道路项目林吉路(车亭公路-红梓路)");
            typeno = 1;
            subtask.setTypeno((byte) typeno);
            subtask.setType("巡查");
            subtask.setScenseid("XvQio9lWSMFguTob");
            subtask.setScensename("金山亭林大型居住区市政道路项目林吉路(车亭公路-红梓路)");
            subtask.setScenseaddress("亭林镇林吉路");
            subtask.setProvincename("上海市");
            subtask.setCityname("上海市");
            subtask.setDistrictname("金山区");
            startTime = java.util.Calendar.getInstance();
            startTime.set(2018, 1, 20, 10, 20);
            endTime = java.util.Calendar.getInstance();
            endTime.set(2018, 1, 20, 11, 30);
            subtask.setPlanstarttime(startTime.getTime());
            subtask.setPlanendtime(endTime.getTime());
            subtask.setExecutorguids("Kmi6GJoee93KzWfm");
            subtask.setExecutorusernames("chenchong");
            subtask.setExecutorrealtimes("陈冲");
            subtask.setStatus("正在执行");
            subTaskListCurrent.add(subtask);
 
            subtask = new Subtask();
            subtask.setStguid(UUIDGenerator.generate16ShortUUID());
            subtask.setName("巡查静安区大宁路街道325街坊地块住宅项目");
            typeno = 1;
            subtask.setTypeno((byte) typeno);
            subtask.setType("巡查");
            subtask.setScenseid("ZjTy9pdMPUmAgltG");
            subtask.setScensename("静安区大宁路街道325街坊地块住宅项目");
            subtask.setScenseaddress("彭江路,平型关路交叉口");
            subtask.setProvincename("上海市");
            subtask.setCityname("上海市");
            subtask.setDistrictname("静安区");
            startTime = java.util.Calendar.getInstance();
            startTime.set(2018, 1, 23, 15, 10);
            endTime = java.util.Calendar.getInstance();
            endTime.set(2018, 1, 23, 16, 30);
            subtask.setPlanstarttime(startTime.getTime());
            subtask.setPlanendtime(endTime.getTime());
            subtask.setExecutorguids("Kmi6GJoee93KzWfm");
            subtask.setExecutorusernames("chenchong");
            subtask.setExecutorrealtimes("陈冲");
            subtask.setStatus("已结束");
            subTaskListCurrent.add(subtask);
        } else {
            if (subTaskMapCurrent != null) {
                List<Subtask> subTaskList = subTaskMapCurrent.get(day);
                subTaskListCurrent.clear();
                if (subTaskList != null && subTaskList.size() > 0) {
                    for (Subtask subtask : subTaskList) {
                        if (!subTaskListCurrent.contains(subtask)) {
                            subTaskListCurrent.add(subtask);
                        }
                    }
 
                }
                if (subTaskListCurrent.size() > 0) {
                    if (rl_content.getVisibility() != View.VISIBLE) {
                        fab_map.show();
                    }
                } else {
                    fab_map.hide();
                }
            }
 
        }
 
        subTaskListAdapter.notifyDataSetChanged();
    }
 
    //设置spinner的点击事件
    private void initSpinnerData() {
        sp_selectMonthTask.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                //将选中的文字变为白色
                CheckedTextView tv = (CheckedTextView) view.findViewById(view.getId());
                tv.setTextColor(getContext().getResources().getColor(R.color.white));
                //选择后清空数据重新读取
                dayTaskTimeList = new ArrayList<Integer>();
                subTaskMapCurrent = new HashMap<Integer, List<Subtask>>();
                if (position == 0) {
                    showOneMonthAllTask2(calendarCurrent);
                    showSubTaskByDay(calendarCurrent.get(java.util.Calendar.DAY_OF_MONTH));
                } else {
                    monthTaskSelected = monthTaskListCurrent.get(position - 1);
                    showOneMonthTask(monthTaskSelected);
                    showSubTaskByDay(calendarCurrent.get(java.util.Calendar.DAY_OF_MONTH));
                }
 
            }
 
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
 
            }
        });
 
    }
 
    //初始化子任务列表
    private void initRecyclerView() {
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        rv_subTaskList.setLayoutManager(manager);
 
        subTaskListAdapter = new TaskListAdapter(getContext(), subTaskListCurrent);
        subTaskListAdapter.setOnDeleteListener(new OnDeleteListener() {
            @Override
            public void delete(final int position) {
                Call<ResponseBody> deleteSubTask = subTaskService.deleteSubTask(subTaskListCurrent.get(position).getStguid());
                deleteSubTask.enqueue(new Callback<ResponseBody>() {
                    @Override
                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                        if (response.body() != null) {
                            subTaskListAdapter.notifyItemRemoved(position);
                            subTaskListAdapter.notifyItemRangeChanged(position, subTaskListCurrent.size() - position);
                            subTaskListCurrent.remove(position);
                            showToast("删除成功");
                            String yearMonth = DateFormatter.YearMonthFormat.format(new Date());
                            getThreeMonthTask(yearMonth, "Middle", false);
                        } else {
                            showToast("删除失败");
                        }
                    }
 
                    @Override
                    public void onFailure(Call<ResponseBody> call, Throwable t) {
 
                    }
                });
            }
        });
 
        subTaskListAdapter.setOnItemClickListener(new OnSwipeItemClickListener() {
 
            @Override
            public void click(int position) {
                subTaskSelected = subTaskListCurrent.get(position);
                loadInspectionData(subTaskSelected.getStguid());
            }
        });
        rv_subTaskList.setAdapter(subTaskListAdapter);
        //2019.1.23 by riku 添加滑动删除功能
        if (application.getCurrentUser().getUsertypeid() == 0) {
            PlusItemSlideCallback callback = new PlusItemSlideCallback(WItemTouchHelperPlus.SLIDE_ITEM_TYPE_ITEMVIEW);
            extension = new WItemTouchHelperPlus(callback);
            extension.attachToRecyclerView(rv_subTaskList);
        }
    }
 
    //初始化功能面版viewpager
    private void initIconViewPager() {
        ll_show.setVisibility(View.INVISIBLE);
        View iconPage1 = View.inflate(getContext(), R.layout.page_patrol_icons_first, null);
        View iconPage2 = View.inflate(getContext(), R.layout.page_patrol_icons_second, null);
        ll_problemRecheck = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_problem_recheck);
        ll_takeEvidence = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_take_evidence);
        ll_problemList = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_problem_list);
        ll_problemChange = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_change);
        ll_camera = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_camera);
        ll_newGit = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_newgit);
        ll_promise = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_promiss);
        ll_evaluation = (LinearLayout) iconPage1.findViewById(R.id.ln_patrol_rate);
        ll_navi = (LinearLayout) iconPage2.findViewById(R.id.ln_patrol_navi);
        ll_choseLatlng = (LinearLayout) iconPage2.findViewById(R.id.ln_patrol_chose_latlng);
        ll_editeScence = (LinearLayout) iconPage2.findViewById(R.id.ln_patrol_edit);
        List<View> viewList = new ArrayList<>();
        viewList.add(iconPage1);
        viewList.add(iconPage2);
 
        IconsPageAdapter adapter = new IconsPageAdapter(viewList);
        vp_icons.setAdapter(adapter);
        vp_icons.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
 
            }
 
            @Override
            public void onPageSelected(int position) {
                //当页面改变时,切换到对应的小圆点
                if (position == 0) {
                    iv_pointer.setImageResource(R.drawable.select_first_point);
                } else if (position == 1) {
                    iv_pointer.setImageResource(R.drawable.select_second_point);
                }
            }
 
            @Override
            public void onPageScrollStateChanged(int state) {
 
            }
        });
 
    }
 
    //根据日期列表添加全部标记点
    private void addScheme(List<Integer> dayTaskTimeList) {
        schemes = new HashMap<>();
        if (dayTaskTimeList != null && dayTaskTimeList.size() > 0) {
            for (Integer day : dayTaskTimeList) {
                Calendar c = getSchemeCalendar(calendarCurrent.get(java.util.Calendar.YEAR), (calendarCurrent.get(java.util.Calendar.MONTH) + 1), day, 0xFFdf1356, false);
                schemes.put(c.toString(), c);
            }
        }
        mCalendarView.setSchemeDate(schemes);
    }
 
 
    //添加标记点
    private Calendar getSchemeCalendar(int year, int month, int day, int color, boolean schemeCompleted) {
        Calendar calendar = new Calendar();
        calendar.setYear(year);
        calendar.setMonth(month);
        calendar.setDay(day);
        calendar.setSchemeColor(color);//如果单独标记颜色、则会使用这个颜色
        calendar.setScheme("记");
        return calendar;
    }
 
    //初始化地图
    private void initMap(Bundle savedInstanceState) {
        mv_main.onCreate(savedInstanceState);
        aMap = mv_main.getMap();
        aMap.setRenderFps(60);
        aMap.getUiSettings().setZoomControlsEnabled(false);
        aMap.getUiSettings().setScaleControlsEnabled(true);
        //点击marker跳转到问题详情
        aMap.setOnMarkerClickListener(new AMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                String guid = marker.getSnippet();
                if (guid != null && guid.length() > 0) {
                    Intent intent = new Intent(getActivity(), ProblemDetailActivity.class);
                    ProblemlistVo problemlistVo = null;
                    for (int i = 0; i < problemListVoListCurrent.size(); i++) {
                        if (problemListVoListCurrent.get(i).getGuid().equals(guid)) {
                            problemlistVo = problemListVoListCurrent.get(i);
                        }
                    }
                    intent.putExtra("problemlistVo", problemlistVo);
                    intent.putExtra("subTaskSelected", subTaskSelected);
                    intent.putExtra("scenseLat", scenseCurrent.getLatitude());
                    intent.putExtra("scenseLng", scenseCurrent.getLongitude());
                    intent.putExtra("editable", problemEditable);
                    intent.putExtra("type", PROBLEM_LIST);
                    startActivity(intent);
                }
                return false;
            }
        });
 
    }
 
    //联网加载巡查信息
    private void loadInspectionData(final String subTaskId) {
        showLoadingDialog();
        if (inspectionService == null)
            inspectionService = application.getRetrofit().create(InspectionService.class);
        Call<InspectionVo> loadallInspectionData = inspectionService.loadInspectionData(subTaskId);
        loadallInspectionData.enqueue(new Callback<InspectionVo>() {
            @Override
            public void onResponse(Call<InspectionVo> call, Response<InspectionVo> response) {
                if (response.body() != null) {
                    inspectionVoCurrent = response.body();
                    inspectionCurrent = transInspectionVo(inspectionVoCurrent);
                    initInspectionData();
 
                    fab_map.hide();
                    showIcons();
                    rl_content.setVisibility(View.VISIBLE);
                    rl_selectTask.setVisibility(View.INVISIBLE);
                    loadingOver(true);
                } else if (response.errorBody() != null) {
                    if (!requestAgain) {
                        requestAgain = true;
                        loadInspectionData(subTaskId);
                    } else {
                        loadingOver(false);
                        Toast.makeText(application, "获取巡查信息失败", Toast.LENGTH_SHORT).show();
                        System.out.println("loadInspectionData:" + response.errorBody().toString());
                    }
                }
            }
 
            @Override
            public void onFailure(Call<InspectionVo> call, Throwable t) {
                if (!requestAgain) {
                    requestAgain = true;
                    loadInspectionData(subTaskId);
                } else {
                    loadingOver(false);
                    Toast.makeText(application, "联网失败", Toast.LENGTH_SHORT).show();
                    System.out.println("loadInspectionData:" + t.toString());
                }
            }
        });
    }
 
    private Inspection transInspectionVo(InspectionVo inspectionVo) {
        Inspection inspection = new Inspection();
        inspection.setGuid(inspectionVo.getGuid());
        inspection.setStguid(inspectionVo.getStguid());
        inspection.setSguid(inspectionVo.getSguid());
        inspection.setScensename(inspectionVo.getScensename());
        inspection.setScenseaddress(inspectionVo.getScenseaddress());
        inspection.setIstogether(inspectionVo.getIstogether());
        inspection.setEntouraget(inspectionVo.getEntouraget());
        inspection.setEntouragewx(inspectionVo.getEntouragewx());
        inspection.setEntourage(inspectionVo.getEntourage());
        inspection.setExecutionstarttime(inspectionVo.getExecutionstarttime());
        inspection.setExecutionendtime(inspectionVo.getExecutionendtime());
        inspection.setProblemcount(inspectionVo.getProblemcount());
        inspection.setIsrechecked(inspectionVo.getIsrechecked());
        inspection.setRecheckcount(inspectionVo.getRecheckcount());
        inspection.setPromissednum(inspectionVo.getPromissednum());
        inspection.setChangednum(inspectionVo.getChangednum());
        inspection.setChangednum(inspectionVo.getChangednum());
        inspection.setIschanged(inspectionVo.getIschanged());
        inspection.setIsrvaluated(inspectionVo.getIsrvaluated());
        inspection.setIspromissed(inspectionVo.getIspromissed());
        inspection.setPromissedtime(inspectionVo.getPromissedtime());
        inspection.setPromisseduserguid(inspectionVo.getPromisseduserguid());
        inspection.setPromissedusername(inspectionVo.getPromissedusername());
        inspection.setPromisseduserrealname(inspectionVo.getPromisseduserrealname());
        inspection.setPromissedway(inspectionVo.getPromissedway());
        inspection.setPromisseddeadline(inspectionVo.getPromisseddeadline());
        inspection.setPromissbookpath(inspectionVo.getPromissbookpath());
        inspection.setSignpath(inspectionVo.getSignpath());
        inspection.setExtension1(inspectionVo.getExtension1());
        inspection.setExtension2(inspectionVo.getExtension2());
        inspection.setExtension3(inspectionVo.getExtension3());
        inspection.setRemark(inspectionVo.getRemark());
        return inspection;
    }
 
    //初始化巡查的基本信息
    private void initInspectionData() {
        if (application.isDebugMode()) {
            inspectionCurrent = new Inspection();
            inspectionCurrent.setGuid(UUIDGenerator.generate16ShortUUID());
            inspectionCurrent.setStguid(subTaskSelected.getStguid());
            inspectionCurrent.setSguid(subTaskSelected.getScenseid());
            inspectionCurrent.setScensename(subTaskSelected.getScensename());
            inspectionCurrent.setScenseaddress(subTaskSelected.getScenseaddress());
            inspectionCurrent.setProblemcount(0);
            inspectionCurrent.setChangednum(0);
        }
        tv_subTaskNameBar.setText(subTaskSelected.getName());
        currentPage = INSPECTION_PAGE;
        aMap.clear();
        subTaskStatusCurrent = subTaskSelected.getStatus();
        switch (subTaskStatusCurrent) {
            case subTaskNotStart:
                iv_startEndTask.setSelected(false);
                break;
            case subTaskRunning:
                iv_startEndTask.setSelected(true);
                break;
            case subTaskEnd:
                iv_startEndTask.setSelected(true);
        }
        updateStatus();
        //2019.1.4 by riku: 添加 用户类型为“主管部门”或“管理员”,编号为2或0时,按钮iv_startEndTask没有点击事件
        if (application.getCurrentUser().getUsertypeid() != 2 || application.getCurrentUser().getUsertypeid() != 0) {
            iv_startEndTask.setOnClickListener(this);
        } else {
            iv_startEndTask.setAlpha(0.5f);
        }
        scenseCurrent = scenseDao.queryBuilder().where(ScenseDao.Properties.Guid.eq(subTaskSelected.getScenseid())).unique();
        scenseType = scenseCurrent.getType();
        switch (scenseType) {
            case site:
                siteCurrent = siteDao.queryBuilder().where(SiteDao.Properties.Sguid.eq(subTaskSelected.getScenseid())).unique();
                break;
        }
        tv_detailTaskName.setText(subTaskSelected.getName());
        tv_detailTaskType.setText(subTaskSelected.getType());
        java.util.Calendar planStartTime = java.util.Calendar.getInstance();
        planStartTime.setTime(subTaskSelected.getPlanstarttime());
        java.util.Calendar planEndTime = java.util.Calendar.getInstance();
        planEndTime.setTime(subTaskSelected.getPlanendtime());
        if (planStartTime.get(java.util.Calendar.YEAR) == planEndTime.get(java.util.Calendar.YEAR) &&
                planStartTime.get(java.util.Calendar.MONTH) == planEndTime.get(java.util.Calendar.MONTH) &&
                planStartTime.get(java.util.Calendar.DAY_OF_MONTH) == planEndTime.get(java.util.Calendar.DAY_OF_MONTH)) {
            String text = DateFormatter.dateFormat.format(planStartTime.getTime());
            String startTime = DateFormatter.timeFormat.format(planStartTime.getTime());
            if (startTime.equals("00:00")) {
                tv_detailPlanTime.setText(text);
            } else {
                String endTime = DateFormatter.timeFormat.format(planEndTime.getTime());
                tv_detailPlanTime.setText(text + " " + startTime + " - " + endTime);
            }
        } else {
            String startTime = DateFormatter.dateTimeFormat.format(planStartTime.getTime());
            String endTime = DateFormatter.dateTimeFormat.format(planEndTime.getTime());
            tv_detailPlanTime.setText(startTime + " - " + endTime);
        }
        refreshExecutionTime();
        tv_detailExecutors.setText(subTaskSelected.getExecutorrealtimes().replaceAll(Constant.CONNECTOR, Constant.CONNECTOR_FOR_VIEW));
        tv_detailScenseName.setText(scenseCurrent.getName());
        tv_detailScenseType.setText(scenseCurrent.getType());
        tv_detailScenseAddress.setText(scenseCurrent.getCityname() + scenseCurrent.getDistrictname() + " " + scenseCurrent.getLocation());
        tv_detailContact1.setText(scenseCurrent.getContacts() + "  " + scenseCurrent.getContactst());
        tv_detailContact2.setText("");
        tv_callContact1.setOnClickListener(callClikeListner(scenseCurrent.getContactst()));
        refreshProblemMarker();
        //将场景位置添加到地图上
        LatLng sourceLatLng = new LatLng(scenseCurrent.getLatitude(), scenseCurrent.getLongitude());
        MarkerOptions options = new MarkerOptions().position(sourceLatLng);
        aMap.addMarker(options);
        aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sourceLatLng, 15f));
 
    }
 
    private void refreshExecutionTime() {
        String executeTime = "";
        if (subTaskSelected.getExecutionstarttime() != null) {
            executeTime = DateFormatter.dateTimeFormat.format(subTaskSelected.getExecutionstarttime());
        } else {
            executeTime = "未执行";
        }
        if (subTaskSelected.getExecutionendtime() != null) {
            executeTime = executeTime + " - " + DateFormatter.timeFormat.format(subTaskSelected.getExecutionendtime());
        }
        tv_detailExecuteTime.setText(executeTime);
    }
 
    //更新状态信息
    private void updateStatus() {
        tv_subTaskStatusBar.setText(subTaskStatusCurrent);
        setIconsStatus(subTaskStatusCurrent);
    }
 
    //初始化位置
    public void initLocation() {
        MyLocationStyle myLocationStyle;
        myLocationStyle = new MyLocationStyle();//初始化定位蓝点样式类myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。(1秒1次定位)如果不设置myLocationType,默认也会执行此种模式。
        //   myLocationStyle.interval(2000); //设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。
        myLocationStyle.showMyLocation(true);
        myLocationStyle.radiusFillColor(getResources().getColor(R.color.transparent));
        myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER);//连续定位、蓝点不会移动到地图中心点,定位点依照设备方向旋转,并且蓝点会跟随设备移动
        aMap.setMyLocationStyle(myLocationStyle);//设置定位蓝点的Style
        aMap.getUiSettings().setMyLocationButtonEnabled(false);//设置默认定位按钮是否显示,非必需设置。
        aMap.setMyLocationEnabled(true);// 设置为true表示启动显示定位蓝点,false表示隐藏定位蓝点并不进行定位,默认是false。
        aMap.setOnMyLocationChangeListener(this);
    }
 
    //根据任务状态,设置图标面板功能开关
    public void setIconsStatus(String subTaskStatus) {
        switch (subTaskStatus) {
            case subTaskNotStart:
                ll_problemRecheck.setAlpha(banAlpha);
                ll_problemRecheck.setOnClickListener(showNeedStartTaskListener());
                ll_takeEvidence.setAlpha(banAlpha);
                ll_takeEvidence.setOnClickListener(showNeedStartTaskListener());
                ll_problemList.setAlpha(banAlpha);
                ll_problemList.setOnClickListener(showNeedStartTaskListener());
                ll_problemChange.setAlpha(banAlpha);
                ll_problemChange.setOnClickListener(showNeedStartTaskListener());
                ll_camera.setAlpha(banAlpha);
                ll_camera.setOnClickListener(showNeedStartTaskListener());
                ll_newGit.setAlpha(banAlpha);
                ll_newGit.setOnClickListener(showNeedStartTaskListener());
                ll_promise.setAlpha(banAlpha);
                ll_promise.setOnClickListener(showNeedStartTaskListener());
                ll_evaluation.setAlpha(banAlpha);
                ll_evaluation.setOnClickListener(showNeedStartTaskListener());
                ll_navi.setOnClickListener(this);
                ll_choseLatlng.setOnClickListener(this);
                ll_editeScence.setOnClickListener(this);
                break;
            case subTaskRunning:
                ll_problemRecheck.setAlpha(1);
                ll_problemRecheck.setOnClickListener(this);
                ll_takeEvidence.setAlpha(1);
                ll_takeEvidence.setOnClickListener(this);
                ll_problemList.setAlpha(1);
                ll_problemList.setOnClickListener(this);
                ll_problemChange.setAlpha(1);
                ll_problemChange.setOnClickListener(this);
                ll_camera.setAlpha(1);
                ll_camera.setOnClickListener(this);
                ll_newGit.setAlpha(1);
                ll_newGit.setOnClickListener(this);
                ll_promise.setAlpha(1);
                ll_promise.setOnClickListener(this);
                ll_evaluation.setAlpha(1);
                ll_evaluation.setOnClickListener(this);
                ll_navi.setOnClickListener(this);
                ll_choseLatlng.setOnClickListener(this);
                ll_editeScence.setOnClickListener(this);
                break;
            case subTaskEnd:
                ll_problemRecheck.setAlpha(1);
                ll_problemRecheck.setOnClickListener(this);
                ll_takeEvidence.setAlpha(banAlpha);
                ll_takeEvidence.setOnClickListener(null);
                ll_problemList.setAlpha(1);
                ll_problemList.setOnClickListener(this);
                ll_problemChange.setAlpha(1);
                ll_problemChange.setOnClickListener(this);
                ll_camera.setAlpha(1);
                ll_camera.setOnClickListener(this);
                ll_newGit.setAlpha(1);
                ll_newGit.setOnClickListener(this);
                ll_promise.setAlpha(1);
                ll_promise.setOnClickListener(this);
                ll_evaluation.setAlpha(1);
                ll_evaluation.setOnClickListener(this);
                ll_navi.setOnClickListener(this);
                ll_choseLatlng.setOnClickListener(this);
                ll_editeScence.setOnClickListener(this);
                break;
        }
        if (application.getCurrentUser().getUsertypeid() == 2) {
            ll_takeEvidence.setAlpha(banAlpha);
            ll_takeEvidence.setOnClickListener(null);
            ll_problemChange.setAlpha(banAlpha);
            ll_problemChange.setOnClickListener(null);
            ll_camera.setAlpha(banAlpha);
            ll_camera.setOnClickListener(null);
            ll_evaluation.setAlpha(banAlpha);
            ll_evaluation.setOnClickListener(null);
            ll_navi.setAlpha(banAlpha);
            ll_navi.setOnClickListener(null);
            ll_choseLatlng.setAlpha(banAlpha);
            ll_choseLatlng.setOnClickListener(null);
            ll_editeScence.setAlpha(banAlpha);
            ll_editeScence.setOnClickListener(null);
        }
    }
 
    //显示请开始任务的OnClickListener
    public View.OnClickListener showNeedStartTaskListener() {
        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
                if (application.getCurrentUser().getUsertypeid() == 2) {
                    dialog.setTitle("任务还未开始");
                    dialog.setMessage("无可查看的详细信息");
                } else {
                    dialog.setTitle("请先开始任务");
                    dialog.setMessage("点击界面右上角的'开始'按钮,来开始任务");
                }
                dialog.setPositiveButton("确定", null);
                dialog.show();
            }
        };
 
        return listener;
    }
 
    //向下收缩图标面板
    public void hideIcons() {
        ll_icons.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.bottom_menu_exit));
        ll_icons.setVisibility(View.GONE);
        ll_show.setVisibility(View.VISIBLE);
    }
 
    //向上显示图标面板
    public void showIcons() {
        ll_icons.setVisibility(View.VISIBLE);
        ll_icons.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.bottom_menu_enter));
        ll_show.setVisibility(View.GONE);
    }
 
    //向上收缩任务详情
    private void hideTaskDetail() {
        ll_taskDetail.setVisibility(View.VISIBLE);
        ll_taskDetail.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.top_menu_exit));
        ll_taskDetail.setVisibility(View.GONE);
 
    }
 
    //向下显示任务详情
    private void showTaskDetail() {
        refreshExecutionTime();
        ll_taskDetail.setVisibility(View.VISIBLE);
        ll_taskDetail.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.top_menu_enter));
    }
 
    //显示开始任务对话框
    private void showStartTaskDialog() {
        AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
        dialog.setTitle("要开始任务吗?");
        dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                subTaskStatusCurrent = subTaskRunning;
                updateStatus();
                subTaskSelected.setStatus(subTaskRunning);
                subTaskSelected.setExecutionstarttime(new Date());
                inspectionCurrent.setExecutionstarttime(new Date());
                updateSubtask(subTaskSelected);
                updateInspection(inspectionCurrent);
                iv_startEndTask.setSelected(true);
            }
        });
        dialog.setNegativeButton("取消", null);
        dialog.show();
    }
 
    //显示结束任务对话框
    private void showEndTaskDialog() {
        AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
        dialog.setTitle("要结束任务吗?");
        dialog.setMessage("结束任务后问题取证功能将不可用");
        dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                subTaskStatusCurrent = subTaskEnd;
                updateStatus();
                subTaskSelected.setStatus(subTaskEnd);
                subTaskSelected.setExecutionendtime(new Date());
                inspectionCurrent.setExecutionendtime(new Date());
                updateSubtask(subTaskSelected);
                updateInspection(inspectionCurrent);
            }
        });
        dialog.setNegativeButton("取消", null);
        dialog.show();
    }
 
    //提交subtask信息
    private void updateSubtask(Subtask subtask) {
        Call<String> updateSubtask = inspectionService.updateSubTask(subtask);
        updateSubtask.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                if (response.body() != null) {
                    System.out.println("SubTask:" + response.body().toString());
//                    showToast("提交subtask成功");
                } else if (response.errorBody() != null) {
                    System.out.println("SubTask:" + response.errorBody().toString());
                    showToast("提交subtask失败");
                }
            }
 
            @Override
            public void onFailure(Call<String> call, Throwable t) {
                System.out.println("SubTask:" + t.toString());
                showToast("联网失败");
            }
        });
 
 
    }
 
    //提交inspection信息
    private void updateInspection(Inspection inspection) {
        Call<ResponseBody> updateInspection = inspectionService.updateInspection(inspection);
        updateInspection.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                if (response.body() != null) {
                    System.out.println("inspection:" + response.body().toString());
//                    showToast("提交inspection成功");
                } else if (response.errorBody() != null) {
                    System.out.println("inspection:" + response.errorBody().toString());
                    showToast("提交inspection失败");
                }
            }
 
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                System.out.println("inspection:" + t.toString());
                showToast("联网失败");
            }
        });
    }
 
    //刷新problem位置marker
    private void refreshProblemMarker() {
 
 
        Call<List<ProblemlistVo>> loadProblemList = inspectionService.loadProblemList(inspectionCurrent.getGuid());
        loadProblemList.enqueue(new Callback<List<ProblemlistVo>>() {
            @Override
            public void onResponse(Call<List<ProblemlistVo>> call, Response<List<ProblemlistVo>> response) {
                if (response.body() != null) {
                    List<ProblemlistVo> problemlistVoList = response.body();
                    if (problemlistVoList != null) {
                        addProblemMarkers(problemlistVoList);
                    }
                } else if (response.errorBody() != null) {
                    showToast("获取问题marker失败");
                    System.out.println("loadProblemList:" + response.errorBody().toString());
                }
            }
 
            @Override
            public void onFailure(Call<List<ProblemlistVo>> call, Throwable t) {
                showToast("联网失败");
                System.out.println("loadProblemList:" + t.toString());
            }
        });
 
    }
 
    //往地图上添加问题位置marker
    private void addProblemMarkers(List<ProblemlistVo> problemlistVoList) {
        problemListVoListCurrent = problemlistVoList;
        aMap.clear();
        for (int i = 0; i < problemlistVoList.size(); i++) {
            ProblemlistVo problemlistVo = problemlistVoList.get(i);
            //添加marker到地图上
            LatLng latLngNow = new LatLng(problemlistVo.getLatitude(), problemlistVo.getLongitude());
            MarkerOptions options = new MarkerOptions();
            //将marker放大
            Bitmap bm = BitmapFactory.decodeResource(getResources(), problemNowMarkerList.get(i));
            Matrix matrix = new Matrix();
            matrix.setScale(0.7f, 0.7f);
            Bitmap bmBig = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
                    bm.getHeight(), matrix, true);
            options.icon(BitmapDescriptorFactory.fromBitmap(bmBig));
 
            options.position(latLngNow);
            options.snippet(problemlistVo.getGuid());
            Marker marker = aMap.addMarker(options);
            marker.setInfoWindowEnable(false);
        }
        //将场景位置添加到地图上
        LatLng sourceLatLng = new LatLng(scenseCurrent.getLatitude(), scenseCurrent.getLongitude());
        MarkerOptions options = new MarkerOptions().position(sourceLatLng);
        aMap.addMarker(options);
    }
 
    //显示问题取证的dialog
    private void showTaskEvidenceDialog() {
        final Dialog dialog = new Dialog(getContext());
        dialog.setContentView(R.layout.dialog_take_evidence);
        //设置dialog宽度
        Window dialogWindow = dialog.getWindow();
        dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
        final WindowManager.LayoutParams p = dialogWindow.getAttributes();
        p.width = (int) (ScreenUtils.getScreenWidth(getContext()) * 1);
        dialog.setCancelable(false);
        //初始化控件
        final FloatingActionButton fab_ok = (FloatingActionButton) dialog.findViewById(R.id.fab_take_evidence_ok);
        FloatingActionButton fab_Close = (FloatingActionButton) dialog.findViewById(R.id.fab_take_evidence_close);
        miv_add_photo1 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo1);
        miv_add_photo2 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo2);
        miv_add_photo3 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo3);
        final Spinner sp_problemType = (Spinner) dialog.findViewById(R.id.sp_take_evidence_select_problem_type);
        final Spinner sp_problem = (Spinner) dialog.findViewById(R.id.sp_take_evidence_select_problem);
        final Spinner sp_location = (Spinner) dialog.findViewById(R.id.sp_take_evidence_select_location);
        final EditText et_locationRemark = (EditText) dialog.findViewById(R.id.et_take_evidence_location);
        final TextView tv_location = (TextView) dialog.findViewById(R.id.tv_location);
        final EditText et_problemDes = (EditText) dialog.findViewById(R.id.et_take_evidence_problem_des);
 
        //初始化变量
        pathTempList = new ArrayList<>();
        //2019.3.8 by riku 新增添加整改建议
        LinearLayout ll_change_suggestion = dialog.findViewById(R.id.ll_change_suggestion);
        final Spinner sp_change_suggestion = dialog.findViewById(R.id.sp_take_evidence_select_suggestion);
        final EditText et_change_suggestion = dialog.findViewById(R.id.et_take_evidence_suggestion);
        final ArrayList<String> suggestionList = new ArrayList<>();
        final ArrayAdapter suggestionAdapter = new ArrayAdapter(getContext(), R.layout.item_spinner_drop_down, suggestionList);
 
        //加载位置信息
        List<Domainitem> locationList = domainitemDao.queryBuilder().where(DomainitemDao.Properties.Catelogname.eq("工地位置结果集")).orderAsc(DomainitemDao.Properties.Value).list();
        if (locationList != null && locationList.size() > 0) {
            DomainItemListAdapter domainItemListAdapter = new DomainItemListAdapter(locationList, getContext());
            sp_location.setAdapter(domainItemListAdapter);
        }
 
        //加载问题数据
        List<Problemtype> problemtypeList = problemtypeDao.queryBuilder()
                .where(ProblemtypeDao.Properties.Tasktypeid.eq(subTaskSelected.getTypeno()))
                .where(ProblemtypeDao.Properties.Citycode.eq(subTaskSelected.getCitycode()))
                .where(ProblemtypeDao.Properties.Districtcode.eq(subTaskSelected.getDistrictcode()))
                .where(ProblemtypeDao.Properties.Scensetypeid.eq(scenseCurrent.getTypeid()))
                .orderAsc(ProblemtypeDao.Properties.Typeid).list();
 
        if (problemtypeList.size() == 0) {
            Problemtype problemtype = new Problemtype();
            problemtype.setGuid("0");
            problemtype.setTypename("无");
            problemtype.setName("无");
            problemtypeList.add(problemtype);
        }
 
        final List<String> problemTypeStringList = new ArrayList<>();
        final Map<String, List<Problemtype>> problemTypeMap = new HashMap<>();
        for (Problemtype problemtype : problemtypeList) {
            if (problemTypeMap.containsKey(problemtype.getTypename())) {
                problemTypeMap.get(problemtype.getTypename()).add(problemtype);
            } else {
                problemTypeStringList.add(problemtype.getTypename());
                List<Problemtype> problemtypeList1 = new ArrayList<>();
                problemtypeList1.add(problemtype);
                problemTypeMap.put(problemtype.getTypename(), problemtypeList1);
            }
        }
        ArrayAdapter problemTypeAdapter = new ArrayAdapter(getContext(), R.layout.item_spinner_drop_down, problemTypeStringList);
        sp_problemType.setAdapter(problemTypeAdapter);
        final List<Problemtype> problemtypes = new ArrayList<>();
        final ProblemTypeListAdapter problemTypeListAdapter = new ProblemTypeListAdapter(problemtypes, getContext());
        sp_problem.setAdapter(problemTypeListAdapter);
        sp_problemType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                //当选中一个分类时,从map加载问题列表,填充数据
                problemtypes.removeAll(problemtypes);
                problemtypes.addAll(problemTypeMap.get(problemTypeStringList.get(i)));
                problemTypeListAdapter.notifyDataSetChanged();
                if (problemTypeStringList.get(i).equals("态度")) {
                    sp_location.setVisibility(View.GONE);
                    et_locationRemark.setVisibility(View.GONE);
                    miv_add_photo1.setVisibility(View.GONE);
                    miv_add_photo2.setVisibility(View.GONE);
                    miv_add_photo3.setVisibility(View.GONE);
                    tv_location.setVisibility(View.GONE);
                } else {
                    sp_location.setVisibility(View.VISIBLE);
                    et_locationRemark.setVisibility(View.VISIBLE);
                    miv_add_photo1.setVisibility(View.VISIBLE);
                    miv_add_photo2.setVisibility(View.VISIBLE);
                    miv_add_photo3.setVisibility(View.VISIBLE);
                    tv_location.setVisibility(View.VISIBLE);
                }
 
                sp_problem.setSelection(0);
                //刷新对应问题的整改建议
                refreshSuggestion(problemtypes.get(0).getGuid(), suggestionList, suggestionAdapter);
            }
 
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
            }
        });
 
        ll_change_suggestion.setVisibility(View.VISIBLE);
        sp_change_suggestion.setAdapter(suggestionAdapter);
 
        sp_problem.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                //当选中一个具体问题时,应该显示对应的整改建议
                refreshSuggestion(problemtypes.get(position).getGuid(), suggestionList, suggestionAdapter);
            }
 
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
 
            }
        });
 
 
        //设置确定按钮的点击事件
        fab_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                fab_ok.setClickable(false);
                if (subTaskSelected != null && inspectionCurrent != null && scenseCurrent != null) {
                    String problemType = sp_problemType.getSelectedItem().toString();
 
                    Problemlist problemlist = new Problemlist();
                    problemlist.setGuid(UUIDGenerator.generate16ShortUUID());
                    problemlist.setIguid(inspectionCurrent.getGuid());
                    problemlist.setStguid(subTaskSelected.getStguid());
                    problemlist.setSguid(scenseCurrent.getGuid());
                    problemlist.setSensename(scenseCurrent.getName());
                    problemlist.setSenseaddress(getScenceAddress());
                    Problemtype problemtypeSelected = (Problemtype) sp_problem.getSelectedItem();
                    problemlist.setPtguid(problemtypeSelected.getGuid());
                    String problemDes = "";
                    if (et_problemDes.getText().length() > 0) {
                        problemDes = "(" + et_problemDes.getText().toString() + ")";
                    }
                    problemlist.setProblemname(problemtypeSelected.getName() + problemDes);
 
                    String adviceDes = "";
                    if (et_change_suggestion.getText().length() > 0) {
                        adviceDes = "(" + et_change_suggestion.getText().toString() + ")";
                    }
                    problemlist.setAdvise(sp_change_suggestion.getSelectedItem().toString() + adviceDes);
                    problemlist.setLatitude(latitudeCurrent);
                    problemlist.setLongitude(longitudeCurrent);
                    Domainitem locationSelected = (Domainitem) sp_location.getSelectedItem();
                    if (!problemType.equals("态度")) {
                        problemlist.setLocationid(intToByte(locationSelected.getIndex()));
                        String locationRemark = et_locationRemark.getText().toString();
                        if (locationRemark.length() > 0) {
                            locationRemark = "(" + locationRemark + ")";
                        }
                        problemlist.setLocation(locationSelected.getText() + locationRemark);
 
                    } else {
                        problemlist.setLocation("无位置");
                    }
                    problemlist.setTime(new Date());
                    problemlist.setIsrechecked(false);
                    problemlist.setIschanged(false);
 
                    if (!problemType.equals("态度") && pathTempList.size() > 0) {
                        //保存照片到对应文件夹
                        List<File> savePathList = new ArrayList<File>();
                        java.util.Calendar calendar = java.util.Calendar.getInstance();
                        calendar.setTime(subTaskSelected.getExecutionstarttime());
                        String path = "FlightFeather/Photo/" + scenseCurrent.getDistrictname() + "/" + calendar.get(java.util.Calendar.YEAR) + "年" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月/" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月" + calendar.get(java.util.Calendar.DAY_OF_MONTH) + "日/" + scenseCurrent.getName() + "/";
                        String fileName1 = problemlist.getProblemname() + " " + problemlist.getLocation() + " " + UUIDGenerator.generateUUID(4) + ".jpg";
                        String fileName2 = problemlist.getProblemname() + " " + problemlist.getLocation() + "  " + UUIDGenerator.generateUUID(4) + ".jpg";
                        String fileName3 = problemlist.getProblemname() + " " + problemlist.getLocation() + " " + UUIDGenerator.generateUUID(4) + ".jpg";
                        File photo1 = new File(Environment.getExternalStorageDirectory(), (path + fileName1));
                        File photo2 = new File(Environment.getExternalStorageDirectory(), (path + fileName2));
                        File photo3 = new File(Environment.getExternalStorageDirectory(), (path + fileName3));
                        photo1.getParentFile().mkdirs();
 
                        savePathList.add(photo1);
                        savePathList.add(photo2);
                        savePathList.add(photo3);
 
                        List<String> fileNameList = new ArrayList<String>();
                        fileNameList.add(fileName1);
                        fileNameList.add(fileName2);
                        fileNameList.add(fileName3);
 
                        for (int i = 0; i < pathTempList.size(); i++) {
                            File oldFile = pathTempList.get(i);
                            File newFile = savePathList.get(i);
                            //保存到mediaFile数据库
                            Mediafile mediaFile = new Mediafile();
                            mediaFile.setGuid(UUIDGenerator.generate16ShortUUID());
                            mediaFile.setIguid(inspectionCurrent.getGuid());
                            mediaFile.setBusinessguid(problemlist.getGuid());
                            mediaFile.setLongitude(longitudeCurrent);
                            mediaFile.setLatitude(latitudeCurrent);
                            mediaFile.setAddress(problemlist.getSenseaddress());
                            mediaFile.setFiletype(1);
                            mediaFile.setBusinesstype("问题");
                            mediaFile.setBusinesstypeid(intToByte(1));
                            mediaFile.setPath(path);
                            mediaFile.setDescription(fileNameList.get(i));
                            mediaFile.setSavetime(new Date());
                            mediaFile.setIschanged(false);
                            String exetension1 = scenseCurrent.getCitycode() + "/" + scenseCurrent.getDistrictcode() + "/" + DateFormatter.dateFormat2.format(calendar.getTime()) + "/" + scenseCurrent.getGuid() + "/";
                            mediaFile.setExtension1(exetension1);
                            mediaFile.setRemark("未上传");
                            mediafileDao.insert(mediaFile);
 
                            try {
                                copyfile(oldFile, newFile);
                            } catch (IOException e) {
                                e.printStackTrace();
                                showToast("拷贝出错" + i);
                            }
                        }
                        //上传问题的基本数据
                        if (problemlist.getPtguid() == null) {
                            Toast.makeText(application, "问题ID为空", Toast.LENGTH_SHORT).show();
                            AlertDialog.Builder d2 = new AlertDialog.Builder(getActivity());
                            d2.setTitle("问题ID为空");
                            d2.setPositiveButton("确定", null);
                            d2.show();
                        }
                        Call<ResponseBody> putOneProblemLsit = inspectionService.putOneProblemList(problemlist);
                        putOneProblemLsit.enqueue(new Callback<ResponseBody>() {
                            @Override
                            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                                if (response.body() != null) {
                                    System.out.println("problemList:" + response.body());
                                    showToast("提交成功");
                                    clearTemp();
                                    refreshProblemMarker();
                                    if (inspectionCurrent.getProblemcount() != null) {
                                        inspectionCurrent.setProblemcount(inspectionCurrent.getProblemcount() + 1);
                                    } else {
                                        inspectionCurrent.setProblemcount(1);
                                    }
                                    updateInspection(inspectionCurrent);
                                    dialog.dismiss();
                                } else if (response.errorBody() != null) {
                                    System.out.println("problemList:" + response.errorBody());
                                    showToast("提交失败");
                                }
                            }
 
                            @Override
                            public void onFailure(Call<ResponseBody> call, Throwable t) {
                                System.out.println("problemList:" + t.toString());
                                showToast("联网失败");
                            }
                        });
 
                    } else {
                        showToast("至少拍一张照片");
                    }
                    if (problemType.equals("态度")) {
                        //上传问题的基本数据
                        Call<ResponseBody> putOneProblemLsit = inspectionService.putOneProblemList(problemlist);
                        putOneProblemLsit.enqueue(new Callback<ResponseBody>() {
                            @Override
                            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                                if (response.body() != null) {
                                    System.out.println("problemList:" + response.body());
                                    showToast("提交成功");
                                    clearTemp();
                                    refreshProblemMarker();
                                    dialog.dismiss();
                                } else if (response.errorBody() != null) {
                                    System.out.println("problemList:" + response.errorBody());
                                    showToast("提交失败");
                                }
                            }
 
                            @Override
                            public void onFailure(Call<ResponseBody> call, Throwable t) {
                                System.out.println("problemList:" + t.toString());
                                showToast("联网失败");
                            }
                        });
                    }
 
 
                } else {
                    showToast("错误,Current数据缺失");
                }
 
            }
        });
        //设置取消按钮的点击事件
        fab_Close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clearTemp();
                dialog.dismiss();
 
            }
        });
        clearTemp();
        refreshPhotoClickListener(pathTempList);
        dialog.show();
 
    }
 
    //刷新问题对应的整改建议
    private void refreshSuggestion(String ptGuid, final List<String> list, final ArrayAdapter arrayAdapter) {
        dbSource.getAdviceByProblemType(ptGuid)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<ChangeAdvice>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
 
                    }
 
                    @Override
                    public void onNext(List<ChangeAdvice> changeAdvices) {
                        List<String> advices = new ArrayList<>();
                        for (ChangeAdvice c : changeAdvices) {
                            advices.add(c.getAdName());
                        }
                        advices.add("暂无建议");
                        list.clear();
                        list.addAll(advices);
                        arrayAdapter.notifyDataSetChanged();
                    }
 
                    @Override
                    public void onError(Throwable e) {
 
                    }
 
                    @Override
                    public void onComplete() {
 
                    }
                });
    }
 
    //显示问题列表
    public void showProblemList(final int type) {
        final Dialog dialog = new Dialog(getContext());
        dialog.setContentView(R.layout.dialog_problem_list);
        //设置dialog宽度
        Window dialogWindow = dialog.getWindow();
        dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
        final WindowManager.LayoutParams p = dialogWindow.getAttributes();
        p.width = (int) (ScreenUtils.getScreenWidth(getContext()) * 1);
        p.height = (int) (ScreenUtils.getScreenHeight(getContext()) * 0.8);
 
        FloatingActionButton fab_close = (FloatingActionButton) dialog.findViewById(R.id.fab_problem_list_close);
        RecyclerView rv_main = (RecyclerView) dialog.findViewById(R.id.rv_dialog_problem_list_main);
        final TextView tv_titile = (TextView) dialog.findViewById(R.id.tv_title);
        final LinearLayout ll_lastSubTaskData = (LinearLayout) dialog.findViewById(R.id.ll_last_subTask_data);
        final TextView tv_executors = (TextView) dialog.findViewById(R.id.tv_executors);
        final TextView tv_startTime = (TextView) dialog.findViewById(R.id.tv_start_time);
 
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        rv_main.setLayoutManager(linearLayoutManager);
        final List<ProblemlistVo> problemlistVoList = new ArrayList<>();
 
        if (type == PROBLEM_LIST || type == PROBLEM_CHANGE) {
            problemListAdapter = new ProblemListAdapter(getActivity(), problemlistVoList, ProblemListAdapter.PROBLEM_LIST);
        } else if (type == PROBLEM_RECHECK) {
            problemListAdapter = new ProblemListAdapter(getActivity(), problemlistVoList, ProblemListAdapter.RECHECK_LIST);
        }
        rv_main.setAdapter(problemListAdapter);
        rv_main.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), rv_main, new RecyclerItemClickListener.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Intent intent = new Intent(getActivity(), ProblemDetailActivity.class);
                intent.putExtra("problemlistVo", problemlistVoList.get(position));
                intent.putExtra("subTaskSelected", subTaskSelected);
                intent.putExtra("scenseLat", scenseCurrent.getLatitude());
                intent.putExtra("scenseLng", scenseCurrent.getLongitude());
                intent.putExtra("editable", problemEditable);
                intent.putExtra("type", type);
                startActivityForResult(intent, PROBLEM_DETAIL);
                dialog.dismiss();
 
            }
 
            @Override
            public void onItemLongClick(View view, int position) {
 
            }
        }));
 
        if (type == PROBLEM_LIST || type == PROBLEM_CHANGE) {
            if (type == PROBLEM_LIST) {
                tv_titile.setText("问题清单");
                problemEditable = false;
            } else if (type == PROBLEM_CHANGE) {
                tv_titile.setText("现场整改");
                problemEditable = true;
            }
 
            Call<List<ProblemlistVo>> loadProblemList = inspectionService.loadProblemList(inspectionCurrent.getGuid());
            loadProblemList.enqueue(new Callback<List<ProblemlistVo>>() {
                @Override
                public void onResponse(Call<List<ProblemlistVo>> call, Response<List<ProblemlistVo>> response) {
                    if (response.body() != null) {
                        problemlistVoList.addAll(response.body());
                        problemListAdapter.notifyDataSetChanged();
                        addProblemMarkers(problemlistVoList);
                        tv_executors.setText("共" + problemlistVoList.size() + "个问题");
                        int changed = 0;
                        for (ProblemlistVo problemlistVo : problemlistVoList) {
                            if (problemlistVo.getIschanged()) {
                                changed++;
                            }
                        }
                        tv_startTime.setText(changed + "个已整改");
                    } else if (response.errorBody() != null) {
                        System.out.println("loadProblemList:" + response.errorBody().toString());
                        tv_executors.setText("获取问题数据失败");
                        Toast.makeText(application, "获取问题数据失败", Toast.LENGTH_SHORT).show();
                    }
                }
 
                @Override
                public void onFailure(Call<List<ProblemlistVo>> call, Throwable t) {
                    System.out.println("loadProblemList:" + t.toString());
                    tv_executors.setText("联网失败");
                    Toast.makeText(application, "联网失败", Toast.LENGTH_SHORT).show();
                }
            });
        } else if (type == PROBLEM_RECHECK) {
            tv_titile.setText("问题复核");
            problemEditable = true;
            ll_lastSubTaskData.setVisibility(View.INVISIBLE);
            String date = DateFormatter.dateTimeFormat2.format(subTaskSelected.getPlanstarttime());
            Call<LastSubtaskPack> loadLastProblemList = inspectionService.loadLastProblemList(subTaskSelected.getScenseid(), date);
            loadLastProblemList.enqueue(new Callback<LastSubtaskPack>() {
                @Override
                public void onResponse(Call<LastSubtaskPack> call, Response<LastSubtaskPack> response) {
                    if (response.body() != null) {
                        int rechecked = 0;
                        if (response.body().getProblemlistVo() != null && response.body().getProblemlistVo().size() > 0) {
                            problemlistVoList.addAll(response.body().getProblemlistVo());
                            List<ProblemlistVo> changedList = new ArrayList<ProblemlistVo>();
                            for (int i = 0; i < problemlistVoList.size(); i++) {
                                ProblemlistVo problemlistVo = problemlistVoList.get(i);
                                if (problemlistVo.getIschanged()) {
                                    changedList.add(problemlistVo);
                                }
                                if (problemlistVo.getIsrechecked()) {
                                    rechecked++;
                                }
                            }
                            problemlistVoList.removeAll(changedList);
                            problemListAdapter.notifyDataSetChanged();
                        }
                        try {
                            if (response.body().getSubtaskVo() != null) {
                                tv_executors.setText("" + response.body().getSubtaskVo().getExecutorrealtimes().replaceAll(Constant.CONNECTOR, Constant.CONNECTOR_FOR_VIEW) + "\n共" + problemlistVoList.size() + "个问题");
                                tv_startTime.setText("" + DateFormatter.dateTimeFormat.format(response.body().getSubtaskVo().getExecutionstarttime()) + "\n" + rechecked + "个已复核");
                            } else {
                                tv_executors.setText("共" + problemlistVoList.size() + "个问题");
                                tv_startTime.setText(rechecked + "个已复核");
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        ll_lastSubTaskData.setVisibility(View.VISIBLE);
 
                    } else if (response.errorBody() != null) {
                        showToast("获取上一次任务信息失败");
                        tv_executors.setText("获取上一次任务信息失败");
                        System.out.println("loadLastProblemList:" + response.errorBody().toString());
                    }
                }
 
                @Override
                public void onFailure(Call<LastSubtaskPack> call, Throwable t) {
                    showToast("联网失败");
                    tv_executors.setText("联网失败");
                    System.out.println("loadLastProblemList:" + t.toString());
                }
            });
        }
        fab_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
 
        dialog.show();
    }
 
    //显示任意拍照的dialog
    private void showCameraDialog() {
        final Dialog dialog = new Dialog(getContext());
        dialog.setContentView(R.layout.dialog_camera);
        //设置dialog宽度
        Window dialogWindow = dialog.getWindow();
        dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
        final WindowManager.LayoutParams p = dialogWindow.getAttributes();
        p.width = (int) (ScreenUtils.getScreenWidth(getContext()) * 1);
        p.height = (int) (ScreenUtils.getScreenHeight(getContext()) * 0.8);
 
        FloatingActionButton fab_close = (FloatingActionButton) dialog.findViewById(R.id.fab_problem_list_close);
        final RecyclerView rv_main = (RecyclerView) dialog.findViewById(R.id.rv_photo_list);
        ImageView iv_newPhoto = (ImageView) dialog.findViewById(R.id.iv_new_photo);
        final TextView tv_count = (TextView) dialog.findViewById(R.id.tv_count);
 
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 4);
        rv_main.setLayoutManager(gridLayoutManager);
 
 
        Call<List<Mediafile>> loadCameraMediaFileList = inspectionService.loadMediaFileList(inspectionCurrent.getGuid(), BUSSINESS_TYPE_CAMERA);
        loadCameraMediaFileList.enqueue(new Callback<List<Mediafile>>() {
            @Override
            public void onResponse(Call<List<Mediafile>> call, Response<List<Mediafile>> response) {
                List<Mediafile> mediafilesList = new ArrayList<>();
 
                if (response.body() != null) {
                    mediafilesList.addAll(response.body());
 
 
                } else if (response.errorBody() != null) {
                    Toast.makeText(application, "获取在线图片列表失败", Toast.LENGTH_SHORT).show();
                    tv_count.setText("获取在线图片列表失败");
                }
                mediafilesList.addAll(mediafileDao.queryBuilder().where(MediafileDao.Properties.Iguid.eq(inspectionCurrent.getGuid())).where(MediafileDao.Properties.Businesstypeid.eq(BUSSINESS_TYPE_CAMERA)).where(MediafileDao.Properties.Remark.eq("未上传")).list());
                PhotoListAdapter photoListAdapter = new PhotoListAdapter(mediafilesList, getContext());
                rv_main.setAdapter(photoListAdapter);
                rv_main.addOnItemTouchListener(imagelistListener(rv_main, mediafilesList));
                tv_count.setText("共" + mediafilesList.size() + "张照片");
            }
 
            @Override
            public void onFailure(Call<List<Mediafile>> call, Throwable t) {
                Toast.makeText(application, "联网失败", Toast.LENGTH_SHORT).show();
                List<Mediafile> mediafilesList = new ArrayList<>();
                mediafilesList = mediafileDao.queryBuilder().where(MediafileDao.Properties.Iguid.eq(inspectionCurrent.getGuid())).where(MediafileDao.Properties.Businesstypeid.eq(BUSSINESS_TYPE_CAMERA)).where(MediafileDao.Properties.Remark.eq("未上传")).list();
                PhotoListAdapter photoListAdapter = new PhotoListAdapter(mediafilesList, getContext());
                rv_main.setAdapter(photoListAdapter);
                rv_main.addOnItemTouchListener(imagelistListener(rv_main, mediafilesList));
                tv_count.setText("共" + mediafilesList.size() + "张照片");
            }
        });
 
 
        iv_newPhoto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showNewPhotoDailog();
                dialog.dismiss();
            }
        });
        fab_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        cameraDialog = dialog;
        dialog.show();
 
    }
 
    //任意拍照图片列表的clicklistener
    private RecyclerView.OnItemTouchListener imagelistListener(RecyclerView rv_main, final List<Mediafile> mediafilesList) {
        RecyclerView.OnItemTouchListener listerner = new RecyclerItemClickListener(getContext(), rv_main, new RecyclerItemClickListener.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                List<File> files = new ArrayList<>();
                for (Mediafile m :
                        mediafilesList) {
                    File f = new File(Environment.getExternalStorageDirectory(), m.getPath() + m.getDescription());
                    files.add(f);
                }
//                File file = new File(Environment.getExternalStorageDirectory(), mediafilesList.get(position).getPath() + mediafilesList.get(position).getDescription());
                Intent intent = new Intent(getActivity(), PhotoViewerActivity.class);
//                intent.putExtra("file", file);
                intent.putExtra(PhotoViewerActivity.PARA_FILES, (Serializable) files);
                intent.putExtra("type", PhotoViewerActivity.CAMERA_PHOTO);
                intent.putExtra("deletable", true);
                intent.putExtra("position", position);
//                intent.putExtra("mediaFile", mediafilesList.get(position));
                intent.putExtra(PhotoViewerActivity.PARA_MEDIAS, (Serializable) mediafilesList);
                startActivityForResult(intent, VIEW_CAMERA_PHOTO);
            }
 
            @Override
            public void onItemLongClick(View view, int position) {
 
            }
        });
        return listerner;
    }
 
    //添加新的任意拍照照片
    private void showNewPhotoDailog() {
        final Dialog dialog = new Dialog(getContext());
        dialog.setContentView(R.layout.dialog_new_photo);
        //设置dialog宽度
        Window dialogWindow = dialog.getWindow();
        dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
        final WindowManager.LayoutParams p = dialogWindow.getAttributes();
        p.width = (int) (ScreenUtils.getScreenWidth(getContext()) * 1);
        dialog.setCancelable(false);
        //初始化控件
        FloatingActionButton fab_ok = (FloatingActionButton) dialog.findViewById(R.id.fab_take_evidence_ok);
        FloatingActionButton fab_Close = (FloatingActionButton) dialog.findViewById(R.id.fab_take_evidence_close);
        final EditText et_description = (EditText) dialog.findViewById(R.id.et_description);
 
        iv_cameraPhoto1 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo1);
        iv_cameraPhoto2 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo2);
        iv_cameraPhoto3 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo3);
 
        ivCameraList = new ArrayList<>();
        ivCameraList.add(iv_cameraPhoto1);
        ivCameraList.add(iv_cameraPhoto2);
        ivCameraList.add(iv_cameraPhoto3);
 
        pathTempList = new ArrayList<>();
        refreshNewPhotoClickListener();
 
        //确定按钮保存图片和数据库
        fab_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (et_description.getText().toString().length() > 0) {
                    java.util.Calendar calendar = java.util.Calendar.getInstance();
                    calendar.setTime(subTaskSelected.getExecutionstarttime());
                    String path = "FlightFeather/Photo/" + scenseCurrent.getDistrictname() + "/" + calendar.get(java.util.Calendar.YEAR) + "年" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月/" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月" + calendar.get(java.util.Calendar.DAY_OF_MONTH) + "日/" + scenseCurrent.getName() + "/任意拍照/";
                    if (pathTempList != null && pathTempList.size() > 0) {
                        for (int i = 0; i < pathTempList.size(); i++) {
                            String fileName = et_description.getText().toString() + " " + UUIDGenerator.generateUUID(4) + ".jpg";
                            File newFile = new File(Environment.getExternalStorageDirectory(), path + fileName);
                            newFile.getParentFile().mkdirs();
                            try {
                                //把文件从temp复制到特定文件夹下
                                copyfile(pathTempList.get(i), newFile);
                                Mediafile mediaFile = new Mediafile();
                                mediaFile.setGuid(UUIDGenerator.generate16ShortUUID());
                                mediaFile.setIguid(inspectionCurrent.getGuid());
                                mediaFile.setLongitude(longitudeCurrent);
                                mediaFile.setLatitude(latitudeCurrent);
                                mediaFile.setAddress(getScenceAddress());
                                mediaFile.setFiletype(1);
                                mediaFile.setBusinesstype("常规记录");
                                mediaFile.setBusinesstypeid(intToByte(5));
                                mediaFile.setPath(path);
                                mediaFile.setDescription(fileName);
                                mediaFile.setSavetime(new Date());
                                mediaFile.setIschanged(false);
                                String exetension1 = scenseCurrent.getCitycode() + "/" + scenseCurrent.getDistrictcode() + "/" + DateFormatter.dateFormat2.format(calendar.getTime()) + "/" + scenseCurrent.getGuid() + "/";
                                mediaFile.setExtension1(exetension1);
                                mediaFile.setRemark("未上传");
                                mediafileDao.insert(mediaFile);
 
                            } catch (IOException e) {
                                e.printStackTrace();
                                Toast.makeText(application, "复制文件出错", Toast.LENGTH_SHORT).show();
                                return;
                            }
                        }
                        Toast.makeText(application, "保存成功", Toast.LENGTH_SHORT).show();
                        clearTemp();
                        dialog.dismiss();
                    } else {
                        Toast.makeText(application, "请至少拍一张照片", Toast.LENGTH_SHORT).show();
                    }
 
                } else {
                    Toast.makeText(application, "请填写照片描述", Toast.LENGTH_SHORT).show();
                }
 
 
            }
        });
        fab_Close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                clearTemp();
                dialog.dismiss();
            }
        });
        dialog.show();
    }
 
    //清除拍照取证的缓存
    public void clearTemp() {
        for (int i = 0; i < pathTempList.size(); i++) {
            File file = pathTempList.get(i);
            if (file.exists()) {
                file.delete();
            }
        }
    }
 
    //刷新任意拍照的图片点击事件
    public void refreshNewPhotoClickListener() {
        for (int i = 0; i < pathTempList.size(); i++) {
            SetImageTask task1 = new SetImageTask(pathTempList.get(i), ivCameraList.get(i));
            task1.execute();
            ivCameraList.get(i).setOnClickListener(showPhotoClicker(i, PhotoViewerActivity.CAMERA_PHOTO_TEMP, VIEW_CAMERA_TEMP_PHOTO));
        }
        if (pathTempList.size() < 3) {
            ImageView iv_camera = ivCameraList.get(pathTempList.size());
            iv_camera.setImageResource(R.drawable.icon_add_photo);
            iv_camera.setOnClickListener(addPhotoClickListener(CAMERA_PHOTO));
            //将拍照的图片框前后位置设置为空图片框
            if (pathTempList.size() < 2) {
                ivCameraList.get(pathTempList.size() + 1).setImageResource(R.drawable.icon_add_photo_blank);
            }
        }
        if (pathTempList.size() > 0) {
            ivCameraList.get(pathTempList.size() - 1).setImageResource(R.drawable.icon_add_photo_blank);
        }
    }
 
    //点击显示任意拍照的大图
    private View.OnClickListener showPhotoClicker(final int position, final int type, final int requestCode) {
        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), PhotoViewerActivity.class);
                intent.putExtra("position", position);
                intent.putExtra("type", type);
                intent.putExtra("deletable", true);
//                intent.putExtra("file", pathTempList.get(position));
                intent.putExtra(PhotoViewerActivity.PARA_FILES, (Serializable) pathTempList);
                startActivityForResult(intent, requestCode);
            }
        };
        return listener;
    }
 
 
    //刷新列表点击事件状态
    public void refreshPhotoClickListener(List<File> files) {
        int a = files.size();
        if (a == 0) {
            miv_add_photo1.setOnClickListener(addPhotoClickListener(PHOTO1));
            miv_add_photo2.setOnClickListener(null);
            miv_add_photo3.setOnClickListener(null);
 
            miv_add_photo1.setImageResource(R.drawable.icon_add_photo);
            miv_add_photo2.setImageResource(R.drawable.icon_add_photo_blank);
            miv_add_photo3.setImageResource(R.drawable.icon_add_photo_blank);
        } else if (a == 1) {
            miv_add_photo1.setOnClickListener(viewPhotoClickListener(PHOTO1));
            miv_add_photo2.setOnClickListener(addPhotoClickListener(PHOTO2));
            miv_add_photo3.setOnClickListener(null);
 
            SetImageTask task1 = new SetImageTask(files.get(PHOTO1), miv_add_photo1);
            task1.execute();
            miv_add_photo2.setImageResource(R.drawable.icon_add_photo);
            miv_add_photo3.setImageResource(R.drawable.icon_add_photo_blank);
        } else if (a == 2) {
            miv_add_photo1.setOnClickListener(viewPhotoClickListener(PHOTO1));
            miv_add_photo2.setOnClickListener(viewPhotoClickListener(PHOTO2));
            miv_add_photo3.setOnClickListener(addPhotoClickListener(PHOTO3));
 
            SetImageTask task1 = new SetImageTask(files.get(PHOTO1), miv_add_photo1);
            task1.execute();
            SetImageTask task2 = new SetImageTask(files.get(PHOTO2), miv_add_photo2);
            task2.execute();
            miv_add_photo3.setImageResource(R.drawable.icon_add_photo);
        } else if (a == 3) {
            miv_add_photo1.setOnClickListener(viewPhotoClickListener(PHOTO1));
            miv_add_photo2.setOnClickListener(viewPhotoClickListener(PHOTO2));
            miv_add_photo3.setOnClickListener(viewPhotoClickListener(PHOTO3));
 
            SetImageTask task1 = new SetImageTask(files.get(PHOTO1), miv_add_photo1);
            task1.execute();
            SetImageTask task2 = new SetImageTask(files.get(PHOTO2), miv_add_photo2);
            task2.execute();
            SetImageTask task3 = new SetImageTask(files.get(PHOTO3), miv_add_photo3);
            task3.execute();
        }
    }
 
    //添加图片用的点击事件
    public View.OnClickListener addPhotoClickListener(final int position) {
        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
                int t = 3 - pathTempList.size();
                final int picNum = t >= 0 ? t : 0;
                switch (position) {
                    case PHOTO1:
                        pickPhoto(PICK_PHOTO1, picNum);
                        break;
                    case PHOTO2:
                        pickPhoto(PICK_PHOTO2, picNum);
                        break;
                    case PHOTO3:
                        pickPhoto(PICK_PHOTO3, picNum);
                        break;
                    case CAMERA_PHOTO:
                        pickPhoto(PICK_CAMERA_PHTOO, picNum);
                        break;
                    case GIT_PHOTO:
                        pickPhoto(PICK_GIT_PHOTO, picNum);
                }
            }
        };
        return listener;
    }
 
    //有图片时,查看图片的点击事件(temp)
    public View.OnClickListener viewPhotoClickListener(final int position) {
        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), PhotoViewerActivity.class);
 
                if (position == PHOTO1 || position == PHOTO2 || position == PHOTO3) {
                    intent.putExtra("position", position);
                    intent.putExtra("type", PhotoViewerActivity.EVIDENCE_PHOTO_TEMP);
                    intent.putExtra("deletable", true);
//                    intent.putExtra("file", pathTempList.get(position));
                    intent.putExtra(PhotoViewerActivity.PARA_FILES, (Serializable) pathTempList);
                    startActivityForResult(intent, VIEW_EVIDENCE_TEMP_PHOTO);
                }
            }
        };
        return listener;
    }
 
    //显示技防措施列表
    private void showGitListDialog() {
        final Dialog dialog = new Dialog(getContext());
        dialog.setContentView(R.layout.dialog_camera);
        //设置dialog宽度
        Window dialogWindow = dialog.getWindow();
        dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
        final WindowManager.LayoutParams p = dialogWindow.getAttributes();
        p.width = (int) (ScreenUtils.getScreenWidth(getContext()) * 1);
        p.height = (int) (ScreenUtils.getScreenHeight(getContext()) * 0.8);
 
        TextView tv_title = (TextView) dialog.findViewById(R.id.tv_title);
        FloatingActionButton fab_close = (FloatingActionButton) dialog.findViewById(R.id.fab_problem_list_close);
        final RecyclerView rv_main = (RecyclerView) dialog.findViewById(R.id.rv_photo_list);
        ImageView iv_newPhoto = (ImageView) dialog.findViewById(R.id.iv_new_photo);
        final TextView tv_count = (TextView) dialog.findViewById(R.id.tv_count);
 
        tv_title.setText("技防措施");
        final List<GitlistVo> gitlistVoList = new ArrayList<>();
        final GitListAdapter gitListAdapter = new GitListAdapter(getContext(), gitlistVoList);
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        rv_main.setLayoutManager(manager);
        rv_main.setAdapter(gitListAdapter);
        Call<List<GitlistVo>> loadGitList = inspectionService.loadGitList(inspectionCurrent.getGuid());
        loadGitList.enqueue(new Callback<List<GitlistVo>>() {
            @Override
            public void onResponse(Call<List<GitlistVo>> call, Response<List<GitlistVo>> response) {
                if (response.body() != null) {
                    gitlistVoList.addAll(response.body());
                    gitListAdapter.notifyDataSetChanged();
                    tv_count.setText("共" + gitlistVoList.size() + "条技防措施");
                } else if (response.errorBody() != null) {
                    Toast.makeText(application, "获取技防措施数据失败", Toast.LENGTH_SHORT).show();
                    tv_count.setText("获取技防措施数据失败");
                }
            }
 
            @Override
            public void onFailure(Call<List<GitlistVo>> call, Throwable t) {
                Toast.makeText(application, "网络连接失败", Toast.LENGTH_SHORT).show();
                tv_count.setText("网络连接失败");
            }
        });
        rv_main.addOnItemTouchListener(new RecyclerItemClickListener(getContext(), rv_main, new RecyclerItemClickListener.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Intent intent = new Intent(getActivity(), GitDetailActivity.class);
                intent.putExtra("gitlistVo", gitlistVoList.get(position));
                intent.putExtra("subTask", subTaskSelected);
                intent.putExtra("inspectionGuid", inspectionCurrent.getGuid());
                intent.putExtra("scenseAddress", getScenceAddress());
                startActivity(intent);
            }
 
            @Override
            public void onItemLongClick(View view, int position) {
 
            }
        }));
        iv_newPhoto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
                showNewGitDialog();
            }
        });
        fab_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
 
        dialog.show();
    }
 
 
    //新增一条技防措施的dialog
    private void showNewGitDialog() {
        final Dialog dialog = new Dialog(getContext());
        dialog.setContentView(R.layout.dialog_take_evidence);
        //设置dialog宽度
        Window dialogWindow = dialog.getWindow();
        dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
        final WindowManager.LayoutParams p = dialogWindow.getAttributes();
        p.width = (int) (ScreenUtils.getScreenWidth(getContext()) * 1);
        dialog.setCancelable(false);
        //初始化控件
        TextView tv_title = (TextView) dialog.findViewById(R.id.tv_dialog_take_evidence_title);
        TextView tv_type = (TextView) dialog.findViewById(R.id.tv_type);
        TextView tv_chose = (TextView) dialog.findViewById(R.id.tv_chose);
        TextView tv_location = (TextView) dialog.findViewById(R.id.tv_location);
        FloatingActionButton fab_ok = (FloatingActionButton) dialog.findViewById(R.id.fab_take_evidence_ok);
        FloatingActionButton fab_Close = (FloatingActionButton) dialog.findViewById(R.id.fab_take_evidence_close);
        iv_gitPhoto1 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo1);
        iv_gitPhoto2 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo2);
        iv_gitPhoto3 = (ImageView) dialog.findViewById(R.id.iv_take_evidence_add_photo3);
        Spinner sp_gitType = (Spinner) dialog.findViewById(R.id.sp_take_evidence_select_problem_type);
        final Spinner sp_git = (Spinner) dialog.findViewById(R.id.sp_take_evidence_select_problem);
        final Spinner sp_location = (Spinner) dialog.findViewById(R.id.sp_take_evidence_select_location);
        final EditText et_locationRemark = (EditText) dialog.findViewById(R.id.et_take_evidence_location);
        final EditText et_problemDes = (EditText) dialog.findViewById(R.id.et_take_evidence_problem_des);
 
        ivGitList = new ArrayList<>();
        ivGitList.add(iv_gitPhoto1);
        ivGitList.add(iv_gitPhoto2);
        ivGitList.add(iv_gitPhoto3);
 
        //设置界面
        tv_title.setText("新增技防措施");
        tv_type.setText("措施类型");
        tv_chose.setText("选择一个技防措施");
        tv_location.setVisibility(View.GONE);
        sp_location.setVisibility(View.GONE);
        et_locationRemark.setVisibility(View.GONE);
        et_problemDes.setVisibility(View.GONE);
        //初始化变量
        pathTempList = new ArrayList<>();
        refreshNewGitPhotoClickListener();
        //加载预置数据
        List<Gittype> gittypeList = gittypeDao.queryBuilder().where(GittypeDao.Properties.Tasktype.eq(subTaskSelected.getType())).where(GittypeDao.Properties.Scensetype.eq(scenseCurrent.getType())).where(GittypeDao.Properties.Districtname.eq(subTaskSelected.getDistrictname())).orderAsc(GittypeDao.Properties.Typeid).list();
        if (gittypeList.size() == 0) {
            Gittype gittype1 = new Gittype();
            gittype1.setGuid("00");
            gittype1.setName("无");
            gittype1.setType("无");
            gittype1.setDesc("无");
            gittypeList.add(gittype1);
        }
 
        final List<String> gitTypeStringList = new ArrayList<>();
        final Map<String, List<Gittype>> gitTypeMap = new HashMap<>();
        for (Gittype gittype : gittypeList) {
            if (gitTypeMap.containsKey(gittype.getType())) {
                gitTypeMap.get(gittype.getType()).add(gittype);
            } else {
                gitTypeStringList.add(gittype.getType());
                List<Gittype> gittypeList1 = new ArrayList<>();
                gittypeList1.add(gittype);
                gitTypeMap.put(gittype.getType(), gittypeList1);
            }
        }
        ArrayAdapter gittypeAdapter = new ArrayAdapter(getContext(), R.layout.item_spinner_drop_down, gitTypeStringList);
        sp_gitType.setAdapter(gittypeAdapter);
        final List<Gittype> gittypeList1 = new ArrayList<>();
        final GitTypeListAdapter gitTypeListAdapter = new GitTypeListAdapter(gittypeList1, getContext());
        sp_git.setAdapter(gitTypeListAdapter);
        sp_gitType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                //当选中一个分类时,从map加载问题列表,填充数据
                gittypeList1.removeAll(gittypeList1);
                gittypeList1.addAll(gitTypeMap.get(gitTypeStringList.get(i)));
                gitTypeListAdapter.notifyDataSetChanged();
            }
 
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
 
            }
        });
 
 
        fab_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (pathTempList.size() > 0) {
                    //准备gitlist
                    final Gitlist gitlist = new Gitlist();
                    gitlist.setGuid(UUIDGenerator.generate16ShortUUID());
                    gitlist.setIguid(inspectionCurrent.getGuid());
                    gitlist.setStguid(subTaskSelected.getStguid());
                    gitlist.setSguid(scenseCurrent.getGuid());
                    gitlist.setScensename(scenseCurrent.getName());
                    gitlist.setScenseaddress(getScenceAddress());
                    final Gittype gitSelected = (Gittype) sp_git.getSelectedItem();
                    gitlist.setGtguid(gitSelected.getGuid());
                    gitlist.setName(gitSelected.getName());
                    gitlist.setType(gitSelected.getType());
                    gitlist.setDesc(gitSelected.getDesc());
                    gitlist.setCreatedate(new Date());
                    gitlist.setUpdatedate(new Date());
                    //准备mediaFIle
                    final java.util.Calendar calendar = java.util.Calendar.getInstance();
                    calendar.setTime(subTaskSelected.getExecutionstarttime());
                    final String path = "FlightFeather/Photo/" + scenseCurrent.getDistrictname() + "/" + calendar.get(java.util.Calendar.YEAR) + "年" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月/" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月" + calendar.get(java.util.Calendar.DAY_OF_MONTH) + "日/" + scenseCurrent.getName() + "/技防措施/";
 
                    Call<ResponseBody> putGit = inspectionService.putGitList(gitlist);
                    putGit.enqueue(new Callback<ResponseBody>() {
                        @Override
                        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                            if (response.body() != null) {
                                Toast.makeText(application, "提交成功", Toast.LENGTH_SHORT).show();
                                for (File oldfile : pathTempList) {
                                    String fileName = gitSelected.getName() + " " + UUIDGenerator.generateUUID(4) + ".jpg";
                                    Mediafile mediafile = new Mediafile();
                                    mediafile.setGuid(UUIDGenerator.generate16ShortUUID());
                                    mediafile.setBusinessguid(gitlist.getGuid());
                                    mediafile.setIguid(inspectionCurrent.getGuid());
                                    mediafile.setLongitude(longitudeCurrent);
                                    mediafile.setLatitude(latitudeCurrent);
                                    mediafile.setAddress(getScenceAddress());
                                    mediafile.setFiletype(1);
                                    mediafile.setBusinesstype("2");
                                    mediafile.setBusinesstype("技防措施");
                                    mediafile.setPath(path);
                                    mediafile.setDescription(fileName);
                                    mediafile.setSavetime(new Date());
                                    String exetension1 = scenseCurrent.getCitycode() + "/" + scenseCurrent.getDistrictcode() + "/" + DateFormatter.dateFormat2.format(calendar.getTime()) + "/" + scenseCurrent.getGuid() + "/";
                                    mediafile.setExtension1(exetension1);
                                    mediafile.setRemark("未上传");
                                    try {
                                        File newfile = new File(Environment.getExternalStorageDirectory(), (path + fileName));
                                        newfile.getParentFile().mkdirs();
                                        copyfile(oldfile, newfile);
                                        mediafileDao.insert(mediafile);
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    }
                                }
                                dialog.dismiss();
                            } else if (response.errorBody() != null) {
                                Log.e("putGit:", response.errorBody().toString());
                                Toast.makeText(application, "提交失败", Toast.LENGTH_SHORT).show();
                            }
                        }
 
                        @Override
                        public void onFailure(Call<ResponseBody> call, Throwable t) {
                            Log.e("putGit:", t.toString());
                            Toast.makeText(application, "联网失败", Toast.LENGTH_SHORT).show();
                        }
                    });
 
                } else {
                    Toast.makeText(application, "至少拍一张照片", Toast.LENGTH_SHORT).show();
                }
 
            }
        });
        fab_Close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }
 
    //刷新技防措施每个图片的点击事件
    private void refreshNewGitPhotoClickListener() {
        for (int i = 0; i < pathTempList.size(); i++) {
            SetImageTask task1 = new SetImageTask(pathTempList.get(i), ivGitList.get(i));
            task1.execute();
            ivGitList.get(i).setOnClickListener(showPhotoClicker(i, PhotoViewerActivity.GIT_PHOTO_TEMP, VIEW_GIT_TEMP_PHOTO));
        }
        if (pathTempList.size() < 3) {
            ImageView iv_camera = ivGitList.get(pathTempList.size());
            iv_camera.setImageResource(R.drawable.icon_add_photo);
            iv_camera.setOnClickListener(addPhotoClickListener(GIT_PHOTO));
            //将拍照的图片框前后位置设置为空图片框
            if (pathTempList.size() < 2) {
                ivGitList.get(pathTempList.size() + 1).setImageResource(R.drawable.icon_add_photo_blank);
            }
        }
        if (pathTempList.size() > 0) {
            ivGitList.get(pathTempList.size() - 1).setImageResource(R.drawable.icon_add_photo_blank);
        }
    }
 
    //拍照
    public void takePhoto(int type) {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //判断要跳转的目的地是否为空
        if (intent.resolveActivity(getContext().getPackageManager()) != null) {
            File path = null;
            if (type == TAKE_PHOTO1 || type == TAKE_PHOTO2 || type == TAKE_PHOTO3 || type == TAKE_CAMERA_PHOTO || type == TAKE_GIT_PHOTO) {
                path = new File(Environment.getExternalStorageDirectory(), "FlightFeather/Temp/" + UUIDGenerator.generateUUID(4) + ".jpg");
                path.getParentFile().mkdirs();
                tempFileCurrent = path;
            }
            //安卓7.0适配
            Uri uri;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                uri = FileProvider.getUriForFile(getContext(), "cn.flightfeather.thirdapp.fileProvider", path);
            } else {
                uri = Uri.fromFile(path);
            }
            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
            startActivityForResult(intent, type);
        }
    }
 
    //从相册中选择图片
    public void pickPhoto(int type, int num) {
//        Intent intent = new Intent();
//        intent.setAction(Intent.ACTION_PICK);//Pick an item from the data
//        intent.setType("image/*");//从所有图片中进行选择
//        startActivityForResult(intent, type);
 
        PhotoUtil.pickPhoto(this, type, num);
    }
 
 
    //初始化整改承诺
    private void initPromiss() {
        Toast.makeText(application, "加载中请稍后", Toast.LENGTH_SHORT).show();
        Call<List<Mediafile>> loadSignMediaFile = inspectionService.loadMediaFileList(inspectionCurrent.getGuid(), BUSSINESS_TYPE_SIGN);
        loadSignMediaFile.enqueue(new Callback<List<Mediafile>>() {
            @Override
            public void onResponse(Call<List<Mediafile>> call, Response<List<Mediafile>> response) {
                if (response.body() != null) {
                    loadSignPhoto(response.body());
 
                } else if (response.errorBody() != null) {
                    Log.e("loadSignMediaFIle", response.errorBody().toString());
                    Toast.makeText(application, "获取签名图片失败", Toast.LENGTH_SHORT).show();
                }
            }
 
            @Override
            public void onFailure(Call<List<Mediafile>> call, Throwable t) {
                Log.e("loadSignMediaFIle", t.toString());
                Toast.makeText(application, "网络连接失败", Toast.LENGTH_SHORT).show();
            }
        });
    }
 
    //加载签名照片
    private void loadSignPhoto(List<Mediafile> mediaFileList) {
        //如果联网传过来的签名mediaFile是空的,则查询本地的mediaFIle
        if (mediaFileList == null) {
            mediaFileList = new ArrayList<>();
        }
        List<Mediafile> mediaFilelocal = mediafileDao.queryBuilder().where(MediafileDao.Properties.Iguid.eq(inspectionCurrent.getGuid())).where(MediafileDao.Properties.Businesstypeid.eq(BUSSINESS_TYPE_SIGN)).where(MediafileDao.Properties.Remark.eq("未上传")).list();
        mediaFileList.addAll(mediaFilelocal);
 
        //最终的mediafilelist中有数据就显示,没有就新增签名
        if (mediaFileList.size() > 0) {
            List<File> files = new ArrayList<>();
            for (Mediafile m : mediaFileList) {
                File file = new File(Environment.getExternalStorageDirectory(), (m.getPath() + m.getDescription()));
                files.add(file);
            }
 
            if (files.get(0).exists()) {
                Intent intent = new Intent(getActivity(), PhotoViewerActivity.class);
                intent.putExtra(PhotoViewerActivity.PARA_FILES, (Serializable) files);
                intent.putExtra("type", PhotoViewerActivity.CAMERA_PHOTO);
                intent.putExtra("deletable", true);
                intent.putExtra("mediaFile", (Serializable) mediaFileList);
                startActivityForResult(intent, VIEW_SIGN_PHOTO);
            } else {
                if (mediaFileList.get(0).getRemark().equals("未上传")) {
                    for (Mediafile m : mediaFileList) {
                        mediafileDao.delete(m);
                    }
 
                } else if (mediaFileList.get(0).getRemark().equals("已上传")) {
                    for (Mediafile m : mediaFileList) {
                        downloadAndSetImage(m);
                    }
                }
 
            }
        } else {
            startActivityForResult(new Intent(getActivity(), SignActivity.class), SIGN);
        }
    }
 
    //下载并显示图片
    private void downloadAndSetImage(final Mediafile mediafile) {
        String url = mediafile.getExtension1() + mediafile.getGuid() + ".jpg";
        Call<ResponseBody> downloadImage = inspectionImageService.downloadImage(url);
        downloadImage.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                if (response.body() != null) {
                    writeResponseBodyToDisk(mediafile, response.body());
                } else if (response.errorBody() != null) {
                    Toast.makeText(application, "获取图片失败", Toast.LENGTH_SHORT).show();
                    Log.e("downloadImage:", response.errorBody().toString());
                }
 
            }
 
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(application, "联网失败", Toast.LENGTH_SHORT).show();
                Log.e("downloadImage:", t.toString());
            }
        });
    }
 
    //将下载的图片写入磁盘
    public void writeResponseBodyToDisk(Mediafile mediafile, ResponseBody body) {
        if (body == null) {
            Toast.makeText(getActivity(), "图片源错误", Toast.LENGTH_SHORT).show();
            return;
        }
        try {
            InputStream is = body.byteStream();
            File fileDr = new File(Environment.getExternalStorageDirectory(), (mediafile.getPath()));
            if (!fileDr.exists()) {
                fileDr.mkdir();
            }
            File file = new File(Environment.getExternalStorageDirectory(), (mediafile.getPath() + mediafile.getDescription()));
            if (file.exists()) {
                file.delete();
                file = new File(Environment.getExternalStorageDirectory(), (mediafile.getPath() + mediafile.getDescription()));
            }
            FileOutputStream fos = new FileOutputStream(file);
            BufferedInputStream bis = new BufferedInputStream(is);
            byte[] buffer = new byte[1024];
            int len;
            while ((len = bis.read(buffer)) != -1) {
                fos.write(buffer, 0, len);
            }
            fos.flush();
            fos.close();
            bis.close();
            is.close();
            //显示图片
            Intent intent = new Intent(getActivity(), PhotoViewerActivity.class);
            List<File> files = new ArrayList<>();
            files.add(file);
            List<Mediafile> mediafiles = new ArrayList<>();
            mediafiles.add(mediafile);
//            intent.putExtra("file", file);
            intent.putExtra(PhotoViewerActivity.PARA_FILES, (Serializable) files);
            intent.putExtra("type", PhotoViewerActivity.CAMERA_PHOTO);
            intent.putExtra("deletable", true);
//            intent.putExtra("mediaFile", mediafile);
            intent.putExtra(PhotoViewerActivity.PARA_MEDIAS, (Serializable) mediafiles);
            startActivityForResult(intent, VIEW_SIGN_PHOTO);
 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
    //开始导航
    private void startNavi() {
        LatLng sourceLatLng = new LatLng(scenseCurrent.getLatitude(), scenseCurrent.getLongitude());
 
        AmapNavi amapNavi = new AmapNavi(getContext());
        amapNavi.startNavi(sourceLatLng.latitude, sourceLatLng.longitude);
    }
 
    private void backToTaskPage() {
        currentPage = TASK_PAGE;
        rl_selectTask.setVisibility(View.VISIBLE);
        rl_content.setVisibility(View.INVISIBLE);
        fab_map.show();
        subTaskListAdapter.notifyDataSetChanged();
        refreshUploadIconStatus();
    }
 
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_patrol_hide:
                hideIcons();
                break;
            case R.id.ll_patrol_show:
                showIcons();
                break;
            case R.id.ll_show_hide_detail:
                if (iv_showHideDetail.isSelected()) {
                    hideTaskDetail();
                    iv_showHideDetail.setSelected(false);
                } else {
                    showTaskDetail();
                    iv_showHideDetail.setSelected(true);
                }
                break;
            case R.id.iv_patrol_back:
                backToTaskPage();
                break;
            case R.id.iv_start_end_task:
                if (iv_startEndTask.isSelected()) {
                    if (subTaskStatusCurrent.equals(subTaskRunning)) {
                        showEndTaskDialog();
                    }
                } else {
                    if (subTaskStatusCurrent.equals(subTaskNotStart)) {
                        showStartTaskDialog();
                    }
                }
                break;
            case R.id.ln_patrol_take_evidence:
                showTaskEvidenceDialog();
                break;
            case R.id.ln_patrol_problem_list:
                OPEN_TYPE = PROBLEM_LIST;
                showProblemList(PROBLEM_LIST);
                break;
            case R.id.ln_patrol_change:
                OPEN_TYPE = PROBLEM_CHANGE;
                showProblemList(PROBLEM_CHANGE);
                break;
            case R.id.ln_patrol_problem_recheck:
                OPEN_TYPE = PROBLEM_RECHECK;
                showProblemList(PROBLEM_RECHECK);
                break;
            case R.id.ln_patrol_camera:
                showCameraDialog();
                break;
            case R.id.ln_patrol_newgit:
                showGitListDialog();
                break;
            case R.id.ln_patrol_promiss:
//                initPromiss();
                java.util.Calendar calendar = java.util.Calendar.getInstance();
                calendar.setTime(subTaskSelected.getExecutionstarttime());
                String path = "FlightFeather/Photo/" + scenseCurrent.getDistrictname() + "/" + calendar.get(java.util.Calendar.YEAR) + "年" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月/" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月" + calendar.get(java.util.Calendar.DAY_OF_MONTH) + "日/" + scenseCurrent.getName() + "/签字/";
                String fileName1 = "签字 " + UUIDGenerator.generateUUID(4) + ".jpg";
                Mediafile mediaFile = new Mediafile();
                mediaFile.setGuid(UUIDGenerator.generate16ShortUUID());
                mediaFile.setIguid(inspectionCurrent.getGuid());
                mediaFile.setLongitude(longitudeCurrent);
                mediaFile.setLatitude(latitudeCurrent);
                mediaFile.setAddress(getScenceAddress());
                mediaFile.setFiletype(1);
                mediaFile.setBusinesstype("签字");
                mediaFile.setBusinesstypeid(intToByte(6));
                mediaFile.setPath(path);
                mediaFile.setDescription(fileName1);
                mediaFile.setSavetime(new Date());
                mediaFile.setIschanged(false);
                String exetension1 = scenseCurrent.getCitycode() + "/" + scenseCurrent.getDistrictcode() + "/" + DateFormatter.dateFormat2.format(calendar.getTime()) + "/" + scenseCurrent.getGuid() + "/";
                mediaFile.setExtension1(exetension1);
                mediaFile.setRemark("未上传");
 
                Intent intent4 = new Intent(getActivity(), PromiseActivity.class);
                intent4.putExtra("problemlistVoList", (Serializable) problemListVoListCurrent);
                intent4.putExtra("mediaFilePreData", mediaFile);
                intent4.putExtra("inspectionCurrent", inspectionCurrent);
                startActivityForResult(intent4, PROMISE);
                break;
            case R.id.ln_patrol_rate:
 
                Intent intentEvaluation = new Intent(getActivity(), GradeActivity.class);
                intentEvaluation.putExtra("inspectionGuid", inspectionCurrent.getGuid());
                intentEvaluation.putExtra("subtask", subTaskSelected);
                intentEvaluation.putExtra("scense", scenseCurrent);
 
                startActivity(intentEvaluation);
 
//                startActivity(intentEvaluation);
                break;
            case R.id.iv_upload:
                Intent intent = new Intent(getActivity(), UploadMediaFilesActivity.class);
                startActivity(intent);
                break;
            case R.id.ln_patrol_navi:
                startNavi();
                break;
            case R.id.fab_map:
                Intent intent2 = new Intent(getActivity(), SubTaskMapActivity.class);
                intent2.putExtra("subTaskListCurrent", (Serializable) subTaskListCurrent);
                startActivityForResult(intent2, SUBTASK_MAP);
                break;
            case R.id.ln_patrol_chose_latlng:
                Intent intent3 = new Intent(getActivity(), MapActivity.class);
                startActivityForResult(intent3, CHOSE_LATLNG);
 
                break;
            case R.id.ln_patrol_edit:
//                if (scenseCurrent.getType().equals("工地")){
                Intent intent1 = new Intent(getActivity(), SceneDetailActivity.class);
                intent1.putExtra("mode", 1);
                intent1.putExtra("updateScene", scenseCurrent);
                startActivityForResult(intent1, EDITE_SCENSE);
//                }else {
//                    showToast("目前仅支持修改工地");
//                }
                break;
 
        }
    }
 
    //滑动页面会选择当月1号
//    @Override
//    public void onDateChange(Calendar calendar) {
//        tv_title.setText(calendar.getYear() + "年" + calendar.getMonth() + "月");
//        calendarCurrent = trans2Calendar(calendar.getYear(), calendar.getMonth(), calendar.getDay());
//        //如果切换月份,则查询该月的日任务并添加到日历上
//        if (calendarCurrent.get(java.util.Calendar.YEAR) != lastMonthCalender.get(java.util.Calendar.YEAR) || calendarCurrent.get(java.util.Calendar.MONTH) != lastMonthCalender.get(java.util.Calendar.MONTH)) {
//            lastMonthCalender.set(java.util.Calendar.YEAR, calendarCurrent.get(java.util.Calendar.YEAR));
//            lastMonthCalender.set(java.util.Calendar.MONTH, calendarCurrent.get(java.util.Calendar.MONTH));
//            showMonthAllTask(calendarCurrent);
//        }
//        showSubTaskByDay(calendarCurrent.get(java.util.Calendar.DAY_OF_MONTH));
//    }
//
//    @Override
//    public void onYearChange(int year) {
//
//    }
//
//    @Override
//    public void onDateSelected(Calendar calendar) {
//
//    }
 
    //将int的年月日转换为calendar对象
    public java.util.Calendar trans2Calendar(int year, int month, int day) {
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        calendar.set(java.util.Calendar.YEAR, year);
        calendar.set(java.util.Calendar.MONTH, (month - 1));
        calendar.set(java.util.Calendar.DAY_OF_MONTH, day);
        calendar.set(java.util.Calendar.HOUR_OF_DAY, 0);
        calendar.set(java.util.Calendar.MINUTE, 0);
        calendar.set(java.util.Calendar.SECOND, 0);
        calendar.set(java.util.Calendar.MILLISECOND, 0);
 
        return calendar;
    }
 
    @Override
    public void onHiddenChanged(boolean hidden) {
        this.hidden = hidden;
        if (hidden) {
            aMap.setMyLocationEnabled(false);
        } else {
//            String yearMonth = DateFormater.YearMonthFormat.format(new Date());
//            getThreeMonthTask(yearMonth, "Middle", false);
            refreshUploadIconStatus();
            initLocation();
        }
    }
 
    @Override
    public void onMyLocationChange(Location location) {
 
        latitudeCurrent = location.getLatitude();
        longitudeCurrent = location.getLongitude();
 
    }
 
    @Override
    public void onDestroy() {
        super.onDestroy();
        aMap.setMyLocationEnabled(false);
        mv_main.onDestroy();
        for (Disposable d :
                disposables) {
            if (!d.isDisposed()) d.dispose();
        }
    }
 
    @Override
    public void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView.onResume (),重新绘制加载地图
        mv_main.onResume();
 
        refreshUploadIconStatus();
        if (!hidden) {
            initLocation();
        }
 
    }
 
    @Override
    public void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView.onPause (),暂停地图的绘制
        aMap.setMyLocationEnabled(false);
        mv_main.onPause();
    }
 
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState),保存地图当前的状态
        mv_main.onSaveInstanceState(outState);
    }
 
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == TAKE_PHOTO1 || requestCode == TAKE_PHOTO2 || requestCode == TAKE_PHOTO3 || requestCode == TAKE_CAMERA_PHOTO || requestCode == TAKE_GIT_PHOTO) {
            if (resultCode == RESULT_OK) {
                pathTempList.add(tempFileCurrent);
                if (requestCode == TAKE_PHOTO1 || requestCode == TAKE_PHOTO2 || requestCode == TAKE_PHOTO3) {
                    refreshPhotoClickListener(pathTempList);
                } else if (requestCode == TAKE_CAMERA_PHOTO) {
                    refreshNewPhotoClickListener();
                } else if (requestCode == TAKE_GIT_PHOTO) {
                    refreshNewGitPhotoClickListener();
                }
            }
        } else if (requestCode == PICK_PHOTO1 || requestCode == PICK_PHOTO2 || requestCode == PICK_PHOTO3 || requestCode == PICK_CAMERA_PHTOO || requestCode == PICK_GIT_PHOTO) {
            if (resultCode == RESULT_OK) {
 
                List<String> paths = data.getStringArrayListExtra(BaseTakePicActivity.EXTRA_SELECT_IMAGES);
 
//                Uri selectedImage = data.getData(); //获取系统返回的照片的Uri
//
//                String[] filePathColumn = {MediaStore.Images.Media.DATA};
//
//                Cursor cursor = getContext().getContentResolver().query(selectedImage,
//                        filePathColumn, null, null, null);//从系统表中查询指定Uri对应的照片
//                if (cursor!=null){
//                    cursor.moveToFirst();
//                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
//                    String picturePath = cursor.getString(columnIndex);  //获取照片路径
//                    oldFile = new File(picturePath);
//                    cursor.close();
//                }else {
//                    String a =selectedImage.getPath();
//                    oldFile = new File(a);
//                }
 
                for (String p : paths) {
                    File oldFile = new File(p);
                    File newFile = new File(Environment.getExternalStorageDirectory(), "FlightFeather/Temp/" + UUIDGenerator.generateUUID(4) + ".jpg");
                    if (!newFile.getParentFile().exists()) {
                        newFile.getParentFile().mkdirs();
                    }
                    try {
                        copyfile(oldFile, newFile);
                        pathTempList.add(newFile);
                    } catch (IOException e) {
                        e.printStackTrace();
                        Toast.makeText(getContext(), "复制文件失败", Toast.LENGTH_SHORT).show();
                    }
                }
                if (requestCode == PICK_PHOTO1 || requestCode == PICK_PHOTO2 || requestCode == PICK_PHOTO3) {
                    refreshPhotoClickListener(pathTempList);
                } else if (requestCode == PICK_CAMERA_PHTOO) {
                    refreshNewPhotoClickListener();
                } else if (requestCode == PICK_GIT_PHOTO) {
                    refreshNewGitPhotoClickListener();
                }
 
            }
        } else if (requestCode == PROBLEM_DETAIL) {
            showProblemList(OPEN_TYPE);
        } else if (requestCode == VIEW_CAMERA_PHOTO) {
            if (resultCode == RESULT_OK) {
                cameraDialog.dismiss();
                showCameraDialog();
            }
        } else if (requestCode == VIEW_EVIDENCE_TEMP_PHOTO || requestCode == VIEW_CAMERA_TEMP_PHOTO || requestCode == VIEW_GIT_TEMP_PHOTO) {
            if (resultCode == RESULT_OK) {
                int position = data.getIntExtra("position", -1);
                if (position > -1) {
                    if (pathTempList.get(position).exists()) {
                        pathTempList.get(position).delete();
                    }
                    pathTempList.remove(position);
                    if (requestCode == VIEW_EVIDENCE_TEMP_PHOTO) {
                        refreshPhotoClickListener(pathTempList);
                    } else if (requestCode == VIEW_CAMERA_TEMP_PHOTO) {
                        refreshNewPhotoClickListener();
                    } else if (requestCode == VIEW_GIT_TEMP_PHOTO) {
                        refreshNewGitPhotoClickListener();
                    }
 
                }
            }
        } else if (requestCode == SIGN) {
            //保存签字照片
            if (resultCode == RESULT_OK) {
                if (data != null) {
                    byte[] bis = data.getByteArrayExtra(Constant.KEY_INTENT_SIGHPIC);
                    Bitmap bitmap = BitmapFactory.decodeByteArray(bis, 0, bis.length);
                    java.util.Calendar calendar = java.util.Calendar.getInstance();
                    calendar.setTime(subTaskSelected.getExecutionstarttime());
                    String path = "FlightFeather/Photo/" + scenseCurrent.getDistrictname() + "/" + calendar.get(java.util.Calendar.YEAR) + "年" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月/" + (calendar.get(java.util.Calendar.MONTH) + 1) + "月" + calendar.get(java.util.Calendar.DAY_OF_MONTH) + "日/" + scenseCurrent.getName() + "/签字/";
                    String fileName1 = "签字.jpg";
                    File file = new File(Environment.getExternalStorageDirectory(), (path + fileName1));
                    file.getParentFile().mkdirs();
                    if (file.exists()) {
                        file.delete();
                    }
                    try {
                        FileOutputStream out = new FileOutputStream(file);
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 99, out);
                        out.flush();
                        out.close();
                        //保存到mediaFile数据库
                        Mediafile mediaFile = new Mediafile();
                        mediaFile.setGuid(UUIDGenerator.generate16ShortUUID());
                        mediaFile.setIguid(inspectionCurrent.getGuid());
                        mediaFile.setLongitude(longitudeCurrent);
                        mediaFile.setLatitude(latitudeCurrent);
                        mediaFile.setAddress(getScenceAddress());
                        mediaFile.setFiletype(1);
                        mediaFile.setBusinesstype("签字");
                        mediaFile.setBusinesstypeid(intToByte(6));
                        mediaFile.setPath(path);
                        mediaFile.setDescription(fileName1);
                        mediaFile.setSavetime(new Date());
                        mediaFile.setIschanged(false);
                        String exetension1 = scenseCurrent.getCitycode() + "/" + scenseCurrent.getDistrictcode() + "/" + DateFormatter.dateFormat2.format(calendar.getTime()) + "/" + scenseCurrent.getGuid() + "/";
                        mediaFile.setExtension1(exetension1);
                        mediaFile.setRemark("未上传");
                        mediafileDao.insert(mediaFile);
                        Toast.makeText(application, "保存成功", Toast.LENGTH_SHORT).show();
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                        Toast.makeText(application, "保存失败", Toast.LENGTH_SHORT).show();
                    } catch (IOException e) {
                        e.printStackTrace();
                        Toast.makeText(application, "保存失败", Toast.LENGTH_SHORT).show();
                    }
//
                }
            }
        } else if (requestCode == SUBTASK_MAP && resultCode == RESULT_OK) {
            int position = data.getIntExtra("position", -1);
            if (position > -1) {
                subTaskSelected = subTaskListCurrent.get(position);
                loadInspectionData(subTaskSelected.getStguid());
            }
        } else if (requestCode == CHOSE_LATLNG && resultCode == RESULT_OK) {
            Double longitude = data.getDoubleExtra("Longitude", 0);
            Double latitude = data.getDoubleExtra("Latitude", 0);
            if (longitude != 0 && latitude != 0) {
                if (scenseCurrent.getType().equals("工地")) {
                    scenseCurrent.setLongitude(longitude);
                    scenseCurrent.setLatitude(latitude);
                    if (siteCurrent != null) {
                        siteCurrent.setSitelatitude(latitude);
                        siteCurrent.setSitelongitude(longitude);
                        Call<ResponseBody> updateSite = inspectionService.updateSite(siteCurrent);
                        updateSite.enqueue(new Callback<ResponseBody>() {
                            @Override
                            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                                if (response.body() != null) {
                                    showToast("修改成功");
                                    if (siteCurrent != null) {
                                        siteDao.update(siteCurrent);
                                    }
                                    scenseDao.update(scenseCurrent);
                                    refreshProblemMarker();
                                } else if (response.errorBody() != null) {
                                    showToast("修改失败,请重试");
                                }
                            }
 
                            @Override
                            public void onFailure(Call<ResponseBody> call, Throwable t) {
                                showToast("网络连接错误");
                            }
                        });
                    } else {
                        Call<ResponseBody> updateScense = inspectionService.updateScense(scenseCurrent);
                        updateScense.enqueue(new Callback<ResponseBody>() {
                            @Override
                            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                                if (response.body() != null) {
                                    showToast("修改成功");
                                    scenseDao.update(scenseCurrent);
                                    refreshProblemMarker();
                                } else if (response.errorBody() != null) {
                                    showToast("修改失败,请重试");
                                }
                            }
 
                            @Override
                            public void onFailure(Call<ResponseBody> call, Throwable t) {
                                showToast("网络连接错误");
                            }
                        });
                    }
 
 
                } else {
                    scenseCurrent.setLongitude(longitude);
                    scenseCurrent.setLatitude(latitude);
 
                    Call<ResponseBody> updateScense = inspectionService.updateScense(scenseCurrent);
                    updateScense.enqueue(new Callback<ResponseBody>() {
                        @Override
                        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                            if (response.body() != null) {
                                showToast("修改成功");
                                scenseDao.update(scenseCurrent);
                                refreshProblemMarker();
                            } else if (response.errorBody() != null) {
                                showToast("修改失败,请重试");
                            }
                        }
 
                        @Override
                        public void onFailure(Call<ResponseBody> call, Throwable t) {
                            showToast("网络连接错误");
                        }
                    });
                }
 
            }
        } else if (requestCode == PROMISE) {
            refreshProblemMarker();
        } else if (requestCode == EDITE_SCENSE) {
            AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
            dialog.setTitle("需要重启");
            dialog.setMessage("app重启后才能更新修改后的场景信息,要现在退出吗?");
            dialog.setPositiveButton("退出", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    getActivity().finish();
                }
            });
            dialog.setNegativeButton("取消", null);
            dialog.show();
        }
 
    }
 
    //获取string类型的场景地址
    public String getScenceAddress() {
        String a = "";
        if (scenseCurrent != null) {
            if (scenseCurrent.getTownname() == null) {
                scenseCurrent.setTownname("");
            }
            a = scenseCurrent.getCityname() + scenseCurrent.getDistrictname() + scenseCurrent.getTownname() + scenseCurrent.getLocation();
        }
        return a;
    }
 
    //重命名文件
    public Boolean renameFile(File oldFile, File newFile) {
 
        if (!oldFile.getAbsolutePath().equals(newFile.getAbsolutePath())) {
            if (!oldFile.exists()) {
                showToast("旧文件不存在");
                return false;
            } else if (newFile.exists()) {
                showToast("新文件已存在");
                return false;
            } else {
                oldFile.renameTo(newFile);
                return true;
            }
        } else {
            showToast("新文件和旧文件名名字相同");
            return false;
        }
 
    }
 
    //复制文件
    public static void copyfile(File oldfile, File newfile) throws IOException {
        FileInputStream ins = new FileInputStream(oldfile);
        FileOutputStream out = new FileOutputStream(newfile);
        //自定义缓冲对象
        byte[] b = new byte[1024];
        int n = 0;
        while ((n = ins.read(b)) != -1) {
            out.write(b, 0, b.length);
        }
        ins.close();
        out.close();
 
        System.out.println("copy success");
    }
 
    public static byte intToByte(int x) {
        return (byte) x;
    }
 
    //显示toast
    public void showToast(String s) {
        Toast.makeText(getActivity(), s, Toast.LENGTH_SHORT).show();
    }
 
 
    //<editor-fold desc="加载弹出框开启关闭">
    private void showLoadingDialog() {
        if (dialog == null) {
            dialog = DialogUtil.createLoadingDialog(getActivity(), "");
        }
        if (!dialog.isShowing()) {
            dialog.show();
        }
    }
 
    private void loadingOver(boolean b) {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (dialog.isShowing()) {
                    dialog.dismiss();
                }
            }
        }, 500);
        if (b) {//加载成功
//            scrollView.setVisibility(View.VISIBLE);
//            no_data.setVisibility(View.GONE);
        } else {//加载失败
//            scrollView.setVisibility(View.GONE);
//            no_data.setVisibility(View.VISIBLE);
        }
    }
 
    @Override
    public void onCalendarOutOfRange(Calendar calendar) {
 
    }
 
    @Override
    public void onCalendarSelect(Calendar calendar, boolean isClick) {
 
    }
    //</editor-fold>
 
}