删除多余文件2
This commit is contained in:
parent
78e546310d
commit
9026dff6b4
|
|
@ -33,8 +33,6 @@ import com.cncat.vpn.service.ProfileManager
|
|||
import com.yingmao.clash.conf.BZYConstants
|
||||
import com.yingmao.clash.conf.Conf
|
||||
import com.yingmao.clash.entity.ClashNodebBean
|
||||
import com.yingmao.clash.fragment.NewAccFragment
|
||||
import com.yingmao.clash.fragment.NewAccFragment.Companion.CHECK_NODE_RESULT_CODE
|
||||
import com.yingmao.clash.remote.Resource
|
||||
import com.cncat.vpn.service.model.Profile
|
||||
import com.cncat.vpn.service.remote.IProfileManager
|
||||
|
|
@ -98,7 +96,7 @@ class ChangeNodeActivity : BaseActivity(), View.OnClickListener {
|
|||
|
||||
override fun onBackPressed() {
|
||||
intent.putExtra(BZYConstants.EXTRA_KEY_IS_RUNING, is_runing)
|
||||
setResult(CHECK_NODE_RESULT_CODE, intent)
|
||||
setResult(HomeFragment.CHECK_NODE_RESULT_CODE, intent)
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
|
|
@ -470,7 +468,7 @@ class ChangeNodeActivity : BaseActivity(), View.OnClickListener {
|
|||
val intent = Intent()
|
||||
intent.putExtra(BZYConstants.MMKV_KEY_SELECT_NODE_NAME, profile.name)
|
||||
intent.putExtra(BZYConstants.EXTRA_KEY_IS_RUNING, is_runing)
|
||||
setResult(CHECK_NODE_RESULT_CODE, intent)
|
||||
setResult(HomeFragment.CHECK_NODE_RESULT_CODE, intent)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,13 +31,12 @@ import com.cncat.vpn.common.log.Log
|
|||
import com.yingmao.clash.conf.BZYConstants
|
||||
import com.yingmao.clash.conf.Conf
|
||||
import com.yingmao.clash.entity.ClashNodebBean
|
||||
import com.yingmao.clash.fragment.NewAccFragment
|
||||
import com.yingmao.clash.fragment.NewAccFragment.Companion.CHECK_NODE_RESULT_CODE
|
||||
import com.yingmao.clash.remote.Resource
|
||||
import com.cncat.vpn.service.model.Profile
|
||||
import com.cncat.vpn.service.remote.IProfileManager
|
||||
import com.cncat.vpn.service.remote.IRemoteService
|
||||
import com.yingmao.clash.app.MainApplication
|
||||
import com.yingmao.clash.fragment.home.HomeFragment
|
||||
import com.yingmao.clash.util.Utils
|
||||
import com.yingmao.clash.view.RxToast
|
||||
import com.yingmao.clash.view.adapter.NodeListAdapter
|
||||
|
|
@ -92,7 +91,7 @@ class ChangeNodeTzActivity : BaseActivity(), View.OnClickListener {
|
|||
|
||||
override fun onBackPressed() {
|
||||
intent.putExtra(BZYConstants.EXTRA_KEY_IS_RUNING, is_runing)
|
||||
setResult(CHECK_NODE_RESULT_CODE, intent)
|
||||
setResult(HomeFragment.CHECK_NODE_RESULT_CODE, intent)
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
|
|
@ -337,7 +336,7 @@ class ChangeNodeTzActivity : BaseActivity(), View.OnClickListener {
|
|||
|
||||
val reloadLock = Semaphore(10)
|
||||
private fun setPing() {
|
||||
if (!NewAccFragment.clashRunning) {
|
||||
if (!HomeFragment.clashRunning) {
|
||||
RxToast.info("请先开启加速后,再进行测试.");
|
||||
return
|
||||
}
|
||||
|
|
@ -430,7 +429,7 @@ class ChangeNodeTzActivity : BaseActivity(), View.OnClickListener {
|
|||
val intent = Intent()
|
||||
intent.putExtra(BZYConstants.MMKV_KEY_SELECT_NODE_NAME, "自动选择")
|
||||
intent.putExtra(BZYConstants.EXTRA_KEY_IS_RUNING, is_runing)
|
||||
setResult(CHECK_NODE_RESULT_CODE, intent)
|
||||
setResult(HomeFragment.CHECK_NODE_RESULT_CODE, intent)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ import com.yingmao.clash.R
|
|||
import com.yingmao.clash.base.BaseActivity
|
||||
import com.cncat.vpn.common.log.Log
|
||||
import com.yingmao.clash.conf.BZYConstants
|
||||
import com.yingmao.clash.fragment.NewAccFragment
|
||||
import com.cncat.vpn.service.model.AccessControlMode
|
||||
import com.yingmao.clash.fragment.home.HomeFragment
|
||||
import com.yingmao.clash.view.RxToast
|
||||
import com.yingmao.clash.view.popwindow.CommonPopupWindow
|
||||
import okio.ByteString.Companion.encode
|
||||
|
|
@ -120,7 +120,7 @@ class ProxyModeActivity : BaseActivity() {
|
|||
}
|
||||
}
|
||||
llApplicationMode.setOnClickListener {
|
||||
if (NewAccFragment.clashRunning) {
|
||||
if (HomeFragment.clashRunning) {
|
||||
RxToast.info("请关闭加速后再选择.");
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
|
@ -207,7 +207,7 @@ class ProxyModeActivity : BaseActivity() {
|
|||
|
||||
when (proxyMode) {
|
||||
ProxyMode.PAC -> {
|
||||
NewAccFragment.isGlo = false
|
||||
HomeFragment.isGlo = false
|
||||
radio_but_global.isChecked = false
|
||||
radio_but_pac.isChecked = true
|
||||
radioApplicationMode.isChecked = false
|
||||
|
|
@ -218,7 +218,7 @@ class ProxyModeActivity : BaseActivity() {
|
|||
}
|
||||
|
||||
ProxyMode.GLOBAL -> {
|
||||
NewAccFragment.isGlo = true
|
||||
HomeFragment.isGlo = true
|
||||
radio_but_global.isChecked = true
|
||||
radio_but_pac.isChecked = false
|
||||
radioApplicationMode.isChecked = false
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ import com.yingmao.clash.base.BaseActivity
|
|||
import com.yingmao.clash.conf.BZYConstants
|
||||
import com.yingmao.clash.conf.Conf
|
||||
import com.yingmao.clash.entity.CheckLoginRsp
|
||||
import com.yingmao.clash.fragment.NewAccFragment
|
||||
import com.yingmao.clash.fragment.home.HomeFragment
|
||||
import com.yingmao.clash.fragment.setting.SettingFragment
|
||||
import com.yingmao.clash.listener.DownLoadListener
|
||||
|
|
|
|||
|
|
@ -1,890 +0,0 @@
|
|||
package com.yingmao.clash.fragment
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.ResultReceiver
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageView
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import androidx.activity.result.contract.ActivityResultContract
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity.RESULT_OK
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.cncat.vpn.common.constants.Intents
|
||||
import com.cncat.vpn.common.log.Log
|
||||
import com.cncat.vpn.core.Clash
|
||||
import com.cncat.vpn.core.model.TunnelState
|
||||
import com.orhanobut.logger.Logger
|
||||
import com.tencent.mmkv.MMKV
|
||||
import com.yingmao.clash.R
|
||||
import com.yingmao.clash.act.ChangeNodeActivity
|
||||
import com.yingmao.clash.act.ProxyModeActivity
|
||||
import com.yingmao.clash.act.UIMainActivity
|
||||
import com.yingmao.clash.conf.BZYConstants
|
||||
import com.yingmao.clash.conf.Conf
|
||||
import com.yingmao.clash.entity.ClashNodebBean
|
||||
import com.yingmao.clash.listener.AsyncCallBackListener
|
||||
import com.yingmao.clash.net.http.HttpReqType
|
||||
import com.yingmao.clash.net.http.HttpStatus
|
||||
import com.yingmao.clash.net.http.entity.AppStartupStatus
|
||||
import com.yingmao.clash.service.ConnectionService
|
||||
import com.yingmao.clash.util.ActivityResultLifecycle
|
||||
import com.yingmao.clash.util.CommonUtils
|
||||
import com.yingmao.clash.util.startClashService
|
||||
import com.yingmao.clash.util.stopClashService
|
||||
import com.yingmao.clash.view.RxToast
|
||||
import com.yingmao.clash.view.dialog.RxDialogShapeLoading
|
||||
import com.yingmao.clash.view.dialog.RxDialogSureCancel
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.Response
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
|
||||
class NewAccFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatchers.IO),
|
||||
View.OnClickListener {
|
||||
|
||||
|
||||
companion object {
|
||||
const val REQUEST_CONNECT = 1
|
||||
const val CHECK_NODE_REQUEST_CODE = 2
|
||||
const val CHECK_NODE_RESULT_CODE = 3
|
||||
|
||||
const val Proxy_Mode_REQUEST_CODE = 4
|
||||
const val Clash_Started = 11
|
||||
const val Clash_Starting = 22
|
||||
const val Clash_Stop = 33
|
||||
public var currNodeJsonA: String? = null
|
||||
var isGlo: Boolean = false
|
||||
var clashRunning: Boolean = false
|
||||
|
||||
}
|
||||
|
||||
lateinit var accelerateViewModel: AccelerateViewModel
|
||||
private lateinit var rxDialogShapeLoading: RxDialogShapeLoading
|
||||
private lateinit var rxDialogSureCancel: RxDialogSureCancel
|
||||
private lateinit var accelerateIv: ImageView
|
||||
private lateinit var tv_proxy_model: TextView
|
||||
private lateinit var tv_end_time: TextView
|
||||
private lateinit var iv_proxy_mode: ImageView
|
||||
private lateinit var nodeNameTv: TextView
|
||||
private lateinit var countryIv: ImageView
|
||||
|
||||
// var currentNode: Profile? = null
|
||||
private var reConnection = false
|
||||
private var connectId=-1
|
||||
|
||||
override fun init(
|
||||
titleBarRl: RelativeLayout,
|
||||
backIv: ImageView,
|
||||
moreTv: TextView,
|
||||
titleTv: TextView,
|
||||
container: FrameLayout,
|
||||
) {
|
||||
titleBarRl.visibility = View.VISIBLE
|
||||
backIv.visibility = View.INVISIBLE
|
||||
moreTv.visibility = View.INVISIBLE
|
||||
titleTv.visibility = View.INVISIBLE
|
||||
val accelerateFragmentView = View.inflate(
|
||||
activity, R.layout.fragment_accelerate, null
|
||||
)
|
||||
|
||||
initViews(accelerateFragmentView)
|
||||
container.addView(accelerateFragmentView)
|
||||
}
|
||||
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
Logger.d("onActivityCreated")
|
||||
accelerateViewModel = ViewModelProvider(this).get(AccelerateViewModel::class.java)
|
||||
observe(this, accelerateViewModel)
|
||||
initSS()
|
||||
// initSub()
|
||||
getNodesStatus()
|
||||
// accelerateViewModel.getAirNodes()
|
||||
// accelerateViewModel.appCheck()
|
||||
val token = MMKV.defaultMMKV().decodeString(
|
||||
BZYConstants.MMKV_KEY_TOKEN
|
||||
).toString()
|
||||
// Log.d("token==>$token")
|
||||
}
|
||||
|
||||
|
||||
private fun initSS() {
|
||||
val intentFilter = IntentFilter()
|
||||
intentFilter.addAction(Intents.ACTION_CLASH_STARTED)
|
||||
intentFilter.addAction(Intents.ACTION_CLASH_STOPPED)
|
||||
intentFilter.addAction(Intents.ACTION_CLASH_REQUEST_STOP)
|
||||
intentFilter.addAction(Intents.ACTION_Glo_Mode)
|
||||
intentFilter.addAction(Intents.ACTION_OVERRIDE_CHANGED)
|
||||
if (Build.VERSION.SDK_INT >= 34 && requireContext().applicationInfo.targetSdkVersion >= 34) {
|
||||
requireContext().registerReceiver(
|
||||
ClashBP(), intentFilter, Context.RECEIVER_EXPORTED
|
||||
)
|
||||
} else {
|
||||
requireContext().registerReceiver(
|
||||
ClashBP(), intentFilter
|
||||
)
|
||||
}
|
||||
// context?.registerReceiver(
|
||||
// ClashBP(), intentFilter
|
||||
// )
|
||||
}
|
||||
|
||||
private fun initViews(view: View) {
|
||||
val checkNodeRl = view.findViewById<RelativeLayout>(R.id.rl_check_node)
|
||||
nodeNameTv = view.findViewById(R.id.tv_node)
|
||||
countryIv = view.findViewById(R.id.iv_country)
|
||||
tv_end_time = view.findViewById(R.id.tv_end_time)
|
||||
|
||||
|
||||
//不记住
|
||||
// currentNode = MMKV.defaultMMKV().decodeParcelable(
|
||||
// BZYConstants.MMKV_KEY_CURRENT_NODE,
|
||||
// Node::class.java
|
||||
// )
|
||||
// setNodeNameAndImg(currentNode)
|
||||
|
||||
checkNodeRl.setOnClickListener(this)
|
||||
accelerateIv = view.findViewById(R.id.iv_accelerate)
|
||||
accelerateIv.setOnClickListener(this)
|
||||
tv_proxy_model = view.findViewById(R.id.tv_proxy_model)
|
||||
iv_proxy_mode = view.findViewById(R.id.iv_proxy_mode)
|
||||
view.findViewById<View>(R.id.ll_proxy_mode).setOnClickListener {
|
||||
// startActivity(Intent(activity, ProxyModeActivity::class.java))
|
||||
val intent = Intent(activity, ProxyModeActivity::class.java)
|
||||
startActivityForResult(intent, Proxy_Mode_REQUEST_CODE)
|
||||
}
|
||||
var selected_name =
|
||||
MMKV.defaultMMKV().decodeString(BZYConstants.NODE_SELECTED_NAME_KEY, "");
|
||||
if (!TextUtils.isEmpty(selected_name)) {
|
||||
setNodeNameAndImg(selected_name!!)
|
||||
}
|
||||
view.findViewById<Button>(R.id.recharge_but).setOnClickListener {
|
||||
goNewRecharge()
|
||||
}
|
||||
//备用充值
|
||||
view.findViewById<Button>(R.id.backupRecharge).setOnClickListener {
|
||||
goRechargeWeb()
|
||||
}
|
||||
view.findViewById<ImageView>(R.id.refresh_expire_iv).setOnClickListener {
|
||||
updateUserInfo()
|
||||
}
|
||||
setExpireDate()
|
||||
setProxyModeView(UIMainActivity.newMainActGlo)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
// val isGlobal = MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
|
||||
lifecycleScope.launch {
|
||||
// if (isGlobal) {
|
||||
// iv_proxy_mode.setImageResource(R.drawable.ic_s_global)
|
||||
// tv_proxy_model.text = "全局模式"
|
||||
// } else {
|
||||
// iv_proxy_mode.setImageResource(R.drawable.smart)
|
||||
// tv_proxy_model.text = "智能模式"
|
||||
// }
|
||||
Log.d("clashRunning==>$clashRunning")
|
||||
if (clashRunning) {
|
||||
stateChanged(Clash_Started, false)
|
||||
} else {
|
||||
stateChanged(Clash_Stop, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// protected val uiStore by lazy { MainApplication.getApp()?.applicationContext?.let { UiStore(it) } }
|
||||
override fun onClick(v: View?) {
|
||||
when (v?.id) {
|
||||
R.id.rl_check_node -> {
|
||||
if (checkExpire()) {
|
||||
if (isAdded) {
|
||||
RxToast.info(requireActivity().resources.getString(R.string.AccountExpired))
|
||||
}
|
||||
return
|
||||
}
|
||||
val intent = Intent(CommonUtils.getApp(), ChangeNodeActivity::class.java)
|
||||
if (!TextUtils.isEmpty(UIMainActivity.newUuid)) {
|
||||
intent.putExtra(BZYConstants.MMKV_KEY_CURRENT_NODE, UIMainActivity.newUuid)
|
||||
intent.putExtra(BZYConstants.EXTRA_KEY_IS_RUNING, clashRunning)
|
||||
}
|
||||
startActivityForResult(intent, CHECK_NODE_REQUEST_CODE)
|
||||
}
|
||||
|
||||
R.id.iv_accelerate -> {
|
||||
// Logger.i("mState:${mState}")
|
||||
|
||||
if (clashRunning) {
|
||||
val rxDialogSureCancel = RxDialogSureCancel(activity)
|
||||
if (isAdded) {
|
||||
rxDialogSureCancel.setContent(requireActivity().resources.getString(R.string.StopAccelerating))
|
||||
}
|
||||
rxDialogSureCancel.setCancelListener {
|
||||
rxDialogSureCancel.cancel()
|
||||
}
|
||||
rxDialogSureCancel.setSureListener {
|
||||
// Core.stopService()
|
||||
stop_u_timer()
|
||||
stopClash()
|
||||
rxDialogSureCancel.cancel()
|
||||
reConnection = false
|
||||
Log.d("NewAccFragment connectId:::${connectId}")
|
||||
if(connectId!=-1){
|
||||
accelerateViewModel.appStopStatus(connectId)
|
||||
}
|
||||
|
||||
}
|
||||
rxDialogSureCancel.show()
|
||||
|
||||
} else {
|
||||
|
||||
startClash()
|
||||
|
||||
// connectVPNSS(currentNode)
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun selectActive() {
|
||||
|
||||
}
|
||||
|
||||
public fun stopClash() {
|
||||
context?.stopClashService()
|
||||
}
|
||||
|
||||
|
||||
private fun startClash() {
|
||||
if (checkExpire()) {
|
||||
if (isAdded) {
|
||||
RxToast.info(resources.getString(R.string.AccountExpired))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
// if (!NewMainActivity.isSubed) {
|
||||
// if(isAdded){
|
||||
// RxToast.info(resources.getString(R.string.Initializing))
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
launch {
|
||||
UIMainActivity.profileBinder?.let { pm ->
|
||||
val active = pm.queryActive()
|
||||
if (active == null) {
|
||||
com.cncat.vpn.common.log.Log.d("startClash: 未选择")
|
||||
val pro = pm.queryAll().find {
|
||||
it.name == Conf.getClashConfName(this@NewAccFragment.context)
|
||||
}
|
||||
|
||||
pro?.let { profile ->
|
||||
com.cncat.vpn.common.log.Log.d("new setactive name " + profile.name)
|
||||
pm.setActive(profile)
|
||||
|
||||
UIMainActivity.newUuid = profile.uuid.toString();
|
||||
UIMainActivity.isSubed = true
|
||||
} ?: run {
|
||||
//为空的情况下选择第一个
|
||||
pm.queryAll().forEach { profile ->
|
||||
pm.setActive(profile)
|
||||
|
||||
UIMainActivity.newUuid = profile.uuid.toString();
|
||||
UIMainActivity.isSubed = true
|
||||
return@forEach
|
||||
}
|
||||
}
|
||||
delay(500)
|
||||
}
|
||||
|
||||
val vpnRequest = context?.startClashService()
|
||||
try {
|
||||
start_u_timer()
|
||||
if (vpnRequest != null) {
|
||||
val result = startActivityForResult(
|
||||
ActivityResultContracts.StartActivityForResult(), vpnRequest
|
||||
)
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
stateChanged(Clash_Starting, true)
|
||||
context?.startClashService()
|
||||
accelerateViewModel.appStartupStatus()
|
||||
// clashRunning = true
|
||||
}
|
||||
}else{
|
||||
accelerateViewModel.appStartupStatus()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
stop_u_timer()
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private val nextRequestKey = AtomicInteger(0)
|
||||
private suspend fun <I, O> startActivityForResult(
|
||||
contracts: ActivityResultContract<I, O>,
|
||||
input: I,
|
||||
): O = withContext(Dispatchers.Main) {
|
||||
val requestKey = nextRequestKey.getAndIncrement().toString()
|
||||
|
||||
ActivityResultLifecycle().use { lifecycle, start ->
|
||||
suspendCoroutine { c ->
|
||||
activity?.activityResultRegistry?.register(requestKey, lifecycle, contracts) {
|
||||
c.resume(it)
|
||||
}.apply { start() }?.launch(input)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner class ClashBP : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
com.cncat.vpn.common.log.Log.i("action==>" + intent?.action)
|
||||
when (intent?.action) {
|
||||
Intents.ACTION_CLASH_STARTED -> {
|
||||
if (::rxDialogShapeLoading.isInitialized) {
|
||||
rxDialogShapeLoading.cancel()
|
||||
}
|
||||
accelerateIv.isSelected = true
|
||||
clashRunning = true
|
||||
|
||||
// MMKV.defaultMMKV().encode(
|
||||
// BZYConstants.MMKV_KEY_CURRENT_NODE,
|
||||
// currentNode
|
||||
// )
|
||||
// setNodeNameAndImg(currentNode!!.name)
|
||||
if (isAdded) {
|
||||
RxToast.success(resources.getString(R.string.AccelerateSuccess))
|
||||
}
|
||||
checkGlo()
|
||||
}
|
||||
|
||||
Intents.ACTION_CLASH_STOPPED -> {
|
||||
if (::rxDialogShapeLoading.isInitialized) {
|
||||
rxDialogShapeLoading.cancel()
|
||||
}
|
||||
accelerateIv.isSelected = false
|
||||
clashRunning = false
|
||||
stop_u_timer()
|
||||
}
|
||||
|
||||
Intents.ACTION_CLASH_REQUEST_STOP -> {
|
||||
// clashRunning = false
|
||||
com.cncat.vpn.common.log.Log.d("ACTION_CLASH_REQUEST_STOP")
|
||||
if (::rxDialogShapeLoading.isInitialized) {
|
||||
if (!rxDialogShapeLoading.isShowing) {
|
||||
if (isAdded) {
|
||||
rxDialogShapeLoading.setMessage(resources.getString(R.string.Disconnecting))
|
||||
}
|
||||
rxDialogShapeLoading.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Intents.ACTION_Glo_Mode -> {
|
||||
var mode = intent.getBooleanExtra("mode", false)
|
||||
Log.d("ACTION_Glo_Mode mode==>${mode}")
|
||||
isGlo = mode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun getNodesStatus() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun stateChanged(state: Int, isShowToast: Boolean) {
|
||||
Logger.i("!!!!!!!!!!:${state}")
|
||||
|
||||
when (state) {
|
||||
Clash_Started -> {
|
||||
if (::rxDialogShapeLoading.isInitialized) {
|
||||
rxDialogShapeLoading.cancel()
|
||||
}
|
||||
accelerateIv.isSelected = true
|
||||
// MMKV.defaultMMKV().encode(
|
||||
// BZYConstants.MMKV_KEY_CURRENT_NODE,
|
||||
// currentNode
|
||||
// )
|
||||
// setNodeNameAndImg(currentNode!!.name)
|
||||
if (isShowToast) {
|
||||
if (isAdded) {
|
||||
RxToast.success(resources.getString(R.string.AccelerateSuccess))
|
||||
}
|
||||
}
|
||||
// File("${Core.deviceStorage.noBackupFilesDir}/${BaseService.CONFIG_FILE}").delete()
|
||||
accelerateViewModel.appStartupStatus()
|
||||
}
|
||||
|
||||
Clash_Stop -> {
|
||||
if (::rxDialogShapeLoading.isInitialized) {
|
||||
rxDialogShapeLoading.cancel()
|
||||
}
|
||||
accelerateIv.isSelected = false
|
||||
// if (reConnection) {
|
||||
// connectVPNSS(currentNode)
|
||||
// }
|
||||
}
|
||||
|
||||
Clash_Starting -> {
|
||||
if (::rxDialogShapeLoading.isInitialized) {
|
||||
if (!rxDialogShapeLoading.isShowing) {
|
||||
if (isAdded) {
|
||||
rxDialogShapeLoading.setMessage(resources.getString(R.string.ConnectingInProgress))
|
||||
}
|
||||
rxDialogShapeLoading.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// BaseService.State.Stopping -> {
|
||||
// if (::rxDialogShapeLoading.isInitialized) {
|
||||
// if (!rxDialogShapeLoading.isShowing) {
|
||||
// rxDialogShapeLoading.setMessage("正在断开...")
|
||||
// rxDialogShapeLoading.show()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
com.cncat.vpn.common.log.Log.i("onActivityResult ==>>> requestCode:${requestCode} resultCode:${resultCode}")
|
||||
if (requestCode == REQUEST_CONNECT) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (clashRunning) {
|
||||
Log.d("clashRunning $clashRunning")
|
||||
} else {
|
||||
startClash()
|
||||
}
|
||||
} else {
|
||||
if (::rxDialogShapeLoading.isInitialized || rxDialogShapeLoading.isShowing) {
|
||||
rxDialogShapeLoading.cancel()
|
||||
}
|
||||
}
|
||||
} else if (requestCode == CHECK_NODE_REQUEST_CODE) {
|
||||
val node = data?.extras?.getString(BZYConstants.MMKV_KEY_SELECT_NODE_NAME)
|
||||
val is_runing = data?.extras?.getBoolean(BZYConstants.EXTRA_KEY_IS_RUNING)
|
||||
// val node = data?.extras?.getSerializable(BZYConstants.MMKV_KEY_SELECT_NODE) as Profile
|
||||
Log.d("onActivityResult ==>>> Node:${node}")
|
||||
node?.let {
|
||||
setNodeNameAndImg(node)
|
||||
if (clashRunning) {
|
||||
Log.d("clashRunning $clashRunning")
|
||||
} else {
|
||||
startClash()
|
||||
}
|
||||
checkGlo()
|
||||
}?.run {
|
||||
if (is_runing == true && !clashRunning) {
|
||||
startClash()
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
} else if (requestCode == Proxy_Mode_REQUEST_CODE) {
|
||||
checkGlo()
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
fun setExpireDate() {
|
||||
var isExpire = checkExpire()
|
||||
// var isExpire = false
|
||||
var endTimeInfo = "--"
|
||||
if (isExpire) {
|
||||
if (isAdded) {
|
||||
endTimeInfo = resources.getString(R.string.AccountExpired)
|
||||
}
|
||||
} else {
|
||||
val validPeriod = MMKV.defaultMMKV().decodeLong(BZYConstants.MMKV_KEY_VPN_VALID_PERIOD)
|
||||
|
||||
val decodeString = MMKV.defaultMMKV().decodeString(BZYConstants.languageInfo, "")
|
||||
if (decodeString.isNullOrEmpty()) {
|
||||
//获取当前系统语言
|
||||
val config = resources.configuration
|
||||
val language = config.locale.language
|
||||
if (language.equals("en")) {
|
||||
val dateFormat = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
val localEN = Locale.ENGLISH
|
||||
SimpleDateFormat("MM/dd/yyyy HH:mm", localEN)
|
||||
} else {
|
||||
val localEN = Locale.ENGLISH
|
||||
SimpleDateFormat("MM/dd/yyyy HH:mm", localEN)
|
||||
}
|
||||
endTimeInfo = dateFormat.format(validPeriod)
|
||||
} else {
|
||||
val dateFormat = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
|
||||
SimpleDateFormat("yyyy年MM月dd日 HH:mm")
|
||||
} else {
|
||||
SimpleDateFormat("yyyy年MM月dd日 HH:mm")
|
||||
|
||||
}
|
||||
endTimeInfo = dateFormat.format(validPeriod)
|
||||
}
|
||||
|
||||
} else {
|
||||
if (decodeString == "English") {
|
||||
val dateFormat = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
val locale = Locale.ENGLISH
|
||||
SimpleDateFormat("MM/dd/yyyy HH:mm", locale)
|
||||
} else {
|
||||
val locale = Locale.ENGLISH
|
||||
SimpleDateFormat("MM/dd/yyyy HH:mm", locale)
|
||||
}
|
||||
endTimeInfo = dateFormat.format(validPeriod)
|
||||
} else {
|
||||
val dateFormat = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
SimpleDateFormat("yyyy年MM月dd日 HH:mm")
|
||||
} else {
|
||||
SimpleDateFormat("yyyy年MM月dd日 HH:mm")
|
||||
}
|
||||
endTimeInfo = dateFormat.format(validPeriod)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tv_end_time.text = endTimeInfo
|
||||
}
|
||||
|
||||
private fun checkExpire(): Boolean {
|
||||
val validPeriod = MMKV.defaultMMKV().decodeLong(BZYConstants.MMKV_KEY_VPN_VALID_PERIOD)
|
||||
if (validPeriod > 0) {
|
||||
var nowTime = System.currentTimeMillis();
|
||||
com.cncat.vpn.common.log.Log.d("validPeriod==>$validPeriod, nowTime==>$nowTime")
|
||||
if (validPeriod >= nowTime) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private fun setNodeNameAndImg(it: String) {
|
||||
launch(Dispatchers.Main) {
|
||||
nodeNameTv.text = it
|
||||
when {
|
||||
it.contains("中国", true) -> {
|
||||
countryIv.setImageResource(R.drawable.flag_china)
|
||||
}
|
||||
|
||||
it.contains("香港", true) -> {
|
||||
countryIv.setImageResource(R.drawable.flag_china)
|
||||
}
|
||||
|
||||
it.contains("日本", true) -> {
|
||||
countryIv.setImageResource(R.drawable.flag_japan)
|
||||
}
|
||||
|
||||
it.contains("韩国", true) -> {
|
||||
countryIv.setImageResource(R.drawable.flag_korea)
|
||||
}
|
||||
|
||||
it.contains("美国", true) -> {
|
||||
countryIv.setImageResource(R.drawable.flag_usa)
|
||||
}
|
||||
|
||||
it.contains("德国", true) -> {
|
||||
countryIv.setImageResource(R.drawable.flag_germany)
|
||||
}
|
||||
|
||||
it.contains("法国", true) -> {
|
||||
countryIv.setImageResource(R.drawable.flag_france)
|
||||
}
|
||||
|
||||
it.contains("俄罗斯", true) -> {
|
||||
countryIv.setImageResource(R.drawable.flag_russia)
|
||||
}
|
||||
|
||||
it.contains("新加坡", true) -> {
|
||||
countryIv.setImageResource(R.drawable.flag_singapore)
|
||||
}
|
||||
|
||||
it.contains("英国", true) -> {
|
||||
countryIv.setImageResource(R.drawable.flag_uk)
|
||||
}
|
||||
|
||||
it.contains("澳大利亚", true) -> {
|
||||
countryIv.setImageResource(R.drawable.flag_australia)
|
||||
}
|
||||
|
||||
it.contains("印度", true) -> {
|
||||
countryIv.setImageResource(R.drawable.flag_india)
|
||||
}
|
||||
|
||||
it.contains("加拿大", true) -> {
|
||||
countryIv.setImageResource(R.drawable.flag_canada)
|
||||
}
|
||||
|
||||
else -> {
|
||||
countryIv.setImageResource(R.drawable.ic_s_location)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun goRechargeWeb() {
|
||||
if (activity != null) {
|
||||
var mact = activity as UIMainActivity
|
||||
mact.goRechargeWeb()
|
||||
}
|
||||
}
|
||||
|
||||
private fun goNewRecharge() {
|
||||
if (activity != null) {
|
||||
var mact = activity as UIMainActivity
|
||||
mact.goBackupRechargeWeb()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateUserInfo() {
|
||||
if (activity != null) {
|
||||
var mact = activity as UIMainActivity
|
||||
mact.goCheckLogin()
|
||||
}
|
||||
}
|
||||
|
||||
private fun start_u_timer() {
|
||||
if (activity != null) {
|
||||
var mact = activity as UIMainActivity
|
||||
mact.startUploadTimer()
|
||||
}
|
||||
}
|
||||
|
||||
private fun stop_u_timer() {
|
||||
if (activity != null) {
|
||||
var mact = activity as UIMainActivity
|
||||
mact.stopUploadTimer()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun checkGlo() {
|
||||
val isGlobal = isGlo
|
||||
val isGlobal2 = MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
|
||||
Log.i("checkGlo isGlobal==>${isGlobal}, isGlobal2==>${isGlobal2}")
|
||||
setProxyModeView(isGlobal)
|
||||
launch(Dispatchers.IO) {
|
||||
if (isGlobal) {
|
||||
if (clashRunning) {
|
||||
getNodes()
|
||||
}
|
||||
} else {
|
||||
if (clashRunning) {
|
||||
delay(1000)
|
||||
UIMainActivity.clashBinder?.let { cm ->
|
||||
val names = cm.queryProxyGroupNames(false)
|
||||
Log.i("checkGlo names==>${names}")
|
||||
if (names.isNotEmpty()) {
|
||||
var selected_name =
|
||||
MMKV.defaultMMKV()
|
||||
.decodeString(BZYConstants.NODE_SELECTED_NAME_KEY, "");
|
||||
Log.i("selected_name ==>${selected_name}")
|
||||
if (!TextUtils.isEmpty(selected_name)) {
|
||||
val o = cm.queryOverride(Clash.OverrideSlot.Session)
|
||||
o.mode = TunnelState.Mode.Rule
|
||||
cm.patchOverride(Clash.OverrideSlot.Session, o)
|
||||
delay(500)
|
||||
var gName = names[0]
|
||||
//全局模式下 names[0]会自动添加一个 "GLOBAL" 组
|
||||
if (names.size >= 2) {
|
||||
if ("GLOBAL" == gName) {
|
||||
//names[0] 为 "GLOBAL" //names[1]才是规则模式下的组名,所以需要手动赋值
|
||||
gName = names[1]
|
||||
}
|
||||
}
|
||||
cm.patchSelector(gName, selected_name!!)
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setProxyModeView(isGlobal: Boolean) {
|
||||
if (isGlobal) {
|
||||
iv_proxy_mode.setImageResource(R.drawable.ic_s_global)
|
||||
if (isAdded) {
|
||||
tv_proxy_model.text = resources.getString(R.string.GlobalMode)
|
||||
}
|
||||
} else {
|
||||
iv_proxy_mode.setImageResource(R.drawable.smart)
|
||||
if (isAdded) {
|
||||
tv_proxy_model.text = resources.getString(R.string.IntelligentMode)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
var proList: MutableList<ClashNodebBean>? = null
|
||||
private suspend fun getNodes() {
|
||||
var selected_name =
|
||||
MMKV.defaultMMKV().decodeString(BZYConstants.NODE_SELECTED_NAME_KEY, "");
|
||||
Log.d("getNodes selected_name==>${selected_name}")
|
||||
if (TextUtils.isEmpty(selected_name)) {
|
||||
UIMainActivity.subUrl?.let {
|
||||
accelerateViewModel?.get_Node_Other(it, object : AsyncCallBackListener {
|
||||
override fun suc(obj: Any?) {
|
||||
proList = obj as MutableList<ClashNodebBean>
|
||||
proList?.let { proListItem ->
|
||||
var nodeName = proListItem[0].name
|
||||
if (!TextUtils.isEmpty(nodeName)) {
|
||||
launch(Dispatchers.IO) {
|
||||
UIMainActivity.clashBinder?.let { cm ->
|
||||
|
||||
val o = cm.queryOverride(Clash.OverrideSlot.Session)
|
||||
o.mode = TunnelState.Mode.Global
|
||||
cm.patchOverride(Clash.OverrideSlot.Session, o)
|
||||
delay(3000)
|
||||
//等待全局模式生效
|
||||
var maxIndex = 0
|
||||
while (true) {
|
||||
if (maxIndex > 3) {
|
||||
break
|
||||
}
|
||||
var names = cm.queryProxyGroupNames(false)
|
||||
if (names.isNotEmpty()) {
|
||||
if (names[0] == "GLOBAL") {
|
||||
Log.d("repeat end")
|
||||
break
|
||||
}
|
||||
}
|
||||
Log.d("repeat agent")
|
||||
maxIndex++
|
||||
delay(1000)
|
||||
}
|
||||
|
||||
cm.patchSelector("GLOBAL", nodeName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun faild(response: Response) {
|
||||
}
|
||||
|
||||
override fun err(msg: String, exception: Exception?) {
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
} else {
|
||||
UIMainActivity.clashBinder?.let { cm ->
|
||||
val o = cm.queryOverride(Clash.OverrideSlot.Session)
|
||||
o.mode = TunnelState.Mode.Global
|
||||
cm.patchOverride(Clash.OverrideSlot.Session, o)
|
||||
delay(3000)
|
||||
//等待全局
|
||||
var maxIndex = 0
|
||||
while (true) {
|
||||
if (maxIndex > 3) {
|
||||
break
|
||||
}
|
||||
var names = cm.queryProxyGroupNames(false)
|
||||
if (names.isNotEmpty()) {
|
||||
if (names[0] == "GLOBAL") {
|
||||
Log.d("repeat end")
|
||||
break
|
||||
}
|
||||
}
|
||||
Log.d("repeat agent")
|
||||
maxIndex++
|
||||
delay(1000)
|
||||
}
|
||||
|
||||
cm.patchSelector("GLOBAL", selected_name!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
private val resultReceiver: ResultReceiver = object : ResultReceiver(null) {
|
||||
override fun onReceiveResult(resultCode: Int, resultData: Bundle) {
|
||||
val data = resultData.getString("data")
|
||||
Log.d("ping to from Service: $data")
|
||||
if(connectId!=-1){
|
||||
Log.d("activity connectId: $connectId")
|
||||
accelerateViewModel.appUpStatus(connectId)
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun httpLoading(httpStatus: HttpStatus.Loading) {
|
||||
|
||||
}
|
||||
override fun httpSuccess(httpStatus: HttpStatus.Success) {
|
||||
when(httpStatus.reqType){
|
||||
HttpReqType.AppStartupStatus ->{
|
||||
Log.d("AppStartupStatus is Success ${httpStatus.rsp}")
|
||||
val dataInfo = httpStatus.rsp as AppStartupStatus
|
||||
if(dataInfo.data!=null){
|
||||
if(dataInfo.data.id!=null){
|
||||
connectId= dataInfo.data.id
|
||||
val serviceIntent= Intent(requireContext(), ConnectionService::class.java)
|
||||
serviceIntent.putExtra("receiver",resultReceiver)
|
||||
requireContext().startService(serviceIntent)
|
||||
}
|
||||
}
|
||||
}
|
||||
HttpReqType.AppStopStatus ->{
|
||||
Log.d("AppStopStatus is Success ${httpStatus.rsp}")
|
||||
val serviceIntent= Intent(requireContext(), ConnectionService::class.java)
|
||||
requireContext().stopService(serviceIntent)
|
||||
}
|
||||
else->{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun httpFailure(httpStatus: HttpStatus.Failure) {
|
||||
when(httpStatus.reqType){
|
||||
HttpReqType.AppStartupStatus ->{
|
||||
Log.d("AppStartupStatus is Failure ${httpStatus.msg}")
|
||||
}
|
||||
HttpReqType.AppStopStatus ->{
|
||||
Log.d("AppStopStatus is Failure ${httpStatus.msg}")
|
||||
}
|
||||
else->{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,139 +0,0 @@
|
|||
package com.yingmao.clash.ui.fragment
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.fragment.app.FragmentManager
|
||||
|
||||
class TFragmentManager(private val mFragmentManager: FragmentManager, private val mContainerViewId: Int,
|
||||
/**
|
||||
* Fragment切换数组
|
||||
*/
|
||||
private val mFragments: MutableList<Fragment>) {
|
||||
|
||||
/**
|
||||
* 当前选中的Tab
|
||||
*/
|
||||
var currentTab = 0
|
||||
private set
|
||||
|
||||
val currentFragment: Fragment
|
||||
get() = mFragments[currentTab]
|
||||
|
||||
/**
|
||||
* 界面切换控制
|
||||
*/
|
||||
fun setFragments(index: Int) {
|
||||
val fragment = mFragments[index]
|
||||
showFragment(mFragmentManager, fragment, mContainerViewId)
|
||||
currentTab = index
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* android.app.Activity下的使用
|
||||
* 动态的使用Fragment
|
||||
*
|
||||
*
|
||||
* 在布局文件中使用 FrameLayout 标签
|
||||
*
|
||||
* @param activity activity
|
||||
* @param fragment fragment
|
||||
* @param containerViewId <FrameLayout android:id="@+id/containerViewId"></FrameLayout>
|
||||
*/
|
||||
fun showFragment(activity: Activity, fragment: android.app.Fragment?, containerViewId: Int) {
|
||||
val fragmentManager = activity.fragmentManager
|
||||
val fragmentTransaction = fragmentManager.beginTransaction()
|
||||
fragmentTransaction.replace(containerViewId, fragment)
|
||||
fragmentTransaction.commit()
|
||||
}
|
||||
|
||||
/**
|
||||
* androidX 包下的使用
|
||||
* 动态的使用Fragment
|
||||
*
|
||||
*
|
||||
* 在布局文件中使用 FrameLayout 标签
|
||||
*
|
||||
* @param fragmentLazy fragmentLazy
|
||||
* @param containerViewId <FrameLayout android:id="@+id/containerViewId"></FrameLayout>
|
||||
*/
|
||||
fun showFragmentLazy(fragmentManager: FragmentManager, fragmentLazy: FragmentLazy, containerViewId: Int) {
|
||||
val fragmentTransaction = fragmentManager.beginTransaction()
|
||||
fragmentTransaction.replace(containerViewId, fragmentLazy)
|
||||
fragmentTransaction.commit()
|
||||
fragmentLazy.onHiddenChanged(true)
|
||||
fragmentLazy.onHiddenChanged(false)
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------Fragment的静态使用 start
|
||||
//在布局文件中直接使用标签
|
||||
/* <fragment
|
||||
android:layout_below="@id/id_fragment_title"
|
||||
android:id="@+id/id_fragment_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" />*/
|
||||
//==============================================================================================Fragment的静态使用 end
|
||||
//----------------------------------------------------------------------------------------------Fragment的动态使用 start
|
||||
/**
|
||||
* androidX 包下的使用
|
||||
* 动态的使用Fragment
|
||||
*
|
||||
*
|
||||
* 在布局文件中使用 FrameLayout 标签
|
||||
*
|
||||
* @param fragment fragment
|
||||
* @param containerViewId <FrameLayout android:id="@+id/containerViewId"></FrameLayout>
|
||||
*/
|
||||
fun showFragment(fragmentManager: FragmentManager, fragment: Fragment, containerViewId: Int) {
|
||||
val fragmentTransaction = fragmentManager.beginTransaction()
|
||||
fragmentTransaction.replace(containerViewId, fragment)
|
||||
fragmentTransaction.commit()
|
||||
fragment.onHiddenChanged(true)
|
||||
fragment.onHiddenChanged(false)
|
||||
}
|
||||
//==============================================================================================Fragment的动态使用 end
|
||||
/**
|
||||
* androidX 包下的使用
|
||||
* 动态的使用Fragment
|
||||
*
|
||||
*
|
||||
* 在布局文件中使用 FrameLayout 标签
|
||||
*
|
||||
* @param fragmentActivity fragmentActivity
|
||||
* @param fragment fragment
|
||||
* @param containerViewId <FrameLayout android:id="@+id/containerViewId"></FrameLayout>
|
||||
*/
|
||||
fun showFragment(fragmentActivity: FragmentActivity, fragment: Fragment?, containerViewId: Int) {
|
||||
val fragmentManager = fragmentActivity.supportFragmentManager
|
||||
val fragmentTransaction = fragmentManager.beginTransaction()
|
||||
fragmentTransaction.replace(containerViewId, fragment!!)
|
||||
fragmentTransaction.commit()
|
||||
}
|
||||
|
||||
/**
|
||||
* androidX 包下的使用
|
||||
* 动态的使用Fragment
|
||||
*
|
||||
*
|
||||
* 在布局文件中使用 FrameLayout 标签
|
||||
*
|
||||
* @param fragmentActivity fragmentActivity
|
||||
* @param fragmentLazy fragmentLazy
|
||||
* @param containerViewId <FrameLayout android:id="@+id/containerViewId"></FrameLayout>
|
||||
*/
|
||||
fun showFragmentLazy(fragmentActivity: FragmentActivity, fragmentLazy: FragmentLazy, containerViewId: Int) {
|
||||
val fragmentManager = fragmentActivity.supportFragmentManager
|
||||
val fragmentTransaction = fragmentManager.beginTransaction()
|
||||
fragmentTransaction.replace(containerViewId, fragmentLazy)
|
||||
fragmentTransaction.commit()
|
||||
fragmentLazy.onHiddenChanged(true)
|
||||
fragmentLazy.onHiddenChanged(false)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
if (mFragments.isNotEmpty()) {
|
||||
setFragments(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue