diff --git a/app/src/main/java/com/yingmao/clash/fragment/home/HomeFragment.kt b/app/src/main/java/com/yingmao/clash/fragment/home/HomeFragment.kt index 1b3169b..c309850 100644 --- a/app/src/main/java/com/yingmao/clash/fragment/home/HomeFragment.kt +++ b/app/src/main/java/com/yingmao/clash/fragment/home/HomeFragment.kt @@ -2,7 +2,6 @@ package com.yingmao.clash.fragment.home import android.annotation.SuppressLint import android.app.Activity -import android.app.ActivityManager import android.content.BroadcastReceiver import android.content.Context import android.content.Intent @@ -45,7 +44,6 @@ import com.yingmao.clash.act.ConnectionModeActivity import com.yingmao.clash.act.LoginActivity import com.yingmao.clash.act.UIMainActivity import com.yingmao.clash.act.UIMainActivity.Companion.clashBinder -import com.yingmao.clash.act.UIMainActivity.Companion.isSubbed import com.yingmao.clash.act.UIMainActivity.Companion.newMainActGlo import com.yingmao.clash.act.UIMainActivity.Companion.newUuid import com.yingmao.clash.act.UIMainActivity.Companion.profileBinder @@ -53,13 +51,11 @@ import com.yingmao.clash.act.UIMainActivity.Companion.subUrl import com.yingmao.clash.conf.BZYConstants import com.yingmao.clash.conf.Conf import com.yingmao.clash.entity.ClashNodebBean -import com.yingmao.clash.fragment.AccelerateViewModel import com.yingmao.clash.fragment.BaseFragment 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.net.http.entity.AppStopStatus import com.yingmao.clash.net.http.entity.PhDownloadUrlRsp import com.yingmao.clash.service.ConnectionService import com.yingmao.clash.util.ActivityResultLifecycle @@ -107,12 +103,12 @@ class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatcher private lateinit var llLine: ConstraintLayout private lateinit var clActivity: ConstraintLayout private lateinit var clMember: ConstraintLayout - private val fragments = arrayListOf() var proList: MutableList? = null private val nextRequestKey = AtomicInteger(0) private var reConnection = false private var connectId = -1 + private var baseLoading: RxDialogShapeLoading? = null companion object { const val REQUEST_CONNECT = 1 @@ -187,8 +183,8 @@ class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatcher llLine = view.findViewById(R.id.llLine) clActivity = view.findViewById(R.id.clActivity) clMember = view.findViewById(R.id.clMember) - if (BuildConfig.productId=="182269"&&BuildConfig.is_tz){ - clActivity.visibility=View.INVISIBLE + if (BuildConfig.productId == "182269" && BuildConfig.is_tz) { + clActivity.visibility = View.INVISIBLE } llLine.setOnClickListener { @@ -213,7 +209,7 @@ class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatcher return@setOnClickListener } var intent: Intent? = null - if (BuildConfig.is_tz&&BuildConfig.productId=="182269") { + if (BuildConfig.is_tz && BuildConfig.productId == "182269") { intent = Intent(CommonUtils.getApp(), ChangeNodeTzActivity::class.java) } else { intent = Intent(CommonUtils.getApp(), ChangeNodeActivity::class.java) @@ -261,13 +257,28 @@ class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatcher } rxDialogSureCancel.show() } else { - android.util.Log.i("AAAAAAAAAAAAA::","data isSubbed::: "+isSubbed) - if(isSubbed){ - startClash() - }else{ - RxToast.success(resources.getString(R.string.tooFast)) + if (checkExpire()) { + if (isAdded) { + hideLoading() + MaterialDialog(requireContext()).show { + this.cancelable(false) + cornerRadius(res = R.dimen.dp_10) + customView( + R.layout.expired_recharge__layout, + scrollable = false, + noVerticalPadding = true, + horizontalPadding = false + ) + getCustomView().findViewById(R.id.tv_pay_finish).setOnClickListener { + goNewRecharge() + dismiss() + } + } + } + return@setOnClickListener } - + showLoading(resources.getString(R.string.Starting), requireContext()) + startClash(true) } } clActivity.setOnClickListener { @@ -285,12 +296,29 @@ class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatcher var selected_name = MMKV.defaultMMKV().decodeString(BZYConstants.NODE_SELECTED_NAME_KEY, "") if (!TextUtils.isEmpty(selected_name)) { - if (!BuildConfig.is_tz){ + if (!BuildConfig.is_tz) { setNodeNameAndImg(selected_name!!) } } } + fun showLoading(str: String, context: Context) { + val message = if (TextUtils.isEmpty(str)) "进行中..." else str + if (baseLoading == null) { + baseLoading = RxDialogShapeLoading(context) + } + baseLoading?.setMessage(message) + if (baseLoading?.isShowing == false) { + baseLoading?.show() + } + } + + fun hideLoading() { + if (baseLoading != null && baseLoading?.isShowing == true) { + baseLoading?.cancel() + } + } + private fun updateUserInfo() { if (activity != null) { val mact = activity as UIMainActivity @@ -393,8 +421,8 @@ class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatcher serviceIntent.putExtra("receiver", resultReceiver) val serviceRunning = Utils.isServiceRunning(requireContext(), ConnectionService::class.java) - android.util.Log.i("AppStartupStatus","data::"+serviceRunning) - if(!serviceRunning){ + android.util.Log.i("AppStartupStatus", "data::" + serviceRunning) + if (!serviceRunning) { requireContext().startService(serviceIntent) } } @@ -469,7 +497,7 @@ class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatcher if (clashRunning) { Log.d("clashRunning $clashRunning") } else { - startClash() + startClash(false) } } else { if (::rxDialogShapeLoading.isInitialized || rxDialogShapeLoading.isShowing) { @@ -485,12 +513,12 @@ class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatcher if (clashRunning) { Log.d("clashRunning $clashRunning") } else { - startClash() + startClash(false) } checkGlo() }?.run { if (isRunNing == true && !clashRunning) { - startClash() + startClash(false) } } } else if (requestCode == Proxy_Mode_REQUEST_CODE) { @@ -498,27 +526,11 @@ class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatcher } } - private fun startClash() { - if (checkExpire()) { - if (isAdded) { - MaterialDialog(requireContext()).show { - this.cancelable(false) - cornerRadius(res = R.dimen.dp_10) - customView( - R.layout.expired_recharge__layout, - scrollable = false, - noVerticalPadding = true, - horizontalPadding = false - ) - getCustomView().findViewById(R.id.tv_pay_finish).setOnClickListener { - goNewRecharge() - dismiss() - } - } - } - return - } + private fun startClash(isStart:Boolean) { launch { + if(isStart){ + delay(2000) + } profileBinder?.let { pm -> val active = pm.queryActive() if (active == null) { @@ -557,9 +569,15 @@ class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatcher stateChanged(Clash_Starting, true) context?.startClashService() mainAtyVM.appStartupStatus() + withContext(Dispatchers.Main) { + hideLoading() + } } } else { mainAtyVM.appStartupStatus() + withContext(Dispatchers.Main) { + hideLoading() + } } } catch (e: Exception) { stopUpLoadTimer() @@ -1004,12 +1022,13 @@ class HomeFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatcher }) dialog.show() } + override fun onDestroy() { super.onDestroy() val serviceRunning = Utils.isServiceRunning(requireContext(), ConnectionService::class.java) - if(serviceRunning){ - val serviceIntent= Intent(requireContext(), ConnectionService::class.java) + if (serviceRunning) { + val serviceIntent = Intent(requireContext(), ConnectionService::class.java) requireContext().stopService(serviceIntent) } } diff --git a/app/src/main/java/com/yingmao/clash/fragment/setting/SettingFragment.kt b/app/src/main/java/com/yingmao/clash/fragment/setting/SettingFragment.kt index 9bbb900..0379208 100644 --- a/app/src/main/java/com/yingmao/clash/fragment/setting/SettingFragment.kt +++ b/app/src/main/java/com/yingmao/clash/fragment/setting/SettingFragment.kt @@ -329,7 +329,12 @@ class SettingFragment : BaseFragment(), CoroutineScope by CoroutineScope(Dispatc startActivity(intent) } initializationRepair.setOnClickListener { + if (checkExpire()) { + RxToast.info(resources.getString(R.string.AccountExpired)) + return@setOnClickListener + } if (TextUtils.isEmpty(subUrl)) { + RxToast.success(resources.getString(R.string.tooFast)) return@setOnClickListener } cleanNodeMmkv() diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index aa1ea77..eb24f14 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -360,4 +360,6 @@ Service Description\n Recharge Membership It is detected that the current account is logged in on other devices. If it is not your own operation, please change the password immediately and log out of the unfamiliar device. The application is initializing. Please wait for 1~2 seconds and try again. + Starting + \ No newline at end of file diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index fb30da2..260ef73 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -351,4 +351,5 @@ 充值會員 檢測到當前賬號在其他設備登錄,如非本人操作,請立即修改密碼並退出陌生設備。 應用初始化中,請等待1~2秒後重試 + 啟動中 \ No newline at end of file diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 2cef652..8bab8a5 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -349,4 +349,5 @@ 充值會員 檢測到當前賬號在其他設備登錄,如非本人操作,請立即修改密碼並退出陌生設備。 應用初始化中,請等待1~2秒後重試 + 啟動中 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3c85c12..7aec67a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -371,4 +371,5 @@ 充值会员 检测到当前账号在其他设备登录,如非本人操作,请立即修改密码并退出陌生设备。 应用初始化中,请等待1~2秒后重试 + 启动中 \ No newline at end of file