Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
598f00c536 | ||
|
|
426dbf1457 | ||
|
|
ba1b139f40 | ||
|
|
40dc4b788d | ||
|
|
69d5ec6477 | ||
|
|
96cb5538da | ||
|
|
c3101ea5f6 | ||
|
|
493e6559df | ||
|
|
8945002652 | ||
|
|
8f30f3558a | ||
|
|
15ba07198d | ||
|
|
39fff2bfc9 | ||
|
|
8339c2d86b | ||
|
|
29ca2d1c50 | ||
|
|
8b2cd301c9 | ||
|
|
5240320d99 | ||
|
|
25205d579b | ||
|
|
32c904f504 | ||
|
|
9e3a62a283 | ||
|
|
050e172949 | ||
|
|
b231fe8f4e | ||
|
|
14c2fd8aed | ||
|
|
27ac32648c | ||
|
|
f6c3a4b34a | ||
|
|
fcf0513356 | ||
|
|
26f51acc0c | ||
|
|
9a36ad35e4 | ||
|
|
4771eaaa7e | ||
|
|
170a642858 | ||
|
|
2dd4fb9e58 | ||
|
|
77c95ed14a | ||
|
|
75b3467f89 | ||
|
|
7c77f4a75e | ||
|
|
a36403ee14 | ||
|
|
31c99f3e6e | ||
|
|
fdd85b2df3 | ||
|
|
1e971d4ec3 | ||
|
|
1274349fc9 | ||
|
|
f2065c3ec8 | ||
|
|
bb34c1e02f | ||
|
|
41ac2482d8 | ||
|
|
9baacea029 | ||
|
|
1d87208dca | ||
|
|
af315b7775 | ||
|
|
212d21761b | ||
|
|
eb48200149 | ||
|
|
814db9020a | ||
|
|
893a729093 | ||
|
|
43b06d11eb | ||
|
|
3e9e8ca299 | ||
|
|
0a6ce5bf07 | ||
|
|
813eb7fb32 | ||
|
|
e30056eb5d | ||
|
|
7f039fa2b4 | ||
|
|
9be3a9c6d3 | ||
|
|
a8989b0810 | ||
|
|
c9f27e3157 | ||
|
|
26f1e17b7c | ||
|
|
47fa7563c0 | ||
|
|
f2fc197df7 | ||
|
|
647ebea95b | ||
|
|
eebc4d4ee4 | ||
|
|
e1ff89d3d9 | ||
|
|
11d72a2336 | ||
|
|
68e6544da8 | ||
|
|
a26f7e30a4 | ||
|
|
b989a47b9e | ||
|
|
a7f98989b3 | ||
|
|
4aaded50ac | ||
|
|
3089841a05 | ||
|
|
eeabdd24fd | ||
|
|
8c82ed7d8c | ||
|
|
5fd289afb5 | ||
|
|
8d0213c7bb | ||
|
|
7e8b83aefe | ||
|
|
136432b97b | ||
|
|
cbcf71da8a | ||
|
|
9bc58aa9fe | ||
|
|
74e3fd8878 | ||
|
|
c857f4a1e7 | ||
|
|
fb853086e6 | ||
|
|
54f4130bab | ||
|
|
2acc11875b | ||
|
|
0c1b341ce9 | ||
|
|
b4d89a54e3 | ||
|
|
c7d3ae137f | ||
|
|
e71ae4fda1 | ||
|
|
8c111ffaf2 | ||
|
|
238c7b512a | ||
|
|
68e5be5214 | ||
|
|
b417da22a2 | ||
|
|
3758363dd3 | ||
|
|
b7587e419b | ||
|
|
4decb78017 | ||
|
|
129e0c36fa | ||
|
|
a784ff2cd8 | ||
|
|
52badae681 | ||
|
|
2bfd46d5f5 | ||
|
|
10240aaa4e | ||
|
|
4855d59e99 | ||
|
|
59594878ab | ||
|
|
7fc552ab67 | ||
|
|
5197800b55 | ||
|
|
6fe29dfe53 | ||
|
|
ea84410eb6 | ||
|
|
0a8a52ea3c | ||
|
|
d115339a99 | ||
|
|
0c01f0dba2 | ||
|
|
7b35b2eb80 | ||
|
|
3508205328 | ||
|
|
0c7ec55414 | ||
|
|
8cf43373c8 | ||
|
|
e14e402c2f | ||
|
|
84e93a652b | ||
|
|
23a9f10939 | ||
|
|
8c485c6157 | ||
|
|
618e896393 | ||
|
|
18ca6283ee | ||
|
|
9b7f9c9217 | ||
|
|
7f32f76da9 | ||
|
|
9a31467584 | ||
|
|
23884b53a7 | ||
|
|
497860369c | ||
|
|
6800830280 | ||
|
|
6111913de4 | ||
|
|
5c9994940d | ||
|
|
b399dae19d | ||
|
|
f2921a8069 | ||
|
|
344e5b6e8c | ||
|
|
efbecd2a56 | ||
|
|
650b12460a | ||
|
|
cb3f19a5d0 | ||
|
|
5b6768723d | ||
|
|
326dda6662 | ||
|
|
f73939ed2c | ||
|
|
0684b03b5e | ||
|
|
1127ff86d9 | ||
|
|
4e8160496b | ||
|
|
e18cb0c75c | ||
|
|
d11d7a1b9b | ||
|
|
aa3ce3bbd5 | ||
|
|
1c7ae9771a | ||
|
|
f1c6f3e36f | ||
|
|
a04da0801a | ||
|
|
9ef38cb086 | ||
|
|
3fe29db05b | ||
|
|
09626a9226 | ||
|
|
e822b18624 | ||
|
|
5bb7ba9399 | ||
|
|
c794ea0b60 | ||
|
|
4a72f8dbc0 | ||
|
|
ef61d3b028 | ||
|
|
ead7bd36fe | ||
|
|
240f30b187 | ||
|
|
24eb0bc20c | ||
|
|
b0bf5d875a | ||
|
|
cea07a185b | ||
|
|
2db9a330ad | ||
|
|
3f952796a3 | ||
|
|
350addbefa | ||
|
|
23c8a82390 | ||
|
|
c063814b93 | ||
|
|
3c4fa741c6 | ||
|
|
49da709574 | ||
|
|
177f3e21bf | ||
|
|
82ce78fc0e | ||
|
|
346a4640c1 | ||
|
|
d9998715cb | ||
|
|
842a77b8c5 | ||
|
|
4b235d07ba | ||
|
|
f615dfe527 | ||
|
|
92e530432f | ||
|
|
4a0f0f371a | ||
|
|
333d0692e8 | ||
|
|
241d0ce861 | ||
|
|
77d2deae0c | ||
|
|
7cc31f43b1 | ||
|
|
bdd89a27b9 | ||
|
|
77481770a6 | ||
|
|
c9f616e1c0 | ||
|
|
167f82edea | ||
|
|
8032f13f0e | ||
|
|
71fe478d54 | ||
|
|
e3af22bbeb | ||
|
|
87ee6b7041 | ||
|
|
b6b26f6732 | ||
|
|
ab1a9ab5af | ||
|
|
0fe8dc724e | ||
|
|
b5836bea95 | ||
|
|
3fd427afc1 | ||
|
|
d2bd26ba38 | ||
|
|
6ffeebb6a2 | ||
|
|
ccd4bab93d | ||
|
|
bbaa0cf9ee | ||
|
|
19b65999fd | ||
|
|
04ef14e5f1 | ||
|
|
c500fb773e | ||
|
|
8c325ed5de | ||
|
|
4fde150bbe | ||
|
|
cebb14e60b | ||
|
|
0fc6a38b12 | ||
|
|
17340fb74e | ||
|
|
9ec4c5d20b | ||
|
|
a8164da137 | ||
|
|
886b7cb27e | ||
|
|
9f67243f0d | ||
|
|
78d7e0972b | ||
|
|
683f434030 | ||
|
|
df0ac6191f | ||
|
|
1d3ad86341 | ||
|
|
bac5c662ef | ||
|
|
8d447f0068 | ||
|
|
7a2b67ed57 | ||
|
|
c55b8f44f0 | ||
|
|
43806aa694 | ||
|
|
90efcaaae1 | ||
|
|
8fdb0920e6 | ||
|
|
e74f6a258a | ||
|
|
54e8b1816f | ||
|
|
efa3cbc6e1 | ||
|
|
12165d41c2 | ||
|
|
fe3aa1bda8 | ||
|
|
83ae1c721e | ||
|
|
50cae3e04e | ||
|
|
e6b2a2af18 | ||
|
|
02671c0804 | ||
|
|
a3c57bf6ef | ||
|
|
72c8d1313f | ||
|
|
89ca480c0c | ||
|
|
b2a6b17c5a | ||
|
|
a6926f25bc | ||
|
|
335a3f7084 | ||
|
|
58c35c1bbb | ||
|
|
27000d9fa2 | ||
|
|
c5ed7684cf | ||
|
|
d8b92d5cdb | ||
|
|
c7989db3c7 | ||
|
|
353e3c3610 | ||
|
|
2d35dc0620 | ||
|
|
5a1f11ba4f | ||
|
|
c1de9ec1a9 | ||
|
|
b02bb044a3 | ||
|
|
002ad6e4f9 | ||
|
|
c05ea1ced5 | ||
|
|
6537ecfac7 | ||
|
|
0d8fee5929 | ||
|
|
9563bf2057 | ||
|
|
7b75db3437 | ||
|
|
6273412d9e | ||
|
|
87f71c599c | ||
|
|
3261862c7d | ||
|
|
afadfc0d2d | ||
|
|
f6fdaf1673 | ||
|
|
7e21d6c564 | ||
|
|
89c0bb3b1b | ||
|
|
f18b751714 | ||
|
|
250817ffbf | ||
|
|
5e52b7098d | ||
|
|
ffdbf54561 | ||
|
|
b11d89ceda | ||
|
|
045ee268e1 | ||
|
|
f5915bff31 | ||
|
|
d153ec969e | ||
|
|
bfcabe29c0 | ||
|
|
08c71e275e | ||
|
|
d211b6416c | ||
|
|
010a197b94 | ||
|
|
bd4a809cac | ||
|
|
cd5c53a662 | ||
|
|
5e6211035c | ||
|
|
2260f7032c | ||
|
|
1cab7cca82 | ||
|
|
018aa9d3a9 | ||
|
|
423e65990f | ||
|
|
644e2ace3c | ||
|
|
e61a1dc7f4 | ||
|
|
03378e6947 | ||
|
|
0d22efa21b | ||
|
|
72175fd7b2 | ||
|
|
94576238c4 | ||
|
|
6dda721a0b | ||
|
|
9db120bce9 | ||
|
|
1c48dcd01d | ||
|
|
62b296a293 | ||
|
|
5ad27fd477 | ||
|
|
d846384bdc | ||
|
|
5c18fa1074 | ||
|
|
9b13a2158a | ||
|
|
6edbc2560f | ||
|
|
3a1f53b7fc | ||
|
|
cad7839a36 | ||
|
|
219121f400 | ||
|
|
3afbb1dbe0 | ||
|
|
d39a670e4d | ||
|
|
7036b17b93 | ||
|
|
624c9c3dbb | ||
|
|
99cc362fdb | ||
|
|
92563b84ec | ||
|
|
873d68a715 | ||
|
|
7c3c64149a | ||
|
|
7615d7786a | ||
|
|
064237bed4 | ||
|
|
e8f8a145ea | ||
|
|
b03e860dee | ||
|
|
359c4b40e9 | ||
|
|
c4852b3830 | ||
|
|
e006bea84e | ||
|
|
766d54cc13 | ||
|
|
f9b6a96fc5 | ||
|
|
4467aa9085 | ||
|
|
9240a89663 | ||
|
|
c15bea8b37 | ||
|
|
e58de859cd | ||
|
|
22a219e985 | ||
|
|
7823fe0327 | ||
|
|
d0d48f4ad1 | ||
|
|
cd1ed25ba1 | ||
|
|
9e864858c0 | ||
|
|
d72596f3a0 | ||
|
|
f56d0c7d1b | ||
|
|
98e0b4ae2f | ||
|
|
8cb643b8c9 | ||
|
|
0df52203be | ||
|
|
7cf4f85b0d | ||
|
|
e89403dff3 | ||
|
|
9a63bffca9 | ||
|
|
b8a14332c5 | ||
|
|
65342ed8f5 | ||
|
|
f76313b998 | ||
|
|
6e821e9db4 | ||
|
|
696ec185bf | ||
|
|
3f7cfcd079 | ||
|
|
38c5b91eb2 | ||
|
|
2138c0b22c | ||
|
|
c32ffbae68 | ||
|
|
100422fc63 | ||
|
|
3f7984808c | ||
|
|
524baa1271 | ||
|
|
b0fe869954 | ||
|
|
e88f83dd15 | ||
|
|
2b9ed09211 | ||
|
|
9278dd1e76 | ||
|
|
a2f66c29be | ||
|
|
086ca2e049 | ||
|
|
6a8648728b | ||
|
|
5e796605be | ||
|
|
abe1d10440 | ||
|
|
adddb21fbf | ||
|
|
67ad5f3bad | ||
|
|
0cf2302d00 | ||
|
|
e23b95b514 | ||
|
|
ba8fe59bf0 | ||
|
|
380328b401 | ||
|
|
15fc31b131 | ||
|
|
65972a9ae6 | ||
|
|
5351f95cf4 | ||
|
|
e0bc6ccb22 | ||
|
|
58b82e87be | ||
|
|
54c7066a4a | ||
|
|
da2e085e7b | ||
|
|
69e9f91814 | ||
|
|
edfc942a6d | ||
|
|
71f8ee26de | ||
|
|
02ac267c27 | ||
|
|
8ae92ef552 | ||
|
|
4006671f99 | ||
|
|
a19ac36801 | ||
|
|
86d718b5f5 | ||
|
|
e95c923a6a | ||
|
|
ee0a04bf09 | ||
|
|
4f7129f5f4 | ||
|
|
4e5f0d63cc | ||
|
|
c40e70d18e | ||
|
|
b3ca913921 | ||
|
|
99bdcf6637 | ||
|
|
8f8650ef7c | ||
|
|
da2747306b | ||
|
|
bb7dc87027 | ||
|
|
4464cbf7f0 | ||
|
|
c33d567a6a | ||
|
|
2c626db54f | ||
|
|
fec52ca412 | ||
|
|
2cece3dc05 | ||
|
|
37e85c4a6b | ||
|
|
b9f3f158b0 | ||
|
|
e9c4c41d3e | ||
|
|
f2b87a5e0e | ||
|
|
6175338b99 | ||
|
|
729b5bd45a | ||
|
|
5139692f2c | ||
|
|
d6bd048012 | ||
|
|
ca839b2e1f | ||
|
|
02ba6f986b | ||
|
|
417cabcaeb | ||
|
|
5218dd4174 | ||
|
|
35836d7778 | ||
|
|
be9cb13971 | ||
|
|
2a7191b7be | ||
|
|
4b930308f8 | ||
|
|
2567781e63 | ||
|
|
13485cb19c | ||
|
|
eae4e344b6 | ||
|
|
e5fab5cb5e | ||
|
|
5fd233e790 | ||
|
|
48a730e4a9 | ||
|
|
4c3d5af7f7 | ||
|
|
829d982d23 | ||
|
|
b01b9a87d6 | ||
|
|
c4395b364c | ||
|
|
dc1f8b9802 | ||
|
|
4279dd3be7 | ||
|
|
373f784fb6 | ||
|
|
fe12b2116c | ||
|
|
9f906aa11c | ||
|
|
e20b3c7c49 | ||
|
|
9bab8ad4b6 | ||
|
|
31b976c258 | ||
|
|
660116fb60 | ||
|
|
984e34f425 | ||
|
|
cd06c87263 | ||
|
|
633ae66a80 | ||
|
|
005843ec00 | ||
|
|
4327a94c14 | ||
|
|
fb4ffea292 | ||
|
|
7570ab5405 | ||
|
|
8899c5c743 | ||
|
|
cc69b4b63b | ||
|
|
0f77761380 | ||
|
|
cdf124319f | ||
|
|
63fe703a6d | ||
|
|
84043b06e7 | ||
|
|
bf35b34ce2 | ||
|
|
1cde08bef6 | ||
|
|
e37f7e36db | ||
|
|
e6c6184c9d | ||
|
|
512637b23c | ||
|
|
398e43469f | ||
|
|
1f5cab1d5b | ||
|
|
a185c727a2 | ||
|
|
28b9a74c3d | ||
|
|
2e8d8b8603 | ||
|
|
a0a4bc9e4e | ||
|
|
97c23f9d44 | ||
|
|
bde2f7dd1f | ||
|
|
d005102716 | ||
|
|
953dc65428 | ||
|
|
69f8a09ceb | ||
|
|
bf56df28fa | ||
|
|
3e49bc1836 | ||
|
|
ad069e5e9f | ||
|
|
5adfac4db2 | ||
|
|
1ecfa1566f | ||
|
|
724cb5e9f5 | ||
|
|
69a9f36100 | ||
|
|
450dfed0a3 | ||
|
|
c1404ec522 | ||
|
|
bcff2f338f | ||
|
|
5582a5851f | ||
|
|
1d0794d135 | ||
|
|
0e20f211f2 | ||
|
|
6f4a2bec97 | ||
|
|
85e5e3007b | ||
|
|
4760ab01d5 | ||
|
|
d8fc106a89 | ||
|
|
f4bf2786de | ||
|
|
c2e7e38f97 | ||
|
|
343d358d22 |
No files matched your search
@@ -0,0 +1,14 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: Anthonyy232
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
polar: # Replace with a single Polar username
|
||||
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: "[Bug] <BUG_NAME>"
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Smartphone (please complete the following information):**
|
||||
- Device: [e.g. Pixel 32 Pro]
|
||||
- OS: [e.g. OneUI 21]
|
||||
- Version [e.g. v2.1.0]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: "[Feature request] <FEATURE_NAME>"
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
@@ -1,5 +1,6 @@
|
||||
*.iml
|
||||
.gradle
|
||||
.idea
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
@@ -13,3 +14,8 @@
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
local.properties
|
||||
/app/build
|
||||
/app/release
|
||||
/app/schemas
|
||||
.kotlin
|
||||
/.kotlin/sessions
|
||||
Generated
-3
@@ -1,3 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
Generated
-1
@@ -1 +0,0 @@
|
||||
Paperize
|
||||
Generated
-41
@@ -1,41 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AppInsightsSettings">
|
||||
<option name="selectedTabId" value="Android Vitals" />
|
||||
<option name="tabSettings">
|
||||
<map>
|
||||
<entry key="Android Vitals">
|
||||
<value>
|
||||
<InsightsFilterSettings>
|
||||
<option name="connection">
|
||||
<ConnectionSetting>
|
||||
<option name="appId" value="com.anthonyla.paperize" />
|
||||
</ConnectionSetting>
|
||||
</option>
|
||||
<option name="signal" value="SIGNAL_UNSPECIFIED" />
|
||||
<option name="timeIntervalDays" value="SEVEN_DAYS" />
|
||||
<option name="visibilityType" value="ALL" />
|
||||
</InsightsFilterSettings>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="Firebase Crashlytics">
|
||||
<value>
|
||||
<InsightsFilterSettings>
|
||||
<option name="connection">
|
||||
<ConnectionSetting>
|
||||
<option name="appId" value="PLACEHOLDER" />
|
||||
<option name="mobileSdkAppId" value="" />
|
||||
<option name="projectId" value="" />
|
||||
<option name="projectNumber" value="" />
|
||||
</ConnectionSetting>
|
||||
</option>
|
||||
<option name="signal" value="SIGNAL_UNSPECIFIED" />
|
||||
<option name="timeIntervalDays" value="THIRTY_DAYS" />
|
||||
<option name="visibilityType" value="ALL" />
|
||||
</InsightsFilterSettings>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
Generated
-123
@@ -1,123 +0,0 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<JetCodeStyleSettings>
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</JetCodeStyleSettings>
|
||||
<codeStyleSettings language="XML">
|
||||
<option name="FORCE_REARRANGE_MODE" value="1" />
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
<arrangement>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
Generated
-5
@@ -1,5 +0,0 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
||||
Generated
-6
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="17" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
-23
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<value>
|
||||
<entry key="Paperize">
|
||||
<State>
|
||||
<runningDeviceTargetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="RUNNING_DEVICE_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="SERIAL_NUMBER" />
|
||||
<value value="RFCTA1MRS4H" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</runningDeviceTargetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2024-04-30T06:47:19.015867100Z" />
|
||||
</State>
|
||||
</entry>
|
||||
</value>
|
||||
</component>
|
||||
</project>
|
||||
Generated
-19
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="jbr-17" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveExternalAnnotations" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
||||
Generated
-9
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Kotlin2JvmCompilerArguments">
|
||||
<option name="jvmTarget" value="1.8" />
|
||||
</component>
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="1.9.22" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
-10
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectMigrations">
|
||||
<option name="MigrateToGradleLocalJavaHome">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
Generated
-54
@@ -1,54 +0,0 @@
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="androidx.annotation.Nullable" />
|
||||
<option name="myDefaultNotNull" value="androidx.annotation.NonNull" />
|
||||
<option name="myNullables">
|
||||
<value>
|
||||
<list size="15">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jspecify.annotations.Nullable" />
|
||||
<item index="1" class="java.lang.String" itemvalue="com.android.annotations.Nullable" />
|
||||
<item index="2" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
|
||||
<item index="3" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
|
||||
<item index="4" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
|
||||
<item index="6" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.Nullable" />
|
||||
<item index="7" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||
<item index="8" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||
<item index="9" class="java.lang.String" itemvalue="jakarta.annotation.Nullable" />
|
||||
<item index="10" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
|
||||
<item index="11" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||
<item index="12" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
|
||||
<item index="13" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
|
||||
<item index="14" class="java.lang.String" itemvalue="android.annotation.Nullable" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myNotNulls">
|
||||
<value>
|
||||
<list size="14">
|
||||
<item index="0" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
|
||||
<item index="1" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
|
||||
<item index="2" class="java.lang.String" itemvalue="org.jspecify.annotations.NonNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="jakarta.annotation.Nonnull" />
|
||||
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
|
||||
<item index="5" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
|
||||
<item index="6" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||
<item index="7" class="java.lang.String" itemvalue="com.android.annotations.NonNull" />
|
||||
<item index="8" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
|
||||
<item index="10" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||
<item index="11" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||
<item index="12" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.NonNull" />
|
||||
<item index="13" class="java.lang.String" itemvalue="android.annotation.NonNull" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
-6
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,12 +1,13 @@
|
||||
|
||||
<div align="center">
|
||||
<img width="300" height="300" style="display: block; border-radius: 9999px;" src="https://github.com/Anthonyy232/Paperize/assets/60626873/c40018a1-bc0a-4efd-bd4a-bc83fb23589e">
|
||||
<h1>Paperize</h1>
|
||||
<p align="center">
|
||||
</p>
|
||||
<img style="display: block; border-radius: 9999px;" src="https://github.com/user-attachments/assets/e8fb14f5-ec8e-440e-a2ac-8065322b0e28" alt="">
|
||||
<h1>
|
||||
Paperize
|
||||
<p><img style="display: block; border-radius: 9999px;" src="https://img.shields.io/github/downloads/Anthonyy232/Paperize/total" alt=""></p>
|
||||
</h1>
|
||||
<p align="center"></p>
|
||||
<p>Paperize is a dynamic wallpaper changer application designed to keep your device's aesthetic fresh and exciting</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
## Features
|
||||
@@ -14,28 +15,30 @@
|
||||
- **Supports Various Image Types**: Paperize can handle a wide range of image types
|
||||
- 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
|
||||
- **Home and Lock Screen Wallpaper**: Choose the same or separate albums for your home screen and lock screen
|
||||
- **Wallpaper effects**: Change the brightness and the blur of your wallpaper
|
||||
- **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/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/user-attachments/assets/f054e7f1-d67f-4500-a547-64bccd986bbd" width="30%" alt="wallpaper" />
|
||||
<img src="https://github.com/user-attachments/assets/cdf0d989-ae11-44ba-b33c-4aeec6b6116e" 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" />
|
||||
<img src="https://github.com/user-attachments/assets/d23f290d-bb2c-4b89-9321-b426e45864f9" 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>
|
||||
<video controls src="https://github.com/user-attachments/assets/ce7f5c7c-66a7-45fc-bb28-a53d8d9cf733" muted="muted"></video>
|
||||
</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)
|
||||
|
||||
F-Droid will be added soon
|
||||
## Download
|
||||
[<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)
|
||||
[<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" alt="Download app from F-Droid" height="80">](https://f-droid.org/en/packages/com.anthonyla.paperize/)
|
||||
[<img src="https://gitlab.com/IzzyOnDroid/repo/-/raw/master/assets/IzzyOnDroid.png" alt="Download app from IzzyOnDroid" height="80">](https://apt.izzysoft.de/fdroid/index/apk/com.anthonyla.paperize)
|
||||
|
||||
## 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 want to allow more people to use the app. Currently, most of the 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)!
|
||||
|
||||
@@ -45,7 +48,7 @@ I would love some help translating the app! Help me out with that [here](https:/
|
||||
|
||||
- [Kotlin](https://kotlinlang.org/) - A programming language that is used for Android app development
|
||||
- [Jetpack Compose](https://developer.android.com/develop/ui/compose) - A declarative UI toolkit for building native Android UI
|
||||
- [Material 3](https://m3.material.io/) - A UI design system git for modern UI guidelines
|
||||
- [Material 3](https://m3.material.io/) - A UI design system for modern UI guidelines
|
||||
- [Dagger Hilt](https://dagger.dev/hilt/) - A dependency injection library
|
||||
- [Room](https://developer.android.com/training/data-storage/room) - A persistence library that provides an abstraction layer over SQLite interfacing with Kotlin
|
||||
- [AboutLibraries](https://github.com/mikepenz/AboutLibraries) - A library to offer some information of libraries
|
||||
@@ -54,6 +57,8 @@ I would love some help translating the app! Help me out with that [here](https:/
|
||||
- [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
|
||||
- [LazyColumnScrollbar](https://github.com/nanihadesuka/LazyColumnScrollbar) - A Compose scrollbar library
|
||||
- [compose-collapsing-toolbar](https://github.com/onebone/compose-collapsing-toolbar) - A Compose library that provides a collapsing toolbar
|
||||
|
||||
Thanks to the creators and maintainers of the open-source libraries used in this project.
|
||||
|
||||
@@ -63,9 +68,9 @@ 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
|
||||
- Android Gradle Plugin 8.4.1 or later
|
||||
- Gradle 8.8
|
||||
- Android Studio Jellyfish | 2024.2.1 or later
|
||||
- Android Gradle Plugin 8.7.0 or later
|
||||
- Gradle 8.10.2
|
||||
- Minimum SDK 26
|
||||
|
||||
### Steps
|
||||
@@ -81,8 +86,12 @@ All contributions to the app is welcome. Feel free to report any issues and crea
|
||||
|
||||
Inspiration from j4velin for their wallpaper changer app
|
||||
|
||||
## Donations
|
||||
|
||||
If you want to donate, you can do so using GitHub sponsorship (one-time or monthly). I appreciate the thought, thanks!
|
||||
|
||||
|
||||
## License
|
||||
Contact on my GitHub profile
|
||||
|
||||
Anthony La © GNU GPL v3.0
|
||||
[Anthony La](https://github.com/Anthonyy232) © GNU GPL v3.0
|
||||
+82
-75
@@ -1,70 +1,77 @@
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
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")
|
||||
alias(libs.plugins.androidApplication)
|
||||
alias(libs.plugins.kotlinAndroid)
|
||||
alias(libs.plugins.kotlinCompose)
|
||||
alias(libs.plugins.hiltAndroid)
|
||||
alias(libs.plugins.ksp)
|
||||
alias(libs.plugins.kotlinSerialization)
|
||||
}
|
||||
|
||||
ksp {
|
||||
arg("room.schemaLocation", "$projectDir/schemas")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.anthonyla.paperize"
|
||||
compileSdk = 34
|
||||
compileSdk = 35
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.anthonyla.paperize"
|
||||
minSdk = 26
|
||||
targetSdk = 34
|
||||
versionCode = 20
|
||||
versionName = "1.5.2"
|
||||
|
||||
targetSdk = 37
|
||||
versionCode = 37
|
||||
versionName = "3.0.0"
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
useSupportLibrary = true
|
||||
}
|
||||
ndk {
|
||||
debugSymbolLevel = "FULL"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = true
|
||||
isShrinkResources = true
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
signingConfig = signingConfigs.getByName("debug")
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
freeCompilerArgs += strongSkippingConfiguration()
|
||||
jvmTarget = "17"
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
compose = true
|
||||
viewBinding = true
|
||||
buildConfig = true
|
||||
}
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion = "1.5.10"
|
||||
}
|
||||
|
||||
androidResources {
|
||||
@Suppress("UnstableApiUsage")
|
||||
generateLocaleConfig = true
|
||||
}
|
||||
ndkVersion = "26.3.11579264"
|
||||
buildToolsVersion = "34.0.0"
|
||||
|
||||
aboutLibraries {
|
||||
excludeFields = arrayOf("generated")
|
||||
buildToolsVersion = "35.0.1"
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
includeInBundle = false
|
||||
}
|
||||
|
||||
applicationVariants.all {
|
||||
this.outputs
|
||||
.map { it as com.android.build.gradle.internal.api.ApkVariantOutputImpl }
|
||||
.forEach { output ->
|
||||
val apkName = "paperize-v${this.versionName}.apk"
|
||||
output.outputFileName = apkName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,52 +82,52 @@ androidComponents {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("androidx.core:core-ktx:1.13.1")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.1")
|
||||
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-beta02")
|
||||
implementation("androidx.compose.ui:ui-graphics:1.7.0-beta02")
|
||||
implementation("androidx.compose.ui:ui-tooling-preview:1.7.0-beta02")
|
||||
implementation("androidx.compose.material3:material3:1.3.0-beta02")
|
||||
implementation("androidx.navigation:navigation-compose:2.8.0-beta02")
|
||||
implementation("androidx.compose.material:material:1.7.0-beta02")
|
||||
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-beta02")
|
||||
implementation("com.google.accompanist:accompanist-adaptive:0.34.0")
|
||||
implementation("androidx.hilt:hilt-navigation-compose:1.2.0")
|
||||
implementation("androidx.compose.animation:animation:1.7.0-beta02")
|
||||
implementation("androidx.core:core-splashscreen:1.2.0-alpha01")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.1")
|
||||
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("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.1")
|
||||
implementation("com.google.accompanist:accompanist-permissions:0.35.0-alpha")
|
||||
implementation("com.mikepenz:aboutlibraries-core:11.2.1")
|
||||
implementation("com.mikepenz:aboutlibraries-compose-m3:11.2.1")
|
||||
implementation("androidx.compose.foundation:foundation:1.7.0-beta02")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.0-rc01")
|
||||
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.7.0-beta02")
|
||||
debugImplementation("androidx.compose.ui:ui-tooling:1.7.0-beta02")
|
||||
debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.0-beta02")
|
||||
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("com.github.android:renderscript-intrinsics-replacement-toolkit:b6363490c3")
|
||||
}
|
||||
|
||||
private fun strongSkippingConfiguration() = listOf(
|
||||
"-P",
|
||||
"plugin:androidx.compose.compiler.plugins.kotlin:experimentalStrongSkipping=true",
|
||||
)
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||
implementation(libs.androidx.activity.compose)
|
||||
implementation(platform(libs.androidx.compose.bom))
|
||||
implementation(libs.androidx.ui)
|
||||
implementation(libs.androidx.ui.graphics)
|
||||
implementation(libs.androidx.ui.tooling.preview)
|
||||
implementation(libs.androidx.material3)
|
||||
implementation(libs.androidx.navigation.compose)
|
||||
implementation(libs.androidx.material)
|
||||
implementation(libs.androidx.datastore)
|
||||
implementation(libs.androidx.datastore.preferences)
|
||||
implementation(libs.androidx.material.icons.extended)
|
||||
implementation(libs.androidx.hilt.navigation.compose)
|
||||
implementation(libs.androidx.animation)
|
||||
implementation(libs.androidx.core.splashscreen)
|
||||
implementation(libs.androidx.lifecycle.runtime.compose)
|
||||
implementation(libs.gson)
|
||||
implementation(libs.androidx.documentfile)
|
||||
implementation(libs.zoomable)
|
||||
implementation(libs.landscapist.glide)
|
||||
implementation(libs.androidx.work.runtime.ktx)
|
||||
implementation(libs.androidx.hilt.work)
|
||||
implementation(libs.lottie.compose)
|
||||
implementation(libs.accompanist.permissions)
|
||||
implementation(libs.androidx.foundation)
|
||||
implementation(libs.lazycolumnscrollbar)
|
||||
implementation(libs.taskerpluginlibrary)
|
||||
implementation(libs.androidx.profileinstaller)
|
||||
implementation(libs.reorderable)
|
||||
implementation(libs.androidx.glance.appwidget)
|
||||
implementation(libs.androidx.glance.material3)
|
||||
implementation(libs.androidx.glance.material)
|
||||
implementation(files("dependencies/renderscript-toolkit-release.aar"))
|
||||
testImplementation(libs.junit)
|
||||
androidTestImplementation(libs.androidx.junit)
|
||||
androidTestImplementation(libs.androidx.espresso.core)
|
||||
androidTestImplementation(libs.androidx.ui.test.junit4)
|
||||
debugImplementation(libs.androidx.ui.tooling)
|
||||
debugImplementation(libs.androidx.ui.test.manifest)
|
||||
implementation(libs.hilt.android)
|
||||
ksp(libs.hilt.android.compiler)
|
||||
implementation(libs.androidx.room.runtime)
|
||||
ksp(libs.androidx.room.compiler)
|
||||
implementation(libs.androidx.room.ktx)
|
||||
implementation(libs.dfc)
|
||||
implementation (libs.kotlinx.serialization.json)
|
||||
implementation(libs.toolbar.compose)
|
||||
}
|
||||
Binary file not shown.
Vendored
+15
@@ -23,6 +23,8 @@
|
||||
-keep class com.google.gson.reflect.TypeToken { *; }
|
||||
-keep class * extends com.google.gson.reflect.TypeToken
|
||||
-keep class kotlin.coroutines.Continuation
|
||||
-keep class androidx.datastore.*.** {*;}
|
||||
|
||||
-keepclassmembers class com.anthonyla.paperize.feature.wallpaper.domain.model.Album {
|
||||
!transient <fields>;
|
||||
}
|
||||
@@ -35,3 +37,16 @@
|
||||
-keepclassmembers class com.anthonyla.paperize.feature.wallpaper.domain.model.Folder {
|
||||
!transient <fields>;
|
||||
}
|
||||
|
||||
# Keep wallpaper services and their action enums
|
||||
-keep class com.anthonyla.paperize.feature.wallpaper.wallpaper_service.HomeWallpaperService { *; }
|
||||
-keep class com.anthonyla.paperize.feature.wallpaper.wallpaper_service.HomeWallpaperService$Actions { *; }
|
||||
-keep class com.anthonyla.paperize.feature.wallpaper.wallpaper_service.LockWallpaperService { *; }
|
||||
-keep class com.anthonyla.paperize.feature.wallpaper.wallpaper_service.LockWallpaperService$Actions { *; }
|
||||
|
||||
# Keep WallpaperAction classes
|
||||
-keep class com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAction { *; }
|
||||
-keep class com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAction$* { *; }
|
||||
|
||||
# Keep Type enum
|
||||
-keep class com.anthonyla.paperize.core.Type { *; }
|
||||
@@ -2,11 +2,12 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
|
||||
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
|
||||
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" tools:node="remove"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
@@ -17,6 +18,7 @@
|
||||
android:icon="@mipmap/app_icon"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
android:theme="@style/Theme.Paperize" tools:targetApi="tiramisu">
|
||||
<activity
|
||||
android:name=".feature.wallpaper.presentation.MainActivity"
|
||||
@@ -27,18 +29,40 @@
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<meta-data android:resource="@xml/shortcuts" android:name="android.app.shortcuts" />
|
||||
</activity>
|
||||
<activity android:name=".feature.wallpaper.app_shortcut.BroadcastActivity"
|
||||
android:theme="@android:style/Theme.NoDisplay">
|
||||
</activity>
|
||||
<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"
|
||||
<service android:name=".feature.wallpaper.wallpaper_service.HomeWallpaperService" />
|
||||
<service android:name=".feature.wallpaper.wallpaper_service.LockWallpaperService" />
|
||||
<service
|
||||
android:name=".feature.wallpaper.wallpaper_tile.ChangeWallpaperTileService"
|
||||
android:exported="true"
|
||||
android:label="@string/change_wallpaper"
|
||||
android:icon="@drawable/notification_icon"
|
||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||
<intent-filter> <action android:name="android.service.quicksettings.action.QS_TILE" /> </intent-filter>
|
||||
</service>
|
||||
<receiver android:name=".feature.wallpaper.wallpaper_alarmmanager.WallpaperBootAndChangeReceiver"
|
||||
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" />
|
||||
<action android:name="com.anthonyla.paperize.SHORTCUT" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name="com.anthonyla.paperize.feature.wallpaper.glance_widget.PaperizeWidgetReceiver"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/paperize_widget_info" />
|
||||
</receiver>
|
||||
<provider
|
||||
android:name="androidx.startup.InitializationProvider"
|
||||
android:authorities="${applicationId}.androidx-startup"
|
||||
@@ -47,5 +71,23 @@
|
||||
<meta-data android:name="androidx.emoji2.text.EmojiCompatInitializer"
|
||||
tools:node="remove" />
|
||||
</provider>
|
||||
|
||||
<activity
|
||||
android:name=".feature.wallpaper.tasker_shortcut.ActivityConfigBasicAction"
|
||||
android:exported="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="Change wallpaper">
|
||||
<intent-filter>
|
||||
<action android:name="com.twofortyfouram.locale.intent.action.EDIT_SETTING" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".feature.wallpaper.tasker_shortcut.ActivityConfigBasicEvent"
|
||||
android:exported="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="Change wallpaper event">
|
||||
<intent-filter>
|
||||
<action android:name="net.dinglisch.android.tasker.ACTION_EDIT_EVENT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.anthonyla.paperize
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.database.CursorWindow
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import java.lang.reflect.Field
|
||||
|
||||
|
||||
/**
|
||||
* Application class for Hilt
|
||||
@@ -14,7 +17,7 @@ class App: Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
val channel = NotificationChannel("wallpaper_service_channel", "Paperize", NotificationManager.IMPORTANCE_LOW)
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,6 @@ package com.anthonyla.paperize.core
|
||||
enum class ScalingConstants {
|
||||
FIT,
|
||||
FILL,
|
||||
STRETCH
|
||||
STRETCH,
|
||||
NONE
|
||||
}
|
||||
@@ -6,24 +6,45 @@ package com.anthonyla.paperize.core
|
||||
object SettingsConstants {
|
||||
const val SETTINGS_DATASTORE = "settings_datastore"
|
||||
const val DARK_MODE_TYPE = "dark_mode_type"
|
||||
const val AMOLED_THEME_TYPE = "amoled_theme_type"
|
||||
const val DYNAMIC_THEME_TYPE = "dynamic_theme_type"
|
||||
const val ANIMATE_TYPE = "animate_type"
|
||||
const val ENABLE_CHANGER = "enable_changer"
|
||||
const val HOME_WALLPAPER = "home_wallpaper"
|
||||
const val LOCK_WALLPAPER = "lock_wallpaper"
|
||||
const val ENABLE_HOME_WALLPAPER = "home_wallpaper"
|
||||
const val ENABLE_LOCK_WALLPAPER = "lock_wallpaper"
|
||||
const val CURRENT_HOME_WALLPAPER = "current_home_wallpaper"
|
||||
const val CURRENT_LOCK_WALLPAPER = "current_lock_wallpaper"
|
||||
const val HOME_ALBUM_NAME = "home_album_name"
|
||||
const val LOCK_ALBUM_NAME = "lock_album_name"
|
||||
const val HOME_WALLPAPER_CHANGE_INTERVAL = "home_wallpaper_change_interval"
|
||||
const val LOCK_WALLPAPER_CHANGE_INTERVAL = "lock_wallpaper_change_interval"
|
||||
const val REFRESH = "refresh"
|
||||
const val WALLPAPER_CHANGE_INTERVAL_DEFAULT = 15
|
||||
const val WALLPAPER_CHANGE_INTERVAL_MIN = 1
|
||||
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 HOME_DARKEN_PERCENTAGE = "home_darken_percentage"
|
||||
const val LOCK_DARKEN_PERCENTAGE = "darken_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"
|
||||
const val HOME_BLUR_PERCENTAGE = "home_blur_percentage"
|
||||
const val LOCK_BLUR_PERCENTAGE = "lock_blur_percentage"
|
||||
const val VIGNETTE = "vignette"
|
||||
const val HOME_VIGNETTE_PERCENTAGE = "home_vignette_percentage"
|
||||
const val LOCK_VIGNETTE_PERCENTAGE = "lock_vignette_percentage"
|
||||
const val HOME_NEXT_SET_TIME = "next_set_time_1"
|
||||
const val LOCK_NEXT_SET_TIME = "next_set_time_2"
|
||||
const val NEXT_HOME_WALLPAPER = "next_home_wallpaper"
|
||||
const val NEXT_LOCK_WALLPAPER = "next_lock_wallpaper"
|
||||
const val GRAYSCALE = "grayscale"
|
||||
const val HOME_GRAYSCALE_PERCENTAGE = "home_grayscale_percentage"
|
||||
const val LOCK_GRAYSCALE_PERCENTAGE = "lock_grayscale_percentage"
|
||||
const val CHANGE_START_TIME = "change_start_time"
|
||||
const val START_HOUR = "start_hour"
|
||||
const val START_MINUTE = "start_minute"
|
||||
const val SHUFFLE = "shuffle"
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.anthonyla.paperize.core
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
|
||||
import com.bumptech.glide.util.Util
|
||||
import java.security.MessageDigest
|
||||
|
||||
/**
|
||||
* A BitmapTransformation that applies a vignette effect to a bitmap to be used with Glide
|
||||
*/
|
||||
class VignetteBitmapTransformation(private val percent: Int): BitmapTransformation() {
|
||||
|
||||
override fun transform(
|
||||
pool: BitmapPool,
|
||||
toTransform: Bitmap,
|
||||
outWidth: Int,
|
||||
outHeight: Int
|
||||
): Bitmap {
|
||||
return vignetteBitmap(toTransform, percent)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return other is VignetteBitmapTransformation && other.percent == percent
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return Util.hashCode(percent)
|
||||
}
|
||||
|
||||
override fun updateDiskCacheKey(messageDigest: MessageDigest) {
|
||||
messageDigest.update((ID + percent).toByteArray(CHARSET))
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ID = "com.bumptech.glide.transformations.VignettedBitmapTransformation"
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,48 @@
|
||||
package com.anthonyla.paperize.core
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.ColorMatrix
|
||||
import android.graphics.ColorMatrixColorFilter
|
||||
import android.graphics.ImageDecoder
|
||||
import android.graphics.Matrix
|
||||
import android.graphics.Paint
|
||||
import android.graphics.RadialGradient
|
||||
import android.graphics.Shader
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.DocumentsContract
|
||||
import android.util.Base64
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.Log
|
||||
import android.util.Size
|
||||
import android.view.WindowManager
|
||||
import android.view.WindowMetrics
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.compose.ui.util.fastRoundToInt
|
||||
import androidx.core.graphics.createBitmap
|
||||
import androidx.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import com.anthonyla.paperize.core.ScreenMetricsCompat.getScreenSize
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Metadata
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.google.android.renderscript.Toolkit
|
||||
import com.lazygeniouz.dfc.file.DocumentFileCompat
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.nio.charset.Charset
|
||||
import java.util.zip.DeflaterOutputStream
|
||||
import java.util.zip.InflaterInputStream
|
||||
|
||||
enum class Type { HOME, LOCK, BOTH }
|
||||
enum class Type { HOME, LOCK, SINGLE, REFRESH }
|
||||
|
||||
/**
|
||||
* Get the dimensions of the image from the uri
|
||||
@@ -27,73 +51,213 @@ 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
|
||||
val width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0)
|
||||
val height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0)
|
||||
if (width > 0 && height > 0) {
|
||||
return Size(width, height)
|
||||
}
|
||||
return Size(width, height)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w("WallpaperUtil", "Error reading EXIF dimensions for $this, falling back: $e")
|
||||
}
|
||||
|
||||
try {
|
||||
context.contentResolver.openInputStream(this)?.use { inputStream ->
|
||||
val options = BitmapFactory.Options().apply {
|
||||
inJustDecodeBounds = true
|
||||
}
|
||||
BitmapFactory.decodeStream(inputStream, null, options)
|
||||
if (options.outWidth > 0 && options.outHeight > 0) {
|
||||
return Size(options.outWidth, options.outHeight)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error getting image dimensions with BitmapFactory for $this: $e")
|
||||
return null
|
||||
} catch (e: Exception) { return null }
|
||||
}
|
||||
Log.w("WallpaperUtil", "Could not get image dimensions for $this")
|
||||
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() }
|
||||
if (imageSize.width == 0 || imageSize.height == 0) return 1
|
||||
if (width == 0 || height == 0) return 1
|
||||
|
||||
if (imageSize.width > width || imageSize.height > height) {
|
||||
val heightRatio = (imageSize.height.toFloat() / height.toFloat()).fastRoundToInt()
|
||||
val widthRatio = (imageSize.width.toFloat() / width.toFloat()).fastRoundToInt()
|
||||
return (if (heightRatio < widthRatio) heightRatio else widthRatio).coerceAtLeast(1)
|
||||
}
|
||||
else { return 1 }
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the screen size of the device without orientation
|
||||
* https://stackoverflow.com/a/70087378
|
||||
*/
|
||||
object ScreenMetricsCompat {
|
||||
private val api: Api = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) ApiLevel30() else Api()
|
||||
fun getScreenSize(context: Context): Size = api.getScreenSize(context)
|
||||
@Suppress("DEPRECATION")
|
||||
private open class Api {
|
||||
open fun getScreenSize(context: Context): Size {
|
||||
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
val display = windowManager.defaultDisplay
|
||||
val metrics = if (display != null) {
|
||||
DisplayMetrics().also { display.getRealMetrics(it) }
|
||||
} else {
|
||||
Resources.getSystem().displayMetrics
|
||||
}
|
||||
return Size(metrics.widthPixels, metrics.heightPixels)
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
private class ApiLevel30 : Api() {
|
||||
override fun getScreenSize(context: Context): Size {
|
||||
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
val metrics: WindowMetrics = windowManager.currentWindowMetrics
|
||||
return Size(metrics.bounds.width(), metrics.bounds.height())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get device screen size with orientation
|
||||
*/
|
||||
fun getDeviceScreenSize(context: Context): Size {
|
||||
val orientation = context.resources.configuration.orientation
|
||||
val size = getScreenSize(context)
|
||||
return if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
Size(minOf(size.width, size.height), maxOf(size.width, size.height))
|
||||
} else {
|
||||
Size(maxOf(size.width, size.height), minOf(size.width, size.height))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a bitmap from a URI that is scaled down to the device's screen size
|
||||
*/
|
||||
fun retrieveBitmap(
|
||||
context: Context,
|
||||
wallpaper: Uri,
|
||||
width: Int,
|
||||
height: Int,
|
||||
scaling: ScalingConstants = ScalingConstants.FIT
|
||||
): Bitmap? {
|
||||
val imageSize = wallpaper.getImageDimensions(context) ?: return null
|
||||
if (imageSize.width <= 0 || imageSize.height <= 0) {
|
||||
Log.e("WallpaperUtil", "Invalid image dimensions from URI: $imageSize")
|
||||
return null
|
||||
}
|
||||
|
||||
val sampleSize = if (scaling == ScalingConstants.NONE) {
|
||||
1
|
||||
} else {
|
||||
calculateInSampleSize(imageSize, width, height)
|
||||
}
|
||||
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
try {
|
||||
val source = ImageDecoder.createSource(context.contentResolver, wallpaper)
|
||||
ImageDecoder.decodeBitmap(source) { decoder, _, _ ->
|
||||
decoder.setTargetSampleSize(sampleSize)
|
||||
decoder.isMutableRequired = true
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w("WallpaperUtil", "ImageDecoder failed, falling back to BitmapFactory: $e")
|
||||
context.contentResolver.openInputStream(wallpaper)?.use { inputStream ->
|
||||
val options = BitmapFactory.Options().apply {
|
||||
inSampleSize = sampleSize
|
||||
inMutable = true
|
||||
}
|
||||
BitmapFactory.decodeStream(inputStream, null, options)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
context.contentResolver.openInputStream(wallpaper)?.use { inputStream ->
|
||||
val options = BitmapFactory.Options().apply {
|
||||
inSampleSize = sampleSize
|
||||
inMutable = true
|
||||
}
|
||||
BitmapFactory.decodeStream(inputStream, null, options)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val SharedPaintFilterAntiAlias = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG)
|
||||
|
||||
/**
|
||||
* 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
|
||||
if (source.width == width && source.height == height) {
|
||||
return source
|
||||
}
|
||||
if (source.width <= 0 || source.height <= 0 || width <= 0 || height <= 0) {
|
||||
Log.w("WallpaperUtil", "Invalid dimensions for fitBitmap, returning source.")
|
||||
return source
|
||||
}
|
||||
|
||||
return try {
|
||||
val bitmap = createBitmap(width, height, source.config ?: Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(bitmap)
|
||||
val scale = width.toFloat() / source.width
|
||||
val scaledSourceHeight = source.height * scale
|
||||
val yOffset = (height - scaledSourceHeight) / 2f
|
||||
val matrix = Matrix().apply {
|
||||
postScale(scale, scale)
|
||||
postTranslate(0f, yOffset)
|
||||
}
|
||||
canvas.drawBitmap(source, matrix, SharedPaintFilterAntiAlias)
|
||||
bitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error fitting bitmap: $e")
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale a bitmap using the fill height method
|
||||
* Scale a bitmap using the fill 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)
|
||||
if (source.width == width && source.height == height) {
|
||||
return source
|
||||
}
|
||||
return try {
|
||||
val bitmap = createBitmap(width, height, source.config ?: Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(bitmap)
|
||||
canvas.drawBitmap(scaledBitmap, x, y, null)
|
||||
scaledBitmap.recycle()
|
||||
return bitmap
|
||||
val sourceAspect = source.width.toFloat() / source.height.toFloat()
|
||||
val targetAspect = width.toFloat() / height.toFloat()
|
||||
|
||||
val scale: Float
|
||||
val xOffset: Float
|
||||
val yOffset: Float
|
||||
|
||||
if (sourceAspect >= targetAspect) {
|
||||
scale = height.toFloat() / source.height.toFloat()
|
||||
xOffset = (width - source.width * scale) / 2f
|
||||
yOffset = 0f
|
||||
} else {
|
||||
scale = width.toFloat() / source.width.toFloat()
|
||||
xOffset = 0f
|
||||
yOffset = (height - source.height * scale) / 2f
|
||||
}
|
||||
|
||||
val matrix = Matrix().apply {
|
||||
postScale(scale, scale)
|
||||
postTranslate(xOffset, yOffset)
|
||||
}
|
||||
canvas.drawBitmap(source, matrix, SharedPaintFilterAntiAlias)
|
||||
bitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error filling bitmap: $e")
|
||||
return source
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,127 +265,293 @@ fun fillBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
* 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
|
||||
if (source.width == width && source.height == height) {
|
||||
return source
|
||||
}
|
||||
return try {
|
||||
val bitmap = createBitmap(width, height, source.config ?: Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(bitmap)
|
||||
val matrix = Matrix().apply {
|
||||
setScale(
|
||||
width.toFloat() / source.width,
|
||||
height.toFloat() / source.height
|
||||
)
|
||||
}
|
||||
canvas.drawBitmap(source, matrix, SharedPaintFilterAntiAlias)
|
||||
bitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error stretching bitmap: $e")
|
||||
return source
|
||||
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")
|
||||
fun darkenBitmap(source: Bitmap, brightnessToRetainPercent: Int): Bitmap {
|
||||
if (!source.isMutable) {
|
||||
Log.w("WallpaperUtil", "darkenBitmap received an immutable bitmap. Returning a copy.")
|
||||
val mutableCopy = source.copy(source.config ?: Bitmap.Config.ARGB_8888, true)
|
||||
return darkenBitmap(mutableCopy, brightnessToRetainPercent)
|
||||
}
|
||||
|
||||
val targetBrightnessFactor = brightnessToRetainPercent.coerceIn(0, 100) / 100f
|
||||
if (targetBrightnessFactor >= 1.0f) {
|
||||
return source
|
||||
}
|
||||
|
||||
val paint = Paint().apply {
|
||||
colorFilter = ColorMatrixColorFilter(ColorMatrix().apply {
|
||||
setScale(targetBrightnessFactor, targetBrightnessFactor, targetBrightnessFactor, 1f)
|
||||
})
|
||||
}
|
||||
Canvas(source).drawBitmap(source, 0f, 0f, paint)
|
||||
return source
|
||||
}
|
||||
|
||||
/**
|
||||
* Blur the bitmap by a certain percentage
|
||||
*/
|
||||
fun blurBitmap(source: Bitmap, percent: Int): Bitmap {
|
||||
try {
|
||||
val factor = percent.toFloat().div(100f) * 10
|
||||
return Toolkit.blur(source, factor.toInt())
|
||||
if (percent <= 0) return source
|
||||
return try {
|
||||
val radius = (percent.coerceIn(0, 100) * 0.25f).coerceIn(1f, 25f)
|
||||
Toolkit.blur(source, radius.toInt())
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error darkening bitmap: $e")
|
||||
Log.e("WallpaperUtil", "Error blurring bitmap (Renderscript): $e")
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a vignette effect to the bitmap
|
||||
*/
|
||||
fun vignetteBitmap(source: Bitmap, percent: Int): Bitmap {
|
||||
if (percent <= 0) return source
|
||||
if (!source.isMutable) {
|
||||
Log.w("WallpaperUtil", "vignetteBitmap received an immutable bitmap. Returning a copy.")
|
||||
val mutableCopy = source.copy(source.config ?: Bitmap.Config.ARGB_8888, true)
|
||||
return vignetteBitmap(mutableCopy, percent)
|
||||
}
|
||||
|
||||
try {
|
||||
val canvas = Canvas(source)
|
||||
val dim = if (source.width < source.height) source.height else source.width
|
||||
val rad = (dim * (1 - (percent.coerceIn(0, 100) / 150f))).coerceAtLeast(0.1f)
|
||||
val centerX = source.width / 2f
|
||||
val centerY = source.height / 2f
|
||||
|
||||
val colors = intArrayOf(
|
||||
Color.TRANSPARENT,
|
||||
Color.argb((0.1f * 255).toInt(), 0, 0, 0),
|
||||
Color.argb((0.8f * 255).toInt(), 0, 0, 0)
|
||||
)
|
||||
val pos = floatArrayOf(0f, 0.7f, 1f)
|
||||
|
||||
|
||||
val vignettePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
shader = RadialGradient(
|
||||
centerX, centerY, rad,
|
||||
colors, pos, Shader.TileMode.CLAMP
|
||||
)
|
||||
}
|
||||
canvas.drawRect(0f, 0f, source.width.toFloat(), source.height.toFloat(), vignettePaint)
|
||||
return source
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error applying vignette: $e")
|
||||
return source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve wallpaper URIs from a folder directory URI
|
||||
* Apply a grey filter to the bitmap based on a percentage
|
||||
*/
|
||||
fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
|
||||
fun grayBitmap(bitmap: Bitmap, percent: Int): Bitmap {
|
||||
if (percent <= 0) return bitmap
|
||||
if (!bitmap.isMutable) {
|
||||
Log.w("WallpaperUtil", "grayBitmap received an immutable bitmap. Returning a copy.")
|
||||
val mutableCopy = bitmap.copy(bitmap.config ?: Bitmap.Config.ARGB_8888, true)
|
||||
return grayBitmap(mutableCopy, percent)
|
||||
}
|
||||
|
||||
val factor = percent.coerceIn(0, 100) / 100f
|
||||
if (factor <= 0f) return bitmap
|
||||
|
||||
val colorMatrix = ColorMatrix().apply { setSaturation(1 - factor) }
|
||||
val paint = Paint().apply { colorFilter = ColorMatrixColorFilter(colorMatrix) }
|
||||
|
||||
Canvas(bitmap).drawBitmap(bitmap, 0f, 0f, paint)
|
||||
return bitmap
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all wallpapers from a folder URI
|
||||
*/
|
||||
suspend fun getWallpaperFromFolder(folderUri: String, context: Context): List<Wallpaper> = withContext(Dispatchers.IO) {
|
||||
val allowedExtensions = setOf("jpg", "jpeg", "png", "heif", "heic", "webp")
|
||||
val contentResolver = context.contentResolver
|
||||
val wallpapers = mutableListOf<Wallpaper>()
|
||||
|
||||
if (folderUri.isEmpty()) {
|
||||
return@withContext emptyList<Wallpaper>()
|
||||
}
|
||||
val rootUri = folderUri.toUri()
|
||||
val foldersToVisit = ArrayDeque<Uri>()
|
||||
foldersToVisit.add(rootUri)
|
||||
|
||||
val projection = arrayOf(
|
||||
DocumentsContract.Document.COLUMN_DOCUMENT_ID,
|
||||
DocumentsContract.Document.COLUMN_DISPLAY_NAME,
|
||||
DocumentsContract.Document.COLUMN_MIME_TYPE,
|
||||
DocumentsContract.Document.COLUMN_LAST_MODIFIED,
|
||||
)
|
||||
|
||||
try {
|
||||
val folderDocumentFile = DocumentFileCompat.fromTreeUri(context, folderUri.toUri())
|
||||
return listFilesRecursive(folderDocumentFile, context)
|
||||
while (foldersToVisit.isNotEmpty()) {
|
||||
val currentFolderDocumentUri = foldersToVisit.removeFirst()
|
||||
val currentFolderTreeDocId = DocumentsContract.getTreeDocumentId(currentFolderDocumentUri)
|
||||
?: DocumentsContract.getDocumentId(currentFolderDocumentUri)
|
||||
|
||||
if (currentFolderTreeDocId == null) {
|
||||
Log.w("WallpaperUtil", "Could not get tree document ID for $currentFolderDocumentUri")
|
||||
continue
|
||||
}
|
||||
|
||||
val childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(
|
||||
rootUri,
|
||||
currentFolderTreeDocId
|
||||
)
|
||||
|
||||
contentResolver.query(childrenUri, projection, null, null, null)?.use { cursor ->
|
||||
val idIndex = cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_DOCUMENT_ID)
|
||||
val nameIndex = cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_DISPLAY_NAME)
|
||||
val mimeTypeIndex = cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_MIME_TYPE)
|
||||
val lastModifiedIndex = cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_LAST_MODIFIED)
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
val documentId = cursor.getString(idIndex)
|
||||
val displayName = cursor.getString(nameIndex)
|
||||
val mimeType = cursor.getString(mimeTypeIndex)
|
||||
val dateModified = cursor.getLong(lastModifiedIndex)
|
||||
|
||||
val documentUri = DocumentsContract.buildDocumentUriUsingTree(rootUri, documentId)
|
||||
|
||||
if (DocumentsContract.Document.MIME_TYPE_DIR == mimeType) {
|
||||
val dirTreeUri = DocumentsContract.buildTreeDocumentUri(rootUri.authority, documentId)
|
||||
foldersToVisit.add(dirTreeUri)
|
||||
} else {
|
||||
val extension = displayName.substringAfterLast('.', "").lowercase()
|
||||
if (extension in allowedExtensions) {
|
||||
wallpapers.add(
|
||||
Wallpaper(
|
||||
initialAlbumName = "",
|
||||
wallpaperUri = documentUri.toString().compress("content://com.android.externalstorage.documents/"),
|
||||
fileName = displayName.substringBeforeLast('.', displayName),
|
||||
dateModified = dateModified,
|
||||
order = wallpapers.size,
|
||||
key = 0
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
val folderDocumentFile = DocumentFile.fromTreeUri(context, folderUri.toUri())
|
||||
return listFilesRecursive(folderDocumentFile, context)
|
||||
Log.e("WallpaperUtil", "Error getting wallpapers from folder '$folderUri': ", e)
|
||||
return@withContext emptyList<Wallpaper>()
|
||||
}
|
||||
|
||||
return@withContext wallpapers
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ->
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the folder name from the folder URI
|
||||
*/
|
||||
fun getFolderNameFromUri(folderUri: String, context: Context): String? {
|
||||
return try {
|
||||
DocumentFileCompat.fromTreeUri(context, folderUri.toUri())?.name
|
||||
suspend fun getFolderMetadata(folderUri: String, context: Context): Metadata = withContext(Dispatchers.IO) {
|
||||
if (folderUri.isEmpty()) return@withContext Metadata("", 0)
|
||||
return@withContext try {
|
||||
val uri = folderUri.toUri()
|
||||
val file = DocumentFileCompat.fromTreeUri(context, uri)
|
||||
val name = file?.name?.substringBeforeLast('.', file.name) ?: ""
|
||||
val lastModified = file?.lastModified ?: 0
|
||||
Metadata(name, lastModified)
|
||||
} catch (e: Exception) {
|
||||
DocumentFile.fromTreeUri(context, folderUri.toUri())?.name
|
||||
Log.w("WallpaperUtil", "Error getting folder metadata with DocumentFileCompat for '$folderUri': $e, trying DocumentFile")
|
||||
try {
|
||||
val uri = folderUri.toUri()
|
||||
val file = DocumentFile.fromTreeUri(context, uri)
|
||||
val name = file?.name?.substringBeforeLast('.', file.name.orEmpty()) ?: ""
|
||||
val lastModified = file?.lastModified() ?: 0
|
||||
Metadata(name, lastModified)
|
||||
} catch (e2: Exception) {
|
||||
Log.e("WallpaperUtil", "Error getting folder metadata with DocumentFile for '$folderUri': $e2")
|
||||
Metadata("", 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filename and last modified date from an image URI
|
||||
* @param context Android context
|
||||
* @param uriString URI string of the image
|
||||
*/
|
||||
suspend fun getImageMetadata(context: Context, uriString: String): Metadata = withContext(Dispatchers.IO) {
|
||||
if (uriString.isEmpty()) return@withContext Metadata("", 0)
|
||||
return@withContext try {
|
||||
val uri = uriString.toUri()
|
||||
val file = DocumentFileCompat.fromSingleUri(context, uri)
|
||||
val name = file?.name?.substringBeforeLast('.', file.name) ?: ""
|
||||
val lastModified = file?.lastModified ?: 0
|
||||
Metadata(name, lastModified)
|
||||
} catch (e: Exception) {
|
||||
Log.w("WallpaperUtil", "Error getting image metadata with DocumentFileCompat for '$uriString': $e, trying DocumentFile")
|
||||
try {
|
||||
val uri = uriString.toUri()
|
||||
val file = DocumentFile.fromSingleUri(context, uri)
|
||||
val name = file?.name?.substringBeforeLast('.', file.name.orEmpty()) ?: ""
|
||||
val lastModified = file?.lastModified() ?: 0
|
||||
Metadata(name, lastModified)
|
||||
} catch (e2: Exception) {
|
||||
Log.e("WallpaperUtil", "Error getting image metadata with DocumentFile for '$uriString': $e2")
|
||||
Metadata("", 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to find the first valid URI from a list of wallpapers and folders
|
||||
*/
|
||||
suspend fun findFirstValidUri(
|
||||
context: Context,
|
||||
folders: List<Folder>,
|
||||
wallpapers: List<Wallpaper>
|
||||
): String? = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
for (folder in folders) {
|
||||
for (wallpaper in folder.wallpapers) {
|
||||
try {
|
||||
if (isValidUri(context, wallpaper.wallpaperUri)) {
|
||||
return@withContext wallpaper.wallpaperUri
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w("WallpaperUtil", "Error checking URI validity for folder wallpaper: ${wallpaper.wallpaperUri}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
for (wallpaper in wallpapers) {
|
||||
try {
|
||||
if (isValidUri(context, wallpaper.wallpaperUri)) {
|
||||
return@withContext wallpaper.wallpaperUri
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w("WallpaperUtil", "Error checking URI validity for standalone wallpaper: ${wallpaper.wallpaperUri}", e)
|
||||
}
|
||||
}
|
||||
return@withContext null
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error finding valid URI", e)
|
||||
return@withContext null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,13 +559,155 @@ fun getFolderNameFromUri(folderUri: String, context: Context): String? {
|
||||
* Check if a URI is valid
|
||||
*/
|
||||
fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.toUri()
|
||||
if (uriString.isNullOrEmpty()) return false
|
||||
val decompressedUriString = try {
|
||||
uriString.decompress("content://com.android.externalstorage.documents/")
|
||||
} catch (e: Exception) {
|
||||
Log.w("WallpaperUtil", "Failed to decompress URI string: $uriString", e)
|
||||
uriString
|
||||
}
|
||||
val uri = decompressedUriString.toUri()
|
||||
|
||||
return try {
|
||||
uri?.let {
|
||||
val inputStream = context.contentResolver.openInputStream(it)
|
||||
inputStream?.close()
|
||||
DocumentFileCompat.fromSingleUri(context, uri)?.exists() == true
|
||||
} catch (e: Exception) {
|
||||
Log.w("WallpaperUtil", "Error checking URI validity with DocumentFileCompat for '$uri': $e, trying DocumentFile")
|
||||
try {
|
||||
DocumentFile.fromSingleUri(context, uri)?.exists() == true
|
||||
} catch (e2: Exception) {
|
||||
Log.w("WallpaperUtil", "Error checking URI validity with DocumentFile for '$uri': $e2")
|
||||
false
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a URI is a directory
|
||||
*/
|
||||
fun isDirectory(context: Context, uriString: String?): Boolean {
|
||||
if (uriString.isNullOrEmpty()) return false
|
||||
val uri = uriString.toUri()
|
||||
return try {
|
||||
DocumentFile.fromSingleUri(context, uri)?.isDirectory == true
|
||||
} catch (e: Exception) {
|
||||
Log.w("WallpaperUtil", "Error checking if URI is a directory for '$uri': $e")
|
||||
try {
|
||||
DocumentFile.fromTreeUri(context, uri)?.isDirectory == true
|
||||
} catch (e2: Exception) {
|
||||
Log.w("WallpaperUtil", "Error checking tree URI directory status for '$uri': $e2")
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress a string
|
||||
*/
|
||||
fun String.compress(prefixToRemove: String, charset: Charset = Charsets.UTF_8): String {
|
||||
val modifiedInput = if (this.startsWith(prefixToRemove)) {
|
||||
this.substring(prefixToRemove.length)
|
||||
} else { this }
|
||||
ByteArrayOutputStream().use { byteStream ->
|
||||
DeflaterOutputStream(byteStream).use { deflaterStream ->
|
||||
deflaterStream.write(modifiedInput.toByteArray(charset))
|
||||
}
|
||||
return Base64.encodeToString(byteStream.toByteArray(), Base64.NO_WRAP)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decompress a string
|
||||
*/
|
||||
fun String.decompress(prefixToAdd: String, charset: Charset = Charsets.UTF_8): String {
|
||||
val compressedData = Base64.decode(this, Base64.NO_WRAP)
|
||||
ByteArrayInputStream(compressedData).use { byteStream ->
|
||||
InflaterInputStream(byteStream).use { inflaterStream ->
|
||||
val decompressedBytes = inflaterStream.readBytes()
|
||||
return prefixToAdd + String(decompressedBytes, charset)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Darkens the bitmap by the given percentage and returns it
|
||||
* 0 - lightest, 100 - darkest
|
||||
*/
|
||||
fun processBitmap(
|
||||
width: Int,
|
||||
height: Int,
|
||||
source: Bitmap,
|
||||
darken: Boolean,
|
||||
darkenPercent: Int,
|
||||
scaling: ScalingConstants,
|
||||
blur: Boolean,
|
||||
blurPercent: Int,
|
||||
vignette: Boolean,
|
||||
vignettePercent: Int,
|
||||
grayscale: Boolean,
|
||||
grayscalePercent: Int
|
||||
): Bitmap? {
|
||||
try {
|
||||
var processedBitmap = source
|
||||
|
||||
processedBitmap = when (scaling) {
|
||||
ScalingConstants.FILL -> fillBitmap(processedBitmap, width, height)
|
||||
ScalingConstants.FIT -> fitBitmap(processedBitmap, width, height)
|
||||
ScalingConstants.STRETCH -> stretchBitmap(processedBitmap, width, height)
|
||||
ScalingConstants.NONE -> processedBitmap
|
||||
}
|
||||
|
||||
if (!processedBitmap.isMutable && (darken || vignette || grayscale)) {
|
||||
Log.w("ProcessBitmap", "Bitmap became immutable before effects. Making a mutable copy.")
|
||||
processedBitmap = processedBitmap.copy(processedBitmap.config ?: Bitmap.Config.ARGB_8888, true)
|
||||
}
|
||||
|
||||
if (darken && darkenPercent > 0) {
|
||||
processedBitmap = darkenBitmap(processedBitmap, darkenPercent)
|
||||
}
|
||||
|
||||
if (blur && blurPercent > 0) {
|
||||
val blurred = blurBitmap(processedBitmap, blurPercent)
|
||||
processedBitmap = blurred
|
||||
if (!processedBitmap.isMutable && (vignette || grayscale)) {
|
||||
Log.w("ProcessBitmap", "Bitmap became immutable after blur. Making a mutable copy.")
|
||||
processedBitmap = processedBitmap.copy(processedBitmap.config ?: Bitmap.Config.ARGB_8888, true)
|
||||
}
|
||||
}
|
||||
|
||||
if (vignette && vignettePercent > 0) {
|
||||
processedBitmap = vignetteBitmap(processedBitmap, vignettePercent)
|
||||
}
|
||||
|
||||
if (grayscale && grayscalePercent > 0) {
|
||||
processedBitmap = grayBitmap(processedBitmap, grayscalePercent)
|
||||
}
|
||||
|
||||
return processedBitmap
|
||||
}
|
||||
catch (e: OutOfMemoryError) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error: Ran out of memory during bitmap processing. Attempting with smaller dimensions.", e)
|
||||
if (width / 2 > 0 && height / 2 > 0) {
|
||||
return processBitmap(
|
||||
width / 2,
|
||||
height / 2,
|
||||
source,
|
||||
darken,
|
||||
darkenPercent,
|
||||
scaling,
|
||||
blur,
|
||||
blurPercent,
|
||||
vignette,
|
||||
vignettePercent,
|
||||
grayscale,
|
||||
grayscalePercent
|
||||
)
|
||||
} else {
|
||||
Log.e("PaperizeWallpaperChanger", "Cannot reduce dimensions further for OOM recovery.")
|
||||
return null
|
||||
}
|
||||
}
|
||||
catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error processing bitmap", e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -3,14 +3,12 @@ package com.anthonyla.paperize.data
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.core.content.ContextCompat.startActivity
|
||||
|
||||
/**
|
||||
* Opens an email intent to contact the developer.
|
||||
*/
|
||||
@Composable
|
||||
fun Contact(context: Context) {
|
||||
fun SendContactIntent(context: Context) {
|
||||
val authorEmail = "anthonyyla.dev@gmail.com"
|
||||
val cc = ""
|
||||
val subject = "[Support] Paperize"
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.anthonyla.paperize.data.settings
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Interface for the data store that handles the settings for application
|
||||
*/
|
||||
@@ -10,8 +12,12 @@ interface SettingsDataStore {
|
||||
suspend fun getBoolean(key: String): Boolean?
|
||||
suspend fun getString(key: String): String?
|
||||
suspend fun getInt(key: String): Int?
|
||||
fun getBooleanFlow(key: String): Flow<Boolean?>
|
||||
fun getStringFlow(key: String): Flow<String?>
|
||||
fun getIntFlow(key: String): Flow<Int?>
|
||||
suspend fun deleteBoolean(key: String)
|
||||
suspend fun deleteString(key: String)
|
||||
suspend fun deleteInt(key: String)
|
||||
suspend fun clear(keys: List<String>)
|
||||
suspend fun clearPreferences()
|
||||
}
|
||||
@@ -5,14 +5,19 @@ import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.core.booleanPreferencesKey
|
||||
import androidx.datastore.preferences.core.edit
|
||||
import androidx.datastore.preferences.core.emptyPreferences
|
||||
import androidx.datastore.preferences.core.intPreferencesKey
|
||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||
import androidx.datastore.preferences.preferencesDataStore
|
||||
import com.anthonyla.paperize.core.SettingsConstants.SETTINGS_DATASTORE
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.first
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
private val Context.dataStore : DataStore<Preferences> by preferencesDataStore(name = SETTINGS_DATASTORE)
|
||||
class SettingsDataStoreImpl @Inject constructor (private val context: Context): SettingsDataStore {
|
||||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = SETTINGS_DATASTORE)
|
||||
|
||||
class SettingsDataStoreImpl(private val context: Context) : SettingsDataStore {
|
||||
override suspend fun putBoolean(key: String, value: Boolean) {
|
||||
val preferencesKey = booleanPreferencesKey(key)
|
||||
context.dataStore.edit {
|
||||
@@ -28,9 +33,9 @@ class SettingsDataStoreImpl @Inject constructor (private val context: Context):
|
||||
}
|
||||
|
||||
override suspend fun putInt(key: String, value: Int) {
|
||||
val preferencesKey = stringPreferencesKey(key)
|
||||
val preferencesKey = intPreferencesKey(key)
|
||||
context.dataStore.edit {
|
||||
it[preferencesKey] = value.toString()
|
||||
it[preferencesKey] = value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +59,7 @@ class SettingsDataStoreImpl @Inject constructor (private val context: Context):
|
||||
override suspend fun getInt(key: String): Int? {
|
||||
return try {
|
||||
val head = context.dataStore.data.first()
|
||||
val preferencesKey = stringPreferencesKey(key)
|
||||
val preferencesKey = intPreferencesKey(key)
|
||||
head[preferencesKey]?.toInt()
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
@@ -62,6 +67,33 @@ class SettingsDataStoreImpl @Inject constructor (private val context: Context):
|
||||
}
|
||||
}
|
||||
|
||||
override fun getBooleanFlow(key: String): Flow<Boolean?> = context.dataStore.data
|
||||
.catch { exception ->
|
||||
exception.printStackTrace()
|
||||
emit(emptyPreferences())
|
||||
}
|
||||
.map { preferences ->
|
||||
preferences[booleanPreferencesKey(key)]
|
||||
}
|
||||
|
||||
override fun getStringFlow(key: String): Flow<String?> = context.dataStore.data
|
||||
.catch { exception ->
|
||||
exception.printStackTrace()
|
||||
emit(emptyPreferences())
|
||||
}
|
||||
.map { preferences ->
|
||||
preferences[stringPreferencesKey(key)]
|
||||
}
|
||||
|
||||
override fun getIntFlow(key: String): Flow<Int?> = context.dataStore.data
|
||||
.catch { exception ->
|
||||
exception.printStackTrace()
|
||||
emit(emptyPreferences())
|
||||
}
|
||||
.map { preferences ->
|
||||
preferences[intPreferencesKey(key)]
|
||||
}
|
||||
|
||||
override suspend fun deleteBoolean(key: String) {
|
||||
val preferencesKey = booleanPreferencesKey(key)
|
||||
context.dataStore.edit {
|
||||
@@ -81,7 +113,7 @@ class SettingsDataStoreImpl @Inject constructor (private val context: Context):
|
||||
}
|
||||
|
||||
override suspend fun deleteInt(key: String) {
|
||||
val preferencesKey = stringPreferencesKey(key)
|
||||
val preferencesKey = intPreferencesKey(key)
|
||||
context.dataStore.edit {
|
||||
if (it.contains(preferencesKey)) {
|
||||
it.remove(preferencesKey)
|
||||
@@ -94,4 +126,20 @@ class SettingsDataStoreImpl @Inject constructor (private val context: Context):
|
||||
it.clear()
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun clear(keys: List<String>) {
|
||||
context.dataStore.edit { preferences ->
|
||||
keys.forEach { key ->
|
||||
if (preferences.contains(booleanPreferencesKey(key))) {
|
||||
preferences.remove(booleanPreferencesKey(key))
|
||||
}
|
||||
else if (preferences.contains(stringPreferencesKey(key))) {
|
||||
preferences.remove(stringPreferencesKey(key))
|
||||
}
|
||||
else if (preferences.contains(intPreferencesKey(key))) {
|
||||
preferences.remove(intPreferencesKey(key))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,8 @@ import androidx.room.Room
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStoreImpl
|
||||
import com.anthonyla.paperize.feature.wallpaper.data.data_source.AlbumDatabase
|
||||
import com.anthonyla.paperize.feature.wallpaper.data.data_source.SelectedAlbumDatabase
|
||||
import com.anthonyla.paperize.feature.wallpaper.data.repository.AlbumRepositoryImpl
|
||||
import com.anthonyla.paperize.feature.wallpaper.data.repository.SelectedAlbumRepositoryImpl
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.SelectedAlbumRepository
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
@@ -28,20 +25,10 @@ object AppModule {
|
||||
@Singleton
|
||||
fun provideAlbumDatabase(app: Application): AlbumDatabase {
|
||||
return Room.databaseBuilder(
|
||||
app,
|
||||
AlbumDatabase::class.java,
|
||||
AlbumDatabase.DATABASE_NAME
|
||||
).fallbackToDestructiveMigration().addMigrations().build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSelectedAlbumDatabase(app: Application): SelectedAlbumDatabase {
|
||||
return Room.databaseBuilder(
|
||||
app,
|
||||
SelectedAlbumDatabase::class.java,
|
||||
SelectedAlbumDatabase.DATABASE_NAME
|
||||
).fallbackToDestructiveMigration().addMigrations().build()
|
||||
app,
|
||||
AlbumDatabase::class.java,
|
||||
AlbumDatabase.DATABASE_NAME
|
||||
).fallbackToDestructiveMigration(true).addMigrations().build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@@ -56,18 +43,6 @@ object AppModule {
|
||||
return AlbumRepositoryImpl(db.albumDao)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSelectedAlbumDao(db: SelectedAlbumDatabase) = db.selectedAlbumDao
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSelectedAlbumRepository(
|
||||
db: SelectedAlbumDatabase
|
||||
): SelectedAlbumRepository {
|
||||
return SelectedAlbumRepositoryImpl(db.selectedAlbumDao)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSettingsDataStore (
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.app_shortcut
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperBootAndChangeReceiver
|
||||
|
||||
class BroadcastActivity : Activity() {
|
||||
companion object {
|
||||
const val ACTION_CUSTOM_BROADCAST = "com.anthonyla.paperize.SHORTCUT"
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val intent = Intent(ACTION_CUSTOM_BROADCAST).apply {
|
||||
setClass(this@BroadcastActivity, WallpaperBootAndChangeReceiver::class.java)
|
||||
addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
|
||||
}
|
||||
sendBroadcast(intent)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -18,11 +18,20 @@ import kotlinx.coroutines.flow.Flow
|
||||
*/
|
||||
@Dao
|
||||
interface AlbumDao {
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM album")
|
||||
fun getAlbumsWithWallpaperAndFolder(): Flow<List<AlbumWithWallpaperAndFolder>>
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM album WHERE selected = 1")
|
||||
fun getSelectedAlbums(): Flow<List<AlbumWithWallpaperAndFolder>>
|
||||
|
||||
@Query("UPDATE album SET selected = :selected WHERE initialAlbumName = :albumName")
|
||||
suspend fun updateAlbumSelection(albumName: String, selected: Boolean)
|
||||
|
||||
@Query("UPDATE album SET selected = 0")
|
||||
suspend fun deselectAllAlbums()
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsertAlbum(album: Album)
|
||||
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
*/
|
||||
@Database(
|
||||
entities = [Album::class, Wallpaper::class, Folder::class],
|
||||
version = 4
|
||||
version = 11
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class AlbumDatabase: RoomDatabase() {
|
||||
|
||||
+16
-1
@@ -1,7 +1,9 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.data.data_source
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
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
|
||||
@@ -19,5 +21,18 @@ class Converters {
|
||||
* Convert json string to list of strings
|
||||
*/
|
||||
@TypeConverter
|
||||
fun jsonStringToList(value: String) = gson.fromJson(value, Array<String>::class.java).toList()
|
||||
fun jsonStringToList(value: String?): List<String> {
|
||||
if (value == null) return emptyList()
|
||||
return gson.fromJson(value, Array<String>::class.java).toList()
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun fromWallpaperList(value: List<Wallpaper>): String? = gson.toJson(value)
|
||||
|
||||
@TypeConverter
|
||||
fun toWallpaperList(value: String?): List<Wallpaper> {
|
||||
if (value == null) return emptyList()
|
||||
val listType = object : TypeToken<List<Wallpaper>>() {}.type
|
||||
return gson.fromJson(value, listType)
|
||||
}
|
||||
}
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.data.data_source
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.Transaction
|
||||
import androidx.room.Update
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Data Access Object for selected album for application to keep track of which album is currently selected for changing wallpapers from
|
||||
*/
|
||||
@Dao
|
||||
interface SelectedAlbumDao {
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM album")
|
||||
fun getSelectedAlbum(): Flow<List<SelectedAlbum>>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsertAlbum(album: Album)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsertWallpaper(wallpaper: Wallpaper)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsertWallpaperList(wallpapers: List<Wallpaper>)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteAlbum(album: Album)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteWallpaper(wallpaper: Wallpaper)
|
||||
|
||||
@Query("DELETE FROM wallpaper WHERE initialAlbumName=:initialAlbumName")
|
||||
suspend fun cascadeDeleteWallpaper(initialAlbumName: String)
|
||||
|
||||
@Query("DELETE FROM album")
|
||||
suspend fun deleteAllAlbums()
|
||||
|
||||
@Query("DELETE FROM wallpaper")
|
||||
suspend fun deleteAllWallpapers()
|
||||
|
||||
@Update
|
||||
suspend fun updateAlbum(album: Album)
|
||||
|
||||
@Transaction
|
||||
suspend fun deleteAll() {
|
||||
deleteAllAlbums()
|
||||
deleteAllWallpapers()
|
||||
}
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.data.data_source
|
||||
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
|
||||
/**
|
||||
* Database for selected album
|
||||
* Stores [Album] and [Wallpaper] inside SelectedAlbum
|
||||
*/
|
||||
@Database(
|
||||
entities = [Album::class, Wallpaper::class],
|
||||
version = 4
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class SelectedAlbumDatabase: RoomDatabase() {
|
||||
abstract val selectedAlbumDao: SelectedAlbumDao
|
||||
companion object {
|
||||
const val DATABASE_NAME = "paperize_selectedAlbum_db"
|
||||
}
|
||||
}
|
||||
+95
-24
@@ -6,88 +6,159 @@ import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperA
|
||||
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 kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class AlbumRepositoryImpl(
|
||||
private val dao: AlbumDao
|
||||
private val dao: AlbumDao,
|
||||
private val dispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||
): AlbumRepository {
|
||||
override fun getAlbumsWithWallpaperAndFolder(): Flow<List<AlbumWithWallpaperAndFolder>> {
|
||||
return dao.getAlbumsWithWallpaperAndFolder()
|
||||
return dao.getAlbumsWithWallpaperAndFolder().map { albumWithWallpaperAndFolderList ->
|
||||
albumWithWallpaperAndFolderList.map {
|
||||
it.copy(
|
||||
wallpapers = it.sortedWallpapers,
|
||||
folders = it.sortedFolders,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSelectedAlbums(): Flow<List<AlbumWithWallpaperAndFolder>> {
|
||||
return dao.getSelectedAlbums().map { albumWithWallpaperAndFolderList ->
|
||||
albumWithWallpaperAndFolderList.map {
|
||||
it.copy(
|
||||
wallpapers = it.sortedWallpapers,
|
||||
folders = it.sortedFolders,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun upsertAlbumWithWallpaperAndFolder(albumWithWallpaperAndFolder: AlbumWithWallpaperAndFolder) {
|
||||
dao.upsertAlbum(albumWithWallpaperAndFolder.album)
|
||||
dao.upsertWallpaperList(albumWithWallpaperAndFolder.wallpapers)
|
||||
dao.upsertFolderList(albumWithWallpaperAndFolder.folders)
|
||||
withContext(dispatcher) {
|
||||
dao.upsertAlbum(albumWithWallpaperAndFolder.album)
|
||||
dao.upsertWallpaperList(albumWithWallpaperAndFolder.wallpapers)
|
||||
dao.upsertFolderList(albumWithWallpaperAndFolder.folders)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updateAlbumSelection(albumName: String, selected: Boolean) {
|
||||
withContext(dispatcher) {
|
||||
dao.updateAlbumSelection(albumName, selected)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deselectAllAlbums() {
|
||||
withContext(dispatcher) {
|
||||
dao.deselectAllAlbums()
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun upsertAlbum(album: Album) {
|
||||
dao.upsertAlbum(album)
|
||||
withContext(dispatcher) {
|
||||
dao.upsertAlbum(album)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun upsertWallpaper(wallpaper: Wallpaper) {
|
||||
dao.upsertWallpaper(wallpaper)
|
||||
withContext(dispatcher) {
|
||||
dao.upsertWallpaper(wallpaper)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun upsertFolder(folder: Folder) {
|
||||
dao.upsertFolder(folder)
|
||||
withContext(dispatcher) {
|
||||
dao.upsertFolder(folder)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun upsertFolderList(folders: List<Folder>) {
|
||||
dao.upsertFolderList(folders)
|
||||
withContext(dispatcher) {
|
||||
dao.upsertFolderList(folders)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun upsertWallpaperList(wallpapers: List<Wallpaper>) {
|
||||
dao.upsertWallpaperList(wallpapers)
|
||||
withContext(dispatcher) {
|
||||
dao.upsertWallpaperList(wallpapers)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteAlbum(album: Album) {
|
||||
dao.deleteAlbum(album)
|
||||
withContext(dispatcher) {
|
||||
dao.deleteAlbum(album)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteWallpaper(wallpaper: Wallpaper) {
|
||||
dao.deleteWallpaper(wallpaper)
|
||||
withContext(dispatcher) {
|
||||
dao.deleteWallpaper(wallpaper)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteFolder(folder: Folder) {
|
||||
dao.deleteFolder(folder)
|
||||
withContext(dispatcher) {
|
||||
dao.deleteFolder(folder)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updateAlbum(album: Album) {
|
||||
dao.updateAlbum(album)
|
||||
withContext(dispatcher) {
|
||||
dao.updateAlbum(album)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updateFolder(folder: Folder) {
|
||||
dao.updateFolder(folder)
|
||||
withContext(dispatcher) {
|
||||
dao.updateFolder(folder)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updateWallpaper(wallpaper: Wallpaper) {
|
||||
dao.updateWallpaper(wallpaper)
|
||||
withContext(dispatcher) {
|
||||
dao.updateWallpaper(wallpaper)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun cascadeDeleteAlbum(album: Album) {
|
||||
dao.deleteAlbum(album)
|
||||
dao.cascadeDeleteWallpaper(album.initialAlbumName)
|
||||
dao.cascadeDeleteFolder(album.initialAlbumName)
|
||||
withContext(dispatcher) {
|
||||
dao.deleteAlbum(album)
|
||||
dao.cascadeDeleteWallpaper(album.initialAlbumName)
|
||||
dao.cascadeDeleteFolder(album.initialAlbumName)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun cascadeDeleteFolder(initialAlbumName: String) {
|
||||
dao.cascadeDeleteFolder(initialAlbumName)
|
||||
withContext(dispatcher) {
|
||||
dao.cascadeDeleteFolder(initialAlbumName)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun cascadeDeleteWallpaper(initialAlbumName: String) {
|
||||
dao.cascadeDeleteWallpaper(initialAlbumName)
|
||||
withContext(dispatcher) {
|
||||
dao.cascadeDeleteWallpaper(initialAlbumName)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteFolderList(folders: List<Folder>) {
|
||||
dao.deleteFolderList(folders)
|
||||
withContext(dispatcher) {
|
||||
dao.deleteFolderList(folders)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteWallpaperList(wallpapers: List<Wallpaper>) {
|
||||
dao.deleteWallpaperList(wallpapers)
|
||||
withContext(dispatcher) {
|
||||
dao.deleteWallpaperList(wallpapers)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteAllData() {
|
||||
dao.deleteAllData()
|
||||
withContext(dispatcher) {
|
||||
dao.deleteAllData()
|
||||
}
|
||||
}
|
||||
}
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
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.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.SelectedAlbumRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class SelectedAlbumRepositoryImpl(
|
||||
private val dao: SelectedAlbumDao
|
||||
): SelectedAlbumRepository {
|
||||
override fun getSelectedAlbum(): Flow<List<SelectedAlbum>> {
|
||||
return dao.getSelectedAlbum()
|
||||
}
|
||||
|
||||
override suspend fun upsertSelectedAlbum(selectedAlbum: SelectedAlbum) {
|
||||
dao.deleteAll()
|
||||
dao.upsertAlbum(selectedAlbum.album)
|
||||
dao.upsertWallpaperList(selectedAlbum.wallpapers)
|
||||
}
|
||||
|
||||
override suspend fun upsertAlbum(album: Album) {
|
||||
dao.upsertAlbum(album)
|
||||
}
|
||||
|
||||
override suspend fun upsertWallpaper(wallpaper: Wallpaper) {
|
||||
dao.upsertWallpaper(wallpaper)
|
||||
}
|
||||
|
||||
override suspend fun upsertWallpaperList(wallpapers: List<Wallpaper>) {
|
||||
dao.upsertWallpaperList(wallpapers)
|
||||
}
|
||||
|
||||
override suspend fun updateAlbum(album: Album) {
|
||||
dao.updateAlbum(album)
|
||||
}
|
||||
|
||||
override suspend fun deleteAlbum(album: Album) {
|
||||
dao.deleteAlbum(album)
|
||||
}
|
||||
|
||||
override suspend fun deleteWallpaper(wallpaper: Wallpaper) {
|
||||
dao.deleteWallpaper(wallpaper)
|
||||
}
|
||||
|
||||
override suspend fun cascadeDeleteWallpaper(initialAlbumName: String) {
|
||||
dao.cascadeDeleteWallpaper(initialAlbumName)
|
||||
}
|
||||
override suspend fun deleteAll() {
|
||||
dao.deleteAll()
|
||||
}
|
||||
}
|
||||
@@ -9,20 +9,16 @@ import androidx.room.PrimaryKey
|
||||
* @param initialAlbumName The initial album name -- should not be changed as it is used as the key for database queries
|
||||
* @param displayedAlbumName The displayed album name
|
||||
* @param coverUri The cover uri of the album
|
||||
* @param initialized Whether the album has been initialized
|
||||
* @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
|
||||
* @param homeWallpapersInQueue The list of home wallpapers in the queue
|
||||
* @param lockWallpapersInQueue The list of lock wallpapers in the queue
|
||||
* @param selected Whether the album is selected
|
||||
*/
|
||||
@Entity
|
||||
data class Album(
|
||||
@PrimaryKey(autoGenerate = false) val initialAlbumName: String,
|
||||
val displayedAlbumName: String,
|
||||
val coverUri: String?,
|
||||
val initialized: Boolean = false,
|
||||
val homeWallpapersInQueue: List<String> = emptyList(),
|
||||
val lockWallpapersInQueue: List<String> = emptyList(),
|
||||
val currentHomeWallpaper: String? = null,
|
||||
val currentLockWallpaper: String? = null
|
||||
val selected : Boolean = false
|
||||
)
|
||||
+15
-2
@@ -8,17 +8,30 @@ import androidx.room.Relation
|
||||
* @param album The album.
|
||||
* @param wallpapers The wallpapers.
|
||||
* @param folders The folders.
|
||||
*/
|
||||
* */
|
||||
data class AlbumWithWallpaperAndFolder(
|
||||
@Embedded val album: Album,
|
||||
@Relation(
|
||||
parentColumn = "initialAlbumName",
|
||||
entityColumn = "initialAlbumName",
|
||||
entity = Wallpaper::class,
|
||||
)
|
||||
val wallpapers: List<Wallpaper> = emptyList(),
|
||||
@Relation(
|
||||
parentColumn = "initialAlbumName",
|
||||
entityColumn = "initialAlbumName",
|
||||
entity = Folder::class
|
||||
)
|
||||
val folders: List<Folder> = emptyList(),
|
||||
)
|
||||
) {
|
||||
val totalWallpapers: List<Wallpaper>
|
||||
get() = folders.flatMap { it.wallpapers } + wallpapers
|
||||
val sortedFolders: List<Folder>
|
||||
get() = folders.map { folder ->
|
||||
folder.copy(wallpapers = folder.wallpapers.sortedBy { it.order })
|
||||
}.sortedBy { it.order }
|
||||
val sortedWallpapers: List<Wallpaper>
|
||||
get() = wallpapers.sortedBy { it.order }
|
||||
val sortedTotalWallpapers: List<Wallpaper>
|
||||
get() = (folders.flatMap { it.wallpapers } + wallpapers).sortedBy { it.order }
|
||||
}
|
||||
@@ -4,20 +4,24 @@ import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
/**
|
||||
* Represents a folder directory containing wallpapers.
|
||||
* Represents a folder directory containing wallpapers
|
||||
*
|
||||
* @param initialAlbumName The initial album name.
|
||||
* @param folderName The folder name.
|
||||
* @param coverUri The cover URI.
|
||||
* @param wallpapers The list of wallpaper URI strings in the folder.
|
||||
* @param folderUri The folder directory URI.
|
||||
* @param initialAlbumName The initial album name
|
||||
* @param folderName The folder name
|
||||
* @param folderUri The folder directory URI
|
||||
* @param coverUri The cover URI
|
||||
* @param dateModified The date modified of the folder
|
||||
* @param wallpapers The list of wallpaper URI strings in the folder
|
||||
* @param order The order of the folder
|
||||
*/
|
||||
@Entity
|
||||
data class Folder(
|
||||
val initialAlbumName: String,
|
||||
val folderName: String?,
|
||||
val coverUri: String?,
|
||||
val wallpapers: List<String> = emptyList(),
|
||||
val folderUri: String,
|
||||
val coverUri: String?,
|
||||
val dateModified: Long,
|
||||
val wallpapers: List<Wallpaper> = emptyList(),
|
||||
val order: Int,
|
||||
@PrimaryKey(autoGenerate = false) val key: Int
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.domain.model
|
||||
|
||||
data class Metadata(
|
||||
val filename: String,
|
||||
val lastModified: Long
|
||||
)
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.domain.model
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Relation
|
||||
|
||||
/**
|
||||
* Data class that represents a selected album with its wallpapers.
|
||||
* @param album the selected album.
|
||||
* @param wallpapers the wallpapers of the selected album. Includes the wallpapers from each folders in album.
|
||||
*/
|
||||
data class SelectedAlbum(
|
||||
@Embedded val album: Album,
|
||||
@Relation(
|
||||
parentColumn = "initialAlbumName",
|
||||
entityColumn = "initialAlbumName",
|
||||
)
|
||||
val wallpapers: List<Wallpaper> = emptyList(),
|
||||
)
|
||||
+8
-3
@@ -4,14 +4,19 @@ import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
/**
|
||||
* Represents a wallpaper object.
|
||||
* Represents a wallpaper object
|
||||
*
|
||||
* @param initialAlbumName The name of the album the wallpaper belongs to.
|
||||
* @param wallpaperUri The URI of the wallpaper.
|
||||
* @param initialAlbumName The name of the album the wallpaper belongs to
|
||||
* @param wallpaperUri The URI of the wallpaper
|
||||
* @param fileName The name of the file
|
||||
* @param dateModified The date the wallpaper was last modified
|
||||
*/
|
||||
@Entity
|
||||
data class Wallpaper(
|
||||
val initialAlbumName: String,
|
||||
val wallpaperUri: String,
|
||||
val fileName: String,
|
||||
val dateModified: Long,
|
||||
val order: Int,
|
||||
@PrimaryKey(autoGenerate = false) val key: Int
|
||||
)
|
||||
+15
@@ -12,6 +12,21 @@ interface AlbumRepository {
|
||||
*/
|
||||
fun getAlbumsWithWallpaperAndFolder(): Flow<List<AlbumWithWallpaperAndFolder>>
|
||||
|
||||
/**
|
||||
* Get all selected albums with wallpaper and folder
|
||||
*/
|
||||
fun getSelectedAlbums(): Flow<List<AlbumWithWallpaperAndFolder>>
|
||||
|
||||
/**
|
||||
* Update album selection
|
||||
*/
|
||||
suspend fun updateAlbumSelection(albumName: String, selected: Boolean)
|
||||
|
||||
/**
|
||||
* Deselect all albums
|
||||
*/
|
||||
suspend fun deselectAllAlbums()
|
||||
|
||||
/**
|
||||
* Insert or update album with wallpaper and folder
|
||||
*/
|
||||
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.domain.repository
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface SelectedAlbumRepository {
|
||||
/**
|
||||
* Get selected album from database
|
||||
*/
|
||||
fun getSelectedAlbum(): Flow<List<SelectedAlbum>>
|
||||
|
||||
/**
|
||||
* Upsert or insert selectedAlbum to database with its wallpapers
|
||||
*/
|
||||
suspend fun upsertSelectedAlbum(selectedAlbum: SelectedAlbum)
|
||||
|
||||
/**
|
||||
* Upsert or insert album to database
|
||||
*/
|
||||
suspend fun upsertAlbum(album: Album)
|
||||
|
||||
/**
|
||||
* Upsert or insert wallpaper to database
|
||||
*/
|
||||
suspend fun updateAlbum(album: Album)
|
||||
|
||||
/**
|
||||
* Delete album from database
|
||||
*/
|
||||
suspend fun deleteAlbum(album: Album)
|
||||
|
||||
/**
|
||||
* Upsert or insert wallpaper to database
|
||||
*/
|
||||
suspend fun upsertWallpaper(wallpaper: Wallpaper)
|
||||
|
||||
/**
|
||||
* Upsert or insert list of wallpapers to database
|
||||
|
||||
*/
|
||||
suspend fun upsertWallpaperList(wallpapers: List<Wallpaper>)
|
||||
|
||||
/**
|
||||
* Delete wallpaper from database
|
||||
*/
|
||||
suspend fun deleteWallpaper(wallpaper: Wallpaper)
|
||||
|
||||
/**
|
||||
* Delete all wallpapers and folders from database
|
||||
*/
|
||||
suspend fun cascadeDeleteWallpaper(initialAlbumName: String)
|
||||
|
||||
/**
|
||||
* Delete all data from database
|
||||
*/
|
||||
suspend fun deleteAll()
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.glance_widget
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.glance.GlanceId
|
||||
import androidx.glance.GlanceModifier
|
||||
import androidx.glance.Image
|
||||
import androidx.glance.ImageProvider
|
||||
import androidx.glance.action.clickable
|
||||
import androidx.glance.appwidget.GlanceAppWidget
|
||||
import androidx.glance.appwidget.provideContent
|
||||
import androidx.glance.layout.Box
|
||||
import androidx.glance.layout.ContentScale
|
||||
import androidx.glance.layout.fillMaxSize
|
||||
import com.anthonyla.paperize.R
|
||||
import androidx.glance.ColorFilter
|
||||
import androidx.glance.GlanceTheme
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperBootAndChangeReceiver
|
||||
|
||||
class PaperizeWidget : GlanceAppWidget() {
|
||||
override suspend fun provideGlance(context: Context, id: GlanceId) {
|
||||
provideContent {
|
||||
WidgetContent(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun WidgetContent(context: Context) {
|
||||
val ACTION_CHANGE_WALLPAPER = "com.anthonyla.paperize.SHORTCUT"
|
||||
Box(
|
||||
modifier = GlanceModifier
|
||||
.fillMaxSize()
|
||||
.clickable(
|
||||
{
|
||||
|
||||
val intent = Intent(ACTION_CHANGE_WALLPAPER).apply {
|
||||
setClass(context, WallpaperBootAndChangeReceiver::class.java)
|
||||
addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
|
||||
}
|
||||
context.sendBroadcast(intent)
|
||||
}
|
||||
)
|
||||
) {
|
||||
Image(
|
||||
provider = ImageProvider(R.drawable.next_wallpaper_icon),
|
||||
contentDescription = "Paperize Widget",
|
||||
modifier = GlanceModifier.fillMaxSize(),
|
||||
contentScale = ContentScale.Fit,
|
||||
colorFilter = ColorFilter.tint(GlanceTheme.colors.primaryContainer)
|
||||
)
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.glance_widget
|
||||
import androidx.glance.appwidget.GlanceAppWidget
|
||||
import androidx.glance.appwidget.GlanceAppWidgetReceiver
|
||||
|
||||
class PaperizeWidgetReceiver : GlanceAppWidgetReceiver() {
|
||||
override val glanceAppWidget: GlanceAppWidget = PaperizeWidget()
|
||||
}
|
||||
+157
-71
@@ -2,9 +2,10 @@ package com.anthonyla.paperize.feature.wallpaper.presentation
|
||||
|
||||
import android.Manifest
|
||||
import android.animation.ObjectAnimator
|
||||
import android.app.Activity
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Color
|
||||
@@ -17,56 +18,75 @@ import androidx.activity.ComponentActivity
|
||||
import androidx.activity.SystemBarStyle
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.viewModels
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.annotation.RequiresPermission
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
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.SettingsState
|
||||
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.WallpaperAlarmSchedulerImpl
|
||||
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
|
||||
|
||||
import androidx.core.net.toUri
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MainActivity : ComponentActivity() {
|
||||
private val albumsViewModel: AlbumsViewModel by viewModels()
|
||||
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)
|
||||
private val settingsViewModel: SettingsViewModel by viewModels()
|
||||
|
||||
// Launcher for SET_WALLPAPER permission
|
||||
private val requestSetWallpaperPermission = registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
) { isGranted: Boolean ->
|
||||
if (!isGranted) {
|
||||
// Handle the case where the user denies the permission.
|
||||
// For wallpaper apps, this permission is critical, so denying it
|
||||
// means the app won't function as intended.
|
||||
// Consider showing a dialog explaining why it's needed and
|
||||
// offering to open app settings.
|
||||
}
|
||||
}
|
||||
|
||||
// Launcher for SCHEDULE_EXACT_ALARM permission (Android 12+)
|
||||
private val requestExactAlarmPermission = registerForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) {
|
||||
// No specific action needed on result here, as we just want the permission granted.
|
||||
// The check `am.canScheduleExactAlarms()` will reflect the new state when needed.
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
enableEdgeToEdge(
|
||||
statusBarStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT),
|
||||
navigationBarStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT)
|
||||
)
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// Request SET_WALLPAPER permission immediately if not granted
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.SET_WALLPAPER) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestSetWallpaperPermission.launch(Manifest.permission.SET_WALLPAPER)
|
||||
}
|
||||
|
||||
val splashScreen = installSplashScreen()
|
||||
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) {
|
||||
@@ -81,76 +101,142 @@ class MainActivity : ComponentActivity() {
|
||||
splashScreen.setKeepOnScreenCondition { settingsViewModel.setKeepOnScreenCondition }
|
||||
|
||||
setContent {
|
||||
val scheduler = WallpaperScheduler(context)
|
||||
// Request SCHEDULE_EXACT_ALARM permission when the Composable is active.
|
||||
// This will prompt the user to grant the permission if not already granted.
|
||||
LaunchedEffect(Unit) {
|
||||
requestExactAlarmPermissionIfNeeded(this@MainActivity)
|
||||
}
|
||||
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
val isFirstLaunch = runBlocking { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) } ?: true
|
||||
if (isFirstLaunch) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
val scheduler = WallpaperAlarmSchedulerImpl(this)
|
||||
|
||||
var hasScheduleRun by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(settingsState.value) {
|
||||
// Only attempt to schedule once settings are initialized and the scheduling logic hasn't run yet.
|
||||
if (!hasScheduleRun && settingsState.value.initialized) {
|
||||
handleWallpaperScheduling(settingsState.value, scheduler)
|
||||
hasScheduleRun = true
|
||||
}
|
||||
}
|
||||
|
||||
PaperizeTheme(settingsState.value.darkMode, settingsState.value.dynamicTheming) {
|
||||
Surface(tonalElevation = 5.dp) {
|
||||
PaperizeApp(isFirstLaunch, scheduler, topInset)
|
||||
PaperizeTheme(
|
||||
darkMode = settingsState.value.themeSettings.darkMode,
|
||||
amoledMode = settingsState.value.themeSettings.amoledTheme,
|
||||
dynamicTheming = settingsState.value.themeSettings.dynamicTheming
|
||||
) {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
tonalElevation = 5.dp
|
||||
) {
|
||||
PaperizeApp(isFirstLaunch, scheduler)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
/**
|
||||
* Requests the SCHEDULE_EXACT_ALARM permission if needed on Android 12 (S) and above.
|
||||
* This function should be called from a LaunchedEffect or similar lifecycle-aware scope
|
||||
* within Compose, or directly in onCreate if you prefer.
|
||||
*/
|
||||
private fun requestExactAlarmPermissionIfNeeded(context: Context) {
|
||||
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)
|
||||
val am = context.getSystemService(ALARM_SERVICE) as AlarmManager
|
||||
if (!am.canScheduleExactAlarms()) {
|
||||
val intent = Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM).apply {
|
||||
data = "package:${context.packageName}".toUri()
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
requestExactAlarmPermission.launch(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
topInset = window.decorView.rootWindowInsets.stableInsetTop.dp
|
||||
@SuppressLint("MissingPermission")
|
||||
private suspend fun handleWallpaperScheduling(
|
||||
settings: SettingsState,
|
||||
scheduler: WallpaperAlarmSchedulerImpl
|
||||
) {
|
||||
val wallpaperSettings = settings.wallpaperSettings
|
||||
val scheduleSettings = settings.scheduleSettings
|
||||
|
||||
// If changer is not enabled, or essential album names are missing, disable changer and return.
|
||||
if (!wallpaperSettings.enableChanger || wallpaperSettings.homeAlbumName.isNullOrEmpty() || wallpaperSettings.lockAlbumName.isNullOrEmpty()) {
|
||||
if (wallpaperSettings.enableChanger) { // Only dispatch event if it was enabled
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Check if alarms are already set to avoid redundant scheduling
|
||||
val shouldScheduleAlarm = if (scheduleSettings.scheduleSeparately) {
|
||||
!(isPendingIntentSet(Type.HOME.ordinal) && isPendingIntentSet(Type.LOCK.ordinal))
|
||||
} else {
|
||||
!isPendingIntentSet(Type.SINGLE.ordinal)
|
||||
}
|
||||
|
||||
if (shouldScheduleAlarm) {
|
||||
val canScheduleExactAlarms = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val alarmManager = getSystemService(ALARM_SERVICE) as AlarmManager
|
||||
alarmManager.canScheduleExactAlarms()
|
||||
} else {
|
||||
true
|
||||
}
|
||||
|
||||
if (canScheduleExactAlarms) {
|
||||
scheduleWallpaperAlarm(settings, scheduler)
|
||||
} else {
|
||||
// Optionally prompt user to grant permission
|
||||
requestExactAlarmPermissionIfNeeded(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresPermission(Manifest.permission.SCHEDULE_EXACT_ALARM)
|
||||
private suspend fun scheduleWallpaperAlarm(
|
||||
settings: SettingsState,
|
||||
scheduler: WallpaperAlarmSchedulerImpl
|
||||
) {
|
||||
val scheduleSettings = settings.scheduleSettings
|
||||
val wallpaperSettings = settings.wallpaperSettings
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val am = getSystemService(ALARM_SERVICE) as AlarmManager
|
||||
if (!am.canScheduleExactAlarms()) {
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
scheduler.scheduleWallpaperAlarm(
|
||||
WallpaperAlarmItem(
|
||||
homeInterval = scheduleSettings.homeInterval,
|
||||
lockInterval = scheduleSettings.lockInterval,
|
||||
setLock = wallpaperSettings.setLockWallpaper,
|
||||
setHome = wallpaperSettings.setHomeWallpaper,
|
||||
scheduleSeparately = scheduleSettings.scheduleSeparately,
|
||||
changeStartTime = scheduleSettings.changeStartTime,
|
||||
startTime = scheduleSettings.startTime,
|
||||
),
|
||||
origin = null,
|
||||
changeImmediate = true,
|
||||
cancelImmediate = true,
|
||||
firstLaunch = true,
|
||||
homeNextTime = settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME),
|
||||
lockNextTime = settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME)
|
||||
)
|
||||
settingsViewModel.onEvent(SettingsEvent.RefreshNextSetTime)
|
||||
}
|
||||
|
||||
private fun isPendingIntentSet(requestCode: Int): Boolean {
|
||||
val intent = Intent(context.applicationContext, WallpaperReceiver::class.java)
|
||||
val intent = Intent(applicationContext, WallpaperReceiver::class.java)
|
||||
val pendingIntent = PendingIntent.getBroadcast(
|
||||
context.applicationContext,
|
||||
applicationContext,
|
||||
requestCode,
|
||||
intent,
|
||||
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_NO_CREATE
|
||||
)
|
||||
return pendingIntent != null
|
||||
}
|
||||
}
|
||||
}
|
||||
+582
-586
File diff suppressed because it is too large.
Load diff
+13
-8
@@ -1,17 +1,16 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
|
||||
sealed class AddAlbumEvent {
|
||||
data object SaveAlbum: AddAlbumEvent()
|
||||
data object Reset: AddAlbumEvent()
|
||||
data object DeleteSelected: AddAlbumEvent()
|
||||
data object SelectAll: AddAlbumEvent()
|
||||
data object DeselectAll: AddAlbumEvent()
|
||||
data class SetAlbumName(
|
||||
data class SaveAlbum(
|
||||
val initialAlbumName: String
|
||||
): AddAlbumEvent()
|
||||
data class ReflectAlbumName(
|
||||
val newAlbumName: String
|
||||
): AddAlbumEvent()
|
||||
data class AddWallpapers(
|
||||
val wallpaperUris: List<String>
|
||||
): AddAlbumEvent()
|
||||
@@ -24,11 +23,17 @@ sealed class AddAlbumEvent {
|
||||
data class SelectFolder(
|
||||
val directoryUri: String
|
||||
): AddAlbumEvent()
|
||||
|
||||
data class RemoveFolderFromSelection(
|
||||
data class DeselectFolder(
|
||||
val directoryUri: String
|
||||
): AddAlbumEvent()
|
||||
data class RemoveWallpaperFromSelection(
|
||||
data class DeselectWallpaper(
|
||||
val wallpaperUri: String
|
||||
): AddAlbumEvent()
|
||||
data class SetLoading(
|
||||
val isLoading: Boolean
|
||||
): AddAlbumEvent()
|
||||
data class LoadFoldersAndWallpapers(
|
||||
val folders: List<Folder>,
|
||||
val wallpapers: List<Wallpaper>
|
||||
): AddAlbumEvent()
|
||||
}
|
||||
+249
-148
@@ -2,64 +2,92 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.scaleIn
|
||||
import androidx.compose.animation.scaleOut
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.items
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumAnimatedFab
|
||||
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
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import my.nanihadesuka.compose.LazyVerticalGridScrollbar
|
||||
import my.nanihadesuka.compose.ScrollbarSettings
|
||||
|
||||
@Composable
|
||||
fun AddAlbumScreen(
|
||||
addAlbumViewModel: AddAlbumViewModel = hiltViewModel(),
|
||||
settingsViewModel: SettingsViewModel = hiltViewModel(),
|
||||
addAlbumViewModel: AddAlbumViewModel,
|
||||
initialAlbumName: String,
|
||||
onBackClick: () -> Unit,
|
||||
onConfirmation: () -> Unit,
|
||||
onShowWallpaperView: (String) -> Unit,
|
||||
onShowFolderView: (String?, List<String>) -> Unit
|
||||
onShowWallpaperView: (String, String) -> Unit,
|
||||
onShowFolderView: (Folder) -> Unit,
|
||||
onSortClick: (List<Folder>, List<Wallpaper>) -> Unit,
|
||||
animate: Boolean // This likely controls item animation, similar to AlbumViewScreen
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val lazyGridState = rememberLazyStaggeredGridState()
|
||||
val addAlbumState = addAlbumViewModel.state.collectAsStateWithLifecycle()
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
var selectionMode by rememberSaveable { mutableStateOf(false) }
|
||||
if (addAlbumState.value.initialAlbumName.isEmpty()) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.SetAlbumName(initialAlbumName))
|
||||
}
|
||||
val scope = rememberCoroutineScope()
|
||||
val addAlbumState by addAlbumViewModel.state.collectAsStateWithLifecycle() // Use by for direct access
|
||||
val lazyListState = rememberLazyGridState()
|
||||
var showSpotlight by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
// Remember scrollbar settings for consistency and performance
|
||||
val colorScheme = MaterialTheme.colorScheme
|
||||
val scrollbarSettings = remember {
|
||||
ScrollbarSettings.Default.copy(
|
||||
thumbUnselectedColor = colorScheme.primary,
|
||||
thumbSelectedColor = colorScheme.primary,
|
||||
thumbShape = RoundedCornerShape(16.dp),
|
||||
scrollbarPadding = 1.dp,
|
||||
)
|
||||
}
|
||||
|
||||
// Remember common modifier for grid items for consistency and responsiveness
|
||||
val commonItemModifier = remember {
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.aspectRatio(9f / 16f) // Common aspect ratio for wallpapers/photos
|
||||
}
|
||||
|
||||
BackHandler(
|
||||
enabled = selectionMode,
|
||||
onBack = {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
|
||||
selectionMode = false
|
||||
enabled = addAlbumState.selectionState.selectedCount > 0,
|
||||
onBack = remember(addAlbumState.isLoading, addAlbumViewModel) { // Remember the lambda
|
||||
{
|
||||
if (!addAlbumState.isLoading) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -67,14 +95,23 @@ fun AddAlbumScreen(
|
||||
val imagePickerLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.OpenMultipleDocuments(),
|
||||
onResult = { uris: List<Uri> ->
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
val uriList = uris.mapNotNull { uri ->
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
|
||||
if (persistedUriPermissions.any { it.uri == uri }) uri.toString() else null
|
||||
}
|
||||
if (uriList.isNotEmpty()) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.AddWallpapers(uriList))
|
||||
scope.launch(Dispatchers.IO) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.SetLoading(true))
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
val uriList = uris.mapNotNull { uri ->
|
||||
try {
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
uri.toString()
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
if (uriList.isNotEmpty()) {
|
||||
withContext(Dispatchers.Main) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.AddWallpapers(uriList))
|
||||
}
|
||||
}
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.SetLoading(false))
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -83,12 +120,17 @@ fun AddAlbumScreen(
|
||||
val folderPickerLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.OpenDocumentTree(),
|
||||
onResult = { uri: Uri? ->
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
if (uri != null) {
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
|
||||
if (persistedUriPermissions.any { it.uri == uri }) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.AddFolder(uri.toString()))
|
||||
scope.launch(Dispatchers.IO) {
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
if (uri != null) {
|
||||
try {
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
withContext(Dispatchers.Main) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.AddFolder(uri.toString()))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("AddAlbumScreen", "Failed to take persistable URI permission: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,140 +138,199 @@ fun AddAlbumScreen(
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
AddAlbumSmallTopBar(
|
||||
title = initialAlbumName,
|
||||
isEmpty = addAlbumState.value.isEmpty,
|
||||
selectionMode = selectionMode,
|
||||
albumState = addAlbumViewModel.state,
|
||||
showSpotlight = showSpotlight,
|
||||
onBackClick = {
|
||||
val onBackClickTopBar = remember(addAlbumViewModel, onBackClick) {
|
||||
{
|
||||
showSpotlight = false
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.Reset)
|
||||
onBackClick()
|
||||
},
|
||||
onConfirmationClick = {
|
||||
showSpotlight = false
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.ReflectAlbumName(it))
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.SaveAlbum)
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.Reset)
|
||||
onConfirmation()
|
||||
},
|
||||
onSelectAllClick = {
|
||||
if (!addAlbumState.value.allSelected) addAlbumViewModel.onEvent(AddAlbumEvent.SelectAll)
|
||||
else addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
|
||||
},
|
||||
onDeleteSelected = {
|
||||
selectionMode = false
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.DeleteSelected)
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
|
||||
}
|
||||
}
|
||||
|
||||
val onConfirmationClickTopBar = remember(addAlbumState.isLoading, addAlbumViewModel, initialAlbumName, onConfirmation) {
|
||||
{ text: String ->
|
||||
if (!addAlbumState.isLoading) {
|
||||
showSpotlight = false
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.SaveAlbum(text))
|
||||
onConfirmation()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val onSelectAllClickTopBar = remember(addAlbumState.isLoading, addAlbumState.selectionState.allSelected, addAlbumViewModel) {
|
||||
{
|
||||
if (!addAlbumState.isLoading) {
|
||||
if (!addAlbumState.selectionState.allSelected) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.SelectAll)
|
||||
} else {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val onDeleteSelectedTopBar = remember(addAlbumState.isLoading, addAlbumViewModel) {
|
||||
{
|
||||
if (!addAlbumState.isLoading) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.DeleteSelected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val onSortClickTopBar = remember(addAlbumState.isLoading, addAlbumViewModel, addAlbumState.folders, addAlbumState.wallpapers, onSortClick) {
|
||||
{
|
||||
if (!addAlbumState.isLoading) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
|
||||
onSortClick(addAlbumState.folders, addAlbumState.wallpapers)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AddAlbumSmallTopBar(
|
||||
title = initialAlbumName,
|
||||
allSelected = addAlbumState.selectionState.allSelected,
|
||||
selectedCount = addAlbumState.selectionState.selectedCount,
|
||||
isEmpty = addAlbumState.isEmpty,
|
||||
selectionMode = addAlbumState.selectionState.selectedCount > 0,
|
||||
showSpotlight = showSpotlight,
|
||||
isLoad = addAlbumState.isLoading,
|
||||
onBackClick = onBackClickTopBar,
|
||||
onConfirmationClick = onConfirmationClickTopBar,
|
||||
onSelectAllClick = onSelectAllClickTopBar,
|
||||
onDeleteSelected = onDeleteSelectedTopBar,
|
||||
onSortClick = onSortClickTopBar
|
||||
)
|
||||
},
|
||||
floatingActionButton = {
|
||||
if (settingsState.value.animate) {
|
||||
AnimatedVisibility(
|
||||
visible = !lazyGridState.isScrollInProgress || lazyGridState.firstVisibleItemScrollOffset < 0,
|
||||
enter = scaleIn(tween(400, 50, FastOutSlowInEasing)),
|
||||
exit = scaleOut(tween(400, 50, FastOutSlowInEasing)),
|
||||
) {
|
||||
AddAlbumAnimatedFab(
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
},
|
||||
animate = true
|
||||
)
|
||||
// Remember FAB callbacks
|
||||
val onImageClickFab = remember(addAlbumViewModel, imagePickerLauncher) {
|
||||
{
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
}
|
||||
}
|
||||
else {
|
||||
AddAlbumAnimatedFab(
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
showSpotlight = true
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
showSpotlight = true
|
||||
},
|
||||
animate = false
|
||||
)
|
||||
val onFolderClickFab = remember(addAlbumViewModel, folderPickerLauncher) {
|
||||
{
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
|
||||
folderPickerLauncher.launch(null)
|
||||
}
|
||||
}
|
||||
|
||||
AddAlbumAnimatedFab(
|
||||
isLoading = addAlbumState.isLoading,
|
||||
animate = animate,
|
||||
onImageClick = onImageClickFab,
|
||||
onFolderClick = onFolderClickFab
|
||||
)
|
||||
},
|
||||
bottomBar = {
|
||||
if (addAlbumState.isLoading) {
|
||||
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
||||
}
|
||||
},
|
||||
content = {
|
||||
LazyVerticalStaggeredGrid(
|
||||
state = lazyGridState,
|
||||
content = { paddingValues -> // Use paddingValues from Scaffold
|
||||
LazyVerticalGridScrollbar(
|
||||
state = lazyListState,
|
||||
settings = scrollbarSettings, // Use remembered settings
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(it),
|
||||
columns = StaggeredGridCells.Fixed(2),
|
||||
contentPadding = PaddingValues(4.dp, 4.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
content = {
|
||||
items (items = addAlbumState.value.folders, key = { folder -> folder.folderUri }
|
||||
) { folder ->
|
||||
.padding(paddingValues), // Apply Scaffold padding
|
||||
) {
|
||||
LazyVerticalGrid(
|
||||
state = lazyListState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
columns = GridCells.Adaptive(150.dp),
|
||||
contentPadding = PaddingValues(4.dp), // Apply padding to grid content
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp), // Use spacedBy for consistent spacing
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp), // Use spacedBy for consistent spacing
|
||||
) {
|
||||
items(
|
||||
items = addAlbumState.folders,
|
||||
key = { folder -> folder.folderUri }
|
||||
) { folder -> // Renamed 'it' to 'folder' for clarity
|
||||
val isSelected = addAlbumState.selectionState.selectedFolders.contains(folder.folderUri)
|
||||
val onFolderItemSelection = remember(folder.folderUri, addAlbumState.isLoading, addAlbumViewModel, isSelected) {
|
||||
{
|
||||
if (!addAlbumState.isLoading) {
|
||||
if (!isSelected) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.SelectFolder(folder.folderUri))
|
||||
} else {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectFolder(folder.folderUri))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val onFolderViewClickItem = remember(folder, addAlbumState.isLoading, onShowFolderView) {
|
||||
{
|
||||
if (!addAlbumState.isLoading) {
|
||||
onShowFolderView(folder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FolderItem(
|
||||
folder = folder,
|
||||
itemSelected = addAlbumState.value.selectedFolders.contains(folder.folderUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
addAlbumViewModel.onEvent(
|
||||
if (!addAlbumState.value.selectedFolders.contains(folder.folderUri))
|
||||
AddAlbumEvent.SelectFolder(folder.folderUri)
|
||||
else {
|
||||
AddAlbumEvent.RemoveFolderFromSelection(folder.folderUri)
|
||||
}
|
||||
itemSelected = isSelected,
|
||||
selectionMode = addAlbumState.selectionState.selectedCount > 0,
|
||||
onItemSelection = onFolderItemSelection,
|
||||
onFolderViewClick = onFolderViewClickItem,
|
||||
modifier = commonItemModifier // Use common responsive modifier
|
||||
.then(
|
||||
if (animate) Modifier.animateItem( // Add item animation
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
)
|
||||
) else Modifier
|
||||
)
|
||||
},
|
||||
onFolderViewClick = {
|
||||
if (folder.wallpapers.isNotEmpty()) onShowFolderView(folder.folderName, folder.wallpapers)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
items (items = addAlbumState.value.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri }
|
||||
) { wallpaper ->
|
||||
items(
|
||||
items = addAlbumState.wallpapers,
|
||||
key = { wallpaper -> wallpaper.wallpaperUri }
|
||||
) { wallpaper -> // Renamed 'it' to 'wallpaper' for clarity
|
||||
val isSelected = addAlbumState.selectionState.selectedWallpapers.contains(wallpaper.wallpaperUri)
|
||||
val onWallpaperItemSelection = remember(wallpaper.wallpaperUri, addAlbumState.isLoading, addAlbumViewModel, isSelected) {
|
||||
{
|
||||
if (!addAlbumState.isLoading) {
|
||||
if (!isSelected) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.SelectWallpaper(wallpaper.wallpaperUri))
|
||||
} else {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectWallpaper(wallpaper.wallpaperUri))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val onWallpaperViewClickItem = remember(wallpaper, addAlbumState.isLoading, onShowWallpaperView) {
|
||||
{
|
||||
if (!addAlbumState.isLoading) {
|
||||
onShowWallpaperView(wallpaper.wallpaperUri, wallpaper.fileName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper.wallpaperUri,
|
||||
itemSelected = addAlbumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
addAlbumViewModel.onEvent(
|
||||
if (!addAlbumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri))
|
||||
AddAlbumEvent.SelectWallpaper(wallpaper.wallpaperUri)
|
||||
else {
|
||||
AddAlbumEvent.RemoveWallpaperFromSelection(wallpaper.wallpaperUri)
|
||||
}
|
||||
itemSelected = isSelected,
|
||||
selectionMode = addAlbumState.selectionState.selectedCount > 0,
|
||||
onItemSelection = onWallpaperItemSelection,
|
||||
onWallpaperViewClick = onWallpaperViewClickItem,
|
||||
modifier = commonItemModifier // Use common responsive modifier
|
||||
.then(
|
||||
if (animate) Modifier.animateItem( // Add item animation
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
)
|
||||
) else Modifier
|
||||
)
|
||||
},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper.wallpaperUri)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
),
|
||||
animate = settingsState.value.animate
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
+6
-4
@@ -3,13 +3,15 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
|
||||
data class AddAlbumState (
|
||||
val initialAlbumName: String = "",
|
||||
val displayedAlbumName: String = "",
|
||||
val coverUri: String = "",
|
||||
data class AddAlbumState(
|
||||
val wallpapers: List<Wallpaper> = emptyList(),
|
||||
val folders: List<Folder> = emptyList(),
|
||||
val selectionState: SelectionState = SelectionState(),
|
||||
val isEmpty: Boolean = true,
|
||||
val isLoading: Boolean = false
|
||||
)
|
||||
|
||||
data class SelectionState(
|
||||
val selectedWallpapers: List<String> = emptyList(),
|
||||
val selectedFolders: List<String> = emptyList(),
|
||||
val allSelected: Boolean = false,
|
||||
|
||||
+189
-169
@@ -1,11 +1,12 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.core.getFolderNameFromUri
|
||||
import com.anthonyla.paperize.core.compress
|
||||
import com.anthonyla.paperize.core.getFolderMetadata
|
||||
import com.anthonyla.paperize.core.getImageMetadata
|
||||
import com.anthonyla.paperize.core.getWallpaperFromFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
@@ -38,221 +39,240 @@ class AddAlbumViewModel @Inject constructor(
|
||||
is AddAlbumEvent.SaveAlbum -> {
|
||||
viewModelScope.launch {
|
||||
if (_state.value.wallpapers.isEmpty() && _state.value.folders.isEmpty()) { return@launch }
|
||||
val albumCoverUri = when (_state.value.isEmpty) {
|
||||
true -> ""
|
||||
false -> {
|
||||
if (_state.value.wallpapers.isNotEmpty())
|
||||
_state.value.wallpapers.random().wallpaperUri
|
||||
else {
|
||||
_state.value.folders.random().coverUri
|
||||
}
|
||||
}
|
||||
val wallpapers = _state.value.wallpapers.map {
|
||||
it.copy(
|
||||
initialAlbumName = event.initialAlbumName,
|
||||
key = event.initialAlbumName.hashCode() + it.wallpaperUri.hashCode()
|
||||
)
|
||||
}
|
||||
var totalWallpapers = _state.value.wallpapers.size
|
||||
val folders = _state.value.folders.map { folder ->
|
||||
val updatedWallpapers = folder.wallpapers.map {
|
||||
it.copy(
|
||||
initialAlbumName = event.initialAlbumName,
|
||||
key = event.initialAlbumName.hashCode() + folder.folderUri.hashCode() + it.wallpaperUri.hashCode(),
|
||||
order = it.order + totalWallpapers
|
||||
)
|
||||
}
|
||||
totalWallpapers += folder.wallpapers.size
|
||||
folder.copy(
|
||||
initialAlbumName = event.initialAlbumName,
|
||||
key = event.initialAlbumName.hashCode() + folder.hashCode(),
|
||||
coverUri = updatedWallpapers.firstOrNull()?.wallpaperUri ?: folder.coverUri,
|
||||
wallpapers = updatedWallpapers
|
||||
)
|
||||
}
|
||||
|
||||
val albumWithWallpaperAndFolder = AlbumWithWallpaperAndFolder(
|
||||
album = Album(
|
||||
initialAlbumName = _state.value.initialAlbumName,
|
||||
displayedAlbumName = _state.value.displayedAlbumName,
|
||||
coverUri = albumCoverUri,
|
||||
initialAlbumName = event.initialAlbumName,
|
||||
displayedAlbumName = event.initialAlbumName,
|
||||
coverUri = folders.firstOrNull()?.coverUri ?: wallpapers.firstOrNull()?.wallpaperUri ?: "",
|
||||
homeWallpapersInQueue = emptyList(),
|
||||
lockWallpapersInQueue = emptyList(),
|
||||
selected = false
|
||||
),
|
||||
wallpapers = _state.value.wallpapers,
|
||||
folders = _state.value.folders,
|
||||
wallpapers = wallpapers,
|
||||
folders = folders
|
||||
)
|
||||
repository.upsertAlbumWithWallpaperAndFolder(albumWithWallpaperAndFolder)
|
||||
_state.update { it.copy(
|
||||
initialAlbumName = "",
|
||||
displayedAlbumName = "",
|
||||
coverUri = "",
|
||||
wallpapers = emptyList(),
|
||||
folders = emptyList(),
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
isEmpty = false,
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
) }
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.DeleteSelected -> {
|
||||
viewModelScope.launch {
|
||||
_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 -> {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
initialAlbumName = event.initialAlbumName,
|
||||
displayedAlbumName = event.initialAlbumName,
|
||||
) }
|
||||
_state.update { AddAlbumState() }
|
||||
}
|
||||
}
|
||||
|
||||
is AddAlbumEvent.ReflectAlbumName -> {
|
||||
if (event.newAlbumName != _state.value.initialAlbumName) {
|
||||
viewModelScope.launch {
|
||||
_state.update {
|
||||
val wallpapers = it.wallpapers.map { wallpaper ->
|
||||
wallpaper.copy(initialAlbumName = event.newAlbumName)
|
||||
}
|
||||
val folders = it.folders.map { folder ->
|
||||
folder.copy(initialAlbumName = event.newAlbumName)
|
||||
}
|
||||
it.copy(
|
||||
initialAlbumName = event.newAlbumName,
|
||||
displayedAlbumName = event.newAlbumName,
|
||||
coverUri = it.coverUri,
|
||||
wallpapers = wallpapers,
|
||||
folders = folders,
|
||||
isEmpty = wallpapers.isEmpty() && folders.isEmpty()
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.AddWallpapers -> {
|
||||
is AddAlbumEvent.DeleteSelected -> {
|
||||
viewModelScope.launch {
|
||||
val newWallpaperUris = event.wallpaperUris.filterNot { it in _state.value.wallpapers.map { wallpaper -> wallpaper.wallpaperUri } }
|
||||
val newWallpapers = newWallpaperUris.map { uri ->
|
||||
Wallpaper(
|
||||
initialAlbumName = _state.value.initialAlbumName,
|
||||
wallpaperUri = uri,
|
||||
key = uri.hashCode() + _state.value.initialAlbumName.hashCode(),
|
||||
)
|
||||
val selectedWallpaperUris = _state.value.selectionState.selectedWallpapers.toSet()
|
||||
val selectedFolderUris = _state.value.selectionState.selectedFolders.toSet()
|
||||
val wallpapersRemoved = _state.value.wallpapers.filter { wallpaper ->
|
||||
wallpaper.wallpaperUri !in selectedWallpaperUris
|
||||
}
|
||||
val foldersRemoved = _state.value.folders.filter { folder ->
|
||||
folder.folderUri !in selectedFolderUris
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
wallpapers = it.wallpapers.plus(newWallpapers),
|
||||
isEmpty = false
|
||||
wallpapers = wallpapersRemoved,
|
||||
folders = foldersRemoved,
|
||||
isEmpty = wallpapersRemoved.isEmpty() && foldersRemoved.isEmpty(),
|
||||
selectionState = SelectionState()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AddAlbumEvent.AddWallpapers -> {
|
||||
viewModelScope.launch {
|
||||
val existingWallpapers = _state.value.wallpapers.map { it.wallpaperUri }.toSet()
|
||||
val newWallpapers = event.wallpaperUris.filter { wallpaperUri ->
|
||||
wallpaperUri !in existingWallpapers
|
||||
}
|
||||
val wallpapers = _state.value.wallpapers.plus(
|
||||
newWallpapers.mapIndexed { index, wallpaperUri ->
|
||||
val metadata = getImageMetadata(context, wallpaperUri)
|
||||
Wallpaper(
|
||||
initialAlbumName = "",
|
||||
wallpaperUri = wallpaperUri.compress("content://com.android.externalstorage.documents/"),
|
||||
fileName = metadata.filename,
|
||||
dateModified = metadata.lastModified,
|
||||
order = index + _state.value.wallpapers.size,
|
||||
key = 0
|
||||
)
|
||||
}
|
||||
)
|
||||
_state.update {
|
||||
it.copy(
|
||||
wallpapers = wallpapers,
|
||||
isEmpty = false,
|
||||
selectionState = SelectionState(),
|
||||
isLoading = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AddAlbumEvent.AddFolder -> {
|
||||
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(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
isEmpty = false,
|
||||
folders = it.folders.plus(
|
||||
Folder(
|
||||
initialAlbumName = it.initialAlbumName,
|
||||
folderName = folderName,
|
||||
folderUri = event.directoryUri,
|
||||
coverUri = wallpapers.randomOrNull(),
|
||||
wallpapers = wallpapers,
|
||||
key = event.directoryUri.hashCode() + it.initialAlbumName.hashCode()
|
||||
)
|
||||
if (event.directoryUri in _state.value.folders.map { it.folderUri }) {
|
||||
return@launch
|
||||
}
|
||||
_state.update { it.copy(isLoading = true) }
|
||||
val wallpapers = getWallpaperFromFolder(event.directoryUri, context)
|
||||
val metadata = getFolderMetadata(event.directoryUri, context)
|
||||
val folder = Folder(
|
||||
initialAlbumName = "",
|
||||
folderName = metadata.filename,
|
||||
folderUri = event.directoryUri,
|
||||
wallpapers = wallpapers,
|
||||
coverUri = wallpapers.firstOrNull()?.wallpaperUri ?: "",
|
||||
dateModified = metadata.lastModified,
|
||||
order = if (_state.value.folders.isEmpty()) 0 else _state.value.folders.size,
|
||||
key = 0
|
||||
)
|
||||
_state.update {
|
||||
it.copy(
|
||||
folders = it.folders.plus(folder),
|
||||
isEmpty = false,
|
||||
selectionState = SelectionState(),
|
||||
isLoading = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AddAlbumEvent.SelectAll -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.selectionState.allSelected) {
|
||||
_state.update { state ->
|
||||
state.copy(
|
||||
selectionState = SelectionState(
|
||||
selectedFolders = state.folders.map { it.folderUri },
|
||||
selectedWallpapers = state.wallpapers.map { it.wallpaperUri },
|
||||
allSelected = true,
|
||||
selectedCount = state.folders.size + state.wallpapers.size
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.SelectAll -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.allSelected) {
|
||||
_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,
|
||||
allSelected = true
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.DeselectAll-> {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
selectedCount = 0,
|
||||
allSelected = false
|
||||
) }
|
||||
_state.update { it.copy(selectionState = SelectionState()) }
|
||||
}
|
||||
}
|
||||
|
||||
is AddAlbumEvent.SelectFolder -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.selectedFolders.any { it == event.directoryUri }) {
|
||||
_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
|
||||
) }
|
||||
val folderUri = (_state.value.folders.find { it.folderUri == event.directoryUri } ?: return@launch).folderUri
|
||||
_state.update {
|
||||
val newSelectedFolders = it.selectionState.selectedFolders.plus(folderUri)
|
||||
it.copy(
|
||||
selectionState = it.selectionState.copy(
|
||||
selectedFolders = newSelectedFolders,
|
||||
selectedCount = newSelectedFolders.size + it.selectionState.selectedWallpapers.size,
|
||||
allSelected = newSelectedFolders.size + it.selectionState.selectedWallpapers.size >=
|
||||
it.wallpapers.size + it.folders.size
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AddAlbumEvent.SelectWallpaper -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.selectedWallpapers.any { it == event.wallpaperUri }) {
|
||||
if (!_state.value.selectionState.selectedWallpapers.contains(event.wallpaperUri)) {
|
||||
_state.update {
|
||||
val wallpapers = it.selectedWallpapers.plus(event.wallpaperUri)
|
||||
val newSelectedWallpapers = it.selectionState.selectedWallpapers.plus(event.wallpaperUri)
|
||||
it.copy(
|
||||
selectedWallpapers = wallpapers,
|
||||
selectedCount = it.selectedCount + 1,
|
||||
allSelected = it.selectedFolders.size + wallpapers.size >= it.wallpapers.size + it.folders.size
|
||||
) }
|
||||
selectionState = it.selectionState.copy(
|
||||
selectedWallpapers = newSelectedWallpapers,
|
||||
selectedCount = newSelectedWallpapers.size + it.selectionState.selectedFolders.size,
|
||||
allSelected = it.selectionState.selectedFolders.size + newSelectedWallpapers.size >=
|
||||
it.wallpapers.size + it.folders.size
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.RemoveFolderFromSelection -> {
|
||||
viewModelScope.launch {
|
||||
if (_state.value.selectedFolders.find { it == event.directoryUri } != null ) {
|
||||
_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 -> {
|
||||
is AddAlbumEvent.DeselectFolder -> {
|
||||
viewModelScope.launch {
|
||||
if (_state.value.selectedWallpapers.find { it == event.wallpaperUri } != null ) {
|
||||
_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
|
||||
) }
|
||||
val folderUri = (_state.value.folders.find { it.folderUri == event.directoryUri } ?: return@launch).folderUri
|
||||
_state.update {
|
||||
val newSelectedFolders = it.selectionState.selectedFolders.minus(folderUri)
|
||||
it.copy(
|
||||
selectionState = it.selectionState.copy(
|
||||
selectedFolders = newSelectedFolders,
|
||||
selectedCount = it.selectionState.selectedCount - 1,
|
||||
allSelected = false
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AddAlbumEvent.DeselectWallpaper -> {
|
||||
viewModelScope.launch {
|
||||
if (_state.value.selectionState.selectedWallpapers.contains(event.wallpaperUri)) {
|
||||
_state.update {
|
||||
val newSelectedWallpapers = it.selectionState.selectedWallpapers.minus(event.wallpaperUri)
|
||||
it.copy(
|
||||
selectionState = it.selectionState.copy(
|
||||
selectedWallpapers = newSelectedWallpapers,
|
||||
selectedCount = it.selectionState.selectedCount - 1,
|
||||
allSelected = false
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AddAlbumEvent.LoadFoldersAndWallpapers -> {
|
||||
viewModelScope.launch {
|
||||
_state.update {
|
||||
it.copy(
|
||||
folders = event.folders,
|
||||
wallpapers = event.wallpapers,
|
||||
isEmpty = event.folders.isEmpty() && event.wallpapers.isEmpty(),
|
||||
selectionState = SelectionState(),
|
||||
isLoading = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AddAlbumEvent.SetLoading -> {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(isLoading = event.isLoading) }
|
||||
}
|
||||
}
|
||||
|
||||
is AddAlbumEvent.Reset -> {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
initialAlbumName = "",
|
||||
displayedAlbumName = "",
|
||||
coverUri = "",
|
||||
wallpapers = emptyList(),
|
||||
folders = emptyList(),
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
isEmpty = false,
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
) }
|
||||
_state.update { AddAlbumState() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+162
-184
@@ -1,223 +1,201 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.animation.*
|
||||
import androidx.compose.animation.core.*
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
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
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LargeFloatingActionButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components.MenuRow
|
||||
|
||||
/**
|
||||
* Animated FAB that expands to show two options: Add image and Add folder
|
||||
* Source: https://github.com/rajaumair7890/AnimatedFABMenu
|
||||
*/
|
||||
@Composable
|
||||
fun AddAlbumAnimatedFab(
|
||||
isLoading: Boolean,
|
||||
animate: Boolean,
|
||||
onImageClick: () -> Unit,
|
||||
onFolderClick: () -> Unit
|
||||
) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
val fabTransition = updateTransition(targetState = expanded, label = "")
|
||||
val expandedWidth = 165.dp
|
||||
val collapsedFabSize = 96.dp
|
||||
val expandedFabHeight = 60.dp
|
||||
val menuItemHeight = 56.dp
|
||||
val menuItemCount = 2
|
||||
|
||||
BackHandler(expanded) { expanded = false }
|
||||
val menuColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
val fabColor = MaterialTheme.colorScheme.primaryContainer
|
||||
|
||||
val expandHorizontalSize = Pair(165.dp, 90.dp)
|
||||
val expandHorizontally by fabTransition.animateDp(
|
||||
transitionSpec = { spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow) }, label = "",
|
||||
targetValueByState = { isExpanded ->
|
||||
if (isExpanded) expandHorizontalSize.first else expandHorizontalSize.second
|
||||
var isFabExpanded by remember { mutableStateOf(false) }
|
||||
BackHandler(isFabExpanded) { isFabExpanded = false }
|
||||
|
||||
val transition = updateTransition(targetState = isFabExpanded, label = "fabTransition")
|
||||
|
||||
val fabWidth by transition.animateDp(
|
||||
label = "fabWidth",
|
||||
transitionSpec = {
|
||||
if (animate) {
|
||||
spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)
|
||||
} else {
|
||||
snap()
|
||||
}
|
||||
}
|
||||
)
|
||||
) { expanded ->
|
||||
if (expanded) expandedWidth else collapsedFabSize
|
||||
}
|
||||
|
||||
val shrinkVerticalSize = Pair(50.dp, 90.dp)
|
||||
val shrinkVertically by fabTransition.animateDp(
|
||||
transitionSpec = { spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow) }, label = "",
|
||||
targetValueByState = { isExpanded ->
|
||||
if (isExpanded) shrinkVerticalSize.first else shrinkVerticalSize.second
|
||||
val fabHeight by transition.animateDp(
|
||||
label = "fabHeight",
|
||||
transitionSpec = {
|
||||
if (animate) {
|
||||
spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)
|
||||
} else {
|
||||
snap()
|
||||
}
|
||||
}
|
||||
)
|
||||
) { expanded ->
|
||||
if (expanded) expandedFabHeight else collapsedFabSize
|
||||
}
|
||||
|
||||
val menuHeightSize = Pair(100.dp, 90.dp)
|
||||
val menuHeight by fabTransition.animateDp(
|
||||
transitionSpec = { spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow) }, label = "",
|
||||
targetValueByState = { isExpanded ->
|
||||
if (isExpanded) menuHeightSize.first else menuHeightSize.second
|
||||
val menuHeight by transition.animateDp(
|
||||
label = "menuHeight",
|
||||
transitionSpec = {
|
||||
if (animate) {
|
||||
spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)
|
||||
} else {
|
||||
snap()
|
||||
}
|
||||
}
|
||||
)
|
||||
) { expanded ->
|
||||
if (expanded) menuItemHeight * menuItemCount else 0.dp
|
||||
}
|
||||
|
||||
if (animate) {
|
||||
ElevatedCard(
|
||||
colors = CardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
contentColor = Color.Transparent,
|
||||
disabledContentColor = Color.Transparent,
|
||||
disabledContainerColor = Color.Transparent,
|
||||
),
|
||||
shape = RoundedCornerShape(28.dp),
|
||||
val fabIconTransitionSpec: AnimatedContentTransitionScope<Boolean>.() -> ContentTransform = {
|
||||
if (animate) {
|
||||
(scaleIn(tween(100, 300, FastOutSlowInEasing)) + fadeIn(tween(250, 300, LinearEasing)))
|
||||
.togetherWith(fadeOut(tween(10, 0, LinearEasing)))
|
||||
} else {
|
||||
EnterTransition.None.togetherWith(ExitTransition.None)
|
||||
}
|
||||
}
|
||||
|
||||
ElevatedCard(
|
||||
modifier = Modifier.padding(4.dp),
|
||||
shape = RoundedCornerShape(28.dp),
|
||||
elevation = CardDefaults.elevatedCardElevation(4.dp),
|
||||
colors = CardDefaults.elevatedCardColors(
|
||||
containerColor = menuColor
|
||||
)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.width(expandHorizontally)
|
||||
.pointerInput(Unit) {
|
||||
detectTapGestures(onTap = { expanded = false })
|
||||
}
|
||||
.height(menuHeight)
|
||||
.width(fabWidth),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.SpaceEvenly
|
||||
) {
|
||||
AnimatedVisibility(
|
||||
visible = expanded,
|
||||
enter = fadeIn(tween(300, 0, FastOutSlowInEasing)),
|
||||
exit = fadeOut(tween(300, 0, FastOutSlowInEasing)),
|
||||
modifier = Modifier.animateContentSize(tween(50, 0, FastOutSlowInEasing)),
|
||||
visible = isFabExpanded,
|
||||
label = stringResource(R.string.add_images_btn),
|
||||
enter = if (animate) fadeIn(tween(300, 150, LinearEasing)) else EnterTransition.None,
|
||||
exit = if (animate) fadeOut(tween(200, 50, LinearEasing)) + scaleOut() else ExitTransition.None
|
||||
) {
|
||||
Surface(tonalElevation = 5.dp) {
|
||||
Column(modifier = Modifier.height(menuHeight)) {
|
||||
MenuRow(
|
||||
text = stringResource(R.string.add_images_btn),
|
||||
icon = Icons.Filled.PhotoLibrary,
|
||||
horizontalExpansion = expandHorizontally,
|
||||
onClick = {
|
||||
expanded = false
|
||||
onImageClick()
|
||||
}
|
||||
)
|
||||
MenuRow(
|
||||
text = stringResource(R.string.add_folder_btn),
|
||||
icon = Icons.Filled.Folder,
|
||||
horizontalExpansion = expandHorizontally,
|
||||
onClick = {
|
||||
expanded = false
|
||||
onFolderClick()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Surface(
|
||||
tonalElevation = 3.dp,
|
||||
) {
|
||||
LargeFloatingActionButton(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
onClick = { expanded = !expanded },
|
||||
MenuItemRow(
|
||||
icon = Icons.Filled.PhotoLibrary,
|
||||
text = stringResource(R.string.add_images_btn),
|
||||
onClick = {
|
||||
onImageClick()
|
||||
isFabExpanded = false
|
||||
},
|
||||
modifier = Modifier
|
||||
.width(expandHorizontally)
|
||||
.height(shrinkVertically)
|
||||
.animateContentSize(),
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
if (!expanded) Icons.Filled.Add else Icons.Filled.Remove,
|
||||
contentDescription = stringResource(R.string.add_wallpaper),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
.fillMaxWidth()
|
||||
.height(menuItemHeight)
|
||||
)
|
||||
}
|
||||
|
||||
AnimatedVisibility(
|
||||
visible = isFabExpanded,
|
||||
label = stringResource(R.string.add_folder_btn),
|
||||
enter = if (animate) fadeIn(tween(300, 150, LinearEasing)) else EnterTransition.None,
|
||||
exit = if (animate) fadeOut(tween(200, 50, LinearEasing)) + scaleOut() else ExitTransition.None
|
||||
) {
|
||||
MenuItemRow(
|
||||
icon = Icons.Filled.Folder,
|
||||
text = stringResource(R.string.add_folder_btn),
|
||||
onClick = {
|
||||
onFolderClick()
|
||||
isFabExpanded = false
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(menuItemHeight)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
LargeFloatingActionButton(
|
||||
onClick = { if (!isLoading) isFabExpanded = !isFabExpanded },
|
||||
modifier = Modifier
|
||||
.width(fabWidth)
|
||||
.height(fabHeight),
|
||||
shape = RoundedCornerShape(28.dp),
|
||||
containerColor = fabColor,
|
||||
elevation = FloatingActionButtonDefaults.elevation(4.dp)
|
||||
) {
|
||||
AnimatedContent(
|
||||
targetState = isFabExpanded,
|
||||
transitionSpec = fabIconTransitionSpec,
|
||||
label = "FabContent"
|
||||
) { expanded ->
|
||||
Icon(
|
||||
imageVector = if (expanded) Icons.Filled.Remove else Icons.Filled.Add,
|
||||
contentDescription = stringResource(R.string.add_wallpaper)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ElevatedCard(
|
||||
colors = CardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
contentColor = Color.Transparent,
|
||||
disabledContentColor = Color.Transparent,
|
||||
disabledContainerColor = Color.Transparent,
|
||||
),
|
||||
shape = RoundedCornerShape(28.dp),
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.width(if (expanded) expandHorizontalSize.first else expandHorizontalSize.second)
|
||||
.pointerInput(Unit) {
|
||||
detectTapGestures(onTap = { expanded = false })
|
||||
}
|
||||
) {
|
||||
if (expanded) {
|
||||
Surface(tonalElevation = 5.dp) {
|
||||
Column(modifier = Modifier.height(if (expanded) menuHeightSize.first else menuHeightSize.second)) {
|
||||
MenuRow(
|
||||
text = stringResource(R.string.add_images_btn),
|
||||
icon = Icons.Filled.PhotoLibrary,
|
||||
horizontalExpansion = if (expanded) expandHorizontalSize.first else expandHorizontalSize.second,
|
||||
onClick = {
|
||||
expanded = false
|
||||
onImageClick()
|
||||
}
|
||||
)
|
||||
MenuRow(
|
||||
text = stringResource(R.string.add_folder_btn),
|
||||
icon = Icons.Filled.Folder,
|
||||
horizontalExpansion = if (expanded) expandHorizontalSize.first else expandHorizontalSize.second,
|
||||
onClick = {
|
||||
expanded = false
|
||||
onFolderClick()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Surface(
|
||||
tonalElevation = 3.dp,
|
||||
) {
|
||||
LargeFloatingActionButton(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
onClick = { expanded = !expanded },
|
||||
modifier = Modifier
|
||||
.width(if (expanded) expandHorizontalSize.first else expandHorizontalSize.second)
|
||||
.height(if (expanded) shrinkVerticalSize.first else shrinkVerticalSize.second)
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
if (!expanded) Icons.Filled.Add else Icons.Filled.Remove,
|
||||
contentDescription = stringResource(R.string.add_wallpaper),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reusable Composable for a single menu item row.
|
||||
*/
|
||||
@Composable
|
||||
private fun MenuItemRow(
|
||||
modifier: Modifier = Modifier,
|
||||
icon: ImageVector,
|
||||
text: String,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
Row(
|
||||
modifier = modifier.clickable(onClick = onClick),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = text,
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(start = 16.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
Text(
|
||||
text = text,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
}
|
||||
}
|
||||
+19
-4
@@ -22,10 +22,14 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.testTagsAsResourceId
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -37,6 +41,7 @@ import kotlinx.coroutines.android.awaitFrame
|
||||
/**
|
||||
* Dialog for adding a new album.
|
||||
*/
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun AddAlbumDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
@@ -44,11 +49,16 @@ fun AddAlbumDialog(
|
||||
) {
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
var albumName by rememberSaveable { mutableStateOf("") }
|
||||
Dialog(onDismissRequest = onDismissRequest) {
|
||||
Dialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(24.dp),
|
||||
.padding(24.dp)
|
||||
.semantics {
|
||||
testTagsAsResourceId = true
|
||||
},
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
@@ -99,7 +109,10 @@ fun AddAlbumDialog(
|
||||
onClick = { onDismissRequest() },
|
||||
modifier = Modifier.padding(8.dp),
|
||||
) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
Text(
|
||||
text = stringResource(R.string.cancel),
|
||||
modifier = Modifier.testTag("paperize:cancel_album_button")
|
||||
)
|
||||
}
|
||||
TextButton(
|
||||
modifier = Modifier.padding(8.dp),
|
||||
@@ -110,7 +123,9 @@ fun AddAlbumDialog(
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(stringResource(R.string.save))
|
||||
Text(
|
||||
text = stringResource(R.string.save),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+87
-96
@@ -1,5 +1,6 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components
|
||||
|
||||
import android.R.attr.contentDescription
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.RepeatMode
|
||||
import androidx.compose.animation.core.animateFloat
|
||||
@@ -19,7 +20,9 @@ import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material.icons.automirrored.filled.Sort
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.RadioButtonUnchecked
|
||||
import androidx.compose.material.icons.outlined.Add
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
@@ -32,6 +35,7 @@ import androidx.compose.material3.TextField
|
||||
import androidx.compose.material3.TextFieldDefaults
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.TopAppBarDefaults.topAppBarColors
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -49,10 +53,7 @@ import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.AddAlbumState
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
/**
|
||||
* Top bar for the Add Album screen
|
||||
@@ -60,51 +61,48 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun AddAlbumSmallTopBar(
|
||||
albumState: StateFlow<AddAlbumState>,
|
||||
title: String,
|
||||
isEmpty: Boolean,
|
||||
allSelected: Boolean,
|
||||
selectedCount: Int,
|
||||
selectionMode: Boolean,
|
||||
showSpotlight: Boolean,
|
||||
isLoad: Boolean,
|
||||
onSelectAllClick: () -> Unit,
|
||||
onBackClick: () -> Unit,
|
||||
onDeleteSelected: () -> Unit,
|
||||
onConfirmationClick: (String) -> Unit
|
||||
onConfirmationClick: (String) -> Unit,
|
||||
onSortClick: () -> 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)
|
||||
)
|
||||
val radiusValues = listOf(50f, 60f, 75f).map { targetValue ->
|
||||
infiniteTransition.animateFloat(
|
||||
initialValue = 25f,
|
||||
targetValue = targetValue,
|
||||
animationSpec = infiniteRepeatable(
|
||||
animation = tween(2000, easing = LinearOutSlowInEasing),
|
||||
repeatMode = RepeatMode.Reverse
|
||||
),
|
||||
label = "circle_${targetValue}_animation"
|
||||
)
|
||||
}
|
||||
|
||||
if (showSelectionDeleteDialog) {
|
||||
DeleteImagesAlertDialog(
|
||||
onDismissRequest = { showSelectionDeleteDialog = false },
|
||||
onConfirmation = {
|
||||
showSelectionDeleteDialog = false
|
||||
onDeleteSelected()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||
colors = topAppBarColors(containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)),
|
||||
title = {
|
||||
if (!selectionMode) {
|
||||
TextField(
|
||||
@@ -112,6 +110,7 @@ fun AddAlbumSmallTopBar(
|
||||
onValueChange = { editableTitle = it },
|
||||
placeholder = { Text(stringResource(R.string.enter_the_name_of_the_album)) },
|
||||
singleLine = true,
|
||||
readOnly = isLoad,
|
||||
textStyle = MaterialTheme.typography.titleLarge,
|
||||
colors = TextFieldDefaults.colors(
|
||||
focusedContainerColor = Color.Transparent,
|
||||
@@ -122,7 +121,7 @@ fun AddAlbumSmallTopBar(
|
||||
isError = editableTitle.isEmpty(),
|
||||
keyboardOptions = KeyboardOptions(
|
||||
keyboardType = KeyboardType.Text,
|
||||
imeAction = ImeAction.Done,
|
||||
imeAction = ImeAction.Done
|
||||
),
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() })
|
||||
)
|
||||
@@ -138,91 +137,83 @@ fun AddAlbumSmallTopBar(
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen),
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
Row (
|
||||
} else {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
IconButton(onClick = onSelectAllClick) {
|
||||
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
if (state.value.allSelected) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.CheckCircle,
|
||||
contentDescription = stringResource(R.string.all_images_selected_for_deletion),
|
||||
modifier = Modifier
|
||||
Icon(
|
||||
imageVector = if (allSelected) Icons.Default.CheckCircle else Icons.Default.RadioButtonUnchecked,
|
||||
contentDescription = stringResource(
|
||||
if (allSelected) R.string.all_images_selected_for_deletion
|
||||
else R.string.select_all_images_for_deletion
|
||||
),
|
||||
modifier = if (allSelected) {
|
||||
Modifier
|
||||
.padding(4.dp)
|
||||
.border(2.dp, bgColor, CircleShape)
|
||||
.clip(CircleShape)
|
||||
.background(bgColor)
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
imageVector = Icons.Default.RadioButtonUnchecked,
|
||||
contentDescription = stringResource(R.string.select_all_images_for_deletion),
|
||||
tint = Color.White.copy(alpha = 0.7f),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Modifier.padding(6.dp)
|
||||
}
|
||||
)
|
||||
}
|
||||
Text("${state.value.selectedCount} selected")
|
||||
Text(stringResource(R.string.selected, selectedCount))
|
||||
}
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
if(!selectionMode) {
|
||||
if (!isEmpty) {
|
||||
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 (!selectionMode) {
|
||||
if (!isEmpty && editableTitle.isNotEmpty()) {
|
||||
Row {
|
||||
Box {
|
||||
IconButton(onClick = onSortClick) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Default.Sort,
|
||||
contentDescription = stringResource(R.string.sort_items),
|
||||
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)
|
||||
Box {
|
||||
IconButton(onClick = { onConfirmationClick(editableTitle) }) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Add,
|
||||
contentDescription = stringResource(R.string.add_album),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
}
|
||||
if (!showSpotlight) {
|
||||
val primaryColor = MaterialTheme.colorScheme.inversePrimary
|
||||
val secondaryColor = MaterialTheme.colorScheme.secondary
|
||||
val colors = listOf(primaryColor, secondaryColor, primaryColor)
|
||||
val animationValues = radiusValues.map { it.value }
|
||||
val pairs = animationValues.zip(colors)
|
||||
|
||||
Canvas(modifier = Modifier.matchParentSize()) {
|
||||
pairs.forEach { (radius, color) ->
|
||||
drawCircle(
|
||||
color = color,
|
||||
radius = radius,
|
||||
center = Offset(size.width / 2, size.height / 2),
|
||||
style = Stroke(width = 5f)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (showSelectionDeleteDialog) DeleteImagesAlertDialog (
|
||||
onDismissRequest = { showSelectionDeleteDialog = false },
|
||||
onConfirmation = {
|
||||
showSelectionDeleteDialog = false
|
||||
onDeleteSelected()
|
||||
}
|
||||
)
|
||||
IconButton(
|
||||
onClick = { showSelectionDeleteDialog = true }
|
||||
) {
|
||||
} else {
|
||||
IconButton(onClick = { showSelectionDeleteDialog = true }) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Delete,
|
||||
imageVector = if (showSelectionDeleteDialog) Icons.Filled.Delete else Icons.Outlined.Delete,
|
||||
contentDescription = stringResource(R.string.select_all_images_for_deletion),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
|
||||
+8
-12
@@ -1,20 +1,16 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
|
||||
sealed class AlbumsEvent {
|
||||
data object RefreshAlbums: AlbumsEvent()
|
||||
data object DeselectSelected: AlbumsEvent()
|
||||
data object Reset: AlbumsEvent()
|
||||
data object Refresh: AlbumsEvent()
|
||||
|
||||
data class DeleteAlbumWithWallpapers(
|
||||
val albumWithWallpaperAndFolder: AlbumWithWallpaperAndFolder
|
||||
): AlbumsEvent()
|
||||
|
||||
data class ChangeAlbumName(
|
||||
val title: String,
|
||||
val albumWithWallpaperAndFolder: AlbumWithWallpaperAndFolder
|
||||
): AlbumsEvent()
|
||||
|
||||
data class InitializeAlbum(
|
||||
val albumWithWallpaperAndFolder: AlbumWithWallpaperAndFolder
|
||||
data class AddSelectedAlbum(
|
||||
val album: AlbumWithWallpaperAndFolder,
|
||||
val deselectAlbumName: String? = null,
|
||||
val shuffle: Boolean = true
|
||||
): AlbumsEvent()
|
||||
data class RemoveSelectedAlbum(val deselectAlbumName: String): AlbumsEvent()
|
||||
}
|
||||
+4
-3
@@ -2,6 +2,7 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.album
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
|
||||
data class AlbumsState (
|
||||
val albumsWithWallpapers: List<AlbumWithWallpaperAndFolder> = emptyList()
|
||||
)
|
||||
data class AlbumsState(
|
||||
val albumsWithWallpapers: List<AlbumWithWallpaperAndFolder> = emptyList(),
|
||||
val selectedAlbum: List<AlbumWithWallpaperAndFolder> = emptyList()
|
||||
)
|
||||
+132
-101
@@ -2,21 +2,22 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.album
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.core.findFirstValidUri
|
||||
import com.anthonyla.paperize.core.getFolderMetadata
|
||||
import com.anthonyla.paperize.core.getWallpaperFromFolder
|
||||
import com.anthonyla.paperize.core.isDirectory
|
||||
import com.anthonyla.paperize.core.isValidUri
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
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.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -27,126 +28,156 @@ class AlbumsViewModel @Inject constructor (
|
||||
) : AndroidViewModel(application) {
|
||||
private val context: Context
|
||||
get() = getApplication<Application>().applicationContext
|
||||
private val _state = MutableStateFlow(AlbumsState())
|
||||
val state = _state.stateIn(
|
||||
viewModelScope,
|
||||
SharingStarted.WhileSubscribed(5000), AlbumsState()
|
||||
|
||||
private val _state = MutableStateFlow<AlbumsState>(AlbumsState())
|
||||
val state = combine(
|
||||
loadAlbumsFlow(),
|
||||
loadSelectedAlbumFlow(),
|
||||
_state
|
||||
) { albums: List<AlbumWithWallpaperAndFolder>, selectedAlbum: List<AlbumWithWallpaperAndFolder>, currentState: AlbumsState ->
|
||||
currentState.copy(
|
||||
albumsWithWallpapers = albums,
|
||||
selectedAlbum = selectedAlbum
|
||||
)
|
||||
}.stateIn(
|
||||
scope = viewModelScope,
|
||||
started = SharingStarted.WhileSubscribed(5000),
|
||||
initialValue = AlbumsState()
|
||||
)
|
||||
|
||||
init {
|
||||
updateAlbums()
|
||||
refreshAlbums()
|
||||
}
|
||||
private fun loadAlbumsFlow() = repository.getAlbumsWithWallpaperAndFolder()
|
||||
private fun loadSelectedAlbumFlow() = repository.getSelectedAlbums()
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
state.collect { newState -> _state.value = newState }
|
||||
}
|
||||
}
|
||||
|
||||
fun onEvent(event: AlbumsEvent) {
|
||||
when (event) {
|
||||
is AlbumsEvent.DeleteAlbumWithWallpapers -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.cascadeDeleteAlbum(event.albumWithWallpaperAndFolder.album)
|
||||
}
|
||||
}
|
||||
is AlbumsEvent.ChangeAlbumName -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (!(_state.value.albumsWithWallpapers.any { it.album.displayedAlbumName == event.title })) {
|
||||
repository.updateAlbum(
|
||||
event.albumWithWallpaperAndFolder.album.copy(displayedAlbumName = event.title)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
is AlbumsEvent.RefreshAlbums -> {
|
||||
updateAlbums()
|
||||
refreshAlbums()
|
||||
}
|
||||
is AlbumsEvent.InitializeAlbum -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
is AlbumsEvent.AddSelectedAlbum -> {
|
||||
viewModelScope.launch {
|
||||
event.deselectAlbumName?.let { repository.updateAlbumSelection(it, false) }
|
||||
val homeWallpapers = if (event.shuffle) event.album.totalWallpapers.shuffled().map { it.wallpaperUri }
|
||||
else event.album.sortedTotalWallpapers.map { it.wallpaperUri }
|
||||
val lockWallpapers = if (event.shuffle) event.album.totalWallpapers.shuffled().map { it.wallpaperUri }
|
||||
else event.album.sortedTotalWallpapers.map { it.wallpaperUri }
|
||||
repository.updateAlbum(
|
||||
event.albumWithWallpaperAndFolder.album.copy(
|
||||
initialized = true
|
||||
event.album.album.copy(
|
||||
selected = true,
|
||||
lockWallpapersInQueue = lockWallpapers,
|
||||
homeWallpapersInQueue = homeWallpapers
|
||||
)
|
||||
)
|
||||
|
||||
_state.value.albumsWithWallpapers
|
||||
.filter { it.album.initialAlbumName != event.album.album.initialAlbumName }
|
||||
.forEach { album ->
|
||||
val otherHomeWallpapers = if (event.shuffle) album.totalWallpapers.shuffled().map { it.wallpaperUri }
|
||||
else album.sortedTotalWallpapers.map { it.wallpaperUri }
|
||||
val otherLockWallpapers = if (event.shuffle) album.totalWallpapers.shuffled().map { it.wallpaperUri }
|
||||
else album.sortedTotalWallpapers.map { it.wallpaperUri }
|
||||
repository.updateAlbum(
|
||||
album.album.copy(
|
||||
lockWallpapersInQueue = otherLockWallpapers,
|
||||
homeWallpapersInQueue = otherHomeWallpapers
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumsEvent.RemoveSelectedAlbum -> {
|
||||
viewModelScope.launch {
|
||||
repository.updateAlbumSelection(event.deselectAlbumName, false)
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumsEvent.DeselectSelected -> {
|
||||
viewModelScope.launch {
|
||||
repository.deselectAllAlbums()
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumsEvent.Refresh -> {
|
||||
viewModelScope.launch {
|
||||
updateAlbums()
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumsEvent.Reset -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
_state.update { AlbumsState() }
|
||||
viewModelScope.launch {
|
||||
repository.deleteAllData()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify and remove stale data in Room database
|
||||
*/
|
||||
private fun updateAlbums() {
|
||||
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 = DocumentFileCompat.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
|
||||
file?.exists() == true
|
||||
}
|
||||
if (invalidWallpapers.isNotEmpty()) {
|
||||
repository.deleteWallpaperList(invalidWallpapers)
|
||||
viewModelScope.launch {
|
||||
_state.value.albumsWithWallpapers.forEach { album ->
|
||||
// Remove invalid wallpapers
|
||||
val validWallpapers = async {
|
||||
album.wallpapers
|
||||
.asSequence()
|
||||
.filter { isValidUri(context, it.wallpaperUri) }
|
||||
.mapIndexed { index, wallpaper -> wallpaper.copy(order = index) }
|
||||
.toList()
|
||||
}
|
||||
|
||||
// Update folder cover uri and wallpapers uri
|
||||
albumWithWallpaper.folders.forEach { folder ->
|
||||
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 { DocumentFile.fromSingleUri(context, it.toUri()) }
|
||||
val folderCover = folderCoverFile?.takeIf { it.exists() }?.uri?.toString() ?: wallpapers.randomOrNull()
|
||||
repository.updateFolder(folder.copy(coverUri = folderCover, wallpapers = wallpapers))
|
||||
// Remove invalid folders and inner wallpapers
|
||||
val validFolders = async {
|
||||
album.folders
|
||||
.asSequence()
|
||||
.filterNot { isDirectory(context, it.folderUri) }
|
||||
.map { folder ->
|
||||
async {
|
||||
val metadata = getFolderMetadata(folder.folderUri, context)
|
||||
if (metadata.lastModified != folder.dateModified) {
|
||||
val existingWallpapers = folder.wallpapers
|
||||
.asSequence()
|
||||
.filter { isValidUri(context, it.wallpaperUri) }
|
||||
.mapIndexed { index, wallpaper -> wallpaper.copy(order = index) }
|
||||
.toList()
|
||||
val newWallpapers =
|
||||
getWallpaperFromFolder(folder.folderUri, context)
|
||||
.asSequence()
|
||||
.filterNot { new -> existingWallpapers.any { it.wallpaperUri == new.wallpaperUri } }
|
||||
.mapIndexed { index, wallpaper ->
|
||||
wallpaper.copy(
|
||||
initialAlbumName = album.album.initialAlbumName,
|
||||
order = existingWallpapers.size + 1 + index,
|
||||
key = album.album.initialAlbumName.hashCode() +
|
||||
folder.folderUri.hashCode() +
|
||||
wallpaper.wallpaperUri.hashCode()
|
||||
)
|
||||
}.toList()
|
||||
val combinedWallpapers = existingWallpapers + newWallpapers
|
||||
folder.copy(
|
||||
coverUri = combinedWallpapers.firstOrNull()?.wallpaperUri ?: "",
|
||||
wallpapers = combinedWallpapers,
|
||||
dateModified = metadata.lastModified,
|
||||
folderName = metadata.filename
|
||||
)
|
||||
}
|
||||
else { folder }
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
.toList()
|
||||
.awaitAll()
|
||||
}
|
||||
}
|
||||
albumWithWallpapers = repository.getAlbumsWithWallpaperAndFolder().first()
|
||||
albumWithWallpapers.forEach { albumWithWallpaper ->
|
||||
// Delete empty albums
|
||||
if (albumWithWallpaper.wallpapers.isEmpty() && albumWithWallpaper.folders.all { it.wallpapers.isEmpty() }) {
|
||||
repository.deleteAlbum(albumWithWallpaper.album)
|
||||
}
|
||||
else {
|
||||
// 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(context, albumWithWallpaper.wallpapers, albumWithWallpaper.folders)
|
||||
repository.updateAlbum(albumWithWallpaper.album.copy(coverUri = newCoverUri))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve albums from database into viewModel
|
||||
*/
|
||||
private fun refreshAlbums() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.getAlbumsWithWallpaperAndFolder().collect { albumWithWallpapers ->
|
||||
_state.update { it.copy(
|
||||
albumsWithWallpapers = albumWithWallpapers
|
||||
) }
|
||||
val folders = validFolders.await()
|
||||
val wallpapers = validWallpapers.await()
|
||||
val coverUri = findFirstValidUri(context, folders, wallpapers)
|
||||
repository.upsertAlbumWithWallpaperAndFolder(
|
||||
album.copy(
|
||||
album = album.album.copy(coverUri = coverUri),
|
||||
wallpapers = wallpapers,
|
||||
folders = folders
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+36
-38
@@ -1,29 +1,35 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.foundation.border
|
||||
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.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
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.text.style.TextOverflow
|
||||
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.core.decompress
|
||||
import com.anthonyla.paperize.core.isValidUri
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
@@ -36,66 +42,58 @@ fun AlbumItem(
|
||||
album: Album,
|
||||
onAlbumViewClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
animate: Boolean = true
|
||||
) {
|
||||
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 context = LocalContext.current
|
||||
val showCoverUri by remember(album.coverUri) {
|
||||
mutableStateOf(!album.coverUri.isNullOrEmpty() && isValidUri(context, album.coverUri))
|
||||
}
|
||||
|
||||
val showCoverUri = album.coverUri != null && isValidUri(LocalContext.current, album.coverUri)
|
||||
|
||||
Card(
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
.clip(RoundedCornerShape(16.dp)),
|
||||
modifier = modifier.fillMaxSize(),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
onClick = onAlbumViewClick
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(12.dp),
|
||||
verticalArrangement = Arrangement.Top,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
horizontalAlignment = Alignment.Start
|
||||
) {
|
||||
Box {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.aspectRatio(1f)
|
||||
.border(
|
||||
width = 1.dp,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.1f),
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
)
|
||||
.clip(RoundedCornerShape(12.dp)),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
if (showCoverUri) {
|
||||
GlideImage(
|
||||
imageModel = { album.coverUri },
|
||||
imageModel = {
|
||||
album.coverUri?.decompress("content://com.android.externalstorage.documents/")?.toUri()
|
||||
},
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(300, 300),
|
||||
),
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.padding(6.dp))
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
Text(
|
||||
text = album.displayedAlbumName,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 24.dp)
|
||||
.align(Alignment.Start),
|
||||
fontSize = 16.sp,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
Spacer(modifier = Modifier.padding(8.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
+80
-72
@@ -1,6 +1,5 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
@@ -10,31 +9,33 @@ import androidx.compose.foundation.combinedClickable
|
||||
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.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.wrapContentHeight
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.RadioButtonUnchecked
|
||||
import androidx.compose.material.icons.rounded.Block
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
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.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -43,6 +44,8 @@ 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.core.decompress
|
||||
import com.anthonyla.paperize.core.isValidUri
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
@@ -56,43 +59,30 @@ fun FolderItem(
|
||||
folder: Folder,
|
||||
itemSelected: Boolean,
|
||||
selectionMode: Boolean,
|
||||
onActivateSelectionMode: (Boolean) -> Unit,
|
||||
onItemSelection: () -> Unit,
|
||||
onFolderViewClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
animate: Boolean = true
|
||||
) {
|
||||
val configuration = LocalConfiguration.current
|
||||
val context = LocalContext.current
|
||||
val haptics = LocalHapticFeedback.current
|
||||
val transition = updateTransition(itemSelected, label = "")
|
||||
val transition = updateTransition(itemSelected, label = "FolderSelectionTransition")
|
||||
|
||||
val iconSelectionColor = MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp)
|
||||
val paddingTransition by transition.animateDp(label = "") { selected ->
|
||||
if (selected) 5.dp else 0.dp
|
||||
val paddingTransition by transition.animateDp(label = "FolderPaddingTransition") { selected ->
|
||||
if (selected) 4.dp else 0.dp
|
||||
}
|
||||
val roundedCornerShapeTransition by transition.animateDp(label = "") { selected ->
|
||||
val roundedCornerShapeTransition by transition.animateDp(label = "FolderRoundedCornerTransition") { selected ->
|
||||
if (selected) 24.dp else 16.dp
|
||||
}
|
||||
|
||||
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 showCoverUri = folder.coverUri != null && isValidUri(LocalContext.current, folder.coverUri)
|
||||
val showCoverUri by remember(folder.coverUri) { mutableStateOf(!folder.coverUri.isNullOrEmpty() && isValidUri(context, folder.coverUri)) }
|
||||
|
||||
Card(
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
|
||||
shape = RoundedCornerShape(roundedCornerShapeTransition),
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingTransition)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (!selectionMode) {
|
||||
@@ -104,80 +94,98 @@ fun FolderItem(
|
||||
onLongClick = {
|
||||
if (!selectionMode) {
|
||||
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onActivateSelectionMode(true)
|
||||
onItemSelection()
|
||||
}
|
||||
}
|
||||
),
|
||||
shape = RoundedCornerShape(roundedCornerShapeTransition),
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(12.dp),
|
||||
verticalArrangement = Arrangement.Top,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Box {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxHeight(0.8f)
|
||||
.fillMaxWidth()
|
||||
.border(
|
||||
width = 1.dp,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.1f),
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
)
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
) {
|
||||
if (showCoverUri) {
|
||||
GlideImage(
|
||||
imageModel = { folder.coverUri?.toUri() },
|
||||
imageModel = { folder.coverUri?.decompress("content://com.android.externalstorage.documents/")?.toUri() },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(300, 300),
|
||||
),
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(0.8f)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
}
|
||||
if (selectionMode) {
|
||||
if (itemSelected) {
|
||||
} else {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.CheckCircle,
|
||||
contentDescription = stringResource(R.string.image_is_selected),
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(2.dp, iconSelectionColor, CircleShape)
|
||||
.clip(CircleShape)
|
||||
.background(iconSelectionColor)
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
imageVector = Icons.Default.RadioButtonUnchecked,
|
||||
imageVector = Icons.Rounded.Block,
|
||||
contentDescription = stringResource(R.string.image_is_not_selected),
|
||||
tint = Color.White.copy(alpha = 0.7f),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(16.dp),
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.4f)
|
||||
)
|
||||
}
|
||||
}
|
||||
if (selectionMode) {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
if (itemSelected) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.CheckCircle,
|
||||
contentDescription = stringResource(R.string.image_is_selected),
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopStart)
|
||||
.padding(9.dp)
|
||||
.border(2.dp, iconSelectionColor, CircleShape)
|
||||
.clip(CircleShape)
|
||||
.background(iconSelectionColor)
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
imageVector = Icons.Default.RadioButtonUnchecked,
|
||||
contentDescription = stringResource(R.string.image_is_not_selected),
|
||||
tint = Color.White.copy(alpha = 0.7f),
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopStart)
|
||||
.padding(6.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.padding(6.dp))
|
||||
folder.folderName?.let { name ->
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier
|
||||
.align(Alignment.Start)
|
||||
.fillMaxHeight()
|
||||
.wrapContentHeight(Alignment.CenterVertically),
|
||||
) {
|
||||
folder.folderName?.let { name ->
|
||||
Text(
|
||||
text = name,
|
||||
modifier = Modifier,
|
||||
fontSize = 16.sp,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = name,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 24.dp)
|
||||
.align(Alignment.Start),
|
||||
fontSize = 16.sp,
|
||||
text = folder.wallpapers.size.toString().plus(" " + stringResource(R.string.wallpapers)),
|
||||
fontSize = 12.sp,
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
}
|
||||
Text(
|
||||
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,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
Spacer(modifier = Modifier.padding(8.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
+37
-89
@@ -1,6 +1,5 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
@@ -8,40 +7,34 @@ import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.RadioButtonUnchecked
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember // Added
|
||||
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 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.DecodeFormat
|
||||
import com.anthonyla.paperize.core.decompress
|
||||
import com.anthonyla.paperize.core.isValidUri
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
|
||||
@@ -54,44 +47,37 @@ fun WallpaperItem(
|
||||
wallpaperUri: String,
|
||||
itemSelected: Boolean,
|
||||
selectionMode: Boolean,
|
||||
onActivateSelectionMode: (Boolean) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
allowHapticFeedback: Boolean = true,
|
||||
onItemSelection: () -> Unit,
|
||||
onWallpaperViewClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
aspectRatio: Float? = null,
|
||||
clickable: 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
|
||||
val transition = updateTransition(itemSelected, label = "")
|
||||
|
||||
val paddingTransition by transition.animateDp(label = "") { selected ->
|
||||
val showUri by remember(wallpaperUri) { mutableStateOf(isValidUri(context, wallpaperUri)) }
|
||||
val decompressedUri by remember(wallpaperUri) {
|
||||
mutableStateOf(wallpaperUri.decompress("content://com.android.externalstorage.documents/").toUri())
|
||||
}
|
||||
|
||||
val imageOptions = remember {
|
||||
ImageOptions(
|
||||
requestSize = IntSize(200, 200),
|
||||
alignment = Alignment.Center,
|
||||
)
|
||||
}
|
||||
|
||||
val transition = updateTransition(itemSelected, label = "WallpaperItemSelection")
|
||||
|
||||
val paddingTransition by transition.animateDp(label = "padding") { selected ->
|
||||
if (selected) 5.dp else 0.dp
|
||||
}
|
||||
val roundedCornerShapeTransition by transition.animateDp(label = "") { selected ->
|
||||
val roundedCornerShapeTransition by transition.animateDp(label = "roundedCornerShape") { selected ->
|
||||
if (selected) 24.dp else 16.dp
|
||||
}
|
||||
|
||||
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 showUri = isValidUri(LocalContext.current, wallpaperUri)
|
||||
val boxModifier = if (clickable) {
|
||||
modifier
|
||||
Box(
|
||||
modifier = modifier
|
||||
.padding(paddingTransition)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.combinedClickable(
|
||||
@@ -104,60 +90,18 @@ fun WallpaperItem(
|
||||
},
|
||||
onLongClick = {
|
||||
if (!selectionMode) {
|
||||
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onActivateSelectionMode(true)
|
||||
if (allowHapticFeedback) haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onItemSelection()
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
modifier
|
||||
.padding(paddingTransition)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
}
|
||||
Box(modifier = boxModifier) {
|
||||
) {
|
||||
if (showUri) {
|
||||
val dimension = wallpaperUri.toUri().getImageDimensions(context)
|
||||
val imageAspectRatio = aspectRatio ?: ((dimension?.width?.toFloat() ?: 9f) / (dimension?.height?.toFloat() ?: 19.5f))
|
||||
GlideImage(
|
||||
imageModel = { wallpaperUri },
|
||||
imageOptions = ImageOptions(
|
||||
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 }
|
||||
),
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
}
|
||||
}
|
||||
},
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.format(DecodeFormat.PREFER_RGB_565)
|
||||
},
|
||||
imageModel = { decompressedUri },
|
||||
imageOptions = imageOptions,
|
||||
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 })
|
||||
.fillMaxSize()
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
)
|
||||
}
|
||||
@@ -167,18 +111,22 @@ fun WallpaperItem(
|
||||
Icon(
|
||||
imageVector = Icons.Default.CheckCircle,
|
||||
contentDescription = stringResource(R.string.image_is_selected),
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(2.dp, bgColor, CircleShape)
|
||||
.padding(9.dp)
|
||||
.clip(CircleShape)
|
||||
.background(bgColor)
|
||||
.border(2.dp, bgColor, CircleShape)
|
||||
.align(Alignment.TopEnd)
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
imageVector = Icons.Default.RadioButtonUnchecked,
|
||||
contentDescription = stringResource(R.string.image_is_not_selected),
|
||||
tint = Color.White.copy(alpha = 0.7f),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
modifier = Modifier
|
||||
.padding(6.dp)
|
||||
.align(Alignment.TopEnd)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+354
@@ -0,0 +1,354 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen
|
||||
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.core.compress
|
||||
import com.anthonyla.paperize.core.getFolderMetadata
|
||||
import com.anthonyla.paperize.core.getImageMetadata
|
||||
import com.anthonyla.paperize.core.getWallpaperFromFolder
|
||||
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.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.SelectionState
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
import kotlin.collections.plus
|
||||
|
||||
@HiltViewModel
|
||||
class AlbumScreenViewModel @Inject constructor(
|
||||
application: Application,
|
||||
private val repository: AlbumRepository,
|
||||
) : AndroidViewModel(application) {
|
||||
private val context: Context
|
||||
get() = getApplication<Application>().applicationContext
|
||||
private val _state = MutableStateFlow<AlbumViewState>(AlbumViewState())
|
||||
val state = combine(
|
||||
loadAlbumsFlow(),
|
||||
_state
|
||||
) { albums: List<AlbumWithWallpaperAndFolder>, currentState: AlbumViewState ->
|
||||
currentState.copy(albums = albums)
|
||||
}.stateIn(
|
||||
scope = viewModelScope,
|
||||
started = SharingStarted.WhileSubscribed(5000),
|
||||
initialValue = AlbumViewState()
|
||||
)
|
||||
|
||||
private fun loadAlbumsFlow() = repository.getAlbumsWithWallpaperAndFolder()
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
state.collect { newState -> _state.value = newState }
|
||||
}
|
||||
}
|
||||
|
||||
fun onEvent(event: AlbumViewEvent) {
|
||||
when (event) {
|
||||
is AlbumViewEvent.LoadAlbum -> {
|
||||
viewModelScope.launch {
|
||||
_state.update {
|
||||
it.copy(initialAlbumName = event.initialAlbumName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.AddWallpapers -> {
|
||||
viewModelScope.launch {
|
||||
if (event.wallpaperUris.isEmpty()) { return@launch }
|
||||
val album = _state.value.albums.find { it.album.initialAlbumName == _state.value.initialAlbumName }
|
||||
if (album == null) { return@launch }
|
||||
val existingUris = album.wallpapers.map { it.wallpaperUri }
|
||||
val newUris = event.wallpaperUris.filter { it !in existingUris }
|
||||
if (newUris.isEmpty()) { return@launch }
|
||||
val wallpapers = newUris.mapIndexed { index, uri ->
|
||||
val metadata = getImageMetadata(context, uri)
|
||||
Wallpaper(
|
||||
initialAlbumName = _state.value.initialAlbumName,
|
||||
wallpaperUri = uri.compress("content://com.android.externalstorage.documents/"),
|
||||
fileName = metadata.filename,
|
||||
dateModified = metadata.lastModified,
|
||||
order = if (album.wallpapers.isEmpty()) 0 else album.wallpapers.size + index,
|
||||
key = _state.value.initialAlbumName.hashCode() + uri.hashCode()
|
||||
)
|
||||
}
|
||||
var totalWallpapers = album.wallpapers.size + wallpapers.size
|
||||
val folders = album.folders.map { folder ->
|
||||
val updatedWallpapers = folder.wallpapers.mapIndexed { index, wallpaper ->
|
||||
wallpaper.copy(
|
||||
order = index + totalWallpapers
|
||||
)
|
||||
}
|
||||
totalWallpapers += folder.wallpapers.size
|
||||
folder.copy(
|
||||
wallpapers = updatedWallpapers
|
||||
)
|
||||
}
|
||||
val albumWithWallpaperAndFolder = album.copy(
|
||||
wallpapers = album.wallpapers + wallpapers,
|
||||
folders = folders
|
||||
)
|
||||
repository.upsertAlbumWithWallpaperAndFolder(albumWithWallpaperAndFolder)
|
||||
_state.update {
|
||||
it.copy(
|
||||
isEmpty = false,
|
||||
selectionState = SelectionState(),
|
||||
isLoading = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.AddFolder -> {
|
||||
viewModelScope.launch {
|
||||
val album = _state.value.albums.find { it.album.initialAlbumName == _state.value.initialAlbumName }
|
||||
if (album == null || album.folders.any { it.folderUri == event.directoryUri }) { return@launch }
|
||||
_state.update { it.copy(isLoading = true) }
|
||||
val wallpapers = getWallpaperFromFolder(event.directoryUri, context).mapIndexed { index, wallpaper ->
|
||||
wallpaper.copy(
|
||||
initialAlbumName = _state.value.initialAlbumName,
|
||||
key = _state.value.initialAlbumName.hashCode() + event.directoryUri.hashCode() + wallpaper.wallpaperUri.hashCode(),
|
||||
order = index + album.wallpapers.size + album.folders.sumOf { it.wallpapers.size }
|
||||
)
|
||||
}
|
||||
val metadata = getFolderMetadata(event.directoryUri, context)
|
||||
val folder = Folder(
|
||||
initialAlbumName = _state.value.initialAlbumName,
|
||||
folderUri = event.directoryUri,
|
||||
folderName = metadata.filename,
|
||||
coverUri = wallpapers.map { it.wallpaperUri }.firstOrNull() ?: "",
|
||||
dateModified = metadata.lastModified,
|
||||
wallpapers = wallpapers,
|
||||
order = album.folders.size,
|
||||
key = _state.value.initialAlbumName.hashCode() + event.directoryUri.hashCode()
|
||||
)
|
||||
repository.upsertFolder(folder)
|
||||
_state.update {
|
||||
it.copy(
|
||||
isEmpty = false,
|
||||
selectionState = SelectionState(),
|
||||
isLoading = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.ChangeAlbumName -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.albums.any { it.album.displayedAlbumName == event.displayName }) {
|
||||
val album = _state.value.albums.find { it.album.initialAlbumName == _state.value.initialAlbumName }
|
||||
if (album == null) { return@launch }
|
||||
repository.updateAlbum(
|
||||
album.album.copy(displayedAlbumName = event.displayName)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.SelectWallpaper -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.selectionState.selectedWallpapers.contains(event.wallpaperUri)) {
|
||||
val album = _state.value.albums.find { it.album.initialAlbumName == _state.value.initialAlbumName }
|
||||
if (album == null) { return@launch }
|
||||
_state.update {
|
||||
val newSelectedWallpapers = it.selectionState.selectedWallpapers.plus(event.wallpaperUri)
|
||||
it.copy(
|
||||
selectionState = it.selectionState.copy(
|
||||
selectedWallpapers = newSelectedWallpapers,
|
||||
selectedCount = newSelectedWallpapers.size + it.selectionState.selectedFolders.size,
|
||||
allSelected = it.selectionState.selectedFolders.size + newSelectedWallpapers.size >=
|
||||
album.folders.size + album.wallpapers.size
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.SelectFolder -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.selectionState.selectedFolders.contains(event.directoryUri)) {
|
||||
val album = _state.value.albums.find { it.album.initialAlbumName == _state.value.initialAlbumName }
|
||||
if (album == null) { return@launch }
|
||||
_state.update {
|
||||
val newSelectedFolders = it.selectionState.selectedFolders.plus(event.directoryUri)
|
||||
it.copy(
|
||||
selectionState = it.selectionState.copy(
|
||||
selectedFolders = newSelectedFolders,
|
||||
selectedCount = newSelectedFolders.size + it.selectionState.selectedWallpapers.size,
|
||||
allSelected = newSelectedFolders.size + it.selectionState.selectedWallpapers.size >=
|
||||
album.folders.size + album.wallpapers.size
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.DeselectFolder -> {
|
||||
viewModelScope.launch {
|
||||
if (_state.value.selectionState.selectedFolders.contains(event.directoryUri)) {
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectionState = it.selectionState.copy(
|
||||
selectedFolders = it.selectionState.selectedFolders.minus(event.directoryUri),
|
||||
selectedCount = it.selectionState.selectedCount - 1,
|
||||
allSelected = false
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.DeselectWallpaper -> {
|
||||
viewModelScope.launch {
|
||||
if (_state.value.selectionState.selectedWallpapers.contains(event.wallpaperUri)) {
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectionState = it.selectionState.copy(
|
||||
selectedWallpapers = it.selectionState.selectedWallpapers.minus(event.wallpaperUri),
|
||||
selectedCount = it.selectionState.selectedCount - 1,
|
||||
allSelected = false
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.DeleteSelected -> {
|
||||
viewModelScope.launch {
|
||||
val album = _state.value.albums.find { it.album.initialAlbumName == _state.value.initialAlbumName }
|
||||
if (album == null) { return@launch }
|
||||
val selectedFolders = _state.value.selectionState.selectedFolders
|
||||
val selectedWallpapers = _state.value.selectionState.selectedWallpapers
|
||||
val foldersToDelete = album.folders.filter { selectedFolders.contains(it.folderUri) }
|
||||
val wallpapersToDelete = album.wallpapers.filter { selectedWallpapers.contains(it.wallpaperUri) }
|
||||
if (foldersToDelete.size + wallpapersToDelete.size == album.folders.size + album.wallpapers.size) {
|
||||
repository.cascadeDeleteAlbum(album.album)
|
||||
}
|
||||
else {
|
||||
repository.deleteFolderList(foldersToDelete)
|
||||
repository.deleteWallpaperList(wallpapersToDelete)
|
||||
if (album.album.coverUri in (foldersToDelete.map { it.folderUri } + wallpapersToDelete.map { it.wallpaperUri })) {
|
||||
val newCover = album.folders.minus(foldersToDelete.toSet()).firstOrNull()?.coverUri ?: album.wallpapers.minus(wallpapersToDelete.toSet()
|
||||
).firstOrNull()?.wallpaperUri ?: ""
|
||||
repository.updateAlbum(album.album.copy(coverUri = newCover))
|
||||
}
|
||||
|
||||
val remainingWallpapers = album.wallpapers.minus(wallpapersToDelete.toSet())
|
||||
val newWallpapers = remainingWallpapers.sortedBy { it.order }.mapIndexed { index, wallpaper ->
|
||||
wallpaper.copy(order = index)
|
||||
}
|
||||
|
||||
val remainingFolders = album.folders.minus(foldersToDelete.toSet())
|
||||
var totalWallpaper = newWallpapers.size
|
||||
val newFolders = remainingFolders.sortedBy { it.order }.mapIndexed { folderIndex, folder ->
|
||||
val updatedWallpapers = folder.wallpapers.mapIndexed { index, wallpaper ->
|
||||
wallpaper.copy(order = index + totalWallpaper)
|
||||
}
|
||||
totalWallpaper += folder.wallpapers.size
|
||||
folder.copy(
|
||||
wallpapers = updatedWallpapers,
|
||||
order = folderIndex
|
||||
)
|
||||
}
|
||||
|
||||
repository.upsertAlbumWithWallpaperAndFolder(
|
||||
album.copy(
|
||||
folders = newFolders,
|
||||
wallpapers = newWallpapers
|
||||
)
|
||||
)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectionState = SelectionState(),
|
||||
isLoading = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.Reset -> {
|
||||
viewModelScope.launch {
|
||||
_state.update { AlbumViewState() }
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.SelectAll -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.selectionState.allSelected) {
|
||||
val album = _state.value.albums.find { it.album.initialAlbumName == _state.value.initialAlbumName }
|
||||
if (album == null) { return@launch }
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectionState = SelectionState(
|
||||
selectedFolders = album.folders.map { it.folderUri },
|
||||
selectedWallpapers = album.wallpapers.map { it.wallpaperUri },
|
||||
allSelected = true,
|
||||
selectedCount = album.folders.size + album.wallpapers.size
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.DeselectAll -> {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(selectionState = SelectionState()) }
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.SetLoading -> {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(isLoading = event.isLoading) }
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.LoadFoldersAndWallpapers -> {
|
||||
viewModelScope.launch {
|
||||
_state.update { state ->
|
||||
val album = _state.value.albums.find { it.album.initialAlbumName == _state.value.initialAlbumName }
|
||||
if (album == null) { return@launch }
|
||||
repository.upsertAlbumWithWallpaperAndFolder(
|
||||
AlbumWithWallpaperAndFolder(
|
||||
album = album.album.copy(
|
||||
coverUri = event.folders.firstOrNull()?.coverUri ?: event.wallpapers.firstOrNull()?.wallpaperUri ?: ""
|
||||
),
|
||||
folders = event.folders.map {
|
||||
it.copy(coverUri = it.wallpapers.firstOrNull()?.wallpaperUri ?: "")
|
||||
},
|
||||
wallpapers = event.wallpapers
|
||||
)
|
||||
)
|
||||
state.copy(
|
||||
selectionState = SelectionState(),
|
||||
isLoading = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.DeleteAlbum -> {
|
||||
viewModelScope.launch {
|
||||
val album = _state.value.albums.find { it.album.initialAlbumName == _state.value.initialAlbumName }
|
||||
if (album == null) { return@launch }
|
||||
repository.cascadeDeleteAlbum(album.album)
|
||||
_state.update { AlbumViewState() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+21
-17
@@ -1,41 +1,45 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen
|
||||
|
||||
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.presentation.add_album_screen.AddAlbumEvent
|
||||
|
||||
sealed class AlbumViewEvent {
|
||||
data object ClearState: AlbumViewEvent()
|
||||
data class SelectAll(
|
||||
val albumsWithWallpaper: AlbumWithWallpaperAndFolder
|
||||
): AlbumViewEvent()
|
||||
data object Reset: AlbumViewEvent()
|
||||
data object SelectAll: AlbumViewEvent()
|
||||
data object DeselectAll: AlbumViewEvent()
|
||||
data class DeleteSelected(
|
||||
val albumsWithWallpaper: AlbumWithWallpaperAndFolder
|
||||
): AlbumViewEvent()
|
||||
data object DeleteSelected: AlbumViewEvent()
|
||||
data object DeleteAlbum: AlbumViewEvent()
|
||||
|
||||
data class LoadAlbum(
|
||||
val initialAlbumName: String
|
||||
): AlbumViewEvent()
|
||||
data class AddWallpapers(
|
||||
val album: AlbumWithWallpaperAndFolder,
|
||||
val wallpaperUris: List<String>
|
||||
): AlbumViewEvent()
|
||||
|
||||
data class AddFolder(
|
||||
val album: AlbumWithWallpaperAndFolder,
|
||||
val directoryUri: String
|
||||
): AlbumViewEvent()
|
||||
|
||||
data class SelectWallpaper(
|
||||
val wallpaperUri: String
|
||||
): AlbumViewEvent()
|
||||
data class SelectFolder(
|
||||
val directoryUri: String
|
||||
): AlbumViewEvent()
|
||||
|
||||
data class RemoveFolderFromSelection(
|
||||
data class DeselectFolder(
|
||||
val directoryUri: String
|
||||
): AlbumViewEvent()
|
||||
data class RemoveWallpaperFromSelection(
|
||||
data class DeselectWallpaper(
|
||||
val wallpaperUri: String
|
||||
): AlbumViewEvent()
|
||||
data class SetSize(
|
||||
val size: Int
|
||||
data class ChangeAlbumName(
|
||||
val displayName: String
|
||||
): AlbumViewEvent()
|
||||
data class SetLoading(
|
||||
val isLoading: Boolean
|
||||
): AlbumViewEvent()
|
||||
data class LoadFoldersAndWallpapers(
|
||||
val folders: List<Folder>,
|
||||
val wallpapers: List<Wallpaper>
|
||||
): AlbumViewEvent()
|
||||
}
|
||||
+299
-207
@@ -5,68 +5,109 @@ import android.net.Uri
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.scaleIn
|
||||
import androidx.compose.animation.scaleOut
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.items
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
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.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumAnimatedFab
|
||||
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
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import my.nanihadesuka.compose.LazyVerticalGridScrollbar
|
||||
import my.nanihadesuka.compose.ScrollbarSettings
|
||||
|
||||
@Composable
|
||||
fun AlbumViewScreen(
|
||||
albumViewScreenViewModel: AlbumViewScreenViewModel = hiltViewModel(),
|
||||
settingsViewModel: SettingsViewModel = hiltViewModel(),
|
||||
album: AlbumWithWallpaperAndFolder,
|
||||
albumScreenViewModel: AlbumScreenViewModel,
|
||||
animate: Boolean,
|
||||
onBackClick: () -> Unit,
|
||||
onShowWallpaperView: (String) -> Unit,
|
||||
onShowFolderView: (String?, List<String>) -> Unit,
|
||||
onShowWallpaperView: (String, String) -> Unit,
|
||||
onShowFolderView: (Folder) -> Unit,
|
||||
onDeleteAlbum: () -> Unit,
|
||||
onTitleChange: (String, AlbumWithWallpaperAndFolder) -> Unit,
|
||||
onSelectionDeleted: () -> Unit,
|
||||
onSortClick: (List<Folder>, List<Wallpaper>) -> Unit,
|
||||
) {
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.SetSize(album.wallpapers.size + album.folders.size)) // For selectedAll state
|
||||
val lazyListState = rememberLazyStaggeredGridState()
|
||||
val albumState = albumViewScreenViewModel.state.collectAsStateWithLifecycle()
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
var selectionMode by rememberSaveable { mutableStateOf(false) }
|
||||
val context = LocalContext.current
|
||||
val scope = rememberCoroutineScope()
|
||||
val lazyListState = rememberLazyGridState()
|
||||
|
||||
val albumViewState by albumScreenViewModel.state.collectAsStateWithLifecycle()
|
||||
|
||||
val album = remember(albumViewState.albums, albumViewState.initialAlbumName) {
|
||||
albumViewState.albums.find { it.album.initialAlbumName == albumViewState.initialAlbumName }
|
||||
}
|
||||
|
||||
val colorScheme = MaterialTheme.colorScheme
|
||||
val scrollbarSettings = remember {
|
||||
ScrollbarSettings.Default.copy(
|
||||
thumbUnselectedColor = colorScheme.primary,
|
||||
thumbSelectedColor = colorScheme.primary,
|
||||
thumbShape = RoundedCornerShape(16.dp),
|
||||
scrollbarPadding = 1.dp,
|
||||
)
|
||||
}
|
||||
|
||||
val commonItemModifier = remember {
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.aspectRatio(9f / 16f)
|
||||
}
|
||||
|
||||
BackHandler(
|
||||
enabled = albumViewState.selectionState.selectedCount > 0,
|
||||
onBack = remember(albumViewState.isLoading, albumScreenViewModel) {
|
||||
{
|
||||
if (!albumViewState.isLoading) {
|
||||
albumScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/** Image picker **/
|
||||
val imagePickerLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.OpenMultipleDocuments(),
|
||||
onResult = { uris: List<Uri> ->
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
val uriList = uris.mapNotNull { uri ->
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
|
||||
if (persistedUriPermissions.any { it.uri == uri }) uri.toString() else null
|
||||
}
|
||||
if (uriList.isNotEmpty()) {
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.AddWallpapers(album, uriList))
|
||||
onResult = remember(albumScreenViewModel, scope, context) {
|
||||
{ uris: List<Uri> ->
|
||||
scope.launch(Dispatchers.IO) {
|
||||
albumScreenViewModel.onEvent(AlbumViewEvent.SetLoading(true))
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
val uriList = uris.mapNotNull { uri ->
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
|
||||
if (persistedUriPermissions.any { it.uri == uri }) uri.toString() else null
|
||||
}
|
||||
if (uriList.isNotEmpty()) {
|
||||
withContext(Dispatchers.Main) {
|
||||
albumScreenViewModel.onEvent(AlbumViewEvent.AddWallpapers(uriList))
|
||||
}
|
||||
}
|
||||
albumScreenViewModel.onEvent(AlbumViewEvent.SetLoading(false))
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -74,204 +115,255 @@ fun AlbumViewScreen(
|
||||
/** Folder picker **/
|
||||
val folderPickerLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.OpenDocumentTree(),
|
||||
onResult = { uri: Uri? ->
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
if (uri != null) {
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
|
||||
if (persistedUriPermissions.any { it.uri == uri }) {
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.AddFolder(album, uri.toString()))
|
||||
onResult = remember(albumScreenViewModel, scope, context) {
|
||||
{ uri: Uri? ->
|
||||
scope.launch(Dispatchers.IO) {
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
if (uri != null) {
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
|
||||
if (persistedUriPermissions.any { it.uri == uri }) {
|
||||
albumScreenViewModel.onEvent(AlbumViewEvent.AddFolder(uri.toString()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
BackHandler(
|
||||
enabled = selectionMode,
|
||||
onBack = {
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
selectionMode = false
|
||||
}
|
||||
)
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
AlbumViewTopBar(
|
||||
title = album.album.displayedAlbumName,
|
||||
selectionMode = selectionMode,
|
||||
albumState = albumViewScreenViewModel.state,
|
||||
onBackClick = {
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.ClearState)
|
||||
onBackClick()
|
||||
},
|
||||
onDeleteAlbum = onDeleteAlbum,
|
||||
onTitleChange = { onTitleChange(it, album) },
|
||||
onSelectAllClick = {
|
||||
if (!albumState.value.allSelected) albumViewScreenViewModel.onEvent(AlbumViewEvent.SelectAll(album))
|
||||
else albumViewScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
},
|
||||
onDeleteSelected = {
|
||||
selectionMode = false
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.DeleteSelected(album))
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
onSelectionDeleted()
|
||||
val onSelectAllClick = remember(
|
||||
albumViewState.isLoading,
|
||||
albumViewState.selectionState.allSelected,
|
||||
albumScreenViewModel
|
||||
) {
|
||||
{
|
||||
if (!albumViewState.isLoading) {
|
||||
if (!albumViewState.selectionState.allSelected) albumScreenViewModel.onEvent(
|
||||
AlbumViewEvent.SelectAll
|
||||
)
|
||||
else albumScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val onBackClickTopBar = remember(albumScreenViewModel, onBackClick) {
|
||||
{
|
||||
albumScreenViewModel.onEvent(AlbumViewEvent.Reset)
|
||||
onBackClick()
|
||||
}
|
||||
}
|
||||
|
||||
val onDeleteSelected = remember(
|
||||
albumViewState.isLoading,
|
||||
album,
|
||||
albumViewState.selectionState.selectedCount,
|
||||
albumScreenViewModel,
|
||||
onBackClick
|
||||
) {
|
||||
{
|
||||
if (!albumViewState.isLoading) {
|
||||
if (album != null) {
|
||||
if (album.folders.size + album.wallpapers.size == albumViewState.selectionState.selectedCount) {
|
||||
onBackClick()
|
||||
}
|
||||
albumScreenViewModel.onEvent(AlbumViewEvent.DeleteSelected)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val onDeleteAlbumTopBar = remember(
|
||||
albumViewState.isLoading,
|
||||
album,
|
||||
albumScreenViewModel,
|
||||
onDeleteAlbum
|
||||
) {
|
||||
{
|
||||
if (!albumViewState.isLoading && album != null) {
|
||||
albumScreenViewModel.onEvent(AlbumViewEvent.DeleteAlbum)
|
||||
onDeleteAlbum()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val onTitleChangeTopBar: (String) -> Unit = remember(
|
||||
albumViewState.isLoading,
|
||||
album,
|
||||
albumScreenViewModel
|
||||
) {
|
||||
{ newTitle ->
|
||||
if (!albumViewState.isLoading && album != null) {
|
||||
albumScreenViewModel.onEvent(AlbumViewEvent.ChangeAlbumName(newTitle))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val onSortClickTopBar = remember(
|
||||
albumViewState.isLoading,
|
||||
album,
|
||||
onSortClick
|
||||
) {
|
||||
{
|
||||
if (!albumViewState.isLoading && album != null) {
|
||||
onSortClick(album.folders, album.wallpapers)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AlbumViewTopBar(
|
||||
title = album?.album?.displayedAlbumName ?: "",
|
||||
allSelected = albumViewState.selectionState.allSelected,
|
||||
selectedCount = albumViewState.selectionState.selectedCount,
|
||||
selectionMode = albumViewState.selectionState.selectedCount > 0,
|
||||
isLoad = albumViewState.isLoading,
|
||||
onSelectAllClick = onSelectAllClick,
|
||||
onBackClick = onBackClickTopBar,
|
||||
onDeleteSelected = onDeleteSelected,
|
||||
onDeleteAlbum = onDeleteAlbumTopBar,
|
||||
onTitleChange = onTitleChangeTopBar,
|
||||
onSortClick = onSortClickTopBar
|
||||
)
|
||||
},
|
||||
floatingActionButton = {
|
||||
if (settingsState.value.animate) {
|
||||
AnimatedVisibility(
|
||||
visible = !lazyListState.isScrollInProgress || lazyListState.firstVisibleItemScrollOffset < 0,
|
||||
enter = scaleIn(tween(400, 50, FastOutSlowInEasing)),
|
||||
exit = scaleOut(tween(400, 50, FastOutSlowInEasing)),
|
||||
) {
|
||||
AddAlbumAnimatedFab(
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
},
|
||||
animate = true
|
||||
)
|
||||
val onImageClickFab = remember(albumScreenViewModel, imagePickerLauncher) {
|
||||
{
|
||||
albumScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
}
|
||||
}
|
||||
else {
|
||||
AddAlbumAnimatedFab(
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
},
|
||||
animate = false
|
||||
)
|
||||
val onFolderClickFab = remember(albumScreenViewModel, folderPickerLauncher) {
|
||||
{
|
||||
albumScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
folderPickerLauncher.launch(null)
|
||||
}
|
||||
}
|
||||
|
||||
AddAlbumAnimatedFab(
|
||||
isLoading = albumViewState.isLoading,
|
||||
animate = animate,
|
||||
onImageClick = onImageClickFab,
|
||||
onFolderClick = onFolderClickFab
|
||||
)
|
||||
},
|
||||
bottomBar = {
|
||||
if (albumViewState.isLoading) {
|
||||
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
||||
}
|
||||
},
|
||||
content = { it ->
|
||||
LazyVerticalStaggeredGrid(
|
||||
state = lazyListState,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(it),
|
||||
columns = StaggeredGridCells.Fixed(2),
|
||||
contentPadding = PaddingValues(4.dp, 4.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
content = {
|
||||
items (items = album.folders, key = { folder -> folder.folderUri }
|
||||
) { folder ->
|
||||
if (settingsState.value.animate) {
|
||||
FolderItem(
|
||||
folder = folder,
|
||||
itemSelected = albumState.value.selectedFolders.contains(folder.folderUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
albumViewScreenViewModel.onEvent(
|
||||
if (!albumState.value.selectedFolders.contains(folder.folderUri))
|
||||
AlbumViewEvent.SelectFolder(folder.folderUri)
|
||||
else {
|
||||
AlbumViewEvent.RemoveFolderFromSelection(folder.folderUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onFolderViewClick = {
|
||||
if (folder.wallpapers.isNotEmpty()) onShowFolderView(folder.folderName, folder.wallpapers)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
),
|
||||
animate = true
|
||||
)
|
||||
}
|
||||
else {
|
||||
FolderItem(
|
||||
folder = folder,
|
||||
itemSelected = albumState.value.selectedFolders.contains(folder.folderUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
albumViewScreenViewModel.onEvent(
|
||||
if (!albumState.value.selectedFolders.contains(folder.folderUri))
|
||||
AlbumViewEvent.SelectFolder(folder.folderUri)
|
||||
else {
|
||||
AlbumViewEvent.RemoveFolderFromSelection(folder.folderUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onFolderViewClick = {
|
||||
if (folder.wallpapers.isNotEmpty()) onShowFolderView(folder.folderName, folder.wallpapers)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp),
|
||||
animate = false
|
||||
)
|
||||
}
|
||||
}
|
||||
items (items = album.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri }
|
||||
) { wallpaper ->
|
||||
if (settingsState.value.animate) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper.wallpaperUri,
|
||||
itemSelected = albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
albumViewScreenViewModel.onEvent(
|
||||
if (!albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri))
|
||||
AlbumViewEvent.SelectWallpaper(wallpaper.wallpaperUri)
|
||||
else {
|
||||
AlbumViewEvent.RemoveWallpaperFromSelection(wallpaper.wallpaperUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper.wallpaperUri)
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
content = { paddingValues ->
|
||||
if (album != null) {
|
||||
LazyVerticalGridScrollbar(
|
||||
state = lazyListState,
|
||||
settings = scrollbarSettings,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues),
|
||||
) {
|
||||
LazyVerticalGrid(
|
||||
state = lazyListState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
columns = GridCells.Adaptive(150.dp),
|
||||
contentPadding = PaddingValues(4.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
items(
|
||||
items = album.folders,
|
||||
key = { folder -> folder.folderUri }
|
||||
) { folder ->
|
||||
val isSelected = albumViewState.selectionState.selectedFolders.contains(folder.folderUri)
|
||||
val onFolderItemSelection = remember(
|
||||
folder.folderUri,
|
||||
albumViewState.isLoading,
|
||||
albumViewState.selectionState.selectedFolders
|
||||
) {
|
||||
{
|
||||
if (!albumViewState.isLoading) {
|
||||
albumScreenViewModel.onEvent(
|
||||
if (!isSelected) AlbumViewEvent.SelectFolder(folder.folderUri)
|
||||
else AlbumViewEvent.DeselectFolder(folder.folderUri)
|
||||
)
|
||||
),
|
||||
animate = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val onFolderViewClickItem = remember(folder, albumViewState.isLoading, onShowFolderView) {
|
||||
{
|
||||
if (!albumViewState.isLoading) {
|
||||
onShowFolderView(folder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FolderItem(
|
||||
folder = folder,
|
||||
itemSelected = isSelected,
|
||||
selectionMode = albumViewState.selectionState.selectedCount > 0,
|
||||
onItemSelection = onFolderItemSelection,
|
||||
onFolderViewClick = onFolderViewClickItem,
|
||||
modifier = commonItemModifier
|
||||
.then(
|
||||
if (animate) Modifier.animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
)
|
||||
) else Modifier
|
||||
)
|
||||
)
|
||||
}
|
||||
else {
|
||||
|
||||
items(
|
||||
items = album.wallpapers,
|
||||
key = { wallpaper -> wallpaper.wallpaperUri }
|
||||
) { wallpaper ->
|
||||
val isSelected = albumViewState.selectionState.selectedWallpapers.contains(wallpaper.wallpaperUri)
|
||||
val onWallpaperItemSelection = remember(
|
||||
wallpaper.wallpaperUri,
|
||||
albumViewState.isLoading,
|
||||
albumViewState.selectionState.selectedWallpapers
|
||||
) {
|
||||
{
|
||||
if (!albumViewState.isLoading) {
|
||||
albumScreenViewModel.onEvent(
|
||||
if (!isSelected) AlbumViewEvent.SelectWallpaper(wallpaper.wallpaperUri)
|
||||
else AlbumViewEvent.DeselectWallpaper(wallpaper.wallpaperUri)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val onWallpaperViewClickItem = remember(wallpaper, albumViewState.isLoading, onShowWallpaperView) {
|
||||
{
|
||||
if (!albumViewState.isLoading)
|
||||
onShowWallpaperView(wallpaper.wallpaperUri, wallpaper.fileName)
|
||||
}
|
||||
}
|
||||
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper.wallpaperUri,
|
||||
itemSelected = albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
albumViewScreenViewModel.onEvent(
|
||||
if (!albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri))
|
||||
AlbumViewEvent.SelectWallpaper(wallpaper.wallpaperUri)
|
||||
else {
|
||||
AlbumViewEvent.RemoveWallpaperFromSelection(wallpaper.wallpaperUri)
|
||||
}
|
||||
itemSelected = isSelected,
|
||||
selectionMode = albumViewState.selectionState.selectedCount > 0,
|
||||
onItemSelection = onWallpaperItemSelection,
|
||||
onWallpaperViewClick = onWallpaperViewClickItem,
|
||||
modifier = commonItemModifier
|
||||
.then(
|
||||
if (animate) Modifier.animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
)
|
||||
) else Modifier
|
||||
)
|
||||
},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper.wallpaperUri)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp),
|
||||
animate = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
-219
@@ -1,219 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen
|
||||
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
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 dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class AlbumViewScreenViewModel @Inject constructor(
|
||||
application: Application,
|
||||
private val repository: AlbumRepository,
|
||||
) : AndroidViewModel(application) {
|
||||
private val context: Context
|
||||
get() = getApplication<Application>().applicationContext
|
||||
private val _state = MutableStateFlow(AlbumViewState())
|
||||
val state = _state.stateIn(
|
||||
viewModelScope,
|
||||
SharingStarted.WhileSubscribed(5000), AlbumViewState()
|
||||
)
|
||||
|
||||
fun onEvent(event: AlbumViewEvent) {
|
||||
when (event) {
|
||||
is AlbumViewEvent.DeleteSelected -> {
|
||||
viewModelScope.launch {
|
||||
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 containsCoverUri = wallpapers.any { it.wallpaperUri == album.album.coverUri }
|
||||
repository.deleteFolderList(folders)
|
||||
repository.deleteWallpaperList(wallpapers)
|
||||
if (containsCoverUri) {
|
||||
repository.updateAlbum(album.album.copy(coverUri = null))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
is AlbumViewEvent.SelectAll -> {
|
||||
viewModelScope.launch {
|
||||
event.albumsWithWallpaper.let { album ->
|
||||
if (!_state.value.allSelected) {
|
||||
_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,
|
||||
allSelected = true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.DeselectAll -> {
|
||||
viewModelScope.launch {
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
selectedCount = 0,
|
||||
allSelected = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.SelectFolder -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.selectedFolders.any { it == event.directoryUri }) {
|
||||
_state.update {
|
||||
val folders = it.selectedFolders.plus(event.directoryUri)
|
||||
it.copy(
|
||||
selectedFolders = folders,
|
||||
selectedCount = it.selectedCount + 1,
|
||||
allSelected = folders.size + it.selectedWallpapers.size >= it.maxSize
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.SelectWallpaper -> {
|
||||
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,
|
||||
allSelected = it.selectedFolders.size + wallpapers.size >= it.maxSize
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.RemoveFolderFromSelection -> {
|
||||
viewModelScope.launch {
|
||||
if (_state.value.selectedFolders.find { it == event.directoryUri } != null) {
|
||||
_state.update {
|
||||
val folders = it.selectedFolders.minus(event.directoryUri)
|
||||
it.copy(
|
||||
selectedFolders = folders,
|
||||
selectedCount = it.selectedCount - 1,
|
||||
allSelected = folders.size + it.selectedWallpapers.size >= it.maxSize
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.RemoveWallpaperFromSelection -> {
|
||||
viewModelScope.launch {
|
||||
if (_state.value.selectedWallpapers.find { it == event.wallpaperUri } != null) {
|
||||
_state.update {
|
||||
val wallpapers = it.selectedWallpapers.minus(event.wallpaperUri)
|
||||
it.copy(
|
||||
selectedWallpapers = wallpapers,
|
||||
selectedCount = it.selectedCount - 1,
|
||||
allSelected = it.selectedFolders.size + wallpapers.size >= it.maxSize
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.ClearState -> {
|
||||
viewModelScope.launch {
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
maxSize = 0
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.SetSize -> {
|
||||
viewModelScope.launch {
|
||||
_state.update {
|
||||
it.copy(
|
||||
maxSize = event.size
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.AddWallpapers -> {
|
||||
viewModelScope.launch {
|
||||
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(wallpapers)
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
maxSize = it.maxSize + wallpapers.size
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.AddFolder -> {
|
||||
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(
|
||||
folderUri = event.directoryUri,
|
||||
folderName = folderName,
|
||||
initialAlbumName = event.album.album.initialAlbumName,
|
||||
key = event.directoryUri.hashCode() + event.album.album.initialAlbumName.hashCode(),
|
||||
coverUri = wallpapers.randomOrNull(),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
)
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
maxSize = it.maxSize + 1
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+7
-5
@@ -1,9 +1,11 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.SelectionState
|
||||
|
||||
data class AlbumViewState (
|
||||
val selectedWallpapers: List<String> = emptyList(),
|
||||
val selectedFolders: List<String> = emptyList(),
|
||||
val allSelected: Boolean = false,
|
||||
val selectedCount: Int = 0,
|
||||
val maxSize: Int = 0
|
||||
val albums: List<AlbumWithWallpaperAndFolder> = emptyList(),
|
||||
val initialAlbumName: String = "",
|
||||
val selectionState: SelectionState = SelectionState(),
|
||||
val isEmpty: Boolean = true,
|
||||
val isLoading: Boolean = false
|
||||
)
|
||||
+59
-37
@@ -3,6 +3,7 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen.
|
||||
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
|
||||
@@ -10,7 +11,9 @@ import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material.icons.automirrored.filled.Sort
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material.icons.filled.RadioButtonUnchecked
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
@@ -23,6 +26,7 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.TopAppBarDefaults.topAppBarColors
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -32,7 +36,6 @@ 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.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.DpOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -48,23 +51,25 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun AlbumViewTopBar(
|
||||
albumState: StateFlow<AlbumViewState>,
|
||||
title: String,
|
||||
onBackClick: () -> Unit,
|
||||
allSelected: Boolean,
|
||||
selectedCount: Int,
|
||||
selectionMode: Boolean,
|
||||
isLoad: Boolean,
|
||||
onBackClick: () -> Unit,
|
||||
onSortClick: () -> Unit,
|
||||
onSelectAllClick: () -> Unit,
|
||||
onDeleteAlbum: () -> Unit,
|
||||
onDeleteSelected: () -> Unit,
|
||||
onTitleChange: (String) -> Unit,
|
||||
) {
|
||||
val state = albumState.collectAsStateWithLifecycle()
|
||||
var showDeleteAlertDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showNameChangeDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var menuExpanded by rememberSaveable { mutableStateOf(false) }
|
||||
var showSelectionDeleteDialog by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||
colors = topAppBarColors(containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)),
|
||||
title = { if (!selectionMode) Text(title) },
|
||||
navigationIcon = {
|
||||
if (!selectionMode) {
|
||||
@@ -76,39 +81,34 @@ fun AlbumViewTopBar(
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen),
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
Row (
|
||||
} else {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
IconButton(
|
||||
onClick = onSelectAllClick
|
||||
) {
|
||||
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
if (state.value.allSelected) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.CheckCircle,
|
||||
contentDescription = stringResource(R.string.all_images_selected_for_deletion),
|
||||
modifier = Modifier
|
||||
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
IconButton(onClick = onSelectAllClick) {
|
||||
Icon(
|
||||
imageVector = if (allSelected) Icons.Default.CheckCircle else Icons.Default.RadioButtonUnchecked,
|
||||
contentDescription = stringResource(
|
||||
if (allSelected) R.string.all_images_selected_for_deletion
|
||||
else R.string.select_all_images_for_deletion
|
||||
),
|
||||
modifier = if (allSelected) {
|
||||
Modifier
|
||||
.padding(4.dp)
|
||||
.border(2.dp, bgColor, CircleShape)
|
||||
.clip(CircleShape)
|
||||
.background(bgColor)
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
imageVector = Icons.Default.RadioButtonUnchecked,
|
||||
contentDescription = stringResource(R.string.select_all_images_for_deletion),
|
||||
tint = Color.White.copy(alpha = 0.7f),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Modifier.padding(6.dp)
|
||||
}
|
||||
)
|
||||
}
|
||||
Text(stringResource(R.string.selected_count, state.value.selectedCount))
|
||||
Text(stringResource(R.string.selected, selectedCount))
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -118,17 +118,32 @@ fun AlbumViewTopBar(
|
||||
onDismissRequest = { showDeleteAlertDialog = false },
|
||||
onConfirmation = {
|
||||
showDeleteAlertDialog = false
|
||||
onDeleteAlbum()
|
||||
if (!isLoad) { onDeleteAlbum() }
|
||||
}
|
||||
)
|
||||
if (showNameChangeDialog) AlbumNameDialog (
|
||||
onDismissRequest = { showNameChangeDialog = false },
|
||||
onConfirmation = {
|
||||
showNameChangeDialog = false
|
||||
onTitleChange(it)
|
||||
if (!isLoad) { onTitleChange(it) }
|
||||
}
|
||||
)
|
||||
IconButton(onClick = { menuExpanded = true }) {
|
||||
Row {
|
||||
Box {
|
||||
IconButton(
|
||||
onClick = { if (!isLoad) { onSortClick() } }
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Default.Sort,
|
||||
contentDescription = stringResource(R.string.sort_items),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
IconButton(onClick = {
|
||||
if (!isLoad) { menuExpanded = true }
|
||||
}) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.MoreVert,
|
||||
contentDescription = stringResource(R.string.more_options),
|
||||
@@ -140,19 +155,24 @@ fun AlbumViewTopBar(
|
||||
expanded = menuExpanded,
|
||||
onDismissRequest = { menuExpanded = false },
|
||||
offset = DpOffset(0.dp, 5.dp),
|
||||
modifier = Modifier.padding(8.dp)
|
||||
modifier = Modifier.padding(8.dp),
|
||||
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.delete_album)) },
|
||||
onClick = {
|
||||
showDeleteAlertDialog = true
|
||||
menuExpanded = false
|
||||
if (!isLoad) {
|
||||
showDeleteAlertDialog = true
|
||||
}
|
||||
menuExpanded = false
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.change_name)) },
|
||||
onClick = {
|
||||
showNameChangeDialog = true
|
||||
if (!isLoad) {
|
||||
showNameChangeDialog = true
|
||||
}
|
||||
menuExpanded = false
|
||||
}
|
||||
)
|
||||
@@ -164,14 +184,16 @@ fun AlbumViewTopBar(
|
||||
onDismissRequest = { showSelectionDeleteDialog = false },
|
||||
onConfirmation = {
|
||||
showSelectionDeleteDialog = false
|
||||
onDeleteSelected()
|
||||
if (!isLoad) {
|
||||
onDeleteSelected()
|
||||
}
|
||||
}
|
||||
)
|
||||
IconButton(
|
||||
onClick = { showSelectionDeleteDialog = true }
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Delete,
|
||||
imageVector = if (showSelectionDeleteDialog) Icons.Filled.Delete else Icons.Outlined.Delete,
|
||||
contentDescription = stringResource(R.string.select_all_images_for_deletion),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.folder_view_screen
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
|
||||
sealed class FolderEvent {
|
||||
data object Reset: FolderEvent()
|
||||
|
||||
data class LoadFolderView(
|
||||
val folder: Folder? = null
|
||||
): FolderEvent()
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.folder_view_screen
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
|
||||
data class FolderState(
|
||||
val folder: Folder? = null,
|
||||
)
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.folder_view_screen
|
||||
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.sort_view_screen.SortEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.sort_view_screen.SortState
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* ViewModel for the folder view screen to hold the folder name and the list of wallpapers
|
||||
*/
|
||||
class FolderViewModel @Inject constructor (): ViewModel() {
|
||||
private val _state = MutableStateFlow<FolderState>(FolderState())
|
||||
val state = _state.stateIn(
|
||||
scope = viewModelScope,
|
||||
started = SharingStarted.WhileSubscribed(5000),
|
||||
initialValue = FolderState()
|
||||
)
|
||||
|
||||
fun onEvent(event: FolderEvent) {
|
||||
when (event) {
|
||||
is FolderEvent.LoadFolderView -> {
|
||||
_state.value = state.value.copy(
|
||||
folder = event.folder
|
||||
)
|
||||
}
|
||||
is FolderEvent.Reset -> {
|
||||
_state.value = FolderState()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+70
-53
@@ -5,86 +5,103 @@ 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.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.items
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember // Added remember import
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.folder_view_screen.components.FolderViewTopBar
|
||||
import my.nanihadesuka.compose.LazyVerticalGridScrollbar
|
||||
import my.nanihadesuka.compose.ScrollbarSettings
|
||||
|
||||
@Composable
|
||||
fun FolderViewScreen(
|
||||
folderName: String?,
|
||||
wallpapers: List<String>,
|
||||
folder: Folder,
|
||||
onBackClick: () -> Unit,
|
||||
onShowWallpaperView: (String) -> Unit,
|
||||
onShowWallpaperView: (String, String) -> Unit,
|
||||
animate: Boolean
|
||||
) {
|
||||
val lazyListState = rememberLazyStaggeredGridState()
|
||||
val lazyListState = rememberLazyGridState()
|
||||
val colorScheme = MaterialTheme.colorScheme
|
||||
|
||||
val scrollbarSettings = remember {
|
||||
ScrollbarSettings.Default.copy(
|
||||
thumbUnselectedColor = colorScheme.primary,
|
||||
thumbSelectedColor = colorScheme.primary,
|
||||
thumbShape = RoundedCornerShape(16.dp),
|
||||
scrollbarPadding = 1.dp,
|
||||
)
|
||||
}
|
||||
|
||||
val noOpItemSelection: () -> Unit = remember { { /* Do nothing */ } }
|
||||
|
||||
BackHandler { onBackClick() }
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
FolderViewTopBar(
|
||||
title = folderName ?: "",
|
||||
title = folder.folderName ?: "",
|
||||
onBackClick = onBackClick
|
||||
)
|
||||
},
|
||||
content = {
|
||||
LazyVerticalStaggeredGrid(
|
||||
content = { paddingValues ->
|
||||
LazyVerticalGridScrollbar(
|
||||
state = lazyListState,
|
||||
settings = scrollbarSettings,
|
||||
modifier = Modifier
|
||||
.padding(it)
|
||||
.fillMaxSize(),
|
||||
columns = StaggeredGridCells.Fixed(2),
|
||||
contentPadding = PaddingValues(4.dp, 4.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
content = {
|
||||
items (items = wallpapers, key = { wallpaper -> wallpaper }
|
||||
) { wallpaper ->
|
||||
if (animate) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
),
|
||||
animate = true
|
||||
)
|
||||
}
|
||||
else {
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp),
|
||||
animate = false
|
||||
)
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
) {
|
||||
LazyVerticalGrid(
|
||||
state = lazyListState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
columns = GridCells.Adaptive(150.dp),
|
||||
contentPadding = PaddingValues(4.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
items(items = folder.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri }) { wallpaper ->
|
||||
val itemModifier = remember(animate) {
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.aspectRatio(9f / 16f)
|
||||
.then(
|
||||
if (animate) Modifier.animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
)
|
||||
) else Modifier
|
||||
)
|
||||
}
|
||||
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper.wallpaperUri,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
allowHapticFeedback = false,
|
||||
onItemSelection = noOpItemSelection,
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper.wallpaperUri, wallpaper.fileName)
|
||||
},
|
||||
modifier = itemModifier
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
+3
-1
@@ -11,6 +11,8 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.TopAppBarDefaults.topAppBarColors
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -27,7 +29,7 @@ fun FolderViewTopBar(
|
||||
onBackClick: () -> Unit
|
||||
) {
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||
colors = topAppBarColors(containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)),
|
||||
title = { Text(title) },
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
|
||||
+70
-99
@@ -4,14 +4,13 @@ import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.PrimaryTabRow
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Tab
|
||||
import androidx.compose.material3.TabRow
|
||||
import androidx.compose.material3.TabRowDefaults
|
||||
import androidx.compose.material3.TabRowDefaults.tabIndicatorOffset
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TimePickerState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -19,64 +18,70 @@ 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.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.SettingsState.EffectSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ScheduleSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ThemeSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.WallpaperSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreen
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun HomeScreen(
|
||||
animate : Boolean,
|
||||
darken: Boolean,
|
||||
darkenPercentage: Int,
|
||||
enableChanger: Boolean,
|
||||
homeEnabled : Boolean,
|
||||
interval1: Int,
|
||||
interval2: Int,
|
||||
lastSetTime: String?,
|
||||
lockEnabled : Boolean,
|
||||
navigateToAddWallpaperScreen: (String) -> Unit,
|
||||
nextSetTime: String?,
|
||||
onAlbumViewClick: (String) -> Unit,
|
||||
albums: List<AlbumWithWallpaperAndFolder>,
|
||||
homeSelectedAlbum: AlbumWithWallpaperAndFolder?,
|
||||
lockSelectedAlbum: AlbumWithWallpaperAndFolder?,
|
||||
themeSettings: ThemeSettings,
|
||||
wallpaperSettings: WallpaperSettings,
|
||||
scheduleSettings: ScheduleSettings,
|
||||
effectSettings: EffectSettings,
|
||||
onNavigateAddWallpaper: (String) -> Unit,
|
||||
onViewAlbum: (String) -> Unit,
|
||||
onDarkCheck: (Boolean) -> Unit,
|
||||
onDarkenPercentage: (Int) -> Unit,
|
||||
onDarkenPercentage: (Int, Int) -> Unit,
|
||||
onHomeCheckedChange: (Boolean) -> Unit,
|
||||
onLockCheckedChange: (Boolean) -> Unit,
|
||||
onScalingChange: (ScalingConstants) -> Unit,
|
||||
onScheduleWallpaperChanger1: (Int) -> Unit,
|
||||
onScheduleWallpaperChanger2: (Int) -> Unit,
|
||||
onSelectAlbum: (AlbumWithWallpaperAndFolder) -> Unit,
|
||||
onSelectAlbum: (AlbumWithWallpaperAndFolder, Boolean, Boolean) -> Unit,
|
||||
onScheduleSeparatelyChange: (Boolean) -> Unit,
|
||||
onTimeChange1: (Int) -> Unit,
|
||||
onTimeChange2: (Int) -> Unit,
|
||||
onHomeTimeChange: (Int) -> Unit,
|
||||
onLockTimeChange: (Int) -> Unit,
|
||||
onSettingsClick: () -> Unit,
|
||||
onStop: () -> Unit,
|
||||
onDeselect: (Boolean, Boolean) -> Unit,
|
||||
onToggleChanger: (Boolean) -> Unit,
|
||||
scaling: ScalingConstants,
|
||||
selectedAlbum: SelectedAlbum?,
|
||||
scheduleSeparately: Boolean,
|
||||
blur: Boolean,
|
||||
onBlurPercentageChange: (Int) -> Unit,
|
||||
onBlurPercentageChange: (Int, Int) -> Unit,
|
||||
onBlurChange: (Boolean) -> Unit,
|
||||
blurPercentage: Int,
|
||||
firstSet: Boolean
|
||||
onVignettePercentageChange: (Int, Int) -> Unit,
|
||||
onVignetteChange: (Boolean) -> Unit,
|
||||
onGrayscalePercentageChange: (Int, Int) -> Unit,
|
||||
onGrayscaleChange: (Boolean) -> Unit,
|
||||
onChangeStartTimeToggle: (Boolean) -> Unit,
|
||||
onStartTimeChange: (TimePickerState) -> Unit,
|
||||
onShuffleCheck: (Boolean) -> Unit,
|
||||
onRefreshChange: (Boolean) -> Unit
|
||||
) {
|
||||
var tabIndex by rememberSaveable { mutableIntStateOf(0) }
|
||||
val tabItems = getTabItems()
|
||||
val pagerState = rememberPagerState { tabItems.size }
|
||||
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) }
|
||||
onConfirmation = { onNavigateAddWallpaper(it) }
|
||||
)
|
||||
|
||||
LaunchedEffect(tabIndex) {
|
||||
pagerState.animateScrollToPage(tabIndex)
|
||||
}
|
||||
LaunchedEffect(pagerState.currentPage) {
|
||||
tabIndex = pagerState.currentPage
|
||||
}
|
||||
|
||||
Scaffold (
|
||||
topBar = {
|
||||
HomeTopBar(
|
||||
@@ -85,36 +90,10 @@ fun HomeScreen(
|
||||
onSettingsClick = onSettingsClick,
|
||||
)
|
||||
}
|
||||
) { padding ->
|
||||
LaunchedEffect(tabIndex) {
|
||||
if (tabIndex in tabItems.indices) {
|
||||
pagerState.animateScrollToPage(tabIndex)
|
||||
}
|
||||
}
|
||||
LaunchedEffect(pagerState) {
|
||||
snapshotFlow { pagerState.currentPage }.collect { page ->
|
||||
if (page in tabItems.indices) {
|
||||
tabIndex = page
|
||||
}
|
||||
}
|
||||
}
|
||||
Column(modifier = Modifier.padding(padding)) {
|
||||
TabRow(
|
||||
) {
|
||||
Column(modifier = Modifier.padding(it)) {
|
||||
PrimaryTabRow(
|
||||
selectedTabIndex = tabIndex,
|
||||
indicator = { tabPositions ->
|
||||
if (tabIndex < tabPositions.size) {
|
||||
TabRowDefaults.PrimaryIndicator(
|
||||
modifier = Modifier.tabIndicatorOffset(tabPositions[tabIndex]),
|
||||
shape = RoundedCornerShape(
|
||||
topStart = 6.dp,
|
||||
topEnd = 6.dp,
|
||||
bottomEnd = 0.dp,
|
||||
bottomStart = 0.dp,
|
||||
),
|
||||
width = 60.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
) {
|
||||
tabItems.forEachIndexed { index, item ->
|
||||
Tab(
|
||||
@@ -123,11 +102,7 @@ fun HomeScreen(
|
||||
text = { Text(text = item.title) },
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector =
|
||||
if (index == tabIndex)
|
||||
item.filledIcon
|
||||
else
|
||||
item.unfilledIcon,
|
||||
imageVector = if (index == tabIndex) item.filledIcon else item.unfilledIcon,
|
||||
contentDescription = item.title
|
||||
)
|
||||
}
|
||||
@@ -136,47 +111,43 @@ fun HomeScreen(
|
||||
}
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
beyondViewportPageCount = 1,
|
||||
userScrollEnabled = true,
|
||||
beyondViewportPageCount = 1
|
||||
) { index ->
|
||||
when(index) {
|
||||
when (index.coerceIn(tabItems.indices)) {
|
||||
0 -> WallpaperScreen(
|
||||
animate = animate,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
enableChanger = enableChanger,
|
||||
homeEnabled = homeEnabled,
|
||||
interval1 = interval1,
|
||||
interval2 = interval2,
|
||||
lastSetTime = lastSetTime,
|
||||
lockEnabled = lockEnabled,
|
||||
nextSetTime = nextSetTime,
|
||||
albums = albums,
|
||||
homeSelectedAlbum = homeSelectedAlbum,
|
||||
lockSelectedAlbum = lockSelectedAlbum,
|
||||
themeSettings = themeSettings,
|
||||
wallpaperSettings = wallpaperSettings,
|
||||
scheduleSettings = scheduleSettings,
|
||||
effectSettings = effectSettings,
|
||||
onDarkCheck = onDarkCheck,
|
||||
onDarkenPercentage = onDarkenPercentage,
|
||||
onHomeCheckedChange = onHomeCheckedChange,
|
||||
onLockCheckedChange = onLockCheckedChange,
|
||||
onScheduleWallpaperChanger1 = onScheduleWallpaperChanger1,
|
||||
onScheduleWallpaperChanger2 = onScheduleWallpaperChanger2,
|
||||
onScalingChange = onScalingChange,
|
||||
onSelectAlbum = onSelectAlbum,
|
||||
onStop = onStop,
|
||||
onToggleChanger = onToggleChanger,
|
||||
scaling = scaling,
|
||||
selectedAlbum = selectedAlbum,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
|
||||
onTimeChange1 = onTimeChange1,
|
||||
onTimeChange2 = onTimeChange2,
|
||||
blur = blur,
|
||||
onSelectAlbum = onSelectAlbum,
|
||||
onHomeTimeChange = onHomeTimeChange,
|
||||
onLockTimeChange = onLockTimeChange,
|
||||
onDeselect = onDeselect,
|
||||
onToggleChanger = onToggleChanger,
|
||||
onBlurPercentageChange = onBlurPercentageChange,
|
||||
onBlurChange = onBlurChange,
|
||||
blurPercentage = blurPercentage,
|
||||
firstSet = firstSet
|
||||
onVignettePercentageChange = onVignettePercentageChange,
|
||||
onVignetteChange = onVignetteChange,
|
||||
onGrayscalePercentageChange = onGrayscalePercentageChange,
|
||||
onGrayscaleChange = onGrayscaleChange,
|
||||
onChangeStartTimeToggle = onChangeStartTimeToggle,
|
||||
onStartTimeChange = onStartTimeChange,
|
||||
onShuffleCheck = onShuffleCheck,
|
||||
onRefreshChange = onRefreshChange
|
||||
)
|
||||
1 -> LibraryScreen(
|
||||
else -> LibraryScreen(
|
||||
albums = albums,
|
||||
onAddNewAlbumClick = { addAlbumDialog = true },
|
||||
onViewAlbum = onAlbumViewClick,
|
||||
animate = animate
|
||||
onViewAlbum = onViewAlbum,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -27,6 +27,7 @@ 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.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
@@ -90,7 +91,7 @@ fun HomeTopBar (
|
||||
}
|
||||
} else {
|
||||
IconButton(
|
||||
onClick = { onSettingsClick() },
|
||||
onClick = { onSettingsClick() }
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Settings,
|
||||
|
||||
+8
-11
@@ -15,24 +15,22 @@ import androidx.compose.material3.LargeFloatingActionButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.AlbumItem
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun LibraryScreen(
|
||||
albumsViewModel: AlbumsViewModel = hiltViewModel(),
|
||||
albums: List<AlbumWithWallpaperAndFolder>,
|
||||
onAddNewAlbumClick: () -> Unit,
|
||||
onViewAlbum: (String) -> Unit,
|
||||
animate: Boolean
|
||||
) {
|
||||
onViewAlbum: (String) -> Unit
|
||||
) {
|
||||
val lazyListState = rememberLazyGridState()
|
||||
val state = albumsViewModel.state.collectAsStateWithLifecycle()
|
||||
Scaffold(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
floatingActionButton = {
|
||||
@@ -52,17 +50,16 @@ fun LibraryScreen(
|
||||
LazyVerticalGrid(
|
||||
state = lazyListState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
columns = GridCells.Fixed(2),
|
||||
columns = GridCells.Adaptive(150.dp),
|
||||
contentPadding = PaddingValues(4.dp, 4.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
content = {
|
||||
items (state.value.albumsWithWallpapers, key = { album -> album.album.initialAlbumName}
|
||||
items (albums, key = { album -> album.album.initialAlbumName}
|
||||
) { album ->
|
||||
AlbumItem(
|
||||
album = album.album,
|
||||
onAlbumViewClick = { onViewAlbum(album.album.initialAlbumName) },
|
||||
modifier = Modifier.padding(4.dp),
|
||||
animate = animate
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
/**
|
||||
* A row that contains an icon, text, and an onClick listener.
|
||||
*/
|
||||
@Composable
|
||||
fun MenuRow(text: String, icon: ImageVector?, horizontalExpansion: Dp, onClick: () -> Unit) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.width(horizontalExpansion)
|
||||
.clickable { onClick() },
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
if (icon != null) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = text,
|
||||
modifier = Modifier.padding(12.dp)
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
Text(
|
||||
text = text,
|
||||
overflow = TextOverflow.Visible,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(end = 20.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components
|
||||
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
|
||||
/**
|
||||
* Data class for selection options
|
||||
*/
|
||||
data class SelectionOptions(
|
||||
val id: String = "",
|
||||
val text: String = "",
|
||||
val subText: String? = "",
|
||||
val icon: ImageVector? = null
|
||||
)
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
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.LicenseTitle
|
||||
|
||||
@Composable
|
||||
fun LicensesScreen(
|
||||
topInsets: Dp,
|
||||
onBackClick: () -> Unit,
|
||||
) {
|
||||
val lazyListState = rememberLazyListState()
|
||||
val offset = rememberCurrentOffset(lazyListState)
|
||||
val largeTopAppBarHeight = 152.dp
|
||||
val smallTopAppBarHeight = 64.dp
|
||||
val paddingMedium = 16.dp
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
LicenseScrollableSettings(
|
||||
largeTopAppBarHeightPx = largeTopAppBarHeight,
|
||||
lazyListState = lazyListState,
|
||||
offset = offset,
|
||||
onBackClick = onBackClick
|
||||
)
|
||||
LicenseTitle(
|
||||
largeTopAppBarHeight = largeTopAppBarHeight,
|
||||
smallTopAppBarHeight = smallTopAppBarHeight,
|
||||
paddingMedium = paddingMedium,
|
||||
offset = offset,
|
||||
topInset = topInsets
|
||||
)
|
||||
}
|
||||
}
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
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>,
|
||||
onBackClick: () -> Unit
|
||||
) {
|
||||
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
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components
|
||||
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Title for the license screen.
|
||||
*/
|
||||
@Composable
|
||||
fun LicenseTitle(
|
||||
largeTopAppBarHeight: Dp,
|
||||
smallTopAppBarHeight: Dp,
|
||||
paddingMedium: Dp,
|
||||
modifier: Modifier = Modifier,
|
||||
offset: State<Int>,
|
||||
topInset: Dp,
|
||||
) {
|
||||
val titlePaddingStart = 16.dp
|
||||
val titlePaddingEnd = 64.dp
|
||||
val titleFontScaleStart = 1f
|
||||
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(R.string.licenses),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
fontSize = 30.sp,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
modifier = modifier
|
||||
.graphicsLayer {
|
||||
val collapseRange: Float = (largeTopAppBarHeight.toPx() - smallTopAppBarHeight.toPx())
|
||||
val collapseFraction: Float = (offset.value.toFloat() / collapseRange).coerceIn(0f, 1f)
|
||||
|
||||
val scaleXY = lerp(
|
||||
titleFontScaleStart.dp,
|
||||
titleFontScaleEnd.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleExtraStartPadding = titleWidthPx.toDp() * (1 - scaleXY.value) / 2f
|
||||
|
||||
val titleYFirstInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium + statusPadding,
|
||||
largeTopAppBarHeight / 2,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleXFirstInterpolatedPoint = lerp(
|
||||
titlePaddingStart,
|
||||
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleYSecondInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight / 2,
|
||||
(smallTopAppBarHeight + statusPadding - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleXSecondInterpolatedPoint = lerp(
|
||||
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
|
||||
titlePaddingEnd - titleExtraStartPadding,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleY = lerp(
|
||||
titleYFirstInterpolatedPoint,
|
||||
titleYSecondInterpolatedPoint,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleX = lerp(
|
||||
titleXFirstInterpolatedPoint,
|
||||
titleXSecondInterpolatedPoint,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
translationY = titleY.toPx()
|
||||
translationX = titleX.toPx()
|
||||
scaleX = scaleXY.value
|
||||
scaleY = scaleXY.value
|
||||
}
|
||||
.onGloballyPositioned {
|
||||
titleHeightPx = it.size.height.toFloat()
|
||||
titleWidthPx = it.size.width.toFloat()
|
||||
}
|
||||
)
|
||||
}
|
||||
+2
@@ -25,6 +25,7 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -39,6 +40,7 @@ import com.airbnb.lottie.compose.animateLottieCompositionAsState
|
||||
import com.airbnb.lottie.compose.rememberLottieComposition
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun NotificationScreen(
|
||||
onAgree: () -> Unit
|
||||
|
||||
+115
-22
@@ -1,38 +1,131 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.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.rememberScrollState
|
||||
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.TopAppBarDefaults
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.res.stringResource
|
||||
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.PrivacyTitle
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.anthonyla.paperize.R
|
||||
import me.onebone.toolbar.CollapsingToolbarScaffold
|
||||
import me.onebone.toolbar.ScrollStrategy
|
||||
import me.onebone.toolbar.rememberCollapsingToolbarScaffoldState
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun PrivacyScreen(
|
||||
topInsets: Dp,
|
||||
onBackClick: () -> Unit,
|
||||
) {
|
||||
val scroll: ScrollState = rememberScrollState(0)
|
||||
val largeTopAppBarHeight = 152.dp
|
||||
val smallTopAppBarHeight = 64.dp
|
||||
val paddingMedium = 16.dp
|
||||
val topBarState = rememberCollapsingToolbarScaffoldState()
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
PrivacyScrollableSettings(
|
||||
largeTopAppBarHeightPx = largeTopAppBarHeight,
|
||||
scroll = scroll,
|
||||
onBackClick = onBackClick
|
||||
)
|
||||
PrivacyTitle(
|
||||
scroll = scroll,
|
||||
largeTopAppBarHeight = largeTopAppBarHeight,
|
||||
smallTopAppBarHeight = smallTopAppBarHeight,
|
||||
paddingMedium = paddingMedium,
|
||||
topInset = topInsets
|
||||
)
|
||||
// Collapsing top bar
|
||||
val largeTopAppBarHeight = TopAppBarDefaults.LargeAppBarExpandedHeight
|
||||
val startPadding = 64.dp
|
||||
val endPadding = 16.dp
|
||||
val titleFontScaleStart = 30
|
||||
val titleFontScaleEnd = 21
|
||||
val titleExtraStartPadding = 32.dp
|
||||
val collapseFraction = topBarState.toolbarState.progress
|
||||
val firstPaddingInterpolation = lerp((endPadding * 5 / 4), endPadding, collapseFraction) + titleExtraStartPadding
|
||||
val secondPaddingInterpolation = lerp(startPadding, (endPadding * 5 / 4), collapseFraction)
|
||||
val dynamicPaddingStart = lerp(firstPaddingInterpolation, secondPaddingInterpolation, collapseFraction)
|
||||
val textSize = (titleFontScaleEnd + (titleFontScaleStart - titleFontScaleEnd) * collapseFraction).sp
|
||||
|
||||
Scaffold {
|
||||
CollapsingToolbarScaffold(
|
||||
state = topBarState,
|
||||
modifier = Modifier.fillMaxSize().padding(it),
|
||||
scrollStrategy = ScrollStrategy.ExitUntilCollapsed,
|
||||
toolbar = {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(largeTopAppBarHeight)
|
||||
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp))
|
||||
.pin()
|
||||
)
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = stringResource(id = R.string.privacy_policy),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
fontSize = textSize,
|
||||
modifier = Modifier
|
||||
.road(Alignment.CenterStart, Alignment.BottomStart)
|
||||
.padding(dynamicPaddingStart, 16.dp, 16.dp, 16.dp),
|
||||
)
|
||||
}
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 24.dp),
|
||||
) {
|
||||
PrivacyNoticeText()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PrivacyNoticeText() {
|
||||
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
|
||||
private fun SectionText(title: String, content: String) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
modifier = Modifier.padding(vertical = 8.dp),
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
|
||||
)
|
||||
Text(
|
||||
text = content,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = Modifier.padding(bottom = 16.dp)
|
||||
)
|
||||
}
|
||||
-100
@@ -1,100 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
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
|
||||
) {
|
||||
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(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
|
||||
fun SectionText(title: String, content: String) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
modifier = Modifier.padding(vertical = 8.dp),
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
|
||||
)
|
||||
Text(
|
||||
text = content,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = Modifier.padding(bottom = 16.dp)
|
||||
)
|
||||
}
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Title for the privacy screen.
|
||||
*/
|
||||
@Composable
|
||||
fun PrivacyTitle(
|
||||
largeTopAppBarHeight: Dp,
|
||||
smallTopAppBarHeight: Dp,
|
||||
paddingMedium: Dp,
|
||||
scroll: ScrollState,
|
||||
modifier: Modifier = Modifier,
|
||||
topInset: Dp,
|
||||
) {
|
||||
val titlePaddingStart = 16.dp
|
||||
val titlePaddingEnd = 64.dp
|
||||
val titleFontScaleStart = 1f
|
||||
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.privacy_policy),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
fontSize = 30.sp,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
modifier = modifier
|
||||
.graphicsLayer {
|
||||
val collapseRange: Float = (largeTopAppBarHeight.toPx() - smallTopAppBarHeight.toPx())
|
||||
val collapseFraction: Float = (scroll.value / collapseRange).coerceIn(0f, 1f)
|
||||
|
||||
val scaleXY = lerp(
|
||||
titleFontScaleStart.dp,
|
||||
titleFontScaleEnd.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleExtraStartPadding = titleWidthPx.toDp() * (1 - scaleXY.value) / 2f
|
||||
|
||||
val titleYFirstInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium + statusPadding,
|
||||
largeTopAppBarHeight / 2,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleXFirstInterpolatedPoint = lerp(
|
||||
titlePaddingStart,
|
||||
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleYSecondInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight / 2,
|
||||
(smallTopAppBarHeight + statusPadding - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleXSecondInterpolatedPoint = lerp(
|
||||
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
|
||||
titlePaddingEnd - titleExtraStartPadding,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleY = lerp(
|
||||
titleYFirstInterpolatedPoint,
|
||||
titleYSecondInterpolatedPoint,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleX = lerp(
|
||||
titleXFirstInterpolatedPoint,
|
||||
titleXSecondInterpolatedPoint,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
translationY = titleY.toPx()
|
||||
translationX = titleX.toPx()
|
||||
scaleX = scaleXY.value
|
||||
scaleY = scaleXY.value
|
||||
}
|
||||
.onGloballyPositioned {
|
||||
titleHeightPx = it.size.height.toFloat()
|
||||
titleWidthPx = it.size.width.toFloat()
|
||||
}
|
||||
)
|
||||
}
|
||||
+15
-4
@@ -4,23 +4,34 @@ import com.anthonyla.paperize.core.ScalingConstants
|
||||
|
||||
|
||||
sealed class SettingsEvent {
|
||||
data object Refresh: SettingsEvent()
|
||||
data object Reset: SettingsEvent()
|
||||
data object SetFirstLaunch: SettingsEvent()
|
||||
data object SetFirstSet: SettingsEvent()
|
||||
data object RefreshNextSetTime: SettingsEvent()
|
||||
data class SetDarkMode(val darkMode: Boolean?): SettingsEvent()
|
||||
data class SetAmoledTheme(val amoledTheme: Boolean): SettingsEvent()
|
||||
data class SetDynamicTheming(val dynamicTheming: Boolean): SettingsEvent()
|
||||
data class SetAnimate(val animate: Boolean): SettingsEvent()
|
||||
data class SetDarken(val darken: Boolean): SettingsEvent()
|
||||
data class SetBlur(val blur: Boolean): SettingsEvent()
|
||||
data class SetVignette(val vignette: Boolean): SettingsEvent()
|
||||
data class SetGrayscale(val grayscale: Boolean): SettingsEvent()
|
||||
data class SetLock(val lock: Boolean): SettingsEvent()
|
||||
data class SetHome(val home: Boolean): SettingsEvent()
|
||||
data class SetChangeStartTime(val changeStartTime: Boolean): SettingsEvent()
|
||||
data class SetCurrentWallpaper(val currentHomeWallpaper: String?, val currentLockWallpaper: String?): SettingsEvent()
|
||||
data class SetAlbum(val homeAlbumName: String? = null, val lockAlbumName: String? = null): SettingsEvent()
|
||||
data class RemoveSelectedAlbumAsType(val removeLock: Boolean = false, val removeHome: Boolean = false): SettingsEvent()
|
||||
data class RemoveSelectedAlbumAsName(val albumName: String): 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 SetDarkenPercentage(val homeDarkenPercentage: Int?, val lockDarkenPercentage: Int?): SettingsEvent()
|
||||
data class SetBlurPercentage(val homeBlurPercentage: Int?, val lockBlurPercentage: Int?): SettingsEvent()
|
||||
data class SetVignettePercentage(val homeVignettePercentage: Int?, val lockVignettePercentage: Int?): SettingsEvent()
|
||||
data class SetGrayscalePercentage(val homeGrayscalePercentage: Int?, val lockGrayscalePercentage: Int?): SettingsEvent()
|
||||
data class SetChangerToggle(val toggle: Boolean): SettingsEvent()
|
||||
data class SetWallpaperScaling(val scaling: ScalingConstants): SettingsEvent()
|
||||
data class SetStartTime(val hour: Int, val minute: Int): SettingsEvent()
|
||||
data class SetShuffle(val shuffle: Boolean): SettingsEvent()
|
||||
data class SetRefresh(val refresh: Boolean): SettingsEvent()
|
||||
}
|
||||
+214
-34
@@ -1,57 +1,237 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.provider.Settings
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.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.rememberScrollState
|
||||
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.TopAppBarDefaults
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
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.SettingsTitle
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ThemeSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.AmoledListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.AnimationListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ContactListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.DarkModeListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.DynamicThemingListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ListSectionTitle
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.NotificationListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.PaperizeListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.PrivacyPolicyListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ResetListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.TranslateListItem
|
||||
import me.onebone.toolbar.CollapsingToolbarScaffold
|
||||
import me.onebone.toolbar.ScrollStrategy
|
||||
import me.onebone.toolbar.rememberCollapsingToolbarScaffoldState
|
||||
|
||||
private object Links {
|
||||
const val TRANSLATE = "https://crowdin.com/project/paperize/invite?h=d8d7a7513d2beb0c96ba9b2a5f85473e2084922"
|
||||
const val GITHUB = "https://github.com/Anthonyy232/Paperize"
|
||||
const val FDROID = "https://f-droid.org/en/packages/com.anthonyla.paperize/"
|
||||
const val IZZY = "https://apt.izzysoft.de/fdroid/index/apk/com.anthonyla.paperize"
|
||||
}
|
||||
|
||||
private object ToolbarConfig {
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
val LargeTopAppBarHeight = TopAppBarDefaults.LargeAppBarExpandedHeight
|
||||
val StartPadding = 64.dp
|
||||
val EndPadding = 16.dp
|
||||
const val START = 30
|
||||
const val END = 21
|
||||
val TitleExtraStartPadding = 32.dp
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun calculateToolbarValues(collapseFraction: Float) = with(ToolbarConfig) {
|
||||
val firstPaddingInterpolation = lerp((EndPadding * 5 / 4), EndPadding, collapseFraction) + TitleExtraStartPadding
|
||||
val secondPaddingInterpolation = lerp(StartPadding, (EndPadding * 5 / 4), collapseFraction)
|
||||
val dynamicPaddingStart = lerp(firstPaddingInterpolation, secondPaddingInterpolation, collapseFraction)
|
||||
val textSize = (END + (START - END) * collapseFraction).sp
|
||||
Pair(dynamicPaddingStart, textSize)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SettingsScreen(
|
||||
settingsState: StateFlow<SettingsState>,
|
||||
topInsets: Dp,
|
||||
themeSettings: ThemeSettings,
|
||||
onBackClick: () -> Unit,
|
||||
onDarkModeClick: (Boolean?) -> Unit,
|
||||
onAmoledClick: (Boolean) -> Unit,
|
||||
onDynamicThemingClick: (Boolean) -> Unit,
|
||||
onAnimateClick: (Boolean) -> Unit,
|
||||
onPrivacyClick: () -> Unit,
|
||||
onLicenseClick: () -> Unit,
|
||||
onResetClick: () -> Unit,
|
||||
onContactClick: () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val topBarState = rememberCollapsingToolbarScaffoldState()
|
||||
val (dynamicPaddingStart, textSize) = calculateToolbarValues(topBarState.toolbarState.progress)
|
||||
|
||||
Scaffold {
|
||||
CollapsingToolbarScaffold(
|
||||
state = topBarState,
|
||||
modifier = Modifier.fillMaxSize().padding(it),
|
||||
scrollStrategy = ScrollStrategy.ExitUntilCollapsed,
|
||||
toolbar = {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(ToolbarConfig.LargeTopAppBarHeight)
|
||||
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp))
|
||||
.pin()
|
||||
)
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = stringResource(id = R.string.settings_screen),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
fontSize = textSize,
|
||||
modifier = Modifier
|
||||
.road(Alignment.CenterStart, Alignment.BottomStart)
|
||||
.padding(dynamicPaddingStart, 16.dp, 16.dp, 16.dp),
|
||||
)
|
||||
}
|
||||
) {
|
||||
SettingsContent(
|
||||
themeSettings = themeSettings,
|
||||
onDarkModeClick = onDarkModeClick,
|
||||
onAmoledClick = onAmoledClick,
|
||||
onDynamicThemingClick = onDynamicThemingClick,
|
||||
onAnimateClick = onAnimateClick,
|
||||
onPrivacyClick = onPrivacyClick,
|
||||
onResetClick = onResetClick,
|
||||
onContactClick = onContactClick,
|
||||
context = context
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SettingsContent(
|
||||
themeSettings: ThemeSettings,
|
||||
onDarkModeClick: (Boolean?) -> Unit,
|
||||
onAmoledClick: (Boolean) -> Unit,
|
||||
onDynamicThemingClick: (Boolean) -> Unit,
|
||||
onAnimateClick: (Boolean) -> Unit,
|
||||
onPrivacyClick: () -> Unit,
|
||||
onResetClick: () -> Unit,
|
||||
onContactClick: () -> Unit,
|
||||
context: android.content.Context
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 24.dp)
|
||||
) {
|
||||
AppearanceSection(themeSettings, onDarkModeClick, onAmoledClick, onDynamicThemingClick, onAnimateClick)
|
||||
AboutSection(context, onPrivacyClick, onContactClick, onResetClick)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AppearanceSection(
|
||||
themeSettings: ThemeSettings,
|
||||
onDarkModeClick: (Boolean?) -> Unit,
|
||||
onAmoledClick: (Boolean) -> Unit,
|
||||
onDynamicThemingClick: (Boolean) -> Unit,
|
||||
onAnimateClick: (Boolean) -> Unit
|
||||
) {
|
||||
ListSectionTitle(stringResource(R.string.appearance))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
DarkModeListItem(
|
||||
darkMode = themeSettings.darkMode,
|
||||
onDarkModeClick = onDarkModeClick
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
if (themeSettings.darkMode == null || themeSettings.darkMode == true) {
|
||||
AmoledListItem(
|
||||
amoledMode = themeSettings.amoledTheme,
|
||||
onAmoledClick = onAmoledClick
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
DynamicThemingListItem(
|
||||
dynamicTheming = themeSettings.dynamicTheming,
|
||||
onDynamicThemingClick = onDynamicThemingClick
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
AnimationListItem(
|
||||
animate = themeSettings.animate,
|
||||
onAnimateClick = onAnimateClick
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AboutSection(
|
||||
context: android.content.Context,
|
||||
onPrivacyClick: () -> Unit,
|
||||
onContactClick: () -> Unit,
|
||||
onResetClick: () -> Unit
|
||||
) {
|
||||
val scroll: ScrollState = rememberScrollState(0)
|
||||
val largeTopAppBarHeight = TopAppBarDefaults.LargeAppBarExpandedHeight
|
||||
val smallTopAppBarHeight = TopAppBarDefaults.LargeAppBarCollapsedHeight
|
||||
val paddingMedium = 16.dp
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
SettingsScrollableSettings(
|
||||
settingsState = settingsState,
|
||||
largeTopAppBarHeightPx = largeTopAppBarHeight,
|
||||
scroll = scroll,
|
||||
onDarkModeClick = onDarkModeClick,
|
||||
onDynamicThemingClick = onDynamicThemingClick,
|
||||
onAnimateClick = onAnimateClick,
|
||||
onPrivacyClick = onPrivacyClick,
|
||||
onLicenseClick = onLicenseClick,
|
||||
onResetClick = onResetClick,
|
||||
onBackClick = onBackClick,
|
||||
)
|
||||
SettingsTitle(
|
||||
scroll = scroll,
|
||||
largeTopAppBarHeight = largeTopAppBarHeight,
|
||||
smallTopAppBarHeight = smallTopAppBarHeight,
|
||||
paddingMedium = paddingMedium,
|
||||
topInset = topInsets
|
||||
)
|
||||
ListSectionTitle(stringResource(R.string.about))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
NotificationListItem {
|
||||
val intent = Intent().apply {
|
||||
action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
|
||||
putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
|
||||
}
|
||||
context.startActivity(intent)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
TranslateListItem {
|
||||
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Links.TRANSLATE)))
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PrivacyPolicyListItem(onPrivacyClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ContactListItem(onContactClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PaperizeListItem(
|
||||
onGitHubClick = { context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Links.GITHUB))) },
|
||||
onFdroidClick = { context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Links.FDROID))) },
|
||||
onIzzyOnDroidClick = { context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Links.IZZY))) }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ResetListItem(onResetClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
+76
-20
@@ -1,26 +1,82 @@
|
||||
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(
|
||||
val firstLaunch: Boolean = true,
|
||||
val firstSet: Boolean = true,
|
||||
// App settings
|
||||
val darkMode: Boolean? = null,
|
||||
val dynamicTheming: Boolean = false,
|
||||
val animate: Boolean = true,
|
||||
// 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 darkenPercentage: Int = 100,
|
||||
val darken: Boolean = false,
|
||||
val blur: Boolean = false,
|
||||
val blurPercentage: Int = 0,
|
||||
val wallpaperScaling: ScalingConstants = ScalingConstants.FILL
|
||||
)
|
||||
val initialized: Boolean = false,
|
||||
val themeSettings: ThemeSettings = ThemeSettings(),
|
||||
val wallpaperSettings: WallpaperSettings = WallpaperSettings(),
|
||||
val scheduleSettings: ScheduleSettings = ScheduleSettings(),
|
||||
val effectSettings: EffectSettings = EffectSettings()
|
||||
) {
|
||||
data class ThemeSettings(
|
||||
val darkMode: Boolean? = null,
|
||||
val amoledTheme: Boolean = false,
|
||||
val dynamicTheming: Boolean = false,
|
||||
val animate: Boolean = true
|
||||
)
|
||||
|
||||
data class WallpaperSettings(
|
||||
val enableChanger: Boolean = false,
|
||||
val setHomeWallpaper: Boolean = false,
|
||||
val setLockWallpaper: Boolean = false,
|
||||
val currentHomeWallpaper: String? = null,
|
||||
val currentLockWallpaper: String? = null,
|
||||
val nextHomeWallpaper: String? = null,
|
||||
val nextLockWallpaper: String? = null,
|
||||
val homeAlbumName: String? = null,
|
||||
val lockAlbumName: String? = null,
|
||||
val wallpaperScaling: ScalingConstants = ScalingConstants.FILL
|
||||
)
|
||||
|
||||
data class ScheduleSettings(
|
||||
val scheduleSeparately: Boolean = false,
|
||||
val shuffle: Boolean = true,
|
||||
val homeInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val lockInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val lastSetTime: String? = null,
|
||||
val nextSetTime: String? = null,
|
||||
val changeStartTime: Boolean = false,
|
||||
val startTime: Pair<Int, Int> = Pair(0, 0),
|
||||
val refresh: Boolean = true
|
||||
)
|
||||
|
||||
data class EffectSettings(
|
||||
val darken: Boolean = false,
|
||||
val homeDarkenPercentage: Int = 100,
|
||||
val lockDarkenPercentage: Int = 100,
|
||||
val blur: Boolean = false,
|
||||
val homeBlurPercentage: Int = 0,
|
||||
val lockBlurPercentage: Int = 0,
|
||||
val vignette: Boolean = false,
|
||||
val homeVignettePercentage: Int = 0,
|
||||
val lockVignettePercentage: Int = 0,
|
||||
val grayscale: Boolean = false,
|
||||
val homeGrayscalePercentage: Int = 0,
|
||||
val lockGrayscalePercentage: Int = 0
|
||||
)
|
||||
|
||||
data class ServiceSettings(
|
||||
val enableChanger: Boolean,
|
||||
val setHome: Boolean,
|
||||
val setLock: Boolean,
|
||||
val scaling: ScalingConstants,
|
||||
val darken: Boolean,
|
||||
val homeDarkenPercentage: Int,
|
||||
val lockDarkenPercentage: Int,
|
||||
val blur: Boolean,
|
||||
val homeBlurPercentage: Int,
|
||||
val lockBlurPercentage: Int,
|
||||
val vignette: Boolean,
|
||||
val homeVignettePercentage: Int,
|
||||
val lockVignettePercentage: Int,
|
||||
val grayscale: Boolean,
|
||||
val homeGrayscalePercentage: Int,
|
||||
val lockGrayscalePercentage: Int,
|
||||
val lockAlbumName: String,
|
||||
val homeAlbumName: String,
|
||||
val shuffle: Boolean
|
||||
)
|
||||
}
|
||||
+455
-274
@@ -4,11 +4,14 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.EffectSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ScheduleSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ThemeSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.WallpaperSettings
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
@@ -20,238 +23,258 @@ import java.time.format.FormatStyle
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class SettingsViewModel @Inject constructor (
|
||||
class SettingsViewModel @Inject constructor(
|
||||
private val settingsDataStoreImpl: SettingsDataStore
|
||||
): ViewModel() {
|
||||
) : ViewModel() {
|
||||
private val _state = MutableStateFlow(SettingsState())
|
||||
val state = _state.stateIn(
|
||||
viewModelScope,
|
||||
SharingStarted.WhileSubscribed(5000), SettingsState()
|
||||
SharingStarted.WhileSubscribed(5000),
|
||||
SettingsState()
|
||||
)
|
||||
|
||||
private var currentGetJob: Job? = null
|
||||
var setKeepOnScreenCondition: Boolean = true
|
||||
|
||||
init {
|
||||
currentGetJob = viewModelScope.launch(Dispatchers.IO) {
|
||||
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
|
||||
val firstSet = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_SET) ?: false }
|
||||
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(),
|
||||
homeInterval = homeWallpaperInterval.await(),
|
||||
lockInterval = lockWallpaperInterval.await(),
|
||||
firstLaunch = firstLaunch.await(),
|
||||
firstSet = firstSet.await(),
|
||||
lastSetTime = lastSetTime.await(),
|
||||
nextSetTime = nextSetTime.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
|
||||
viewModelScope.launch {
|
||||
combine(
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.FIRST_LAUNCH),
|
||||
loadThemeSettingsFlow(),
|
||||
loadWallpaperSettingsFlow(),
|
||||
loadScheduleSettingsFlow(),
|
||||
loadEffectSettingsFlow()
|
||||
) { firstLaunch, themeSettings, wallpaperSettings, scheduleSettings, effectSettings ->
|
||||
_state.update {
|
||||
it.copy(
|
||||
firstLaunch = firstLaunch ?: true,
|
||||
initialized = true,
|
||||
themeSettings = themeSettings,
|
||||
wallpaperSettings = wallpaperSettings,
|
||||
scheduleSettings = scheduleSettings,
|
||||
effectSettings = effectSettings
|
||||
)
|
||||
}
|
||||
setKeepOnScreenCondition = false
|
||||
}.collect()
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadThemeSettingsFlow(): Flow<ThemeSettings> = combine(
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.DARK_MODE_TYPE),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.AMOLED_THEME_TYPE),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.DYNAMIC_THEME_TYPE),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.ANIMATE_TYPE)
|
||||
) { darkMode, amoledTheme, dynamicTheming, animate ->
|
||||
ThemeSettings(
|
||||
darkMode = darkMode,
|
||||
amoledTheme = amoledTheme ?: false,
|
||||
dynamicTheming = dynamicTheming ?: false,
|
||||
animate = animate ?: true
|
||||
)
|
||||
}
|
||||
|
||||
private fun loadWallpaperSettingsFlow(): Flow<WallpaperSettings> = combine(
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.ENABLE_CHANGER),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.ENABLE_HOME_WALLPAPER),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.ENABLE_LOCK_WALLPAPER),
|
||||
settingsDataStoreImpl.getStringFlow(SettingsConstants.CURRENT_HOME_WALLPAPER),
|
||||
settingsDataStoreImpl.getStringFlow(SettingsConstants.CURRENT_LOCK_WALLPAPER),
|
||||
settingsDataStoreImpl.getStringFlow(SettingsConstants.NEXT_HOME_WALLPAPER),
|
||||
settingsDataStoreImpl.getStringFlow(SettingsConstants.NEXT_LOCK_WALLPAPER),
|
||||
settingsDataStoreImpl.getStringFlow(SettingsConstants.HOME_ALBUM_NAME),
|
||||
settingsDataStoreImpl.getStringFlow(SettingsConstants.LOCK_ALBUM_NAME),
|
||||
settingsDataStoreImpl.getStringFlow(SettingsConstants.WALLPAPER_SCALING)
|
||||
) { flows ->
|
||||
WallpaperSettings(
|
||||
enableChanger = flows[0] as Boolean? ?: false,
|
||||
setHomeWallpaper = flows[1] as Boolean? ?: false,
|
||||
setLockWallpaper = flows[2] as Boolean? ?: false,
|
||||
currentHomeWallpaper = flows[3] as String?,
|
||||
currentLockWallpaper = flows[4] as String?,
|
||||
nextHomeWallpaper = flows[5] as String?,
|
||||
nextLockWallpaper = flows[6] as String?,
|
||||
homeAlbumName = flows[7] as String?,
|
||||
lockAlbumName = flows[8] as String?,
|
||||
wallpaperScaling = ScalingConstants.valueOf((flows[9] as String?) ?: ScalingConstants.FILL.name)
|
||||
)
|
||||
}
|
||||
|
||||
private fun loadScheduleSettingsFlow(): Flow<ScheduleSettings> = combine(
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.SCHEDULE_SEPARATELY),
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL),
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL),
|
||||
settingsDataStoreImpl.getStringFlow(SettingsConstants.LAST_SET_TIME),
|
||||
settingsDataStoreImpl.getStringFlow(SettingsConstants.NEXT_SET_TIME),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.CHANGE_START_TIME),
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.START_HOUR),
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.START_MINUTE),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.SHUFFLE),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.REFRESH)
|
||||
) { flows ->
|
||||
ScheduleSettings(
|
||||
scheduleSeparately = flows[0] as Boolean? ?: false,
|
||||
homeInterval = flows[1] as Int? ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
lockInterval = flows[2] as Int? ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
lastSetTime = flows[3] as String?,
|
||||
nextSetTime = flows[4] as String?,
|
||||
changeStartTime = flows[5] as Boolean? ?: false,
|
||||
startTime = Pair(flows[6] as Int? ?: 0, flows[7] as Int? ?: 0),
|
||||
shuffle = flows[8] as Boolean? ?: true,
|
||||
refresh = flows[9] as Boolean? ?: true
|
||||
)
|
||||
}
|
||||
|
||||
private fun loadEffectSettingsFlow(): Flow<EffectSettings> = combine(
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.DARKEN),
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.HOME_DARKEN_PERCENTAGE),
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.LOCK_DARKEN_PERCENTAGE),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.BLUR),
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.HOME_BLUR_PERCENTAGE),
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.LOCK_BLUR_PERCENTAGE),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.VIGNETTE),
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.HOME_VIGNETTE_PERCENTAGE),
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.GRAYSCALE),
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE),
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE)
|
||||
) { flows ->
|
||||
EffectSettings(
|
||||
darken = flows[0] as Boolean? ?: false,
|
||||
homeDarkenPercentage = flows[1] as Int? ?: 100,
|
||||
lockDarkenPercentage = flows[2] as Int? ?: 100,
|
||||
blur = flows[3] as Boolean? ?: false,
|
||||
homeBlurPercentage = flows[4] as Int? ?: 0,
|
||||
lockBlurPercentage = flows[5] as Int? ?: 0,
|
||||
vignette = flows[6] as Boolean? ?: false,
|
||||
homeVignettePercentage = flows[7] as Int? ?: 0,
|
||||
lockVignettePercentage = flows[8] as Int? ?: 0,
|
||||
grayscale = flows[9] as Boolean? ?: false,
|
||||
homeGrayscalePercentage = flows[10] as Int? ?: 0,
|
||||
lockGrayscalePercentage = flows[11] as Int? ?: 0
|
||||
)
|
||||
}
|
||||
|
||||
private fun calculateNextSetTime(currentTime: LocalDateTime, scheduleSettings: ScheduleSettings): Triple<LocalDateTime, LocalDateTime, LocalDateTime> {
|
||||
val homeNextTime = when {
|
||||
scheduleSettings.changeStartTime -> currentTime
|
||||
else -> currentTime.plusMinutes(scheduleSettings.homeInterval.toLong())
|
||||
}
|
||||
|
||||
val lockNextTime = when {
|
||||
scheduleSettings.changeStartTime -> currentTime
|
||||
else -> currentTime.plusMinutes(scheduleSettings.lockInterval.toLong())
|
||||
}
|
||||
|
||||
val nextSetTime = when {
|
||||
scheduleSettings.changeStartTime -> currentTime
|
||||
scheduleSettings.scheduleSeparately -> if (homeNextTime.isBefore(lockNextTime)) homeNextTime else lockNextTime
|
||||
else -> homeNextTime
|
||||
}
|
||||
|
||||
return Triple(nextSetTime, homeNextTime, lockNextTime)
|
||||
}
|
||||
|
||||
fun onEvent(event: SettingsEvent) {
|
||||
when (event) {
|
||||
is SettingsEvent.SetFirstLaunch -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.FIRST_LAUNCH, false)
|
||||
_state.update {
|
||||
it.copy(
|
||||
firstLaunch = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetChangerToggle -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
viewModelScope.launch {
|
||||
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 }
|
||||
val firstSet = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_SET) ?: true }
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = darkMode.await(),
|
||||
dynamicTheming = dynamicTheming.await(),
|
||||
firstLaunch = firstLaunch.await(),
|
||||
lastSetTime = lastSetTime.await(),
|
||||
nextSetTime = nextSetTime.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(),
|
||||
firstSet = firstSet.await()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetDarkMode -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
viewModelScope.launch {
|
||||
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) }
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = event.darkMode
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetAmoledTheme -> {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.AMOLED_THEME_TYPE, event.amoledTheme)
|
||||
if (event.amoledTheme) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.DYNAMIC_THEME_TYPE, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetDynamicTheming -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.DYNAMIC_THEME_TYPE, event.dynamicTheming)
|
||||
_state.update {
|
||||
it.copy(
|
||||
dynamicTheming = event.dynamicTheming
|
||||
)
|
||||
if (event.dynamicTheming) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.AMOLED_THEME_TYPE, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetAnimate -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ANIMATE_TYPE, event.animate)
|
||||
_state.update {
|
||||
it.copy(
|
||||
animate = event.animate
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetFirstSet -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.FIRST_SET, false)
|
||||
_state.update {
|
||||
it.copy(
|
||||
firstSet = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetHomeWallpaperInterval -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL, event.interval)
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now()
|
||||
val currentTime = if (_state.value.scheduleSettings.changeStartTime) {
|
||||
LocalDateTime.now().withHour(_state.value.scheduleSettings.startTime.first)
|
||||
.withMinute(_state.value.scheduleSettings.startTime.second)
|
||||
} else {
|
||||
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)
|
||||
if (_state.value.scheduleSettings.scheduleSeparately) {
|
||||
val homeNextSetTime = currentTime.plusMinutes(event.interval.toLong())
|
||||
val lockNextSetTime = currentTime.plusMinutes(_state.value.scheduleSettings.lockInterval.toLong())
|
||||
nextSetTime = (if (homeNextSetTime!!.isBefore(lockNextSetTime)) homeNextSetTime else lockNextSetTime)!!.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())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, homeNextSetTime.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, lockNextSetTime.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(
|
||||
homeInterval = event.interval,
|
||||
lastSetTime = currentTime.format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetLockWallpaperInterval -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL, event.interval)
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now()
|
||||
val currentTime = if (_state.value.scheduleSettings.changeStartTime) {
|
||||
LocalDateTime.now().withHour(_state.value.scheduleSettings.startTime.first)
|
||||
.withMinute(_state.value.scheduleSettings.startTime.second)
|
||||
} else {
|
||||
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())
|
||||
if (_state.value.scheduleSettings.scheduleSeparately) {
|
||||
val nextSetTime1 = currentTime.plusMinutes(_state.value.scheduleSettings.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())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime1.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, 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(
|
||||
lockInterval = event.interval,
|
||||
lastSetTime = currentTime.format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -259,158 +282,316 @@ class SettingsViewModel @Inject constructor (
|
||||
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)
|
||||
val currentTime = if (_state.value.scheduleSettings.changeStartTime) {
|
||||
var calculatedTime = LocalDateTime.now()
|
||||
.withHour(_state.value.scheduleSettings.startTime.first)
|
||||
.withMinute(_state.value.scheduleSettings.startTime.second)
|
||||
if (calculatedTime.isBefore(LocalDateTime.now())) {
|
||||
calculatedTime = calculatedTime.plusDays(1)
|
||||
}
|
||||
calculatedTime
|
||||
} else {
|
||||
LocalDateTime.now()
|
||||
}
|
||||
else {
|
||||
nextSetTime = currentTime.plusMinutes(_state.value.homeInterval.toLong()).format(formatter)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
lastSetTime = currentTime.format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
|
||||
val (nextSetTime, homeNextTime, lockNextTime) = calculateNextSetTime(
|
||||
currentTime,
|
||||
_state.value.scheduleSettings
|
||||
)
|
||||
|
||||
settingsDataStoreImpl.run {
|
||||
putString(SettingsConstants.LAST_SET_TIME, LocalDateTime.now().format(formatter))
|
||||
putString(SettingsConstants.NEXT_SET_TIME, nextSetTime.format(formatter))
|
||||
putString(SettingsConstants.HOME_NEXT_SET_TIME, homeNextTime.toString())
|
||||
putString(SettingsConstants.LOCK_NEXT_SET_TIME, lockNextTime.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetHome -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.HOME_WALLPAPER, event.home)
|
||||
_state.update {
|
||||
it.copy(
|
||||
setHomeWallpaper = event.home
|
||||
)
|
||||
}
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER, 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
|
||||
)
|
||||
}
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER, event.lock)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetDarken -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.DARKEN, event.darken)
|
||||
_state.update {
|
||||
it.copy(
|
||||
darken = event.darken
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetWallpaperScaling -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.WALLPAPER_SCALING, event.scaling.name)
|
||||
_state.update {
|
||||
it.copy(
|
||||
wallpaperScaling = event.scaling
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetScheduleSeparately -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.SCHEDULE_SEPARATELY, event.scheduleSeparately)
|
||||
_state.update {
|
||||
it.copy(
|
||||
scheduleSeparately = event.scheduleSeparately
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetBlur -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.BLUR, event.blur)
|
||||
_state.update {
|
||||
it.copy(
|
||||
blur = event.blur
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetDarkenPercentage -> {
|
||||
viewModelScope.launch {
|
||||
if (event.lockDarkenPercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.LOCK_DARKEN_PERCENTAGE, event.lockDarkenPercentage)
|
||||
}
|
||||
if (event.homeDarkenPercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.HOME_DARKEN_PERCENTAGE, event.homeDarkenPercentage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetBlurPercentage -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.BLUR_PERCENTAGE, event.blurPercentage)
|
||||
viewModelScope.launch {
|
||||
if (event.lockBlurPercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.LOCK_BLUR_PERCENTAGE, event.lockBlurPercentage)
|
||||
}
|
||||
if (event.homeBlurPercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.HOME_BLUR_PERCENTAGE, event.homeBlurPercentage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetVignette -> {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.VIGNETTE, event.vignette)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetVignettePercentage -> {
|
||||
viewModelScope.launch {
|
||||
if (event.lockVignettePercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE, event.lockVignettePercentage)
|
||||
}
|
||||
if (event.homeVignettePercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE, event.homeVignettePercentage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetGrayscale -> {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.GRAYSCALE, event.grayscale)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetGrayscalePercentage -> {
|
||||
viewModelScope.launch {
|
||||
if (event.lockGrayscalePercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE, event.lockGrayscalePercentage)
|
||||
}
|
||||
if (event.homeGrayscalePercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE, event.homeGrayscalePercentage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetCurrentWallpaper -> {
|
||||
viewModelScope.launch {
|
||||
if (event.currentLockWallpaper != null) {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.CURRENT_LOCK_WALLPAPER, event.currentLockWallpaper)
|
||||
}
|
||||
if (event.currentHomeWallpaper != null) {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.CURRENT_HOME_WALLPAPER, event.currentHomeWallpaper)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
blurPercentage = event.blurPercentage
|
||||
wallpaperSettings = it.wallpaperSettings.copy(
|
||||
currentLockWallpaper = event.currentLockWallpaper ?: it.wallpaperSettings.currentLockWallpaper,
|
||||
currentHomeWallpaper = event.currentHomeWallpaper ?: it.wallpaperSettings.currentHomeWallpaper
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.Reset -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARK_MODE_TYPE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DYNAMIC_THEME_TYPE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.FIRST_LAUNCH)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LAST_SET_TIME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ANIMATE_TYPE)
|
||||
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,
|
||||
firstLaunch = true,
|
||||
lastSetTime = null,
|
||||
nextSetTime = null,
|
||||
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,
|
||||
firstSet = true
|
||||
)
|
||||
is SettingsEvent.SetAlbum -> {
|
||||
viewModelScope.launch {
|
||||
event.lockAlbumName?.let { settingsDataStoreImpl.putString(SettingsConstants.LOCK_ALBUM_NAME, it) }
|
||||
event.homeAlbumName?.let { settingsDataStoreImpl.putString(SettingsConstants.HOME_ALBUM_NAME, it) }
|
||||
val enableChanger: Boolean = when {
|
||||
event.homeAlbumName != null && event.lockAlbumName != null -> { true }
|
||||
event.homeAlbumName != null && !_state.value.wallpaperSettings.lockAlbumName.isNullOrEmpty() -> { true }
|
||||
event.lockAlbumName != null && !_state.value.wallpaperSettings.homeAlbumName.isNullOrEmpty() -> { true }
|
||||
else -> { false }
|
||||
}
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, enableChanger)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.RemoveSelectedAlbumAsType -> {
|
||||
viewModelScope.launch {
|
||||
if (_state.value.wallpaperSettings.setLockWallpaper && _state.value.wallpaperSettings.setHomeWallpaper) {
|
||||
if (event.removeLock) {
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME)
|
||||
}
|
||||
if (event.removeHome) {
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.HOME_ALBUM_NAME)
|
||||
}
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_LOCK_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_HOME_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LAST_SET_TIME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME)
|
||||
}
|
||||
else {
|
||||
if (event.removeLock) {
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_LOCK_WALLPAPER)
|
||||
}
|
||||
if (event.removeHome) {
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.HOME_ALBUM_NAME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_HOME_WALLPAPER)
|
||||
}
|
||||
}
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ENABLE_CHANGER)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.RemoveSelectedAlbumAsName -> {
|
||||
viewModelScope.launch {
|
||||
var enableChanger = _state.value.wallpaperSettings.enableChanger
|
||||
if (event.albumName == _state.value.wallpaperSettings.lockAlbumName) {
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_LOCK_WALLPAPER)
|
||||
enableChanger = false
|
||||
}
|
||||
if (event.albumName == _state.value.wallpaperSettings.homeAlbumName) {
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.HOME_ALBUM_NAME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_HOME_WALLPAPER)
|
||||
enableChanger = false
|
||||
}
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, enableChanger)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetChangeStartTime -> {
|
||||
viewModelScope.launch {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = if (event.changeStartTime) {
|
||||
LocalDateTime.now()
|
||||
.withHour(_state.value.scheduleSettings.startTime.first)
|
||||
.withMinute(_state.value.scheduleSettings.startTime.second)
|
||||
.let {
|
||||
if (it.isBefore(LocalDateTime.now())) it.plusDays(1) else it
|
||||
}
|
||||
} else {
|
||||
LocalDateTime.now()
|
||||
}
|
||||
val nextSetTime = when {
|
||||
event.changeStartTime -> {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.toString())
|
||||
currentTime.format(formatter)
|
||||
}
|
||||
_state.value.scheduleSettings.scheduleSeparately -> {
|
||||
val nextSetTime1 = currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong())
|
||||
val nextSetTime2 = currentTime.plusMinutes(_state.value.scheduleSettings.lockInterval.toLong())
|
||||
val nextSetTime = if (nextSetTime1.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime1.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime2.toString())
|
||||
nextSetTime.format(formatter)
|
||||
}
|
||||
else -> {
|
||||
val nextSetTime = currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime.toString())
|
||||
nextSetTime.format(formatter)
|
||||
}
|
||||
}
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.CHANGE_START_TIME, event.changeStartTime)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetStartTime -> {
|
||||
viewModelScope.launch {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now().withHour(event.hour).withMinute(event.minute).let {
|
||||
if (it.isBefore(LocalDateTime.now())) it.plusDays(1) else it
|
||||
}
|
||||
val nextSetTime = currentTime.format(formatter)
|
||||
settingsDataStoreImpl.run {
|
||||
putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.toString())
|
||||
putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.toString())
|
||||
putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
putInt(SettingsConstants.START_HOUR, event.hour)
|
||||
putInt(SettingsConstants.START_MINUTE, event.minute)
|
||||
putBoolean(SettingsConstants.CHANGE_START_TIME, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetShuffle -> {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.SHUFFLE, event.shuffle)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetRefresh -> {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.REFRESH, event.refresh)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.Reset -> {
|
||||
viewModelScope.launch {
|
||||
val keysToDelete = listOf(
|
||||
SettingsConstants.DARK_MODE_TYPE,
|
||||
SettingsConstants.AMOLED_THEME_TYPE,
|
||||
SettingsConstants.DYNAMIC_THEME_TYPE,
|
||||
SettingsConstants.FIRST_LAUNCH,
|
||||
SettingsConstants.LAST_SET_TIME,
|
||||
SettingsConstants.NEXT_SET_TIME,
|
||||
SettingsConstants.ANIMATE_TYPE,
|
||||
SettingsConstants.ENABLE_CHANGER,
|
||||
SettingsConstants.HOME_DARKEN_PERCENTAGE,
|
||||
SettingsConstants.LOCK_DARKEN_PERCENTAGE,
|
||||
SettingsConstants.DARKEN,
|
||||
SettingsConstants.WALLPAPER_SCALING,
|
||||
SettingsConstants.ENABLE_HOME_WALLPAPER,
|
||||
SettingsConstants.ENABLE_LOCK_WALLPAPER,
|
||||
SettingsConstants.CURRENT_HOME_WALLPAPER,
|
||||
SettingsConstants.CURRENT_LOCK_WALLPAPER,
|
||||
SettingsConstants.HOME_ALBUM_NAME,
|
||||
SettingsConstants.LOCK_ALBUM_NAME,
|
||||
SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL,
|
||||
SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL,
|
||||
SettingsConstants.SCHEDULE_SEPARATELY,
|
||||
SettingsConstants.BLUR,
|
||||
SettingsConstants.HOME_BLUR_PERCENTAGE,
|
||||
SettingsConstants.LOCK_BLUR_PERCENTAGE,
|
||||
SettingsConstants.FIRST_SET,
|
||||
SettingsConstants.HOME_NEXT_SET_TIME,
|
||||
SettingsConstants.LOCK_NEXT_SET_TIME,
|
||||
SettingsConstants.NEXT_HOME_WALLPAPER,
|
||||
SettingsConstants.NEXT_LOCK_WALLPAPER,
|
||||
SettingsConstants.VIGNETTE,
|
||||
SettingsConstants.HOME_VIGNETTE_PERCENTAGE,
|
||||
SettingsConstants.LOCK_VIGNETTE_PERCENTAGE,
|
||||
SettingsConstants.GRAYSCALE,
|
||||
SettingsConstants.HOME_GRAYSCALE_PERCENTAGE,
|
||||
SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE,
|
||||
SettingsConstants.CHANGE_START_TIME,
|
||||
SettingsConstants.START_HOUR,
|
||||
SettingsConstants.START_MINUTE,
|
||||
SettingsConstants.SHUFFLE,
|
||||
SettingsConstants.REFRESH
|
||||
)
|
||||
settingsDataStoreImpl.clear(keysToDelete)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
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.filled.DarkMode
|
||||
import androidx.compose.material3.Icon
|
||||
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.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
|
||||
|
||||
/**
|
||||
* AMOLED list item to enable AMOLED mode
|
||||
*/
|
||||
@Composable
|
||||
fun AmoledListItem(amoledMode: Boolean, onAmoledClick: (Boolean) -> Unit) {
|
||||
val context = LocalContext.current
|
||||
Row {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.clickable { onAmoledClick(!amoledMode) },
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.amoled_mode),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.full_dark_mode),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {
|
||||
Switch(
|
||||
modifier = Modifier.semantics { contentDescription = context.getString(R.string.amoled_mode) },
|
||||
checked = amoledMode,
|
||||
onCheckedChange = onAmoledClick,
|
||||
enabled = true
|
||||
) },
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.Filled.DarkMode,
|
||||
contentDescription = stringResource(R.string.amoled_mode),
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
) },
|
||||
tonalElevation = 5.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -15,7 +15,6 @@ import androidx.compose.material.icons.outlined.Brightness6
|
||||
import androidx.compose.material.icons.outlined.BrightnessAuto
|
||||
import androidx.compose.material.icons.outlined.DarkMode
|
||||
import androidx.compose.material.icons.outlined.LightMode
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -38,7 +37,6 @@ import com.anthonyla.paperize.R
|
||||
/**
|
||||
* Three-state selector for dark mode in settings
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun DarkModeListItem(darkMode: Boolean?, onDarkModeClick: (Boolean?) -> Unit) {
|
||||
val options = listOf(
|
||||
@@ -77,7 +75,7 @@ fun DarkModeListItem(darkMode: Boolean?, onDarkModeClick: (Boolean?) -> Unit) {
|
||||
},
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.dark_mode),
|
||||
text = stringResource(R.string.theme),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
|
||||
) },
|
||||
|
||||
+10
-9
@@ -1,9 +1,10 @@
|
||||
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.automirrored.outlined.LibraryBooks
|
||||
import androidx.compose.material.icons.outlined.Notifications
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -16,33 +17,33 @@ import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* A list item that displays the licenses
|
||||
* Notification list item to send to the notification permission page
|
||||
*/
|
||||
@Composable
|
||||
fun LicenseListItem(onLicenseClick: () -> Unit) {
|
||||
fun NotificationListItem(onClick: () -> Unit) {
|
||||
Row {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.clickable { onLicenseClick() },
|
||||
.clickable { onClick() },
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.licenses),
|
||||
text = stringResource(R.string.notifications),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.click_here_to_view_the_licenses),
|
||||
text = stringResource(R.string.change_notification_settings),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {},
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.AutoMirrored.Outlined.LibraryBooks,
|
||||
contentDescription = stringResource(R.string.licenses),
|
||||
Icons.Outlined.Notifications,
|
||||
contentDescription = stringResource(R.string.notifications),
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
) },
|
||||
tonalElevation = 5.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-20
@@ -36,13 +36,13 @@ 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) {
|
||||
fun PaperizeListItem(onGitHubClick: () -> Unit, onIzzyOnDroidClick: () -> Unit, onFdroidClick: () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
var version = ""
|
||||
try {
|
||||
val pInfo: PackageInfo =
|
||||
context.packageManager.getPackageInfo(context.packageName, 0)
|
||||
version = pInfo.versionName
|
||||
version = pInfo.versionName.toString()
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
@@ -106,25 +106,7 @@ fun PaperizeListItem(onGitHubClick: () -> Unit, onPlaystoreClick: () -> Unit, on
|
||||
tint = MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
IconButton(
|
||||
onClick = onPlaystoreClick,
|
||||
modifier = Modifier
|
||||
.size(60.dp)
|
||||
.background(MaterialTheme.colorScheme.primary, CircleShape)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(id = R.drawable.google_play),
|
||||
contentDescription = "Playstore",
|
||||
modifier = Modifier.size(12.dp),
|
||||
tint = MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
IconButton(
|
||||
onClick = onFdroidClick,
|
||||
modifier = Modifier
|
||||
@@ -138,6 +120,20 @@ fun PaperizeListItem(onGitHubClick: () -> Unit, onPlaystoreClick: () -> Unit, on
|
||||
tint = MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
IconButton(
|
||||
onClick = onIzzyOnDroidClick,
|
||||
modifier = Modifier
|
||||
.size(60.dp)
|
||||
.background(MaterialTheme.colorScheme.primary, CircleShape)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(id = R.drawable.izzyondroid),
|
||||
contentDescription = "Izzy-On-Droid-Droid",
|
||||
modifier = Modifier.size(32.dp),
|
||||
tint = MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-185
@@ -1,185 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
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
|
||||
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.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
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* Scrollable settings screen to wrap all settings components
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SettingsScrollableSettings(
|
||||
settingsState: StateFlow<SettingsState>,
|
||||
largeTopAppBarHeightPx: Dp,
|
||||
scroll: ScrollState,
|
||||
onDynamicThemingClick: (Boolean) -> Unit,
|
||||
onDarkModeClick: (Boolean?) -> Unit,
|
||||
onAnimateClick: (Boolean) -> Unit,
|
||||
onPrivacyClick: () -> Unit,
|
||||
onLicenseClick: () -> Unit,
|
||||
onResetClick: () -> Unit,
|
||||
onBackClick: () -> Unit
|
||||
) {
|
||||
val state = settingsState.collectAsStateWithLifecycle()
|
||||
val context = LocalContext.current
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
var toContact by rememberSaveable { mutableStateOf(false) }
|
||||
if (toContact) {
|
||||
Contact(context)
|
||||
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 = {
|
||||
SnackbarHost(
|
||||
hostState = snackbarHostState,
|
||||
snackbar = { data ->
|
||||
Snackbar(
|
||||
snackbarData = data,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 16.dp, vertical = 24.dp)),
|
||||
shape = RoundedCornerShape(24.dp)
|
||||
)
|
||||
}
|
||||
) },
|
||||
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(
|
||||
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))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ListSectionTitle(stringResource(R.string.appearance))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
DarkModeListItem(
|
||||
darkMode = state.value.darkMode,
|
||||
onDarkModeClick = { onDarkModeClick(it) }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
DynamicThemingListItem(
|
||||
dynamicTheming = state.value.dynamicTheming,
|
||||
onDynamicThemingClick = { onDynamicThemingClick(it) }
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
AnimationListItem(
|
||||
animate = state.value.animate,
|
||||
onAnimateClick = { onAnimateClick(it) }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
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))
|
||||
LicenseListItem(onLicenseClick = onLicenseClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ContactListItem(onContactClick = { toContact = true })
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PaperizeListItem(
|
||||
onGitHubClick = {
|
||||
val openURL = Intent(Intent.ACTION_VIEW)
|
||||
openURL.data = Uri.parse(githubLink)
|
||||
context.startActivity(openURL)
|
||||
},
|
||||
onPlaystoreClick = {
|
||||
val openURL = Intent(Intent.ACTION_VIEW)
|
||||
openURL.data = Uri.parse(playstoreLink)
|
||||
context.startActivity(openURL)
|
||||
},
|
||||
onFdroidClick = {
|
||||
coroutineScope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
snackbarHostState.showSnackbar(
|
||||
message = context.getString(R.string.coming_soon),
|
||||
actionLabel = context.getString(R.string.dismiss),
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ResetListItem(onResetClick = onResetClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
-106
@@ -1,106 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Title for the settings screen.
|
||||
*/
|
||||
@Composable
|
||||
fun SettingsTitle(
|
||||
largeTopAppBarHeight: Dp,
|
||||
smallTopAppBarHeight: Dp,
|
||||
paddingMedium: Dp,
|
||||
scroll: ScrollState,
|
||||
topInset: Dp,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val titlePaddingStart = 16.dp
|
||||
val titlePaddingEnd = 64.dp
|
||||
val titleFontScaleStart = 1f
|
||||
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),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
fontSize = 30.sp,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
modifier = modifier
|
||||
.graphicsLayer {
|
||||
val collapseRange: Float = (largeTopAppBarHeight.toPx() - smallTopAppBarHeight.toPx())
|
||||
val collapseFraction: Float = (scroll.value / collapseRange).coerceIn(0f, 1f)
|
||||
|
||||
val scaleXY = lerp(
|
||||
titleFontScaleStart.dp,
|
||||
titleFontScaleEnd.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleExtraStartPadding = titleWidthPx.toDp() * (1 - scaleXY.value) / 2f
|
||||
|
||||
val titleYFirstInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium + statusPadding,
|
||||
largeTopAppBarHeight / 2,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleXFirstInterpolatedPoint = lerp(
|
||||
titlePaddingStart,
|
||||
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleYSecondInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight / 2,
|
||||
(smallTopAppBarHeight + statusPadding - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleXSecondInterpolatedPoint = lerp(
|
||||
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
|
||||
titlePaddingEnd - titleExtraStartPadding,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleY = lerp(
|
||||
titleYFirstInterpolatedPoint,
|
||||
titleYSecondInterpolatedPoint,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleX = lerp(
|
||||
titleXFirstInterpolatedPoint,
|
||||
titleXSecondInterpolatedPoint,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
translationY = titleY.toPx()
|
||||
translationX = titleX.toPx()
|
||||
scaleX = scaleXY.value
|
||||
scaleY = scaleXY.value
|
||||
}
|
||||
.onGloballyPositioned {
|
||||
titleHeightPx = it.size.height.toFloat()
|
||||
titleWidthPx = it.size.width.toFloat()
|
||||
}
|
||||
)
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.sort_view_screen
|
||||
|
||||
import androidx.compose.foundation.lazy.LazyListItemInfo
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
|
||||
sealed class SortEvent {
|
||||
data object Reset: SortEvent()
|
||||
|
||||
data class LoadSortView(
|
||||
val folders: List<Folder>,
|
||||
val wallpapers: List<Wallpaper>
|
||||
): SortEvent()
|
||||
|
||||
data class ShiftFolder(
|
||||
val from: LazyListItemInfo,
|
||||
val to: LazyListItemInfo
|
||||
): SortEvent()
|
||||
|
||||
data class ShiftWallpaper(
|
||||
val from: LazyListItemInfo,
|
||||
val to: LazyListItemInfo
|
||||
): SortEvent()
|
||||
|
||||
data class ShiftFolderWallpaper(
|
||||
val folderId: String,
|
||||
val from: LazyListItemInfo,
|
||||
val to: LazyListItemInfo
|
||||
): SortEvent()
|
||||
|
||||
data object SortAlphabetically : SortEvent()
|
||||
data object SortAlphabeticallyReverse : SortEvent()
|
||||
data object SortByLastModified : SortEvent()
|
||||
data object SortByLastModifiedReverse : SortEvent()
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.sort_view_screen
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
|
||||
data class SortState(
|
||||
val folders: List<Folder> = emptyList(),
|
||||
val wallpapers: List<Wallpaper> = emptyList()
|
||||
)
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.sort_view_screen
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* ViewModel for the sort view screen to hold the folders and wallpapers
|
||||
*/
|
||||
class SortViewModel @Inject constructor (): ViewModel() {
|
||||
private val _state = MutableStateFlow<SortState>(SortState())
|
||||
val state = _state.stateIn(
|
||||
scope = viewModelScope,
|
||||
started = SharingStarted.WhileSubscribed(5000),
|
||||
initialValue = SortState()
|
||||
)
|
||||
|
||||
fun onEvent(event: SortEvent) {
|
||||
when (event) {
|
||||
is SortEvent.LoadSortView -> {
|
||||
_state.value = state.value.copy(
|
||||
folders = event.folders,
|
||||
wallpapers = event.wallpapers
|
||||
)
|
||||
}
|
||||
|
||||
is SortEvent.ShiftFolder -> {
|
||||
val currentFolders = state.value.folders.toMutableList()
|
||||
val fromIndex = currentFolders.indexOfFirst { it.folderUri == event.from.key }
|
||||
val toIndex = currentFolders.indexOfFirst { it.folderUri == event.to.key }
|
||||
val movedFolder = currentFolders.removeAt(fromIndex)
|
||||
currentFolders.add(toIndex, movedFolder)
|
||||
currentFolders.forEachIndexed { index, folder ->
|
||||
currentFolders[index] = folder.copy(order = index)
|
||||
}
|
||||
_state.value = state.value.copy(folders = currentFolders)
|
||||
}
|
||||
|
||||
is SortEvent.ShiftFolderWallpaper -> {
|
||||
val folder = state.value.folders.find { it.folderUri == event.folderId }
|
||||
val currentWallpapers = folder?.wallpapers?.toMutableList() ?: return
|
||||
val fromIndex = currentWallpapers.indexOfFirst { it.wallpaperUri == event.from.key }
|
||||
val toIndex = currentWallpapers.indexOfFirst { it.wallpaperUri == event.to.key }
|
||||
val movedWallpaper = currentWallpapers.removeAt(fromIndex)
|
||||
currentWallpapers.add(toIndex, movedWallpaper)
|
||||
currentWallpapers.forEachIndexed { index, wallpaper ->
|
||||
currentWallpapers[index] = wallpaper.copy(order = index)
|
||||
}
|
||||
val updatedFolders = state.value.folders.map { folder ->
|
||||
if (folder.folderUri == event.folderId) {
|
||||
folder.copy(
|
||||
wallpapers = currentWallpapers,
|
||||
coverUri = currentWallpapers.firstOrNull()?.wallpaperUri ?: folder.coverUri
|
||||
)
|
||||
} else {
|
||||
folder
|
||||
}
|
||||
}
|
||||
_state.value = state.value.copy(folders = updatedFolders)
|
||||
}
|
||||
|
||||
is SortEvent.ShiftWallpaper -> {
|
||||
val currentWallpapers = state.value.wallpapers.toMutableList()
|
||||
val fromIndex = currentWallpapers.indexOfFirst { it.wallpaperUri == event.from.key }
|
||||
val toIndex = currentWallpapers.indexOfFirst { it.wallpaperUri == event.to.key }
|
||||
val movedWallpaper = currentWallpapers.removeAt(fromIndex)
|
||||
currentWallpapers.add(toIndex, movedWallpaper)
|
||||
currentWallpapers.forEachIndexed { index, wallpaper ->
|
||||
currentWallpapers[index] = wallpaper.copy(order = index)
|
||||
}
|
||||
_state.value = state.value.copy(wallpapers = currentWallpapers)
|
||||
}
|
||||
|
||||
is SortEvent.Reset -> {
|
||||
_state.value = SortState()
|
||||
}
|
||||
|
||||
is SortEvent.SortAlphabetically -> {
|
||||
val sortedFolders = state.value.folders
|
||||
.map { folder ->
|
||||
val sortedFolderWallpapers = folder.wallpapers
|
||||
.sortedBy { it.fileName }
|
||||
.mapIndexed { index, wallpaper ->
|
||||
wallpaper.copy(order = index)
|
||||
}
|
||||
folder.copy(wallpapers = sortedFolderWallpapers)
|
||||
}
|
||||
.sortedBy { it.folderName }
|
||||
.mapIndexed { index, folder ->
|
||||
folder.copy(order = index)
|
||||
}
|
||||
|
||||
val sortedWallpapers = state.value.wallpapers
|
||||
.sortedBy { it.fileName }
|
||||
.mapIndexed { index, wallpaper ->
|
||||
wallpaper.copy(order = index)
|
||||
}
|
||||
|
||||
_state.value = state.value.copy(
|
||||
folders = sortedFolders,
|
||||
wallpapers = sortedWallpapers
|
||||
)
|
||||
}
|
||||
|
||||
is SortEvent.SortAlphabeticallyReverse -> {
|
||||
val sortedFolders = state.value.folders
|
||||
.map { folder ->
|
||||
val sortedFolderWallpapers = folder.wallpapers
|
||||
.sortedByDescending { it.fileName }
|
||||
.mapIndexed { index, wallpaper ->
|
||||
wallpaper.copy(order = index)
|
||||
}
|
||||
folder.copy(wallpapers = sortedFolderWallpapers)
|
||||
}
|
||||
.sortedByDescending { it.folderName }
|
||||
.mapIndexed { index, folder ->
|
||||
folder.copy(order = index)
|
||||
}
|
||||
|
||||
val sortedWallpapers = state.value.wallpapers
|
||||
.sortedByDescending { it.fileName }
|
||||
.mapIndexed { index, wallpaper ->
|
||||
wallpaper.copy(order = index)
|
||||
}
|
||||
|
||||
_state.value = state.value.copy(
|
||||
folders = sortedFolders,
|
||||
wallpapers = sortedWallpapers
|
||||
)
|
||||
}
|
||||
|
||||
is SortEvent.SortByLastModified -> {
|
||||
val sortedFolders = state.value.folders
|
||||
.map { folder ->
|
||||
val sortedFolderWallpapers = folder.wallpapers
|
||||
.sortedBy { it.dateModified }
|
||||
.mapIndexed { index, wallpaper ->
|
||||
wallpaper.copy(order = index)
|
||||
}
|
||||
folder.copy(wallpapers = sortedFolderWallpapers)
|
||||
}
|
||||
.sortedBy { it.dateModified }
|
||||
.mapIndexed { index, folder ->
|
||||
folder.copy(order = index)
|
||||
}
|
||||
|
||||
val sortedWallpapers = state.value.wallpapers
|
||||
.sortedBy { it.dateModified }
|
||||
.mapIndexed { index, wallpaper ->
|
||||
wallpaper.copy(order = index)
|
||||
}
|
||||
|
||||
_state.value = state.value.copy(
|
||||
folders = sortedFolders,
|
||||
wallpapers = sortedWallpapers
|
||||
)
|
||||
}
|
||||
|
||||
is SortEvent.SortByLastModifiedReverse -> {
|
||||
val sortedFolders = state.value.folders
|
||||
.map { folder ->
|
||||
val sortedFolderWallpapers = folder.wallpapers
|
||||
.sortedByDescending { it.dateModified }
|
||||
.mapIndexed { index, wallpaper ->
|
||||
wallpaper.copy(order = index)
|
||||
}
|
||||
folder.copy(wallpapers = sortedFolderWallpapers)
|
||||
}
|
||||
.sortedByDescending { it.dateModified }
|
||||
.mapIndexed { index, folder ->
|
||||
folder.copy(order = index)
|
||||
}
|
||||
|
||||
val sortedWallpapers = state.value.wallpapers
|
||||
.sortedByDescending { it.dateModified }
|
||||
.mapIndexed { index, wallpaper ->
|
||||
wallpaper.copy(order = index)
|
||||
}
|
||||
|
||||
_state.value = state.value.copy(
|
||||
folders = sortedFolders,
|
||||
wallpapers = sortedWallpapers
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loaded 100 of 204 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user