Compare commits
609
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c92f7e5e03 | ||
|
|
c49ddf85cb | ||
|
|
da02d23032 | ||
|
|
f977687b27 | ||
|
|
31077727e1 | ||
|
|
6a783a701c | ||
|
|
8a5db6b89e | ||
|
|
c46006858f | ||
|
|
0e5366a81a | ||
|
|
318ba07ed5 | ||
|
|
391bbb6bc0 | ||
|
|
572252b187 | ||
|
|
894b86cd14 | ||
|
|
1006902d07 | ||
|
|
49fecf56af | ||
|
|
ca59cd8155 | ||
|
|
9820581723 | ||
|
|
9079306f8f | ||
|
|
3b2f739254 | ||
|
|
c6c841f7c0 | ||
|
|
66c3a4bb2e | ||
|
|
1b317798a4 | ||
|
|
95feb975ea | ||
|
|
bf1d2d4793 | ||
|
|
1f66b1c616 | ||
|
|
8cee52fcd6 | ||
|
|
44692cde8e | ||
|
|
23359ee714 | ||
|
|
25004356b5 | ||
|
|
7e4e5ff452 | ||
|
|
d63c1005b7 | ||
|
|
bf71bca11a | ||
|
|
c35b87a1da | ||
|
|
afa520a68a | ||
|
|
b67734b8e1 | ||
|
|
d124da717d | ||
|
|
40417b99b1 | ||
|
|
ba7d29990c | ||
|
|
b18c5bdb1e | ||
|
|
1191872b3e | ||
|
|
ae5a533baf | ||
|
|
9cc7c0e26a | ||
|
|
7ca5e2bac4 | ||
|
|
e064c31175 | ||
|
|
8959e239fe | ||
|
|
06c9566df4 | ||
|
|
108f5cd9c1 | ||
|
|
9b86b54ae1 | ||
|
|
40e0884ee7 | ||
|
|
e1fa4e7890 | ||
|
|
4161b8817b | ||
|
|
4554190912 | ||
|
|
b714ad8eb6 | ||
|
|
6cd5c1eed3 | ||
|
|
6784e2a2de | ||
|
|
7f69debe1d | ||
|
|
f8df7c2a6a | ||
|
|
b3fb2b82f2 | ||
|
|
04d0c57cb0 | ||
|
|
27b0fe62c8 | ||
|
|
096beb22d7 | ||
|
|
21766a5dc6 | ||
|
|
fd5e8b63b2 | ||
|
|
2f514e6464 | ||
|
|
74d2c614fd | ||
|
|
da0d8c45e6 | ||
|
|
e87d8116a6 | ||
|
|
8aaff066b3 | ||
|
|
685c9d1981 | ||
|
|
81ae25035e | ||
|
|
530ff36a16 | ||
|
|
9fd52e7bc4 | ||
|
|
0c2ca68dcd | ||
|
|
e7c92eae71 | ||
|
|
7b26e323ac | ||
|
|
b0069e3bc9 | ||
|
|
8582bc903b | ||
|
|
8690284ac2 | ||
|
|
c9e485ac88 | ||
|
|
9d577880e0 | ||
|
|
09bacfb3e5 | ||
|
|
3fd9cec67d | ||
|
|
ac7a1e0cb0 | ||
|
|
53ba0a2347 | ||
|
|
83cc89e1b3 | ||
|
|
655c4a91e5 | ||
|
|
083f269605 | ||
|
|
9880bac0c6 | ||
|
|
0f87776d16 | ||
|
|
ed291459d1 | ||
|
|
bc1eb7f996 | ||
|
|
8366965a03 | ||
|
|
904f77191c | ||
|
|
ec9f56cf1e | ||
|
|
980527cdde | ||
|
|
efe794c63f | ||
|
|
65a677ea91 | ||
|
|
dabf63fc58 | ||
|
|
1da95e09b5 | ||
|
|
ad195a985e | ||
|
|
0e06584780 | ||
|
|
a6f44ecad5 | ||
|
|
d527fa9a80 | ||
|
|
ffe360ee80 | ||
|
|
8fd9c9b80e | ||
|
|
d77f2fe8df | ||
|
|
86c44825d9 | ||
|
|
b5d8bb5548 | ||
|
|
9000be1951 | ||
|
|
38ba5154f9 | ||
|
|
9f670031b1 | ||
|
|
c0dd7baeaa | ||
|
|
1c96dcfc4a | ||
|
|
2a3821e1e7 | ||
|
|
8b61b1d719 | ||
|
|
431df5c334 | ||
|
|
2b49a01eb4 | ||
|
|
3bc438a06d | ||
|
|
57d6b7dc8e | ||
|
|
5d87257516 | ||
|
|
cb9ab7d1af | ||
|
|
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 | ||
|
|
c219aa2b30 | ||
|
|
5ba325b93f | ||
|
|
dc1a65f234 | ||
|
|
48a198091e | ||
|
|
81020c9ba0 | ||
|
|
c47f3957bf | ||
|
|
68e94fe284 | ||
|
|
265edf8f63 | ||
|
|
322a10bf0c | ||
|
|
f6688c84ab | ||
|
|
62a5934220 | ||
|
|
64dedae516 | ||
|
|
1ff2539574 | ||
|
|
219a4cdb52 | ||
|
|
322e6907ab | ||
|
|
c39527b3b5 | ||
|
|
068f78f86c | ||
|
|
87ef7ebaf0 | ||
|
|
996208b03d | ||
|
|
ec54bbb8c5 | ||
|
|
b52a47770d |
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.
|
||||
@@ -0,0 +1,161 @@
|
||||
# ===================================================================
|
||||
# Paperize CI/CD Pipeline
|
||||
#
|
||||
# Automates the testing, building and release process for the Paperize Android application.
|
||||
#
|
||||
# Workflow Architecture:
|
||||
# 1. Test: Runs unit tests to ensure code quality.
|
||||
# 2. Build: Compiles and signs the release APK (depends on test passing).
|
||||
# 3. Release: Publishes the APK to a draft GitHub Release, but only for version tags.
|
||||
#
|
||||
# Triggering Conditions:
|
||||
# - On push to `master`:
|
||||
# - Executes the `test` and `build` jobs.
|
||||
# - Produces a versioned build artifact for testing and internal distribution.
|
||||
# - On push of a tag (e.g., `v1.2.3`):
|
||||
# - Executes all jobs: `test`, `build` and `release`.
|
||||
# - Creates a formal, versioned draft release on GitHub with the signed APK attached.
|
||||
# - On pull requests to `master`:
|
||||
# - Executes only the `test` job to validate changes before merge.
|
||||
# ===================================================================
|
||||
name: Paperize CI/CD Pipeline
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
tags: [ 'v*' ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
|
||||
jobs:
|
||||
# ===================================================================
|
||||
# JOB: test
|
||||
#
|
||||
# Runs unit tests to ensure code quality before building.
|
||||
# ===================================================================
|
||||
test:
|
||||
name: Run Unit Tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository source code
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'temurin'
|
||||
cache: gradle
|
||||
|
||||
- name: Grant execute permission for gradlew
|
||||
run: chmod +x gradlew
|
||||
|
||||
- name: Run unit tests
|
||||
run: ./gradlew clean test
|
||||
|
||||
- name: Upload test reports
|
||||
uses: actions/upload-artifact@v6
|
||||
if: always()
|
||||
with:
|
||||
name: test-reports
|
||||
path: app/build/reports/tests/
|
||||
retention-days: 7
|
||||
|
||||
# ===================================================================
|
||||
# JOB: build
|
||||
#
|
||||
# Compiles, signs, and packages the release APK. This job produces a
|
||||
# versioned artifact that is used for both internal testing and the final release.
|
||||
# Only runs after tests pass.
|
||||
# ===================================================================
|
||||
build:
|
||||
name: Build Signed APK
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
if: github.event_name == 'push'
|
||||
steps:
|
||||
- name: Checkout repository source code
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'temurin'
|
||||
cache: gradle
|
||||
|
||||
- name: Grant execute permission for gradlew
|
||||
# The gradlew wrapper requires execute permissions to run on the Linux-based runner.
|
||||
run: chmod +x gradlew
|
||||
|
||||
- name: Decode Base64 Keystore
|
||||
# Reconstructs the binary .jks keystore file from the Base64 encoded secret.
|
||||
env:
|
||||
SIGNING_KEYSTORE_BASE64: ${{ secrets.SIGNING_KEYSTORE_BASE64 }}
|
||||
run: |
|
||||
echo $SIGNING_KEYSTORE_BASE64 | base64 --decode > ${{ github.workspace }}/keystore.jks
|
||||
|
||||
- name: Build Release APK
|
||||
env:
|
||||
SIGNING_KEYSTORE_PATH: ${{ github.workspace }}/keystore.jks
|
||||
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
|
||||
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
|
||||
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
||||
run: ./gradlew assembleRelease
|
||||
|
||||
- name: Get Version Name
|
||||
# Determines the application version for artifact naming.
|
||||
# - For tag pushes (e.g., 'v1.2.3'), it uses the tag name directly.
|
||||
# - For master branch pushes, it parses the `versionName` from the app's build.gradle.kts file.
|
||||
id: get_version
|
||||
shell: bash
|
||||
run: |
|
||||
if [[ $GITHUB_REF == refs/tags/v* ]]; then
|
||||
VERSION_NAME=${GITHUB_REF_NAME}
|
||||
else
|
||||
RAW_VERSION=$(grep "versionName =" app/build.gradle.kts | awk -F'"' '{print $2}')
|
||||
VERSION_NAME="v${RAW_VERSION}"
|
||||
fi
|
||||
echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Upload APK as a build artifact
|
||||
# Archives the generated APK with a dynamic, versioned name. This artifact is essential
|
||||
# for passing the APK file to the subsequent `release` job.
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
name: paperize-${{ steps.get_version.outputs.VERSION_NAME }}
|
||||
path: app/build/outputs/apk/release/paperize-v*.apk
|
||||
if-no-files-found: error
|
||||
|
||||
# ===================================================================
|
||||
# JOB: release
|
||||
#
|
||||
# Creates a draft GitHub Release and attaches the signed APK. This job is
|
||||
# conditional and will only execute for pushes that include a version tag.
|
||||
# ===================================================================
|
||||
release:
|
||||
name: Create GitHub Release
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Download signed APK artifact
|
||||
# Downloads the versioned artifact produced by the `build` job. The pattern ensures
|
||||
# it finds the correct artifact regardless of the specific version number.
|
||||
uses: actions/download-artifact@v7
|
||||
with:
|
||||
pattern: paperize-v*
|
||||
path: ./apk-artifact
|
||||
merge-multiple: true
|
||||
|
||||
- name: Create Draft Release
|
||||
# Publishes a new release to GitHub. `draft: true` ensures the release is not made
|
||||
# public until it has been manually reviewed and published.
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: ./apk-artifact/paperize-v*.apk
|
||||
draft: true
|
||||
generate_release_notes: true
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
# Simple workflow for deploying static content to GitHub Pages
|
||||
name: Deploy static content to Pages
|
||||
|
||||
on:
|
||||
# Runs on pushes targeting the default branch
|
||||
push:
|
||||
branches: ["master"]
|
||||
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
|
||||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
|
||||
concurrency:
|
||||
group: "pages"
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
# Single deploy job since we're just deploying
|
||||
deploy:
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Pages
|
||||
uses: actions/configure-pages@v5
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
# Upload entire repository
|
||||
path: '.'
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
@@ -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,86 +1,116 @@
|
||||
|
||||
<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>
|
||||
<p>Paperize is a dynamic wallpaper changer application designed to keep your device's aesthetic fresh and exciting</p>
|
||||
</div>
|
||||
<img style="display: block" src="https://github.com/user-attachments/assets/e8fb14f5-ec8e-440e-a2ac-8065322b0e28" alt="">
|
||||
<h1>Paperize</h1>
|
||||
<p><strong>A dynamic wallpaper changer that keeps your device's aesthetic fresh and exciting</strong></p>
|
||||
|
||||
|
||||
|
||||
## Features
|
||||
- **Dynamic Wallpaper Changer**: Set your wallpaper to change at specific time intervals
|
||||
- **Supports Various Image Types**: Paperize can handle a wide range of image types
|
||||
- JPEG, PNG, AVIF, WEBP
|
||||
- **Folder Support**: Organize your wallpapers into folders for auto-updating
|
||||
- **Home and Lock Screen Wallpaper**: Choose to change either your home screen, lock screen, or both
|
||||
- **On-Device Storage**: All your wallpapers and settings are stored on your device
|
||||
<div align="center">
|
||||
<br/>
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/57122f72-78f8-45ed-a9ac-de943061d6a2" width="30%" alt="onboarding" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/9f41d715-7b14-4ff2-9c30-87ad3d86d94c" width="30%" alt="wallpaper" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/47aa95c3-ef80-4c3c-a8cd-a51ac6824507" width="30%" alt="interval" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/4ce1b28d-f4b2-4048-a261-203156222263" width="30%" alt="album" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/66b092e5-4af4-4396-b145-63ee506d9257" width="30%" alt="settings" />
|
||||
<br/>
|
||||
<br/>
|
||||
<div><video controls src="https://github.com/Anthonyy232/Paperize/assets/60626873/015afb04-e3f3-4641-b8f9-707cfa26d16f" muted="true"></video></div>
|
||||
[](https://github.com/Anthonyy232/Paperize/releases)
|
||||
[](https://github.com/Anthonyy232/Paperize/releases/latest)
|
||||
[](LICENSE)
|
||||
[](https://f-droid.org/en/packages/com.anthonyla.paperize/)
|
||||
|
||||
[](https://crowdin.com/project/paperize)
|
||||
</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
|
||||
## Features
|
||||
|
||||
- **Dynamic Wallpaper Changer** — Set your wallpaper to change at specific time intervals
|
||||
- **Static & Live Wallpapers** — Choose between traditional static wallpapers or smooth live wallpaper transitions
|
||||
- **Multiple Image Formats** — Supports JPG, PNG, WEBP, AVIF, HEIC/HEIF, BMP, GIF, TIFF, and SVG
|
||||
- **Folder Support** — Organize wallpapers into folders for auto-updating
|
||||
- **Dual Screen Support** — Choose the same or separate albums for home and lock screen
|
||||
- **Wallpaper Effects** — Apply various effects including brightness, blur, scaling, vignette, and more
|
||||
- **On-Device Storage** — All wallpapers and settings stored locally on your device
|
||||
|
||||
---
|
||||
|
||||
## Download
|
||||
|
||||
[<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/1c034414-21cd-4a0a-838d-89fe7bd56910" alt="Download from GitHub" height="60">](https://github.com/Anthonyy232/Paperize/releases)
|
||||
[<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" alt="Get it on F-Droid" height="60">](https://f-droid.org/en/packages/com.anthonyla.paperize/)
|
||||
[<img src="https://gitlab.com/IzzyOnDroid/repo/-/raw/master/assets/IzzyOnDroid.png" alt="Get it on IzzyOnDroid" height="60">](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 would love some help translating the app! Help me out with that [here](https://crowdin.com/project/paperize/invite?h=d8d7a7513d2beb0c96ba9b2a5f85473e2084922)!
|
||||
Help translate Paperize into your language! Currently, most translations are provided using machine translation — contributions from native speakers are greatly appreciated.
|
||||
|
||||
[](https://crowdin.com/project/paperize)
|
||||
**[Contribute on Crowdin →](https://crowdin.com/project/paperize/invite?h=d8d7a7513d2beb0c96ba9b2a5f85473e2084922)**
|
||||
|
||||
## Technologies
|
||||
---
|
||||
|
||||
- [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
|
||||
- [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
|
||||
- [Lottie Compose](https://github.com/airbnb/lottie) - A library that provides Lottie animation support for Jetpack Compose
|
||||
- [Landscapist](https://github.com/skydoves/landscapist) - A Compose and KPP image loading library that streamlines Glide, Coil, and Fresco
|
||||
- [Zoomable](https://github.com/usuiat/Zoomable) - A library that provides a zoomable and pannable view, which can be used with any view you want
|
||||
- [AnimatedFABMenu](https://github.com/rajaumair7890/AnimatedFABMenu) - A animated floating action button with Material 3 design
|
||||
## Tech Stack
|
||||
|
||||
Thanks to the creators and maintainers of the open-source libraries used in this project.
|
||||
| Category | Technology |
|
||||
|----------|------------|
|
||||
| **Language** | [Kotlin](https://kotlinlang.org/) |
|
||||
| **UI Framework** | [Jetpack Compose](https://developer.android.com/develop/ui/compose) |
|
||||
| **Design System** | [Material 3](https://m3.material.io/) |
|
||||
| **Dependency Injection** | [Dagger Hilt](https://dagger.dev/hilt/) |
|
||||
| **Database** | [Room](https://developer.android.com/training/data-storage/room) |
|
||||
| **Image Loading** | [Coil](https://coil-kt.github.io/coil/) |
|
||||
| **Animations** | [Lottie](https://github.com/airbnb/lottie) |
|
||||
|
||||
## Build
|
||||
<details>
|
||||
<summary><b>View all dependencies</b></summary>
|
||||
|
||||
This project is built using Kotlin, Java, and Gradle. Here are the steps to build the project:
|
||||
- [Zoomable](https://github.com/usuiat/Zoomable) — Zoomable and pannable views
|
||||
- [DocumentFileCompat](https://github.com/ItzNotABug/DocumentFileCompat) — Efficient DocumentFile wrapper
|
||||
- [LazyColumnScrollbar](https://github.com/nanihadesuka/LazyColumnScrollbar) — Compose scrollbar library
|
||||
- [compose-collapsing-toolbar](https://github.com/onebone/compose-collapsing-toolbar) — Collapsing toolbar for Compose
|
||||
|
||||
</details>
|
||||
|
||||
---
|
||||
|
||||
## Building from Source
|
||||
|
||||
### Prerequisites
|
||||
- Java 8 (1.8)
|
||||
- Android Studio Jellyfish | 2023.3.1 or later
|
||||
- Gradle 8.4.1 or later
|
||||
- Minimum SDK 26
|
||||
|
||||
### Steps
|
||||
- Open a terminal and run the following git command: <pre>git clone https://github.com/Anthonyy232/Paperize.git </pre>
|
||||
- Launch Android Studio and choose Open an existing Android Studio project. Navigate to the cloned repository and select the root folder of the project.
|
||||
- In Android Studio, click on Build -> Generate Signed Bundle / APK and follow the instructions to generate an APK
|
||||
- Alternatively, click `▶ Run` and build the app and run it immediately
|
||||
| Requirement | Version |
|
||||
|-------------|---------|
|
||||
| Java | 17 |
|
||||
| Android Gradle Plugin | 8.7.0+ |
|
||||
| Gradle | 9.2.1 |
|
||||
| Minimum SDK | 31 (Android 12) |
|
||||
| Target SDK | 36 |
|
||||
|
||||
### Build Steps
|
||||
|
||||
## Contributions
|
||||
1. **Clone the repository**
|
||||
```bash
|
||||
git clone https://github.com/Anthonyy232/Paperize.git
|
||||
cd Paperize
|
||||
```
|
||||
|
||||
All contributions to the app is welcome. Feel free to report any issues and create pull requests for any issues or pull requests.
|
||||
2. **Open in Android Studio**
|
||||
- Launch Android Studio
|
||||
- Select `File > Open` and navigate to the cloned repository
|
||||
|
||||
Inspiration from j4velin for their wallpaper changer app
|
||||
3. **Build and Run**
|
||||
- Click `▶ Run` to build and install on a connected device, or
|
||||
- Select `Build > Generate Signed Bundle / APK` to create a signed release
|
||||
|
||||
---
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Feel free to:
|
||||
|
||||
- Report bugs by opening an issue
|
||||
- Suggest features or improvements
|
||||
- Submit pull requests
|
||||
|
||||
---
|
||||
|
||||
## Support
|
||||
|
||||
If you find Paperize useful, consider supporting development through [GitHub Sponsors](https://github.com/sponsors/Anthonyy232) (one-time or monthly). Thank you!
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
Contact on my GitHub profile
|
||||
|
||||
Anthony La © GNU GPL v3.0
|
||||
This project is licensed under the **GNU General Public License v3.0** — see the [LICENSE](LICENSE) file for details.
|
||||
+101
-73
@@ -1,25 +1,38 @@
|
||||
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 = 36
|
||||
|
||||
signingConfigs {
|
||||
create("release") {
|
||||
val storeFilePath = System.getenv("SIGNING_KEYSTORE_PATH")
|
||||
if (storeFilePath != null) {
|
||||
storeFile = file(storeFilePath)
|
||||
storePassword = System.getenv("SIGNING_STORE_PASSWORD")
|
||||
keyAlias = System.getenv("SIGNING_KEY_ALIAS")
|
||||
keyPassword = System.getenv("SIGNING_KEY_PASSWORD")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.anthonyla.paperize"
|
||||
minSdk = 26
|
||||
targetSdk = 34
|
||||
versionCode = 15
|
||||
versionName = "1.4.1"
|
||||
minSdk = 31
|
||||
targetSdk = 36
|
||||
versionCode = 50
|
||||
versionName = "4.0.0"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
@@ -27,91 +40,106 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = true
|
||||
isShrinkResources = true
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
signingConfig = signingConfigs.getByName("release")
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
|
||||
}
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
compose = true
|
||||
viewBinding = true
|
||||
buildConfig = true
|
||||
}
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion = "1.5.10"
|
||||
}
|
||||
|
||||
androidResources {
|
||||
@Suppress("UnstableApiUsage")
|
||||
generateLocaleConfig = true
|
||||
}
|
||||
}
|
||||
|
||||
androidComponents {
|
||||
onVariants(selector().withBuildType("release")) {
|
||||
it.packaging.resources.excludes.add("META-INF/**")
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("androidx.core:core-ktx:1.13.1")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.0")
|
||||
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-beta01")
|
||||
implementation("androidx.compose.ui:ui-graphics:1.7.0-beta01")
|
||||
implementation("androidx.compose.ui:ui-tooling-preview:1.7.0-beta01")
|
||||
implementation("androidx.compose.material3:material3:1.3.0-beta01")
|
||||
implementation("androidx.navigation:navigation-compose:2.8.0-beta01")
|
||||
implementation("androidx.compose.material:material:1.7.0-beta01")
|
||||
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-beta01")
|
||||
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-beta01")
|
||||
implementation("androidx.core:core-splashscreen:1.2.0-alpha01")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.0")
|
||||
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.0")
|
||||
implementation("com.google.accompanist:accompanist-permissions:0.35.0-alpha")
|
||||
implementation("com.mikepenz:aboutlibraries-core:11.2.0")
|
||||
implementation("com.mikepenz:aboutlibraries-compose-m3:11.2.0")
|
||||
implementation("androidx.compose.foundation:foundation:1.7.0-beta01")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.0-beta01")
|
||||
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.7.0-beta01")
|
||||
debugImplementation("androidx.compose.ui:ui-tooling:1.7.0-beta01")
|
||||
debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.0-beta01")
|
||||
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.google.material)
|
||||
implementation(libs.androidx.navigation.compose)
|
||||
implementation(libs.androidx.material)
|
||||
implementation(libs.coil.compose)
|
||||
implementation(libs.coil.network.okhttp)
|
||||
implementation(libs.coil.gif)
|
||||
implementation(libs.coil.svg)
|
||||
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.androidx.exifinterface)
|
||||
implementation(libs.zoomable)
|
||||
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.androidx.profileinstaller)
|
||||
implementation(libs.reorderable)
|
||||
testImplementation(libs.junit)
|
||||
testImplementation(libs.mockk)
|
||||
testImplementation(libs.kotlinx.coroutines.test)
|
||||
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)
|
||||
ksp(libs.androidx.hilt.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)
|
||||
}
|
||||
Vendored
+34
-7
@@ -14,7 +14,7 @@
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
@@ -23,15 +23,42 @@
|
||||
-keep class com.google.gson.reflect.TypeToken { *; }
|
||||
-keep class * extends com.google.gson.reflect.TypeToken
|
||||
-keep class kotlin.coroutines.Continuation
|
||||
-keepclassmembers class com.anthonyla.paperize.feature.wallpaper.domain.model.Album {
|
||||
-keep class androidx.datastore.*.** {*;}
|
||||
|
||||
# Keep domain models for serialization
|
||||
-keepclassmembers class com.anthonyla.paperize.domain.model.Album {
|
||||
!transient <fields>;
|
||||
}
|
||||
-keepclassmembers class com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder {
|
||||
-keepclassmembers class com.anthonyla.paperize.domain.model.Wallpaper {
|
||||
!transient <fields>;
|
||||
}
|
||||
-keepclassmembers class com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper {
|
||||
!transient <fields>;
|
||||
}
|
||||
-keepclassmembers class com.anthonyla.paperize.feature.wallpaper.domain.model.Folder {
|
||||
-keepclassmembers class com.anthonyla.paperize.domain.model.Folder {
|
||||
!transient <fields>;
|
||||
}
|
||||
|
||||
# Keep database entities
|
||||
-keep class com.anthonyla.paperize.data.database.entities.** { *; }
|
||||
|
||||
# Keep wallpaper service
|
||||
-keep class com.anthonyla.paperize.service.wallpaper.WallpaperChangeService { *; }
|
||||
-keep class com.anthonyla.paperize.service.wallpaper.WallpaperChangeService$* { *; }
|
||||
|
||||
# Keep enums
|
||||
-keep class com.anthonyla.paperize.core.WallpaperSourceType { *; }
|
||||
-keep class com.anthonyla.paperize.core.ScreenType { *; }
|
||||
-keep class com.anthonyla.paperize.core.ScalingType { *; }
|
||||
|
||||
# Keep navigation routes for serialization
|
||||
-keep class com.anthonyla.paperize.presentation.common.navigation.** { *; }
|
||||
|
||||
# Keep Hilt generated classes (more specific to avoid overly broad rules)
|
||||
-keep,allowobfuscation,allowshrinking @dagger.hilt.android.lifecycle.HiltViewModel class *
|
||||
-keep,allowobfuscation,allowshrinking class * extends androidx.lifecycle.ViewModel
|
||||
-keep class dagger.hilt.android.** { *; }
|
||||
-keep class dagger.hilt.internal.** { *; }
|
||||
-keep class javax.inject.** { *; }
|
||||
|
||||
# Keep Room database
|
||||
-keep class * extends androidx.room.RoomDatabase
|
||||
-keep @androidx.room.Entity class *
|
||||
-dontwarn androidx.room.paging.**
|
||||
@@ -2,51 +2,103 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<!-- Permissions -->
|
||||
<uses-permission android:name="android.permission.SET_WALLPAPER" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
|
||||
tools:ignore="ScopedStorage" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||
|
||||
<queries>
|
||||
<intent>
|
||||
<action android:name="android.service.wallpaper.WallpaperService" />
|
||||
</intent>
|
||||
</queries>
|
||||
<!-- Features -->
|
||||
<uses-feature
|
||||
android:name="android.software.wallpaper"
|
||||
android:required="false" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:name=".App"
|
||||
android:persistent="true"
|
||||
android:name=".PaperizeApplication"
|
||||
android:allowBackup="false"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:fullBackupContent="false"
|
||||
android:icon="@mipmap/app_icon"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/app_icon_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Paperize" tools:targetApi="tiramisu">
|
||||
android:theme="@style/Theme.Paperize">
|
||||
|
||||
<!-- Disable default WorkManager initialization (using custom Configuration.Provider) -->
|
||||
<provider
|
||||
android:name="androidx.startup.InitializationProvider"
|
||||
android:authorities="${applicationId}.androidx-startup"
|
||||
android:exported="false"
|
||||
tools:node="merge">
|
||||
<meta-data
|
||||
android:name="androidx.work.WorkManagerInitializer"
|
||||
android:value="androidx.startup"
|
||||
tools:node="remove" />
|
||||
</provider>
|
||||
|
||||
<!-- Main Activity -->
|
||||
<activity
|
||||
android:name=".feature.wallpaper.presentation.MainActivity"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:name=".presentation.MainActivity"
|
||||
android:exported="true"
|
||||
android:configChanges="uiMode|density|orientation|screenSize|screenLayout|keyboardHidden|keyboard"
|
||||
android:theme="@style/Theme.Paperize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service android:name=".feature.wallpaper.wallpaper_service.WallpaperService" android:foregroundServiceType="mediaPlayback"/>
|
||||
<receiver android:name=".feature.wallpaper.wallpaper_service.WallpaperBootReceiver"
|
||||
|
||||
<service
|
||||
android:name=".service.wallpaper.WallpaperChangeService"
|
||||
android:enabled="true"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="dataSync" />
|
||||
|
||||
<!-- Broadcast Receivers -->
|
||||
<receiver
|
||||
android:name=".service.alarm.BootReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<provider
|
||||
android:name="androidx.startup.InitializationProvider"
|
||||
android:authorities="${applicationId}.androidx-startup"
|
||||
android:exported="false"
|
||||
tools:node="merge">
|
||||
<meta-data android:name="androidx.emoji2.text.EmojiCompatInitializer"
|
||||
tools:node="remove" />
|
||||
</provider>
|
||||
|
||||
<!-- Quick Settings Tile -->
|
||||
<service
|
||||
android:name=".service.tile.WallpaperTileService"
|
||||
android:exported="true"
|
||||
android:icon="@drawable/ic_launcher_foreground"
|
||||
android:label="@string/app_name"
|
||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||
<intent-filter>
|
||||
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<!-- Live Wallpaper Service -->
|
||||
<service
|
||||
android:name=".service.livewallpaper.PaperizeLiveWallpaperService"
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
android:label="@string/live_wallpaper_name"
|
||||
android:permission="android.permission.BIND_WALLPAPER">
|
||||
<intent-filter>
|
||||
<action android:name="android.service.wallpaper.WallpaperService" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.service.wallpaper"
|
||||
android:resource="@xml/wallpaper" />
|
||||
</service>
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
</manifest>
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.anthonyla.paperize
|
||||
|
||||
import android.app.Application
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
|
||||
/**
|
||||
* Application class for Hilt
|
||||
*/
|
||||
@HiltAndroidApp
|
||||
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
|
||||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.anthonyla.paperize
|
||||
|
||||
import android.app.Application
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import androidx.hilt.work.HiltWorkerFactory
|
||||
import androidx.work.Configuration
|
||||
import androidx.work.Constraints
|
||||
import androidx.work.ExistingWorkPolicy
|
||||
import androidx.work.NetworkType
|
||||
import androidx.work.OneTimeWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
import com.anthonyla.paperize.service.worker.AlbumRefreshWorker
|
||||
import com.anthonyla.paperize.core.util.DataResetManager
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Application class for Paperize
|
||||
*
|
||||
* Annotated with @HiltAndroidApp to enable dependency injection
|
||||
* Implements Configuration.Provider for WorkManager with Hilt support
|
||||
*/
|
||||
@HiltAndroidApp
|
||||
class PaperizeApplication : Application(), Configuration.Provider {
|
||||
|
||||
@Inject
|
||||
lateinit var workerFactory: HiltWorkerFactory
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
// Perform one-time data reset for major version upgrades (e.g., v3 -> v4)
|
||||
// Must run before any other initialization that accesses DB/preferences
|
||||
DataResetManager.performResetIfNeeded(this)
|
||||
|
||||
// Create notification channel (minSdk is 31, so always supported)
|
||||
createNotificationChannel()
|
||||
|
||||
// Trigger album refresh on app cold start to validate and update all albums
|
||||
refreshAlbumsOnStartup()
|
||||
}
|
||||
|
||||
override val workManagerConfiguration: Configuration
|
||||
get() = Configuration.Builder()
|
||||
.setWorkerFactory(workerFactory)
|
||||
.build()
|
||||
|
||||
private fun createNotificationChannel() {
|
||||
val channel = NotificationChannel(
|
||||
Constants.NOTIFICATION_CHANNEL_ID,
|
||||
getString(R.string.app_name),
|
||||
NotificationManager.IMPORTANCE_LOW
|
||||
).apply {
|
||||
description = getString(R.string.notification_channel_description)
|
||||
setShowBadge(false)
|
||||
}
|
||||
|
||||
val notificationManager = getSystemService(NotificationManager::class.java)
|
||||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh all albums on app startup to validate and update wallpapers/folders
|
||||
*
|
||||
* This runs in the background without blocking app startup and ensures:
|
||||
* - Invalid wallpapers/folders are removed
|
||||
* - New wallpapers are discovered in existing folders
|
||||
* - Album covers are up-to-date
|
||||
*/
|
||||
private fun refreshAlbumsOnStartup() {
|
||||
val workManager = WorkManager.getInstance(this)
|
||||
|
||||
val constraints = Constraints.Builder()
|
||||
.setRequiredNetworkType(NetworkType.NOT_REQUIRED)
|
||||
.build()
|
||||
|
||||
val refreshWorkRequest = OneTimeWorkRequestBuilder<AlbumRefreshWorker>()
|
||||
.setConstraints(constraints)
|
||||
.addTag("startup_refresh")
|
||||
.build()
|
||||
|
||||
// Use KEEP policy to avoid duplicate refreshes if app is quickly reopened
|
||||
workManager.enqueueUniqueWork(
|
||||
"album_refresh_on_startup",
|
||||
ExistingWorkPolicy.KEEP,
|
||||
refreshWorkRequest
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.anthonyla.paperize.core
|
||||
|
||||
/**
|
||||
* A generic class that holds a value or an error
|
||||
*/
|
||||
sealed class Result<out T> {
|
||||
data class Success<T>(val data: T) : Result<T>()
|
||||
data class Error(val exception: Throwable, val message: String? = exception.message) : Result<Nothing>()
|
||||
data object Loading : Result<Nothing>()
|
||||
|
||||
val isSuccess: Boolean get() = this is Success
|
||||
val isError: Boolean get() = this is Error
|
||||
val isLoading: Boolean get() = this is Loading
|
||||
|
||||
fun getOrNull(): T? = if (this is Success) data else null
|
||||
fun exceptionOrNull(): Throwable? = if (this is Error) exception else null
|
||||
|
||||
inline fun onSuccess(action: (T) -> Unit): Result<T> {
|
||||
if (this is Success) action(data)
|
||||
return this
|
||||
}
|
||||
|
||||
inline fun onError(action: (Throwable) -> Unit): Result<T> {
|
||||
if (this is Error) action(exception)
|
||||
return this
|
||||
}
|
||||
|
||||
companion object {
|
||||
inline fun <T> runCatching(block: () -> T): Result<T> {
|
||||
return try {
|
||||
Success(block())
|
||||
} catch (e: Exception) {
|
||||
Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a Result to another type
|
||||
*/
|
||||
inline fun <T, R> Result<T>.map(transform: (T) -> R): Result<R> {
|
||||
return when (this) {
|
||||
is Result.Success -> Result.Success(transform(data))
|
||||
is Result.Error -> Result.Error(exception, message)
|
||||
is Result.Loading -> Result.Loading
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flat map a Result
|
||||
*/
|
||||
inline fun <T, R> Result<T>.flatMap(transform: (T) -> Result<R>): Result<R> {
|
||||
return when (this) {
|
||||
is Result.Success -> transform(data)
|
||||
is Result.Error -> Result.Error(exception, message)
|
||||
is Result.Loading -> Result.Loading
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.anthonyla.paperize.core
|
||||
|
||||
enum class ScalingConstants {
|
||||
FIT,
|
||||
FILL,
|
||||
STRETCH
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.anthonyla.paperize.core
|
||||
|
||||
/**
|
||||
* Wallpaper scaling options
|
||||
*/
|
||||
enum class ScalingType {
|
||||
/**
|
||||
* Fill the screen, cropping if necessary
|
||||
*/
|
||||
FILL,
|
||||
|
||||
/**
|
||||
* Fit the entire image, adding letterboxing/pillarboxing if necessary
|
||||
*/
|
||||
FIT,
|
||||
|
||||
/**
|
||||
* Stretch the image to fill the screen
|
||||
*/
|
||||
STRETCH,
|
||||
|
||||
/**
|
||||
* Display at original size
|
||||
*/
|
||||
NONE;
|
||||
|
||||
companion object {
|
||||
fun fromString(value: String?): ScalingType {
|
||||
return entries.find { it.name.equals(value, ignoreCase = true) } ?: FILL
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.anthonyla.paperize.core
|
||||
|
||||
/**
|
||||
* Screen types for wallpaper setting
|
||||
*/
|
||||
enum class ScreenType {
|
||||
HOME,
|
||||
LOCK,
|
||||
BOTH,
|
||||
LIVE;
|
||||
|
||||
companion object {
|
||||
fun fromString(value: String?): ScreenType {
|
||||
return entries.find { it.name.equals(value, ignoreCase = true) } ?: BOTH
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.anthonyla.paperize.core
|
||||
|
||||
/**
|
||||
* Constants for application settings
|
||||
*/
|
||||
object SettingsConstants {
|
||||
const val SETTINGS_DATASTORE = "settings_datastore"
|
||||
const val DARK_MODE_TYPE = "dark_mode_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 HOME_WALLPAPER_CHANGE_INTERVAL = "home_wallpaper_change_interval"
|
||||
const val LOCK_WALLPAPER_CHANGE_INTERVAL = "lock_wallpaper_change_interval"
|
||||
const val WALLPAPER_CHANGE_INTERVAL_DEFAULT = 15
|
||||
const val FIRST_LAUNCH = "first_launch"
|
||||
const val FIRST_SET = "first_set"
|
||||
const val LAST_SET_TIME = "last_set_time"
|
||||
const val NEXT_SET_TIME = "next_set_time"
|
||||
const val DARKEN_PERCENTAGE = "darken_percentage"
|
||||
const val DARKEN = "darken"
|
||||
const val WALLPAPER_SCALING = "wallpaper_scaling"
|
||||
const val SCHEDULE_SEPARATELY = "schedule_separately"
|
||||
const val BLUR = "blur"
|
||||
const val BLUR_PERCENTAGE = "blur_percentage"
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.anthonyla.paperize.core
|
||||
|
||||
/**
|
||||
* Media type for wallpapers
|
||||
*
|
||||
* Determines what type of media the wallpaper file is, which affects
|
||||
* how it's rendered in live wallpaper mode.
|
||||
*
|
||||
* Note: Currently only IMAGE type is supported.
|
||||
*/
|
||||
enum class WallpaperMediaType {
|
||||
/**
|
||||
* Image files: JPEG, PNG, WEBP, AVIF, HEIC, HEIF, BMP, GIF, TIFF
|
||||
* Supported in both static and live wallpaper modes
|
||||
*/
|
||||
IMAGE;
|
||||
|
||||
/**
|
||||
* Supported file extensions for this media type
|
||||
*/
|
||||
val supportedExtensions: Set<String>
|
||||
get() = when (this) {
|
||||
IMAGE -> setOf(
|
||||
"jpg", "jpeg", "png", "webp", "avif",
|
||||
"heic", "heif", // HEIC/HEIF - Apple's high efficiency format
|
||||
"bmp", // Bitmap - legacy but still used
|
||||
"gif", // GIF - mostly for static images (first frame used)
|
||||
"tiff", "tif", // TIFF - high quality archival format
|
||||
"svg" // SVG - vector graphics (rasterized for wallpaper)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this media type is supported in static wallpaper mode
|
||||
*/
|
||||
val supportedInStaticMode: Boolean
|
||||
get() = this == IMAGE
|
||||
|
||||
/**
|
||||
* Whether this media type is supported in live wallpaper mode
|
||||
*/
|
||||
val supportedInLiveMode: Boolean
|
||||
get() = true // All types supported in live mode
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Detect media type from file extension
|
||||
*/
|
||||
fun fromExtension(extension: String): WallpaperMediaType? {
|
||||
val ext = extension.lowercase()
|
||||
return entries.find { ext in it.supportedExtensions }
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert string to WallpaperMediaType
|
||||
*/
|
||||
fun fromString(value: String?): WallpaperMediaType? {
|
||||
return entries.find { it.name.equals(value, ignoreCase = true) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.anthonyla.paperize.core
|
||||
|
||||
/**
|
||||
* Wallpaper mode enum
|
||||
*
|
||||
* Determines whether the app uses static wallpaper (WallpaperManager.setBitmap)
|
||||
* or live wallpaper (WallpaperService) for applying wallpapers.
|
||||
*
|
||||
* Users choose their preferred mode during onboarding and can switch later
|
||||
* with full data reset.
|
||||
*/
|
||||
enum class WallpaperMode {
|
||||
/**
|
||||
* Static wallpaper mode
|
||||
* - Uses WallpaperManager.setBitmap() to apply wallpapers
|
||||
* - Supports images only
|
||||
* - Lower battery usage
|
||||
* - No interactive effects
|
||||
*/
|
||||
STATIC,
|
||||
|
||||
/**
|
||||
* Live wallpaper mode
|
||||
* - Uses WallpaperService for continuous rendering
|
||||
* - Supports images only (with effects)
|
||||
* - Interactive effects (double-tap, parallax)
|
||||
* - Higher battery usage
|
||||
*/
|
||||
LIVE;
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Convert string to WallpaperMode
|
||||
* Defaults to STATIC if string is null or doesn't match any mode
|
||||
*/
|
||||
fun fromString(value: String?): WallpaperMode {
|
||||
return entries.find { it.name.equals(value, ignoreCase = true) } ?: STATIC
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.anthonyla.paperize.core
|
||||
|
||||
/**
|
||||
* Source type for wallpapers
|
||||
*/
|
||||
enum class WallpaperSourceType {
|
||||
/**
|
||||
* Directly selected wallpaper files
|
||||
*/
|
||||
DIRECT,
|
||||
|
||||
/**
|
||||
* Wallpapers from monitored folders
|
||||
*/
|
||||
FOLDER
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
package com.anthonyla.paperize.core
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.ColorMatrix
|
||||
import android.graphics.ColorMatrixColorFilter
|
||||
import android.graphics.Paint
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import android.util.Size
|
||||
import androidx.compose.ui.util.fastRoundToInt
|
||||
import androidx.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.google.android.renderscript.Toolkit
|
||||
import com.lazygeniouz.dfc.file.DocumentFileCompat
|
||||
|
||||
/**
|
||||
* Get the dimensions of the image from the uri
|
||||
*/
|
||||
fun Uri.getImageDimensions(context: Context): Size? {
|
||||
try {
|
||||
context.contentResolver.openInputStream(this)?.use { inputStream ->
|
||||
val exif = ExifInterface(inputStream)
|
||||
var width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0)
|
||||
var height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0)
|
||||
if (width == 0 || height == 0) {
|
||||
val options = BitmapFactory.Options().apply {
|
||||
inJustDecodeBounds = true
|
||||
}
|
||||
BitmapFactory.decodeStream(
|
||||
context.contentResolver.openInputStream(this),
|
||||
null,
|
||||
options
|
||||
)
|
||||
width = options.outWidth
|
||||
height = options.outHeight
|
||||
}
|
||||
return Size(width, height)
|
||||
}
|
||||
return null
|
||||
} catch (e: Exception) { return null }
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the inSampleSize for the image
|
||||
*/
|
||||
fun calculateInSampleSize(imageSize: Size, width: Int, height: Int): Int {
|
||||
return if (imageSize.width <= width && imageSize.height <= height) { 1 }
|
||||
else { (imageSize.width/ width.toFloat()).fastRoundToInt() }
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale a bitmap using the fit width method
|
||||
* The bitmap will fit into the given width while maintaining the same aspect ratio
|
||||
*/
|
||||
fun fitBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
val aspectRatio = source.height.toFloat() / source.width.toFloat()
|
||||
val newHeight = (width * aspectRatio).toInt()
|
||||
val newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(newBitmap)
|
||||
val scaledBitmap = Bitmap.createScaledBitmap(source, width, newHeight, true)
|
||||
val top = (height - newHeight) / 2f
|
||||
canvas.drawBitmap(scaledBitmap, 0f, top, null)
|
||||
scaledBitmap.recycle()
|
||||
return newBitmap
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale a bitmap using the fill height method
|
||||
*/
|
||||
fun fillBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
try {
|
||||
val aspectRatio = source.width.toFloat() / source.height.toFloat()
|
||||
var newWidth = width
|
||||
var newHeight = (newWidth / aspectRatio).toInt()
|
||||
if (newHeight < height) {
|
||||
newHeight = height
|
||||
newWidth = (newHeight * aspectRatio).toInt()
|
||||
}
|
||||
val scaledBitmap = Bitmap.createScaledBitmap(source, newWidth, newHeight, true)
|
||||
val x = (width - newWidth) / 2f
|
||||
val y = (height - newHeight) / 2f
|
||||
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(bitmap)
|
||||
canvas.drawBitmap(scaledBitmap, x, y, null)
|
||||
scaledBitmap.recycle()
|
||||
return bitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error filling bitmap: $e")
|
||||
return source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stretch the bitmap to fit the given width and height
|
||||
*/
|
||||
fun stretchBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
try {
|
||||
val newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(newBitmap)
|
||||
val bitmap = Bitmap.createScaledBitmap(source, width, height, true)
|
||||
canvas.drawBitmap(bitmap, 0f, 0f, null)
|
||||
bitmap.recycle()
|
||||
return newBitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error stretching bitmap: $e")
|
||||
return source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Darken the bitmap by a certain percentage - 0 is darkest, 100 is original
|
||||
*/
|
||||
fun darkenBitmap(source: Bitmap, percent: Int): Bitmap {
|
||||
try {
|
||||
val safePercentage = (100 - percent).coerceIn(0, 100)
|
||||
val factor = 1 - safePercentage / 100f
|
||||
val canvas = Canvas(source)
|
||||
val paint = Paint().apply {
|
||||
colorFilter = ColorMatrixColorFilter(ColorMatrix().apply {
|
||||
setScale(factor, factor, factor, 1f)
|
||||
})
|
||||
}
|
||||
canvas.drawBitmap(source, 0f, 0f, paint)
|
||||
return source
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error darkening bitmap: $e")
|
||||
return source
|
||||
}
|
||||
}
|
||||
|
||||
fun blurBitmap(source: Bitmap, percent: Int): Bitmap {
|
||||
try {
|
||||
val factor = percent.toFloat().div(100f) * 10
|
||||
return Toolkit.blur(source, factor.toInt())
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error darkening bitmap: $e")
|
||||
return source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve wallpaper URIs from a folder directory URI
|
||||
*/
|
||||
fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
|
||||
val folderDocumentFile = DocumentFileCompat.fromTreeUri(context, folderUri.toUri())
|
||||
return listFilesRecursive(folderDocumentFile, context)
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to recursively list files in a directory
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
package com.anthonyla.paperize.core.constants
|
||||
|
||||
/**
|
||||
* Application-wide constants
|
||||
*/
|
||||
object Constants {
|
||||
// Database
|
||||
const val DATABASE_NAME = "paperize_database"
|
||||
const val DATABASE_VERSION = 2 // v2: Added mediaType and crop fields to WallpaperEntity
|
||||
|
||||
// DataStore
|
||||
const val PREFERENCES_NAME = "paperize_preferences"
|
||||
|
||||
// Notifications
|
||||
const val NOTIFICATION_CHANNEL_ID = "paperize_channel"
|
||||
const val NOTIFICATION_ID = 1
|
||||
|
||||
// Services
|
||||
const val ACTION_CHANGE_WALLPAPER = "com.anthonyla.paperize.ACTION_CHANGE_WALLPAPER"
|
||||
const val ACTION_RELOAD_WALLPAPER = "com.anthonyla.paperize.ACTION_RELOAD_WALLPAPER"
|
||||
|
||||
// WorkManager
|
||||
const val WORK_NAME_HOME = "wallpaper_change_home"
|
||||
const val WORK_NAME_LOCK = "wallpaper_change_lock"
|
||||
const val WORK_NAME_BOTH = "wallpaper_change_both"
|
||||
const val WORK_NAME_LIVE = "wallpaper_change_live"
|
||||
const val WORK_NAME_REFRESH = "album_refresh"
|
||||
const val WORK_TAG_HOME = "wallpaper_change_home_tag"
|
||||
const val WORK_TAG_LOCK = "wallpaper_change_lock_tag"
|
||||
const val WORK_TAG_BOTH = "wallpaper_change_both_tag"
|
||||
const val WORK_TAG_LIVE = "wallpaper_change_live_tag"
|
||||
const val WORK_TAG_REFRESH = "album_refresh_tag"
|
||||
const val MAX_WORK_RETRY_ATTEMPTS = 3
|
||||
|
||||
// Intents
|
||||
const val EXTRA_SCREEN_TYPE = "screen_type"
|
||||
|
||||
// Wallpaper
|
||||
const val DEFAULT_BLUR_PERCENTAGE = 0
|
||||
const val DEFAULT_DARKEN_PERCENTAGE = 0
|
||||
const val DEFAULT_VIGNETTE_PERCENTAGE = 0
|
||||
const val DEFAULT_PARALLAX_INTENSITY = 50
|
||||
const val DEFAULT_GRAYSCALE_PERCENTAGE = 0
|
||||
const val MAX_EFFECT_PERCENTAGE = 100
|
||||
const val SLIDER_EFFECT_STEPS = 99
|
||||
const val DIALOG_MESSAGE_MAX_LINES = 10
|
||||
const val MIN_EFFECT_PERCENTAGE = 0
|
||||
const val FLOW_SUBSCRIPTION_TIMEOUT_MS = 5000L
|
||||
|
||||
// Scheduling
|
||||
const val MIN_INTERVAL_MINUTES = 15
|
||||
const val MAX_INTERVAL_MINUTES = 43200 // 30 days in minutes
|
||||
const val DEFAULT_INTERVAL_MINUTES = 60
|
||||
|
||||
// UI
|
||||
const val ANIMATION_DURATION_LONG_MS = 800 // For item reordering animations
|
||||
const val DEBOUNCE_DELAY_MS = 500L
|
||||
const val PERMISSION_SCREEN_TRANSITION_DELAY_MS = 300L // Brief delay for permission screen transitions
|
||||
const val SETTINGS_DEBOUNCE_MS = 2000L // Debounce for settings changes before persisting
|
||||
const val WALLPAPER_CHANGE_DEBOUNCE_MS = 2000L
|
||||
const val WALLPAPER_ASPECT_RATIO = 9f / 16f // Standard phone aspect ratio
|
||||
const val GRID_THUMBNAIL_WIDTH = 300
|
||||
const val GRID_THUMBNAIL_HEIGHT = 500
|
||||
const val LIST_THUMBNAIL_SIZE = 150
|
||||
const val PREVIEW_THUMBNAIL_WIDTH = 600
|
||||
const val PREVIEW_THUMBNAIL_HEIGHT = 1200
|
||||
|
||||
// Time conversion
|
||||
const val MINUTES_PER_HOUR = 60
|
||||
const val MINUTES_PER_DAY = 1440
|
||||
|
||||
// Image processing
|
||||
const val MAX_BLUR_RADIUS = 25.0f
|
||||
const val BRIGHTNESS_SAMPLE_SIZE = 10 // Pixel sample size for brightness calculation
|
||||
const val DEFAULT_BRIGHTNESS = 0.5f // Default brightness fallback
|
||||
|
||||
// Luminance coefficients (ITU-R BT.709 standard)
|
||||
const val LUMINANCE_RED = 0.2126
|
||||
const val LUMINANCE_GREEN = 0.7152
|
||||
const val LUMINANCE_BLUE = 0.0722
|
||||
|
||||
// Adaptive brightness thresholds (based on WallYou implementation)
|
||||
const val LIGHT_BRIGHTNESS_MIN = 0.8f // Threshold for bright images in dark mode
|
||||
const val DARK_BRIGHTNESS_MAX = 0.3f // Threshold for dark images in light mode
|
||||
const val TARGET_BRIGHTNESS_DARK = 0.7f // Target brightness in dark mode
|
||||
const val TARGET_BRIGHTNESS_LIGHT = 0.4f // Target brightness in light mode
|
||||
|
||||
// Vignette effect
|
||||
const val VIGNETTE_DIVISOR = 150f // Radius calculation divisor
|
||||
const val VIGNETTE_MIN_RADIUS = 0.1f // Minimum vignette radius
|
||||
const val VIGNETTE_INNER_ALPHA = 0.1f // Inner alpha for vignette gradient
|
||||
const val VIGNETTE_OUTER_ALPHA = 0.8f // Outer alpha for vignette gradient
|
||||
val VIGNETTE_GRADIENT_POSITIONS = floatArrayOf(0f, 0.7f, 1f) // Vignette gradient positions
|
||||
|
||||
// Wallpaper loading retry
|
||||
const val WALLPAPER_READ_INITIAL_DELAY_MS = 500L // Initial retry delay (with linear backoff)
|
||||
|
||||
// Input validation
|
||||
const val MAX_DAYS_INPUT_LENGTH = 3
|
||||
const val MAX_HOURS_MINUTES_INPUT_LENGTH = 2
|
||||
|
||||
// File types
|
||||
val SUPPORTED_IMAGE_EXTENSIONS = setOf(
|
||||
"jpg", "jpeg", "png", "webp", "avif",
|
||||
"heic", "heif", // HEIC/HEIF - Apple's high efficiency format
|
||||
"bmp", // Bitmap - legacy but still used
|
||||
"gif", // GIF - mostly for static images (first frame used)
|
||||
"tiff", "tif", // TIFF - high quality archival format
|
||||
"svg" // SVG - vector graphics (rasterized for wallpaper)
|
||||
)
|
||||
|
||||
// Renderer
|
||||
/** Crossfade animation duration in milliseconds - consistent across all refresh rates */
|
||||
const val CROSSFADE_DURATION_MS = 750f
|
||||
const val RELOAD_THROTTLE_MS = 250L
|
||||
const val BLUR_MIN_THRESHOLD = 0.01f
|
||||
const val PERCENTAGE_DIVISOR = 100f
|
||||
const val GL_ES_VERSION = 2
|
||||
const val SURFACE_POLL_INTERVAL_MS = 50L
|
||||
|
||||
// Wallpaper loading
|
||||
const val MAX_WALLPAPER_LOAD_RETRIES = 10
|
||||
const val MAX_QUEUE_REBUILD_ATTEMPTS = 2
|
||||
}
|
||||
|
||||
/**
|
||||
* Preference keys for DataStore
|
||||
*/
|
||||
object PreferenceKeys {
|
||||
// Theme
|
||||
const val DARK_MODE = "dark_mode"
|
||||
const val DYNAMIC_THEMING = "dynamic_theming"
|
||||
const val ANIMATE = "animate"
|
||||
|
||||
// Scheduling
|
||||
const val ENABLE_CHANGER = "enable_changer"
|
||||
const val SEPARATE_SCHEDULES = "separate_schedules"
|
||||
const val SHUFFLE_ENABLED = "shuffle_enabled"
|
||||
const val HOME_ENABLED = "home_enabled"
|
||||
const val LOCK_ENABLED = "lock_enabled"
|
||||
const val HOME_ALBUM_ID = "home_album_id"
|
||||
const val LOCK_ALBUM_ID = "lock_album_id"
|
||||
const val HOME_INTERVAL_MINUTES = "home_interval_minutes"
|
||||
const val LOCK_INTERVAL_MINUTES = "lock_interval_minutes"
|
||||
|
||||
// Effects - Home
|
||||
const val HOME_ENABLE_BLUR = "home_enable_blur"
|
||||
const val HOME_BLUR = "home_blur"
|
||||
const val HOME_ENABLE_DARKEN = "home_enable_darken"
|
||||
const val HOME_DARKEN = "home_darken"
|
||||
const val HOME_ENABLE_VIGNETTE = "home_enable_vignette"
|
||||
const val HOME_VIGNETTE = "home_vignette"
|
||||
const val HOME_ENABLE_GRAYSCALE = "home_enable_grayscale"
|
||||
const val HOME_GRAYSCALE = "home_grayscale"
|
||||
|
||||
// Effects - Lock
|
||||
const val LOCK_ENABLE_BLUR = "lock_enable_blur"
|
||||
const val LOCK_BLUR = "lock_blur"
|
||||
const val LOCK_ENABLE_DARKEN = "lock_enable_darken"
|
||||
const val LOCK_DARKEN = "lock_darken"
|
||||
const val LOCK_ENABLE_VIGNETTE = "lock_enable_vignette"
|
||||
const val LOCK_VIGNETTE = "lock_vignette"
|
||||
const val LOCK_ENABLE_GRAYSCALE = "lock_enable_grayscale"
|
||||
const val LOCK_GRAYSCALE = "lock_grayscale"
|
||||
|
||||
// Interactive Effects - Home (live wallpaper mode only)
|
||||
const val HOME_ENABLE_DOUBLE_TAP = "home_enable_double_tap"
|
||||
const val HOME_ENABLE_PARALLAX = "home_enable_parallax"
|
||||
const val HOME_PARALLAX_INTENSITY = "home_parallax_intensity"
|
||||
|
||||
// Interactive Effects - Lock (live wallpaper mode only)
|
||||
const val LOCK_ENABLE_DOUBLE_TAP = "lock_enable_double_tap"
|
||||
const val LOCK_ENABLE_PARALLAX = "lock_enable_parallax"
|
||||
const val LOCK_PARALLAX_INTENSITY = "lock_parallax_intensity"
|
||||
|
||||
// Live Wallpaper Mode Settings
|
||||
const val LIVE_ALBUM_ID = "live_album_id"
|
||||
const val LIVE_INTERVAL_MINUTES = "live_interval_minutes"
|
||||
const val LIVE_ENABLE_BLUR = "live_enable_blur"
|
||||
const val LIVE_BLUR = "live_blur"
|
||||
const val LIVE_ENABLE_DARKEN = "live_enable_darken"
|
||||
const val LIVE_DARKEN = "live_darken"
|
||||
const val LIVE_ENABLE_VIGNETTE = "live_enable_vignette"
|
||||
const val LIVE_VIGNETTE = "live_vignette"
|
||||
const val LIVE_ENABLE_GRAYSCALE = "live_enable_grayscale"
|
||||
const val LIVE_GRAYSCALE = "live_grayscale"
|
||||
const val LIVE_ENABLE_DOUBLE_TAP = "live_enable_double_tap"
|
||||
const val LIVE_ENABLE_CHANGE_ON_SCREEN_ON = "live_enable_change_on_screen_on"
|
||||
const val LIVE_ENABLE_PARALLAX = "live_enable_parallax"
|
||||
const val LIVE_PARALLAX_INTENSITY = "live_parallax_intensity"
|
||||
|
||||
// Scaling
|
||||
const val HOME_SCALING_TYPE = "home_scaling_type"
|
||||
const val LOCK_SCALING_TYPE = "lock_scaling_type"
|
||||
const val LIVE_SCALING_TYPE = "live_scaling_type"
|
||||
|
||||
// Current wallpapers
|
||||
const val CURRENT_HOME_WALLPAPER_ID = "current_home_wallpaper_id"
|
||||
const val CURRENT_LOCK_WALLPAPER_ID = "current_lock_wallpaper_id"
|
||||
|
||||
// Behavior
|
||||
const val ADAPTIVE_BRIGHTNESS = "adaptive_brightness"
|
||||
|
||||
// First launch
|
||||
const val FIRST_LAUNCH = "first_launch"
|
||||
|
||||
// Wallpaper mode
|
||||
const val WALLPAPER_MODE = "wallpaper_mode"
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.anthonyla.paperize.core.di
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.room.Room
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
import com.anthonyla.paperize.data.database.PaperizeDatabase
|
||||
import com.anthonyla.paperize.data.database.dao.AlbumDao
|
||||
import com.anthonyla.paperize.data.database.dao.FolderDao
|
||||
import com.anthonyla.paperize.data.database.dao.WallpaperDao
|
||||
import com.anthonyla.paperize.data.database.dao.WallpaperQueueDao
|
||||
import com.anthonyla.paperize.data.datastore.PreferencesManager
|
||||
import com.anthonyla.paperize.data.repository.AlbumRepositoryImpl
|
||||
import com.anthonyla.paperize.data.repository.SettingsRepositoryImpl
|
||||
import com.anthonyla.paperize.data.repository.WallpaperRepositoryImpl
|
||||
import com.anthonyla.paperize.domain.repository.AlbumRepository
|
||||
import com.anthonyla.paperize.domain.repository.SettingsRepository
|
||||
import com.anthonyla.paperize.domain.repository.WallpaperRepository
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Hilt dependency injection module
|
||||
*
|
||||
* Provides all application-wide dependencies
|
||||
*/
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object AppModule {
|
||||
|
||||
/**
|
||||
* Provide Room database
|
||||
*/
|
||||
@Provides
|
||||
@Singleton
|
||||
fun providePaperizeDatabase(app: Application): PaperizeDatabase {
|
||||
return Room.databaseBuilder(
|
||||
app,
|
||||
PaperizeDatabase::class.java,
|
||||
Constants.DATABASE_NAME
|
||||
)
|
||||
.fallbackToDestructiveMigration(dropAllTables = true)
|
||||
.build()
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide DAOs
|
||||
*/
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideAlbumDao(database: PaperizeDatabase): AlbumDao =
|
||||
database.albumDao()
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideWallpaperDao(database: PaperizeDatabase): WallpaperDao =
|
||||
database.wallpaperDao()
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideFolderDao(database: PaperizeDatabase): FolderDao =
|
||||
database.folderDao()
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideWallpaperQueueDao(database: PaperizeDatabase): WallpaperQueueDao =
|
||||
database.wallpaperQueueDao()
|
||||
|
||||
/**
|
||||
* Provide PreferencesManager
|
||||
*/
|
||||
@Provides
|
||||
@Singleton
|
||||
fun providePreferencesManager(@ApplicationContext context: Context): PreferencesManager =
|
||||
PreferencesManager(context)
|
||||
|
||||
/**
|
||||
* Provide Repositories
|
||||
*/
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideAlbumRepository(
|
||||
@ApplicationContext context: Context,
|
||||
database: PaperizeDatabase,
|
||||
albumDao: AlbumDao,
|
||||
wallpaperDao: WallpaperDao,
|
||||
folderDao: FolderDao,
|
||||
wallpaperRepository: dagger.Lazy<WallpaperRepository>
|
||||
): AlbumRepository = AlbumRepositoryImpl(context, database, albumDao, wallpaperDao, folderDao, wallpaperRepository)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideWallpaperRepository(
|
||||
@ApplicationContext context: Context,
|
||||
wallpaperDao: WallpaperDao,
|
||||
wallpaperQueueDao: WallpaperQueueDao
|
||||
): WallpaperRepository = WallpaperRepositoryImpl(context, wallpaperDao, wallpaperQueueDao)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSettingsRepository(
|
||||
preferencesManager: PreferencesManager
|
||||
): SettingsRepository = SettingsRepositoryImpl(preferencesManager)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.anthonyla.paperize.core.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.PowerManager
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
|
||||
/**
|
||||
* Utility for handling battery optimization (Doze mode) exclusion
|
||||
*/
|
||||
object BatteryOptimizationUtil {
|
||||
private const val TAG = "BatteryOptimizationUtil"
|
||||
|
||||
/**
|
||||
* Check if the app is currently excluded from battery optimizations
|
||||
*/
|
||||
fun isIgnoringBatteryOptimizations(context: Context): Boolean {
|
||||
val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||
return powerManager.isIgnoringBatteryOptimizations(context.packageName)
|
||||
}
|
||||
|
||||
/**
|
||||
* Request the user to exclude the app from battery optimizations
|
||||
* Opens the system battery optimization settings page
|
||||
*/
|
||||
fun requestIgnoreBatteryOptimizations(context: Context) {
|
||||
try {
|
||||
val intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply {
|
||||
data = Uri.parse("package:${context.packageName}")
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
context.startActivity(intent)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error requesting battery optimization exclusion", e)
|
||||
// Fallback: open general battery optimization settings
|
||||
try {
|
||||
val fallbackIntent = Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
context.startActivity(fallbackIntent)
|
||||
} catch (e2: Exception) {
|
||||
Log.e(TAG, "Error opening battery optimization settings", e2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.anthonyla.paperize.core.util
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import androidx.core.graphics.get
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
|
||||
/**
|
||||
* Utility class for brightness calculations and adaptive adjustments.
|
||||
* Extracted from WallpaperUtil for better testability.
|
||||
*/
|
||||
object BrightnessCalculator {
|
||||
|
||||
/**
|
||||
* Calculate relative luminance of a single pixel using ITU-R BT.709 standard.
|
||||
* Use bitwise operations to avoid dependency on android.graphics.Color in core logic tests.
|
||||
*/
|
||||
fun calculateLuminance(pixel: Int): Double {
|
||||
val r = ((pixel shr 16) and 0xFF) / 255.0
|
||||
val g = ((pixel shr 8) and 0xFF) / 255.0
|
||||
val b = (pixel and 0xFF) / 255.0
|
||||
|
||||
return Constants.LUMINANCE_RED * r + Constants.LUMINANCE_GREEN * g + Constants.LUMINANCE_BLUE * b
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate brightness estimate of bitmap (0.0 - 1.0)
|
||||
* Uses luminance calculation based on RGB values.
|
||||
*/
|
||||
fun calculateBitmapBrightness(bitmap: Bitmap): Float {
|
||||
val sampleSize = Constants.BRIGHTNESS_SAMPLE_SIZE
|
||||
var totalLuminance = 0.0
|
||||
var pixelCount = 0
|
||||
|
||||
for (x in 0 until bitmap.width step sampleSize) {
|
||||
for (y in 0 until bitmap.height step sampleSize) {
|
||||
val pixel = bitmap[x, y]
|
||||
totalLuminance += calculateLuminance(pixel)
|
||||
pixelCount++
|
||||
}
|
||||
}
|
||||
|
||||
return if (pixelCount > 0) {
|
||||
(totalLuminance / pixelCount).toFloat()
|
||||
} else {
|
||||
Constants.DEFAULT_BRIGHTNESS
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get adaptive brightness multiplier factor based on system dark/light mode.
|
||||
*
|
||||
* @param isDarkMode Whether the system is in dark mode
|
||||
* @param brightness Current image brightness (0.0 to 1.0)
|
||||
* @return Multiplier factor to apply to colors
|
||||
*/
|
||||
fun getAdaptiveMultiplier(isDarkMode: Boolean, brightness: Float): Float {
|
||||
val lightBrightnessMin = Constants.LIGHT_BRIGHTNESS_MIN
|
||||
val darkBrightnessMax = Constants.DARK_BRIGHTNESS_MAX
|
||||
val targetBrightnessDark = Constants.TARGET_BRIGHTNESS_DARK
|
||||
val targetBrightnessLight = Constants.TARGET_BRIGHTNESS_LIGHT
|
||||
|
||||
// Avoid issues with very dark items or division by zero
|
||||
if (brightness < 0.01f) return 1.0f
|
||||
|
||||
return when {
|
||||
// In dark mode with very bright image: darken it
|
||||
isDarkMode && brightness > lightBrightnessMin -> targetBrightnessDark / brightness
|
||||
// In light mode with very dark image: brighten it
|
||||
!isDarkMode && brightness < darkBrightnessMax -> targetBrightnessLight / brightness
|
||||
// No adjustment needed
|
||||
else -> 1.0f
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.anthonyla.paperize.core.util
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Manages one-time data reset for major version upgrades.
|
||||
*
|
||||
* Uses a separate preferences file (version_prefs) to track reset status,
|
||||
* ensuring the flag survives the data wipe itself.
|
||||
*/
|
||||
object DataResetManager {
|
||||
private const val TAG = "DataResetManager"
|
||||
|
||||
/**
|
||||
* Version tracking preferences - stored separately from main app prefs
|
||||
* so it survives the data wipe.
|
||||
*/
|
||||
private const val VERSION_PREFS_NAME = "version_prefs"
|
||||
private const val KEY_LAST_RESET_VERSION = "last_reset_version"
|
||||
|
||||
/**
|
||||
* Target reset version - increment this for future major version upgrades
|
||||
* that require a complete data wipe.
|
||||
*
|
||||
* Version 4 = v4.0.0 release (complete app rewrite)
|
||||
*/
|
||||
private const val TARGET_RESET_VERSION = 4
|
||||
|
||||
/**
|
||||
* Database and DataStore names to clear (must match Constants)
|
||||
*/
|
||||
private const val DATABASE_NAME = "paperize_database"
|
||||
private const val DATASTORE_NAME = "paperize_preferences.preferences_pb"
|
||||
|
||||
/**
|
||||
* Performs a complete data reset if needed for the current app version.
|
||||
*
|
||||
* This should be called at the very start of Application.onCreate(),
|
||||
* before any other initialization occurs.
|
||||
*
|
||||
* @return true if a reset was performed, false otherwise
|
||||
*/
|
||||
fun performResetIfNeeded(context: Context): Boolean {
|
||||
val versionPrefs = context.getSharedPreferences(VERSION_PREFS_NAME, Context.MODE_PRIVATE)
|
||||
val lastResetVersion = versionPrefs.getInt(KEY_LAST_RESET_VERSION, 0)
|
||||
|
||||
if (lastResetVersion >= TARGET_RESET_VERSION) {
|
||||
Log.d(TAG, "No reset needed (last=$lastResetVersion, target=$TARGET_RESET_VERSION)")
|
||||
return false
|
||||
}
|
||||
|
||||
Log.w(TAG, "Performing data reset: upgrading from version $lastResetVersion to $TARGET_RESET_VERSION")
|
||||
|
||||
try {
|
||||
// 1. Delete Room database files
|
||||
deleteDatabase(context)
|
||||
|
||||
// 2. Delete DataStore file
|
||||
deleteDataStore(context)
|
||||
|
||||
// 3. Update version after successful wipe
|
||||
versionPrefs.edit()
|
||||
.putInt(KEY_LAST_RESET_VERSION, TARGET_RESET_VERSION)
|
||||
.apply()
|
||||
|
||||
Log.i(TAG, "Data reset completed successfully")
|
||||
return true
|
||||
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error during data reset", e)
|
||||
// Still mark as reset to avoid infinite reset loops on corrupted data
|
||||
versionPrefs.edit()
|
||||
.putInt(KEY_LAST_RESET_VERSION, TARGET_RESET_VERSION)
|
||||
.apply()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes Room database and all related files (WAL, SHM, journal)
|
||||
*/
|
||||
private fun deleteDatabase(context: Context) {
|
||||
val dbPath = context.getDatabasePath(DATABASE_NAME)
|
||||
val dbDir = dbPath.parentFile
|
||||
|
||||
if (dbDir != null && dbDir.exists()) {
|
||||
// Delete main database file and all related files
|
||||
val filesToDelete = listOf(
|
||||
DATABASE_NAME,
|
||||
"$DATABASE_NAME-wal",
|
||||
"$DATABASE_NAME-shm",
|
||||
"$DATABASE_NAME-journal"
|
||||
)
|
||||
|
||||
for (fileName in filesToDelete) {
|
||||
val file = File(dbDir, fileName)
|
||||
if (file.exists()) {
|
||||
val deleted = file.delete()
|
||||
Log.d(TAG, "Deleted $fileName: $deleted")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Also use Context.deleteDatabase for good measure
|
||||
val deleted = context.deleteDatabase(DATABASE_NAME)
|
||||
Log.d(TAG, "Context.deleteDatabase result: $deleted")
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes DataStore preferences file
|
||||
*/
|
||||
private fun deleteDataStore(context: Context) {
|
||||
val dataStoreFile = File(context.filesDir, "datastore/$DATASTORE_NAME")
|
||||
if (dataStoreFile.exists()) {
|
||||
val deleted = dataStoreFile.delete()
|
||||
Log.d(TAG, "Deleted DataStore file: $deleted")
|
||||
}
|
||||
|
||||
// Also delete the datastore directory if empty
|
||||
val dataStoreDir = File(context.filesDir, "datastore")
|
||||
if (dataStoreDir.exists() && dataStoreDir.isDirectory) {
|
||||
val files = dataStoreDir.listFiles()
|
||||
if (files.isNullOrEmpty()) {
|
||||
dataStoreDir.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.anthonyla.paperize.core.util
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import java.util.UUID
|
||||
|
||||
/**
|
||||
* URI extensions
|
||||
*/
|
||||
fun Uri.isValid(contentResolver: ContentResolver): Boolean {
|
||||
// Basic scheme check - we only handle content URIs
|
||||
if (scheme != "content") return false
|
||||
|
||||
return try {
|
||||
// Optimization: Use query to check existence/accessibility without opening the file
|
||||
// This is significantly faster and less likely to hang on slow cloud providers
|
||||
contentResolver.query(this, arrayOf(android.provider.OpenableColumns.DISPLAY_NAME), null, null, null)?.use { cursor ->
|
||||
cursor.moveToFirst()
|
||||
} ?: false
|
||||
} catch (_: Exception) {
|
||||
// Fallback to opening the stream if the provider doesn't support the specific query
|
||||
try {
|
||||
contentResolver.openFileDescriptor(this, "r")?.use { true } ?: false
|
||||
} catch (_: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Uri.getFileName(context: Context): String? {
|
||||
return DocumentFile.fromSingleUri(context, this)?.name
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan a folder URI and return all image file URIs
|
||||
*/
|
||||
fun Uri.scanFolderForImages(context: Context): List<Uri> {
|
||||
val documentFile = DocumentFile.fromTreeUri(context, this) ?: return emptyList()
|
||||
if (!documentFile.isDirectory) return emptyList()
|
||||
|
||||
val imageUris = mutableListOf<Uri>()
|
||||
val supportedTypes = setOf(
|
||||
"image/jpeg",
|
||||
"image/jpg",
|
||||
"image/png",
|
||||
"image/webp",
|
||||
"image/avif"
|
||||
)
|
||||
|
||||
fun scanDirectory(directory: DocumentFile) {
|
||||
directory.listFiles().forEach { file ->
|
||||
when {
|
||||
file.isDirectory -> scanDirectory(file) // Recursively scan subdirectories
|
||||
file.isFile && file.type in supportedTypes -> {
|
||||
imageUris.add(file.uri)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scanDirectory(documentFile)
|
||||
return imageUris.sortedBy { it.toString() } // Sort for consistency
|
||||
}
|
||||
|
||||
/**
|
||||
* UUID generation
|
||||
*/
|
||||
fun generateId(): String = UUID.randomUUID().toString()
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.anthonyla.paperize.core.util
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import androidx.core.content.ContextCompat
|
||||
|
||||
object PermissionUtil {
|
||||
|
||||
fun hasNotificationPermission(context: Context): Boolean {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
ContextCompat.checkSelfPermission(
|
||||
context,
|
||||
Manifest.permission.POST_NOTIFICATIONS
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fun hasStoragePermission(): Boolean {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
Environment.isExternalStorageManager()
|
||||
} else {
|
||||
// For older versions, we might check READ_EXTERNAL_STORAGE, but the app flow seems to rely on MANAGE for All Files Access
|
||||
// Stick to the existing logic which uses Environment.isExternalStorageManager()
|
||||
Environment.isExternalStorageManager()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.anthonyla.paperize.core.util
|
||||
|
||||
/**
|
||||
* Utility object for building and managing wallpaper queues
|
||||
* Extracted from WallpaperRepositoryImpl for testability
|
||||
*
|
||||
* Note: The DAO-specific operations remain in the repository,
|
||||
* but the pure logic functions are extracted here for testing.
|
||||
*/
|
||||
object QueueBuilder {
|
||||
|
||||
/**
|
||||
* Build a queue of wallpaper IDs based on display order (sequential mode)
|
||||
* @param wallpaperIds List of wallpaper IDs with their display orders
|
||||
* @return List of IDs sorted by display order
|
||||
*/
|
||||
fun buildSequentialQueue(wallpaperIds: List<Pair<String, Int>>): List<String> {
|
||||
return wallpaperIds.sortedBy { it.second }.map { it.first }
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a shuffled queue of wallpaper IDs
|
||||
* @param wallpaperIds List of wallpaper IDs to shuffle
|
||||
* @return Shuffled list of IDs
|
||||
*/
|
||||
fun buildShuffledQueue(wallpaperIds: List<String>): List<String> {
|
||||
return wallpaperIds.shuffled()
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if queue positions need normalization
|
||||
* Positions need normalization if they have gaps (e.g., 0, 2, 4 instead of 0, 1, 2)
|
||||
* @param positions Current queue positions
|
||||
* @return True if normalization is needed, false otherwise
|
||||
*/
|
||||
fun needsNormalization(positions: List<Int>): Boolean {
|
||||
if (positions.isEmpty()) return false
|
||||
val sorted = positions.sorted()
|
||||
return sorted.indices.any { sorted[it] != it }
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize queue positions to be sequential starting from 0
|
||||
* @param positions Current queue positions (may have gaps)
|
||||
* @return Normalized positions (0, 1, 2, ...)
|
||||
*/
|
||||
fun normalizePositions(positions: List<Int>): List<Int> {
|
||||
return positions.indices.toList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge existing queue with new wallpapers while preserving existing order
|
||||
* Used when new wallpapers are added to an album during shuffle mode
|
||||
* @param existingQueueIds Current queue order (filtered to valid IDs)
|
||||
* @param allWallpaperIds All current wallpaper IDs in the album
|
||||
* @return Combined list with existing order preserved, new IDs shuffled at end
|
||||
*/
|
||||
fun mergeWithExistingQueue(
|
||||
existingQueueIds: List<String>,
|
||||
allWallpaperIds: List<String>
|
||||
): List<String> {
|
||||
// Filter existing queue to only include IDs that still exist
|
||||
val existingValid = existingQueueIds.filter { it in allWallpaperIds }
|
||||
|
||||
// Find new wallpapers not in existing queue
|
||||
val newWallpaperIds = allWallpaperIds.filter { it !in existingQueueIds }
|
||||
|
||||
// Return existing order with new wallpapers shuffled at the end
|
||||
return existingValid + newWallpaperIds.shuffled()
|
||||
}
|
||||
|
||||
/**
|
||||
* Deterministic version of mergeWithExistingQueue for testing
|
||||
* New wallpapers are appended in their original order instead of shuffled
|
||||
*/
|
||||
fun mergeWithExistingQueueDeterministic(
|
||||
existingQueueIds: List<String>,
|
||||
allWallpaperIds: List<String>
|
||||
): List<String> {
|
||||
val existingValid = existingQueueIds.filter { it in allWallpaperIds }
|
||||
val newWallpaperIds = allWallpaperIds.filter { it !in existingQueueIds }
|
||||
return existingValid + newWallpaperIds
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a wallpaper queue based on shuffle and existing queues
|
||||
* @param wallpapers Current list of wallpapers in the album
|
||||
* @param shuffle Whether shuffle is enabled
|
||||
* @param otherScreenQueue Optional existing queue for another screen type to synchronize with
|
||||
* @return List of wallpaper IDs for the new queue
|
||||
*/
|
||||
fun buildQueue(
|
||||
wallpapers: List<com.anthonyla.paperize.domain.model.Wallpaper>,
|
||||
shuffle: Boolean,
|
||||
otherScreenQueue: List<String>? = null
|
||||
): List<String> {
|
||||
return if (shuffle) {
|
||||
if (otherScreenQueue != null && otherScreenQueue.isNotEmpty()) {
|
||||
// Synchronize with existing queue from another screen
|
||||
mergeWithExistingQueue(otherScreenQueue, wallpapers.map { it.id })
|
||||
} else {
|
||||
// New shuffled order
|
||||
buildShuffledQueue(wallpapers.map { it.id })
|
||||
}
|
||||
} else {
|
||||
// Sequential order by displayOrder
|
||||
buildSequentialQueue(wallpapers.map { it.id to it.displayOrder })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
package com.anthonyla.paperize.core.util
|
||||
|
||||
import com.anthonyla.paperize.domain.model.Folder
|
||||
import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
|
||||
/**
|
||||
* Utility object for sorting wallpapers and folders
|
||||
* Extracted from ViewModels for testability
|
||||
*/
|
||||
object WallpaperSorter {
|
||||
|
||||
/**
|
||||
* Sort wallpapers by filename (alphabetically)
|
||||
* @param wallpapers List of wallpapers to sort
|
||||
* @param ascending True for A-Z, false for Z-A
|
||||
* @return New sorted list preserving original list
|
||||
*/
|
||||
fun sortWallpapersByName(
|
||||
wallpapers: List<Wallpaper>,
|
||||
ascending: Boolean = true
|
||||
): List<Wallpaper> {
|
||||
return if (ascending) {
|
||||
wallpapers.sortedBy { it.fileName.lowercase() }
|
||||
} else {
|
||||
wallpapers.sortedByDescending { it.fileName.lowercase() }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort wallpapers by date added (addedAt timestamp)
|
||||
* @param wallpapers List of wallpapers to sort
|
||||
* @param ascending True for oldest first, false for newest first
|
||||
* @return New sorted list preserving original list
|
||||
*/
|
||||
fun sortWallpapersByDateAdded(
|
||||
wallpapers: List<Wallpaper>,
|
||||
ascending: Boolean = true
|
||||
): List<Wallpaper> {
|
||||
return if (ascending) {
|
||||
wallpapers.sortedBy { it.addedAt }
|
||||
} else {
|
||||
wallpapers.sortedByDescending { it.addedAt }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort wallpapers by date modified (dateModified timestamp)
|
||||
* @param wallpapers List of wallpapers to sort
|
||||
* @param ascending True for oldest first, false for newest first
|
||||
* @return New sorted list preserving original list
|
||||
*/
|
||||
fun sortWallpapersByDateModified(
|
||||
wallpapers: List<Wallpaper>,
|
||||
ascending: Boolean = true
|
||||
): List<Wallpaper> {
|
||||
return if (ascending) {
|
||||
wallpapers.sortedBy { it.dateModified }
|
||||
} else {
|
||||
wallpapers.sortedByDescending { it.dateModified }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort folders by name (alphabetically)
|
||||
*/
|
||||
fun sortFoldersByName(
|
||||
folders: List<Folder>,
|
||||
ascending: Boolean = true
|
||||
): List<Folder> {
|
||||
return if (ascending) {
|
||||
folders.sortedBy { it.name.lowercase() }
|
||||
} else {
|
||||
folders.sortedByDescending { it.name.lowercase() }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort folders by date modified
|
||||
*/
|
||||
fun sortFoldersByDateModified(
|
||||
folders: List<Folder>,
|
||||
ascending: Boolean = true
|
||||
): List<Folder> {
|
||||
return if (ascending) {
|
||||
folders.sortedBy { it.dateModified }
|
||||
} else {
|
||||
folders.sortedByDescending { it.dateModified }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift a wallpaper within a list (drag and drop)
|
||||
* @param wallpapers Current list of wallpapers
|
||||
* @param fromUri URI of the wallpaper being moved
|
||||
* @param toUri URI of the target position
|
||||
* @return New list with wallpaper moved and display orders updated
|
||||
*/
|
||||
fun shiftWallpaper(
|
||||
wallpapers: List<Wallpaper>,
|
||||
fromUri: String,
|
||||
toUri: String
|
||||
): List<Wallpaper> {
|
||||
val mutableList = wallpapers.toMutableList()
|
||||
val fromIndex = mutableList.indexOfFirst { it.uri == fromUri }
|
||||
val toIndex = mutableList.indexOfFirst { it.uri == toUri }
|
||||
|
||||
if (fromIndex == -1 || toIndex == -1) return wallpapers
|
||||
|
||||
val movedItem = mutableList.removeAt(fromIndex)
|
||||
mutableList.add(toIndex, movedItem)
|
||||
|
||||
return applyDisplayOrder(mutableList)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift a folder within a list (drag and drop)
|
||||
* @param folders Current list of folders
|
||||
* @param fromUri URI of the folder being moved
|
||||
* @param toUri URI of the target position
|
||||
* @return New list with folder moved and display orders updated
|
||||
*/
|
||||
fun shiftFolder(
|
||||
folders: List<Folder>,
|
||||
fromUri: String,
|
||||
toUri: String
|
||||
): List<Folder> {
|
||||
val mutableList = folders.toMutableList()
|
||||
val fromIndex = mutableList.indexOfFirst { it.uri == fromUri }
|
||||
val toIndex = mutableList.indexOfFirst { it.uri == toUri }
|
||||
|
||||
if (fromIndex == -1 || toIndex == -1) return folders
|
||||
|
||||
val movedItem = mutableList.removeAt(fromIndex)
|
||||
mutableList.add(toIndex, movedItem)
|
||||
|
||||
return applyFolderDisplayOrder(mutableList)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift a wallpaper within a folder's wallpaper list
|
||||
* @param folders List of all folders
|
||||
* @param folderId ID of the folder containing the wallpaper
|
||||
* @param fromUri URI of the wallpaper being moved
|
||||
* @param toUri URI of the target position
|
||||
* @return Pair of updated folders list and the new cover URI for the folder
|
||||
*/
|
||||
fun shiftWallpaperInFolder(
|
||||
folders: List<Folder>,
|
||||
folderId: String,
|
||||
fromUri: String,
|
||||
toUri: String
|
||||
): List<Folder> {
|
||||
return folders.map { folder ->
|
||||
if (folder.id == folderId) {
|
||||
val updatedWallpapers = shiftWallpaper(folder.wallpapers, fromUri, toUri)
|
||||
folder.copy(
|
||||
wallpapers = updatedWallpapers,
|
||||
coverUri = updatedWallpapers.firstOrNull()?.uri ?: folder.coverUri
|
||||
)
|
||||
} else {
|
||||
folder
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort all folders and wallpapers alphabetically
|
||||
*/
|
||||
fun sortAllAlphabetically(
|
||||
folders: List<Folder>,
|
||||
wallpapers: List<Wallpaper>,
|
||||
ascending: Boolean = true
|
||||
): Pair<List<Folder>, List<Wallpaper>> {
|
||||
val sortedFolders = folders.map { folder ->
|
||||
val sortedWallpapers = sortWallpapersByName(folder.wallpapers, ascending)
|
||||
folder.copy(wallpapers = applyDisplayOrder(sortedWallpapers))
|
||||
}
|
||||
|
||||
val finalFolders = if (ascending) {
|
||||
sortedFolders.sortedBy { it.name.lowercase() }
|
||||
} else {
|
||||
sortedFolders.sortedByDescending { it.name.lowercase() }
|
||||
}
|
||||
|
||||
val finalWallpapers = sortWallpapersByName(wallpapers, ascending)
|
||||
|
||||
return Pair(
|
||||
applyFolderDisplayOrder(finalFolders),
|
||||
applyDisplayOrder(finalWallpapers)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort all folders and wallpapers by date modified
|
||||
*/
|
||||
fun sortAllByDateModified(
|
||||
folders: List<Folder>,
|
||||
wallpapers: List<Wallpaper>,
|
||||
ascending: Boolean = true
|
||||
): Pair<List<Folder>, List<Wallpaper>> {
|
||||
val sortedFolders = folders.map { folder ->
|
||||
val sortedWallpapers = sortWallpapersByDateModified(folder.wallpapers, ascending)
|
||||
folder.copy(wallpapers = applyDisplayOrder(sortedWallpapers))
|
||||
}
|
||||
|
||||
val finalFolders = if (ascending) {
|
||||
sortedFolders.sortedBy { it.dateModified }
|
||||
} else {
|
||||
sortedFolders.sortedByDescending { it.dateModified }
|
||||
}
|
||||
|
||||
val finalWallpapers = sortWallpapersByDateModified(wallpapers, ascending)
|
||||
|
||||
return Pair(
|
||||
applyFolderDisplayOrder(finalFolders),
|
||||
applyDisplayOrder(finalWallpapers)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply displayOrder indices to sorted wallpapers
|
||||
* @param wallpapers Sorted list of wallpapers
|
||||
* @return New list with displayOrder updated to match list position
|
||||
*/
|
||||
fun applyDisplayOrder(wallpapers: List<Wallpaper>): List<Wallpaper> {
|
||||
return wallpapers.mapIndexed { index, wallpaper ->
|
||||
wallpaper.copy(displayOrder = index)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply displayOrder indices to sorted folders
|
||||
* @param folders Sorted list of folders
|
||||
* @return New list with folder moved and display orders updated
|
||||
*/
|
||||
fun applyFolderDisplayOrder(folders: List<Folder>): List<Folder> {
|
||||
return folders.mapIndexed { index, folder ->
|
||||
folder.copy(displayOrder = index)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,638 @@
|
||||
package com.anthonyla.paperize.core.util
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
|
||||
import android.app.WallpaperManager
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
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.HardwareRenderer
|
||||
import android.graphics.ImageDecoder
|
||||
import android.graphics.Matrix
|
||||
import android.graphics.Paint
|
||||
import android.graphics.PixelFormat
|
||||
import android.graphics.RadialGradient
|
||||
import android.graphics.RenderEffect
|
||||
import android.graphics.RenderNode
|
||||
import android.graphics.Shader
|
||||
import android.hardware.HardwareBuffer
|
||||
import android.media.ImageReader
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import android.util.Size
|
||||
import android.view.WindowManager
|
||||
import android.view.WindowMetrics
|
||||
import androidx.compose.ui.util.fastRoundToInt
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import com.anthonyla.paperize.core.ScalingType
|
||||
import com.anthonyla.paperize.core.WallpaperMediaType
|
||||
|
||||
/**
|
||||
* Wallpaper utility functions for bitmap processing and effects
|
||||
*
|
||||
* Improvements:
|
||||
* - Added EXIF orientation handling
|
||||
* - API-safe blur with fallback for Android < S
|
||||
* - Memory management with bitmap recycling
|
||||
* - Effect enable flags respected
|
||||
* - Quality optimization options
|
||||
*/
|
||||
|
||||
private const val TAG = "WallpaperUtil"
|
||||
|
||||
/**
|
||||
* Get the dimensions of the image from the URI
|
||||
*/
|
||||
fun Uri.getImageDimensions(context: Context): Size? {
|
||||
// Try EXIF first
|
||||
try {
|
||||
context.contentResolver.openInputStream(this)?.use { inputStream ->
|
||||
val exif = ExifInterface(inputStream)
|
||||
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)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Error reading EXIF dimensions for $this, falling back: $e")
|
||||
}
|
||||
|
||||
// Fallback to BitmapFactory
|
||||
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(TAG, "Error getting image dimensions with BitmapFactory for $this: $e")
|
||||
return null
|
||||
}
|
||||
|
||||
Log.w(TAG, "Could not get image dimensions for $this")
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get EXIF orientation from URI
|
||||
*/
|
||||
fun Uri.getExifOrientation(context: Context): Int {
|
||||
return try {
|
||||
context.contentResolver.openInputStream(this)?.use { inputStream ->
|
||||
val exif = ExifInterface(inputStream)
|
||||
exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)
|
||||
} ?: ExifInterface.ORIENTATION_UNDEFINED
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Error reading EXIF orientation: $e")
|
||||
ExifInterface.ORIENTATION_UNDEFINED
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create transformation matrix for EXIF orientation
|
||||
*/
|
||||
fun getExifTransformationMatrix(orientation: Int, width: Int, height: Int): Matrix {
|
||||
val matrix = Matrix()
|
||||
|
||||
when (orientation) {
|
||||
ExifInterface.ORIENTATION_FLIP_HORIZONTAL -> {
|
||||
matrix.setScale(-1f, 1f)
|
||||
matrix.postTranslate(width.toFloat(), 0f)
|
||||
}
|
||||
ExifInterface.ORIENTATION_ROTATE_180 -> {
|
||||
matrix.setRotate(180f)
|
||||
matrix.postTranslate(width.toFloat(), height.toFloat())
|
||||
}
|
||||
ExifInterface.ORIENTATION_FLIP_VERTICAL -> {
|
||||
matrix.setScale(1f, -1f)
|
||||
matrix.postTranslate(0f, height.toFloat())
|
||||
}
|
||||
ExifInterface.ORIENTATION_TRANSPOSE -> {
|
||||
matrix.setRotate(90f)
|
||||
matrix.postScale(-1f, 1f)
|
||||
}
|
||||
ExifInterface.ORIENTATION_ROTATE_90 -> {
|
||||
matrix.setRotate(90f)
|
||||
matrix.postTranslate(height.toFloat(), 0f)
|
||||
}
|
||||
ExifInterface.ORIENTATION_TRANSVERSE -> {
|
||||
matrix.setRotate(-90f)
|
||||
matrix.postScale(-1f, 1f)
|
||||
}
|
||||
ExifInterface.ORIENTATION_ROTATE_270 -> {
|
||||
matrix.setRotate(-90f)
|
||||
matrix.postTranslate(0f, width.toFloat())
|
||||
}
|
||||
}
|
||||
|
||||
return matrix
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the inSampleSize for the image
|
||||
*/
|
||||
fun calculateInSampleSize(imageSize: Size, width: Int, height: Int): Int {
|
||||
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)
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
/**
|
||||
* Get device screen size without orientation
|
||||
*/
|
||||
object ScreenMetricsCompat {
|
||||
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 = ScreenMetricsCompat.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
|
||||
* Now with EXIF orientation support
|
||||
*/
|
||||
fun retrieveBitmap(
|
||||
context: Context,
|
||||
wallpaperUri: Uri,
|
||||
width: Int,
|
||||
height: Int,
|
||||
scaling: ScalingType = ScalingType.FIT
|
||||
): Bitmap? {
|
||||
val imageSize = wallpaperUri.getImageDimensions(context) ?: return null
|
||||
if (imageSize.width <= 0 || imageSize.height <= 0) {
|
||||
Log.e(TAG, "Invalid image dimensions from URI: $imageSize")
|
||||
return null
|
||||
}
|
||||
|
||||
val sampleSize = if (scaling == ScalingType.NONE) {
|
||||
1
|
||||
} else {
|
||||
calculateInSampleSize(imageSize, width, height)
|
||||
}
|
||||
|
||||
val bitmap = try {
|
||||
val source = ImageDecoder.createSource(context.contentResolver, wallpaperUri)
|
||||
ImageDecoder.decodeBitmap(source) { decoder, _, _ ->
|
||||
val (targetWidth, targetHeight) = when (scaling) {
|
||||
ScalingType.FILL -> {
|
||||
// Calculate scale to cover target dimensions
|
||||
val widthRatio = width.toFloat() / imageSize.width
|
||||
val heightRatio = height.toFloat() / imageSize.height
|
||||
val scale = maxOf(widthRatio, heightRatio)
|
||||
Pair((imageSize.width * scale).fastRoundToInt(), (imageSize.height * scale).fastRoundToInt())
|
||||
}
|
||||
ScalingType.FIT -> {
|
||||
// Calculate scale to fit inside target dimensions
|
||||
val widthRatio = width.toFloat() / imageSize.width
|
||||
val heightRatio = height.toFloat() / imageSize.height
|
||||
val scale = minOf(widthRatio, heightRatio)
|
||||
Pair((imageSize.width * scale).fastRoundToInt(), (imageSize.height * scale).fastRoundToInt())
|
||||
}
|
||||
ScalingType.STRETCH -> Pair(width, height)
|
||||
ScalingType.NONE -> Pair(imageSize.width, imageSize.height)
|
||||
}
|
||||
|
||||
decoder.setTargetSize(targetWidth, targetHeight)
|
||||
decoder.isMutableRequired = true
|
||||
// Use high quality when possible
|
||||
decoder.allocator = ImageDecoder.ALLOCATOR_SOFTWARE
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "ImageDecoder failed, falling back to BitmapFactory: $e")
|
||||
context.contentResolver.openInputStream(wallpaperUri)?.use { inputStream ->
|
||||
val options = BitmapFactory.Options().apply {
|
||||
inSampleSize = sampleSize
|
||||
inMutable = true
|
||||
inPreferredConfig = Bitmap.Config.ARGB_8888
|
||||
}
|
||||
BitmapFactory.decodeStream(inputStream, null, options)
|
||||
}
|
||||
} catch (e: OutOfMemoryError) {
|
||||
Log.e(TAG, "OOM during retrieveBitmap for $wallpaperUri: $e")
|
||||
null
|
||||
}
|
||||
|
||||
// Handle EXIF orientation
|
||||
return bitmap?.let { applyExifOrientation(it, wallpaperUri, context) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply EXIF orientation to bitmap
|
||||
*/
|
||||
private fun applyExifOrientation(source: Bitmap, uri: Uri, context: Context): Bitmap {
|
||||
val orientation = uri.getExifOrientation(context)
|
||||
if (orientation == ExifInterface.ORIENTATION_UNDEFINED || orientation == ExifInterface.ORIENTATION_NORMAL) {
|
||||
return source
|
||||
}
|
||||
|
||||
return try {
|
||||
val matrix = getExifTransformationMatrix(orientation, source.width, source.height)
|
||||
val rotated = Bitmap.createBitmap(source, 0, 0, source.width, source.height, matrix, true)
|
||||
if (rotated != source) {
|
||||
source.recycle() // Recycle old bitmap to free memory
|
||||
}
|
||||
rotated
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error applying EXIF orientation: $e")
|
||||
source
|
||||
} catch (e: OutOfMemoryError) {
|
||||
Log.e(TAG, "OOM applying EXIF orientation: $e")
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Darken the bitmap by a certain percentage
|
||||
* @param darkenPercent 0-100 (0 is original brightness, 100 is completely dark/black)
|
||||
*/
|
||||
fun darkenBitmap(source: Bitmap, darkenPercent: Int): Bitmap {
|
||||
if (!source.isMutable) {
|
||||
Log.w(TAG, "darkenBitmap received an immutable bitmap. Creating a mutable copy.")
|
||||
val mutableCopy = source.copy(source.config ?: Bitmap.Config.ARGB_8888, true)
|
||||
source.recycle()
|
||||
return darkenBitmap(mutableCopy, darkenPercent)
|
||||
}
|
||||
|
||||
// Convert darkenPercent to brightness factor (invert)
|
||||
val targetBrightnessFactor = (100 - darkenPercent.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 using GPU acceleration
|
||||
* @param percent 0-100
|
||||
*/
|
||||
fun blurBitmapHardware(source: Bitmap, percent: Int): Bitmap {
|
||||
val clampedPercent = percent.coerceIn(0, 100)
|
||||
if (clampedPercent == 0) {
|
||||
return source
|
||||
}
|
||||
|
||||
val maxBlurRadius = Constants.MAX_BLUR_RADIUS
|
||||
val radius = (clampedPercent / 100.0f) * maxBlurRadius
|
||||
|
||||
val imageReader = ImageReader.newInstance(
|
||||
source.width, source.height,
|
||||
PixelFormat.RGBA_8888, 1,
|
||||
HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE or HardwareBuffer.USAGE_GPU_COLOR_OUTPUT
|
||||
)
|
||||
|
||||
val renderNode = RenderNode("BlurEffect")
|
||||
val hardwareRenderer = HardwareRenderer()
|
||||
|
||||
var resultBitmap: Bitmap?
|
||||
try {
|
||||
hardwareRenderer.setSurface(imageReader.surface)
|
||||
hardwareRenderer.setContentRoot(renderNode)
|
||||
renderNode.setPosition(0, 0, source.width, source.height)
|
||||
|
||||
val blurEffect = RenderEffect.createBlurEffect(radius, radius, Shader.TileMode.MIRROR)
|
||||
renderNode.setRenderEffect(blurEffect)
|
||||
|
||||
val canvas = renderNode.beginRecording()
|
||||
canvas.drawBitmap(source, 0f, 0f, null)
|
||||
renderNode.endRecording()
|
||||
|
||||
hardwareRenderer.createRenderRequest()
|
||||
.setWaitForPresent(true)
|
||||
.syncAndDraw()
|
||||
|
||||
val image = imageReader.acquireNextImage()
|
||||
?: throw IllegalStateException("Failed to acquire blurred image")
|
||||
|
||||
val hardwareBuffer = image.hardwareBuffer
|
||||
?: throw IllegalStateException("Failed to acquire hardware buffer")
|
||||
|
||||
val hardwareBitmap = Bitmap.wrapHardwareBuffer(hardwareBuffer, null)
|
||||
?: throw IllegalStateException("Failed to create bitmap from hardware buffer")
|
||||
|
||||
// Convert hardware bitmap to regular bitmap for further processing
|
||||
// Use mutable=true to allow subsequent effects to modify in-place
|
||||
resultBitmap = hardwareBitmap.copy(Bitmap.Config.ARGB_8888, true)
|
||||
?: throw IllegalStateException("Failed to copy hardware bitmap to software bitmap")
|
||||
|
||||
hardwareBitmap.recycle()
|
||||
hardwareBuffer.close()
|
||||
image.close()
|
||||
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error blurring bitmap: $e")
|
||||
return source
|
||||
} catch (e: OutOfMemoryError) {
|
||||
Log.e(TAG, "OOM blurring bitmap: $e")
|
||||
return source
|
||||
} finally {
|
||||
hardwareRenderer.destroy()
|
||||
renderNode.discardDisplayList()
|
||||
imageReader.close()
|
||||
}
|
||||
|
||||
return resultBitmap
|
||||
}
|
||||
|
||||
/**
|
||||
* Blur bitmap using GPU acceleration
|
||||
*/
|
||||
fun blurBitmap(source: Bitmap, percent: Int): Bitmap {
|
||||
return blurBitmapHardware(source, percent)
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a vignette effect to the bitmap
|
||||
* @param percent 0-100
|
||||
*/
|
||||
fun vignetteBitmap(source: Bitmap, percent: Int): Bitmap {
|
||||
if (percent <= 0) return source
|
||||
if (!source.isMutable) {
|
||||
Log.w(TAG, "vignetteBitmap received an immutable bitmap. Creating a mutable copy.")
|
||||
val mutableCopy = source.copy(source.config ?: Bitmap.Config.ARGB_8888, true)
|
||||
source.recycle()
|
||||
return vignetteBitmap(mutableCopy, percent)
|
||||
}
|
||||
|
||||
return 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) / Constants.VIGNETTE_DIVISOR))).coerceAtLeast(Constants.VIGNETTE_MIN_RADIUS)
|
||||
val centerX = source.width / 2f
|
||||
val centerY = source.height / 2f
|
||||
|
||||
val colors = intArrayOf(
|
||||
Color.TRANSPARENT,
|
||||
Color.argb((Constants.VIGNETTE_INNER_ALPHA * 255).toInt(), 0, 0, 0),
|
||||
Color.argb((Constants.VIGNETTE_OUTER_ALPHA * 255).toInt(), 0, 0, 0)
|
||||
)
|
||||
val pos = Constants.VIGNETTE_GRADIENT_POSITIONS
|
||||
|
||||
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)
|
||||
source
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error applying vignette: $e")
|
||||
source
|
||||
} catch (e: OutOfMemoryError) {
|
||||
Log.e(TAG, "OOM applying vignette: $e")
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a grayscale filter to the bitmap
|
||||
* @param percent 0-100 (0 is original, 100 is full grayscale)
|
||||
*/
|
||||
fun grayscaleBitmap(source: Bitmap, percent: Int): Bitmap {
|
||||
if (percent <= 0) return source
|
||||
if (!source.isMutable) {
|
||||
Log.w(TAG, "grayscaleBitmap received an immutable bitmap. Creating a mutable copy.")
|
||||
val mutableCopy = source.copy(source.config ?: Bitmap.Config.ARGB_8888, true)
|
||||
source.recycle()
|
||||
return grayscaleBitmap(mutableCopy, percent)
|
||||
}
|
||||
|
||||
val factor = percent.coerceIn(0, 100) / 100f
|
||||
if (factor <= 0f) return source
|
||||
|
||||
val colorMatrix = ColorMatrix().apply { setSaturation(1 - factor) }
|
||||
val paint = Paint().apply { colorFilter = ColorMatrixColorFilter(colorMatrix) }
|
||||
|
||||
Canvas(source).drawBitmap(source, 0f, 0f, paint)
|
||||
return source
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate brightness estimate of bitmap (0.0 - 1.0)
|
||||
* Uses luminance calculation based on RGB values
|
||||
*/
|
||||
fun calculateBitmapBrightness(bitmap: Bitmap): Float {
|
||||
return BrightnessCalculator.calculateBitmapBrightness(bitmap)
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust bitmap brightness by a multiplier
|
||||
* @param brightnessFactor Brightness multiplier (e.g., 0.7 to darken, 1.5 to brighten)
|
||||
*/
|
||||
fun adjustBitmapBrightness(source: Bitmap, brightnessFactor: Float): Bitmap {
|
||||
if (brightnessFactor == 1.0f) return source
|
||||
if (!source.isMutable) {
|
||||
Log.w(TAG, "adjustBitmapBrightness received an immutable bitmap. Returning a copy.")
|
||||
val mutableCopy = source.copy(source.config ?: Bitmap.Config.ARGB_8888, true)
|
||||
source.recycle() // Recycle source to prevent memory leak
|
||||
return adjustBitmapBrightness(mutableCopy, brightnessFactor)
|
||||
}
|
||||
|
||||
val paint = Paint().apply {
|
||||
colorFilter = ColorMatrixColorFilter(ColorMatrix().apply {
|
||||
setScale(brightnessFactor, brightnessFactor, brightnessFactor, 1f)
|
||||
})
|
||||
}
|
||||
Canvas(source).drawBitmap(source, 0f, 0f, paint)
|
||||
return source
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get adaptive brightness multiplier factor based on system dark/light mode
|
||||
*
|
||||
* @param context Application context
|
||||
* @param brightness Current image brightness (0.0 to 1.0)
|
||||
* @return Multiplier factor to apply to colors
|
||||
*/
|
||||
fun getAdaptiveBrightnessMultiplier(context: Context, brightness: Float): Float {
|
||||
val isDarkMode = (context.resources.configuration.uiMode and
|
||||
Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
|
||||
|
||||
return BrightnessCalculator.getAdaptiveMultiplier(isDarkMode, brightness)
|
||||
}
|
||||
|
||||
fun adaptiveBrightnessAdjustment(context: Context, source: Bitmap): Bitmap {
|
||||
val isDarkMode = (context.resources.configuration.uiMode and
|
||||
Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
|
||||
|
||||
val currentBrightness = BrightnessCalculator.calculateBitmapBrightness(source)
|
||||
val adjustmentFactor = BrightnessCalculator.getAdaptiveMultiplier(isDarkMode, currentBrightness)
|
||||
|
||||
return if (adjustmentFactor != 1.0f) {
|
||||
Log.d(TAG, "Adaptive brightness adjustment factor: $adjustmentFactor (brightness: $currentBrightness, dark mode: $isDarkMode)")
|
||||
adjustBitmapBrightness(source, adjustmentFactor)
|
||||
} else {
|
||||
Log.d(TAG, "No adaptive brightness adjustment needed (brightness: $currentBrightness, dark mode: $isDarkMode)")
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process bitmap with all effects - now respects enable flags
|
||||
* Properly manages bitmap lifecycle by recycling intermediate results
|
||||
*/
|
||||
fun processBitmap(
|
||||
source: Bitmap,
|
||||
enableDarken: Boolean = false,
|
||||
darkenPercent: Int = 0,
|
||||
enableBlur: Boolean = false,
|
||||
blurPercent: Int = 0,
|
||||
enableVignette: Boolean = false,
|
||||
vignettePercent: Int = 0,
|
||||
enableGrayscale: Boolean = false,
|
||||
grayscalePercent: Int = 0
|
||||
): Bitmap {
|
||||
var result = source
|
||||
|
||||
// Apply effects in order, respecting enable flags
|
||||
// Recycle intermediate bitmaps to prevent memory leaks
|
||||
|
||||
// Darken modifies in-place for mutable bitmaps, no need to track previous
|
||||
if (enableDarken && darkenPercent > 0) {
|
||||
result = darkenBitmap(result, darkenPercent)
|
||||
}
|
||||
|
||||
// Blur always creates a new bitmap
|
||||
if (enableBlur && blurPercent > 0) {
|
||||
val previous = result
|
||||
result = blurBitmap(result, blurPercent)
|
||||
// Recycle the previous one if different from source
|
||||
if (result !== previous && previous !== source) {
|
||||
previous.recycle()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (enableVignette && vignettePercent > 0) {
|
||||
val previous = result
|
||||
result = vignetteBitmap(result, vignettePercent)
|
||||
// Vignette modifies in-place for mutable bitmaps, may create copy for immutable
|
||||
if (result !== previous && previous !== source) {
|
||||
previous.recycle()
|
||||
}
|
||||
}
|
||||
|
||||
if (enableGrayscale && grayscalePercent > 0) {
|
||||
val previous = result
|
||||
result = grayscaleBitmap(result, grayscalePercent)
|
||||
// Grayscale modifies in-place for mutable bitmaps, may create copy for immutable
|
||||
if (result !== previous && previous !== source) {
|
||||
previous.recycle()
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect media type from URI
|
||||
*
|
||||
* Examines the file extension and MIME type to determine the media type.
|
||||
* Returns null if the media type cannot be determined or is unsupported.
|
||||
*/
|
||||
fun Uri.detectMediaType(context: Context): WallpaperMediaType? {
|
||||
try {
|
||||
// First try to get file extension from path
|
||||
val path = this.path
|
||||
if (path != null) {
|
||||
val extension = path.substringAfterLast('.', "")
|
||||
if (extension.isNotEmpty()) {
|
||||
val mediaType = WallpaperMediaType.fromExtension(extension)
|
||||
if (mediaType != null) {
|
||||
return mediaType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: Try to get MIME type from content resolver
|
||||
val mimeType = context.contentResolver.getType(this)
|
||||
if (mimeType != null) {
|
||||
return when {
|
||||
mimeType.startsWith("image/") -> WallpaperMediaType.IMAGE
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
// If all else fails, assume IMAGE for backward compatibility
|
||||
return WallpaperMediaType.IMAGE
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error detecting media type for URI: $this", e)
|
||||
return WallpaperMediaType.IMAGE // Default to IMAGE on error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Paperize live wallpaper is currently active/selected
|
||||
* Returns true if the Paperize live wallpaper service is the current wallpaper
|
||||
*/
|
||||
fun isPaperizeLiveWallpaperActive(context: Context): Boolean {
|
||||
return try {
|
||||
// If we are checking from within the service itself (e.g. preview mode), we are active
|
||||
if (context is com.anthonyla.paperize.service.livewallpaper.PaperizeLiveWallpaperService) {
|
||||
Log.d(TAG, "isPaperizeLiveWallpaperActive: called from service context, returning true")
|
||||
return true
|
||||
}
|
||||
|
||||
val wallpaperManager = WallpaperManager.getInstance(context)
|
||||
val wallpaperInfo = wallpaperManager.wallpaperInfo
|
||||
|
||||
// If wallpaperInfo is null, user has a static wallpaper (not a live wallpaper)
|
||||
if (wallpaperInfo == null) {
|
||||
Log.d(TAG, "isPaperizeLiveWallpaperActive: wallpaperInfo is null (static wallpaper), returning false")
|
||||
return false
|
||||
}
|
||||
|
||||
// Check if the service component matches Paperize live wallpaper
|
||||
val expectedComponent = android.content.ComponentName(
|
||||
context.packageName,
|
||||
"com.anthonyla.paperize.service.livewallpaper.PaperizeLiveWallpaperService"
|
||||
)
|
||||
val isPaperize = wallpaperInfo.component == expectedComponent
|
||||
|
||||
Log.d(TAG, "isPaperizeLiveWallpaperActive: current=${wallpaperInfo.component}, expected=$expectedComponent, match=$isPaperize")
|
||||
isPaperize
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error checking live wallpaper status", e)
|
||||
false
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
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) {
|
||||
val authorEmail = "anthonyyla.dev@gmail.com"
|
||||
val cc = ""
|
||||
val subject = "[Support] Paperize"
|
||||
val bodyText = "This is regarding the Paperize app for Android:\n"
|
||||
val mailto = "mailto:" + Uri.encode(authorEmail) +
|
||||
"?cc=" + Uri.encode(cc) +
|
||||
"&subject=" + Uri.encode(subject) +
|
||||
"&body=" + Uri.encode(bodyText)
|
||||
|
||||
val emailIntent = Intent(Intent.ACTION_SENDTO)
|
||||
emailIntent.setData(Uri.parse(mailto))
|
||||
startActivity(context, emailIntent, null)
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.anthonyla.paperize.data.database
|
||||
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import com.anthonyla.paperize.data.database.converters.TypeConverters as PaperizeTypeConverters
|
||||
import com.anthonyla.paperize.data.database.dao.AlbumDao
|
||||
import com.anthonyla.paperize.data.database.dao.FolderDao
|
||||
import com.anthonyla.paperize.data.database.dao.WallpaperDao
|
||||
import com.anthonyla.paperize.data.database.dao.WallpaperQueueDao
|
||||
import com.anthonyla.paperize.data.database.entities.AlbumEntity
|
||||
import com.anthonyla.paperize.data.database.entities.FolderEntity
|
||||
import com.anthonyla.paperize.data.database.entities.WallpaperEntity
|
||||
import com.anthonyla.paperize.data.database.entities.WallpaperQueueEntity
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
|
||||
/**
|
||||
* Paperize Room Database
|
||||
*
|
||||
* **MAJOR ARCHITECTURAL IMPROVEMENT:**
|
||||
* - Properly normalized schema (no nested collections in entities)
|
||||
* - NO CursorWindow reflection hack needed!
|
||||
* - Proper foreign keys with cascade delete
|
||||
* - Indexed columns for performance
|
||||
* - Separate queue management table
|
||||
* - Room migrations support (no destructive migrations!)
|
||||
*
|
||||
* Version: 1
|
||||
*/
|
||||
@Database(
|
||||
entities = [
|
||||
AlbumEntity::class,
|
||||
WallpaperEntity::class,
|
||||
FolderEntity::class,
|
||||
WallpaperQueueEntity::class
|
||||
],
|
||||
version = Constants.DATABASE_VERSION,
|
||||
exportSchema = true
|
||||
)
|
||||
@TypeConverters(PaperizeTypeConverters::class)
|
||||
abstract class PaperizeDatabase : RoomDatabase() {
|
||||
abstract fun albumDao(): AlbumDao
|
||||
abstract fun wallpaperDao(): WallpaperDao
|
||||
abstract fun folderDao(): FolderDao
|
||||
abstract fun wallpaperQueueDao(): WallpaperQueueDao
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.anthonyla.paperize.data.database.converters
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.anthonyla.paperize.core.ScreenType
|
||||
import com.anthonyla.paperize.core.ScalingType
|
||||
import com.anthonyla.paperize.core.WallpaperMediaType
|
||||
import com.anthonyla.paperize.core.WallpaperSourceType
|
||||
|
||||
/**
|
||||
* Room type converters for enum types
|
||||
*/
|
||||
class TypeConverters {
|
||||
@TypeConverter
|
||||
fun fromScreenType(value: ScreenType): String = value.name
|
||||
|
||||
@TypeConverter
|
||||
fun toScreenType(value: String): ScreenType = ScreenType.fromString(value)
|
||||
|
||||
@TypeConverter
|
||||
fun fromScalingType(value: ScalingType): String = value.name
|
||||
|
||||
@TypeConverter
|
||||
fun toScalingType(value: String): ScalingType = ScalingType.fromString(value)
|
||||
|
||||
@TypeConverter
|
||||
fun fromWallpaperSourceType(value: WallpaperSourceType): String = value.name
|
||||
|
||||
@TypeConverter
|
||||
fun toWallpaperSourceType(value: String): WallpaperSourceType =
|
||||
WallpaperSourceType.entries.find { it.name == value } ?: WallpaperSourceType.DIRECT
|
||||
|
||||
@TypeConverter
|
||||
fun fromWallpaperMediaType(value: WallpaperMediaType): String = value.name
|
||||
|
||||
@TypeConverter
|
||||
fun toWallpaperMediaType(value: String): WallpaperMediaType =
|
||||
WallpaperMediaType.fromString(value) ?: WallpaperMediaType.IMAGE
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.anthonyla.paperize.data.database.dao
|
||||
|
||||
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.data.database.entities.AlbumEntity
|
||||
import com.anthonyla.paperize.data.database.entities.AlbumSummaryEntity
|
||||
import com.anthonyla.paperize.data.database.relations.AlbumWithDetails
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Data Access Object for Album operations
|
||||
*/
|
||||
@Dao
|
||||
interface AlbumDao {
|
||||
/**
|
||||
* Get all album summaries (lightweight metadata + counts)
|
||||
* Efficiently handles large libraries by avoiding loading all wallpaper objects
|
||||
*/
|
||||
@Query("""
|
||||
SELECT
|
||||
a.id,
|
||||
a.name,
|
||||
a.coverUri,
|
||||
a.createdAt,
|
||||
a.modifiedAt,
|
||||
(SELECT COUNT(*) FROM wallpapers w WHERE w.albumId = a.id) as wallpaperCount,
|
||||
(SELECT COUNT(*) FROM folders f WHERE f.albumId = a.id) as folderCount
|
||||
FROM albums a
|
||||
ORDER BY a.modifiedAt DESC
|
||||
""")
|
||||
fun getAlbumSummaries(): Flow<List<AlbumSummaryEntity>>
|
||||
|
||||
/**
|
||||
* Get all albums with their wallpapers and folders
|
||||
*/
|
||||
@Transaction
|
||||
@Query("SELECT * FROM albums ORDER BY modifiedAt DESC")
|
||||
fun getAllAlbumsWithDetails(): Flow<List<AlbumWithDetails>>
|
||||
|
||||
/**
|
||||
* Get a specific album by ID with details
|
||||
*/
|
||||
@Transaction
|
||||
@Query("SELECT * FROM albums WHERE id = :albumId")
|
||||
fun getAlbumWithDetails(albumId: String): Flow<AlbumWithDetails?>
|
||||
|
||||
/**
|
||||
* Get all albums (without relations)
|
||||
*/
|
||||
@Query("SELECT * FROM albums ORDER BY modifiedAt DESC")
|
||||
fun getAllAlbums(): Flow<List<AlbumEntity>>
|
||||
|
||||
/**
|
||||
* Get a specific album by ID
|
||||
*/
|
||||
@Query("SELECT * FROM albums WHERE id = :albumId")
|
||||
suspend fun getAlbumById(albumId: String): AlbumEntity?
|
||||
|
||||
/**
|
||||
* Get a specific album by name
|
||||
*/
|
||||
@Query("SELECT * FROM albums WHERE name = :name LIMIT 1")
|
||||
suspend fun getAlbumByName(name: String): AlbumEntity?
|
||||
|
||||
/**
|
||||
* Get album count
|
||||
*/
|
||||
@Query("SELECT COUNT(*) FROM albums")
|
||||
suspend fun getAlbumCount(): Int
|
||||
|
||||
/**
|
||||
* Insert album
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertAlbum(album: AlbumEntity)
|
||||
|
||||
/**
|
||||
* Update album
|
||||
*/
|
||||
@Update
|
||||
suspend fun updateAlbum(album: AlbumEntity)
|
||||
|
||||
/**
|
||||
* Delete album
|
||||
*/
|
||||
@Delete
|
||||
suspend fun deleteAlbum(album: AlbumEntity)
|
||||
|
||||
/**
|
||||
* Delete album by ID
|
||||
*/
|
||||
@Query("DELETE FROM albums WHERE id = :albumId")
|
||||
suspend fun deleteAlbumById(albumId: String)
|
||||
|
||||
/**
|
||||
* Update album name
|
||||
*/
|
||||
@Query("UPDATE albums SET name = :name, modifiedAt = :modifiedAt WHERE id = :albumId")
|
||||
suspend fun updateAlbumName(albumId: String, name: String, modifiedAt: Long)
|
||||
|
||||
/**
|
||||
* Update album cover
|
||||
*/
|
||||
@Query("UPDATE albums SET coverUri = :coverUri, modifiedAt = :modifiedAt WHERE id = :albumId")
|
||||
suspend fun updateAlbumCover(albumId: String, coverUri: String?, modifiedAt: Long)
|
||||
|
||||
/**
|
||||
* Update album modified time
|
||||
*/
|
||||
@Query("UPDATE albums SET modifiedAt = :modifiedAt WHERE id = :albumId")
|
||||
suspend fun updateAlbumModifiedTime(albumId: String, modifiedAt: Long)
|
||||
|
||||
/**
|
||||
* Delete all albums
|
||||
*/
|
||||
@Query("DELETE FROM albums")
|
||||
suspend fun deleteAllAlbums()
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.anthonyla.paperize.data.database.dao
|
||||
|
||||
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.data.database.entities.FolderEntity
|
||||
import com.anthonyla.paperize.data.database.relations.FolderWithWallpapers
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Data Access Object for Folder operations
|
||||
*/
|
||||
@Dao
|
||||
interface FolderDao {
|
||||
/**
|
||||
* Get all folders for an album with their wallpapers
|
||||
*/
|
||||
@Transaction
|
||||
@Query("SELECT * FROM folders WHERE albumId = :albumId ORDER BY displayOrder ASC")
|
||||
fun getFoldersWithWallpapersByAlbum(albumId: String): Flow<List<FolderWithWallpapers>>
|
||||
|
||||
/**
|
||||
* Get a specific folder by ID with wallpapers
|
||||
*/
|
||||
@Transaction
|
||||
@Query("SELECT * FROM folders WHERE id = :folderId")
|
||||
fun getFolderWithWallpapers(folderId: String): Flow<FolderWithWallpapers?>
|
||||
|
||||
/**
|
||||
* Get a specific folder by ID
|
||||
*/
|
||||
@Query("SELECT * FROM folders WHERE id = :folderId")
|
||||
suspend fun getFolderById(folderId: String): FolderEntity?
|
||||
|
||||
/**
|
||||
* Get folder by URI
|
||||
*/
|
||||
@Query("SELECT * FROM folders WHERE uri = :uri LIMIT 1")
|
||||
suspend fun getFolderByUri(uri: String): FolderEntity?
|
||||
|
||||
/**
|
||||
* Insert folder
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertFolder(folder: FolderEntity)
|
||||
|
||||
/**
|
||||
* Update folder
|
||||
*/
|
||||
@Update
|
||||
suspend fun updateFolder(folder: FolderEntity)
|
||||
|
||||
/**
|
||||
* Update folder cover
|
||||
*/
|
||||
@Query("UPDATE folders SET coverUri = :coverUri WHERE id = :folderId")
|
||||
suspend fun updateFolderCover(folderId: String, coverUri: String?)
|
||||
|
||||
/**
|
||||
* Delete folder by ID
|
||||
*/
|
||||
@Query("DELETE FROM folders WHERE id = :folderId")
|
||||
suspend fun deleteFolderById(folderId: String)
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.anthonyla.paperize.data.database.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import com.anthonyla.paperize.data.database.entities.WallpaperEntity
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Data Access Object for Wallpaper operations
|
||||
*/
|
||||
@Dao
|
||||
interface WallpaperDao {
|
||||
/**
|
||||
* Get all wallpapers for an album
|
||||
*/
|
||||
@Query("SELECT * FROM wallpapers WHERE albumId = :albumId ORDER BY displayOrder ASC")
|
||||
fun getWallpapersByAlbum(albumId: String): Flow<List<WallpaperEntity>>
|
||||
|
||||
/**
|
||||
* Get direct wallpapers for an album (not from folders)
|
||||
*/
|
||||
@Query("SELECT * FROM wallpapers WHERE albumId = :albumId AND folderId IS NULL ORDER BY displayOrder ASC")
|
||||
fun getDirectWallpapersByAlbum(albumId: String): Flow<List<WallpaperEntity>>
|
||||
|
||||
/**
|
||||
* Get all wallpapers for an album (synchronous for transactions)
|
||||
*/
|
||||
@Query("SELECT * FROM wallpapers WHERE albumId = :albumId ORDER BY displayOrder ASC")
|
||||
suspend fun getWallpapersByAlbumSync(albumId: String): List<WallpaperEntity>
|
||||
|
||||
/**
|
||||
* Get wallpapers for an album (paginated for memory-intensive operations)
|
||||
*/
|
||||
@Query("SELECT * FROM wallpapers WHERE albumId = :albumId ORDER BY displayOrder ASC LIMIT :limit OFFSET :offset")
|
||||
suspend fun getWallpapersByAlbumPaged(albumId: String, limit: Int, offset: Int): List<WallpaperEntity>
|
||||
|
||||
/**
|
||||
* Get direct wallpapers for an album (synchronous for transactions)
|
||||
*/
|
||||
@Query("SELECT * FROM wallpapers WHERE albumId = :albumId AND folderId IS NULL ORDER BY displayOrder ASC")
|
||||
suspend fun getDirectWallpapersByAlbumSync(albumId: String): List<WallpaperEntity>
|
||||
|
||||
/**
|
||||
* Get wallpapers for a folder
|
||||
*/
|
||||
@Query("SELECT * FROM wallpapers WHERE folderId = :folderId ORDER BY displayOrder ASC")
|
||||
fun getWallpapersByFolder(folderId: String): Flow<List<WallpaperEntity>>
|
||||
|
||||
/**
|
||||
* Get a specific wallpaper by ID
|
||||
*/
|
||||
@Query("SELECT * FROM wallpapers WHERE id = :wallpaperId")
|
||||
suspend fun getWallpaperById(wallpaperId: String): WallpaperEntity?
|
||||
|
||||
/**
|
||||
* Get wallpaper by URI
|
||||
*/
|
||||
@Query("SELECT * FROM wallpapers WHERE uri = :uri LIMIT 1")
|
||||
suspend fun getWallpaperByUri(uri: String): WallpaperEntity?
|
||||
|
||||
/**
|
||||
* Insert wallpaper
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertWallpaper(wallpaper: WallpaperEntity)
|
||||
|
||||
/**
|
||||
* Insert multiple wallpapers
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertWallpapers(wallpapers: List<WallpaperEntity>)
|
||||
|
||||
/**
|
||||
* Update wallpaper
|
||||
*/
|
||||
@Update
|
||||
suspend fun updateWallpaper(wallpaper: WallpaperEntity)
|
||||
|
||||
/**
|
||||
* Update wallpaper display order
|
||||
*/
|
||||
@Query("UPDATE wallpapers SET displayOrder = :order WHERE id = :wallpaperId")
|
||||
suspend fun updateWallpaperOrder(wallpaperId: String, order: Int)
|
||||
|
||||
/**
|
||||
* Delete wallpaper
|
||||
*/
|
||||
@Delete
|
||||
suspend fun deleteWallpaper(wallpaper: WallpaperEntity)
|
||||
|
||||
/**
|
||||
* Delete wallpaper by ID
|
||||
*/
|
||||
@Query("DELETE FROM wallpapers WHERE id = :wallpaperId")
|
||||
suspend fun deleteWallpaperById(wallpaperId: String)
|
||||
|
||||
/**
|
||||
* Delete wallpapers by IDs (batch operation)
|
||||
*/
|
||||
@Query("DELETE FROM wallpapers WHERE id IN (:wallpaperIds)")
|
||||
suspend fun deleteWallpapersByIds(wallpaperIds: List<String>)
|
||||
|
||||
/**
|
||||
* Delete all wallpapers for a folder
|
||||
*/
|
||||
@Query("DELETE FROM wallpapers WHERE folderId = :folderId")
|
||||
suspend fun deleteWallpapersByFolder(folderId: String)
|
||||
|
||||
/**
|
||||
* Delete wallpapers by URIs
|
||||
*/
|
||||
@Query("DELETE FROM wallpapers WHERE uri IN (:uris)")
|
||||
suspend fun deleteWallpapersByUris(uris: List<String>)
|
||||
|
||||
/**
|
||||
* Get total wallpaper count for an album
|
||||
*/
|
||||
@Query("SELECT COUNT(*) FROM wallpapers WHERE albumId = :albumId")
|
||||
suspend fun getWallpaperCountByAlbum(albumId: String): Int
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.anthonyla.paperize.data.database.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.Transaction
|
||||
import com.anthonyla.paperize.core.ScreenType
|
||||
import com.anthonyla.paperize.data.database.entities.WallpaperEntity
|
||||
import com.anthonyla.paperize.data.database.entities.WallpaperQueueEntity
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Data Access Object for Wallpaper Queue operations
|
||||
*
|
||||
* This replaces the manual queue management in the old Album entity
|
||||
*/
|
||||
@Dao
|
||||
interface WallpaperQueueDao {
|
||||
/**
|
||||
* Get next wallpaper in queue
|
||||
*/
|
||||
@Query("""
|
||||
SELECT w.* FROM wallpapers w
|
||||
INNER JOIN wallpaper_queue wq ON w.id = wq.wallpaperId
|
||||
WHERE wq.albumId = :albumId AND wq.screenType = :screenType
|
||||
ORDER BY wq.queuePosition ASC
|
||||
LIMIT 1
|
||||
""")
|
||||
suspend fun getNextWallpaperInQueue(albumId: String, screenType: ScreenType): WallpaperEntity?
|
||||
|
||||
/**
|
||||
* Atomically get and remove next wallpaper from queue
|
||||
* This prevents race conditions when multiple services try to get wallpapers simultaneously
|
||||
*/
|
||||
@Transaction
|
||||
suspend fun getAndDequeueWallpaper(albumId: String, screenType: ScreenType): WallpaperEntity? {
|
||||
val wallpaper = getNextWallpaperInQueue(albumId, screenType)
|
||||
if (wallpaper != null) {
|
||||
// Delete specifically the item we just retrieved to ensure atomicity
|
||||
deleteQueueItem(albumId, screenType, wallpaper.id)
|
||||
}
|
||||
return wallpaper
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queue items for album and screen type
|
||||
*/
|
||||
@Query("SELECT * FROM wallpaper_queue WHERE albumId = :albumId AND screenType = :screenType ORDER BY queuePosition ASC")
|
||||
suspend fun getQueueItems(albumId: String, screenType: ScreenType): List<WallpaperQueueEntity>
|
||||
|
||||
/**
|
||||
* Insert multiple queue items
|
||||
*/
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertQueueItems(items: List<WallpaperQueueEntity>)
|
||||
|
||||
@Query("""
|
||||
DELETE FROM wallpaper_queue
|
||||
WHERE albumId = :albumId AND screenType = :screenType
|
||||
AND wallpaperId = :wallpaperId
|
||||
AND queuePosition = (
|
||||
SELECT MIN(queuePosition)
|
||||
FROM wallpaper_queue
|
||||
WHERE albumId = :albumId AND screenType = :screenType
|
||||
)
|
||||
""")
|
||||
suspend fun deleteQueueItem(albumId: String, screenType: ScreenType, wallpaperId: String)
|
||||
|
||||
@Query("""
|
||||
DELETE FROM wallpaper_queue
|
||||
WHERE albumId = :albumId AND screenType = :screenType
|
||||
AND queuePosition = (
|
||||
SELECT MIN(queuePosition)
|
||||
FROM wallpaper_queue
|
||||
WHERE albumId = :albumId AND screenType = :screenType
|
||||
)
|
||||
""")
|
||||
suspend fun deleteFirstQueueItem(albumId: String, screenType: ScreenType)
|
||||
|
||||
/**
|
||||
* Normalize queue positions to be sequential starting from 0
|
||||
* This fixes gaps created by CASCADE deletes when wallpapers are removed
|
||||
* Called after every dequeue to ensure queue integrity
|
||||
*/
|
||||
@Transaction
|
||||
suspend fun normalizeQueuePositions(albumId: String, screenType: ScreenType) {
|
||||
val items = getQueueItems(albumId, screenType)
|
||||
if (items.isEmpty()) return
|
||||
|
||||
// Check if normalization is needed (positions should be 0, 1, 2, ...)
|
||||
val needsNormalization = items.any { it.queuePosition != items.indexOf(it) }
|
||||
if (!needsNormalization) return
|
||||
|
||||
// Rebuild queue with normalized positions
|
||||
clearQueue(albumId, screenType)
|
||||
val normalizedItems = items.mapIndexed { index, item ->
|
||||
item.copy(queuePosition = index)
|
||||
}
|
||||
insertQueueItems(normalizedItems)
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear queue for album and screen type
|
||||
*/
|
||||
@Query("DELETE FROM wallpaper_queue WHERE albumId = :albumId AND screenType = :screenType")
|
||||
suspend fun clearQueue(albumId: String, screenType: ScreenType)
|
||||
|
||||
/**
|
||||
* Clear all queues for an album
|
||||
*/
|
||||
@Query("DELETE FROM wallpaper_queue WHERE albumId = :albumId")
|
||||
suspend fun clearAllQueues(albumId: String)
|
||||
|
||||
/**
|
||||
* Delete all queue items
|
||||
*/
|
||||
@Query("DELETE FROM wallpaper_queue")
|
||||
suspend fun deleteAllQueueItems()
|
||||
|
||||
/**
|
||||
* Rebuild queue with wallpaper IDs
|
||||
*/
|
||||
@Transaction
|
||||
suspend fun rebuildQueue(
|
||||
albumId: String,
|
||||
screenType: ScreenType,
|
||||
wallpaperIds: List<String>
|
||||
) {
|
||||
clearQueue(albumId, screenType)
|
||||
val items = wallpaperIds.mapIndexed { index, wallpaperId ->
|
||||
WallpaperQueueEntity(
|
||||
albumId = albumId,
|
||||
wallpaperId = wallpaperId,
|
||||
screenType = screenType,
|
||||
queuePosition = index
|
||||
)
|
||||
}
|
||||
insertQueueItems(items)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.anthonyla.paperize.data.database.entities
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
/**
|
||||
* Room entity for Album
|
||||
*
|
||||
* Stores album metadata without nested collections to avoid CursorWindow issues
|
||||
*/
|
||||
@Entity(tableName = "albums")
|
||||
data class AlbumEntity(
|
||||
@PrimaryKey
|
||||
val id: String,
|
||||
val name: String,
|
||||
val coverUri: String?,
|
||||
val createdAt: Long = System.currentTimeMillis(),
|
||||
val modifiedAt: Long = System.currentTimeMillis()
|
||||
)
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.anthonyla.paperize.data.database.entities
|
||||
|
||||
/**
|
||||
* Entity for holding lightweight album summary query results
|
||||
*/
|
||||
data class AlbumSummaryEntity(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val coverUri: String?,
|
||||
val wallpaperCount: Int,
|
||||
val folderCount: Int,
|
||||
val createdAt: Long,
|
||||
val modifiedAt: Long
|
||||
)
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.anthonyla.paperize.data.database.entities
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
/**
|
||||
* Room entity for Folder
|
||||
*
|
||||
* No longer stores nested wallpapers - they're separate entities with foreign keys
|
||||
*/
|
||||
@Entity(
|
||||
tableName = "folders",
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = AlbumEntity::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["albumId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)
|
||||
],
|
||||
indices = [
|
||||
Index(value = ["albumId"]),
|
||||
Index(value = ["uri"])
|
||||
]
|
||||
)
|
||||
data class FolderEntity(
|
||||
@PrimaryKey
|
||||
val id: String,
|
||||
|
||||
@ColumnInfo(name = "albumId")
|
||||
val albumId: String,
|
||||
|
||||
val name: String,
|
||||
val uri: String,
|
||||
val coverUri: String?,
|
||||
val dateModified: Long,
|
||||
val displayOrder: Int = 0,
|
||||
val addedAt: Long = System.currentTimeMillis()
|
||||
)
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.anthonyla.paperize.data.database.entities
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
import com.anthonyla.paperize.core.WallpaperMediaType
|
||||
import com.anthonyla.paperize.core.WallpaperSourceType
|
||||
|
||||
/**
|
||||
* Room entity for Wallpaper
|
||||
*
|
||||
* Properly indexed foreign key to Album and optional foreign key to Folder
|
||||
*/
|
||||
@Entity(
|
||||
tableName = "wallpapers",
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = AlbumEntity::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["albumId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
),
|
||||
ForeignKey(
|
||||
entity = FolderEntity::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["folderId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)
|
||||
],
|
||||
indices = [
|
||||
Index(value = ["albumId"]),
|
||||
Index(value = ["folderId"]),
|
||||
Index(value = ["uri"])
|
||||
]
|
||||
)
|
||||
data class WallpaperEntity(
|
||||
@PrimaryKey
|
||||
val id: String,
|
||||
|
||||
@ColumnInfo(name = "albumId")
|
||||
val albumId: String,
|
||||
|
||||
@ColumnInfo(name = "folderId")
|
||||
val folderId: String? = null,
|
||||
|
||||
val uri: String,
|
||||
val fileName: String,
|
||||
val dateModified: Long,
|
||||
val displayOrder: Int = 0,
|
||||
val sourceType: WallpaperSourceType = WallpaperSourceType.DIRECT,
|
||||
val addedAt: Long = System.currentTimeMillis(),
|
||||
|
||||
/**
|
||||
* Media type (IMAGE)
|
||||
* Added in database version 2 for live wallpaper support
|
||||
*/
|
||||
val mediaType: WallpaperMediaType = WallpaperMediaType.IMAGE,
|
||||
|
||||
/**
|
||||
* Manual crop parameters for live wallpaper rendering
|
||||
* Added in database version 2
|
||||
*/
|
||||
val cropOffsetX: Float? = null,
|
||||
val cropOffsetY: Float? = null,
|
||||
val cropScale: Float? = null
|
||||
)
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.anthonyla.paperize.data.database.entities
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
import com.anthonyla.paperize.core.ScreenType
|
||||
|
||||
/**
|
||||
* Room entity for Wallpaper Queue
|
||||
*
|
||||
* Properly manages wallpaper queues instead of storing them as JSON lists in Album
|
||||
* Separate queues for HOME and LOCK screens
|
||||
*/
|
||||
@Entity(
|
||||
tableName = "wallpaper_queue",
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = AlbumEntity::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["albumId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
),
|
||||
ForeignKey(
|
||||
entity = WallpaperEntity::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["wallpaperId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)
|
||||
],
|
||||
indices = [
|
||||
Index(value = ["albumId", "screenType"]),
|
||||
Index(value = ["wallpaperId"]),
|
||||
Index(value = ["queuePosition"])
|
||||
]
|
||||
)
|
||||
data class WallpaperQueueEntity(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val id: Long = 0,
|
||||
|
||||
@ColumnInfo(name = "albumId")
|
||||
val albumId: String,
|
||||
|
||||
@ColumnInfo(name = "wallpaperId")
|
||||
val wallpaperId: String,
|
||||
|
||||
val screenType: ScreenType,
|
||||
val queuePosition: Int,
|
||||
val addedAt: Long = System.currentTimeMillis()
|
||||
)
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.anthonyla.paperize.data.database.relations
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Relation
|
||||
import com.anthonyla.paperize.data.database.entities.AlbumEntity
|
||||
import com.anthonyla.paperize.data.database.entities.FolderEntity
|
||||
import com.anthonyla.paperize.data.database.entities.WallpaperEntity
|
||||
|
||||
/**
|
||||
* Room relation combining Album with its Wallpapers and Folders
|
||||
*
|
||||
* This replaces the old AlbumWithWallpaperAndFolder but with proper foreign keys
|
||||
* No nested collections in entities - avoiding CursorWindow issues!
|
||||
*/
|
||||
data class AlbumWithDetails(
|
||||
@Embedded
|
||||
val album: AlbumEntity,
|
||||
|
||||
@Relation(
|
||||
parentColumn = "id",
|
||||
entityColumn = "albumId",
|
||||
entity = WallpaperEntity::class
|
||||
)
|
||||
val wallpapers: List<WallpaperEntity> = emptyList(),
|
||||
|
||||
@Relation(
|
||||
parentColumn = "id",
|
||||
entityColumn = "albumId",
|
||||
entity = FolderEntity::class
|
||||
)
|
||||
val folders: List<FolderEntity> = emptyList()
|
||||
) {
|
||||
/**
|
||||
* Get direct wallpapers (not from folders)
|
||||
*/
|
||||
val directWallpapers: List<WallpaperEntity>
|
||||
get() = wallpapers.filter { it.folderId == null }
|
||||
|
||||
/**
|
||||
* Get total count including folder wallpapers
|
||||
*/
|
||||
fun getTotalWallpaperCount(folderWallpapers: Map<String, Int>): Int {
|
||||
val directCount = directWallpapers.size
|
||||
val folderCount = folders.sumOf { folderWallpapers[it.id] ?: 0 }
|
||||
return directCount + folderCount
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.anthonyla.paperize.data.database.relations
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Relation
|
||||
import com.anthonyla.paperize.data.database.entities.FolderEntity
|
||||
import com.anthonyla.paperize.data.database.entities.WallpaperEntity
|
||||
|
||||
/**
|
||||
* Room relation combining Folder with its Wallpapers
|
||||
*/
|
||||
data class FolderWithWallpapers(
|
||||
@Embedded
|
||||
val folder: FolderEntity,
|
||||
|
||||
@Relation(
|
||||
parentColumn = "id",
|
||||
entityColumn = "folderId",
|
||||
entity = WallpaperEntity::class
|
||||
)
|
||||
val wallpapers: List<WallpaperEntity> = emptyList()
|
||||
)
|
||||
@@ -0,0 +1,554 @@
|
||||
package com.anthonyla.paperize.data.datastore
|
||||
|
||||
import android.content.Context
|
||||
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.intPreferencesKey
|
||||
import androidx.datastore.preferences.core.longPreferencesKey
|
||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||
import androidx.datastore.preferences.preferencesDataStore
|
||||
import com.anthonyla.paperize.core.ScalingType
|
||||
import com.anthonyla.paperize.core.WallpaperMode
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
import com.anthonyla.paperize.core.constants.PreferenceKeys
|
||||
import com.anthonyla.paperize.domain.model.AppSettings
|
||||
import com.anthonyla.paperize.domain.model.ScheduleSettings
|
||||
import com.anthonyla.paperize.domain.model.WallpaperEffects
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Context extension for DataStore
|
||||
*/
|
||||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(
|
||||
name = Constants.PREFERENCES_NAME
|
||||
)
|
||||
|
||||
/**
|
||||
* PreferencesManager - Clean interface for DataStore operations
|
||||
*
|
||||
* Replaces the old SettingsDataStore with better organization and type safety
|
||||
*/
|
||||
@Singleton
|
||||
class PreferencesManager @Inject constructor(
|
||||
private val context: Context
|
||||
) {
|
||||
private val dataStore = context.dataStore
|
||||
|
||||
// ============ App Settings ============
|
||||
|
||||
suspend fun getAppSettings(): AppSettings {
|
||||
val prefs = dataStore.data.first()
|
||||
return AppSettings(
|
||||
darkMode = prefs[booleanPreferencesKey(PreferenceKeys.DARK_MODE)] ?: false,
|
||||
dynamicTheming = prefs[booleanPreferencesKey(PreferenceKeys.DYNAMIC_THEMING)] ?: true,
|
||||
animate = prefs[booleanPreferencesKey(PreferenceKeys.ANIMATE)] ?: true,
|
||||
firstLaunch = prefs[booleanPreferencesKey(PreferenceKeys.FIRST_LAUNCH)] ?: true,
|
||||
currentHomeWallpaperId = prefs[stringPreferencesKey(PreferenceKeys.CURRENT_HOME_WALLPAPER_ID)],
|
||||
currentLockWallpaperId = prefs[stringPreferencesKey(PreferenceKeys.CURRENT_LOCK_WALLPAPER_ID)]
|
||||
)
|
||||
}
|
||||
|
||||
fun getAppSettingsFlow(): Flow<AppSettings> = dataStore.data.map { prefs ->
|
||||
AppSettings(
|
||||
darkMode = prefs[booleanPreferencesKey(PreferenceKeys.DARK_MODE)] ?: false,
|
||||
dynamicTheming = prefs[booleanPreferencesKey(PreferenceKeys.DYNAMIC_THEMING)] ?: true,
|
||||
animate = prefs[booleanPreferencesKey(PreferenceKeys.ANIMATE)] ?: true,
|
||||
firstLaunch = prefs[booleanPreferencesKey(PreferenceKeys.FIRST_LAUNCH)] ?: true,
|
||||
currentHomeWallpaperId = prefs[stringPreferencesKey(PreferenceKeys.CURRENT_HOME_WALLPAPER_ID)],
|
||||
currentLockWallpaperId = prefs[stringPreferencesKey(PreferenceKeys.CURRENT_LOCK_WALLPAPER_ID)]
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun updateAppSettings(settings: AppSettings) {
|
||||
dataStore.edit { prefs ->
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.DARK_MODE)] = settings.darkMode ?: false
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.DYNAMIC_THEMING)] = settings.dynamicTheming
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.ANIMATE)] = settings.animate
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.FIRST_LAUNCH)] = settings.firstLaunch
|
||||
settings.currentHomeWallpaperId?.let {
|
||||
prefs[stringPreferencesKey(PreferenceKeys.CURRENT_HOME_WALLPAPER_ID)] = it
|
||||
}
|
||||
settings.currentLockWallpaperId?.let {
|
||||
prefs[stringPreferencesKey(PreferenceKeys.CURRENT_LOCK_WALLPAPER_ID)] = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Wallpaper Mode ============
|
||||
|
||||
/**
|
||||
* Get current wallpaper mode (STATIC or LIVE)
|
||||
* Defaults to STATIC for new installations and backward compatibility
|
||||
*/
|
||||
suspend fun getWallpaperMode(): WallpaperMode {
|
||||
val prefs = dataStore.data.first()
|
||||
val modeString = prefs[stringPreferencesKey(PreferenceKeys.WALLPAPER_MODE)]
|
||||
return WallpaperMode.fromString(modeString)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get wallpaper mode as a Flow for reactive updates
|
||||
*/
|
||||
fun getWallpaperModeFlow(): Flow<WallpaperMode> = dataStore.data.map { prefs ->
|
||||
val modeString = prefs[stringPreferencesKey(PreferenceKeys.WALLPAPER_MODE)]
|
||||
WallpaperMode.fromString(modeString)
|
||||
}
|
||||
|
||||
/**
|
||||
* Update wallpaper mode
|
||||
* IMPORTANT: Caller should handle data reset when switching modes
|
||||
*/
|
||||
suspend fun updateWallpaperMode(mode: WallpaperMode) {
|
||||
dataStore.edit { prefs ->
|
||||
prefs[stringPreferencesKey(PreferenceKeys.WALLPAPER_MODE)] = mode.name
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Schedule Settings ============
|
||||
|
||||
suspend fun getScheduleSettings(): ScheduleSettings {
|
||||
val prefs = dataStore.data.first()
|
||||
return ScheduleSettings(
|
||||
enableChanger = prefs[booleanPreferencesKey(PreferenceKeys.ENABLE_CHANGER)] ?: false,
|
||||
separateSchedules = prefs[booleanPreferencesKey(PreferenceKeys.SEPARATE_SCHEDULES)] ?: false,
|
||||
shuffleEnabled = prefs[booleanPreferencesKey(PreferenceKeys.SHUFFLE_ENABLED)] ?: false,
|
||||
homeEnabled = prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLED)] ?: false,
|
||||
lockEnabled = prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLED)] ?: false,
|
||||
homeAlbumId = prefs[stringPreferencesKey(PreferenceKeys.HOME_ALBUM_ID)],
|
||||
lockAlbumId = prefs[stringPreferencesKey(PreferenceKeys.LOCK_ALBUM_ID)],
|
||||
liveAlbumId = prefs[stringPreferencesKey(PreferenceKeys.LIVE_ALBUM_ID)],
|
||||
homeIntervalMinutes = prefs[intPreferencesKey(PreferenceKeys.HOME_INTERVAL_MINUTES)]
|
||||
?: Constants.DEFAULT_INTERVAL_MINUTES,
|
||||
lockIntervalMinutes = prefs[intPreferencesKey(PreferenceKeys.LOCK_INTERVAL_MINUTES)]
|
||||
?: Constants.DEFAULT_INTERVAL_MINUTES,
|
||||
liveIntervalMinutes = prefs[intPreferencesKey(PreferenceKeys.LIVE_INTERVAL_MINUTES)]
|
||||
?: Constants.DEFAULT_INTERVAL_MINUTES,
|
||||
homeScalingType = ScalingType.fromString(prefs[stringPreferencesKey(PreferenceKeys.HOME_SCALING_TYPE)]),
|
||||
lockScalingType = ScalingType.fromString(prefs[stringPreferencesKey(PreferenceKeys.LOCK_SCALING_TYPE)]),
|
||||
liveScalingType = ScalingType.fromString(prefs[stringPreferencesKey(PreferenceKeys.LIVE_SCALING_TYPE)]),
|
||||
homeEffects = WallpaperEffects(
|
||||
enableBlur = prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_BLUR)] ?: false,
|
||||
blurPercentage = prefs[intPreferencesKey(PreferenceKeys.HOME_BLUR)] ?: 0,
|
||||
enableDarken = prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_DARKEN)] ?: false,
|
||||
darkenPercentage = prefs[intPreferencesKey(PreferenceKeys.HOME_DARKEN)] ?: 0,
|
||||
enableVignette = prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_VIGNETTE)] ?: false,
|
||||
vignettePercentage = prefs[intPreferencesKey(PreferenceKeys.HOME_VIGNETTE)] ?: 0,
|
||||
enableGrayscale = prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_GRAYSCALE)] ?: false,
|
||||
grayscalePercentage = prefs[intPreferencesKey(PreferenceKeys.HOME_GRAYSCALE)] ?: 0,
|
||||
enableDoubleTap = prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_DOUBLE_TAP)] ?: false,
|
||||
enableParallax = prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_PARALLAX)] ?: false,
|
||||
parallaxIntensity = prefs[intPreferencesKey(PreferenceKeys.HOME_PARALLAX_INTENSITY)] ?: Constants.DEFAULT_PARALLAX_INTENSITY
|
||||
),
|
||||
lockEffects = WallpaperEffects(
|
||||
enableBlur = prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_BLUR)] ?: false,
|
||||
blurPercentage = prefs[intPreferencesKey(PreferenceKeys.LOCK_BLUR)] ?: 0,
|
||||
enableDarken = prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_DARKEN)] ?: false,
|
||||
darkenPercentage = prefs[intPreferencesKey(PreferenceKeys.LOCK_DARKEN)] ?: 0,
|
||||
enableVignette = prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_VIGNETTE)] ?: false,
|
||||
vignettePercentage = prefs[intPreferencesKey(PreferenceKeys.LOCK_VIGNETTE)] ?: 0,
|
||||
enableGrayscale = prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_GRAYSCALE)] ?: false,
|
||||
grayscalePercentage = prefs[intPreferencesKey(PreferenceKeys.LOCK_GRAYSCALE)] ?: 0,
|
||||
enableDoubleTap = prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_DOUBLE_TAP)] ?: false,
|
||||
enableParallax = prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_PARALLAX)] ?: false,
|
||||
parallaxIntensity = prefs[intPreferencesKey(PreferenceKeys.LOCK_PARALLAX_INTENSITY)] ?: Constants.DEFAULT_PARALLAX_INTENSITY
|
||||
),
|
||||
liveEffects = WallpaperEffects(
|
||||
enableBlur = prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_BLUR)] ?: false,
|
||||
blurPercentage = prefs[intPreferencesKey(PreferenceKeys.LIVE_BLUR)] ?: 0,
|
||||
enableDarken = prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_DARKEN)] ?: false,
|
||||
darkenPercentage = prefs[intPreferencesKey(PreferenceKeys.LIVE_DARKEN)] ?: 0,
|
||||
enableVignette = prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_VIGNETTE)] ?: false,
|
||||
vignettePercentage = prefs[intPreferencesKey(PreferenceKeys.LIVE_VIGNETTE)] ?: 0,
|
||||
enableGrayscale = prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_GRAYSCALE)] ?: false,
|
||||
grayscalePercentage = prefs[intPreferencesKey(PreferenceKeys.LIVE_GRAYSCALE)] ?: 0,
|
||||
enableDoubleTap = prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_DOUBLE_TAP)] ?: false,
|
||||
enableChangeOnScreenOn = prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_CHANGE_ON_SCREEN_ON)] ?: false,
|
||||
enableParallax = prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_PARALLAX)] ?: false,
|
||||
parallaxIntensity = prefs[intPreferencesKey(PreferenceKeys.LIVE_PARALLAX_INTENSITY)] ?: Constants.DEFAULT_PARALLAX_INTENSITY
|
||||
),
|
||||
adaptiveBrightness = prefs[booleanPreferencesKey(PreferenceKeys.ADAPTIVE_BRIGHTNESS)] ?: false
|
||||
)
|
||||
}
|
||||
|
||||
fun getScheduleSettingsFlow(): Flow<ScheduleSettings> = dataStore.data.map { prefs ->
|
||||
ScheduleSettings(
|
||||
enableChanger = prefs[booleanPreferencesKey(PreferenceKeys.ENABLE_CHANGER)] ?: false,
|
||||
separateSchedules = prefs[booleanPreferencesKey(PreferenceKeys.SEPARATE_SCHEDULES)] ?: false,
|
||||
shuffleEnabled = prefs[booleanPreferencesKey(PreferenceKeys.SHUFFLE_ENABLED)] ?: false,
|
||||
homeEnabled = prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLED)] ?: false,
|
||||
lockEnabled = prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLED)] ?: false,
|
||||
homeAlbumId = prefs[stringPreferencesKey(PreferenceKeys.HOME_ALBUM_ID)],
|
||||
lockAlbumId = prefs[stringPreferencesKey(PreferenceKeys.LOCK_ALBUM_ID)],
|
||||
liveAlbumId = prefs[stringPreferencesKey(PreferenceKeys.LIVE_ALBUM_ID)],
|
||||
homeIntervalMinutes = prefs[intPreferencesKey(PreferenceKeys.HOME_INTERVAL_MINUTES)]
|
||||
?: Constants.DEFAULT_INTERVAL_MINUTES,
|
||||
lockIntervalMinutes = prefs[intPreferencesKey(PreferenceKeys.LOCK_INTERVAL_MINUTES)]
|
||||
?: Constants.DEFAULT_INTERVAL_MINUTES,
|
||||
liveIntervalMinutes = prefs[intPreferencesKey(PreferenceKeys.LIVE_INTERVAL_MINUTES)]
|
||||
?: Constants.DEFAULT_INTERVAL_MINUTES,
|
||||
homeScalingType = ScalingType.fromString(prefs[stringPreferencesKey(PreferenceKeys.HOME_SCALING_TYPE)]),
|
||||
lockScalingType = ScalingType.fromString(prefs[stringPreferencesKey(PreferenceKeys.LOCK_SCALING_TYPE)]),
|
||||
liveScalingType = ScalingType.fromString(prefs[stringPreferencesKey(PreferenceKeys.LIVE_SCALING_TYPE)]),
|
||||
homeEffects = WallpaperEffects(
|
||||
enableBlur = prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_BLUR)] ?: false,
|
||||
blurPercentage = prefs[intPreferencesKey(PreferenceKeys.HOME_BLUR)] ?: 0,
|
||||
enableDarken = prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_DARKEN)] ?: false,
|
||||
darkenPercentage = prefs[intPreferencesKey(PreferenceKeys.HOME_DARKEN)] ?: 0,
|
||||
enableVignette = prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_VIGNETTE)] ?: false,
|
||||
vignettePercentage = prefs[intPreferencesKey(PreferenceKeys.HOME_VIGNETTE)] ?: 0,
|
||||
enableGrayscale = prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_GRAYSCALE)] ?: false,
|
||||
grayscalePercentage = prefs[intPreferencesKey(PreferenceKeys.HOME_GRAYSCALE)] ?: 0,
|
||||
enableDoubleTap = prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_DOUBLE_TAP)] ?: false,
|
||||
enableParallax = prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_PARALLAX)] ?: false,
|
||||
parallaxIntensity = prefs[intPreferencesKey(PreferenceKeys.HOME_PARALLAX_INTENSITY)] ?: Constants.DEFAULT_PARALLAX_INTENSITY
|
||||
),
|
||||
lockEffects = WallpaperEffects(
|
||||
enableBlur = prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_BLUR)] ?: false,
|
||||
blurPercentage = prefs[intPreferencesKey(PreferenceKeys.LOCK_BLUR)] ?: 0,
|
||||
enableDarken = prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_DARKEN)] ?: false,
|
||||
darkenPercentage = prefs[intPreferencesKey(PreferenceKeys.LOCK_DARKEN)] ?: 0,
|
||||
enableVignette = prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_VIGNETTE)] ?: false,
|
||||
vignettePercentage = prefs[intPreferencesKey(PreferenceKeys.LOCK_VIGNETTE)] ?: 0,
|
||||
enableGrayscale = prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_GRAYSCALE)] ?: false,
|
||||
grayscalePercentage = prefs[intPreferencesKey(PreferenceKeys.LOCK_GRAYSCALE)] ?: 0,
|
||||
enableDoubleTap = prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_DOUBLE_TAP)] ?: false,
|
||||
enableParallax = prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_PARALLAX)] ?: false,
|
||||
parallaxIntensity = prefs[intPreferencesKey(PreferenceKeys.LOCK_PARALLAX_INTENSITY)] ?: Constants.DEFAULT_PARALLAX_INTENSITY
|
||||
),
|
||||
liveEffects = WallpaperEffects(
|
||||
enableBlur = prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_BLUR)] ?: false,
|
||||
blurPercentage = prefs[intPreferencesKey(PreferenceKeys.LIVE_BLUR)] ?: 0,
|
||||
enableDarken = prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_DARKEN)] ?: false,
|
||||
darkenPercentage = prefs[intPreferencesKey(PreferenceKeys.LIVE_DARKEN)] ?: 0,
|
||||
enableVignette = prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_VIGNETTE)] ?: false,
|
||||
vignettePercentage = prefs[intPreferencesKey(PreferenceKeys.LIVE_VIGNETTE)] ?: 0,
|
||||
enableGrayscale = prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_GRAYSCALE)] ?: false,
|
||||
grayscalePercentage = prefs[intPreferencesKey(PreferenceKeys.LIVE_GRAYSCALE)] ?: 0,
|
||||
enableDoubleTap = prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_DOUBLE_TAP)] ?: false,
|
||||
enableChangeOnScreenOn = prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_CHANGE_ON_SCREEN_ON)] ?: false,
|
||||
enableParallax = prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_PARALLAX)] ?: false,
|
||||
parallaxIntensity = prefs[intPreferencesKey(PreferenceKeys.LIVE_PARALLAX_INTENSITY)] ?: Constants.DEFAULT_PARALLAX_INTENSITY
|
||||
),
|
||||
adaptiveBrightness = prefs[booleanPreferencesKey(PreferenceKeys.ADAPTIVE_BRIGHTNESS)] ?: false
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun updateScheduleSettings(settings: ScheduleSettings) {
|
||||
dataStore.edit { prefs ->
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.ENABLE_CHANGER)] = settings.enableChanger
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.SEPARATE_SCHEDULES)] = settings.separateSchedules
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.SHUFFLE_ENABLED)] = settings.shuffleEnabled
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLED)] = settings.homeEnabled
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLED)] = settings.lockEnabled
|
||||
if (settings.homeAlbumId != null) {
|
||||
prefs[stringPreferencesKey(PreferenceKeys.HOME_ALBUM_ID)] = settings.homeAlbumId
|
||||
} else {
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.HOME_ALBUM_ID))
|
||||
}
|
||||
if (settings.lockAlbumId != null) {
|
||||
prefs[stringPreferencesKey(PreferenceKeys.LOCK_ALBUM_ID)] = settings.lockAlbumId
|
||||
} else {
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.LOCK_ALBUM_ID))
|
||||
}
|
||||
if (settings.liveAlbumId != null) {
|
||||
prefs[stringPreferencesKey(PreferenceKeys.LIVE_ALBUM_ID)] = settings.liveAlbumId
|
||||
} else {
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.LIVE_ALBUM_ID))
|
||||
}
|
||||
prefs[intPreferencesKey(PreferenceKeys.HOME_INTERVAL_MINUTES)] = settings.homeIntervalMinutes
|
||||
prefs[intPreferencesKey(PreferenceKeys.LOCK_INTERVAL_MINUTES)] = settings.lockIntervalMinutes
|
||||
prefs[intPreferencesKey(PreferenceKeys.LIVE_INTERVAL_MINUTES)] = settings.liveIntervalMinutes
|
||||
prefs[stringPreferencesKey(PreferenceKeys.HOME_SCALING_TYPE)] = settings.homeScalingType.name
|
||||
prefs[stringPreferencesKey(PreferenceKeys.LOCK_SCALING_TYPE)] = settings.lockScalingType.name
|
||||
prefs[stringPreferencesKey(PreferenceKeys.LIVE_SCALING_TYPE)] = settings.liveScalingType.name
|
||||
|
||||
// Home effects
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_BLUR)] = settings.homeEffects.enableBlur
|
||||
prefs[intPreferencesKey(PreferenceKeys.HOME_BLUR)] = settings.homeEffects.blurPercentage
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_DARKEN)] = settings.homeEffects.enableDarken
|
||||
prefs[intPreferencesKey(PreferenceKeys.HOME_DARKEN)] = settings.homeEffects.darkenPercentage
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_VIGNETTE)] = settings.homeEffects.enableVignette
|
||||
prefs[intPreferencesKey(PreferenceKeys.HOME_VIGNETTE)] = settings.homeEffects.vignettePercentage
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_GRAYSCALE)] = settings.homeEffects.enableGrayscale
|
||||
prefs[intPreferencesKey(PreferenceKeys.HOME_GRAYSCALE)] = settings.homeEffects.grayscalePercentage
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_DOUBLE_TAP)] = settings.homeEffects.enableDoubleTap
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_PARALLAX)] = settings.homeEffects.enableParallax
|
||||
prefs[intPreferencesKey(PreferenceKeys.HOME_PARALLAX_INTENSITY)] = settings.homeEffects.parallaxIntensity
|
||||
|
||||
// Lock effects
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_BLUR)] = settings.lockEffects.enableBlur
|
||||
prefs[intPreferencesKey(PreferenceKeys.LOCK_BLUR)] = settings.lockEffects.blurPercentage
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_DARKEN)] = settings.lockEffects.enableDarken
|
||||
prefs[intPreferencesKey(PreferenceKeys.LOCK_DARKEN)] = settings.lockEffects.darkenPercentage
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_VIGNETTE)] = settings.lockEffects.enableVignette
|
||||
prefs[intPreferencesKey(PreferenceKeys.LOCK_VIGNETTE)] = settings.lockEffects.vignettePercentage
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_GRAYSCALE)] = settings.lockEffects.enableGrayscale
|
||||
prefs[intPreferencesKey(PreferenceKeys.LOCK_GRAYSCALE)] = settings.lockEffects.grayscalePercentage
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_DOUBLE_TAP)] = settings.lockEffects.enableDoubleTap
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_PARALLAX)] = settings.lockEffects.enableParallax
|
||||
prefs[intPreferencesKey(PreferenceKeys.LOCK_PARALLAX_INTENSITY)] = settings.lockEffects.parallaxIntensity
|
||||
|
||||
// Live effects
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_BLUR)] = settings.liveEffects.enableBlur
|
||||
prefs[intPreferencesKey(PreferenceKeys.LIVE_BLUR)] = settings.liveEffects.blurPercentage
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_DARKEN)] = settings.liveEffects.enableDarken
|
||||
prefs[intPreferencesKey(PreferenceKeys.LIVE_DARKEN)] = settings.liveEffects.darkenPercentage
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_VIGNETTE)] = settings.liveEffects.enableVignette
|
||||
prefs[intPreferencesKey(PreferenceKeys.LIVE_VIGNETTE)] = settings.liveEffects.vignettePercentage
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_GRAYSCALE)] = settings.liveEffects.enableGrayscale
|
||||
prefs[intPreferencesKey(PreferenceKeys.LIVE_GRAYSCALE)] = settings.liveEffects.grayscalePercentage
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_DOUBLE_TAP)] = settings.liveEffects.enableDoubleTap
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_CHANGE_ON_SCREEN_ON)] = settings.liveEffects.enableChangeOnScreenOn
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_PARALLAX)] = settings.liveEffects.enableParallax
|
||||
prefs[intPreferencesKey(PreferenceKeys.LIVE_PARALLAX_INTENSITY)] = settings.liveEffects.parallaxIntensity
|
||||
|
||||
// Adaptive brightness
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.ADAPTIVE_BRIGHTNESS)] = settings.adaptiveBrightness
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Atomic Album Selection Operations ============
|
||||
|
||||
/**
|
||||
* Atomically update home album ID without race conditions
|
||||
* This prevents lost updates when both home and lock albums are selected simultaneously
|
||||
*/
|
||||
suspend fun updateHomeAlbumId(albumId: String?) {
|
||||
dataStore.edit { prefs ->
|
||||
if (albumId != null) {
|
||||
prefs[stringPreferencesKey(PreferenceKeys.HOME_ALBUM_ID)] = albumId
|
||||
} else {
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.HOME_ALBUM_ID))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Atomically update lock album ID without race conditions
|
||||
* This prevents lost updates when both home and lock albums are selected simultaneously
|
||||
*/
|
||||
suspend fun updateLockAlbumId(albumId: String?) {
|
||||
dataStore.edit { prefs ->
|
||||
if (albumId != null) {
|
||||
prefs[stringPreferencesKey(PreferenceKeys.LOCK_ALBUM_ID)] = albumId
|
||||
} else {
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.LOCK_ALBUM_ID))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Atomically update live album ID without race conditions
|
||||
*/
|
||||
suspend fun updateLiveAlbumId(albumId: String?) {
|
||||
dataStore.edit { prefs ->
|
||||
if (albumId != null) {
|
||||
prefs[stringPreferencesKey(PreferenceKeys.LIVE_ALBUM_ID)] = albumId
|
||||
} else {
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.LIVE_ALBUM_ID))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Atomically clear album selections if they match the given album ID
|
||||
* Used when deleting an album to prevent race conditions
|
||||
* Returns true if any selections were cleared
|
||||
*/
|
||||
suspend fun clearAlbumSelectionsIfMatches(albumId: String): Boolean {
|
||||
var wasCleared = false
|
||||
dataStore.edit { prefs ->
|
||||
val homeAlbumId = prefs[stringPreferencesKey(PreferenceKeys.HOME_ALBUM_ID)]
|
||||
val lockAlbumId = prefs[stringPreferencesKey(PreferenceKeys.LOCK_ALBUM_ID)]
|
||||
val liveAlbumId = prefs[stringPreferencesKey(PreferenceKeys.LIVE_ALBUM_ID)]
|
||||
|
||||
// Clear home album if it matches
|
||||
if (homeAlbumId == albumId) {
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.HOME_ALBUM_ID))
|
||||
wasCleared = true
|
||||
}
|
||||
|
||||
// Clear lock album if it matches
|
||||
if (lockAlbumId == albumId) {
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.LOCK_ALBUM_ID))
|
||||
wasCleared = true
|
||||
}
|
||||
|
||||
// Clear live album if it matches
|
||||
if (liveAlbumId == albumId) {
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.LIVE_ALBUM_ID))
|
||||
wasCleared = true
|
||||
}
|
||||
}
|
||||
return wasCleared
|
||||
}
|
||||
|
||||
// ============ Atomic AppSettings Operations ============
|
||||
|
||||
/**
|
||||
* Atomically update dark mode setting without race conditions
|
||||
*/
|
||||
suspend fun updateDarkMode(enabled: Boolean) {
|
||||
dataStore.edit { prefs ->
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.DARK_MODE)] = enabled
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Atomically update dynamic theming setting without race conditions
|
||||
*/
|
||||
suspend fun updateDynamicTheming(enabled: Boolean) {
|
||||
dataStore.edit { prefs ->
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.DYNAMIC_THEMING)] = enabled
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Atomically update animate setting without race conditions
|
||||
*/
|
||||
suspend fun updateAnimate(enabled: Boolean) {
|
||||
dataStore.edit { prefs ->
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.ANIMATE)] = enabled
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Atomically update first launch setting without race conditions
|
||||
*/
|
||||
suspend fun updateFirstLaunch(isFirstLaunch: Boolean) {
|
||||
dataStore.edit { prefs ->
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.FIRST_LAUNCH)] = isFirstLaunch
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Atomic ScheduleSettings Operations ============
|
||||
|
||||
/**
|
||||
* Atomically update enableChanger setting without race conditions
|
||||
*/
|
||||
suspend fun updateEnableChanger(enabled: Boolean) {
|
||||
dataStore.edit { prefs ->
|
||||
prefs[booleanPreferencesKey(PreferenceKeys.ENABLE_CHANGER)] = enabled
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Individual Preference Operations ============
|
||||
|
||||
suspend fun <T> setValue(key: String, value: T) {
|
||||
dataStore.edit { prefs ->
|
||||
when (value) {
|
||||
is Boolean -> prefs[booleanPreferencesKey(key)] = value
|
||||
is Int -> prefs[intPreferencesKey(key)] = value
|
||||
is Long -> prefs[longPreferencesKey(key)] = value
|
||||
is String -> prefs[stringPreferencesKey(key)] = value
|
||||
else -> throw IllegalArgumentException("Unsupported preference type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun <T> getValue(key: String, defaultValue: T): T {
|
||||
val prefs = dataStore.data.first()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return when (defaultValue) {
|
||||
is Boolean -> prefs[booleanPreferencesKey(key)] ?: defaultValue
|
||||
is Int -> prefs[intPreferencesKey(key)] ?: defaultValue
|
||||
is Long -> prefs[longPreferencesKey(key)] ?: defaultValue
|
||||
is String -> prefs[stringPreferencesKey(key)] ?: defaultValue
|
||||
else -> throw IllegalArgumentException("Unsupported preference type")
|
||||
} as T
|
||||
}
|
||||
|
||||
fun <T> getValueFlow(key: String, defaultValue: T): Flow<T> = dataStore.data.map { prefs ->
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
when (defaultValue) {
|
||||
is Boolean -> prefs[booleanPreferencesKey(key)] ?: defaultValue
|
||||
is Int -> prefs[intPreferencesKey(key)] ?: defaultValue
|
||||
is Long -> prefs[longPreferencesKey(key)] ?: defaultValue
|
||||
is String -> prefs[stringPreferencesKey(key)] ?: defaultValue
|
||||
else -> throw IllegalArgumentException("Unsupported preference type")
|
||||
} as T
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear schedule settings (reset to defaults)
|
||||
* Used when switching wallpaper modes
|
||||
*/
|
||||
suspend fun clearScheduleSettings() {
|
||||
dataStore.edit { prefs ->
|
||||
// Clear scheduling settings
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.ENABLE_CHANGER))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.SEPARATE_SCHEDULES))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.SHUFFLE_ENABLED))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.HOME_ENABLED))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.LOCK_ENABLED))
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.HOME_ALBUM_ID))
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.LOCK_ALBUM_ID))
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.LIVE_ALBUM_ID))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.HOME_INTERVAL_MINUTES))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.LOCK_INTERVAL_MINUTES))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.LIVE_INTERVAL_MINUTES))
|
||||
|
||||
// Clear home effects
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_BLUR))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.HOME_BLUR))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_DARKEN))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.HOME_DARKEN))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_VIGNETTE))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.HOME_VIGNETTE))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_GRAYSCALE))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.HOME_GRAYSCALE))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_DOUBLE_TAP))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.HOME_ENABLE_PARALLAX))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.HOME_PARALLAX_INTENSITY))
|
||||
|
||||
// Clear lock effects
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_BLUR))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.LOCK_BLUR))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_DARKEN))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.LOCK_DARKEN))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_VIGNETTE))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.LOCK_VIGNETTE))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_GRAYSCALE))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.LOCK_GRAYSCALE))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_DOUBLE_TAP))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.LOCK_ENABLE_PARALLAX))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.LOCK_PARALLAX_INTENSITY))
|
||||
|
||||
// Clear live effects
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_BLUR))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.LIVE_BLUR))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_DARKEN))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.LIVE_DARKEN))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_VIGNETTE))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.LIVE_VIGNETTE))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_GRAYSCALE))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.LIVE_GRAYSCALE))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_DOUBLE_TAP))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_CHANGE_ON_SCREEN_ON))
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.LIVE_ENABLE_PARALLAX))
|
||||
prefs.remove(intPreferencesKey(PreferenceKeys.LIVE_PARALLAX_INTENSITY))
|
||||
|
||||
// Clear scaling
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.HOME_SCALING_TYPE))
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.LOCK_SCALING_TYPE))
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.LIVE_SCALING_TYPE))
|
||||
|
||||
// Clear current wallpapers
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.CURRENT_HOME_WALLPAPER_ID))
|
||||
prefs.remove(stringPreferencesKey(PreferenceKeys.CURRENT_LOCK_WALLPAPER_ID))
|
||||
|
||||
// Clear adaptive brightness
|
||||
prefs.remove(booleanPreferencesKey(PreferenceKeys.ADAPTIVE_BRIGHTNESS))
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun clear() {
|
||||
dataStore.edit { it.clear() }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.anthonyla.paperize.data.mapper
|
||||
|
||||
import com.anthonyla.paperize.data.database.entities.AlbumEntity
|
||||
import com.anthonyla.paperize.data.database.relations.AlbumWithDetails
|
||||
import com.anthonyla.paperize.domain.model.Album
|
||||
|
||||
/**
|
||||
* Mappers for Album entity <-> domain model conversion
|
||||
*/
|
||||
|
||||
fun AlbumEntity.toDomainModel(
|
||||
wallpapers: List<com.anthonyla.paperize.domain.model.Wallpaper> = emptyList(),
|
||||
folders: List<com.anthonyla.paperize.domain.model.Folder> = emptyList()
|
||||
): Album = Album(
|
||||
id = id,
|
||||
name = name,
|
||||
coverUri = coverUri,
|
||||
wallpapers = wallpapers,
|
||||
folders = folders,
|
||||
createdAt = createdAt,
|
||||
modifiedAt = modifiedAt
|
||||
)
|
||||
|
||||
fun Album.toEntity(): AlbumEntity = AlbumEntity(
|
||||
id = id,
|
||||
name = name,
|
||||
coverUri = coverUri,
|
||||
createdAt = createdAt,
|
||||
modifiedAt = modifiedAt
|
||||
)
|
||||
|
||||
fun AlbumWithDetails.toDomainModel(): Album {
|
||||
// Optimization: Group wallpapers by folderId once to avoid repeated filtering
|
||||
val wallpapersByFolder = wallpapers.groupBy { it.folderId }
|
||||
|
||||
val domainWallpapers = wallpapersByFolder[null]?.map { it.toDomainModel() } ?: emptyList()
|
||||
|
||||
val domainFolders = folders.map { folderEntity ->
|
||||
val folderWallpapers = wallpapersByFolder[folderEntity.id]?.map { it.toDomainModel() } ?: emptyList()
|
||||
folderEntity.toDomainModel(folderWallpapers)
|
||||
}
|
||||
|
||||
return album.toDomainModel(
|
||||
wallpapers = domainWallpapers,
|
||||
folders = domainFolders
|
||||
)
|
||||
}
|
||||
|
||||
fun List<AlbumEntity>.toDomainModels(): List<Album> = map { it.toDomainModel() }
|
||||
|
||||
fun List<AlbumWithDetails>.toDomainModelsFromRelations(): List<Album> = map { it.toDomainModel() }
|
||||
|
||||
fun com.anthonyla.paperize.data.database.entities.AlbumSummaryEntity.toDomainModel(): com.anthonyla.paperize.domain.model.AlbumSummary =
|
||||
com.anthonyla.paperize.domain.model.AlbumSummary(
|
||||
id = id,
|
||||
name = name,
|
||||
coverUri = coverUri,
|
||||
wallpaperCount = wallpaperCount,
|
||||
folderCount = folderCount,
|
||||
createdAt = createdAt,
|
||||
modifiedAt = modifiedAt
|
||||
)
|
||||
|
||||
fun List<com.anthonyla.paperize.data.database.entities.AlbumSummaryEntity>.toDomainModelsFromSummaries(): List<com.anthonyla.paperize.domain.model.AlbumSummary> =
|
||||
map { it.toDomainModel() }
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.anthonyla.paperize.data.mapper
|
||||
|
||||
import com.anthonyla.paperize.data.database.entities.FolderEntity
|
||||
import com.anthonyla.paperize.data.database.relations.FolderWithWallpapers
|
||||
import com.anthonyla.paperize.domain.model.Folder
|
||||
|
||||
/**
|
||||
* Mappers for Folder entity <-> domain model conversion
|
||||
*/
|
||||
|
||||
fun FolderEntity.toDomainModel(
|
||||
wallpapers: List<com.anthonyla.paperize.domain.model.Wallpaper> = emptyList()
|
||||
): Folder = Folder(
|
||||
id = id,
|
||||
albumId = albumId,
|
||||
name = name,
|
||||
uri = uri,
|
||||
coverUri = coverUri,
|
||||
dateModified = dateModified,
|
||||
displayOrder = displayOrder,
|
||||
wallpapers = wallpapers,
|
||||
addedAt = addedAt
|
||||
)
|
||||
|
||||
fun Folder.toEntity(): FolderEntity = FolderEntity(
|
||||
id = id,
|
||||
albumId = albumId,
|
||||
name = name,
|
||||
uri = uri,
|
||||
coverUri = coverUri,
|
||||
dateModified = dateModified,
|
||||
displayOrder = displayOrder,
|
||||
addedAt = addedAt
|
||||
)
|
||||
|
||||
fun FolderWithWallpapers.toDomainModel(): Folder = folder.toDomainModel(
|
||||
wallpapers = wallpapers.map { it.toDomainModel() }
|
||||
)
|
||||
|
||||
fun List<FolderEntity>.toDomainModels(): List<Folder> = map { it.toDomainModel() }
|
||||
|
||||
fun List<FolderWithWallpapers>.toDomainModelsFromRelations(): List<Folder> = map { it.toDomainModel() }
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.anthonyla.paperize.data.mapper
|
||||
|
||||
import com.anthonyla.paperize.data.database.entities.WallpaperEntity
|
||||
import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
|
||||
/**
|
||||
* Mappers for Wallpaper entity <-> domain model conversion
|
||||
*/
|
||||
|
||||
fun WallpaperEntity.toDomainModel(): Wallpaper = Wallpaper(
|
||||
id = id,
|
||||
albumId = albumId,
|
||||
folderId = folderId,
|
||||
uri = uri,
|
||||
fileName = fileName,
|
||||
dateModified = dateModified,
|
||||
displayOrder = displayOrder,
|
||||
sourceType = sourceType,
|
||||
addedAt = addedAt,
|
||||
mediaType = mediaType
|
||||
)
|
||||
|
||||
fun Wallpaper.toEntity(): WallpaperEntity = WallpaperEntity(
|
||||
id = id,
|
||||
albumId = albumId,
|
||||
folderId = folderId,
|
||||
uri = uri,
|
||||
fileName = fileName,
|
||||
dateModified = dateModified,
|
||||
displayOrder = displayOrder,
|
||||
sourceType = sourceType,
|
||||
addedAt = addedAt,
|
||||
mediaType = mediaType
|
||||
)
|
||||
|
||||
fun List<WallpaperEntity>.toDomainModels(): List<Wallpaper> = map { it.toDomainModel() }
|
||||
|
||||
fun List<Wallpaper>.toEntities(): List<WallpaperEntity> = map { it.toEntity() }
|
||||
@@ -1,62 +0,0 @@
|
||||
package com.anthonyla.paperize.data
|
||||
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
|
||||
/**
|
||||
* Remember the current offset of a [LazyListState].
|
||||
* Source:
|
||||
* https://stackoverflow.com/a/75677163
|
||||
* https://stackoverflow.com/a/70558512
|
||||
*/
|
||||
@Composable
|
||||
fun rememberCurrentOffset(state: LazyListState): State<Int> {
|
||||
val position = remember { derivedStateOf { state.firstVisibleItemIndex } }
|
||||
val itemOffset = remember { derivedStateOf { state.firstVisibleItemScrollOffset } }
|
||||
val lastPosition = rememberPrevious(position.value)
|
||||
val lastItemOffset = rememberPrevious(itemOffset.value)
|
||||
val currentOffset = remember { mutableIntStateOf(0) }
|
||||
|
||||
LaunchedEffect(position.value, itemOffset.value) {
|
||||
currentOffset.intValue = when {
|
||||
lastPosition == null || position.value == 0 -> itemOffset.value
|
||||
lastPosition == position.value -> currentOffset.intValue + (itemOffset.value - (lastItemOffset ?: 0))
|
||||
lastPosition > position.value -> currentOffset.intValue - (lastItemOffset ?: 0)
|
||||
else -> currentOffset.intValue + itemOffset.value
|
||||
}
|
||||
}
|
||||
|
||||
return currentOffset
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T> rememberPrevious(
|
||||
current: T,
|
||||
shouldUpdate: (prev: T?, curr: T) -> Boolean = { prev, curr -> prev != curr },
|
||||
): T? {
|
||||
val ref = rememberRef<T>()
|
||||
SideEffect {
|
||||
if (shouldUpdate(ref.value, current)) {
|
||||
ref.value = current
|
||||
}
|
||||
}
|
||||
return ref.value
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T> rememberRef(): MutableState<T?> {
|
||||
return remember {
|
||||
object : MutableState<T?> {
|
||||
override var value: T? = null
|
||||
override fun component1(): T? = value
|
||||
override fun component2(): (T?) -> Unit = { value = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
package com.anthonyla.paperize.data.repository
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.room.withTransaction
|
||||
import com.anthonyla.paperize.core.Result
|
||||
import com.anthonyla.paperize.core.util.generateId
|
||||
import com.anthonyla.paperize.data.database.PaperizeDatabase
|
||||
import com.anthonyla.paperize.data.database.dao.AlbumDao
|
||||
import com.anthonyla.paperize.data.database.dao.FolderDao
|
||||
import com.anthonyla.paperize.data.database.dao.WallpaperDao
|
||||
import com.anthonyla.paperize.data.database.entities.AlbumEntity
|
||||
import com.anthonyla.paperize.data.mapper.toDomainModel
|
||||
import com.anthonyla.paperize.data.mapper.toDomainModelsFromRelations
|
||||
import com.anthonyla.paperize.data.mapper.toDomainModelsFromSummaries
|
||||
import com.anthonyla.paperize.data.mapper.toEntities
|
||||
import com.anthonyla.paperize.data.mapper.toEntity
|
||||
import com.anthonyla.paperize.domain.model.Album
|
||||
import com.anthonyla.paperize.domain.model.AlbumSummary
|
||||
import com.anthonyla.paperize.domain.model.Folder
|
||||
import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.domain.repository.AlbumRepository
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Implementation of AlbumRepository
|
||||
*
|
||||
* Handles data operations for albums using Room database
|
||||
*/
|
||||
@Singleton
|
||||
class AlbumRepositoryImpl @Inject constructor(
|
||||
@param:ApplicationContext private val context: Context,
|
||||
private val database: PaperizeDatabase,
|
||||
private val albumDao: AlbumDao,
|
||||
private val wallpaperDao: WallpaperDao,
|
||||
private val folderDao: FolderDao,
|
||||
private val wallpaperRepository: dagger.Lazy<com.anthonyla.paperize.domain.repository.WallpaperRepository>
|
||||
) : AlbumRepository {
|
||||
|
||||
override fun getAlbumSummaries(): Flow<List<AlbumSummary>> =
|
||||
albumDao.getAlbumSummaries().map { it.toDomainModelsFromSummaries() }
|
||||
|
||||
override fun getAllAlbums(): Flow<List<Album>> =
|
||||
albumDao.getAllAlbumsWithDetails().map { it.toDomainModelsFromRelations() }
|
||||
|
||||
override fun getAlbumById(albumId: String): Flow<Album?> =
|
||||
albumDao.getAlbumWithDetails(albumId).map { it?.toDomainModel() }
|
||||
|
||||
override suspend fun getAlbumByName(name: String): Album? =
|
||||
albumDao.getAlbumByName(name)?.toDomainModel()
|
||||
|
||||
override fun getFolderById(folderId: String): Flow<Folder?> =
|
||||
folderDao.getFolderWithWallpapers(folderId).map { it?.toDomainModel() }
|
||||
|
||||
override suspend fun createAlbum(name: String, coverUri: String?): Result<Album> {
|
||||
return try {
|
||||
val album = Album(
|
||||
id = generateId(),
|
||||
name = name,
|
||||
coverUri = coverUri,
|
||||
createdAt = System.currentTimeMillis(),
|
||||
modifiedAt = System.currentTimeMillis()
|
||||
)
|
||||
albumDao.insertAlbum(album.toEntity())
|
||||
Result.Success(album)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updateAlbum(album: Album): Result<Unit> {
|
||||
return try {
|
||||
albumDao.updateAlbum(album.toEntity())
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteAlbum(albumId: String): Result<Unit> {
|
||||
return try {
|
||||
database.withTransaction {
|
||||
albumDao.deleteAlbumById(albumId)
|
||||
wallpaperRepository.get().clearQueuesForAlbum(albumId)
|
||||
}
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updateAlbumName(albumId: String, name: String): Result<Unit> {
|
||||
return try {
|
||||
albumDao.updateAlbumName(albumId, name, System.currentTimeMillis())
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updateAlbumCover(albumId: String, coverUri: String?): Result<Unit> {
|
||||
return try {
|
||||
albumDao.updateAlbumCover(albumId, coverUri, System.currentTimeMillis())
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun addWallpapersToAlbum(
|
||||
albumId: String,
|
||||
wallpapers: List<Wallpaper>
|
||||
): Result<Unit> {
|
||||
return try {
|
||||
// Atomic transaction - insert wallpapers, update timestamp, and update cover
|
||||
database.withTransaction {
|
||||
wallpaperDao.insertWallpapers(wallpapers.toEntities())
|
||||
albumDao.updateAlbumModifiedTime(albumId, System.currentTimeMillis())
|
||||
|
||||
// Update album cover if it doesn't have one
|
||||
updateAlbumCoverIfNeeded(albumId)
|
||||
}
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun addFolderToAlbum(albumId: String, folder: Folder): Result<Unit> {
|
||||
return try {
|
||||
// Atomic transaction - folder, wallpapers, timestamp, and cover all succeed or all fail
|
||||
database.withTransaction {
|
||||
folderDao.insertFolder(folder.toEntity())
|
||||
// Insert folder wallpapers
|
||||
wallpaperDao.insertWallpapers(folder.wallpapers.toEntities())
|
||||
albumDao.updateAlbumModifiedTime(albumId, System.currentTimeMillis())
|
||||
|
||||
// Update album cover if it doesn't have one
|
||||
updateAlbumCoverIfNeeded(albumId)
|
||||
}
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updateFolder(folder: Folder): Result<Unit> {
|
||||
return try {
|
||||
folderDao.updateFolder(folder.toEntity())
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun removeWallpaperFromAlbum(
|
||||
albumId: String,
|
||||
wallpaperId: String
|
||||
): Result<Unit> {
|
||||
return try {
|
||||
// Atomic transaction - delete wallpaper, update timestamp, and refresh cover
|
||||
database.withTransaction {
|
||||
val wallpaper = wallpaperDao.getWallpaperById(wallpaperId)
|
||||
wallpaperDao.deleteWallpaperById(wallpaperId)
|
||||
albumDao.updateAlbumModifiedTime(albumId, System.currentTimeMillis())
|
||||
|
||||
// Refresh cover if deleted wallpaper was the cover
|
||||
val album = albumDao.getAlbumById(albumId)
|
||||
if (album?.coverUri == wallpaper?.uri) {
|
||||
updateAlbumCoverIfNeeded(albumId)
|
||||
}
|
||||
}
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun removeWallpapersFromAlbum(
|
||||
albumId: String,
|
||||
wallpaperIds: List<String>
|
||||
): Result<Unit> {
|
||||
return try {
|
||||
if (wallpaperIds.isEmpty()) {
|
||||
return Result.Success(Unit)
|
||||
}
|
||||
|
||||
// Atomic transaction - delete wallpapers, update timestamp, and refresh cover
|
||||
database.withTransaction {
|
||||
val album = albumDao.getAlbumById(albumId)
|
||||
val currentCoverUri = album?.coverUri
|
||||
|
||||
// Batch delete wallpapers
|
||||
wallpaperDao.deleteWallpapersByIds(wallpaperIds)
|
||||
albumDao.updateAlbumModifiedTime(albumId, System.currentTimeMillis())
|
||||
|
||||
// Refresh cover if any deleted wallpaper was the cover
|
||||
// (we check by querying the album cover to see if it still exists)
|
||||
if (currentCoverUri != null) {
|
||||
val coverStillExists = wallpaperDao.getWallpaperByUri(currentCoverUri) != null
|
||||
if (!coverStillExists) {
|
||||
updateAlbumCoverIfNeeded(albumId)
|
||||
}
|
||||
}
|
||||
}
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun removeFolderFromAlbum(albumId: String, folderId: String): Result<Unit> {
|
||||
return try {
|
||||
// Atomic transaction - delete folder, update timestamp, and refresh cover
|
||||
database.withTransaction {
|
||||
folderDao.deleteFolderById(folderId)
|
||||
albumDao.updateAlbumModifiedTime(albumId, System.currentTimeMillis())
|
||||
|
||||
// Always refresh cover after folder deletion (folder wallpapers might be cover)
|
||||
updateAlbumCoverIfNeeded(albumId)
|
||||
}
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getAlbumCount(): Int = albumDao.getAlbumCount()
|
||||
|
||||
override suspend fun deleteAllAlbums(): Result<Unit> {
|
||||
return try {
|
||||
database.withTransaction {
|
||||
albumDao.deleteAllAlbums()
|
||||
wallpaperRepository.get().clearAllQueues()
|
||||
}
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun validateAndRemoveInvalidFolders(albumId: String): Result<Int> {
|
||||
return try {
|
||||
val album = albumDao.getAlbumWithDetails(albumId).first() ?: return Result.Success(0)
|
||||
val folders = album.folders.map { it.toDomainModel() }
|
||||
|
||||
val invalidFolderIds = folders.filter { folder ->
|
||||
// Check if folder URI is still valid
|
||||
val uri = Uri.parse(folder.uri)
|
||||
val documentFile = DocumentFile.fromTreeUri(context, uri)
|
||||
documentFile == null || !documentFile.exists() || !documentFile.canRead()
|
||||
}.map { it.id }
|
||||
|
||||
if (invalidFolderIds.isNotEmpty()) {
|
||||
// Atomic transaction - delete all invalid folders or none
|
||||
database.withTransaction {
|
||||
invalidFolderIds.forEach { folderId ->
|
||||
folderDao.deleteFolderById(folderId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Result.Success(invalidFolderIds.size)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun refreshAlbumCover(albumId: String): Result<Unit> {
|
||||
return try {
|
||||
database.withTransaction {
|
||||
updateAlbumCoverIfNeeded(albumId)
|
||||
}
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun refreshFolderCovers(albumId: String): Result<Unit> {
|
||||
return try {
|
||||
// Get all folders in the album with their wallpapers
|
||||
val folders = folderDao.getFoldersWithWallpapersByAlbum(albumId).first()
|
||||
|
||||
// Update each folder's cover to its first wallpaper
|
||||
folders.forEach { folderWithWallpapers ->
|
||||
val folder = folderWithWallpapers.folder
|
||||
val wallpapers = folderWithWallpapers.wallpapers
|
||||
val newCoverUri = wallpapers.firstOrNull()?.uri
|
||||
|
||||
// Only update if cover changed
|
||||
if (folder.coverUri != newCoverUri) {
|
||||
folderDao.updateFolderCover(folder.id, newCoverUri)
|
||||
}
|
||||
}
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update album cover art based on available wallpapers
|
||||
* Priority: 1) First direct wallpaper, 2) First wallpaper from first folder
|
||||
* NOTE: This must be called within a transaction
|
||||
*/
|
||||
private suspend fun updateAlbumCoverIfNeeded(albumId: String) {
|
||||
val album = albumDao.getAlbumById(albumId) ?: return
|
||||
|
||||
// Try to get first direct wallpaper (uploaded directly, not from folder)
|
||||
val directWallpapers = wallpaperDao.getDirectWallpapersByAlbumSync(albumId)
|
||||
val newCoverUri = when {
|
||||
// Priority 1: First direct wallpaper
|
||||
directWallpapers.isNotEmpty() -> directWallpapers.first().uri
|
||||
|
||||
// Priority 2: First wallpaper from any folder
|
||||
else -> {
|
||||
val allWallpapers = wallpaperDao.getWallpapersByAlbumSync(albumId)
|
||||
allWallpapers.firstOrNull()?.uri
|
||||
}
|
||||
}
|
||||
|
||||
// Only update if cover changed
|
||||
if (album.coverUri != newCoverUri) {
|
||||
albumDao.updateAlbumCover(albumId, newCoverUri, System.currentTimeMillis())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.anthonyla.paperize.data.repository
|
||||
|
||||
import com.anthonyla.paperize.core.WallpaperMode
|
||||
import com.anthonyla.paperize.data.datastore.PreferencesManager
|
||||
import com.anthonyla.paperize.domain.model.AppSettings
|
||||
import com.anthonyla.paperize.domain.model.ScheduleSettings
|
||||
import com.anthonyla.paperize.domain.repository.SettingsRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Implementation of SettingsRepository
|
||||
*/
|
||||
@Singleton
|
||||
class SettingsRepositoryImpl @Inject constructor(
|
||||
private val preferencesManager: PreferencesManager
|
||||
) : SettingsRepository {
|
||||
|
||||
override suspend fun getAppSettings(): AppSettings =
|
||||
preferencesManager.getAppSettings()
|
||||
|
||||
override fun getAppSettingsFlow(): Flow<AppSettings> =
|
||||
preferencesManager.getAppSettingsFlow()
|
||||
|
||||
override suspend fun updateAppSettings(settings: AppSettings) =
|
||||
preferencesManager.updateAppSettings(settings)
|
||||
|
||||
override suspend fun getWallpaperMode(): WallpaperMode =
|
||||
preferencesManager.getWallpaperMode()
|
||||
|
||||
override fun getWallpaperModeFlow(): Flow<WallpaperMode> =
|
||||
preferencesManager.getWallpaperModeFlow()
|
||||
|
||||
override suspend fun updateWallpaperMode(mode: WallpaperMode) =
|
||||
preferencesManager.updateWallpaperMode(mode)
|
||||
|
||||
override suspend fun getScheduleSettings(): ScheduleSettings =
|
||||
preferencesManager.getScheduleSettings()
|
||||
|
||||
override fun getScheduleSettingsFlow(): Flow<ScheduleSettings> =
|
||||
preferencesManager.getScheduleSettingsFlow()
|
||||
|
||||
override suspend fun updateScheduleSettings(settings: ScheduleSettings) =
|
||||
preferencesManager.updateScheduleSettings(settings)
|
||||
|
||||
override suspend fun clearAllSettings() =
|
||||
preferencesManager.clear()
|
||||
|
||||
override suspend fun clearScheduleSettings() =
|
||||
preferencesManager.clearScheduleSettings()
|
||||
|
||||
override suspend fun updateHomeAlbumId(albumId: String?) =
|
||||
preferencesManager.updateHomeAlbumId(albumId)
|
||||
|
||||
override suspend fun updateLockAlbumId(albumId: String?) =
|
||||
preferencesManager.updateLockAlbumId(albumId)
|
||||
|
||||
override suspend fun updateLiveAlbumId(albumId: String?) =
|
||||
preferencesManager.updateLiveAlbumId(albumId)
|
||||
|
||||
override suspend fun clearAlbumSelectionsIfMatches(albumId: String): Boolean =
|
||||
preferencesManager.clearAlbumSelectionsIfMatches(albumId)
|
||||
|
||||
// ============ Atomic AppSettings Operations ============
|
||||
|
||||
override suspend fun updateDarkMode(enabled: Boolean) =
|
||||
preferencesManager.updateDarkMode(enabled)
|
||||
|
||||
override suspend fun updateDynamicTheming(enabled: Boolean) =
|
||||
preferencesManager.updateDynamicTheming(enabled)
|
||||
|
||||
override suspend fun updateAnimate(enabled: Boolean) =
|
||||
preferencesManager.updateAnimate(enabled)
|
||||
|
||||
override suspend fun updateFirstLaunch(isFirstLaunch: Boolean) =
|
||||
preferencesManager.updateFirstLaunch(isFirstLaunch)
|
||||
|
||||
// ============ Atomic ScheduleSettings Operations ============
|
||||
|
||||
override suspend fun updateEnableChanger(enabled: Boolean) =
|
||||
preferencesManager.updateEnableChanger(enabled)
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
package com.anthonyla.paperize.data.repository
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import com.anthonyla.paperize.core.Result
|
||||
import com.anthonyla.paperize.core.ScreenType
|
||||
import com.anthonyla.paperize.core.WallpaperSourceType
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
import com.anthonyla.paperize.core.util.generateId
|
||||
import com.anthonyla.paperize.core.util.isValid
|
||||
import com.anthonyla.paperize.data.database.dao.WallpaperDao
|
||||
import com.anthonyla.paperize.data.database.dao.WallpaperQueueDao
|
||||
import com.anthonyla.paperize.data.mapper.toDomainModel
|
||||
import com.anthonyla.paperize.data.mapper.toDomainModels
|
||||
import com.anthonyla.paperize.data.mapper.toEntity
|
||||
import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.domain.repository.WallpaperRepository
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
/**
|
||||
* Implementation of WallpaperRepository
|
||||
*/
|
||||
@Singleton
|
||||
class WallpaperRepositoryImpl @Inject constructor(
|
||||
@param:ApplicationContext private val context: Context,
|
||||
private val wallpaperDao: WallpaperDao,
|
||||
private val wallpaperQueueDao: WallpaperQueueDao
|
||||
) : WallpaperRepository {
|
||||
|
||||
private val contentResolver: ContentResolver = context.contentResolver
|
||||
|
||||
/**
|
||||
* Mutexes to synchronize queue rebuild operations per (albumId, screenType)
|
||||
* Prevents duplicate rebuilds when multiple threads detect empty queue simultaneously
|
||||
*/
|
||||
private val queueRebuildMutexes = ConcurrentHashMap<String, Mutex>()
|
||||
|
||||
override fun getWallpapersByAlbum(albumId: String): Flow<List<Wallpaper>> =
|
||||
wallpaperDao.getWallpapersByAlbum(albumId).map { it.toDomainModels() }
|
||||
|
||||
override fun getDirectWallpapersByAlbum(albumId: String): Flow<List<Wallpaper>> =
|
||||
wallpaperDao.getDirectWallpapersByAlbum(albumId).map { it.toDomainModels() }
|
||||
|
||||
override fun getWallpapersByFolder(folderId: String): Flow<List<Wallpaper>> =
|
||||
wallpaperDao.getWallpapersByFolder(folderId).map { it.toDomainModels() }
|
||||
|
||||
override suspend fun getWallpaperById(wallpaperId: String): Wallpaper? =
|
||||
wallpaperDao.getWallpaperById(wallpaperId)?.toDomainModel()
|
||||
|
||||
override suspend fun addWallpaper(wallpaper: Wallpaper): Result<Unit> {
|
||||
return try {
|
||||
wallpaperDao.insertWallpaper(wallpaper.toEntity())
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updateWallpaper(wallpaper: Wallpaper): Result<Unit> {
|
||||
return try {
|
||||
wallpaperDao.updateWallpaper(wallpaper.toEntity())
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteWallpaper(wallpaperId: String): Result<Unit> {
|
||||
return try {
|
||||
wallpaperDao.deleteWallpaperById(wallpaperId)
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteWallpapers(wallpaperIds: List<String>): Result<Unit> {
|
||||
return try {
|
||||
if (wallpaperIds.isEmpty()) {
|
||||
return Result.Success(Unit)
|
||||
}
|
||||
wallpaperDao.deleteWallpapersByIds(wallpaperIds)
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteWallpapersByFolderId(folderId: String): Result<Unit> {
|
||||
return try {
|
||||
wallpaperDao.deleteWallpapersByFolder(folderId)
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun updateWallpaperOrder(wallpaperId: String, order: Int): Result<Unit> {
|
||||
return try {
|
||||
wallpaperDao.updateWallpaperOrder(wallpaperId, order)
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun validateAndRemoveInvalidWallpapers(albumId: String): Result<Int> {
|
||||
return try {
|
||||
val totalCount = wallpaperDao.getWallpaperCountByAlbum(albumId)
|
||||
var totalRemoved = 0
|
||||
val batchSize = 100 // Process in smaller batches to avoid memory spikes
|
||||
|
||||
for (offset in 0 until totalCount step batchSize) {
|
||||
val wallpapers = wallpaperDao.getWallpapersByAlbumPaged(albumId, batchSize, offset)
|
||||
val invalidUris = wallpapers
|
||||
.filter { !it.uri.toUri().isValid(contentResolver) }
|
||||
.map { it.uri }
|
||||
|
||||
if (invalidUris.isNotEmpty()) {
|
||||
wallpaperDao.deleteWallpapersByUris(invalidUris)
|
||||
totalRemoved += invalidUris.size
|
||||
}
|
||||
}
|
||||
|
||||
Result.Success(totalRemoved)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getNextWallpaperInQueue(albumId: String, screenType: ScreenType): Wallpaper? =
|
||||
wallpaperQueueDao.getNextWallpaperInQueue(albumId, screenType)?.toDomainModel()
|
||||
|
||||
override suspend fun getAndDequeueWallpaper(albumId: String, screenType: ScreenType): Wallpaper? =
|
||||
wallpaperQueueDao.getAndDequeueWallpaper(albumId, screenType)?.toDomainModel()
|
||||
|
||||
override suspend fun buildWallpaperQueue(
|
||||
albumId: String,
|
||||
screenType: ScreenType,
|
||||
shuffle: Boolean
|
||||
): Result<Unit> {
|
||||
// In shuffle mode, use album-level mutex to ensure synchronized shuffle order
|
||||
// In sequential mode, use per-screen mutex for independent rebuilds
|
||||
val mutexKey = if (shuffle) albumId else "$albumId:$screenType"
|
||||
val mutex = queueRebuildMutexes.getOrPut(mutexKey) { Mutex() }
|
||||
|
||||
return mutex.withLock {
|
||||
try {
|
||||
val wallpapers = wallpaperDao.getWallpapersByAlbum(albumId).first()
|
||||
|
||||
// If shuffle is enabled, check if there's an existing queue for another screen type
|
||||
// with the same album to maintain synchronized order
|
||||
val otherScreenType = if (shuffle) {
|
||||
when (screenType) {
|
||||
ScreenType.HOME -> ScreenType.LOCK
|
||||
ScreenType.LOCK -> ScreenType.HOME
|
||||
ScreenType.BOTH -> null
|
||||
ScreenType.LIVE -> null
|
||||
}
|
||||
} else null
|
||||
|
||||
val otherScreenQueueIds = otherScreenType?.let {
|
||||
try {
|
||||
wallpaperQueueDao.getQueueItems(albumId, it)
|
||||
.map { queueItem -> queueItem.wallpaperId }
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
val wallpaperIds = com.anthonyla.paperize.core.util.QueueBuilder.buildQueue(
|
||||
wallpapers = wallpapers.toDomainModels(),
|
||||
shuffle = shuffle,
|
||||
otherScreenQueue = otherScreenQueueIds
|
||||
)
|
||||
|
||||
wallpaperQueueDao.rebuildQueue(albumId, screenType, wallpaperIds)
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun clearAllQueues(): Result<Unit> {
|
||||
return try {
|
||||
wallpaperQueueDao.deleteAllQueueItems()
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun clearQueuesForAlbum(albumId: String): Result<Unit> {
|
||||
return try {
|
||||
wallpaperQueueDao.clearAllQueues(albumId)
|
||||
|
||||
// Prune mutexes for this album to prevent memory leak
|
||||
// Keys are either albumId (shuffled) or $albumId:$screenType (sequential)
|
||||
queueRebuildMutexes.keys.filter { it.startsWith(albumId) }.forEach {
|
||||
queueRebuildMutexes.remove(it)
|
||||
}
|
||||
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun normalizeAllQueuesForAlbum(albumId: String): Result<Unit> {
|
||||
return try {
|
||||
// Normalize all queue types for this album
|
||||
// This fixes gaps in queue positions caused by CASCADE deletes
|
||||
wallpaperQueueDao.normalizeQueuePositions(albumId, ScreenType.HOME)
|
||||
wallpaperQueueDao.normalizeQueuePositions(albumId, ScreenType.LOCK)
|
||||
wallpaperQueueDao.normalizeQueuePositions(albumId, ScreenType.LIVE)
|
||||
wallpaperQueueDao.normalizeQueuePositions(albumId, ScreenType.BOTH)
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun scanFolderForWallpapers(folderUri: Uri): Result<List<Wallpaper>> {
|
||||
return try {
|
||||
val documentFile = DocumentFile.fromTreeUri(context, folderUri)
|
||||
?: return Result.Error(Exception("Invalid folder URI"))
|
||||
|
||||
val wallpapers = mutableListOf<Wallpaper>()
|
||||
scanDirectoryRecursive(documentFile, wallpapers)
|
||||
|
||||
Result.Success(wallpapers)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun scanDirectoryRecursive(directory: DocumentFile, result: MutableList<Wallpaper>) {
|
||||
directory.listFiles().forEach { file ->
|
||||
if (file.isDirectory) {
|
||||
scanDirectoryRecursive(file, result)
|
||||
} else if (file.isFile && file.name?.let { name -> isImageFile(name) } == true) {
|
||||
try {
|
||||
val uri = file.uri.toString()
|
||||
val fileName = file.name ?: return@forEach
|
||||
val dateModified = file.lastModified()
|
||||
|
||||
result.add(
|
||||
Wallpaper(
|
||||
id = generateId(),
|
||||
albumId = "",
|
||||
folderId = null,
|
||||
uri = uri,
|
||||
fileName = fileName,
|
||||
dateModified = dateModified,
|
||||
sourceType = WallpaperSourceType.FOLDER
|
||||
)
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
// Skip failed items
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun isImageFile(fileName: String): Boolean {
|
||||
val extension = fileName.substringAfterLast('.', "").lowercase()
|
||||
return extension in Constants.SUPPORTED_IMAGE_EXTENSIONS
|
||||
}
|
||||
|
||||
override suspend fun isWallpaperInAlbum(albumId: String, uri: String): Boolean =
|
||||
wallpaperDao.getWallpaperByUri(uri)?.let { it.albumId == albumId } ?: false
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.anthonyla.paperize.data.settings
|
||||
|
||||
/**
|
||||
* Interface for the data store that handles the settings for application
|
||||
*/
|
||||
interface SettingsDataStore {
|
||||
suspend fun putBoolean(key: String, value: Boolean)
|
||||
suspend fun putString(key: String, value: String)
|
||||
suspend fun putInt(key: String, value: Int)
|
||||
suspend fun getBoolean(key: String): Boolean?
|
||||
suspend fun getString(key: String): String?
|
||||
suspend fun getInt(key: String): Int?
|
||||
suspend fun deleteBoolean(key: String)
|
||||
suspend fun deleteString(key: String)
|
||||
suspend fun deleteInt(key: String)
|
||||
suspend fun clearPreferences()
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
package com.anthonyla.paperize.data.settings
|
||||
|
||||
import android.content.Context
|
||||
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.stringPreferencesKey
|
||||
import androidx.datastore.preferences.preferencesDataStore
|
||||
import com.anthonyla.paperize.core.SettingsConstants.SETTINGS_DATASTORE
|
||||
import kotlinx.coroutines.flow.first
|
||||
import javax.inject.Inject
|
||||
|
||||
private val Context.dataStore : DataStore<Preferences> by preferencesDataStore(name = SETTINGS_DATASTORE)
|
||||
class SettingsDataStoreImpl @Inject constructor (private val context: Context): SettingsDataStore {
|
||||
override suspend fun putBoolean(key: String, value: Boolean) {
|
||||
val preferencesKey = booleanPreferencesKey(key)
|
||||
context.dataStore.edit {
|
||||
it[preferencesKey] = value
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun putString(key: String, value: String) {
|
||||
val preferencesKey = stringPreferencesKey(key)
|
||||
context.dataStore.edit {
|
||||
it[preferencesKey] = value
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun putInt(key: String, value: Int) {
|
||||
val preferencesKey = stringPreferencesKey(key)
|
||||
context.dataStore.edit {
|
||||
it[preferencesKey] = value.toString()
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getBoolean(key: String): Boolean? {
|
||||
val head = context.dataStore.data.first()
|
||||
val preferencesKey = booleanPreferencesKey(key)
|
||||
return head[preferencesKey]
|
||||
}
|
||||
|
||||
override suspend fun getString(key: String): String? {
|
||||
return try {
|
||||
val head = context.dataStore.data.first()
|
||||
val preferencesKey = stringPreferencesKey(key)
|
||||
head[preferencesKey]
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getInt(key: String): Int? {
|
||||
return try {
|
||||
val head = context.dataStore.data.first()
|
||||
val preferencesKey = stringPreferencesKey(key)
|
||||
head[preferencesKey]?.toInt()
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteBoolean(key: String) {
|
||||
val preferencesKey = booleanPreferencesKey(key)
|
||||
context.dataStore.edit {
|
||||
if (it.contains(preferencesKey)) {
|
||||
it.remove(preferencesKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteString(key: String) {
|
||||
val preferencesKey = stringPreferencesKey(key)
|
||||
context.dataStore.edit {
|
||||
if (it.contains(preferencesKey)) {
|
||||
it.remove(preferencesKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteInt(key: String) {
|
||||
val preferencesKey = stringPreferencesKey(key)
|
||||
context.dataStore.edit {
|
||||
if (it.contains(preferencesKey)) {
|
||||
it.remove(preferencesKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun clearPreferences() {
|
||||
context.dataStore.edit {
|
||||
it.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package com.anthonyla.paperize.di
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
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
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* AppModule provides dependencies for the application for Dagger Hilt to inject
|
||||
*/
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object AppModule {
|
||||
@Provides
|
||||
@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()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideAlbumDao(db: AlbumDatabase) = db.albumDao
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideAlbumRepository(
|
||||
db: AlbumDatabase
|
||||
): AlbumRepository {
|
||||
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 (
|
||||
@ApplicationContext context: Context
|
||||
): SettingsDataStore = SettingsDataStoreImpl(context)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideContext(
|
||||
@ApplicationContext context: Context,
|
||||
): Context { return context }
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.anthonyla.paperize.domain.model
|
||||
|
||||
/**
|
||||
* Domain model for Album
|
||||
*
|
||||
* Pure Kotlin data class without Room annotations
|
||||
*/
|
||||
data class Album(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val coverUri: String?,
|
||||
val wallpapers: List<Wallpaper> = emptyList(),
|
||||
val folders: List<Folder> = emptyList(),
|
||||
val createdAt: Long = System.currentTimeMillis(),
|
||||
val modifiedAt: Long = System.currentTimeMillis()
|
||||
) {
|
||||
/**
|
||||
* Get total wallpaper count (direct + in folders)
|
||||
*/
|
||||
val totalWallpaperCount: Int
|
||||
get() = wallpapers.size + folders.sumOf { it.wallpapers.size }
|
||||
|
||||
/**
|
||||
* Get all wallpapers (direct + from folders)
|
||||
*/
|
||||
val allWallpapers: List<Wallpaper>
|
||||
get() = wallpapers + folders.flatMap { it.wallpapers }
|
||||
|
||||
/**
|
||||
* Get all wallpapers sorted by display order
|
||||
*/
|
||||
val sortedWallpapers: List<Wallpaper>
|
||||
get() = allWallpapers.sortedBy { it.displayOrder }
|
||||
|
||||
/**
|
||||
* Check if album is empty
|
||||
*/
|
||||
val isEmpty: Boolean
|
||||
get() = totalWallpaperCount == 0
|
||||
|
||||
companion object {
|
||||
fun empty(id: String = "", name: String = "") = Album(
|
||||
id = id,
|
||||
name = name,
|
||||
coverUri = null
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.anthonyla.paperize.domain.model
|
||||
|
||||
/**
|
||||
* Lightweight summary of an Album for list displays.
|
||||
* Prevents loading potentially thousands of Wallpaper objects into memory
|
||||
* when just displaying a list of albums.
|
||||
*/
|
||||
data class AlbumSummary(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val coverUri: String?,
|
||||
val wallpaperCount: Int,
|
||||
val folderCount: Int,
|
||||
val createdAt: Long,
|
||||
val modifiedAt: Long
|
||||
) {
|
||||
/**
|
||||
* Check if album is empty without a full object load
|
||||
*/
|
||||
val isEmpty: Boolean
|
||||
get() = wallpaperCount == 0
|
||||
|
||||
companion object {
|
||||
fun empty(id: String = "", name: String = "") = AlbumSummary(
|
||||
id = id,
|
||||
name = name,
|
||||
coverUri = null,
|
||||
wallpaperCount = 0,
|
||||
folderCount = 0,
|
||||
createdAt = System.currentTimeMillis(),
|
||||
modifiedAt = System.currentTimeMillis()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.anthonyla.paperize.domain.model
|
||||
|
||||
/**
|
||||
* Domain model for App Settings (theme, preferences, etc.)
|
||||
*/
|
||||
data class AppSettings(
|
||||
val darkMode: Boolean? = null, // null = system default, true = dark, false = light
|
||||
val dynamicTheming: Boolean = true,
|
||||
val animate: Boolean = true,
|
||||
val firstLaunch: Boolean = true,
|
||||
val currentHomeWallpaperId: String? = null,
|
||||
val currentLockWallpaperId: String? = null
|
||||
) {
|
||||
companion object {
|
||||
fun default() = AppSettings()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.anthonyla.paperize.domain.model
|
||||
|
||||
import android.net.Uri
|
||||
|
||||
/**
|
||||
* Domain model for Folder
|
||||
*
|
||||
* Pure Kotlin data class without Room annotations
|
||||
*/
|
||||
data class Folder(
|
||||
val id: String,
|
||||
val albumId: String,
|
||||
val name: String,
|
||||
val uri: String,
|
||||
val coverUri: String?,
|
||||
val dateModified: Long,
|
||||
val displayOrder: Int = 0,
|
||||
val wallpapers: List<Wallpaper> = emptyList(),
|
||||
val addedAt: Long = System.currentTimeMillis()
|
||||
) {
|
||||
/**
|
||||
* Get URL-decoded name for display (last path segment only)
|
||||
*/
|
||||
val displayName: String
|
||||
get() = try {
|
||||
val decoded = Uri.decode(name)
|
||||
// Extract just the folder name (last segment after / or :)
|
||||
decoded.substringAfterLast('/', decoded.substringAfterLast(':', decoded))
|
||||
} catch (e: Exception) {
|
||||
name
|
||||
}
|
||||
|
||||
/**
|
||||
* Get wallpaper count
|
||||
*/
|
||||
val wallpaperCount: Int
|
||||
get() = wallpapers.size
|
||||
|
||||
/**
|
||||
* Check if folder is empty
|
||||
*/
|
||||
val isEmpty: Boolean
|
||||
get() = wallpapers.isEmpty()
|
||||
|
||||
/**
|
||||
* Get sorted wallpapers
|
||||
*/
|
||||
val sortedWallpapers: List<Wallpaper>
|
||||
get() = wallpapers.sortedBy { it.displayOrder }
|
||||
|
||||
companion object {
|
||||
fun empty(id: String = "", albumId: String = "") = Folder(
|
||||
id = id,
|
||||
albumId = albumId,
|
||||
name = "",
|
||||
uri = "",
|
||||
coverUri = null,
|
||||
dateModified = 0L
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.anthonyla.paperize.domain.model
|
||||
|
||||
import com.anthonyla.paperize.core.ScalingType
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
|
||||
/**
|
||||
* Domain model for Wallpaper Schedule Settings
|
||||
*/
|
||||
data class ScheduleSettings(
|
||||
val enableChanger: Boolean = false,
|
||||
val separateSchedules: Boolean = false,
|
||||
val shuffleEnabled: Boolean = false,
|
||||
val homeEnabled: Boolean = false,
|
||||
val lockEnabled: Boolean = false,
|
||||
val homeAlbumId: String? = null,
|
||||
val lockAlbumId: String? = null,
|
||||
val homeIntervalMinutes: Int = Constants.DEFAULT_INTERVAL_MINUTES,
|
||||
val lockIntervalMinutes: Int = Constants.DEFAULT_INTERVAL_MINUTES,
|
||||
val liveIntervalMinutes: Int = Constants.DEFAULT_INTERVAL_MINUTES,
|
||||
val homeScalingType: ScalingType = ScalingType.FILL,
|
||||
val lockScalingType: ScalingType = ScalingType.FILL,
|
||||
val homeEffects: WallpaperEffects = WallpaperEffects.none(),
|
||||
val lockEffects: WallpaperEffects = WallpaperEffects.none(),
|
||||
val liveAlbumId: String? = null,
|
||||
val liveScalingType: ScalingType = ScalingType.FILL,
|
||||
val liveEffects: WallpaperEffects = WallpaperEffects.none(),
|
||||
val adaptiveBrightness: Boolean = false
|
||||
) {
|
||||
/**
|
||||
* Validate interval values
|
||||
*/
|
||||
fun validate(): ScheduleSettings = copy(
|
||||
homeIntervalMinutes = homeIntervalMinutes.coerceAtLeast(Constants.MIN_INTERVAL_MINUTES),
|
||||
lockIntervalMinutes = lockIntervalMinutes.coerceAtLeast(Constants.MIN_INTERVAL_MINUTES),
|
||||
liveIntervalMinutes = liveIntervalMinutes.coerceAtLeast(Constants.MIN_INTERVAL_MINUTES),
|
||||
homeEffects = homeEffects.validate(),
|
||||
lockEffects = lockEffects.validate(),
|
||||
liveEffects = liveEffects.validate()
|
||||
)
|
||||
|
||||
/**
|
||||
* Check if scheduling-related settings changed (not just display settings)
|
||||
*
|
||||
* Returns true if any of these changed:
|
||||
* - Screen enable/disable
|
||||
* - Interval timing
|
||||
* - Separate schedules toggle
|
||||
* - Shuffle (handled separately with queue clearing)
|
||||
*
|
||||
* Display-only settings (scaling, effects, adaptive brightness) don't affect scheduling
|
||||
*/
|
||||
fun hasSchedulingChanges(other: ScheduleSettings): Boolean {
|
||||
return homeEnabled != other.homeEnabled ||
|
||||
lockEnabled != other.lockEnabled ||
|
||||
homeIntervalMinutes != other.homeIntervalMinutes ||
|
||||
lockIntervalMinutes != other.lockIntervalMinutes ||
|
||||
separateSchedules != other.separateSchedules ||
|
||||
liveIntervalMinutes != other.liveIntervalMinutes
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if display settings changed (scaling, effects, adaptive brightness)
|
||||
*
|
||||
* When these change, we should reapply the current wallpaper immediately
|
||||
* to show the user the effect, but we don't need to reschedule WorkManager
|
||||
*/
|
||||
fun hasDisplayChanges(other: ScheduleSettings): Boolean {
|
||||
return homeScalingType != other.homeScalingType ||
|
||||
lockScalingType != other.lockScalingType ||
|
||||
homeEffects != other.homeEffects ||
|
||||
lockEffects != other.lockEffects ||
|
||||
liveEffects != other.liveEffects ||
|
||||
liveScalingType != other.liveScalingType ||
|
||||
adaptiveBrightness != other.adaptiveBrightness
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun default() = ScheduleSettings()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.anthonyla.paperize.domain.model
|
||||
|
||||
import android.net.Uri
|
||||
import com.anthonyla.paperize.core.WallpaperMediaType
|
||||
import com.anthonyla.paperize.core.WallpaperSourceType
|
||||
|
||||
/**
|
||||
* Domain model for Wallpaper
|
||||
*
|
||||
* Pure Kotlin data class without Room annotations
|
||||
*/
|
||||
data class Wallpaper(
|
||||
val id: String,
|
||||
val albumId: String,
|
||||
val folderId: String? = null,
|
||||
val uri: String,
|
||||
val fileName: String,
|
||||
val dateModified: Long,
|
||||
val displayOrder: Int = 0,
|
||||
val sourceType: WallpaperSourceType = WallpaperSourceType.DIRECT,
|
||||
val addedAt: Long = System.currentTimeMillis(),
|
||||
val mediaType: WallpaperMediaType = WallpaperMediaType.IMAGE
|
||||
) {
|
||||
/**
|
||||
* Get URL-decoded file name for display (filename only, no path)
|
||||
*/
|
||||
val displayFileName: String
|
||||
get() = try {
|
||||
val decoded = Uri.decode(fileName)
|
||||
// Extract just the filename (last segment after / or :)
|
||||
decoded.substringAfterLast('/', decoded.substringAfterLast(':', decoded))
|
||||
} catch (e: Exception) {
|
||||
fileName
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if wallpaper is from a folder
|
||||
*/
|
||||
val isFromFolder: Boolean
|
||||
get() = folderId != null && sourceType == WallpaperSourceType.FOLDER
|
||||
|
||||
/**
|
||||
* Get file extension
|
||||
*/
|
||||
val extension: String
|
||||
get() = fileName.substringAfterLast('.', "").lowercase()
|
||||
|
||||
/**
|
||||
* Check if file is a valid image
|
||||
*/
|
||||
val isValidImage: Boolean
|
||||
get() = extension in setOf("jpg", "jpeg", "png", "webp", "avif")
|
||||
|
||||
companion object {
|
||||
fun empty(id: String = "", albumId: String = "") = Wallpaper(
|
||||
id = id,
|
||||
albumId = albumId,
|
||||
uri = "",
|
||||
fileName = "",
|
||||
dateModified = 0L
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.anthonyla.paperize.domain.model
|
||||
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
|
||||
/**
|
||||
* Domain model for Wallpaper Effects
|
||||
*
|
||||
* Represents the visual effects applied to wallpapers
|
||||
* Includes both visual effects (blur, darken, etc.) and interactive effects (double-tap, parallax)
|
||||
*/
|
||||
data class WallpaperEffects(
|
||||
// Visual effects (available in both static and live modes)
|
||||
val enableBlur: Boolean = false,
|
||||
val blurPercentage: Int = Constants.DEFAULT_BLUR_PERCENTAGE,
|
||||
val enableDarken: Boolean = false,
|
||||
val darkenPercentage: Int = Constants.DEFAULT_DARKEN_PERCENTAGE,
|
||||
val enableVignette: Boolean = false,
|
||||
val vignettePercentage: Int = Constants.DEFAULT_VIGNETTE_PERCENTAGE,
|
||||
val enableGrayscale: Boolean = false,
|
||||
val grayscalePercentage: Int = Constants.DEFAULT_GRAYSCALE_PERCENTAGE,
|
||||
|
||||
// Interactive effects (live wallpaper mode only)
|
||||
val enableDoubleTap: Boolean = false,
|
||||
val enableChangeOnScreenOn: Boolean = false,
|
||||
val enableParallax: Boolean = false,
|
||||
val parallaxIntensity: Int = Constants.DEFAULT_PARALLAX_INTENSITY
|
||||
) {
|
||||
/**
|
||||
* Check if any effects are applied
|
||||
*/
|
||||
val hasEffects: Boolean
|
||||
get() = (enableBlur && blurPercentage > 0) ||
|
||||
(enableDarken && darkenPercentage > 0) ||
|
||||
(enableVignette && vignettePercentage > 0) ||
|
||||
(enableGrayscale && grayscalePercentage > 0)
|
||||
|
||||
/**
|
||||
* Validate effect percentages
|
||||
*/
|
||||
fun validate(): WallpaperEffects = copy(
|
||||
darkenPercentage = darkenPercentage.coerceIn(0, 100),
|
||||
blurPercentage = blurPercentage.coerceIn(0, 100),
|
||||
vignettePercentage = vignettePercentage.coerceIn(0, 100),
|
||||
grayscalePercentage = grayscalePercentage.coerceIn(0, 100),
|
||||
parallaxIntensity = parallaxIntensity.coerceIn(0, 100)
|
||||
)
|
||||
|
||||
companion object {
|
||||
fun default() = WallpaperEffects()
|
||||
fun none() = WallpaperEffects()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.anthonyla.paperize.domain.repository
|
||||
|
||||
import com.anthonyla.paperize.core.Result
|
||||
import com.anthonyla.paperize.domain.model.Album
|
||||
import com.anthonyla.paperize.domain.model.AlbumSummary
|
||||
import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.domain.model.Folder
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Repository interface for Album operations
|
||||
*
|
||||
* Clean interface following repository pattern - implementation in data layer
|
||||
*/
|
||||
interface AlbumRepository {
|
||||
/**
|
||||
* Get all album summaries (lightweight metadata + counts)
|
||||
*/
|
||||
fun getAlbumSummaries(): Flow<List<AlbumSummary>>
|
||||
|
||||
/**
|
||||
* Get all albums with their wallpapers and folders
|
||||
*/
|
||||
fun getAllAlbums(): Flow<List<Album>>
|
||||
|
||||
/**
|
||||
* Get a specific album by ID
|
||||
*/
|
||||
fun getAlbumById(albumId: String): Flow<Album?>
|
||||
|
||||
/**
|
||||
* Get a specific album by name
|
||||
*/
|
||||
suspend fun getAlbumByName(name: String): Album?
|
||||
|
||||
/**
|
||||
* Get a specific folder by ID
|
||||
*/
|
||||
fun getFolderById(folderId: String): Flow<Folder?>
|
||||
|
||||
/**
|
||||
* Create a new album
|
||||
*/
|
||||
suspend fun createAlbum(name: String, coverUri: String? = null): Result<Album>
|
||||
|
||||
/**
|
||||
* Update album
|
||||
*/
|
||||
suspend fun updateAlbum(album: Album): Result<Unit>
|
||||
|
||||
/**
|
||||
* Delete album
|
||||
*/
|
||||
suspend fun deleteAlbum(albumId: String): Result<Unit>
|
||||
|
||||
/**
|
||||
* Update album name
|
||||
*/
|
||||
suspend fun updateAlbumName(albumId: String, name: String): Result<Unit>
|
||||
|
||||
/**
|
||||
* Update album cover
|
||||
*/
|
||||
suspend fun updateAlbumCover(albumId: String, coverUri: String?): Result<Unit>
|
||||
|
||||
/**
|
||||
* Add wallpapers to album
|
||||
*/
|
||||
suspend fun addWallpapersToAlbum(
|
||||
albumId: String,
|
||||
wallpapers: List<Wallpaper>
|
||||
): Result<Unit>
|
||||
|
||||
/**
|
||||
* Add folder to album
|
||||
*/
|
||||
suspend fun addFolderToAlbum(albumId: String, folder: Folder): Result<Unit>
|
||||
|
||||
/**
|
||||
* Update folder
|
||||
*/
|
||||
suspend fun updateFolder(folder: Folder): Result<Unit>
|
||||
|
||||
/**
|
||||
* Remove wallpaper from album
|
||||
*/
|
||||
suspend fun removeWallpaperFromAlbum(albumId: String, wallpaperId: String): Result<Unit>
|
||||
|
||||
/**
|
||||
* Remove multiple wallpapers from album (batch operation)
|
||||
* Updates album modified time and refreshes cover art
|
||||
*/
|
||||
suspend fun removeWallpapersFromAlbum(albumId: String, wallpaperIds: List<String>): Result<Unit>
|
||||
|
||||
/**
|
||||
* Remove folder from album
|
||||
*/
|
||||
suspend fun removeFolderFromAlbum(albumId: String, folderId: String): Result<Unit>
|
||||
|
||||
/**
|
||||
* Get album count
|
||||
*/
|
||||
suspend fun getAlbumCount(): Int
|
||||
|
||||
/**
|
||||
* Delete all albums
|
||||
*/
|
||||
suspend fun deleteAllAlbums(): Result<Unit>
|
||||
|
||||
/**
|
||||
* Validate folder URIs and remove invalid ones
|
||||
* Returns number of folders removed
|
||||
*/
|
||||
suspend fun validateAndRemoveInvalidFolders(albumId: String): Result<Int>
|
||||
|
||||
/**
|
||||
* Refresh album cover art based on current wallpapers
|
||||
*/
|
||||
suspend fun refreshAlbumCover(albumId: String): Result<Unit>
|
||||
|
||||
/**
|
||||
* Refresh all folder covers in an album based on their current wallpapers
|
||||
*/
|
||||
suspend fun refreshFolderCovers(albumId: String): Result<Unit>
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.anthonyla.paperize.domain.repository
|
||||
|
||||
import com.anthonyla.paperize.core.WallpaperMode
|
||||
import com.anthonyla.paperize.domain.model.AppSettings
|
||||
import com.anthonyla.paperize.domain.model.ScheduleSettings
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Repository interface for Settings operations
|
||||
*/
|
||||
interface SettingsRepository {
|
||||
/**
|
||||
* Get app settings
|
||||
*/
|
||||
suspend fun getAppSettings(): AppSettings
|
||||
|
||||
/**
|
||||
* Get app settings as Flow
|
||||
*/
|
||||
fun getAppSettingsFlow(): Flow<AppSettings>
|
||||
|
||||
/**
|
||||
* Update app settings
|
||||
*/
|
||||
suspend fun updateAppSettings(settings: AppSettings)
|
||||
|
||||
/**
|
||||
* Get wallpaper mode (STATIC or LIVE)
|
||||
*/
|
||||
suspend fun getWallpaperMode(): WallpaperMode
|
||||
|
||||
/**
|
||||
* Get wallpaper mode as Flow
|
||||
*/
|
||||
fun getWallpaperModeFlow(): Flow<WallpaperMode>
|
||||
|
||||
/**
|
||||
* Update wallpaper mode
|
||||
* IMPORTANT: Caller must handle data reset when switching modes
|
||||
*/
|
||||
suspend fun updateWallpaperMode(mode: WallpaperMode)
|
||||
|
||||
/**
|
||||
* Get schedule settings
|
||||
*/
|
||||
suspend fun getScheduleSettings(): ScheduleSettings
|
||||
|
||||
/**
|
||||
* Get schedule settings as Flow
|
||||
*/
|
||||
fun getScheduleSettingsFlow(): Flow<ScheduleSettings>
|
||||
|
||||
/**
|
||||
* Update schedule settings
|
||||
*/
|
||||
suspend fun updateScheduleSettings(settings: ScheduleSettings)
|
||||
|
||||
/**
|
||||
* Clear all settings
|
||||
*/
|
||||
suspend fun clearAllSettings()
|
||||
|
||||
/**
|
||||
* Clear schedule settings (reset to defaults)
|
||||
* Used when switching wallpaper modes to reset all scheduling configuration
|
||||
*/
|
||||
suspend fun clearScheduleSettings()
|
||||
|
||||
/**
|
||||
* Set wallpaper mode (wrapper for updateWallpaperMode)
|
||||
*/
|
||||
suspend fun setWallpaperMode(mode: WallpaperMode) = updateWallpaperMode(mode)
|
||||
|
||||
/**
|
||||
* Atomically update home album ID to prevent race conditions
|
||||
* Use this instead of updateScheduleSettings when only changing home album
|
||||
*/
|
||||
suspend fun updateHomeAlbumId(albumId: String?)
|
||||
|
||||
/**
|
||||
* Atomically update lock album ID to prevent race conditions
|
||||
* Use this instead of updateScheduleSettings when only changing lock album
|
||||
*/
|
||||
suspend fun updateLockAlbumId(albumId: String?)
|
||||
|
||||
/**
|
||||
* Atomically update live album ID to prevent race conditions
|
||||
* Use this instead of updateScheduleSettings when only changing live album
|
||||
*/
|
||||
suspend fun updateLiveAlbumId(albumId: String?)
|
||||
|
||||
/**
|
||||
* Atomically clear album selections if they match the given album ID
|
||||
* Used when deleting an album to prevent race conditions
|
||||
* Returns true if any selections were cleared
|
||||
*/
|
||||
suspend fun clearAlbumSelectionsIfMatches(albumId: String): Boolean
|
||||
|
||||
// ============ Atomic AppSettings Operations ============
|
||||
|
||||
suspend fun updateDarkMode(enabled: Boolean)
|
||||
suspend fun updateDynamicTheming(enabled: Boolean)
|
||||
suspend fun updateAnimate(enabled: Boolean)
|
||||
suspend fun updateFirstLaunch(isFirstLaunch: Boolean)
|
||||
|
||||
// ============ Atomic ScheduleSettings Operations ============
|
||||
|
||||
/**
|
||||
* Atomically update enableChanger to prevent race conditions
|
||||
* Use this instead of updateScheduleSettings when only toggling changer
|
||||
*/
|
||||
suspend fun updateEnableChanger(enabled: Boolean)
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package com.anthonyla.paperize.domain.repository
|
||||
|
||||
import android.net.Uri
|
||||
import com.anthonyla.paperize.core.Result
|
||||
import com.anthonyla.paperize.core.ScreenType
|
||||
import com.anthonyla.paperize.domain.model.Wallpaper
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Repository interface for Wallpaper operations
|
||||
*/
|
||||
interface WallpaperRepository {
|
||||
/**
|
||||
* Get wallpapers for an album
|
||||
*/
|
||||
fun getWallpapersByAlbum(albumId: String): Flow<List<Wallpaper>>
|
||||
|
||||
/**
|
||||
* Get direct wallpapers for an album (not from folders)
|
||||
*/
|
||||
fun getDirectWallpapersByAlbum(albumId: String): Flow<List<Wallpaper>>
|
||||
|
||||
/**
|
||||
* Get wallpapers for a folder
|
||||
*/
|
||||
fun getWallpapersByFolder(folderId: String): Flow<List<Wallpaper>>
|
||||
|
||||
/**
|
||||
* Get wallpaper by ID
|
||||
*/
|
||||
suspend fun getWallpaperById(wallpaperId: String): Wallpaper?
|
||||
|
||||
/**
|
||||
* Add wallpaper
|
||||
*/
|
||||
suspend fun addWallpaper(wallpaper: Wallpaper): Result<Unit>
|
||||
|
||||
/**
|
||||
* Update wallpaper
|
||||
*/
|
||||
suspend fun updateWallpaper(wallpaper: Wallpaper): Result<Unit>
|
||||
|
||||
/**
|
||||
* Delete wallpaper
|
||||
*/
|
||||
suspend fun deleteWallpaper(wallpaperId: String): Result<Unit>
|
||||
|
||||
/**
|
||||
* Delete multiple wallpapers by IDs (batch operation)
|
||||
*/
|
||||
suspend fun deleteWallpapers(wallpaperIds: List<String>): Result<Unit>
|
||||
|
||||
/**
|
||||
* Delete all wallpapers in a folder
|
||||
*/
|
||||
suspend fun deleteWallpapersByFolderId(folderId: String): Result<Unit>
|
||||
|
||||
/**
|
||||
* Update wallpaper order
|
||||
*/
|
||||
suspend fun updateWallpaperOrder(wallpaperId: String, order: Int): Result<Unit>
|
||||
|
||||
/**
|
||||
* Validate wallpaper URIs and remove invalid ones
|
||||
*/
|
||||
suspend fun validateAndRemoveInvalidWallpapers(albumId: String): Result<Int>
|
||||
|
||||
/**
|
||||
* Get next wallpaper in queue
|
||||
*/
|
||||
suspend fun getNextWallpaperInQueue(albumId: String, screenType: ScreenType): Wallpaper?
|
||||
|
||||
/**
|
||||
* Atomically get and remove next wallpaper from queue
|
||||
* Prevents race conditions when multiple wallpaper changes happen simultaneously
|
||||
*/
|
||||
suspend fun getAndDequeueWallpaper(albumId: String, screenType: ScreenType): Wallpaper?
|
||||
|
||||
/**
|
||||
* Build wallpaper queue for album
|
||||
*/
|
||||
suspend fun buildWallpaperQueue(
|
||||
albumId: String,
|
||||
screenType: ScreenType,
|
||||
shuffle: Boolean = false
|
||||
): Result<Unit>
|
||||
|
||||
/**
|
||||
* Clear all queues for all albums
|
||||
* Used when shuffle setting changes to force rebuild with new mode
|
||||
*/
|
||||
suspend fun clearAllQueues(): Result<Unit>
|
||||
|
||||
/**
|
||||
* Clear all queues for a specific album
|
||||
* Used when sort order changes to force rebuild with new order
|
||||
*/
|
||||
suspend fun clearQueuesForAlbum(albumId: String): Result<Unit>
|
||||
|
||||
/**
|
||||
* Normalize queue positions for all queues (HOME and LOCK) of an album
|
||||
* Fixes gaps in queue positions caused by CASCADE deletes when wallpapers are removed
|
||||
* Ensures positions are sequential (0, 1, 2, ...) without gaps
|
||||
*/
|
||||
suspend fun normalizeAllQueuesForAlbum(albumId: String): Result<Unit>
|
||||
|
||||
/**
|
||||
* Scan folder for wallpapers
|
||||
*/
|
||||
suspend fun scanFolderForWallpapers(folderUri: Uri): Result<List<Wallpaper>>
|
||||
|
||||
/**
|
||||
* Check if a wallpaper with the given URI already exists in the album
|
||||
* Optimized for checking duplicates during folder sync
|
||||
*/
|
||||
suspend fun isWallpaperInAlbum(albumId: String, uri: String): Boolean
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.anthonyla.paperize.domain.usecase
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.Result
|
||||
import com.anthonyla.paperize.core.ScreenType
|
||||
import com.anthonyla.paperize.core.util.adaptiveBrightnessAdjustment
|
||||
import com.anthonyla.paperize.core.util.getDeviceScreenSize
|
||||
import com.anthonyla.paperize.core.util.isValid
|
||||
import com.anthonyla.paperize.core.util.processBitmap
|
||||
import com.anthonyla.paperize.core.util.retrieveBitmap
|
||||
import com.anthonyla.paperize.domain.repository.SettingsRepository
|
||||
import com.anthonyla.paperize.domain.repository.WallpaperRepository
|
||||
import com.anthonyla.paperize.core.constants.Constants
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Use case to change wallpaper
|
||||
*
|
||||
* Handles the complete wallpaper changing flow:
|
||||
* 1. Atomically get and dequeue next wallpaper from queue
|
||||
* 2. Validate URI
|
||||
* 3. Load and process bitmap
|
||||
* 4. Apply effects
|
||||
* 5. Refill queue if needed
|
||||
*/
|
||||
class ChangeWallpaperUseCase @Inject constructor(
|
||||
@param:ApplicationContext private val context: Context,
|
||||
private val wallpaperRepository: WallpaperRepository,
|
||||
private val settingsRepository: SettingsRepository
|
||||
) {
|
||||
suspend operator fun invoke(albumId: String, screenType: ScreenType): Result<Bitmap> {
|
||||
return try {
|
||||
// Get settings first - needed for queue building
|
||||
val settings = settingsRepository.getScheduleSettings()
|
||||
|
||||
// Check if queue exists, build it if empty
|
||||
val queueCheck = wallpaperRepository.getNextWallpaperInQueue(albumId, screenType)
|
||||
if (queueCheck == null) {
|
||||
// Queue is empty, build it first
|
||||
val buildResult = wallpaperRepository.buildWallpaperQueue(albumId, screenType, settings.shuffleEnabled)
|
||||
if (buildResult is Result.Error) {
|
||||
return Result.Error(Exception(context.getString(R.string.error_failed_to_build_queue)))
|
||||
}
|
||||
}
|
||||
|
||||
// Atomically get and dequeue wallpaper, skipping invalid or corrupted ones
|
||||
var finalBitmap: Bitmap? = null
|
||||
var maxRetries = Constants.MAX_WALLPAPER_LOAD_RETRIES
|
||||
var queueRebuildAttempts = 0
|
||||
|
||||
// Get screen dimensions once for the retry loop
|
||||
val screenSize = getDeviceScreenSize(context)
|
||||
val effects = when (screenType) {
|
||||
ScreenType.LIVE -> settings.liveEffects
|
||||
ScreenType.HOME, ScreenType.BOTH -> settings.homeEffects
|
||||
ScreenType.LOCK -> settings.lockEffects
|
||||
}
|
||||
val scaling = when (screenType) {
|
||||
ScreenType.LIVE -> settings.liveScalingType
|
||||
ScreenType.HOME, ScreenType.BOTH -> settings.homeScalingType
|
||||
ScreenType.LOCK -> settings.lockScalingType
|
||||
}
|
||||
|
||||
while (finalBitmap == null && maxRetries > 0) {
|
||||
val candidate = wallpaperRepository.getAndDequeueWallpaper(albumId, screenType)
|
||||
|
||||
if (candidate == null) {
|
||||
queueRebuildAttempts++
|
||||
if (queueRebuildAttempts > 2) {
|
||||
return Result.Error(Exception(context.getString(R.string.no_wallpapers_in_album)))
|
||||
}
|
||||
val rebuildResult = wallpaperRepository.buildWallpaperQueue(albumId, screenType, settings.shuffleEnabled)
|
||||
if (rebuildResult is Result.Error) {
|
||||
return Result.Error(Exception(context.getString(R.string.error_failed_to_build_queue)))
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
val uri = candidate.uri.toUri()
|
||||
if (uri.isValid(context.contentResolver)) {
|
||||
// Try to load and process the bitmap
|
||||
try {
|
||||
val bitmap = retrieveBitmap(context, uri, screenSize.width, screenSize.height, scaling)
|
||||
if (bitmap != null) {
|
||||
// retrieveBitmap already applies scaling via ImageDecoder.setTargetSize
|
||||
// Apply effects directly to the retrieved bitmap
|
||||
|
||||
var processedBitmap = processBitmap(
|
||||
source = bitmap,
|
||||
enableDarken = effects.enableDarken,
|
||||
darkenPercent = effects.darkenPercentage,
|
||||
enableBlur = effects.enableBlur,
|
||||
blurPercent = effects.blurPercentage,
|
||||
enableVignette = effects.enableVignette,
|
||||
vignettePercent = effects.vignettePercentage,
|
||||
enableGrayscale = effects.enableGrayscale,
|
||||
grayscalePercent = effects.grayscalePercentage
|
||||
)
|
||||
|
||||
if (processedBitmap !== bitmap) {
|
||||
bitmap.recycle()
|
||||
}
|
||||
|
||||
// Apply adaptive brightness
|
||||
if (settings.adaptiveBrightness) {
|
||||
val previousBitmap = processedBitmap
|
||||
processedBitmap = adaptiveBrightnessAdjustment(context, processedBitmap)
|
||||
if (processedBitmap !== previousBitmap) {
|
||||
previousBitmap.recycle()
|
||||
}
|
||||
}
|
||||
|
||||
finalBitmap = processedBitmap
|
||||
} else {
|
||||
// File exists but failed to decode (corrupted)
|
||||
wallpaperRepository.deleteWallpaper(candidate.id)
|
||||
maxRetries--
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
// Error during processing, skip this wallpaper
|
||||
wallpaperRepository.deleteWallpaper(candidate.id)
|
||||
maxRetries--
|
||||
}
|
||||
} else {
|
||||
// URI invalid
|
||||
wallpaperRepository.deleteWallpaper(candidate.id)
|
||||
maxRetries--
|
||||
}
|
||||
}
|
||||
|
||||
if (finalBitmap == null) {
|
||||
return Result.Error(Exception(context.getString(R.string.error_no_valid_wallpaper_after_retries)))
|
||||
}
|
||||
|
||||
// Check if queue needs refilling
|
||||
val nextItem = wallpaperRepository.getNextWallpaperInQueue(albumId, screenType)
|
||||
if (nextItem == null) {
|
||||
wallpaperRepository.buildWallpaperQueue(albumId, screenType, settings.shuffleEnabled)
|
||||
}
|
||||
|
||||
Result.Success(finalBitmap)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.anthonyla.paperize.domain.usecase
|
||||
|
||||
import com.anthonyla.paperize.core.Result
|
||||
import com.anthonyla.paperize.domain.model.Album
|
||||
import com.anthonyla.paperize.domain.repository.AlbumRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Use case to create a new album
|
||||
*/
|
||||
class CreateAlbumUseCase @Inject constructor(
|
||||
private val albumRepository: AlbumRepository
|
||||
) {
|
||||
suspend operator fun invoke(name: String, coverUri: String? = null): Result<Album> {
|
||||
if (name.isBlank()) {
|
||||
return Result.Error(IllegalArgumentException("Album name cannot be empty"))
|
||||
}
|
||||
|
||||
val existingAlbum = albumRepository.getAlbumByName(name)
|
||||
if (existingAlbum != null) {
|
||||
return Result.Error(IllegalArgumentException("Album with this name already exists"))
|
||||
}
|
||||
|
||||
return albumRepository.createAlbum(name, coverUri)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.anthonyla.paperize.domain.usecase
|
||||
|
||||
import com.anthonyla.paperize.core.Result
|
||||
import com.anthonyla.paperize.data.datastore.PreferencesManager
|
||||
import com.anthonyla.paperize.domain.repository.AlbumRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Use case to delete an album
|
||||
*/
|
||||
class DeleteAlbumUseCase @Inject constructor(
|
||||
private val albumRepository: AlbumRepository,
|
||||
private val preferencesManager: PreferencesManager
|
||||
) {
|
||||
suspend operator fun invoke(albumId: String): Result<Unit> {
|
||||
val result = albumRepository.deleteAlbum(albumId)
|
||||
if (result is Result.Success) {
|
||||
preferencesManager.clearAlbumSelectionsIfMatches(albumId)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.anthonyla.paperize.domain.usecase
|
||||
|
||||
import com.anthonyla.paperize.domain.model.AlbumSummary
|
||||
import com.anthonyla.paperize.domain.repository.AlbumRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Use case to get all album summaries (lightweight metadata + counts)
|
||||
* Optimized for displaying lists of albums without loading full wallpaper data
|
||||
*/
|
||||
class GetAlbumSummariesUseCase @Inject constructor(
|
||||
private val albumRepository: AlbumRepository
|
||||
) {
|
||||
operator fun invoke(): Flow<List<AlbumSummary>> = albumRepository.getAlbumSummaries()
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.anthonyla.paperize.domain.usecase
|
||||
|
||||
import com.anthonyla.paperize.domain.model.Album
|
||||
import com.anthonyla.paperize.domain.repository.AlbumRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Use case to get all albums
|
||||
*/
|
||||
class GetAlbumsUseCase @Inject constructor(
|
||||
private val albumRepository: AlbumRepository
|
||||
) {
|
||||
operator fun invoke(): Flow<List<Album>> = albumRepository.getAllAlbums()
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.anthonyla.paperize.domain.usecase
|
||||
|
||||
import com.anthonyla.paperize.core.Result
|
||||
import com.anthonyla.paperize.domain.repository.AlbumRepository
|
||||
import com.anthonyla.paperize.domain.repository.WallpaperRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Use case to refresh album wallpapers and folders
|
||||
*
|
||||
* Validates all wallpaper URIs and folder URIs, removes invalid ones
|
||||
* Normalizes wallpaper queues after deletions to maintain queue integrity
|
||||
* Returns total number of items removed (wallpapers + folders)
|
||||
*/
|
||||
class RefreshAlbumUseCase @Inject constructor(
|
||||
private val wallpaperRepository: WallpaperRepository,
|
||||
private val albumRepository: AlbumRepository
|
||||
) {
|
||||
suspend operator fun invoke(albumId: String): Result<Int> {
|
||||
var totalRemoved = 0
|
||||
|
||||
// Validate and remove invalid folders
|
||||
val foldersResult = albumRepository.validateAndRemoveInvalidFolders(albumId)
|
||||
if (foldersResult is Result.Success) {
|
||||
totalRemoved += foldersResult.data
|
||||
}
|
||||
|
||||
// Validate and remove invalid wallpapers
|
||||
val wallpapersResult = wallpaperRepository.validateAndRemoveInvalidWallpapers(albumId)
|
||||
if (wallpapersResult is Result.Success) {
|
||||
totalRemoved += wallpapersResult.data
|
||||
}
|
||||
|
||||
// If wallpapers were removed, normalize queue positions to fix gaps from CASCADE deletes
|
||||
if (totalRemoved > 0) {
|
||||
// Refresh album cover after validation (in case cover wallpaper was removed)
|
||||
albumRepository.refreshAlbumCover(albumId)
|
||||
|
||||
// Normalize both HOME and LOCK queues to fix position gaps
|
||||
// CASCADE deletes may leave gaps in queue positions (e.g., 0, 2, 4 instead of 0, 1, 2)
|
||||
wallpaperRepository.normalizeAllQueuesForAlbum(albumId)
|
||||
}
|
||||
|
||||
// Return error if either operation failed
|
||||
return when {
|
||||
foldersResult is Result.Error -> foldersResult
|
||||
wallpapersResult is Result.Error -> wallpapersResult
|
||||
else -> Result.Success(totalRemoved)
|
||||
}
|
||||
}
|
||||
}
|
||||
-85
@@ -1,85 +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.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Data access object for AlbumWithWallpaperAndFolder which is used for application's list of user albums
|
||||
*/
|
||||
@Dao
|
||||
interface AlbumDao {
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM album")
|
||||
fun getAlbumsWithWallpaperAndFolder(): Flow<List<AlbumWithWallpaperAndFolder>>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsertAlbum(album: Album)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsertWallpaper(wallpaper: Wallpaper)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsertFolder(folder: Folder)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsertWallpaperList(wallpapers: List<Wallpaper>)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsertFolderList(folders: List<Folder>)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteAlbum(album: Album)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteWallpaper(wallpaper: Wallpaper)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteFolder(folder: Folder)
|
||||
@Delete
|
||||
suspend fun deleteWallpaperList(wallpapers: List<Wallpaper>)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteFolderList(folders: List<Folder>)
|
||||
|
||||
@Query("DELETE FROM wallpaper WHERE initialAlbumName=:initialAlbumName")
|
||||
suspend fun cascadeDeleteWallpaper(initialAlbumName: String)
|
||||
|
||||
@Query("DELETE FROM folder WHERE initialAlbumName=:initialAlbumName")
|
||||
suspend fun cascadeDeleteFolder(initialAlbumName: String)
|
||||
|
||||
@Update
|
||||
suspend fun updateAlbum(album: Album)
|
||||
|
||||
@Update
|
||||
suspend fun updateWallpaper(wallpaper: Wallpaper)
|
||||
|
||||
@Update
|
||||
suspend fun updateFolder(folder: Folder)
|
||||
|
||||
@Query("DELETE FROM album")
|
||||
suspend fun deleteAllAlbums()
|
||||
|
||||
@Query("DELETE FROM wallpaper")
|
||||
suspend fun deleteAllWallpapers()
|
||||
|
||||
@Query("DELETE FROM folder")
|
||||
suspend fun deleteAllFolders()
|
||||
|
||||
@Transaction
|
||||
suspend fun deleteAllData() {
|
||||
deleteAllWallpapers()
|
||||
deleteAllFolders()
|
||||
deleteAllAlbums()
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +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.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
|
||||
/**
|
||||
* Database for storing albums, wallpapers, and folders
|
||||
* Stores [Album], [Wallpaper], and [Folder] inside AlbumWithWallpaperAndFolder
|
||||
*/
|
||||
@Database(
|
||||
entities = [Album::class, Wallpaper::class, Folder::class],
|
||||
version = 4
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class AlbumDatabase: RoomDatabase() {
|
||||
abstract val albumDao: AlbumDao
|
||||
companion object {
|
||||
const val DATABASE_NAME = "paperize_album_db"
|
||||
}
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.data.data_source
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.google.gson.Gson
|
||||
|
||||
/**
|
||||
* Converters for Room database to convert list of strings to json string and vice versa
|
||||
*/
|
||||
class Converters {
|
||||
private val gson = Gson()
|
||||
|
||||
/**
|
||||
* Convert list of strings to json string
|
||||
*/
|
||||
@TypeConverter
|
||||
fun listToJsonString(value: List<String>?): String = gson.toJson(value)
|
||||
|
||||
/**
|
||||
* Convert json string to list of strings
|
||||
*/
|
||||
@TypeConverter
|
||||
fun jsonStringToList(value: String) = gson.fromJson(value, Array<String>::class.java).toList()
|
||||
}
|
||||
-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"
|
||||
}
|
||||
}
|
||||
-93
@@ -1,93 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.data.repository
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.data.data_source.AlbumDao
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class AlbumRepositoryImpl(
|
||||
private val dao: AlbumDao
|
||||
): AlbumRepository {
|
||||
override fun getAlbumsWithWallpaperAndFolder(): Flow<List<AlbumWithWallpaperAndFolder>> {
|
||||
return dao.getAlbumsWithWallpaperAndFolder()
|
||||
}
|
||||
|
||||
override suspend fun upsertAlbumWithWallpaperAndFolder(albumWithWallpaperAndFolder: AlbumWithWallpaperAndFolder) {
|
||||
dao.upsertAlbum(albumWithWallpaperAndFolder.album)
|
||||
dao.upsertWallpaperList(albumWithWallpaperAndFolder.wallpapers)
|
||||
dao.upsertFolderList(albumWithWallpaperAndFolder.folders)
|
||||
}
|
||||
|
||||
override suspend fun upsertAlbum(album: Album) {
|
||||
dao.upsertAlbum(album)
|
||||
}
|
||||
|
||||
override suspend fun upsertWallpaper(wallpaper: Wallpaper) {
|
||||
dao.upsertWallpaper(wallpaper)
|
||||
}
|
||||
|
||||
override suspend fun upsertFolder(folder: Folder) {
|
||||
dao.upsertFolder(folder)
|
||||
}
|
||||
|
||||
override suspend fun upsertFolderList(folders: List<Folder>) {
|
||||
dao.upsertFolderList(folders)
|
||||
}
|
||||
|
||||
override suspend fun upsertWallpaperList(wallpapers: List<Wallpaper>) {
|
||||
dao.upsertWallpaperList(wallpapers)
|
||||
}
|
||||
|
||||
override suspend fun deleteAlbum(album: Album) {
|
||||
dao.deleteAlbum(album)
|
||||
}
|
||||
|
||||
override suspend fun deleteWallpaper(wallpaper: Wallpaper) {
|
||||
dao.deleteWallpaper(wallpaper)
|
||||
}
|
||||
|
||||
override suspend fun deleteFolder(folder: Folder) {
|
||||
dao.deleteFolder(folder)
|
||||
}
|
||||
|
||||
override suspend fun updateAlbum(album: Album) {
|
||||
dao.updateAlbum(album)
|
||||
}
|
||||
|
||||
override suspend fun updateFolder(folder: Folder) {
|
||||
dao.updateFolder(folder)
|
||||
}
|
||||
|
||||
override suspend fun updateWallpaper(wallpaper: Wallpaper) {
|
||||
dao.updateWallpaper(wallpaper)
|
||||
}
|
||||
|
||||
override suspend fun cascadeDeleteAlbum(album: Album) {
|
||||
dao.deleteAlbum(album)
|
||||
dao.cascadeDeleteWallpaper(album.initialAlbumName)
|
||||
dao.cascadeDeleteFolder(album.initialAlbumName)
|
||||
}
|
||||
|
||||
override suspend fun cascadeDeleteFolder(initialAlbumName: String) {
|
||||
dao.cascadeDeleteFolder(initialAlbumName)
|
||||
}
|
||||
|
||||
override suspend fun cascadeDeleteWallpaper(initialAlbumName: String) {
|
||||
dao.cascadeDeleteWallpaper(initialAlbumName)
|
||||
}
|
||||
|
||||
override suspend fun deleteFolderList(folders: List<Folder>) {
|
||||
dao.deleteFolderList(folders)
|
||||
}
|
||||
|
||||
override suspend fun deleteWallpaperList(wallpapers: List<Wallpaper>) {
|
||||
dao.deleteWallpaperList(wallpapers)
|
||||
}
|
||||
|
||||
override suspend fun deleteAllData() {
|
||||
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()
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.domain.model
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
/**
|
||||
* Album model
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
@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
|
||||
)
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.domain.model
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Relation
|
||||
|
||||
/**
|
||||
* Complete data class that represents an album with its wallpapers and folders.
|
||||
* @param album The album.
|
||||
* @param wallpapers The wallpapers.
|
||||
* @param folders The folders.
|
||||
*/
|
||||
data class AlbumWithWallpaperAndFolder(
|
||||
@Embedded val album: Album,
|
||||
@Relation(
|
||||
parentColumn = "initialAlbumName",
|
||||
entityColumn = "initialAlbumName",
|
||||
)
|
||||
val wallpapers: List<Wallpaper> = emptyList(),
|
||||
@Relation(
|
||||
parentColumn = "initialAlbumName",
|
||||
entityColumn = "initialAlbumName",
|
||||
)
|
||||
val folders: List<Folder> = emptyList(),
|
||||
)
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.domain.model
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Entity
|
||||
data class Folder(
|
||||
val initialAlbumName: String,
|
||||
val folderName: String?,
|
||||
val coverUri: String?,
|
||||
val wallpapers: List<String> = emptyList(),
|
||||
val folderUri: String,
|
||||
@PrimaryKey(autoGenerate = false) val key: Int
|
||||
)
|
||||
-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(),
|
||||
)
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.domain.model
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
/**
|
||||
* Represents a wallpaper object.
|
||||
*
|
||||
* @param initialAlbumName The name of the album the wallpaper belongs to.
|
||||
* @param wallpaperUri The URI of the wallpaper.
|
||||
*/
|
||||
@Entity
|
||||
data class Wallpaper(
|
||||
val initialAlbumName: String,
|
||||
val wallpaperUri: String,
|
||||
@PrimaryKey(autoGenerate = false) val key: Int
|
||||
)
|
||||
-104
@@ -1,104 +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.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface AlbumRepository {
|
||||
/**
|
||||
* Get all albums with wallpaper and folder
|
||||
*/
|
||||
fun getAlbumsWithWallpaperAndFolder(): Flow<List<AlbumWithWallpaperAndFolder>>
|
||||
|
||||
/**
|
||||
* Insert or update album with wallpaper and folder
|
||||
*/
|
||||
suspend fun upsertAlbumWithWallpaperAndFolder(albumWithWallpaperAndFolder: AlbumWithWallpaperAndFolder)
|
||||
|
||||
/**
|
||||
* Insert or update album and its wallpaper and folder
|
||||
*/
|
||||
suspend fun upsertAlbum(album: Album)
|
||||
|
||||
/**
|
||||
* Delete album and its wallpaper and folder
|
||||
*/
|
||||
suspend fun deleteAlbum(album: Album)
|
||||
|
||||
/**
|
||||
* Update album
|
||||
*/
|
||||
suspend fun updateAlbum(album: Album)
|
||||
|
||||
/**
|
||||
* Cascade delete album and its wallpaper and folder. Proper way to delete an AlbumWithWallpaperAndFolder
|
||||
*/
|
||||
suspend fun cascadeDeleteAlbum(album: Album)
|
||||
|
||||
/**
|
||||
* Insert or update wallpaper
|
||||
*/
|
||||
suspend fun upsertWallpaper(wallpaper: Wallpaper)
|
||||
|
||||
/**
|
||||
* Insert or update wallpaper list in one transaction
|
||||
*/
|
||||
suspend fun upsertWallpaperList(wallpapers: List<Wallpaper>)
|
||||
|
||||
/**
|
||||
* Delete wallpaper
|
||||
*/
|
||||
suspend fun deleteWallpaper(wallpaper: Wallpaper)
|
||||
|
||||
/**
|
||||
* Delete wallpaper list in one transaction
|
||||
*/
|
||||
suspend fun deleteWallpaperList(wallpapers: List<Wallpaper>)
|
||||
|
||||
/**
|
||||
* Update wallpaper
|
||||
*/
|
||||
suspend fun updateWallpaper(wallpaper: Wallpaper)
|
||||
|
||||
/**
|
||||
* Cascade delete wallpaper. Proper way to delete a single wallpaper
|
||||
*/
|
||||
suspend fun cascadeDeleteWallpaper(initialAlbumName: String)
|
||||
|
||||
/**
|
||||
* Insert or update folder
|
||||
*/
|
||||
suspend fun upsertFolder(folder: Folder)
|
||||
|
||||
/**
|
||||
* Insert or update folder list in one transaction
|
||||
*/
|
||||
suspend fun upsertFolderList(folders: List<Folder>)
|
||||
|
||||
/**
|
||||
* Delete folder
|
||||
*/
|
||||
suspend fun deleteFolder(folder: Folder)
|
||||
|
||||
/**
|
||||
* Update folder
|
||||
*/
|
||||
suspend fun updateFolder(folder: Folder)
|
||||
|
||||
/**
|
||||
* Cascade delete folder. Proper way to delete a single folder
|
||||
*/
|
||||
suspend fun cascadeDeleteFolder(initialAlbumName: String)
|
||||
|
||||
/**
|
||||
* Delete folder list in one transaction
|
||||
*/
|
||||
suspend fun deleteFolderList(folders: List<Folder>)
|
||||
|
||||
/**
|
||||
* Delete all data in database
|
||||
*/
|
||||
suspend fun deleteAllData()
|
||||
}
|
||||
-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()
|
||||
}
|
||||
-139
@@ -1,139 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation
|
||||
|
||||
import android.Manifest
|
||||
import android.animation.ObjectAnimator
|
||||
import android.app.Activity
|
||||
import android.app.ActivityManager
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.animation.AccelerateInterpolator
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.SystemBarStyle
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.viewModels
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.animation.doOnEnd
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.compose.LifecycleEventEffect
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.themes.PaperizeTheme
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreenViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.WallpaperService
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
@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)
|
||||
}
|
||||
enableEdgeToEdge(
|
||||
statusBarStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT),
|
||||
navigationBarStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT)
|
||||
)
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
val splashScreen = installSplashScreen()
|
||||
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) {
|
||||
splashScreen.setOnExitAnimationListener { splashScreenViewProvider ->
|
||||
val fadeOut = ObjectAnimator.ofFloat(splashScreenViewProvider.view, View.ALPHA, 1f, 0f)
|
||||
fadeOut.interpolator = AccelerateInterpolator()
|
||||
fadeOut.duration = 300L
|
||||
fadeOut.doOnEnd { splashScreenViewProvider.remove() }
|
||||
fadeOut.start()
|
||||
}
|
||||
}
|
||||
splashScreen.setKeepOnScreenCondition { settingsViewModel.setKeepOnScreenCondition }
|
||||
|
||||
setContent {
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
val selectedState = wallpaperScreenViewModel.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_RESUME) {
|
||||
lifecycleScope.launch {
|
||||
val serviceIntent = Intent(this@MainActivity, WallpaperService::class.java)
|
||||
val isAlreadyRunning = withContext(Dispatchers.IO) {
|
||||
val activityManager = getSystemService(ACTIVITY_SERVICE) as? ActivityManager
|
||||
activityManager?.getRunningServices(Integer.MAX_VALUE)?.any {
|
||||
it.service == serviceIntent.component
|
||||
} ?: false
|
||||
}
|
||||
if (selectedState.value.selectedAlbum != null && settingsState.value.enableChanger) {
|
||||
if (!isAlreadyRunning) {
|
||||
settingsViewModel.onEvent(SettingsEvent.RefreshNextSetTime)
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.START.toString()
|
||||
putExtra("timeInMinutes1", settingsState.value.homeInterval)
|
||||
putExtra("timeInMinutes2", settingsState.value.lockInterval)
|
||||
putExtra("scheduleSeparately", settingsState.value.scheduleSeparately)
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
} else {
|
||||
if (isAlreadyRunning) {
|
||||
Intent(context, WallpaperService::class.java).also {
|
||||
it.action = WallpaperService.Actions.STOP.toString()
|
||||
context.startForegroundService(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
PaperizeTheme(settingsState.value.darkMode, settingsState.value.dynamicTheming) {
|
||||
Surface(tonalElevation = 5.dp) {
|
||||
PaperizeApp(isFirstLaunch, topInset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
topInset = window.decorView.rootWindowInsets.stableInsetTop.dp
|
||||
}
|
||||
}
|
||||
Loaded 100 of 362 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user