Skip to content

Commit 26f1ade

Browse files
committed
feat: Clipboard tile subtitle text
1 parent c322cf1 commit 26f1ade

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

app/src/main/java/com/sameerasw/airsync/service/ClipboardTileService.kt

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import com.sameerasw.airsync.utils.WebSocketUtil
1515
import kotlinx.coroutines.CoroutineScope
1616
import kotlinx.coroutines.Dispatchers
1717
import kotlinx.coroutines.SupervisorJob
18+
import kotlinx.coroutines.flow.first
1819
import kotlinx.coroutines.launch
1920
import kotlinx.coroutines.cancel
21+
import com.sameerasw.airsync.data.local.DataStoreManager
2022

2123
@RequiresApi(Build.VERSION_CODES.N)
2224
class ClipboardTileService : TileService() {
@@ -93,19 +95,27 @@ class ClipboardTileService : TileService() {
9395
// Removed direct sendClipboard method as it is now handled by the Activity
9496

9597
private fun updateTileState(isConnected: Boolean) {
96-
try {
97-
qsTile?.apply {
98-
state = if (isConnected) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
99-
val labelText = if (isConnected) "Send Clipboard" else "Not Connected"
100-
label = labelText
101-
102-
// Using existing icon as placeholder
103-
// icon = Icon.createWithResource(this@ClipboardTileService, R.drawable.ic_laptop_24)
104-
105-
updateTile()
98+
serviceScope.launch {
99+
try {
100+
val dataStoreManager = DataStoreManager.getInstance(this@ClipboardTileService)
101+
val connectedDevice = dataStoreManager.getLastConnectedDevice().first()
102+
val deviceName = connectedDevice?.name ?: getString(R.string.your_mac)
103+
104+
qsTile?.apply {
105+
state = if (isConnected) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
106+
107+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
108+
subtitle = if (isConnected) deviceName else getString(R.string.disconnected)
109+
} else {
110+
val labelText = if (isConnected) "Send Clipboard ($deviceName)" else "Not Connected"
111+
label = labelText
112+
}
113+
114+
updateTile()
115+
}
116+
} catch (e: Exception) {
117+
Log.e(TAG, "Error updating tile state", e)
106118
}
107-
} catch (e: Exception) {
108-
Log.e(TAG, "Error updating tile state", e)
109119
}
110120
}
111121
}

0 commit comments

Comments
 (0)