From 45c3c6d2bc7adb831239a9c86d2a05017d69461d Mon Sep 17 00:00:00 2001 From: Paul Colby Date: Thu, 20 Jun 2024 21:57:25 +1000 Subject: [PATCH] Make the tile more responsive Will clean-up / refactor a little after some initial testing. --- .../java/au/id/colby/nfcquicksettings/NfcTileService.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/main/java/au/id/colby/nfcquicksettings/NfcTileService.kt b/app/src/main/java/au/id/colby/nfcquicksettings/NfcTileService.kt index 39b3afb..087b1b5 100644 --- a/app/src/main/java/au/id/colby/nfcquicksettings/NfcTileService.kt +++ b/app/src/main/java/au/id/colby/nfcquicksettings/NfcTileService.kt @@ -85,11 +85,20 @@ class NfcTileService : TileService() { Log.i(TAG, "Have WRITE_SECURE_SETTINGS permission") val adapter: NfcAdapter? = NfcAdapter.getDefaultAdapter(this) adapter?.apply { + val wasEnabled = adapter.isEnabled val methodName = if (adapter.isEnabled) "disable" else "enable" try { Log.d(TAG, "Invoking NfcAdapter::$methodName()") val result = NfcAdapter::class.java.getMethod(methodName).invoke(adapter) Log.d(TAG, "NfcAdapter::$methodName() returned $result") + qsTile?.apply { + Log.d(TAG, "Updating tile") + state = if (!wasEnabled) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE + if (SDK_INT >= Build.VERSION_CODES.Q) subtitle = getText( + if (!wasEnabled) string.tile_subtitle_active else string.tile_subtitle_inactive + ) + updateTile() + } if (result is Boolean && result) return // Success; return early. } catch (e: Exception) { Log.e(TAG, "Failed to invoke NfcAdapter::$methodName()", e)