18034727885
2026-09-18 1328a7b0b90825b1fd63bca8f7675e52df8b151d
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
package com.igo.user.ui
 
import android.content.Context
import android.content.Intent
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.viewpager2.widget.ViewPager2
import cn.sinata.xldutils.gone
import com.igo.user.R
import com.igo.user.ui.adapter.ShowPictureAdapter
 
//显示图片页
class ShowPictureActivity : TransparentStatusBarActivity() {
    private val title by lazy { intent.getStringExtra("title") }
    private val list by lazy { intent.getStringArrayListExtra("list") }
    private val index by lazy { intent.getIntExtra("index", 0) }
    private val adapter by lazy { ShowPictureAdapter() }
    private val tvLeftTitle by lazy { findViewById<TextView>(R.id.tv_left_title) }
    private val tvTitle by lazy { findViewById<TextView>(R.id.tv_title) }
    private val viewPager by lazy { findViewById<ViewPager2>(R.id.viewPager) }
    private val tvCount by lazy { findViewById<TextView>(R.id.tv_count) }
 
    companion object {
        //获取跳转此页面intent
        fun getIntent(
            context: Context,
            title: String,
            list: ArrayList<String>,
            index: Int = 0
        ): Intent {
            return Intent(context, ShowPictureActivity::class.java).apply {
                putExtra("title", title)
                putStringArrayListExtra("list", list)
                putExtra("index", index)
            }
        }
    }
 
    override fun setContentView() = R.layout.activity_show_picture
 
    override fun initView() {
        titleBar.gone()
        tvTitle.text = title
        viewPager.adapter = adapter
        viewPager.offscreenPageLimit = list?.size ?: 1
        adapter.setData(list ?: emptyList())
        tvCount.isVisible = (list?.size ?: 0) > 1
        runOnUiThread {
            viewPager.currentItem = index
            refreshCount(index)
        }
    }
 
    override fun initClick() {
        tvLeftTitle.setOnClickListener { finish() }
        viewPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                refreshCount(position)
            }
        })
    }
 
    //刷新下标
    private fun refreshCount(index: Int) {
        tvCount.text = "${index + 1}/${list?.size ?: 0}"
    }
}