Commit e22086b1 by fengquan

fix: 非wifi状态下播放视频弹框

parent 83a495c5
package com.yidianling.consultant.preview
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.net.Uri
......@@ -17,6 +18,8 @@ import androidx.fragment.app.Fragment
import com.dou361.ijkplayer.widget.IjkVideoView
import com.ydl.ydlcommon.ui.Loading.close
import com.ydl.ydlcommon.ui.Loading.show
import com.ydl.ydlcommon.view.dialog.CommonDialog
import com.yidianling.common.tools.RxNetTool
import com.yidianling.common.tools.ToastUtil
import com.yidianling.consultant.R
import com.yidianling.consultant.preview.SmoothImageView.*
......@@ -49,6 +52,8 @@ class BasePhotoFragment : Fragment() {
private var isPrepared = false
private var ivImg: ImageView? = null
private val keySp = "check_network_continue"
@Volatile
private var isTouch = false
private var isCompletion = false
......@@ -242,15 +247,7 @@ class BasePhotoFragment : Fragment() {
true
}
ivPlay!!.setOnClickListener {
if (!isPrepared) {
loading!!.visibility = VISIBLE
}
ivImg!!.visibility = GONE
ivPlay!!.visibility = GONE
startTiming()
videoView?.visibility = VISIBLE
videoView!!.start()
isCompletion = false
checkNetwork()
}
videoContainer!!.setOnClickListener {
if (videoView!!.isPlaying) {
......@@ -329,6 +326,51 @@ class BasePhotoFragment : Fragment() {
imageView!!.setTransformOutListener { (activity as GPreviewActivity?)!!.transformOut() }
}
internal fun checkNetwork() {
val lastCheck =
context?.getSharedPreferences("temp_test", Context.MODE_PRIVATE)?.getLong(keySp, 0)
val duration = System.currentTimeMillis() - lastCheck!!
if (!RxNetTool.isWifi(requireActivity()!!) && duration > 24 * 60 * 60 * 1000) {
val dialog = CommonDialog.create(context)
.setTitle("提示")
.setMessage("当前处于非wifi环境下,播放会消耗流量,确定继续播放?")
.setLeftOnclick("继续播放") {
if (!isPrepared) {
loading!!.visibility = VISIBLE
}
ivImg!!.visibility = GONE
ivPlay!!.visibility = GONE
startTiming()
videoView?.visibility = VISIBLE
videoView!!.start()
isCompletion = false
context?.getSharedPreferences("temp_test", Context.MODE_PRIVATE)?.edit()
?.putLong(keySp, System.currentTimeMillis())?.apply()
}
.setLeftButton_color(R.color.platform_but_text_color_selected)
.setRightButton_color(R.color.platform_text_bright_color)
.setRightClick("取消") {
}
.setCancelAble(true)
dialog.setOnCancelListener {
dialog.dismiss()
}
dialog.show()
} else {
if (!isPrepared) {
loading!!.visibility = VISIBLE
}
ivImg!!.visibility = GONE
ivPlay!!.visibility = GONE
startTiming()
videoView?.visibility = VISIBLE
videoView!!.start()
isCompletion = false
}
}
fun transformIn() {
assert(imageView != null)
imageView!!.transformIn { rootView!!.setBackgroundColor(Color.BLACK) }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment