|
@@ -1,6 +1,7 @@
|
|
|
package com.swago.room.base
|
|
|
|
|
|
import android.graphics.Rect
|
|
|
+import android.text.TextUtils
|
|
|
import android.util.Log
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
@@ -9,15 +10,18 @@ import androidx.fragment.app.activityViewModels
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
import com.gyf.immersionbar.ImmersionBar
|
|
|
+import com.liulishuo.okdownload.DownloadListener
|
|
|
+import com.liulishuo.okdownload.DownloadTask
|
|
|
+import com.liulishuo.okdownload.core.breakpoint.BreakpointInfo
|
|
|
+import com.liulishuo.okdownload.core.cause.EndCause
|
|
|
+import com.liulishuo.okdownload.core.cause.ResumeFailedCause
|
|
|
import com.swago.baseswago.baseroom.IRoomActiveListener
|
|
|
import com.swago.baseswago.baseroom.RoomTimer
|
|
|
import com.swago.baseswago.baseroom.SwagoRoomManager
|
|
|
+import com.swago.baseswago.constant.UrlConstant
|
|
|
import com.swago.baseswago.fragment.BaseXFragment
|
|
|
import com.swago.baseswago.im.IRoomChat
|
|
|
-import com.swago.baseswago.model.live.gift.IMGiftModel
|
|
|
-import com.swago.baseswago.util.DpPxUtil
|
|
|
-import com.swago.baseswago.util.KeyboardUtils
|
|
|
-import com.swago.baseswago.util.NoDoubleClickListener
|
|
|
+import com.swago.baseswago.util.*
|
|
|
import com.swago.room.R
|
|
|
import com.swago.room.adapter.RoomChatAdapter
|
|
|
import com.swago.room.databinding.FragmentBaseComBinding
|
|
@@ -31,24 +35,30 @@ import com.swago.room.inter.IHeader
|
|
|
import com.swago.room.piaotiao.WaftManager
|
|
|
import com.swago.room.vm.MsgVm
|
|
|
import com.swago.room.vm.RoomVm
|
|
|
+import kotlinx.coroutines.Dispatchers
|
|
|
+import kotlinx.coroutines.GlobalScope
|
|
|
+import kotlinx.coroutines.launch
|
|
|
+import java.io.File
|
|
|
+import java.lang.Exception
|
|
|
import java.util.concurrent.CopyOnWriteArrayList
|
|
|
|
|
|
/**
|
|
|
*@date 2021/10/8 16:43
|
|
|
*description:
|
|
|
*/
|
|
|
-abstract class BaseComFragment<T:FragmentBaseComBinding> : BaseXFragment<T>(),IRoomActiveListener,
|
|
|
+abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
|
|
|
+ IRoomActiveListener,
|
|
|
RoomTimer.TimeTickListener {
|
|
|
|
|
|
val roomVm by activityViewModels<RoomVm>()
|
|
|
val msgVm by activityViewModels<MsgVm>()
|
|
|
|
|
|
- abstract val iHeader : IHeader
|
|
|
- abstract val iFooter : IFooter
|
|
|
+ abstract val iHeader: IHeader
|
|
|
+ abstract val iFooter: IFooter
|
|
|
|
|
|
- var dialog:SendMsgDialog? = null
|
|
|
- var gameDialog:GamePlayDialog? = null
|
|
|
- var msgListDialog:MessageListDialog? = null
|
|
|
+ var dialog: SendMsgDialog? = null
|
|
|
+ var gameDialog: GamePlayDialog? = null
|
|
|
+ var msgListDialog: MessageListDialog? = null
|
|
|
|
|
|
private val chatAdapter by lazy {
|
|
|
RoomChatAdapter()
|
|
@@ -95,19 +105,19 @@ abstract class BaseComFragment<T:FragmentBaseComBinding> : BaseXFragment<T>(),IR
|
|
|
binding.rv.adapter = chatAdapter
|
|
|
chatAdapter.setNewData(dataChatList)
|
|
|
context?.let {
|
|
|
- svgPlayerManager.init(it,binding.xSvgaPlayer)
|
|
|
+ svgPlayerManager.init(it, binding.xSvgaPlayer)
|
|
|
}
|
|
|
|
|
|
activity?.let {
|
|
|
- KeyboardUtils.registerSoftInputChangedListener(it.window,listener)
|
|
|
+ KeyboardUtils.registerSoftInputChangedListener(it.window, listener)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var listener = KeyboardUtils.OnSoftInputChangedListener {
|
|
|
- if (it==0){
|
|
|
- setChatRvPop(false,it)
|
|
|
- }else{
|
|
|
- setChatRvPop(true,it)
|
|
|
+ if (it == 0) {
|
|
|
+ setChatRvPop(false, it)
|
|
|
+ } else {
|
|
|
+ setChatRvPop(true, it)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -147,31 +157,33 @@ abstract class BaseComFragment<T:FragmentBaseComBinding> : BaseXFragment<T>(),IR
|
|
|
}
|
|
|
|
|
|
|
|
|
- private var keyboardUpRvLayoutParams:ViewGroup.LayoutParams? = null
|
|
|
- private var keyboardCloseRvLayoutParams:ViewGroup.LayoutParams? = null
|
|
|
- private fun setChatRvPop(isPopUp:Boolean,height:Int){
|
|
|
- if (isPopUp){
|
|
|
- if (keyboardUpRvLayoutParams == null){
|
|
|
- keyboardUpRvLayoutParams = ConstraintLayout.LayoutParams(0,DpPxUtil.dip2px(170f)).apply {
|
|
|
- bottomToBottom = R.id.cl
|
|
|
- startToStart = R.id.cl
|
|
|
- endToEnd = R.id.cl
|
|
|
- marginStart = DpPxUtil.dip2px(10f)
|
|
|
- marginEnd = DpPxUtil.dip2px(10f)
|
|
|
- bottomMargin = height + DpPxUtil.dip2px(55f)
|
|
|
- }
|
|
|
+ private var keyboardUpRvLayoutParams: ViewGroup.LayoutParams? = null
|
|
|
+ private var keyboardCloseRvLayoutParams: ViewGroup.LayoutParams? = null
|
|
|
+ private fun setChatRvPop(isPopUp: Boolean, height: Int) {
|
|
|
+ if (isPopUp) {
|
|
|
+ if (keyboardUpRvLayoutParams == null) {
|
|
|
+ keyboardUpRvLayoutParams =
|
|
|
+ ConstraintLayout.LayoutParams(0, DpPxUtil.dip2px(170f)).apply {
|
|
|
+ bottomToBottom = R.id.cl
|
|
|
+ startToStart = R.id.cl
|
|
|
+ endToEnd = R.id.cl
|
|
|
+ marginStart = DpPxUtil.dip2px(10f)
|
|
|
+ marginEnd = DpPxUtil.dip2px(10f)
|
|
|
+ bottomMargin = height + DpPxUtil.dip2px(55f)
|
|
|
+ }
|
|
|
}
|
|
|
binding.rv.layoutParams = keyboardUpRvLayoutParams
|
|
|
- }else{
|
|
|
- if (keyboardCloseRvLayoutParams == null){
|
|
|
- keyboardCloseRvLayoutParams = ConstraintLayout.LayoutParams(0,DpPxUtil.dip2px(170f)).apply {
|
|
|
- bottomToBottom = R.id.cl
|
|
|
- startToStart = R.id.cl
|
|
|
- endToEnd = R.id.cl
|
|
|
- marginStart = DpPxUtil.dip2px(10f)
|
|
|
- marginEnd = DpPxUtil.dip2px(10f)
|
|
|
- bottomMargin = DpPxUtil.dip2px(70f)
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ if (keyboardCloseRvLayoutParams == null) {
|
|
|
+ keyboardCloseRvLayoutParams =
|
|
|
+ ConstraintLayout.LayoutParams(0, DpPxUtil.dip2px(170f)).apply {
|
|
|
+ bottomToBottom = R.id.cl
|
|
|
+ startToStart = R.id.cl
|
|
|
+ endToEnd = R.id.cl
|
|
|
+ marginStart = DpPxUtil.dip2px(10f)
|
|
|
+ marginEnd = DpPxUtil.dip2px(10f)
|
|
|
+ bottomMargin = DpPxUtil.dip2px(70f)
|
|
|
+ }
|
|
|
}
|
|
|
binding.rv.layoutParams = keyboardCloseRvLayoutParams
|
|
|
}
|
|
@@ -187,23 +199,29 @@ abstract class BaseComFragment<T:FragmentBaseComBinding> : BaseXFragment<T>(),IR
|
|
|
SwagoRoomManager.removeListener(this)
|
|
|
}
|
|
|
|
|
|
- fun openSendMessageDialog(){
|
|
|
+ fun openSendMessageDialog() {
|
|
|
dialog = SendMsgDialog()
|
|
|
dialog?.addSenderMsgToRoomChatList = {
|
|
|
addChatMsgToRv(it)
|
|
|
}
|
|
|
- dialog?.show(childFragmentManager,"SendMsgDialog")
|
|
|
+ dialog?.show(childFragmentManager, "SendMsgDialog")
|
|
|
}
|
|
|
|
|
|
- fun openMessageListDialog(){
|
|
|
+ fun openMessageListDialog() {
|
|
|
msgListDialog = MessageListDialog()
|
|
|
- msgListDialog?.show(childFragmentManager,"MessageListDialog")
|
|
|
+ msgListDialog?.show(childFragmentManager, "MessageListDialog")
|
|
|
}
|
|
|
|
|
|
- fun openGameDialog(){
|
|
|
+ fun openGameDialog() {
|
|
|
+
|
|
|
SwagoRoomManager.iRoomInfo?.let {
|
|
|
- gameDialog = GamePlayDialog.newInstance(it.getGameUrl())
|
|
|
- gameDialog?.show(childFragmentManager,"GamePlayDialog")
|
|
|
+ val download = checkGameVersion(it.getGameType().toString(),it.getGameDownLoadUrl(),it.getGameVersion().toString())
|
|
|
+ if (download){
|
|
|
+ gameDialog = GamePlayDialog.newInstance("file://" + UrlConstant.appGameRootPath + File.separator + it.getGameType() + File.separator + "index.html")
|
|
|
+ }else{
|
|
|
+ gameDialog = GamePlayDialog.newInstance(it.getGameUrl())
|
|
|
+ }
|
|
|
+ gameDialog?.show(childFragmentManager, "GamePlayDialog")
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -235,7 +253,7 @@ abstract class BaseComFragment<T:FragmentBaseComBinding> : BaseXFragment<T>(),IR
|
|
|
}
|
|
|
|
|
|
override fun onTimeCount(time: Int) {
|
|
|
- if (time%30 == 0){
|
|
|
+ if (time % 30 == 0) {
|
|
|
SwagoRoomManager.iRoomInfo?.let {
|
|
|
roomVm.loadRoomData(it.getRoomId())
|
|
|
}
|
|
@@ -243,4 +261,98 @@ abstract class BaseComFragment<T:FragmentBaseComBinding> : BaseXFragment<T>(),IR
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private fun checkGameVersion(gameId: String, gamePackageUrl: String, gameVersionCode: String): Boolean {
|
|
|
+ if (gamePackageUrl.isEmpty() || gameVersionCode.isEmpty()) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ val zipNames = gamePackageUrl.split("/")
|
|
|
+ val gameName = zipNames.last()
|
|
|
+ if (TextUtils.isEmpty(UrlConstant.appGameRootPath) || !File(UrlConstant.appGameRootPath + File.separator + gameId).exists()) {
|
|
|
+ downLoadGamePackage(gameId, gamePackageUrl, gameVersionCode, gameName)
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ return if (!File(UrlConstant.appGameRootPath + File.separator + gameId + File.separator + gameName).exists()) {
|
|
|
+ downLoadGamePackage(gameId, gamePackageUrl, gameVersionCode, gameName)
|
|
|
+ false
|
|
|
+ } else {
|
|
|
+ val localGameVersionCode = SpUtil.readInt(gameId)
|
|
|
+ if (localGameVersionCode == 0 || (gameVersionCode.isEmpty() && localGameVersionCode < gameVersionCode.toInt())) {
|
|
|
+ downLoadGamePackage(gameId, gamePackageUrl, gameVersionCode, gameName)
|
|
|
+ false
|
|
|
+ } else {
|
|
|
+ true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun downLoadGamePackage(
|
|
|
+ gameId: String,
|
|
|
+ gamePackageUrl: String,
|
|
|
+ gameVersionCode: String,
|
|
|
+ name: String
|
|
|
+ ) {
|
|
|
+ val path = UrlConstant.appGameRootPath + File.separator + gameId
|
|
|
+ val file = File(path)
|
|
|
+ if (file.exists()) {
|
|
|
+ file.delete()
|
|
|
+ }
|
|
|
+ file.mkdirs()
|
|
|
+
|
|
|
+ val task = DownloadTask.Builder(gamePackageUrl,path,name).build()
|
|
|
+ task.enqueue(object:DownloadListener{
|
|
|
+ override fun taskStart(task: DownloadTask) {}
|
|
|
+
|
|
|
+ override fun connectTrialStart(
|
|
|
+ task: DownloadTask,
|
|
|
+ requestHeaderFields: MutableMap<String, MutableList<String>>
|
|
|
+ ) {}
|
|
|
+
|
|
|
+ override fun connectTrialEnd(
|
|
|
+ task: DownloadTask,
|
|
|
+ responseCode: Int,
|
|
|
+ responseHeaderFields: MutableMap<String, MutableList<String>>
|
|
|
+ ) {}
|
|
|
+
|
|
|
+ override fun downloadFromBeginning(
|
|
|
+ task: DownloadTask,
|
|
|
+ info: BreakpointInfo,
|
|
|
+ cause: ResumeFailedCause
|
|
|
+ ) {}
|
|
|
+
|
|
|
+ override fun downloadFromBreakpoint(task: DownloadTask, info: BreakpointInfo) {}
|
|
|
+
|
|
|
+ override fun connectStart(
|
|
|
+ task: DownloadTask,
|
|
|
+ blockIndex: Int,
|
|
|
+ requestHeaderFields: MutableMap<String, MutableList<String>>
|
|
|
+ ) {}
|
|
|
+
|
|
|
+ override fun connectEnd(
|
|
|
+ task: DownloadTask,
|
|
|
+ blockIndex: Int,
|
|
|
+ responseCode: Int,
|
|
|
+ responseHeaderFields: MutableMap<String, MutableList<String>>
|
|
|
+ ) {}
|
|
|
+
|
|
|
+ override fun fetchStart(task: DownloadTask, blockIndex: Int, contentLength: Long) {}
|
|
|
+
|
|
|
+ override fun fetchProgress(task: DownloadTask, blockIndex: Int, increaseBytes: Long) {}
|
|
|
+
|
|
|
+ override fun fetchEnd(task: DownloadTask, blockIndex: Int, contentLength: Long) {}
|
|
|
+
|
|
|
+ override fun taskEnd(task: DownloadTask, cause: EndCause, realCause: Exception?) {
|
|
|
+ GlobalScope.launch(Dispatchers.IO) {
|
|
|
+ val packagePath = path + File.separator + name
|
|
|
+ FileUtil.upZipFile(packagePath,path + File.separator)
|
|
|
+ SpUtil.putInt(gameId, gameVersionCode.toInt())
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
}
|