描述:

1.修改toast 样式
2. 修改记录开启时长
3.新增版本号
This commit is contained in:
level 2025-03-18 19:08:39 +08:00
parent 9d9d899754
commit 7869a2a827
11 changed files with 146 additions and 13 deletions

View File

@ -176,7 +176,6 @@
android:process=":background" android:process=":background"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<service android:name=".service.ConnectionService"/> <service android:name=".service.ConnectionService"/>
<provider <provider
android:name="androidx.core.content.FileProvider" android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider" android:authorities="${applicationId}.fileprovider"

View File

@ -114,5 +114,6 @@ class BZYConstants {
const val APP_SETTING_PACKAGE_INFO = "APP_SETTING_PACKAGE_INFO" const val APP_SETTING_PACKAGE_INFO = "APP_SETTING_PACKAGE_INFO"
const val languageInfo = "languageInfo" const val languageInfo = "languageInfo"
const val applicationMode = "ApplicationMode" const val applicationMode = "ApplicationMode"
const val CONNECTID = "connectId"
} }
} }

View File

@ -2,12 +2,14 @@ package com.yingmao.clash.fragment.home
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.app.ActivityManager
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.ResultReceiver
import android.text.TextUtils import android.text.TextUtils
import android.view.View import android.view.View
import android.widget.FrameLayout import android.widget.FrameLayout
@ -45,11 +47,15 @@ import com.yingmao.clash.act.UIMainActivity.Companion.subUrl
import com.yingmao.clash.conf.BZYConstants import com.yingmao.clash.conf.BZYConstants
import com.yingmao.clash.conf.Conf import com.yingmao.clash.conf.Conf
import com.yingmao.clash.entity.ClashNodebBean import com.yingmao.clash.entity.ClashNodebBean
import com.yingmao.clash.fragment.AccelerateViewModel
import com.yingmao.clash.fragment.BaseFragment import com.yingmao.clash.fragment.BaseFragment
import com.yingmao.clash.listener.AsyncCallBackListener import com.yingmao.clash.listener.AsyncCallBackListener
import com.yingmao.clash.net.http.HttpReqType import com.yingmao.clash.net.http.HttpReqType
import com.yingmao.clash.net.http.HttpStatus 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.net.http.entity.PhDownloadUrlRsp
import com.yingmao.clash.service.ConnectionService
import com.yingmao.clash.util.ActivityResultLifecycle import com.yingmao.clash.util.ActivityResultLifecycle
import com.yingmao.clash.util.CommonUtils import com.yingmao.clash.util.CommonUtils
import com.yingmao.clash.util.MarqueeTextView import com.yingmao.clash.util.MarqueeTextView
@ -99,6 +105,7 @@ class HomeFragment: BaseFragment() , CoroutineScope by CoroutineScope(Dispatcher
var proList: MutableList<ClashNodebBean>? = null var proList: MutableList<ClashNodebBean>? = null
private val nextRequestKey = AtomicInteger(0) private val nextRequestKey = AtomicInteger(0)
private var reConnection = false private var reConnection = false
private var connectId=-1
companion object { companion object {
const val REQUEST_CONNECT = 1 const val REQUEST_CONNECT = 1
const val CHECK_NODE_REQUEST_CODE = 2 const val CHECK_NODE_REQUEST_CODE = 2
@ -211,6 +218,10 @@ class HomeFragment: BaseFragment() , CoroutineScope by CoroutineScope(Dispatcher
rxDialogSureCancel.setSureListener { rxDialogSureCancel.setSureListener {
stopUpLoadTimer() stopUpLoadTimer()
stopClash() stopClash()
Log.d("NewAccFragment connectId${connectId}")
if(connectId!=-1){
mainAtyVM.appStopStatus(connectId)
}
rxDialogSureCancel.cancel() rxDialogSureCancel.cancel()
reConnection = false reConnection = false
} }
@ -317,6 +328,28 @@ class HomeFragment: BaseFragment() , CoroutineScope by CoroutineScope(Dispatcher
} }
} }
} }
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
MMKV.defaultMMKV().encode(BZYConstants.CONNECTID, dataInfo.data.id)
val serviceIntent= Intent(requireContext(), ConnectionService::class.java)
serviceIntent.putExtra("receiver",resultReceiver)
requireContext().startService(serviceIntent)
}
}
}
HttpReqType.AppUpStatus ->{
Log.d("AppUpStatus is Success ${httpStatus.rsp}")
}
HttpReqType.AppStopStatus ->{
Log.d("AppStopStatus is Success ${httpStatus.rsp}")
val serviceIntent= Intent(requireContext(), ConnectionService::class.java)
requireContext().stopService(serviceIntent)
}
else->{ else->{
} }
@ -324,9 +357,30 @@ class HomeFragment: BaseFragment() , CoroutineScope by CoroutineScope(Dispatcher
} }
override fun httpFailure(httpStatus: HttpStatus.Failure) { override fun httpFailure(httpStatus: HttpStatus.Failure) {
when(httpStatus.reqType){
HttpReqType.AppStartupStatus ->{
Log.d("AppStartupStatus is Failure ${httpStatus.msg}")
}
HttpReqType.AppUpStatus ->{
Log.d("AppUpStatus is Failure ${httpStatus.msg}")
}
HttpReqType.AppStopStatus ->{
Log.d("AppStopStatus is Failure ${httpStatus.msg}")
}
else->{
}
}
}
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){
mainAtyVM.appUpStatus(connectId)
}
}
} }
private fun initMainPageHorseRaceLamp(noticeData: String) { private fun initMainPageHorseRaceLamp(noticeData: String) {
if (noticeData.isNotEmpty()) { if (noticeData.isNotEmpty()) {
tvNotice.text = noticeData tvNotice.text = noticeData
@ -424,7 +478,10 @@ class HomeFragment: BaseFragment() , CoroutineScope by CoroutineScope(Dispatcher
if (result.resultCode == RESULT_OK) { if (result.resultCode == RESULT_OK) {
stateChanged(Clash_Starting, true) stateChanged(Clash_Starting, true)
context?.startClashService() context?.startClashService()
mainAtyVM.appStartupStatus()
} }
}else{
mainAtyVM.appStartupStatus()
} }
} catch (e: Exception) { } catch (e: Exception) {
stopUpLoadTimer() stopUpLoadTimer()

View File

@ -115,6 +115,8 @@ class SettingFragment: BaseFragment(), CoroutineScope by CoroutineScope(Dispatch
private lateinit var tvExitLog:TextView private lateinit var tvExitLog:TextView
private lateinit var tvSignIn:TextView private lateinit var tvSignIn:TextView
private lateinit var tvVersion:TextView
private var baseLoading: RxDialogShapeLoading? = null private var baseLoading: RxDialogShapeLoading? = null
private val fragments = arrayListOf<Fragment>() private val fragments = arrayListOf<Fragment>()
private lateinit var mainAtyVM: MainAtyVM private lateinit var mainAtyVM: MainAtyVM
@ -136,6 +138,7 @@ class SettingFragment: BaseFragment(), CoroutineScope by CoroutineScope(Dispatch
container.addView(view) container.addView(view)
} }
@SuppressLint("SetTextI18n")
private fun initLanguage(view: View) { private fun initLanguage(view: View) {
userIdentityNumberCopy.text = requireActivity().resources.getString(R.string.copy) userIdentityNumberCopy.text = requireActivity().resources.getString(R.string.copy)
view.findViewById<TextView>(R.id.expirationTimeStr).text = requireActivity().resources.getString(R.string.expire_date) view.findViewById<TextView>(R.id.expirationTimeStr).text = requireActivity().resources.getString(R.string.expire_date)
@ -179,6 +182,7 @@ class SettingFragment: BaseFragment(), CoroutineScope by CoroutineScope(Dispatch
tvSignIn.text = requireActivity().resources.getString(R.string.SignIn) tvSignIn.text = requireActivity().resources.getString(R.string.SignIn)
tvExitLog.text=requireActivity().resources.getString(R.string.exit) tvExitLog.text=requireActivity().resources.getString(R.string.exit)
tvVersion.text=requireActivity().resources.getString(R.string.edition) + "${BuildConfig.VERSION_NAME}." + BuildConfig.productId
} }
private fun initView(view: View) { private fun initView(view: View) {
@ -203,6 +207,8 @@ class SettingFragment: BaseFragment(), CoroutineScope by CoroutineScope(Dispatch
clApplicationLanguage=view.findViewById(R.id.clApplicationLanguage) clApplicationLanguage=view.findViewById(R.id.clApplicationLanguage)
clTelegraph=view.findViewById(R.id.clTelegraph) clTelegraph=view.findViewById(R.id.clTelegraph)
tvExitLog=view.findViewById(R.id.tvExitLog) tvExitLog=view.findViewById(R.id.tvExitLog)
tvVersion=view.findViewById(R.id.tvVersion)
setExpireDate() setExpireDate()
if(checkExpire()){ if(checkExpire()){

View File

@ -92,10 +92,10 @@ class NetService private constructor() : INetService {
// .sslSocketFactory(getSSLSocketFactory(), CustomTrustManager())//信任所有证书 // .sslSocketFactory(getSSLSocketFactory(), CustomTrustManager())//信任所有证书
.sslSocketFactory(getSSLSocketFactory(), trustAllCerts[0] as X509TrustManager) .sslSocketFactory(getSSLSocketFactory(), trustAllCerts[0] as X509TrustManager)
.hostnameVerifier(getHostnameVerifier()!!) .hostnameVerifier(getHostnameVerifier()!!)
if (BuildConfig.DEBUG) { // if (BuildConfig.DEBUG) {
builder.addInterceptor(loggingInterceptor) // builder.addInterceptor(loggingInterceptor)
} // }
// builder.addInterceptor(loggingInterceptor) builder.addInterceptor(loggingInterceptor)
return builder.build() return builder.build()
} }

View File

@ -283,7 +283,7 @@ object RxToast {
toastTextView.typeface = Typeface.create(TOAST_TYPEFACE, Typeface.NORMAL) toastTextView.typeface = Typeface.create(TOAST_TYPEFACE, Typeface.NORMAL)
currentToast?.view = toastLayout currentToast?.view = toastLayout
currentToast?.duration = duration currentToast?.duration = duration
currentToast?.setGravity(Gravity.TOP,0,200) currentToast?.setGravity(Gravity.CENTER,0,200)
return currentToast return currentToast
} }

View File

@ -24,10 +24,12 @@ import com.yingmao.clash.net.http.HttpReqType
import com.yingmao.clash.net.http.NetService import com.yingmao.clash.net.http.NetService
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async import kotlinx.coroutines.async
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import okhttp3.RequestBody import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import org.yaml.snakeyaml.Yaml import org.yaml.snakeyaml.Yaml
import java.math.BigDecimal import java.math.BigDecimal
import java.util.* import java.util.*
@ -283,4 +285,60 @@ class MainAtyVM : PublicViewMode() {
Log.d("e==>" + e.localizedMessage) Log.d("e==>" + e.localizedMessage)
} }
} }
fun appStartupStatus() {
val httpApi = NetService.instances.createHttpsEncodeStr(HttpApi::class.java)
val token = MMKV.defaultMMKV().decodeString(BZYConstants.MMKV_KEY_PH_TOKEN, "")!!
val phoneNumber =
MMKV.defaultMMKV().decodeString(BZYConstants.MMKV_KEY_REMEMBER_USERNAME, "")!!
val params = mutableMapOf(
"phToken" to token,
"phoneNumber" to phoneNumber,
)
Log.d("appCheck==>$params")
doAsync(HttpReqType.AppStartupStatus) {
httpApi.appStartupStatus(params)
}
}
fun appStopStatus(addId:Int) {
val httpApi = NetService.instances.createHttpsEncodeStr(HttpApi::class.java)
val token = MMKV.defaultMMKV().decodeString(BZYConstants.MMKV_KEY_PH_TOKEN, "")!!
val phoneNumber =
MMKV.defaultMMKV().decodeString(BZYConstants.MMKV_KEY_REMEMBER_USERNAME, "")!!
val paramsToken = mutableMapOf(
"phToken" to token,
"phoneNumber" to phoneNumber,
)
val params = hashMapOf(
"id" to addId
)
val gson = Gson()
val jsonString = gson.toJson(params)
val requestBody: RequestBody = jsonString.toRequestBody("application/json; charset=utf-8".toMediaType())
doAsync(HttpReqType.AppStopStatus) {
httpApi.appStopStatus(paramsToken,requestBody)
}
}
fun appUpStatus(addId:Int) {
val httpApi = NetService.instances.createHttpsEncodeStr(HttpApi::class.java)
val token = MMKV.defaultMMKV().decodeString(BZYConstants.MMKV_KEY_PH_TOKEN, "")!!
val phoneNumber =
MMKV.defaultMMKV().decodeString(BZYConstants.MMKV_KEY_REMEMBER_USERNAME, "")!!
val paramsToken = mutableMapOf(
"phToken" to token,
"phoneNumber" to phoneNumber,
)
val params = hashMapOf(
"id" to addId
)
val gson = Gson()
val jsonString = gson.toJson(params)
val requestBody: RequestBody = jsonString.toRequestBody("application/json; charset=utf-8".toMediaType())
doAsync(HttpReqType.AppUpStatus) {
httpApi.appUpStatus(paramsToken,requestBody)
}
}
} }

View File

@ -2,8 +2,8 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:shape="rectangle"
> >
<gradient android:startColor="#FFD29A" <gradient android:startColor="@color/black"
android:endColor="#FFD29A" android:endColor="@color/black"
android:angle="360" android:angle="360"
/> />
<corners android:radius="24dp"/> <corners android:radius="24dp"/>

View File

@ -2,8 +2,8 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:shape="rectangle"
> >
<gradient android:startColor="#4072FE" <gradient android:startColor="@color/black"
android:endColor="#9AAAFE" android:endColor="@color/black"
android:angle="180" android:angle="180"
/> />
<corners android:radius="24dp"/> <corners android:radius="24dp"/>

View File

@ -1089,17 +1089,28 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toTopOf="@+id/tvVersion"
android:paddingTop="13dp" android:paddingTop="13dp"
android:paddingBottom="13dp" android:paddingBottom="13dp"
android:layout_marginStart="13dp" android:layout_marginStart="13dp"
android:layout_marginEnd="13dp" android:layout_marginEnd="13dp"
android:gravity="center" android:gravity="center"
android:text="@string/SignIn" android:text="@string/SignIn"
android:layout_marginBottom="16dp"
android:textColor="#4072FE" android:textColor="#4072FE"
android:textSize="16sp" android:textSize="16sp"
android:background="@drawable/setting_sing_in_bg" android:background="@drawable/setting_sing_in_bg"
/> />
<TextView
android:id="@+id/tvVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:text="版本"
android:textColor="@color/black"
android:textSize="18sp"
android:layout_marginBottom="16dp"
/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -17,6 +17,7 @@
android:id="@+id/toast_text" android:id="@+id/toast_text"
android:textSize="16sp" android:textSize="16sp"
android:textStyle="bold" android:textStyle="bold"
android:textColor="@color/white"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />