Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1404ec522 | ||
|
|
bcff2f338f | ||
|
|
5582a5851f | ||
|
|
1d0794d135 | ||
|
|
0e20f211f2 | ||
|
|
6f4a2bec97 | ||
|
|
85e5e3007b | ||
|
|
4760ab01d5 | ||
|
|
d8fc106a89 | ||
|
|
f4bf2786de | ||
|
|
c2e7e38f97 | ||
|
|
343d358d22 | ||
|
|
c219aa2b30 | ||
|
|
5ba325b93f | ||
|
|
dc1a65f234 | ||
|
|
48a198091e | ||
|
|
81020c9ba0 | ||
|
|
c47f3957bf | ||
|
|
68e94fe284 | ||
|
|
265edf8f63 | ||
|
|
322a10bf0c | ||
|
|
f6688c84ab | ||
|
|
62a5934220 | ||
|
|
64dedae516 | ||
|
|
1ff2539574 | ||
|
|
219a4cdb52 | ||
|
|
322e6907ab | ||
|
|
c39527b3b5 | ||
|
|
068f78f86c | ||
|
|
87ef7ebaf0 | ||
|
|
996208b03d | ||
|
|
ec54bbb8c5 | ||
|
|
b52a47770d | ||
|
|
61e3144de4 | ||
|
|
895af4f865 | ||
|
|
c956f6a3e3 | ||
|
|
d52effa343 | ||
|
|
4313e4a442 | ||
|
|
9ecc96e92b | ||
|
|
3df28a3a9a | ||
|
|
fff8b241c0 | ||
|
|
46d1284550 | ||
|
|
25717d83fd | ||
|
|
bca711a50d | ||
|
|
0449a93b31 | ||
|
|
58b24e50ff | ||
|
|
0cc477b7e8 | ||
|
|
4117ffb90a | ||
|
|
a8302ff3e2 | ||
|
|
5d9e87ff63 | ||
|
|
9a5b40ba7f | ||
|
|
dab5e4fe97 | ||
|
|
a635595ade | ||
|
|
f6fb087104 | ||
|
|
e3f56445d8 | ||
|
|
d8d6d4897d | ||
|
|
626b0a4de5 | ||
|
|
742d14ae3b | ||
|
|
a58a0c1e9a | ||
|
|
7b216d5534 | ||
|
|
65e4f38f83 | ||
|
|
fe43b4f631 | ||
|
|
7aab2a39d9 | ||
|
|
162d73e4e0 | ||
|
|
0f49241d7b | ||
|
|
df1bc642fc | ||
|
|
8eb9cb2aaa | ||
|
|
3f412f4724 | ||
|
|
047d519e80 | ||
|
|
b4041cc8ea | ||
|
|
fc57f14d2a | ||
|
|
4fd1e06b8e | ||
|
|
6a08e0eff9 | ||
|
|
d7edb40a9b | ||
|
|
ac889ed7b1 | ||
|
|
c97f9f7e3d | ||
|
|
4429355a1e |
No files matched your search
@@ -4,6 +4,6 @@
|
||||
<option name="jvmTarget" value="1.8" />
|
||||
</component>
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="1.9.22" />
|
||||
<option name="version" value="2.0.0" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,263 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="direct_access_persist.xml">
|
||||
<option name="deviceSelectionList">
|
||||
<list>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="27" />
|
||||
<option name="brand" value="DOCOMO" />
|
||||
<option name="codename" value="F01L" />
|
||||
<option name="id" value="F01L" />
|
||||
<option name="manufacturer" value="FUJITSU" />
|
||||
<option name="name" value="F-01L" />
|
||||
<option name="screenDensity" value="360" />
|
||||
<option name="screenX" value="720" />
|
||||
<option name="screenY" value="1280" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="28" />
|
||||
<option name="brand" value="DOCOMO" />
|
||||
<option name="codename" value="SH-01L" />
|
||||
<option name="id" value="SH-01L" />
|
||||
<option name="manufacturer" value="SHARP" />
|
||||
<option name="name" value="AQUOS sense2 SH-01L" />
|
||||
<option name="screenDensity" value="480" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2160" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="31" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="a51" />
|
||||
<option name="id" value="a51" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy A51" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="akita" />
|
||||
<option name="id" value="akita" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 8a" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="b0q" />
|
||||
<option name="id" value="b0q" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy S22 Ultra" />
|
||||
<option name="screenDensity" value="600" />
|
||||
<option name="screenX" value="1440" />
|
||||
<option name="screenY" value="3088" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="32" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="bluejay" />
|
||||
<option name="id" value="bluejay" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 6a" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="29" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="crownqlteue" />
|
||||
<option name="id" value="crownqlteue" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy Note9" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="2220" />
|
||||
<option name="screenY" value="1080" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="dm3q" />
|
||||
<option name="id" value="dm3q" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy S23 Ultra" />
|
||||
<option name="screenDensity" value="600" />
|
||||
<option name="screenX" value="1440" />
|
||||
<option name="screenY" value="3088" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="felix" />
|
||||
<option name="id" value="felix" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel Fold" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="2208" />
|
||||
<option name="screenY" value="1840" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="felix_camera" />
|
||||
<option name="id" value="felix_camera" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel Fold (Camera-enabled)" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="2208" />
|
||||
<option name="screenY" value="1840" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="gts8uwifi" />
|
||||
<option name="id" value="gts8uwifi" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy Tab S8 Ultra" />
|
||||
<option name="screenDensity" value="320" />
|
||||
<option name="screenX" value="1848" />
|
||||
<option name="screenY" value="2960" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="husky" />
|
||||
<option name="id" value="husky" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 8 Pro" />
|
||||
<option name="screenDensity" value="390" />
|
||||
<option name="screenX" value="1008" />
|
||||
<option name="screenY" value="2244" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="30" />
|
||||
<option name="brand" value="motorola" />
|
||||
<option name="codename" value="java" />
|
||||
<option name="id" value="java" />
|
||||
<option name="manufacturer" value="Motorola" />
|
||||
<option name="name" value="G20" />
|
||||
<option name="screenDensity" value="280" />
|
||||
<option name="screenX" value="720" />
|
||||
<option name="screenY" value="1600" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="lynx" />
|
||||
<option name="id" value="lynx" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 7a" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="31" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="oriole" />
|
||||
<option name="id" value="oriole" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 6" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="panther" />
|
||||
<option name="id" value="panther" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 7" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="31" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="q2q" />
|
||||
<option name="id" value="q2q" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy Z Fold3" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1768" />
|
||||
<option name="screenY" value="2208" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="q5q" />
|
||||
<option name="id" value="q5q" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy Z Fold5" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1812" />
|
||||
<option name="screenY" value="2176" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="30" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="r11" />
|
||||
<option name="id" value="r11" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel Watch" />
|
||||
<option name="screenDensity" value="320" />
|
||||
<option name="screenX" value="384" />
|
||||
<option name="screenY" value="384" />
|
||||
<option name="type" value="WEAR_OS" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="30" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="redfin" />
|
||||
<option name="id" value="redfin" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 5" />
|
||||
<option name="screenDensity" value="440" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2340" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="shiba" />
|
||||
<option name="id" value="shiba" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 8" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="tangorpro" />
|
||||
<option name="id" value="tangorpro" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel Tablet" />
|
||||
<option name="screenDensity" value="320" />
|
||||
<option name="screenX" value="1600" />
|
||||
<option name="screenY" value="2560" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="29" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="x1q" />
|
||||
<option name="id" value="x1q" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy S20" />
|
||||
<option name="screenDensity" value="480" />
|
||||
<option name="screenX" value="1440" />
|
||||
<option name="screenY" value="3200" />
|
||||
</PersistentDeviceSelectionData>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
@@ -12,26 +12,34 @@
|
||||
## Features
|
||||
- **Dynamic Wallpaper Changer**: Set your wallpaper to change at specific time intervals
|
||||
- **Supports Various Image Types**: Paperize can handle a wide range of image types
|
||||
- JPEG, PNG, AVIF, WEBP
|
||||
- Including: JPEG, PNG, AVIF, WEBP
|
||||
- **Folder Support**: Organize your wallpapers into folders for auto-updating
|
||||
- **Home and Lock Screen Wallpaper**: Choose to change either your home screen, lock screen, or both
|
||||
- **On-Device Storage**: All your wallpapers and settings are stored on your device
|
||||
<div align="center">
|
||||
<br/>
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/eebec922-70a6-4d54-97d9-ab02cbfb7a36" width="30%" alt="onboarding" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/60a4d68d-5e19-49f2-8822-e702d02651c6" width="30%" alt="wallpaper" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/e106c0dc-23ff-4f4a-adfc-5ebe93219ae0" width="30%" alt="album" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/7093a1ea-91ab-4da8-a82b-43e24d88d376" width="30%" alt="settings" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/54ebd285-8da4-4446-83f1-ba0e7ee9476d" width="30%" alt="adding" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/57122f72-78f8-45ed-a9ac-de943061d6a2" width="30%" alt="onboarding" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/9f41d715-7b14-4ff2-9c30-87ad3d86d94c" width="30%" alt="wallpaper" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/47aa95c3-ef80-4c3c-a8cd-a51ac6824507" width="30%" alt="interval" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/4ce1b28d-f4b2-4048-a261-203156222263" width="30%" alt="album" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/66b092e5-4af4-4396-b145-63ee506d9257" width="30%" alt="settings" />
|
||||
<br/>
|
||||
<br/>
|
||||
<div><video controls src="https://github.com/Anthonyy232/Paperize/assets/60626873/015afb04-e3f3-4641-b8f9-707cfa26d16f" muted="true"></video></div>
|
||||
</div>
|
||||
|
||||
|
||||
## Download
|
||||
|
||||
[<img src="https://play.google.com/intl/en_us/badges/static/images/badges/en_badge_web_generic.png" alt="Download app from Google Play" height="80">](https://play.google.com/store/apps/details?id=com.anthonyla.paperize)
|
||||
[<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/1c034414-21cd-4a0a-838d-89fe7bd56910" alt="Download app from GitHub" height="80">](https://github.com/Anthonyy232/Paperize/releases)
|
||||
|
||||
Playstore and F-Droid will be added soon
|
||||
F-Droid will be added soon
|
||||
|
||||
## Localization
|
||||
I want to allow more people to use the app. Currently, translations are provided using machine translation and AI -- which is not optimal.
|
||||
|
||||
I would love some help translating the app! Help me out with that [here](https://crowdin.com/project/paperize/invite?h=d8d7a7513d2beb0c96ba9b2a5f85473e2084922)!
|
||||
|
||||
[](https://crowdin.com/project/paperize)
|
||||
|
||||
## Technologies
|
||||
|
||||
@@ -45,10 +53,10 @@ Playstore and F-Droid will be added soon
|
||||
- [Landscapist](https://github.com/skydoves/landscapist) - A Compose and KPP image loading library that streamlines Glide, Coil, and Fresco
|
||||
- [Zoomable](https://github.com/usuiat/Zoomable) - A library that provides a zoomable and pannable view, which can be used with any view you want
|
||||
- [AnimatedFABMenu](https://github.com/rajaumair7890/AnimatedFABMenu) - A animated floating action button with Material 3 design
|
||||
- [DocumentFileCompat](https://github.com/ItzNotABug/DocumentFileCompat) - A DocumentFile wrapper that caches the result to improve efficiency
|
||||
|
||||
Thanks to the creators and maintainers of the open-source libraries used in this project.
|
||||
|
||||
|
||||
## Build
|
||||
|
||||
This project is built using Kotlin, Java, and Gradle. Here are the steps to build the project:
|
||||
@@ -56,7 +64,8 @@ This project is built using Kotlin, Java, and Gradle. Here are the steps to buil
|
||||
### Prerequisites
|
||||
- Java 8 (1.8)
|
||||
- Android Studio Jellyfish | 2023.3.1 or later
|
||||
- Gradle 8.4.0 or later
|
||||
- Android Gradle Plugin 8.5.0 or later
|
||||
- Gradle 8.8
|
||||
- Minimum SDK 26
|
||||
|
||||
### Steps
|
||||
@@ -70,8 +79,10 @@ This project is built using Kotlin, Java, and Gradle. Here are the steps to buil
|
||||
|
||||
All contributions to the app is welcome. Feel free to report any issues and create pull requests for any issues or pull requests.
|
||||
|
||||
Inspiration from j4velin for their wallpaper changer app
|
||||
|
||||
|
||||
## License
|
||||
Contact on my GitHub profile
|
||||
|
||||
Paperize © GNU GPL v3.0
|
||||
Anthony La © GNU GPL v3.0
|
||||
@@ -3,12 +3,14 @@ plugins {
|
||||
id("org.jetbrains.kotlin.android")
|
||||
id("com.google.devtools.ksp")
|
||||
id("com.google.dagger.hilt.android")
|
||||
id ("com.mikepenz.aboutlibraries.plugin")
|
||||
id ("org.jetbrains.kotlin.plugin.serialization")
|
||||
id("com.mikepenz.aboutlibraries.plugin")
|
||||
id("org.jetbrains.kotlin.plugin.serialization")
|
||||
id("org.jetbrains.kotlin.plugin.compose")
|
||||
}
|
||||
ksp {
|
||||
arg("room.schemaLocation", "$projectDir/schemas")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.anthonyla.paperize"
|
||||
compileSdk = 34
|
||||
@@ -17,16 +19,14 @@ android {
|
||||
applicationId = "com.anthonyla.paperize"
|
||||
minSdk = 26
|
||||
targetSdk = 34
|
||||
versionCode = 4
|
||||
versionName = "1.0.0"
|
||||
|
||||
versionCode = 24
|
||||
versionName = "1.5.6"
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
useSupportLibrary = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = true
|
||||
@@ -34,22 +34,46 @@ android {
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
ndk {
|
||||
debugSymbolLevel = "FULL"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
freeCompilerArgs += strongSkippingConfiguration()
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
compose = true
|
||||
viewBinding = true
|
||||
buildConfig = true
|
||||
}
|
||||
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion = "1.5.10"
|
||||
}
|
||||
|
||||
androidResources {
|
||||
generateLocaleConfig = true
|
||||
}
|
||||
|
||||
ndkVersion = "26.3.11579264"
|
||||
buildToolsVersion = "34.0.0"
|
||||
dependenciesInfo {
|
||||
includeInApk = true
|
||||
includeInBundle = true
|
||||
}
|
||||
|
||||
aboutLibraries {
|
||||
excludeFields = arrayOf("generated")
|
||||
}
|
||||
}
|
||||
|
||||
androidComponents {
|
||||
@@ -60,45 +84,50 @@ androidComponents {
|
||||
|
||||
dependencies {
|
||||
implementation("androidx.core:core-ktx:1.13.1")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.3")
|
||||
implementation("androidx.activity:activity-compose:1.9.0")
|
||||
implementation(platform("androidx.compose:compose-bom:2024.05.00"))
|
||||
implementation("androidx.compose.ui:ui:1.7.0-alpha08")
|
||||
implementation("androidx.compose.ui:ui-graphics:1.7.0-alpha08")
|
||||
implementation("androidx.compose.ui:ui-tooling-preview:1.7.0-alpha08")
|
||||
implementation("androidx.compose.material3:material3:1.3.0-alpha06")
|
||||
implementation("androidx.navigation:navigation-compose:2.8.0-alpha08")
|
||||
implementation("androidx.compose.material:material:1.7.0-alpha08")
|
||||
implementation(platform("androidx.compose:compose-bom:2024.06.00"))
|
||||
implementation("androidx.compose.ui:ui:1.7.0-beta04")
|
||||
implementation("androidx.compose.ui:ui-graphics:1.7.0-beta04")
|
||||
implementation("androidx.compose.ui:ui-tooling-preview:1.7.0-beta04")
|
||||
implementation("androidx.compose.material3:material3:1.3.0-beta04")
|
||||
implementation("androidx.navigation:navigation-compose:2.8.0-beta04")
|
||||
implementation("androidx.compose.material:material:1.7.0-beta04")
|
||||
implementation("androidx.datastore:datastore:1.1.1")
|
||||
implementation("androidx.datastore:datastore-preferences:1.1.1")
|
||||
implementation("androidx.compose.material:material-icons-extended:1.7.0-alpha08")
|
||||
implementation("com.google.accompanist:accompanist-adaptive:0.34.0")
|
||||
implementation("androidx.compose.material:material-icons-extended:1.7.0-beta04")
|
||||
implementation("androidx.hilt:hilt-navigation-compose:1.2.0")
|
||||
implementation("androidx.compose.animation:animation:1.7.0-alpha08")
|
||||
implementation("androidx.compose.animation:animation:1.7.0-beta04")
|
||||
implementation("androidx.core:core-splashscreen:1.2.0-alpha01")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0")
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.3")
|
||||
implementation("com.google.code.gson:gson:2.11.0")
|
||||
implementation("androidx.documentfile:documentfile:1.1.0-alpha01")
|
||||
implementation("net.engawapg.lib:zoomable:1.7.0-beta02")
|
||||
implementation("com.github.skydoves:landscapist-glide:2.3.3")
|
||||
implementation("com.github.skydoves:landscapist-glide:2.3.6")
|
||||
implementation("androidx.work:work-runtime-ktx:2.10.0-alpha02")
|
||||
implementation("androidx.hilt:hilt-work:1.2.0")
|
||||
implementation("com.airbnb.android:lottie-compose:6.4.0")
|
||||
implementation("com.airbnb.android:lottie-compose:6.4.1")
|
||||
implementation("com.google.accompanist:accompanist-permissions:0.35.0-alpha")
|
||||
implementation("com.mikepenz:aboutlibraries-core:11.1.4")
|
||||
implementation("com.mikepenz:aboutlibraries-compose-m3:11.1.4")
|
||||
implementation("androidx.compose.foundation:foundation:1.7.0-alpha08")
|
||||
implementation("com.mikepenz:aboutlibraries-core:11.2.2")
|
||||
implementation("com.mikepenz:aboutlibraries-compose-m3:11.2.2")
|
||||
implementation("androidx.compose.foundation:foundation:1.7.0-beta04")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.0-alpha04")
|
||||
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.7.0-alpha08")
|
||||
debugImplementation("androidx.compose.ui:ui-tooling:1.7.0-alpha08")
|
||||
debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.0-alpha08")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.2.1")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
|
||||
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.7.0-beta04")
|
||||
debugImplementation("androidx.compose.ui:ui-tooling:1.7.0-beta04")
|
||||
debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.0-beta04")
|
||||
implementation("com.google.dagger:hilt-android:2.51.1")
|
||||
ksp("com.google.dagger:hilt-android-compiler:2.51.1")
|
||||
implementation("androidx.room:room-runtime:2.6.1")
|
||||
ksp("androidx.room:room-compiler:2.6.1")
|
||||
implementation("androidx.room:room-ktx:2.6.1")
|
||||
implementation("com.lazygeniouz:dfc:1.0.8")
|
||||
implementation ("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
|
||||
}
|
||||
implementation ("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
|
||||
implementation("com.github.android:renderscript-intrinsics-replacement-toolkit:b6363490c3")
|
||||
}
|
||||
|
||||
private fun strongSkippingConfiguration() = listOf(
|
||||
"-P",
|
||||
"plugin:androidx.compose.compiler.plugins.kotlin:experimentalStrongSkipping=true",
|
||||
)
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
@@ -26,7 +26,7 @@
|
||||
-keepclassmembers class com.anthonyla.paperize.feature.wallpaper.domain.model.Album {
|
||||
!transient <fields>;
|
||||
}
|
||||
-keepclassmembers class com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper {
|
||||
-keepclassmembers class com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder {
|
||||
!transient <fields>;
|
||||
}
|
||||
-keepclassmembers class com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper {
|
||||
|
||||
@@ -2,17 +2,13 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-feature
|
||||
android:name="android.software.paperize"
|
||||
android:required="true" />
|
||||
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:allowBackup="false"
|
||||
android:name=".App"
|
||||
android:persistent="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
@@ -20,11 +16,10 @@
|
||||
android:icon="@mipmap/app_icon"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Paperize"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
tools:targetApi="tiramisu">
|
||||
android:theme="@style/Theme.Paperize" tools:targetApi="tiramisu">
|
||||
<activity
|
||||
android:name=".feature.wallpaper.presentation.MainActivity"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.Paperize">
|
||||
<intent-filter>
|
||||
@@ -32,12 +27,24 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service android:name=".feature.wallpaper.wallpaperservice.WallpaperService" android:foregroundServiceType="mediaPlayback"/>
|
||||
<receiver android:name=".feature.wallpaper.wallpaperservice.WallpaperBootReceiver"
|
||||
android:exported="true">
|
||||
<receiver android:name=".feature.wallpaper.wallpaper_alarmmanager.WallpaperReceiver" />
|
||||
<service android:name=".feature.wallpaper.wallpaper_service.WallpaperService1"/>
|
||||
<service android:name=".feature.wallpaper.wallpaper_service.WallpaperService2"/>
|
||||
<receiver android:name=".feature.wallpaper.wallpaper_alarmmanager.WallpaperBootAndTimeChangeReceiver"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.TIME_SET" />
|
||||
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<provider
|
||||
android:name="androidx.startup.InitializationProvider"
|
||||
android:authorities="${applicationId}.androidx-startup"
|
||||
android:exported="false"
|
||||
tools:node="merge">
|
||||
<meta-data android:name="androidx.emoji2.text.EmojiCompatInitializer"
|
||||
tools:node="remove" />
|
||||
</provider>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.anthonyla.paperize.core
|
||||
|
||||
enum class ScalingConstants {
|
||||
FIT,
|
||||
FILL,
|
||||
STRETCH
|
||||
}
|
||||
@@ -8,10 +8,22 @@ object SettingsConstants {
|
||||
const val DARK_MODE_TYPE = "dark_mode_type"
|
||||
const val DYNAMIC_THEME_TYPE = "dynamic_theme_type"
|
||||
const val ANIMATE_TYPE = "animate_type"
|
||||
const val WALLPAPER_CHANGE_INTERVAL = "wallpaper_change_interval"
|
||||
const val ENABLE_CHANGER = "enable_changer"
|
||||
const val HOME_WALLPAPER = "home_wallpaper"
|
||||
const val LOCK_WALLPAPER = "lock_wallpaper"
|
||||
const val HOME_WALLPAPER_CHANGE_INTERVAL = "home_wallpaper_change_interval"
|
||||
const val LOCK_WALLPAPER_CHANGE_INTERVAL = "lock_wallpaper_change_interval"
|
||||
const val WALLPAPER_CHANGE_INTERVAL_DEFAULT = 15
|
||||
const val SET_LOCK_WITH_HOME = "set_lock_with_home"
|
||||
const val FIRST_LAUNCH = "first_launch"
|
||||
const val FIRST_SET = "first_set"
|
||||
const val LAST_SET_TIME = "last_set_time"
|
||||
const val NEXT_SET_TIME = "next_set_time"
|
||||
const val DARKEN_PERCENTAGE = "darken_percentage"
|
||||
const val DARKEN = "darken"
|
||||
const val WALLPAPER_SCALING = "wallpaper_scaling"
|
||||
const val SCHEDULE_SEPARATELY = "schedule_separately"
|
||||
const val BLUR = "blur"
|
||||
const val BLUR_PERCENTAGE = "blur_percentage"
|
||||
const val NEXT_SET_TIME_1 = "next_set_time_1"
|
||||
const val NEXT_SET_TIME_2 = "next_set_time_2"
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
package com.anthonyla.paperize.core
|
||||
import android.app.WallpaperManager
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.ColorMatrix
|
||||
import android.graphics.ColorMatrixColorFilter
|
||||
import android.graphics.Paint
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import android.util.Size
|
||||
import androidx.compose.ui.util.fastRoundToInt
|
||||
import androidx.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.google.android.renderscript.Toolkit
|
||||
import com.lazygeniouz.dfc.file.DocumentFileCompat
|
||||
|
||||
enum class Type { HOME, LOCK, BOTH, REFRESH }
|
||||
|
||||
/**
|
||||
* Get the dimensions of the image from the uri
|
||||
*/
|
||||
fun Uri.getImageDimensions(context: Context): Size? {
|
||||
try {
|
||||
context.contentResolver.openInputStream(this)?.use { inputStream ->
|
||||
val exif = ExifInterface(inputStream)
|
||||
var width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0)
|
||||
var height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0)
|
||||
if (width == 0 || height == 0) {
|
||||
val options = BitmapFactory.Options().apply {
|
||||
inJustDecodeBounds = true
|
||||
}
|
||||
BitmapFactory.decodeStream(
|
||||
context.contentResolver.openInputStream(this),
|
||||
null,
|
||||
options
|
||||
)
|
||||
width = options.outWidth
|
||||
height = options.outHeight
|
||||
}
|
||||
return Size(width, height)
|
||||
}
|
||||
return null
|
||||
} catch (e: Exception) { return null }
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the inSampleSize for the image
|
||||
*/
|
||||
fun calculateInSampleSize(imageSize: Size, width: Int, height: Int): Int {
|
||||
return if (imageSize.width <= width && imageSize.height <= height) { 1 }
|
||||
else { (imageSize.width/ width.toFloat()).fastRoundToInt() }
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale a bitmap using the fit width method
|
||||
* The bitmap will fit into the given width while maintaining the same aspect ratio
|
||||
*/
|
||||
fun fitBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
val aspectRatio = source.height.toFloat() / source.width.toFloat()
|
||||
val newHeight = (width * aspectRatio).toInt()
|
||||
val newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(newBitmap)
|
||||
val scaledBitmap = Bitmap.createScaledBitmap(source, width, newHeight, true)
|
||||
val top = (height - newHeight) / 2f
|
||||
canvas.drawBitmap(scaledBitmap, 0f, top, null)
|
||||
scaledBitmap.recycle()
|
||||
return newBitmap
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale a bitmap using the fill height method
|
||||
*/
|
||||
fun fillBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
try {
|
||||
val aspectRatio = source.width.toFloat() / source.height.toFloat()
|
||||
var newWidth = width
|
||||
var newHeight = (newWidth / aspectRatio).toInt()
|
||||
if (newHeight < height) {
|
||||
newHeight = height
|
||||
newWidth = (newHeight * aspectRatio).toInt()
|
||||
}
|
||||
val scaledBitmap = Bitmap.createScaledBitmap(source, newWidth, newHeight, true)
|
||||
val x = (width - newWidth) / 2f
|
||||
val y = (height - newHeight) / 2f
|
||||
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(bitmap)
|
||||
canvas.drawBitmap(scaledBitmap, x, y, null)
|
||||
scaledBitmap.recycle()
|
||||
return bitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error filling bitmap: $e")
|
||||
return source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stretch the bitmap to fit the given width and height
|
||||
*/
|
||||
fun stretchBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
try {
|
||||
val newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(newBitmap)
|
||||
val bitmap = Bitmap.createScaledBitmap(source, width, height, true)
|
||||
canvas.drawBitmap(bitmap, 0f, 0f, null)
|
||||
bitmap.recycle()
|
||||
return newBitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error stretching bitmap: $e")
|
||||
return source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Darken the bitmap by a certain percentage - 0 is darkest, 100 is original
|
||||
*/
|
||||
fun darkenBitmap(source: Bitmap, percent: Int): Bitmap {
|
||||
try {
|
||||
val safePercentage = (100 - percent).coerceIn(0, 100)
|
||||
val factor = 1 - safePercentage / 100f
|
||||
val canvas = Canvas(source)
|
||||
val paint = Paint().apply {
|
||||
colorFilter = ColorMatrixColorFilter(ColorMatrix().apply {
|
||||
setScale(factor, factor, factor, 1f)
|
||||
})
|
||||
}
|
||||
canvas.drawBitmap(source, 0f, 0f, paint)
|
||||
return source
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error darkening bitmap: $e")
|
||||
return source
|
||||
}
|
||||
}
|
||||
|
||||
fun blurBitmap(source: Bitmap, percent: Int): Bitmap {
|
||||
try {
|
||||
val factor = percent.toFloat().div(100f) * 10
|
||||
return Toolkit.blur(source, factor.toInt())
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error darkening bitmap: $e")
|
||||
return source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve wallpaper URIs from a folder directory URI
|
||||
*/
|
||||
fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
|
||||
try {
|
||||
val folderDocumentFile = DocumentFileCompat.fromTreeUri(context, folderUri.toUri())
|
||||
return listFilesRecursive(folderDocumentFile, context)
|
||||
} catch (e: Exception) {
|
||||
val folderDocumentFile = DocumentFile.fromTreeUri(context, folderUri.toUri())
|
||||
return listFilesRecursive(folderDocumentFile, context)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to recursively list files in a directory for DocumentFileCompat
|
||||
*/
|
||||
fun listFilesRecursive(parent: DocumentFileCompat?, context: Context): List<String> {
|
||||
val files = mutableListOf<String>()
|
||||
parent?.listFiles()?.forEach { file ->
|
||||
if (file.isDirectory()) {
|
||||
files.addAll(listFilesRecursive(file, context))
|
||||
} else {
|
||||
val allowedExtensions = listOf("jpg", "jpeg", "png", "heif", "webp", "JPG", "JPEG", "PNG", "HEIF", "WEBP")
|
||||
if (file.extension in allowedExtensions) {
|
||||
files.add(file.uri.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
/** Overloaded version of the function for DocumentFile */
|
||||
fun listFilesRecursive(parent: DocumentFile?, context: Context): List<String> {
|
||||
val files = mutableListOf<String>()
|
||||
parent?.listFiles()?.forEach { file ->
|
||||
if (file.isDirectory) {
|
||||
files.addAll(listFilesRecursive(file, context))
|
||||
} else {
|
||||
val allowedExtensions = listOf("jpg", "jpeg", "png", "heif", "webp", "JPG", "JPEG", "PNG", "HEIF", "WEBP")
|
||||
if ((file.name?.substringAfterLast(".") ?: "") in allowedExtensions) {
|
||||
files.add(file.uri.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to find the first valid URI from a list of wallpapers
|
||||
* It will search through all wallpapers of an album first, and then all wallpapers of every folder of an album
|
||||
*/
|
||||
fun findFirstValidUri(context: Context, wallpapers: List<Wallpaper>, folders: List<Folder>): String? {
|
||||
wallpapers.forEach { wallpaper ->
|
||||
try {
|
||||
val file = DocumentFileCompat.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
|
||||
if (file?.exists() == true) {
|
||||
return wallpaper.wallpaperUri
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
val file = DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
|
||||
if (file?.exists() == true) {
|
||||
return wallpaper.wallpaperUri
|
||||
}
|
||||
}
|
||||
}
|
||||
folders.forEach { folder ->
|
||||
folder.wallpapers.forEach { wallpaper ->
|
||||
try {
|
||||
val file = DocumentFileCompat.fromSingleUri(context, wallpaper.toUri())
|
||||
if (file?.exists() == true) {
|
||||
return wallpaper
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
val file = DocumentFile.fromSingleUri(context, wallpaper.toUri())
|
||||
if (file?.exists() == true) {
|
||||
return wallpaper
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the folder name from the folder URI
|
||||
*/
|
||||
fun getFolderNameFromUri(folderUri: String, context: Context): String? {
|
||||
return try {
|
||||
DocumentFileCompat.fromTreeUri(context, folderUri.toUri())?.name
|
||||
} catch (e: Exception) {
|
||||
DocumentFile.fromTreeUri(context, folderUri.toUri())?.name
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a URI is valid
|
||||
*/
|
||||
fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.toUri()
|
||||
return try {
|
||||
uri?.let {
|
||||
val inputStream = context.contentResolver.openInputStream(it)
|
||||
inputStream?.close()
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if device uses a live wallpaper
|
||||
*/
|
||||
fun isLiveWallpaperSet(context: Context): Boolean {
|
||||
val wallpaperManager = WallpaperManager.getInstance(context)
|
||||
return wallpaperManager.wallpaperInfo != null
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ object AppModule {
|
||||
app,
|
||||
AlbumDatabase::class.java,
|
||||
AlbumDatabase.DATABASE_NAME
|
||||
).build()
|
||||
).fallbackToDestructiveMigration().addMigrations().build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@@ -41,7 +41,7 @@ object AppModule {
|
||||
app,
|
||||
SelectedAlbumDatabase::class.java,
|
||||
SelectedAlbumDatabase.DATABASE_NAME
|
||||
).build()
|
||||
).fallbackToDestructiveMigration().addMigrations().build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
*/
|
||||
@Database(
|
||||
entities = [Album::class, Wallpaper::class, Folder::class],
|
||||
version = 1
|
||||
version = 4
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class AlbumDatabase: RoomDatabase() {
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.anthonyla.paperize.feature.wallpaper.data.data_source
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
|
||||
/**
|
||||
* Converters for Room database to convert list of strings to json string and vice versa
|
||||
|
||||
@@ -12,7 +12,7 @@ import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
*/
|
||||
@Database(
|
||||
entities = [Album::class, Wallpaper::class],
|
||||
version = 1
|
||||
version = 4
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class SelectedAlbumDatabase: RoomDatabase() {
|
||||
|
||||
@@ -2,8 +2,6 @@ package com.anthonyla.paperize.feature.wallpaper.data.repository
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.data.data_source.SelectedAlbumDao
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.SelectedAlbumRepository
|
||||
@@ -17,6 +15,7 @@ class SelectedAlbumRepositoryImpl(
|
||||
}
|
||||
|
||||
override suspend fun upsertSelectedAlbum(selectedAlbum: SelectedAlbum) {
|
||||
dao.deleteAll()
|
||||
dao.upsertAlbum(selectedAlbum.album)
|
||||
dao.upsertWallpaperList(selectedAlbum.wallpapers)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,10 @@ import androidx.room.PrimaryKey
|
||||
* @param displayedAlbumName The displayed album name
|
||||
* @param coverUri The cover uri of the album
|
||||
* @param initialized Whether the album has been initialized
|
||||
* @param wallpapersInQueue The wallpapers in the queue to be displayed
|
||||
* @param homeWallpapersInQueue The wallpapers in the queue to be displayed for the home screen or when the user schedules both lock and home together
|
||||
* @param lockWallpapersInQueue The wallpapers in the queue to be displayed for the lock screen when scheduled separately
|
||||
* @param currentHomeWallpaper The current wallpaper for the home screen
|
||||
* @param currentLockWallpaper The current wallpaper for the lock screen
|
||||
*/
|
||||
@Entity
|
||||
data class Album(
|
||||
@@ -18,5 +21,8 @@ data class Album(
|
||||
val displayedAlbumName: String,
|
||||
val coverUri: String?,
|
||||
val initialized: Boolean = false,
|
||||
val wallpapersInQueue: List<String> = emptyList(),
|
||||
val homeWallpapersInQueue: List<String> = emptyList(),
|
||||
val lockWallpapersInQueue: List<String> = emptyList(),
|
||||
val currentHomeWallpaper: String? = null,
|
||||
val currentLockWallpaper: String? = null
|
||||
)
|
||||
@@ -1,26 +1,50 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation
|
||||
|
||||
import android.Manifest
|
||||
import android.animation.ObjectAnimator
|
||||
import android.app.Activity
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.view.View
|
||||
import android.view.animation.AccelerateInterpolator
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.SystemBarStyle
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.viewModels
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.animation.doOnEnd
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.compose.LifecycleEventEffect
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.core.Type
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.themes.PaperizeTheme
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreenViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperReceiver
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperScheduler
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -31,29 +55,103 @@ class MainActivity : ComponentActivity() {
|
||||
private val settingsViewModel: SettingsViewModel by viewModels()
|
||||
private val wallpaperScreenViewModel: WallpaperScreenViewModel by viewModels()
|
||||
private val context = this
|
||||
private var topInset = 0.dp
|
||||
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (ContextCompat.checkSelfPermission(context, Manifest.permission.SET_WALLPAPER) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(context as Activity, arrayOf(Manifest.permission.SET_WALLPAPER), 0)
|
||||
}
|
||||
enableEdgeToEdge()
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge(
|
||||
statusBarStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT),
|
||||
navigationBarStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT)
|
||||
)
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
val splashScreen = installSplashScreen()
|
||||
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) {
|
||||
splashScreen.setOnExitAnimationListener { splashScreenViewProvider ->
|
||||
val fadeOut = ObjectAnimator.ofFloat(splashScreenViewProvider.view, View.ALPHA, 1f, 0f)
|
||||
fadeOut.interpolator = AccelerateInterpolator()
|
||||
fadeOut.duration = 300L
|
||||
fadeOut.doOnEnd { splashScreenViewProvider.remove() }
|
||||
fadeOut.start()
|
||||
}
|
||||
}
|
||||
splashScreen.setKeepOnScreenCondition { settingsViewModel.setKeepOnScreenCondition }
|
||||
|
||||
setContent {
|
||||
val scheduler = WallpaperScheduler(context)
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
val isFirstLaunch = runBlocking { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) } ?: true
|
||||
if (isFirstLaunch) {
|
||||
scheduler.cancelWallpaperAlarm()
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
settingsViewModel.onEvent(SettingsEvent.Reset)
|
||||
albumsViewModel.onEvent(AlbumsEvent.Reset)
|
||||
val contentResolver = context.contentResolver
|
||||
val persistedUris = contentResolver.persistedUriPermissions
|
||||
for (permission in persistedUris) {
|
||||
contentResolver.releasePersistableUriPermission(permission.uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||
}
|
||||
}
|
||||
PaperizeTheme(settingsViewModel.state) {
|
||||
LifecycleEventEffect(Lifecycle.Event.ON_CREATE) {
|
||||
lifecycleScope.launch {
|
||||
if (settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) == true) {
|
||||
val shouldScheduleSeparately = settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false
|
||||
val shouldScheduleAlarm = if (shouldScheduleSeparately) {
|
||||
!(isPendingIntentSet(Type.HOME.ordinal) && isPendingIntentSet(Type.LOCK.ordinal))
|
||||
} else {
|
||||
!isPendingIntentSet(Type.BOTH.ordinal)
|
||||
}
|
||||
if (shouldScheduleAlarm) {
|
||||
scheduler.scheduleWallpaperAlarm(
|
||||
WallpaperAlarmItem(
|
||||
timeInMinutes1 = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
timeInMinutes2 = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
scheduleSeparately = shouldScheduleSeparately
|
||||
), null, true, true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PaperizeTheme(settingsState.value.darkMode, settingsState.value.dynamicTheming) {
|
||||
Surface(tonalElevation = 5.dp) {
|
||||
PaperizeApp(isFirstLaunch)
|
||||
PaperizeApp(isFirstLaunch, scheduler, topInset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val alarmManager = ContextCompat.getSystemService(context, AlarmManager::class.java)
|
||||
if (alarmManager?.canScheduleExactAlarms() == false) {
|
||||
Intent().also { intent ->
|
||||
intent.action = Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
topInset = window.decorView.rootWindowInsets.stableInsetTop.dp
|
||||
}
|
||||
|
||||
private fun isPendingIntentSet(requestCode: Int): Boolean {
|
||||
val intent = Intent(context.applicationContext, WallpaperReceiver::class.java)
|
||||
val pendingIntent = PendingIntent.getBroadcast(
|
||||
context.applicationContext,
|
||||
requestCode,
|
||||
intent,
|
||||
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_NO_CREATE
|
||||
)
|
||||
return pendingIntent != null
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,14 @@ import android.content.pm.PackageManager
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.runtime.Composable
|
||||
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.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
@@ -48,11 +54,19 @@ import com.anthonyla.paperize.feature.wallpaper.util.navigation.Startup
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.WallpaperView
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.sharedXTransitionIn
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.sharedXTransitionOut
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaperservice.WallpaperService
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperScheduler
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@Composable
|
||||
fun PaperizeApp(
|
||||
firstLaunch: Boolean,
|
||||
scheduler : WallpaperScheduler,
|
||||
topInsets: Dp,
|
||||
albumsViewModel: AlbumsViewModel = hiltViewModel(),
|
||||
settingsViewModel: SettingsViewModel = hiltViewModel(),
|
||||
wallpaperScreenViewModel: WallpaperScreenViewModel = hiltViewModel(),
|
||||
@@ -63,57 +77,70 @@ fun PaperizeApp(
|
||||
val selectedState = wallpaperScreenViewModel.state.collectAsStateWithLifecycle()
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
val context = LocalContext.current
|
||||
var job by remember { mutableStateOf<Job?>(null) }
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
// React to albumState changes and change selectedAlbum's details to keep it from being stale
|
||||
LaunchedEffect(albumState.value.albumsWithWallpapers) {
|
||||
albumState.value.albumsWithWallpapers.asSequence().forEach { albumWithWallpapers ->
|
||||
if (!albumWithWallpapers.album.initialized && (albumWithWallpapers.wallpapers.isNotEmpty() || albumWithWallpapers.folders.isNotEmpty())) {
|
||||
albumsViewModel.onEvent(AlbumsEvent.InitializeAlbum(albumWithWallpapers))
|
||||
} else if (albumWithWallpapers.album.initialized && albumWithWallpapers.wallpapers.isEmpty() && albumWithWallpapers.folders.isEmpty()) {
|
||||
if (navController.currentDestination?.route == Home::class.simpleName) {
|
||||
navController.popBackStack<Home>(inclusive = false)
|
||||
}
|
||||
albumsViewModel.onEvent(AlbumsEvent.DeleteAlbumWithWallpapers(albumWithWallpapers))
|
||||
}
|
||||
}
|
||||
|
||||
selectedState.value.selectedAlbum?.let { selectedAlbum ->
|
||||
albumState.value.albumsWithWallpapers.find { it.album.initialAlbumName == selectedAlbum.album.initialAlbumName }
|
||||
?.let { foundAlbum ->
|
||||
val albumNameHashCode = foundAlbum.album.initialAlbumName.hashCode()
|
||||
val wallpapers: List<Wallpaper> =
|
||||
foundAlbum.wallpapers + foundAlbum.folders.flatMap { folder ->
|
||||
folder.wallpapers.map { wallpaper ->
|
||||
val wallpaperHashCode = wallpaper.hashCode()
|
||||
Wallpaper(
|
||||
initialAlbumName = foundAlbum.album.initialAlbumName,
|
||||
wallpaperUri = wallpaper,
|
||||
key = wallpaperHashCode + albumNameHashCode,
|
||||
)
|
||||
}
|
||||
withContext(Dispatchers.IO) {
|
||||
albumState.value.albumsWithWallpapers.asSequence().forEach { albumWithWallpapers ->
|
||||
if (!albumWithWallpapers.album.initialized && (albumWithWallpapers.wallpapers.isNotEmpty() || albumWithWallpapers.folders.isNotEmpty())) {
|
||||
albumsViewModel.onEvent(AlbumsEvent.InitializeAlbum(albumWithWallpapers))
|
||||
} else if (albumWithWallpapers.wallpapers.isEmpty() && albumWithWallpapers.folders.isEmpty() && albumWithWallpapers.album.initialized) {
|
||||
if (navController.currentDestination?.route == Home::class.simpleName) {
|
||||
try {
|
||||
navController.popBackStack<Home>(inclusive = false)
|
||||
} catch (e: Exception) {
|
||||
navController.navigate(Home)
|
||||
}
|
||||
val wallpaperUriSet = wallpapers.map { it.wallpaperUri }.toSet()
|
||||
val newSelectedAlbum = SelectedAlbum(
|
||||
album = foundAlbum.album.copy(
|
||||
wallpapersInQueue = selectedAlbum.album.wallpapersInQueue.filter { it in wallpaperUriSet }
|
||||
),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(newSelectedAlbum))
|
||||
settingsViewModel.onEvent(SettingsEvent.SetWallpaperInterval(settingsState.value.interval))
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.START.toString()
|
||||
putExtra("timeInMinutes", settingsState.value.interval)
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
albumsViewModel.onEvent(AlbumsEvent.DeleteAlbumWithWallpapers(albumWithWallpapers))
|
||||
}
|
||||
?: run {
|
||||
}
|
||||
selectedState.value.selectedAlbum?.let { selectedAlbum ->
|
||||
albumState.value.albumsWithWallpapers.find { it.album.initialAlbumName == selectedAlbum.album.initialAlbumName }
|
||||
?.let { foundAlbum ->
|
||||
val albumNameHashCode = foundAlbum.album.initialAlbumName.hashCode()
|
||||
val wallpapers: List<Wallpaper> =
|
||||
foundAlbum.wallpapers + foundAlbum.folders.flatMap { folder ->
|
||||
folder.wallpapers.map { wallpaper ->
|
||||
Wallpaper(
|
||||
initialAlbumName = foundAlbum.album.initialAlbumName,
|
||||
wallpaperUri = wallpaper,
|
||||
key = wallpaper.hashCode() + albumNameHashCode,
|
||||
)
|
||||
}
|
||||
}
|
||||
val wallpapersUri = wallpapers.map { it.wallpaperUri }.toSet()
|
||||
val newSelectedAlbum = SelectedAlbum(
|
||||
album = foundAlbum.album.copy(
|
||||
homeWallpapersInQueue = if (selectedAlbum.album.homeWallpapersInQueue.firstOrNull() in wallpapersUri) {
|
||||
val firstElement = selectedAlbum.album.homeWallpapersInQueue.first()
|
||||
val modifiedWallpapersUri = wallpapersUri.filter { it != firstElement }
|
||||
listOf(firstElement) + modifiedWallpapersUri.shuffled()
|
||||
} else { wallpapersUri.shuffled() },
|
||||
lockWallpapersInQueue = if (selectedAlbum.album.lockWallpapersInQueue.firstOrNull() in wallpapersUri) {
|
||||
val firstElement = selectedAlbum.album.lockWallpapersInQueue.first()
|
||||
val modifiedWallpapersUri = wallpapersUri.filter { it != firstElement }
|
||||
listOf(firstElement) + modifiedWallpapersUri.shuffled()
|
||||
} else { wallpapersUri.shuffled() },
|
||||
currentHomeWallpaper = if (selectedAlbum.album.currentHomeWallpaper in wallpapersUri) selectedAlbum.album.currentHomeWallpaper else selectedAlbum.album.homeWallpapersInQueue.firstOrNull { it in wallpapersUri },
|
||||
currentLockWallpaper = if (selectedAlbum.album.currentLockWallpaper in wallpapersUri) selectedAlbum.album.currentLockWallpaper else selectedAlbum.album.lockWallpapersInQueue.firstOrNull { it in wallpapersUri }
|
||||
),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
wallpaperScreenViewModel.onEvent(
|
||||
WallpaperEvent.UpdateSelectedAlbum(
|
||||
newSelectedAlbum,
|
||||
null,
|
||||
settingsState.value.scheduleSeparately
|
||||
)
|
||||
)
|
||||
} ?: run {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
Intent(context, WallpaperService::class.java).also {
|
||||
it.action = WallpaperService.Actions.STOP.toString()
|
||||
context.startForegroundService(it)
|
||||
}
|
||||
scheduler.cancelWallpaperAlarm()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,25 +152,30 @@ fun PaperizeApp(
|
||||
// Navigate to the startup screen to show the privacy policy and notification screen
|
||||
composable<Startup> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) {
|
||||
StartupScreen(
|
||||
onAgree = {
|
||||
if (ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetFirstLaunch)
|
||||
navController.navigate(Home) {
|
||||
popUpTo<Startup> { inclusive = true }
|
||||
}
|
||||
}
|
||||
else { navController.navigate(Notification) }
|
||||
}
|
||||
@@ -152,41 +184,52 @@ fun PaperizeApp(
|
||||
// Navigate to the notification screen to ask for notification permission
|
||||
composable<Notification> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) {
|
||||
NotificationScreen(
|
||||
onAgree = {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetFirstLaunch)
|
||||
navController.navigate(Home) {
|
||||
popUpTo<Notification> { inclusive = true }
|
||||
}
|
||||
}
|
||||
onAgree = { settingsViewModel.onEvent(SettingsEvent.SetFirstLaunch) }
|
||||
)
|
||||
}
|
||||
// Navigate to the home screen to view all albums and wallpapers
|
||||
composable<Home> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) {
|
||||
HomeScreen(
|
||||
onSettingsClick = { navController.navigate(Settings) },
|
||||
@@ -196,54 +239,322 @@ fun PaperizeApp(
|
||||
onAlbumViewClick = {
|
||||
navController.navigate(AlbumView(it))
|
||||
},
|
||||
onScheduleWallpaperChanger = { timeInMinutes ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetWallpaperInterval(timeInMinutes))
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.START.toString()
|
||||
putExtra("timeInMinutes", timeInMinutes)
|
||||
onScheduleWallpaperChanger1 = { timeInMinutes ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetHomeWallpaperInterval(timeInMinutes))
|
||||
if (settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
timeInMinutes1 = timeInMinutes,
|
||||
timeInMinutes2 = settingsState.value.lockInterval,
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
},
|
||||
onScheduleWallpaperChanger2 = { timeInMinutes ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetLockWallpaperInterval(timeInMinutes))
|
||||
if (settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
timeInMinutes1 = settingsState.value.homeInterval,
|
||||
timeInMinutes2 = timeInMinutes,
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
},
|
||||
onTimeChange1 = { timeInMinutes ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetHomeWallpaperInterval(timeInMinutes))
|
||||
if (settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(3000)
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
timeInMinutes1 = timeInMinutes,
|
||||
timeInMinutes2 = settingsState.value.lockInterval,
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately
|
||||
)
|
||||
alarmItem.let{scheduler.updateWallpaperAlarm(it)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
onTimeChange2 = { timeInMinutes ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetLockWallpaperInterval(timeInMinutes))
|
||||
if (settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(3000)
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
timeInMinutes1 = settingsState.value.homeInterval,
|
||||
timeInMinutes2 = timeInMinutes,
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately
|
||||
)
|
||||
alarmItem.let{scheduler.updateWallpaperAlarm(it)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
onStop = {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
Intent(context, WallpaperService::class.java).also {
|
||||
it.action = WallpaperService.Actions.STOP.toString()
|
||||
context.startForegroundService(it)
|
||||
if (selectedState.value.selectedAlbum != null) {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
|
||||
scheduler.cancelWallpaperAlarm()
|
||||
}
|
||||
},
|
||||
animate = settingsState.value.animate,
|
||||
interval = settingsState.value.interval,
|
||||
setLockWithHome = settingsState.value.setLockWithHome,
|
||||
interval1 = settingsState.value.homeInterval,
|
||||
interval2 = settingsState.value.lockInterval,
|
||||
lastSetTime = settingsState.value.lastSetTime,
|
||||
nextSetTime = settingsState.value.nextSetTime,
|
||||
onSetLockWithHome = {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetLockWithHome(it))
|
||||
selectedAlbum = selectedState.value.selectedAlbum,
|
||||
enableChanger = settingsState.value.enableChanger,
|
||||
darkenPercentage = settingsState.value.darkenPercentage,
|
||||
darken = settingsState.value.darken,
|
||||
homeEnabled = settingsState.value.setHomeWallpaper,
|
||||
lockEnabled = settingsState.value.setLockWallpaper,
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately,
|
||||
blur = settingsState.value.blur,
|
||||
blurPercentage = settingsState.value.blurPercentage,
|
||||
onToggleChanger = { enableWallpaperChanger ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(enableWallpaperChanger))
|
||||
if (selectedState.value.selectedAlbum != null && enableWallpaperChanger && (settingsState.value.setHomeWallpaper || settingsState.value.setLockWallpaper)) {
|
||||
wallpaperScreenViewModel.onEvent(
|
||||
WallpaperEvent.UpdateSelectedAlbum(
|
||||
selectedState.value.selectedAlbum!!.copy(
|
||||
album = selectedState.value.selectedAlbum!!.album.copy(
|
||||
currentHomeWallpaper = if (settingsState.value.setHomeWallpaper) selectedState.value.selectedAlbum!!.album.homeWallpapersInQueue.firstOrNull() else null,
|
||||
currentLockWallpaper = if (settingsState.value.scheduleSeparately && settingsState.value.setLockWallpaper) selectedState.value.selectedAlbum!!.album.lockWallpapersInQueue.firstOrNull() else if (settingsState.value.setLockWallpaper) selectedState.value.selectedAlbum!!.album.homeWallpapersInQueue.firstOrNull() else null
|
||||
)
|
||||
),
|
||||
null,
|
||||
settingsState.value.scheduleSeparately,
|
||||
settingsState.value.setHomeWallpaper,
|
||||
settingsState.value.setLockWallpaper
|
||||
)
|
||||
)
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
timeInMinutes1 = settingsState.value.homeInterval,
|
||||
timeInMinutes2 = settingsState.value.lockInterval,
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
else { scheduler.cancelWallpaperAlarm() }
|
||||
},
|
||||
onSelectAlbum = {album ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(true))
|
||||
wallpaperScreenViewModel.onEvent(
|
||||
WallpaperEvent.UpdateSelectedAlbum(
|
||||
null,
|
||||
album,
|
||||
settingsState.value.scheduleSeparately,
|
||||
settingsState.value.setHomeWallpaper,
|
||||
settingsState.value.setLockWallpaper
|
||||
)
|
||||
)
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
timeInMinutes1 = settingsState.value.homeInterval,
|
||||
timeInMinutes2 = settingsState.value.lockInterval,
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
},
|
||||
onDarkenPercentage = {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetDarkenPercentage(it))
|
||||
if (settingsState.value.enableChanger && settingsState.value.darken) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
scheduler.updateWallpaper(settingsState.value.scheduleSeparately)
|
||||
}
|
||||
}
|
||||
},
|
||||
onDarkCheck = {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetDarken(it))
|
||||
if (settingsState.value.enableChanger && (settingsState.value.darken && settingsState.value.darkenPercentage < 100)) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
scheduler.updateWallpaper(settingsState.value.scheduleSeparately)
|
||||
}
|
||||
}
|
||||
},
|
||||
scaling = settingsState.value.wallpaperScaling,
|
||||
onScalingChange = {
|
||||
if (settingsState.value.wallpaperScaling != it) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetWallpaperScaling(it))
|
||||
if (settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
scheduler.updateWallpaper(settingsState.value.scheduleSeparately)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onHomeCheckedChange = { enableHome ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetHome(enableHome))
|
||||
if (selectedState.value.selectedAlbum!= null && !enableHome && !settingsState.value.setLockWallpaper) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
|
||||
selectedState.value.selectedAlbum?.let {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
}
|
||||
scheduler.cancelWallpaperAlarm()
|
||||
}
|
||||
else if (selectedState.value.selectedAlbum!= null && (enableHome && !settingsState.value.setLockWallpaper) || (!enableHome && settingsState.value.setLockWallpaper)) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetScheduleSeparately(false))
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
timeInMinutes1 = settingsState.value.homeInterval,
|
||||
timeInMinutes2 = settingsState.value.lockInterval,
|
||||
scheduleSeparately = false
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
else if (selectedState.value.selectedAlbum != null && settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
scheduler.updateWallpaper(settingsState.value.scheduleSeparately)
|
||||
}
|
||||
}
|
||||
},
|
||||
onLockCheckedChange = { enableLock ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetLock(enableLock))
|
||||
if (selectedState.value.selectedAlbum!= null && !enableLock && !settingsState.value.setHomeWallpaper) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
|
||||
selectedState.value.selectedAlbum?.let {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
}
|
||||
scheduler.cancelWallpaperAlarm()
|
||||
}
|
||||
else if (selectedState.value.selectedAlbum!= null && (enableLock && !settingsState.value.setHomeWallpaper) || (!enableLock && settingsState.value.setHomeWallpaper)) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetScheduleSeparately(false))
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
timeInMinutes1 = settingsState.value.homeInterval,
|
||||
timeInMinutes2 = settingsState.value.lockInterval,
|
||||
scheduleSeparately = false
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
else if (selectedState.value.selectedAlbum != null && settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
scheduler.updateWallpaper(settingsState.value.scheduleSeparately)
|
||||
}
|
||||
}
|
||||
},
|
||||
onScheduleSeparatelyChange = { changeSeparately ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetScheduleSeparately(changeSeparately))
|
||||
if (selectedState.value.selectedAlbum!= null && settingsState.value.enableChanger) {
|
||||
wallpaperScreenViewModel.onEvent(
|
||||
WallpaperEvent.UpdateSelectedAlbum(
|
||||
selectedState.value.selectedAlbum!!.copy(
|
||||
album = selectedState.value.selectedAlbum!!.album.copy(
|
||||
currentHomeWallpaper = if (settingsState.value.setHomeWallpaper) selectedState.value.selectedAlbum!!.album.homeWallpapersInQueue.firstOrNull() else null,
|
||||
currentLockWallpaper = if (changeSeparately && settingsState.value.setLockWallpaper) selectedState.value.selectedAlbum!!.album.lockWallpapersInQueue.firstOrNull() else if (settingsState.value.setLockWallpaper) selectedState.value.selectedAlbum!!.album.homeWallpapersInQueue.firstOrNull() else null
|
||||
)
|
||||
|
||||
),
|
||||
null,
|
||||
settingsState.value.scheduleSeparately,
|
||||
settingsState.value.setHomeWallpaper,
|
||||
settingsState.value.setLockWallpaper
|
||||
)
|
||||
)
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
timeInMinutes1 = settingsState.value.homeInterval,
|
||||
timeInMinutes2 = settingsState.value.lockInterval,
|
||||
scheduleSeparately = changeSeparately
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
},
|
||||
onBlurChange = {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetBlur(it))
|
||||
if (settingsState.value.enableChanger && (settingsState.value.blur && settingsState.value.blurPercentage > 0)) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
scheduler.updateWallpaper(settingsState.value.scheduleSeparately)
|
||||
}
|
||||
}
|
||||
},
|
||||
onBlurPercentageChange = {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetBlurPercentage(it))
|
||||
if (settingsState.value.enableChanger && settingsState.value.blur) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(2000)
|
||||
scheduler.updateWallpaper(settingsState.value.scheduleSeparately)
|
||||
}
|
||||
}
|
||||
},
|
||||
selectedAlbum = selectedState.value.selectedAlbum
|
||||
)
|
||||
}
|
||||
// Navigate to the add album screen to create a new album and add wallpapers to it
|
||||
composable<AddEdit>(
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) {backStackEntry ->
|
||||
) { backStackEntry ->
|
||||
val addEdit: AddEdit = backStackEntry.toRoute()
|
||||
AddAlbumScreen(
|
||||
initialAlbumName = addEdit.wallpaper,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
onConfirmation = { navController.navigateUp() },
|
||||
onShowWallpaperView = { wallpaper ->
|
||||
navController.navigate(WallpaperView(wallpaper))
|
||||
onShowWallpaperView = {
|
||||
navController.navigate(WallpaperView(it))
|
||||
},
|
||||
onShowFolderView = { folderName, wallpapers ->
|
||||
navController.navigate(FolderView(folderName, wallpapers))
|
||||
@@ -253,17 +564,25 @@ fun PaperizeApp(
|
||||
// Navigate to wallpaper view screen to view individual wallpapers in full screen
|
||||
composable<WallpaperView> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) { backStackEntry ->
|
||||
val wallpaperView: WallpaperView = backStackEntry.toRoute()
|
||||
WallpaperViewScreen(
|
||||
@@ -272,46 +591,63 @@ fun PaperizeApp(
|
||||
animate = settingsState.value.animate
|
||||
)
|
||||
}
|
||||
// Navigate to folder view screen to view wallpapers in a particular folder
|
||||
composable<FolderView> (
|
||||
composable<FolderView>(
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) { backStackEntry ->
|
||||
val folderView: FolderView = backStackEntry.toRoute()
|
||||
FolderViewScreen(
|
||||
folderName = folderView.folderName,
|
||||
wallpapers = folderView.wallpapers,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
onShowWallpaperView = {
|
||||
navController.navigate(WallpaperView(it))
|
||||
},
|
||||
animate = settingsState.value.animate
|
||||
)
|
||||
if (folderView.wallpapers.isNotEmpty()) {
|
||||
FolderViewScreen(
|
||||
folderName = folderView.folderName,
|
||||
wallpapers = folderView.wallpapers,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
onShowWallpaperView = {
|
||||
navController.navigate(WallpaperView(it))
|
||||
},
|
||||
animate = settingsState.value.animate
|
||||
)
|
||||
} else { navController.navigateUp() }
|
||||
}
|
||||
// Navigate to the album view screen to view folders and wallpapers in an album
|
||||
composable<AlbumView> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) { backStackEntry ->
|
||||
val albumView: AlbumView = backStackEntry.toRoute()
|
||||
val albumWithWallpaper = albumState.value.albumsWithWallpapers.find { it.album.initialAlbumName == albumView.initialAlbumName }
|
||||
@@ -326,8 +662,8 @@ fun PaperizeApp(
|
||||
navController.navigate(FolderView(folderName, wallpapers))
|
||||
},
|
||||
onDeleteAlbum = {
|
||||
albumsViewModel.onEvent(AlbumsEvent.DeleteAlbumWithWallpapers(albumWithWallpaper))
|
||||
navController.navigateUp()
|
||||
albumsViewModel.onEvent(AlbumsEvent.DeleteAlbumWithWallpapers(albumWithWallpaper))
|
||||
},
|
||||
onTitleChange = { title, originalAlbumWithWallpaper ->
|
||||
albumsViewModel.onEvent(AlbumsEvent.ChangeAlbumName(title, originalAlbumWithWallpaper))
|
||||
@@ -341,20 +677,29 @@ fun PaperizeApp(
|
||||
// Navigate to the settings screen to change app settings
|
||||
composable<Settings> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) {
|
||||
SettingsScreen(
|
||||
settingsState = settingsViewModel.state,
|
||||
topInsets = topInsets,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
onDarkModeClick = {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetDarkMode(it))
|
||||
@@ -372,17 +717,11 @@ fun PaperizeApp(
|
||||
navController.navigate(Licenses)
|
||||
},
|
||||
onResetClick = {
|
||||
navController.navigate(Startup) {
|
||||
popUpTo<Settings> { inclusive = true }
|
||||
}
|
||||
settingsViewModel.onEvent(SettingsEvent.Reset)
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
albumsViewModel.onEvent(AlbumsEvent.Reset)
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.Reset)
|
||||
Intent(context, WallpaperService::class.java).also {
|
||||
it.action = WallpaperService.Actions.STOP.toString()
|
||||
context.startForegroundService(it)
|
||||
}
|
||||
scheduler.cancelWallpaperAlarm()
|
||||
val contentResolver = context.contentResolver
|
||||
val persistedUris = contentResolver.persistedUriPermissions
|
||||
for (permission in persistedUris) {
|
||||
@@ -394,38 +733,56 @@ fun PaperizeApp(
|
||||
// Navigate to the privacy screen to view the privacy policy
|
||||
composable<Privacy> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) {
|
||||
PrivacyScreen(
|
||||
topInsets = topInsets,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
)
|
||||
}
|
||||
// Navigate to the licenses screen to view the licenses of the libraries used
|
||||
composable<Licenses> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
}
|
||||
) {
|
||||
LicensesScreen(
|
||||
topInsets = topInsets,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumAnimatedFab
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumFabMenuOptions
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumSmallTopBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.FolderItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
|
||||
@@ -54,16 +53,15 @@ fun AddAlbumScreen(
|
||||
if (addAlbumState.value.initialAlbumName.isEmpty()) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.SetAlbumName(initialAlbumName))
|
||||
}
|
||||
var showSpotlight by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
BackHandler {
|
||||
if (selectionMode) {
|
||||
selectionMode = false
|
||||
BackHandler(
|
||||
enabled = selectionMode,
|
||||
onBack = {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
|
||||
} else {
|
||||
onBackClick()
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.Reset)
|
||||
selectionMode = false
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/** Image picker **/
|
||||
val imagePickerLauncher = rememberLauncherForActivityResult(
|
||||
@@ -103,11 +101,14 @@ fun AddAlbumScreen(
|
||||
isEmpty = addAlbumState.value.isEmpty,
|
||||
selectionMode = selectionMode,
|
||||
albumState = addAlbumViewModel.state,
|
||||
showSpotlight = showSpotlight,
|
||||
onBackClick = {
|
||||
showSpotlight = false
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.Reset)
|
||||
onBackClick()
|
||||
},
|
||||
onConfirmationClick = {
|
||||
showSpotlight = false
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.ReflectAlbumName(it))
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.SaveAlbum)
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.Reset)
|
||||
@@ -132,7 +133,6 @@ fun AddAlbumScreen(
|
||||
exit = scaleOut(tween(400, 50, FastOutSlowInEasing)),
|
||||
) {
|
||||
AddAlbumAnimatedFab(
|
||||
menuOptions = AddAlbumFabMenuOptions(),
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
@@ -147,14 +147,15 @@ fun AddAlbumScreen(
|
||||
}
|
||||
else {
|
||||
AddAlbumAnimatedFab(
|
||||
menuOptions = AddAlbumFabMenuOptions(),
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
showSpotlight = true
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
showSpotlight = true
|
||||
},
|
||||
animate = false
|
||||
)
|
||||
@@ -170,7 +171,7 @@ fun AddAlbumScreen(
|
||||
contentPadding = PaddingValues(4.dp, 4.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
content = {
|
||||
items (items = addAlbumState.value.folders, key = { folder -> folder.folderUri.hashCode()}
|
||||
items (items = addAlbumState.value.folders, key = { folder -> folder.folderUri }
|
||||
) { folder ->
|
||||
FolderItem(
|
||||
folder = folder,
|
||||
@@ -187,7 +188,7 @@ fun AddAlbumScreen(
|
||||
)
|
||||
},
|
||||
onFolderViewClick = {
|
||||
onShowFolderView(folder.folderName, folder.wallpapers)
|
||||
if (folder.wallpapers.isNotEmpty()) onShowFolderView(folder.folderName, folder.wallpapers)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
@@ -198,7 +199,7 @@ fun AddAlbumScreen(
|
||||
)
|
||||
)
|
||||
}
|
||||
items (items = addAlbumState.value.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri.hashCode()}
|
||||
items (items = addAlbumState.value.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri }
|
||||
) { wallpaper ->
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper.wallpaperUri,
|
||||
|
||||
@@ -3,16 +3,15 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.core.getFolderNameFromUri
|
||||
import com.anthonyla.paperize.core.getWallpaperFromFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import com.lazygeniouz.dfc.file.DocumentFileCompat
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
@@ -59,8 +58,6 @@ class AddAlbumViewModel @Inject constructor(
|
||||
folders = _state.value.folders,
|
||||
)
|
||||
repository.upsertAlbumWithWallpaperAndFolder(albumWithWallpaperAndFolder)
|
||||
|
||||
//Clear viewModel state after adding album
|
||||
_state.update { it.copy(
|
||||
initialAlbumName = "",
|
||||
displayedAlbumName = "",
|
||||
@@ -77,13 +74,14 @@ class AddAlbumViewModel @Inject constructor(
|
||||
}
|
||||
is AddAlbumEvent.DeleteSelected -> {
|
||||
viewModelScope.launch {
|
||||
val wallpapersRemoved = _state.value.wallpapers.filterNot { it.wallpaperUri in _state.value.selectedWallpapers }
|
||||
val foldersRemoved = _state.value.folders.filterNot { it.folderUri in _state.value.selectedFolders }
|
||||
_state.update { it.copy(
|
||||
wallpapers = wallpapersRemoved,
|
||||
folders = foldersRemoved
|
||||
) }
|
||||
updateIsEmpty()
|
||||
_state.update {
|
||||
val wallpapersRemoved = it.wallpapers.filterNot { it.wallpaperUri in _state.value.selectedWallpapers }
|
||||
val foldersRemoved = it.folders.filterNot { it.folderUri in _state.value.selectedFolders }
|
||||
it.copy(
|
||||
wallpapers = wallpapersRemoved,
|
||||
folders = foldersRemoved,
|
||||
isEmpty = wallpapersRemoved.isEmpty() && foldersRemoved.isEmpty()
|
||||
) }
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.SetAlbumName -> {
|
||||
@@ -98,18 +96,21 @@ class AddAlbumViewModel @Inject constructor(
|
||||
is AddAlbumEvent.ReflectAlbumName -> {
|
||||
if (event.newAlbumName != _state.value.initialAlbumName) {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
initialAlbumName = event.newAlbumName,
|
||||
displayedAlbumName = event.newAlbumName,
|
||||
coverUri = it.coverUri,
|
||||
wallpapers = it.wallpapers.map { wallpaper ->
|
||||
_state.update {
|
||||
val wallpapers = it.wallpapers.map { wallpaper ->
|
||||
wallpaper.copy(initialAlbumName = event.newAlbumName)
|
||||
},
|
||||
folders = it.folders.map { folder ->
|
||||
}
|
||||
val folders = it.folders.map { folder ->
|
||||
folder.copy(initialAlbumName = event.newAlbumName)
|
||||
},
|
||||
) }
|
||||
updateIsEmpty()
|
||||
}
|
||||
it.copy(
|
||||
initialAlbumName = event.newAlbumName,
|
||||
displayedAlbumName = event.newAlbumName,
|
||||
coverUri = it.coverUri,
|
||||
wallpapers = wallpapers,
|
||||
folders = folders,
|
||||
isEmpty = wallpapers.isEmpty() && folders.isEmpty()
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,6 +140,7 @@ class AddAlbumViewModel @Inject constructor(
|
||||
viewModelScope.launch {
|
||||
if (event.directoryUri !in _state.value.folders.map { it.folderUri }) {
|
||||
val wallpapers: List<String> = getWallpaperFromFolder(event.directoryUri, context)
|
||||
if (wallpapers.isEmpty()) { return@launch }
|
||||
val folderName = getFolderNameFromUri(event.directoryUri, context)
|
||||
_state.update {
|
||||
it.copy(
|
||||
@@ -168,9 +170,9 @@ class AddAlbumViewModel @Inject constructor(
|
||||
_state.update { it.copy(
|
||||
selectedFolders = _state.value.folders.map { folder -> folder.folderUri },
|
||||
selectedWallpapers = _state.value.wallpapers.map { wallpaper -> wallpaper.wallpaperUri },
|
||||
selectedCount = it.folders.size + it.wallpapers.size
|
||||
selectedCount = it.folders.size + it.wallpapers.size,
|
||||
allSelected = true
|
||||
) }
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -187,44 +189,53 @@ class AddAlbumViewModel @Inject constructor(
|
||||
is AddAlbumEvent.SelectFolder -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.selectedFolders.any { it == event.directoryUri }) {
|
||||
_state.update { it.copy(
|
||||
selectedFolders = it.selectedFolders.plus(event.directoryUri),
|
||||
selectedCount = it.selectedCount + 1
|
||||
) }
|
||||
updateAllSelected()
|
||||
_state.update {
|
||||
val folders = it.selectedFolders.plus(event.directoryUri)
|
||||
it.copy(
|
||||
selectedFolders = folders,
|
||||
selectedCount = it.selectedCount + 1,
|
||||
allSelected = folders.size + it.selectedWallpapers.size >= it.wallpapers.size + it.folders.size
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.SelectWallpaper -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.selectedWallpapers.any { it == event.wallpaperUri }) {
|
||||
_state.update { it.copy(
|
||||
selectedWallpapers = it.selectedWallpapers.plus(event.wallpaperUri),
|
||||
selectedCount = it.selectedCount + 1
|
||||
) }
|
||||
updateAllSelected()
|
||||
_state.update {
|
||||
val wallpapers = it.selectedWallpapers.plus(event.wallpaperUri)
|
||||
it.copy(
|
||||
selectedWallpapers = wallpapers,
|
||||
selectedCount = it.selectedCount + 1,
|
||||
allSelected = it.selectedFolders.size + wallpapers.size >= it.wallpapers.size + it.folders.size
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.RemoveFolderFromSelection -> {
|
||||
viewModelScope.launch {
|
||||
if (_state.value.selectedFolders.find { it == event.directoryUri } != null ) {
|
||||
_state.update { it.copy(
|
||||
selectedFolders = it.selectedFolders.minus(event.directoryUri),
|
||||
selectedCount = it.selectedCount - 1
|
||||
) }
|
||||
updateAllSelected()
|
||||
_state.update {
|
||||
val folders = it.selectedFolders.minus(event.directoryUri)
|
||||
it.copy(
|
||||
selectedFolders = folders,
|
||||
selectedCount = it.selectedCount - 1,
|
||||
allSelected = folders.size + it.selectedWallpapers.size >= it.wallpapers.size + it.folders.size
|
||||
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.RemoveWallpaperFromSelection -> {
|
||||
viewModelScope.launch {
|
||||
if (_state.value.selectedWallpapers.find { it == event.wallpaperUri } != null ) {
|
||||
_state.update { it.copy(
|
||||
selectedWallpapers = it.selectedWallpapers.minus(event.wallpaperUri),
|
||||
selectedCount = it.selectedCount - 1
|
||||
) }
|
||||
updateAllSelected()
|
||||
_state.update {
|
||||
val wallpapers = it.selectedWallpapers.minus(event.wallpaperUri)
|
||||
it.copy(
|
||||
selectedWallpapers = wallpapers,
|
||||
selectedCount = it.selectedCount - 1,
|
||||
allSelected = it.selectedFolders.size + wallpapers.size >= it.wallpapers.size + it.folders.size
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,45 +257,4 @@ class AddAlbumViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateIsEmpty() {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
isEmpty = it.wallpapers.isEmpty() && it.folders.isEmpty()
|
||||
) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateAllSelected() {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
allSelected = it.selectedFolders.size + it.selectedWallpapers.size >= it.wallpapers.size + it.folders.size
|
||||
) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
|
||||
val folderDocumentFile = DocumentFileCompat.fromTreeUri(context, folderUri.toUri())
|
||||
return listFilesRecursive(folderDocumentFile, context)
|
||||
}
|
||||
|
||||
private fun listFilesRecursive(parent: DocumentFileCompat?, context: Context): List<String> {
|
||||
val files = mutableListOf<String>()
|
||||
parent?.listFiles()?.forEach { file ->
|
||||
if (file.isDirectory()) {
|
||||
files.addAll(listFilesRecursive(file, context))
|
||||
} else {
|
||||
val extension = MimeTypeMap.getFileExtensionFromUrl(file.uri.toString())
|
||||
val allowedExtensions = listOf("jpg", "png", "heif", "webp")
|
||||
if (extension in allowedExtensions) {
|
||||
files.add(file.uri.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
private fun getFolderNameFromUri(folderUri: String, context: Context): String? {
|
||||
return DocumentFileCompat.fromTreeUri(context, folderUri.toUri())?.name
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@ import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.Folder
|
||||
import androidx.compose.material.icons.filled.PhotoLibrary
|
||||
import androidx.compose.material.icons.filled.Remove
|
||||
import androidx.compose.material3.CardColors
|
||||
import androidx.compose.material3.ElevatedCard
|
||||
@@ -49,7 +51,6 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.comp
|
||||
*/
|
||||
@Composable
|
||||
fun AddAlbumAnimatedFab(
|
||||
menuOptions: AddAlbumFabMenuOptions,
|
||||
animate: Boolean,
|
||||
onImageClick: () -> Unit,
|
||||
onFolderClick: () -> Unit
|
||||
@@ -59,7 +60,7 @@ fun AddAlbumAnimatedFab(
|
||||
|
||||
BackHandler(expanded) { expanded = false }
|
||||
|
||||
val expandHorizontalSize = Pair(155.dp, 90.dp)
|
||||
val expandHorizontalSize = Pair(165.dp, 90.dp)
|
||||
val expandHorizontally by fabTransition.animateDp(
|
||||
transitionSpec = { spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow) }, label = "",
|
||||
targetValueByState = { isExpanded ->
|
||||
@@ -108,8 +109,8 @@ fun AddAlbumAnimatedFab(
|
||||
Surface(tonalElevation = 5.dp) {
|
||||
Column(modifier = Modifier.height(menuHeight)) {
|
||||
MenuRow(
|
||||
text = menuOptions.imageOption.text,
|
||||
icon = menuOptions.imageOption.icon,
|
||||
text = stringResource(R.string.add_images_btn),
|
||||
icon = Icons.Filled.PhotoLibrary,
|
||||
horizontalExpansion = expandHorizontally,
|
||||
onClick = {
|
||||
expanded = false
|
||||
@@ -117,8 +118,8 @@ fun AddAlbumAnimatedFab(
|
||||
}
|
||||
)
|
||||
MenuRow(
|
||||
text = menuOptions.folderOption.text,
|
||||
icon = menuOptions.folderOption.icon,
|
||||
text = stringResource(R.string.add_folder_btn),
|
||||
icon = Icons.Filled.Folder,
|
||||
horizontalExpansion = expandHorizontally,
|
||||
onClick = {
|
||||
expanded = false
|
||||
@@ -174,8 +175,8 @@ fun AddAlbumAnimatedFab(
|
||||
Surface(tonalElevation = 5.dp) {
|
||||
Column(modifier = Modifier.height(if (expanded) menuHeightSize.first else menuHeightSize.second)) {
|
||||
MenuRow(
|
||||
text = menuOptions.imageOption.text,
|
||||
icon = menuOptions.imageOption.icon,
|
||||
text = stringResource(R.string.add_images_btn),
|
||||
icon = Icons.Filled.PhotoLibrary,
|
||||
horizontalExpansion = if (expanded) expandHorizontalSize.first else expandHorizontalSize.second,
|
||||
onClick = {
|
||||
expanded = false
|
||||
@@ -183,8 +184,8 @@ fun AddAlbumAnimatedFab(
|
||||
}
|
||||
)
|
||||
MenuRow(
|
||||
text = menuOptions.folderOption.text,
|
||||
icon = menuOptions.folderOption.icon,
|
||||
text = stringResource(R.string.add_folder_btn),
|
||||
icon = Icons.Filled.Folder,
|
||||
horizontalExpansion = if (expanded) expandHorizontalSize.first else expandHorizontalSize.second,
|
||||
onClick = {
|
||||
expanded = false
|
||||
|
||||
@@ -60,7 +60,7 @@ fun AddAlbumDialog(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Text(
|
||||
text = "New Album",
|
||||
text = stringResource(R.string.new_album),
|
||||
modifier = Modifier.padding(20.dp),
|
||||
fontSize = 25.sp
|
||||
)
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Folder
|
||||
import androidx.compose.material.icons.filled.PhotoLibrary
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components.SelectionOptions
|
||||
|
||||
/**
|
||||
* Options for the FAB menu in the Add Album screen
|
||||
*/
|
||||
data class AddAlbumFabMenuOptions (
|
||||
val imageOption: SelectionOptions = SelectionOptions("add_images", "Add Image", null, Icons.Filled.PhotoLibrary),
|
||||
val folderOption: SelectionOptions = SelectionOptions("add_folder", "Add Folder", null, Icons.Filled.Folder)
|
||||
)
|
||||
@@ -1,8 +1,16 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components
|
||||
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.RepeatMode
|
||||
import androidx.compose.animation.core.animateFloat
|
||||
import androidx.compose.animation.core.infiniteRepeatable
|
||||
import androidx.compose.animation.core.rememberInfiniteTransition
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.requiredSize
|
||||
@@ -33,7 +41,9 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
@@ -54,17 +64,44 @@ fun AddAlbumSmallTopBar(
|
||||
title: String,
|
||||
isEmpty: Boolean,
|
||||
selectionMode: Boolean,
|
||||
showSpotlight: Boolean,
|
||||
onSelectAllClick: () -> Unit,
|
||||
onBackClick: () -> Unit,
|
||||
onDeleteSelected: () -> Unit,
|
||||
onConfirmationClick: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
onConfirmationClick: (String) -> Unit
|
||||
) {
|
||||
val state = albumState.collectAsStateWithLifecycle()
|
||||
val focusManager = LocalFocusManager.current
|
||||
var editableTitle by rememberSaveable { mutableStateOf(title) }
|
||||
var showSelectionDeleteDialog by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
val infiniteTransition = rememberInfiniteTransition(label = stringResource(R.string.spotlight_animation))
|
||||
val radius1 by infiniteTransition.animateFloat(
|
||||
initialValue = 25f,
|
||||
targetValue = 50f,
|
||||
animationSpec = infiniteRepeatable(
|
||||
animation = tween(2000, easing = LinearOutSlowInEasing),
|
||||
repeatMode = RepeatMode.Reverse
|
||||
), label = stringResource(R.string.circle_1_animation)
|
||||
)
|
||||
val radius2 by infiniteTransition.animateFloat(
|
||||
initialValue = 25f,
|
||||
targetValue = 60f,
|
||||
animationSpec = infiniteRepeatable(
|
||||
animation = tween(2000, easing = LinearOutSlowInEasing),
|
||||
repeatMode = RepeatMode.Reverse
|
||||
), label = stringResource(R.string.circle_2_animation)
|
||||
)
|
||||
|
||||
val radius3 by infiniteTransition.animateFloat(
|
||||
initialValue = 25f,
|
||||
targetValue = 75f,
|
||||
animationSpec = infiniteRepeatable(
|
||||
animation = tween(2000, easing = LinearOutSlowInEasing),
|
||||
repeatMode = RepeatMode.Reverse
|
||||
), label = stringResource(R.string.circle_3_animation)
|
||||
)
|
||||
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||
title = {
|
||||
@@ -109,9 +146,7 @@ fun AddAlbumSmallTopBar(
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
IconButton(
|
||||
onClick = onSelectAllClick
|
||||
) {
|
||||
IconButton(onClick = onSelectAllClick) {
|
||||
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
if (state.value.allSelected) {
|
||||
Icon(
|
||||
@@ -138,13 +173,39 @@ fun AddAlbumSmallTopBar(
|
||||
},
|
||||
actions = {
|
||||
if(!selectionMode) {
|
||||
if (!isEmpty) {
|
||||
IconButton(onClick = { onConfirmationClick(editableTitle) }) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Add,
|
||||
contentDescription = stringResource(R.string.add_album),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
if (!isEmpty && editableTitle.isNotEmpty()) {
|
||||
Box {
|
||||
val primaryColor = MaterialTheme.colorScheme.inversePrimary
|
||||
val secondaryColor = MaterialTheme.colorScheme.secondary
|
||||
IconButton(onClick = { onConfirmationClick(editableTitle) }) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Add,
|
||||
contentDescription = stringResource(R.string.add_album),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
}
|
||||
if (!showSpotlight) {
|
||||
Canvas(modifier = Modifier.matchParentSize()) {
|
||||
drawCircle(
|
||||
color = primaryColor,
|
||||
radius = radius1,
|
||||
center = Offset(size.width / 2, size.height / 2),
|
||||
style = Stroke(width = 5f)
|
||||
)
|
||||
drawCircle(
|
||||
color = secondaryColor,
|
||||
radius = radius2,
|
||||
center = Offset(size.width / 2, size.height / 2),
|
||||
style = Stroke(width = 5f)
|
||||
)
|
||||
drawCircle(
|
||||
color = primaryColor,
|
||||
radius = radius3,
|
||||
center = Offset(size.width / 2, size.height / 2),
|
||||
style = Stroke(width = 5f)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,17 +22,17 @@ fun DeleteImagesAlertDialog(
|
||||
icon = {
|
||||
Icon(Icons.Outlined.Delete, contentDescription = stringResource(R.string.delete_confirmation))
|
||||
},
|
||||
title = { Text(text = "Delete these?") },
|
||||
text = { Text(text = "Are you sure you want to delete these wallpapers?") },
|
||||
title = { Text(text = stringResource(R.string.delete_these)) },
|
||||
text = { Text(text = stringResource(R.string.are_you_sure_you_want_to_delete_these_wallpapers)) },
|
||||
onDismissRequest = { onDismissRequest() },
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onConfirmation() }) {
|
||||
Text("Confirm")
|
||||
Text(stringResource(R.string.confirm))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { onDismissRequest() }) {
|
||||
Text("Cancel")
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -2,16 +2,16 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.album
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.core.findFirstValidUri
|
||||
import com.anthonyla.paperize.core.getWallpaperFromFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import com.lazygeniouz.dfc.file.DocumentFileCompat
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.first
|
||||
@@ -34,22 +34,20 @@ class AlbumsViewModel @Inject constructor (
|
||||
)
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
updateAlbums()
|
||||
refreshAlbums()
|
||||
}
|
||||
updateAlbums()
|
||||
refreshAlbums()
|
||||
}
|
||||
|
||||
|
||||
fun onEvent(event: AlbumsEvent) {
|
||||
when (event) {
|
||||
is AlbumsEvent.DeleteAlbumWithWallpapers -> {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.cascadeDeleteAlbum(event.albumWithWallpaperAndFolder.album)
|
||||
}
|
||||
}
|
||||
is AlbumsEvent.ChangeAlbumName -> {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (!(_state.value.albumsWithWallpapers.any { it.album.displayedAlbumName == event.title })) {
|
||||
repository.updateAlbum(
|
||||
event.albumWithWallpaperAndFolder.album.copy(displayedAlbumName = event.title)
|
||||
@@ -58,13 +56,11 @@ class AlbumsViewModel @Inject constructor (
|
||||
}
|
||||
}
|
||||
is AlbumsEvent.RefreshAlbums -> {
|
||||
viewModelScope.launch {
|
||||
updateAlbums()
|
||||
refreshAlbums()
|
||||
}
|
||||
updateAlbums()
|
||||
refreshAlbums()
|
||||
}
|
||||
is AlbumsEvent.InitializeAlbum -> {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.updateAlbum(
|
||||
event.albumWithWallpaperAndFolder.album.copy(
|
||||
initialized = true
|
||||
@@ -73,7 +69,7 @@ class AlbumsViewModel @Inject constructor (
|
||||
}
|
||||
}
|
||||
is AlbumsEvent.Reset -> {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
_state.update { AlbumsState() }
|
||||
repository.deleteAllData()
|
||||
}
|
||||
@@ -85,39 +81,124 @@ class AlbumsViewModel @Inject constructor (
|
||||
* Verify and remove stale data in Room database
|
||||
*/
|
||||
private fun updateAlbums() {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
var albumWithWallpapers = repository.getAlbumsWithWallpaperAndFolder().first()
|
||||
albumWithWallpapers.forEach { albumWithWallpaper ->
|
||||
// Delete wallpaper if the URI is invalid
|
||||
val invalidWallpapers = albumWithWallpaper.wallpapers.filterNot { wallpaper ->
|
||||
val file = DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
|
||||
file?.exists() == true
|
||||
try {
|
||||
val file = DocumentFileCompat.fromSingleUri(
|
||||
context,
|
||||
wallpaper.wallpaperUri.toUri()
|
||||
)
|
||||
file?.exists() == true
|
||||
} catch (e: Exception) {
|
||||
val file =
|
||||
DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
|
||||
file?.exists() == true
|
||||
}
|
||||
}
|
||||
if (invalidWallpapers.isNotEmpty()) {
|
||||
repository.deleteWallpaperList(invalidWallpapers)
|
||||
}
|
||||
|
||||
// Update folder cover uri and children uri
|
||||
// Update folder cover uri and wallpapers uri
|
||||
albumWithWallpaper.folders.forEach { folder ->
|
||||
DocumentFile.fromTreeUri(context, folder.folderUri.toUri())?.let { folderDirectory ->
|
||||
if (!folderDirectory.isDirectory) {
|
||||
repository.deleteFolder(folder)
|
||||
} else {
|
||||
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
|
||||
val folderCoverFile = folder.coverUri?.let { DocumentFile.fromSingleUri(context, it.toUri()) }
|
||||
val folderCover = folderCoverFile?.takeIf { it.exists() }?.uri?.toString() ?: wallpapers.randomOrNull()
|
||||
repository.updateFolder(folder.copy(coverUri = folderCover, wallpapers = wallpapers))
|
||||
}
|
||||
try {
|
||||
DocumentFileCompat.fromTreeUri(context, folder.folderUri.toUri())
|
||||
?.let { folderDirectory ->
|
||||
if (!folderDirectory.isDirectory()) {
|
||||
repository.deleteFolder(folder)
|
||||
} else {
|
||||
val wallpapers =
|
||||
getWallpaperFromFolder(folder.folderUri, context)
|
||||
val folderCoverFile = folder.coverUri?.let {
|
||||
DocumentFileCompat.fromSingleUri(
|
||||
context,
|
||||
it.toUri()
|
||||
)
|
||||
}
|
||||
val folderCover =
|
||||
folderCoverFile?.takeIf { it.exists() }?.uri?.toString()
|
||||
?: wallpapers.randomOrNull()
|
||||
repository.updateFolder(
|
||||
folder.copy(
|
||||
coverUri = folderCover,
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
DocumentFile.fromTreeUri(context, folder.folderUri.toUri())
|
||||
?.let { folderDirectory ->
|
||||
if (!folderDirectory.isDirectory) {
|
||||
repository.deleteFolder(folder)
|
||||
} else {
|
||||
val wallpapers =
|
||||
getWallpaperFromFolder(folder.folderUri, context)
|
||||
try {
|
||||
val folderCoverFile = folder.coverUri?.let {
|
||||
DocumentFileCompat.fromSingleUri(
|
||||
context,
|
||||
it.toUri()
|
||||
)
|
||||
}
|
||||
val folderCover =
|
||||
folderCoverFile?.takeIf { it.exists() }?.uri?.toString()
|
||||
?: wallpapers.randomOrNull()
|
||||
repository.updateFolder(
|
||||
folder.copy(
|
||||
coverUri = folderCover,
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
val folderCoverFile = folder.coverUri?.let {
|
||||
DocumentFile.fromSingleUri(
|
||||
context,
|
||||
it.toUri()
|
||||
)
|
||||
}
|
||||
val folderCover =
|
||||
folderCoverFile?.takeIf { it.exists() }?.uri?.toString()
|
||||
?: wallpapers.randomOrNull()
|
||||
repository.updateFolder(
|
||||
folder.copy(
|
||||
coverUri = folderCover,
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
albumWithWallpapers = repository.getAlbumsWithWallpaperAndFolder().first()
|
||||
albumWithWallpapers.forEach { albumWithWallpaper ->
|
||||
// Update album cover uri if null or invalid
|
||||
val albumCoverFile = albumWithWallpaper.album.coverUri?.toUri()?.let { DocumentFile.fromSingleUri(context, it) }
|
||||
if (albumCoverFile == null || !albumCoverFile.exists()) {
|
||||
val newCoverUri = findFirstValidUri(albumWithWallpaper.wallpapers, albumWithWallpaper.folders)
|
||||
repository.updateAlbum(albumWithWallpaper.album.copy(coverUri = newCoverUri))
|
||||
albumWithWallpapers = repository.getAlbumsWithWallpaperAndFolder().first()
|
||||
albumWithWallpapers.forEach { album ->
|
||||
// Delete empty albums
|
||||
if (album.wallpapers.isEmpty() && album.folders.all { it.wallpapers.isEmpty() }) {
|
||||
repository.deleteAlbum(album.album)
|
||||
} else {
|
||||
// Update album cover uri if null or invalid
|
||||
try {
|
||||
val albumCoverFile = album.album.coverUri?.toUri()
|
||||
?.let { DocumentFileCompat.fromSingleUri(context, it) }
|
||||
if (albumCoverFile == null || !albumCoverFile.exists()) {
|
||||
val newCoverUri =
|
||||
findFirstValidUri(context, album.wallpapers, album.folders)
|
||||
repository.updateAlbum(album.album.copy(coverUri = newCoverUri))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
val albumCoverFile = album.album.coverUri?.toUri()
|
||||
?.let { DocumentFile.fromSingleUri(context, it) }
|
||||
if (albumCoverFile == null || !albumCoverFile.exists()) {
|
||||
val newCoverUri =
|
||||
findFirstValidUri(context, album.wallpapers, album.folders)
|
||||
repository.updateAlbum(album.album.copy(coverUri = newCoverUri))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,7 +208,7 @@ class AlbumsViewModel @Inject constructor (
|
||||
* Retrieve albums from database into viewModel
|
||||
*/
|
||||
private fun refreshAlbums() {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.getAlbumsWithWallpaperAndFolder().collect { albumWithWallpapers ->
|
||||
_state.update { it.copy(
|
||||
albumsWithWallpapers = albumWithWallpapers
|
||||
@@ -135,54 +216,5 @@ class AlbumsViewModel @Inject constructor (
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve wallpaper URIs from a folder directory URI
|
||||
*/
|
||||
private fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
|
||||
val folderDocumentFile = DocumentFileCompat.fromTreeUri(context, folderUri.toUri())
|
||||
return listFilesRecursive(folderDocumentFile, context)
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to recursively list files in a directory
|
||||
*/
|
||||
private fun listFilesRecursive(parent: DocumentFileCompat?, context: Context): List<String> {
|
||||
val files = mutableListOf<String>()
|
||||
parent?.listFiles()?.forEach { file ->
|
||||
if (file.isDirectory()) {
|
||||
files.addAll(listFilesRecursive(file, context))
|
||||
} else {
|
||||
val extension = MimeTypeMap.getFileExtensionFromUrl(file.uri.toString())
|
||||
val allowedExtensions = listOf("jpg", "png", "heif", "webp")
|
||||
if (extension in allowedExtensions) {
|
||||
files.add(file.uri.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to find the first valid URI from a list of wallpapers
|
||||
* It will search through all wallpapers of an album first, and then all wallpapers of every folder of an album
|
||||
*/
|
||||
private fun findFirstValidUri(wallpapers: List<Wallpaper>, folders: List<Folder>): String? {
|
||||
wallpapers.forEach { wallpaper ->
|
||||
val file = DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
|
||||
if (file?.exists() == true) {
|
||||
return wallpaper.wallpaperUri
|
||||
}
|
||||
}
|
||||
folders.forEach { folder ->
|
||||
folder.wallpapers.forEach { wallpaper ->
|
||||
val file = DocumentFile.fromSingleUri(context, wallpaper.toUri())
|
||||
if (file?.exists() == true) {
|
||||
return wallpaper
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,11 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
|
||||
@@ -70,14 +69,9 @@ fun AlbumItem(
|
||||
imageModel = { album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(300, 300),
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
@@ -98,7 +92,8 @@ fun AlbumItem(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 24.dp)
|
||||
.align(Alignment.Start),
|
||||
fontSize = 16.sp
|
||||
fontSize = 16.sp,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
Spacer(modifier = Modifier.padding(8.dp))
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
@@ -38,13 +38,12 @@ import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
|
||||
@@ -96,8 +95,11 @@ fun FolderItem(
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (!selectionMode) { onFolderViewClick() }
|
||||
else { onItemSelection() }
|
||||
if (!selectionMode) {
|
||||
onFolderViewClick()
|
||||
} else {
|
||||
onItemSelection()
|
||||
}
|
||||
},
|
||||
onLongClick = {
|
||||
if (!selectionMode) {
|
||||
@@ -119,14 +121,9 @@ fun FolderItem(
|
||||
imageModel = { folder.coverUri?.toUri() },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(300, 300),
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
@@ -135,7 +132,7 @@ fun FolderItem(
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.height(configuration.screenHeightDp.dp / 4.0f)
|
||||
.aspectRatio(0.8f)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
)
|
||||
}
|
||||
@@ -167,16 +164,18 @@ fun FolderItem(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 24.dp)
|
||||
.align(Alignment.Start),
|
||||
fontSize = 16.sp
|
||||
fontSize = 16.sp,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = folder.wallpapers.size.toString().plus(" wallpapers"),
|
||||
text = folder.wallpapers.size.toString().plus(" " + stringResource(R.string.wallpapers)),
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 24.dp)
|
||||
.align(Alignment.Start),
|
||||
fontSize = 12.sp,
|
||||
color = MaterialTheme.colorScheme.tertiary
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
Spacer(modifier = Modifier.padding(8.dp))
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.net.Uri
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
@@ -26,19 +23,25 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.blur
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.BlendMode
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.times
|
||||
import androidx.core.net.toUri
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.core.getImageDimensions
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions
|
||||
import com.bumptech.glide.load.DecodeFormat
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
|
||||
@@ -55,10 +58,14 @@ fun WallpaperItem(
|
||||
onItemSelection: () -> Unit,
|
||||
onWallpaperViewClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
wallpaperDrawable : Bitmap? = null,
|
||||
aspectRatio: Float? = null,
|
||||
clickable: Boolean = true,
|
||||
animate: Boolean = true
|
||||
animate: Boolean = true,
|
||||
darken: Boolean = false,
|
||||
darkenPercentage: Int? = null,
|
||||
blur: Boolean = false,
|
||||
blurPercentage: Int? = null,
|
||||
scaling: ScalingConstants? = null
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val haptics = LocalHapticFeedback.current
|
||||
@@ -89,8 +96,11 @@ fun WallpaperItem(
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (!selectionMode) { onWallpaperViewClick() }
|
||||
else { onItemSelection() }
|
||||
if (!selectionMode) {
|
||||
onWallpaperViewClick()
|
||||
} else {
|
||||
onItemSelection()
|
||||
}
|
||||
},
|
||||
onLongClick = {
|
||||
if (!selectionMode) {
|
||||
@@ -107,20 +117,27 @@ fun WallpaperItem(
|
||||
}
|
||||
Box(modifier = boxModifier) {
|
||||
if (showUri) {
|
||||
val dimension = wallpaperDrawable?.let { Pair(it.width, it.height) } ?: wallpaperUri.toUri().getImageDimensions(context)
|
||||
val imageAspectRatio = aspectRatio ?: (dimension.first.toFloat() / dimension.second.toFloat())
|
||||
val dimension = wallpaperUri.toUri().getImageDimensions(context)
|
||||
val imageAspectRatio = aspectRatio ?: ((dimension?.width?.toFloat() ?: 9f) / (dimension?.height?.toFloat() ?: 19.5f))
|
||||
GlideImage(
|
||||
imageModel = { wallpaperDrawable ?: wallpaperUri.toUri() },
|
||||
imageModel = { wallpaperUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center
|
||||
contentScale = if (scaling != null) {
|
||||
when (scaling) {
|
||||
ScalingConstants.FILL -> ContentScale.FillHeight
|
||||
ScalingConstants.FIT -> ContentScale.FillWidth
|
||||
ScalingConstants.STRETCH -> ContentScale.FillBounds
|
||||
}
|
||||
} else { ContentScale.Crop },
|
||||
requestSize = IntSize(300, 300),
|
||||
alignment = Alignment.Center,
|
||||
colorFilter = if (darken && darkenPercentage != null && darkenPercentage < 100) {
|
||||
ColorFilter.tint(
|
||||
Color.Black.copy(alpha = (100 - darkenPercentage).toFloat().div(100f)),
|
||||
BlendMode.Darken
|
||||
)
|
||||
} else { null }
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
@@ -128,7 +145,20 @@ fun WallpaperItem(
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier.aspectRatio(imageAspectRatio)
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.format(DecodeFormat.PREFER_RGB_565)
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(imageAspectRatio)
|
||||
.background(if (scaling != null) Color.Black else Color.Transparent)
|
||||
.blur(
|
||||
if (blur && blurPercentage != null && blurPercentage > 0 ) {
|
||||
blurPercentage.toFloat().div(100f) * 1.5.dp
|
||||
} else { 0.dp })
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
)
|
||||
}
|
||||
if (selectionMode) {
|
||||
@@ -153,23 +183,4 @@ fun WallpaperItem(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Uri.getImageDimensions(context: Context): Pair<Int, Int> {
|
||||
val inputStream = context.contentResolver.openInputStream(this)!!
|
||||
val exif = ExifInterface(inputStream)
|
||||
|
||||
var width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0)
|
||||
var height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0)
|
||||
|
||||
if (width == 0 || height == 0) {
|
||||
val options = BitmapFactory.Options().apply {
|
||||
inJustDecodeBounds = true
|
||||
}
|
||||
BitmapFactory.decodeStream(context.contentResolver.openInputStream(this), null, options)
|
||||
width = options.outWidth
|
||||
height = options.outHeight
|
||||
}
|
||||
|
||||
return Pair(width, height)
|
||||
}
|
||||
@@ -31,7 +31,6 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumAnimatedFab
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumFabMenuOptions
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.FolderItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen.components.AlbumViewTopBar
|
||||
@@ -87,15 +86,13 @@ fun AlbumViewScreen(
|
||||
}
|
||||
)
|
||||
|
||||
BackHandler {
|
||||
if (selectionMode) {
|
||||
selectionMode = false
|
||||
BackHandler(
|
||||
enabled = selectionMode,
|
||||
onBack = {
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
} else {
|
||||
onBackClick()
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.ClearState)
|
||||
selectionMode = false
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
@@ -129,7 +126,6 @@ fun AlbumViewScreen(
|
||||
exit = scaleOut(tween(400, 50, FastOutSlowInEasing)),
|
||||
) {
|
||||
AddAlbumAnimatedFab(
|
||||
menuOptions = AddAlbumFabMenuOptions(),
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
@@ -144,7 +140,6 @@ fun AlbumViewScreen(
|
||||
}
|
||||
else {
|
||||
AddAlbumAnimatedFab(
|
||||
menuOptions = AddAlbumFabMenuOptions(),
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
@@ -167,7 +162,7 @@ fun AlbumViewScreen(
|
||||
contentPadding = PaddingValues(4.dp, 4.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
content = {
|
||||
items (items = album.folders, key = { folder -> folder.folderUri.hashCode() }
|
||||
items (items = album.folders, key = { folder -> folder.folderUri }
|
||||
) { folder ->
|
||||
if (settingsState.value.animate) {
|
||||
FolderItem(
|
||||
@@ -185,7 +180,7 @@ fun AlbumViewScreen(
|
||||
)
|
||||
},
|
||||
onFolderViewClick = {
|
||||
onShowFolderView(folder.folderName, folder.wallpapers)
|
||||
if (folder.wallpapers.isNotEmpty()) onShowFolderView(folder.folderName, folder.wallpapers)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
@@ -213,14 +208,14 @@ fun AlbumViewScreen(
|
||||
)
|
||||
},
|
||||
onFolderViewClick = {
|
||||
onShowFolderView(folder.folderName, folder.wallpapers)
|
||||
if (folder.wallpapers.isNotEmpty()) onShowFolderView(folder.folderName, folder.wallpapers)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp),
|
||||
animate = false
|
||||
)
|
||||
}
|
||||
}
|
||||
items (items = album.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri.hashCode()}
|
||||
items (items = album.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri }
|
||||
) { wallpaper ->
|
||||
if (settingsState.value.animate) {
|
||||
WallpaperItem(
|
||||
|
||||
@@ -3,14 +3,13 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.core.getFolderNameFromUri
|
||||
import com.anthonyla.paperize.core.getWallpaperFromFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import com.lazygeniouz.dfc.file.DocumentFileCompat
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
@@ -39,10 +38,10 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
event.albumsWithWallpaper.let { album ->
|
||||
val folders = album.folders.filter { _state.value.selectedFolders.contains(it.folderUri)}
|
||||
val wallpapers = album.wallpapers.filter { _state.value.selectedWallpapers.contains(it.wallpaperUri)}
|
||||
val doesContainCover = wallpapers.any { it.wallpaperUri == album.album.coverUri }
|
||||
val containsCoverUri = wallpapers.any { it.wallpaperUri == album.album.coverUri }
|
||||
repository.deleteFolderList(folders)
|
||||
repository.deleteWallpaperList(wallpapers)
|
||||
if (doesContainCover) {
|
||||
if (containsCoverUri) {
|
||||
repository.updateAlbum(album.album.copy(coverUri = null))
|
||||
}
|
||||
}
|
||||
@@ -52,15 +51,15 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
viewModelScope.launch {
|
||||
event.albumsWithWallpaper.let { album ->
|
||||
if (!_state.value.allSelected) {
|
||||
_state.update { state ->
|
||||
state.copy(
|
||||
_state.update { it ->
|
||||
it.copy(
|
||||
selectedFolders = album.folders.map { it.folderUri },
|
||||
selectedWallpapers = album.wallpapers.map { it.wallpaperUri },
|
||||
selectedCount = album.folders.size + album.wallpapers.size,
|
||||
maxSize = album.folders.size + album.wallpapers.size
|
||||
maxSize = album.folders.size + album.wallpapers.size,
|
||||
allSelected = true
|
||||
)
|
||||
}
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,12 +82,13 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.selectedFolders.any { it == event.directoryUri }) {
|
||||
_state.update {
|
||||
val folders = it.selectedFolders.plus(event.directoryUri)
|
||||
it.copy(
|
||||
selectedFolders = it.selectedFolders.plus(event.directoryUri),
|
||||
selectedCount = it.selectedCount + 1
|
||||
selectedFolders = folders,
|
||||
selectedCount = it.selectedCount + 1,
|
||||
allSelected = folders.size + it.selectedWallpapers.size >= it.maxSize
|
||||
)
|
||||
}
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,12 +97,13 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.selectedWallpapers.any { it == event.wallpaperUri }) {
|
||||
_state.update {
|
||||
val wallpapers = it.selectedWallpapers.plus(event.wallpaperUri)
|
||||
it.copy(
|
||||
selectedWallpapers = it.selectedWallpapers.plus(event.wallpaperUri),
|
||||
selectedCount = it.selectedCount + 1
|
||||
selectedCount = it.selectedCount + 1,
|
||||
allSelected = it.selectedFolders.size + wallpapers.size >= it.maxSize
|
||||
)
|
||||
}
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,12 +112,13 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
viewModelScope.launch {
|
||||
if (_state.value.selectedFolders.find { it == event.directoryUri } != null) {
|
||||
_state.update {
|
||||
val folders = it.selectedFolders.minus(event.directoryUri)
|
||||
it.copy(
|
||||
selectedFolders = it.selectedFolders.minus(event.directoryUri),
|
||||
selectedCount = it.selectedCount - 1
|
||||
selectedFolders = folders,
|
||||
selectedCount = it.selectedCount - 1,
|
||||
allSelected = folders.size + it.selectedWallpapers.size >= it.maxSize
|
||||
)
|
||||
}
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,12 +127,13 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
viewModelScope.launch {
|
||||
if (_state.value.selectedWallpapers.find { it == event.wallpaperUri } != null) {
|
||||
_state.update {
|
||||
val wallpapers = it.selectedWallpapers.minus(event.wallpaperUri)
|
||||
it.copy(
|
||||
selectedWallpapers = it.selectedWallpapers.minus(event.wallpaperUri),
|
||||
selectedCount = it.selectedCount - 1
|
||||
selectedWallpapers = wallpapers,
|
||||
selectedCount = it.selectedCount - 1,
|
||||
allSelected = it.selectedFolders.size + wallpapers.size >= it.maxSize
|
||||
)
|
||||
}
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,22 +164,22 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
|
||||
is AlbumViewEvent.AddWallpapers -> {
|
||||
viewModelScope.launch {
|
||||
val newWallpaperUris = event.wallpaperUris.filterNot { it in event.album.wallpapers.map { wallpaper -> wallpaper.wallpaperUri } }
|
||||
val newWallpapers = newWallpaperUris.map { uri ->
|
||||
val wallpaperUris = event.wallpaperUris.filterNot { it in event.album.wallpapers.map { wallpaper -> wallpaper.wallpaperUri } }
|
||||
val wallpapers = wallpaperUris.map { uri ->
|
||||
Wallpaper(
|
||||
initialAlbumName = event.album.album.initialAlbumName,
|
||||
wallpaperUri = uri,
|
||||
key = uri.hashCode() + event.album.album.initialAlbumName.hashCode(),
|
||||
)
|
||||
}
|
||||
repository.upsertWallpaperList(newWallpapers)
|
||||
repository.upsertWallpaperList(wallpapers)
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
maxSize = _state.value.maxSize + newWallpapers.size
|
||||
maxSize = it.maxSize + wallpapers.size
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -186,6 +189,7 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
viewModelScope.launch {
|
||||
if (event.directoryUri !in event.album.folders.map { it.folderUri }) {
|
||||
val wallpapers: List<String> = getWallpaperFromFolder(event.directoryUri, context)
|
||||
if (wallpapers.isEmpty()) { return@launch }
|
||||
val folderName = getFolderNameFromUri(event.directoryUri, context)
|
||||
repository.upsertFolder(
|
||||
Folder(
|
||||
@@ -203,7 +207,7 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
selectedWallpapers = emptyList(),
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
maxSize = _state.value.maxSize + 1
|
||||
maxSize = it.maxSize + 1
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -212,38 +216,4 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateAllSelected() {
|
||||
viewModelScope.launch {
|
||||
_state.update {
|
||||
it.copy(
|
||||
allSelected = it.selectedFolders.size + it.selectedWallpapers.size >= _state.value.maxSize
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
|
||||
val folderDocumentFile = DocumentFileCompat.fromTreeUri(context, folderUri.toUri())
|
||||
return listFilesRecursive(folderDocumentFile, context)
|
||||
}
|
||||
|
||||
private fun listFilesRecursive(parent: DocumentFileCompat?, context: Context): List<String> {
|
||||
val files = mutableListOf<String>()
|
||||
parent?.listFiles()?.forEach { file ->
|
||||
if (file.isDirectory()) {
|
||||
files.addAll(listFilesRecursive(file, context))
|
||||
} else {
|
||||
val extension = MimeTypeMap.getFileExtensionFromUrl(file.uri.toString())
|
||||
val allowedExtensions = listOf("jpg", "png", "heif", "webp")
|
||||
if (extension in allowedExtensions) {
|
||||
files.add(file.uri.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
private fun getFolderNameFromUri(folderUri: String, context: Context): String? {
|
||||
return DocumentFileCompat.fromTreeUri(context, folderUri.toUri())?.name
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,6 @@ fun AlbumViewTopBar(
|
||||
onDeleteAlbum: () -> Unit,
|
||||
onDeleteSelected: () -> Unit,
|
||||
onTitleChange: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val state = albumState.collectAsStateWithLifecycle()
|
||||
var showDeleteAlertDialog by rememberSaveable { mutableStateOf(false) }
|
||||
@@ -109,7 +108,7 @@ fun AlbumViewTopBar(
|
||||
)
|
||||
}
|
||||
}
|
||||
Text("${state.value.selectedCount} selected")
|
||||
Text(stringResource(R.string.selected_count, state.value.selectedCount))
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -22,17 +22,17 @@ fun DeleteAlbumAlertDialog(
|
||||
icon = {
|
||||
Icon(Icons.Outlined.Delete, contentDescription = stringResource(R.string.delete_confirmation))
|
||||
},
|
||||
title = { Text(text = "Delete album?") },
|
||||
text = { Text(text = "Are you sure you want to delete this?") },
|
||||
title = { Text(text = stringResource(R.string.delete_album_question)) },
|
||||
text = { Text(text = stringResource(R.string.are_you_sure_you_want_to_delete_this)) },
|
||||
onDismissRequest = { onDismissRequest() },
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onConfirmation() }) {
|
||||
Text("Confirm")
|
||||
Text(stringResource(R.string.confirm))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { onDismissRequest() }) {
|
||||
Text("Cancel")
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.home_screen
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
@@ -21,45 +19,67 @@ import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumDialog
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components.HomeTopBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components.getTabItems
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.LibraryScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.tabItems
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreen
|
||||
|
||||
@Composable
|
||||
fun HomeScreen(
|
||||
onSettingsClick: () -> Unit,
|
||||
navigateToAddWallpaperScreen: (String) -> Unit,
|
||||
onAlbumViewClick: (String) -> Unit,
|
||||
onScheduleWallpaperChanger: (Int) -> Unit,
|
||||
onSetLockWithHome: (Boolean) -> Unit,
|
||||
onStop: () -> Unit,
|
||||
animate : Boolean,
|
||||
interval: Int,
|
||||
setLockWithHome: Boolean,
|
||||
darken: Boolean,
|
||||
darkenPercentage: Int,
|
||||
enableChanger: Boolean,
|
||||
homeEnabled : Boolean,
|
||||
interval1: Int,
|
||||
interval2: Int,
|
||||
lastSetTime: String?,
|
||||
lockEnabled : Boolean,
|
||||
navigateToAddWallpaperScreen: (String) -> Unit,
|
||||
nextSetTime: String?,
|
||||
selectedAlbum: SelectedAlbum?
|
||||
onAlbumViewClick: (String) -> Unit,
|
||||
onDarkCheck: (Boolean) -> Unit,
|
||||
onDarkenPercentage: (Int) -> Unit,
|
||||
onHomeCheckedChange: (Boolean) -> Unit,
|
||||
onLockCheckedChange: (Boolean) -> Unit,
|
||||
onScalingChange: (ScalingConstants) -> Unit,
|
||||
onScheduleWallpaperChanger1: (Int) -> Unit,
|
||||
onScheduleWallpaperChanger2: (Int) -> Unit,
|
||||
onSelectAlbum: (AlbumWithWallpaperAndFolder) -> Unit,
|
||||
onScheduleSeparatelyChange: (Boolean) -> Unit,
|
||||
onTimeChange1: (Int) -> Unit,
|
||||
onTimeChange2: (Int) -> Unit,
|
||||
onSettingsClick: () -> Unit,
|
||||
onStop: () -> Unit,
|
||||
onToggleChanger: (Boolean) -> Unit,
|
||||
scaling: ScalingConstants,
|
||||
selectedAlbum: SelectedAlbum?,
|
||||
scheduleSeparately: Boolean,
|
||||
blur: Boolean,
|
||||
onBlurPercentageChange: (Int) -> Unit,
|
||||
onBlurChange: (Boolean) -> Unit,
|
||||
blurPercentage: Int,
|
||||
) {
|
||||
var tabIndex by rememberSaveable { mutableIntStateOf(0) }
|
||||
val pagerState = rememberPagerState { tabItems.size }
|
||||
|
||||
val tabItems = getTabItems()
|
||||
val pagerState = rememberPagerState(0) { tabItems.size }
|
||||
var tabIndex by rememberSaveable { mutableIntStateOf(pagerState.currentPage) }
|
||||
var addAlbumDialog by rememberSaveable { mutableStateOf(false) }
|
||||
if (addAlbumDialog) AddAlbumDialog(
|
||||
onDismissRequest = { addAlbumDialog = false },
|
||||
onConfirmation = { navigateToAddWallpaperScreen(it) }
|
||||
)
|
||||
|
||||
val context = LocalContext.current
|
||||
val activity = context as? Activity
|
||||
BackHandler {
|
||||
activity?.moveTaskToBack(true)
|
||||
LaunchedEffect(tabIndex) {
|
||||
pagerState.animateScrollToPage(tabIndex)
|
||||
}
|
||||
LaunchedEffect(pagerState.currentPage) {
|
||||
tabIndex = pagerState.currentPage
|
||||
}
|
||||
|
||||
Scaffold (
|
||||
@@ -70,16 +90,12 @@ fun HomeScreen(
|
||||
onSettingsClick = onSettingsClick,
|
||||
)
|
||||
}
|
||||
) { padding ->
|
||||
LaunchedEffect(tabIndex) { pagerState.animateScrollToPage(tabIndex) }
|
||||
LaunchedEffect(pagerState) {
|
||||
snapshotFlow { pagerState.currentPage }.collect { page -> tabIndex = page }
|
||||
}
|
||||
Column(modifier = Modifier.padding(padding)) {
|
||||
) {
|
||||
Column(modifier = Modifier.padding(it)) {
|
||||
TabRow(
|
||||
selectedTabIndex = tabIndex,
|
||||
indicator = { tabPositions ->
|
||||
if (tabIndex < tabPositions.size) {
|
||||
if (tabIndex in tabPositions.indices) {
|
||||
TabRowDefaults.PrimaryIndicator(
|
||||
modifier = Modifier.tabIndicatorOffset(tabPositions[tabIndex]),
|
||||
shape = RoundedCornerShape(
|
||||
@@ -101,10 +117,8 @@ fun HomeScreen(
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector =
|
||||
if (index == tabIndex)
|
||||
item.filledIcon
|
||||
else
|
||||
item.unfilledIcon,
|
||||
if (index == tabIndex) item.filledIcon
|
||||
else item.unfilledIcon,
|
||||
contentDescription = item.title
|
||||
)
|
||||
}
|
||||
@@ -113,22 +127,42 @@ fun HomeScreen(
|
||||
}
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
beyondViewportPageCount = 1,
|
||||
userScrollEnabled = true,
|
||||
beyondViewportPageCount = 1
|
||||
) { index ->
|
||||
when(index) {
|
||||
when(index.coerceIn(tabItems.indices)) {
|
||||
0 -> WallpaperScreen(
|
||||
onScheduleWallpaperChanger = onScheduleWallpaperChanger,
|
||||
onStop = onStop,
|
||||
animate = animate,
|
||||
interval = interval,
|
||||
setLockWithHome = setLockWithHome,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
enableChanger = enableChanger,
|
||||
homeEnabled = homeEnabled,
|
||||
interval1 = interval1,
|
||||
interval2 = interval2,
|
||||
lastSetTime = lastSetTime,
|
||||
lockEnabled = lockEnabled,
|
||||
nextSetTime = nextSetTime,
|
||||
onSetLockWithHome = { onSetLockWithHome(it) },
|
||||
selectedAlbum = selectedAlbum
|
||||
onDarkCheck = onDarkCheck,
|
||||
onDarkenPercentage = onDarkenPercentage,
|
||||
onHomeCheckedChange = onHomeCheckedChange,
|
||||
onLockCheckedChange = onLockCheckedChange,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
|
||||
onScheduleWallpaperChanger1 = onScheduleWallpaperChanger1,
|
||||
onScheduleWallpaperChanger2 = onScheduleWallpaperChanger2,
|
||||
onScalingChange = onScalingChange,
|
||||
onSelectAlbum = onSelectAlbum,
|
||||
onTimeChange1 = onTimeChange1,
|
||||
onTimeChange2 = onTimeChange2,
|
||||
onStop = onStop,
|
||||
onToggleChanger = onToggleChanger,
|
||||
scaling = scaling,
|
||||
selectedAlbum = selectedAlbum,
|
||||
blur = blur,
|
||||
onBlurPercentageChange = onBlurPercentageChange,
|
||||
onBlurChange = onBlurChange,
|
||||
blurPercentage = blurPercentage
|
||||
)
|
||||
1 -> LibraryScreen(
|
||||
else -> LibraryScreen(
|
||||
onAddNewAlbumClick = { addAlbumDialog = true },
|
||||
onViewAlbum = onAlbumViewClick,
|
||||
animate = animate
|
||||
|
||||
@@ -5,7 +5,6 @@ import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
@@ -45,7 +44,7 @@ fun HomeTopBar (
|
||||
) {
|
||||
CenterAlignedTopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
|
||||
title = { if (!showSelectionModeAppBar) Text(stringResource(R.string.appname)) },
|
||||
title = { if (!showSelectionModeAppBar) Text(stringResource(R.string.app_name)) },
|
||||
actions = {
|
||||
if (showSelectionModeAppBar) {
|
||||
var showAlertDialog by rememberSaveable { mutableStateOf(false) }
|
||||
@@ -87,7 +86,7 @@ fun HomeTopBar (
|
||||
.background(bgColor)
|
||||
)
|
||||
}
|
||||
Text("$selectionCount selected")
|
||||
Text(stringResource(R.string.selected_count, selectionCount))
|
||||
}
|
||||
} else {
|
||||
IconButton(
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.AddToPhotos
|
||||
import androidx.compose.material.icons.filled.Image
|
||||
import androidx.compose.material.icons.outlined.AddToPhotos
|
||||
import androidx.compose.material.icons.outlined.Image
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Data class representing a tab item
|
||||
*/
|
||||
data class TabItem(
|
||||
val title: String,
|
||||
val filledIcon: ImageVector,
|
||||
val unfilledIcon: ImageVector,
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun getTabItems(): List<TabItem> {
|
||||
val context = LocalContext.current
|
||||
return listOf(
|
||||
TabItem(
|
||||
title = context.getString(R.string.wallpaper_screen),
|
||||
filledIcon = Icons.Filled.Image,
|
||||
unfilledIcon = Icons.Outlined.Image
|
||||
),
|
||||
TabItem(
|
||||
title = context.getString(R.string.library_screen),
|
||||
filledIcon = Icons.Filled.AddToPhotos,
|
||||
unfilledIcon = Icons.Outlined.AddToPhotos
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library_screen
|
||||
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
@@ -63,13 +61,7 @@ fun LibraryScreen(
|
||||
AlbumItem(
|
||||
album = album.album,
|
||||
onAlbumViewClick = { onViewAlbum(album.album.initialAlbumName) },
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
),
|
||||
modifier = Modifier.padding(4.dp),
|
||||
animate = animate
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,14 +5,15 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.data.rememberCurrentOffset
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components.LicenseScrollableSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components.LicenseSmallTopAppBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components.LicenseTitle
|
||||
|
||||
@Composable
|
||||
fun LicensesScreen(
|
||||
topInsets: Dp,
|
||||
onBackClick: () -> Unit,
|
||||
) {
|
||||
val lazyListState = rememberLazyListState()
|
||||
@@ -25,14 +26,15 @@ fun LicensesScreen(
|
||||
LicenseScrollableSettings(
|
||||
largeTopAppBarHeightPx = largeTopAppBarHeight,
|
||||
lazyListState = lazyListState,
|
||||
offset = offset
|
||||
offset = offset,
|
||||
onBackClick = onBackClick
|
||||
)
|
||||
LicenseSmallTopAppBar(onBackClick = onBackClick)
|
||||
LicenseTitle(
|
||||
largeTopAppBarHeight = largeTopAppBarHeight,
|
||||
smallTopAppBarHeight = smallTopAppBarHeight,
|
||||
paddingMedium = paddingMedium,
|
||||
offset = offset
|
||||
offset = offset,
|
||||
topInset = topInsets
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -6,50 +6,83 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
|
||||
import com.mikepenz.aboutlibraries.ui.compose.m3.LibraryDefaults
|
||||
|
||||
/**
|
||||
* Scrollable license screen to display open source licenses
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LicenseScrollableSettings(
|
||||
largeTopAppBarHeightPx: Dp,
|
||||
lazyListState: LazyListState,
|
||||
offset: State<Int>
|
||||
offset: State<Int>,
|
||||
onBackClick: () -> Unit
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 24.dp),
|
||||
) {
|
||||
val offsetInDp = offset.value.toFloat() / 2f.dp.value
|
||||
val newHeight = largeTopAppBarHeightPx - offsetInDp.dp
|
||||
Spacer(Modifier.height(newHeight))
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
LibrariesContainer(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
lazyListState = lazyListState,
|
||||
showVersion = false,
|
||||
colors = LibraryDefaults.libraryColors(
|
||||
backgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
contentColor = MaterialTheme.colorScheme.onSurface,
|
||||
badgeBackgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
badgeContentColor = MaterialTheme.colorScheme.primary,
|
||||
dialogConfirmButtonColor = MaterialTheme.colorScheme.onSurface
|
||||
Scaffold (
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
) { it
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 24.dp),
|
||||
) {
|
||||
val offsetInDp = offset.value.toFloat() / 2f.dp.value
|
||||
val newHeight = largeTopAppBarHeightPx - offsetInDp.dp
|
||||
Spacer(Modifier.height(newHeight))
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
LibrariesContainer(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
lazyListState = lazyListState,
|
||||
showVersion = false,
|
||||
colors = LibraryDefaults.libraryColors(
|
||||
backgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
contentColor = MaterialTheme.colorScheme.onSurface,
|
||||
badgeBackgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
badgeContentColor = MaterialTheme.colorScheme.primary,
|
||||
dialogConfirmButtonColor = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Small top app bar for license screen to replace [LicenseLargeTopAppBar] when scrolling down
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LicenseSmallTopAppBar(onBackClick: () -> Unit) {
|
||||
Surface {
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
|
||||
title = {},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,11 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -35,7 +27,8 @@ fun LicenseTitle(
|
||||
smallTopAppBarHeight: Dp,
|
||||
paddingMedium: Dp,
|
||||
modifier: Modifier = Modifier,
|
||||
offset: State<Int>
|
||||
offset: State<Int>,
|
||||
topInset: Dp,
|
||||
) {
|
||||
val titlePaddingStart = 16.dp
|
||||
val titlePaddingEnd = 64.dp
|
||||
@@ -44,6 +37,9 @@ fun LicenseTitle(
|
||||
var titleHeightPx by remember { mutableFloatStateOf(0f) }
|
||||
var titleWidthPx by remember { mutableFloatStateOf(0f) }
|
||||
|
||||
val fraction = (topInset - 74.dp) / (151.dp - 74.dp)
|
||||
val statusPadding = lerp(0.dp, 24.dp, fraction.coerceIn(0f, 1f))
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.licenses),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
@@ -63,7 +59,7 @@ fun LicenseTitle(
|
||||
val titleExtraStartPadding = titleWidthPx.toDp() * (1 - scaleXY.value) / 2f
|
||||
|
||||
val titleYFirstInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium,
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium + statusPadding,
|
||||
largeTopAppBarHeight / 2,
|
||||
collapseFraction
|
||||
)
|
||||
@@ -76,7 +72,7 @@ fun LicenseTitle(
|
||||
|
||||
val titleYSecondInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight / 2,
|
||||
(smallTopAppBarHeight - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
(smallTopAppBarHeight + statusPadding - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
|
||||
@@ -18,23 +18,18 @@ import androidx.compose.material3.ExtendedFloatingActionButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Snackbar
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.SnackbarResult
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
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.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.airbnb.lottie.compose.LottieAnimation
|
||||
@@ -43,46 +38,21 @@ import com.airbnb.lottie.compose.LottieConstants
|
||||
import com.airbnb.lottie.compose.animateLottieCompositionAsState
|
||||
import com.airbnb.lottie.compose.rememberLottieComposition
|
||||
import com.anthonyla.paperize.R
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun NotificationScreen(
|
||||
onAgree: () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val scope = rememberCoroutineScope()
|
||||
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.notification_animation))
|
||||
val progress by animateLottieCompositionAsState(
|
||||
composition = composition,
|
||||
iterations = LottieConstants.IterateForever,
|
||||
)
|
||||
val askPermission = rememberSaveable { mutableStateOf(false) }
|
||||
val askCount = rememberSaveable { mutableIntStateOf(0) }
|
||||
|
||||
val requestPermissionLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.RequestPermission()
|
||||
) { isGranted: Boolean ->
|
||||
if (isGranted) {
|
||||
onAgree()
|
||||
} else {
|
||||
if (++askCount.intValue >= 2) {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
onAgree()
|
||||
}
|
||||
scope.launch {
|
||||
val result = snackbarHostState.showSnackbar(
|
||||
message = context.getString(R.string.notification_permission_is_required_for_this_app_to_work_properly),
|
||||
actionLabel = context.getString(R.string.allow),
|
||||
duration = SnackbarDuration.Short,
|
||||
)
|
||||
when (result) {
|
||||
SnackbarResult.Dismissed -> {}
|
||||
SnackbarResult.ActionPerformed -> { askPermission.value = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
) { onAgree() }
|
||||
|
||||
fun handleFabClick() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
@@ -100,30 +70,24 @@ fun NotificationScreen(
|
||||
LaunchedEffect (askPermission.value) {
|
||||
if (askPermission.value) {
|
||||
handleFabClick()
|
||||
askPermission.value = false
|
||||
}
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = {
|
||||
SnackbarHost(
|
||||
hostState = snackbarHostState,
|
||||
snackbar = { data ->
|
||||
Snackbar(
|
||||
snackbarData = data,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 8.dp, vertical = 8.dp))
|
||||
)
|
||||
}
|
||||
) },
|
||||
content = { it
|
||||
Column (modifier = Modifier.padding(32.dp)) {
|
||||
Spacer(modifier = Modifier.height(120.dp))
|
||||
Text(text = "Notifications", style = MaterialTheme.typography.headlineLarge)
|
||||
Text(text = stringResource(id = R.string.notifications), style = MaterialTheme.typography.headlineLarge)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
LottieAnimation(
|
||||
composition = composition,
|
||||
progress = { progress },
|
||||
modifier = Modifier.fillMaxHeight(0.5f)
|
||||
modifier = Modifier
|
||||
.fillMaxHeight(0.5f)
|
||||
.align(Alignment.CenterHorizontally)
|
||||
.semantics { contentDescription = context.getString(R.string.notification_bell_animation) },
|
||||
safeMode = true,
|
||||
enableMergePaths = true
|
||||
)
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Info,
|
||||
|
||||
@@ -6,13 +6,14 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components.PrivacyScrollableSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components.PrivacySmallTopAppBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components.PrivacyTitle
|
||||
|
||||
@Composable
|
||||
fun PrivacyScreen(
|
||||
topInsets: Dp,
|
||||
onBackClick: () -> Unit,
|
||||
) {
|
||||
val scroll: ScrollState = rememberScrollState(0)
|
||||
@@ -24,13 +25,14 @@ fun PrivacyScreen(
|
||||
PrivacyScrollableSettings(
|
||||
largeTopAppBarHeightPx = largeTopAppBarHeight,
|
||||
scroll = scroll,
|
||||
onBackClick = onBackClick
|
||||
)
|
||||
PrivacySmallTopAppBar(onBackClick = onBackClick)
|
||||
PrivacyTitle(
|
||||
scroll = scroll,
|
||||
largeTopAppBarHeight = largeTopAppBarHeight,
|
||||
smallTopAppBarHeight = smallTopAppBarHeight,
|
||||
paddingMedium = paddingMedium
|
||||
paddingMedium = paddingMedium,
|
||||
topInset = topInsets
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -7,47 +7,80 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Scrollable privacy screen to display privacy note
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun PrivacyScrollableSettings(
|
||||
largeTopAppBarHeightPx: Dp,
|
||||
scroll: ScrollState,
|
||||
onBackClick: () -> Unit
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.verticalScroll(scroll)
|
||||
.padding(horizontal = 24.dp),
|
||||
) {
|
||||
Spacer(Modifier.height(largeTopAppBarHeightPx))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PrivacyNoticeText()
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
) { it
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.verticalScroll(scroll)
|
||||
.padding(horizontal = 24.dp),
|
||||
) {
|
||||
Spacer(Modifier.height(largeTopAppBarHeightPx))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PrivacyNoticeText()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun PrivacyNoticeText() {
|
||||
SectionText("Introduction", "Welcome to Paperize! This privacy notice outlines how we collect, use, and protect your personal information when you use our mobile application. By using Paperize, you agree to the terms described in this notice.")
|
||||
SectionText("Data Collection", "Notification Access: Paperize requests notification access to provide you with personalized wallpaper recommendations based on your notifications. We do not store any notification content or personally identifiable information (PII) outside of your device.\n\nLocal Files: Paperize accesses files stored on your device to allow you to set them as wallpapers. We do not upload or transfer these files to any external servers.")
|
||||
SectionText("Information Usage", "Personal Data: We do not collect or store any personal data such as names, email addresses, or phone numbers.\n\nUsage Analytics: Paperize does not track your usage behavior or collect analytics data.")
|
||||
SectionText("Data Security", "On-Device Storage: All data used by Paperize remains on your device. We do not transmit or store any data externally.")
|
||||
SectionText("Third-Party Services", "Advertisements: Paperize does not display third-party ads.\n\nExternal Links: Our app may contain links to external websites. Please note that we are not responsible for the privacy practices of these sites.")
|
||||
SectionText("Children’s Privacy", "Paperize is not intended for children under the age of 13. We do not knowingly collect any information from children.")
|
||||
SectionText("Changes to this notice", "We may update this privacy notice from time to time. Any changes will be reflected in the app and on our website.")
|
||||
SectionText("Contact Us", "If you have any questions or concerns about this privacy notice, please contact me at anthonyyla.dev@gmail.com.")
|
||||
SectionText(stringResource(R.string.privacy_intro_title), stringResource(R.string.privacy_intro_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_data_collection_title), stringResource(R.string.privacy_data_collection_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_information_usage_title), stringResource(R.string.privacy_information_usage_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_data_security_title), stringResource(R.string.privacy_data_security_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_third_party_services_title), stringResource(R.string.privacy_third_party_services_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_children_privacy_title), stringResource(R.string.privacy_children_privacy_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_changes_notice_title), stringResource(R.string.privacy_changes_notice_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_contact_us_title), stringResource(R.string.privacy_contact_us_content, "anthonyyla.dev@gmail.com"))
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Small top app bar for privacy screen to replace [PrivacyLargeTopAppBar] when scrolling down
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun PrivacySmallTopAppBar(onBackClick: () -> Unit) {
|
||||
Surface {
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
|
||||
title = {},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,8 @@ fun PrivacyTitle(
|
||||
smallTopAppBarHeight: Dp,
|
||||
paddingMedium: Dp,
|
||||
scroll: ScrollState,
|
||||
modifier: Modifier = Modifier
|
||||
modifier: Modifier = Modifier,
|
||||
topInset: Dp,
|
||||
) {
|
||||
val titlePaddingStart = 16.dp
|
||||
val titlePaddingEnd = 64.dp
|
||||
@@ -36,6 +37,9 @@ fun PrivacyTitle(
|
||||
var titleHeightPx by remember { mutableFloatStateOf(0f) }
|
||||
var titleWidthPx by remember { mutableFloatStateOf(0f) }
|
||||
|
||||
val fraction = (topInset - 74.dp) / (151.dp - 74.dp)
|
||||
val statusPadding = lerp(0.dp, 24.dp, fraction.coerceIn(0f, 1f))
|
||||
|
||||
Text(
|
||||
text = stringResource(id = R.string.privacy_policy),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
@@ -55,7 +59,7 @@ fun PrivacyTitle(
|
||||
val titleExtraStartPadding = titleWidthPx.toDp() * (1 - scaleXY.value) / 2f
|
||||
|
||||
val titleYFirstInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium,
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium + statusPadding,
|
||||
largeTopAppBarHeight / 2,
|
||||
collapseFraction
|
||||
)
|
||||
@@ -68,7 +72,7 @@ fun PrivacyTitle(
|
||||
|
||||
val titleYSecondInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight / 2,
|
||||
(smallTopAppBarHeight - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
(smallTopAppBarHeight + statusPadding - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
|
||||
@@ -1,13 +1,25 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen
|
||||
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
|
||||
|
||||
sealed class SettingsEvent {
|
||||
data object Refresh: SettingsEvent()
|
||||
data object Reset: SettingsEvent()
|
||||
data object SetFirstLaunch: SettingsEvent()
|
||||
data object RefreshNextSetTime: SettingsEvent()
|
||||
data class SetDarkMode(val darkMode: Boolean?): SettingsEvent()
|
||||
data class SetDynamicTheming(val dynamicTheming: Boolean): SettingsEvent()
|
||||
data class SetAnimate(val animate: Boolean): SettingsEvent()
|
||||
data class SetWallpaperInterval(val interval: Int): SettingsEvent()
|
||||
data class SetLockWithHome(val lockWithHome: Boolean): SettingsEvent()
|
||||
data class SetDarken(val darken: Boolean): SettingsEvent()
|
||||
data class SetBlur(val blur: Boolean): SettingsEvent()
|
||||
data class SetLock(val lock: Boolean): SettingsEvent()
|
||||
data class SetHome(val home: Boolean): SettingsEvent()
|
||||
data class SetScheduleSeparately(val scheduleSeparately: Boolean): SettingsEvent()
|
||||
data class SetHomeWallpaperInterval(val interval: Int): SettingsEvent()
|
||||
data class SetLockWallpaperInterval(val interval: Int): SettingsEvent()
|
||||
data class SetDarkenPercentage(val darkenPercentage: Int): SettingsEvent()
|
||||
data class SetBlurPercentage(val blurPercentage: Int): SettingsEvent()
|
||||
data class SetChangerToggle(val toggle: Boolean): SettingsEvent()
|
||||
data class SetWallpaperScaling(val scaling: ScalingConstants): SettingsEvent()
|
||||
}
|
||||
@@ -4,17 +4,22 @@ import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.SettingsScrollableSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.SettingsSmallTopAppBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.SettingsTitle
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SettingsScreen(
|
||||
settingsState: StateFlow<SettingsState>,
|
||||
topInsets: Dp,
|
||||
onBackClick: () -> Unit,
|
||||
onDarkModeClick: (Boolean?) -> Unit,
|
||||
onDynamicThemingClick: (Boolean) -> Unit,
|
||||
@@ -24,8 +29,8 @@ fun SettingsScreen(
|
||||
onResetClick: () -> Unit
|
||||
) {
|
||||
val scroll: ScrollState = rememberScrollState(0)
|
||||
val largeTopAppBarHeight = 152.dp
|
||||
val smallTopAppBarHeight = 64.dp
|
||||
val largeTopAppBarHeight = TopAppBarDefaults.LargeAppBarExpandedHeight
|
||||
val smallTopAppBarHeight = TopAppBarDefaults.LargeAppBarCollapsedHeight
|
||||
val paddingMedium = 16.dp
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
@@ -38,14 +43,15 @@ fun SettingsScreen(
|
||||
onAnimateClick = onAnimateClick,
|
||||
onPrivacyClick = onPrivacyClick,
|
||||
onLicenseClick = onLicenseClick,
|
||||
onResetClick = onResetClick
|
||||
onResetClick = onResetClick,
|
||||
onBackClick = onBackClick,
|
||||
)
|
||||
SettingsSmallTopAppBar(onBackClick = onBackClick)
|
||||
SettingsTitle(
|
||||
scroll = scroll,
|
||||
largeTopAppBarHeight = largeTopAppBarHeight,
|
||||
smallTopAppBarHeight = smallTopAppBarHeight,
|
||||
paddingMedium = paddingMedium
|
||||
paddingMedium = paddingMedium,
|
||||
topInset = topInsets
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,25 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
|
||||
data class SettingsState (
|
||||
data class SettingsState(
|
||||
val firstLaunch: Boolean = true,
|
||||
// App settings
|
||||
val darkMode: Boolean? = null,
|
||||
val dynamicTheming: Boolean = false,
|
||||
val animate: Boolean = true,
|
||||
val interval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val setLockWithHome: Boolean = false,
|
||||
// Wallpaper settings
|
||||
val enableChanger: Boolean = false,
|
||||
val setHomeWallpaper: Boolean = false,
|
||||
val setLockWallpaper: Boolean = false,
|
||||
val scheduleSeparately: Boolean = false,
|
||||
val homeInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val lockInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val lastSetTime: String? = null,
|
||||
val nextSetTime: String? = null
|
||||
val nextSetTime: String? = null,
|
||||
val darkenPercentage: Int = 100,
|
||||
val darken: Boolean = false,
|
||||
val blur: Boolean = false,
|
||||
val blurPercentage: Int = 0,
|
||||
val wallpaperScaling: ScalingConstants = ScalingConstants.FILL
|
||||
)
|
||||
@@ -2,9 +2,11 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@@ -14,6 +16,7 @@ import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.format.FormatStyle
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
@@ -30,38 +33,44 @@ class SettingsViewModel @Inject constructor (
|
||||
var setKeepOnScreenCondition: Boolean = true
|
||||
|
||||
init {
|
||||
currentGetJob = viewModelScope.launch {
|
||||
val darkMode =
|
||||
async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) }
|
||||
val dynamicTheming = async {
|
||||
settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false
|
||||
}
|
||||
val wallpaperInterval = async {
|
||||
settingsDataStoreImpl.getInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL)
|
||||
?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
}
|
||||
val firstLaunch =
|
||||
async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
|
||||
val setLockWithHome = async {
|
||||
settingsDataStoreImpl.getBoolean(SettingsConstants.SET_LOCK_WITH_HOME) ?: false
|
||||
}
|
||||
val lastSetTime =
|
||||
async { settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME) }
|
||||
val nextSetTime =
|
||||
async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME) }
|
||||
val animate =
|
||||
async { settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true }
|
||||
currentGetJob = viewModelScope.launch(Dispatchers.IO) {
|
||||
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
|
||||
val darkMode = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) }
|
||||
val dynamicTheming = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false }
|
||||
val enableChanger = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: true }
|
||||
val setHomeWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.HOME_WALLPAPER) ?: false }
|
||||
val setLockWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.LOCK_WALLPAPER) ?: false }
|
||||
val homeWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val lockWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val lastSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME) }
|
||||
val nextSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME) }
|
||||
val animate = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true }
|
||||
val darkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.DARKEN_PERCENTAGE) ?: 100 }
|
||||
val darken = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false }
|
||||
val wallpaperScaling = async { ScalingConstants.valueOf(settingsDataStoreImpl.getString(SettingsConstants.WALLPAPER_SCALING) ?: ScalingConstants.FILL.name) }
|
||||
val scheduleSeparately = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false }
|
||||
val blur = async { settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false }
|
||||
val blurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.BLUR_PERCENTAGE) ?: 0 }
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = darkMode.await(),
|
||||
dynamicTheming = dynamicTheming.await(),
|
||||
interval = wallpaperInterval.await(),
|
||||
setLockWithHome = setLockWithHome.await(),
|
||||
homeInterval = homeWallpaperInterval.await(),
|
||||
lockInterval = lockWallpaperInterval.await(),
|
||||
firstLaunch = firstLaunch.await(),
|
||||
lastSetTime = lastSetTime.await(),
|
||||
nextSetTime = nextSetTime.await(),
|
||||
animate = animate.await()
|
||||
animate = animate.await(),
|
||||
enableChanger = enableChanger.await(),
|
||||
darkenPercentage = darkenPercentage.await(),
|
||||
darken = darken.await(),
|
||||
wallpaperScaling = wallpaperScaling.await(),
|
||||
setHomeWallpaper = setHomeWallpaper.await(),
|
||||
setLockWallpaper = setLockWallpaper.await(),
|
||||
scheduleSeparately = scheduleSeparately.await(),
|
||||
blur = blur.await(),
|
||||
blurPercentage = blurPercentage.await()
|
||||
)
|
||||
}
|
||||
setKeepOnScreenCondition = false
|
||||
@@ -71,7 +80,7 @@ class SettingsViewModel @Inject constructor (
|
||||
fun onEvent(event: SettingsEvent) {
|
||||
when (event) {
|
||||
is SettingsEvent.SetFirstLaunch -> {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.FIRST_LAUNCH, false)
|
||||
_state.update {
|
||||
it.copy(
|
||||
@@ -81,65 +90,64 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.Refresh -> {
|
||||
currentGetJob = viewModelScope.launch {
|
||||
val darkMode =
|
||||
async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) }
|
||||
val dynamicTheming = async {
|
||||
settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE)
|
||||
?: false
|
||||
}
|
||||
val wallpaperInterval = async {
|
||||
settingsDataStoreImpl.getInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL)
|
||||
?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
}
|
||||
val firstLaunch = async {
|
||||
settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true
|
||||
}
|
||||
val setLockWithHome = async {
|
||||
settingsDataStoreImpl.getBoolean(SettingsConstants.SET_LOCK_WITH_HOME)
|
||||
?: false
|
||||
}
|
||||
val lastSetTime =
|
||||
async { settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME) }
|
||||
val nextSetTime =
|
||||
async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME) }
|
||||
val animate = async {
|
||||
settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true
|
||||
is SettingsEvent.SetChangerToggle -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, event.toggle)
|
||||
_state.update {
|
||||
it.copy(
|
||||
enableChanger = event.toggle
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.Refresh -> {
|
||||
currentGetJob = viewModelScope.launch(Dispatchers.IO) {
|
||||
val darkMode = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) }
|
||||
val dynamicTheming = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false }
|
||||
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
|
||||
val lastSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME) }
|
||||
val nextSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME) }
|
||||
val animate = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true }
|
||||
val enableChanger = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: true }
|
||||
val darkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.DARKEN_PERCENTAGE) ?: 0 }
|
||||
val darken = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false }
|
||||
val setHomeWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.HOME_WALLPAPER) ?: false }
|
||||
val setLockWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.LOCK_WALLPAPER) ?: false }
|
||||
val homeWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val lockWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val scheduleSeparately = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false }
|
||||
val blur = async { settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false }
|
||||
val blurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.BLUR_PERCENTAGE) ?: 0 }
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = darkMode.await(),
|
||||
dynamicTheming = dynamicTheming.await(),
|
||||
interval = wallpaperInterval.await(),
|
||||
setLockWithHome = setLockWithHome.await(),
|
||||
firstLaunch = firstLaunch.await(),
|
||||
lastSetTime = lastSetTime.await(),
|
||||
nextSetTime = nextSetTime.await(),
|
||||
animate = animate.await()
|
||||
animate = animate.await(),
|
||||
enableChanger = enableChanger.await(),
|
||||
darkenPercentage = darkenPercentage.await(),
|
||||
darken = darken.await(),
|
||||
setHomeWallpaper = setHomeWallpaper.await(),
|
||||
setLockWallpaper = setLockWallpaper.await(),
|
||||
lockInterval = lockWallpaperInterval.await(),
|
||||
homeInterval = homeWallpaperInterval.await(),
|
||||
scheduleSeparately = scheduleSeparately.await(),
|
||||
blur = blur.await(),
|
||||
blurPercentage = blurPercentage.await(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetDarkMode -> {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
when (event.darkMode) {
|
||||
true -> {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.DARK_MODE_TYPE, true)
|
||||
}
|
||||
|
||||
false -> {
|
||||
settingsDataStoreImpl.putBoolean(
|
||||
SettingsConstants.DARK_MODE_TYPE,
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
null -> {
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARK_MODE_TYPE)
|
||||
}
|
||||
true -> { settingsDataStoreImpl.putBoolean(SettingsConstants.DARK_MODE_TYPE, true) }
|
||||
false -> { settingsDataStoreImpl.putBoolean(SettingsConstants.DARK_MODE_TYPE, false) }
|
||||
null -> { settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARK_MODE_TYPE) }
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
@@ -150,22 +158,8 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
|
||||
is SettingsEvent.SetDynamicTheming -> {
|
||||
viewModelScope.launch {
|
||||
when (event.dynamicTheming) {
|
||||
true -> {
|
||||
settingsDataStoreImpl.putBoolean(
|
||||
SettingsConstants.DYNAMIC_THEME_TYPE,
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
false -> {
|
||||
settingsDataStoreImpl.putBoolean(
|
||||
SettingsConstants.DYNAMIC_THEME_TYPE,
|
||||
false
|
||||
)
|
||||
}
|
||||
}
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.DYNAMIC_THEME_TYPE, event.dynamicTheming)
|
||||
_state.update {
|
||||
it.copy(
|
||||
dynamicTheming = event.dynamicTheming
|
||||
@@ -175,16 +169,8 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
|
||||
is SettingsEvent.SetAnimate -> {
|
||||
viewModelScope.launch {
|
||||
when (event.animate) {
|
||||
true -> {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ANIMATE_TYPE, true)
|
||||
}
|
||||
|
||||
false -> {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ANIMATE_TYPE, false)
|
||||
}
|
||||
}
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ANIMATE_TYPE, event.animate)
|
||||
_state.update {
|
||||
it.copy(
|
||||
animate = event.animate
|
||||
@@ -193,80 +179,220 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetWallpaperInterval -> {
|
||||
viewModelScope.launch {
|
||||
val formatter = DateTimeFormatter.ofPattern("MM/dd/yy hh:mm\na")
|
||||
val time = LocalDateTime.now()
|
||||
val formattedLastSetTime = time.format(formatter)
|
||||
val formattedNextSetTime =
|
||||
time.plusMinutes(event.interval.toLong()).format(formatter)
|
||||
settingsDataStoreImpl.putString(
|
||||
SettingsConstants.LAST_SET_TIME,
|
||||
formattedLastSetTime
|
||||
)
|
||||
settingsDataStoreImpl.putString(
|
||||
SettingsConstants.NEXT_SET_TIME,
|
||||
formattedNextSetTime
|
||||
)
|
||||
settingsDataStoreImpl.putInt(
|
||||
SettingsConstants.WALLPAPER_CHANGE_INTERVAL,
|
||||
event.interval
|
||||
)
|
||||
is SettingsEvent.SetHomeWallpaperInterval -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL, event.interval)
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now()
|
||||
val nextSetTime: String?
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
|
||||
if (_state.value.scheduleSeparately) {
|
||||
val nextSetTime1 = currentTime.plusMinutes(event.interval.toLong())
|
||||
val nextSetTime2 = currentTime.plusMinutes(_state.value.lockInterval.toLong())
|
||||
nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)!!.format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, nextSetTime1.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, nextSetTime2.toString())
|
||||
}
|
||||
else {
|
||||
nextSetTime = currentTime.plusMinutes(event.interval.toLong()).format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
interval = event.interval,
|
||||
lastSetTime = formattedLastSetTime,
|
||||
nextSetTime = formattedNextSetTime
|
||||
homeInterval = event.interval,
|
||||
lastSetTime = currentTime.format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetLockWithHome -> {
|
||||
viewModelScope.launch {
|
||||
when (event.lockWithHome) {
|
||||
true -> {
|
||||
settingsDataStoreImpl.putBoolean(
|
||||
SettingsConstants.SET_LOCK_WITH_HOME,
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
false -> {
|
||||
settingsDataStoreImpl.putBoolean(
|
||||
SettingsConstants.SET_LOCK_WITH_HOME,
|
||||
false
|
||||
)
|
||||
}
|
||||
is SettingsEvent.SetLockWallpaperInterval -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL, event.interval)
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now()
|
||||
val nextSetTime: String?
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
|
||||
if (_state.value.scheduleSeparately) {
|
||||
val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong())
|
||||
val nextSetTime2 = currentTime.plusMinutes(event.interval.toLong())
|
||||
nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)!!.format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, nextSetTime1.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, nextSetTime2.toString())
|
||||
}
|
||||
else {
|
||||
nextSetTime = currentTime.plusMinutes(event.interval.toLong()).format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
setLockWithHome = event.lockWithHome
|
||||
lockInterval = event.interval,
|
||||
lastSetTime = currentTime.format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.RefreshNextSetTime -> {
|
||||
viewModelScope.launch {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now()
|
||||
val nextSetTime: String?
|
||||
if (_state.value.scheduleSeparately) {
|
||||
val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong())
|
||||
val nextSetTime2 = currentTime.plusMinutes(_state.value.lockInterval.toLong())
|
||||
nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)!!.format(formatter)
|
||||
}
|
||||
else {
|
||||
nextSetTime = currentTime.plusMinutes(_state.value.homeInterval.toLong()).format(formatter)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
lastSetTime = currentTime.format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetHome -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.HOME_WALLPAPER, event.home)
|
||||
_state.update {
|
||||
it.copy(
|
||||
setHomeWallpaper = event.home
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetLock -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.LOCK_WALLPAPER, event.lock)
|
||||
_state.update {
|
||||
it.copy(
|
||||
setLockWallpaper = event.lock
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetDarkenPercentage -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.DARKEN_PERCENTAGE, event.darkenPercentage)
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkenPercentage = event.darkenPercentage
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetDarken -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.DARKEN, event.darken)
|
||||
_state.update {
|
||||
it.copy(
|
||||
darken = event.darken
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetWallpaperScaling -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.WALLPAPER_SCALING, event.scaling.name)
|
||||
_state.update {
|
||||
it.copy(
|
||||
wallpaperScaling = event.scaling
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetScheduleSeparately -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.SCHEDULE_SEPARATELY, event.scheduleSeparately)
|
||||
_state.update {
|
||||
it.copy(
|
||||
scheduleSeparately = event.scheduleSeparately
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetBlur -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.BLUR, event.blur)
|
||||
_state.update {
|
||||
it.copy(
|
||||
blur = event.blur
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetBlurPercentage -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.BLUR_PERCENTAGE, event.blurPercentage)
|
||||
_state.update {
|
||||
it.copy(
|
||||
blurPercentage = event.blurPercentage
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.Reset -> {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARK_MODE_TYPE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DYNAMIC_THEME_TYPE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.FIRST_LAUNCH)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.SET_LOCK_WITH_HOME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LAST_SET_TIME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ANIMATE_TYPE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ENABLE_CHANGER)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.DARKEN_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARKEN)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.WALLPAPER_SCALING)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.HOME_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.LOCK_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.SCHEDULE_SEPARATELY)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.BLUR)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.BLUR_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.FIRST_SET)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME_1)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME_2)
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = null,
|
||||
dynamicTheming = false,
|
||||
interval = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
setLockWithHome = false,
|
||||
firstLaunch = true,
|
||||
lastSetTime = null,
|
||||
nextSetTime = null,
|
||||
animate = true
|
||||
animate = true,
|
||||
enableChanger = true,
|
||||
darkenPercentage = 100,
|
||||
darken = false,
|
||||
wallpaperScaling = ScalingConstants.FILL,
|
||||
setHomeWallpaper = false,
|
||||
setLockWallpaper = false,
|
||||
lockInterval = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
homeInterval = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
scheduleSeparately = false,
|
||||
blur = false,
|
||||
blurPercentage = 0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Animation
|
||||
import androidx.compose.material.icons.outlined.Palette
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -14,15 +13,19 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Enable animation switch
|
||||
*/
|
||||
@Composable
|
||||
fun AnimationListItem(animate: Boolean, onAnimateClick: (Boolean) -> Unit) {
|
||||
val context = LocalContext.current
|
||||
Row {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
@@ -30,17 +33,17 @@ fun AnimationListItem(animate: Boolean, onAnimateClick: (Boolean) -> Unit) {
|
||||
.clickable { onAnimateClick(!animate) },
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = "Animation",
|
||||
text = stringResource(R.string.animation),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = "Increase visual appeal",
|
||||
text = stringResource(R.string.increase_visual_appeal),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {
|
||||
Switch(
|
||||
modifier = Modifier.semantics { contentDescription = "Animation" },
|
||||
modifier = Modifier.semantics { contentDescription = context.getString(R.string.animation) },
|
||||
checked = animate,
|
||||
onCheckedChange = onAnimateClick,
|
||||
enabled = true
|
||||
@@ -48,7 +51,7 @@ fun AnimationListItem(animate: Boolean, onAnimateClick: (Boolean) -> Unit) {
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.Outlined.Animation,
|
||||
contentDescription = "Animation",
|
||||
contentDescription = stringResource(R.string.animation),
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
) },
|
||||
tonalElevation = 5.dp
|
||||
|
||||
@@ -4,10 +4,7 @@ import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.ArrowCircleRight
|
||||
import androidx.compose.material.icons.outlined.Email
|
||||
import androidx.compose.material.icons.outlined.PrivacyTip
|
||||
import androidx.compose.material.icons.outlined.SubdirectoryArrowRight
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
|
||||
@@ -30,8 +30,10 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Three-state selector for dark mode in settings
|
||||
@@ -40,9 +42,9 @@ import androidx.compose.ui.unit.dp
|
||||
@Composable
|
||||
fun DarkModeListItem(darkMode: Boolean?, onDarkModeClick: (Boolean?) -> Unit) {
|
||||
val options = listOf(
|
||||
Triple("Dark Mode", Icons.Outlined.DarkMode, Icons.Filled.DarkMode),
|
||||
Triple("Automatic Device Mode", Icons.Outlined.BrightnessAuto, Icons.Filled.BrightnessAuto),
|
||||
Triple("Light Mode", Icons.Outlined.LightMode, Icons.Filled.LightMode)
|
||||
Triple(stringResource(R.string.dark_mode), Icons.Outlined.DarkMode, Icons.Filled.DarkMode),
|
||||
Triple(stringResource(R.string.automatic_device_mode), Icons.Outlined.BrightnessAuto, Icons.Filled.BrightnessAuto),
|
||||
Triple(stringResource(R.string.light_mode), Icons.Outlined.LightMode, Icons.Filled.LightMode)
|
||||
)
|
||||
var selectedIndex by remember {
|
||||
mutableIntStateOf(
|
||||
@@ -51,7 +53,8 @@ fun DarkModeListItem(darkMode: Boolean?, onDarkModeClick: (Boolean?) -> Unit) {
|
||||
false -> 2
|
||||
else -> 1
|
||||
}
|
||||
) }
|
||||
)
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
@@ -70,16 +73,17 @@ fun DarkModeListItem(darkMode: Boolean?, onDarkModeClick: (Boolean?) -> Unit) {
|
||||
2 -> false
|
||||
else -> null
|
||||
}
|
||||
) },
|
||||
)
|
||||
},
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = "Dark Mode",
|
||||
text = stringResource(R.string.dark_mode),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = "Easier on the eyes",
|
||||
text = stringResource(R.string.easier_on_the_eyes),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
) },
|
||||
@@ -116,7 +120,7 @@ fun DarkModeListItem(darkMode: Boolean?, onDarkModeClick: (Boolean?) -> Unit) {
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.Outlined.Brightness6,
|
||||
contentDescription = "Dark Mode",
|
||||
contentDescription = stringResource(R.string.dark_mode),
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
},
|
||||
|
||||
@@ -13,15 +13,19 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Dynamic theming switch
|
||||
*/
|
||||
@Composable
|
||||
fun DynamicThemingListItem(dynamicTheming: Boolean, onDynamicThemingClick: (Boolean) -> Unit) {
|
||||
val context = LocalContext.current
|
||||
Row {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
@@ -29,18 +33,18 @@ fun DynamicThemingListItem(dynamicTheming: Boolean, onDynamicThemingClick: (Bool
|
||||
.clickable { onDynamicThemingClick(!dynamicTheming) },
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = "Dynamic Theme",
|
||||
text = stringResource(R.string.dynamic_theme),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = "Material You",
|
||||
text = stringResource(R.string.material_you),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {
|
||||
Switch(
|
||||
modifier = Modifier.semantics { contentDescription = "Dynamic Theme" },
|
||||
modifier = Modifier.semantics { contentDescription = context.getString(R.string.dynamic_theme) },
|
||||
checked = dynamicTheming,
|
||||
onCheckedChange = onDynamicThemingClick,
|
||||
enabled = true
|
||||
@@ -48,7 +52,7 @@ fun DynamicThemingListItem(dynamicTheming: Boolean, onDynamicThemingClick: (Bool
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.Outlined.Palette,
|
||||
contentDescription = "Dynamic Theming",
|
||||
contentDescription = stringResource(R.string.dynamic_theming),
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
) },
|
||||
tonalElevation = 5.dp
|
||||
|
||||
@@ -4,8 +4,6 @@ import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.outlined.LibraryBooks
|
||||
import androidx.compose.material.icons.outlined.Newspaper
|
||||
import androidx.compose.material.icons.outlined.PrivacyTip
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -34,7 +32,7 @@ fun LicenseListItem(onLicenseClick: () -> Unit) {
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = "Click here to view the licenses",
|
||||
text = stringResource(R.string.click_here_to_view_the_licenses),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {},
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -23,16 +25,28 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.scale
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
|
||||
/**
|
||||
* List item for app version and link to GitHub and PlayStore
|
||||
*/
|
||||
@Composable
|
||||
fun PaperizeListItem(onGitHubClick: () -> Unit, onPlaystoreClick: () -> Unit, onFdroidClick: () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
var version = ""
|
||||
try {
|
||||
val pInfo: PackageInfo =
|
||||
context.packageManager.getPackageInfo(context.packageName, 0)
|
||||
version = pInfo.versionName
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -53,17 +67,19 @@ fun PaperizeListItem(onGitHubClick: () -> Unit, onPlaystoreClick: () -> Unit, on
|
||||
) {
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(id = R.drawable.app_icon_foreground),
|
||||
contentDescription = stringResource(id = R.string.appname),
|
||||
modifier = Modifier.size(160.dp).scale(1.5f),
|
||||
contentDescription = stringResource(id = R.string.app_name),
|
||||
modifier = Modifier
|
||||
.size(160.dp)
|
||||
.scale(1.5f),
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
Text(
|
||||
text = stringResource(id = R.string.appname),
|
||||
text = stringResource(id = R.string.app_name),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontSize = MaterialTheme.typography.titleLarge.fontSize
|
||||
)
|
||||
Text(
|
||||
text = "Version: 1.0.0",
|
||||
text = stringResource(R.string.version, version),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
fontSize = MaterialTheme.typography.bodyMedium.fontSize
|
||||
)
|
||||
|
||||
@@ -33,7 +33,7 @@ fun PrivacyPolicyListItem(onPrivacyPolicyClick: () -> Unit) {
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = "Click here to view our privacy policy",
|
||||
text = stringResource(R.string.click_here_to_view_our_privacy_policy),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {},
|
||||
|
||||
@@ -10,13 +10,20 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Snackbar
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -27,9 +34,11 @@ import androidx.compose.runtime.setValue
|
||||
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.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.data.Contact
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
@@ -38,6 +47,7 @@ import kotlinx.coroutines.launch
|
||||
/**
|
||||
* Scrollable settings screen to wrap all settings components
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SettingsScrollableSettings(
|
||||
settingsState: StateFlow<SettingsState>,
|
||||
@@ -49,6 +59,7 @@ fun SettingsScrollableSettings(
|
||||
onPrivacyClick: () -> Unit,
|
||||
onLicenseClick: () -> Unit,
|
||||
onResetClick: () -> Unit,
|
||||
onBackClick: () -> Unit
|
||||
) {
|
||||
val state = settingsState.collectAsStateWithLifecycle()
|
||||
val context = LocalContext.current
|
||||
@@ -61,7 +72,10 @@ fun SettingsScrollableSettings(
|
||||
toContact = false
|
||||
}
|
||||
|
||||
val translateLink = "https://crowdin.com/project/paperize/invite?h=d8d7a7513d2beb0c96ba9b2a5f85473e2084922"
|
||||
val githubLink = "https://github.com/Anthonyy232/Paperize"
|
||||
val playstoreLink = "https://play.google.com/store/apps/details?id=com.anthonyla.paperize"
|
||||
val fdroidLink = ""
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = {
|
||||
@@ -75,6 +89,24 @@ fun SettingsScrollableSettings(
|
||||
)
|
||||
}
|
||||
) },
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
content = { it
|
||||
Column(
|
||||
@@ -87,10 +119,8 @@ fun SettingsScrollableSettings(
|
||||
) {
|
||||
Spacer(Modifier.height(largeTopAppBarHeightPx))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
ListSectionTitle("Appearance")
|
||||
ListSectionTitle(stringResource(R.string.appearance))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
DarkModeListItem(
|
||||
darkMode = state.value.darkMode,
|
||||
@@ -107,9 +137,16 @@ fun SettingsScrollableSettings(
|
||||
animate = state.value.animate,
|
||||
onAnimateClick = { onAnimateClick(it) }
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ListSectionTitle("About")
|
||||
ListSectionTitle(stringResource(R.string.about))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
TranslateListItem(
|
||||
onClick = {
|
||||
val openURL = Intent(Intent.ACTION_VIEW)
|
||||
openURL.data = Uri.parse(translateLink)
|
||||
context.startActivity(openURL)
|
||||
}
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PrivacyPolicyListItem (onPrivacyPolicyClick = onPrivacyClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
@@ -124,21 +161,16 @@ fun SettingsScrollableSettings(
|
||||
context.startActivity(openURL)
|
||||
},
|
||||
onPlaystoreClick = {
|
||||
coroutineScope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
snackbarHostState.showSnackbar(
|
||||
message = "Coming soon",
|
||||
actionLabel = "Dismiss",
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
}
|
||||
val openURL = Intent(Intent.ACTION_VIEW)
|
||||
openURL.data = Uri.parse(playstoreLink)
|
||||
context.startActivity(openURL)
|
||||
},
|
||||
onFdroidClick = {
|
||||
coroutineScope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
snackbarHostState.showSnackbar(
|
||||
message = "Coming soon",
|
||||
actionLabel = "Dismiss",
|
||||
message = context.getString(R.string.coming_soon),
|
||||
actionLabel = context.getString(R.string.dismiss),
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Small top app bar for settings screen to replace [SettingsLargeTopAppBar] when scrolling down
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SettingsSmallTopAppBar(onBackClick: () -> Unit) {
|
||||
Surface {
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
|
||||
title = {},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ fun SettingsTitle(
|
||||
smallTopAppBarHeight: Dp,
|
||||
paddingMedium: Dp,
|
||||
scroll: ScrollState,
|
||||
topInset: Dp,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val titlePaddingStart = 16.dp
|
||||
@@ -35,6 +36,8 @@ fun SettingsTitle(
|
||||
val titleFontScaleEnd = 0.7f
|
||||
var titleHeightPx by remember { mutableFloatStateOf(0f) }
|
||||
var titleWidthPx by remember { mutableFloatStateOf(0f) }
|
||||
val fraction = (topInset - 74.dp) / (151.dp - 74.dp)
|
||||
val statusPadding = lerp(0.dp, 24.dp, fraction.coerceIn(0f, 1f))
|
||||
|
||||
Text(
|
||||
text = stringResource(id = R.string.settings_screen),
|
||||
@@ -55,7 +58,7 @@ fun SettingsTitle(
|
||||
val titleExtraStartPadding = titleWidthPx.toDp() * (1 - scaleXY.value) / 2f
|
||||
|
||||
val titleYFirstInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium,
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium + statusPadding,
|
||||
largeTopAppBarHeight / 2,
|
||||
collapseFraction
|
||||
)
|
||||
@@ -68,7 +71,7 @@ fun SettingsTitle(
|
||||
|
||||
val titleYSecondInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight / 2,
|
||||
(smallTopAppBarHeight - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
(smallTopAppBarHeight + statusPadding - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.AddToPhotos
|
||||
import androidx.compose.material.icons.filled.Image
|
||||
import androidx.compose.material.icons.outlined.AddToPhotos
|
||||
import androidx.compose.material.icons.outlined.Image
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
|
||||
/**
|
||||
* Data class representing a tab item
|
||||
*/
|
||||
data class TabItem(
|
||||
val title: String,
|
||||
val filledIcon: ImageVector,
|
||||
val unfilledIcon: ImageVector,
|
||||
)
|
||||
|
||||
/**
|
||||
* List of tab items
|
||||
*/
|
||||
val tabItems = listOf(
|
||||
TabItem(
|
||||
title = "Wallpaper",
|
||||
filledIcon = Icons.Filled.Image,
|
||||
unfilledIcon = Icons.Outlined.Image
|
||||
),
|
||||
TabItem(
|
||||
title = "Library",
|
||||
filledIcon = Icons.Filled.AddToPhotos,
|
||||
unfilledIcon = Icons.Outlined.AddToPhotos
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Translate
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* A list item that links the user to the translation page
|
||||
*/
|
||||
@Composable
|
||||
fun TranslateListItem(onClick: () -> Unit) {
|
||||
Row {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.clickable { onClick() },
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.translation),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.help_translate_the_app_on_crowdin),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {},
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.Outlined.Translate,
|
||||
contentDescription = stringResource(R.string.translation),
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
) },
|
||||
tonalElevation = 5.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,8 @@ 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.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.airbnb.lottie.compose.LottieAnimation
|
||||
@@ -88,7 +90,14 @@ fun StartupScreen(
|
||||
LottieAnimation(
|
||||
composition = composition,
|
||||
progress = { progress },
|
||||
modifier = Modifier.fillMaxHeight(0.5f)
|
||||
modifier = Modifier
|
||||
.fillMaxHeight(0.5f)
|
||||
.align(Alignment.CenterHorizontally)
|
||||
.semantics {
|
||||
contentDescription = context.getString(R.string.welcome_animation)
|
||||
},
|
||||
safeMode = true,
|
||||
enableMergePaths = true
|
||||
)
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Info,
|
||||
@@ -96,7 +105,7 @@ fun StartupScreen(
|
||||
modifier = Modifier.padding(PaddingValues(vertical = 16.dp))
|
||||
)
|
||||
Text(
|
||||
text = "Please read and agree to the following privacy notice to use the app.",
|
||||
text = stringResource(R.string.please_read_and_agree_to_the_following_privacy_notice_to_use_the_app),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
)
|
||||
Box(
|
||||
@@ -111,7 +120,7 @@ fun StartupScreen(
|
||||
} },
|
||||
modifier = Modifier.padding(PaddingValues(vertical = 16.dp)),
|
||||
) {
|
||||
Text(text = "Privacy Notice", textAlign = TextAlign.Start)
|
||||
Text(text = stringResource(R.string.privacy_notice), textAlign = TextAlign.Start)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,8 +134,8 @@ fun StartupScreen(
|
||||
} else {
|
||||
scope.launch {
|
||||
val result = snackbarHostState.showSnackbar(
|
||||
message = "Please read and agree to the privacy notice.",
|
||||
actionLabel = "View",
|
||||
message = context.getString(R.string.please_read_and_agree_to_the_privacy_notice),
|
||||
actionLabel = context.getString(R.string.view),
|
||||
duration = SnackbarDuration.Short,
|
||||
)
|
||||
when (result) {
|
||||
@@ -152,12 +161,12 @@ fun StartupScreen(
|
||||
if (showToS) {
|
||||
seenToS = true
|
||||
AlertDialog(
|
||||
modifier = Modifier.fillMaxHeight(0.8f),
|
||||
modifier = Modifier.fillMaxHeight(0.7f),
|
||||
onDismissRequest = { showToS = false },
|
||||
title = {
|
||||
Box(modifier = Modifier.fillMaxWidth()) {
|
||||
Text(
|
||||
text = "Privacy Notice",
|
||||
text = stringResource(R.string.privacy_notice),
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.align(Alignment.Center)
|
||||
)
|
||||
@@ -168,7 +177,7 @@ fun StartupScreen(
|
||||
Button(
|
||||
onClick = { showToS = false },
|
||||
) {
|
||||
Text("Dismiss")
|
||||
Text(stringResource(R.string.dismiss))
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -178,30 +187,14 @@ fun StartupScreen(
|
||||
@Composable
|
||||
fun PrivacyNoticeText() {
|
||||
LazyColumn {
|
||||
item {
|
||||
SectionText("Hello!", "Welcome to Paperize! We respect your privacy and protect your personal info. By using our app, you're okay with our privacy policy.")
|
||||
}
|
||||
item {
|
||||
SectionText("What We Collect", "We ask for notification access to personalize your wallpapers. We don't store or share your notifications. We also access your local files for wallpapers, but don't upload or transfer them.")
|
||||
}
|
||||
item {
|
||||
SectionText("How We Use Info", "We don't collect personal data or track your usage. All your data stays on your device.")
|
||||
}
|
||||
item {
|
||||
SectionText("Security", "Your data is safe with us. It stays on your device at all times.")
|
||||
}
|
||||
item {
|
||||
SectionText("Third-Party Services", "No third-party ads here! We might have external links, but we're not responsible for their privacy practices.")
|
||||
}
|
||||
item {
|
||||
SectionText("For Kids", "Paperize isn't for kids under 13. We don't knowingly collect their info.")
|
||||
}
|
||||
item {
|
||||
SectionText("Policy Updates", "We might update this policy sometimes. You'll see any changes in the app and on GitHub.")
|
||||
}
|
||||
item {
|
||||
SectionText("Contact Us", "Got questions or concerns about our privacy policy? Email us at anthonyyla.dev@gmail.com.")
|
||||
}
|
||||
item { SectionText(stringResource(R.string.privacy_intro_title), stringResource(R.string.privacy_intro_content, stringResource(R.string.app_name))) }
|
||||
item { SectionText(stringResource(R.string.privacy_data_collection_title), stringResource(R.string.privacy_data_collection_content, stringResource(R.string.app_name))) }
|
||||
item { SectionText(stringResource(R.string.privacy_information_usage_title), stringResource(R.string.privacy_information_usage_content, stringResource(R.string.app_name))) }
|
||||
item { SectionText(stringResource(R.string.privacy_data_security_title), stringResource(R.string.privacy_data_security_content, stringResource(R.string.app_name))) }
|
||||
item { SectionText(stringResource(R.string.privacy_third_party_services_title), stringResource(R.string.privacy_third_party_services_content, stringResource(R.string.app_name))) }
|
||||
item { SectionText(stringResource(R.string.privacy_children_privacy_title), stringResource(R.string.privacy_children_privacy_content, stringResource(R.string.app_name))) }
|
||||
item { SectionText(stringResource(R.string.privacy_changes_notice_title), stringResource(R.string.privacy_changes_notice_content, stringResource(R.string.app_name))) }
|
||||
item { SectionText(stringResource(R.string.privacy_contact_us_title), stringResource(R.string.privacy_contact_us_content, "anthonyyla.dev@gmail.com")) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,18 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.themes
|
||||
|
||||
import android.app.Activity
|
||||
import android.graphics.Color.TRANSPARENT
|
||||
import android.os.Build
|
||||
import androidx.activity.SystemBarStyle
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
|
||||
private val LightColors = lightColorScheme(
|
||||
@@ -91,14 +86,13 @@ private val DarkColors = darkColorScheme(
|
||||
*/
|
||||
@Composable
|
||||
fun PaperizeTheme(
|
||||
settingsState: StateFlow<SettingsState>,
|
||||
darkMode: Boolean?,
|
||||
dynamicTheming: Boolean,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val state = settingsState.collectAsStateWithLifecycle()
|
||||
val context = LocalContext.current
|
||||
|
||||
val isDarkMode = isDarkMode(darkMode = state.value.darkMode)
|
||||
val isDynamicTheming = isDynamicTheming(dynamicTheming = state.value.dynamicTheming)
|
||||
val isDarkMode = isDarkMode(darkMode = darkMode)
|
||||
val isDynamicTheming = isDynamicTheming(dynamicTheming = dynamicTheming)
|
||||
val dynamicThemingSupported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
||||
val colors = when {
|
||||
isDynamicTheming && dynamicThemingSupported && isDarkMode -> dynamicDarkColorScheme(context)
|
||||
@@ -112,9 +106,8 @@ fun PaperizeTheme(
|
||||
if (!view.isInEditMode) {
|
||||
SideEffect {
|
||||
val window = (view.context as Activity).window
|
||||
window.statusBarColor = TRANSPARENT
|
||||
SystemBarStyle.light(TRANSPARENT, TRANSPARENT)
|
||||
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !isDarkMode
|
||||
WindowCompat.getInsetsController(window, view).isAppearanceLightNavigationBars = !isDarkMode
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,15 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
|
||||
sealed class WallpaperEvent {
|
||||
data class UpdateSelectedAlbum(val selectedAlbum: SelectedAlbum): WallpaperEvent()
|
||||
object Reset : WallpaperEvent()
|
||||
object Refresh : WallpaperEvent()
|
||||
data class UpdateSelectedAlbum(
|
||||
val selectedAlbum: SelectedAlbum?,
|
||||
val album: AlbumWithWallpaperAndFolder?,
|
||||
val scheduleSeparately: Boolean = false,
|
||||
val setHome: Boolean = false,
|
||||
val setLock: Boolean = false
|
||||
): WallpaperEvent()
|
||||
data object Reset : WallpaperEvent()
|
||||
data object Refresh : WallpaperEvent()
|
||||
}
|
||||
@@ -1,13 +1,21 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.WallpaperManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Snackbar
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
@@ -22,40 +30,75 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.AlbumBottomSheet
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.BlurSwitchAndSlider
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ChangerSelectionRow
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentAndNextChange
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentSelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.SetLockScreenSwitch
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.DarkenSwitchAndSlider
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ShowLiveWallpaperEnabledDialog
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.TimeSliders
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.WallpaperPreviewAndScale
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun WallpaperScreen(
|
||||
albumsViewModel: AlbumsViewModel = hiltViewModel(),
|
||||
wallpaperScreenViewModel: WallpaperScreenViewModel = hiltViewModel(),
|
||||
settingsViewModel: SettingsViewModel = hiltViewModel(),
|
||||
onScheduleWallpaperChanger: (Int) -> Unit,
|
||||
onSetLockWithHome: (Boolean) -> Unit,
|
||||
onStop: () -> Unit,
|
||||
animate: Boolean,
|
||||
interval: Int,
|
||||
setLockWithHome: Boolean,
|
||||
darken: Boolean,
|
||||
darkenPercentage: Int,
|
||||
enableChanger: Boolean,
|
||||
homeEnabled: Boolean,
|
||||
interval1: Int,
|
||||
interval2: Int,
|
||||
lastSetTime: String?,
|
||||
lockEnabled: Boolean,
|
||||
nextSetTime: String?,
|
||||
selectedAlbum: SelectedAlbum?
|
||||
onDarkCheck: (Boolean) -> Unit,
|
||||
onDarkenPercentage: (Int) -> Unit,
|
||||
onHomeCheckedChange: (Boolean) -> Unit,
|
||||
onLockCheckedChange: (Boolean) -> Unit,
|
||||
scheduleSeparately: Boolean,
|
||||
onScheduleSeparatelyChange: (Boolean) -> Unit,
|
||||
onScheduleWallpaperChanger1: (Int) -> Unit,
|
||||
onScheduleWallpaperChanger2: (Int) -> Unit,
|
||||
onScalingChange: (ScalingConstants) -> Unit,
|
||||
onSelectAlbum: (AlbumWithWallpaperAndFolder) -> Unit,
|
||||
onTimeChange1: (Int) -> Unit,
|
||||
onTimeChange2: (Int) -> Unit,
|
||||
onStop: () -> Unit,
|
||||
onToggleChanger: (Boolean) -> Unit,
|
||||
scaling: ScalingConstants,
|
||||
selectedAlbum: SelectedAlbum?,
|
||||
blur: Boolean,
|
||||
onBlurPercentageChange: (Int) -> Unit,
|
||||
onBlurChange: (Boolean) -> Unit,
|
||||
blurPercentage: Int
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val albumState = albumsViewModel.state.collectAsStateWithLifecycle()
|
||||
var openBottomSheet by rememberSaveable { mutableStateOf(false) }
|
||||
val scope = rememberCoroutineScope()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val openLiveDialog = rememberSaveable { mutableStateOf(false) }
|
||||
val showInterval = rememberSaveable { mutableStateOf(false) }
|
||||
val scrollState = rememberScrollState()
|
||||
|
||||
if (openLiveDialog.value) {
|
||||
ShowLiveWallpaperEnabledDialog(
|
||||
onDismissRequest = { openLiveDialog.value = false }
|
||||
)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = {
|
||||
@@ -71,151 +114,265 @@ fun WallpaperScreen(
|
||||
) },
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
content = { padding ->
|
||||
LazyColumn(
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(8.dp),
|
||||
.padding(8.dp)
|
||||
.verticalScroll(scrollState),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
item {
|
||||
ChangerSelectionRow(
|
||||
homeEnabled = homeEnabled,
|
||||
lockEnabled = lockEnabled,
|
||||
onHomeCheckedChange = onHomeCheckedChange,
|
||||
onLockCheckedChange = onLockCheckedChange
|
||||
)
|
||||
if (homeEnabled || lockEnabled) {
|
||||
CurrentSelectedAlbum(
|
||||
selectedAlbum = selectedAlbum,
|
||||
onOpenBottomSheet = {
|
||||
if (albumState.value.albumsWithWallpapers.firstOrNull() != null) openBottomSheet = true
|
||||
if (albumState.value.albumsWithWallpapers.firstOrNull() != null) {
|
||||
if (isLiveWallpaperSet(context)) {
|
||||
openLiveDialog.value = true
|
||||
} else {
|
||||
openBottomSheet = true
|
||||
}
|
||||
} else {
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
snackbarHostState.showSnackbar(
|
||||
message = context.getString(R.string.no_albums_found),
|
||||
actionLabel = context.getString(R.string.dismiss),
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
onStop = {
|
||||
if (selectedAlbum != null) {
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
snackbarHostState.showSnackbar(
|
||||
message = "${selectedAlbum.album.displayedAlbumName} has been unselected.",
|
||||
actionLabel = "Dismiss",
|
||||
message = context.getString(
|
||||
R.string.has_been_unselected,
|
||||
selectedAlbum.album.displayedAlbumName
|
||||
),
|
||||
actionLabel = context.getString(R.string.dismiss),
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
}
|
||||
onStop()
|
||||
}
|
||||
},
|
||||
animate = animate
|
||||
animate = animate,
|
||||
enableChanger = enableChanger,
|
||||
onToggleChanger = {
|
||||
if (!it) {
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
snackbarHostState.showSnackbar(
|
||||
message = context.getString(R.string.wallpaper_changer_has_been_disabled),
|
||||
actionLabel = context.getString(R.string.dismiss),
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
}
|
||||
}
|
||||
onToggleChanger(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
item {
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
if (selectedAlbum != null) {
|
||||
CurrentAndNextChange(lastSetTime, nextSetTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (selectedAlbum != null) {
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
CurrentAndNextChange(lastSetTime, nextSetTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
item {
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
if (selectedAlbum != null) {
|
||||
SetLockScreenSwitch(
|
||||
albumUri = selectedAlbum.album.coverUri,
|
||||
checked = setLockWithHome,
|
||||
onCheckedChange = { onSetLockWithHome(it) },
|
||||
animate = true
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
CurrentAndNextChange(lastSetTime, nextSetTime)
|
||||
}
|
||||
else {
|
||||
if (selectedAlbum != null) {
|
||||
SetLockScreenSwitch(
|
||||
albumUri = selectedAlbum.album.coverUri,
|
||||
checked = setLockWithHome,
|
||||
onCheckedChange = { onSetLockWithHome(it) },
|
||||
animate = false
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
WallpaperPreviewAndScale(
|
||||
currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = selectedAlbum.album.currentLockWallpaper,
|
||||
animate = true,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
scaling = scaling,
|
||||
onScalingChange = onScalingChange,
|
||||
homeEnabled = homeEnabled,
|
||||
lockEnabled = lockEnabled,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
item {
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
TimeSliders(
|
||||
timeInMinutes = interval,
|
||||
onTimeChange = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
settingsViewModel.onEvent(
|
||||
SettingsEvent.SetWallpaperInterval(totalMinutes)
|
||||
)
|
||||
onScheduleWallpaperChanger(totalMinutes)
|
||||
}
|
||||
)
|
||||
}
|
||||
else {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
WallpaperPreviewAndScale(
|
||||
currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = selectedAlbum.album.currentLockWallpaper,
|
||||
animate = false,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
scaling = scaling,
|
||||
onScalingChange = onScalingChange,
|
||||
homeEnabled = homeEnabled,
|
||||
lockEnabled = lockEnabled,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage
|
||||
)
|
||||
}
|
||||
else {
|
||||
if (selectedAlbum != null) {
|
||||
TimeSliders(
|
||||
timeInMinutes = interval,
|
||||
onTimeChange = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
settingsViewModel.onEvent(
|
||||
SettingsEvent.SetWallpaperInterval(totalMinutes)
|
||||
)
|
||||
onScheduleWallpaperChanger(totalMinutes)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
TimeSliders(
|
||||
timeInMinutes1 = interval1,
|
||||
timeInMinutes2 = interval2,
|
||||
onTimeChange1 = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
onTimeChange1(totalMinutes)
|
||||
},
|
||||
onTimeChange2 = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
onTimeChange2(totalMinutes)
|
||||
},
|
||||
showInterval = showInterval.value,
|
||||
animate = true,
|
||||
onShowIntervalChange = { showInterval.value = it },
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
|
||||
lockEnabled = lockEnabled,
|
||||
homeEnabled = homeEnabled
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
TimeSliders(
|
||||
timeInMinutes1 = interval1,
|
||||
timeInMinutes2 = interval2,
|
||||
onTimeChange1 = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
onScheduleWallpaperChanger1(totalMinutes)
|
||||
},
|
||||
onTimeChange2 = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
onScheduleWallpaperChanger2(totalMinutes)
|
||||
},
|
||||
showInterval = showInterval.value,
|
||||
animate = false,
|
||||
onShowIntervalChange = { showInterval.value = it },
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
|
||||
lockEnabled = lockEnabled,
|
||||
homeEnabled = homeEnabled,
|
||||
)
|
||||
}
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
DarkenSwitchAndSlider(
|
||||
onDarkCheck = onDarkCheck,
|
||||
darken = darken,
|
||||
onDarkenChange = onDarkenPercentage,
|
||||
darkenPercentage = darkenPercentage,
|
||||
animate = true
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
DarkenSwitchAndSlider(
|
||||
onDarkCheck = onDarkCheck,
|
||||
darken = darken,
|
||||
onDarkenChange = onDarkenPercentage,
|
||||
darkenPercentage = darkenPercentage,
|
||||
animate = false
|
||||
)
|
||||
}
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
BlurSwitchAndSlider(
|
||||
onBlurPercentageChange = onBlurPercentageChange,
|
||||
onBlurChange = onBlurChange,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage,
|
||||
animate = true
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
BlurSwitchAndSlider(
|
||||
onBlurPercentageChange = onBlurPercentageChange,
|
||||
onBlurChange = onBlurChange,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage,
|
||||
animate = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (openBottomSheet) {
|
||||
if (((homeEnabled || lockEnabled)) && openBottomSheet) {
|
||||
AlbumBottomSheet(
|
||||
albums = albumState.value.albumsWithWallpapers,
|
||||
currentSelectedAlbum = selectedAlbum,
|
||||
onDismiss = { openBottomSheet = false },
|
||||
onSelect = { album ->
|
||||
val wallpapers: List<Wallpaper> = album.wallpapers + album.folders.asSequence().flatMap { folder ->
|
||||
folder.wallpapers.asSequence().map { wallpaper ->
|
||||
Wallpaper(
|
||||
initialAlbumName = album.album.initialAlbumName,
|
||||
wallpaperUri = wallpaper,
|
||||
key = wallpaper.hashCode() + album.album.initialAlbumName.hashCode(),
|
||||
)
|
||||
}
|
||||
}.toList()
|
||||
val newSelectedAlbum = SelectedAlbum(
|
||||
album = album.album.copy(
|
||||
wallpapersInQueue = wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(newSelectedAlbum))
|
||||
openBottomSheet = false
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
snackbarHostState.showSnackbar(
|
||||
message = "${album.album.displayedAlbumName} has been selected.",
|
||||
actionLabel = "Dismiss",
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val alarmManager = ContextCompat.getSystemService(context, AlarmManager::class.java)
|
||||
if (alarmManager?.canScheduleExactAlarms() == false) {
|
||||
Intent().also { intent ->
|
||||
intent.action = Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
else {
|
||||
onSelectAlbum(album)
|
||||
onScheduleWallpaperChanger1(interval1)
|
||||
}
|
||||
}
|
||||
else {
|
||||
onSelectAlbum(album)
|
||||
onScheduleWallpaperChanger1(interval1)
|
||||
}
|
||||
onScheduleWallpaperChanger(interval)
|
||||
},
|
||||
animate = animate
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fun isLiveWallpaperSet(context: Context): Boolean {
|
||||
val wallpaperManager = WallpaperManager.getInstance(context)
|
||||
return wallpaperManager.wallpaperInfo != null
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.SelectedAlbumRepository
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -11,7 +13,6 @@ import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
@@ -26,32 +27,72 @@ class WallpaperScreenViewModel @Inject constructor (
|
||||
)
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
refreshAlbums()
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.getSelectedAlbum().collect { selectedAlbum ->
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedAlbum = selectedAlbum.firstOrNull(),
|
||||
isDataLoaded = true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onEvent(event: WallpaperEvent) {
|
||||
when (event) {
|
||||
is WallpaperEvent.UpdateSelectedAlbum -> {
|
||||
viewModelScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
repository.deleteAll()
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (!event.setHome && !event.setLock) return@launch
|
||||
if (event.selectedAlbum != null) {
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedAlbum = event.selectedAlbum
|
||||
)
|
||||
}
|
||||
repository.upsertSelectedAlbum(event.selectedAlbum)
|
||||
}
|
||||
else if (event.album != null) {
|
||||
val wallpapers: List<Wallpaper> = event.album.wallpapers + event.album.folders.asSequence().flatMap { folder ->
|
||||
folder.wallpapers.asSequence().map { wallpaper ->
|
||||
Wallpaper(
|
||||
initialAlbumName = event.album.album.initialAlbumName,
|
||||
wallpaperUri = wallpaper,
|
||||
key = wallpaper.hashCode() + event.album.album.initialAlbumName.hashCode(),
|
||||
)
|
||||
}
|
||||
}.toList()
|
||||
val shuffledWallpapers1 = wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
val shuffledWallpapers2 = wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
val newSelectedAlbum = SelectedAlbum(
|
||||
album = event.album.album.copy(
|
||||
homeWallpapersInQueue = shuffledWallpapers1,
|
||||
lockWallpapersInQueue = shuffledWallpapers2,
|
||||
currentHomeWallpaper = if (event.setHome) shuffledWallpapers1.firstOrNull() else null,
|
||||
currentLockWallpaper = if (event.scheduleSeparately && event.setLock) shuffledWallpapers2.firstOrNull() else if (event.setLock) shuffledWallpapers1.firstOrNull() else null,
|
||||
),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedAlbum = newSelectedAlbum
|
||||
)
|
||||
}
|
||||
repository.upsertSelectedAlbum(newSelectedAlbum)
|
||||
}
|
||||
}
|
||||
}
|
||||
is WallpaperEvent.Refresh -> {
|
||||
refreshAlbums()
|
||||
}
|
||||
is WallpaperEvent.Reset -> {
|
||||
viewModelScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
repository.deleteAll()
|
||||
_state.update {
|
||||
WallpaperState()
|
||||
}
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedAlbum = null
|
||||
)
|
||||
}
|
||||
repository.deleteAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,10 +100,10 @@ class WallpaperScreenViewModel @Inject constructor (
|
||||
|
||||
// Retrieve album from database into viewModel
|
||||
private fun refreshAlbums() {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.getSelectedAlbum().collect { selectedAlbum ->
|
||||
_state.update { it.copy(
|
||||
selectedAlbum = selectedAlbum.firstOrNull()
|
||||
selectedAlbum = selectedAlbum.firstOrNull(),
|
||||
) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,6 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
|
||||
data class WallpaperState (
|
||||
val isDataLoaded: Boolean = false,
|
||||
val selectedAlbum: SelectedAlbum? = null
|
||||
)
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.asPaddingValues
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.navigationBars
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
@@ -28,13 +32,12 @@ import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.isValidUri
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -51,17 +54,6 @@ fun AlbumBottomSheet(
|
||||
onSelect: (AlbumWithWallpaperAndFolder) -> Unit,
|
||||
animate: Boolean
|
||||
) {
|
||||
fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.toUri()
|
||||
return try {
|
||||
uri?.let {
|
||||
val inputStream = context.contentResolver.openInputStream(it)
|
||||
inputStream?.close()
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
|
||||
val modalBottomSheetState = rememberModalBottomSheetState()
|
||||
val scope = rememberCoroutineScope()
|
||||
ModalBottomSheet(
|
||||
@@ -69,12 +61,17 @@ fun AlbumBottomSheet(
|
||||
sheetState = modalBottomSheetState,
|
||||
dragHandle = { BottomSheetDefaults.DragHandle() },
|
||||
containerColor = MaterialTheme.colorScheme.background,
|
||||
tonalElevation = 5.dp
|
||||
tonalElevation = 5.dp,
|
||||
modifier = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
||||
Modifier.fillMaxSize().padding(bottom = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding())
|
||||
} else {
|
||||
Modifier.padding(bottom = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding())
|
||||
}
|
||||
) {
|
||||
albums.forEach {
|
||||
if (it.folders.sumOf { folder -> folder.wallpapers.size } + it.wallpapers.size == 0) return@forEach
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.clickable {
|
||||
scope.launch {
|
||||
modalBottomSheetState.hide()
|
||||
@@ -88,8 +85,9 @@ fun AlbumBottomSheet(
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
) },
|
||||
supportingContent = {
|
||||
val totalWallpapers = it.folders.sumOf { folder -> folder.wallpapers.size } + it.wallpapers.size
|
||||
Text(
|
||||
text = (it.folders.sumOf { folder -> folder.wallpapers.size } + it.wallpapers.size).toString() + stringResource(R.string.wallpaper),
|
||||
text = LocalContext.current.resources.getQuantityString(R.plurals.wallpaper_count, totalWallpapers, totalWallpapers),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
@@ -103,15 +101,10 @@ fun AlbumBottomSheet(
|
||||
GlideImage(
|
||||
imageModel = { it.album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.FillBounds,
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(150, 150),
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import android.view.HapticFeedbackConstants
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
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.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Composable that displays a switch and slider for the user to adjust the blur effect of the wallpaper
|
||||
*/
|
||||
@Composable
|
||||
fun BlurSwitchAndSlider(
|
||||
onBlurPercentageChange: (Int) -> Unit,
|
||||
onBlurChange: (Boolean) -> Unit,
|
||||
blur: Boolean,
|
||||
blurPercentage: Int,
|
||||
animate: Boolean
|
||||
) {
|
||||
val view = LocalView.current
|
||||
val scope = rememberCoroutineScope()
|
||||
var job by remember { mutableStateOf<Job?>(null) }
|
||||
var percentage by rememberSaveable { mutableFloatStateOf(blurPercentage.toFloat()) }
|
||||
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
) {
|
||||
val columnModifier = if (animate) {
|
||||
Modifier.animateContentSize(animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing))
|
||||
} else { Modifier }
|
||||
Column (
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
modifier = columnModifier
|
||||
) {
|
||||
Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
text = stringResource(R.string.change_blur),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
Switch(
|
||||
checked = blur,
|
||||
onCheckedChange = onBlurChange
|
||||
)
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = blur,
|
||||
enter = expandVertically(animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)),
|
||||
exit = fadeOut(
|
||||
animationSpec = tween(
|
||||
durationMillis = 300,
|
||||
easing = LinearOutSlowInEasing
|
||||
)
|
||||
)
|
||||
) {
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, percentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
Slider(
|
||||
value = percentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
percentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onBlurPercentageChange(it.roundToInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (blur) {
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, percentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
Slider(
|
||||
value = percentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
percentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onBlurPercentageChange(it.roundToInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.MultiChoiceSegmentedButtonRow
|
||||
import androidx.compose.material3.SegmentedButton
|
||||
import androidx.compose.material3.SegmentedButtonDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
@Composable
|
||||
fun ChangerSelectionRow(
|
||||
homeEnabled : Boolean,
|
||||
lockEnabled : Boolean,
|
||||
onHomeCheckedChange: (Boolean) -> Unit,
|
||||
onLockCheckedChange: (Boolean) -> Unit
|
||||
) {
|
||||
MultiChoiceSegmentedButtonRow (
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(start = 16.dp, end = 16.dp,))
|
||||
) {
|
||||
SegmentedButton(
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 0, count = 2),
|
||||
onCheckedChange = onHomeCheckedChange,
|
||||
checked = homeEnabled
|
||||
) {
|
||||
Text(text = stringResource(R.string.home_screen_btn))
|
||||
}
|
||||
SegmentedButton(
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 1, count = 2),
|
||||
onCheckedChange = onLockCheckedChange,
|
||||
checked = lockEnabled
|
||||
) {
|
||||
Text(stringResource(R.string.lock_screen_btn))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.QueuePlayNext
|
||||
import androidx.compose.material.icons.outlined.RemoveFromQueue
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
@@ -18,13 +17,15 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Contains the current and next change components that shows the last and next set time
|
||||
*/
|
||||
@Composable
|
||||
fun CurrentAndNextChange(
|
||||
lastSetTime: String?,
|
||||
@@ -38,10 +39,10 @@ fun CurrentAndNextChange(
|
||||
) {
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(PaddingValues(16.dp, 8.dp, 8.dp, 8.dp))
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
@@ -56,10 +57,16 @@ fun CurrentAndNextChange(
|
||||
)
|
||||
Column {
|
||||
lastSetTime?.split(" ", "\n")?.let { parts ->
|
||||
if (parts.size == 3) {
|
||||
if (parts.size == 2) {
|
||||
Text(stringResource(R.string.last_change), style = textFirst, modifier = Modifier.align(Alignment.CenterHorizontally))
|
||||
Text(parts[0], style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally))
|
||||
Text("${parts[1]} ${parts[2]}", style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally)) }
|
||||
Text(parts[0].replace(',', ' '), style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally))
|
||||
Text(parts[1], style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally))
|
||||
}
|
||||
else if (parts.size == 3) {
|
||||
Text(stringResource(R.string.last_change), style = textFirst, modifier = Modifier.align(Alignment.CenterHorizontally))
|
||||
Text(parts[0].replace(',', ' '), style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally))
|
||||
Text(parts[1] + ' ' + parts[2], style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,10 +74,10 @@ fun CurrentAndNextChange(
|
||||
}
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(PaddingValues(16.dp, 8.dp, 8.dp, 8.dp))
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
@@ -85,10 +92,16 @@ fun CurrentAndNextChange(
|
||||
)
|
||||
Column {
|
||||
nextSetTime?.split(" ", "\n")?.let { parts ->
|
||||
if (parts.size == 3) {
|
||||
if (parts.size == 2) {
|
||||
Text(stringResource(R.string.next_change), style = textFirst, modifier = Modifier.align(Alignment.CenterHorizontally))
|
||||
Text(parts[0], style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally))
|
||||
Text("${parts[1]} ${parts[2]}", style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally)) }
|
||||
Text(parts[0].replace(',', ' '), style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally))
|
||||
Text(parts[1], style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally))
|
||||
}
|
||||
else if (parts.size == 3) {
|
||||
Text(stringResource(R.string.last_change), style = textFirst, modifier = Modifier.align(Alignment.CenterHorizontally))
|
||||
Text(parts[0].replace(',', ' '), style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally))
|
||||
Text(parts[1] + ' ' + parts[2], style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.c
|
||||
import android.content.Context
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
@@ -19,21 +21,23 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.rotate
|
||||
import androidx.compose.ui.draw.scale
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
|
||||
@@ -43,9 +47,11 @@ import com.skydoves.landscapist.glide.GlideImage
|
||||
@Composable
|
||||
fun CurrentSelectedAlbum(
|
||||
selectedAlbum: SelectedAlbum?,
|
||||
enableChanger: Boolean,
|
||||
onOpenBottomSheet: () -> Unit,
|
||||
onStop: () -> Unit,
|
||||
animate: Boolean
|
||||
animate: Boolean,
|
||||
onToggleChanger: (Boolean) -> Unit
|
||||
) {
|
||||
fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.toUri()
|
||||
@@ -62,9 +68,15 @@ fun CurrentSelectedAlbum(
|
||||
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.padding(PaddingValues(vertical = 8.dp, horizontal = 16.dp))
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.clickable { onOpenBottomSheet() },
|
||||
.clickable {
|
||||
if (selectedAlbum != null) {
|
||||
onToggleChanger(!enableChanger)
|
||||
} else {
|
||||
onOpenBottomSheet()
|
||||
}
|
||||
},
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = selectedAlbum?.album?.displayedAlbumName ?: stringResource(R.string.no_album_selected),
|
||||
@@ -75,7 +87,7 @@ fun CurrentSelectedAlbum(
|
||||
supportingContent = {
|
||||
if (selectedAlbum != null) {
|
||||
Text(
|
||||
text = "${selectedAlbum.wallpapers.size} ${stringResource(R.string.wallpaper)}",
|
||||
text = LocalContext.current.resources.getQuantityString(R.plurals.wallpaper_count, selectedAlbum.wallpapers.size, selectedAlbum.wallpapers.size),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
@@ -87,15 +99,10 @@ fun CurrentSelectedAlbum(
|
||||
GlideImage(
|
||||
imageModel = { selectedAlbum.album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.FillBounds,
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(150, 150),
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
@@ -119,7 +126,10 @@ fun CurrentSelectedAlbum(
|
||||
}
|
||||
},
|
||||
trailingContent = {
|
||||
Row {
|
||||
Row (
|
||||
horizontalArrangement = Arrangement.spacedBy((-8).dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
if (selectedAlbum != null) {
|
||||
IconButton(onClick = { onStop() }) {
|
||||
Icon(imageVector = Icons.Default.Stop, contentDescription = stringResource(R.string.stop_the_album))
|
||||
@@ -131,6 +141,15 @@ fun CurrentSelectedAlbum(
|
||||
imageVector = Icons.Filled.ArrowDropDown,
|
||||
)
|
||||
}
|
||||
if (selectedAlbum != null) {
|
||||
Switch(
|
||||
checked = enableChanger,
|
||||
onCheckedChange = onToggleChanger,
|
||||
modifier = Modifier
|
||||
.rotate(270f)
|
||||
.scale(0.75f)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
tonalElevation = 10.dp
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import android.view.HapticFeedbackConstants
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
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.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Composable that displays a switch and slider to adjust the brightness of the wallpaper
|
||||
*/
|
||||
@Composable
|
||||
fun DarkenSwitchAndSlider(
|
||||
onDarkCheck: (Boolean) -> Unit,
|
||||
onDarkenChange: (Int) -> Unit,
|
||||
darken: Boolean,
|
||||
darkenPercentage: Int,
|
||||
animate: Boolean
|
||||
) {
|
||||
val view = LocalView.current
|
||||
val scope = rememberCoroutineScope()
|
||||
var job by remember { mutableStateOf<Job?>(null) }
|
||||
var percentage by rememberSaveable { mutableFloatStateOf(darkenPercentage.toFloat()) }
|
||||
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
) {
|
||||
val columnModifier = if (animate) {
|
||||
Modifier.animateContentSize(animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing))
|
||||
} else { Modifier }
|
||||
Column (
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
modifier = columnModifier
|
||||
) {
|
||||
Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
text = stringResource(R.string.change_brightness),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
Switch(
|
||||
checked = darken,
|
||||
onCheckedChange = onDarkCheck
|
||||
)
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = darken,
|
||||
enter = expandVertically(animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)),
|
||||
exit = fadeOut(
|
||||
animationSpec = tween(
|
||||
durationMillis = 300,
|
||||
easing = LinearOutSlowInEasing
|
||||
)
|
||||
)
|
||||
) {
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, percentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
Slider(
|
||||
value = percentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
percentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onDarkenChange(it.roundToInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (darken) {
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, percentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
Slider(
|
||||
value = percentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
percentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onDarkenChange(it.roundToInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ErrorOutline
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Dialog to show when a live wallpaper is detected and ask the user to disable it
|
||||
*/
|
||||
@Composable
|
||||
fun ShowLiveWallpaperEnabledDialog(
|
||||
onDismissRequest: () -> Unit
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { onDismissRequest() },
|
||||
icon = { Icon(Icons.Filled.ErrorOutline, stringResource(R.string.disable_live_wallpaper)) },
|
||||
title = {
|
||||
Text(stringResource(R.string.live_wallpaper_detected))
|
||||
},
|
||||
text = {
|
||||
Text(stringResource(R.string.please_disable_your_live_wallpaper_to_use_the_wallpaper_changer))
|
||||
},
|
||||
confirmButton = {
|
||||
Button(
|
||||
onClick = { onDismissRequest() }
|
||||
) {
|
||||
Text(stringResource(R.string.ok))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.shrinkVertically
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
|
||||
|
||||
@Composable
|
||||
fun SetLockScreenSwitch(
|
||||
albumUri : String?,
|
||||
checked: Boolean,
|
||||
onCheckedChange: (Boolean) -> Unit,
|
||||
animate: Boolean
|
||||
) {
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
) {
|
||||
Column (horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) {
|
||||
Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
text = stringResource(R.string.set_as_lock_screen),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
Switch(
|
||||
checked = checked,
|
||||
onCheckedChange = onCheckedChange
|
||||
)
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = checked,
|
||||
enter = expandVertically(animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)),
|
||||
exit = shrinkVertically(animationSpec = tween(durationMillis = 700, easing = LinearOutSlowInEasing))
|
||||
) {
|
||||
Row(Modifier.fillMaxWidth()) {
|
||||
Column(
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.padding(4.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = stringResource(R.string.lock_screen), fontWeight = FontWeight.W500)
|
||||
if (albumUri != null) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = albumUri,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(3.dp, color = Color.Black, shape = RoundedCornerShape(16.dp)),
|
||||
aspectRatio = 9f / 19.5f,
|
||||
clickable = false,
|
||||
animate = true
|
||||
)
|
||||
}
|
||||
}
|
||||
Column(
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.padding(4.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = stringResource(R.string.home), fontWeight = FontWeight.W500)
|
||||
if (albumUri != null) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = albumUri,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(3.dp, color = Color.Black, shape = RoundedCornerShape(16.dp)),
|
||||
aspectRatio = 9f / 19.5f,
|
||||
clickable = false,
|
||||
animate = true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Row(Modifier.fillMaxWidth()) {
|
||||
if (checked) {
|
||||
Column(
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.padding(4.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = stringResource(R.string.lock_screen), fontWeight = FontWeight.W500)
|
||||
if (albumUri != null) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = albumUri,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(3.dp, color = Color.Black, shape = RoundedCornerShape(16.dp)),
|
||||
aspectRatio = 9f / 19.5f,
|
||||
clickable = false,
|
||||
animate = false
|
||||
)
|
||||
}
|
||||
}
|
||||
Column(
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.padding(4.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = stringResource(R.string.home), fontWeight = FontWeight.W500)
|
||||
if (albumUri != null) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = albumUri,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(3.dp, color = Color.Black, shape = RoundedCornerShape(16.dp)),
|
||||
aspectRatio = 9f / 19.5f,
|
||||
clickable = false,
|
||||
animate = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,34 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import android.view.HapticFeedbackConstants
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.shrinkVertically
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowDropDown
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -16,122 +38,402 @@ 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.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* TimeSliders is a composable that displays sliders for the user to select the time interval for changing wallpaper
|
||||
*/
|
||||
@Composable
|
||||
fun TimeSliders(
|
||||
onTimeChange: (Int, Int, Int) -> Unit,
|
||||
timeInMinutes: Int
|
||||
timeInMinutes1: Int,
|
||||
timeInMinutes2: Int,
|
||||
showInterval: Boolean,
|
||||
animate: Boolean,
|
||||
onShowIntervalChange: (Boolean) -> Unit,
|
||||
scheduleSeparately: Boolean,
|
||||
onScheduleSeparatelyChange: (Boolean) -> Unit,
|
||||
onTimeChange1: (Int, Int, Int) -> Unit,
|
||||
onTimeChange2: (Int, Int, Int) -> Unit,
|
||||
lockEnabled: Boolean,
|
||||
homeEnabled: Boolean,
|
||||
) {
|
||||
val view = LocalView.current
|
||||
var days by rememberSaveable { mutableFloatStateOf((timeInMinutes / (24 * 60)).toFloat()) }
|
||||
var hours by rememberSaveable { mutableFloatStateOf(((timeInMinutes % (24 * 60)) / 60).toFloat()) }
|
||||
var minutes by rememberSaveable { mutableFloatStateOf((timeInMinutes % 60).toFloat()) }
|
||||
var days1 by rememberSaveable { mutableFloatStateOf((timeInMinutes1 / (24 * 60)).toFloat()) }
|
||||
var hours1 by rememberSaveable { mutableFloatStateOf(((timeInMinutes1 % (24 * 60)) / 60).toFloat()) }
|
||||
var minutes1 by rememberSaveable { mutableFloatStateOf((timeInMinutes1 % 60).toFloat()) }
|
||||
var days2 by rememberSaveable { mutableFloatStateOf((timeInMinutes2 / (24 * 60)).toFloat()) }
|
||||
var hours2 by rememberSaveable { mutableFloatStateOf(((timeInMinutes2 % (24 * 60)) / 60).toFloat()) }
|
||||
var minutes2 by rememberSaveable { mutableFloatStateOf((timeInMinutes2 % 60).toFloat()) }
|
||||
val scope = rememberCoroutineScope()
|
||||
val context = LocalView.current
|
||||
var job by remember { mutableStateOf<Job?>(null) }
|
||||
|
||||
val columnModifier = remember {
|
||||
if (animate) {
|
||||
Modifier.animateContentSize(
|
||||
animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing)
|
||||
)
|
||||
} else { Modifier }
|
||||
}
|
||||
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
) {
|
||||
Column {
|
||||
val totalMinutes = (days.toInt() * 24 * 60) + (hours.toInt() * 60) + minutes.toInt()
|
||||
val displayDays = totalMinutes / (24 * 60)
|
||||
val displayHours = (totalMinutes % (24 * 60)) / 60
|
||||
val displayMinutes = totalMinutes % 60
|
||||
val formattedDays = when {
|
||||
displayDays > 1 -> "$displayDays days"
|
||||
displayDays == 1 -> "$displayDays day"
|
||||
else -> ""
|
||||
}
|
||||
val formattedHours = when {
|
||||
displayHours > 1 -> "$displayHours hours"
|
||||
displayHours == 1 -> "$displayHours hour"
|
||||
else -> ""
|
||||
}
|
||||
val formattedMinutes = when {
|
||||
displayMinutes > 1 -> "$displayMinutes minutes"
|
||||
displayMinutes == 1 -> "$displayMinutes minute"
|
||||
else -> ""
|
||||
}
|
||||
val formattedTime = "Interval | ${listOf(formattedDays, formattedHours, formattedMinutes).filter { it.isNotEmpty() }.joinToString(", ")}"
|
||||
Column (
|
||||
modifier = columnModifier
|
||||
) {
|
||||
val totalMinutes1 = (days1.toInt() * 24 * 60) + (hours1.toInt() * 60) + minutes1.toInt()
|
||||
val displayDays1 = totalMinutes1 / (24 * 60)
|
||||
val displayHours1 = (totalMinutes1 % (24 * 60)) / 60
|
||||
val displayMinutes1 = totalMinutes1 % 60
|
||||
|
||||
Text(
|
||||
text = formattedTime,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp, vertical = 12.dp)),
|
||||
fontWeight = FontWeight.W500
|
||||
val formattedDays1 = if (displayDays1 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.days, displayDays1, displayDays1)
|
||||
} else {""}
|
||||
|
||||
val formattedHours1 = if (displayHours1 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.hours, displayHours1, displayHours1)
|
||||
} else {""}
|
||||
|
||||
val formattedMinutes1 = if (displayMinutes1 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.minutes, displayMinutes1, displayMinutes1)
|
||||
} else {""}
|
||||
|
||||
val formattedTime1 = stringResource(
|
||||
if (scheduleSeparately)
|
||||
R.string.interval_home
|
||||
else
|
||||
R.string.interval,
|
||||
listOf(formattedDays1, formattedHours1, formattedMinutes1).filter { it.isNotEmpty() }.joinToString(", ")
|
||||
)
|
||||
|
||||
Slider(
|
||||
value = days,
|
||||
onValueChange = { newDays ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
days = newDays
|
||||
val totalMinutes = (newDays.toInt() * 24 * 60) + (hours.toInt() * 60) + minutes.toInt()
|
||||
if (totalMinutes < 15) {
|
||||
minutes = 15f - (hours.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange(newDays.toInt(), hours.toInt(), minutes.toInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..30f,
|
||||
steps = 30,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
val totalMinutes2 = (days2.toInt() * 24 * 60) + (hours2.toInt() * 60) + minutes2.toInt()
|
||||
val displayDays2 = totalMinutes2 / (24 * 60)
|
||||
val displayHours2 = (totalMinutes2 % (24 * 60)) / 60
|
||||
val displayMinutes2 = totalMinutes2 % 60
|
||||
|
||||
val formattedDays2 = if (displayDays2 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.days, displayDays2, displayDays2)
|
||||
} else {""}
|
||||
|
||||
val formattedHours2 = if (displayHours2 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.hours, displayHours2, displayHours2)
|
||||
} else {""}
|
||||
|
||||
val formattedMinutes2 = if (displayMinutes2 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.minutes, displayMinutes2, displayMinutes2)
|
||||
} else {""}
|
||||
|
||||
val formattedTime2 = stringResource(
|
||||
if (scheduleSeparately)
|
||||
R.string.interval_lock
|
||||
else
|
||||
R.string.interval,
|
||||
listOf(formattedDays2, formattedHours2, formattedMinutes2).filter { it.isNotEmpty() }.joinToString(", ")
|
||||
)
|
||||
|
||||
Slider(
|
||||
value = hours,
|
||||
onValueChange = { newHours ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
hours = newHours
|
||||
val totalMinutes = (days.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes.toInt()
|
||||
if (totalMinutes < 15) {
|
||||
minutes = 15f - (newHours.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange(days.toInt(), newHours.toInt(), minutes.toInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..24f,
|
||||
steps = 24,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Slider(
|
||||
value = minutes,
|
||||
onValueChange = { newMinutes ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
minutes = if (days.toInt() == 0 && hours.toInt() == 0 && newMinutes < 15) {
|
||||
15f
|
||||
Row (
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
Spacer(modifier = Modifier.width(32.dp))
|
||||
Text(
|
||||
text = if (showInterval) {
|
||||
formattedTime1
|
||||
} else {
|
||||
newMinutes
|
||||
if (scheduleSeparately) {
|
||||
stringResource(R.string.interval_text)
|
||||
} else {
|
||||
formattedTime1
|
||||
}
|
||||
},
|
||||
fontWeight = FontWeight.W500,
|
||||
)
|
||||
IconButton(
|
||||
onClick = { onShowIntervalChange(!showInterval) },
|
||||
) {
|
||||
Icon(imageVector = Icons.Filled.ArrowDropDown, contentDescription = stringResource(R.string.show_interval_sliders))
|
||||
}
|
||||
}
|
||||
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = showInterval,
|
||||
enter = expandVertically(
|
||||
animationSpec = spring(
|
||||
dampingRatio = Spring.DampingRatioMediumBouncy,
|
||||
stiffness = Spring.StiffnessLow
|
||||
)
|
||||
),
|
||||
exit = fadeOut(
|
||||
animationSpec = tween(
|
||||
durationMillis = 300,
|
||||
easing = LinearOutSlowInEasing
|
||||
)
|
||||
)
|
||||
) {
|
||||
Column {
|
||||
Slider(
|
||||
value = days1,
|
||||
onValueChange = { newDays ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
days1 = newDays
|
||||
val totalMinute =
|
||||
(newDays.toInt() * 24 * 60) + (hours1.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (hours1.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange1(newDays.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..30f,
|
||||
steps = 30,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Slider(
|
||||
value = hours1,
|
||||
onValueChange = { newHours ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
hours1 = newHours
|
||||
val totalMinute =
|
||||
(days1.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (newHours.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange1(days1.toInt(), newHours.toInt(), minutes1.toInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..24f,
|
||||
steps = 24,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Slider(
|
||||
value = minutes1,
|
||||
onValueChange = { newMinutes ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
minutes1 =
|
||||
if (days1.toInt() == 0 && hours1.toInt() == 0 && newMinutes < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat()
|
||||
} else {
|
||||
newMinutes
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange1(days1.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..60f,
|
||||
steps = 60,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
if (homeEnabled && lockEnabled) {
|
||||
AnimatedVisibility(
|
||||
visible = scheduleSeparately,
|
||||
enter = expandVertically(
|
||||
animationSpec = spring(
|
||||
dampingRatio = Spring.DampingRatioLowBouncy,
|
||||
stiffness = Spring.StiffnessLow
|
||||
)
|
||||
),
|
||||
exit = shrinkVertically(
|
||||
animationSpec = spring(
|
||||
dampingRatio = Spring.DampingRatioLowBouncy,
|
||||
stiffness = Spring.StiffnessLow
|
||||
)
|
||||
)
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Text(
|
||||
text = formattedTime2,
|
||||
fontWeight = FontWeight.W500,
|
||||
)
|
||||
Slider(
|
||||
value = days2,
|
||||
onValueChange = { newDays ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
days2 = newDays
|
||||
val totalMinute =
|
||||
(newDays.toInt() * 24 * 60) + (hours2.toInt() * 60) + minutes2.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes2 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (hours2.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange2(
|
||||
newDays.toInt(),
|
||||
hours2.toInt(),
|
||||
minutes2.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..30f,
|
||||
steps = 30,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Slider(
|
||||
value = hours2,
|
||||
onValueChange = { newHours ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
hours2 = newHours
|
||||
val totalMinute =
|
||||
(days2.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes2.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes2 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (newHours.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange2(
|
||||
days2.toInt(),
|
||||
newHours.toInt(),
|
||||
minutes2.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..24f,
|
||||
steps = 24,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Slider(
|
||||
value = minutes2,
|
||||
onValueChange = { newMinutes ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
minutes2 =
|
||||
if (days2.toInt() == 0 && hours2.toInt() == 0 && newMinutes < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat()
|
||||
} else {
|
||||
newMinutes
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange2(
|
||||
days2.toInt(),
|
||||
hours2.toInt(),
|
||||
minutes2.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..60f,
|
||||
steps = 60,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
}
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
Text(text = stringResource(R.string.individual_scheduling), fontWeight = FontWeight.W500)
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
Switch(
|
||||
checked = scheduleSeparately,
|
||||
onCheckedChange = onScheduleSeparatelyChange
|
||||
)
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange(days.toInt(), hours.toInt(), minutes.toInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..60f,
|
||||
steps = 60,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (showInterval) {
|
||||
Slider(
|
||||
value = days1,
|
||||
onValueChange = { newDays ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
days1 = newDays
|
||||
val totalMinute = (newDays.toInt() * 24 * 60) + (hours1.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (hours1.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange1(newDays.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..30f,
|
||||
steps = 30,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Slider(
|
||||
value = hours1,
|
||||
onValueChange = { newHours ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
hours1 = newHours
|
||||
val totalMinute = (days1.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (newHours.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange1(days1.toInt(), newHours.toInt(), minutes1.toInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..24f,
|
||||
steps = 24,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Slider(
|
||||
value = minutes1,
|
||||
onValueChange = { newMinutes ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
minutes1 = if (days1.toInt() == 0 && hours1.toInt() == 0 && newMinutes < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat()
|
||||
} else {
|
||||
newMinutes
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange1(days1.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..60f,
|
||||
steps = 60,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
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.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.SegmentedButton
|
||||
import androidx.compose.material3.SegmentedButtonDefaults
|
||||
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
|
||||
|
||||
/**
|
||||
* SetLockScreenSwitch is a composable that displays a switch to set the wallpaper as the lock screen wallpaper
|
||||
* Also shows a preview of lock and home screen when enabled along with brightness added
|
||||
*/
|
||||
@Composable
|
||||
fun WallpaperPreviewAndScale(
|
||||
currentHomeWallpaper: String?,
|
||||
currentLockWallpaper: String?,
|
||||
animate: Boolean,
|
||||
darken: Boolean,
|
||||
darkenPercentage: Int,
|
||||
homeEnabled: Boolean,
|
||||
lockEnabled: Boolean,
|
||||
scaling: ScalingConstants,
|
||||
onScalingChange: (ScalingConstants) -> Unit,
|
||||
blur: Boolean,
|
||||
blurPercentage: Int,
|
||||
) {
|
||||
var selectedIndex by rememberSaveable {
|
||||
mutableIntStateOf(
|
||||
when (scaling) {
|
||||
ScalingConstants.FILL -> 0
|
||||
ScalingConstants.FIT -> 1
|
||||
ScalingConstants.STRETCH -> 2
|
||||
}
|
||||
)
|
||||
}
|
||||
val options = listOf(
|
||||
stringResource(R.string.fill),
|
||||
stringResource(R.string.fit),
|
||||
stringResource(R.string.stretch)
|
||||
)
|
||||
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
) {
|
||||
Column (
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
val modifier = if (lockEnabled && homeEnabled) {
|
||||
Modifier.weight(1f).padding(8.dp)
|
||||
} else {
|
||||
Modifier.fillMaxSize(0.5f).padding(8.dp)
|
||||
}
|
||||
|
||||
if (lockEnabled) {
|
||||
Column(
|
||||
modifier = modifier,
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = stringResource(R.string.lock_screen), fontWeight = FontWeight.W500)
|
||||
if (currentLockWallpaper != null) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = currentLockWallpaper,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(
|
||||
3.dp,
|
||||
color = Color.Black,
|
||||
shape = RoundedCornerShape(16.dp)
|
||||
),
|
||||
aspectRatio = 9f / 19.5f,
|
||||
clickable = false,
|
||||
animate = animate,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
scaling = scaling,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
if (homeEnabled) {
|
||||
Column(
|
||||
modifier = modifier,
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = stringResource(R.string.home), fontWeight = FontWeight.W500)
|
||||
if (currentHomeWallpaper != null) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = currentHomeWallpaper,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(
|
||||
3.dp,
|
||||
color = Color.Black,
|
||||
shape = RoundedCornerShape(16.dp)
|
||||
),
|
||||
aspectRatio = 9f / 19.5f,
|
||||
clickable = false,
|
||||
animate = animate,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
scaling = scaling,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SingleChoiceSegmentedButtonRow (
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(start = 8.dp, end = 8.dp, bottom = 16.dp))
|
||||
) {
|
||||
options.forEachIndexed { index, label ->
|
||||
SegmentedButton(
|
||||
shape = SegmentedButtonDefaults.itemShape(index = index, count = options.size),
|
||||
onClick = {
|
||||
selectedIndex = index
|
||||
onScalingChange(
|
||||
when (index) {
|
||||
0 -> ScalingConstants.FILL
|
||||
1 -> ScalingConstants.FIT
|
||||
2 -> ScalingConstants.STRETCH
|
||||
else -> ScalingConstants.FILL
|
||||
}
|
||||
) },
|
||||
selected = index == selectedIndex
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Icon(
|
||||
painter = when (index) {
|
||||
0 -> painterResource(id = R.drawable.fill)
|
||||
1 -> painterResource(id = R.drawable.fit)
|
||||
2 -> painterResource(id = R.drawable.stretch)
|
||||
else -> painterResource(id = R.drawable.fill)
|
||||
},
|
||||
contentDescription = null,
|
||||
tint = Color.Unspecified,
|
||||
modifier = Modifier.size(40.dp)
|
||||
)
|
||||
Text(text = label, maxLines = 1, overflow = TextOverflow.Ellipsis )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,6 @@ import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
import net.engawapg.lib.zoomable.rememberZoomState
|
||||
@@ -76,6 +74,7 @@ fun WallpaperViewScreen(
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen),
|
||||
tint = Color.White
|
||||
)
|
||||
}
|
||||
},
|
||||
@@ -103,15 +102,9 @@ fun WallpaperViewScreen(
|
||||
GlideImage(
|
||||
imageModel = { wallpaperUri.toUri() },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
contentScale = ContentScale.Fit,
|
||||
alignment = Alignment.Center
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
|
||||
@@ -61,4 +61,4 @@ data class WallpaperView(val wallpaper: String)
|
||||
* Data class for FolderView screen
|
||||
*/
|
||||
@Serializable
|
||||
data class FolderView(val folderName: String?, val wallpapers: List<String>)
|
||||
data class FolderView(val folderName: String?, val wallpapers: List<String>)
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager
|
||||
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
|
||||
/**
|
||||
* Data class for storing wallpaper alarm item
|
||||
* @param timeInMinutes1: Int - time in minutes for home wallpaper or both if scheduled together
|
||||
* @param timeInMinutes2: Int - time in minutes for lock wallpaper
|
||||
* @param scheduleSeparately: Boolean - schedule wallpapers separately
|
||||
*/
|
||||
data class WallpaperAlarmItem(
|
||||
val timeInMinutes1: Int = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val timeInMinutes2: Int = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val scheduleSeparately: Boolean = false
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager
|
||||
|
||||
interface WallpaperAlarmScheduler {
|
||||
/**
|
||||
* Schedule a wallpaper alarm to change the wallpaper
|
||||
* @param wallpaperAlarmItem the wallpaper alarm item to schedule
|
||||
* @param origin where the request came from (null if not from a specific origin, 0 if home screen, 1 if lock screen, 2 if both)
|
||||
* @param changeImmediate whether to change the wallpaper immediately or just schedule the alarm
|
||||
* @param cancelImmediate whether to cancel all alarms before scheduling the new one
|
||||
*/
|
||||
fun scheduleWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem, origin: Int? = null, changeImmediate: Boolean = false, cancelImmediate: Boolean = false)
|
||||
|
||||
/**
|
||||
* Update the wallpaper alarm with new times without changing the wallpaper
|
||||
*/
|
||||
fun updateWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem)
|
||||
|
||||
/**
|
||||
* Update the wallpaper without changing the alarm
|
||||
*/
|
||||
fun updateWallpaper(scheduleSeparately: Boolean)
|
||||
|
||||
/**
|
||||
* Cancel all wallpaper alarms
|
||||
*/
|
||||
fun cancelWallpaperAlarm()
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
|
||||
/**
|
||||
* Receiver for boot and time change events to restart alarm manager
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class WallpaperBootAndTimeChangeReceiver : BroadcastReceiver() {
|
||||
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
override fun onReceive(context: Context, intent: Intent) = goAsync {
|
||||
try {
|
||||
if (Intent.ACTION_BOOT_COMPLETED == intent.action || Intent.ACTION_TIME_CHANGED == intent.action || Intent.ACTION_TIMEZONE_CHANGED == intent.action) {
|
||||
val scheduler = WallpaperScheduler(context)
|
||||
val toggleChanger = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false
|
||||
if (toggleChanger) {
|
||||
val timeInMinutes1 = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val timeInMinutes2 = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val scheduleSeparately = settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
timeInMinutes1 = timeInMinutes1,
|
||||
timeInMinutes2 = timeInMinutes2,
|
||||
scheduleSeparately = scheduleSeparately
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, false, true)}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
/* https://stackoverflow.com/questions/74111692/run-coroutine-functions-on-broadcast-receiver */
|
||||
private fun BroadcastReceiver.goAsync(
|
||||
context: CoroutineContext = EmptyCoroutineContext,
|
||||
block: suspend CoroutineScope.() -> Unit
|
||||
) {
|
||||
val pendingResult = goAsync()
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
GlobalScope.launch(context) {
|
||||
try {
|
||||
block()
|
||||
} finally {
|
||||
pendingResult.finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
import com.anthonyla.paperize.core.Type
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.WallpaperService1
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.WallpaperService2
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
/**
|
||||
* Receiver for the alarm manager to change wallpaper
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class WallpaperReceiver: BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (context != null) {
|
||||
val refresh = intent?.getBooleanExtra("refresh", false) ?: false
|
||||
if (refresh) {
|
||||
val serviceIntent = Intent(context, WallpaperService1::class.java).apply {
|
||||
action = WallpaperService1.Actions.REFRESH.toString()
|
||||
}
|
||||
context.startService(serviceIntent)
|
||||
WallpaperScheduler(context).scheduleRefresh()
|
||||
}
|
||||
else {
|
||||
val timeInMinutes1 = intent?.getIntExtra("timeInMinutes1", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val timeInMinutes2 = intent?.getIntExtra("timeInMinutes2", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val scheduleSeparately = intent?.getBooleanExtra("scheduleSeparately", false) ?: false
|
||||
val type = intent?.getIntExtra("type", Type.BOTH.ordinal) ?: Type.BOTH.ordinal
|
||||
val serviceIntent = Intent().apply {
|
||||
putExtra("timeInMinutes1", timeInMinutes1)
|
||||
putExtra("timeInMinutes2", timeInMinutes2)
|
||||
putExtra("scheduleSeparately", scheduleSeparately)
|
||||
putExtra("type", type)
|
||||
}
|
||||
if (type == Type.BOTH.ordinal || type == Type.HOME.ordinal) {
|
||||
serviceIntent.setClass(context, WallpaperService1::class.java).apply {
|
||||
action = WallpaperService1.Actions.START.toString()
|
||||
}
|
||||
} else {
|
||||
serviceIntent.setClass(context, WallpaperService2::class.java).apply {
|
||||
action = WallpaperService2.Actions.START.toString()
|
||||
}
|
||||
}
|
||||
context.startService(serviceIntent)
|
||||
|
||||
// Schedule next alarm for next wallpaper change
|
||||
val origin = intent?.getIntExtra("origin", -1)?.takeIf { it != -1 }
|
||||
WallpaperScheduler(context).scheduleWallpaperAlarm(
|
||||
WallpaperAlarmItem(
|
||||
timeInMinutes1 = timeInMinutes1,
|
||||
timeInMinutes2 = timeInMinutes2,
|
||||
scheduleSeparately = scheduleSeparately
|
||||
),
|
||||
origin
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import com.anthonyla.paperize.core.Type
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.WallpaperService1
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.WallpaperService2
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
|
||||
/**
|
||||
* This class is responsible for scheduling wallpaper alarms.
|
||||
* It uses the AlarmManager to schedule alarms for the WallpaperReceiver.
|
||||
* It also uses the WallpaperService to change the wallpaper due to receiver limitations.
|
||||
*/
|
||||
class WallpaperScheduler (
|
||||
private val context: Context,
|
||||
): WallpaperAlarmScheduler {
|
||||
private val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
|
||||
/**
|
||||
* Schedules the wallpaper alarm based on the origin and changeImmediate
|
||||
*/
|
||||
override fun scheduleWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem, origin: Int?, changeImmediate: Boolean, cancelImmediate: Boolean) {
|
||||
if (cancelImmediate) cancelWallpaperAlarm()
|
||||
else {
|
||||
when(origin) {
|
||||
Type.HOME.ordinal -> cancelAlarm(Type.HOME)
|
||||
Type.LOCK.ordinal -> cancelAlarm(Type.LOCK)
|
||||
null -> {
|
||||
cancelAlarm(Type.HOME)
|
||||
cancelAlarm(Type.LOCK)
|
||||
cancelAlarm(Type.BOTH)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wallpaperAlarmItem.scheduleSeparately) {
|
||||
when (origin) {
|
||||
Type.LOCK.ordinal -> {
|
||||
if (changeImmediate) changeWallpaperImmediate(wallpaperAlarmItem, Type.LOCK)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, origin)
|
||||
}
|
||||
Type.HOME.ordinal -> {
|
||||
if (changeImmediate) changeWallpaperImmediate(wallpaperAlarmItem, Type.HOME)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, origin)
|
||||
}
|
||||
null -> {
|
||||
if (changeImmediate) {
|
||||
changeWallpaperImmediate(wallpaperAlarmItem, Type.LOCK)
|
||||
changeWallpaperImmediate(wallpaperAlarmItem, Type.HOME)
|
||||
}
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, Type.LOCK.ordinal)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, Type.HOME.ordinal)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (changeImmediate) changeWallpaperImmediate(wallpaperAlarmItem, Type.BOTH)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.BOTH)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the alarms
|
||||
*/
|
||||
override fun updateWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem) {
|
||||
cancelWallpaperAlarm()
|
||||
if (wallpaperAlarmItem.scheduleSeparately) {
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, null, true)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, null, true)
|
||||
}
|
||||
else {
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.BOTH, null, true)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the wallpaper without scheduling alarms
|
||||
*/
|
||||
override fun updateWallpaper(scheduleSeparately: Boolean) {
|
||||
if (scheduleSeparately) {
|
||||
updateWallpaper(Type.LOCK)
|
||||
updateWallpaper(Type.HOME)
|
||||
}
|
||||
else {
|
||||
updateWallpaper(Type.BOTH)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels all active alarms
|
||||
*/
|
||||
override fun cancelWallpaperAlarm() {
|
||||
cancelAlarm(Type.HOME)
|
||||
cancelAlarm(Type.LOCK)
|
||||
cancelAlarm(Type.BOTH)
|
||||
cancelAlarm(Type.REFRESH)
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules the wallpaper alarm based on type and time
|
||||
*/
|
||||
private fun scheduleWallpaper(wallpaperAlarmItem: WallpaperAlarmItem, type: Type, origin: Int? = null, update: Boolean = false) {
|
||||
val nextTime = when (type) {
|
||||
Type.HOME, Type.BOTH -> LocalDateTime.now().plusMinutes(wallpaperAlarmItem.timeInMinutes1.toLong())
|
||||
Type.LOCK -> LocalDateTime.now().plusMinutes(wallpaperAlarmItem.timeInMinutes2.toLong())
|
||||
else -> LocalDateTime.now()
|
||||
}
|
||||
val intent = Intent(context, WallpaperReceiver::class.java).apply {
|
||||
putExtra("timeInMinutes1", wallpaperAlarmItem.timeInMinutes1)
|
||||
putExtra("timeInMinutes2", wallpaperAlarmItem.timeInMinutes2)
|
||||
putExtra("scheduleSeparately", wallpaperAlarmItem.scheduleSeparately)
|
||||
putExtra("type", type.ordinal)
|
||||
putExtra("origin", origin)
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
if (!alarmManager.canScheduleExactAlarms()) {
|
||||
cancelWallpaperAlarm()
|
||||
}
|
||||
else {
|
||||
alarmManager.setExactAndAllowWhileIdle(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
nextTime.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
type.ordinal,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
alarmManager.setExactAndAllowWhileIdle(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
nextTime.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
type.ordinal,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
)
|
||||
}
|
||||
if (update) {
|
||||
val serviceIntent = Intent().apply {
|
||||
putExtra("timeInMinutes1", wallpaperAlarmItem.timeInMinutes1)
|
||||
putExtra("timeInMinutes2", wallpaperAlarmItem.timeInMinutes2)
|
||||
putExtra("scheduleSeparately", wallpaperAlarmItem.scheduleSeparately)
|
||||
putExtra("type", type.ordinal)
|
||||
}
|
||||
if (type == Type.BOTH || type == Type.HOME) {
|
||||
serviceIntent.setClass(context, WallpaperService1::class.java).apply {
|
||||
action = WallpaperService1.Actions.REQUEUE.toString()
|
||||
}
|
||||
} else {
|
||||
serviceIntent.setClass(context, WallpaperService2::class.java).apply {
|
||||
action = WallpaperService2.Actions.REQUEUE.toString()
|
||||
}
|
||||
}
|
||||
context.startService(serviceIntent)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a refresh alarm every 24hrs
|
||||
*/
|
||||
fun scheduleRefresh() {
|
||||
cancelAlarm(Type.REFRESH)
|
||||
val intent = Intent(context, WallpaperReceiver::class.java).apply {
|
||||
putExtra("refresh", true)
|
||||
}
|
||||
val nextMidnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
if (!alarmManager.canScheduleExactAlarms()) {
|
||||
cancelWallpaperAlarm()
|
||||
}
|
||||
else {
|
||||
alarmManager.setExact(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
nextMidnight.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
Type.REFRESH.ordinal,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
alarmManager.setExact(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
nextMidnight.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
Type.REFRESH.ordinal,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the service to change the wallpaper
|
||||
*/
|
||||
private fun changeWallpaperImmediate(wallpaperAlarmItem: WallpaperAlarmItem, type: Type) {
|
||||
val serviceIntent = Intent().apply {
|
||||
putExtra("timeInMinutes1", wallpaperAlarmItem.timeInMinutes1)
|
||||
putExtra("timeInMinutes2", wallpaperAlarmItem.timeInMinutes2)
|
||||
putExtra("scheduleSeparately", wallpaperAlarmItem.scheduleSeparately)
|
||||
putExtra("type", type.ordinal)
|
||||
}
|
||||
if (type == Type.BOTH || type == Type.HOME) {
|
||||
serviceIntent.setClass(context, WallpaperService1::class.java).apply {
|
||||
action = WallpaperService1.Actions.START.toString()
|
||||
}
|
||||
} else {
|
||||
serviceIntent.setClass(context, WallpaperService2::class.java).apply {
|
||||
action = WallpaperService2.Actions.START.toString()
|
||||
}
|
||||
}
|
||||
context.startService(serviceIntent)
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the wallpaper without changing the alarm
|
||||
*/
|
||||
private fun updateWallpaper(type: Type) {
|
||||
val serviceIntent = Intent()
|
||||
if (type == Type.BOTH || type == Type.HOME) {
|
||||
serviceIntent.setClass(context, WallpaperService1::class.java).apply {
|
||||
action = WallpaperService1.Actions.UPDATE.toString()
|
||||
}
|
||||
} else {
|
||||
serviceIntent.setClass(context, WallpaperService2::class.java).apply {
|
||||
action = WallpaperService2.Actions.UPDATE.toString()
|
||||
}
|
||||
}
|
||||
context.startService(serviceIntent)
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the alarm based on type
|
||||
*/
|
||||
private fun cancelAlarm(type: Type) {
|
||||
val pendingIntent = PendingIntent.getBroadcast(
|
||||
context,
|
||||
type.ordinal,
|
||||
Intent(context, WallpaperReceiver::class.java),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
alarmManager.cancel(pendingIntent)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,726 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.wallpaper_service
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.app.Service
|
||||
import android.app.WallpaperManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.ImageDecoder
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.os.IBinder
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.Log
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.core.Type
|
||||
import com.anthonyla.paperize.core.blurBitmap
|
||||
import com.anthonyla.paperize.core.calculateInSampleSize
|
||||
import com.anthonyla.paperize.core.darkenBitmap
|
||||
import com.anthonyla.paperize.core.fillBitmap
|
||||
import com.anthonyla.paperize.core.fitBitmap
|
||||
import com.anthonyla.paperize.core.getImageDimensions
|
||||
import com.anthonyla.paperize.core.getWallpaperFromFolder
|
||||
import com.anthonyla.paperize.core.stretchBitmap
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.SelectedAlbumRepository
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.MainActivity
|
||||
import com.lazygeniouz.dfc.file.DocumentFileCompat
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.IOException
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.format.FormatStyle
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* Main service for changing the wallpaper if wallpapers are scheduled together
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class WallpaperService1: Service() {
|
||||
private val handleThread = HandlerThread("MyThread1")
|
||||
private lateinit var workerHandler: Handler
|
||||
@Inject lateinit var selectedRepository: SelectedAlbumRepository
|
||||
@Inject lateinit var albumRepository: AlbumRepository
|
||||
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
private var scheduleSeparately: Boolean = false
|
||||
private var timeInMinutes1: Int = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
private var timeInMinutes2: Int = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
private var nextSetTime1: LocalDateTime? = null
|
||||
private var nextSetTime2: LocalDateTime? = null
|
||||
private var nextSetTime: LocalDateTime? = null
|
||||
|
||||
enum class Actions {
|
||||
START,
|
||||
REQUEUE,
|
||||
UPDATE,
|
||||
REFRESH
|
||||
}
|
||||
|
||||
override fun onBind(p0: Intent?): IBinder? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
handleThread.start()
|
||||
workerHandler = Handler(handleThread.looper)
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
if (intent != null) {
|
||||
when (intent.action) {
|
||||
Actions.START.toString() -> {
|
||||
timeInMinutes1 = intent.getIntExtra("timeInMinutes1", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
timeInMinutes2 = intent.getIntExtra("timeInMinutes2", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
scheduleSeparately = intent.getBooleanExtra("scheduleSeparately", false)
|
||||
val setHomeOrLock = if (scheduleSeparately) {
|
||||
when (intent.getIntExtra("type", Type.BOTH.ordinal)) {
|
||||
Type.HOME.ordinal -> true
|
||||
Type.LOCK.ordinal -> false
|
||||
else -> null
|
||||
}
|
||||
} else { null }
|
||||
workerTaskStart(setHomeOrLock)
|
||||
}
|
||||
Actions.REQUEUE.toString() -> {
|
||||
timeInMinutes1 = intent.getIntExtra("timeInMinutes1", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
timeInMinutes2 = intent.getIntExtra("timeInMinutes2", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
scheduleSeparately = intent.getBooleanExtra("scheduleSeparately", false)
|
||||
workerTaskRequeue()
|
||||
}
|
||||
Actions.UPDATE.toString() -> {
|
||||
workerTaskUpdate()
|
||||
}
|
||||
Actions.REFRESH.toString() -> {
|
||||
workerTaskRefresh()
|
||||
}
|
||||
}
|
||||
}
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
workerHandler.removeCallbacksAndMessages(null)
|
||||
handleThread.quitSafely()
|
||||
}
|
||||
|
||||
private fun workerTaskStart(setHomeOrLock: Boolean? = null) {
|
||||
workerHandler.post {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
if (scheduleSeparately) delay(5000)
|
||||
changeWallpaper(this@WallpaperService1, setHomeOrLock)
|
||||
}
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
|
||||
private fun workerTaskRequeue() {
|
||||
workerHandler.post {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
nextSetTime1 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_1))
|
||||
nextSetTime2 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_2))
|
||||
nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)
|
||||
val notification = createNotification()
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notification?.let { notificationManager.notify(1, it) }
|
||||
}
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
|
||||
private fun workerTaskUpdate() {
|
||||
workerHandler.post {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
updateCurrentWallpaper(this@WallpaperService1)
|
||||
}
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
|
||||
private fun workerTaskRefresh() {
|
||||
workerHandler.post {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
refreshAlbum(this@WallpaperService1)
|
||||
}
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a notification for the wallpaper service
|
||||
*/
|
||||
private fun createNotification(): Notification? {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
if (nextSetTime != null) {
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
val pendingIntent = PendingIntent.getActivity(this, 3, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return NotificationCompat.Builder(this, "wallpaper_service_channel")
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setContentText(getString(R.string.next_wallpaper_change, nextSetTime!!.format(formatter)))
|
||||
.setSmallIcon(R.drawable.notification_icon)
|
||||
.setContentIntent(pendingIntent)
|
||||
.build()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the wallpaper to the next wallpaper in the queue of the selected album
|
||||
* If none left, reshuffle the wallpapers and pick the first one
|
||||
*/
|
||||
private suspend fun changeWallpaper(context: Context, setHomeOrLock: Boolean? = null) {
|
||||
try {
|
||||
val selectedAlbum = selectedRepository.getSelectedAlbum().first().firstOrNull()
|
||||
if (selectedAlbum == null) {
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
else {
|
||||
val toggled = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false
|
||||
val setHome = settingsDataStoreImpl.getBoolean(SettingsConstants.HOME_WALLPAPER) ?: false
|
||||
val setLock = settingsDataStoreImpl.getBoolean(SettingsConstants.LOCK_WALLPAPER) ?: false
|
||||
nextSetTime1 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_1))
|
||||
nextSetTime2 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_2))
|
||||
if (!toggled || (!setHome && !setLock)) {
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now()
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
|
||||
|
||||
if (setHomeOrLock == null) {
|
||||
nextSetTime1 = currentTime.plusMinutes(timeInMinutes1.toLong())
|
||||
nextSetTime2 = nextSetTime1
|
||||
nextSetTime = nextSetTime1
|
||||
nextSetTime?.let { settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, it.format(formatter)) }
|
||||
}
|
||||
else {
|
||||
if (setHomeOrLock) { nextSetTime1 = currentTime.plusMinutes(timeInMinutes1.toLong()) }
|
||||
else { nextSetTime2 = currentTime.plusMinutes(timeInMinutes2.toLong()) }
|
||||
nextSetTime = if (nextSetTime1 == null && nextSetTime2 != null) {
|
||||
nextSetTime2
|
||||
} else if (nextSetTime1 != null && nextSetTime2 == null) {
|
||||
nextSetTime1
|
||||
} else {
|
||||
if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2
|
||||
}
|
||||
nextSetTime?.let { settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, it.format(formatter)) }
|
||||
}
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, nextSetTime1.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, nextSetTime2.toString())
|
||||
|
||||
val notification = createNotification()
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notification?.let { notificationManager.notify(1, it) }
|
||||
|
||||
val scaling = settingsDataStoreImpl.getString(SettingsConstants.WALLPAPER_SCALING)?.let { ScalingConstants.valueOf(it) } ?: ScalingConstants.FILL
|
||||
val darken = settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false
|
||||
val darkenPercentage = settingsDataStoreImpl.getInt(SettingsConstants.DARKEN_PERCENTAGE) ?: 100
|
||||
val blur = settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false
|
||||
val blurPercentage = settingsDataStoreImpl.getInt(SettingsConstants.BLUR_PERCENTAGE) ?: 0
|
||||
|
||||
selectedAlbum.let { it ->
|
||||
if (setHomeOrLock != null) {
|
||||
var wallpaper = if (setHomeOrLock) it.album.homeWallpapersInQueue.firstOrNull() else it.album.lockWallpapersInQueue.firstOrNull()
|
||||
if (wallpaper != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
setLockOrHome = setHomeOrLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = if (setHomeOrLock) it.album.homeWallpapersInQueue.drop(1) else it.album.homeWallpapersInQueue,
|
||||
lockWallpapersInQueue = if (!setHomeOrLock) it.album.lockWallpapersInQueue.drop(1) else it.album.lockWallpapersInQueue
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 },
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
} else {
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = if (setHomeOrLock) it.album.homeWallpapersInQueue.drop(1) else it.album.homeWallpapersInQueue,
|
||||
lockWallpapersInQueue = if (!setHomeOrLock) it.album.lockWallpapersInQueue.drop(1) else it.album.lockWallpapersInQueue,
|
||||
currentHomeWallpaper = if (setHomeOrLock) wallpaper else it.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (!setHomeOrLock) wallpaper else it.album.currentLockWallpaper
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
// No more wallpapers in the queue -- reshuffle the wallpapers
|
||||
else {
|
||||
val newWallpaperInQueue = it.wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
wallpaper = newWallpaperInQueue.firstOrNull()
|
||||
if (wallpaper != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
setLockOrHome = setHomeOrLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)
|
||||
) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = if (setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.homeWallpapersInQueue,
|
||||
lockWallpapersInQueue = if (!setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.lockWallpapersInQueue
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 }
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
} else {
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = if (setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.homeWallpapersInQueue,
|
||||
lockWallpapersInQueue = if (!setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.lockWallpapersInQueue,
|
||||
currentHomeWallpaper = if (setHomeOrLock) wallpaper else it.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (!setHomeOrLock) wallpaper else it.album.currentLockWallpaper
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
} else { onDestroy() }
|
||||
}
|
||||
}
|
||||
else {
|
||||
var wallpaper = it.album.homeWallpapersInQueue.firstOrNull()
|
||||
if (wallpaper != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = it.album.homeWallpapersInQueue.drop(1),
|
||||
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper }
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 },
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
} else {
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = it.album.homeWallpapersInQueue.drop(1),
|
||||
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper },
|
||||
currentHomeWallpaper = wallpaper,
|
||||
currentLockWallpaper = wallpaper
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
// No more wallpapers in the queue -- reshuffle the wallpapers
|
||||
else {
|
||||
val newWallpaperInQueue = it.wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
wallpaper = newWallpaperInQueue.firstOrNull()
|
||||
if (wallpaper != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
setLockOrHome = setHomeOrLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)
|
||||
) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = it.album.homeWallpapersInQueue.drop(1),
|
||||
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper }
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 }
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
} else {
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = newWallpaperInQueue.drop(1),
|
||||
currentHomeWallpaper = wallpaper,
|
||||
currentLockWallpaper = wallpaper
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
} else { onDestroy() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error in changing wallpaper", e)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun updateCurrentWallpaper(context: Context) {
|
||||
try {
|
||||
val selectedAlbum = selectedRepository.getSelectedAlbum().first().firstOrNull()
|
||||
if (selectedAlbum == null) {
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
else {
|
||||
val setHome = settingsDataStoreImpl.getBoolean(SettingsConstants.HOME_WALLPAPER) ?: false
|
||||
val setLock = settingsDataStoreImpl.getBoolean(SettingsConstants.LOCK_WALLPAPER) ?: false
|
||||
if (!setHome && !setLock) {
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val time = LocalDateTime.now()
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, time.format(formatter))
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, time.plusMinutes(timeInMinutes1.toLong()).format(formatter))
|
||||
val scaling = settingsDataStoreImpl.getString(SettingsConstants.WALLPAPER_SCALING)?.let { ScalingConstants.valueOf(it) } ?: ScalingConstants.FILL
|
||||
val darken = settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false
|
||||
val darkenPercentage = settingsDataStoreImpl.getInt(SettingsConstants.DARKEN_PERCENTAGE) ?: 100
|
||||
val blur = settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false
|
||||
val blurPercentage = settingsDataStoreImpl.getInt(SettingsConstants.BLUR_PERCENTAGE) ?: 0
|
||||
|
||||
selectedAlbum.let { it ->
|
||||
val wallpaper1 = it.album.currentHomeWallpaper
|
||||
val wallpaper2 = it.album.currentLockWallpaper
|
||||
if (wallpaper1 != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper1.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
setLockOrHome = true,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull{ it.wallpaperUri == wallpaper1 }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = it.album.homeWallpapersInQueue.filter { it != wallpaper1 },
|
||||
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper1 }
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 },
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wallpaper2 != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper2.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
setLockOrHome = false,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull{ it.wallpaperUri == wallpaper2 }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = it.album.homeWallpapersInQueue.filter { it != wallpaper1 },
|
||||
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper1 }
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 },
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error in updating", e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the wallpaper to the given uri
|
||||
*/
|
||||
private fun setWallpaper(
|
||||
context: Context,
|
||||
wallpaper: Uri,
|
||||
darken: Boolean,
|
||||
darkenPercent: Int,
|
||||
scaling: ScalingConstants,
|
||||
setHome: Boolean, setLock: Boolean,
|
||||
setLockOrHome: Boolean? = null,
|
||||
blur: Boolean = false,
|
||||
blurPercent: Int,
|
||||
): Boolean {
|
||||
val wallpaperManager = WallpaperManager.getInstance(context)
|
||||
try {
|
||||
val imageSize = wallpaper.getImageDimensions(context) ?: return false
|
||||
val aspectRatio = imageSize.height.toFloat() / imageSize.width.toFloat()
|
||||
val device = context.resources.displayMetrics
|
||||
val targetWidth = min(device.widthPixels, imageSize.width)
|
||||
val targetHeight = (targetWidth * aspectRatio).toInt()
|
||||
|
||||
val bitmap = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
try {
|
||||
val source = ImageDecoder.createSource(context.contentResolver, wallpaper)
|
||||
ImageDecoder.decodeBitmap(source) { decoder, _, _ ->
|
||||
decoder.setTargetSize(targetWidth, targetHeight)
|
||||
decoder.isMutableRequired = true
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
context.contentResolver.openInputStream(wallpaper)?.use { inputStream ->
|
||||
val options = BitmapFactory.Options().apply {
|
||||
inSampleSize = calculateInSampleSize(imageSize, targetWidth, targetHeight)
|
||||
inMutable = true
|
||||
}
|
||||
BitmapFactory.decodeStream(inputStream, null, options)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
context.contentResolver.openInputStream(wallpaper)?.use { inputStream ->
|
||||
val options = BitmapFactory.Options().apply {
|
||||
inSampleSize = calculateInSampleSize(imageSize, targetWidth, targetHeight)
|
||||
inMutable = true
|
||||
}
|
||||
BitmapFactory.decodeStream(inputStream, null, options)
|
||||
}
|
||||
}
|
||||
|
||||
if (bitmap == null) return false
|
||||
else {
|
||||
processBitmap(device, bitmap, darken, darkenPercent, scaling, blur, blurPercent)?.let { image ->
|
||||
when {
|
||||
setLockOrHome == true -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_SYSTEM)
|
||||
setLockOrHome == false -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_LOCK)
|
||||
setHome && setLock -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_LOCK or WallpaperManager.FLAG_SYSTEM)
|
||||
setHome -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_SYSTEM)
|
||||
setLock -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_LOCK)
|
||||
else -> {}
|
||||
}
|
||||
image.recycle()
|
||||
}
|
||||
bitmap.recycle()
|
||||
return true
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error setting wallpaper", e)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Darkens the bitmap by the given percentage and returns it
|
||||
* 0 - lightest, 100 - darkest
|
||||
*/
|
||||
private fun processBitmap(
|
||||
device: DisplayMetrics,
|
||||
source: Bitmap, darken: Boolean,
|
||||
darkenPercent: Int,
|
||||
scaling: ScalingConstants,
|
||||
blur: Boolean,
|
||||
blurPercent: Int
|
||||
): Bitmap? {
|
||||
try {
|
||||
var processedBitmap = source
|
||||
|
||||
// Apply wallpaper scaling effects
|
||||
processedBitmap = when (scaling) {
|
||||
ScalingConstants.FILL -> fillBitmap(processedBitmap, device.widthPixels, device.heightPixels)
|
||||
ScalingConstants.FIT -> fitBitmap(processedBitmap, device.widthPixels, device.heightPixels)
|
||||
ScalingConstants.STRETCH -> stretchBitmap(processedBitmap, device.widthPixels, device.heightPixels)
|
||||
}
|
||||
|
||||
// Apply brightness effect
|
||||
if (darken && darkenPercent < 100) {
|
||||
processedBitmap = darkenBitmap(processedBitmap, darkenPercent)
|
||||
}
|
||||
|
||||
// Apply blur effect
|
||||
if (blur && blurPercent > 0) {
|
||||
processedBitmap = blurBitmap(processedBitmap, blurPercent)
|
||||
}
|
||||
return processedBitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error darkening bitmap", e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
private fun refreshAlbum(context: Context) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
var albumWithWallpapers = albumRepository.getAlbumsWithWallpaperAndFolder().first()
|
||||
albumWithWallpapers.forEach { albumWithWallpaper ->
|
||||
// Delete wallpaper if the URI is invalid
|
||||
val invalidWallpapers = albumWithWallpaper.wallpapers.filterNot { wallpaper ->
|
||||
val file = DocumentFileCompat.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
|
||||
file?.exists() == true
|
||||
}
|
||||
if (invalidWallpapers.isNotEmpty()) {
|
||||
albumRepository.deleteWallpaperList(invalidWallpapers)
|
||||
}
|
||||
|
||||
// Update folder cover uri and wallpapers uri
|
||||
albumWithWallpaper.folders.forEach { folder ->
|
||||
try {
|
||||
DocumentFileCompat.fromTreeUri(context, folder.folderUri.toUri())?.let { folderDirectory ->
|
||||
if (!folderDirectory.isDirectory()) {
|
||||
albumRepository.deleteFolder(folder)
|
||||
} else {
|
||||
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
|
||||
val folderCoverFile = folder.coverUri?.let { DocumentFileCompat.fromSingleUri(context, it.toUri()) }
|
||||
val folderCover = folderCoverFile?.takeIf { it.exists() }?.uri?.toString() ?: wallpapers.randomOrNull()
|
||||
albumRepository.updateFolder(folder.copy(coverUri = folderCover, wallpapers = wallpapers))
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
DocumentFile.fromTreeUri(context, folder.folderUri.toUri())?.let { folderDirectory ->
|
||||
if (!folderDirectory.isDirectory) {
|
||||
albumRepository.deleteFolder(folder)
|
||||
} else {
|
||||
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
|
||||
val folderCoverFile = folder.coverUri?.let { DocumentFileCompat.fromSingleUri(context, it.toUri()) }
|
||||
val folderCover = folderCoverFile?.takeIf { it.exists() }?.uri?.toString() ?: wallpapers.randomOrNull()
|
||||
albumRepository.updateFolder(folder.copy(coverUri = folderCover, wallpapers = wallpapers))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Delete empty albums
|
||||
if (albumWithWallpaper.wallpapers.isEmpty() && albumWithWallpaper.folders.all { it.wallpapers.isEmpty() }) {
|
||||
albumRepository.deleteAlbum(albumWithWallpaper.album)
|
||||
}
|
||||
}
|
||||
|
||||
// Update selected album
|
||||
albumWithWallpapers = albumRepository.getAlbumsWithWallpaperAndFolder().first()
|
||||
val selectedAlbum = selectedRepository.getSelectedAlbum().first().firstOrNull()
|
||||
if (selectedAlbum != null) {
|
||||
albumWithWallpapers.find { it.album.initialAlbumName == selectedAlbum.album.initialAlbumName }
|
||||
?.let { foundAlbum ->
|
||||
val albumNameHashCode = foundAlbum.album.initialAlbumName.hashCode()
|
||||
val wallpapers: List<Wallpaper> =
|
||||
foundAlbum.wallpapers + foundAlbum.folders.flatMap { folder ->
|
||||
folder.wallpapers.map { wallpaper ->
|
||||
Wallpaper(
|
||||
initialAlbumName = foundAlbum.album.initialAlbumName,
|
||||
wallpaperUri = wallpaper,
|
||||
key = wallpaper.hashCode() + albumNameHashCode,
|
||||
)
|
||||
}
|
||||
}
|
||||
val wallpapersUri = wallpapers.map { it.wallpaperUri }.toSet()
|
||||
if (wallpapersUri.isEmpty()) {
|
||||
selectedRepository.deleteAll()
|
||||
onDestroy()
|
||||
}
|
||||
else {
|
||||
val newSelectedAlbum = SelectedAlbum(
|
||||
album = foundAlbum.album.copy(
|
||||
homeWallpapersInQueue = if (selectedAlbum.album.homeWallpapersInQueue.firstOrNull() in wallpapersUri) {
|
||||
val firstElement = selectedAlbum.album.homeWallpapersInQueue.first()
|
||||
val modifiedWallpapersUri = wallpapersUri.filter { it != firstElement }
|
||||
listOf(firstElement) + modifiedWallpapersUri.shuffled()
|
||||
} else { wallpapersUri.shuffled() },
|
||||
lockWallpapersInQueue = if (selectedAlbum.album.lockWallpapersInQueue.firstOrNull() in wallpapersUri) {
|
||||
val firstElement = selectedAlbum.album.lockWallpapersInQueue.first()
|
||||
val modifiedWallpapersUri = wallpapersUri.filter { it != firstElement }
|
||||
listOf(firstElement) + modifiedWallpapersUri.shuffled()
|
||||
} else { wallpapersUri.shuffled() },
|
||||
currentHomeWallpaper = if (selectedAlbum.album.currentHomeWallpaper in wallpapersUri) selectedAlbum.album.currentHomeWallpaper else selectedAlbum.album.homeWallpapersInQueue.firstOrNull { it in wallpapersUri },
|
||||
currentLockWallpaper = if (selectedAlbum.album.currentLockWallpaper in wallpapersUri) selectedAlbum.album.currentLockWallpaper else selectedAlbum.album.lockWallpapersInQueue.firstOrNull { it in wallpapersUri }
|
||||
),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
selectedRepository.upsertSelectedAlbum(newSelectedAlbum)
|
||||
}
|
||||
} ?: run { onDestroy() }
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error refreshing album", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,611 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.wallpaper_service
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.app.Service
|
||||
import android.app.WallpaperManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.ImageDecoder
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.os.IBinder
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.Log
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.core.Type
|
||||
import com.anthonyla.paperize.core.blurBitmap
|
||||
import com.anthonyla.paperize.core.calculateInSampleSize
|
||||
import com.anthonyla.paperize.core.darkenBitmap
|
||||
import com.anthonyla.paperize.core.fillBitmap
|
||||
import com.anthonyla.paperize.core.fitBitmap
|
||||
import com.anthonyla.paperize.core.getImageDimensions
|
||||
import com.anthonyla.paperize.core.stretchBitmap
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.SelectedAlbumRepository
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.MainActivity
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.IOException
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.format.FormatStyle
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* Used in conjunction with [WallpaperService1] to schedule home screen and lock screen separately -- sets lock screen wallpaper
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class WallpaperService2: Service() {
|
||||
private val handleThread = HandlerThread("MyThread2")
|
||||
private lateinit var workerHandler: Handler
|
||||
@Inject lateinit var selectedRepository: SelectedAlbumRepository
|
||||
@Inject lateinit var albumRepository: AlbumRepository
|
||||
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
private var scheduleSeparately: Boolean = false
|
||||
private var timeInMinutes1: Int = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
private var timeInMinutes2: Int = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
private var nextSetTime1: LocalDateTime? = null
|
||||
private var nextSetTime2: LocalDateTime? = null
|
||||
private var nextSetTime: LocalDateTime? = null
|
||||
|
||||
enum class Actions {
|
||||
START,
|
||||
REQUEUE,
|
||||
UPDATE
|
||||
}
|
||||
|
||||
override fun onBind(p0: Intent?): IBinder? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
handleThread.start()
|
||||
workerHandler = Handler(handleThread.looper)
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
if (intent != null) {
|
||||
when (intent.action) {
|
||||
Actions.START.toString() -> {
|
||||
timeInMinutes1 = intent.getIntExtra("timeInMinutes1", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
timeInMinutes2 = intent.getIntExtra("timeInMinutes2", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
scheduleSeparately = intent.getBooleanExtra("scheduleSeparately", false)
|
||||
val setHomeOrLock = if (scheduleSeparately) {
|
||||
when (intent.getIntExtra("type", Type.BOTH.ordinal)) {
|
||||
Type.HOME.ordinal -> true
|
||||
Type.LOCK.ordinal -> false
|
||||
else -> null
|
||||
}
|
||||
} else { null }
|
||||
workerTaskStart(setHomeOrLock)
|
||||
}
|
||||
Actions.REQUEUE.toString() -> {
|
||||
timeInMinutes1 = intent.getIntExtra("timeInMinutes1", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
timeInMinutes2 = intent.getIntExtra("timeInMinutes2", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
scheduleSeparately = intent.getBooleanExtra("scheduleSeparately", false)
|
||||
workerTaskRequeue()
|
||||
}
|
||||
Actions.UPDATE.toString() -> {
|
||||
workerTaskUpdate()
|
||||
}
|
||||
}
|
||||
}
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
workerHandler.removeCallbacksAndMessages(null)
|
||||
handleThread.quitSafely()
|
||||
}
|
||||
|
||||
private fun workerTaskStart(setHomeOrLock: Boolean? = null) {
|
||||
workerHandler.post {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
changeWallpaper(this@WallpaperService2, setHomeOrLock)
|
||||
}
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
|
||||
private fun workerTaskRequeue() {
|
||||
workerHandler.post {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
nextSetTime1 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_1))
|
||||
nextSetTime2 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_2))
|
||||
nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)
|
||||
val notification = createNotification()
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notification?.let { notificationManager.notify(1, it) }
|
||||
}
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
|
||||
private fun workerTaskUpdate() {
|
||||
workerHandler.post {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
updateCurrentWallpaper(this@WallpaperService2)
|
||||
}
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a notification for the wallpaper service
|
||||
*/
|
||||
private fun createNotification(): Notification? {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
if (nextSetTime != null) {
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
val pendingIntent = PendingIntent.getActivity(this, 3, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return NotificationCompat.Builder(this, "wallpaper_service_channel")
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setContentText(getString(R.string.next_wallpaper_change, nextSetTime!!.format(formatter)))
|
||||
.setSmallIcon(R.drawable.notification_icon)
|
||||
.setContentIntent(pendingIntent)
|
||||
.build()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the wallpaper to the next wallpaper in the queue of the selected album
|
||||
* If none left, reshuffle the wallpapers and pick the first one
|
||||
*/
|
||||
private suspend fun changeWallpaper(context: Context, setHomeOrLock: Boolean? = null) {
|
||||
try {
|
||||
val selectedAlbum = selectedRepository.getSelectedAlbum().first().firstOrNull()
|
||||
if (selectedAlbum == null) {
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
else {
|
||||
val toggled = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false
|
||||
val setHome = settingsDataStoreImpl.getBoolean(SettingsConstants.HOME_WALLPAPER) ?: false
|
||||
val setLock = settingsDataStoreImpl.getBoolean(SettingsConstants.LOCK_WALLPAPER) ?: false
|
||||
nextSetTime1 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_1))
|
||||
nextSetTime2 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_2))
|
||||
if (!toggled || (!setHome && !setLock)) {
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now()
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
|
||||
|
||||
if (setHomeOrLock == null) {
|
||||
nextSetTime1 = currentTime.plusMinutes(timeInMinutes1.toLong())
|
||||
nextSetTime2 = nextSetTime1
|
||||
nextSetTime = nextSetTime1
|
||||
nextSetTime?.let { settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, it.format(formatter)) }
|
||||
}
|
||||
else {
|
||||
if (setHomeOrLock) { nextSetTime1 = currentTime.plusMinutes(timeInMinutes1.toLong()) }
|
||||
else { nextSetTime2 = currentTime.plusMinutes(timeInMinutes2.toLong()) }
|
||||
if (nextSetTime1 == null && nextSetTime2 != null) {
|
||||
nextSetTime = nextSetTime2
|
||||
}
|
||||
else if (nextSetTime1 != null && nextSetTime2 == null) {
|
||||
nextSetTime = nextSetTime1
|
||||
}
|
||||
else {
|
||||
nextSetTime = if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2
|
||||
}
|
||||
nextSetTime?.let { settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, it.format(formatter)) }
|
||||
}
|
||||
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, nextSetTime1.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, nextSetTime2.toString())
|
||||
|
||||
val notification = createNotification()
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notification?.let { notificationManager.notify(1, it) }
|
||||
|
||||
val scaling = settingsDataStoreImpl.getString(SettingsConstants.WALLPAPER_SCALING)?.let { ScalingConstants.valueOf(it) } ?: ScalingConstants.FILL
|
||||
val darken = settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false
|
||||
val darkenPercentage = settingsDataStoreImpl.getInt(SettingsConstants.DARKEN_PERCENTAGE) ?: 100
|
||||
val blur = settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false
|
||||
val blurPercentage = settingsDataStoreImpl.getInt(SettingsConstants.BLUR_PERCENTAGE) ?: 0
|
||||
|
||||
selectedAlbum.let { it ->
|
||||
if (setHomeOrLock != null) {
|
||||
var wallpaper = if (setHomeOrLock) it.album.homeWallpapersInQueue.firstOrNull() else it.album.lockWallpapersInQueue.firstOrNull()
|
||||
if (wallpaper != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
setLockOrHome = setHomeOrLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = if (setHomeOrLock) it.album.homeWallpapersInQueue.drop(1) else it.album.homeWallpapersInQueue,
|
||||
lockWallpapersInQueue = if (!setHomeOrLock) it.album.lockWallpapersInQueue.drop(1) else it.album.lockWallpapersInQueue,
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 },
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
} else {
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = if (setHomeOrLock) it.album.homeWallpapersInQueue.drop(1) else it.album.homeWallpapersInQueue,
|
||||
lockWallpapersInQueue = if (!setHomeOrLock) it.album.lockWallpapersInQueue.drop(1) else it.album.lockWallpapersInQueue,
|
||||
currentHomeWallpaper = if (setHomeOrLock) wallpaper else it.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (!setHomeOrLock) wallpaper else it.album.currentLockWallpaper
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
// No more wallpapers in the queue -- reshuffle the wallpapers
|
||||
else {
|
||||
val newWallpaperInQueue = it.wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
wallpaper = newWallpaperInQueue.firstOrNull()
|
||||
if (wallpaper != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
setLockOrHome = setHomeOrLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)
|
||||
) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = if (setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.homeWallpapersInQueue,
|
||||
lockWallpapersInQueue = if (!setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.lockWallpapersInQueue
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 }
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
} else {
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = if (setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.homeWallpapersInQueue,
|
||||
lockWallpapersInQueue = if (!setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.lockWallpapersInQueue,
|
||||
currentHomeWallpaper = if (setHomeOrLock) wallpaper else it.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (!setHomeOrLock) wallpaper else it.album.currentLockWallpaper
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
} else { onDestroy() }
|
||||
}
|
||||
}
|
||||
else {
|
||||
var wallpaper = it.album.homeWallpapersInQueue.firstOrNull()
|
||||
if (wallpaper != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = it.album.homeWallpapersInQueue.drop(1),
|
||||
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper }
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 },
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
} else {
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = it.album.homeWallpapersInQueue.drop(1),
|
||||
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper },
|
||||
currentHomeWallpaper = wallpaper,
|
||||
currentLockWallpaper = wallpaper,
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
// No more wallpapers in the queue -- reshuffle the wallpapers
|
||||
else {
|
||||
val newWallpaperInQueue = it.wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
wallpaper = newWallpaperInQueue.firstOrNull()
|
||||
if (wallpaper != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
setLockOrHome = setHomeOrLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)
|
||||
) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = it.album.homeWallpapersInQueue.drop(1),
|
||||
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper }
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 }
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
} else {
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = newWallpaperInQueue.drop(1),
|
||||
currentHomeWallpaper = wallpaper,
|
||||
currentLockWallpaper = wallpaper
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
} else { onDestroy() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error in changing wallpaper", e)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun updateCurrentWallpaper(context: Context) {
|
||||
try {
|
||||
val selectedAlbum = selectedRepository.getSelectedAlbum().first().firstOrNull()
|
||||
if (selectedAlbum == null) {
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
else {
|
||||
val setHome = settingsDataStoreImpl.getBoolean(SettingsConstants.HOME_WALLPAPER) ?: false
|
||||
val setLock = settingsDataStoreImpl.getBoolean(SettingsConstants.LOCK_WALLPAPER) ?: false
|
||||
if (!setHome && !setLock) {
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val time = LocalDateTime.now()
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, time.format(formatter))
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, time.plusMinutes(timeInMinutes1.toLong()).format(formatter))
|
||||
val scaling = settingsDataStoreImpl.getString(SettingsConstants.WALLPAPER_SCALING)?.let { ScalingConstants.valueOf(it) } ?: ScalingConstants.FILL
|
||||
val darken = settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false
|
||||
val darkenPercentage = settingsDataStoreImpl.getInt(SettingsConstants.DARKEN_PERCENTAGE) ?: 100
|
||||
val blur = settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false
|
||||
val blurPercentage = settingsDataStoreImpl.getInt(SettingsConstants.BLUR_PERCENTAGE) ?: 0
|
||||
|
||||
selectedAlbum.let { it ->
|
||||
val wallpaper1 = it.album.currentHomeWallpaper
|
||||
val wallpaper2 = it.album.currentLockWallpaper
|
||||
if (wallpaper1 != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper1.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
setLockOrHome = true,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull{ it.wallpaperUri == wallpaper1 }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = it.album.homeWallpapersInQueue.filter { it != wallpaper1 },
|
||||
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper1 }
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 },
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wallpaper2 != null) {
|
||||
if (!setWallpaper(
|
||||
context = context,
|
||||
wallpaper = wallpaper2.toUri(),
|
||||
darken = darken,
|
||||
darkenPercent = darkenPercentage,
|
||||
scaling = scaling,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
setLockOrHome = false,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull{ it.wallpaperUri == wallpaper2 }
|
||||
?.let { it1 ->
|
||||
selectedRepository.deleteWallpaper(it1)
|
||||
selectedRepository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
homeWallpapersInQueue = it.album.homeWallpapersInQueue.filter { it != wallpaper1 },
|
||||
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper1 }
|
||||
),
|
||||
wallpapers = it.wallpapers.filter { it == it1 },
|
||||
)
|
||||
)
|
||||
albumRepository.deleteWallpaper(it1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error in updating", e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the wallpaper to the given uri
|
||||
*/
|
||||
private fun setWallpaper(
|
||||
context: Context,
|
||||
wallpaper: Uri,
|
||||
darken: Boolean,
|
||||
darkenPercent: Int,
|
||||
scaling: ScalingConstants,
|
||||
setHome: Boolean, setLock: Boolean,
|
||||
setLockOrHome: Boolean? = null,
|
||||
blur: Boolean = false,
|
||||
blurPercent: Int,
|
||||
): Boolean {
|
||||
val wallpaperManager = WallpaperManager.getInstance(context)
|
||||
try {
|
||||
val imageSize = wallpaper.getImageDimensions(context) ?: return false
|
||||
val aspectRatio = imageSize.height.toFloat() / imageSize.width.toFloat()
|
||||
val device = context.resources.displayMetrics
|
||||
val targetWidth = min(device.widthPixels, imageSize.width)
|
||||
val targetHeight = (targetWidth * aspectRatio).toInt()
|
||||
|
||||
val bitmap = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
try {
|
||||
val source = ImageDecoder.createSource(context.contentResolver, wallpaper)
|
||||
ImageDecoder.decodeBitmap(source) { decoder, _, _ ->
|
||||
decoder.setTargetSize(targetWidth, targetHeight)
|
||||
decoder.isMutableRequired = true
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
context.contentResolver.openInputStream(wallpaper)?.use { inputStream ->
|
||||
val options = BitmapFactory.Options().apply {
|
||||
inSampleSize = calculateInSampleSize(imageSize, targetWidth, targetHeight)
|
||||
inMutable = true
|
||||
}
|
||||
BitmapFactory.decodeStream(inputStream, null, options)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
context.contentResolver.openInputStream(wallpaper)?.use { inputStream ->
|
||||
val options = BitmapFactory.Options().apply {
|
||||
inSampleSize = calculateInSampleSize(imageSize, targetWidth, targetHeight)
|
||||
inMutable = true
|
||||
}
|
||||
BitmapFactory.decodeStream(inputStream, null, options)
|
||||
}
|
||||
}
|
||||
|
||||
if (bitmap == null) return false
|
||||
else {
|
||||
processBitmap(device, bitmap, darken, darkenPercent, scaling, blur, blurPercent)?.let { image ->
|
||||
when {
|
||||
setLockOrHome == true -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_SYSTEM)
|
||||
setLockOrHome == false -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_LOCK)
|
||||
setHome && setLock -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_LOCK or WallpaperManager.FLAG_SYSTEM)
|
||||
setHome -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_SYSTEM)
|
||||
setLock -> wallpaperManager.setBitmap(image, null, true, WallpaperManager.FLAG_LOCK)
|
||||
else -> {}
|
||||
}
|
||||
image.recycle()
|
||||
}
|
||||
bitmap.recycle()
|
||||
}
|
||||
return true
|
||||
} catch (e: IOException) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error setting wallpaper", e)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Darkens the bitmap by the given percentage and returns it
|
||||
* 0 - lightest, 100 - darkest
|
||||
*/
|
||||
private fun processBitmap(
|
||||
device: DisplayMetrics,
|
||||
source: Bitmap, darken: Boolean,
|
||||
darkenPercent: Int,
|
||||
scaling: ScalingConstants,
|
||||
blur: Boolean,
|
||||
blurPercent: Int
|
||||
): Bitmap? {
|
||||
try {
|
||||
var processedBitmap = source
|
||||
|
||||
// Apply wallpaper scaling effects
|
||||
processedBitmap = when (scaling) {
|
||||
ScalingConstants.FILL -> fillBitmap(processedBitmap, device.widthPixels, device.heightPixels)
|
||||
ScalingConstants.FIT -> fitBitmap(processedBitmap, device.widthPixels, device.heightPixels)
|
||||
ScalingConstants.STRETCH -> stretchBitmap(processedBitmap, device.widthPixels, device.heightPixels)
|
||||
}
|
||||
|
||||
// Apply brightness effect
|
||||
if (darken && darkenPercent < 100) {
|
||||
processedBitmap = darkenBitmap(processedBitmap, darkenPercent)
|
||||
}
|
||||
|
||||
// Apply blur effect
|
||||
if (blur && blurPercent > 0) {
|
||||
processedBitmap = blurBitmap(processedBitmap, blurPercent)
|
||||
}
|
||||
return processedBitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error darkening bitmap", e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.wallpaperservice
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class WallpaperBootReceiver : BroadcastReceiver() {
|
||||
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (Intent.ACTION_BOOT_COMPLETED == intent.action) {
|
||||
Log.d("PaperizeWallpaperChanger", "Boot completed")
|
||||
val serviceIntent = Intent(context, WallpaperService::class.java)
|
||||
serviceIntent.action = WallpaperService.Actions.START.toString()
|
||||
runBlocking {
|
||||
val timeInMinutes = settingsDataStoreImpl.getInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val setLockWithHome = settingsDataStoreImpl.getBoolean(SettingsConstants.SET_LOCK_WITH_HOME) ?: false
|
||||
serviceIntent.putExtra("timeInMinutes", timeInMinutes)
|
||||
serviceIntent.putExtra("setLockWithHome", setLockWithHome)
|
||||
}
|
||||
context.startForegroundService(serviceIntent)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,232 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.wallpaperservice
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
import android.app.Service
|
||||
import android.app.WallpaperManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.ImageDecoder
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.IBinder
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.SelectedAlbumRepository
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.IOException
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
@AndroidEntryPoint
|
||||
class WallpaperService: Service() {
|
||||
@Inject lateinit var repository: SelectedAlbumRepository
|
||||
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private lateinit var runnableCode: Runnable
|
||||
private var timeInMinutes: Int = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
|
||||
enum class Actions {
|
||||
START,
|
||||
STOP
|
||||
}
|
||||
|
||||
override fun onBind(p0: Intent?): IBinder? {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the runnable code to change the wallpaper to prevent runnableCode from being null
|
||||
*/
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
startForeground(1, createNotification(0, 0))
|
||||
runnableCode = object : Runnable {
|
||||
override fun run() {
|
||||
val self = this
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
changeWallpaper(this@WallpaperService)
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error in runnableCode", e)
|
||||
} finally {
|
||||
handler.postDelayed(self, timeInMinutes * 60 * 1000L)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the service and schedule the wallpaper change
|
||||
*/
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
handler.removeCallbacks(runnableCode)
|
||||
when(intent?.action) {
|
||||
Actions.START.toString() -> {
|
||||
timeInMinutes = intent.getIntExtra("timeInMinutes", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
// Schedule the next wallpaper change
|
||||
runnableCode = object : Runnable {
|
||||
override fun run() {
|
||||
val self = this
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
changeWallpaper(this@WallpaperService)
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error in runnableCode", e)
|
||||
} finally {
|
||||
handler.postDelayed(self, timeInMinutes * 60 * 1000L)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
handler.post(runnableCode)
|
||||
}
|
||||
Actions.STOP.toString() -> {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, "")
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, "")
|
||||
}
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
return START_STICKY
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up the service when it is destroyed
|
||||
*/
|
||||
override fun onDestroy() {
|
||||
Log.d("PaperizeWallpaperChanger", "Service destroyed")
|
||||
super.onDestroy()
|
||||
handler.removeCallbacks(runnableCode)
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, "")
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, "")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a notification for the wallpaper service
|
||||
*/
|
||||
private fun createNotification(current: Int = 0, total: Int = 0): Notification {
|
||||
return NotificationCompat.Builder(this, "wallpaper_service_channel")
|
||||
.setContentTitle("Paperize")
|
||||
.setContentText("Rotation: $current/$total wallpapers\nInterval: ${formatTime(timeInMinutes)}")
|
||||
.setSmallIcon(R.drawable.notification_icon)
|
||||
.build()
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the wallpaper to the next wallpaper in the queue of the selected album
|
||||
* If none left, reshuffle the wallpapers and pick the first one
|
||||
*/
|
||||
private suspend fun changeWallpaper(context: Context) {
|
||||
val formatter = DateTimeFormatter.ofPattern("MM/dd/yy hh:mm\na")
|
||||
val time = LocalDateTime.now()
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, time.format(formatter))
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, time.plusMinutes(timeInMinutes.toLong()).format(formatter))
|
||||
val setLockWithHome = settingsDataStoreImpl.getBoolean(SettingsConstants.SET_LOCK_WITH_HOME) ?: false
|
||||
val album = repository.getSelectedAlbum().first().firstOrNull()
|
||||
album?.let {
|
||||
val notification = createNotification(it.album.wallpapersInQueue.size, it.wallpapers.size)
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(1, notification)
|
||||
var wallpaper = it.album.wallpapersInQueue.firstOrNull()
|
||||
if (wallpaper != null) {
|
||||
setWallpaper(context, wallpaper.toUri(), setLockWithHome)
|
||||
repository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
wallpapersInQueue = it.album.wallpapersInQueue.drop(1)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
else {
|
||||
val newWallpaperInQueue = it.wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
wallpaper = newWallpaperInQueue.firstOrNull()
|
||||
if (wallpaper != null) {
|
||||
setWallpaper(context, wallpaper.toUri(), setLockWithHome)
|
||||
repository.upsertSelectedAlbum(
|
||||
it.copy(
|
||||
album = it.album.copy(
|
||||
wallpapersInQueue = newWallpaperInQueue.drop(1)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the wallpaper to the given uri
|
||||
*/
|
||||
private fun setWallpaper(context: Context, wallpaper: Uri, setLockWithHome: Boolean) {
|
||||
val wallpaperManager = WallpaperManager.getInstance(context)
|
||||
try {
|
||||
val bitmap = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
val source = ImageDecoder.createSource(context.contentResolver, wallpaper)
|
||||
ImageDecoder.decodeBitmap(source) { decoder, _, _ ->
|
||||
val displayMetrics = context.resources.displayMetrics
|
||||
val targetWidth = displayMetrics.widthPixels
|
||||
val targetHeight = displayMetrics.heightPixels
|
||||
decoder.setTargetSize(targetWidth, targetHeight)
|
||||
}
|
||||
} else {
|
||||
context.contentResolver.openInputStream(wallpaper)?.use { inputStream ->
|
||||
BitmapFactory.decodeStream(inputStream)
|
||||
}
|
||||
}
|
||||
bitmap?.let {
|
||||
image -> wallpaperManager.setBitmap(image, null, true, when (setLockWithHome) {
|
||||
true -> WallpaperManager.FLAG_LOCK or WallpaperManager.FLAG_SYSTEM
|
||||
false -> WallpaperManager.FLAG_SYSTEM
|
||||
})
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error changing wallpaper", e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the time in minutes to a human readable format
|
||||
*/
|
||||
private fun formatTime(timeInMinutes: Int): String {
|
||||
val days = timeInMinutes / (24 * 60)
|
||||
val hours = (timeInMinutes % (24 * 60)) / 60
|
||||
val minutes = timeInMinutes % 60
|
||||
|
||||
val formattedDays = when {
|
||||
days > 1 -> "$days days"
|
||||
days == 1 -> "$days day"
|
||||
else -> ""
|
||||
}
|
||||
val formattedHours = when {
|
||||
hours > 1 -> "$hours hours"
|
||||
hours == 1 -> "$hours hour"
|
||||
else -> ""
|
||||
}
|
||||
val formattedMinutes = when {
|
||||
minutes > 1 -> "$minutes minutes"
|
||||
minutes == 1 -> "$minutes minute"
|
||||
else -> ""
|
||||
}
|
||||
|
||||
return listOf(formattedDays, formattedHours, formattedMinutes).filter { it.isNotEmpty() }.joinToString(", ")
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="1024"
|
||||
android:viewportHeight="1024"
|
||||
android:tint="#FFFFFF">
|
||||
<group android:scaleX="1.127451"
|
||||
android:scaleY="1.127451"
|
||||
android:translateX="-65.254906"
|
||||
android:translateY="-65.254906">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M351,344c0.2,2.9 -0.8,4.8 -4,5.1 -2.3,0.2 -3.7,1.6 -3.5,4 0.1,2.5 2.1,3.2 4.1,3.5 5.9,0.9 11.7,-0 17.3,-1.8 10.5,-3.3 21.5,-4.7 32,-7.6 3,-0.8 6.9,-0.9 7.6,-4.6 0.7,-3.4 -1.8,-5.8 -4.7,-7.6 -0.5,-0.3 -0.7,-1 -1.4,-2.1 6.8,-2.8 13.7,-3.3 20.5,-4.1 28.2,-3.3 56.6,-5.4 84.6,-10 3.7,-0.6 7.3,-2.2 11.4,-1.3 -10.2,6.7 -20.5,13.2 -32,18.3 3.8,-0.5 7.6,-0.9 11.3,-1.4 3.8,-0.6 7.5,-1.5 11.3,-2.1 48.3,-8 92,-28.4 135,-50.5 12.5,-6.4 25.3,-11.9 38.8,-15.9 7.5,-2.3 14.5,-1.8 21.6,1.9 16,8.2 26.6,21.3 34.6,36.9 0.5,0.9 0.7,1.9 0.2,3.2 -2.6,0.5 -5.6,1.9 -5.3,-3.2 0.1,-1.2 -0.4,-2.5 -1.4,-3 -8,-4.1 -15,-11.3 -25.6,-6.6 -7.4,3.3 -15.6,4.5 -23,8.5 1.6,3.2 4,3.8 7.1,3.1 1.3,-0.3 2.6,-0.3 4,-0.4 2.9,-0 4.7,1.5 5.1,4.4 0.5,3.2 -1.8,4 -4.1,4.6 -8.6,2.1 -17.1,4.2 -25.7,6.3 -20.4,5.1 -40,12.5 -60.3,17.8 -29.1,7.6 -58.3,15 -88.7,16.3 -4.4,0.2 -8.8,0.8 -13.3,1.7 6.6,1.5 12.8,4.6 20.1,3.1 6,-1.2 12.2,-1.1 18.4,-1.5 19.5,-1.1 38.6,-4.4 57.3,-10.2 2.4,-0.7 4.7,-1.6 7.1,-2.3 0.1,-0 0.3,0.1 1.2,0.5 -4.6,5.5 -11.1,8 -18,11.8 4.9,1.5 8.3,0.2 11.5,-0.4 25.4,-4.8 50,-12.7 75,-18.7 21.4,-5.2 43,-8.7 65.2,-7.8 5.7,0.2 11.3,1.1 16.8,2.4 3.1,0.7 5.7,2.4 7.9,4.9 11.4,13 16.8,28.5 19.2,45.3 0.5,3.8 1,7.5 1.8,12.8l-22.7,-9.9c1.6,-1.8 3.1,-1.1 4.5,-1.3 2,-0.3 5,0.6 5.3,-2.3 0.3,-2.5 -1,-5.1 -3.6,-6.1 -4,-1.6 -8.1,-3.1 -12.3,-4.1 -24.1,-5.8 -48.2,-4.4 -72.3,0.3 -15.3,3 -30.6,6.5 -45.5,11.4 -0.9,0.3 -1.9,0.6 -2.8,1 -2,1 -4,2.3 -3.3,4.9 0.7,2.8 3.2,2 5,1.7 8.8,-1.6 17.6,-3.5 26.2,-6.4 1.3,-0.5 2.7,-1.4 4.8,-0.5 -6.4,6.6 -15.2,9.5 -22.5,16.7 11.1,-1.9 20.9,-3.5 30.6,-5.2 25.7,-4.4 51.5,-5.3 76.7,1.7 31.8,8.9 46,27.6 47.1,58.9 0.5,15 -2,29.5 -7.4,43.5 -0.5,1.3 -0.4,3.1 -2.2,3.6 -1.1,-0.4 -1,-1.4 -0.8,-2.1 4,-21 -10.6,-43.7 -30.1,-53.4 -16.8,-8.3 -34.7,-9.9 -53.1,-9 -3.7,0.2 -7.2,1.6 -9.9,4.4 -1.1,1.1 -2.9,2.1 -2.2,4.1 0.8,2.2 2.7,2.7 4.9,2.7 7,0 14,0.3 21,0.9 7.5,0.6 14.8,2 22.2,3.1 3.8,0.6 5.5,2.6 6.3,6.3 4.3,20 5.2,40.2 3.4,60.5 -2.8,30.8 -11.3,59.8 -26.1,86.8 -19.9,36.5 -47,66.4 -81.9,89.3 -34.2,22.5 -71.8,34.9 -112.3,38.2 -24.4,2 -48.9,0.8 -72.9,-5.5 -4,-1 -5.8,-2.5 -5.7,-7 0.1,-46.7 0.1,-93.3 -0,-140 -0,-4.8 1.9,-5.9 6.3,-5.9 24,0.1 48,0.2 72,0 24.7,-0.2 48.8,-4.2 71.1,-15.3 23.7,-11.9 39.9,-30.5 45.8,-56.7 6.1,-27.1 -0.7,-51.1 -19.7,-71.5 -19,-20.4 -43.2,-31.8 -69.4,-39.8 -22,-6.7 -44.7,-10.1 -67.5,-13 -33.7,-4.3 -67.5,-3.1 -101.3,-3.1 -4.7,0 -6,1.8 -6,6.2 0.1,51.2 0,102.3 -0,153.5 -0,74.8 -0.1,149.7 -0.1,224.5 -0,5.4 0,10.9 0,16.1 -2.1,0.5 -2.8,-0.3 -3.4,-1 -7.2,-8.1 -14.4,-16.2 -21.6,-24.2 -2.2,-2.5 -3.2,-5.3 -3.1,-8.6 0.1,-25.5 -0,-50.9 -0,-76.4 0,-91.3 0,-182.6 0.1,-273.9 0,-5.3 -2.7,-7.7 -10.5,-9.4 -1.6,1.8 -0.9,4.1 -0.9,6.2 -0.1,103.7 -0.1,207.3 -0.1,311 0,2.2 0,4.4 -0.3,6.5 -0.3,1.8 0,4.5 -2.8,4.6 -2.6,0.1 -5,-1 -6.1,-3.5 -1.3,-2.8 -1.2,-5.8 -1.2,-8.8 -0,-70.5 -0,-141 -0,-211.5 -0,-33.2 -0.2,-66.3 0.2,-99.5 0.1,-6.7 -1.7,-11.1 -7.8,-13.7 -1.3,-0.6 -2.3,-2 -4.1,-2.1 -2.7,1.6 -1.8,4.3 -1.8,6.6 -0,59.8 -0,119.7 -0,179.5 0,33.3 0.1,66.7 0.1,100 0,1.3 -0.2,2.6 -0.2,4 -0.7,0 -1.3,0.2 -1.6,-0 -7.8,-7.3 -14.8,-15.4 -21.5,-23.6 -2.2,-2.7 -2.1,-6.4 -1.9,-9.6 1.2,-15.2 -2.5,-28.8 -9,-42.7 -10,-21.2 -14,-44.2 -15.6,-67.7 -2.1,-29.9 0.8,-59.1 10.1,-87.7 2,-6 4.7,-11.7 7.3,-17.5 1,-2.3 1.9,-4.9 5.4,-5.2 2.5,-0.2 1.6,-2.9 1.6,-4.6 0.1,-13.7 1,-27.4 -0.1,-41 -1.3,-17.4 5.2,-29.9 18.9,-40.3 17.2,-12.9 35.7,-23.2 55.1,-32.2 33.5,-15.6 69.2,-24.7 104.7,-34.4 33,-9.1 65.3,-20 94.2,-38.9 1.1,-0.7 2.4,-1.3 3.3,-2.3 5.7,-6 12.3,-5.5 19.3,-3.2 5.6,1.8 11.4,3.3 16.9,6.4 -0.7,0.9 -1,1.6 -1.5,1.9 -25.5,14.4 -50.4,30 -77.8,40.7 -24,9.3 -48.7,15.7 -73.8,21.1 -33.6,7.2 -66.8,15.7 -96.9,33.1 -8.8,5.1 -17.6,10.3 -24.1,18.4 -3.1,3.8 -5.3,8 -2.8,13.3 5.6,-1.6 10.4,-4.6 16.3,-5.2 0.4,-0 0.4,-0.1 0.4,-0.1z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M509.5,440.1c10.1,1.1 19.5,2.9 28.4,6.8 22.1,9.6 31.3,34.1 19.8,53.7 -6.8,11.7 -18.4,16.1 -31,17.6 -21.7,2.5 -43.6,0.6 -65.3,1.2 -4.5,0.1 -4.7,-2.7 -4.7,-5.9 -0,-12.8 0,-25.6 0,-38.4 -0,-10.2 0.1,-20.3 -0.1,-30.5 -0.1,-4.2 1.5,-5.6 5.5,-5.6 15.6,-0 31.3,0.1 47.3,1.1zM585,279.1c-22.2,10.8 -44,21.6 -67.6,27.8 -17.7,4.7 -35.7,7.7 -54,9.6 -35.4,3.6 -70.8,7.1 -105,17.8 -5,1.6 -9.9,3.6 -15.4,5.6 0.7,-2.6 2.6,-3 3.9,-3.9 23.4,-16.4 50,-25.3 77.1,-33.3 25.2,-7.4 51.1,-12.1 76.5,-19 29.3,-7.9 56.9,-19.5 83.4,-34.1 14,-7.7 27.9,-15.7 43.6,-19.5 4,-1 7.8,-1 11.8,0.2 11.3,3.4 21.7,8.4 30.5,16.4 3,2.7 2.9,4.5 -0.9,6.1 -3.1,1.3 -6.1,2.7 -9.1,4.2 -3.3,1.7 -6.1,3.6 -9.1,-1 -1.6,-2.3 -5,-1.8 -7.9,-1 -20.1,5.8 -39.2,13.9 -57.9,24z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M615.3,281.3c-17.6,9.8 -35.2,18.9 -54.7,23.9 16.7,-11.1 33.3,-22.2 49.5,-34.4 2.4,4.2 -2.7,5.2 -1.9,8.4 14.4,-4.2 25.3,-16 40.7,-17.7 -10.3,7.9 -22.4,12.7 -33.6,19.7zM715,306.4c4.1,-0.1 7.8,-1.1 12.6,-0.1 -4.4,2.7 -8.1,4.1 -12.3,3.7 -3.4,-0.3 -3.3,-1.7 -0.4,-3.6zM706.1,378c3.5,0.1 6.3,-3.1 9.7,-0.6 -6,0.8 -10.9,5.6 -18.4,4.3 2.8,-2.7 5.7,-2.8 8.6,-3.7zM351,344c4.1,-2.3 7.6,-3.3 11.8,-3 -3.1,4.5 -7.4,2.4 -11.4,3 -0.4,0 -0.4,0 -0.4,0z"/>
|
||||
</group>
|
||||
</vector>
|
||||
|
Before Width: | Height: | Size: 572 B After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 361 B After Width: | Height: | Size: 683 B |
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<solid android:color="@color/default_splash_dark"/>
|
||||
</shape>
|
||||
|
Before Width: | Height: | Size: 799 B After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
@@ -0,0 +1,33 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="128dp" android:viewportHeight="128" android:viewportWidth="128" android:width="128dp">
|
||||
|
||||
<path android:fillColor="#e1e0a6" android:pathData="M29.66,113.89l0,0l68.68,0l0,0l0,-98.85l0,0l-68.68,0l0,0l0,98.85z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#b8ca43" android:pathData="M79.94,109.3c0,1.76 -1.44,3.2 -3.2,3.2h-38.35c-1.76,0 -3.2,-1.44 -3.2,-3.2 0,0 20.61,-27.17 22.37,-27.17 1.76,0 22.37,27.17 22.37,27.17Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#231c1c" android:pathData="M76.14,113.89h-38.23c-2.65,0 -4.79,-2.15 -4.79,-4.79v-0.48s0.32,-0.48 0.32,-0.48c21.03,-27.81 22.63,-27.81 23.58,-27.81 0.96,0 2.55,0 23.58,27.81l0.32,0.48v0.48c0,2.72 -2.07,4.79 -4.78,4.79h0ZM36.18,109.53c0.16,0.64 0.8,1.12 1.6,1.12h38.35c0.8,0 1.28,-0.48 1.6,-1.12 -7.35,-9.59 -17.74,-22.85 -20.77,-25.73 -3.04,2.88 -13.42,16.14 -20.77,25.73Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#b8ca43" android:pathData="M93.63,108.73c0,1.65 -1.36,3.1 -3.13,3.1h-37.04c-1.67,0 -3.13,-1.34 -3.13,-3.1 0,0 19.93,-25.92 21.6,-25.92 1.77,0 21.7,25.92 21.7,25.92Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#231c1c" android:pathData="M90.84,113.89h-37.97c-2.35,0 -4.27,-1.92 -4.27,-4.27v-0.32s0.21,-0.32 0.21,-0.32c20.75,-27.23 22.35,-27.23 22.99,-27.23s2.25,0 22.99,27.23l0.21,0.32v0.32c0.11,2.35 -1.82,4.27 -4.17,4.27ZM50.91,109.76c0.11,0.96 1.07,1.82 2.03,1.82h37.91c1.07,0 1.92,-0.75 2.03,-1.82 -8.65,-11.43 -18.58,-23.92 -20.93,-25.95 -2.35,2.03 -12.28,14.52 -21.04,25.95Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#f29b54" android:pathData="M53.55,45.67c4.7,0 8.24,-4.99 5.59,-9.97 -1.01,-1.89 -3.02,-3.03 -5.16,-3.03h-0.61c-2.55,0 -4.89,1.52 -5.82,3.9 -1.83,4.67 1.56,9.1 5.99,9.1h0Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#231c1c" android:pathData="M60.87,39.62c0,4.47 -3.52,7.99 -7.99,7.99s-7.99,-3.52 -7.99,-7.99 3.52,-7.99 7.99,-7.99 7.99,3.52 7.99,7.99ZM48.09,39.62c0,2.72 2.08,4.79 4.79,4.79s4.79,-2.08 4.79,-4.79 -2.08,-4.79 -4.79,-4.79 -4.79,2.08 -4.79,4.79Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#00000000" android:pathData="M39.29,23.3c0,-5.14 3.53,-9.31 7.9,-9.31" android:strokeColor="#000" android:strokeWidth="2"/>
|
||||
|
||||
<path android:fillColor="#00000000" android:pathData="M47.2,13.99h34.25" android:strokeColor="#000" android:strokeWidth="2"/>
|
||||
|
||||
<path android:fillColor="#00000000" android:pathData="M88.45,21.29c0,-4.03 -3.35,-7.3 -7.48,-7.3" android:strokeColor="#000" android:strokeWidth="2"/>
|
||||
|
||||
<path android:fillColor="#00000000" android:pathData="M88.45,21.29v85.52" android:strokeColor="#000" android:strokeWidth="2"/>
|
||||
|
||||
<path android:fillColor="#00000000" android:pathData="M88.45,106.81c0,3.98 -3.76,7.21 -8.4,7.21" android:strokeColor="#000" android:strokeWidth="2"/>
|
||||
|
||||
<path android:fillColor="#00000000" android:pathData="M80.05,114.01h-33.38" android:strokeColor="#000" android:strokeWidth="2"/>
|
||||
|
||||
<path android:fillColor="#00000000" android:pathData="M39.56,105.81c0,4.53 3.41,8.2 7.63,8.2" android:strokeColor="#000" android:strokeWidth="2"/>
|
||||
|
||||
<path android:fillColor="#00000000" android:pathData="M40.56,105.81h-1c-0.15,0 -0.27,-36.9 -0.27,-82.51" android:strokeColor="#000" android:strokeWidth="2"/>
|
||||
|
||||
</vector>
|
||||
@@ -0,0 +1,33 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="128dp" android:viewportHeight="128" android:viewportWidth="128" android:width="128dp">
|
||||
|
||||
<path android:fillColor="#fff" android:pathData="M47.5,14L80.5,14A8,8 0,0 1,88.5 22L88.5,106A8,8 0,0 1,80.5 114L47.5,114A8,8 0,0 1,39.5 106L39.5,22A8,8 0,0 1,47.5 14z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#00000000" android:pathData="M47.5,14L80.5,14A8,8 0,0 1,88.5 22L88.5,106A8,8 0,0 1,80.5 114L47.5,114A8,8 0,0 1,39.5 106L39.5,22A8,8 0,0 1,47.5 14z" android:strokeColor="#000" android:strokeWidth="2"/>
|
||||
|
||||
<path android:fillColor="#e1e0a6" android:pathData="M40.54,97.28l0,0l46.88,0l0,0l0,-67.64l0,0l-46.88,0l0,0l0,67.64z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#b8ca43" android:pathData="M74.87,94.47c0,1.21 -0.99,2.2 -2.2,2.2h-26.37c-1.21,0 -2.2,-0.99 -2.2,-2.2 0,0 14.18,-18.68 15.38,-18.68s15.38,18.68 15.38,18.68Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#231c1c" android:pathData="M72.26,97.62h-26.29c-1.82,0 -3.3,-1.48 -3.3,-3.3v-0.33s0.22,-0.33 0.22,-0.33c14.46,-19.12 15.56,-19.12 16.22,-19.12s1.75,0 16.22,19.12l0.22,0.33v0.33c0,1.87 -1.42,3.3 -3.29,3.3h0ZM44.78,94.62c0.11,0.44 0.55,0.77 1.1,0.77h26.37c0.55,0 0.88,-0.33 1.1,-0.77 -5.06,-6.59 -12.2,-15.71 -14.29,-17.69 -2.09,1.98 -9.23,11.1 -14.29,17.69Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#b8ca43" android:pathData="M84.29,94.07c0,1.14 -0.93,2.13 -2.15,2.13h-25.47c-1.15,0 -2.15,-0.92 -2.15,-2.13 0,0 13.71,-17.82 14.85,-17.82 1.22,0 14.93,17.82 14.93,17.82Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#231c1c" android:pathData="M82.36,97.62h-26.11c-1.62,0 -2.94,-1.32 -2.94,-2.94v-0.22s0.15,-0.22 0.15,-0.22c14.27,-18.73 15.37,-18.73 15.81,-18.73s1.54,0 15.81,18.73l0.15,0.22v0.22c0.07,1.62 -1.25,2.94 -2.87,2.94ZM54.91,94.78c0.07,0.66 0.73,1.25 1.4,1.25h26.07c0.73,0 1.32,-0.51 1.4,-1.25 -5.95,-7.86 -12.78,-16.45 -14.39,-17.84 -1.62,1.4 -8.44,9.99 -14.47,17.84Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#f29b54" android:pathData="M56.72,50.71c3.23,0 5.67,-3.43 3.85,-6.85 -0.69,-1.3 -2.08,-2.08 -3.55,-2.08h-0.42c-1.75,0 -3.36,1.05 -4,2.68 -1.26,3.21 1.07,6.25 4.12,6.26h0Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#231c1c" android:pathData="M61.76,46.55c0,3.08 -2.42,5.49 -5.49,5.49s-5.49,-2.42 -5.49,-5.49 2.42,-5.49 5.49,-5.49 5.49,2.42 5.49,5.49ZM52.97,46.55c0,1.87 1.43,3.3 3.3,3.3s3.3,-1.43 3.3,-3.3 -1.43,-3.3 -3.3,-3.3 -3.3,1.43 -3.3,3.3Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#000" android:pathData="M40.3,17.04h47.74v12.6h-47.74z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#000" android:pathData="M42.65,15.47h42.9v2.64h-42.9z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#000" android:pathData="M44.71,14.25h39.23v4.89h-39.23z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#000" android:pathData="M40.3,97.28h47.74v12.35h-47.74z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#000" android:pathData="M41.34,108.99h45.04v3.25h-45.04z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#000" android:pathData="M44.1,110.99h39.67v2.25h-39.67z" android:strokeWidth="0"/>
|
||||
|
||||
</vector>
|
||||
@@ -1,170 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#3DDC84"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
||||
@@ -1,30 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
||||
@@ -0,0 +1,21 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="128dp" android:viewportHeight="128" android:viewportWidth="128" android:width="128dp">
|
||||
|
||||
<path android:fillColor="#fff" android:pathData="M47.5,14L80.5,14A8,8 0,0 1,88.5 22L88.5,106A8,8 0,0 1,80.5 114L47.5,114A8,8 0,0 1,39.5 106L39.5,22A8,8 0,0 1,47.5 14z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#00000000" android:pathData="M47.5,14L80.5,14A8,8 0,0 1,88.5 22L88.5,106A8,8 0,0 1,80.5 114L47.5,114A8,8 0,0 1,39.5 106L39.5,22A8,8 0,0 1,47.5 14z" android:strokeColor="#000" android:strokeWidth="2"/>
|
||||
|
||||
<path android:fillColor="#e1e0a6" android:pathData="M48.05,14.8L79.67,14.8A8,8 0,0 1,87.67 22.8L87.67,105.29A8,8 0,0 1,79.67 113.29L48.05,113.29A8,8 0,0 1,40.05 105.29L40.05,22.8A8,8 0,0 1,48.05 14.8z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#b8ca43" android:pathData="M73.43,109.33c0,1.65 -0.93,3.01 -2.07,3.01h-24.79c-1.14,0 -2.07,-1.35 -2.07,-3.01 0,0 13.32,-25.58 14.46,-25.58s14.46,25.58 14.46,25.58Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#231c1c" android:pathData="M71.51,113.36h-24.06c-1.66,0 -3,-1.92 -3,-4.3v-0.43s0.2,-0.43 0.2,-0.43c13.23,-24.91 14.23,-24.91 14.84,-24.91s1.6,0 14.84,24.91l0.2,0.43v0.43c0,2.43 -1.3,4.3 -3.01,4.3h0ZM45.87,109.34c0.1,0.57 0.5,1 1.01,1h24.19c0.5,0 0.81,-0.43 1.01,-1 -4.64,-8.59 -11.19,-20.47 -13.1,-23.05 -1.91,2.58 -8.47,14.46 -13.1,23.05Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#b8ca43" android:pathData="M82.73,107.65c0,1.83 -1.02,3.43 -2.35,3.43h-27.85c-1.26,0 -2.35,-1.49 -2.35,-3.43 0,0 14.98,-28.68 16.24,-28.68 1.33,0 16.32,28.68 16.32,28.68Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#231c1c" android:pathData="M80.91,113.36h-28.85c-1.78,0 -3.24,-2.12 -3.24,-4.72v-0.35s0.16,-0.35 0.16,-0.35c15.76,-30.09 16.98,-30.09 17.47,-30.09s1.71,0 17.47,30.09l0.16,0.35v0.35c0.08,2.6 -1.38,4.72 -3.17,4.72ZM50.18,108.34c0.08,1.06 0.82,2.01 1.56,2.01h29.13c0.82,0 1.48,-0.83 1.56,-2.01 -6.65,-12.63 -14.28,-26.43 -16.08,-28.68 -1.81,2.24 -9.44,16.05 -16.17,28.68Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#f29b54" android:pathData="M52.47,44.36c3.08,0 5.38,-4.89 3.43,-9.64 -0.63,-1.53 -1.78,-2.45 -3,-2.45h-0.63c-1.37,0 -2.69,0.99 -3.34,2.73 -1.75,4.65 0.52,9.35 3.54,9.35h0Z" android:strokeWidth="0"/>
|
||||
|
||||
<path android:fillColor="#231c1c" android:pathData="M58.4,39.37c0,4.21 -2.27,7.52 -5.16,7.52s-5.16,-3.31 -5.16,-7.52 2.27,-7.52 5.16,-7.52 5.16,3.31 5.16,7.52ZM50.14,39.37c0,2.56 1.34,4.51 3.1,4.51s3.1,-1.96 3.1,-4.51 -1.34,-4.51 -3.1,-4.51 -3.1,1.96 -3.1,4.51Z" android:strokeWidth="0"/>
|
||||
|
||||
</vector>
|
||||