|
|
|
@ -2,18 +2,20 @@ package com.hmg.hmgDr
|
|
|
|
|
|
|
|
|
|
import android.app.Activity
|
|
|
|
|
import android.content.ComponentName
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.content.ServiceConnection
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.os.IBinder
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import android.view.inputmethod.InputMethodManager
|
|
|
|
|
import android.widget.EditText
|
|
|
|
|
import androidx.annotation.NonNull
|
|
|
|
|
import com.google.gson.GsonBuilder
|
|
|
|
|
import com.hmg.hmgDr.Model.GetSessionStatusModel
|
|
|
|
|
import com.hmg.hmgDr.Model.SessionStatusModel
|
|
|
|
|
import com.hmg.hmgDr.Service.VideoStreamContainerService
|
|
|
|
|
import com.hmg.hmgDr.ui.VideoCallResponseListener
|
|
|
|
|
import com.hmg.hmgDr.ui.fragment.VideoCallFragment
|
|
|
|
|
import io.flutter.embedding.android.FlutterFragmentActivity
|
|
|
|
|
import io.flutter.embedding.engine.FlutterEngine
|
|
|
|
|
import io.flutter.plugin.common.MethodCall
|
|
|
|
@ -21,7 +23,8 @@ import io.flutter.plugin.common.MethodChannel
|
|
|
|
|
import io.flutter.plugins.GeneratedPluginRegistrant
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler, VideoCallResponseListener {
|
|
|
|
|
class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
|
|
|
|
|
VideoCallResponseListener {
|
|
|
|
|
|
|
|
|
|
private val CHANNEL = "Dr.cloudSolution/videoCall"
|
|
|
|
|
private lateinit var methodChannel: MethodChannel
|
|
|
|
@ -33,8 +36,6 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
|
|
|
|
|
private var videoStreamService: VideoStreamContainerService? = null
|
|
|
|
|
private var bound = false
|
|
|
|
|
|
|
|
|
|
private var dialogFragment: VideoCallFragment? = null
|
|
|
|
|
|
|
|
|
|
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
|
|
|
|
GeneratedPluginRegistrant.registerWith(flutterEngine)
|
|
|
|
|
|
|
|
|
@ -62,14 +63,15 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
|
|
|
|
|
val doctorId = call.argument<Int>("DoctorId")
|
|
|
|
|
val patientName = call.argument<String>("patientName")
|
|
|
|
|
|
|
|
|
|
val sessionStatusModel = GetSessionStatusModel(VC_ID, tokenID, generalId, doctorId, patientName)
|
|
|
|
|
val sessionStatusModel =
|
|
|
|
|
GetSessionStatusModel(VC_ID, tokenID, generalId, doctorId, patientName)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
openVideoCall(apiKey, sessionId, token, appLang, baseUrl, sessionStatusModel)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
"closeVideoCall" -> {
|
|
|
|
|
dialogFragment?.onCallClicked()
|
|
|
|
|
videoStreamService?.closeVideoCall()
|
|
|
|
|
}
|
|
|
|
|
"onCallConnected" -> {
|
|
|
|
|
|
|
|
|
@ -80,7 +82,14 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun openVideoCall(apiKey: String?, sessionId: String?, token: String?, appLang: String?, baseUrl: String?, sessionStatusModel: GetSessionStatusModel) {
|
|
|
|
|
private fun openVideoCall(
|
|
|
|
|
apiKey: String?,
|
|
|
|
|
sessionId: String?,
|
|
|
|
|
token: String?,
|
|
|
|
|
appLang: String?,
|
|
|
|
|
baseUrl: String?,
|
|
|
|
|
sessionStatusModel: GetSessionStatusModel
|
|
|
|
|
) {
|
|
|
|
|
val arguments = Bundle()
|
|
|
|
|
arguments.putString("apiKey", apiKey)
|
|
|
|
|
arguments.putString("sessionId", sessionId)
|
|
|
|
@ -89,31 +98,14 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
|
|
|
|
|
arguments.putString("baseUrl", baseUrl)
|
|
|
|
|
arguments.putParcelable("sessionStatusModel", sessionStatusModel)
|
|
|
|
|
|
|
|
|
|
// showSoftKeyBoard(null)
|
|
|
|
|
// start service
|
|
|
|
|
serviceIntent = Intent(this@MainActivity, VideoStreamContainerService::class.java)
|
|
|
|
|
serviceIntent?.run {
|
|
|
|
|
putExtras(arguments)
|
|
|
|
|
startService(this)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoStreamContainerService.videoCallResponseListener = this
|
|
|
|
|
|
|
|
|
|
if (dialogFragment == null) {
|
|
|
|
|
val transaction = supportFragmentManager.beginTransaction()
|
|
|
|
|
dialogFragment = VideoCallFragment.newInstance(arguments)
|
|
|
|
|
dialogFragment?.let {
|
|
|
|
|
it.setCallListener(this)
|
|
|
|
|
it.isCancelable = true
|
|
|
|
|
if (it.isAdded){
|
|
|
|
|
it.dismiss()
|
|
|
|
|
}else {
|
|
|
|
|
it.show(transaction, "dialog")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (!dialogFragment!!.isVisible) {
|
|
|
|
|
val transaction = supportFragmentManager.beginTransaction()
|
|
|
|
|
dialogFragment!!.show(transaction, "dialog")
|
|
|
|
|
}
|
|
|
|
|
bindService()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
|
|
@ -143,9 +135,9 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
override fun onCallFinished(resultCode: Int, intent: Intent?) {
|
|
|
|
|
dialogFragment = null
|
|
|
|
|
// TODO uncomment it
|
|
|
|
|
|
|
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
|
|
/*if (resultCode == Activity.RESULT_OK) {
|
|
|
|
|
val result: SessionStatusModel? = intent?.getParcelableExtra("sessionStatusNotRespond")
|
|
|
|
|
val callResponse: HashMap<String, String> = HashMap()
|
|
|
|
|
|
|
|
|
@ -158,7 +150,7 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
this.result?.success(callResponse)
|
|
|
|
|
} catch (e : Exception){
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
Log.e("onVideoCallFinished", "${e.message}.")
|
|
|
|
|
}
|
|
|
|
|
} else if (resultCode == Activity.RESULT_CANCELED) {
|
|
|
|
@ -166,15 +158,14 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
|
|
|
|
|
callResponse["callResponse"] = "CallEnd"
|
|
|
|
|
try {
|
|
|
|
|
result?.success(callResponse)
|
|
|
|
|
} catch (e : Exception){
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
Log.e("onVideoCallFinished", "${e.message}.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun errorHandle(message: String) {
|
|
|
|
|
dialogFragment = null
|
|
|
|
|
// Toast.makeText(this, message, Toast.LENGTH_LONG).show()
|
|
|
|
|
*/
|
|
|
|
|
stopService(serviceIntent)
|
|
|
|
|
unbindService()
|
|
|
|
|
videoStreamService!!.serviceRunning = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun minimizeVideoEvent(isMinimize: Boolean) {
|
|
|
|
@ -188,23 +179,30 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
|
|
|
|
|
super.onBackPressed()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onStart() {
|
|
|
|
|
super.onStart()
|
|
|
|
|
bindService()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onStop() {
|
|
|
|
|
super.onStop()
|
|
|
|
|
unbindService()
|
|
|
|
|
}
|
|
|
|
|
// override fun onStart() {
|
|
|
|
|
// super.onStart()
|
|
|
|
|
// bindService()
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// override fun onStop() {
|
|
|
|
|
// super.onStop()
|
|
|
|
|
// unbindService()
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
private fun bindService() {
|
|
|
|
|
bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE)
|
|
|
|
|
serviceIntent?.run {
|
|
|
|
|
if (videoStreamService != null && !videoStreamService!!.serviceRunning){
|
|
|
|
|
startService(this)
|
|
|
|
|
}
|
|
|
|
|
bindService(this, serviceConnection, Context.BIND_AUTO_CREATE)
|
|
|
|
|
videoStreamService?.serviceRunning = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun unbindService() {
|
|
|
|
|
if (bound) {
|
|
|
|
|
gpsService.registerCallBack(null) // unregister
|
|
|
|
|
videoStreamService!!.videoCallResponseListener = null // unregister
|
|
|
|
|
videoStreamService!!.mActivity = null
|
|
|
|
|
unbindService(serviceConnection)
|
|
|
|
|
bound = false
|
|
|
|
|
}
|
|
|
|
@ -212,10 +210,12 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
|
|
|
|
|
|
|
|
|
|
private val serviceConnection: ServiceConnection = object : ServiceConnection {
|
|
|
|
|
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
|
|
|
|
|
val binder: VideoStreamContainerService.GPSBinder = service as GPSService.GPSBinder
|
|
|
|
|
gpsService = binder.getService()
|
|
|
|
|
val binder: VideoStreamContainerService.VideoStreamBinder =
|
|
|
|
|
service as VideoStreamContainerService.VideoStreamBinder
|
|
|
|
|
videoStreamService = binder.service
|
|
|
|
|
bound = true
|
|
|
|
|
gpsService.registerCallBack(this@YourActivity) // register
|
|
|
|
|
videoStreamService!!.videoCallResponseListener = this@MainActivity // register
|
|
|
|
|
videoStreamService!!.mActivity = this@MainActivity // register
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onServiceDisconnected(name: ComponentName?) {
|
|
|
|
@ -224,4 +224,18 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// code to hide soft keyboard
|
|
|
|
|
fun hideSoftKeyBoard(editBox: EditText?) {
|
|
|
|
|
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
|
|
|
|
imm.hideSoftInputFromWindow(editBox?.windowToken, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// code to show soft keyboard
|
|
|
|
|
private fun showSoftKeyBoard(editBox: EditText?) {
|
|
|
|
|
val inputMethodManager = this.getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
|
|
|
|
editBox?.requestFocus()
|
|
|
|
|
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|