Skip to content

Commit da3a7fb

Browse files
committed
Merge branch 'main' into gradle-versions-check
2 parents 7df8db4 + dd32c2b commit da3a7fb

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

CHANGELOG.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
## [Unreleased][]
44

5+
## [1.3.0][] (2023-10-21)
6+
7+
Added tile update timer to solve race condition.
8+
9+
## [1.2.2][] (2023-10-20)
10+
11+
Fixed potential crash when tile is added to Quick Settings menu.
12+
513
## [1.2.1][] (2023-10-20)
614

715
Exclude devices without NFC hardware.
@@ -18,7 +26,9 @@ Added translations for 86 languages.
1826

1927
Initial release.
2028

21-
[Unreleased]: https://github.com/pcolby/nfc-quick-settings/compare/v1.2.1...HEAD
29+
[Unreleased]: https://github.com/pcolby/nfc-quick-settings/compare/v1.3.0...HEAD
30+
[1.3.0]: https://github.com/pcolby/nfc-quick-settings/releases/tag/v1.3.0
31+
[1.2.2]: https://github.com/pcolby/nfc-quick-settings/releases/tag/v1.2.2
2232
[1.2.1]: https://github.com/pcolby/nfc-quick-settings/releases/tag/v1.2.1
2333
[1.2.0]: https://github.com/pcolby/nfc-quick-settings/releases/tag/v1.2.0
2434
[1.1.0]: https://github.com/pcolby/nfc-quick-settings/releases/tag/v1.1.0

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ android {
3030
applicationId "au.id.colby.nfcquicksettings"
3131
minSdk 24
3232
targetSdk 34
33-
versionCode 6
34-
versionName "1.2.1-post"
33+
versionCode 8
34+
versionName "1.3.0-post"
3535
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3636
}
3737

app/src/main/java/au/id/colby/nfcquicksettings/NfcTileService.kt

+30-11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import android.service.quicksettings.Tile
1515
import android.service.quicksettings.TileService
1616
import android.util.Log
1717
import au.id.colby.nfcquicksettings.R.*
18+
import java.util.Timer
19+
import kotlin.concurrent.fixedRateTimer
1820

1921
/**
2022
* A custom Quick Settings tile for NFC.
@@ -24,6 +26,7 @@ import au.id.colby.nfcquicksettings.R.*
2426
*/
2527
class NfcTileService : TileService() {
2628
private val TAG = "NfcTileService"
29+
private var updateTimer: Timer? = null
2730

2831
/**
2932
* Called when this tile moves into a listening state.
@@ -34,18 +37,34 @@ class NfcTileService : TileService() {
3437
override fun onStartListening() {
3538
super.onStartListening()
3639
Log.d(TAG, "onStartListening")
37-
if (qsTile == null) {
38-
Log.i(TAG, "qsTile is null; won't update at this time.")
39-
return
40-
}
4140
val adapter: NfcAdapter? = NfcAdapter.getDefaultAdapter(this)
42-
qsTile.state = if (adapter == null) Tile.STATE_UNAVAILABLE else
43-
if (adapter.isEnabled) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
44-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) qsTile.subtitle = getText(
45-
if (adapter == null) string.tile_subtitle_unavailable else
46-
if (adapter.isEnabled) string.tile_subtitle_active else string.tile_subtitle_inactive
47-
)
48-
qsTile.updateTile()
41+
updateTimer = fixedRateTimer("default", false, 0L, 500) {
42+
Log.d(TAG, "updateTimer")
43+
qsTile?.apply {
44+
Log.d(TAG, "Updating tile")
45+
state = if (adapter == null) Tile.STATE_INACTIVE else
46+
if (adapter.isEnabled) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
47+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) subtitle = getText(
48+
if (adapter == null) string.tile_subtitle_unavailable else
49+
if (adapter.isEnabled) string.tile_subtitle_active else string.tile_subtitle_inactive
50+
)
51+
updateTile()
52+
}
53+
}
54+
}
55+
56+
/**
57+
* Called when this tile moves out of the listening state.
58+
*
59+
* This override cancels the update timer, if any is running.
60+
*/
61+
override fun onStopListening() {
62+
Log.d(TAG, "onStopListening")
63+
updateTimer?.apply {
64+
Log.d(TAG, "Cancelling update timer")
65+
cancel()
66+
}
67+
super.onStopListening()
4968
}
5069

5170
/**

0 commit comments

Comments
 (0)