Skip to content

Commit

Permalink
feat: quick tile to apply a random wallpaper
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Nov 20, 2023
1 parent 544e582 commit 89f1c2b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 25 deletions.
11 changes: 11 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@
</intent-filter>
</receiver>

<service
android:name=".util.WallpaperChangerTileService"
android:exported="true"
android:icon="@drawable/ic_qs_tile"
android:label="@string/random_wallpaper"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.bnyro.wallpaper.util

import android.os.Build
import android.os.Handler
import android.os.Looper
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
import androidx.annotation.RequiresApi
import androidx.core.os.postDelayed
import androidx.work.ExistingWorkPolicy
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager

@RequiresApi(Build.VERSION_CODES.N)
class WallpaperChangerTileService : TileService() {
override fun onStartListening() {
super.onStartListening()

qsTile.state = Tile.STATE_INACTIVE
qsTile.updateTile()
}

override fun onClick() {
super.onClick()

val oneTimeJob = OneTimeWorkRequestBuilder<BackgroundWorker>()
.build()

WorkManager.getInstance(this)
.enqueueUniqueWork(TILE_WORKER_KEY, ExistingWorkPolicy.KEEP, oneTimeJob)

qsTile.state = Tile.STATE_ACTIVE
qsTile.updateTile()

Handler(Looper.getMainLooper()).postDelayed(3000) {
qsTile.state = Tile.STATE_INACTIVE
qsTile.updateTile()
}
}

companion object {
private const val TILE_WORKER_KEY = "tile_worker_key"
}
}
12 changes: 0 additions & 12 deletions app/src/main/java/com/bnyro/wallpaper/util/WorkerHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ object WorkerHelper {
return
}


val repeatIntervalMinutes = Preferences.getString(
Preferences.wallpaperChangerIntervalKey,
Preferences.defaultWallpaperChangeInterval.toString()
Expand All @@ -49,15 +48,4 @@ object WorkerHelper {
WorkManager.getInstance(context)
.enqueueUniquePeriodicWork(JOB_NAME, policy, job)
}

/**
fun enqueueTestWorker(context: Context) {
val job = OneTimeWorkRequestBuilder<BackgroundWorker>()
.setConstraints(getWorkerConstraints())
.build()
WorkManager.getInstance(context)
.enqueue(job)
}
**/
}
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/ic_qs_tile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<vector android:height="24dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="24dp"
xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#1a1a1a" android:fillType="evenOdd"
android:pathData="m431.27,347.53 l-127.92,-170.55 -65.19,86.77 -26.64,-35.51 72.91,-97.04c9.48,-12.62 28.41,-12.61 37.88,0.02l165.79,221.06c11.71,15.61 0.57,37.89 -18.95,37.89L42.86,390.16c-19.52,0 -30.66,-22.28 -18.95,-37.89L118.64,225.96c9.41,-12.54 28.16,-12.63 37.7,-0.26l88.53,118.04 2.86,3.79zM80.75,347.53L194.43,347.53L137.59,271.75Z" android:strokeWidth="1.38765"/>
</vector>
13 changes: 0 additions & 13 deletions app/src/main/res/drawable/ic_wallhaven.xml

This file was deleted.

1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<string name="home">Home screen</string>
<string name="lockscreen">Lockscreen</string>
<string name="applying_random">Applying random wallpaper</string>
<string name="random_wallpaper">Random wallpaper</string>
<!-- Image Filters -->
<string name="blur">Blur</string>
<string name="grayscale">Grayscale</string>
Expand Down

0 comments on commit 89f1c2b

Please sign in to comment.