Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bb05ea13b | ||
|
|
e30b51e5e4 | ||
|
|
3fc9facf32 | ||
|
|
dbd80fe3fa | ||
|
|
d1ad40b213 | ||
|
|
2adcf1a318 | ||
|
|
80c70f82ee | ||
|
|
faf40edf30 | ||
|
|
29be20ca10 | ||
|
|
8d3701bc6a | ||
|
|
76cb388199 | ||
|
|
e4b0eab824 | ||
|
|
c9bdce1484 | ||
|
|
db01ecab9c | ||
|
|
229c54258c | ||
|
|
2d6b905c07 | ||
|
|
48562bf01c | ||
|
|
d51e0920d0 | ||
|
|
d2fb14dcd0 | ||
|
|
82e5fbd5e9 | ||
|
|
da506a4df7 | ||
|
|
6b682980b9 | ||
|
|
15769d2fe2 | ||
|
|
dd46dfc9d4 | ||
|
|
06738a4485 | ||
|
|
d0cad6f45c | ||
|
|
49ba1aafaf | ||
|
|
1a2c6eecd1 | ||
|
|
8634a59ee8 | ||
|
|
bc6bc2c405 | ||
|
|
707df3a25d | ||
|
|
e9cd2c388f | ||
|
|
50f6677c95 | ||
|
|
740175fb10 | ||
|
|
d94e1be668 | ||
|
|
6270d1c2be |
No files matched your search
@@ -0,0 +1,3 @@
|
||||
* text=auto eol=lf
|
||||
*.bat text eol=crlf
|
||||
*.jar binary
|
||||
@@ -0,0 +1,69 @@
|
||||
name: Paperize Android Debug CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["dev-LFA"]
|
||||
pull_request:
|
||||
branches: ["dev-LFA"]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
test-and-lint:
|
||||
name: Run unit tests and lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out source code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: "17"
|
||||
distribution: temurin
|
||||
|
||||
- name: Set up Android SDK
|
||||
uses: android-actions/setup-android@v3
|
||||
with:
|
||||
packages: platform-tools
|
||||
|
||||
- name: Install Android SDK 37
|
||||
run: sdkmanager --install "platforms;android-37.0" "build-tools;37.0.0"
|
||||
|
||||
- name: Run unit tests and lint
|
||||
run: ./gradlew testDebugUnitTest lintDebug
|
||||
|
||||
build:
|
||||
name: Build debug APK
|
||||
if: github.event_name == 'push'
|
||||
needs: test-and-lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out source code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: "17"
|
||||
distribution: temurin
|
||||
|
||||
- name: Set up Android SDK
|
||||
uses: android-actions/setup-android@v3
|
||||
with:
|
||||
packages: platform-tools
|
||||
|
||||
- name: Install Android SDK 37
|
||||
run: sdkmanager --install "platforms;android-37.0" "build-tools;37.0.0"
|
||||
|
||||
- name: Build debug APK
|
||||
run: ./gradlew assembleDebug
|
||||
|
||||
- name: Upload debug APK
|
||||
uses: https://github.com/christopherHX/gitea-upload-artifact@v4
|
||||
with:
|
||||
name: paperize-debug-apk
|
||||
path: app/build/outputs/apk/debug/app-debug.apk
|
||||
if-no-files-found: error
|
||||
@@ -0,0 +1,80 @@
|
||||
name: Paperize Android Release CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main-LFA"]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
test-and-lint:
|
||||
name: Run unit tests and lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out source code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: "17"
|
||||
distribution: temurin
|
||||
|
||||
- name: Set up Android SDK
|
||||
uses: android-actions/setup-android@v3
|
||||
with:
|
||||
packages: platform-tools
|
||||
|
||||
- name: Install Android SDK 37
|
||||
run: sdkmanager --install "platforms;android-37.0" "build-tools;37.0.0"
|
||||
|
||||
- name: Run unit tests and lint
|
||||
run: ./gradlew testDebugUnitTest lintDebug
|
||||
|
||||
build:
|
||||
name: Build release APK
|
||||
needs: test-and-lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out source code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: "17"
|
||||
distribution: temurin
|
||||
|
||||
- name: Set up Android SDK
|
||||
uses: android-actions/setup-android@v3
|
||||
with:
|
||||
packages: platform-tools
|
||||
|
||||
- name: Install Android SDK 37
|
||||
run: sdkmanager --install "platforms;android-37.0" "build-tools;37.0.0"
|
||||
|
||||
- name: Build signed release APK
|
||||
env:
|
||||
SIGNING_KEYSTORE_BASE64: ${{ secrets.SIGNING_KEYSTORE_BASE64 }}
|
||||
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
|
||||
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
|
||||
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
: "${SIGNING_KEYSTORE_BASE64:?Missing SIGNING_KEYSTORE_BASE64 secret}"
|
||||
: "${SIGNING_KEY_ALIAS:?Missing SIGNING_KEY_ALIAS secret}"
|
||||
: "${SIGNING_STORE_PASSWORD:?Missing SIGNING_STORE_PASSWORD secret}"
|
||||
: "${SIGNING_KEY_PASSWORD:?Missing SIGNING_KEY_PASSWORD secret}"
|
||||
export SIGNING_KEYSTORE_PATH="$(mktemp "${RUNNER_TEMP}/paperize-keystore.XXXXXX")"
|
||||
trap 'rm -f "$SIGNING_KEYSTORE_PATH"' EXIT
|
||||
printf '%s' "$SIGNING_KEYSTORE_BASE64" | base64 --decode > "$SIGNING_KEYSTORE_PATH"
|
||||
./gradlew assembleRelease
|
||||
|
||||
- name: Upload release APK
|
||||
uses: https://github.com/christopherHX/gitea-upload-artifact@v4
|
||||
with:
|
||||
name: paperize-release-apk
|
||||
path: app/build/outputs/apk/release/app-release.apk
|
||||
if-no-files-found: error
|
||||
|
Before Width: | Height: | Size: 249 KiB After Width: | Height: | Size: 249 KiB |
|
Before Width: | Height: | Size: 234 KiB After Width: | Height: | Size: 234 KiB |
|
Before Width: | Height: | Size: 235 KiB After Width: | Height: | Size: 234 KiB |
|
Before Width: | Height: | Size: 193 KiB After Width: | Height: | Size: 193 KiB |
|
Before Width: | Height: | Size: 262 KiB After Width: | Height: | Size: 263 KiB |
|
Before Width: | Height: | Size: 252 KiB After Width: | Height: | Size: 253 KiB |
|
Before Width: | Height: | Size: 271 KiB After Width: | Height: | Size: 272 KiB |
|
Before Width: | Height: | Size: 237 KiB After Width: | Height: | Size: 237 KiB |
@@ -17,4 +17,5 @@ local.properties
|
||||
/app/build
|
||||
/app/release
|
||||
.kotlin
|
||||
/.kotlin/sessions
|
||||
/.kotlin/sessions
|
||||
*.jks
|
||||
@@ -49,6 +49,7 @@ An Android app that changes the home and lock screen wallpaper on a schedule: Ko
|
||||
- README is for users: what it does, how to get it, how to use it. No internals, no agent instructions.
|
||||
- This file is for agents: only what can't be found quickly in the code.
|
||||
- No meta docs in the repo (notes, audits, plans, reports).
|
||||
- Generated images are built from the orphan `media` branch; its README has the steps.
|
||||
|
||||
## Git
|
||||
|
||||
@@ -66,11 +67,10 @@ An Android app that changes the home and lock screen wallpaper on a schedule: Ko
|
||||
## Releases
|
||||
|
||||
- Bump commit `chore: release vX.Y.Z`; tag `vX.Y.Z`.
|
||||
- A pushed `v*` tag is the store submission. F-Droid picks the tag up by itself as soon as it is pushed, builds it, and compares its build with the release APK. CI attaches the signed `paperize-vX.Y.Z.apk` to the draft release for that tag, reusing a draft that already has the notes, but the APK is not public while the release is a draft: publish the draft as soon as CI has attached the APK, or the F-Droid comparison fails and has to be retried. Never rename a tag or asset.
|
||||
- A pushed `v*` tag is the store submission: F-Droid builds it straight away and compares the result with the release APK. CI attaches the signed APK to the tag's draft release (reusing a draft that already has notes), but a draft's APK isn't public: publish the draft as soon as CI has attached it, or the F-Droid comparison fails. Never rename a tag or asset.
|
||||
- Title `Paperize X.Y.Z`.
|
||||
- Notes: banner image first, then `### New`, `### Improved`, `### Fixed` (only those that apply). One line per change, written for users; no internals, dependency lists or test counts. End with the install links (APK, F-Droid, IzzyOnDroid) and the full changelog link.
|
||||
- Banner: generated and hosted on the orphan `media` branch; use `https://raw.githubusercontent.com/Anthonyy232/Paperize/media/releases/vX.Y.Z.png`.
|
||||
- The README, site and store listing images are built on the `media` branch too, from emulator captures; its README has the steps for both.
|
||||
- Banner: built and hosted on the `media` branch; reference its raw URL.
|
||||
- The site in `site/` hosts the privacy policy the store listing links to at `#privacy`; keep that anchor.
|
||||
|
||||
## Agents
|
||||
|
||||
@@ -20,7 +20,9 @@ Paperize is an Android app that changes your home and lock screen wallpaper on a
|
||||
<img src=".github/readme/feature-albums-light.png" alt="01. Albums, on rotation. The library with two albums, and an album open showing its wallpapers.">
|
||||
</picture>
|
||||
|
||||
An album holds single images, whole folders, or both. Paperize rescans folders each time you open the app, and once a day while a schedule is running, so new files join the rotation and deleted ones leave it by themselves; **Refresh folder** rescans one straight away. Removing something from an album never touches the file on your device.
|
||||
An album holds single images, whole folders, or both. Paperize rescans folders each time you open the app, and every hour while a schedule is running, so new files join the rotation and deleted ones leave it by themselves; **Refresh folder** rescans one straight away. Open an album's options menu to rename or delete it, filter it (encrypted albums), or rescan all its folders. Removing something from an album never touches the file on your device.
|
||||
|
||||
When creating an album, you can mark it encrypted; this choice is permanent and imports only `.jpg_enc` files made by wallpaper_changer. Set the same passphrase in **Settings → Encrypted albums**. **Filter wallpapers** in the album menu takes a regular expression matched (ignoring case) against each line of the folder's `naming_table.enc` (`name;encrypted file;hash`), as wallpaper_changer does; every image is imported but only matching ones are picked as wallpaper, and images in folders without a naming table never match. It is protected by Android Keystore and remains available for scheduled changes. Encrypted previews are off by default; enabling them decrypts images in memory without caching them to disk. Turning previews off removes them from the app's display. Android may still retain the applied wallpaper, and wallpaper_changer's encryption format does not authenticate its contents.
|
||||
|
||||
Supported formats: JPG, PNG, WEBP, AVIF, HEIC/HEIF, BMP, GIF and TIFF.
|
||||
|
||||
@@ -29,14 +31,14 @@ Supported formats: JPG, PNG, WEBP, AVIF, HEIC/HEIF, BMP, GIF and TIFF.
|
||||
<img src=".github/readme/feature-schedule-light.png" alt="02. Home and lock, your call. The wallpaper tab with the current lock and home wallpapers, an album for each, and the time interval.">
|
||||
</picture>
|
||||
|
||||
Turn on **Lock**, **Home** or both and pick an album for each. One interval covers both screens, from 15 minutes to 30 days; **Individual Scheduling** gives each screen its own. Wallpapers go in order unless **Shuffle** is on.
|
||||
Turn on **Lock**, **Home** or both and pick an album for each. One interval covers both screens, from 15 minutes to 30 days; **Individual Scheduling** gives each screen its own. Wallpapers go in order unless **Shuffle** is on. Tired of the one on screen? Tap the bin under it in **Current Wallpapers** to take it out of its album and move on to the next. An image removed from a folder stays out when the folder is rescanned, and tapping it under **Removed** in that folder puts it back.
|
||||
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset=".github/readme/feature-effects-dark.png">
|
||||
<img src=".github/readme/feature-effects-light.png" alt="03. Effects, to taste. Brightness, blur and vignette, each with a switch for home and lock and a strength slider.">
|
||||
</picture>
|
||||
|
||||
Brightness, blur, vignette and a gray filter each have a strength slider and separate switches for home and lock. **Adaptive Brightness** adjusts the wallpaper to the system's light or dark mode. Scaling is Fill, Fit, Stretch or None, and **Horizontal scrolling** lets a wide Fill wallpaper move between home-screen pages.
|
||||
Brightness, blur, vignette and a gray filter each have a strength slider and separate switches for home and lock. **Adaptive Brightness** adjusts the wallpaper to the system's light or dark mode. Scaling is Fill, Fit, Stretch or None. **Blurred background** fills the space around a Fit wallpaper with a blurred copy of it instead of black, and **Horizontal scrolling** lets a wide Fill wallpaper move between home-screen pages.
|
||||
|
||||
## How it works
|
||||
|
||||
@@ -88,6 +90,8 @@ cd Paperize
|
||||
|
||||
The APK lands in `app/build/outputs/apk/debug`. Or open the folder in Android Studio and press Run.
|
||||
|
||||
For the development setup with an emulator on `lucas@quiethost`, `./build_and_install.sh` builds locally, installs the debug app and test APK remotely, copies test images, and runs the tests. The Android tests can cancel wallpaper schedules in the installed app.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome. Report bugs in [issues](https://github.com/Anthonyy232/Paperize/issues), suggest features in [Discussions](https://github.com/Anthonyy232/Paperize/discussions), and read [AGENTS.md](AGENTS.md) before opening a pull request.
|
||||
|
||||
@@ -14,7 +14,9 @@ ksp {
|
||||
|
||||
android {
|
||||
namespace = "com.anthonyla.paperize"
|
||||
compileSdk = 37
|
||||
compileSdk {
|
||||
version = release(37) { minorApiLevel = 2 }
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
create("release") {
|
||||
@@ -77,6 +79,11 @@ android {
|
||||
baseline = file("lint-baseline.xml")
|
||||
// Crowdin exports no "many" form for Romance languages; Android falls back to "other".
|
||||
disable += "MissingQuantity"
|
||||
// App screens, not a library: a modifier no caller passes is dead weight.
|
||||
disable += "ComposeModifierMissing"
|
||||
// Dependabot handles updates; these fail the build whenever anything upstream releases.
|
||||
disable += listOf("AndroidGradlePluginVersion", "GradleDependency", "NewerVersionAvailable")
|
||||
warningsAsErrors = true
|
||||
}
|
||||
|
||||
dependenciesInfo {
|
||||
@@ -88,6 +95,7 @@ android {
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
jvmTarget.set(JvmTarget.JVM_17)
|
||||
allWarningsAsErrors = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +124,7 @@ dependencies {
|
||||
implementation(libs.androidx.hilt.work)
|
||||
implementation(libs.androidx.foundation)
|
||||
implementation(libs.androidx.profileinstaller)
|
||||
lintChecks(libs.compose.lint.checks)
|
||||
testImplementation(libs.junit)
|
||||
testImplementation(libs.mockk)
|
||||
testImplementation(libs.kotlinx.coroutines.test)
|
||||
|
||||
@@ -0,0 +1,512 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 5,
|
||||
"identityHash": "2457e5712f12294d683a5788349b5f84",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "albums",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `coverUri` TEXT, `createdAt` INTEGER NOT NULL, `modifiedAt` INTEGER NOT NULL, PRIMARY KEY(`id`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "coverUri",
|
||||
"columnName": "coverUri",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "createdAt",
|
||||
"columnName": "createdAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "modifiedAt",
|
||||
"columnName": "modifiedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tableName": "wallpapers",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `albumId` TEXT NOT NULL, `folderId` TEXT, `uri` TEXT NOT NULL, `fileName` TEXT NOT NULL, `dateModified` INTEGER NOT NULL, `displayOrder` INTEGER NOT NULL, `sourceType` TEXT NOT NULL, `addedAt` INTEGER NOT NULL, `mediaType` TEXT NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`albumId`) REFERENCES `albums`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`folderId`) REFERENCES `folders`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "albumId",
|
||||
"columnName": "albumId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "folderId",
|
||||
"columnName": "folderId",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "uri",
|
||||
"columnName": "uri",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "fileName",
|
||||
"columnName": "fileName",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "dateModified",
|
||||
"columnName": "dateModified",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "displayOrder",
|
||||
"columnName": "displayOrder",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "sourceType",
|
||||
"columnName": "sourceType",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "addedAt",
|
||||
"columnName": "addedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "mediaType",
|
||||
"columnName": "mediaType",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_wallpapers_albumId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"albumId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpapers_albumId` ON `${TABLE_NAME}` (`albumId`)"
|
||||
},
|
||||
{
|
||||
"name": "index_wallpapers_folderId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"folderId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpapers_folderId` ON `${TABLE_NAME}` (`folderId`)"
|
||||
},
|
||||
{
|
||||
"name": "index_wallpapers_uri",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"uri"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpapers_uri` ON `${TABLE_NAME}` (`uri`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "albums",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"albumId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table": "folders",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"folderId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "folders",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `albumId` TEXT NOT NULL, `name` TEXT NOT NULL, `uri` TEXT NOT NULL, `coverUri` TEXT, `dateModified` INTEGER NOT NULL, `displayOrder` INTEGER NOT NULL, `addedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`albumId`) REFERENCES `albums`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "albumId",
|
||||
"columnName": "albumId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "uri",
|
||||
"columnName": "uri",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "coverUri",
|
||||
"columnName": "coverUri",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "dateModified",
|
||||
"columnName": "dateModified",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "displayOrder",
|
||||
"columnName": "displayOrder",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "addedAt",
|
||||
"columnName": "addedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_folders_albumId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"albumId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_folders_albumId` ON `${TABLE_NAME}` (`albumId`)"
|
||||
},
|
||||
{
|
||||
"name": "index_folders_uri",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"uri"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_folders_uri` ON `${TABLE_NAME}` (`uri`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "albums",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"albumId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "wallpaper_queue",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `albumId` TEXT NOT NULL, `wallpaperId` TEXT NOT NULL, `screenType` TEXT NOT NULL, `queuePosition` INTEGER NOT NULL, `addedAt` INTEGER NOT NULL, FOREIGN KEY(`albumId`) REFERENCES `albums`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`wallpaperId`) REFERENCES `wallpapers`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "albumId",
|
||||
"columnName": "albumId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "wallpaperId",
|
||||
"columnName": "wallpaperId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "screenType",
|
||||
"columnName": "screenType",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "queuePosition",
|
||||
"columnName": "queuePosition",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "addedAt",
|
||||
"columnName": "addedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_wallpaper_queue_albumId_screenType",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"albumId",
|
||||
"screenType"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpaper_queue_albumId_screenType` ON `${TABLE_NAME}` (`albumId`, `screenType`)"
|
||||
},
|
||||
{
|
||||
"name": "index_wallpaper_queue_wallpaperId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"wallpaperId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpaper_queue_wallpaperId` ON `${TABLE_NAME}` (`wallpaperId`)"
|
||||
},
|
||||
{
|
||||
"name": "index_wallpaper_queue_queuePosition",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"queuePosition"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpaper_queue_queuePosition` ON `${TABLE_NAME}` (`queuePosition`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "albums",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"albumId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table": "wallpapers",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"wallpaperId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "wallpaper_current",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`albumId` TEXT NOT NULL, `screenType` TEXT NOT NULL, `wallpaperId` TEXT NOT NULL, `appliedAt` INTEGER NOT NULL, PRIMARY KEY(`albumId`, `screenType`), FOREIGN KEY(`albumId`) REFERENCES `albums`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`wallpaperId`) REFERENCES `wallpapers`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "albumId",
|
||||
"columnName": "albumId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "screenType",
|
||||
"columnName": "screenType",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "wallpaperId",
|
||||
"columnName": "wallpaperId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "appliedAt",
|
||||
"columnName": "appliedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"albumId",
|
||||
"screenType"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_wallpaper_current_wallpaperId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"wallpaperId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpaper_current_wallpaperId` ON `${TABLE_NAME}` (`wallpaperId`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "albums",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"albumId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table": "wallpapers",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"wallpaperId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "excluded_wallpapers",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`folderId` TEXT NOT NULL, `uri` TEXT NOT NULL, `id` TEXT NOT NULL, `fileName` TEXT NOT NULL, `dateModified` INTEGER NOT NULL, `displayOrder` INTEGER NOT NULL, `addedAt` INTEGER NOT NULL, PRIMARY KEY(`folderId`, `uri`), FOREIGN KEY(`folderId`) REFERENCES `folders`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "folderId",
|
||||
"columnName": "folderId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "uri",
|
||||
"columnName": "uri",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "fileName",
|
||||
"columnName": "fileName",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "dateModified",
|
||||
"columnName": "dateModified",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "displayOrder",
|
||||
"columnName": "displayOrder",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "addedAt",
|
||||
"columnName": "addedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"folderId",
|
||||
"uri"
|
||||
]
|
||||
},
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "folders",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"folderId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '2457e5712f12294d683a5788349b5f84')"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,519 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 6,
|
||||
"identityHash": "126e2fefe2b0a0804b9ce27d880edf8f",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "albums",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `coverUri` TEXT, `createdAt` INTEGER NOT NULL, `modifiedAt` INTEGER NOT NULL, `isEncrypted` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`id`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "coverUri",
|
||||
"columnName": "coverUri",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "createdAt",
|
||||
"columnName": "createdAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "modifiedAt",
|
||||
"columnName": "modifiedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isEncrypted",
|
||||
"columnName": "isEncrypted",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tableName": "wallpapers",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `albumId` TEXT NOT NULL, `folderId` TEXT, `uri` TEXT NOT NULL, `fileName` TEXT NOT NULL, `dateModified` INTEGER NOT NULL, `displayOrder` INTEGER NOT NULL, `sourceType` TEXT NOT NULL, `addedAt` INTEGER NOT NULL, `mediaType` TEXT NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`albumId`) REFERENCES `albums`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`folderId`) REFERENCES `folders`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "albumId",
|
||||
"columnName": "albumId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "folderId",
|
||||
"columnName": "folderId",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "uri",
|
||||
"columnName": "uri",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "fileName",
|
||||
"columnName": "fileName",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "dateModified",
|
||||
"columnName": "dateModified",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "displayOrder",
|
||||
"columnName": "displayOrder",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "sourceType",
|
||||
"columnName": "sourceType",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "addedAt",
|
||||
"columnName": "addedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "mediaType",
|
||||
"columnName": "mediaType",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_wallpapers_albumId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"albumId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpapers_albumId` ON `${TABLE_NAME}` (`albumId`)"
|
||||
},
|
||||
{
|
||||
"name": "index_wallpapers_folderId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"folderId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpapers_folderId` ON `${TABLE_NAME}` (`folderId`)"
|
||||
},
|
||||
{
|
||||
"name": "index_wallpapers_uri",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"uri"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpapers_uri` ON `${TABLE_NAME}` (`uri`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "albums",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"albumId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table": "folders",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"folderId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "folders",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `albumId` TEXT NOT NULL, `name` TEXT NOT NULL, `uri` TEXT NOT NULL, `coverUri` TEXT, `dateModified` INTEGER NOT NULL, `displayOrder` INTEGER NOT NULL, `addedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`albumId`) REFERENCES `albums`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "albumId",
|
||||
"columnName": "albumId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "uri",
|
||||
"columnName": "uri",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "coverUri",
|
||||
"columnName": "coverUri",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "dateModified",
|
||||
"columnName": "dateModified",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "displayOrder",
|
||||
"columnName": "displayOrder",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "addedAt",
|
||||
"columnName": "addedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_folders_albumId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"albumId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_folders_albumId` ON `${TABLE_NAME}` (`albumId`)"
|
||||
},
|
||||
{
|
||||
"name": "index_folders_uri",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"uri"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_folders_uri` ON `${TABLE_NAME}` (`uri`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "albums",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"albumId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "wallpaper_queue",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `albumId` TEXT NOT NULL, `wallpaperId` TEXT NOT NULL, `screenType` TEXT NOT NULL, `queuePosition` INTEGER NOT NULL, `addedAt` INTEGER NOT NULL, FOREIGN KEY(`albumId`) REFERENCES `albums`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`wallpaperId`) REFERENCES `wallpapers`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "albumId",
|
||||
"columnName": "albumId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "wallpaperId",
|
||||
"columnName": "wallpaperId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "screenType",
|
||||
"columnName": "screenType",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "queuePosition",
|
||||
"columnName": "queuePosition",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "addedAt",
|
||||
"columnName": "addedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_wallpaper_queue_albumId_screenType",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"albumId",
|
||||
"screenType"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpaper_queue_albumId_screenType` ON `${TABLE_NAME}` (`albumId`, `screenType`)"
|
||||
},
|
||||
{
|
||||
"name": "index_wallpaper_queue_wallpaperId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"wallpaperId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpaper_queue_wallpaperId` ON `${TABLE_NAME}` (`wallpaperId`)"
|
||||
},
|
||||
{
|
||||
"name": "index_wallpaper_queue_queuePosition",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"queuePosition"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpaper_queue_queuePosition` ON `${TABLE_NAME}` (`queuePosition`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "albums",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"albumId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table": "wallpapers",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"wallpaperId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "wallpaper_current",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`albumId` TEXT NOT NULL, `screenType` TEXT NOT NULL, `wallpaperId` TEXT NOT NULL, `appliedAt` INTEGER NOT NULL, PRIMARY KEY(`albumId`, `screenType`), FOREIGN KEY(`albumId`) REFERENCES `albums`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`wallpaperId`) REFERENCES `wallpapers`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "albumId",
|
||||
"columnName": "albumId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "screenType",
|
||||
"columnName": "screenType",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "wallpaperId",
|
||||
"columnName": "wallpaperId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "appliedAt",
|
||||
"columnName": "appliedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"albumId",
|
||||
"screenType"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_wallpaper_current_wallpaperId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"wallpaperId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpaper_current_wallpaperId` ON `${TABLE_NAME}` (`wallpaperId`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "albums",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"albumId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table": "wallpapers",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"wallpaperId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "excluded_wallpapers",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`folderId` TEXT NOT NULL, `uri` TEXT NOT NULL, `id` TEXT NOT NULL, `fileName` TEXT NOT NULL, `dateModified` INTEGER NOT NULL, `displayOrder` INTEGER NOT NULL, `addedAt` INTEGER NOT NULL, PRIMARY KEY(`folderId`, `uri`), FOREIGN KEY(`folderId`) REFERENCES `folders`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "folderId",
|
||||
"columnName": "folderId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "uri",
|
||||
"columnName": "uri",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "fileName",
|
||||
"columnName": "fileName",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "dateModified",
|
||||
"columnName": "dateModified",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "displayOrder",
|
||||
"columnName": "displayOrder",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "addedAt",
|
||||
"columnName": "addedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"folderId",
|
||||
"uri"
|
||||
]
|
||||
},
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "folders",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"folderId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '126e2fefe2b0a0804b9ce27d880edf8f')"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,524 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 7,
|
||||
"identityHash": "dd85d0b5892ec87e1bc8906b1f42a004",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "albums",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `coverUri` TEXT, `createdAt` INTEGER NOT NULL, `modifiedAt` INTEGER NOT NULL, `isEncrypted` INTEGER NOT NULL DEFAULT 0, `filter` TEXT, PRIMARY KEY(`id`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "coverUri",
|
||||
"columnName": "coverUri",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "createdAt",
|
||||
"columnName": "createdAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "modifiedAt",
|
||||
"columnName": "modifiedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isEncrypted",
|
||||
"columnName": "isEncrypted",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "filter",
|
||||
"columnName": "filter",
|
||||
"affinity": "TEXT"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tableName": "wallpapers",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `albumId` TEXT NOT NULL, `folderId` TEXT, `uri` TEXT NOT NULL, `fileName` TEXT NOT NULL, `dateModified` INTEGER NOT NULL, `displayOrder` INTEGER NOT NULL, `sourceType` TEXT NOT NULL, `addedAt` INTEGER NOT NULL, `mediaType` TEXT NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`albumId`) REFERENCES `albums`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`folderId`) REFERENCES `folders`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "albumId",
|
||||
"columnName": "albumId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "folderId",
|
||||
"columnName": "folderId",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "uri",
|
||||
"columnName": "uri",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "fileName",
|
||||
"columnName": "fileName",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "dateModified",
|
||||
"columnName": "dateModified",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "displayOrder",
|
||||
"columnName": "displayOrder",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "sourceType",
|
||||
"columnName": "sourceType",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "addedAt",
|
||||
"columnName": "addedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "mediaType",
|
||||
"columnName": "mediaType",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_wallpapers_albumId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"albumId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpapers_albumId` ON `${TABLE_NAME}` (`albumId`)"
|
||||
},
|
||||
{
|
||||
"name": "index_wallpapers_folderId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"folderId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpapers_folderId` ON `${TABLE_NAME}` (`folderId`)"
|
||||
},
|
||||
{
|
||||
"name": "index_wallpapers_uri",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"uri"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpapers_uri` ON `${TABLE_NAME}` (`uri`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "albums",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"albumId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table": "folders",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"folderId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "folders",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `albumId` TEXT NOT NULL, `name` TEXT NOT NULL, `uri` TEXT NOT NULL, `coverUri` TEXT, `dateModified` INTEGER NOT NULL, `displayOrder` INTEGER NOT NULL, `addedAt` INTEGER NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`albumId`) REFERENCES `albums`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "albumId",
|
||||
"columnName": "albumId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "uri",
|
||||
"columnName": "uri",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "coverUri",
|
||||
"columnName": "coverUri",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "dateModified",
|
||||
"columnName": "dateModified",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "displayOrder",
|
||||
"columnName": "displayOrder",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "addedAt",
|
||||
"columnName": "addedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_folders_albumId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"albumId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_folders_albumId` ON `${TABLE_NAME}` (`albumId`)"
|
||||
},
|
||||
{
|
||||
"name": "index_folders_uri",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"uri"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_folders_uri` ON `${TABLE_NAME}` (`uri`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "albums",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"albumId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "wallpaper_queue",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `albumId` TEXT NOT NULL, `wallpaperId` TEXT NOT NULL, `screenType` TEXT NOT NULL, `queuePosition` INTEGER NOT NULL, `addedAt` INTEGER NOT NULL, FOREIGN KEY(`albumId`) REFERENCES `albums`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`wallpaperId`) REFERENCES `wallpapers`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "albumId",
|
||||
"columnName": "albumId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "wallpaperId",
|
||||
"columnName": "wallpaperId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "screenType",
|
||||
"columnName": "screenType",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "queuePosition",
|
||||
"columnName": "queuePosition",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "addedAt",
|
||||
"columnName": "addedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_wallpaper_queue_albumId_screenType",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"albumId",
|
||||
"screenType"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpaper_queue_albumId_screenType` ON `${TABLE_NAME}` (`albumId`, `screenType`)"
|
||||
},
|
||||
{
|
||||
"name": "index_wallpaper_queue_wallpaperId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"wallpaperId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpaper_queue_wallpaperId` ON `${TABLE_NAME}` (`wallpaperId`)"
|
||||
},
|
||||
{
|
||||
"name": "index_wallpaper_queue_queuePosition",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"queuePosition"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpaper_queue_queuePosition` ON `${TABLE_NAME}` (`queuePosition`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "albums",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"albumId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table": "wallpapers",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"wallpaperId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "wallpaper_current",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`albumId` TEXT NOT NULL, `screenType` TEXT NOT NULL, `wallpaperId` TEXT NOT NULL, `appliedAt` INTEGER NOT NULL, PRIMARY KEY(`albumId`, `screenType`), FOREIGN KEY(`albumId`) REFERENCES `albums`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`wallpaperId`) REFERENCES `wallpapers`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "albumId",
|
||||
"columnName": "albumId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "screenType",
|
||||
"columnName": "screenType",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "wallpaperId",
|
||||
"columnName": "wallpaperId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "appliedAt",
|
||||
"columnName": "appliedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"albumId",
|
||||
"screenType"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_wallpaper_current_wallpaperId",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"wallpaperId"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_wallpaper_current_wallpaperId` ON `${TABLE_NAME}` (`wallpaperId`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "albums",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"albumId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table": "wallpapers",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"wallpaperId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "excluded_wallpapers",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`folderId` TEXT NOT NULL, `uri` TEXT NOT NULL, `id` TEXT NOT NULL, `fileName` TEXT NOT NULL, `dateModified` INTEGER NOT NULL, `displayOrder` INTEGER NOT NULL, `addedAt` INTEGER NOT NULL, PRIMARY KEY(`folderId`, `uri`), FOREIGN KEY(`folderId`) REFERENCES `folders`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "folderId",
|
||||
"columnName": "folderId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "uri",
|
||||
"columnName": "uri",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "fileName",
|
||||
"columnName": "fileName",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "dateModified",
|
||||
"columnName": "dateModified",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "displayOrder",
|
||||
"columnName": "displayOrder",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "addedAt",
|
||||
"columnName": "addedAt",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"folderId",
|
||||
"uri"
|
||||
]
|
||||
},
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "folders",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"folderId"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'dd85d0b5892ec87e1bc8906b1f42a004')"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ class DocumentAccessInstrumentedTest {
|
||||
}
|
||||
provider.answer = { cursor }
|
||||
try {
|
||||
treeUri.scanFolderImages(context)
|
||||
treeUri.scanFolderImages(context, false)
|
||||
fail("Expected incomplete scan failure")
|
||||
} catch (_: java.io.IOException) { }
|
||||
assertTrue(cursor.isClosed)
|
||||
@@ -91,13 +91,31 @@ class DocumentAccessInstrumentedTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
val found = treeUri.scanFolderImages(context)
|
||||
val found = treeUri.scanFolderImages(context, false)
|
||||
assertEquals(1, found.size)
|
||||
assertEquals("photo.PNG", found.single().name)
|
||||
assertEquals(42L, found.single().modifiedAt)
|
||||
assertEquals(2, provider.queries)
|
||||
}
|
||||
|
||||
@Test fun scansOnlyFilesForTheAlbumModeIncludingNestedDirectories() = runBlocking {
|
||||
provider.answer = { uri ->
|
||||
when (DocumentsContract.getDocumentId(uri)) {
|
||||
"root" -> directoryCursor().apply {
|
||||
addRow(arrayOf<Any>("child", "Child", DocumentsContract.Document.MIME_TYPE_DIR, 0L))
|
||||
addRow(arrayOf<Any>("plain", "photo.JPG", "image/jpeg", 1L))
|
||||
addRow(arrayOf<Any>("encrypted", "photo.JPG_ENC", "application/octet-stream", 2L))
|
||||
addRow(arrayOf<Any>("other", "photo.png_enc", "application/octet-stream", 3L))
|
||||
}
|
||||
else -> directoryCursor().apply {
|
||||
addRow(arrayOf<Any>("nested", "nested.jpg_enc", "application/octet-stream", 4L))
|
||||
}
|
||||
}
|
||||
}
|
||||
assertEquals(setOf("photo.JPG"), treeUri.scanFolderImages(context, false).map { it.name }.toSet())
|
||||
assertEquals(setOf("photo.JPG_ENC", "nested.jpg_enc"), treeUri.scanFolderImages(context, true).map { it.name }.toSet())
|
||||
}
|
||||
|
||||
@Test fun scanSkipsTrashedFilesButKeepsImagesInHiddenFolders() = runBlocking {
|
||||
provider.answer = { uri ->
|
||||
when (DocumentsContract.getDocumentId(uri)) {
|
||||
@@ -115,7 +133,7 @@ class DocumentAccessInstrumentedTest {
|
||||
else -> directoryCursor()
|
||||
}
|
||||
}
|
||||
val found = treeUri.scanFolderImages(context)
|
||||
val found = treeUri.scanFolderImages(context, false)
|
||||
assertEquals(setOf("photo.jpg", "wall.png"), found.map { it.name }.toSet())
|
||||
}
|
||||
|
||||
@@ -127,7 +145,7 @@ class DocumentAccessInstrumentedTest {
|
||||
} else null
|
||||
}
|
||||
try {
|
||||
treeUri.scanFolderImages(context)
|
||||
treeUri.scanFolderImages(context, false)
|
||||
fail("Expected child folder failure")
|
||||
} catch (_: java.io.IOException) { }
|
||||
}
|
||||
@@ -141,7 +159,7 @@ class DocumentAccessInstrumentedTest {
|
||||
check(cancelled.await(5, TimeUnit.SECONDS)) { "Provider query was not cancelled" }
|
||||
signal?.throwIfCanceled()
|
||||
}
|
||||
val scan = launch(Dispatchers.IO) { treeUri.scanFolderImages(context) }
|
||||
val scan = launch(Dispatchers.IO) { treeUri.scanFolderImages(context, false) }
|
||||
assertTrue(started.await(5, TimeUnit.SECONDS))
|
||||
scan.cancel()
|
||||
scan.join()
|
||||
|
||||
@@ -149,6 +149,38 @@ class WallpaperUtilInstrumentedTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun blurredFitBackgroundFillsTheBarsFromTheImage() {
|
||||
val source = mutableBitmap(80, 40, Color.RED)
|
||||
val result = finalizeToCanvas(source, 40, 80, ScalingType.FIT, blurFitBackground = true)
|
||||
try {
|
||||
assertEquals(Color.RED, result.getPixel(20, 0))
|
||||
assertEquals(Color.RED, result.getPixel(20, 40))
|
||||
} finally {
|
||||
result.recycle()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun blurredBackdropAveragesFineDetailInsteadOfSamplingIt() {
|
||||
val source = Bitmap.createBitmap(512, 256, Bitmap.Config.ARGB_8888)
|
||||
val checker = IntArray(512 * 256) { i -> if ((i % 512 + i / 512) % 2 == 0) Color.WHITE else Color.BLACK }
|
||||
source.setPixels(checker, 0, 512, 0, 0, 512, 256)
|
||||
val backdrop = createBlurredBackdrop(source)
|
||||
try {
|
||||
assertEquals(64, backdrop.width)
|
||||
assertEquals(32, backdrop.height)
|
||||
for (y in 0 until backdrop.height) {
|
||||
for (x in 0 until backdrop.width) {
|
||||
assertTrue("Pixel $x,$y", Color.red(backdrop.getPixel(x, y)) in 100..155)
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
source.recycle()
|
||||
backdrop.recycle()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun disabledStaticEffectsLeaveBitmapUntouched() {
|
||||
val source = mutableBitmap(32, 32, Color.rgb(240, 80, 20))
|
||||
|
||||
@@ -16,7 +16,7 @@ class LibraryMigrationInstrumentedTest {
|
||||
private val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
|
||||
@Test fun everyLegacyVersionPreservesLibraryAndQueue() = runBlocking {
|
||||
for (version in 1..3) {
|
||||
for (version in 1..4) {
|
||||
val name = "migration-test-$version"
|
||||
context.deleteDatabase(name)
|
||||
try {
|
||||
@@ -26,6 +26,7 @@ class LibraryMigrationInstrumentedTest {
|
||||
try {
|
||||
assertEquals("My album", db.albumDao().getAlbumById("album")?.name)
|
||||
assertEquals("content://image", db.albumDao().getAlbumById("album")?.coverUri)
|
||||
assertFalse(db.albumDao().getAlbumById("album")!!.isEncrypted)
|
||||
val image = db.wallpaperDao().getWallpaperById("image")!!
|
||||
assertEquals("folder", image.folderId)
|
||||
assertEquals("photo.jpg", image.fileName)
|
||||
@@ -34,6 +35,7 @@ class LibraryMigrationInstrumentedTest {
|
||||
assertEquals("content://image", db.folderDao().getFolderById("folder")?.coverUri)
|
||||
assertEquals(listOf("image"), db.wallpaperQueueDao().getQueueItems("album", ScreenType.HOME).map { it.wallpaperId })
|
||||
assertEquals(if (version >= 3) "image" else null, db.wallpaperCurrentDao().getCurrentWallpaperFlow("album", ScreenType.HOME).first()?.id)
|
||||
assertTrue(db.excludedWallpaperDao().getUris("folder").isEmpty())
|
||||
db.openHelper.readableDatabase.query("PRAGMA foreign_key_check").use { assertEquals(0, it.count) }
|
||||
db.albumDao().deleteAlbumById("album")
|
||||
assertNull(db.wallpaperDao().getWallpaperById("image"))
|
||||
@@ -43,6 +45,61 @@ class LibraryMigrationInstrumentedTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun bothVersionFiveSchemasMigrateToTheCombinedSchema() = runBlocking {
|
||||
for (hasEncryptionColumn in listOf(false, true)) {
|
||||
val name = "migration-test-v5-encrypted-$hasEncryptionColumn"
|
||||
context.deleteDatabase(name)
|
||||
try {
|
||||
createVersionFiveDatabase(name, hasEncryptionColumn)
|
||||
val db = Room.databaseBuilder(context, PaperizeDatabase::class.java, name)
|
||||
.addMigrations(*LIBRARY_MIGRATIONS).build()
|
||||
try {
|
||||
assertEquals(hasEncryptionColumn, db.albumDao().getAlbumById("album")!!.isEncrypted)
|
||||
assertEquals(
|
||||
if (hasEncryptionColumn) emptyList<String>() else listOf("content://excluded"),
|
||||
db.excludedWallpaperDao().getUris("folder")
|
||||
)
|
||||
db.openHelper.readableDatabase.query("PRAGMA foreign_key_check").use { assertEquals(0, it.count) }
|
||||
} finally { db.close() }
|
||||
} finally { context.deleteDatabase(name) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun createVersionFiveDatabase(name: String, hasEncryptionColumn: Boolean) {
|
||||
val schema = InstrumentationRegistry.getInstrumentation().context.assets
|
||||
.open("com.anthonyla.paperize.data.database.PaperizeDatabase/4.json")
|
||||
.bufferedReader().use { JSONObject(it.readText()).getJSONObject("database").getJSONArray("entities") }
|
||||
val path = context.getDatabasePath(name)
|
||||
path.parentFile!!.mkdirs()
|
||||
SQLiteDatabase.openOrCreateDatabase(path, null).use { db ->
|
||||
db.setForeignKeyConstraintsEnabled(true)
|
||||
for (index in 0 until schema.length()) {
|
||||
val entity = schema.getJSONObject(index)
|
||||
val table = entity.getString("tableName")
|
||||
if (table == "excluded_wallpapers") continue
|
||||
db.execSQL(entity.getString("createSql").replace("\${TABLE_NAME}", table))
|
||||
val indices = entity.optJSONArray("indices")
|
||||
if (indices != null) for (i in 0 until indices.length()) {
|
||||
db.execSQL(indices.getJSONObject(i).getString("createSql").replace("\${TABLE_NAME}", table))
|
||||
}
|
||||
}
|
||||
if (hasEncryptionColumn) {
|
||||
db.execSQL("ALTER TABLE `albums` ADD COLUMN `isEncrypted` INTEGER NOT NULL DEFAULT 0")
|
||||
} else {
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS `excluded_wallpapers` (`folderId` TEXT NOT NULL, `uri` TEXT NOT NULL, `id` TEXT NOT NULL, `fileName` TEXT NOT NULL, `dateModified` INTEGER NOT NULL, `displayOrder` INTEGER NOT NULL, `addedAt` INTEGER NOT NULL, PRIMARY KEY(`folderId`, `uri`), FOREIGN KEY(`folderId`) REFERENCES `folders`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE)")
|
||||
}
|
||||
db.execSQL(
|
||||
"INSERT INTO albums (id, name, coverUri, createdAt, modifiedAt${if (hasEncryptionColumn) ", isEncrypted" else ""}) " +
|
||||
"VALUES ('album', 'My album', 'content://image', 1, 2${if (hasEncryptionColumn) ", 1" else ""})"
|
||||
)
|
||||
db.execSQL("INSERT INTO folders (id, albumId, name, uri, coverUri, dateModified, displayOrder, addedAt) VALUES ('folder', 'album', 'Photos', 'content://tree', 'content://image', 3, 0, 4)")
|
||||
if (!hasEncryptionColumn) {
|
||||
db.execSQL("INSERT INTO excluded_wallpapers VALUES ('folder', 'content://excluded', 'excluded', 'excluded.jpg', 5, 6, 7)")
|
||||
}
|
||||
db.version = 5
|
||||
}
|
||||
}
|
||||
|
||||
private fun createLegacyDatabase(name: String, version: Int) {
|
||||
val schema = InstrumentationRegistry.getInstrumentation().context.assets
|
||||
.open("com.anthonyla.paperize.data.database.PaperizeDatabase/4.json")
|
||||
@@ -57,9 +114,10 @@ class LibraryMigrationInstrumentedTest {
|
||||
if (table == "wallpaper_current" && version < 3) continue
|
||||
var create = entity.getString("createSql").replace("\${TABLE_NAME}", table)
|
||||
// Verified against the version 1, 2 and 3 entities in Git history.
|
||||
if (table == "wallpapers") {
|
||||
create = if (version == 1) create.replace("`mediaType` TEXT NOT NULL, ", "")
|
||||
else create.replace("PRIMARY KEY(`id`)", "`cropOffsetX` REAL, `cropOffsetY` REAL, `cropScale` REAL, PRIMARY KEY(`id`)")
|
||||
if (table == "wallpapers") create = when (version) {
|
||||
1 -> create.replace("`mediaType` TEXT NOT NULL, ", "")
|
||||
2, 3 -> create.replace("PRIMARY KEY(`id`)", "`cropOffsetX` REAL, `cropOffsetY` REAL, `cropScale` REAL, PRIMARY KEY(`id`)")
|
||||
else -> create
|
||||
}
|
||||
db.execSQL(create)
|
||||
val indices = entity.optJSONArray("indices")
|
||||
|
||||
@@ -29,11 +29,32 @@ import org.junit.runner.RunWith
|
||||
class AlbumRepositoryInstrumentedTest {
|
||||
private val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
private val db = Room.inMemoryDatabaseBuilder(context, PaperizeDatabase::class.java).build()
|
||||
private val wallpapers = WallpaperRepositoryImpl(db)
|
||||
private val albums = AlbumRepositoryImpl(com.anthonyla.paperize.data.source.AndroidDocumentSource(context), db)
|
||||
private val documents = com.anthonyla.paperize.data.source.AndroidDocumentSource(context)
|
||||
private val wallpapers = WallpaperRepositoryImpl(db, documents, com.anthonyla.paperize.data.source.EncryptedImageStore(context))
|
||||
private val albums = AlbumRepositoryImpl(documents, db)
|
||||
|
||||
@After fun close() = db.close()
|
||||
|
||||
@Test fun renamingPreservesAlbumContentsAndRejectsOtherNamesIgnoringCase() = runBlocking {
|
||||
val album = albums.createAlbum("Original", isEncrypted = true)
|
||||
albums.addWallpapersToAlbum(album.id, listOf(testWallpaper("image", album.id)))
|
||||
albums.createAlbum("Other")
|
||||
assertFalse(albums.renameAlbum(album.id, "other"))
|
||||
assertTrue(albums.renameAlbum(album.id, "ORIGINAL"))
|
||||
assertTrue(albums.renameAlbum(album.id, "Renamed"))
|
||||
val saved = albums.getAlbumById(album.id).first()!!
|
||||
assertEquals("Renamed", saved.name)
|
||||
assertTrue(saved.isEncrypted)
|
||||
assertEquals(listOf("image"), saved.wallpapers.map { it.id })
|
||||
}
|
||||
|
||||
@Test fun encryptedAlbumModeSurvivesPersistence() = runBlocking {
|
||||
val album = albums.createAlbum("Encrypted", isEncrypted = true)
|
||||
assertTrue(album.isEncrypted)
|
||||
assertTrue(albums.getAlbumById(album.id).first()!!.isEncrypted)
|
||||
assertFalse(albums.createAlbum("Ordinary").isEncrypted)
|
||||
}
|
||||
|
||||
@Test fun cancellingAChunkedFolderImportRollsBackAllRows() = runBlocking {
|
||||
db.albumDao().insertAlbum(AlbumEntity("album", "Album", null))
|
||||
val folder = testFolder("folder", "album").copy(
|
||||
@@ -168,4 +189,43 @@ class AlbumRepositoryInstrumentedTest {
|
||||
assertEquals(0, albums.syncFolderWallpapers("album", "folder", emptyList()))
|
||||
assertEquals(1, db.wallpaperDao().getUrisInCollection("album", "folder").size)
|
||||
}
|
||||
|
||||
@Test fun removedFolderImageStaysOutOfRescansUntilRestoredInPlace() = runBlocking {
|
||||
db.albumDao().insertAlbum(AlbumEntity("album", "Album", null))
|
||||
val images = (1..3).map { testWallpaper("image-$it", "album").copy(folderId = "folder", uri = "content://photo-$it") }
|
||||
albums.addFolderToAlbum("album", testFolder("folder", "album").copy(wallpapers = images))
|
||||
val removed = albums.removeWallpaper("image-2")!!
|
||||
|
||||
assertEquals(0, albums.syncFolderWallpapers("album", "folder", images))
|
||||
val folder = albums.getFolderById("folder").first()!!
|
||||
assertEquals(setOf("image-1", "image-3"), folder.wallpapers.map { it.id }.toSet())
|
||||
assertEquals(listOf(removed), folder.removedWallpapers)
|
||||
|
||||
albums.restoreWallpaper(removed)
|
||||
assertEquals(listOf("image-1", "image-2", "image-3"), db.wallpaperDao().getOrderedWallpaperIdsByAlbum("album"))
|
||||
assertTrue(albums.getFolderById("folder").first()!!.removedWallpapers.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun rescanForgetsRemovedImagesWhoseFilesAreGone() = runBlocking {
|
||||
db.albumDao().insertAlbum(AlbumEntity("album", "Album", null))
|
||||
val images = (1..2).map { testWallpaper("image-$it", "album").copy(folderId = "folder", uri = "content://photo-$it") }
|
||||
albums.addFolderToAlbum("album", testFolder("folder", "album").copy(wallpapers = images))
|
||||
albums.removeWallpaper("image-1")
|
||||
|
||||
albums.syncFolderWallpapers("album", "folder", images.drop(1))
|
||||
assertTrue(albums.getFolderById("folder").first()!!.removedWallpapers.isEmpty())
|
||||
// The file coming back later is a new image, not a removed one.
|
||||
assertEquals(1, albums.syncFolderWallpapers("album", "folder", images))
|
||||
}
|
||||
|
||||
@Test fun undoingADirectImageImportedAgainAddsNoDuplicate() = runBlocking {
|
||||
db.albumDao().insertAlbum(AlbumEntity("album", "Album", null))
|
||||
val image = testWallpaper("image", "album").copy(uri = "content://photo")
|
||||
albums.addWallpapersToAlbum("album", listOf(image))
|
||||
val removed = albums.removeWallpaper("image")!!
|
||||
albums.addWallpapersToAlbum("album", listOf(image.copy(id = "again")))
|
||||
|
||||
albums.restoreWallpaper(removed)
|
||||
assertEquals(listOf("again"), db.wallpaperDao().getWallpaperIdsByAlbum("album"))
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,19 @@ import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class SettingsRepositoryInstrumentedTest {
|
||||
@Test fun encryptedPreviewSettingPersistsAndCanBeDisabled() = runBlocking {
|
||||
val preferences = SettingsRepositoryImpl(ApplicationProvider.getApplicationContext<Context>())
|
||||
val original = preferences.getAppSettings().encryptedPreviews
|
||||
try {
|
||||
preferences.updateEncryptedPreviews(true)
|
||||
assertTrue(preferences.getAppSettings().encryptedPreviews)
|
||||
preferences.updateEncryptedPreviews(false)
|
||||
assertFalse(preferences.getAppSettings().encryptedPreviews)
|
||||
} finally {
|
||||
preferences.updateEncryptedPreviews(original)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun concurrentScheduleEditsReadTheLatestValueWithoutLosingSelections() = runBlocking {
|
||||
val preferences = SettingsRepositoryImpl(ApplicationProvider.getApplicationContext<Context>())
|
||||
val previousSettings = preferences.getScheduleSettings()
|
||||
@@ -62,7 +75,7 @@ class SettingsRepositoryInstrumentedTest {
|
||||
homeEnabled = true, lockEnabled = true, homeAlbumId = "home", lockAlbumId = "lock", liveAlbumId = "live",
|
||||
homeIntervalMinutes = 25, lockIntervalMinutes = 35, liveIntervalMinutes = 45,
|
||||
homeScalingType = ScalingType.FIT, lockScalingType = ScalingType.STRETCH, liveScalingType = ScalingType.NONE,
|
||||
homeScrollingEnabled = true, homeEffects = effects, lockEffects = lockEffects, liveEffects = liveEffects,
|
||||
homeScrollingEnabled = true, blurFitBackground = true, homeEffects = effects, lockEffects = lockEffects, liveEffects = liveEffects,
|
||||
adaptiveBrightness = true
|
||||
)
|
||||
preferences.updateScheduleSettings(full)
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.anthonyla.paperize.data.source
|
||||
|
||||
import android.content.ContentProvider
|
||||
import android.content.ContentResolver
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.os.ParcelFileDescriptor
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertThrows
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import java.io.File
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class EncryptedImageStoreInstrumentedTest {
|
||||
private val app = ApplicationProvider.getApplicationContext<Context>()
|
||||
private val directory = File(app.cacheDir, "encrypted-image-store-test").apply { mkdirs() }
|
||||
private val encryptedFile = File(directory, "image")
|
||||
private val provider = ImageProvider(encryptedFile)
|
||||
private val context = object : ContextWrapper(app) {
|
||||
override fun getNoBackupFilesDir(): File = directory
|
||||
override fun getContentResolver(): ContentResolver = ContentResolver.wrap(provider)
|
||||
}
|
||||
private val uri = Uri.parse("content://test/image")
|
||||
private val encrypted = (
|
||||
"53616c7465645f5f00010203040506075fccfb3397721c83694890dfe23e4516" +
|
||||
"7b69d90d234d801114bb019d584a6f47"
|
||||
).chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
||||
|
||||
@After fun cleanup() {
|
||||
directory.deleteRecursively()
|
||||
}
|
||||
|
||||
@Test fun persistsEncryptedPassphraseAndDecryptsProviderStream() {
|
||||
encryptedFile.writeBytes(encrypted)
|
||||
val store = EncryptedImageStore(context)
|
||||
assertEquals(0, store.revision.value)
|
||||
assertFalse(store.hasPassphrase())
|
||||
assertThrows(MissingPassphraseException::class.java) { store.decrypt(uri) }
|
||||
store.setPassphrase("päss漢字")
|
||||
assertEquals(1, store.revision.value)
|
||||
|
||||
val stored = File(directory, "encrypted_image_passphrase").readBytes()
|
||||
assertFalse(stored.toString(Charsets.UTF_8).contains("päss漢字"))
|
||||
val reopened = EncryptedImageStore(context)
|
||||
assertTrue(reopened.hasPassphrase())
|
||||
assertArrayEquals(
|
||||
"Paperize test image\u0000".toByteArray() + byteArrayOf(0xff.toByte()),
|
||||
reopened.decrypt(uri)
|
||||
)
|
||||
reopened.setPassphrase("wrong")
|
||||
assertEquals(1, reopened.revision.value)
|
||||
assertThrows(IncorrectPassphraseException::class.java) { reopened.decrypt(uri) }
|
||||
reopened.clearPassphrase()
|
||||
assertEquals(2, reopened.revision.value)
|
||||
assertFalse(store.hasPassphrase())
|
||||
assertThrows(MissingPassphraseException::class.java) { reopened.decrypt(uri) }
|
||||
}
|
||||
|
||||
@Test fun rejectsTamperedStoredPassphrase() {
|
||||
val store = EncryptedImageStore(context)
|
||||
store.setPassphrase("secret")
|
||||
val file = File(directory, "encrypted_image_passphrase")
|
||||
file.writeBytes(file.readBytes().apply { this[lastIndex] = (last().toInt() xor 1).toByte() })
|
||||
assertThrows(PassphraseStorageException::class.java) { store.decrypt(uri) }
|
||||
}
|
||||
|
||||
private class ImageProvider(private val file: File) : ContentProvider() {
|
||||
override fun onCreate() = true
|
||||
override fun openFile(uri: Uri, mode: String): ParcelFileDescriptor =
|
||||
ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY)
|
||||
override fun query(uri: Uri, projection: Array<out String>?, selection: String?,
|
||||
selectionArgs: Array<out String>?, sortOrder: String?): Cursor? = null
|
||||
override fun getType(uri: Uri): String? = null
|
||||
override fun insert(uri: Uri, values: ContentValues?): Uri? = null
|
||||
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0
|
||||
override fun update(uri: Uri, values: ContentValues?, selection: String?,
|
||||
selectionArgs: Array<out String>?): Int = 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package com.anthonyla.paperize.data.source
|
||||
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.anthonyla.paperize.core.ScreenType
|
||||
import com.anthonyla.paperize.core.util.getDeviceScreenSize
|
||||
import com.anthonyla.paperize.domain.model.ScheduleSettings
|
||||
import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.service.livewallpaper.renderer.EncryptedImageLoader
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.util.UUID
|
||||
import javax.crypto.Cipher
|
||||
import javax.crypto.SecretKeyFactory
|
||||
import javax.crypto.spec.IvParameterSpec
|
||||
import javax.crypto.spec.PBEKeySpec
|
||||
import javax.crypto.spec.SecretKeySpec
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertThrows
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class EncryptedRenderingInstrumentedTest {
|
||||
private val instrumentation = InstrumentationRegistry.getInstrumentation()
|
||||
private val directory = File(instrumentation.targetContext.cacheDir, "encrypted-render-${UUID.randomUUID()}")
|
||||
private val context = object : ContextWrapper(instrumentation.targetContext) {
|
||||
override fun getNoBackupFilesDir(): File = directory
|
||||
}
|
||||
private val encryptedFile = File(directory, "image.jpg_enc")
|
||||
private val uri = Uri.fromFile(encryptedFile)
|
||||
private val store = EncryptedImageStore(context)
|
||||
private val renderer = AndroidWallpaperRenderer(context, store)
|
||||
private val loader = EncryptedImageLoader(store, uri)
|
||||
private val wallpaper = Wallpaper(
|
||||
id = "image", albumId = "album", uri = uri.toString(),
|
||||
fileName = "image.jpg_enc", dateModified = 0
|
||||
)
|
||||
private val passphrase = "päss漢字"
|
||||
private lateinit var wrongPassphrase: String
|
||||
|
||||
@Before fun setup() {
|
||||
check(directory.mkdirs())
|
||||
val image = Bitmap.createBitmap(16, 16, Bitmap.Config.ARGB_8888)
|
||||
val jpeg = try {
|
||||
image.eraseColor(Color.rgb(220, 30, 40))
|
||||
ByteArrayOutputStream().use { output ->
|
||||
check(image.compress(Bitmap.CompressFormat.JPEG, 100, output))
|
||||
output.toByteArray()
|
||||
}
|
||||
} finally {
|
||||
image.recycle()
|
||||
}
|
||||
val encrypted = encryptTestJpeg(jpeg, passphrase)
|
||||
encryptedFile.writeBytes(encrypted)
|
||||
// CBC has no authentication; choose a wrong key that actually fails padding.
|
||||
wrongPassphrase = (0..100).asSequence().map { "wrong-$it" }.first { candidate ->
|
||||
try {
|
||||
decryptEncryptedImage(encrypted, candidate).fill(0)
|
||||
false
|
||||
} catch (_: IncorrectPassphraseException) {
|
||||
true
|
||||
}
|
||||
}
|
||||
store.setPassphrase(passphrase)
|
||||
}
|
||||
|
||||
@After fun cleanup() {
|
||||
directory.deleteRecursively()
|
||||
}
|
||||
|
||||
@Test fun rendersDecryptedJpegInStaticAndLivePaths() {
|
||||
val rendered = runBlocking { renderer.render(wallpaper, ScreenType.HOME, ScheduleSettings()) }
|
||||
assertNotNull(rendered)
|
||||
checkNotNull(rendered)
|
||||
try {
|
||||
val screen = getDeviceScreenSize(context)
|
||||
assertEquals(screen.width, rendered.width)
|
||||
assertEquals(screen.height, rendered.height)
|
||||
assertRed(rendered)
|
||||
} finally {
|
||||
rendered.recycle()
|
||||
}
|
||||
|
||||
val loaded = loader.load(16, 16)
|
||||
assertNotNull(loaded)
|
||||
checkNotNull(loaded)
|
||||
try {
|
||||
assertEquals(16, loaded.width)
|
||||
assertEquals(16, loaded.height)
|
||||
assertRed(loaded)
|
||||
} finally {
|
||||
loaded.recycle()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun wrongOrMissingPassphraseFailsBothPaths() {
|
||||
store.setPassphrase(wrongPassphrase)
|
||||
assertThrows(IncorrectPassphraseException::class.java) {
|
||||
runBlocking { renderer.render(wallpaper, ScreenType.HOME, ScheduleSettings()) }
|
||||
}
|
||||
assertNull(loader.load(16, 16))
|
||||
|
||||
store.clearPassphrase()
|
||||
assertThrows(MissingPassphraseException::class.java) {
|
||||
runBlocking { renderer.render(wallpaper, ScreenType.HOME, ScheduleSettings()) }
|
||||
}
|
||||
assertNull(loader.load(16, 16))
|
||||
}
|
||||
|
||||
private fun assertRed(bitmap: Bitmap) {
|
||||
val pixel = bitmap.getPixel(bitmap.width / 2, bitmap.height / 2)
|
||||
assertTrue(Color.red(pixel) > 180)
|
||||
assertTrue(Color.green(pixel) < 70)
|
||||
assertTrue(Color.blue(pixel) < 80)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun encryptTestJpeg(jpeg: ByteArray, passphrase: String): ByteArray {
|
||||
val salt = byteArrayOf(0, 1, 2, 3, 4, 5, 6, 7)
|
||||
val spec = PBEKeySpec(passphrase.toCharArray(), salt, 10_000, 384)
|
||||
val material = try {
|
||||
SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256").generateSecret(spec).encoded
|
||||
} finally {
|
||||
spec.clearPassword()
|
||||
}
|
||||
return try {
|
||||
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
|
||||
cipher.init(Cipher.ENCRYPT_MODE, SecretKeySpec(material, 0, 32, "AES"), IvParameterSpec(material, 32, 16))
|
||||
"Salted__".toByteArray(Charsets.US_ASCII) + salt + cipher.doFinal(jpeg)
|
||||
} finally {
|
||||
material.fill(0)
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import org.junit.Assert.*
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import com.anthonyla.paperize.presentation.screens.library.LibraryScreen
|
||||
import com.anthonyla.paperize.presentation.screens.album_view.components.AlbumViewTopBar
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import androidx.compose.ui.semantics.SemanticsActions
|
||||
import com.anthonyla.paperize.core.WallpaperMode
|
||||
@@ -56,7 +57,7 @@ class AlbumUiInstrumentedTest {
|
||||
onToggleChanger = {}, onSelectAlbum = { _, _ -> },
|
||||
onUpdateScheduleSettings = { latest = it },
|
||||
onUpdateScheduleSettingsDebounced = { latest = it },
|
||||
onChangeWallpaperNow = {}, homeWallpaperUri = null, lockWallpaperUri = null
|
||||
onChangeWallpaperNow = {}, homeWallpaper = null, lockWallpaper = null, onRemoveWallpaper = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -92,8 +93,9 @@ class AlbumUiInstrumentedTest {
|
||||
var attempts = 0
|
||||
compose.setContent {
|
||||
PaperizeTheme(false, false) {
|
||||
LibraryScreen(emptyList(), {}, { name ->
|
||||
LibraryScreen(emptyList(), {}, { name, encrypted ->
|
||||
assertEquals("Mountains", name)
|
||||
assertTrue(encrypted)
|
||||
attempts++
|
||||
if (attempts == 1) pending.await() else null
|
||||
})
|
||||
@@ -101,6 +103,7 @@ class AlbumUiInstrumentedTest {
|
||||
}
|
||||
compose.onNodeWithContentDescription(context.getString(R.string.add_album)).performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.album_name)).performTextInput("Mountains")
|
||||
compose.onNodeWithText(context.getString(R.string.encrypted_album)).performClick()
|
||||
compose.onNodeWithText(context.getString(R.string.save)).performClick().assertIsNotEnabled()
|
||||
compose.runOnIdle { pending.complete(R.string.album_create_failed) }
|
||||
compose.onNodeWithText(context.getString(R.string.album_create_failed)).assertIsDisplayed()
|
||||
@@ -110,6 +113,33 @@ class AlbumUiInstrumentedTest {
|
||||
compose.runOnIdle { assertEquals(2, attempts) }
|
||||
}
|
||||
|
||||
@Test fun albumOptionsExposeActionsAndDisableRescanWithoutFolders() {
|
||||
val hasFolders = mutableStateOf(false)
|
||||
var action = ""
|
||||
compose.setContent {
|
||||
PaperizeTheme(false, false) {
|
||||
AlbumViewTopBar(
|
||||
title = "Album", isSelectionMode = false, selectedCount = 0, allSelected = false,
|
||||
onBackClick = {}, onSortClick = {}, onDeleteAlbum = { action = "delete" },
|
||||
onRenameAlbum = { action = "rename" }, onFilterAlbum = null, onRefreshFolders = { action = "refresh" },
|
||||
albumActionsEnabled = true, hasFolders = hasFolders.value,
|
||||
onSelectAll = {}, onDeleteSelected = {}, onClearSelection = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
fun openMenu() = compose.onNodeWithContentDescription(context.getString(R.string.album_menu)).performClick()
|
||||
openMenu()
|
||||
compose.onNodeWithText(context.getString(R.string.refresh_album_folders)).assertIsNotEnabled()
|
||||
compose.onNodeWithText(context.getString(R.string.rename_album)).performClick()
|
||||
compose.runOnIdle { assertEquals("rename", action); hasFolders.value = true }
|
||||
openMenu()
|
||||
compose.onNodeWithText(context.getString(R.string.refresh_album_folders)).performClick()
|
||||
compose.runOnIdle { assertEquals("refresh", action) }
|
||||
openMenu()
|
||||
compose.onNodeWithText(context.getString(R.string.delete_album)).performClick()
|
||||
compose.runOnIdle { assertEquals("delete", action) }
|
||||
}
|
||||
|
||||
@Test fun sortSheetExposesCurrentSelectionAndAppliesNewChoice() {
|
||||
var chosen: SortOption? = null
|
||||
var dismissed = false
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.anthonyla.paperize.presentation
|
||||
|
||||
import android.content.ContextWrapper
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.test.junit4.v2.createComposeRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import coil3.request.CachePolicy
|
||||
import coil3.request.ImageRequest
|
||||
import com.anthonyla.paperize.data.source.EncryptedImageStore
|
||||
import com.anthonyla.paperize.data.source.encryptTestJpeg
|
||||
import com.anthonyla.paperize.presentation.common.components.encryptedPreviewImageRequest
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class EncryptedPreviewInstrumentedTest {
|
||||
@get:Rule val compose = createComposeRule()
|
||||
private val instrumentation = InstrumentationRegistry.getInstrumentation()
|
||||
private val directory = File(instrumentation.targetContext.cacheDir, "encrypted-preview-${UUID.randomUUID()}")
|
||||
private val context = object : ContextWrapper(instrumentation.targetContext) {
|
||||
override fun getNoBackupFilesDir(): File = directory
|
||||
}
|
||||
private val image = File(directory, "image.jpg_enc")
|
||||
private val store = EncryptedImageStore(context)
|
||||
|
||||
@Before fun setup() {
|
||||
check(directory.mkdirs())
|
||||
val bitmap = Bitmap.createBitmap(8, 8, Bitmap.Config.ARGB_8888)
|
||||
val jpeg = try {
|
||||
ByteArrayOutputStream().use { output ->
|
||||
check(bitmap.compress(Bitmap.CompressFormat.JPEG, 100, output))
|
||||
output.toByteArray()
|
||||
}
|
||||
} finally {
|
||||
bitmap.recycle()
|
||||
}
|
||||
image.writeBytes(encryptTestJpeg(jpeg, "test"))
|
||||
store.setPassphrase("test")
|
||||
}
|
||||
|
||||
@After fun cleanup() {
|
||||
directory.deleteRecursively()
|
||||
}
|
||||
|
||||
@Test fun disablingPreviewsDropsTheDecryptedRequestAndNeverCachesIt() {
|
||||
val enabled = mutableStateOf(true)
|
||||
val request = AtomicReference<ImageRequest?>()
|
||||
compose.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
val value = encryptedPreviewImageRequest(
|
||||
Uri.fromFile(image).toString(), 32, 32, false, enabled.value, store
|
||||
)
|
||||
SideEffect { request.set(value) }
|
||||
}
|
||||
}
|
||||
compose.waitUntil(20_000) { request.get() != null }
|
||||
val decrypted = checkNotNull(request.get())
|
||||
assertTrue(decrypted.data is Bitmap)
|
||||
assertEquals(CachePolicy.DISABLED, decrypted.memoryCachePolicy)
|
||||
assertEquals(CachePolicy.DISABLED, decrypted.diskCachePolicy)
|
||||
compose.runOnIdle { enabled.value = false }
|
||||
compose.waitUntil(20_000) { request.get() == null }
|
||||
compose.runOnIdle { enabled.value = true }
|
||||
compose.waitUntil(20_000) { request.get() != null }
|
||||
}
|
||||
|
||||
@Test fun missingDocumentMetadataStillLoadsTheOriginalUri() {
|
||||
val uri = Uri.parse("content://missing.provider/image")
|
||||
val request = AtomicReference<ImageRequest?>()
|
||||
compose.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
val value = encryptedPreviewImageRequest(uri.toString(), 32, 32, false, false, store)
|
||||
SideEffect { request.set(value) }
|
||||
}
|
||||
}
|
||||
compose.waitUntil(20_000) { request.get() != null }
|
||||
assertEquals(uri, checkNotNull(request.get()).data)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.anthonyla.paperize.service.livewallpaper.renderer
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.opengl.EGL14
|
||||
import android.opengl.EGLConfig
|
||||
@@ -171,6 +172,72 @@ class LiveWallpaperShaderInstrumentedTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun blurredFitBackgroundFillsTheBarsTheRightWayUpWithAndWithoutBlur() {
|
||||
val app = androidx.test.core.app.ApplicationProvider.getApplicationContext<android.content.Context>()
|
||||
val uploads = java.util.concurrent.LinkedBlockingQueue<() -> Unit>()
|
||||
val renderer = PaperizeWallpaperRenderer(app, object : PaperizeWallpaperRenderer.Callbacks {
|
||||
override fun queueEventOnGlThread(event: () -> Unit): Boolean = uploads.offer(event)
|
||||
override fun requestRender() = Unit
|
||||
})
|
||||
val egl = javax.microedition.khronos.egl.EGLContext.getEGL() as javax.microedition.khronos.egl.EGL10
|
||||
val gl = egl.eglGetCurrentContext().gl as javax.microedition.khronos.opengles.GL10
|
||||
val config = com.anthonyla.paperize.service.livewallpaper.gl.WallpaperEglConfigChooser()
|
||||
.chooseConfig(egl, egl.eglGetCurrentDisplay())
|
||||
val file = java.io.File.createTempFile("fit-backdrop", ".png", app.cacheDir)
|
||||
try {
|
||||
// Wide image, red over blue, so Fit leaves bars above and below it.
|
||||
val bitmap = Bitmap.createBitmap(SIZE * 2, SIZE, Bitmap.Config.ARGB_8888).apply {
|
||||
eraseColor(Color.BLUE)
|
||||
Canvas(this).drawRect(0f, 0f, SIZE * 2f, SIZE / 2f, android.graphics.Paint().apply { color = Color.RED })
|
||||
}
|
||||
file.outputStream().use { bitmap.compress(Bitmap.CompressFormat.PNG, 100, it) }
|
||||
bitmap.recycle()
|
||||
renderer.onSurfaceCreated(gl, config)
|
||||
renderer.onSurfaceChanged(gl, SIZE, SIZE)
|
||||
renderer.updateScalingType(com.anthonyla.paperize.core.ScalingType.FIT)
|
||||
renderer.queueWallpaper(
|
||||
ContentUriImageLoader(
|
||||
app.contentResolver,
|
||||
android.net.Uri.fromFile(file),
|
||||
com.anthonyla.paperize.core.ScalingType.FIT
|
||||
),
|
||||
skipCrossfade = true
|
||||
)
|
||||
checkNotNull(uploads.poll(5, java.util.concurrent.TimeUnit.SECONDS)).invoke()
|
||||
|
||||
renderer.onDrawFrame(gl)
|
||||
assertEquals(Color.BLACK, readPixel(SIZE / 2, SIZE - 2))
|
||||
|
||||
renderer.updateBlurFitBackground(true)
|
||||
renderer.onDrawFrame(gl)
|
||||
assertTopRedBottomBlue()
|
||||
|
||||
renderer.updateEffects(com.anthonyla.paperize.domain.model.WallpaperEffects(enableBlur = true, blurPercentage = 10))
|
||||
renderer.onDrawFrame(gl)
|
||||
assertTopRedBottomBlue()
|
||||
|
||||
// A vignette over the whole screen leaves no seam where the picture meets the backdrop.
|
||||
renderer.updateEffects(com.anthonyla.paperize.domain.model.WallpaperEffects(enableVignette = true, vignettePercentage = 100))
|
||||
renderer.onDrawFrame(gl)
|
||||
val inside = Color.red(readPixel(SIZE / 2, SIZE * 3 / 4 - 1))
|
||||
val outside = Color.red(readPixel(SIZE / 2, SIZE * 3 / 4 + 1))
|
||||
assertTrue("inside=$inside outside=$outside", kotlin.math.abs(inside - outside) <= 20)
|
||||
GLUtil.checkGLError("blurred fit background")
|
||||
} finally {
|
||||
renderer.cancelLoading()
|
||||
file.delete()
|
||||
}
|
||||
}
|
||||
|
||||
// glReadPixels counts rows from the bottom of the surface.
|
||||
private fun assertTopRedBottomBlue() {
|
||||
val top = readPixel(SIZE / 2, SIZE - 2)
|
||||
val bottom = readPixel(SIZE / 2, 1)
|
||||
assertTrue("Top bar ${Integer.toHexString(top)}", Color.red(top) > 200 && Color.blue(top) < 50)
|
||||
assertTrue("Bottom bar ${Integer.toHexString(bottom)}", Color.blue(bottom) > 200 && Color.red(bottom) < 50)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun liveColorEffectsChangeRenderedPixels() {
|
||||
val sourceColor = Color.rgb(200, 100, 40)
|
||||
@@ -228,6 +295,48 @@ class LiveWallpaperShaderInstrumentedTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun liveBlurSpreadsAnEdgeAsFarAsStaticBlur() {
|
||||
val app = androidx.test.core.app.ApplicationProvider.getApplicationContext<android.content.Context>()
|
||||
val uploads = java.util.concurrent.LinkedBlockingQueue<() -> Unit>()
|
||||
val renderer = PaperizeWallpaperRenderer(app, object : PaperizeWallpaperRenderer.Callbacks {
|
||||
override fun queueEventOnGlThread(event: () -> Unit): Boolean = uploads.offer(event)
|
||||
override fun requestRender() = Unit
|
||||
})
|
||||
val egl = javax.microedition.khronos.egl.EGLContext.getEGL() as javax.microedition.khronos.egl.EGL10
|
||||
val gl = egl.eglGetCurrentContext().gl as javax.microedition.khronos.opengles.GL10
|
||||
val config = com.anthonyla.paperize.service.livewallpaper.gl.WallpaperEglConfigChooser()
|
||||
.chooseConfig(egl, egl.eglGetCurrentDisplay())
|
||||
val file = java.io.File.createTempFile("blur-edge", ".png", app.cacheDir)
|
||||
val static = com.anthonyla.paperize.core.util.processBitmap(
|
||||
boundaryBitmap(horizontalBoundary = true), enableBlur = true, blurPercent = 100
|
||||
)
|
||||
try {
|
||||
val edge = boundaryBitmap(horizontalBoundary = true)
|
||||
file.outputStream().use { edge.compress(Bitmap.CompressFormat.PNG, 100, it) }
|
||||
edge.recycle()
|
||||
renderer.onSurfaceCreated(gl, config)
|
||||
renderer.onSurfaceChanged(gl, SIZE, SIZE)
|
||||
renderer.updateEffects(com.anthonyla.paperize.domain.model.WallpaperEffects(enableBlur = true, blurPercentage = 100))
|
||||
renderer.queueWallpaper(
|
||||
ContentUriImageLoader(app.contentResolver, android.net.Uri.fromFile(file)),
|
||||
skipCrossfade = true
|
||||
)
|
||||
checkNotNull(uploads.poll(5, java.util.concurrent.TimeUnit.SECONDS)).invoke()
|
||||
renderer.onDrawFrame(gl)
|
||||
|
||||
for (x in listOf(20, 24, 28, 36, 40, 44)) {
|
||||
val live = Color.red(readPixel(x, SIZE / 2))
|
||||
val expected = Color.red(static.getPixel(x, SIZE / 2))
|
||||
assertTrue("x=$x live=$live static=$expected", kotlin.math.abs(live - expected) <= 16)
|
||||
}
|
||||
} finally {
|
||||
renderer.cancelLoading()
|
||||
static.recycle()
|
||||
file.delete()
|
||||
}
|
||||
}
|
||||
|
||||
private fun drawEffects(
|
||||
program: Int,
|
||||
texture: Int,
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.anthonyla.paperize.core.constants
|
||||
|
||||
object Constants {
|
||||
const val DATABASE_NAME = "paperize_database"
|
||||
const val DATABASE_VERSION = 4
|
||||
const val DATABASE_VERSION = 7
|
||||
|
||||
const val PREFERENCES_NAME = "paperize_preferences"
|
||||
|
||||
@@ -25,7 +25,6 @@ object Constants {
|
||||
const val DEFAULT_GRAYSCALE_PERCENTAGE = 0
|
||||
const val MAX_EFFECT_PERCENTAGE = 100
|
||||
const val SLIDER_EFFECT_STEPS = 99
|
||||
const val DIALOG_MESSAGE_MAX_LINES = 10
|
||||
const val MIN_EFFECT_PERCENTAGE = 0
|
||||
|
||||
const val MIN_LIVE_INTERVAL_MINUTES = 1
|
||||
@@ -44,6 +43,8 @@ object Constants {
|
||||
const val PREVIEW_THUMBNAIL_HEIGHT = 1200
|
||||
|
||||
const val MAX_BLUR_RADIUS = 25.0f
|
||||
const val BACKDROP_MAX_SIZE = 64
|
||||
const val BACKDROP_BLUR_PERCENT = 25
|
||||
const val BRIGHTNESS_SAMPLE_SIZE = 10
|
||||
|
||||
// ITU-R BT.709
|
||||
|
||||
@@ -116,11 +116,13 @@ fun retrieveBitmap(
|
||||
width: Int,
|
||||
height: Int,
|
||||
scaling: ScalingType = ScalingType.FIT,
|
||||
preserveSourceOverflow: Boolean = false
|
||||
preserveSourceOverflow: Boolean = false,
|
||||
blurFitBackground: Boolean = false,
|
||||
imageSource: ImageDecoder.Source? = null
|
||||
): Bitmap? {
|
||||
// ImageDecoder applies EXIF orientation and reports dimensions after it.
|
||||
val bitmap = try {
|
||||
val source = ImageDecoder.createSource(context.contentResolver, wallpaperUri)
|
||||
val source = imageSource ?: ImageDecoder.createSource(context.contentResolver, wallpaperUri)
|
||||
ImageDecoder.decodeBitmap(source) { decoder, info, _ ->
|
||||
val (targetW, targetH) = calculateDecodeSize(
|
||||
info.size.width, info.size.height, width, height, scaling
|
||||
@@ -152,7 +154,7 @@ fun retrieveBitmap(
|
||||
if (preserveSourceOverflow && scaling == ScalingType.FILL) {
|
||||
scaleToFillPreservingOverflow(it, width, height)
|
||||
} else {
|
||||
finalizeToCanvas(it, width, height, scaling)
|
||||
finalizeToCanvas(it, width, height, scaling, blurFitBackground)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,28 +184,61 @@ private fun scaleToFillPreservingOverflow(
|
||||
}
|
||||
|
||||
/** Render the decoded bitmap onto the requested canvas; consumes [source]. */
|
||||
internal fun finalizeToCanvas(source: Bitmap, canvasW: Int, canvasH: Int, scaling: ScalingType): Bitmap {
|
||||
internal fun finalizeToCanvas(
|
||||
source: Bitmap,
|
||||
canvasW: Int,
|
||||
canvasH: Int,
|
||||
scaling: ScalingType,
|
||||
blurFitBackground: Boolean = false
|
||||
): Bitmap {
|
||||
if (source.width == canvasW && source.height == canvasH) return source
|
||||
val widthRatio = canvasW.toFloat() / source.width
|
||||
val heightRatio = canvasH.toFloat() / source.height
|
||||
val scale = when (scaling) {
|
||||
ScalingType.FILL -> maxOf(widthRatio, heightRatio)
|
||||
ScalingType.FIT -> minOf(widthRatio, heightRatio)
|
||||
ScalingType.NONE, ScalingType.STRETCH -> 1f
|
||||
fun centered(width: Float, height: Float) =
|
||||
RectF((canvasW - width) / 2f, (canvasH - height) / 2f, (canvasW + width) / 2f, (canvasH + height) / 2f)
|
||||
fun scaled(bitmap: Bitmap, mode: ScalingType): RectF {
|
||||
if (mode == ScalingType.STRETCH) return centered(canvasW.toFloat(), canvasH.toFloat())
|
||||
val widthRatio = canvasW.toFloat() / bitmap.width
|
||||
val heightRatio = canvasH.toFloat() / bitmap.height
|
||||
val scale = when (mode) {
|
||||
ScalingType.FILL -> maxOf(widthRatio, heightRatio)
|
||||
ScalingType.FIT -> minOf(widthRatio, heightRatio)
|
||||
ScalingType.NONE, ScalingType.STRETCH -> 1f
|
||||
}
|
||||
return centered(bitmap.width * scale, bitmap.height * scale)
|
||||
}
|
||||
val width = if (scaling == ScalingType.STRETCH) canvasW.toFloat() else source.width * scale
|
||||
val height = if (scaling == ScalingType.STRETCH) canvasH.toFloat() else source.height * scale
|
||||
val left = (canvasW - width) / 2f
|
||||
val top = (canvasH - height) / 2f
|
||||
val result = createBitmap(canvasW, canvasH)
|
||||
val paint = Paint(Paint.FILTER_BITMAP_FLAG)
|
||||
Canvas(result).apply {
|
||||
drawColor(Color.BLACK)
|
||||
drawBitmap(source, null, RectF(left, top, left + width, top + height), Paint(Paint.FILTER_BITMAP_FLAG))
|
||||
if (scaling == ScalingType.FIT && blurFitBackground) {
|
||||
val backdrop = createBlurredBackdrop(source)
|
||||
drawBitmap(backdrop, null, scaled(backdrop, ScalingType.FILL), paint)
|
||||
backdrop.recycle()
|
||||
} else {
|
||||
drawColor(Color.BLACK)
|
||||
}
|
||||
drawBitmap(source, null, scaled(source, scaling), paint)
|
||||
}
|
||||
source.recycle()
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* A blurred copy of [source] at most [Constants.BACKDROP_MAX_SIZE] pixels across, meant to be
|
||||
* stretched over the screen. Halving step by step averages every pixel; a single large downscale
|
||||
* samples only a few and turns detailed images into noise.
|
||||
*/
|
||||
fun createBlurredBackdrop(source: Bitmap): Bitmap {
|
||||
var small = source
|
||||
while (maxOf(small.width, small.height) > Constants.BACKDROP_MAX_SIZE) {
|
||||
val half = small.scale(maxOf(1, small.width / 2), maxOf(1, small.height / 2))
|
||||
if (small !== source) small.recycle()
|
||||
small = half
|
||||
}
|
||||
if (small === source) small = source.copy(Bitmap.Config.ARGB_8888, false)
|
||||
val blurred = processBitmap(small, enableBlur = true, blurPercent = Constants.BACKDROP_BLUR_PERCENT)
|
||||
if (blurred !== small) small.recycle()
|
||||
return blurred
|
||||
}
|
||||
|
||||
private fun drawVignette(canvas: Canvas, width: Int, height: Int, percent: Int) {
|
||||
val centerX = width / 2f
|
||||
val centerY = height / 2f
|
||||
|
||||
@@ -4,7 +4,7 @@ import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
/** Versions 1–3 used the same library tables, with extra crop columns in versions 2–3. */
|
||||
val LIBRARY_MIGRATIONS: Array<Migration> = (1..3).map { version ->
|
||||
val LIBRARY_MIGRATIONS: Array<Migration> = (1..3).map<Int, Migration> { version ->
|
||||
object : Migration(version, 4) {
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
// Rebuilding the parent table would cascade-delete these rows; preserve them first.
|
||||
@@ -39,4 +39,24 @@ val LIBRARY_MIGRATIONS: Array<Migration> = (1..3).map { version ->
|
||||
}
|
||||
}
|
||||
}
|
||||
}.toTypedArray()
|
||||
}.toTypedArray() + object : Migration(5, 6) {
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
val hasEncryptionColumn = db.query("PRAGMA table_info(`albums`)").use { cursor ->
|
||||
val nameColumn = cursor.getColumnIndexOrThrow("name")
|
||||
var found = false
|
||||
while (cursor.moveToNext()) {
|
||||
if (cursor.getString(nameColumn) == "isEncrypted") {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
found
|
||||
}
|
||||
if (!hasEncryptionColumn) {
|
||||
db.execSQL("ALTER TABLE `albums` ADD COLUMN `isEncrypted` INTEGER NOT NULL DEFAULT 0")
|
||||
}
|
||||
db.execSQL(
|
||||
"CREATE TABLE IF NOT EXISTS `excluded_wallpapers` (`folderId` TEXT NOT NULL, `uri` TEXT NOT NULL, `id` TEXT NOT NULL, `fileName` TEXT NOT NULL, `dateModified` INTEGER NOT NULL, `displayOrder` INTEGER NOT NULL, `addedAt` INTEGER NOT NULL, PRIMARY KEY(`folderId`, `uri`), FOREIGN KEY(`folderId`) REFERENCES `folders`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE)"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,16 @@
|
||||
package com.anthonyla.paperize.data.database
|
||||
|
||||
import androidx.room.AutoMigration
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import com.anthonyla.paperize.data.database.dao.AlbumDao
|
||||
import com.anthonyla.paperize.data.database.dao.ExcludedWallpaperDao
|
||||
import com.anthonyla.paperize.data.database.dao.FolderDao
|
||||
import com.anthonyla.paperize.data.database.dao.WallpaperCurrentDao
|
||||
import com.anthonyla.paperize.data.database.dao.WallpaperDao
|
||||
import com.anthonyla.paperize.data.database.dao.WallpaperQueueDao
|
||||
import com.anthonyla.paperize.data.database.entities.AlbumEntity
|
||||
import com.anthonyla.paperize.data.database.entities.ExcludedWallpaperEntity
|
||||
import com.anthonyla.paperize.data.database.entities.FolderEntity
|
||||
import com.anthonyla.paperize.data.database.entities.WallpaperCurrentEntity
|
||||
import com.anthonyla.paperize.data.database.entities.WallpaperEntity
|
||||
@@ -20,10 +23,12 @@ import com.anthonyla.paperize.core.constants.Constants
|
||||
WallpaperEntity::class,
|
||||
FolderEntity::class,
|
||||
WallpaperQueueEntity::class,
|
||||
WallpaperCurrentEntity::class
|
||||
WallpaperCurrentEntity::class,
|
||||
ExcludedWallpaperEntity::class
|
||||
],
|
||||
version = Constants.DATABASE_VERSION,
|
||||
exportSchema = true
|
||||
exportSchema = true,
|
||||
autoMigrations = [AutoMigration(from = 4, to = 5), AutoMigration(from = 6, to = 7)]
|
||||
)
|
||||
abstract class PaperizeDatabase : RoomDatabase() {
|
||||
abstract fun albumDao(): AlbumDao
|
||||
@@ -31,4 +36,5 @@ abstract class PaperizeDatabase : RoomDatabase() {
|
||||
abstract fun folderDao(): FolderDao
|
||||
abstract fun wallpaperQueueDao(): WallpaperQueueDao
|
||||
abstract fun wallpaperCurrentDao(): WallpaperCurrentDao
|
||||
abstract fun excludedWallpaperDao(): ExcludedWallpaperDao
|
||||
}
|
||||
@@ -39,6 +39,12 @@ interface AlbumDao {
|
||||
@Query("DELETE FROM albums WHERE id = :albumId")
|
||||
suspend fun deleteAlbumById(albumId: String)
|
||||
|
||||
@Query("UPDATE albums SET name = :name, modifiedAt = :modifiedAt WHERE id = :albumId")
|
||||
suspend fun renameAlbum(albumId: String, name: String, modifiedAt: Long): Int
|
||||
|
||||
@Query("UPDATE albums SET filter = :filter, modifiedAt = :modifiedAt WHERE id = :albumId")
|
||||
suspend fun setFilter(albumId: String, filter: String?, modifiedAt: Long): Int
|
||||
|
||||
@Query("UPDATE albums SET coverUri = :coverUri, modifiedAt = :modifiedAt WHERE id = :albumId")
|
||||
suspend fun updateAlbumCover(albumId: String, coverUri: String?, modifiedAt: Long)
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.anthonyla.paperize.data.database.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.anthonyla.paperize.data.database.entities.ExcludedWallpaperEntity
|
||||
|
||||
@Dao
|
||||
interface ExcludedWallpaperDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insert(entity: ExcludedWallpaperEntity)
|
||||
|
||||
@Query("SELECT uri FROM excluded_wallpapers WHERE folderId = :folderId")
|
||||
suspend fun getUris(folderId: String): List<String>
|
||||
|
||||
@Query("DELETE FROM excluded_wallpapers WHERE folderId = :folderId AND uri IN (:uris)")
|
||||
suspend fun deleteUris(folderId: String, uris: List<String>)
|
||||
}
|
||||
@@ -35,6 +35,9 @@ interface WallpaperDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertWallpapers(wallpapers: List<WallpaperEntity>)
|
||||
|
||||
@Query("SELECT * FROM wallpapers WHERE folderId = :folderId")
|
||||
suspend fun getFolderWallpapers(folderId: String): List<WallpaperEntity>
|
||||
|
||||
@Query("SELECT id FROM wallpapers WHERE albumId = :albumId")
|
||||
suspend fun getWallpaperIdsByAlbum(albumId: String): List<String>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.anthonyla.paperize.data.database.entities
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "albums")
|
||||
@@ -10,5 +11,7 @@ data class AlbumEntity(
|
||||
val name: String,
|
||||
val coverUri: String?,
|
||||
val createdAt: Long = System.currentTimeMillis(),
|
||||
val modifiedAt: Long = System.currentTimeMillis()
|
||||
val modifiedAt: Long = System.currentTimeMillis(),
|
||||
@ColumnInfo(defaultValue = "0") val isEncrypted: Boolean = false,
|
||||
val filter: String? = null
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.anthonyla.paperize.data.database.entities
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
|
||||
/** A folder image the user removed, so folder rescans skip it. Keeps the row to restore it as it was. */
|
||||
@Entity(
|
||||
tableName = "excluded_wallpapers",
|
||||
primaryKeys = ["folderId", "uri"],
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = FolderEntity::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["folderId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)
|
||||
]
|
||||
)
|
||||
data class ExcludedWallpaperEntity(
|
||||
val folderId: String,
|
||||
val uri: String,
|
||||
val id: String,
|
||||
val fileName: String,
|
||||
val dateModified: Long,
|
||||
val displayOrder: Int,
|
||||
val addedAt: Long
|
||||
)
|
||||
@@ -2,6 +2,7 @@ package com.anthonyla.paperize.data.database.relations
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Relation
|
||||
import com.anthonyla.paperize.data.database.entities.ExcludedWallpaperEntity
|
||||
import com.anthonyla.paperize.data.database.entities.FolderEntity
|
||||
import com.anthonyla.paperize.data.database.entities.WallpaperEntity
|
||||
|
||||
@@ -14,5 +15,12 @@ data class FolderWithWallpapers(
|
||||
entityColumn = "folderId",
|
||||
entity = WallpaperEntity::class
|
||||
)
|
||||
val wallpapers: List<WallpaperEntity> = emptyList()
|
||||
val wallpapers: List<WallpaperEntity> = emptyList(),
|
||||
|
||||
@Relation(
|
||||
parentColumn = "id",
|
||||
entityColumn = "folderId",
|
||||
entity = ExcludedWallpaperEntity::class
|
||||
)
|
||||
val excluded: List<ExcludedWallpaperEntity> = emptyList()
|
||||
)
|
||||
@@ -18,7 +18,9 @@ fun AlbumEntity.toDomainModel(
|
||||
wallpapers = wallpapers,
|
||||
folders = folders,
|
||||
createdAt = createdAt,
|
||||
modifiedAt = modifiedAt
|
||||
modifiedAt = modifiedAt,
|
||||
isEncrypted = isEncrypted,
|
||||
filter = filter
|
||||
)
|
||||
|
||||
fun Album.toEntity(): AlbumEntity = AlbumEntity(
|
||||
@@ -26,7 +28,9 @@ fun Album.toEntity(): AlbumEntity = AlbumEntity(
|
||||
name = name,
|
||||
coverUri = coverUri,
|
||||
createdAt = createdAt,
|
||||
modifiedAt = modifiedAt
|
||||
modifiedAt = modifiedAt,
|
||||
isEncrypted = isEncrypted,
|
||||
filter = filter
|
||||
)
|
||||
|
||||
fun AlbumWithDetails.toDomainModel(): Album {
|
||||
|
||||
@@ -6,7 +6,8 @@ import com.anthonyla.paperize.domain.model.Folder
|
||||
import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
|
||||
fun FolderEntity.toDomainModel(
|
||||
wallpapers: List<Wallpaper> = emptyList()
|
||||
wallpapers: List<Wallpaper> = emptyList(),
|
||||
removedWallpapers: List<Wallpaper> = emptyList()
|
||||
): Folder = Folder(
|
||||
id = id,
|
||||
albumId = albumId,
|
||||
@@ -16,6 +17,7 @@ fun FolderEntity.toDomainModel(
|
||||
dateModified = dateModified,
|
||||
displayOrder = displayOrder,
|
||||
wallpapers = wallpapers,
|
||||
removedWallpapers = removedWallpapers,
|
||||
addedAt = addedAt
|
||||
)
|
||||
|
||||
@@ -31,5 +33,6 @@ fun Folder.toEntity(): FolderEntity = FolderEntity(
|
||||
)
|
||||
|
||||
fun FolderWithWallpapers.toDomainModel(): Folder = folder.toDomainModel(
|
||||
wallpapers = wallpapers.map { it.toDomainModel() }
|
||||
wallpapers = wallpapers.map { it.toDomainModel() },
|
||||
removedWallpapers = excluded.map { it.toDomainModel(folder.albumId) }
|
||||
)
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.anthonyla.paperize.data.mapper
|
||||
|
||||
import com.anthonyla.paperize.data.database.entities.ExcludedWallpaperEntity
|
||||
import com.anthonyla.paperize.data.database.entities.WallpaperEntity
|
||||
import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
|
||||
@@ -25,3 +26,24 @@ fun Wallpaper.toEntity(): WallpaperEntity = WallpaperEntity(
|
||||
sourceType = if (folderId == null) "DIRECT" else "FOLDER",
|
||||
addedAt = addedAt
|
||||
)
|
||||
|
||||
fun ExcludedWallpaperEntity.toDomainModel(albumId: String): Wallpaper = Wallpaper(
|
||||
id = id,
|
||||
albumId = albumId,
|
||||
folderId = folderId,
|
||||
uri = uri,
|
||||
fileName = fileName,
|
||||
dateModified = dateModified,
|
||||
displayOrder = displayOrder,
|
||||
addedAt = addedAt
|
||||
)
|
||||
|
||||
fun Wallpaper.toExcludedEntity(folderId: String): ExcludedWallpaperEntity = ExcludedWallpaperEntity(
|
||||
folderId = folderId,
|
||||
uri = uri,
|
||||
id = id,
|
||||
fileName = fileName,
|
||||
dateModified = dateModified,
|
||||
displayOrder = displayOrder,
|
||||
addedAt = addedAt
|
||||
)
|
||||
@@ -5,6 +5,7 @@ import com.anthonyla.paperize.core.util.generateId
|
||||
import com.anthonyla.paperize.data.database.PaperizeDatabase
|
||||
import com.anthonyla.paperize.data.mapper.toDomainModel
|
||||
import com.anthonyla.paperize.data.mapper.toEntity
|
||||
import com.anthonyla.paperize.data.mapper.toExcludedEntity
|
||||
import com.anthonyla.paperize.domain.model.Album
|
||||
import com.anthonyla.paperize.domain.model.AlbumSummary
|
||||
import com.anthonyla.paperize.domain.model.Folder
|
||||
@@ -14,6 +15,7 @@ import com.anthonyla.paperize.domain.source.DocumentSource
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
@Singleton
|
||||
@@ -24,6 +26,7 @@ class AlbumRepositoryImpl @Inject constructor(
|
||||
private val albumDao = database.albumDao()
|
||||
private val wallpaperDao = database.wallpaperDao()
|
||||
private val folderDao = database.folderDao()
|
||||
private val excludedDao = database.excludedWallpaperDao()
|
||||
|
||||
companion object {
|
||||
private const val WALLPAPER_BATCH_SIZE = 500
|
||||
@@ -35,12 +38,15 @@ class AlbumRepositoryImpl @Inject constructor(
|
||||
override fun getAlbumById(albumId: String): Flow<Album?> =
|
||||
albumDao.getAlbumWithDetails(albumId).map { it?.toDomainModel() }
|
||||
|
||||
override suspend fun getAlbumEncryption(albumId: String): Boolean? =
|
||||
albumDao.getAlbumById(albumId)?.isEncrypted
|
||||
|
||||
override fun getFolderById(folderId: String): Flow<Folder?> =
|
||||
folderDao.getFolderWithWallpapers(folderId).map { it?.toDomainModel() }
|
||||
|
||||
override suspend fun createAlbum(name: String, coverUri: String?): Album {
|
||||
override suspend fun createAlbum(name: String, coverUri: String?, isEncrypted: Boolean): Album {
|
||||
val now = System.currentTimeMillis()
|
||||
val album = Album(id = generateId(), name = name, coverUri = coverUri, createdAt = now, modifiedAt = now)
|
||||
val album = Album(id = generateId(), name = name, coverUri = coverUri, createdAt = now, modifiedAt = now, isEncrypted = isEncrypted)
|
||||
albumDao.insertAlbum(album.toEntity())
|
||||
return album
|
||||
}
|
||||
@@ -49,6 +55,19 @@ class AlbumRepositoryImpl @Inject constructor(
|
||||
albumDao.deleteAlbumById(albumId)
|
||||
}
|
||||
|
||||
override suspend fun renameAlbum(albumId: String, name: String): Boolean = database.withTransaction {
|
||||
if (albumDao.getAlbumSummaries().first().any { it.id != albumId && it.name.equals(name, ignoreCase = true) }) {
|
||||
return@withTransaction false
|
||||
}
|
||||
check(albumDao.renameAlbum(albumId, name, System.currentTimeMillis()) == 1)
|
||||
true
|
||||
}
|
||||
|
||||
override suspend fun setAlbumFilter(albumId: String, filter: String?) = database.withTransaction {
|
||||
check(albumDao.setFilter(albumId, filter?.takeIf { it.isNotBlank() }, System.currentTimeMillis()) == 1)
|
||||
database.wallpaperQueueDao().clearAllQueues(albumId)
|
||||
}
|
||||
|
||||
override suspend fun addWallpapersToAlbum(
|
||||
albumId: String,
|
||||
wallpapers: List<Wallpaper>,
|
||||
@@ -84,11 +103,15 @@ class AlbumRepositoryImpl @Inject constructor(
|
||||
// An empty scan can be an unavailable provider, so it removes nothing.
|
||||
val stale = if (scanned.isEmpty()) emptyList()
|
||||
else wallpaperDao.getUrisInCollection(albumId, folderId).filterNot { it in scanned }
|
||||
val excluded = excludedDao.getUris(folderId).toHashSet()
|
||||
if (scanned.isNotEmpty()) excluded.filterNot { it in scanned }.chunked(WALLPAPER_BATCH_SIZE).forEach {
|
||||
excludedDao.deleteUris(folderId, it)
|
||||
}
|
||||
var removed = 0
|
||||
stale.chunked(WALLPAPER_BATCH_SIZE).forEach {
|
||||
removed += wallpaperDao.deleteFolderWallpapersByUris(albumId, folderId, it)
|
||||
}
|
||||
val added = insertNewWallpapers(albumId, wallpapers, onProgress)
|
||||
val added = insertNewWallpapers(albumId, wallpapers.filterNot { it.uri in excluded }, onProgress)
|
||||
if (removed > 0) {
|
||||
folderDao.updateFolderCover(folderId, wallpaperDao.getFolderCoverUri(folderId))
|
||||
updateAlbumCoverIfNeeded(albumId)
|
||||
@@ -154,6 +177,26 @@ class AlbumRepositoryImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun removeWallpaper(wallpaperId: String): Wallpaper? = database.withTransaction {
|
||||
val wallpaper = wallpaperDao.getWallpaperById(wallpaperId)?.toDomainModel() ?: return@withTransaction null
|
||||
wallpaper.folderId?.let { excludedDao.insert(wallpaper.toExcludedEntity(it)) }
|
||||
removeWallpapersFromAlbum(wallpaper.albumId, listOf(wallpaperId))
|
||||
wallpaper
|
||||
}
|
||||
|
||||
override suspend fun restoreWallpaper(wallpaper: Wallpaper) = database.withTransaction {
|
||||
val albumId = wallpaper.albumId
|
||||
val folderId = wallpaper.folderId
|
||||
if (folderId != null) excludedDao.deleteUris(folderId, listOf(wallpaper.uri))
|
||||
// The same image can be imported again before an undo.
|
||||
if (wallpaper.uri in wallpaperDao.getUrisInCollection(albumId, folderId)) return@withTransaction
|
||||
wallpaperDao.insertWallpapers(listOf(wallpaper.toEntity()))
|
||||
database.wallpaperQueueDao().clearAllQueues(albumId)
|
||||
albumDao.updateAlbumModifiedTime(albumId, System.currentTimeMillis())
|
||||
folderDao.refreshFolderCovers(albumId)
|
||||
updateAlbumCoverIfNeeded(albumId)
|
||||
}
|
||||
|
||||
override suspend fun removeFolderFromAlbum(albumId: String, folderId: String) {
|
||||
database.withTransaction {
|
||||
folderDao.deleteAlbumFolder(albumId, folderId)
|
||||
|
||||
@@ -31,6 +31,7 @@ private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(
|
||||
private val DARK_MODE = booleanPreferencesKey("dark_mode")
|
||||
private val DYNAMIC_THEMING = booleanPreferencesKey("dynamic_theming")
|
||||
private val ANIMATE = booleanPreferencesKey("animate")
|
||||
private val ENCRYPTED_PREVIEWS = booleanPreferencesKey("encrypted_previews")
|
||||
private val FIRST_LAUNCH = booleanPreferencesKey("first_launch")
|
||||
private val WALLPAPER_MODE = stringPreferencesKey("wallpaper_mode")
|
||||
private val ENABLE_CHANGER = booleanPreferencesKey("enable_changer")
|
||||
@@ -48,6 +49,7 @@ private val HOME_SCALING_TYPE = stringPreferencesKey("home_scaling_type")
|
||||
private val LOCK_SCALING_TYPE = stringPreferencesKey("lock_scaling_type")
|
||||
private val LIVE_SCALING_TYPE = stringPreferencesKey("live_scaling_type")
|
||||
private val HOME_SCROLLING_ENABLED = booleanPreferencesKey("home_scrolling_enabled")
|
||||
private val BLUR_FIT_BACKGROUND = booleanPreferencesKey("blur_fit_background")
|
||||
private val ADAPTIVE_BRIGHTNESS = booleanPreferencesKey("adaptive_brightness")
|
||||
|
||||
/** Effect keys are "<screen>_<field>", e.g. "home_enable_blur" or "live_parallax_intensity". */
|
||||
@@ -84,7 +86,8 @@ class SettingsRepositoryImpl @Inject constructor(
|
||||
darkMode = prefs[DARK_MODE],
|
||||
dynamicTheming = prefs[DYNAMIC_THEMING] ?: defaults.dynamicTheming,
|
||||
animate = prefs[ANIMATE] ?: defaults.animate,
|
||||
firstLaunch = prefs[FIRST_LAUNCH] ?: defaults.firstLaunch
|
||||
firstLaunch = prefs[FIRST_LAUNCH] ?: defaults.firstLaunch,
|
||||
encryptedPreviews = prefs[ENCRYPTED_PREVIEWS] ?: defaults.encryptedPreviews
|
||||
)
|
||||
}
|
||||
|
||||
@@ -123,6 +126,7 @@ class SettingsRepositoryImpl @Inject constructor(
|
||||
prefs[LOCK_SCALING_TYPE] = settings.lockScalingType.name
|
||||
prefs[LIVE_SCALING_TYPE] = settings.liveScalingType.name
|
||||
prefs[HOME_SCROLLING_ENABLED] = settings.homeScrollingEnabled
|
||||
prefs[BLUR_FIT_BACKGROUND] = settings.blurFitBackground
|
||||
prefs.writeEffects(HOME_EFFECTS, settings.homeEffects)
|
||||
prefs.writeEffects(LOCK_EFFECTS, settings.lockEffects)
|
||||
prefs.writeEffects(LIVE_EFFECTS, settings.liveEffects)
|
||||
@@ -173,6 +177,10 @@ class SettingsRepositoryImpl @Inject constructor(
|
||||
dataStore.edit { it[ANIMATE] = enabled }
|
||||
}
|
||||
|
||||
override suspend fun updateEncryptedPreviews(enabled: Boolean) {
|
||||
dataStore.edit { it[ENCRYPTED_PREVIEWS] = enabled }
|
||||
}
|
||||
|
||||
override suspend fun completeFirstLaunch() {
|
||||
dataStore.edit { it[FIRST_LAUNCH] = false }
|
||||
}
|
||||
@@ -199,6 +207,7 @@ class SettingsRepositoryImpl @Inject constructor(
|
||||
lockScalingType = ScalingType.fromString(prefs[LOCK_SCALING_TYPE]),
|
||||
liveScalingType = ScalingType.fromString(prefs[LIVE_SCALING_TYPE]),
|
||||
homeScrollingEnabled = prefs[HOME_SCROLLING_ENABLED] ?: defaults.homeScrollingEnabled,
|
||||
blurFitBackground = prefs[BLUR_FIT_BACKGROUND] ?: defaults.blurFitBackground,
|
||||
homeEffects = prefs.readEffects(HOME_EFFECTS),
|
||||
lockEffects = prefs.readEffects(LOCK_EFFECTS),
|
||||
liveEffects = prefs.readEffects(LIVE_EFFECTS),
|
||||
|
||||
@@ -7,7 +7,11 @@ import com.anthonyla.paperize.data.database.PaperizeDatabase
|
||||
import com.anthonyla.paperize.data.database.entities.WallpaperCurrentEntity
|
||||
import com.anthonyla.paperize.data.mapper.toDomainModel
|
||||
import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.data.source.EncryptedImageStore
|
||||
import com.anthonyla.paperize.domain.repository.WallpaperRepository
|
||||
import com.anthonyla.paperize.domain.source.DocumentSource
|
||||
import com.anthonyla.paperize.domain.source.albumFilterRegex
|
||||
import com.anthonyla.paperize.domain.source.matchingNamingTableFiles
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@@ -16,7 +20,9 @@ import kotlinx.coroutines.flow.map
|
||||
|
||||
@Singleton
|
||||
class WallpaperRepositoryImpl @Inject constructor(
|
||||
private val database: PaperizeDatabase
|
||||
private val database: PaperizeDatabase,
|
||||
private val documents: DocumentSource,
|
||||
private val encryptedImages: EncryptedImageStore
|
||||
) : WallpaperRepository {
|
||||
|
||||
private val wallpaperDao = database.wallpaperDao()
|
||||
@@ -50,6 +56,8 @@ class WallpaperRepositoryImpl @Inject constructor(
|
||||
screenType: ScreenType,
|
||||
shuffle: Boolean
|
||||
) {
|
||||
if (wallpaperQueueDao.getNextWallpaperInQueue(albumId, screenType) != null) return
|
||||
val allowed = allowedWallpaperIds(albumId)
|
||||
database.withTransaction {
|
||||
// Recheck inside the transaction: another caller may already have filled it.
|
||||
if (wallpaperQueueDao.getNextWallpaperInQueue(albumId, screenType) != null) return@withTransaction
|
||||
@@ -60,11 +68,11 @@ class WallpaperRepositoryImpl @Inject constructor(
|
||||
} else null
|
||||
val otherQueue = otherScreen?.let { wallpaperQueueDao.getQueueItems(albumId, it) }.orEmpty()
|
||||
val ids = if (shuffle) {
|
||||
val available = wallpaperDao.getWallpaperIdsByAlbum(albumId)
|
||||
val available = wallpaperDao.getWallpaperIdsByAlbum(albumId).allowed(allowed)
|
||||
if (otherQueue.isEmpty()) available.shuffled()
|
||||
else QueueBuilder.mergeWithExistingQueue(otherQueue.map { it.wallpaperId }, available)
|
||||
} else {
|
||||
wallpaperDao.getOrderedWallpaperIdsByAlbum(albumId)
|
||||
wallpaperDao.getOrderedWallpaperIdsByAlbum(albumId).allowed(allowed)
|
||||
}
|
||||
wallpaperQueueDao.rebuildQueue(albumId, screenType, ids)
|
||||
if (otherScreen != null && otherQueue.isEmpty()) {
|
||||
@@ -78,12 +86,31 @@ class WallpaperRepositoryImpl @Inject constructor(
|
||||
screenType: ScreenType,
|
||||
wallpaperId: String
|
||||
) {
|
||||
val allowed = allowedWallpaperIds(albumId)
|
||||
database.withTransaction {
|
||||
val ordered = wallpaperDao.getOrderedWallpaperIdsByAlbum(albumId)
|
||||
wallpaperQueueDao.rebuildQueue(albumId, screenType, QueueBuilder.idsAfter(ordered, wallpaperId))
|
||||
wallpaperQueueDao.rebuildQueue(
|
||||
albumId, screenType, QueueBuilder.idsAfter(ordered, wallpaperId).allowed(allowed)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<String>.allowed(allowed: Set<String>?) = if (allowed == null) this else filter { it in allowed }
|
||||
|
||||
/** Ids passing the album filter, or null without one. Images outside a folder with a naming table never pass. */
|
||||
private suspend fun allowedWallpaperIds(albumId: String): Set<String>? {
|
||||
val filter = database.albumDao().getAlbumById(albumId)?.filter?.let(::albumFilterRegex) ?: return null
|
||||
val allowed = HashSet<String>()
|
||||
database.folderDao().getFoldersByAlbum(albumId).forEach { folder ->
|
||||
val table = documents.readNamingTable(folder.uri) ?: return@forEach
|
||||
val files = matchingNamingTableFiles(encryptedImages.decrypt(table).decodeToString(), filter)
|
||||
wallpaperDao.getFolderWallpapers(folder.id)
|
||||
.filter { it.fileName.substringAfterLast('/') in files }
|
||||
.mapTo(allowed) { it.id }
|
||||
}
|
||||
return allowed
|
||||
}
|
||||
|
||||
override suspend fun clearAllQueues() {
|
||||
wallpaperQueueDao.deleteAllQueueItems()
|
||||
}
|
||||
|
||||
@@ -10,11 +10,12 @@ import android.provider.DocumentsContract
|
||||
import android.provider.OpenableColumns
|
||||
import androidx.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
import com.anthonyla.paperize.core.runCatchingCancellable
|
||||
import com.anthonyla.paperize.domain.source.DocumentSource
|
||||
import com.anthonyla.paperize.domain.source.NAMING_TABLE_FILE
|
||||
import com.anthonyla.paperize.domain.source.SourceFolder
|
||||
import com.anthonyla.paperize.domain.source.SourceImage
|
||||
import com.anthonyla.paperize.domain.source.isSupportedSourceName
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.currentCoroutineContext
|
||||
@@ -37,14 +38,27 @@ class AndroidDocumentSource @Inject constructor(
|
||||
SourceImage(uri, document?.name ?: uri.substringAfterLast('/'), document?.lastModified() ?: 0L)
|
||||
}
|
||||
|
||||
override suspend fun readFolder(uri: String, onProgress: (Int) -> Unit): SourceFolder = withContext(Dispatchers.IO) {
|
||||
override suspend fun readFolder(uri: String, isEncrypted: Boolean, onProgress: (Int) -> Unit): SourceFolder = withContext(Dispatchers.IO) {
|
||||
val tree = uri.toUri()
|
||||
SourceFolder(
|
||||
DocumentFile.fromTreeUri(context, tree)?.name ?: uri.substringAfterLast('/'),
|
||||
tree.scanFolderImages(context, onProgress)
|
||||
tree.scanFolderImages(context, isEncrypted, onProgress)
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun readNamingTable(folderUri: String): ByteArray? = withContext(Dispatchers.IO) {
|
||||
val tree = folderUri.toUri()
|
||||
val children = DocumentsContract.buildChildDocumentsUriUsingTree(tree, DocumentsContract.getTreeDocumentId(tree))
|
||||
val projection = arrayOf(DocumentsContract.Document.COLUMN_DOCUMENT_ID, DocumentsContract.Document.COLUMN_DISPLAY_NAME)
|
||||
val documentId = context.contentResolver.query(children, projection, null, null, null)?.use { cursor ->
|
||||
cursor.requireComplete()
|
||||
generateSequence { if (cursor.moveToNext()) cursor else null }
|
||||
.firstOrNull { it.getString(1) == NAMING_TABLE_FILE }?.getString(0)
|
||||
} ?: return@withContext null
|
||||
val table = DocumentsContract.buildDocumentUriUsingTree(tree, documentId)
|
||||
context.contentResolver.openInputStream(table)?.use { it.readBytes() }
|
||||
}
|
||||
|
||||
override suspend fun isMissing(uri: String, isTree: Boolean): Boolean = withContext(Dispatchers.IO) {
|
||||
val source = uri.toUri()
|
||||
val document = if (isTree) {
|
||||
@@ -80,7 +94,7 @@ private fun Cursor.requireComplete() {
|
||||
* Rejects incomplete provider results and cancels in-flight queries with the caller.
|
||||
* [onProgress] reports every [PROGRESS_REPORT_INTERVAL] discoveries and on completion.
|
||||
*/
|
||||
internal suspend fun Uri.scanFolderImages(context: Context, onProgress: (found: Int) -> Unit = {}): List<SourceImage> {
|
||||
internal suspend fun Uri.scanFolderImages(context: Context, isEncrypted: Boolean, onProgress: (found: Int) -> Unit = {}): List<SourceImage> {
|
||||
val rootDocumentId = DocumentsContract.getTreeDocumentId(this)
|
||||
|
||||
val projection = arrayOf(
|
||||
@@ -130,8 +144,7 @@ internal suspend fun Uri.scanFolderImages(context: Context, onProgress: (found:
|
||||
if (cursor.getString(mimeColumn) == DocumentsContract.Document.MIME_TYPE_DIR) {
|
||||
pendingDirs.addLast(documentId)
|
||||
} else {
|
||||
val extension = name.substringAfterLast('.', "").lowercase()
|
||||
if (extension in Constants.SUPPORTED_IMAGE_EXTENSIONS) {
|
||||
if (isSupportedSourceName(name, isEncrypted)) {
|
||||
results.add(
|
||||
SourceImage(
|
||||
uri = DocumentsContract.buildDocumentUriUsingTree(this, documentId).toString(),
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.anthonyla.paperize.data.source
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.ImageDecoder
|
||||
import android.util.Log
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.core.ScreenType
|
||||
import com.anthonyla.paperize.core.util.adaptiveBrightnessAdjustment
|
||||
@@ -14,11 +16,13 @@ import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.domain.source.WallpaperRenderer
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import javax.inject.Inject
|
||||
import java.nio.ByteBuffer
|
||||
import kotlinx.coroutines.currentCoroutineContext
|
||||
import kotlinx.coroutines.ensureActive
|
||||
|
||||
class AndroidWallpaperRenderer @Inject constructor(
|
||||
@param:ApplicationContext private val context: Context
|
||||
@param:ApplicationContext private val context: Context,
|
||||
private val encryptedImages: EncryptedImageStore
|
||||
) : WallpaperRenderer {
|
||||
override suspend fun render(wallpaper: Wallpaper, screen: ScreenType, settings: ScheduleSettings): Bitmap? {
|
||||
currentCoroutineContext().ensureActive()
|
||||
@@ -33,8 +37,22 @@ class AndroidWallpaperRenderer @Inject constructor(
|
||||
ScreenType.LIVE -> settings.liveScalingType
|
||||
}
|
||||
val size = getDeviceScreenSize(context)
|
||||
var bitmap = retrieveBitmap(context, wallpaper.uri.toUri(), size.width, size.height, scaling,
|
||||
usesLauncherManagedScrolling(screen, scaling, settings.homeScrollingEnabled)) ?: return null
|
||||
val decrypted = if (wallpaper.fileName.endsWith(".jpg_enc", ignoreCase = true)) {
|
||||
try {
|
||||
encryptedImages.decrypt(wallpaper.uri.toUri())
|
||||
} catch (e: Exception) {
|
||||
Log.e("AndroidWallpaperRenderer", "Could not decrypt wallpaper", e)
|
||||
throw e
|
||||
}
|
||||
} else null
|
||||
var bitmap = try {
|
||||
retrieveBitmap(context, wallpaper.uri.toUri(), size.width, size.height, scaling,
|
||||
usesLauncherManagedScrolling(screen, scaling, settings.homeScrollingEnabled),
|
||||
settings.blurFitBackground,
|
||||
decrypted?.let { ImageDecoder.createSource(ByteBuffer.wrap(it)) })
|
||||
} finally {
|
||||
decrypted?.fill(0)
|
||||
} ?: return null
|
||||
try {
|
||||
val processed = processBitmap(
|
||||
source = bitmap,
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.anthonyla.paperize.data.source
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.security.keystore.KeyGenParameterSpec
|
||||
import android.security.keystore.KeyProperties
|
||||
import android.util.AtomicFile
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.security.KeyStore
|
||||
import javax.crypto.BadPaddingException
|
||||
import javax.crypto.Cipher
|
||||
import javax.crypto.KeyGenerator
|
||||
import javax.crypto.SecretKey
|
||||
import javax.crypto.SecretKeyFactory
|
||||
import javax.crypto.spec.GCMParameterSpec
|
||||
import javax.crypto.spec.IvParameterSpec
|
||||
import javax.crypto.spec.PBEKeySpec
|
||||
import javax.crypto.spec.SecretKeySpec
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class MissingPassphraseException : IllegalStateException("No encryption passphrase is configured")
|
||||
class PassphraseStorageException(cause: Throwable) : IllegalStateException("Cannot access the stored passphrase", cause)
|
||||
class InvalidEncryptedFileException : IOException("Invalid or truncated encrypted file")
|
||||
class IncorrectPassphraseException : IOException("Incorrect passphrase or damaged encrypted file")
|
||||
|
||||
@Singleton
|
||||
class EncryptedImageStore @Inject constructor(
|
||||
@param:ApplicationContext private val context: Context
|
||||
) {
|
||||
private val passphraseFile = AtomicFile(File(context.noBackupFilesDir, "encrypted_image_passphrase"))
|
||||
private val mutableRevision = MutableStateFlow(0)
|
||||
val revision: StateFlow<Int> = mutableRevision.asStateFlow()
|
||||
|
||||
@Synchronized
|
||||
fun setPassphrase(passphrase: String) {
|
||||
try {
|
||||
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
|
||||
cipher.init(Cipher.ENCRYPT_MODE, key(create = true))
|
||||
val plaintext = passphrase.toByteArray(Charsets.UTF_8)
|
||||
val encrypted = try {
|
||||
cipher.doFinal(plaintext)
|
||||
} finally {
|
||||
plaintext.fill(0)
|
||||
}
|
||||
val output = passphraseFile.startWrite()
|
||||
try {
|
||||
output.write(cipher.iv)
|
||||
output.write(encrypted)
|
||||
passphraseFile.finishWrite(output)
|
||||
mutableRevision.value += 1
|
||||
} catch (e: Exception) {
|
||||
passphraseFile.failWrite(output)
|
||||
throw e
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
throw PassphraseStorageException(e)
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun clearPassphrase() {
|
||||
passphraseFile.delete()
|
||||
check(!passphraseFile.baseFile.exists()) { "Cannot clear the stored passphrase" }
|
||||
mutableRevision.value += 1
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun hasPassphrase(): Boolean = passphraseFile.baseFile.exists()
|
||||
|
||||
fun decrypt(uri: Uri): ByteArray {
|
||||
val passphrase = synchronized(this) { readPassphrase() }
|
||||
val bytes = context.contentResolver.openInputStream(uri)?.use { it.readBytes() }
|
||||
?: throw IOException("Cannot open encrypted file")
|
||||
return decryptEncryptedImage(bytes, passphrase)
|
||||
}
|
||||
|
||||
fun decrypt(bytes: ByteArray): ByteArray = decryptEncryptedImage(bytes, synchronized(this) { readPassphrase() })
|
||||
|
||||
private fun readPassphrase(): String {
|
||||
if (!hasPassphrase()) throw MissingPassphraseException()
|
||||
try {
|
||||
val stored = passphraseFile.readFully()
|
||||
require(stored.size >= IV_SIZE + TAG_SIZE)
|
||||
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
|
||||
cipher.init(Cipher.DECRYPT_MODE, key(create = false), GCMParameterSpec(128, stored, 0, IV_SIZE))
|
||||
val plaintext = cipher.doFinal(stored, IV_SIZE, stored.size - IV_SIZE)
|
||||
return try {
|
||||
plaintext.toString(Charsets.UTF_8)
|
||||
} finally {
|
||||
plaintext.fill(0)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
throw PassphraseStorageException(e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun key(create: Boolean): SecretKey {
|
||||
val keyStore = KeyStore.getInstance("AndroidKeyStore").apply { load(null) }
|
||||
val existing = keyStore.getKey(KEY_ALIAS, null) as? SecretKey
|
||||
if (existing != null) return existing
|
||||
check(create) { "Keystore key is missing" }
|
||||
return KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore").run {
|
||||
init(
|
||||
KeyGenParameterSpec.Builder(
|
||||
KEY_ALIAS,
|
||||
KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT
|
||||
)
|
||||
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
|
||||
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
|
||||
.build()
|
||||
)
|
||||
generateKey()
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val KEY_ALIAS = "paperize_encrypted_image_passphrase"
|
||||
const val IV_SIZE = 12
|
||||
const val TAG_SIZE = 16
|
||||
}
|
||||
}
|
||||
|
||||
internal fun decryptEncryptedImage(encrypted: ByteArray, passphrase: String): ByteArray {
|
||||
val headerSize = 16
|
||||
if (encrypted.size < headerSize + 16 ||
|
||||
(encrypted.size - headerSize) % 16 != 0 ||
|
||||
!encrypted.copyOfRange(0, 8).contentEquals("Salted__".toByteArray(Charsets.US_ASCII))
|
||||
) throw InvalidEncryptedFileException()
|
||||
|
||||
val spec = PBEKeySpec(passphrase.toCharArray(), encrypted.copyOfRange(8, headerSize), 10_000, 384)
|
||||
val material = try {
|
||||
SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256").generateSecret(spec).encoded
|
||||
} finally {
|
||||
spec.clearPassword()
|
||||
}
|
||||
try {
|
||||
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
|
||||
cipher.init(
|
||||
Cipher.DECRYPT_MODE,
|
||||
SecretKeySpec(material, 0, 32, "AES"),
|
||||
IvParameterSpec(material, 32, 16)
|
||||
)
|
||||
return try {
|
||||
cipher.doFinal(encrypted, headerSize, encrypted.size - headerSize)
|
||||
} catch (_: BadPaddingException) {
|
||||
throw IncorrectPassphraseException()
|
||||
}
|
||||
} finally {
|
||||
material.fill(0)
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,8 @@ data class Album(
|
||||
val wallpapers: List<Wallpaper> = emptyList(),
|
||||
val folders: List<Folder> = emptyList(),
|
||||
val createdAt: Long = System.currentTimeMillis(),
|
||||
val modifiedAt: Long = System.currentTimeMillis()
|
||||
val modifiedAt: Long = System.currentTimeMillis(),
|
||||
val isEncrypted: Boolean = false,
|
||||
/** Regex over naming-table lines; only matching images are picked as wallpaper. */
|
||||
val filter: String? = null
|
||||
)
|
||||
@@ -4,5 +4,6 @@ data class AppSettings(
|
||||
val darkMode: Boolean? = null, // null = system default, true = dark, false = light
|
||||
val dynamicTheming: Boolean = false,
|
||||
val animate: Boolean = true,
|
||||
val firstLaunch: Boolean = true
|
||||
val firstLaunch: Boolean = true,
|
||||
val encryptedPreviews: Boolean = false
|
||||
)
|
||||
@@ -11,6 +11,7 @@ data class Folder(
|
||||
val dateModified: Long,
|
||||
val displayOrder: Int = 0,
|
||||
val wallpapers: List<Wallpaper> = emptyList(),
|
||||
val removedWallpapers: List<Wallpaper> = emptyList(),
|
||||
val addedAt: Long = System.currentTimeMillis()
|
||||
) {
|
||||
val displayName: String
|
||||
|
||||
@@ -19,6 +19,7 @@ data class ScheduleSettings(
|
||||
val homeScalingType: ScalingType = ScalingType.FILL,
|
||||
val lockScalingType: ScalingType = ScalingType.FILL,
|
||||
val homeScrollingEnabled: Boolean = false,
|
||||
val blurFitBackground: Boolean = false,
|
||||
val homeEffects: WallpaperEffects = WallpaperEffects(),
|
||||
val lockEffects: WallpaperEffects = WallpaperEffects(),
|
||||
val liveAlbumId: String? = null,
|
||||
@@ -87,6 +88,7 @@ data class ScheduleSettings(
|
||||
return homeScalingType != other.homeScalingType ||
|
||||
lockScalingType != other.lockScalingType ||
|
||||
homeScrollingEnabled != other.homeScrollingEnabled ||
|
||||
blurFitBackground != other.blurFitBackground ||
|
||||
homeEffects != other.homeEffects ||
|
||||
lockEffects != other.lockEffects ||
|
||||
liveEffects != other.liveEffects ||
|
||||
|
||||
@@ -11,9 +11,17 @@ interface AlbumRepository {
|
||||
|
||||
fun getAlbumById(albumId: String): Flow<Album?>
|
||||
|
||||
suspend fun getAlbumEncryption(albumId: String): Boolean?
|
||||
|
||||
fun getFolderById(folderId: String): Flow<Folder?>
|
||||
|
||||
suspend fun createAlbum(name: String, coverUri: String? = null): Album
|
||||
suspend fun createAlbum(name: String, coverUri: String? = null, isEncrypted: Boolean = false): Album
|
||||
|
||||
/** Returns false if another album has this name, ignoring case. */
|
||||
suspend fun renameAlbum(albumId: String, name: String): Boolean
|
||||
|
||||
/** A null or blank [filter] removes it. Rebuilds the album queues. */
|
||||
suspend fun setAlbumFilter(albumId: String, filter: String?)
|
||||
|
||||
suspend fun deleteAlbum(albumId: String)
|
||||
|
||||
@@ -41,6 +49,12 @@ interface AlbumRepository {
|
||||
|
||||
suspend fun removeWallpapersFromAlbum(albumId: String, wallpaperIds: List<String>)
|
||||
|
||||
/** Removes one wallpaper; a folder image is also kept out of later rescans. Returns it for [restoreWallpaper]. */
|
||||
suspend fun removeWallpaper(wallpaperId: String): Wallpaper?
|
||||
|
||||
/** Puts a removed wallpaper back where it was. */
|
||||
suspend fun restoreWallpaper(wallpaper: Wallpaper)
|
||||
|
||||
suspend fun removeFolderFromAlbum(albumId: String, folderId: String)
|
||||
|
||||
suspend fun deleteAllAlbums()
|
||||
|
||||
@@ -42,6 +42,7 @@ interface SettingsRepository {
|
||||
suspend fun updateDarkMode(enabled: Boolean)
|
||||
suspend fun updateDynamicTheming(enabled: Boolean)
|
||||
suspend fun updateAnimate(enabled: Boolean)
|
||||
suspend fun updateEncryptedPreviews(enabled: Boolean)
|
||||
suspend fun completeFirstLaunch()
|
||||
|
||||
suspend fun updateEnableChanger(enabled: Boolean)
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
package com.anthonyla.paperize.domain.source
|
||||
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
|
||||
data class SourceImage(val uri: String, val name: String, val modifiedAt: Long)
|
||||
data class SourceFolder(val name: String, val images: List<SourceImage>)
|
||||
|
||||
fun isSupportedSourceName(name: String, isEncrypted: Boolean): Boolean =
|
||||
if (isEncrypted) name.endsWith(".jpg_enc", ignoreCase = true)
|
||||
else name.substringAfterLast('.', "").lowercase() in Constants.SUPPORTED_IMAGE_EXTENSIONS
|
||||
|
||||
interface DocumentSource {
|
||||
suspend fun retainReadPermission(uri: String)
|
||||
suspend fun readImage(uri: String): SourceImage
|
||||
suspend fun readFolder(uri: String, onProgress: (Int) -> Unit = {}): SourceFolder
|
||||
suspend fun readFolder(uri: String, isEncrypted: Boolean, onProgress: (Int) -> Unit = {}): SourceFolder
|
||||
/** The [NAMING_TABLE_FILE] in the root of a folder, or null if it has none. */
|
||||
suspend fun readNamingTable(folderUri: String): ByteArray?
|
||||
suspend fun isMissing(uri: String, isTree: Boolean = false): Boolean
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.anthonyla.paperize.domain.source
|
||||
|
||||
const val NAMING_TABLE_FILE = "naming_table.enc"
|
||||
|
||||
fun albumFilterRegex(pattern: String) = Regex(pattern, RegexOption.IGNORE_CASE)
|
||||
|
||||
/** File names of the entries whose `name;encrypted_file;hash` line contains a [filter] match, like wallpaper_changer. */
|
||||
fun matchingNamingTableFiles(table: String, filter: Regex): Set<String> =
|
||||
table.lineSequence()
|
||||
.filter { it.count { c -> c == ';' } >= 2 && filter.containsMatchIn(it) }
|
||||
.map { it.split(';', limit = 3)[1].substringAfterLast('/') }
|
||||
.toSet()
|
||||
@@ -8,9 +8,9 @@ class CreateAlbumUseCase @Inject constructor(
|
||||
private val albumRepository: AlbumRepository
|
||||
) {
|
||||
/** Returns false, creating nothing, when an album already has this name ignoring case. */
|
||||
suspend operator fun invoke(name: String): Boolean {
|
||||
suspend operator fun invoke(name: String, isEncrypted: Boolean = false): Boolean {
|
||||
if (albumRepository.getAlbumSummaries().first().any { it.name.equals(name, ignoreCase = true) }) return false
|
||||
albumRepository.createAlbum(name)
|
||||
albumRepository.createAlbum(name, isEncrypted = isEncrypted)
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.domain.repository.AlbumRepository
|
||||
import com.anthonyla.paperize.domain.source.DocumentSource
|
||||
import com.anthonyla.paperize.domain.source.SourceImage
|
||||
import com.anthonyla.paperize.domain.source.isSupportedSourceName
|
||||
import kotlinx.coroutines.flow.first
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -14,9 +15,11 @@ class ImportWallpapersUseCase @Inject constructor(
|
||||
private val albumRepository: AlbumRepository
|
||||
) {
|
||||
suspend fun addImages(albumId: String, uris: List<String>, onSaving: (Int, Int) -> Unit): Boolean {
|
||||
val images = uris.distinct().map { uri ->
|
||||
val isEncrypted = checkNotNull(albumRepository.getAlbumEncryption(albumId))
|
||||
val images = uris.distinct().mapNotNull { uri ->
|
||||
documents.retainReadPermission(uri)
|
||||
documents.readImage(uri).toWallpaper(albumId)
|
||||
val image = documents.readImage(uri)
|
||||
if (!isEncrypted || isSupportedSourceName(image.name, true)) image.toWallpaper(albumId) else null
|
||||
}
|
||||
return albumRepository.addWallpapersToAlbum(albumId, images, onSaving) > 0
|
||||
}
|
||||
@@ -29,8 +32,9 @@ class ImportWallpapersUseCase @Inject constructor(
|
||||
): Boolean {
|
||||
documents.retainReadPermission(uri)
|
||||
// Avoid rescanning an existing folder; insertion still checks duplicates atomically.
|
||||
if (albumRepository.getAlbumById(albumId).first()?.folders.orEmpty().any { it.uri == uri }) return false
|
||||
val source = documents.readFolder(uri, onScanning)
|
||||
val album = checkNotNull(albumRepository.getAlbumById(albumId).first())
|
||||
if (album.folders.any { it.uri == uri }) return false
|
||||
val source = documents.readFolder(uri, album.isEncrypted, onScanning)
|
||||
val folderId = generateId()
|
||||
val folder = Folder(
|
||||
id = folderId, albumId = albumId, uri = uri, name = source.name,
|
||||
|
||||
@@ -12,7 +12,8 @@ class RefreshFolderUseCase @Inject constructor(
|
||||
/** Returns the number of new images. */
|
||||
suspend operator fun invoke(folderId: String): Int {
|
||||
val folder = albumRepository.getFolderById(folderId).first() ?: return 0
|
||||
val source = documents.readFolder(folder.uri)
|
||||
val isEncrypted = albumRepository.getAlbumEncryption(folder.albumId) ?: return 0
|
||||
val source = documents.readFolder(folder.uri, isEncrypted)
|
||||
return albumRepository.syncFolderWallpapers(
|
||||
folder.albumId, folderId, source.images.map { it.toWallpaper(folder.albumId, folderId) }
|
||||
)
|
||||
|
||||
@@ -13,11 +13,8 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import coil3.compose.AsyncImagePainter
|
||||
import coil3.compose.rememberAsyncImagePainter
|
||||
import coil3.request.ImageRequest
|
||||
import coil3.size.Size
|
||||
import com.anthonyla.paperize.domain.model.AlbumSummary
|
||||
|
||||
/** The album's cover image, or a placeholder icon until one loads. */
|
||||
@@ -30,10 +27,7 @@ fun AlbumCover(
|
||||
placeholderModifier: Modifier = Modifier
|
||||
) {
|
||||
val cover = rememberAsyncImagePainter(
|
||||
ImageRequest.Builder(LocalContext.current)
|
||||
.data(album.coverUri)
|
||||
.size(Size(thumbnailSize, thumbnailSize))
|
||||
.build(),
|
||||
encryptedAwareImageRequest(album.coverUri, thumbnailSize, thumbnailSize),
|
||||
contentScale = ContentScale.Crop
|
||||
)
|
||||
val coverState by cover.state.collectAsState()
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
package com.anthonyla.paperize.presentation.common.components
|
||||
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.selection.toggleable
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.presentation.common.theme.AppSpacing
|
||||
|
||||
@Composable
|
||||
fun AddAlbumDialog(
|
||||
onDismiss: () -> Unit,
|
||||
onConfirm: (String) -> Unit,
|
||||
onConfirm: (String, Boolean) -> Unit,
|
||||
errorMessage: String?,
|
||||
isSaving: Boolean
|
||||
) {
|
||||
var albumName by rememberSaveable { mutableStateOf("") }
|
||||
var isEncrypted by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = { if (!isSaving) onDismiss() },
|
||||
@@ -38,11 +42,24 @@ fun AddAlbumDialog(
|
||||
} else null,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().toggleable(
|
||||
value = isEncrypted,
|
||||
enabled = !isSaving,
|
||||
role = Role.Checkbox,
|
||||
onValueChange = { isEncrypted = it }
|
||||
),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Checkbox(checked = isEncrypted, onCheckedChange = null, enabled = !isSaving)
|
||||
Text(stringResource(R.string.encrypted_album))
|
||||
}
|
||||
Text(stringResource(R.string.encrypted_album_hint), style = MaterialTheme.typography.bodySmall)
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = { onConfirm(albumName.trim()) },
|
||||
onClick = { onConfirm(albumName.trim(), isEncrypted) },
|
||||
enabled = !isSaving && albumName.isNotBlank()
|
||||
) {
|
||||
Text(stringResource(R.string.save))
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.anthonyla.paperize.presentation.common.components
|
||||
|
||||
import android.graphics.ImageDecoder
|
||||
import android.provider.OpenableColumns
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.key
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.core.net.toUri
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import coil3.request.CachePolicy
|
||||
import coil3.request.ImageRequest
|
||||
import coil3.request.crossfade
|
||||
import coil3.size.Size
|
||||
import com.anthonyla.paperize.data.source.EncryptedImageStore
|
||||
import com.anthonyla.paperize.domain.repository.SettingsRepository
|
||||
import dagger.hilt.EntryPoint
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.EntryPointAccessors
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import java.nio.ByteBuffer
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@EntryPoint
|
||||
@InstallIn(SingletonComponent::class)
|
||||
interface EncryptedPreviewEntryPoint {
|
||||
fun encryptedImages(): EncryptedImageStore
|
||||
fun settings(): SettingsRepository
|
||||
}
|
||||
|
||||
private data class PreviewImage(val data: Any, val encrypted: Boolean)
|
||||
|
||||
@Composable
|
||||
fun encryptedAwareImageRequest(
|
||||
uri: String?,
|
||||
width: Int? = null,
|
||||
height: Int? = null,
|
||||
animate: Boolean = false
|
||||
): ImageRequest? {
|
||||
val context = LocalContext.current
|
||||
val dependencies = remember(context) {
|
||||
EntryPointAccessors.fromApplication(context.applicationContext, EncryptedPreviewEntryPoint::class.java)
|
||||
}
|
||||
val settings = remember(dependencies) { dependencies.settings().getAppSettingsFlow() }
|
||||
val appSettings by settings.collectAsState(initial = null)
|
||||
val enabled = appSettings?.encryptedPreviews == true
|
||||
val store = remember(dependencies) { dependencies.encryptedImages() }
|
||||
return encryptedPreviewImageRequest(uri, width, height, animate, enabled, store)
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun encryptedPreviewImageRequest(
|
||||
uri: String?,
|
||||
width: Int?,
|
||||
height: Int?,
|
||||
animate: Boolean,
|
||||
enabled: Boolean,
|
||||
store: EncryptedImageStore
|
||||
): ImageRequest? {
|
||||
val context = LocalContext.current
|
||||
val revision by store.revision.collectAsState()
|
||||
|
||||
return key(uri, enabled, revision, width, height) {
|
||||
val image by produceState<PreviewImage?>(initialValue = null) {
|
||||
if (uri != null) {
|
||||
value = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val parsed = uri.toUri()
|
||||
val name = if (parsed.scheme == "file") parsed.lastPathSegment else {
|
||||
try {
|
||||
context.contentResolver.query(
|
||||
parsed, arrayOf(OpenableColumns.DISPLAY_NAME), null, null, null
|
||||
)?.use { cursor ->
|
||||
if (cursor.moveToFirst()) cursor.getString(0) else null
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w("EncryptedPreview", "Could not read image name; loading the original URI", e)
|
||||
null
|
||||
}
|
||||
}
|
||||
if (name == null) {
|
||||
Log.w("EncryptedPreview", "Image name unavailable; loading the original URI")
|
||||
}
|
||||
val isEncrypted = (name ?: parsed.lastPathSegment)?.endsWith(".jpg_enc", ignoreCase = true) == true
|
||||
if (!isEncrypted) {
|
||||
PreviewImage(parsed, false)
|
||||
} else if (!enabled) {
|
||||
null
|
||||
} else {
|
||||
val bytes = store.decrypt(parsed)
|
||||
try {
|
||||
val bitmap = ImageDecoder.decodeBitmap(ImageDecoder.createSource(ByteBuffer.wrap(bytes))) {
|
||||
decoder, info, _ ->
|
||||
val maxWidth = width ?: 2048
|
||||
val maxHeight = height ?: 2048
|
||||
val scale = minOf(1f, maxWidth.toFloat() / info.size.width, maxHeight.toFloat() / info.size.height)
|
||||
decoder.setTargetSize(
|
||||
(info.size.width * scale).toInt().coerceAtLeast(1),
|
||||
(info.size.height * scale).toInt().coerceAtLeast(1)
|
||||
)
|
||||
decoder.allocator = ImageDecoder.ALLOCATOR_SOFTWARE
|
||||
}
|
||||
PreviewImage(bitmap, true)
|
||||
} finally {
|
||||
bytes.fill(0)
|
||||
}
|
||||
}
|
||||
} catch (e: CancellationException) {
|
||||
throw e
|
||||
} catch (e: Exception) {
|
||||
Log.w("EncryptedPreview", "Could not load image preview", e)
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
remember(context, image, width, height, animate) {
|
||||
image?.let {
|
||||
ImageRequest.Builder(context)
|
||||
.data(it.data)
|
||||
.crossfade(animate && !it.encrypted)
|
||||
.apply {
|
||||
if (width != null && height != null) size(Size(width, height))
|
||||
if (it.encrypted) {
|
||||
memoryCachePolicy(CachePolicy.DISABLED)
|
||||
diskCachePolicy(CachePolicy.DISABLED)
|
||||
}
|
||||
}
|
||||
.build()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,9 +40,9 @@ import kotlinx.coroutines.delay
|
||||
@Composable
|
||||
fun OnboardingLayout(
|
||||
title: String,
|
||||
modifier: Modifier = Modifier,
|
||||
iconContent: @Composable () -> Unit,
|
||||
content: @Composable () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
actions: @Composable () -> Unit
|
||||
) {
|
||||
var visible by remember { mutableStateOf(false) }
|
||||
|
||||
@@ -9,7 +9,6 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import com.anthonyla.paperize.presentation.common.theme.AppSpacing
|
||||
|
||||
/** Related [SettingsRow]s drawn as one rounded block, split by hairline gaps instead of nested cards. */
|
||||
@@ -25,9 +24,7 @@ fun SettingsGroup(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(start = AppSpacing.large, end = AppSpacing.large, bottom = AppSpacing.small),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
modifier = Modifier.padding(start = AppSpacing.large, end = AppSpacing.large, bottom = AppSpacing.small)
|
||||
)
|
||||
}
|
||||
Column(
|
||||
@@ -105,17 +102,13 @@ fun SettingText(title: String, description: String?, modifier: Modifier = Modifi
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
if (description != null) {
|
||||
Text(
|
||||
text = description,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
maxLines = 3,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,11 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.role
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.core.net.toUri
|
||||
import coil3.compose.AsyncImage
|
||||
import coil3.request.ImageRequest
|
||||
import coil3.size.Size
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
|
||||
@Composable
|
||||
@@ -36,10 +32,9 @@ fun WallpaperItem(
|
||||
}
|
||||
) {
|
||||
AsyncImage(
|
||||
model = ImageRequest.Builder(LocalContext.current)
|
||||
.data(wallpaperUri.toUri())
|
||||
.size(Size(Constants.GRID_THUMBNAIL_WIDTH, Constants.GRID_THUMBNAIL_HEIGHT))
|
||||
.build(),
|
||||
model = encryptedAwareImageRequest(
|
||||
wallpaperUri, Constants.GRID_THUMBNAIL_WIDTH, Constants.GRID_THUMBNAIL_HEIGHT
|
||||
),
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
|
||||
@@ -5,8 +5,14 @@ import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
import androidx.compose.material3.FilledTonalButton
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
@@ -17,6 +23,7 @@ import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -38,6 +45,7 @@ import com.anthonyla.paperize.presentation.screens.album_view.components.AlbumVi
|
||||
import com.anthonyla.paperize.presentation.screens.album_view.components.FolderItem
|
||||
import com.anthonyla.paperize.presentation.screens.album_view.components.ImportProgressDialog
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun AlbumViewScreen(
|
||||
@@ -57,8 +65,18 @@ fun AlbumViewScreen(
|
||||
val importProgress by viewModel.importProgress.collectAsStateWithLifecycle()
|
||||
val message by viewModel.message.collectAsStateWithLifecycle()
|
||||
val isDeleting by viewModel.isDeleting.collectAsStateWithLifecycle()
|
||||
val isRefreshing by viewModel.isRefreshing.collectAsStateWithLifecycle()
|
||||
val albumDeleted by viewModel.albumDeleted.collectAsStateWithLifecycle()
|
||||
var showDeleteAlbumDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showRenameDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var renameText by rememberSaveable { mutableStateOf("") }
|
||||
var renameError by rememberSaveable { mutableStateOf<Int?>(null) }
|
||||
var isRenaming by remember { mutableStateOf(false) }
|
||||
var showFilterDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var filterText by rememberSaveable { mutableStateOf("") }
|
||||
var filterError by rememberSaveable { mutableStateOf<Int?>(null) }
|
||||
var isFiltering by remember { mutableStateOf(false) }
|
||||
val scope = rememberCoroutineScope()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
SnackbarMessageEffect(message, snackbarHostState, viewModel::dismissMessage)
|
||||
LaunchedEffect(viewModel) {
|
||||
@@ -104,24 +122,42 @@ fun AlbumViewScreen(
|
||||
Scaffold(
|
||||
snackbarHost = { SnackbarHost(snackbarHostState) },
|
||||
topBar = {
|
||||
AlbumViewTopBar(
|
||||
title = album?.name ?: "",
|
||||
isSelectionMode = isSelectionMode,
|
||||
selectedCount = selectedCount,
|
||||
allSelected = allSelected,
|
||||
onBackClick = onBackClick,
|
||||
onSortClick = { showSortSheet = true },
|
||||
onDeleteAlbum = { showDeleteAlbumDialog = true },
|
||||
onSelectAll = { if (allSelected) viewModel.clearSelection() else viewModel.selectAll() },
|
||||
onDeleteSelected = { if (!isDeleting) showDeleteSelectedDialog = true },
|
||||
onClearSelection = { viewModel.clearSelection() }
|
||||
)
|
||||
Column {
|
||||
AlbumViewTopBar(
|
||||
title = album?.name ?: "",
|
||||
isSelectionMode = isSelectionMode,
|
||||
selectedCount = selectedCount,
|
||||
allSelected = allSelected,
|
||||
onBackClick = onBackClick,
|
||||
onSortClick = { showSortSheet = true },
|
||||
onDeleteAlbum = { showDeleteAlbumDialog = true },
|
||||
onRenameAlbum = {
|
||||
renameText = album?.name.orEmpty()
|
||||
renameError = null
|
||||
showRenameDialog = true
|
||||
},
|
||||
onFilterAlbum = if (album?.isEncrypted == true) {
|
||||
{
|
||||
filterText = album?.filter.orEmpty()
|
||||
filterError = null
|
||||
showFilterDialog = true
|
||||
}
|
||||
} else null,
|
||||
onRefreshFolders = viewModel::refreshFolders,
|
||||
albumActionsEnabled = album != null && !isDeleting && !isRefreshing && importProgress is ImportProgress.Idle,
|
||||
hasFolders = folders.isNotEmpty(),
|
||||
onSelectAll = { if (allSelected) viewModel.clearSelection() else viewModel.selectAll() },
|
||||
onDeleteSelected = { if (!isDeleting && !isRefreshing) showDeleteSelectedDialog = true },
|
||||
onClearSelection = { viewModel.clearSelection() }
|
||||
)
|
||||
if (isRefreshing) LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
||||
}
|
||||
},
|
||||
floatingActionButton = {
|
||||
if (!isSelectionMode && totalItemsCount > 0) {
|
||||
if (!isSelectionMode && !isRefreshing && totalItemsCount > 0) {
|
||||
AddAlbumAnimatedFab(
|
||||
isLoading = importProgress !is ImportProgress.Idle,
|
||||
onImageClick = { imagePickerLauncher.launch(arrayOf("image/*")) },
|
||||
onImageClick = { imagePickerLauncher.launch(arrayOf(if (album?.isEncrypted == true) "*/*" else "image/*")) },
|
||||
onFolderClick = { folderPickerLauncher.launch(null) }
|
||||
)
|
||||
}
|
||||
@@ -133,10 +169,10 @@ fun AlbumViewScreen(
|
||||
hint = stringResource(R.string.album_empty_hint),
|
||||
modifier = modifier.padding(paddingValues)
|
||||
) {
|
||||
FilledTonalButton(onClick = { imagePickerLauncher.launch(arrayOf("image/*")) }) {
|
||||
FilledTonalButton(enabled = !isRefreshing, onClick = { imagePickerLauncher.launch(arrayOf(if (album?.isEncrypted == true) "*/*" else "image/*")) }) {
|
||||
Text(stringResource(R.string.add_wallpapers))
|
||||
}
|
||||
TextButton(onClick = { folderPickerLauncher.launch(null) }) {
|
||||
TextButton(enabled = !isRefreshing, onClick = { folderPickerLauncher.launch(null) }) {
|
||||
Text(stringResource(R.string.add_folder))
|
||||
}
|
||||
}
|
||||
@@ -200,6 +236,90 @@ fun AlbumViewScreen(
|
||||
|
||||
ImportProgressDialog(progress = importProgress, onCancel = viewModel::cancelImport)
|
||||
|
||||
if (showRenameDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { if (!isRenaming) showRenameDialog = false },
|
||||
title = { Text(stringResource(R.string.rename_album)) },
|
||||
text = {
|
||||
OutlinedTextField(
|
||||
value = renameText,
|
||||
onValueChange = { renameText = it; renameError = null },
|
||||
label = { Text(stringResource(R.string.album_name)) },
|
||||
singleLine = true,
|
||||
enabled = !isRenaming,
|
||||
isError = renameError != null,
|
||||
supportingText = renameError?.let { error ->
|
||||
{ Text(stringResource(error), color = MaterialTheme.colorScheme.error) }
|
||||
}
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
enabled = !isRenaming && renameText.isNotBlank(),
|
||||
onClick = {
|
||||
isRenaming = true
|
||||
scope.launch {
|
||||
try {
|
||||
renameError = viewModel.renameAlbum(renameText.trim())
|
||||
if (renameError == null) showRenameDialog = false
|
||||
} finally {
|
||||
isRenaming = false
|
||||
}
|
||||
}
|
||||
}
|
||||
) { Text(stringResource(R.string.save)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showRenameDialog = false }, enabled = !isRenaming) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (showFilterDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { if (!isFiltering) showFilterDialog = false },
|
||||
title = { Text(stringResource(R.string.filter_album)) },
|
||||
text = {
|
||||
OutlinedTextField(
|
||||
value = filterText,
|
||||
onValueChange = { filterText = it; filterError = null },
|
||||
label = { Text(stringResource(R.string.filter_pattern)) },
|
||||
supportingText = {
|
||||
val error = filterError
|
||||
if (error != null) Text(stringResource(error), color = MaterialTheme.colorScheme.error)
|
||||
else Text(stringResource(R.string.filter_pattern_hint))
|
||||
},
|
||||
singleLine = true,
|
||||
enabled = !isFiltering,
|
||||
isError = filterError != null
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
enabled = !isFiltering,
|
||||
onClick = {
|
||||
isFiltering = true
|
||||
scope.launch {
|
||||
try {
|
||||
filterError = viewModel.setFilter(filterText.trim())
|
||||
if (filterError == null) showFilterDialog = false
|
||||
} finally {
|
||||
isFiltering = false
|
||||
}
|
||||
}
|
||||
}
|
||||
) { Text(stringResource(R.string.save)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showFilterDialog = false }, enabled = !isFiltering) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (showDeleteSelectedDialog) {
|
||||
ConfirmDialog(
|
||||
title = stringResource(R.string.remove_selected_title, selectedCount),
|
||||
|
||||
@@ -9,8 +9,10 @@ import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.runCatchingCancellable
|
||||
import com.anthonyla.paperize.domain.model.Album
|
||||
import com.anthonyla.paperize.domain.repository.AlbumRepository
|
||||
import com.anthonyla.paperize.domain.source.albumFilterRegex
|
||||
import com.anthonyla.paperize.domain.usecase.DeleteAlbumUseCase
|
||||
import com.anthonyla.paperize.domain.usecase.ImportWallpapersUseCase
|
||||
import com.anthonyla.paperize.domain.usecase.RefreshFolderUseCase
|
||||
import com.anthonyla.paperize.presentation.common.launchBusy
|
||||
import com.anthonyla.paperize.presentation.common.navigation.AlbumRoute
|
||||
import com.anthonyla.paperize.presentation.common.stateWhileSubscribed
|
||||
@@ -20,6 +22,7 @@ import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -28,7 +31,8 @@ class AlbumViewViewModel @Inject constructor(
|
||||
savedStateHandle: SavedStateHandle,
|
||||
private val albumRepository: AlbumRepository,
|
||||
private val importWallpapersUseCase: ImportWallpapersUseCase,
|
||||
private val deleteAlbumUseCase: DeleteAlbumUseCase
|
||||
private val deleteAlbumUseCase: DeleteAlbumUseCase,
|
||||
private val refreshFolderUseCase: RefreshFolderUseCase
|
||||
) : ViewModel() {
|
||||
|
||||
companion object {
|
||||
@@ -55,6 +59,8 @@ class AlbumViewViewModel @Inject constructor(
|
||||
val isDeleting = _isDeleting.asStateFlow()
|
||||
private val _albumDeleted = MutableStateFlow(false)
|
||||
val albumDeleted = _albumDeleted.asStateFlow()
|
||||
private val _isRefreshing = MutableStateFlow(false)
|
||||
val isRefreshing = _isRefreshing.asStateFlow()
|
||||
private var importJob: Job? = null
|
||||
|
||||
fun dismissMessage() { _message.value = null }
|
||||
@@ -79,7 +85,7 @@ class AlbumViewViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
private fun import(initialProgress: ImportProgress, block: suspend () -> Boolean) {
|
||||
if (importJob?.isCompleted == false || _isDeleting.value) return
|
||||
if (importJob?.isCompleted == false || _isDeleting.value || _isRefreshing.value) return
|
||||
_message.value = null
|
||||
_importProgress.value = initialProgress
|
||||
importJob = viewModelScope.launch {
|
||||
@@ -101,7 +107,7 @@ class AlbumViewViewModel @Inject constructor(
|
||||
fun cancelImport() { importJob?.cancel() }
|
||||
|
||||
fun deleteAlbum() {
|
||||
if (_isDeleting.value || importJob?.isCompleted == false) return
|
||||
if (_isDeleting.value || _isRefreshing.value || importJob?.isCompleted == false) return
|
||||
_message.value = null
|
||||
launchBusy(_isDeleting) {
|
||||
runCatchingCancellable { deleteAlbumUseCase(albumId) }
|
||||
@@ -113,6 +119,54 @@ class AlbumViewViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun renameAlbum(name: String): Int? =
|
||||
runCatchingCancellable { albumRepository.renameAlbum(albumId, name) }
|
||||
.fold(
|
||||
onSuccess = { renamed -> if (renamed) null else R.string.album_name_exists_error },
|
||||
onFailure = { e ->
|
||||
Log.e(TAG, "Error renaming album", e)
|
||||
R.string.rename_album_failed
|
||||
}
|
||||
)
|
||||
|
||||
suspend fun setFilter(filter: String): Int? {
|
||||
if (runCatching { albumFilterRegex(filter) }.isFailure) return R.string.filter_invalid
|
||||
return runCatchingCancellable { albumRepository.setAlbumFilter(albumId, filter) }
|
||||
.fold(
|
||||
onSuccess = { null },
|
||||
onFailure = { e ->
|
||||
Log.e(TAG, "Error setting album filter", e)
|
||||
R.string.filter_album_failed
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun refreshFolders() {
|
||||
if (_isRefreshing.value || _isDeleting.value || importJob?.isCompleted == false) return
|
||||
_message.value = null
|
||||
launchBusy(_isRefreshing) {
|
||||
val result = runCatchingCancellable {
|
||||
val folders = checkNotNull(albumRepository.getAlbumById(albumId).first()).folders
|
||||
var failed = false
|
||||
folders.forEach { folder ->
|
||||
runCatchingCancellable { refreshFolderUseCase(folder.id) }
|
||||
.onFailure { e ->
|
||||
Log.e(TAG, "Error refreshing folder '${folder.name}'", e)
|
||||
failed = true
|
||||
}
|
||||
}
|
||||
failed
|
||||
}
|
||||
_message.value = result.fold(
|
||||
onSuccess = { failed -> if (failed) R.string.album_refresh_failed else R.string.album_refreshed },
|
||||
onFailure = { e ->
|
||||
Log.e(TAG, "Error loading album folders", e)
|
||||
R.string.album_refresh_failed
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleWallpaperSelection(wallpaperId: String) = toggle(_selectedWallpapers, wallpaperId)
|
||||
|
||||
fun toggleFolderSelection(folderId: String) = toggle(_selectedFolders, folderId)
|
||||
@@ -135,7 +189,7 @@ class AlbumViewViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
fun deleteSelected() {
|
||||
if (_isDeleting.value || importJob?.isCompleted == false) return
|
||||
if (_isDeleting.value || _isRefreshing.value || importJob?.isCompleted == false) return
|
||||
_message.value = null
|
||||
val wallpaperIds = _selectedWallpapers.value.toList()
|
||||
val folderIds = _selectedFolders.value.toList()
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
package com.anthonyla.paperize.presentation.screens.album_view.components
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.Sort
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material.icons.filled.RadioButtonUnchecked
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import com.anthonyla.paperize.R
|
||||
@@ -27,6 +35,11 @@ fun AlbumViewTopBar(
|
||||
onBackClick: () -> Unit,
|
||||
onSortClick: () -> Unit,
|
||||
onDeleteAlbum: () -> Unit,
|
||||
onRenameAlbum: () -> Unit,
|
||||
onFilterAlbum: (() -> Unit)?,
|
||||
onRefreshFolders: () -> Unit,
|
||||
albumActionsEnabled: Boolean,
|
||||
hasFolders: Boolean,
|
||||
onSelectAll: () -> Unit,
|
||||
onDeleteSelected: () -> Unit,
|
||||
onClearSelection: () -> Unit
|
||||
@@ -64,6 +77,7 @@ fun AlbumViewTopBar(
|
||||
}
|
||||
)
|
||||
} else {
|
||||
var menuExpanded by remember { mutableStateOf(false) }
|
||||
BackTopAppBar(title = title, onBack = onBackClick) {
|
||||
IconButton(onClick = onSortClick) {
|
||||
Icon(
|
||||
@@ -71,11 +85,32 @@ fun AlbumViewTopBar(
|
||||
contentDescription = stringResource(R.string.sort)
|
||||
)
|
||||
}
|
||||
IconButton(onClick = onDeleteAlbum) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Delete,
|
||||
contentDescription = stringResource(R.string.delete_album)
|
||||
)
|
||||
Box {
|
||||
IconButton(onClick = { menuExpanded = true }, enabled = albumActionsEnabled) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.MoreVert,
|
||||
contentDescription = stringResource(R.string.album_menu)
|
||||
)
|
||||
}
|
||||
DropdownMenu(expanded = menuExpanded, onDismissRequest = { menuExpanded = false }) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.rename_album)) },
|
||||
onClick = { menuExpanded = false; onRenameAlbum() }
|
||||
)
|
||||
if (onFilterAlbum != null) DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.filter_album)) },
|
||||
onClick = { menuExpanded = false; onFilterAlbum() }
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.refresh_album_folders)) },
|
||||
enabled = hasFolders,
|
||||
onClick = { menuExpanded = false; onRefreshFolders() }
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.delete_album)) },
|
||||
onClick = { menuExpanded = false; onDeleteAlbum() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,29 @@
|
||||
package com.anthonyla.paperize.presentation.screens.album_view.components
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Folder
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import coil3.compose.AsyncImage
|
||||
import coil3.request.ImageRequest
|
||||
import coil3.size.Size
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
import com.anthonyla.paperize.domain.model.Folder
|
||||
import com.anthonyla.paperize.presentation.common.components.SelectableGridCard
|
||||
import com.anthonyla.paperize.presentation.common.theme.AppSpacing
|
||||
@@ -32,27 +44,56 @@ fun FolderItem(
|
||||
onLongClick = onLongClick,
|
||||
modifier = modifier
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Folder,
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.fillMaxSize(0.5f)
|
||||
.align(Alignment.Center),
|
||||
tint = if (isSelected) {
|
||||
MaterialTheme.colorScheme.primary.copy(alpha = 0.7f)
|
||||
} else {
|
||||
MaterialTheme.colorScheme.primary
|
||||
}
|
||||
)
|
||||
Text(
|
||||
text = folder.displayName,
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
textAlign = TextAlign.Center,
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
val coverUri = folder.coverUri
|
||||
if (coverUri == null) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Folder,
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.fillMaxSize(0.5f)
|
||||
.align(Alignment.Center),
|
||||
tint = if (isSelected) {
|
||||
MaterialTheme.colorScheme.primary.copy(alpha = 0.7f)
|
||||
} else {
|
||||
MaterialTheme.colorScheme.primary
|
||||
}
|
||||
)
|
||||
} else {
|
||||
AsyncImage(
|
||||
model = ImageRequest.Builder(LocalContext.current)
|
||||
.data(coverUri.toUri())
|
||||
.size(Size(Constants.GRID_THUMBNAIL_WIDTH, Constants.GRID_THUMBNAIL_HEIGHT))
|
||||
.build(),
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
alpha = if (isSelected) 0.7f else 1f
|
||||
)
|
||||
}
|
||||
Surface(
|
||||
color = MaterialTheme.colorScheme.surfaceContainerHigh,
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomCenter)
|
||||
.padding(AppSpacing.small)
|
||||
)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.padding(horizontal = AppSpacing.small, vertical = AppSpacing.extraSmall),
|
||||
horizontalArrangement = Arrangement.spacedBy(AppSpacing.extraSmall),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Folder,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
Text(
|
||||
text = folder.displayName,
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,14 @@
|
||||
package com.anthonyla.paperize.presentation.screens.album_view.components
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -22,76 +18,52 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.presentation.common.theme.AppSpacing
|
||||
import com.anthonyla.paperize.presentation.screens.album_view.ImportProgress
|
||||
|
||||
@Composable
|
||||
fun ImportProgressDialog(progress: ImportProgress, onCancel: () -> Unit) {
|
||||
val active = progress as? ImportProgress.Active ?: return
|
||||
|
||||
Dialog(
|
||||
AlertDialog(
|
||||
onDismissRequest = {},
|
||||
properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false)
|
||||
) {
|
||||
Surface(
|
||||
shape = MaterialTheme.shapes.extraLarge,
|
||||
color = MaterialTheme.colorScheme.surface,
|
||||
tonalElevation = 6.dp
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(24.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
when (active) {
|
||||
is ImportProgress.Scanning -> {
|
||||
Title(R.string.import_adding_folder)
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
CircularProgressIndicator(modifier = Modifier.size(24.dp))
|
||||
Text(
|
||||
text = pluralStringResource(R.plurals.import_scanning, active.found, active.found),
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is ImportProgress.Saving -> {
|
||||
Title(R.string.import_adding_wallpapers)
|
||||
Text(
|
||||
text = stringResource(R.string.import_saving, active.saved, active.total),
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
val fraction by animateFloatAsState(
|
||||
targetValue = if (active.total > 0) active.saved.toFloat() / active.total else 0f,
|
||||
label = "importProgress"
|
||||
)
|
||||
LinearProgressIndicator(
|
||||
progress = { fraction },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(6.dp)
|
||||
)
|
||||
properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false),
|
||||
title = {
|
||||
Text(
|
||||
stringResource(
|
||||
when (active) {
|
||||
is ImportProgress.Scanning -> R.string.import_adding_folder
|
||||
is ImportProgress.Saving -> R.string.import_adding_wallpapers
|
||||
}
|
||||
)
|
||||
)
|
||||
},
|
||||
text = {
|
||||
when (active) {
|
||||
is ImportProgress.Scanning -> Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(AppSpacing.medium),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
CircularProgressIndicator(modifier = Modifier.size(24.dp))
|
||||
Text(pluralStringResource(R.plurals.import_scanning, active.found, active.found))
|
||||
}
|
||||
TextButton(onClick = onCancel, modifier = Modifier.align(Alignment.End)) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
|
||||
is ImportProgress.Saving -> Column(verticalArrangement = Arrangement.spacedBy(AppSpacing.medium)) {
|
||||
Text(stringResource(R.string.import_saving, active.saved, active.total))
|
||||
val fraction by animateFloatAsState(
|
||||
targetValue = if (active.total > 0) active.saved.toFloat() / active.total else 0f,
|
||||
label = "importProgress"
|
||||
)
|
||||
LinearProgressIndicator(progress = { fraction }, modifier = Modifier.fillMaxWidth())
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = onCancel) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Title(@StringRes text: Int) {
|
||||
Text(
|
||||
text = stringResource(text),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.anthonyla.paperize.presentation.screens.folder_view
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.grid.GridItemSpan
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.Sort
|
||||
@@ -11,9 +13,11 @@ import androidx.compose.material.icons.filled.Refresh
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -21,6 +25,7 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
@@ -34,6 +39,10 @@ import com.anthonyla.paperize.presentation.common.components.SortOption
|
||||
import com.anthonyla.paperize.presentation.common.components.WallpaperGrid
|
||||
import com.anthonyla.paperize.presentation.common.components.WallpaperItem
|
||||
import com.anthonyla.paperize.presentation.common.components.wallpaperGridItem
|
||||
import com.anthonyla.paperize.presentation.common.theme.AppSpacing
|
||||
|
||||
private const val REMOVED_HEADER_KEY = "removed"
|
||||
private const val REMOVED_ALPHA = 0.5f
|
||||
|
||||
@Composable
|
||||
fun FolderViewScreen(
|
||||
@@ -52,9 +61,13 @@ fun FolderViewScreen(
|
||||
var showSortSheet by rememberSaveable { mutableStateOf(false) }
|
||||
var sortOption by rememberSaveable { mutableStateOf(SortOption.DATE_ADDED_DESC) }
|
||||
|
||||
val removedWallpapers = folder?.removedWallpapers.orEmpty()
|
||||
val sortedWallpapers = remember(wallpapers, sortOption) {
|
||||
wallpapers.sortedWith(sortOption.wallpaperComparator)
|
||||
}
|
||||
val sortedRemoved = remember(removedWallpapers, sortOption) {
|
||||
removedWallpapers.sortedWith(sortOption.wallpaperComparator)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = { SnackbarHost(snackbarHostState) },
|
||||
@@ -70,7 +83,7 @@ fun FolderViewScreen(
|
||||
}
|
||||
) { paddingValues ->
|
||||
Box(modifier = modifier.fillMaxSize().padding(paddingValues)) {
|
||||
if (folder != null && wallpapers.isEmpty()) {
|
||||
if (folder != null && wallpapers.isEmpty() && removedWallpapers.isEmpty()) {
|
||||
EmptyCollection(
|
||||
title = stringResource(R.string.folder_empty_title),
|
||||
hint = stringResource(R.string.folder_empty_hint)
|
||||
@@ -91,6 +104,29 @@ fun FolderViewScreen(
|
||||
modifier = Modifier.wallpaperGridItem(this)
|
||||
)
|
||||
}
|
||||
if (sortedRemoved.isNotEmpty()) {
|
||||
item(key = REMOVED_HEADER_KEY, span = { GridItemSpan(maxLineSpan) }) {
|
||||
Column(modifier = Modifier.padding(top = AppSpacing.large)) {
|
||||
Text(stringResource(R.string.removed_wallpapers), style = MaterialTheme.typography.titleSmall)
|
||||
Text(
|
||||
stringResource(R.string.removed_wallpapers_hint),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
}
|
||||
items(items = sortedRemoved, key = { wallpaper -> wallpaper.id }) { wallpaper ->
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper.uri,
|
||||
wallpaperName = wallpaper.displayFileName,
|
||||
isSelected = false,
|
||||
isSelectionMode = false,
|
||||
onClick = { viewModel.restore(wallpaper) },
|
||||
onLongClick = null,
|
||||
modifier = Modifier.wallpaperGridItem(this).alpha(REMOVED_ALPHA)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isRefreshing) LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.navigation.toRoute
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.runCatchingCancellable
|
||||
import com.anthonyla.paperize.domain.model.Folder
|
||||
import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.domain.repository.AlbumRepository
|
||||
import com.anthonyla.paperize.domain.usecase.RefreshFolderUseCase
|
||||
import com.anthonyla.paperize.presentation.common.launchBusy
|
||||
@@ -17,11 +18,12 @@ import javax.inject.Inject
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@HiltViewModel
|
||||
class FolderViewViewModel @Inject constructor(
|
||||
savedStateHandle: SavedStateHandle,
|
||||
albumRepository: AlbumRepository,
|
||||
private val albumRepository: AlbumRepository,
|
||||
private val refreshFolderUseCase: RefreshFolderUseCase
|
||||
) : ViewModel() {
|
||||
|
||||
@@ -48,4 +50,11 @@ class FolderViewViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun restore(wallpaper: Wallpaper) {
|
||||
viewModelScope.launch {
|
||||
runCatchingCancellable { albumRepository.restoreWallpaper(wallpaper) }
|
||||
.onFailure { _message.value = R.string.restore_wallpaper_failed }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,12 +28,18 @@ import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.PrimaryTabRow
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.SnackbarResult
|
||||
import androidx.compose.material3.Tab
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
@@ -43,6 +49,7 @@ import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.presentation.common.components.SnackbarMessageEffect
|
||||
import com.anthonyla.paperize.presentation.screens.library.LibraryScreen
|
||||
import com.anthonyla.paperize.presentation.screens.wallpaper.WallpaperScreen
|
||||
import com.anthonyla.paperize.service.livewallpaper.PaperizeLiveWallpaperService
|
||||
@@ -72,14 +79,27 @@ fun HomeScreen(
|
||||
val animate by viewModel.animate.collectAsStateWithLifecycle()
|
||||
val wallpaperMode by viewModel.wallpaperMode.collectAsStateWithLifecycle()
|
||||
val showLiveWallpaperPrompt by viewModel.showLiveWallpaperPrompt.collectAsStateWithLifecycle()
|
||||
val currentHomeWallpaperUri by viewModel.currentHomeWallpaperUri.collectAsStateWithLifecycle()
|
||||
val currentLockWallpaperUri by viewModel.currentLockWallpaperUri.collectAsStateWithLifecycle()
|
||||
val currentHomeWallpaper by viewModel.currentHomeWallpaper.collectAsStateWithLifecycle()
|
||||
val currentLockWallpaper by viewModel.currentLockWallpaper.collectAsStateWithLifecycle()
|
||||
val removedWallpaper by viewModel.removedWallpaper.collectAsStateWithLifecycle()
|
||||
val message by viewModel.message.collectAsStateWithLifecycle()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
SnackbarMessageEffect(message, snackbarHostState, viewModel::dismissMessage)
|
||||
val removedText = stringResource(R.string.wallpaper_removed)
|
||||
val undoText = stringResource(R.string.undo)
|
||||
LaunchedEffect(removedWallpaper) {
|
||||
val wallpaper = removedWallpaper ?: return@LaunchedEffect
|
||||
val result = snackbarHostState.showSnackbar(removedText, undoText, duration = SnackbarDuration.Long)
|
||||
if (result == SnackbarResult.ActionPerformed) viewModel.restoreWallpaper(wallpaper)
|
||||
else viewModel.dismissRemovedWallpaper()
|
||||
}
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val context = LocalContext.current
|
||||
|
||||
val pagerState = rememberPagerState { homeTabs.size }
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = { SnackbarHost(snackbarHostState) },
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(stringResource(R.string.app_name)) },
|
||||
@@ -138,8 +158,9 @@ fun HomeScreen(
|
||||
onUpdateScheduleSettings = viewModel::updateScheduleSettings,
|
||||
onUpdateScheduleSettingsDebounced = viewModel::updateScheduleSettingsDebounced,
|
||||
onChangeWallpaperNow = viewModel::changeWallpaperNow,
|
||||
homeWallpaperUri = currentHomeWallpaperUri,
|
||||
lockWallpaperUri = currentLockWallpaperUri
|
||||
homeWallpaper = currentHomeWallpaper,
|
||||
lockWallpaper = currentLockWallpaper,
|
||||
onRemoveWallpaper = viewModel::removeCurrentWallpaper
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.anthonyla.paperize.core.constants.Constants
|
||||
import com.anthonyla.paperize.core.runCatchingCancellable
|
||||
import com.anthonyla.paperize.domain.model.AlbumSummary
|
||||
import com.anthonyla.paperize.domain.model.ScheduleSettings
|
||||
import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.domain.repository.AlbumRepository
|
||||
import com.anthonyla.paperize.domain.repository.SettingsRepository
|
||||
import com.anthonyla.paperize.domain.repository.WallpaperRepository
|
||||
@@ -29,11 +30,12 @@ import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.scan
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@HiltViewModel
|
||||
class HomeViewModel @Inject constructor(
|
||||
albumRepository: AlbumRepository,
|
||||
private val albumRepository: AlbumRepository,
|
||||
settingsRepository: SettingsRepository,
|
||||
private val wallpaperRepository: WallpaperRepository,
|
||||
private val createAlbumUseCase: CreateAlbumUseCase,
|
||||
@@ -53,13 +55,20 @@ class HomeViewModel @Inject constructor(
|
||||
settingsRepository.getWallpaperModeFlow().stateWhileSubscribed(viewModelScope, null)
|
||||
|
||||
/**
|
||||
* URI of the wallpaper Paperize last applied for the home / lock screen, for the in-app preview.
|
||||
* Wallpaper Paperize last applied for the home / lock screen, for the in-app preview.
|
||||
* Reading the source URI (rather than WallpaperManager.getDrawable) avoids the storage permission
|
||||
* the preview would otherwise need. Falls back to the BOTH-mode record when home/lock are synced.
|
||||
*/
|
||||
val currentHomeWallpaperUri: StateFlow<String?> = currentWallpaperUri(ScreenType.HOME) { it.homeAlbumId }
|
||||
val currentHomeWallpaper: StateFlow<Wallpaper?> = currentWallpaper(ScreenType.HOME) { it.homeAlbumId }
|
||||
|
||||
val currentLockWallpaperUri: StateFlow<String?> = currentWallpaperUri(ScreenType.LOCK) { it.lockAlbumId }
|
||||
val currentLockWallpaper: StateFlow<Wallpaper?> = currentWallpaper(ScreenType.LOCK) { it.lockAlbumId }
|
||||
|
||||
private val _removedWallpaper = MutableStateFlow<Wallpaper?>(null)
|
||||
/** The last wallpaper removed from the preview, while its undo is offered. */
|
||||
val removedWallpaper: StateFlow<Wallpaper?> = _removedWallpaper.asStateFlow()
|
||||
|
||||
private val _message = MutableStateFlow<Int?>(null)
|
||||
val message: StateFlow<Int?> = _message.asStateFlow()
|
||||
|
||||
private val _showLiveWallpaperPrompt = MutableStateFlow(false)
|
||||
val showLiveWallpaperPrompt: StateFlow<Boolean> = _showLiveWallpaperPrompt.asStateFlow()
|
||||
@@ -76,7 +85,7 @@ class HomeViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
/** Creates the album and returns null, or returns the string resource of the error to show. */
|
||||
suspend fun createAlbum(name: String): Int? = runCatchingCancellable { createAlbumUseCase(name) }.fold(
|
||||
suspend fun createAlbum(name: String, isEncrypted: Boolean = false): Int? = runCatchingCancellable { createAlbumUseCase(name, isEncrypted) }.fold(
|
||||
onSuccess = { created -> if (created) null else R.string.album_name_exists_error },
|
||||
onFailure = { R.string.album_create_failed }
|
||||
)
|
||||
@@ -108,16 +117,47 @@ class HomeViewModel @Inject constructor(
|
||||
|
||||
fun changeWallpaperNow() = coordinator.changeWallpaperNow()
|
||||
|
||||
/** Removes [wallpaper] from its album and replaces it on every screen that shows it. */
|
||||
fun removeCurrentWallpaper(wallpaper: Wallpaper) {
|
||||
val home = currentHomeWallpaper.value?.id == wallpaper.id
|
||||
val lock = currentLockWallpaper.value?.id == wallpaper.id
|
||||
viewModelScope.launch {
|
||||
runCatchingCancellable { albumRepository.removeWallpaper(wallpaper.id) }
|
||||
.onSuccess { removed ->
|
||||
if (removed == null) return@onSuccess
|
||||
_removedWallpaper.value = removed
|
||||
coordinator.changeWallpaperNow(
|
||||
if (home && lock) ScreenType.BOTH else if (lock) ScreenType.LOCK else ScreenType.HOME
|
||||
)
|
||||
}
|
||||
.onFailure { _message.value = R.string.remove_wallpaper_failed }
|
||||
}
|
||||
}
|
||||
|
||||
fun restoreWallpaper(wallpaper: Wallpaper) {
|
||||
_removedWallpaper.value = null
|
||||
viewModelScope.launch {
|
||||
runCatchingCancellable { albumRepository.restoreWallpaper(wallpaper) }
|
||||
.onFailure { _message.value = R.string.restore_wallpaper_failed }
|
||||
}
|
||||
}
|
||||
|
||||
fun dismissRemovedWallpaper() { _removedWallpaper.value = null }
|
||||
|
||||
fun dismissMessage() { _message.value = null }
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
private fun currentWallpaperUri(screen: ScreenType, albumId: (ScheduleSettings) -> String?): StateFlow<String?> =
|
||||
private fun currentWallpaper(screen: ScreenType, albumId: (ScheduleSettings) -> String?): StateFlow<Wallpaper?> =
|
||||
scheduleSettings
|
||||
.map(albumId)
|
||||
.distinctUntilChanged()
|
||||
.flatMapLatest { id -> if (id == null) flowOf(null) else currentWallpaperUriFlow(id, screen) }
|
||||
.flatMapLatest { id -> if (id == null) flowOf(null) else currentWallpaperFlow(id, screen) }
|
||||
.stateWhileSubscribed(viewModelScope, null)
|
||||
|
||||
private fun currentWallpaperUriFlow(albumId: String, screen: ScreenType): Flow<String?> = combine(
|
||||
private fun currentWallpaperFlow(albumId: String, screen: ScreenType): Flow<Wallpaper?> = combine(
|
||||
wallpaperRepository.getCurrentWallpaperFlow(albumId, screen),
|
||||
wallpaperRepository.getCurrentWallpaperFlow(albumId, ScreenType.BOTH)
|
||||
) { specific, both -> (specific ?: both)?.uri }
|
||||
) { specific, both -> specific ?: both }
|
||||
// Removing the shown image drops its record until the replacement is applied.
|
||||
.scan(null as Wallpaper?) { last, current -> current ?: last }
|
||||
}
|
||||
@@ -4,15 +4,13 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LargeFloatingActionButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.FloatingActionButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -28,7 +26,6 @@ import com.anthonyla.paperize.domain.model.AlbumSummary
|
||||
import com.anthonyla.paperize.presentation.common.components.AddAlbumDialog
|
||||
import com.anthonyla.paperize.presentation.common.components.EmptyCollection
|
||||
import com.anthonyla.paperize.presentation.common.theme.AppGrid
|
||||
import com.anthonyla.paperize.presentation.common.theme.AppIconSizes
|
||||
import com.anthonyla.paperize.presentation.common.theme.AppSpacing
|
||||
import com.anthonyla.paperize.presentation.screens.library.components.AlbumItem
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -38,7 +35,7 @@ import kotlinx.coroutines.launch
|
||||
fun LibraryScreen(
|
||||
albums: List<AlbumSummary>,
|
||||
onViewAlbum: (String) -> Unit,
|
||||
onCreateAlbum: suspend (String) -> Int?,
|
||||
onCreateAlbum: suspend (String, Boolean) -> Int?,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var showAddAlbumDialog by rememberSaveable { mutableStateOf(false) }
|
||||
@@ -49,17 +46,8 @@ fun LibraryScreen(
|
||||
Scaffold(
|
||||
modifier = modifier.fillMaxSize(),
|
||||
floatingActionButton = {
|
||||
LargeFloatingActionButton(
|
||||
containerColor = MaterialTheme.colorScheme.primary,
|
||||
contentColor = MaterialTheme.colorScheme.onPrimary,
|
||||
onClick = { showAddAlbumDialog = true },
|
||||
shape = MaterialTheme.shapes.large
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.Add,
|
||||
contentDescription = stringResource(R.string.add_album),
|
||||
modifier = Modifier.size(AppIconSizes.medium)
|
||||
)
|
||||
FloatingActionButton(onClick = { showAddAlbumDialog = true }) {
|
||||
Icon(Icons.Filled.Add, contentDescription = stringResource(R.string.add_album))
|
||||
}
|
||||
}
|
||||
) { paddingValues ->
|
||||
@@ -95,12 +83,12 @@ fun LibraryScreen(
|
||||
showAddAlbumDialog = false
|
||||
albumNameError = null
|
||||
},
|
||||
onConfirm = { name ->
|
||||
onConfirm = { name, isEncrypted ->
|
||||
isSaving = true
|
||||
albumNameError = null
|
||||
scope.launch {
|
||||
try {
|
||||
albumNameError = onCreateAlbum(name)
|
||||
albumNameError = onCreateAlbum(name, isEncrypted)
|
||||
if (albumNameError == null) showAddAlbumDialog = false
|
||||
} finally {
|
||||
isSaving = false
|
||||
|
||||
@@ -4,6 +4,9 @@ import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.text.input.clearText
|
||||
import androidx.compose.foundation.text.input.rememberTextFieldState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.BatteryAlert
|
||||
@@ -14,6 +17,7 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||
import androidx.lifecycle.Lifecycle
|
||||
@@ -41,9 +45,12 @@ fun SettingsScreen(
|
||||
val appSettings by viewModel.appSettings.collectAsStateWithLifecycle()
|
||||
val isResetting by viewModel.isResetting.collectAsStateWithLifecycle()
|
||||
val resetFailed by viewModel.resetFailed.collectAsStateWithLifecycle()
|
||||
val passphraseFailed by viewModel.passphraseFailed.collectAsStateWithLifecycle()
|
||||
val wallpaperMode by viewModel.wallpaperMode.collectAsStateWithLifecycle()
|
||||
var showResetDialog by remember { mutableStateOf(false) }
|
||||
var pendingMode by remember { mutableStateOf<WallpaperMode?>(null) }
|
||||
var showPassphraseDialog by remember { mutableStateOf(false) }
|
||||
val passphraseState = rememberTextFieldState()
|
||||
val context = LocalContext.current
|
||||
|
||||
var isIgnoringBatteryOptimizations by remember {
|
||||
@@ -122,6 +129,21 @@ fun SettingsScreen(
|
||||
)
|
||||
}
|
||||
|
||||
SettingsGroup(title = stringResource(R.string.encrypted_albums)) {
|
||||
SettingsRow(onClick = { showPassphraseDialog = true }) {
|
||||
SettingText(
|
||||
title = stringResource(R.string.encrypted_passphrase),
|
||||
description = stringResource(R.string.encrypted_passphrase_description)
|
||||
)
|
||||
}
|
||||
SettingSwitchItem(
|
||||
title = stringResource(R.string.encrypted_previews),
|
||||
description = stringResource(R.string.encrypted_previews_description),
|
||||
checked = appSettings?.encryptedPreviews ?: false,
|
||||
onCheckedChange = viewModel::updateEncryptedPreviews
|
||||
)
|
||||
}
|
||||
|
||||
SettingsGroup(title = stringResource(R.string.reliability)) {
|
||||
SettingsRow(verticalArrangement = Arrangement.spacedBy(AppSpacing.small)) {
|
||||
Row(
|
||||
@@ -224,6 +246,46 @@ fun SettingsScreen(
|
||||
confirmColor = MaterialTheme.colorScheme.error
|
||||
)
|
||||
}
|
||||
|
||||
if (showPassphraseDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = {
|
||||
showPassphraseDialog = false
|
||||
passphraseState.clearText()
|
||||
viewModel.dismissPassphraseError()
|
||||
},
|
||||
title = { Text(stringResource(R.string.encrypted_passphrase)) },
|
||||
text = {
|
||||
OutlinedSecureTextField(
|
||||
state = passphraseState,
|
||||
label = { Text(stringResource(R.string.encrypted_passphrase)) },
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
|
||||
isError = passphraseFailed,
|
||||
supportingText = if (passphraseFailed) {
|
||||
{ Text(stringResource(R.string.encrypted_passphrase_save_failed)) }
|
||||
} else null
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
enabled = passphraseState.text.isNotEmpty(),
|
||||
onClick = {
|
||||
viewModel.setPassphrase(passphraseState.text.toString()) {
|
||||
passphraseState.clearText()
|
||||
showPassphraseDialog = false
|
||||
}
|
||||
}
|
||||
) { Text(stringResource(R.string.save)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = {
|
||||
showPassphraseDialog = false
|
||||
passphraseState.clearText()
|
||||
viewModel.dismissPassphraseError()
|
||||
}) { Text(stringResource(R.string.cancel)) }
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.core.WallpaperMode
|
||||
import com.anthonyla.paperize.core.runCatchingCancellable
|
||||
import com.anthonyla.paperize.data.source.EncryptedImageStore
|
||||
import com.anthonyla.paperize.domain.model.AppSettings
|
||||
import com.anthonyla.paperize.domain.repository.SettingsRepository
|
||||
import com.anthonyla.paperize.presentation.common.launchBusy
|
||||
@@ -22,7 +23,8 @@ import kotlinx.coroutines.launch
|
||||
@HiltViewModel
|
||||
class SettingsViewModel @Inject constructor(
|
||||
private val settingsRepository: SettingsRepository,
|
||||
private val coordinator: SettingsCoordinator
|
||||
private val coordinator: SettingsCoordinator,
|
||||
private val encryptedImages: EncryptedImageStore
|
||||
) : ViewModel() {
|
||||
|
||||
// Eager so the first frame already knows whether to show onboarding.
|
||||
@@ -36,6 +38,8 @@ class SettingsViewModel @Inject constructor(
|
||||
val isResetting = _isResetting.asStateFlow()
|
||||
private val _resetFailed = MutableStateFlow(false)
|
||||
val resetFailed = _resetFailed.asStateFlow()
|
||||
private val _passphraseFailed = MutableStateFlow(false)
|
||||
val passphraseFailed = _passphraseFailed.asStateFlow()
|
||||
|
||||
fun updateDarkMode(enabled: Boolean) {
|
||||
viewModelScope.launch { settingsRepository.updateDarkMode(enabled) }
|
||||
@@ -49,6 +53,27 @@ class SettingsViewModel @Inject constructor(
|
||||
viewModelScope.launch { settingsRepository.updateAnimate(enabled) }
|
||||
}
|
||||
|
||||
fun updateEncryptedPreviews(enabled: Boolean) {
|
||||
viewModelScope.launch { settingsRepository.updateEncryptedPreviews(enabled) }
|
||||
}
|
||||
|
||||
fun setPassphrase(passphrase: String, onSuccess: () -> Unit) {
|
||||
viewModelScope.launch {
|
||||
runCatchingCancellable {
|
||||
encryptedImages.setPassphrase(passphrase)
|
||||
_passphraseFailed.value = false
|
||||
onSuccess()
|
||||
}.onFailure {
|
||||
Log.e(TAG, "Could not save encryption passphrase", it)
|
||||
_passphraseFailed.value = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun dismissPassphraseError() {
|
||||
_passphraseFailed.value = false
|
||||
}
|
||||
|
||||
fun completeFirstLaunch() {
|
||||
viewModelScope.launch { settingsRepository.completeFirstLaunch() }
|
||||
}
|
||||
@@ -63,6 +88,7 @@ class SettingsViewModel @Inject constructor(
|
||||
launchBusy(_isResetting) {
|
||||
runCatchingCancellable {
|
||||
coordinator.resetData(mode)
|
||||
if (mode == null) encryptedImages.clearPassphrase()
|
||||
onSuccess()
|
||||
}.onFailure { e ->
|
||||
Log.e(TAG, "Could not reset app data", e)
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.anthonyla.paperize.presentation.screens.wallpaper
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
@@ -15,6 +16,7 @@ import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
||||
import androidx.compose.material.icons.filled.Home
|
||||
import androidx.compose.material.icons.filled.Lock
|
||||
import androidx.compose.material.icons.filled.PhotoAlbum
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Icon
|
||||
@@ -46,6 +48,7 @@ import com.anthonyla.paperize.core.WallpaperMode
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
import com.anthonyla.paperize.domain.model.AlbumSummary
|
||||
import com.anthonyla.paperize.domain.model.ScheduleSettings
|
||||
import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.domain.model.WallpaperEffects
|
||||
import com.anthonyla.paperize.presentation.common.components.AlbumCover
|
||||
import com.anthonyla.paperize.presentation.common.components.SettingSwitchItem
|
||||
@@ -70,8 +73,9 @@ fun WallpaperScreen(
|
||||
onUpdateScheduleSettings: (ScheduleSettings) -> Unit,
|
||||
onUpdateScheduleSettingsDebounced: (ScheduleSettings) -> Unit,
|
||||
onChangeWallpaperNow: () -> Unit,
|
||||
homeWallpaperUri: String?,
|
||||
lockWallpaperUri: String?,
|
||||
homeWallpaper: Wallpaper?,
|
||||
lockWallpaper: Wallpaper?,
|
||||
onRemoveWallpaper: (Wallpaper) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var albumPickerScreen by rememberSaveable { mutableStateOf<ScreenType?>(null) }
|
||||
@@ -139,9 +143,10 @@ fun WallpaperScreen(
|
||||
) {
|
||||
if (wallpaperMode == WallpaperMode.STATIC) {
|
||||
CurrentWallpaperPreview(
|
||||
homeWallpaperUri = homeWallpaperUri,
|
||||
lockWallpaperUri = lockWallpaperUri,
|
||||
animate = animate
|
||||
homeWallpaper = homeWallpaper,
|
||||
lockWallpaper = lockWallpaper,
|
||||
animate = animate,
|
||||
onRemove = onRemoveWallpaper
|
||||
)
|
||||
MultiChoiceSegmentedButtonRow(modifier = Modifier.fillMaxWidth()) {
|
||||
ScreenToggle(
|
||||
@@ -286,6 +291,16 @@ fun WallpaperScreen(
|
||||
}
|
||||
}
|
||||
}
|
||||
if (selectedScaling == ScalingType.FIT) {
|
||||
SettingSwitchItem(
|
||||
title = stringResource(R.string.blur_fit_background),
|
||||
description = stringResource(R.string.blur_fit_background_description),
|
||||
checked = scheduleSettings.blurFitBackground,
|
||||
onCheckedChange = { enabled ->
|
||||
updateSettingsImmediate(scheduleSettings.copy(blurFitBackground = enabled))
|
||||
}
|
||||
)
|
||||
}
|
||||
if (wallpaperMode == WallpaperMode.STATIC) {
|
||||
SettingSwitchItem(
|
||||
title = stringResource(R.string.horizontal_wallpaper_scrolling),
|
||||
@@ -403,20 +418,8 @@ fun WallpaperScreen(
|
||||
if (showEmptyAlbumWarning) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showEmptyAlbumWarning = false },
|
||||
title = {
|
||||
Text(
|
||||
text = stringResource(R.string.empty_album),
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
text = stringResource(R.string.empty_album_message),
|
||||
maxLines = Constants.DIALOG_MESSAGE_MAX_LINES,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
},
|
||||
title = { Text(stringResource(R.string.empty_album)) },
|
||||
text = { Text(stringResource(R.string.empty_album_message)) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = { showEmptyAlbumWarning = false }) {
|
||||
Text(
|
||||
@@ -461,16 +464,21 @@ private fun AlbumSelector(albumId: String?, albums: List<AlbumSummary>, label: S
|
||||
horizontalArrangement = Arrangement.spacedBy(AppSpacing.medium),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
val coverModifier = Modifier
|
||||
.size(AppIconSizes.large)
|
||||
.clip(MaterialTheme.shapes.small)
|
||||
.background(MaterialTheme.colorScheme.surfaceContainerHighest)
|
||||
if (album != null) {
|
||||
AlbumCover(
|
||||
album = album,
|
||||
thumbnailSize = Constants.LIST_THUMBNAIL_SIZE,
|
||||
placeholderTint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier
|
||||
.size(AppIconSizes.large)
|
||||
.clip(MaterialTheme.shapes.small)
|
||||
.background(MaterialTheme.colorScheme.surfaceContainerHighest)
|
||||
modifier = coverModifier
|
||||
)
|
||||
} else {
|
||||
Box(coverModifier, contentAlignment = Alignment.Center) {
|
||||
Icon(Icons.Filled.PhotoAlbum, contentDescription = null, tint = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
SettingText(
|
||||
title = album?.name ?: stringResource(if (albumId == null) R.string.no_album_selected else R.string.loading_placeholder),
|
||||
|
||||
@@ -87,9 +87,7 @@ fun AlbumSelectionBottomSheet(
|
||||
.padding(AppSpacing.extraLarge)
|
||||
.align(Alignment.CenterHorizontally),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
Spacer(modifier = Modifier.height(AppSpacing.extraLarge))
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
@@ -20,17 +24,14 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalWindowInfo
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import coil3.compose.AsyncImage
|
||||
import coil3.request.ImageRequest
|
||||
import coil3.request.crossfade
|
||||
import coil3.size.Size
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.presentation.common.components.encryptedAwareImageRequest
|
||||
import com.anthonyla.paperize.presentation.common.theme.AppSpacing
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
@@ -43,11 +44,12 @@ private val PreviewHeight = 240.dp
|
||||
*/
|
||||
@Composable
|
||||
fun CurrentWallpaperPreview(
|
||||
homeWallpaperUri: String?,
|
||||
lockWallpaperUri: String?,
|
||||
animate: Boolean
|
||||
homeWallpaper: Wallpaper?,
|
||||
lockWallpaper: Wallpaper?,
|
||||
animate: Boolean,
|
||||
onRemove: (Wallpaper) -> Unit
|
||||
) {
|
||||
if (homeWallpaperUri == null && lockWallpaperUri == null) return
|
||||
if (homeWallpaper == null && lockWallpaper == null) return
|
||||
val windowSize = LocalWindowInfo.current.containerSize
|
||||
|
||||
// Portrait-oriented preview: shorter screen dimension as width.
|
||||
@@ -63,9 +65,7 @@ fun CurrentWallpaperPreview(
|
||||
Column(modifier = Modifier.padding(AppSpacing.large)) {
|
||||
Text(
|
||||
text = stringResource(R.string.current_wallpapers),
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
@@ -73,21 +73,25 @@ fun CurrentWallpaperPreview(
|
||||
.padding(top = AppSpacing.medium),
|
||||
horizontalArrangement = Arrangement.spacedBy(AppSpacing.large, Alignment.CenterHorizontally)
|
||||
) {
|
||||
if (lockWallpaperUri != null) {
|
||||
if (lockWallpaper != null) {
|
||||
WallpaperPreviewBox(
|
||||
wallpaperUri = lockWallpaperUri,
|
||||
wallpaperUri = lockWallpaper.uri,
|
||||
aspectRatio = screenAspectRatio,
|
||||
label = stringResource(R.string.lock),
|
||||
contentDescription = stringResource(R.string.content_desc_current_lock_wallpaper),
|
||||
removeDescription = stringResource(R.string.content_desc_remove_lock_wallpaper),
|
||||
onRemove = { onRemove(lockWallpaper) },
|
||||
animate = animate
|
||||
)
|
||||
}
|
||||
if (homeWallpaperUri != null) {
|
||||
if (homeWallpaper != null) {
|
||||
WallpaperPreviewBox(
|
||||
wallpaperUri = homeWallpaperUri,
|
||||
wallpaperUri = homeWallpaper.uri,
|
||||
aspectRatio = screenAspectRatio,
|
||||
label = stringResource(R.string.home),
|
||||
contentDescription = stringResource(R.string.content_desc_current_home_wallpaper),
|
||||
removeDescription = stringResource(R.string.content_desc_remove_home_wallpaper),
|
||||
onRemove = { onRemove(homeWallpaper) },
|
||||
animate = animate
|
||||
)
|
||||
}
|
||||
@@ -102,10 +106,10 @@ private fun WallpaperPreviewBox(
|
||||
aspectRatio: Float,
|
||||
label: String,
|
||||
contentDescription: String,
|
||||
removeDescription: String,
|
||||
onRemove: () -> Unit,
|
||||
animate: Boolean
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(AppSpacing.small)
|
||||
@@ -120,16 +124,19 @@ private fun WallpaperPreviewBox(
|
||||
.background(MaterialTheme.colorScheme.surfaceContainerHighest)
|
||||
) {
|
||||
AsyncImage(
|
||||
model = ImageRequest.Builder(context)
|
||||
.data(wallpaperUri)
|
||||
.size(Size(Constants.PREVIEW_THUMBNAIL_WIDTH, Constants.PREVIEW_THUMBNAIL_HEIGHT))
|
||||
.crossfade(animate)
|
||||
.build(),
|
||||
model = encryptedAwareImageRequest(
|
||||
wallpaperUri, Constants.PREVIEW_THUMBNAIL_WIDTH, Constants.PREVIEW_THUMBNAIL_HEIGHT, animate
|
||||
),
|
||||
contentDescription = contentDescription,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.matchParentSize()
|
||||
)
|
||||
}
|
||||
Text(text = label, style = MaterialTheme.typography.labelLarge)
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(text = label, style = MaterialTheme.typography.labelLarge)
|
||||
IconButton(onClick = onRemove) {
|
||||
Icon(Icons.Default.Delete, contentDescription = removeDescription)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
import com.anthonyla.paperize.presentation.common.components.SettingSwitchRow
|
||||
@@ -147,9 +146,7 @@ private fun PercentageSlider(
|
||||
text = stringResource(label),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.weight(1f),
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
Percentage(value)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.ReadOnlyComposable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
@@ -21,7 +22,6 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
import com.anthonyla.paperize.presentation.common.components.SettingsRow
|
||||
@@ -59,9 +59,7 @@ fun TimeIntervalPicker(
|
||||
SettingsRow(verticalArrangement = Arrangement.spacedBy(AppSpacing.small)) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
|
||||
Row(
|
||||
@@ -86,9 +84,7 @@ fun TimeIntervalPicker(
|
||||
Text(
|
||||
text = stringResource(R.string.total_interval, formatIntervalComposable(minutes)),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
if (note != null) {
|
||||
Text(
|
||||
@@ -101,6 +97,7 @@ fun TimeIntervalPicker(
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun formatIntervalComposable(minutes: Int): String {
|
||||
val (d, h, m) = splitInterval(minutes)
|
||||
return listOfNotNull(
|
||||
|
||||
@@ -38,13 +38,13 @@ import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import coil3.compose.AsyncImage
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScreenType
|
||||
import com.anthonyla.paperize.core.WallpaperMode
|
||||
import com.anthonyla.paperize.presentation.common.components.encryptedAwareImageRequest
|
||||
import com.anthonyla.paperize.presentation.common.theme.AppSpacing
|
||||
import net.engawapg.lib.zoomable.rememberZoomState
|
||||
import net.engawapg.lib.zoomable.zoomable
|
||||
@@ -135,7 +135,7 @@ fun WallpaperViewScreen(
|
||||
.zoomable(zoomState)
|
||||
) {
|
||||
AsyncImage(
|
||||
model = viewModel.wallpaperUri.toUri(),
|
||||
model = encryptedAwareImageRequest(viewModel.wallpaperUri),
|
||||
contentDescription = viewModel.wallpaperName,
|
||||
contentScale = ContentScale.Fit,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
|
||||
@@ -85,8 +85,8 @@ class SettingsCoordinator @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
/** Change every screen the current settings rotate, or reload the live wallpaper. */
|
||||
fun changeWallpaperNow() = WallpaperChangeService.changeWallpaper(context)
|
||||
/** Change [screen], or without one every screen the current settings rotate or the live wallpaper. */
|
||||
fun changeWallpaperNow(screen: ScreenType? = null) = WallpaperChangeService.changeWallpaper(context, screen)
|
||||
|
||||
/** Stop rotation if the user replaced Paperize's live wallpaper outside the app. */
|
||||
suspend fun disableIfLiveWallpaperReplaced() = mutex.withLock {
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.BitmapFactory
|
||||
import android.os.Build
|
||||
import android.os.PowerManager
|
||||
import android.util.Log
|
||||
@@ -27,10 +28,12 @@ import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.domain.model.usesVisibleLiveTimer
|
||||
import com.anthonyla.paperize.domain.repository.SettingsRepository
|
||||
import com.anthonyla.paperize.domain.usecase.ChangeWallpaperUseCase
|
||||
import com.anthonyla.paperize.data.source.EncryptedImageStore
|
||||
import com.anthonyla.paperize.service.LiveWallpaperReload
|
||||
import com.anthonyla.paperize.service.livewallpaper.gl.GLWallpaperService
|
||||
import com.anthonyla.paperize.service.livewallpaper.renderer.ContentUriImageLoader
|
||||
import com.anthonyla.paperize.service.livewallpaper.renderer.EmptyImageLoader
|
||||
import com.anthonyla.paperize.service.livewallpaper.renderer.EncryptedImageLoader
|
||||
import com.anthonyla.paperize.service.livewallpaper.renderer.ImageLoader
|
||||
import com.anthonyla.paperize.service.livewallpaper.renderer.PaperizeRenderController
|
||||
import com.anthonyla.paperize.service.livewallpaper.renderer.PaperizeWallpaperRenderer
|
||||
@@ -58,6 +61,7 @@ class PaperizeLiveWallpaperService : GLWallpaperService() {
|
||||
@Inject lateinit var settingsRepository: SettingsRepository
|
||||
@Inject lateinit var changeWallpaperUseCase: ChangeWallpaperUseCase
|
||||
@Inject lateinit var liveWallpaperReload: LiveWallpaperReload
|
||||
@Inject lateinit var encryptedImages: EncryptedImageStore
|
||||
|
||||
companion object {
|
||||
private const val TAG = "PaperizeLiveWallpaper"
|
||||
@@ -171,9 +175,9 @@ class PaperizeLiveWallpaperService : GLWallpaperService() {
|
||||
val loader = withContext(Dispatchers.IO) {
|
||||
changeWallpaperUseCase.dequeueReadable(albumId, ScreenType.LIVE, settings.shuffleEnabled) { candidate ->
|
||||
val uri = candidate.uri.toUri()
|
||||
if (uri.isReadable(contentResolver)) {
|
||||
if (uri.isReadable(contentResolver) && isValidEncryptedImage(candidate)) {
|
||||
currentWallpaper = candidate
|
||||
ContentUriImageLoader(contentResolver, uri, settings.liveScalingType)
|
||||
imageLoader(candidate, settings.liveScalingType)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
@@ -220,6 +224,7 @@ class PaperizeLiveWallpaperService : GLWallpaperService() {
|
||||
renderer.updateEffects(effects)
|
||||
renderer.updateScalingType(scalingType)
|
||||
renderer.updateAdaptiveBrightness(settings.adaptiveBrightness)
|
||||
renderer.updateBlurFitBackground(settings.blurFitBackground)
|
||||
|
||||
val scalingChanged =
|
||||
observedScalingType != null && observedScalingType != scalingType
|
||||
@@ -229,11 +234,7 @@ class PaperizeLiveWallpaperService : GLWallpaperService() {
|
||||
currentWallpaper?.let { wallpaper ->
|
||||
Log.d(TAG, "Live scaling changed; reloading current wallpaper without advancing")
|
||||
renderer.queueWallpaper(
|
||||
ContentUriImageLoader(
|
||||
contentResolver,
|
||||
wallpaper.uri.toUri(),
|
||||
scalingType
|
||||
)
|
||||
imageLoader(wallpaper, scalingType)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -264,10 +265,35 @@ class PaperizeLiveWallpaperService : GLWallpaperService() {
|
||||
// configuration changes while the wallpaper was hidden.
|
||||
requestRender()
|
||||
}
|
||||
|
||||
restartLiveIntervalTimer()
|
||||
super.onVisibilityChanged(visible)
|
||||
}
|
||||
|
||||
private fun imageLoader(wallpaper: Wallpaper, scalingType: ScalingType): ImageLoader =
|
||||
if (wallpaper.fileName.endsWith(".jpg_enc", ignoreCase = true)) {
|
||||
EncryptedImageLoader(encryptedImages, wallpaper.uri.toUri(), scalingType)
|
||||
} else {
|
||||
ContentUriImageLoader(contentResolver, wallpaper.uri.toUri(), scalingType)
|
||||
}
|
||||
|
||||
private fun isValidEncryptedImage(wallpaper: Wallpaper): Boolean {
|
||||
if (!wallpaper.fileName.endsWith(".jpg_enc", ignoreCase = true)) return true
|
||||
return try {
|
||||
val bytes = encryptedImages.decrypt(wallpaper.uri.toUri())
|
||||
try {
|
||||
val options = BitmapFactory.Options().apply { inJustDecodeBounds = true }
|
||||
BitmapFactory.decodeByteArray(bytes, 0, bytes.size, options)
|
||||
options.outWidth > 0 && options.outHeight > 0
|
||||
} finally {
|
||||
bytes.fill(0)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Could not decrypt live wallpaper", e)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onOffsetsChanged(
|
||||
xOffset: Float,
|
||||
yOffset: Float,
|
||||
|
||||
@@ -7,6 +7,8 @@ import android.net.Uri
|
||||
import android.util.Log
|
||||
import com.anthonyla.paperize.core.ScalingType
|
||||
import com.anthonyla.paperize.core.util.calculateDecodeSize
|
||||
import com.anthonyla.paperize.data.source.EncryptedImageStore
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
sealed interface ImageLoader {
|
||||
/** Decode on a worker thread. The caller owns the returned bitmap. */
|
||||
@@ -40,3 +42,32 @@ class ContentUriImageLoader(
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
class EncryptedImageLoader(
|
||||
private val encryptedImages: EncryptedImageStore,
|
||||
private val uri: Uri,
|
||||
private val scalingType: ScalingType = ScalingType.FILL
|
||||
) : ImageLoader {
|
||||
override fun load(targetWidth: Int, targetHeight: Int): Bitmap? {
|
||||
return try {
|
||||
val bytes = encryptedImages.decrypt(uri)
|
||||
try {
|
||||
ImageDecoder.decodeBitmap(ImageDecoder.createSource(ByteBuffer.wrap(bytes))) { decoder, info, _ ->
|
||||
val (width, height) = calculateDecodeSize(
|
||||
info.size.width, info.size.height, targetWidth, targetHeight, scalingType
|
||||
)
|
||||
decoder.setTargetSize(width, height)
|
||||
decoder.allocator = ImageDecoder.ALLOCATOR_SOFTWARE
|
||||
}
|
||||
} finally {
|
||||
bytes.fill(0)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("EncryptedImageLoader", "Failed to decode encrypted wallpaper", e)
|
||||
null
|
||||
} catch (e: OutOfMemoryError) {
|
||||
Log.e("EncryptedImageLoader", "Out of memory decoding encrypted wallpaper", e)
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.anthonyla.paperize.service.livewallpaper.renderer
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
import com.anthonyla.paperize.core.util.BrightnessCalculator
|
||||
import com.anthonyla.paperize.core.util.createBlurredBackdrop
|
||||
import com.anthonyla.paperize.core.util.getAdaptiveBrightnessMultiplier
|
||||
import com.anthonyla.paperize.core.ScalingType
|
||||
|
||||
@@ -37,6 +38,19 @@ class PaperizeWallpaperRenderer(
|
||||
|
||||
companion object {
|
||||
private const val TAG = "PaperizeRenderer"
|
||||
|
||||
// Skia turns a RenderEffect blur radius into sigma = 0.57735 * radius + 0.5.
|
||||
private const val SKIA_SIGMA_PER_RADIUS = 0.57735f
|
||||
private const val SKIA_SIGMA_OFFSET = 0.5f
|
||||
// BLUR_FRAGMENT_SHADER's kernel has a sigma of 1.815 radius units.
|
||||
private const val SHADER_SIGMA_PER_RADIUS = 1.815f
|
||||
|
||||
/** The shader radius that blurs as much as the static path does at [percent]. */
|
||||
private fun liveBlurRadius(percent: Int): Float {
|
||||
if (percent == 0) return 0f
|
||||
val staticRadius = percent / 100f * Constants.MAX_BLUR_RADIUS
|
||||
return (SKIA_SIGMA_PER_RADIUS * staticRadius + SKIA_SIGMA_OFFSET) / SHADER_SIGMA_PER_RADIUS
|
||||
}
|
||||
}
|
||||
|
||||
interface Callbacks {
|
||||
@@ -77,9 +91,9 @@ class PaperizeWallpaperRenderer(
|
||||
private var blurFbo2 = 0
|
||||
private var blurTexture2 = 0
|
||||
|
||||
private var currentPicture: GLPicture? = null
|
||||
private var currentLayer: Layer? = null
|
||||
|
||||
private var nextPicture: GLPicture? = null
|
||||
private var nextLayer: Layer? = null
|
||||
private var crossfadeStartTimeNanos = 0L
|
||||
|
||||
@Volatile private var currentEffects = WallpaperEffects()
|
||||
@@ -90,6 +104,8 @@ class PaperizeWallpaperRenderer(
|
||||
|
||||
@Volatile private var adaptiveBrightnessEnabled = false
|
||||
|
||||
@Volatile private var blurFitBackground = false
|
||||
|
||||
// Retain the latest request, including images still decoding or waiting for upload,
|
||||
// so a fold/unfold cannot replace it with the previously displayed wallpaper.
|
||||
private var requestedImageLoader: ImageLoader? = null
|
||||
@@ -106,8 +122,8 @@ class PaperizeWallpaperRenderer(
|
||||
|
||||
// A recreated surface has a new EGL context; old handles no longer belong to it.
|
||||
surfaceSize.value = null
|
||||
currentPicture = null
|
||||
nextPicture = null
|
||||
currentLayer = null
|
||||
nextLayer = null
|
||||
blurFbo1 = 0
|
||||
blurFbo2 = 0
|
||||
blurTexture1 = 0
|
||||
@@ -141,7 +157,7 @@ class PaperizeWallpaperRenderer(
|
||||
|
||||
deleteBlurResources()
|
||||
|
||||
if (sizeChanged || currentPicture == null) {
|
||||
if (sizeChanged || currentLayer == null) {
|
||||
synchronized(this) {
|
||||
requestedImageLoader?.let { loader ->
|
||||
queueWallpaper(loader, skipCrossfade = true)
|
||||
@@ -157,18 +173,14 @@ class PaperizeWallpaperRenderer(
|
||||
return
|
||||
}
|
||||
|
||||
val current = currentPicture
|
||||
val next = nextPicture
|
||||
val current = currentLayer
|
||||
val next = nextLayer
|
||||
|
||||
if (current == null && next == null) {
|
||||
return
|
||||
}
|
||||
|
||||
val blurRadius = if (currentEffects.enableBlur) {
|
||||
(currentEffects.blurPercentage / 100.0f) * Constants.MAX_BLUR_RADIUS
|
||||
} else {
|
||||
0f
|
||||
}
|
||||
val blurRadius = if (currentEffects.enableBlur) liveBlurRadius(currentEffects.blurPercentage) else 0f
|
||||
|
||||
val crossfadeProgress = if (next != null) {
|
||||
val elapsedMs = (System.nanoTime() - crossfadeStartTimeNanos) / 1_000_000f
|
||||
@@ -179,17 +191,17 @@ class PaperizeWallpaperRenderer(
|
||||
|
||||
// The current layer stays opaque while the next fades over it; fading both
|
||||
// produces a visible brightness dip at the midpoint.
|
||||
current?.let { picture ->
|
||||
drawPictureWithEffects(picture, 1f, blurRadius)
|
||||
current?.let { layer ->
|
||||
drawPictureWithEffects(layer, 1f, blurRadius)
|
||||
}
|
||||
|
||||
next?.let { picture ->
|
||||
drawPictureWithEffects(picture, crossfadeProgress, blurRadius)
|
||||
next?.let { layer ->
|
||||
drawPictureWithEffects(layer, crossfadeProgress, blurRadius)
|
||||
|
||||
if (crossfadeProgress >= 1.0f) {
|
||||
currentPicture?.recycle()
|
||||
currentPicture = picture
|
||||
nextPicture = null
|
||||
currentLayer?.recycle()
|
||||
currentLayer = layer
|
||||
nextLayer = null
|
||||
|
||||
Log.d(TAG, "Crossfade complete")
|
||||
} else {
|
||||
@@ -198,61 +210,71 @@ class PaperizeWallpaperRenderer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun drawPictureWithEffects(picture: GLPicture, alpha: Float, blurRadius: Float) {
|
||||
calculateMvpMatrix(picture, mvpMatrix)
|
||||
|
||||
if (blurRadius > Constants.BLUR_MIN_THRESHOLD) {
|
||||
drawWithBlur(picture, alpha, blurRadius)
|
||||
private fun drawPictureWithEffects(layer: Layer, alpha: Float, blurRadius: Float) {
|
||||
if (blurRadius > Constants.BLUR_MIN_THRESHOLD || showsBackdrop()) {
|
||||
drawComposited(layer, alpha, blurRadius)
|
||||
} else {
|
||||
drawWithColorEffects(picture, alpha)
|
||||
setEffectUniforms(layer.picture, alpha)
|
||||
drawLayer(layer, flipY = false) {
|
||||
it.draw(aPositionHandle, aTexCoordHandle, mvpMatrix, uMvpMatrixHandle)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showsBackdrop() = blurFitBackground && currentScalingType == ScalingType.FIT
|
||||
|
||||
private fun drawLayer(layer: Layer, flipY: Boolean, draw: (GLPicture) -> Unit) {
|
||||
if (showsBackdrop()) {
|
||||
calculateMvpMatrix(layer.backdrop, mvpMatrix, ScalingType.FILL, flipY)
|
||||
draw(layer.backdrop)
|
||||
}
|
||||
calculateMvpMatrix(layer.picture, mvpMatrix, currentScalingType, flipY)
|
||||
draw(layer.picture)
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw picture with proper 3-pass blur + effects pipeline.
|
||||
* Pass 1: Source texture → Horizontal blur → FBO1
|
||||
* Pass 2: FBO1 texture → Vertical blur → FBO2
|
||||
* Pass 3: FBO2 texture → Color effects → Screen
|
||||
* Blur and color effects run on the whole screen, as in static mode, so they cross the edges
|
||||
* between a Fit picture and its backdrop instead of outlining the picture.
|
||||
* Pass 1: Layer → FBO1, unblurred
|
||||
* Pass 2: FBO1 → Horizontal blur → FBO2
|
||||
* Pass 3: FBO2 → Vertical blur → FBO1
|
||||
* Pass 4: FBO1 → Color effects → Screen
|
||||
*/
|
||||
private fun drawWithBlur(picture: GLPicture, alpha: Float, blurRadius: Float) {
|
||||
private fun drawComposited(layer: Layer, alpha: Float, blurRadius: Float) {
|
||||
if (blurFbo1 == 0) createBlurFramebuffers(surfaceWidth, surfaceHeight)
|
||||
|
||||
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, blurFbo1)
|
||||
GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight)
|
||||
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT)
|
||||
|
||||
GLES20.glUseProgram(blurProgram)
|
||||
GLES20.glUniform2f(blurDirectionHandle, 1f, 0f)
|
||||
GLES20.glUniform2f(blurResolutionHandle, surfaceWidth.toFloat(), surfaceHeight.toFloat())
|
||||
GLES20.glUniform1f(blurRadiusHandle, blurRadius)
|
||||
GLES20.glUniform1i(blurTextureHandle, 0)
|
||||
|
||||
picture.draw(blurPositionHandle, blurTexCoordHandle, mvpMatrix, blurMvpMatrixHandle)
|
||||
|
||||
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, blurFbo2)
|
||||
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, blurFbo1)
|
||||
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT)
|
||||
GLES20.glUniform1f(blurRadiusHandle, 0f)
|
||||
// Each framebuffer-to-framebuffer quad flips the image and three follow, so start upside down.
|
||||
drawLayer(layer, flipY = true) {
|
||||
it.draw(blurPositionHandle, blurTexCoordHandle, mvpMatrix, blurMvpMatrixHandle)
|
||||
}
|
||||
|
||||
GLES20.glActiveTexture(GLES20.GL_TEXTURE0)
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, blurTexture1)
|
||||
|
||||
GLES20.glUniform2f(blurDirectionHandle, 0f, 1f)
|
||||
drawQuad(blurPositionHandle, blurTexCoordHandle, blurMvpMatrixHandle)
|
||||
GLES20.glUniform1f(blurRadiusHandle, blurRadius)
|
||||
drawBlurPass(target = blurFbo2, source = blurTexture1, directionX = 1f, directionY = 0f)
|
||||
drawBlurPass(target = blurFbo1, source = blurTexture2, directionX = 0f, directionY = 1f)
|
||||
|
||||
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0)
|
||||
GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight)
|
||||
|
||||
setEffectUniforms(picture, alpha)
|
||||
|
||||
setEffectUniforms(layer.picture, alpha)
|
||||
GLES20.glActiveTexture(GLES20.GL_TEXTURE0)
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, blurTexture2)
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, blurTexture1)
|
||||
GLES20.glUniform1i(uTextureHandle, 0)
|
||||
|
||||
drawQuad(aPositionHandle, aTexCoordHandle, uMvpMatrixHandle)
|
||||
}
|
||||
|
||||
private fun drawWithColorEffects(picture: GLPicture, alpha: Float) {
|
||||
setEffectUniforms(picture, alpha)
|
||||
picture.draw(aPositionHandle, aTexCoordHandle, mvpMatrix, uMvpMatrixHandle)
|
||||
private fun drawBlurPass(target: Int, source: Int, directionX: Float, directionY: Float) {
|
||||
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, target)
|
||||
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT)
|
||||
GLES20.glActiveTexture(GLES20.GL_TEXTURE0)
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, source)
|
||||
GLES20.glUniform2f(blurDirectionHandle, directionX, directionY)
|
||||
drawQuad(blurPositionHandle, blurTexCoordHandle, blurMvpMatrixHandle)
|
||||
}
|
||||
|
||||
private fun setEffectUniforms(picture: GLPicture, alpha: Float) {
|
||||
@@ -275,7 +297,7 @@ class PaperizeWallpaperRenderer(
|
||||
|
||||
}
|
||||
|
||||
private fun calculateMvpMatrix(picture: GLPicture, matrix: FloatArray) {
|
||||
private fun calculateMvpMatrix(picture: GLPicture, matrix: FloatArray, scalingType: ScalingType, flipY: Boolean) {
|
||||
val viewWidth = surfaceWidth.toFloat()
|
||||
val viewHeight = surfaceHeight.toFloat()
|
||||
val imageWidth = picture.width.toFloat()
|
||||
@@ -286,13 +308,14 @@ class PaperizeWallpaperRenderer(
|
||||
viewHeight = viewHeight,
|
||||
imageWidth = imageWidth,
|
||||
imageHeight = imageHeight,
|
||||
scalingType = currentScalingType,
|
||||
scalingType = scalingType,
|
||||
parallaxEnabled = currentEffects.enableParallax,
|
||||
parallaxIntensity = currentEffects.parallaxIntensity,
|
||||
normalizedOffsetX = normalOffsetX
|
||||
)
|
||||
|
||||
Matrix.orthoM(matrix, 0, -viewWidth / 2f, viewWidth / 2f, -viewHeight / 2f, viewHeight / 2f, -1f, 1f)
|
||||
val halfHeight = if (flipY) -viewHeight / 2f else viewHeight / 2f
|
||||
Matrix.orthoM(matrix, 0, -viewWidth / 2f, viewWidth / 2f, -halfHeight, halfHeight, -1f, 1f)
|
||||
Matrix.translateM(matrix, 0, transform.horizontalOffset, 0f, 0f)
|
||||
// The quad spans -1..1, so scale by half the displayed image dimensions.
|
||||
Matrix.scaleM(
|
||||
@@ -443,15 +466,20 @@ class PaperizeWallpaperRenderer(
|
||||
|
||||
val sourceBrightness =
|
||||
BrightnessCalculator.calculateBitmapBrightness(bitmap)
|
||||
val backdrop = createBlurredBackdrop(bitmap)
|
||||
|
||||
val queued = callbacks.queueEventOnGlThread {
|
||||
if (loadGeneration.get() == generation) {
|
||||
uploadBitmap(bitmap, sourceBrightness, skipCrossfade)
|
||||
uploadBitmap(bitmap, backdrop, sourceBrightness, skipCrossfade)
|
||||
} else {
|
||||
bitmap.recycle()
|
||||
backdrop.recycle()
|
||||
}
|
||||
}
|
||||
if (!queued) bitmap.recycle()
|
||||
if (!queued) {
|
||||
bitmap.recycle()
|
||||
backdrop.recycle()
|
||||
}
|
||||
} else {
|
||||
Log.w(TAG, "Failed to load wallpaper (null bitmap)")
|
||||
}
|
||||
@@ -463,25 +491,32 @@ class PaperizeWallpaperRenderer(
|
||||
}
|
||||
}
|
||||
|
||||
/** Consumes [bitmap] on the GL thread, then swaps or crossfades to it. */
|
||||
/** Consumes [bitmap] and [backdrop] on the GL thread, then swaps or crossfades to them. */
|
||||
private fun uploadBitmap(
|
||||
bitmap: Bitmap,
|
||||
backdrop: Bitmap,
|
||||
sourceBrightness: Float,
|
||||
skipCrossfade: Boolean
|
||||
) {
|
||||
try {
|
||||
val picture = GLPicture(bitmap, sourceBrightness)
|
||||
val layer = try {
|
||||
Layer(picture, GLPicture(backdrop, sourceBrightness))
|
||||
} catch (e: Throwable) {
|
||||
picture.recycle()
|
||||
throw e
|
||||
}
|
||||
|
||||
if (skipCrossfade) {
|
||||
currentPicture?.recycle()
|
||||
nextPicture?.recycle()
|
||||
currentPicture = picture
|
||||
nextPicture = null
|
||||
currentLayer?.recycle()
|
||||
nextLayer?.recycle()
|
||||
currentLayer = layer
|
||||
nextLayer = null
|
||||
|
||||
Log.d(TAG, "Wallpaper instantly swapped (no crossfade): ${picture.width}x${picture.height}")
|
||||
} else {
|
||||
nextPicture?.recycle()
|
||||
nextPicture = picture
|
||||
nextLayer?.recycle()
|
||||
nextLayer = layer
|
||||
|
||||
crossfadeStartTimeNanos = System.nanoTime()
|
||||
Log.d(TAG, "Wallpaper uploaded to GPU with crossfade: ${picture.width}x${picture.height}")
|
||||
@@ -492,6 +527,7 @@ class PaperizeWallpaperRenderer(
|
||||
Log.e(TAG, "Failed to upload bitmap to GPU", e)
|
||||
} finally {
|
||||
bitmap.recycle()
|
||||
backdrop.recycle()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -531,6 +567,13 @@ class PaperizeWallpaperRenderer(
|
||||
1f
|
||||
}
|
||||
|
||||
fun updateBlurFitBackground(enabled: Boolean) {
|
||||
if (blurFitBackground != enabled) {
|
||||
blurFitBackground = enabled
|
||||
callbacks.requestRender()
|
||||
}
|
||||
}
|
||||
|
||||
fun updateScalingType(scalingType: ScalingType) {
|
||||
if (currentScalingType != scalingType) {
|
||||
currentScalingType = scalingType
|
||||
@@ -545,4 +588,11 @@ class PaperizeWallpaperRenderer(
|
||||
loadingScope.cancel()
|
||||
requestedImageLoader = null
|
||||
}
|
||||
|
||||
private class Layer(val picture: GLPicture, val backdrop: GLPicture) {
|
||||
fun recycle() {
|
||||
picture.recycle()
|
||||
backdrop.recycle()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,6 @@ import com.anthonyla.paperize.domain.model.ScheduleSettings
|
||||
import com.anthonyla.paperize.domain.model.usesVisibleLiveTimer
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import java.time.Duration
|
||||
import java.time.ZonedDateTime
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
@@ -79,7 +78,7 @@ class WallpaperScheduler @Inject constructor(
|
||||
workManager.cancelUniqueWork(workName(screen))
|
||||
}
|
||||
}
|
||||
if (enabled) scheduleDailyAlbumRefresh(onlyIfNotScheduled) else workManager.cancelUniqueWork(Constants.WORK_NAME_REFRESH)
|
||||
if (enabled) scheduleHourlyAlbumRefresh(onlyIfNotScheduled) else workManager.cancelUniqueWork(Constants.WORK_NAME_REFRESH)
|
||||
}
|
||||
|
||||
fun cancelAllWallpaperChanges() {
|
||||
@@ -96,13 +95,10 @@ class WallpaperScheduler @Inject constructor(
|
||||
)
|
||||
}
|
||||
|
||||
/** Refresh daily, with the first run at the next 3 AM. */
|
||||
private fun scheduleDailyAlbumRefresh(onlyIfNotScheduled: Boolean) {
|
||||
val now = ZonedDateTime.now()
|
||||
val today3am = now.toLocalDate().atTime(3, 0).atZone(now.zone)
|
||||
val next3am = if (today3am.isAfter(now)) today3am else today3am.plusDays(1)
|
||||
val workRequest = PeriodicWorkRequestBuilder<AlbumRefreshWorker>(1, TimeUnit.DAYS)
|
||||
.setInitialDelay(Duration.between(now, next3am))
|
||||
/** Refresh hourly, with the first run after one hour. */
|
||||
private fun scheduleHourlyAlbumRefresh(onlyIfNotScheduled: Boolean) {
|
||||
val workRequest = PeriodicWorkRequestBuilder<AlbumRefreshWorker>(1, TimeUnit.HOURS)
|
||||
.setInitialDelay(Duration.ofHours(1))
|
||||
.build()
|
||||
workManager.enqueueUniquePeriodicWork(Constants.WORK_NAME_REFRESH, policy(onlyIfNotScheduled), workRequest)
|
||||
}
|
||||
|
||||
@@ -112,6 +112,8 @@
|
||||
<string name="wallpaper_changer_description">Onderbreek of hervat geskeduleerde veranderinge sonder om jou albums uit te vee.</string>
|
||||
<string name="horizontal_wallpaper_scrolling">Horisontale blaai</string>
|
||||
<string name="horizontal_wallpaper_scrolling_description">Laat wye Vul-muurpapiere tussen tuisskerm-bladsye beweeg. Sluitskerm-muurpapiere bly gesentreer.</string>
|
||||
<string name="blur_fit_background">Vervaagde agtergrond</string>
|
||||
<string name="blur_fit_background_description">Vul die ruimte rondom \"Pas in\"-muurpapiere met \'n vervaagde kopie van die beeld in plaas van swart.</string>
|
||||
<string name="lock_album_label">Sluitskerm-album</string>
|
||||
<string name="home_album_label">Tuisskerm-album</string>
|
||||
<string name="scaling">Skalering</string>
|
||||
@@ -191,5 +193,13 @@
|
||||
<string name="refresh_folder">Verfris vouer</string>
|
||||
<string name="folder_refreshed">Vouer is vir nuwe muurpapiere gekontroleer.</string>
|
||||
<string name="folder_refresh_failed">Kon nie hierdie vouer verfris nie. Maak seker dit is toeganklik en probeer weer.</string>
|
||||
<string name="content_desc_remove_home_wallpaper">Verwyder die tuisskerm-muurpapier uit sy album</string>
|
||||
<string name="content_desc_remove_lock_wallpaper">Verwyder die sluitskerm-muurpapier uit sy album</string>
|
||||
<string name="wallpaper_removed">Muurpapier uit die album verwyder</string>
|
||||
<string name="undo">Ontdoen</string>
|
||||
<string name="remove_wallpaper_failed">Kon nie die muurpapier verwyder nie. Probeer asseblief weer.</string>
|
||||
<string name="restore_wallpaper_failed">Kon nie die muurpapier terugsit nie. Probeer asseblief weer.</string>
|
||||
<string name="removed_wallpapers">Verwyder</string>
|
||||
<string name="removed_wallpapers_hint">Hierdie bly uit die rotasie wanneer die vouer weer nagegaan word. Tik op een om dit terug te sit.</string>
|
||||
<string name="reset_failed">Kon nie klaar data terugstel nie. Probeer asseblief weer.</string>
|
||||
</resources>
|
||||
@@ -120,6 +120,8 @@
|
||||
<string name="wallpaper_changer_description">وقّف أو كمّل التغييرات المجدولة من غير ما تمسح الألبومات بتاعتك.</string>
|
||||
<string name="horizontal_wallpaper_scrolling">التمرير الأفقي</string>
|
||||
<string name="horizontal_wallpaper_scrolling_description">خلّي الخلفيات العريضة بوضع الملء تتحرك بين صفحات الشاشة الرئيسية. خلفيات شاشة القفل بتفضل في النص.</string>
|
||||
<string name="blur_fit_background">خلفية مموّهة</string>
|
||||
<string name="blur_fit_background_description">املى المساحة اللي حوالين خلفيات «ملاءمة» بنسخة مموّهة من الصورة بدل الأسود.</string>
|
||||
<string name="lock_album_label">ألبوم شاشة القفل</string>
|
||||
<string name="home_album_label">ألبوم الشاشة الرئيسية</string>
|
||||
<string name="scaling">تغيير الحجم</string>
|
||||
@@ -207,5 +209,13 @@
|
||||
<string name="refresh_folder">حدّث المجلد</string>
|
||||
<string name="folder_refreshed">المجلد اتفحص عن خلفيات جديدة.</string>
|
||||
<string name="folder_refresh_failed">معرفناش نحدّث المجلد ده. اتأكد إنه متاح وجرب تاني.</string>
|
||||
<string name="content_desc_remove_home_wallpaper">شيل خلفية الشاشة الرئيسية من الألبوم بتاعها</string>
|
||||
<string name="content_desc_remove_lock_wallpaper">شيل خلفية شاشة القفل من الألبوم بتاعها</string>
|
||||
<string name="wallpaper_removed">الخلفية اتشالت من الألبوم</string>
|
||||
<string name="undo">تراجع</string>
|
||||
<string name="remove_wallpaper_failed">معرفناش نشيل الخلفية. جرب تاني.</string>
|
||||
<string name="restore_wallpaper_failed">معرفناش نرجّع الخلفية. جرب تاني.</string>
|
||||
<string name="removed_wallpapers">اتشالت</string>
|
||||
<string name="removed_wallpapers_hint">دي مش هترجع للتدوير لما المجلد يتفحص تاني. اضغط على أي واحدة عشان ترجعها.</string>
|
||||
<string name="reset_failed">إعادة ظبط البيانات مخلصتش. جرب تاني.</string>
|
||||
</resources>
|
||||
@@ -120,6 +120,8 @@
|
||||
<string name="wallpaper_changer_description">أوقف التغييرات المجدولة مؤقتاً أو استأنفها دون مسح ألبوماتك.</string>
|
||||
<string name="horizontal_wallpaper_scrolling">التمرير الأفقي</string>
|
||||
<string name="horizontal_wallpaper_scrolling_description">السماح للخلفيات العريضة بوضع «ملء» بالتنقل بين صفحات الشاشة الرئيسية. تبقى خلفيات شاشة القفل في المنتصف.</string>
|
||||
<string name="blur_fit_background">خلفية مموّهة</string>
|
||||
<string name="blur_fit_background_description">املأ المساحة المحيطة بخلفيات «ملاءمة» بنسخة مموّهة من الصورة بدلاً من الأسود.</string>
|
||||
<string name="lock_album_label">ألبوم القفل</string>
|
||||
<string name="home_album_label">ألبوم الرئيسية</string>
|
||||
<string name="scaling">التحجيم</string>
|
||||
@@ -207,5 +209,13 @@
|
||||
<string name="refresh_folder">تحديث المجلد</string>
|
||||
<string name="folder_refreshed">تم فحص المجلد بحثاً عن خلفيات جديدة.</string>
|
||||
<string name="folder_refresh_failed">تعذر تحديث هذا المجلد. تأكد من إمكانية الوصول إليه ثم حاول مرة أخرى.</string>
|
||||
<string name="content_desc_remove_home_wallpaper">إزالة خلفية الشاشة الرئيسية من ألبومها</string>
|
||||
<string name="content_desc_remove_lock_wallpaper">إزالة خلفية شاشة القفل من ألبومها</string>
|
||||
<string name="wallpaper_removed">تمت إزالة الخلفية من الألبوم</string>
|
||||
<string name="undo">تراجع</string>
|
||||
<string name="remove_wallpaper_failed">تعذرت إزالة الخلفية. يرجى المحاولة مرة أخرى.</string>
|
||||
<string name="restore_wallpaper_failed">تعذرت إعادة الخلفية. يرجى المحاولة مرة أخرى.</string>
|
||||
<string name="removed_wallpapers">المُزالة</string>
|
||||
<string name="removed_wallpapers_hint">تبقى هذه خارج التدوير عند فحص المجلد مجددًا. انقر على إحداها لإعادتها.</string>
|
||||
<string name="reset_failed">تعذر إكمال إعادة تعيين البيانات. يرجى المحاولة مرة أخرى.</string>
|
||||
</resources>
|
||||
@@ -100,80 +100,58 @@
|
||||
<string name="notification_permission_title">开启通知</string>
|
||||
<string name="notification_permission_description">允许 Paperize 发送壁纸更换通知,以及在后台运行时显示通知。你可以随时在设置中更改。</string>
|
||||
<string name="skip">跳过</string>
|
||||
|
||||
<!-- Content Descriptions for Accessibility -->
|
||||
<string name="content_desc_clear_selection">清除选择</string>
|
||||
<string name="content_desc_select_all">全选</string>
|
||||
<string name="content_desc_delete_selected">删除所选</string>
|
||||
<string name="content_desc_collapse">收起</string>
|
||||
<string name="content_desc_current_lock_wallpaper">当前锁屏壁纸</string>
|
||||
<string name="content_desc_current_home_wallpaper">当前主屏幕壁纸</string>
|
||||
|
||||
<!-- UI Labels and Status -->
|
||||
<string name="wallpaper_changer">壁纸更换</string>
|
||||
<string name="wallpaper_changer_description">暂停或恢复定时切换,不会清除你的相册。</string>
|
||||
<string name="horizontal_wallpaper_scrolling">横向滚动</string>
|
||||
<string name="horizontal_wallpaper_scrolling_description">允许宽幅「填充」壁纸在桌面页面之间移动。锁屏壁纸保持居中。</string>
|
||||
<string name="blur_fit_background">模糊背景</string>
|
||||
<string name="blur_fit_background_description">用图片的模糊副本填充“适应”壁纸周围的空白,而不是黑色。</string>
|
||||
<string name="lock_album_label">锁屏相册</string>
|
||||
<string name="home_album_label">主屏幕相册</string>
|
||||
<string name="scaling">缩放</string>
|
||||
<string name="visual_effects">视觉效果</string>
|
||||
<string name="interactive_effects">交互效果</string>
|
||||
<string name="current_wallpapers">当前壁纸</string>
|
||||
|
||||
<!-- Sort Options -->
|
||||
<string name="sort_name_asc">名称(A-Z)</string>
|
||||
<string name="sort_name_desc">名称(Z-A)</string>
|
||||
<string name="sort_date_added_asc">添加日期(最早优先)</string>
|
||||
<string name="sort_date_added_desc">添加日期(最新优先)</string>
|
||||
<string name="sort_date_modified_asc">修改日期(最早优先)</string>
|
||||
<string name="sort_date_modified_desc">修改日期(最新优先)</string>
|
||||
|
||||
<!-- Time Interval Picker -->
|
||||
<string name="mins">分钟</string>
|
||||
<string name="total_interval">总计:%1$s</string>
|
||||
<string name="time_unit_min">%d 分</string>
|
||||
<string name="live_short_interval_note">低于 15 分钟的间隔仅在 Paperize 作为可见的动态壁纸运行时生效。</string>
|
||||
|
||||
<!-- Notification Service -->
|
||||
<string name="notification_channel_description">壁纸更换通知</string>
|
||||
<string name="no_wallpapers_in_album">相册中没有壁纸</string>
|
||||
<string name="wallpaper_changer_disabled_empty_album">相册为空,壁纸更换已停用。</string>
|
||||
|
||||
<!-- Error Messages -->
|
||||
<string name="error_no_valid_wallpaper_after_retries">多次重试后仍未找到有效壁纸</string>
|
||||
<string name="wallpaper_not_found">这张壁纸已不可用。</string>
|
||||
<string name="static_mode_required">应用单张壁纸前,请先切换到静态壁纸模式。</string>
|
||||
|
||||
<!-- OEM Compatibility Warnings -->
|
||||
<string name="parallax_may_not_work">视差效果在你的系统或桌面上可能无法生效。</string>
|
||||
|
||||
<!-- Plurals -->
|
||||
<plurals name="time_unit_hours">
|
||||
<item quantity="other">%d 小时</item>
|
||||
</plurals>
|
||||
<plurals name="time_unit_days">
|
||||
<item quantity="other">%d 天</item>
|
||||
</plurals>
|
||||
|
||||
<!-- Material 3 Expressive UI Strings -->
|
||||
<string name="create_first_album_hint">点击 + 创建你的第一个相册</string>
|
||||
|
||||
<!-- Wallpaper Mode Selection -->
|
||||
<string name="choose_wallpaper_mode">选择壁纸模式</string>
|
||||
<string name="change_later_in_settings">之后可以在设置中更改</string>
|
||||
<string name="static_mode">静态模式</string>
|
||||
<string name="static_mode_description">使用系统壁纸管理器进行经典的壁纸切换。简单省电,仅支持静态图片。</string>
|
||||
<string name="live_wallpaper_mode">动态壁纸模式</string>
|
||||
<string name="live_wallpaper_mode_description">带硬件加速特效与交互功能(双击、视差)的高级动态壁纸。</string>
|
||||
|
||||
<!-- Live Wallpaper Selection Dialog -->
|
||||
<string name="select_live_wallpaper">选择动态壁纸</string>
|
||||
<string name="select_live_wallpaper_instruction">若想以动态壁纸模式使用 Paperize,你需要在系统设置中把它选为动态壁纸。</string>
|
||||
<string name="open_wallpaper_picker">打开壁纸选择器</string>
|
||||
<string name="later">稍后</string>
|
||||
|
||||
<!-- Settings Mode Switcher -->
|
||||
<string name="wallpaper_mode_setting">壁纸模式</string>
|
||||
<string name="current_mode">当前模式</string>
|
||||
<string name="mode_static">静态</string>
|
||||
@@ -197,7 +175,6 @@
|
||||
<string name="home_and_lock_screens">主屏幕和锁屏</string>
|
||||
<string name="individual_wallpaper_static_only">请切换到静态模式以设置单张壁纸。</string>
|
||||
<string name="change_next_wallpaper_shortcut">切换到下一张已配置的壁纸</string>
|
||||
|
||||
<string name="import_failed">无法完成导入。请确认文件或文件夹可用后重试。</string>
|
||||
<string name="import_permission_error">无法保留访问权限。请从可访问的位置重新选择文件或文件夹。</string>
|
||||
<string name="import_already_added">所选内容已在相册中。</string>
|
||||
@@ -212,5 +189,13 @@
|
||||
<string name="refresh_folder">刷新文件夹</string>
|
||||
<string name="folder_refreshed">已检查文件夹中的新壁纸。</string>
|
||||
<string name="folder_refresh_failed">无法刷新此文件夹。请确认文件夹可访问后重试。</string>
|
||||
<string name="content_desc_remove_home_wallpaper">从相册中移除当前主屏幕壁纸</string>
|
||||
<string name="content_desc_remove_lock_wallpaper">从相册中移除当前锁屏壁纸</string>
|
||||
<string name="wallpaper_removed">已从相册中移除壁纸</string>
|
||||
<string name="undo">撤销</string>
|
||||
<string name="remove_wallpaper_failed">无法移除壁纸,请重试。</string>
|
||||
<string name="restore_wallpaper_failed">无法恢复壁纸,请重试。</string>
|
||||
<string name="removed_wallpapers">已移除</string>
|
||||
<string name="removed_wallpapers_hint">再次检查文件夹时,这些图片不会重新加入轮换。点按任一图片即可恢复。</string>
|
||||
<string name="reset_failed">无法完成数据重置,请重试。</string>
|
||||
</resources>
|
||||
@@ -2,7 +2,7 @@
|
||||
<resources>
|
||||
<string name="album_create_failed">無法建立相簿,請再試一次。</string>
|
||||
<string name="continue_rotation_from_here">從這裡繼續輪播</string>
|
||||
<string name="continue_rotation_from_here_desc">之後會從這張桌布開始,依相簿順序更換</string>
|
||||
<string name="continue_rotation_from_here_desc">從這張桌布之後依相簿順序更換</string>
|
||||
<string name="import_adding_folder">正在新增資料夾…</string>
|
||||
<string name="import_adding_wallpapers">正在加入桌布…</string>
|
||||
<plurals name="import_scanning">
|
||||
@@ -110,6 +110,8 @@
|
||||
<string name="wallpaper_changer_description">暫停或繼續定時更換,不會清除你的相簿。</string>
|
||||
<string name="horizontal_wallpaper_scrolling">水平捲動</string>
|
||||
<string name="horizontal_wallpaper_scrolling_description">讓採用「填滿」的寬幅桌布可隨主畫面頁面移動。鎖定畫面的桌布會保持置中。</string>
|
||||
<string name="blur_fit_background">模糊背景</string>
|
||||
<string name="blur_fit_background_description">以圖片的模糊副本填滿「完整顯示」桌布周圍的空間,而不是黑色。</string>
|
||||
<string name="lock_album_label">鎖定畫面相簿</string>
|
||||
<string name="home_album_label">主畫面相簿</string>
|
||||
<string name="scaling">縮放</string>
|
||||
@@ -187,5 +189,13 @@
|
||||
<string name="refresh_folder">重新整理資料夾</string>
|
||||
<string name="folder_refreshed">已檢查資料夾是否有新桌布。</string>
|
||||
<string name="folder_refresh_failed">無法重新整理此資料夾。請確認它仍可存取,然後再試一次。</string>
|
||||
<string name="content_desc_remove_home_wallpaper">從相簿移除目前的主畫面桌布</string>
|
||||
<string name="content_desc_remove_lock_wallpaper">從相簿移除目前的鎖定畫面桌布</string>
|
||||
<string name="wallpaper_removed">已從相簿移除桌布</string>
|
||||
<string name="undo">復原</string>
|
||||
<string name="remove_wallpaper_failed">無法移除桌布,請再試一次。</string>
|
||||
<string name="restore_wallpaper_failed">無法放回桌布,請再試一次。</string>
|
||||
<string name="removed_wallpapers">已移除</string>
|
||||
<string name="removed_wallpapers_hint">再次檢查資料夾時,這些圖片不會重新加入輪播。輕觸任一圖片即可放回。</string>
|
||||
<string name="reset_failed">無法完成資料重設,請再試一次。</string>
|
||||
</resources>
|
||||
@@ -112,6 +112,8 @@
|
||||
<string name="wallpaper_changer_description">অ্যালবাম না মুছে নির্ধারিত পরিবর্তন বিরতি দিন বা আবার চালু করুন।</string>
|
||||
<string name="horizontal_wallpaper_scrolling">অনুভূমিক স্ক্রলিং</string>
|
||||
<string name="horizontal_wallpaper_scrolling_description">চওড়া “পূরণ” ওয়ালপেপারকে হোম স্ক্রিনের পৃষ্ঠাগুলোর মধ্যে সরতে দিন। লক স্ক্রিনের ওয়ালপেপার মাঝখানেই থাকে।</string>
|
||||
<string name="blur_fit_background">ঝাপসা পটভূমি</string>
|
||||
<string name="blur_fit_background_description">“ফিট” ওয়ালপেপারের চারপাশের জায়গা কালোর বদলে ছবির একটি ঝাপসা কপি দিয়ে পূরণ করুন।</string>
|
||||
<string name="lock_album_label">লক অ্যালবাম</string>
|
||||
<string name="home_album_label">হোম অ্যালবাম</string>
|
||||
<string name="scaling">স্কেলিং</string>
|
||||
@@ -191,5 +193,13 @@
|
||||
<string name="refresh_folder">ফোল্ডার রিফ্রেশ করুন</string>
|
||||
<string name="folder_refreshed">নতুন ওয়ালপেপারের জন্য ফোল্ডার পরীক্ষা করা হয়েছে।</string>
|
||||
<string name="folder_refresh_failed">এই ফোল্ডার রিফ্রেশ করা যায়নি। এটি অ্যাক্সেসযোগ্য কি না দেখে আবার চেষ্টা করুন।</string>
|
||||
<string name="content_desc_remove_home_wallpaper">হোম স্ক্রিন ওয়ালপেপারটি তার অ্যালবাম থেকে সরান</string>
|
||||
<string name="content_desc_remove_lock_wallpaper">লক স্ক্রিন ওয়ালপেপারটি তার অ্যালবাম থেকে সরান</string>
|
||||
<string name="wallpaper_removed">ওয়ালপেপারটি অ্যালবাম থেকে সরানো হয়েছে</string>
|
||||
<string name="undo">পূর্বাবস্থায় ফেরান</string>
|
||||
<string name="remove_wallpaper_failed">ওয়ালপেপারটি সরানো যায়নি। অনুগ্রহ করে আবার চেষ্টা করুন।</string>
|
||||
<string name="restore_wallpaper_failed">ওয়ালপেপারটি ফিরিয়ে আনা যায়নি। অনুগ্রহ করে আবার চেষ্টা করুন।</string>
|
||||
<string name="removed_wallpapers">সরানো হয়েছে</string>
|
||||
<string name="removed_wallpapers_hint">ফোল্ডারটি আবার যাচাই করা হলেও এগুলো ঘূর্ণনের বাইরে থাকবে। ফিরিয়ে আনতে যেকোনো একটিতে ট্যাপ করুন।</string>
|
||||
<string name="reset_failed">ডেটা রিসেট সম্পন্ন করা যায়নি। অনুগ্রহ করে আবার চেষ্টা করুন।</string>
|
||||
</resources>
|
||||
@@ -112,6 +112,8 @@
|
||||
<string name="wallpaper_changer_description">Posa en pausa o reprèn els canvis programats sense esborrar els àlbums.</string>
|
||||
<string name="horizontal_wallpaper_scrolling">Desplaçament horitzontal</string>
|
||||
<string name="horizontal_wallpaper_scrolling_description">Permet que els fons de pantalla amples amb Omple es moguin entre les pàgines de la pantalla d\'inici. Els fons de la pantalla de bloqueig es mantenen centrats.</string>
|
||||
<string name="blur_fit_background">Fons difuminat</string>
|
||||
<string name="blur_fit_background_description">Omple l\'espai al voltant dels fons de pantalla «Ajusta» amb una còpia difuminada de la imatge en lloc de negre.</string>
|
||||
<string name="lock_album_label">Àlbum de bloqueig</string>
|
||||
<string name="home_album_label">Àlbum d\'inici</string>
|
||||
<string name="scaling">Escalat</string>
|
||||
@@ -191,5 +193,13 @@
|
||||
<string name="refresh_folder">Actualitza la carpeta</string>
|
||||
<string name="folder_refreshed">S\'ha comprovat si la carpeta té fons de pantalla nous.</string>
|
||||
<string name="folder_refresh_failed">No s\'ha pogut actualitzar aquesta carpeta. Comprova que sigui accessible i torna-ho a provar.</string>
|
||||
<string name="content_desc_remove_home_wallpaper">Treu el fons de pantalla de la pantalla d\'inici del seu àlbum</string>
|
||||
<string name="content_desc_remove_lock_wallpaper">Treu el fons de pantalla de la pantalla de bloqueig del seu àlbum</string>
|
||||
<string name="wallpaper_removed">S\'ha tret el fons de pantalla de l\'àlbum</string>
|
||||
<string name="undo">Desfés</string>
|
||||
<string name="remove_wallpaper_failed">No s\'ha pogut treure el fons de pantalla. Torna-ho a provar.</string>
|
||||
<string name="restore_wallpaper_failed">No s\'ha pogut tornar a posar el fons de pantalla. Torna-ho a provar.</string>
|
||||
<string name="removed_wallpapers">Trets</string>
|
||||
<string name="removed_wallpapers_hint">Aquests queden fora de la rotació quan es torna a comprovar la carpeta. Toca\'n un per tornar-lo a posar.</string>
|
||||
<string name="reset_failed">No s\'ha pogut acabar de restablir les dades. Torna-ho a provar.</string>
|
||||
</resources>
|
||||
@@ -116,6 +116,8 @@
|
||||
<string name="wallpaper_changer_description">Pozastavte nebo obnovte plánované změny, aniž byste museli vymazat alba.</string>
|
||||
<string name="horizontal_wallpaper_scrolling">Vodorovné posouvání</string>
|
||||
<string name="horizontal_wallpaper_scrolling_description">Umožní širokým tapetám v režimu Vyplnit posouvat se mezi stránkami domovské obrazovky. Tapety obrazovky zámku zůstanou vystředěné.</string>
|
||||
<string name="blur_fit_background">Rozmazané pozadí</string>
|
||||
<string name="blur_fit_background_description">Vyplnit prostor kolem tapet v režimu „Přizpůsobit“ rozmazanou kopií obrázku místo černé.</string>
|
||||
<string name="lock_album_label">Album zámku</string>
|
||||
<string name="home_album_label">Album domovské obrazovky</string>
|
||||
<string name="scaling">Měřítko</string>
|
||||
@@ -199,5 +201,13 @@
|
||||
<string name="refresh_folder">Obnovit složku</string>
|
||||
<string name="folder_refreshed">Složka byla zkontrolována na nové tapety.</string>
|
||||
<string name="folder_refresh_failed">Tuto složku se nepodařilo obnovit. Zkontrolujte, zda je dostupná, a zkuste to znovu.</string>
|
||||
<string name="content_desc_remove_home_wallpaper">Odebrat tapetu domovské obrazovky z jejího alba</string>
|
||||
<string name="content_desc_remove_lock_wallpaper">Odebrat tapetu obrazovky zámku z jejího alba</string>
|
||||
<string name="wallpaper_removed">Tapeta byla odebrána z alba</string>
|
||||
<string name="undo">Zpět</string>
|
||||
<string name="remove_wallpaper_failed">Tapetu se nepodařilo odebrat. Zkuste to prosím znovu.</string>
|
||||
<string name="restore_wallpaper_failed">Tapetu se nepodařilo vrátit. Zkuste to prosím znovu.</string>
|
||||
<string name="removed_wallpapers">Odebrané</string>
|
||||
<string name="removed_wallpapers_hint">Při další kontrole složky zůstanou mimo střídání. Klepnutím na některou ji vrátíte.</string>
|
||||
<string name="reset_failed">Obnovení dat se nepodařilo dokončit. Zkuste to prosím znovu.</string>
|
||||
</resources>
|
||||