diff --git a/README.md b/README.md index b8eac4e..99b74ad 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Turn your GitHub contribution graph into a phone wallpaper. - **Android** support: 70+ devices across Samsung, Google Pixel, OnePlus, Xiaomi, Nothing, Motorola, Sony, ASUS, OPPO, vivo, Realme, and Honor - Shows contribution stats: total count and current streak - iOS Shortcut-compatible URL for daily auto-updating wallpapers (iPhone) -- GitWall Android app (`android/`) that sets the lock screen from the same URL and refreshes daily +- GitWall Android app (`android/`) that sets the lock screen and/or home screen from the same URL and refreshes daily - In-memory caching with 5-minute TTL ## Setup @@ -69,14 +69,14 @@ The API returns proper status codes: `400` for a missing or malformed username, 1. Generate your wallpaper and copy the Shortcut URL 2. Open iOS Shortcuts → New Shortcut 3. Add **Get Contents of URL** with the copied URL -4. Add **Set Wallpaper** using the result +4. Add **Set Wallpaper Photo** using the result and choose Lock Screen, Home Screen, or both 5. Automate it: Automation → Time of Day → run daily **Android (GitWall app)** 1. Generate your wallpaper and copy the URL (no phone model needed) 2. Install the GitWall app from the website's **Download APK** button (`/download/android`) 3. Tap **Open in GitWall app**, or paste the URL into the app -4. Tap **Set lock screen wallpaper**. The app appends your phone's real resolution, sets the lock screen directly through Android's wallpaper API, and refreshes daily at a time you pick (06:00 by default) +4. Choose Lock screen, Home screen, or both, then tap **Set wallpaper**. The app appends your phone's real resolution, sets the wallpaper directly through Android's wallpaper API, and refreshes daily at a time you pick (06:00 by default) Task-automation apps such as MacroDroid cannot do this reliably: Android copies wallpapers into private system storage, so replacing a file on disk never changes the lock screen, and newer Android versions block writes to shared folders. diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 4de1cbf..c3984a9 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -24,8 +24,8 @@ android { applicationId = "space.gitwall.app" minSdk = 26 targetSdk = 35 - versionCode = 2 - versionName = "1.1.0" + versionCode = 3 + versionName = "1.2.0" } signingConfigs { diff --git a/android/app/src/main/java/space/gitwall/app/MainActivity.kt b/android/app/src/main/java/space/gitwall/app/MainActivity.kt index 9d01a81..2b23778 100644 --- a/android/app/src/main/java/space/gitwall/app/MainActivity.kt +++ b/android/app/src/main/java/space/gitwall/app/MainActivity.kt @@ -41,6 +41,8 @@ import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface +import androidx.compose.material3.Switch +import androidx.compose.material3.SwitchDefaults import androidx.compose.material3.Text import androidx.compose.material3.darkColorScheme import androidx.compose.runtime.Composable @@ -167,6 +169,10 @@ private fun Screen(incomingUrl: String?, onIncomingConsumed: () -> Unit) { } fun apply() { + if (!settings.lockScreen && !settings.homeScreen) { + message = "Turn on Lock screen, Home screen, or both." + return + } when (val check = prepareWallpaperUrl(url, size)) { is UrlCheck.Invalid -> message = check.reason is UrlCheck.Ok -> { @@ -238,6 +244,15 @@ private fun Screen(incomingUrl: String?, onIncomingConsumed: () -> Unit) { } } + Spacer(Modifier.height(14.dp)) + Card { + Label("Apply to") + Spacer(Modifier.height(4.dp)) + ToggleRow("Lock screen", settings.lockScreen) { store.saveTargets(it, settings.homeScreen); message = null } + Divider() + ToggleRow("Home screen", settings.homeScreen) { store.saveTargets(settings.lockScreen, it); message = null } + } + Spacer(Modifier.height(14.dp)) Button( onClick = ::apply, @@ -253,7 +268,7 @@ private fun Screen(incomingUrl: String?, onIncomingConsumed: () -> Unit) { } RunState.WAITING_NETWORK -> Text("Waiting for internet", fontWeight = FontWeight.Bold, fontSize = 15.sp) RunState.IDLE -> Text( - if (settings.lastSuccessAt > 0L) "Update lock screen now" else "Set lock screen wallpaper", + if (settings.lastSuccessAt > 0L) "Update wallpaper now" else "Set wallpaper", fontWeight = FontWeight.Bold, fontSize = 15.sp, ) } @@ -305,7 +320,7 @@ private fun Header() { Spacer(Modifier.width(12.dp)) Column { Text("GitWall", color = TextPrimary, fontSize = 24.sp, fontWeight = FontWeight.ExtraBold, letterSpacing = (-0.5).sp) - Text("Your contribution graph, on your lock screen.", color = TextMuted, fontSize = 13.sp) + Text("Your contribution graph, as your wallpaper.", color = TextMuted, fontSize = 13.sp) } } } @@ -390,10 +405,10 @@ private fun UrlField(value: String, onChange: (String) -> Unit) { private fun StatusCard(settings: Settings, runState: RunState, size: ScreenSize) { val context = LocalContext.current val (tone, headline) = when { - runState == RunState.RUNNING -> Green to "Setting your lock screen…" + runState == RunState.RUNNING -> Green to "Setting your wallpaper…" runState == RunState.WAITING_NETWORK -> Amber to "Waiting for an internet connection." settings.lastError != null -> Danger to "Last attempt failed" - settings.lastSuccessAt > 0L -> Green to "Lock screen updated " + relative(settings.lastSuccessAt) + settings.lastSuccessAt > 0L -> Green to "Wallpaper updated " + relative(settings.lastSuccessAt) else -> TextMuted to "Not set yet" } Card { @@ -420,6 +435,25 @@ private fun StatusCard(settings: Settings, runState: RunState, size: ScreenSize) } } +@Composable +private fun ToggleRow(label: String, checked: Boolean, onChange: (Boolean) -> Unit) { + Row( + Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).clickable { onChange(!checked) }.padding(vertical = 6.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, + ) { + Text(label, color = TextPrimary, fontSize = 14.sp) + Switch( + checked = checked, + onCheckedChange = onChange, + colors = SwitchDefaults.colors( + checkedThumbColor = Ink, checkedTrackColor = Green, + uncheckedThumbColor = TextMuted, uncheckedTrackColor = PanelRaised, uncheckedBorderColor = Line, + ), + ) + } +} + @Composable private fun InfoRow(key: String, value: String) { Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) { diff --git a/android/app/src/main/java/space/gitwall/app/RefreshWorker.kt b/android/app/src/main/java/space/gitwall/app/RefreshWorker.kt index e8727a9..dd1c024 100644 --- a/android/app/src/main/java/space/gitwall/app/RefreshWorker.kt +++ b/android/app/src/main/java/space/gitwall/app/RefreshWorker.kt @@ -17,7 +17,7 @@ import kotlinx.coroutines.withContext import java.util.concurrent.TimeUnit /** - * Downloads the wallpaper and sets the lock screen. Three things enqueue it: + * Downloads the wallpaper and sets the chosen screens. Three things enqueue it: * the exact daily alarm, the user tapping the button, and the periodic * safety net. The periodic run steps aside when the alarm already did the job. */ @@ -38,7 +38,7 @@ class RefreshWorker(context: Context, params: WorkerParameters) : CoroutineWorke return@withContext Result.failure() } try { - WallpaperApplier.applyLockScreen(applicationContext, prepared.url) + WallpaperApplier.apply(applicationContext, prepared.url, settings.lockScreen, settings.homeScreen) store.recordSuccess() Result.success() } catch (e: WallpaperException) { diff --git a/android/app/src/main/java/space/gitwall/app/Settings.kt b/android/app/src/main/java/space/gitwall/app/Settings.kt index d40870d..d9fb07c 100644 --- a/android/app/src/main/java/space/gitwall/app/Settings.kt +++ b/android/app/src/main/java/space/gitwall/app/Settings.kt @@ -11,6 +11,9 @@ data class Settings( /** Daily refresh time, local clock. */ val refreshHour: Int = 6, val refreshMinute: Int = 0, + /** Which wallpapers to set. At least one is always on. */ + val lockScreen: Boolean = true, + val homeScreen: Boolean = false, val lastSuccessAt: Long = 0L, val lastAttemptAt: Long = 0L, val lastError: String? = null, @@ -27,6 +30,8 @@ class SettingsStore(context: Context) { url = prefs.getString(KEY_URL, "") ?: "", refreshHour = prefs.getInt(KEY_HOUR, 6), refreshMinute = prefs.getInt(KEY_MINUTE, 0), + lockScreen = prefs.getBoolean(KEY_LOCK, true), + homeScreen = prefs.getBoolean(KEY_HOME, false), lastSuccessAt = prefs.getLong(KEY_LAST_SUCCESS, 0L), lastAttemptAt = prefs.getLong(KEY_LAST_ATTEMPT, 0L), lastError = prefs.getString(KEY_LAST_ERROR, null), @@ -48,6 +53,10 @@ class SettingsStore(context: Context) { prefs.edit().putInt(KEY_HOUR, hour.coerceIn(0, 23)).putInt(KEY_MINUTE, minute.coerceIn(0, 59)).apply() } + fun saveTargets(lockScreen: Boolean, homeScreen: Boolean) { + prefs.edit().putBoolean(KEY_LOCK, lockScreen).putBoolean(KEY_HOME, homeScreen).apply() + } + fun saveNextRun(at: Long) { prefs.edit().putLong(KEY_NEXT_RUN, at).apply() } @@ -65,6 +74,8 @@ class SettingsStore(context: Context) { const val KEY_URL = "url" const val KEY_HOUR = "refresh_hour" const val KEY_MINUTE = "refresh_minute" + const val KEY_LOCK = "target_lock" + const val KEY_HOME = "target_home" const val KEY_LAST_SUCCESS = "last_success" const val KEY_LAST_ATTEMPT = "last_attempt" const val KEY_LAST_ERROR = "last_error" diff --git a/android/app/src/main/java/space/gitwall/app/WallpaperApplier.kt b/android/app/src/main/java/space/gitwall/app/WallpaperApplier.kt index 3809717..957b8fd 100644 --- a/android/app/src/main/java/space/gitwall/app/WallpaperApplier.kt +++ b/android/app/src/main/java/space/gitwall/app/WallpaperApplier.kt @@ -11,13 +11,18 @@ class WallpaperException(message: String) : Exception(message) /** * Downloads the PNG into memory and hands it to WallpaperManager for the lock - * screen. Nothing is written to shared storage, so it does not matter how a - * manufacturer stores or copies wallpapers internally. + * screen, the home screen, or both. Nothing is written to shared storage, so it + * does not matter how a manufacturer stores or copies wallpapers internally. */ object WallpaperApplier { private const val MAX_BYTES = 40L * 1024 * 1024 - fun applyLockScreen(context: Context, url: String) { + fun apply(context: Context, url: String, lockScreen: Boolean, homeScreen: Boolean) { + var flags = 0 + if (lockScreen) flags = flags or WallpaperManager.FLAG_LOCK + if (homeScreen) flags = flags or WallpaperManager.FLAG_SYSTEM + if (flags == 0) throw WallpaperException("Choose at least one screen to set.") + val bytes = download(url) val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size) ?: throw WallpaperException("The server did not return an image.") @@ -27,7 +32,7 @@ object WallpaperApplier { throw WallpaperException("This device or profile does not allow apps to change the wallpaper.") } try { - manager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK) + manager.setBitmap(bitmap, null, true, flags) } catch (e: IOException) { throw WallpaperException("Android refused the wallpaper: ${e.message ?: "unknown error"}") } finally { diff --git a/public/gitwall.apk b/public/gitwall.apk index 401171a..949f01a 100644 Binary files a/public/gitwall.apk and b/public/gitwall.apk differ diff --git a/src/app/page.tsx b/src/app/page.tsx index d9b4539..3b32e74 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -490,7 +490,7 @@ export default function Home() { -

