|
@@ -0,0 +1,102 @@
|
|
|
+package com.quansu.lookimg
|
|
|
+
|
|
|
+import android.os.Bundle
|
|
|
+import android.view.KeyEvent
|
|
|
+import android.view.View
|
|
|
+import androidx.viewpager.widget.ViewPager
|
|
|
+import com.quansu.lookimg.adapter.ImagePagerAdapter
|
|
|
+import com.quansu.lookimg.databinding.ActivityImagepagerBinding
|
|
|
+import com.quansu.lookimg.vmodel.ImagePagerVModel
|
|
|
+import com.ysnows.base.base.BActivity
|
|
|
+import java.util.*
|
|
|
+
|
|
|
+/**
|
|
|
+ *Created by shihuiyun
|
|
|
+ *on 2020/9/18
|
|
|
+ */
|
|
|
+class ImagePagerActivity : BActivity<ImagePagerVModel, ActivityImagepagerBinding>() {
|
|
|
+
|
|
|
+
|
|
|
+ var adapter: ImagePagerAdapter? = null
|
|
|
+ var urls: ArrayList<String>? = null
|
|
|
+ private var position = 0
|
|
|
+
|
|
|
+
|
|
|
+ override fun __before() {
|
|
|
+ super.__before()
|
|
|
+
|
|
|
+ urls = intent.extras.getStringArrayList("urls")
|
|
|
+ position = intent.extras.getInt("position")
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ override fun initCreate(savedInstanceState: Bundle?) {
|
|
|
+ super.initCreate(savedInstanceState)
|
|
|
+ initViewPager()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private fun initViewPager() {
|
|
|
+ adapter = ImagePagerAdapter(supportFragmentManager, urls!!)
|
|
|
+ binding.pager.adapter = adapter
|
|
|
+
|
|
|
+ val text: CharSequence = getString(R.string.viewpager_indicator, 1, binding.pager.adapter!!.count)
|
|
|
+ if (urls!!.size == 1) binding.indicator.visibility = View.GONE else binding.indicator.visibility = View.VISIBLE
|
|
|
+
|
|
|
+
|
|
|
+ vm.text.value = text.toString()
|
|
|
+
|
|
|
+
|
|
|
+ binding.pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
|
|
+ override fun onPageScrollStateChanged(state: Int) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onPageSelected(position: Int) {
|
|
|
+
|
|
|
+ val text: CharSequence = getString(R.string.viewpager_indicator, position + 1, binding.pager.adapter!!.count)
|
|
|
+ vm.text.value = text.toString()
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
+ binding.pager.currentItem = position
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun vmClass(): Class<ImagePagerVModel> {
|
|
|
+ return ImagePagerVModel::class.java
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ override fun binding(): ActivityImagepagerBinding {
|
|
|
+ return ActivityImagepagerBinding.inflate(layoutInflater)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
|
|
+ if (keyCode == KeyEvent.KEYCODE_BACK && event!!.action == KeyEvent.ACTION_UP) {
|
|
|
+ finish()
|
|
|
+ //不执行父类点击事件
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return super.onKeyDown(keyCode, event)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ override fun title(): String? {
|
|
|
+ return null
|
|
|
+ }
|
|
|
+
|
|
|
+}
|