优化应用模式

This commit is contained in:
cyh 2024-11-18 17:58:58 +08:00
parent 3168e814d0
commit 2820961935
13 changed files with 297 additions and 178 deletions

View File

@ -14,6 +14,7 @@ plugins {
dependencies {
implementation(fileTree(mapOf("dir" to "src/main/libs", "include" to listOf("*.aar"))))
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
implementation(files("src/main/libs/openinstall.jar"))
// compileOnly(project(":hideapi"))
// implementation(project(":core"))
@ -34,7 +35,6 @@ dependencies {
val serviceAar = file("libs/service.aar")
if (commonAar.exists()) {
implementation(files(commonAar))
} else {

View File

@ -161,6 +161,12 @@
<meta-data
android:name="android.webkit.WebView.EnableSafeBrowsing"
android:value="false" />
<meta-data
android:name="com.openinstall.APP_KEY"
android:value="vsiquu"/>
<!-- <meta-data-->
<!-- android:name="com.openinstall.AD_TRACK"-->
<!-- android:value="true"/>-->
</application>
</manifest>

View File

@ -28,6 +28,7 @@ import com.yingmao.clash.base.BaseActivity
import com.yingmao.clash.conf.BZYConstants
import com.yingmao.clash.entity.AppInfoEntity
import com.yingmao.clash.net.http.entity.SendSmsRsp
import com.yingmao.clash.service.model.AccessControlMode
import com.yingmao.clash.util.Utils
import com.yingmao.clash.view.RxToast
import com.yingmao.clash.view.adapter.InstallApplicationAdapter
@ -38,14 +39,14 @@ import java.io.ByteArrayOutputStream
class InstallApplicationActivity : BaseActivity() {
private lateinit var RvIcon: RecyclerView
private lateinit var AIVBack: AppCompatImageView
private lateinit var tableTitleCB: ImageView
private lateinit var TVChooseName: TextView
private lateinit var tableTitle: ConstraintLayout
private lateinit var AIVBack: AppCompatImageView
private lateinit var tableTitleCB: ImageView
private lateinit var TVChooseName: TextView
private lateinit var tableTitle: ConstraintLayout
val iAAdapter = InstallApplicationAdapter()
private var isSelectAll = false
private var index = 0
private var indexBase=0
private var indexBase = 0
private var saveAppInfo = mutableListOf<AppInfoEntity>()
private var saveAppPackageSet = mutableSetOf<String>()
private lateinit var rxDialogShapeLoading: RxDialogShapeLoading
@ -56,50 +57,59 @@ class InstallApplicationActivity : BaseActivity() {
window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
initView()
}
override fun onResume() {
super.onResume()
MainScope().launch {
val decodeString = MMKV.defaultMMKV().decodeString(BZYConstants.APPSETTINGINFO,"")
if(decodeString.isNullOrEmpty()){
val allLauncherIconPackages = getAllLauncherIconPackages(this@InstallApplicationActivity)
val decodeString = MMKV.defaultMMKV().decodeString(BZYConstants.APPSETTINGINFO, "")
if (decodeString.isNullOrEmpty()) {
val allLauncherIconPackages =
getAllLauncherIconPackages(this@InstallApplicationActivity)
allLauncherIconPackages.reverse()
iAAdapter.notifyAdapter(allLauncherIconPackages,this@InstallApplicationActivity)
}else{
iAAdapter.notifyAdapter(allLauncherIconPackages, this@InstallApplicationActivity)
} else {
saveAppInfo = Gson().fromJson<AppInfoEntity>(
MMKV.defaultMMKV().decodeString(BZYConstants.APPSETTINGINFO),
object : TypeToken<ArrayList<AppInfoEntity?>?>() {
}.type
) as MutableList<AppInfoEntity>
val allLauncherIconPackages = getAllLauncherIconPackages(this@InstallApplicationActivity)
val allLauncherIconPackages =
getAllLauncherIconPackages(this@InstallApplicationActivity)
allLauncherIconPackages.reverse()
allLauncherIconPackages.forEach {allItem->
saveAppInfo.forEach { saveItem->
if(allItem.packageName==saveItem.packageName&&allItem.label==saveItem.label){
allItem.isChoose=true
allLauncherIconPackages.forEach { allItem ->
saveAppInfo.forEach { saveItem ->
if (allItem.packageName == saveItem.packageName && allItem.label == saveItem.label) {
allItem.isChoose = true
}
saveAppPackageSet.add(saveItem.packageName)
}
}
indexBase=saveAppInfo.size
iAAdapter.notifyAdapter(allLauncherIconPackages,this@InstallApplicationActivity)
Log.i("levelInstall","saveAppInfo:::"+saveAppInfo.size+"allLauncherIconPackages::::"+allLauncherIconPackages.size)
indexBase = saveAppInfo.size
iAAdapter.notifyAdapter(allLauncherIconPackages, this@InstallApplicationActivity)
Log.i(
"levelInstall",
"saveAppInfo:::" + saveAppInfo.size + "allLauncherIconPackages::::" + allLauncherIconPackages.size
)
if(allLauncherIconPackages.size==saveAppInfo.size){
isSelectAll=true
TVChooseName.text=resources.getString(R.string.cancel)+resources.getString(R.string.SelectAll)
if (allLauncherIconPackages.size == saveAppInfo.size) {
isSelectAll = true
TVChooseName.text =
resources.getString(R.string.cancel) + resources.getString(R.string.SelectAll)
tableTitleCB.setImageResource(R.drawable.ic_xianzhong)
index=saveAppInfo.size
}else if(saveAppInfo.size>0){
TVChooseName.text=resources.getString(R.string.SelectAll)
index = saveAppInfo.size
} else if (saveAppInfo.size > 0) {
TVChooseName.text = resources.getString(R.string.SelectAll)
tableTitleCB.setImageResource(R.drawable.ic_xianzhongjian)
}
}
runOnUiThread {
RvIcon.layoutManager= LinearLayoutManager(this@InstallApplicationActivity)
RvIcon.adapter=iAAdapter
RvIcon.layoutManager = LinearLayoutManager(this@InstallApplicationActivity)
RvIcon.adapter = iAAdapter
hideLoadingDialog()
}
@ -109,49 +119,52 @@ class InstallApplicationActivity : BaseActivity() {
private fun initView() {
showLoadingDialog(resources.getString(R.string.LoadingProgress))
val titleBar=findViewById<AppBarLayout>(R.id.appBar)
val titleBar = findViewById<AppBarLayout>(R.id.appBar)
val statusBarHeight = Utils.getStatusBarHeight(this)
Utils.setLayoutMargins(titleBar,0,statusBarHeight,0,0)
Utils.setLayoutMargins(titleBar, 0, statusBarHeight, 0, 0)
RvIcon=findViewById(R.id.RvIcon)
RvIcon = findViewById(R.id.RvIcon)
val collapsingToolbar = findViewById<CollapsingToolbarLayout>(R.id.collapsingToolbar)
collapsingToolbar.title =resources.getString(R.string.SubApplicationProxy)
AIVBack=findViewById(R.id.AIVBack)
collapsingToolbar.title = resources.getString(R.string.SubApplicationProxy)
AIVBack = findViewById(R.id.AIVBack)
AIVBack.setOnClickListener {
finish()
}
tableTitleCB=findViewById(R.id.tableTitleCB)
tableTitle=findViewById(R.id.tableTitle)
tableTitleCB = findViewById(R.id.tableTitleCB)
tableTitle = findViewById(R.id.tableTitle)
TVChooseName=findViewById(R.id.TVChooseName)
TVChooseName = findViewById(R.id.TVChooseName)
iAAdapter.setListener(object :InstallApplicationAdapter.onItemClickListener{
iAAdapter.setListener(object : InstallApplicationAdapter.onItemClickListener {
@SuppressLint("SetTextI18n")
override fun onItemClick(appInfoList: List<AppInfoEntity>, isPosition: Int) {
val appInfoItem = appInfoList.get(isPosition)
val isSelect = appInfoItem.isChoose
val decodeString = MMKV.defaultMMKV().decodeString(BZYConstants.APPSETTINGINFO,"")
if(!isSelect){
val decodeString = MMKV.defaultMMKV().decodeString(BZYConstants.APPSETTINGINFO, "")
if (!isSelect) {
index++
appInfoItem.isChoose=true
if(index==appInfoList.size){
isSelectAll=true
TVChooseName.text=resources.getString(R.string.cancel)+resources.getString(R.string.SelectAll)
appInfoItem.isChoose = true
if (index == appInfoList.size) {
isSelectAll = true
TVChooseName.text =
resources.getString(R.string.cancel) + resources.getString(R.string.SelectAll)
tableTitleCB.setImageResource(R.drawable.ic_xianzhong)
}
indexBase++
if(indexBase==appInfoList.size){
isSelectAll=true
TVChooseName.text=resources.getString(R.string.cancel)+resources.getString(R.string.SelectAll)
if (indexBase == appInfoList.size) {
isSelectAll = true
TVChooseName.text =
resources.getString(R.string.cancel) + resources.getString(R.string.SelectAll)
tableTitleCB.setImageResource(R.drawable.ic_xianzhong)
}else if(indexBase<appInfoList.size){
TVChooseName.text=resources.getString(R.string.cancel)+resources.getString(R.string.SelectAll)
} else if (indexBase < appInfoList.size) {
TVChooseName.text =
resources.getString(R.string.cancel) + resources.getString(R.string.SelectAll)
tableTitleCB.setImageResource(R.drawable.ic_xianzhongjian)
}
if(decodeString.isNullOrEmpty()){
if (decodeString.isNullOrEmpty()) {
//为空直接将改条数据添加
saveAppInfo.clear()
@ -159,56 +172,61 @@ class InstallApplicationActivity : BaseActivity() {
saveAppPackageSet.clear()
saveAppPackageSet.add(appInfoItem.packageName)
val gson = Gson()
MMKV.defaultMMKV().encode(BZYConstants.APPSETTINGINFO, gson.toJson(saveAppInfo))
}else{
MMKV.defaultMMKV()
.encode(BZYConstants.APPSETTINGINFO, gson.toJson(saveAppInfo))
} else {
saveAppInfo.clear()
saveAppInfo = Gson().fromJson<AppInfoEntity>(
decodeString,
object : TypeToken<ArrayList<AppInfoEntity?>?>() {
}.type
) as MutableList<AppInfoEntity>
com.yingmao.clash.common.log.Log.d("appInfoItem==>${appInfoItem}")
// com.yingmao.clash.common.log.Log.d("appInfoItem==>${appInfoItem}")
saveAppInfo.add(appInfoItem)
saveAppPackageSet.add(appInfoItem.packageName)
val gson = Gson()
MMKV.defaultMMKV().encode(BZYConstants.APPSETTINGINFO, gson.toJson(saveAppInfo))
MMKV.defaultMMKV()
.encode(BZYConstants.APPSETTINGINFO, gson.toJson(saveAppInfo))
}
}else{
appInfoItem.isChoose=false
} else {
appInfoItem.isChoose = false
index--
indexBase--
isSelectAll=false
if(indexBase>1){
TVChooseName.text=resources.getString(R.string.cancel)+resources.getString(R.string.SelectAll)
isSelectAll = false
if (indexBase > 1) {
TVChooseName.text =
resources.getString(R.string.cancel) + resources.getString(R.string.SelectAll)
tableTitleCB.setImageResource(R.drawable.ic_xianzhongjian)
}else if(indexBase<1){
TVChooseName.text=getString(R.string.SelectAll)
} else if (indexBase < 1) {
TVChooseName.text = getString(R.string.SelectAll)
tableTitleCB.setImageResource(R.drawable.ic_weixianzhong)
}
if(!decodeString.isNullOrEmpty()){
if (!decodeString.isNullOrEmpty()) {
saveAppInfo.clear()
saveAppInfo = Gson().fromJson<AppInfoEntity>(
decodeString,
object : TypeToken<ArrayList<AppInfoEntity?>?>() {
}.type
) as MutableList<AppInfoEntity>
var tempIndex =0
var tempIndex = 0
saveAppInfo.forEachIndexed { index, appInfo ->
if(appInfo.packageName==appInfoItem.packageName&&appInfo.label==appInfoItem.label){
tempIndex=index
if (appInfo.packageName == appInfoItem.packageName && appInfo.label == appInfoItem.label) {
tempIndex = index
}
}
saveAppInfo.removeAt(tempIndex)
saveAppPackageSet.remove(appInfoItem.packageName)
MMKV.defaultMMKV().encode(BZYConstants.APPSETTINGINFO, Gson().toJson(saveAppInfo))
MMKV.defaultMMKV()
.encode(BZYConstants.APPSETTINGINFO, Gson().toJson(saveAppInfo))
}
}
MMKV.defaultMMKV().encode(BZYConstants.APP_SETTING_PACKAGE_INFO,saveAppPackageSet)
serStore.packages=saveAppPackageSet
MMKV.defaultMMKV().encode(BZYConstants.APP_SETTING_PACKAGE_INFO, saveAppPackageSet)
serStore.packages = saveAppPackageSet
serStore.accessControlPackages = saveAppPackageSet
saveAppPackageSet.forEach { setItem -> com.yingmao.clash.common.log.Log.d("saveAppPackageSet item==>${setItem}") }
iAAdapter.notifyDataSetChanged()
}
@ -217,40 +235,43 @@ class InstallApplicationActivity : BaseActivity() {
selectAllMain()
}
}
private fun selectAllMain() {
if (!isSelectAll) {
var i = 0
val j: Int = iAAdapter.getChoose().size
while (i < j) {
iAAdapter.getChoose().get(i).isChoose=true
iAAdapter.getChoose().get(i).isChoose = true
i++
}
index = iAAdapter.getChoose().size
indexBase=iAAdapter.getChoose().size
TVChooseName.text=resources.getString(R.string.cancel)+resources.getString(R.string.SelectAll)
indexBase = iAAdapter.getChoose().size
TVChooseName.text =
resources.getString(R.string.cancel) + resources.getString(R.string.SelectAll)
tableTitleCB.setImageResource(R.drawable.ic_xianzhong)
isSelectAll = true
val saveChoose = iAAdapter.getChoose()
saveChoose.forEach {
it.isChoose=true
it.isChoose = true
}
MMKV.defaultMMKV().removeValueForKey(BZYConstants.APPSETTINGINFO)
val gson = Gson()
MMKV.defaultMMKV().encode(BZYConstants.APPSETTINGINFO, gson.toJson(saveChoose))
MMKV.defaultMMKV().removeValueForKey(BZYConstants.APP_SETTING_PACKAGE_INFO)
saveAppPackageSet.clear()
serStore.packages=saveAppPackageSet
serStore.packages = saveAppPackageSet
serStore.accessControlPackages = saveAppPackageSet
} else {
var i = 0
val j: Int = iAAdapter.getChoose().size
while (i < j) {
iAAdapter.getChoose().get(i).isChoose=false
iAAdapter.getChoose().get(i).isChoose = false
i++
}
index = 0
indexBase=0
TVChooseName.text=getString(R.string.SelectAll)
indexBase = 0
TVChooseName.text = getString(R.string.SelectAll)
tableTitleCB.setImageResource(R.drawable.ic_weixianzhong)
isSelectAll = false
@ -259,10 +280,12 @@ class InstallApplicationActivity : BaseActivity() {
MMKV.defaultMMKV().removeValueForKey(BZYConstants.APP_SETTING_PACKAGE_INFO)
saveAppPackageSet.clear()
serStore.packages=saveAppPackageSet
serStore.packages = saveAppPackageSet
serStore.accessControlPackages = saveAppPackageSet
}
iAAdapter.notifyDataSetChanged()
}
/**
* 获取手机已安装应用列表
* @param ctx
@ -270,8 +293,8 @@ class InstallApplicationActivity : BaseActivity() {
* @return
*/
fun getAllLauncherIconPackages(context: Context): MutableList<AppInfoEntity> {
val appBeanList= mutableListOf<AppInfoEntity>()
var appInfoBean:AppInfoEntity
val appBeanList = mutableListOf<AppInfoEntity>()
var appInfoBean: AppInfoEntity
val intent = Intent()
intent.setAction(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_LAUNCHER)
@ -279,20 +302,29 @@ class InstallApplicationActivity : BaseActivity() {
context.packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL)
queryIntentActivities.forEach {
val applicationInfo =
packageManager.getApplicationInfo(it.activityInfo.packageName, PackageManager.GET_META_DATA)
if(it.activityInfo.processName!="com.yingmao.clash:background"){
packageManager.getApplicationInfo(
it.activityInfo.packageName,
PackageManager.GET_META_DATA
)
if (it.activityInfo.processName != "com.yingmao.clash:background") {
val imageStr = drawableToString(it.activityInfo.loadIcon(packageManager))
if(imageStr!=null){
appInfoBean=AppInfoEntity(packageManager.getApplicationLabel(applicationInfo).toString(),it.activityInfo.processName,imageStr,false)
if (imageStr != null) {
appInfoBean = AppInfoEntity(
packageManager.getApplicationLabel(applicationInfo).toString(),
it.activityInfo.processName,
imageStr,
false
)
appBeanList.add(appInfoBean)
}else{
Log.i("LevelTST","转换数据有问题!!")
} else {
Log.i("LevelTST", "转换数据有问题!!")
}
}
}
return appBeanList
}
//将drawable转化成字符串
private fun drawableToString(drawable: Drawable?): String? {
if (drawable != null) {
@ -321,8 +353,9 @@ class InstallApplicationActivity : BaseActivity() {
return Base64.encodeToString(imagedata, Base64.DEFAULT)
}
return null
return null
}
private fun showLoadingDialog(content: String) {
if (!::rxDialogShapeLoading.isInitialized) {
rxDialogShapeLoading = RxDialogShapeLoading(this)

View File

@ -28,6 +28,9 @@ import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.customview.getCustomView
import com.airbnb.lottie.LottieAnimationView
import com.fm.openinstall.OpenInstall
import com.fm.openinstall.listener.AppInstallListener
import com.fm.openinstall.model.AppData
import com.google.gson.Gson
import com.google.gson.JsonArray
import com.google.gson.JsonObject
@ -78,7 +81,6 @@ import com.yingmao.clash.view.dialog.RxDialogShapeLoading
import com.yingmao.clash.vm.MainAtyVM
import com.yingmao.clash.webview.BZYWebViewKeFu
import com.yingmao.clash.webview.BZYWebViewNormal
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
@ -94,6 +96,7 @@ import java.util.Timer
import java.util.TimerTask
import java.util.UUID
class NewMainActivity : BaseActivity() {
@ -207,7 +210,7 @@ class NewMainActivity : BaseActivity() {
// }
//登录失效
if (uploadRequestLogs.code=="-3"){
if (uploadRequestLogs.code == "-3") {
}
}
@ -263,6 +266,7 @@ class NewMainActivity : BaseActivity() {
startLog()
// showBindAccount()
firstEntry()
}
/*
@ -504,7 +508,7 @@ class NewMainActivity : BaseActivity() {
val data = httpStatus.rsp as SubscriptionRsp
if (data.code == "1000") {
} else {
RxToast.error(resources.getString(R.string.NodeAcquisitionFailed)+"${data.msg}")
RxToast.error(resources.getString(R.string.NodeAcquisitionFailed) + "${data.msg}")
}
data.data?.let { url ->
android.util.Log.e("Data", "机场URL=${url}")
@ -526,9 +530,11 @@ class NewMainActivity : BaseActivity() {
gifMins = it.signGiftmins;
}
}
RxToast.success(resources.getString(R.string.CheckFailed).replace("%d","${gifMins}"))
RxToast.success(
resources.getString(R.string.CheckFailed).replace("%d", "${gifMins}")
)
} else {
RxToast.error(resources.getString(R.string.CheckFailed)+"${data.message}")
RxToast.error(resources.getString(R.string.CheckFailed) + "${data.message}")
}
} else if (httpStatus.reqType == HttpReqType.GetActivity) {
val data = httpStatus.rsp as GetActivityRsp
@ -578,7 +584,7 @@ class NewMainActivity : BaseActivity() {
} else if (httpStatus.reqType == HttpReqType.GET_AIRNODES) {
Logger.e("获取节点异常:${httpStatus.msg}")
} else if (httpStatus.reqType == HttpReqType.VIPSIGN) {
RxToast.error(resources.getString(R.string.CheckFailed)+httpStatus.msg)
RxToast.error(resources.getString(R.string.CheckFailed) + httpStatus.msg)
} else {
}
@ -650,7 +656,7 @@ class NewMainActivity : BaseActivity() {
Log.d("cleanProfile go delete name==>${profile.name}, uuid==>${profile.uuid}")
pm.delete(profile.uuid)
}
}?:let {
} ?: let {
Log.d("profileBinder is null")
}
}
@ -675,7 +681,8 @@ class NewMainActivity : BaseActivity() {
// }
// })
findViewById<TextView>(R.id.tv_version).text = resources.getString(R.string.edition)+"${BuildConfig.VERSION_NAME}."+BuildConfig.productId
findViewById<TextView>(R.id.tv_version).text =
resources.getString(R.string.edition) + "${BuildConfig.VERSION_NAME}." + BuildConfig.productId
if (MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_IS_PERFECT)) {
// 临时用户显示默认密码
@ -929,22 +936,22 @@ class NewMainActivity : BaseActivity() {
var isExpire = checkExpire()
var endTimeInfo = "--"
if (isExpire) {
endTimeInfo =resources.getString(R.string.AccountExpired)
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()){
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 locale = Locale.ENGLISH
SimpleDateFormat("MM/dd/yyyy HH:mm",locale)
SimpleDateFormat("MM/dd/yyyy HH:mm", locale)
} else {
val locale = Locale.ENGLISH
SimpleDateFormat("MM/dd/yyyy HH:mm",locale)
SimpleDateFormat("MM/dd/yyyy HH:mm", locale)
}
endTimeInfo = dateFormat.format(validPeriod)
} else {
@ -955,17 +962,17 @@ class NewMainActivity : BaseActivity() {
}
endTimeInfo = dateFormat.format(validPeriod)
}
}else{
if(decodeString == "English"){
} 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)
SimpleDateFormat("MM/dd/yyyy HH:mm", locale)
} else {
val locale = Locale.ENGLISH
SimpleDateFormat("MM/dd/yyyy HH:mm",locale)
SimpleDateFormat("MM/dd/yyyy HH:mm", locale)
}
endTimeInfo = dateFormat.format(validPeriod)
}else{
} else {
val dateFormat = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
SimpleDateFormat("yyyy年MM月dd日 HH:mm")
} else {
@ -1013,7 +1020,7 @@ class NewMainActivity : BaseActivity() {
override fun loading(progress: Int) {
lifecycleScope.async {
pb_down.progress = progress
tv_down.text =resources.getString(R.string.download)+"$progress%"
tv_down.text = resources.getString(R.string.download) + "$progress%"
}
}
@ -1038,7 +1045,7 @@ class NewMainActivity : BaseActivity() {
}
override fun onRequestPermissionsResult(
requestCode: Int, permissions: Array<out String>, grantResults: IntArray
requestCode: Int, permissions: Array<out String>, grantResults: IntArray,
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == REQUEST_CODE_WRITE_STORAGE) {

View File

@ -16,16 +16,17 @@ import com.yingmao.clash.common.log.Log
import com.yingmao.clash.conf.BZYConstants
import com.yingmao.clash.fragment.NewAccFragment
import com.yingmao.clash.service.model.AccessControlMode
import com.yingmao.clash.view.RxToast
import com.yingmao.clash.view.popwindow.CommonPopupWindow
import okio.ByteString.Companion.encode
class ProxyModeActivity : BaseActivity() {
var proxyModeAtyVM: ProxyModeAtyVM? = null
private lateinit var llApplicationMode:LinearLayout
private lateinit var TVApplicationModeTxt:TextView
private lateinit var llControlApplication:LinearLayout
private lateinit var radioApplicationMode:RadioButton
private lateinit var llApplicationMode: LinearLayout
private lateinit var TVApplicationModeTxt: TextView
private lateinit var llControlApplication: LinearLayout
private lateinit var radioApplicationMode: RadioButton
private var popupWindow: CommonPopupWindow? = null
private var layoutGravity: CommonPopupWindow.LayoutGravity? = null
override fun onCreate(savedInstanceState: Bundle?) {
@ -49,10 +50,10 @@ class ProxyModeActivity : BaseActivity() {
radio_but_global = findViewById<RadioButton>(R.id.radio_but_global)
pm = findViewById<LinearLayout>(R.id.ll_pac_mode)
gm = findViewById<LinearLayout>(R.id.ll_global_model)
llApplicationMode=findViewById(R.id.llApplicationMode)
TVApplicationModeTxt=findViewById(R.id.TVApplicationModeTxt)
llControlApplication=findViewById(R.id.llControlApplication)
radioApplicationMode=findViewById(R.id.radioApplicationMode)
llApplicationMode = findViewById(R.id.llApplicationMode)
TVApplicationModeTxt = findViewById(R.id.TVApplicationModeTxt)
llControlApplication = findViewById(R.id.llControlApplication)
radioApplicationMode = findViewById(R.id.radioApplicationMode)
val isGlobal = MMKV.defaultMMKV().decodeBool(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
Log.d("initView isGlobal==>${isGlobal}")
// if (isGlobal) {
@ -61,11 +62,17 @@ class ProxyModeActivity : BaseActivity() {
// } else {
// ivPacMode.visibility = View.VISIBLE
// }
setBackground(isGlobal)
var px = ProxyMode.PAC
if (isGlobal) {
px = ProxyMode.GLOBAL
} else {
px = ProxyMode.PAC
}
setBackground(px)
pm.setOnClickListener {
// ivPacMode.visibility = View.VISIBLE
// ivGlobal.visibility = View.INVISIBLE
setBackground(false)
setBackground(ProxyMode.PAC)
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
goFinish()
}
@ -73,49 +80,51 @@ class ProxyModeActivity : BaseActivity() {
// ivPacMode.visibility = View.INVISIBLE
// ivGlobal.visibility = View.VISIBLE
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, true)
setBackground(true)
setBackground(ProxyMode.GLOBAL)
goFinish()
}
radioApplicationMode.setOnClickListener {
// setBackground(ProxyMode.PACKAGE)
}
radio_but_pac.setOnClickListener {
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, false)
setBackground(false)
setBackground(ProxyMode.PAC)
goFinish()
}
radio_but_global.setOnClickListener {
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_GLOBAL_MODEL, true)
setBackground(true)
setBackground(ProxyMode.GLOBAL)
goFinish()
}
// getNodes()
val amStr = MMKV.defaultMMKV().decodeString(BZYConstants.applicationMode,"")
if(!amStr.isNullOrEmpty()){
when(amStr) {
"" -> {
TVApplicationModeTxt.setText(R.string.allow_all_apps)
}
val amStr = MMKV.defaultMMKV().decodeString(BZYConstants.applicationMode, "")
if (!amStr.isNullOrEmpty()) {
when (amStr) {
"" -> {
TVApplicationModeTxt.setText(R.string.allow_all_apps)
}
"AllApp" -> {
TVApplicationModeTxt.setText(R.string.allow_all_apps)
}
"AllApp" -> {
TVApplicationModeTxt.setText(R.string.allow_all_apps)
}
"ChooseApp" -> {
TVApplicationModeTxt.setText(R.string.allow_selected_apps)
}
"ChooseApp" -> {
TVApplicationModeTxt.setText(R.string.allow_selected_apps)
}
"noChooseApp" -> {
TVApplicationModeTxt.setText(R.string.deny_selected_apps)
}
}
"noChooseApp" -> {
TVApplicationModeTxt.setText(R.string.deny_selected_apps)
}
}
}
llApplicationMode.setOnClickListener {
pm.setBackgroundResource(R.drawable.setting_bg_shape)
gm.setBackgroundResource(R.drawable.setting_bg_shape)
llApplicationMode.setBackgroundResource(R.drawable.setting_bg_shape_selected)
radio_but_global.isChecked = false
radio_but_pac.isChecked = false
radioApplicationMode.isChecked=true
if (NewAccFragment.clashRunning) {
RxToast.info("请关闭加速后再选择.");
return@setOnClickListener
}
popupWindow = object : CommonPopupWindow(
this,
R.layout.applicationmode_popwindow_item,
@ -134,35 +143,36 @@ class ProxyModeActivity : BaseActivity() {
val noChooseApp = view.findViewById<LinearLayout>(R.id.LLNoChoose)
val tvNoChooseApp = view.findViewById<TextView>(R.id.TVNoChoose)
val applicationModeStr = MMKV.defaultMMKV().decodeString(BZYConstants.applicationMode)
if(applicationModeStr.isNullOrEmpty()){
val applicationModeStr =
MMKV.defaultMMKV().decodeString(BZYConstants.applicationMode)
if (applicationModeStr.isNullOrEmpty()) {
allApp.setBackgroundResource(R.color.color_clash)
tvAllApp.setTextColor(resources.getColor(R.color.white))
}else if(applicationModeStr=="AllApp"){
} else if (applicationModeStr == "AllApp") {
allApp.setBackgroundResource(R.color.color_clash)
tvAllApp.setTextColor(resources.getColor(R.color.white))
}else if(applicationModeStr=="ChooseApp"){
} else if (applicationModeStr == "ChooseApp") {
chooseApp.setBackgroundResource(R.color.color_clash)
tvChooseApp.setTextColor(resources.getColor(R.color.white))
}else if(applicationModeStr=="noChooseApp"){
} else if (applicationModeStr == "noChooseApp") {
noChooseApp.setBackgroundResource(R.color.color_clash)
tvNoChooseApp.setTextColor(resources.getColor(R.color.white))
}
allApp.setOnClickListener {
serStore.accessControlMode= AccessControlMode.AcceptAll
MMKV.defaultMMKV().encode(BZYConstants.applicationMode,"AllApp")
serStore.accessControlMode = AccessControlMode.AcceptAll
MMKV.defaultMMKV().encode(BZYConstants.applicationMode, "AllApp")
TVApplicationModeTxt.setText(R.string.allow_all_apps)
popupWindow.dismiss()
}
chooseApp.setOnClickListener {
serStore.accessControlMode= AccessControlMode.AcceptSelected
MMKV.defaultMMKV().encode(BZYConstants.applicationMode,"ChooseApp")
serStore.accessControlMode = AccessControlMode.AcceptSelected
MMKV.defaultMMKV().encode(BZYConstants.applicationMode, "ChooseApp")
TVApplicationModeTxt.setText(R.string.allow_selected_apps)
popupWindow.dismiss()
}
noChooseApp.setOnClickListener {
serStore.accessControlMode= AccessControlMode.DenySelected
MMKV.defaultMMKV().encode(BZYConstants.applicationMode,"noChooseApp")
serStore.accessControlMode = AccessControlMode.DenySelected
MMKV.defaultMMKV().encode(BZYConstants.applicationMode, "noChooseApp")
TVApplicationModeTxt.setText(R.string.deny_selected_apps)
popupWindow.dismiss()
}
@ -170,44 +180,74 @@ class ProxyModeActivity : BaseActivity() {
override fun initEvent() {}
}
layoutGravity=CommonPopupWindow.LayoutGravity(CommonPopupWindow.LayoutGravity.ALIGN_LEFT or CommonPopupWindow.LayoutGravity.TO_BOTTOM)
(popupWindow as CommonPopupWindow).showBashOfAnchor(TVApplicationModeTxt, layoutGravity, 0, 0)
layoutGravity =
CommonPopupWindow.LayoutGravity(CommonPopupWindow.LayoutGravity.ALIGN_LEFT or CommonPopupWindow.LayoutGravity.TO_BOTTOM)
(popupWindow as CommonPopupWindow).showBashOfAnchor(
TVApplicationModeTxt,
layoutGravity,
0,
0
)
}
llControlApplication.setOnClickListener {
startActivity(Intent(this,InstallApplicationActivity::class.java))
startActivity(Intent(this, InstallApplicationActivity::class.java))
}
}
private fun goFinish(){
private fun goFinish() {
val intent = Intent()
setResult(Activity.RESULT_OK, intent)
finish()
}
private fun setBackground(isGlobal: Boolean) {
NewAccFragment.isGlo = isGlobal
private fun setBackground(proxyMode: ProxyMode) {
when (proxyMode) {
ProxyMode.PAC -> {
NewAccFragment.isGlo = false
radio_but_global.isChecked = false
radio_but_pac.isChecked = true
radioApplicationMode.isChecked = false
pm.setBackgroundResource(R.drawable.setting_bg_shape_selected)
gm.setBackgroundResource(R.drawable.setting_bg_shape)
llApplicationMode.setBackgroundResource(R.drawable.setting_bg_shape)
sendMode(false)
}
ProxyMode.GLOBAL -> {
NewAccFragment.isGlo = true
radio_but_global.isChecked = true
radio_but_pac.isChecked = false
radioApplicationMode.isChecked = false
pm.setBackgroundResource(R.drawable.setting_bg_shape)
gm.setBackgroundResource(R.drawable.setting_bg_shape_selected)
llApplicationMode.setBackgroundResource(R.drawable.setting_bg_shape)
sendMode(true)
}
ProxyMode.PACKAGE -> {
// pm.setBackgroundResource(R.drawable.setting_bg_shape)
// gm.setBackgroundResource(R.drawable.setting_bg_shape)
// llApplicationMode.setBackgroundResource(R.drawable.setting_bg_shape_selected)
// radio_but_global.isChecked = false
// radio_but_pac.isChecked = false
// radioApplicationMode.isChecked = true
}
}
}
fun sendMode(type: Boolean) {
val intent = Intent(Intents.ACTION_Glo_Mode)
intent.putExtra("mode", isGlobal)
intent.putExtra("mode", type)
sendBroadcast(
intent.setPackage(this.packageName)
)
if (isGlobal) {
radio_but_global.isChecked = true
radio_but_pac.isChecked = false
radioApplicationMode.isChecked=false
pm.setBackgroundResource(R.drawable.setting_bg_shape)
gm.setBackgroundResource(R.drawable.setting_bg_shape_selected)
llApplicationMode.setBackgroundResource(R.drawable.setting_bg_shape)
} else {
radio_but_global.isChecked = false
radio_but_pac.isChecked = true
radioApplicationMode.isChecked=false
pm.setBackgroundResource(R.drawable.setting_bg_shape_selected)
gm.setBackgroundResource(R.drawable.setting_bg_shape)
llApplicationMode.setBackgroundResource(R.drawable.setting_bg_shape)
}
}
enum class ProxyMode {
PAC, GLOBAL, PACKAGE
}
}

View File

@ -21,6 +21,9 @@ import com.yingmao.clash.view.dialog.RxDialogSureCancel
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.fm.openinstall.OpenInstall
import com.fm.openinstall.listener.AppInstallListener
import com.fm.openinstall.model.AppData
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.gson.JsonParser
@ -94,7 +97,6 @@ class SplashActivity : BaseActivity() {
setContentView(R.layout.layout_splash_activity)
rlPb = findViewById(R.id.rl_pb)
ll_action = findViewById(R.id.ll_action)
// mPermissions.add(Manifest.permission.READ_PHONE_STATE)
// mPermissions.add(Manifest.permission.INTERNET)
// mPermissions.add(Manifest.permission.ACCESS_NETWORK_STATE)
@ -106,6 +108,22 @@ class SplashActivity : BaseActivity() {
// }
// }
// OpenInstall.getInstall(object : AppInstallListener {
// override fun onInstallFinish(
// appData: AppData?,
// error: com.fm.openinstall.model.Error?,
// ) {
// var mAppData = appData
// if (error != null && error.shouldRetry()) {
// // 获取数据异常,可以尝试重新获取
// } else {
// if (mAppData == null) mAppData = AppData()
// val channelCode = mAppData.getChannel() // 获取渠道编号参数
// val bindData = mAppData.getData() // 获取自定义参数
// com.yingmao.clash.common.log.Log.d("channelCode==>${channelCode}, bindData==>${bindData}")
// }
// }
// })
var clashBinder = MainApplication.getApp()?.let {
ClashManager(it).wrap() as IClashManager
@ -152,8 +170,8 @@ class SplashActivity : BaseActivity() {
}
}
}
// val Sgtr= AESUtil.decrypt("DCBF7D3857DB252D9D07265D9EB7F2CF2DD5B6070C6BF6B4EC88A1452B8C30834BBC82465ECD117CAA816E18AF526EBA5749AFA0E504F7EE178912BAFAA308268326299157402233C4C3D7319B1843C680C340F137060762ED370DE8DDB5516A51DE118EE83C6C556B579D2C7B1612D98C64153D11334425298E096461A899DF")
// val Sgtr= AESUtil.Registerdecrypt("CCBF308D702235C8F810876987A43AB02B84EBB47DBFF1B915D5FBB29FF2DBAE90DB72D58351D09D223D49E44A2A073D9156E84D6B7EB89D7493A3F0A7240EE076ADC83B5A12AC37616CEDED00643AD1E6851AFECA82E373CB4E518DF2190708F5191AE195758E8EA41A5242A6C94216B64FF8715B35C54CB894113FC93361F32FDA86CF34093DF924230DEBE27A69293C761A9A797A652A1C35C95C27FB5EB4"
// ,registerKey,registerIV2)
// println("Sgtr==>$Sgtr")
}

View File

@ -11,6 +11,7 @@ import androidx.annotation.RequiresApi
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.getSystemService
import com.fm.openinstall.OpenInstall
import com.orhanobut.logger.Logger
import com.tencent.mmkv.MMKV
import com.yingmao.clash.R
@ -79,6 +80,8 @@ class MainApplication : Application() {
val crashCatchHandler: CrashCatchHandler = CrashCatchHandler.getInstance() //获得单例
crashCatchHandler.init(applicationContext) //初始化,传入context
//openinstall
// OpenInstall.init(applicationContext);
}
fun updateActivity(language:String,locale: Locale){
MMKV.defaultMMKV().encode(BZYConstants.languageInfo, language)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -132,7 +132,18 @@
android:layout_height="wrap_content">
</RadioButton>
</LinearLayout>
<View
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:background="@color/white"
android:layout_height="1dp">
</View>
<LinearLayout
android:layout_marginTop="10dp"
android:id="@+id/llApplicationMode"
@ -171,13 +182,14 @@
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/allow_all_apps"
android:textColor="@color/white_70"
android:textColor="@color/red"
android:textSize="13sp" />
</LinearLayout>
<RadioButton
android:id="@+id/radioApplicationMode"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RadioButton>

View File

@ -245,7 +245,7 @@
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone"
android:visibility="visible"
android:paddingRight="30dp"
android:paddingLeft="30dp"
android:paddingTop="@dimen/dp_10"