“Set Wallpaper Photo” → choose Lock Screen.

+

“Set Wallpaper Photo” → under Set, choose Lock Screen, Home Screen, or Lock Screen and Home Screen.

Important: In “Set Wallpaper Photo”, tap the arrow (→) to show options → disable both “Crop to Subject” and “Show Preview”. This stops iOS from cropping the image and asking for confirmation every day. @@ -508,7 +508,7 @@ export default function Home() {

Enter your GitHub username, choose a theme above, then tap Generate. No phone model needed: the app measures your screen.

-

A small app that does one thing: fetches your wallpaper and sets it as the lock screen, then repeats every day at a time you choose.

+

A small app that does one thing: fetches your wallpaper and sets it on your lock screen, home screen, or both, then repeats every day at a time you choose.

-

In the app tap Set lock screen wallpaper. Your lock screen updates right away and refreshes every day at the time you choose (6:00 by default).

+

In the app, turn on Lock screen, Home screen, or both, then tap Set wallpaper. It updates right away and refreshes every day at the time you choose (6:00 by default).

Tap Allow next to Background refresh so Android lets the app fetch while the phone sleeps.

If your phone has a rotating lock screen feature such as Samsung Dynamic Lock screen or Xiaomi Wallpaper Carousel, turn it off or it will replace GitWall.