feat: добавлена поддержка Quick Settings Tile

This commit is contained in:
samosvalishe committed 2026-06-01 14:50:11 +03:00
1 parent bd714c4de3
commit fab6f0b7b3
4 files changed
+87

No files matched your search

+12
View File
@@ -73,5 +73,17 @@
</intent-filter>
</receiver>
<service
android:name=".ProxyTileService"
android:exported="true"
android:icon="@drawable/ic_qs_tile_nearby"
android:label="@string/tile_service_label"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
tools:targetApi="24">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>
</application>
</manifest>
@@ -0,0 +1,61 @@
package com.freeturn.app
import android.content.Intent
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import android.os.Build
import androidx.annotation.RequiresApi
@RequiresApi(Build.VERSION_CODES.N)
class ProxyTileService : TileService() {
private var scope: CoroutineScope? = null
private var isProxyRunning = false
override fun onStartListening() {
super.onStartListening()
scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
ProxyServiceState.isRunning.onEach { running ->
isProxyRunning = running
updateTileState()
}.launchIn(scope!!)
}
override fun onStopListening() {
super.onStopListening()
scope?.cancel()
scope = null
}
override fun onClick() {
super.onClick()
if (isProxyRunning) {
val intent = Intent(this, ProxyReceiver::class.java).apply {
action = "com.freeturn.app.STOP_PROXY"
}
sendBroadcast(intent)
} else {
val intent = Intent(this, ProxyReceiver::class.java).apply {
action = "com.freeturn.app.START_PROXY"
}
sendBroadcast(intent)
}
}
private fun updateTileState() {
val tile = qsTile ?: return
if (isProxyRunning) {
tile.state = Tile.STATE_ACTIVE
} else {
tile.state = Tile.STATE_INACTIVE
}
tile.icon = android.graphics.drawable.Icon.createWithResource(this, R.drawable.ic_qs_tile_nearby)
tile.updateTile()
}
}
@@ -0,0 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="796"
android:viewportHeight="796"
android:tint="?attr/colorControlNormal">
<group
android:translateX="-82"
android:translateY="-82">
<path
android:fillColor="@android:color/white"
android:pathData="M480,656L304,480L480,304L656,480L480,656ZM536,855Q525,866 510,872Q495,878 480,878Q465,878 450,872Q435,866 424,855L105,536Q94,525 88,510Q82,495 82,480Q82,465 88,450Q94,435 105,424L423,106Q435,94 449.5,88Q464,82 480,82Q496,82 510.5,88Q525,94 537,106L855,424Q866,435 872,450Q878,465 878,480Q878,495 872,510Q866,525 855,536L536,855ZM480,768L768,480Q768,480 768,480Q768,480 768,480L480,192Q480,192 480,192Q480,192 480,192L192,480Q192,480 192,480Q192,480 192,480L480,768Q480,768 480,768Q480,768 480,768Z"/>
</group>
</vector>