riku
2022-02-18 d59d55575d913646b7a90fca651904ab889c6723
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
package cn.flightfeather.thirdappmodule.module.dataanalysis.rank
 
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import butterknife.ButterKnife
import butterknife.Unbinder
import cn.flightfeather.thirdappmodule.R
import cn.flightfeather.thirdappmodule.adapter.AllRecyclerViewAdapter
import cn.flightfeather.thirdappmodule.bean.vo.RankVo.TownRank
import kotlinx.android.synthetic.main.fragment_rank_content.*
import java.util.*
 
class TownRankContentFragment : Fragment() {
    private var townRanks: List<TownRank>? = null
    private var unbinder: Unbinder? = null
 
    //<editor-fold desc="lifecycle">
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (arguments != null) {
            townRanks = arguments!!.getSerializable(ARG_PARAM1) as List<TownRank>
        }
    }
 
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        val view = inflater.inflate(R.layout.fragment_rank_content, container, false)
        unbinder = ButterKnife.bind(this, view)
        return view
    }
 
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
    }
 
    override fun onDestroy() {
        super.onDestroy()
        if (unbinder != null) {
            unbinder!!.unbind()
        }
    }
 
    //</editor-fold>
    //<editor-fold desc="initView">
    var adapter: AllRecyclerViewAdapter<TownRank>? = null
    private fun initView() {
        adapter = object : AllRecyclerViewAdapter<TownRank>(townRanks, R.layout.item_problem_count, activity) {
            override fun bindView(holder: MyViewHolder, obj: TownRank, isSelected: Boolean, position: Int) {
                val rank = obj.rankNo
                holder.setText(R.id.text_name, obj.townName)
                    .setText(R.id.text_firstCount, getScore(obj.averageScore))
                    .setVisibility(R.id.text_secondCount, View.GONE)
                    .setVisibility(R.id.image_rank, View.GONE)
                    .setText(R.id.text_no, rank.toString())
                when (rank) {
                    1 -> holder.setImageResource(R.id.image_no, R.drawable.icon_rank_4)
                    2 -> holder.setImageResource(R.id.image_no, R.drawable.icon_rank_3)
                    3 -> holder.setImageResource(R.id.image_no, R.drawable.icon_rank_2)
                    else -> holder.setImageResource(R.id.image_no, R.drawable.icon_rank_5)
                }
            }
        }
        val lm = LinearLayoutManager(activity)
        lm.orientation = LinearLayoutManager.VERTICAL
        rv_content!!.layoutManager = lm
        rv_content!!.adapter = adapter
    }
 
    //</editor-fold>
    private fun getScore(score: Int): String {
        return if (score == -1) "未评分" else score.toString()
    }
 
    companion object {
        //<editor-fold desc="全局变量">
        private const val ARG_PARAM1 = "param1"
 
        // TODO: Rename and change types and number of parameters
        fun newInstance(params: ArrayList<TownRank?>?): TownRankContentFragment {
            val fragment = TownRankContentFragment()
            val args = Bundle()
            args.putSerializable(ARG_PARAM1, params)
            fragment.arguments = args
            return fragment
        }
    }
}