Skip to content

Commit 80c665f

Browse files
authored
Merge pull request #88 from swingmx/search
Fix: Renew Tokens Automatically
2 parents fc4656d + 8f206ff commit 80c665f

File tree

3 files changed

+25
-39
lines changed

3 files changed

+25
-39
lines changed

.github/images/readme.webp

336 KB
Loading

README.md

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<div align="center"><b><sub><code>v1.0.0</code></sub></b></div>
77

8-
**<div align="center" style="padding-top: 1.25rem">[Download](https://swingmx.com/downloads) • <a href="https://github.com/sponsors/swingmx" target="_blank">Sponsor Us ❤️</a> • [Swing Music Docs](https://swingmx.com/guide/introduction.html)[r/SwingMusicApp](https://www.reddit.com/r/SwingMusicApp)</div>**
8+
**<div align="center" style="padding-top: 1.25rem">[Download](https://github.com/swingmx/android/releases) • <a href="https://github.com/sponsors/swingmx" target="_blank">Sponsor Us ❤️</a> • [Swing Music Docs](https://swingmx.com/guide/introduction.html)[r/SwingMusicApp](https://www.reddit.com/r/SwingMusicApp)</div>**
99

1010
##
1111

@@ -15,11 +15,10 @@ This client application allows you to stream music on your Android device from y
1515

1616
Below is a list of the currently implemented features:
1717

18-
- Playback
19-
- Search tracks
20-
- Album and artist views
2118
- Folders view
22-
- Albums and artist views
19+
- Playback
20+
- Albums and Artist view
21+
- Search Tracks, Albums, Artists
2322
- Playlists can be viewed in the folder view by enabling the `Show Playlists in folder view` option in `Settings > Folders` in the webclient.
2423

2524
More features will be implemented in the future.
@@ -28,29 +27,11 @@ More features will be implemented in the future.
2827

2928
Download the app from the [releases page](https://github.com/swingmx/android/releases) and install the APK. When you launch the app, you should be prompted to scan a QR code or enter your server details manually.
3029

31-
You can to to `Settings > Pair device` on the webclient to get the QR code.
30+
You can go to `Settings > Pair device` on the webclient to get the QR code.
3231

3332
## Screenshots
3433

35-
<table>
36-
<tr>
37-
<td>
38-
<img src="https://github.com/swingmx/android/assets/54077752/0344f6f9-dd70-4a4f-adf9-2a883758af28" width="320" alt="image" />
39-
</td>
40-
<td>
41-
<img src="https://github.com/swingmx/android/assets/54077752/59649546-295b-4e40-8e3e-8e03dd1f7dd7" width="320" alt="image" />
42-
</td>
43-
</tr>
44-
<!--
45-
<tr>
46-
<td>
47-
<img src="https://github.com/swingmx/android/assets/54077752/de0abb9d-95ed-4e2f-91ff-20dbf5288809" width="320" alt="image" />
48-
</td>
49-
<td>
50-
<img src="" width="320" alt="" />
51-
</td>
52-
</tr> -->
53-
</table>
34+
![Image](.github/images/readme.webp)
5435

5536
<!-- [![wakatime](https://wakatime.com/badge/user/99206146-a1fc-4be5-adc8-c2351f27ecef/project/018e7aae-f9e9-42e9-99e1-fc381580884d.svg)](https://wakatime.com/badge/user/99206146-a1fc-4be5-adc8-c2351f27ecef/project/018e7aae-f9e9-42e9-99e1-fc381580884d) -->
5637

auth/src/main/java/com/android/swingmusic/auth/data/workmanager/ScheduleTokenRefreshWork.kt

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,33 @@ import androidx.work.Constraints
66
import androidx.work.ExistingPeriodicWorkPolicy
77
import androidx.work.NetworkType
88
import androidx.work.PeriodicWorkRequestBuilder
9+
import androidx.work.WorkInfo
910
import androidx.work.WorkManager
1011
import java.util.concurrent.TimeUnit
1112

1213
fun scheduleTokenRefreshWork(context: Context) {
13-
val constraints = Constraints.Builder()
14-
.setRequiredNetworkType(NetworkType.CONNECTED)
15-
.setRequiresBatteryNotLow(true)
16-
.build()
14+
val workManager = WorkManager.getInstance(context)
15+
val workInfos = workManager.getWorkInfosForUniqueWork(TokenRefreshWorker.WORK_NAME).get()
1716

18-
val tokenRefreshWorkRequest = PeriodicWorkRequestBuilder<TokenRefreshWorker>(21, TimeUnit.DAYS)
19-
.setConstraints(constraints)
20-
.setBackoffCriteria(
21-
BackoffPolicy.EXPONENTIAL,
22-
1,
23-
TimeUnit.HOURS
24-
)
25-
.build()
17+
// .KEEP failed to work consistently, So, I added this check.
18+
if (workInfos.none { it.state in listOf(WorkInfo.State.ENQUEUED, WorkInfo.State.RUNNING)}) {
19+
val constraints = Constraints.Builder()
20+
.setRequiredNetworkType(NetworkType.CONNECTED)
21+
.build()
22+
23+
val tokenRefreshWorkRequest = PeriodicWorkRequestBuilder<TokenRefreshWorker>(6, TimeUnit.HOURS)
24+
.setConstraints(constraints)
25+
.setBackoffCriteria(
26+
BackoffPolicy.EXPONENTIAL,
27+
15,
28+
TimeUnit.MINUTES
29+
)
30+
.build()
2631

27-
WorkManager.getInstance(context)
28-
.enqueueUniquePeriodicWork(
32+
workManager.enqueueUniquePeriodicWork(
2933
TokenRefreshWorker.WORK_NAME,
3034
ExistingPeriodicWorkPolicy.KEEP,
3135
tokenRefreshWorkRequest
3236
)
37+
}
3338
}

0 commit comments

Comments
 (0)