use proxy order from GLOBAL & add tile

This commit is contained in:
Kr328 committed 2019-12-07 15:48:45 +08:00
1 parent ea29017687
commit 1069ba1991
6 files changed
+99 -5

No files matched your search

+2 -2
View File
@@ -11,8 +11,8 @@ android {
applicationId "com.github.kr328.clash"
minSdkVersion 24
targetSdkVersion 29
versionCode 10005
versionName "1.0.5-alpha"
versionCode 10006
versionName "1.0.6-alpha"
}
buildTypes {
release {
+11 -1
View File
@@ -10,7 +10,7 @@
android:name=".MainApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/launch_name"
android:label="@string/application_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
@@ -86,6 +86,16 @@
<service
android:name=".ClashStartService"
android:exported="false" />
<service
android:name=".TileService"
android:label="@string/launch_name"
android:icon="@drawable/ic_logo"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>
<receiver
android:name=".BootCompleteReceiver"
android:exported="true"
@@ -78,6 +78,8 @@ class ProxyActivity : BaseActivity() {
runClash { clash ->
val packet = clash.queryAllProxies()
val proxies = packet.proxies
val order = (proxies["GLOBAL".hashCode()] ?: error("GLOBAL not found")).all
.mapIndexed { index, i -> i to index }.toMap()
val listData = proxies
.asSequence()
@@ -101,7 +103,7 @@ class ProxyActivity : BaseActivity() {
{
it.value.type != ProxyPacket.Type.SELECT
}, {
it.value.name
order[it.key] ?: 0
})
)
.flatMap {
@@ -0,0 +1,76 @@
package com.github.kr328.clash
import android.content.*
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
import com.github.kr328.clash.core.event.ProcessEvent
import com.github.kr328.clash.service.ClashService
import com.github.kr328.clash.service.Constants
import com.github.kr328.clash.service.IClashService
import com.github.kr328.clash.utils.ServiceUtils
class TileService : TileService() {
override fun onClick() {
val tile = qsTile
when ( tile.state ) {
Tile.STATE_INACTIVE -> {
ServiceUtils.startProxyService(this)
}
Tile.STATE_ACTIVE -> {
val binder = clashStatusReceiver.peekService(this, Intent(this, ClashService::class.java))
runCatching {
val clash = IClashService.Stub.asInterface(binder)
clash?.stop()
}
}
}
}
override fun onStartListening() {
refreshTileStatus()
}
private fun refreshTileStatus() {
when ( currentStatus ) {
ProcessEvent.STARTED -> {
qsTile.state = Tile.STATE_ACTIVE
}
ProcessEvent.STOPPED -> {
qsTile.state = Tile.STATE_INACTIVE
}
}
qsTile.updateTile()
}
private val clashStatusReceiver = object: BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
refreshTileStatus()
}
}
override fun onCreate() {
super.onCreate()
registerReceiver(clashStatusReceiver,
IntentFilter(Constants.CLASH_PROCESS_BROADCAST_ACTION))
}
override fun onDestroy() {
super.onDestroy()
unregisterReceiver(clashStatusReceiver)
}
private val currentStatus: ProcessEvent
get() {
val service = clashStatusReceiver.peekService(this, Intent(this, ClashService::class.java))
return runCatching {
IClashService.Stub.asInterface(service)?.currentProcessStatus
}.getOrNull() ?: ProcessEvent.STOPPED
}
}
@@ -8,7 +8,6 @@ import android.content.IntentFilter
import android.os.*
import com.github.kr328.clash.callback.IUrlTestCallback
import com.github.kr328.clash.core.Clash
import com.github.kr328.clash.core.ClashProcess
import com.github.kr328.clash.core.event.*
import com.github.kr328.clash.core.model.GeneralPacket
import com.github.kr328.clash.core.model.ProxyPacket
@@ -253,6 +252,8 @@ class ClashService : Service(), IClashEventObserver, ClashEventService.Master,
stopSelf()
}
}
sendBroadcast(Intent(Constants.CLASH_PROCESS_BROADCAST_ACTION).setPackage(packageName))
}
private fun reloadProfile() {
@@ -0,0 +1,5 @@
package com.github.kr328.clash.service
object Constants {
const val CLASH_PROCESS_BROADCAST_ACTION = "com.github.kr328.clash.ClashService.ClashProcessEvent"
}