Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
No files matched your search
@@ -0,0 +1,14 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: Anthonyy232
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
polar: # Replace with a single Polar username
|
||||
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: "[Bug] <BUG_NAME>"
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Smartphone (please complete the following information):**
|
||||
- Device: [e.g. Pixel 32 Pro]
|
||||
- OS: [e.g. OneUI 21]
|
||||
- Version [e.g. v2.1.0]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: "[Feature request] <FEATURE_NAME>"
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
@@ -1,5 +1,6 @@
|
||||
*.iml
|
||||
.gradle
|
||||
.idea
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
@@ -13,3 +14,8 @@
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
local.properties
|
||||
/app/build
|
||||
/app/release
|
||||
/app/schemas
|
||||
.kotlin
|
||||
/.kotlin/sessions
|
||||
Generated
-3
@@ -1,3 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
Generated
-1
@@ -1 +0,0 @@
|
||||
Paperize
|
||||
Generated
-41
@@ -1,41 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AppInsightsSettings">
|
||||
<option name="selectedTabId" value="Android Vitals" />
|
||||
<option name="tabSettings">
|
||||
<map>
|
||||
<entry key="Android Vitals">
|
||||
<value>
|
||||
<InsightsFilterSettings>
|
||||
<option name="connection">
|
||||
<ConnectionSetting>
|
||||
<option name="appId" value="com.anthonyla.paperize" />
|
||||
</ConnectionSetting>
|
||||
</option>
|
||||
<option name="signal" value="SIGNAL_UNSPECIFIED" />
|
||||
<option name="timeIntervalDays" value="SEVEN_DAYS" />
|
||||
<option name="visibilityType" value="ALL" />
|
||||
</InsightsFilterSettings>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="Firebase Crashlytics">
|
||||
<value>
|
||||
<InsightsFilterSettings>
|
||||
<option name="connection">
|
||||
<ConnectionSetting>
|
||||
<option name="appId" value="PLACEHOLDER" />
|
||||
<option name="mobileSdkAppId" value="" />
|
||||
<option name="projectId" value="" />
|
||||
<option name="projectNumber" value="" />
|
||||
</ConnectionSetting>
|
||||
</option>
|
||||
<option name="signal" value="SIGNAL_UNSPECIFIED" />
|
||||
<option name="timeIntervalDays" value="THIRTY_DAYS" />
|
||||
<option name="visibilityType" value="ALL" />
|
||||
</InsightsFilterSettings>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
Generated
-123
@@ -1,123 +0,0 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<JetCodeStyleSettings>
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</JetCodeStyleSettings>
|
||||
<codeStyleSettings language="XML">
|
||||
<option name="FORCE_REARRANGE_MODE" value="1" />
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
<arrangement>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
Generated
-5
@@ -1,5 +0,0 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
||||
Generated
-6
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="17" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
-23
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<value>
|
||||
<entry key="Paperize">
|
||||
<State>
|
||||
<runningDeviceTargetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="RUNNING_DEVICE_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="SERIAL_NUMBER" />
|
||||
<value value="RFCTA1MRS4H" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</runningDeviceTargetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2024-04-30T06:47:19.015867100Z" />
|
||||
</State>
|
||||
</entry>
|
||||
</value>
|
||||
</component>
|
||||
</project>
|
||||
Generated
-19
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="jbr-17" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveExternalAnnotations" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
<option name="composableFile" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
||||
Generated
-9
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Kotlin2JvmCompilerArguments">
|
||||
<option name="jvmTarget" value="1.8" />
|
||||
</component>
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="1.9.22" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
-10
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectMigrations">
|
||||
<option name="MigrateToGradleLocalJavaHome">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
Generated
-54
@@ -1,54 +0,0 @@
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="androidx.annotation.Nullable" />
|
||||
<option name="myDefaultNotNull" value="androidx.annotation.NonNull" />
|
||||
<option name="myNullables">
|
||||
<value>
|
||||
<list size="15">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jspecify.annotations.Nullable" />
|
||||
<item index="1" class="java.lang.String" itemvalue="com.android.annotations.Nullable" />
|
||||
<item index="2" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
|
||||
<item index="3" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
|
||||
<item index="4" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
|
||||
<item index="6" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.Nullable" />
|
||||
<item index="7" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||
<item index="8" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||
<item index="9" class="java.lang.String" itemvalue="jakarta.annotation.Nullable" />
|
||||
<item index="10" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
|
||||
<item index="11" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||
<item index="12" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
|
||||
<item index="13" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
|
||||
<item index="14" class="java.lang.String" itemvalue="android.annotation.Nullable" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myNotNulls">
|
||||
<value>
|
||||
<list size="14">
|
||||
<item index="0" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
|
||||
<item index="1" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
|
||||
<item index="2" class="java.lang.String" itemvalue="org.jspecify.annotations.NonNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="jakarta.annotation.Nonnull" />
|
||||
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
|
||||
<item index="5" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
|
||||
<item index="6" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||
<item index="7" class="java.lang.String" itemvalue="com.android.annotations.NonNull" />
|
||||
<item index="8" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
|
||||
<item index="10" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||
<item index="11" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||
<item index="12" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.NonNull" />
|
||||
<item index="13" class="java.lang.String" itemvalue="android.annotation.NonNull" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
-6
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,12 +1,13 @@
|
||||
|
||||
<div align="center">
|
||||
<img width="300" height="300" style="display: block; border-radius: 9999px;" src="https://github.com/Anthonyy232/Paperize/assets/60626873/c40018a1-bc0a-4efd-bd4a-bc83fb23589e">
|
||||
<h1>Paperize</h1>
|
||||
<p align="center">
|
||||
</p>
|
||||
<img style="display: block; border-radius: 9999px;" src="https://github.com/user-attachments/assets/e8fb14f5-ec8e-440e-a2ac-8065322b0e28" alt="">
|
||||
<h1>
|
||||
Paperize
|
||||
<p><img style="display: block; border-radius: 9999px;" src="https://img.shields.io/github/downloads/Anthonyy232/Paperize/total" alt=""></p>
|
||||
</h1>
|
||||
<p align="center"></p>
|
||||
<p>Paperize is a dynamic wallpaper changer application designed to keep your device's aesthetic fresh and exciting</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
## Features
|
||||
@@ -14,28 +15,30 @@
|
||||
- **Supports Various Image Types**: Paperize can handle a wide range of image types
|
||||
- Including: JPEG, PNG, AVIF, WEBP
|
||||
- **Folder Support**: Organize your wallpapers into folders for auto-updating
|
||||
- **Home and Lock Screen Wallpaper**: Choose to change either your home screen, lock screen, or both
|
||||
- **Home and Lock Screen Wallpaper**: Choose the same or separate albums for your home screen and lock screen
|
||||
- **Wallpaper effects**: Change the brightness and the blur of your wallpaper
|
||||
- **On-Device Storage**: All your wallpapers and settings are stored on your device
|
||||
|
||||
|
||||
<div align="center">
|
||||
<br/>
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/57122f72-78f8-45ed-a9ac-de943061d6a2" width="30%" alt="onboarding" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/9f41d715-7b14-4ff2-9c30-87ad3d86d94c" width="30%" alt="wallpaper" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/47aa95c3-ef80-4c3c-a8cd-a51ac6824507" width="30%" alt="interval" />
|
||||
<img src="https://github.com/user-attachments/assets/f054e7f1-d67f-4500-a547-64bccd986bbd" width="30%" alt="wallpaper" />
|
||||
<img src="https://github.com/user-attachments/assets/cdf0d989-ae11-44ba-b33c-4aeec6b6116e" width="30%" alt="interval" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/4ce1b28d-f4b2-4048-a261-203156222263" width="30%" alt="album" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/66b092e5-4af4-4396-b145-63ee506d9257" width="30%" alt="settings" />
|
||||
<img src="https://github.com/user-attachments/assets/d23f290d-bb2c-4b89-9321-b426e45864f9" width="30%" alt="settings" />
|
||||
<br/>
|
||||
<br/>
|
||||
<div><video controls src="https://github.com/Anthonyy232/Paperize/assets/60626873/015afb04-e3f3-4641-b8f9-707cfa26d16f" muted="true"></video></div>
|
||||
<video controls src="https://github.com/user-attachments/assets/ce7f5c7c-66a7-45fc-bb28-a53d8d9cf733" muted="muted"></video>
|
||||
</div>
|
||||
|
||||
## Download
|
||||
[<img src="https://play.google.com/intl/en_us/badges/static/images/badges/en_badge_web_generic.png" alt="Download app from Google Play" height="80">](https://play.google.com/store/apps/details?id=com.anthonyla.paperize)
|
||||
[<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/1c034414-21cd-4a0a-838d-89fe7bd56910" alt="Download app from GitHub" height="80">](https://github.com/Anthonyy232/Paperize/releases)
|
||||
|
||||
F-Droid will be added soon
|
||||
## Download
|
||||
[<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/1c034414-21cd-4a0a-838d-89fe7bd56910" alt="Download app from GitHub" height="80">](https://github.com/Anthonyy232/Paperize/releases)
|
||||
[<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" alt="Download app from F-Droid" height="80">](https://f-droid.org/en/packages/com.anthonyla.paperize/)
|
||||
[<img src="https://gitlab.com/IzzyOnDroid/repo/-/raw/master/assets/IzzyOnDroid.png" alt="Download app from IzzyOnDroid" height="80">](https://apt.izzysoft.de/fdroid/index/apk/com.anthonyla.paperize)
|
||||
|
||||
## Localization
|
||||
I want to allow more people to use the app. Currently, translations are provided using machine translation and AI -- which is not optimal.
|
||||
I want to allow more people to use the app. Currently, most of the translations are provided using machine translation and AI -- which is not optimal.
|
||||
|
||||
I would love some help translating the app! Help me out with that [here](https://crowdin.com/project/paperize/invite?h=d8d7a7513d2beb0c96ba9b2a5f85473e2084922)!
|
||||
|
||||
@@ -45,7 +48,7 @@ I would love some help translating the app! Help me out with that [here](https:/
|
||||
|
||||
- [Kotlin](https://kotlinlang.org/) - A programming language that is used for Android app development
|
||||
- [Jetpack Compose](https://developer.android.com/develop/ui/compose) - A declarative UI toolkit for building native Android UI
|
||||
- [Material 3](https://m3.material.io/) - A UI design system git for modern UI guidelines
|
||||
- [Material 3](https://m3.material.io/) - A UI design system for modern UI guidelines
|
||||
- [Dagger Hilt](https://dagger.dev/hilt/) - A dependency injection library
|
||||
- [Room](https://developer.android.com/training/data-storage/room) - A persistence library that provides an abstraction layer over SQLite interfacing with Kotlin
|
||||
- [AboutLibraries](https://github.com/mikepenz/AboutLibraries) - A library to offer some information of libraries
|
||||
@@ -54,6 +57,8 @@ I would love some help translating the app! Help me out with that [here](https:/
|
||||
- [Zoomable](https://github.com/usuiat/Zoomable) - A library that provides a zoomable and pannable view, which can be used with any view you want
|
||||
- [AnimatedFABMenu](https://github.com/rajaumair7890/AnimatedFABMenu) - A animated floating action button with Material 3 design
|
||||
- [DocumentFileCompat](https://github.com/ItzNotABug/DocumentFileCompat) - A DocumentFile wrapper that caches the result to improve efficiency
|
||||
- [LazyColumnScrollbar](https://github.com/nanihadesuka/LazyColumnScrollbar) - A Compose scrollbar library
|
||||
- [compose-collapsing-toolbar](https://github.com/onebone/compose-collapsing-toolbar) - A Compose library that provides a collapsing toolbar
|
||||
|
||||
Thanks to the creators and maintainers of the open-source libraries used in this project.
|
||||
|
||||
@@ -63,9 +68,9 @@ This project is built using Kotlin, Java, and Gradle. Here are the steps to buil
|
||||
|
||||
### Prerequisites
|
||||
- Java 8 (1.8)
|
||||
- Android Studio Jellyfish | 2023.3.1 or later
|
||||
- Android Gradle Plugin 8.4.1 or later
|
||||
- Gradle 8.8
|
||||
- Android Studio Jellyfish | 2024.2.1 or later
|
||||
- Android Gradle Plugin 8.7.0 or later
|
||||
- Gradle 8.10.2
|
||||
- Minimum SDK 26
|
||||
|
||||
### Steps
|
||||
@@ -81,8 +86,12 @@ All contributions to the app is welcome. Feel free to report any issues and crea
|
||||
|
||||
Inspiration from j4velin for their wallpaper changer app
|
||||
|
||||
## Donations
|
||||
|
||||
If you want to donate, you can do so using GitHub sponsorship (one-time or monthly). I appreciate the thought, thanks!
|
||||
|
||||
|
||||
## License
|
||||
Contact on my GitHub profile
|
||||
|
||||
Anthony La © GNU GPL v3.0
|
||||
[Anthony La](https://github.com/Anthonyy232) © GNU GPL v3.0
|
||||
+86
-73
@@ -1,71 +1,84 @@
|
||||
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.aboutLibraries)
|
||||
alias(libs.plugins.kotlinSerialization)
|
||||
alias(libs.plugins.baselineProfile)
|
||||
}
|
||||
|
||||
ksp {
|
||||
arg("room.schemaLocation", "$projectDir/schemas")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.anthonyla.paperize"
|
||||
compileSdk = 34
|
||||
compileSdk = 35
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.anthonyla.paperize"
|
||||
minSdk = 26
|
||||
targetSdk = 34
|
||||
versionCode = 21
|
||||
versionName = "1.5.3"
|
||||
|
||||
targetSdk = 35
|
||||
versionCode = 33
|
||||
versionName = "2.3.1"
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
useSupportLibrary = true
|
||||
}
|
||||
ndk {
|
||||
debugSymbolLevel = "FULL"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = true
|
||||
isShrinkResources = true
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
freeCompilerArgs += strongSkippingConfiguration()
|
||||
jvmTarget = "17"
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
compose = true
|
||||
viewBinding = true
|
||||
buildConfig = true
|
||||
}
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion = "1.5.10"
|
||||
}
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
androidResources {
|
||||
generateLocaleConfig = true
|
||||
}
|
||||
ndkVersion = "26.3.11579264"
|
||||
buildToolsVersion = "34.0.0"
|
||||
|
||||
ndkVersion = "28.0.12433566"
|
||||
buildToolsVersion = "35.0.0"
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
includeInBundle = false
|
||||
}
|
||||
|
||||
aboutLibraries {
|
||||
excludeFields = arrayOf("generated")
|
||||
}
|
||||
|
||||
androidComponents {
|
||||
onVariants { variant ->
|
||||
variant.outputs.forEach { output ->
|
||||
val apkName = "paperize-v${output.versionName}"
|
||||
output.versionName.set(apkName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
androidComponents {
|
||||
@@ -75,52 +88,52 @@ androidComponents {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("androidx.core:core-ktx:1.13.1")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.1")
|
||||
implementation("androidx.activity:activity-compose:1.9.0")
|
||||
implementation(platform("androidx.compose:compose-bom:2024.05.00"))
|
||||
implementation("androidx.compose.ui:ui:1.7.0-beta02")
|
||||
implementation("androidx.compose.ui:ui-graphics:1.7.0-beta02")
|
||||
implementation("androidx.compose.ui:ui-tooling-preview:1.7.0-beta02")
|
||||
implementation("androidx.compose.material3:material3:1.3.0-beta02")
|
||||
implementation("androidx.navigation:navigation-compose:2.8.0-beta02")
|
||||
implementation("androidx.compose.material:material:1.7.0-beta02")
|
||||
implementation("androidx.datastore:datastore:1.1.1")
|
||||
implementation("androidx.datastore:datastore-preferences:1.1.1")
|
||||
implementation("androidx.compose.material:material-icons-extended:1.7.0-beta02")
|
||||
implementation("com.google.accompanist:accompanist-adaptive:0.34.0")
|
||||
implementation("androidx.hilt:hilt-navigation-compose:1.2.0")
|
||||
implementation("androidx.compose.animation:animation:1.7.0-beta02")
|
||||
implementation("androidx.core:core-splashscreen:1.2.0-alpha01")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.1")
|
||||
implementation("com.google.code.gson:gson:2.11.0")
|
||||
implementation("androidx.documentfile:documentfile:1.1.0-alpha01")
|
||||
implementation("net.engawapg.lib:zoomable:1.7.0-beta02")
|
||||
implementation("com.github.skydoves:landscapist-glide:2.3.3")
|
||||
implementation("androidx.work:work-runtime-ktx:2.10.0-alpha02")
|
||||
implementation("androidx.hilt:hilt-work:1.2.0")
|
||||
implementation("com.airbnb.android:lottie-compose:6.4.1")
|
||||
implementation("com.google.accompanist:accompanist-permissions:0.35.0-alpha")
|
||||
implementation("com.mikepenz:aboutlibraries-core:11.2.1")
|
||||
implementation("com.mikepenz:aboutlibraries-compose-m3:11.2.1")
|
||||
implementation("androidx.compose.foundation:foundation:1.7.0-beta02")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.0-rc01")
|
||||
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.7.0-beta02")
|
||||
debugImplementation("androidx.compose.ui:ui-tooling:1.7.0-beta02")
|
||||
debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.0-beta02")
|
||||
implementation("com.google.dagger:hilt-android:2.51.1")
|
||||
ksp("com.google.dagger:hilt-android-compiler:2.51.1")
|
||||
implementation("androidx.room:room-runtime:2.6.1")
|
||||
ksp("androidx.room:room-compiler:2.6.1")
|
||||
implementation("androidx.room:room-ktx:2.6.1")
|
||||
implementation("com.lazygeniouz:dfc:1.0.8")
|
||||
implementation ("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
|
||||
implementation("com.github.android:renderscript-intrinsics-replacement-toolkit:b6363490c3")
|
||||
}
|
||||
|
||||
private fun strongSkippingConfiguration() = listOf(
|
||||
"-P",
|
||||
"plugin:androidx.compose.compiler.plugins.kotlin:experimentalStrongSkipping=true",
|
||||
)
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||
implementation(libs.androidx.activity.compose)
|
||||
implementation(platform(libs.androidx.compose.bom))
|
||||
implementation(libs.androidx.ui)
|
||||
implementation(libs.androidx.ui.graphics)
|
||||
implementation(libs.androidx.ui.tooling.preview)
|
||||
implementation(libs.androidx.material3)
|
||||
implementation(libs.androidx.navigation.compose)
|
||||
implementation(libs.androidx.material)
|
||||
implementation(libs.androidx.datastore)
|
||||
implementation(libs.androidx.datastore.preferences)
|
||||
implementation(libs.androidx.material.icons.extended)
|
||||
implementation(libs.androidx.hilt.navigation.compose)
|
||||
implementation(libs.androidx.animation)
|
||||
implementation(libs.androidx.core.splashscreen)
|
||||
implementation(libs.androidx.lifecycle.runtime.compose)
|
||||
implementation(libs.gson)
|
||||
implementation(libs.androidx.documentfile)
|
||||
implementation(libs.zoomable)
|
||||
implementation(libs.landscapist.glide)
|
||||
implementation(libs.androidx.work.runtime.ktx)
|
||||
implementation(libs.androidx.hilt.work)
|
||||
implementation(libs.lottie.compose)
|
||||
implementation(libs.accompanist.permissions)
|
||||
implementation(libs.aboutlibraries.core)
|
||||
implementation(libs.aboutlibraries.compose.m3)
|
||||
implementation(libs.androidx.foundation)
|
||||
implementation(libs.lazycolumnscrollbar)
|
||||
implementation(libs.taskerpluginlibrary)
|
||||
implementation(libs.filament.android)
|
||||
implementation(libs.androidx.profileinstaller)
|
||||
testImplementation(libs.junit)
|
||||
androidTestImplementation(libs.androidx.junit)
|
||||
androidTestImplementation(libs.androidx.espresso.core)
|
||||
androidTestImplementation(libs.androidx.ui.test.junit4)
|
||||
"baselineProfile"(project(":baselineprofile"))
|
||||
debugImplementation(libs.androidx.ui.tooling)
|
||||
debugImplementation(libs.androidx.ui.test.manifest)
|
||||
implementation(libs.hilt.android)
|
||||
ksp(libs.hilt.android.compiler)
|
||||
implementation(libs.androidx.room.runtime)
|
||||
ksp(libs.androidx.room.compiler)
|
||||
implementation(libs.androidx.room.ktx)
|
||||
implementation(libs.dfc)
|
||||
implementation (libs.kotlinx.serialization.json)
|
||||
implementation(libs.renderscript.intrinsics.replacement.toolkit)
|
||||
implementation(libs.toolbar.compose)
|
||||
}
|
||||
@@ -2,11 +2,14 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" android:maxSdkVersion="32" />
|
||||
<uses-permission android:name="android.permission.USE_EXACT_ALARM"/>
|
||||
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
|
||||
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" tools:node="remove"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
@@ -27,11 +30,23 @@
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<meta-data android:resource="@xml/shortcuts" android:name="android.app.shortcuts" />
|
||||
</activity>
|
||||
<activity android:name=".feature.wallpaper.app_shortcut.BroadcastActivity"
|
||||
android:theme="@android:style/Theme.NoDisplay">
|
||||
</activity>
|
||||
<receiver android:name=".feature.wallpaper.wallpaper_alarmmanager.WallpaperReceiver" />
|
||||
<service android:name=".feature.wallpaper.wallpaper_service.WallpaperService1"/>
|
||||
<service android:name=".feature.wallpaper.wallpaper_service.WallpaperService2"/>
|
||||
<receiver android:name=".feature.wallpaper.wallpaper_alarmmanager.WallpaperBootAndTimeChangeReceiver"
|
||||
<service android:name=".feature.wallpaper.wallpaper_service.HomeWallpaperService" />
|
||||
<service android:name=".feature.wallpaper.wallpaper_service.LockWallpaperService" />
|
||||
<service
|
||||
android:name=".feature.wallpaper.wallpaper_tile.ChangeWallpaperTileService"
|
||||
android:exported="true"
|
||||
android:label="@string/change_wallpaper"
|
||||
android:icon="@drawable/notification_icon"
|
||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||
<intent-filter> <action android:name="android.service.quicksettings.action.QS_TILE" /> </intent-filter>
|
||||
</service>
|
||||
<receiver android:name=".feature.wallpaper.wallpaper_alarmmanager.WallpaperBootAndChangeReceiver"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
@@ -47,5 +62,23 @@
|
||||
<meta-data android:name="androidx.emoji2.text.EmojiCompatInitializer"
|
||||
tools:node="remove" />
|
||||
</provider>
|
||||
|
||||
<activity
|
||||
android:name=".feature.wallpaper.tasker_shortcut.ActivityConfigBasicAction"
|
||||
android:exported="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="Change wallpaper">
|
||||
<intent-filter>
|
||||
<action android:name="com.twofortyfouram.locale.intent.action.EDIT_SETTING" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".feature.wallpaper.tasker_shortcut.ActivityConfigBasicEvent"
|
||||
android:exported="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="Change wallpaper event">
|
||||
<intent-filter>
|
||||
<action android:name="net.dinglisch.android.tasker.ACTION_EDIT_EVENT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -3,7 +3,6 @@ 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
|
||||
|
||||
/**
|
||||
@@ -14,7 +13,7 @@ class App: Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
val channel = NotificationChannel("wallpaper_service_channel", "Paperize", NotificationManager.IMPORTANCE_LOW)
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,6 @@ package com.anthonyla.paperize.core
|
||||
enum class ScalingConstants {
|
||||
FIT,
|
||||
FILL,
|
||||
STRETCH
|
||||
STRETCH,
|
||||
NONE
|
||||
}
|
||||
@@ -6,24 +6,43 @@ package com.anthonyla.paperize.core
|
||||
object SettingsConstants {
|
||||
const val SETTINGS_DATASTORE = "settings_datastore"
|
||||
const val DARK_MODE_TYPE = "dark_mode_type"
|
||||
const val AMOLED_THEME_TYPE = "amoled_theme_type"
|
||||
const val DYNAMIC_THEME_TYPE = "dynamic_theme_type"
|
||||
const val ANIMATE_TYPE = "animate_type"
|
||||
const val ENABLE_CHANGER = "enable_changer"
|
||||
const val HOME_WALLPAPER = "home_wallpaper"
|
||||
const val LOCK_WALLPAPER = "lock_wallpaper"
|
||||
const val ENABLE_HOME_WALLPAPER = "home_wallpaper"
|
||||
const val ENABLE_LOCK_WALLPAPER = "lock_wallpaper"
|
||||
const val CURRENT_HOME_WALLPAPER = "current_home_wallpaper"
|
||||
const val CURRENT_LOCK_WALLPAPER = "current_lock_wallpaper"
|
||||
const val HOME_ALBUM_NAME = "home_album_name"
|
||||
const val LOCK_ALBUM_NAME = "lock_album_name"
|
||||
const val HOME_WALLPAPER_CHANGE_INTERVAL = "home_wallpaper_change_interval"
|
||||
const val LOCK_WALLPAPER_CHANGE_INTERVAL = "lock_wallpaper_change_interval"
|
||||
const val WALLPAPER_CHANGE_INTERVAL_DEFAULT = 15
|
||||
const val WALLPAPER_CHANGE_INTERVAL_MIN = 1
|
||||
const val FIRST_LAUNCH = "first_launch"
|
||||
const val FIRST_SET = "first_set"
|
||||
const val LAST_SET_TIME = "last_set_time"
|
||||
const val NEXT_SET_TIME = "next_set_time"
|
||||
const val DARKEN_PERCENTAGE = "darken_percentage"
|
||||
const val HOME_DARKEN_PERCENTAGE = "home_darken_percentage"
|
||||
const val LOCK_DARKEN_PERCENTAGE = "darken_darken_percentage"
|
||||
const val DARKEN = "darken"
|
||||
const val WALLPAPER_SCALING = "wallpaper_scaling"
|
||||
const val SCHEDULE_SEPARATELY = "schedule_separately"
|
||||
const val BLUR = "blur"
|
||||
const val BLUR_PERCENTAGE = "blur_percentage"
|
||||
const val NEXT_SET_TIME_1 = "next_set_time_1"
|
||||
const val NEXT_SET_TIME_2 = "next_set_time_2"
|
||||
const val HOME_BLUR_PERCENTAGE = "home_blur_percentage"
|
||||
const val LOCK_BLUR_PERCENTAGE = "lock_blur_percentage"
|
||||
const val VIGNETTE = "vignette"
|
||||
const val HOME_VIGNETTE_PERCENTAGE = "home_vignette_percentage"
|
||||
const val LOCK_VIGNETTE_PERCENTAGE = "lock_vignette_percentage"
|
||||
const val HOME_NEXT_SET_TIME = "next_set_time_1"
|
||||
const val LOCK_NEXT_SET_TIME = "next_set_time_2"
|
||||
const val NEXT_HOME_WALLPAPER = "next_home_wallpaper"
|
||||
const val NEXT_LOCK_WALLPAPER = "next_lock_wallpaper"
|
||||
const val GRAYSCALE = "grayscale"
|
||||
const val HOME_GRAYSCALE_PERCENTAGE = "home_grayscale_percentage"
|
||||
const val LOCK_GRAYSCALE_PERCENTAGE = "lock_grayscale_percentage"
|
||||
const val CHANGE_START_TIME = "change_start_time"
|
||||
const val START_HOUR = "start_hour"
|
||||
const val START_MINUTE = "start_minute"
|
||||
}
|
||||
@@ -1,31 +1,45 @@
|
||||
package com.anthonyla.paperize.core
|
||||
import android.app.WallpaperManager
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.ColorMatrix
|
||||
import android.graphics.ColorMatrixColorFilter
|
||||
import android.graphics.ImageDecoder
|
||||
import android.graphics.Paint
|
||||
import android.graphics.RadialGradient
|
||||
import android.graphics.Rect
|
||||
import android.graphics.RectF
|
||||
import android.graphics.Shader
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.Log
|
||||
import android.util.Size
|
||||
import android.view.WindowManager
|
||||
import android.view.WindowMetrics
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.compose.ui.util.fastRoundToInt
|
||||
import androidx.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import com.anthonyla.paperize.core.ScreenMetricsCompat.getScreenSize
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.google.android.renderscript.Toolkit
|
||||
import com.lazygeniouz.dfc.file.DocumentFileCompat
|
||||
|
||||
enum class Type { HOME, LOCK, BOTH }
|
||||
|
||||
enum class Type { HOME, LOCK, SINGLE, REFRESH }
|
||||
|
||||
/**
|
||||
* Get the dimensions of the image from the uri
|
||||
*/
|
||||
fun Uri.getImageDimensions(context: Context): Size? {
|
||||
try {
|
||||
return try {
|
||||
context.contentResolver.openInputStream(this)?.use { inputStream ->
|
||||
val exif = ExifInterface(inputStream)
|
||||
var width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0)
|
||||
@@ -42,18 +56,112 @@ fun Uri.getImageDimensions(context: Context): Size? {
|
||||
width = options.outWidth
|
||||
height = options.outHeight
|
||||
}
|
||||
return Size(width, height)
|
||||
Size(width, height)
|
||||
}
|
||||
return null
|
||||
} catch (e: Exception) { return null }
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error getting image dimensions: $e")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the inSampleSize for the image
|
||||
*/
|
||||
fun calculateInSampleSize(imageSize: Size, width: Int, height: Int): Int {
|
||||
return if (imageSize.width <= width && imageSize.height <= height) { 1 }
|
||||
else { (imageSize.width/ width.toFloat()).fastRoundToInt() }
|
||||
if (imageSize.width > 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 }
|
||||
}
|
||||
else { return 1 }
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the screen size of the device without orientation
|
||||
* https://stackoverflow.com/a/70087378
|
||||
*/
|
||||
object ScreenMetricsCompat {
|
||||
private val api: Api =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) ApiLevel30() else Api()
|
||||
fun getScreenSize(context: Context): Size = api.getScreenSize(context)
|
||||
@Suppress("DEPRECATION")
|
||||
private open class Api {
|
||||
open fun getScreenSize(context: Context): Size {
|
||||
val display = context.getSystemService(WindowManager::class.java).defaultDisplay
|
||||
val metrics = if (display != null) {
|
||||
DisplayMetrics().also { display.getRealMetrics(it) }
|
||||
} else {
|
||||
Resources.getSystem().displayMetrics
|
||||
}
|
||||
return Size(metrics.widthPixels, metrics.heightPixels)
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
private class ApiLevel30 : Api() {
|
||||
override fun getScreenSize(context: Context): Size {
|
||||
val metrics: WindowMetrics = context.getSystemService(WindowManager::class.java).currentWindowMetrics
|
||||
return Size(metrics.bounds.width(), metrics.bounds.height())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get device screen size with orientation
|
||||
*/
|
||||
fun getDeviceScreenSize(context: Context): Size {
|
||||
val orientation = context.resources.configuration.orientation
|
||||
val size = getScreenSize(context)
|
||||
return if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
Size(size.width, size.height)
|
||||
} else {
|
||||
Size(size.height, size.width)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a bitmap from a URI that is scaled down to the device's screen size
|
||||
*/
|
||||
fun retrieveBitmap(
|
||||
context: Context,
|
||||
wallpaper: Uri,
|
||||
width: Int,
|
||||
height: Int
|
||||
): Bitmap? {
|
||||
val imageSize = wallpaper.getImageDimensions(context) ?: return null
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
try {
|
||||
val source = ImageDecoder.createSource(context.contentResolver, wallpaper)
|
||||
ImageDecoder.decodeBitmap(source) { decoder, _, _ ->
|
||||
decoder.setTargetSampleSize(
|
||||
calculateInSampleSize(
|
||||
imageSize,
|
||||
width,
|
||||
height
|
||||
)
|
||||
)
|
||||
decoder.isMutableRequired = true
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
context.contentResolver.openInputStream(wallpaper)?.use { inputStream ->
|
||||
val options = BitmapFactory.Options().apply {
|
||||
inSampleSize =
|
||||
calculateInSampleSize(imageSize, width, height)
|
||||
inMutable = true
|
||||
}
|
||||
BitmapFactory.decodeStream(inputStream, null, options)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
context.contentResolver.openInputStream(wallpaper)?.use { inputStream ->
|
||||
val options = BitmapFactory.Options().apply {
|
||||
inSampleSize =
|
||||
calculateInSampleSize(imageSize, width, height)
|
||||
inMutable = true
|
||||
}
|
||||
BitmapFactory.decodeStream(inputStream, null, options)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,40 +169,48 @@ fun calculateInSampleSize(imageSize: Size, width: Int, height: Int): Int {
|
||||
* 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
|
||||
return try {
|
||||
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()
|
||||
newBitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error fitting bitmap: $e")
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale a bitmap using the fill height method
|
||||
* Scale a bitmap using the fit method
|
||||
*/
|
||||
fun fillBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
try {
|
||||
return try {
|
||||
val aspectRatio = source.width.toFloat() / source.height.toFloat()
|
||||
var newWidth = width
|
||||
var newHeight = (newWidth / aspectRatio).toInt()
|
||||
if (newHeight < height) {
|
||||
val newWidth: Int
|
||||
val newHeight: Int
|
||||
if (width > height * aspectRatio) {
|
||||
newWidth = width
|
||||
newHeight = (width / aspectRatio).toInt()
|
||||
} else {
|
||||
newHeight = height
|
||||
newWidth = (newHeight * aspectRatio).toInt()
|
||||
newWidth = (height * aspectRatio).toInt()
|
||||
}
|
||||
val scaledBitmap = Bitmap.createScaledBitmap(source, newWidth, newHeight, true)
|
||||
val x = (width - newWidth) / 2f
|
||||
val y = (height - newHeight) / 2f
|
||||
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
|
||||
bitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error filling bitmap: $e")
|
||||
return source
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,16 +218,16 @@ fun fillBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
* Stretch the bitmap to fit the given width and height
|
||||
*/
|
||||
fun stretchBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
try {
|
||||
return 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
|
||||
newBitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error stretching bitmap: $e")
|
||||
return source
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +235,7 @@ fun stretchBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
* Darken the bitmap by a certain percentage - 0 is darkest, 100 is original
|
||||
*/
|
||||
fun darkenBitmap(source: Bitmap, percent: Int): Bitmap {
|
||||
try {
|
||||
return try {
|
||||
val safePercentage = (100 - percent).coerceIn(0, 100)
|
||||
val factor = 1 - safePercentage / 100f
|
||||
val canvas = Canvas(source)
|
||||
@@ -129,35 +245,114 @@ fun darkenBitmap(source: Bitmap, percent: Int): Bitmap {
|
||||
})
|
||||
}
|
||||
canvas.drawBitmap(source, 0f, 0f, paint)
|
||||
return source
|
||||
source
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error darkening bitmap: $e")
|
||||
return source
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Blur the bitmap by a certain percentage
|
||||
*/
|
||||
fun blurBitmap(source: Bitmap, percent: Int): Bitmap {
|
||||
try {
|
||||
val factor = percent.toFloat().div(100f) * 10
|
||||
return Toolkit.blur(source, factor.toInt())
|
||||
return try {
|
||||
val factor = percent.toFloat().div(100f) * 20f
|
||||
Toolkit.blur(source, factor.toInt())
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error darkening bitmap: $e")
|
||||
return source
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a vignette effect to the bitmap
|
||||
*/
|
||||
fun vignetteBitmap(source: Bitmap, percent: Int): Bitmap {
|
||||
return try {
|
||||
val image = Bitmap.createBitmap(source.width, source.height, Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(image)
|
||||
canvas.drawBitmap(source, 0f, 0f, Paint())
|
||||
val rad: Int = if (source.width < source.height) {
|
||||
val o = (source.height * 2) / 100
|
||||
source.height - o * percent / 3
|
||||
} else {
|
||||
val o = (source.width * 2) / 100
|
||||
source.width - o * percent / 3
|
||||
}
|
||||
val rect = Rect(0, 0, source.width, source.height)
|
||||
val rectF = RectF(rect)
|
||||
val colors = intArrayOf(0, 0, Color.BLACK)
|
||||
val pos = floatArrayOf(0.0f, 0.1f, 1.0f)
|
||||
val linGradLR: Shader = RadialGradient(
|
||||
rect.centerX().toFloat(),
|
||||
rect.centerY().toFloat(),
|
||||
rad.toFloat(),
|
||||
colors,
|
||||
pos,
|
||||
Shader.TileMode.CLAMP
|
||||
)
|
||||
val paint = Paint().apply {
|
||||
shader = linGradLR
|
||||
isAntiAlias = true
|
||||
isDither = true
|
||||
alpha = 128
|
||||
}
|
||||
canvas.drawRect(rectF, paint)
|
||||
image
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error applying vignette effect: $e")
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a grey filter to the bitmap based on a percentage
|
||||
*/
|
||||
fun grayBitmap(bitmap: Bitmap, percent: Int): Bitmap {
|
||||
val factor = percent / 100f
|
||||
val colorMatrix = ColorMatrix().apply {
|
||||
setSaturation(1 - factor)
|
||||
}
|
||||
val paint = Paint().apply {
|
||||
colorFilter = ColorMatrixColorFilter(colorMatrix)
|
||||
}
|
||||
val grayBitmap = Bitmap.createBitmap(bitmap.width, bitmap.height, Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(grayBitmap)
|
||||
canvas.drawBitmap(bitmap, 0f, 0f, paint)
|
||||
|
||||
return grayBitmap
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the brightness of a bitmap (0-100)
|
||||
* https://gist.github.com/httnn/b1d772caf76cdc0c11e2
|
||||
*/
|
||||
fun calculateBrightness(bitmap: Bitmap, pixelSpacing: Int = 1): Int {
|
||||
var brightness = 0.0
|
||||
val pixels = IntArray(bitmap.width * bitmap.height)
|
||||
bitmap.getPixels(pixels, 0, bitmap.width, 0, 0, bitmap.width, bitmap.height)
|
||||
for (i in pixels.indices step pixelSpacing.coerceAtLeast(1)) {
|
||||
val color = pixels[i]
|
||||
val R = Color.red(color)
|
||||
val G = Color.green(color)
|
||||
val B = Color.blue(color)
|
||||
brightness += 0.299*R + 0.587*G + 0.114*B
|
||||
}
|
||||
return (brightness / (pixels.size / pixelSpacing)).toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve wallpaper URIs from a folder directory URI
|
||||
*/
|
||||
fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
|
||||
try {
|
||||
return try {
|
||||
val folderDocumentFile = DocumentFileCompat.fromTreeUri(context, folderUri.toUri())
|
||||
return listFilesRecursive(folderDocumentFile, context)
|
||||
} catch (e: Exception) {
|
||||
listFilesRecursive(folderDocumentFile, context)
|
||||
} catch (_: Exception) {
|
||||
val folderDocumentFile = DocumentFile.fromTreeUri(context, folderUri.toUri())
|
||||
return listFilesRecursive(folderDocumentFile, context)
|
||||
listFilesRecursive(folderDocumentFile, context)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,6 +372,7 @@ fun listFilesRecursive(parent: DocumentFileCompat?, context: Context): List<Stri
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
/** Overloaded version of the function for DocumentFile */
|
||||
fun listFilesRecursive(parent: DocumentFile?, context: Context): List<String> {
|
||||
val files = mutableListOf<String>()
|
||||
@@ -199,16 +395,30 @@ fun listFilesRecursive(parent: DocumentFile?, context: Context): List<String> {
|
||||
*/
|
||||
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
|
||||
try {
|
||||
val file = DocumentFileCompat.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
|
||||
if (file?.exists() == true) {
|
||||
return wallpaper.wallpaperUri
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
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
|
||||
try {
|
||||
val file = DocumentFileCompat.fromSingleUri(context, wallpaper.toUri())
|
||||
if (file?.exists() == true) {
|
||||
return wallpaper
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
val file = DocumentFile.fromSingleUri(context, wallpaper.toUri())
|
||||
if (file?.exists() == true) {
|
||||
return wallpaper
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,7 +431,7 @@ fun findFirstValidUri(context: Context, wallpapers: List<Wallpaper>, folders: Li
|
||||
fun getFolderNameFromUri(folderUri: String, context: Context): String? {
|
||||
return try {
|
||||
DocumentFileCompat.fromTreeUri(context, folderUri.toUri())?.name
|
||||
} catch (e: Exception) {
|
||||
} catch (_: Exception) {
|
||||
DocumentFile.fromTreeUri(context, folderUri.toUri())?.name
|
||||
}
|
||||
}
|
||||
@@ -237,14 +447,61 @@ fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
inputStream?.close()
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) { false }
|
||||
} catch (_: Exception) { false }
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if device uses a live wallpaper
|
||||
* Darkens the bitmap by the given percentage and returns it
|
||||
* 0 - lightest, 100 - darkest
|
||||
*/
|
||||
fun isLiveWallpaperSet(context: Context): Boolean {
|
||||
val wallpaperManager = WallpaperManager.getInstance(context)
|
||||
return wallpaperManager.wallpaperInfo != null
|
||||
}
|
||||
fun processBitmap(
|
||||
width: Int,
|
||||
height: Int,
|
||||
source: Bitmap,
|
||||
darken: Boolean,
|
||||
darkenPercent: Int,
|
||||
scaling: ScalingConstants,
|
||||
blur: Boolean,
|
||||
blurPercent: Int,
|
||||
vignette: Boolean,
|
||||
vignettePercent: Int,
|
||||
grayscale: Boolean,
|
||||
grayscalePercent: Int
|
||||
): Bitmap? {
|
||||
try {
|
||||
var processedBitmap = source
|
||||
|
||||
// Apply wallpaper scaling effects
|
||||
processedBitmap = when (scaling) {
|
||||
ScalingConstants.FILL -> fillBitmap(processedBitmap, width, height)
|
||||
ScalingConstants.FIT -> fitBitmap(processedBitmap, width, height)
|
||||
ScalingConstants.STRETCH -> stretchBitmap(processedBitmap, width, height)
|
||||
ScalingConstants.NONE -> processedBitmap
|
||||
}
|
||||
|
||||
// Apply brightness effect
|
||||
if (darken && darkenPercent < 100) {
|
||||
processedBitmap = darkenBitmap(processedBitmap, darkenPercent)
|
||||
}
|
||||
|
||||
// Apply blur effect
|
||||
if (blur && blurPercent > 0) {
|
||||
processedBitmap = blurBitmap(processedBitmap, blurPercent)
|
||||
}
|
||||
|
||||
// Apply vignette effect
|
||||
if (vignette && vignettePercent > 0) {
|
||||
processedBitmap = vignetteBitmap(processedBitmap, vignettePercent)
|
||||
}
|
||||
|
||||
// Apply gray effect
|
||||
if (grayscale && grayscalePercent > 0) {
|
||||
processedBitmap = grayBitmap(processedBitmap, grayscalePercent)
|
||||
}
|
||||
|
||||
return processedBitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error darkening bitmap", e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -3,14 +3,12 @@ package com.anthonyla.paperize.data
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.core.content.ContextCompat.startActivity
|
||||
|
||||
/**
|
||||
* Opens an email intent to contact the developer.
|
||||
*/
|
||||
@Composable
|
||||
fun Contact(context: Context) {
|
||||
fun SendContactIntent(context: Context) {
|
||||
val authorEmail = "anthonyyla.dev@gmail.com"
|
||||
val cc = ""
|
||||
val subject = "[Support] Paperize"
|
||||
@@ -11,8 +11,9 @@ 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 {
|
||||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = SETTINGS_DATASTORE)
|
||||
|
||||
class SettingsDataStoreImpl(private val context: Context) : SettingsDataStore {
|
||||
override suspend fun putBoolean(key: String, value: Boolean) {
|
||||
val preferencesKey = booleanPreferencesKey(key)
|
||||
context.dataStore.edit {
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.app_shortcut
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperBootAndChangeReceiver
|
||||
|
||||
class BroadcastActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val intent = Intent("WallpaperBootAndChangeReceiver.intent.action.BROADCAST").setClass(this, WallpaperBootAndChangeReceiver::class.java)
|
||||
sendBroadcast(intent)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -13,7 +13,7 @@ import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
*/
|
||||
@Database(
|
||||
entities = [Album::class, Wallpaper::class, Folder::class],
|
||||
version = 4
|
||||
version = 5
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class AlbumDatabase: RoomDatabase() {
|
||||
|
||||
+9
-7
@@ -6,7 +6,6 @@ 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
|
||||
@@ -31,13 +30,13 @@ interface SelectedAlbumDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun upsertWallpaperList(wallpapers: List<Wallpaper>)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteAlbum(album: Album)
|
||||
@Query("DELETE FROM album WHERE initialAlbumName = :initialAlbumName")
|
||||
suspend fun deleteAlbum(initialAlbumName: String)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteWallpaper(wallpaper: Wallpaper)
|
||||
|
||||
@Query("DELETE FROM wallpaper WHERE initialAlbumName=:initialAlbumName")
|
||||
@Query("DELETE FROM wallpaper WHERE initialAlbumName = :initialAlbumName")
|
||||
suspend fun cascadeDeleteWallpaper(initialAlbumName: String)
|
||||
|
||||
@Query("DELETE FROM album")
|
||||
@@ -46,12 +45,15 @@ interface SelectedAlbumDao {
|
||||
@Query("DELETE FROM wallpaper")
|
||||
suspend fun deleteAllWallpapers()
|
||||
|
||||
@Update
|
||||
suspend fun updateAlbum(album: Album)
|
||||
|
||||
@Transaction
|
||||
suspend fun deleteAll() {
|
||||
deleteAllAlbums()
|
||||
deleteAllWallpapers()
|
||||
}
|
||||
|
||||
@Transaction
|
||||
suspend fun upsertSelectedAlbum(selectedAlbum: SelectedAlbum) {
|
||||
upsertAlbum(selectedAlbum.album)
|
||||
upsertWallpaperList(selectedAlbum.wallpapers)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -12,7 +12,7 @@ import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
*/
|
||||
@Database(
|
||||
entities = [Album::class, Wallpaper::class],
|
||||
version = 4
|
||||
version = 5
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class SelectedAlbumDatabase: RoomDatabase() {
|
||||
|
||||
+6
-23
@@ -1,7 +1,6 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.data.repository
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.data.data_source.SelectedAlbumDao
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.SelectedAlbumRepository
|
||||
@@ -15,38 +14,22 @@ class SelectedAlbumRepositoryImpl(
|
||||
}
|
||||
|
||||
override suspend fun upsertSelectedAlbum(selectedAlbum: SelectedAlbum) {
|
||||
dao.deleteAll()
|
||||
dao.upsertAlbum(selectedAlbum.album)
|
||||
dao.upsertWallpaperList(selectedAlbum.wallpapers)
|
||||
dao.upsertSelectedAlbum(selectedAlbum)
|
||||
}
|
||||
|
||||
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 deleteAlbum(initialAlbumName: String) {
|
||||
dao.deleteAlbum(initialAlbumName)
|
||||
}
|
||||
|
||||
override suspend fun deleteWallpaper(wallpaper: Wallpaper) {
|
||||
dao.deleteWallpaper(wallpaper)
|
||||
}
|
||||
|
||||
override suspend fun cascadeDeleteWallpaper(initialAlbumName: String) {
|
||||
override suspend fun cascadeDeleteAlbum(initialAlbumName: String) {
|
||||
dao.deleteAlbum(initialAlbumName)
|
||||
dao.cascadeDeleteWallpaper(initialAlbumName)
|
||||
}
|
||||
|
||||
override suspend fun deleteAll() {
|
||||
dao.deleteAll()
|
||||
}
|
||||
|
||||
@@ -10,10 +10,8 @@ import androidx.room.PrimaryKey
|
||||
* @param displayedAlbumName The displayed album name
|
||||
* @param coverUri The cover uri of the album
|
||||
* @param initialized Whether the album has been initialized
|
||||
* @param homeWallpapersInQueue The wallpapers in the queue to be displayed for the home screen or when the user schedules both lock and home together
|
||||
* @param lockWallpapersInQueue The wallpapers in the queue to be displayed for the lock screen when scheduled separately
|
||||
* @param currentHomeWallpaper The current wallpaper for the home screen
|
||||
* @param currentLockWallpaper The current wallpaper for the lock screen
|
||||
* @param homeWallpapersInQueue The list of home wallpapers in the queue
|
||||
* @param lockWallpapersInQueue The list of lock wallpapers in the queue
|
||||
*/
|
||||
@Entity
|
||||
data class Album(
|
||||
@@ -23,6 +21,4 @@ data class Album(
|
||||
val initialized: Boolean = false,
|
||||
val homeWallpapersInQueue: List<String> = emptyList(),
|
||||
val lockWallpapersInQueue: List<String> = emptyList(),
|
||||
val currentHomeWallpaper: String? = null,
|
||||
val currentLockWallpaper: String? = null
|
||||
)
|
||||
+3
-25
@@ -1,6 +1,5 @@
|
||||
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
|
||||
@@ -16,31 +15,10 @@ interface SelectedAlbumRepository {
|
||||
*/
|
||||
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>)
|
||||
suspend fun deleteAlbum(initialAlbumName: String)
|
||||
|
||||
/**
|
||||
* Delete wallpaper from database
|
||||
@@ -48,9 +26,9 @@ interface SelectedAlbumRepository {
|
||||
suspend fun deleteWallpaper(wallpaper: Wallpaper)
|
||||
|
||||
/**
|
||||
* Delete all wallpapers and folders from database
|
||||
* Cascade delete album and its wallpaper and folder. Proper way to delete an AlbumWithWallpaperAndFolder
|
||||
*/
|
||||
suspend fun cascadeDeleteWallpaper(initialAlbumName: String)
|
||||
suspend fun cascadeDeleteAlbum(initialAlbumName: String)
|
||||
|
||||
/**
|
||||
* Delete all data from database
|
||||
|
||||
+75
-26
@@ -18,7 +18,6 @@ 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
|
||||
@@ -41,8 +40,8 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.themes.PaperizeThem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreenViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmSchedulerImpl
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperReceiver
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperScheduler
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
@@ -55,7 +54,6 @@ class MainActivity : ComponentActivity() {
|
||||
private val settingsViewModel: SettingsViewModel by viewModels()
|
||||
private val wallpaperScreenViewModel: WallpaperScreenViewModel by viewModels()
|
||||
private val context = this
|
||||
private var topInset = 0.dp
|
||||
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -81,11 +79,12 @@ class MainActivity : ComponentActivity() {
|
||||
splashScreen.setKeepOnScreenCondition { settingsViewModel.setKeepOnScreenCondition }
|
||||
|
||||
setContent {
|
||||
val scheduler = WallpaperScheduler(context)
|
||||
val scheduler = WallpaperAlarmSchedulerImpl(context)
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
val isFirstLaunch = runBlocking { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) } ?: true
|
||||
if (isFirstLaunch) {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
scheduler.cancelWallpaperAlarm()
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset())
|
||||
settingsViewModel.onEvent(SettingsEvent.Reset)
|
||||
albumsViewModel.onEvent(AlbumsEvent.Reset)
|
||||
val contentResolver = context.contentResolver
|
||||
@@ -97,28 +96,84 @@ class MainActivity : ComponentActivity() {
|
||||
LifecycleEventEffect(Lifecycle.Event.ON_CREATE) {
|
||||
lifecycleScope.launch {
|
||||
if (settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) == true) {
|
||||
val shouldScheduleSeparately = settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false
|
||||
val shouldScheduleAlarm = if (shouldScheduleSeparately) {
|
||||
!(isPendingIntentSet(Type.HOME.ordinal) && isPendingIntentSet(Type.LOCK.ordinal))
|
||||
} else {
|
||||
!isPendingIntentSet(Type.BOTH.ordinal)
|
||||
val homeAlbumName = settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME)
|
||||
val lockAlbumName = settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME)
|
||||
if (homeAlbumName.isNullOrEmpty() || lockAlbumName.isNullOrEmpty()) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
|
||||
}
|
||||
if (shouldScheduleAlarm) {
|
||||
scheduler.scheduleWallpaperAlarm(
|
||||
WallpaperAlarmItem(
|
||||
timeInMinutes1 = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
timeInMinutes2 = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
scheduleSeparately = shouldScheduleSeparately
|
||||
), null, true, true
|
||||
)
|
||||
else {
|
||||
val shouldScheduleSeparately = settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false
|
||||
val shouldScheduleAlarm = if (shouldScheduleSeparately) {
|
||||
!(isPendingIntentSet(Type.HOME.ordinal) && isPendingIntentSet(Type.LOCK.ordinal))
|
||||
} else {
|
||||
!isPendingIntentSet(Type.SINGLE.ordinal)
|
||||
}
|
||||
if (shouldScheduleAlarm) {
|
||||
scheduler.scheduleWallpaperAlarm(
|
||||
WallpaperAlarmItem(
|
||||
homeInterval = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
lockInterval = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
setLock = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false,
|
||||
setHome = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false,
|
||||
scheduleSeparately = shouldScheduleSeparately,
|
||||
changeStartTime = settingsDataStoreImpl.getBoolean(SettingsConstants.CHANGE_START_TIME) ?: false,
|
||||
startTime = Pair(
|
||||
settingsDataStoreImpl.getInt(SettingsConstants.START_HOUR) ?: 0,
|
||||
settingsDataStoreImpl.getInt(SettingsConstants.START_MINUTE) ?: 0
|
||||
),
|
||||
),
|
||||
origin = null,
|
||||
changeImmediate = true,
|
||||
cancelImmediate = true,
|
||||
firstLaunch = true
|
||||
)
|
||||
settingsViewModel.onEvent(SettingsEvent.RefreshNextSetTime)
|
||||
val selectedState = wallpaperScreenViewModel.state.value
|
||||
val currentHomeAlbum = selectedState.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.homeAlbumName }
|
||||
val currentLockAlbum = selectedState.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.lockAlbumName }
|
||||
when {
|
||||
settingsState.value.scheduleSeparately && settingsState.value.setHomeWallpaper && settingsState.value.setLockWallpaper -> {
|
||||
if (currentHomeAlbum != null && currentLockAlbum != null) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
|
||||
currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri,
|
||||
currentLockWallpaper = currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri
|
||||
))
|
||||
}
|
||||
}
|
||||
!settingsState.value.scheduleSeparately && settingsState.value.setHomeWallpaper && settingsState.value.setLockWallpaper -> {
|
||||
if (currentHomeAlbum != null && currentLockAlbum != null) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
|
||||
currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri,
|
||||
currentLockWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri
|
||||
))
|
||||
}
|
||||
}
|
||||
settingsState.value.setHomeWallpaper -> {
|
||||
if (currentHomeAlbum != null) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
|
||||
currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri,
|
||||
currentLockWallpaper = if (settingsState.value.scheduleSeparately) null else currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri
|
||||
))
|
||||
}
|
||||
}
|
||||
settingsState.value.setLockWallpaper -> {
|
||||
if (currentLockAlbum != null) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
|
||||
currentHomeWallpaper = if (settingsState.value.scheduleSeparately) null else currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri,
|
||||
currentLockWallpaper = currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PaperizeTheme(settingsState.value.darkMode, settingsState.value.dynamicTheming) {
|
||||
PaperizeTheme(settingsState.value.darkMode, settingsState.value.amoledTheme, settingsState.value.dynamicTheming) {
|
||||
Surface(tonalElevation = 5.dp) {
|
||||
PaperizeApp(isFirstLaunch, scheduler, topInset)
|
||||
PaperizeApp(isFirstLaunch, scheduler)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,12 +192,6 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
topInset = window.decorView.rootWindowInsets.stableInsetTop.dp
|
||||
}
|
||||
|
||||
private fun isPendingIntentSet(requestCode: Int): Boolean {
|
||||
val intent = Intent(context.applicationContext, WallpaperReceiver::class.java)
|
||||
val pendingIntent = PendingIntent.getBroadcast(
|
||||
|
||||
+558
-255
File diff suppressed because it is too large.
Load diff
+136
-109
@@ -5,19 +5,18 @@ import android.net.Uri
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.scaleIn
|
||||
import androidx.compose.animation.scaleOut
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.items
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -33,26 +32,23 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.co
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumSmallTopBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.FolderItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
|
||||
import my.nanihadesuka.compose.LazyVerticalGridScrollbar
|
||||
import my.nanihadesuka.compose.ScrollbarSettings
|
||||
|
||||
@Composable
|
||||
fun AddAlbumScreen(
|
||||
addAlbumViewModel: AddAlbumViewModel = hiltViewModel(),
|
||||
settingsViewModel: SettingsViewModel = hiltViewModel(),
|
||||
initialAlbumName: String,
|
||||
onBackClick: () -> Unit,
|
||||
onConfirmation: () -> Unit,
|
||||
onShowWallpaperView: (String) -> Unit,
|
||||
onShowFolderView: (String?, List<String>) -> Unit
|
||||
onShowFolderView: (String?, List<String>) -> Unit,
|
||||
animate: Boolean
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val lazyGridState = rememberLazyStaggeredGridState()
|
||||
val lazyListState = rememberLazyGridState()
|
||||
val addAlbumState = addAlbumViewModel.state.collectAsStateWithLifecycle()
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
var selectionMode by rememberSaveable { mutableStateOf(false) }
|
||||
if (addAlbumState.value.initialAlbumName.isEmpty()) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.SetAlbumName(initialAlbumName))
|
||||
}
|
||||
var showSpotlight by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
BackHandler(
|
||||
@@ -126,110 +122,141 @@ fun AddAlbumScreen(
|
||||
)
|
||||
},
|
||||
floatingActionButton = {
|
||||
if (settingsState.value.animate) {
|
||||
AnimatedVisibility(
|
||||
visible = !lazyGridState.isScrollInProgress || lazyGridState.firstVisibleItemScrollOffset < 0,
|
||||
enter = scaleIn(tween(400, 50, FastOutSlowInEasing)),
|
||||
exit = scaleOut(tween(400, 50, FastOutSlowInEasing)),
|
||||
) {
|
||||
AddAlbumAnimatedFab(
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
},
|
||||
animate = true
|
||||
)
|
||||
AddAlbumAnimatedFab(
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
}
|
||||
}
|
||||
else {
|
||||
AddAlbumAnimatedFab(
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
showSpotlight = true
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
showSpotlight = true
|
||||
},
|
||||
animate = false
|
||||
)
|
||||
}
|
||||
)
|
||||
},
|
||||
content = {
|
||||
LazyVerticalStaggeredGrid(
|
||||
state = lazyGridState,
|
||||
LazyVerticalGridScrollbar(
|
||||
state = lazyListState,
|
||||
settings = ScrollbarSettings.Default.copy(
|
||||
thumbUnselectedColor = MaterialTheme.colorScheme.primary,
|
||||
thumbSelectedColor = MaterialTheme.colorScheme.primary,
|
||||
thumbShape = RoundedCornerShape(16.dp),
|
||||
scrollbarPadding = 1.dp,
|
||||
),
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(it),
|
||||
columns = StaggeredGridCells.Fixed(2),
|
||||
contentPadding = PaddingValues(4.dp, 4.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
content = {
|
||||
items (items = addAlbumState.value.folders, key = { folder -> folder.folderUri }
|
||||
) { folder ->
|
||||
FolderItem(
|
||||
folder = folder,
|
||||
itemSelected = addAlbumState.value.selectedFolders.contains(folder.folderUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
addAlbumViewModel.onEvent(
|
||||
if (!addAlbumState.value.selectedFolders.contains(folder.folderUri))
|
||||
AddAlbumEvent.SelectFolder(folder.folderUri)
|
||||
else {
|
||||
AddAlbumEvent.RemoveFolderFromSelection(folder.folderUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onFolderViewClick = {
|
||||
if (folder.wallpapers.isNotEmpty()) onShowFolderView(folder.folderName, folder.wallpapers)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
) {
|
||||
LazyVerticalGrid(
|
||||
state = lazyListState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
columns = GridCells.Adaptive(150.dp),
|
||||
contentPadding = PaddingValues(4.dp, 4.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
) {
|
||||
items(count = addAlbumState.value.folders.size, key = { index -> addAlbumState.value.folders[index].folderUri }) { index ->
|
||||
if (animate) {
|
||||
FolderItem(
|
||||
folder = addAlbumState.value.folders[index],
|
||||
itemSelected = addAlbumState.value.selectedFolders.contains(addAlbumState.value.folders[index].folderUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
addAlbumViewModel.onEvent(
|
||||
if (!addAlbumState.value.selectedFolders.contains(addAlbumState.value.folders[index].folderUri))
|
||||
AddAlbumEvent.SelectFolder(addAlbumState.value.folders[index].folderUri)
|
||||
else {
|
||||
AddAlbumEvent.RemoveFolderFromSelection(addAlbumState.value.folders[index].folderUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onFolderViewClick = {
|
||||
if (addAlbumState.value.folders[index].wallpapers.isNotEmpty()) onShowFolderView(addAlbumState.value.folders[index].folderName, addAlbumState.value.folders[index].wallpapers)
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.size(150.dp, 350.dp)
|
||||
.animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
else {
|
||||
FolderItem(
|
||||
folder = addAlbumState.value.folders[index],
|
||||
itemSelected = addAlbumState.value.selectedFolders.contains(addAlbumState.value.folders[index].folderUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
addAlbumViewModel.onEvent(
|
||||
if (!addAlbumState.value.selectedFolders.contains(addAlbumState.value.folders[index].folderUri))
|
||||
AddAlbumEvent.SelectFolder(addAlbumState.value.folders[index].folderUri)
|
||||
else {
|
||||
AddAlbumEvent.RemoveFolderFromSelection(addAlbumState.value.folders[index].folderUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onFolderViewClick = {
|
||||
if (addAlbumState.value.folders[index].wallpapers.isNotEmpty()) onShowFolderView(addAlbumState.value.folders[index].folderName, addAlbumState.value.folders[index].wallpapers)
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.size(150.dp, 350.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
items (items = addAlbumState.value.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri }
|
||||
) { wallpaper ->
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper.wallpaperUri,
|
||||
itemSelected = addAlbumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
addAlbumViewModel.onEvent(
|
||||
if (!addAlbumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri))
|
||||
AddAlbumEvent.SelectWallpaper(wallpaper.wallpaperUri)
|
||||
else {
|
||||
AddAlbumEvent.RemoveWallpaperFromSelection(wallpaper.wallpaperUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper.wallpaperUri)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
),
|
||||
animate = settingsState.value.animate
|
||||
)
|
||||
items(count = addAlbumState.value.wallpapers.size, key = { index -> addAlbumState.value.wallpapers[index].wallpaperUri }) { index ->
|
||||
if (animate) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = addAlbumState.value.wallpapers[index].wallpaperUri,
|
||||
itemSelected = addAlbumState.value.selectedWallpapers.contains(addAlbumState.value.wallpapers[index].wallpaperUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
addAlbumViewModel.onEvent(
|
||||
if (!addAlbumState.value.selectedWallpapers.contains(addAlbumState.value.wallpapers[index].wallpaperUri))
|
||||
AddAlbumEvent.SelectWallpaper(addAlbumState.value.wallpapers[index].wallpaperUri)
|
||||
else {
|
||||
AddAlbumEvent.RemoveWallpaperFromSelection(addAlbumState.value.wallpapers[index].wallpaperUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(addAlbumState.value.wallpapers[index].wallpaperUri)
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.size(150.dp, 350.dp)
|
||||
.animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
else {
|
||||
WallpaperItem(
|
||||
wallpaperUri = addAlbumState.value.wallpapers[index].wallpaperUri,
|
||||
itemSelected = addAlbumState.value.selectedWallpapers.contains(addAlbumState.value.wallpapers[index].wallpaperUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
},
|
||||
onWallpaperViewClick = {
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.size(150.dp, 350.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
+4
-14
@@ -53,23 +53,13 @@ class AddAlbumViewModel @Inject constructor(
|
||||
initialAlbumName = _state.value.initialAlbumName,
|
||||
displayedAlbumName = _state.value.displayedAlbumName,
|
||||
coverUri = albumCoverUri,
|
||||
initialized = false,
|
||||
),
|
||||
wallpapers = _state.value.wallpapers,
|
||||
folders = _state.value.folders,
|
||||
)
|
||||
repository.upsertAlbumWithWallpaperAndFolder(albumWithWallpaperAndFolder)
|
||||
_state.update { it.copy(
|
||||
initialAlbumName = "",
|
||||
displayedAlbumName = "",
|
||||
coverUri = "",
|
||||
wallpapers = emptyList(),
|
||||
folders = emptyList(),
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
isEmpty = false,
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
) }
|
||||
_state.update { AddAlbumState() }
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.DeleteSelected -> {
|
||||
@@ -121,7 +111,7 @@ class AddAlbumViewModel @Inject constructor(
|
||||
Wallpaper(
|
||||
initialAlbumName = _state.value.initialAlbumName,
|
||||
wallpaperUri = uri,
|
||||
key = uri.hashCode() + _state.value.initialAlbumName.hashCode(),
|
||||
key = uri.hashCode() + _state.value.initialAlbumName.hashCode() + System.currentTimeMillis().toInt()
|
||||
)
|
||||
}
|
||||
_state.update {
|
||||
@@ -156,7 +146,7 @@ class AddAlbumViewModel @Inject constructor(
|
||||
folderUri = event.directoryUri,
|
||||
coverUri = wallpapers.randomOrNull(),
|
||||
wallpapers = wallpapers,
|
||||
key = event.directoryUri.hashCode() + it.initialAlbumName.hashCode()
|
||||
key = event.directoryUri.hashCode() + it.initialAlbumName.hashCode() + System.currentTimeMillis().toInt()
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
+144
-144
@@ -1,9 +1,10 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.AnimatedContent
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.LinearEasing
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.spring
|
||||
@@ -11,10 +12,14 @@ import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.animation.scaleIn
|
||||
import androidx.compose.animation.scaleOut
|
||||
import androidx.compose.animation.togetherWith
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
@@ -24,12 +29,13 @@ import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.Folder
|
||||
import androidx.compose.material.icons.filled.PhotoLibrary
|
||||
import androidx.compose.material.icons.filled.Remove
|
||||
import androidx.compose.material3.CardColors
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.ElevatedCard
|
||||
import androidx.compose.material3.FloatingActionButtonDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LargeFloatingActionButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -38,12 +44,9 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components.MenuRow
|
||||
|
||||
/**
|
||||
* Animated FAB that expands to show two options: Add image and Add folder
|
||||
@@ -51,173 +54,170 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.comp
|
||||
*/
|
||||
@Composable
|
||||
fun AddAlbumAnimatedFab(
|
||||
animate: Boolean,
|
||||
onImageClick: () -> Unit,
|
||||
onFolderClick: () -> Unit
|
||||
) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
val fabTransition = updateTransition(targetState = expanded, label = "")
|
||||
val expandedWidth = 165.dp
|
||||
val itemSize = 2
|
||||
val menuColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
val fabColor = MaterialTheme.colorScheme.primaryContainer
|
||||
var isFabExpanded by remember { mutableStateOf(false) }
|
||||
BackHandler(isFabExpanded) { isFabExpanded = false }
|
||||
|
||||
BackHandler(expanded) { expanded = false }
|
||||
val fabTransition = updateTransition(targetState = isFabExpanded, label = "fabTransition")
|
||||
|
||||
val expandHorizontalSize = Pair(165.dp, 90.dp)
|
||||
val expandHorizontally by fabTransition.animateDp(
|
||||
transitionSpec = { spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow) }, label = "",
|
||||
targetValueByState = { isExpanded ->
|
||||
if (isExpanded) expandHorizontalSize.first else expandHorizontalSize.second
|
||||
val expandFabHorizontally by fabTransition.animateDp(
|
||||
transitionSpec = {
|
||||
spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)
|
||||
},
|
||||
label = "expandVertically",
|
||||
targetValueByState = {isExpanded ->
|
||||
if (isExpanded) expandedWidth else 96.dp
|
||||
}
|
||||
)
|
||||
|
||||
val shrinkVerticalSize = Pair(50.dp, 90.dp)
|
||||
val shrinkVertically by fabTransition.animateDp(
|
||||
transitionSpec = { spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow) }, label = "",
|
||||
targetValueByState = { isExpanded ->
|
||||
if (isExpanded) shrinkVerticalSize.first else shrinkVerticalSize.second
|
||||
val shrinkFabVertically by fabTransition.animateDp(
|
||||
transitionSpec = {
|
||||
spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)
|
||||
},
|
||||
label = "shrinkHorizontally",
|
||||
targetValueByState = {isExpanded ->
|
||||
if (isExpanded) 60.dp else 96.dp
|
||||
}
|
||||
)
|
||||
|
||||
val menuHeightSize = Pair(100.dp, 90.dp)
|
||||
val menuHeight by fabTransition.animateDp(
|
||||
transitionSpec = { spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow) }, label = "",
|
||||
targetValueByState = { isExpanded ->
|
||||
if (isExpanded) menuHeightSize.first else menuHeightSize.second
|
||||
transitionSpec = {
|
||||
spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)
|
||||
},
|
||||
label = "menuHeight",
|
||||
targetValueByState = {isExpanded ->
|
||||
if (isExpanded) (itemSize * 50).dp else 0.dp
|
||||
}
|
||||
)
|
||||
|
||||
if (animate) {
|
||||
ElevatedCard(
|
||||
colors = CardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
contentColor = Color.Transparent,
|
||||
disabledContentColor = Color.Transparent,
|
||||
disabledContainerColor = Color.Transparent,
|
||||
),
|
||||
shape = RoundedCornerShape(28.dp),
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.width(expandHorizontally)
|
||||
.pointerInput(Unit) {
|
||||
detectTapGestures(onTap = { expanded = false })
|
||||
}
|
||||
ElevatedCard(
|
||||
modifier = Modifier.padding(4.dp),
|
||||
shape = RoundedCornerShape(28.dp),
|
||||
elevation = CardDefaults.elevatedCardElevation(4.dp),
|
||||
colors = CardDefaults.elevatedCardColors().copy(
|
||||
containerColor = menuColor
|
||||
)
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.SpaceEvenly,
|
||||
modifier = Modifier.height(menuHeight)
|
||||
) {
|
||||
AnimatedVisibility(
|
||||
visible = expanded,
|
||||
enter = fadeIn(tween(300, 0, FastOutSlowInEasing)),
|
||||
exit = fadeOut(tween(300, 0, FastOutSlowInEasing)),
|
||||
modifier = Modifier.animateContentSize(tween(50, 0, FastOutSlowInEasing)),
|
||||
visible = isFabExpanded,
|
||||
label = stringResource(R.string.add_images_btn),
|
||||
enter = fadeIn(tween(300, 150, LinearEasing)),
|
||||
exit = fadeOut(tween(200, 50, LinearEasing)) + scaleOut(),
|
||||
) {
|
||||
Surface(tonalElevation = 5.dp) {
|
||||
Column(modifier = Modifier.height(menuHeight)) {
|
||||
MenuRow(
|
||||
text = stringResource(R.string.add_images_btn),
|
||||
icon = Icons.Filled.PhotoLibrary,
|
||||
horizontalExpansion = expandHorizontally,
|
||||
onClick = {
|
||||
expanded = false
|
||||
onImageClick()
|
||||
}
|
||||
)
|
||||
MenuRow(
|
||||
text = stringResource(R.string.add_folder_btn),
|
||||
icon = Icons.Filled.Folder,
|
||||
horizontalExpansion = expandHorizontally,
|
||||
onClick = {
|
||||
expanded = false
|
||||
onFolderClick()
|
||||
}
|
||||
)
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.width(expandFabHorizontally)
|
||||
.clickable {
|
||||
onImageClick()
|
||||
isFabExpanded = false
|
||||
},
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.PhotoLibrary,
|
||||
contentDescription = stringResource(R.string.add_images_btn),
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(start = 16.dp, top = 12.dp, bottom = 12.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
Text(
|
||||
text = stringResource(R.string.add_images_btn),
|
||||
modifier = Modifier.padding(end = 16.dp, top = 12.dp, bottom = 12.dp),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
}
|
||||
}
|
||||
Surface(
|
||||
tonalElevation = 3.dp,
|
||||
AnimatedVisibility(
|
||||
visible = isFabExpanded,
|
||||
label = stringResource(R.string.add_folder_btn),
|
||||
enter = fadeIn(tween(300, 150, LinearEasing)),
|
||||
exit = fadeOut(tween(200, 50, LinearEasing)) + scaleOut(),
|
||||
) {
|
||||
LargeFloatingActionButton(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
onClick = { expanded = !expanded },
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.width(expandHorizontally)
|
||||
.height(shrinkVertically)
|
||||
.animateContentSize(),
|
||||
.width(expandFabHorizontally)
|
||||
.clickable {
|
||||
onFolderClick()
|
||||
isFabExpanded = false
|
||||
},
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
if (!expanded) Icons.Filled.Add else Icons.Filled.Remove,
|
||||
contentDescription = stringResource(R.string.add_wallpaper),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
)
|
||||
}
|
||||
Icon(
|
||||
imageVector = Icons.Filled.Folder,
|
||||
contentDescription = stringResource(R.string.add_folder_btn),
|
||||
modifier = Modifier.padding(start = 16.dp, top = 12.dp, bottom = 12.dp),
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
Text(
|
||||
text = stringResource(R.string.add_folder_btn),
|
||||
modifier = Modifier.padding(end = 16.dp, top = 12.dp, bottom = 12.dp),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ElevatedCard(
|
||||
colors = CardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
contentColor = Color.Transparent,
|
||||
disabledContentColor = Color.Transparent,
|
||||
disabledContainerColor = Color.Transparent,
|
||||
),
|
||||
shape = RoundedCornerShape(28.dp),
|
||||
|
||||
LargeFloatingActionButton(
|
||||
elevation = FloatingActionButtonDefaults.elevation(4.dp),
|
||||
shape = RoundedCornerShape(28),
|
||||
containerColor = fabColor,
|
||||
onClick = { isFabExpanded = !isFabExpanded },
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.width(if (expanded) expandHorizontalSize.first else expandHorizontalSize.second)
|
||||
.pointerInput(Unit) {
|
||||
detectTapGestures(onTap = { expanded = false })
|
||||
}
|
||||
.width(expandFabHorizontally)
|
||||
.height(shrinkFabVertically)
|
||||
) {
|
||||
if (expanded) {
|
||||
Surface(tonalElevation = 5.dp) {
|
||||
Column(modifier = Modifier.height(if (expanded) menuHeightSize.first else menuHeightSize.second)) {
|
||||
MenuRow(
|
||||
text = stringResource(R.string.add_images_btn),
|
||||
icon = Icons.Filled.PhotoLibrary,
|
||||
horizontalExpansion = if (expanded) expandHorizontalSize.first else expandHorizontalSize.second,
|
||||
onClick = {
|
||||
expanded = false
|
||||
onImageClick()
|
||||
}
|
||||
)
|
||||
MenuRow(
|
||||
text = stringResource(R.string.add_folder_btn),
|
||||
icon = Icons.Filled.Folder,
|
||||
horizontalExpansion = if (expanded) expandHorizontalSize.first else expandHorizontalSize.second,
|
||||
onClick = {
|
||||
expanded = false
|
||||
onFolderClick()
|
||||
}
|
||||
)
|
||||
AnimatedContent(
|
||||
isFabExpanded,
|
||||
transitionSpec = {
|
||||
when (targetState) {
|
||||
true -> {
|
||||
(
|
||||
scaleIn(
|
||||
tween(100, 300, FastOutSlowInEasing)
|
||||
) + fadeIn(
|
||||
tween(250, 300, LinearEasing)
|
||||
)
|
||||
) .togetherWith(
|
||||
fadeOut(
|
||||
tween(10, 0, LinearEasing)
|
||||
)
|
||||
)
|
||||
}
|
||||
false -> {
|
||||
fadeIn(
|
||||
tween(250, 200, FastOutSlowInEasing)
|
||||
).togetherWith(
|
||||
fadeOut(
|
||||
tween(10, 0, LinearEasing),
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Surface(
|
||||
tonalElevation = 3.dp,
|
||||
) {
|
||||
LargeFloatingActionButton(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
onClick = { expanded = !expanded },
|
||||
modifier = Modifier
|
||||
.width(if (expanded) expandHorizontalSize.first else expandHorizontalSize.second)
|
||||
.height(if (expanded) shrinkVerticalSize.first else shrinkVerticalSize.second)
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
if (!expanded) Icons.Filled.Add else Icons.Filled.Remove,
|
||||
contentDescription = stringResource(R.string.add_wallpaper),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
label = "FabContent"
|
||||
) { isExpanded ->
|
||||
Icon(
|
||||
imageVector = if (isExpanded) Icons.Filled.Remove else Icons.Filled.Add,
|
||||
contentDescription = stringResource(R.string.add_wallpaper),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+19
-4
@@ -22,10 +22,14 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.testTagsAsResourceId
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -37,6 +41,7 @@ import kotlinx.coroutines.android.awaitFrame
|
||||
/**
|
||||
* Dialog for adding a new album.
|
||||
*/
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun AddAlbumDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
@@ -44,11 +49,16 @@ fun AddAlbumDialog(
|
||||
) {
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
var albumName by rememberSaveable { mutableStateOf("") }
|
||||
Dialog(onDismissRequest = onDismissRequest) {
|
||||
Dialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(24.dp),
|
||||
.padding(24.dp)
|
||||
.semantics {
|
||||
testTagsAsResourceId = true
|
||||
},
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
@@ -99,7 +109,10 @@ fun AddAlbumDialog(
|
||||
onClick = { onDismissRequest() },
|
||||
modifier = Modifier.padding(8.dp),
|
||||
) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
Text(
|
||||
text = stringResource(R.string.cancel),
|
||||
modifier = Modifier.testTag("paperize:cancel_album_button")
|
||||
)
|
||||
}
|
||||
TextButton(
|
||||
modifier = Modifier.padding(8.dp),
|
||||
@@ -110,7 +123,9 @@ fun AddAlbumDialog(
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(stringResource(R.string.save))
|
||||
Text(
|
||||
text = stringResource(R.string.save),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -102,7 +102,6 @@ fun AddAlbumSmallTopBar(
|
||||
), label = stringResource(R.string.circle_3_animation)
|
||||
)
|
||||
|
||||
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||
title = {
|
||||
@@ -163,7 +162,6 @@ fun AddAlbumSmallTopBar(
|
||||
Icon(
|
||||
imageVector = Icons.Default.RadioButtonUnchecked,
|
||||
contentDescription = stringResource(R.string.select_all_images_for_deletion),
|
||||
tint = Color.White.copy(alpha = 0.7f),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
}
|
||||
@@ -174,7 +172,7 @@ fun AddAlbumSmallTopBar(
|
||||
},
|
||||
actions = {
|
||||
if(!selectionMode) {
|
||||
if (!isEmpty) {
|
||||
if (!isEmpty && editableTitle.isNotEmpty()) {
|
||||
Box {
|
||||
val primaryColor = MaterialTheme.colorScheme.inversePrimary
|
||||
val secondaryColor = MaterialTheme.colorScheme.secondary
|
||||
|
||||
+139
-38
@@ -44,6 +44,13 @@ class AlbumsViewModel @Inject constructor (
|
||||
is AlbumsEvent.DeleteAlbumWithWallpapers -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.cascadeDeleteAlbum(event.albumWithWallpaperAndFolder.album)
|
||||
_state.update {
|
||||
it.copy(
|
||||
albumsWithWallpapers = it.albumsWithWallpapers.filterNot { albumWithWallpaper ->
|
||||
albumWithWallpaper.album == event.albumWithWallpaperAndFolder.album
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
is AlbumsEvent.ChangeAlbumName -> {
|
||||
@@ -52,13 +59,22 @@ class AlbumsViewModel @Inject constructor (
|
||||
repository.updateAlbum(
|
||||
event.albumWithWallpaperAndFolder.album.copy(displayedAlbumName = event.title)
|
||||
)
|
||||
_state.update {
|
||||
it.copy(
|
||||
albumsWithWallpapers = it.albumsWithWallpapers.map { albumWithWallpaper ->
|
||||
if (albumWithWallpaper.album == event.albumWithWallpaperAndFolder.album) {
|
||||
albumWithWallpaper.copy(
|
||||
album = albumWithWallpaper.album.copy(displayedAlbumName = event.title)
|
||||
)
|
||||
} else {
|
||||
albumWithWallpaper
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
is AlbumsEvent.RefreshAlbums -> {
|
||||
updateAlbums()
|
||||
refreshAlbums()
|
||||
}
|
||||
is AlbumsEvent.InitializeAlbum -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.updateAlbum(
|
||||
@@ -66,12 +82,31 @@ class AlbumsViewModel @Inject constructor (
|
||||
initialized = true
|
||||
)
|
||||
)
|
||||
_state.update {
|
||||
it.copy(
|
||||
albumsWithWallpapers = it.albumsWithWallpapers.map { albumWithWallpaper ->
|
||||
if (albumWithWallpaper.album == event.albumWithWallpaperAndFolder.album) {
|
||||
albumWithWallpaper.copy(
|
||||
album = albumWithWallpaper.album.copy(
|
||||
initialized = true
|
||||
)
|
||||
)
|
||||
} else {
|
||||
albumWithWallpaper
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
is AlbumsEvent.RefreshAlbums -> {
|
||||
updateAlbums()
|
||||
refreshAlbums()
|
||||
}
|
||||
is AlbumsEvent.Reset -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
_state.update { AlbumsState() }
|
||||
repository.deleteAllData()
|
||||
_state.update { AlbumsState() }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,8 +121,17 @@ class AlbumsViewModel @Inject constructor (
|
||||
albumWithWallpapers.forEach { albumWithWallpaper ->
|
||||
// Delete wallpaper if the URI is invalid
|
||||
val invalidWallpapers = albumWithWallpaper.wallpapers.filterNot { wallpaper ->
|
||||
val file = DocumentFileCompat.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
|
||||
file?.exists() == true
|
||||
try {
|
||||
val file = DocumentFileCompat.fromSingleUri(
|
||||
context,
|
||||
wallpaper.wallpaperUri.toUri()
|
||||
)
|
||||
file?.exists() == true
|
||||
} catch (e: Exception) {
|
||||
val file =
|
||||
DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
|
||||
file?.exists() == true
|
||||
}
|
||||
}
|
||||
if (invalidWallpapers.isNotEmpty()) {
|
||||
repository.deleteWallpaperList(invalidWallpapers)
|
||||
@@ -96,42 +140,99 @@ class AlbumsViewModel @Inject constructor (
|
||||
// Update folder cover uri and wallpapers uri
|
||||
albumWithWallpaper.folders.forEach { folder ->
|
||||
try {
|
||||
DocumentFileCompat.fromTreeUri(context, folder.folderUri.toUri())?.let { folderDirectory ->
|
||||
if (!folderDirectory.isDirectory()) {
|
||||
repository.deleteFolder(folder)
|
||||
} else {
|
||||
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
|
||||
val folderCoverFile = folder.coverUri?.let { DocumentFile.fromSingleUri(context, it.toUri()) }
|
||||
val folderCover = folderCoverFile?.takeIf { it.exists() }?.uri?.toString() ?: wallpapers.randomOrNull()
|
||||
repository.updateFolder(folder.copy(coverUri = folderCover, wallpapers = wallpapers))
|
||||
DocumentFileCompat.fromTreeUri(context, folder.folderUri.toUri())
|
||||
?.let { folderDirectory ->
|
||||
if (!folderDirectory.isDirectory()) {
|
||||
repository.deleteFolder(folder)
|
||||
} else {
|
||||
val wallpapers =
|
||||
getWallpaperFromFolder(folder.folderUri, context)
|
||||
val folderCoverFile = folder.coverUri?.let {
|
||||
DocumentFileCompat.fromSingleUri(
|
||||
context,
|
||||
it.toUri()
|
||||
)
|
||||
}
|
||||
val folderCover =
|
||||
folderCoverFile?.takeIf { it.exists() }?.uri?.toString()
|
||||
?: wallpapers.randomOrNull()
|
||||
repository.updateFolder(
|
||||
folder.copy(
|
||||
coverUri = folderCover,
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
DocumentFile.fromTreeUri(context, folder.folderUri.toUri())?.let { folderDirectory ->
|
||||
if (!folderDirectory.isDirectory) {
|
||||
repository.deleteFolder(folder)
|
||||
} else {
|
||||
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
|
||||
val folderCoverFile = folder.coverUri?.let { DocumentFile.fromSingleUri(context, it.toUri()) }
|
||||
val folderCover = folderCoverFile?.takeIf { it.exists() }?.uri?.toString() ?: wallpapers.randomOrNull()
|
||||
repository.updateFolder(folder.copy(coverUri = folderCover, wallpapers = wallpapers))
|
||||
DocumentFile.fromTreeUri(context, folder.folderUri.toUri())
|
||||
?.let { folderDirectory ->
|
||||
if (!folderDirectory.isDirectory) {
|
||||
repository.deleteFolder(folder)
|
||||
} else {
|
||||
val wallpapers =
|
||||
getWallpaperFromFolder(folder.folderUri, context)
|
||||
try {
|
||||
val folderCoverFile = folder.coverUri?.let {
|
||||
DocumentFileCompat.fromSingleUri(
|
||||
context,
|
||||
it.toUri()
|
||||
)
|
||||
}
|
||||
val folderCover =
|
||||
folderCoverFile?.takeIf { it.exists() }?.uri?.toString()
|
||||
?: wallpapers.randomOrNull()
|
||||
repository.updateFolder(
|
||||
folder.copy(
|
||||
coverUri = folderCover,
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
val folderCoverFile = folder.coverUri?.let {
|
||||
DocumentFile.fromSingleUri(
|
||||
context,
|
||||
it.toUri()
|
||||
)
|
||||
}
|
||||
val folderCover =
|
||||
folderCoverFile?.takeIf { it.exists() }?.uri?.toString()
|
||||
?: wallpapers.randomOrNull()
|
||||
repository.updateFolder(
|
||||
folder.copy(
|
||||
coverUri = folderCover,
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
albumWithWallpapers = repository.getAlbumsWithWallpaperAndFolder().first()
|
||||
albumWithWallpapers.forEach { albumWithWallpaper ->
|
||||
// Delete empty albums
|
||||
if (albumWithWallpaper.wallpapers.isEmpty() && albumWithWallpaper.folders.all { it.wallpapers.isEmpty() }) {
|
||||
repository.deleteAlbum(albumWithWallpaper.album)
|
||||
}
|
||||
else {
|
||||
// Update album cover uri if null or invalid
|
||||
val albumCoverFile = albumWithWallpaper.album.coverUri?.toUri()?.let { DocumentFile.fromSingleUri(context, it) }
|
||||
if (albumCoverFile == null || !albumCoverFile.exists()) {
|
||||
val newCoverUri = findFirstValidUri(context, albumWithWallpaper.wallpapers, albumWithWallpaper.folders)
|
||||
repository.updateAlbum(albumWithWallpaper.album.copy(coverUri = newCoverUri))
|
||||
albumWithWallpapers = repository.getAlbumsWithWallpaperAndFolder().first()
|
||||
albumWithWallpapers.forEach { album ->
|
||||
// Delete empty albums
|
||||
if (album.wallpapers.isEmpty() && album.folders.all { it.wallpapers.isEmpty() }) {
|
||||
repository.deleteAlbum(album.album)
|
||||
} else {
|
||||
// Update album cover uri if null or invalid
|
||||
try {
|
||||
val albumCoverFile = album.album.coverUri?.toUri()
|
||||
?.let { DocumentFileCompat.fromSingleUri(context, it) }
|
||||
if (albumCoverFile == null || !albumCoverFile.exists()) {
|
||||
val newCoverUri =
|
||||
findFirstValidUri(context, album.wallpapers, album.folders)
|
||||
repository.updateAlbum(album.album.copy(coverUri = newCoverUri))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
val albumCoverFile = album.album.coverUri?.toUri()
|
||||
?.let { DocumentFile.fromSingleUri(context, it) }
|
||||
if (albumCoverFile == null || !albumCoverFile.exists()) {
|
||||
val newCoverUri =
|
||||
findFirstValidUri(context, album.wallpapers, album.folders)
|
||||
repository.updateAlbum(album.album.copy(coverUri = newCoverUri))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-26
@@ -1,6 +1,5 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -11,10 +10,12 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
@@ -23,7 +24,7 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.core.isValidUri
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
@@ -36,26 +37,13 @@ fun AlbumItem(
|
||||
album: Album,
|
||||
onAlbumViewClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
animate: Boolean = true
|
||||
) {
|
||||
fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.toUri()
|
||||
return try {
|
||||
uri?.let {
|
||||
val inputStream = context.contentResolver.openInputStream(it)
|
||||
inputStream?.close()
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
|
||||
val showCoverUri = album.coverUri != null && isValidUri(LocalContext.current, album.coverUri)
|
||||
val context = LocalContext.current
|
||||
val showCoverUri by remember { mutableStateOf(album.coverUri != null && isValidUri(context, album.coverUri)) }
|
||||
|
||||
Card(
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
.clip(RoundedCornerShape(16.dp)),
|
||||
modifier = modifier.fillMaxSize(),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
onClick = onAlbumViewClick
|
||||
) {
|
||||
@@ -72,13 +60,6 @@ fun AlbumItem(
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(300, 300),
|
||||
),
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
|
||||
+33
-48
@@ -1,6 +1,5 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
@@ -10,10 +9,10 @@ import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.wrapContentHeight
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
@@ -21,20 +20,20 @@ import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.RadioButtonUnchecked
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -43,6 +42,7 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.isValidUri
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
@@ -60,9 +60,8 @@ fun FolderItem(
|
||||
onItemSelection: () -> Unit,
|
||||
onFolderViewClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
animate: Boolean = true
|
||||
) {
|
||||
val configuration = LocalConfiguration.current
|
||||
val context = LocalContext.current
|
||||
val haptics = LocalHapticFeedback.current
|
||||
val transition = updateTransition(itemSelected, label = "")
|
||||
|
||||
@@ -74,18 +73,7 @@ fun FolderItem(
|
||||
if (selected) 24.dp else 16.dp
|
||||
}
|
||||
|
||||
fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.toUri()
|
||||
return try {
|
||||
uri?.let {
|
||||
val inputStream = context.contentResolver.openInputStream(it)
|
||||
inputStream?.close()
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
|
||||
val showCoverUri = folder.coverUri != null && isValidUri(LocalContext.current, folder.coverUri)
|
||||
val showCoverUri by remember { mutableStateOf(folder.coverUri != null && isValidUri(context, folder.coverUri)) }
|
||||
|
||||
Card(
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
|
||||
@@ -109,13 +97,14 @@ fun FolderItem(
|
||||
}
|
||||
}
|
||||
),
|
||||
shape = RoundedCornerShape(roundedCornerShapeTransition),
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Top,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Box {
|
||||
Box (
|
||||
modifier = Modifier.fillMaxHeight(0.8f)
|
||||
) {
|
||||
if (showCoverUri) {
|
||||
GlideImage(
|
||||
imageModel = { folder.coverUri?.toUri() },
|
||||
@@ -124,16 +113,9 @@ fun FolderItem(
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(300, 300),
|
||||
),
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(0.8f)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.fillMaxSize()
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
)
|
||||
}
|
||||
if (selectionMode) {
|
||||
@@ -142,7 +124,7 @@ fun FolderItem(
|
||||
imageVector = Icons.Default.CheckCircle,
|
||||
contentDescription = stringResource(R.string.image_is_selected),
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.padding(9.dp)
|
||||
.border(2.dp, iconSelectionColor, CircleShape)
|
||||
.clip(CircleShape)
|
||||
.background(iconSelectionColor)
|
||||
@@ -157,27 +139,30 @@ fun FolderItem(
|
||||
}
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.padding(6.dp))
|
||||
folder.folderName?.let { name ->
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 16.dp)
|
||||
.align(Alignment.Start)
|
||||
.fillMaxHeight()
|
||||
.wrapContentHeight(Alignment.CenterVertically),
|
||||
) {
|
||||
folder.folderName?.let { name ->
|
||||
Text(
|
||||
text = name,
|
||||
modifier = Modifier,
|
||||
fontSize = 16.sp,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = name,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 24.dp)
|
||||
.align(Alignment.Start),
|
||||
fontSize = 16.sp,
|
||||
text = folder.wallpapers.size.toString().plus(" " + stringResource(R.string.wallpapers)),
|
||||
fontSize = 12.sp,
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = folder.wallpapers.size.toString().plus(" " + stringResource(R.string.wallpapers)),
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 24.dp)
|
||||
.align(Alignment.Start),
|
||||
fontSize = 12.sp,
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
Spacer(modifier = Modifier.padding(8.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
+30
-83
@@ -8,40 +8,32 @@ import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.RadioButtonUnchecked
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.blur
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.BlendMode
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.times
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.core.getImageDimensions
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.DecodeFormat
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
|
||||
@@ -54,18 +46,11 @@ fun WallpaperItem(
|
||||
wallpaperUri: String,
|
||||
itemSelected: Boolean,
|
||||
selectionMode: Boolean,
|
||||
modifier: Modifier = Modifier,
|
||||
allowHapticFeedback: Boolean = true,
|
||||
onActivateSelectionMode: (Boolean) -> Unit,
|
||||
onItemSelection: () -> Unit,
|
||||
onWallpaperViewClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
aspectRatio: Float? = null,
|
||||
clickable: Boolean = true,
|
||||
animate: Boolean = true,
|
||||
darken: Boolean = false,
|
||||
darkenPercentage: Int? = null,
|
||||
blur: Boolean = false,
|
||||
blurPercentage: Int? = null,
|
||||
scaling: ScalingConstants? = null
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val haptics = LocalHapticFeedback.current
|
||||
@@ -88,76 +73,38 @@ fun WallpaperItem(
|
||||
true
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
val showUri by remember { mutableStateOf(isValidUri(context, wallpaperUri)) }
|
||||
|
||||
val showUri = isValidUri(LocalContext.current, wallpaperUri)
|
||||
val boxModifier = if (clickable) {
|
||||
modifier
|
||||
.padding(paddingTransition)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (!selectionMode) {
|
||||
onWallpaperViewClick()
|
||||
} else {
|
||||
onItemSelection()
|
||||
}
|
||||
},
|
||||
onLongClick = {
|
||||
if (!selectionMode) {
|
||||
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onActivateSelectionMode(true)
|
||||
onItemSelection()
|
||||
}
|
||||
Box(
|
||||
modifier = modifier
|
||||
.padding(paddingTransition)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (!selectionMode) {
|
||||
onWallpaperViewClick()
|
||||
} else {
|
||||
onItemSelection()
|
||||
}
|
||||
)
|
||||
} else {
|
||||
modifier
|
||||
.padding(paddingTransition)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
}
|
||||
Box(modifier = boxModifier) {
|
||||
},
|
||||
onLongClick = {
|
||||
if (!selectionMode) {
|
||||
if (allowHapticFeedback) haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onActivateSelectionMode(true)
|
||||
onItemSelection()
|
||||
}
|
||||
}
|
||||
)
|
||||
) {
|
||||
if (showUri) {
|
||||
val dimension = wallpaperUri.toUri().getImageDimensions(context)
|
||||
val imageAspectRatio = aspectRatio ?: ((dimension?.width?.toFloat() ?: 9f) / (dimension?.height?.toFloat() ?: 19.5f))
|
||||
GlideImage(
|
||||
imageModel = { wallpaperUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = if (scaling != null) {
|
||||
when (scaling) {
|
||||
ScalingConstants.FILL -> ContentScale.FillHeight
|
||||
ScalingConstants.FIT -> ContentScale.FillWidth
|
||||
ScalingConstants.STRETCH -> ContentScale.FillBounds
|
||||
}
|
||||
} else { ContentScale.Crop },
|
||||
requestSize = IntSize(300, 300),
|
||||
requestSize = IntSize(200, 200),
|
||||
alignment = Alignment.Center,
|
||||
colorFilter = if (darken && darkenPercentage != null && darkenPercentage < 100) {
|
||||
ColorFilter.tint(
|
||||
Color.Black.copy(alpha = (100 - darkenPercentage).toFloat().div(100f)),
|
||||
BlendMode.Darken
|
||||
)
|
||||
} else { null }
|
||||
),
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
}
|
||||
}
|
||||
},
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.format(DecodeFormat.PREFER_RGB_565)
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(imageAspectRatio)
|
||||
.background(if (scaling != null) Color.Black else Color.Transparent)
|
||||
.blur(
|
||||
if (blur && blurPercentage != null && blurPercentage > 0 ) {
|
||||
blurPercentage.toFloat().div(100f) * 1.5.dp
|
||||
} else { 0.dp })
|
||||
.fillMaxSize()
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
)
|
||||
}
|
||||
@@ -168,10 +115,10 @@ fun WallpaperItem(
|
||||
imageVector = Icons.Default.CheckCircle,
|
||||
contentDescription = stringResource(R.string.image_is_selected),
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(2.dp, bgColor, CircleShape)
|
||||
.padding(9.dp)
|
||||
.clip(CircleShape)
|
||||
.background(bgColor)
|
||||
.border(2.dp, bgColor, CircleShape)
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
|
||||
+84
-94
@@ -5,19 +5,18 @@ import android.net.Uri
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.scaleIn
|
||||
import androidx.compose.animation.scaleOut
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.items
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -34,24 +33,24 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.co
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.FolderItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen.components.AlbumViewTopBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
|
||||
import my.nanihadesuka.compose.LazyVerticalGridScrollbar
|
||||
import my.nanihadesuka.compose.ScrollbarSettings
|
||||
|
||||
@Composable
|
||||
fun AlbumViewScreen(
|
||||
albumViewScreenViewModel: AlbumViewScreenViewModel = hiltViewModel(),
|
||||
settingsViewModel: SettingsViewModel = hiltViewModel(),
|
||||
album: AlbumWithWallpaperAndFolder,
|
||||
animate: Boolean,
|
||||
onBackClick: () -> Unit,
|
||||
onShowWallpaperView: (String) -> Unit,
|
||||
onShowFolderView: (String?, List<String>) -> Unit,
|
||||
onDeleteAlbum: () -> Unit,
|
||||
onTitleChange: (String, AlbumWithWallpaperAndFolder) -> Unit,
|
||||
onAlbumNameChange: (String, AlbumWithWallpaperAndFolder) -> Unit,
|
||||
onSelectionDeleted: () -> Unit,
|
||||
) {
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.SetSize(album.wallpapers.size + album.folders.size)) // For selectedAll state
|
||||
val lazyListState = rememberLazyStaggeredGridState()
|
||||
val lazyListState = rememberLazyGridState()
|
||||
val albumState = albumViewScreenViewModel.state.collectAsStateWithLifecycle()
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
var selectionMode by rememberSaveable { mutableStateOf(false) }
|
||||
val context = LocalContext.current
|
||||
|
||||
@@ -105,7 +104,7 @@ fun AlbumViewScreen(
|
||||
onBackClick()
|
||||
},
|
||||
onDeleteAlbum = onDeleteAlbum,
|
||||
onTitleChange = { onTitleChange(it, album) },
|
||||
onTitleChange = { onAlbumNameChange(it, album) },
|
||||
onSelectAllClick = {
|
||||
if (!albumState.value.allSelected) albumViewScreenViewModel.onEvent(AlbumViewEvent.SelectAll(album))
|
||||
else albumViewScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
@@ -119,159 +118,150 @@ fun AlbumViewScreen(
|
||||
)
|
||||
},
|
||||
floatingActionButton = {
|
||||
if (settingsState.value.animate) {
|
||||
AnimatedVisibility(
|
||||
visible = !lazyListState.isScrollInProgress || lazyListState.firstVisibleItemScrollOffset < 0,
|
||||
enter = scaleIn(tween(400, 50, FastOutSlowInEasing)),
|
||||
exit = scaleOut(tween(400, 50, FastOutSlowInEasing)),
|
||||
) {
|
||||
AddAlbumAnimatedFab(
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
},
|
||||
animate = true
|
||||
)
|
||||
AddAlbumAnimatedFab(
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
}
|
||||
}
|
||||
else {
|
||||
AddAlbumAnimatedFab(
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
},
|
||||
animate = false
|
||||
)
|
||||
}
|
||||
)
|
||||
},
|
||||
content = { it ->
|
||||
LazyVerticalStaggeredGrid(
|
||||
LazyVerticalGridScrollbar(
|
||||
state = lazyListState,
|
||||
settings = ScrollbarSettings.Default.copy(
|
||||
thumbUnselectedColor = MaterialTheme.colorScheme.primary,
|
||||
thumbSelectedColor = MaterialTheme.colorScheme.primary,
|
||||
thumbShape = RoundedCornerShape(16.dp),
|
||||
scrollbarPadding = 1.dp,
|
||||
),
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(it),
|
||||
columns = StaggeredGridCells.Fixed(2),
|
||||
contentPadding = PaddingValues(4.dp, 4.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
content = {
|
||||
items (items = album.folders, key = { folder -> folder.folderUri }
|
||||
) { folder ->
|
||||
if (settingsState.value.animate) {
|
||||
) {
|
||||
LazyVerticalGrid(
|
||||
state = lazyListState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
columns = GridCells.Adaptive(150.dp),
|
||||
contentPadding = PaddingValues(4.dp, 4.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
) {
|
||||
items(count = album.folders.size, key = { index -> album.folders[index].folderUri }) { index ->
|
||||
if (animate) {
|
||||
FolderItem(
|
||||
folder = folder,
|
||||
itemSelected = albumState.value.selectedFolders.contains(folder.folderUri),
|
||||
folder = album.folders[index],
|
||||
itemSelected = albumState.value.selectedFolders.contains(album.folders[index].folderUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
albumViewScreenViewModel.onEvent(
|
||||
if (!albumState.value.selectedFolders.contains(folder.folderUri))
|
||||
AlbumViewEvent.SelectFolder(folder.folderUri)
|
||||
if (!albumState.value.selectedFolders.contains(album.folders[index].folderUri))
|
||||
AlbumViewEvent.SelectFolder(album.folders[index].folderUri)
|
||||
else {
|
||||
AlbumViewEvent.RemoveFolderFromSelection(folder.folderUri)
|
||||
AlbumViewEvent.RemoveFolderFromSelection(album.folders[index].folderUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onFolderViewClick = {
|
||||
if (folder.wallpapers.isNotEmpty()) onShowFolderView(folder.folderName, folder.wallpapers)
|
||||
if (album.folders[index].wallpapers.isNotEmpty()) onShowFolderView(album.folders[index].folderName, album.folders[index].wallpapers)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
),
|
||||
animate = true
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.size(150.dp, 350.dp)
|
||||
.animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
else {
|
||||
FolderItem(
|
||||
folder = folder,
|
||||
itemSelected = albumState.value.selectedFolders.contains(folder.folderUri),
|
||||
folder = album.folders[index],
|
||||
itemSelected = albumState.value.selectedFolders.contains(album.folders[index].folderUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
albumViewScreenViewModel.onEvent(
|
||||
if (!albumState.value.selectedFolders.contains(folder.folderUri))
|
||||
AlbumViewEvent.SelectFolder(folder.folderUri)
|
||||
if (!albumState.value.selectedFolders.contains(album.folders[index].folderUri))
|
||||
AlbumViewEvent.SelectFolder(album.folders[index].folderUri)
|
||||
else {
|
||||
AlbumViewEvent.RemoveFolderFromSelection(folder.folderUri)
|
||||
AlbumViewEvent.RemoveFolderFromSelection(album.folders[index].folderUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onFolderViewClick = {
|
||||
if (folder.wallpapers.isNotEmpty()) onShowFolderView(folder.folderName, folder.wallpapers)
|
||||
if (album.folders[index].wallpapers.isNotEmpty()) onShowFolderView(album.folders[index].folderName, album.folders[index].wallpapers)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp),
|
||||
animate = false
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.size(150.dp, 350.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
items (items = album.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri }
|
||||
) { wallpaper ->
|
||||
if (settingsState.value.animate) {
|
||||
items(count = album.wallpapers.size, key = { index -> album.wallpapers[index].wallpaperUri }) { index ->
|
||||
if (animate) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper.wallpaperUri,
|
||||
itemSelected = albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri),
|
||||
wallpaperUri = album.wallpapers[index].wallpaperUri,
|
||||
itemSelected = albumState.value.selectedWallpapers.contains(album.wallpapers[index].wallpaperUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
albumViewScreenViewModel.onEvent(
|
||||
if (!albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri))
|
||||
AlbumViewEvent.SelectWallpaper(wallpaper.wallpaperUri)
|
||||
if (!albumState.value.selectedWallpapers.contains(album.wallpapers[index].wallpaperUri))
|
||||
AlbumViewEvent.SelectWallpaper(album.wallpapers[index].wallpaperUri)
|
||||
else {
|
||||
AlbumViewEvent.RemoveWallpaperFromSelection(wallpaper.wallpaperUri)
|
||||
AlbumViewEvent.RemoveWallpaperFromSelection(album.wallpapers[index].wallpaperUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper.wallpaperUri)
|
||||
onShowWallpaperView(album.wallpapers[index].wallpaperUri)
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.size(150.dp, 350.dp)
|
||||
.animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
)
|
||||
),
|
||||
animate = true
|
||||
)
|
||||
)
|
||||
}
|
||||
else {
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper.wallpaperUri,
|
||||
itemSelected = albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri),
|
||||
wallpaperUri = album.wallpapers[index].wallpaperUri,
|
||||
itemSelected = albumState.value.selectedWallpapers.contains(album.wallpapers[index].wallpaperUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
albumViewScreenViewModel.onEvent(
|
||||
if (!albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri))
|
||||
AlbumViewEvent.SelectWallpaper(wallpaper.wallpaperUri)
|
||||
if (!albumState.value.selectedWallpapers.contains(album.wallpapers[index].wallpaperUri))
|
||||
AlbumViewEvent.SelectWallpaper(album.wallpapers[index].wallpaperUri)
|
||||
else {
|
||||
AlbumViewEvent.RemoveWallpaperFromSelection(wallpaper.wallpaperUri)
|
||||
AlbumViewEvent.RemoveWallpaperFromSelection(album.wallpapers[index].wallpaperUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper.wallpaperUri)
|
||||
onShowWallpaperView(album.wallpapers[index].wallpaperUri)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp),
|
||||
animate = false
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.size(150.dp, 350.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
-2
@@ -32,7 +32,6 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.DpOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -103,7 +102,6 @@ fun AlbumViewTopBar(
|
||||
Icon(
|
||||
imageVector = Icons.Default.RadioButtonUnchecked,
|
||||
contentDescription = stringResource(R.string.select_all_images_for_deletion),
|
||||
tint = Color.White.copy(alpha = 0.7f),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.folder_view_screen
|
||||
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.lifecycle.ViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* ViewModel for the folder view screen to hold the folder name and the list of wallpapers
|
||||
*/
|
||||
class FolderViewModel @Inject constructor (): ViewModel() {
|
||||
var folderName = mutableStateOf<String?>(null)
|
||||
var wallpapers = mutableStateOf<List<String>?>(null)
|
||||
}
|
||||
+46
-28
@@ -7,16 +7,20 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.items
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.folder_view_screen.components.FolderViewTopBar
|
||||
import my.nanihadesuka.compose.LazyVerticalGridScrollbar
|
||||
import my.nanihadesuka.compose.ScrollbarSettings
|
||||
|
||||
@Composable
|
||||
fun FolderViewScreen(
|
||||
@@ -26,7 +30,7 @@ fun FolderViewScreen(
|
||||
onShowWallpaperView: (String) -> Unit,
|
||||
animate: Boolean
|
||||
) {
|
||||
val lazyListState = rememberLazyStaggeredGridState()
|
||||
val lazyListState = rememberLazyGridState()
|
||||
BackHandler { onBackClick() }
|
||||
|
||||
Scaffold(
|
||||
@@ -37,54 +41,68 @@ fun FolderViewScreen(
|
||||
)
|
||||
},
|
||||
content = {
|
||||
LazyVerticalStaggeredGrid(
|
||||
LazyVerticalGridScrollbar(
|
||||
state = lazyListState,
|
||||
settings = ScrollbarSettings.Default.copy(
|
||||
thumbUnselectedColor = MaterialTheme.colorScheme.primary,
|
||||
thumbSelectedColor = MaterialTheme.colorScheme.primary,
|
||||
thumbShape = RoundedCornerShape(16.dp),
|
||||
scrollbarPadding = 1.dp,
|
||||
),
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(it)
|
||||
.fillMaxSize(),
|
||||
columns = StaggeredGridCells.Fixed(2),
|
||||
contentPadding = PaddingValues(4.dp, 4.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
content = {
|
||||
items (items = wallpapers, key = { wallpaper -> wallpaper }
|
||||
) { wallpaper ->
|
||||
) {
|
||||
LazyVerticalGrid(
|
||||
state = lazyListState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
columns = GridCells.Adaptive(150.dp),
|
||||
contentPadding = PaddingValues(4.dp, 4.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
) {
|
||||
items(count = wallpapers.size, key = { index -> wallpapers[index] }) { index ->
|
||||
if (animate) {
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper,
|
||||
wallpaperUri = wallpapers[index],
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
allowHapticFeedback = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper)
|
||||
onShowWallpaperView(wallpapers[index])
|
||||
},
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
),
|
||||
animate = true
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.size(150.dp, 350.dp)
|
||||
.animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
else {
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper,
|
||||
wallpaperUri = wallpapers[index],
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
allowHapticFeedback = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper)
|
||||
onShowWallpaperView(wallpapers[index])
|
||||
},
|
||||
modifier = Modifier.padding(4.dp),
|
||||
animate = false
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.size(150.dp, 350.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
+81
-37
@@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Tab
|
||||
@@ -12,6 +13,7 @@ import androidx.compose.material3.TabRow
|
||||
import androidx.compose.material3.TabRowDefaults
|
||||
import androidx.compose.material3.TabRowDefaults.tabIndicatorOffset
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TimePickerState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -19,8 +21,11 @@ import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.testTagsAsResourceId
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
@@ -31,42 +36,61 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.compone
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.LibraryScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreen
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun HomeScreen(
|
||||
albums: List<AlbumWithWallpaperAndFolder>,
|
||||
animate : Boolean,
|
||||
darken: Boolean,
|
||||
darkenPercentage: Int,
|
||||
homeDarkenPercentage: Int,
|
||||
lockDarkenPercentage: Int,
|
||||
enableChanger: Boolean,
|
||||
homeEnabled : Boolean,
|
||||
interval1: Int,
|
||||
interval2: Int,
|
||||
homeInterval: Int,
|
||||
lockInterval: Int,
|
||||
lastSetTime: String?,
|
||||
lockEnabled : Boolean,
|
||||
navigateToAddWallpaperScreen: (String) -> Unit,
|
||||
nextSetTime: String?,
|
||||
onAlbumViewClick: (String) -> Unit,
|
||||
onViewAlbum: (String) -> Unit,
|
||||
onDarkCheck: (Boolean) -> Unit,
|
||||
onDarkenPercentage: (Int) -> Unit,
|
||||
onDarkenPercentage: (Int, Int) -> Unit,
|
||||
onHomeCheckedChange: (Boolean) -> Unit,
|
||||
onLockCheckedChange: (Boolean) -> Unit,
|
||||
onScalingChange: (ScalingConstants) -> Unit,
|
||||
onScheduleWallpaperChanger1: (Int) -> Unit,
|
||||
onScheduleWallpaperChanger2: (Int) -> Unit,
|
||||
onSelectAlbum: (AlbumWithWallpaperAndFolder) -> Unit,
|
||||
onScheduleWallpaperChanger: () -> Unit,
|
||||
onSelectAlbum: (AlbumWithWallpaperAndFolder, Boolean, Boolean) -> Unit,
|
||||
onScheduleSeparatelyChange: (Boolean) -> Unit,
|
||||
onTimeChange1: (Int) -> Unit,
|
||||
onTimeChange2: (Int) -> Unit,
|
||||
onHomeTimeChange: (Int) -> Unit,
|
||||
onLockTimeChange: (Int) -> Unit,
|
||||
onSettingsClick: () -> Unit,
|
||||
onStop: () -> Unit,
|
||||
onStop: (Boolean, Boolean) -> Unit,
|
||||
onToggleChanger: (Boolean) -> Unit,
|
||||
scaling: ScalingConstants,
|
||||
selectedAlbum: SelectedAlbum?,
|
||||
scheduleSeparately: Boolean,
|
||||
blur: Boolean,
|
||||
onBlurPercentageChange: (Int) -> Unit,
|
||||
onBlurPercentageChange: (Int, Int) -> Unit,
|
||||
onBlurChange: (Boolean) -> Unit,
|
||||
blurPercentage: Int,
|
||||
firstSet: Boolean
|
||||
homeBlurPercentage: Int,
|
||||
lockBlurPercentage: Int,
|
||||
currentHomeWallpaper: String?,
|
||||
currentLockWallpaper: String?,
|
||||
homeSelectedAlbum: SelectedAlbum?,
|
||||
lockSelectedAlbum: SelectedAlbum?,
|
||||
homeVignettePercentage: Int,
|
||||
lockVignettePercentage: Int,
|
||||
onVignettePercentageChange: (Int, Int) -> Unit,
|
||||
onVignetteChange: (Boolean) -> Unit,
|
||||
vignette: Boolean,
|
||||
homeGrayscalePercentage: Int,
|
||||
lockGrayscalePercentage: Int,
|
||||
onGrayscalePercentageChange: (Int, Int) -> Unit,
|
||||
onGrayscaleChange: (Boolean) -> Unit,
|
||||
grayscale: Boolean,
|
||||
changeStartTime: Boolean,
|
||||
onChangeStartTimeToggle: (Boolean) -> Unit,
|
||||
onStartTimeChange: (TimePickerState) -> Unit,
|
||||
startingTime: Pair<Int, Int>
|
||||
) {
|
||||
val tabItems = getTabItems()
|
||||
val pagerState = rememberPagerState(0) { tabItems.size }
|
||||
@@ -85,6 +109,9 @@ fun HomeScreen(
|
||||
}
|
||||
|
||||
Scaffold (
|
||||
modifier = Modifier.semantics {
|
||||
testTagsAsResourceId = true
|
||||
},
|
||||
topBar = {
|
||||
HomeTopBar(
|
||||
showSelectionModeAppBar = false,
|
||||
@@ -97,7 +124,7 @@ fun HomeScreen(
|
||||
TabRow(
|
||||
selectedTabIndex = tabIndex,
|
||||
indicator = { tabPositions ->
|
||||
if (tabIndex < tabPositions.size) {
|
||||
if (tabIndex in tabPositions.indices) {
|
||||
TabRowDefaults.PrimaryIndicator(
|
||||
modifier = Modifier.tabIndicatorOffset(tabPositions[tabIndex]),
|
||||
shape = RoundedCornerShape(
|
||||
@@ -118,12 +145,11 @@ fun HomeScreen(
|
||||
text = { Text(text = item.title) },
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector =
|
||||
if (index == tabIndex) item.filledIcon
|
||||
else item.unfilledIcon,
|
||||
imageVector = if (index == tabIndex) item.filledIcon else item.unfilledIcon,
|
||||
contentDescription = item.title
|
||||
)
|
||||
}
|
||||
},
|
||||
modifier = Modifier.testTag("paperize:${item.title}_button"),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -131,15 +157,17 @@ fun HomeScreen(
|
||||
state = pagerState,
|
||||
beyondViewportPageCount = 1
|
||||
) { index ->
|
||||
when(index) {
|
||||
when (index.coerceIn(tabItems.indices)) {
|
||||
0 -> WallpaperScreen(
|
||||
albums = albums,
|
||||
animate = animate,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
homeDarkenPercentage = homeDarkenPercentage,
|
||||
lockDarkenPercentage = lockDarkenPercentage,
|
||||
enableChanger = enableChanger,
|
||||
homeEnabled = homeEnabled,
|
||||
interval1 = interval1,
|
||||
interval2 = interval2,
|
||||
homeInterval = homeInterval,
|
||||
lockInterval = lockInterval,
|
||||
lastSetTime = lastSetTime,
|
||||
lockEnabled = lockEnabled,
|
||||
nextSetTime = nextSetTime,
|
||||
@@ -147,28 +175,44 @@ fun HomeScreen(
|
||||
onDarkenPercentage = onDarkenPercentage,
|
||||
onHomeCheckedChange = onHomeCheckedChange,
|
||||
onLockCheckedChange = onLockCheckedChange,
|
||||
onScheduleWallpaperChanger1 = onScheduleWallpaperChanger1,
|
||||
onScheduleWallpaperChanger2 = onScheduleWallpaperChanger2,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
|
||||
onScheduleWallpaperChanger = onScheduleWallpaperChanger,
|
||||
onScalingChange = onScalingChange,
|
||||
onSelectAlbum = onSelectAlbum,
|
||||
onHomeTimeChange = onHomeTimeChange,
|
||||
onLockTimeChange = onLockTimeChange,
|
||||
onStop = onStop,
|
||||
onToggleChanger = onToggleChanger,
|
||||
scaling = scaling,
|
||||
selectedAlbum = selectedAlbum,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
|
||||
onTimeChange1 = onTimeChange1,
|
||||
onTimeChange2 = onTimeChange2,
|
||||
homeSelectedAlbum = homeSelectedAlbum,
|
||||
lockSelectedAlbum = lockSelectedAlbum,
|
||||
blur = blur,
|
||||
onBlurPercentageChange = onBlurPercentageChange,
|
||||
onBlurChange = onBlurChange,
|
||||
blurPercentage = blurPercentage,
|
||||
firstSet = firstSet
|
||||
homeBlurPercentage = homeBlurPercentage,
|
||||
lockBlurPercentage = lockBlurPercentage,
|
||||
currentHomeWallpaper = currentHomeWallpaper,
|
||||
currentLockWallpaper = currentLockWallpaper,
|
||||
homeVignettePercentage = homeVignettePercentage,
|
||||
lockVignettePercentage = lockVignettePercentage,
|
||||
onVignettePercentageChange = onVignettePercentageChange,
|
||||
onVignetteChange = onVignetteChange,
|
||||
vignette = vignette,
|
||||
homeGrayscalePercentage = homeGrayscalePercentage,
|
||||
lockGrayscalePercentage = lockGrayscalePercentage,
|
||||
onGrayscalePercentageChange = onGrayscalePercentageChange,
|
||||
onGrayscaleChange = onGrayscaleChange,
|
||||
grayscale = grayscale,
|
||||
changeStartTime = changeStartTime,
|
||||
onChangeStartTimeToggle = onChangeStartTimeToggle,
|
||||
onStartTimeChange = onStartTimeChange,
|
||||
startingTime = startingTime
|
||||
)
|
||||
1 -> LibraryScreen(
|
||||
else -> LibraryScreen(
|
||||
albums = albums,
|
||||
onAddNewAlbumClick = { addAlbumDialog = true },
|
||||
onViewAlbum = onAlbumViewClick,
|
||||
animate = animate
|
||||
onViewAlbum = onViewAlbum,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -27,6 +27,7 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
@@ -91,6 +92,7 @@ fun HomeTopBar (
|
||||
} else {
|
||||
IconButton(
|
||||
onClick = { onSettingsClick() },
|
||||
modifier = Modifier.testTag("paperize:home_to_settings_button"),
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Settings,
|
||||
|
||||
+17
-12
@@ -15,31 +15,37 @@ import androidx.compose.material3.LargeFloatingActionButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.testTagsAsResourceId
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.AlbumItem
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun LibraryScreen(
|
||||
albumsViewModel: AlbumsViewModel = hiltViewModel(),
|
||||
albums: List<AlbumWithWallpaperAndFolder>,
|
||||
onAddNewAlbumClick: () -> Unit,
|
||||
onViewAlbum: (String) -> Unit,
|
||||
animate: Boolean
|
||||
) {
|
||||
onViewAlbum: (String) -> Unit
|
||||
) {
|
||||
val lazyListState = rememberLazyGridState()
|
||||
val state = albumsViewModel.state.collectAsStateWithLifecycle()
|
||||
Scaffold(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.semantics {
|
||||
testTagsAsResourceId = true
|
||||
},
|
||||
floatingActionButton = {
|
||||
LargeFloatingActionButton(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
onClick = onAddNewAlbumClick,
|
||||
modifier = Modifier.testTag("paperize:library_floating_button")
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.Add,
|
||||
@@ -52,17 +58,16 @@ fun LibraryScreen(
|
||||
LazyVerticalGrid(
|
||||
state = lazyListState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
columns = GridCells.Fixed(2),
|
||||
columns = GridCells.Adaptive(150.dp),
|
||||
contentPadding = PaddingValues(4.dp, 4.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
content = {
|
||||
items (state.value.albumsWithWallpapers, key = { album -> album.album.initialAlbumName}
|
||||
items (albums, key = { album -> album.album.initialAlbumName}
|
||||
) { album ->
|
||||
AlbumItem(
|
||||
album = album.album,
|
||||
onAlbumViewClick = { onViewAlbum(album.album.initialAlbumName) },
|
||||
modifier = Modifier.padding(4.dp),
|
||||
animate = animate
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
/**
|
||||
* A row that contains an icon, text, and an onClick listener.
|
||||
*/
|
||||
@Composable
|
||||
fun MenuRow(text: String, icon: ImageVector?, horizontalExpansion: Dp, onClick: () -> Unit) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.width(horizontalExpansion)
|
||||
.clickable { onClick() },
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
if (icon != null) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = text,
|
||||
modifier = Modifier.padding(12.dp)
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
Text(
|
||||
text = text,
|
||||
overflow = TextOverflow.Visible,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(end = 20.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components
|
||||
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
|
||||
/**
|
||||
* Data class for selection options
|
||||
*/
|
||||
data class SelectionOptions(
|
||||
val id: String = "",
|
||||
val text: String = "",
|
||||
val subText: String? = "",
|
||||
val icon: ImageVector? = null
|
||||
)
|
||||
+98
-23
@@ -1,40 +1,115 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.data.rememberCurrentOffset
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components.LicenseScrollableSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components.LicenseTitle
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
|
||||
import com.mikepenz.aboutlibraries.ui.compose.m3.LibraryDefaults
|
||||
import me.onebone.toolbar.CollapsingToolbarScaffold
|
||||
import me.onebone.toolbar.ScrollStrategy
|
||||
import me.onebone.toolbar.rememberCollapsingToolbarScaffoldState
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LicensesScreen(
|
||||
topInsets: Dp,
|
||||
onBackClick: () -> Unit,
|
||||
) {
|
||||
val lazyListState = rememberLazyListState()
|
||||
val offset = rememberCurrentOffset(lazyListState)
|
||||
val largeTopAppBarHeight = 152.dp
|
||||
val smallTopAppBarHeight = 64.dp
|
||||
val paddingMedium = 16.dp
|
||||
val topBarState = rememberCollapsingToolbarScaffoldState()
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
LicenseScrollableSettings(
|
||||
largeTopAppBarHeightPx = largeTopAppBarHeight,
|
||||
lazyListState = lazyListState,
|
||||
offset = offset,
|
||||
onBackClick = onBackClick
|
||||
)
|
||||
LicenseTitle(
|
||||
largeTopAppBarHeight = largeTopAppBarHeight,
|
||||
smallTopAppBarHeight = smallTopAppBarHeight,
|
||||
paddingMedium = paddingMedium,
|
||||
offset = offset,
|
||||
topInset = topInsets
|
||||
)
|
||||
// Collapsing top bar
|
||||
val largeTopAppBarHeight = TopAppBarDefaults.LargeAppBarExpandedHeight
|
||||
val startPadding = 64.dp
|
||||
val endPadding = 16.dp
|
||||
val titleFontScaleStart = 30
|
||||
val titleFontScaleEnd = 21
|
||||
val titleExtraStartPadding = 32.dp
|
||||
val collapseFraction = topBarState.toolbarState.progress
|
||||
val firstPaddingInterpolation = lerp((endPadding * 5 / 4), endPadding, collapseFraction) + titleExtraStartPadding
|
||||
val secondPaddingInterpolation = lerp(startPadding, (endPadding * 5 / 4), collapseFraction)
|
||||
val dynamicPaddingStart = lerp(firstPaddingInterpolation, secondPaddingInterpolation, collapseFraction)
|
||||
val textSize = (titleFontScaleEnd + (titleFontScaleStart - titleFontScaleEnd) * collapseFraction).sp
|
||||
|
||||
Scaffold {
|
||||
CollapsingToolbarScaffold(
|
||||
state = topBarState,
|
||||
modifier = Modifier.fillMaxSize().padding(it),
|
||||
scrollStrategy = ScrollStrategy.ExitUntilCollapsed,
|
||||
toolbar = {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(largeTopAppBarHeight)
|
||||
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp))
|
||||
.pin()
|
||||
)
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = stringResource(R.string.licenses),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
fontSize = textSize,
|
||||
modifier = Modifier
|
||||
.road(Alignment.CenterStart, Alignment.BottomStart)
|
||||
.padding(dynamicPaddingStart, 16.dp, 16.dp, 16.dp),
|
||||
)
|
||||
}
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 24.dp),
|
||||
) {
|
||||
LibrariesContainer(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
lazyListState = lazyListState,
|
||||
showVersion = false,
|
||||
colors = LibraryDefaults.libraryColors(
|
||||
backgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
contentColor = MaterialTheme.colorScheme.onSurface,
|
||||
badgeBackgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
badgeContentColor = MaterialTheme.colorScheme.primary,
|
||||
dialogConfirmButtonColor = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
|
||||
import com.mikepenz.aboutlibraries.ui.compose.m3.LibraryDefaults
|
||||
|
||||
/**
|
||||
* Scrollable license screen to display open source licenses
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LicenseScrollableSettings(
|
||||
largeTopAppBarHeightPx: Dp,
|
||||
lazyListState: LazyListState,
|
||||
offset: State<Int>,
|
||||
onBackClick: () -> Unit
|
||||
) {
|
||||
Scaffold (
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
) { it
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 24.dp),
|
||||
) {
|
||||
val offsetInDp = offset.value.toFloat() / 2f.dp.value
|
||||
val newHeight = largeTopAppBarHeightPx - offsetInDp.dp
|
||||
Spacer(Modifier.height(newHeight))
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
LibrariesContainer(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
lazyListState = lazyListState,
|
||||
showVersion = false,
|
||||
colors = LibraryDefaults.libraryColors(
|
||||
backgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
contentColor = MaterialTheme.colorScheme.onSurface,
|
||||
badgeBackgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
badgeContentColor = MaterialTheme.colorScheme.primary,
|
||||
dialogConfirmButtonColor = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components
|
||||
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Title for the license screen.
|
||||
*/
|
||||
@Composable
|
||||
fun LicenseTitle(
|
||||
largeTopAppBarHeight: Dp,
|
||||
smallTopAppBarHeight: Dp,
|
||||
paddingMedium: Dp,
|
||||
modifier: Modifier = Modifier,
|
||||
offset: State<Int>,
|
||||
topInset: Dp,
|
||||
) {
|
||||
val titlePaddingStart = 16.dp
|
||||
val titlePaddingEnd = 64.dp
|
||||
val titleFontScaleStart = 1f
|
||||
val titleFontScaleEnd = 0.7f
|
||||
var titleHeightPx by remember { mutableFloatStateOf(0f) }
|
||||
var titleWidthPx by remember { mutableFloatStateOf(0f) }
|
||||
|
||||
val fraction = (topInset - 74.dp) / (151.dp - 74.dp)
|
||||
val statusPadding = lerp(0.dp, 24.dp, fraction.coerceIn(0f, 1f))
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.licenses),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
fontSize = 30.sp,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
modifier = modifier
|
||||
.graphicsLayer {
|
||||
val collapseRange: Float = (largeTopAppBarHeight.toPx() - smallTopAppBarHeight.toPx())
|
||||
val collapseFraction: Float = (offset.value.toFloat() / collapseRange).coerceIn(0f, 1f)
|
||||
|
||||
val scaleXY = lerp(
|
||||
titleFontScaleStart.dp,
|
||||
titleFontScaleEnd.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleExtraStartPadding = titleWidthPx.toDp() * (1 - scaleXY.value) / 2f
|
||||
|
||||
val titleYFirstInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium + statusPadding,
|
||||
largeTopAppBarHeight / 2,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleXFirstInterpolatedPoint = lerp(
|
||||
titlePaddingStart,
|
||||
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleYSecondInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight / 2,
|
||||
(smallTopAppBarHeight + statusPadding - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleXSecondInterpolatedPoint = lerp(
|
||||
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
|
||||
titlePaddingEnd - titleExtraStartPadding,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleY = lerp(
|
||||
titleYFirstInterpolatedPoint,
|
||||
titleYSecondInterpolatedPoint,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleX = lerp(
|
||||
titleXFirstInterpolatedPoint,
|
||||
titleXSecondInterpolatedPoint,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
translationY = titleY.toPx()
|
||||
translationX = titleX.toPx()
|
||||
scaleX = scaleXY.value
|
||||
scaleY = scaleXY.value
|
||||
}
|
||||
.onGloballyPositioned {
|
||||
titleHeightPx = it.size.height.toFloat()
|
||||
titleWidthPx = it.size.width.toFloat()
|
||||
}
|
||||
)
|
||||
}
|
||||
+10
-1
@@ -25,11 +25,14 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.testTagsAsResourceId
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.airbnb.lottie.compose.LottieAnimation
|
||||
@@ -39,6 +42,7 @@ import com.airbnb.lottie.compose.animateLottieCompositionAsState
|
||||
import com.airbnb.lottie.compose.rememberLottieComposition
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun NotificationScreen(
|
||||
onAgree: () -> Unit
|
||||
@@ -74,6 +78,9 @@ fun NotificationScreen(
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.semantics {
|
||||
testTagsAsResourceId = true
|
||||
},
|
||||
content = { it
|
||||
Column (modifier = Modifier.padding(32.dp)) {
|
||||
Spacer(modifier = Modifier.height(120.dp))
|
||||
@@ -102,7 +109,9 @@ fun NotificationScreen(
|
||||
},
|
||||
floatingActionButton = {
|
||||
ExtendedFloatingActionButton(
|
||||
modifier = Modifier.padding(8.dp),
|
||||
modifier = Modifier
|
||||
.padding(8.dp)
|
||||
.testTag("paperize:floating_notification_button"),
|
||||
onClick = { askPermission.value = true },
|
||||
icon = {
|
||||
Icon(
|
||||
|
||||
+115
-22
@@ -1,38 +1,131 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components.PrivacyScrollableSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components.PrivacyTitle
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.anthonyla.paperize.R
|
||||
import me.onebone.toolbar.CollapsingToolbarScaffold
|
||||
import me.onebone.toolbar.ScrollStrategy
|
||||
import me.onebone.toolbar.rememberCollapsingToolbarScaffoldState
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun PrivacyScreen(
|
||||
topInsets: Dp,
|
||||
onBackClick: () -> Unit,
|
||||
) {
|
||||
val scroll: ScrollState = rememberScrollState(0)
|
||||
val largeTopAppBarHeight = 152.dp
|
||||
val smallTopAppBarHeight = 64.dp
|
||||
val paddingMedium = 16.dp
|
||||
val topBarState = rememberCollapsingToolbarScaffoldState()
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
PrivacyScrollableSettings(
|
||||
largeTopAppBarHeightPx = largeTopAppBarHeight,
|
||||
scroll = scroll,
|
||||
onBackClick = onBackClick
|
||||
)
|
||||
PrivacyTitle(
|
||||
scroll = scroll,
|
||||
largeTopAppBarHeight = largeTopAppBarHeight,
|
||||
smallTopAppBarHeight = smallTopAppBarHeight,
|
||||
paddingMedium = paddingMedium,
|
||||
topInset = topInsets
|
||||
)
|
||||
// Collapsing top bar
|
||||
val largeTopAppBarHeight = TopAppBarDefaults.LargeAppBarExpandedHeight
|
||||
val startPadding = 64.dp
|
||||
val endPadding = 16.dp
|
||||
val titleFontScaleStart = 30
|
||||
val titleFontScaleEnd = 21
|
||||
val titleExtraStartPadding = 32.dp
|
||||
val collapseFraction = topBarState.toolbarState.progress
|
||||
val firstPaddingInterpolation = lerp((endPadding * 5 / 4), endPadding, collapseFraction) + titleExtraStartPadding
|
||||
val secondPaddingInterpolation = lerp(startPadding, (endPadding * 5 / 4), collapseFraction)
|
||||
val dynamicPaddingStart = lerp(firstPaddingInterpolation, secondPaddingInterpolation, collapseFraction)
|
||||
val textSize = (titleFontScaleEnd + (titleFontScaleStart - titleFontScaleEnd) * collapseFraction).sp
|
||||
|
||||
Scaffold {
|
||||
CollapsingToolbarScaffold(
|
||||
state = topBarState,
|
||||
modifier = Modifier.fillMaxSize().padding(it),
|
||||
scrollStrategy = ScrollStrategy.ExitUntilCollapsed,
|
||||
toolbar = {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(largeTopAppBarHeight)
|
||||
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp))
|
||||
.pin()
|
||||
)
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = stringResource(id = R.string.privacy_policy),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
fontSize = textSize,
|
||||
modifier = Modifier
|
||||
.road(Alignment.CenterStart, Alignment.BottomStart)
|
||||
.padding(dynamicPaddingStart, 16.dp, 16.dp, 16.dp),
|
||||
)
|
||||
}
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 24.dp),
|
||||
) {
|
||||
PrivacyNoticeText()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PrivacyNoticeText() {
|
||||
SectionText(stringResource(R.string.privacy_intro_title), stringResource(R.string.privacy_intro_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_data_collection_title), stringResource(R.string.privacy_data_collection_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_information_usage_title), stringResource(R.string.privacy_information_usage_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_data_security_title), stringResource(R.string.privacy_data_security_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_third_party_services_title), stringResource(R.string.privacy_third_party_services_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_children_privacy_title), stringResource(R.string.privacy_children_privacy_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_changes_notice_title), stringResource(R.string.privacy_changes_notice_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_contact_us_title), stringResource(R.string.privacy_contact_us_content, "anthonyyla.dev@gmail.com"))
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SectionText(title: String, content: String) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
modifier = Modifier.padding(vertical = 8.dp),
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
|
||||
)
|
||||
Text(
|
||||
text = content,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = Modifier.padding(bottom = 16.dp)
|
||||
)
|
||||
}
|
||||
-100
@@ -1,100 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Scrollable privacy screen to display privacy note
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun PrivacyScrollableSettings(
|
||||
largeTopAppBarHeightPx: Dp,
|
||||
scroll: ScrollState,
|
||||
onBackClick: () -> Unit
|
||||
) {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
) { it
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.verticalScroll(scroll)
|
||||
.padding(horizontal = 24.dp),
|
||||
) {
|
||||
Spacer(Modifier.height(largeTopAppBarHeightPx))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PrivacyNoticeText()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun PrivacyNoticeText() {
|
||||
SectionText(stringResource(R.string.privacy_intro_title), stringResource(R.string.privacy_intro_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_data_collection_title), stringResource(R.string.privacy_data_collection_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_information_usage_title), stringResource(R.string.privacy_information_usage_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_data_security_title), stringResource(R.string.privacy_data_security_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_third_party_services_title), stringResource(R.string.privacy_third_party_services_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_children_privacy_title), stringResource(R.string.privacy_children_privacy_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_changes_notice_title), stringResource(R.string.privacy_changes_notice_content, stringResource(R.string.app_name)))
|
||||
SectionText(stringResource(R.string.privacy_contact_us_title), stringResource(R.string.privacy_contact_us_content, "anthonyyla.dev@gmail.com"))
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SectionText(title: String, content: String) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
modifier = Modifier.padding(vertical = 8.dp),
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
|
||||
)
|
||||
Text(
|
||||
text = content,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = Modifier.padding(bottom = 16.dp)
|
||||
)
|
||||
}
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Title for the privacy screen.
|
||||
*/
|
||||
@Composable
|
||||
fun PrivacyTitle(
|
||||
largeTopAppBarHeight: Dp,
|
||||
smallTopAppBarHeight: Dp,
|
||||
paddingMedium: Dp,
|
||||
scroll: ScrollState,
|
||||
modifier: Modifier = Modifier,
|
||||
topInset: Dp,
|
||||
) {
|
||||
val titlePaddingStart = 16.dp
|
||||
val titlePaddingEnd = 64.dp
|
||||
val titleFontScaleStart = 1f
|
||||
val titleFontScaleEnd = 0.7f
|
||||
var titleHeightPx by remember { mutableFloatStateOf(0f) }
|
||||
var titleWidthPx by remember { mutableFloatStateOf(0f) }
|
||||
|
||||
val fraction = (topInset - 74.dp) / (151.dp - 74.dp)
|
||||
val statusPadding = lerp(0.dp, 24.dp, fraction.coerceIn(0f, 1f))
|
||||
|
||||
Text(
|
||||
text = stringResource(id = R.string.privacy_policy),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
fontSize = 30.sp,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
modifier = modifier
|
||||
.graphicsLayer {
|
||||
val collapseRange: Float = (largeTopAppBarHeight.toPx() - smallTopAppBarHeight.toPx())
|
||||
val collapseFraction: Float = (scroll.value / collapseRange).coerceIn(0f, 1f)
|
||||
|
||||
val scaleXY = lerp(
|
||||
titleFontScaleStart.dp,
|
||||
titleFontScaleEnd.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleExtraStartPadding = titleWidthPx.toDp() * (1 - scaleXY.value) / 2f
|
||||
|
||||
val titleYFirstInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium + statusPadding,
|
||||
largeTopAppBarHeight / 2,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleXFirstInterpolatedPoint = lerp(
|
||||
titlePaddingStart,
|
||||
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleYSecondInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight / 2,
|
||||
(smallTopAppBarHeight + statusPadding - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleXSecondInterpolatedPoint = lerp(
|
||||
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
|
||||
titlePaddingEnd - titleExtraStartPadding,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleY = lerp(
|
||||
titleYFirstInterpolatedPoint,
|
||||
titleYSecondInterpolatedPoint,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleX = lerp(
|
||||
titleXFirstInterpolatedPoint,
|
||||
titleXSecondInterpolatedPoint,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
translationY = titleY.toPx()
|
||||
translationX = titleX.toPx()
|
||||
scaleX = scaleXY.value
|
||||
scaleY = scaleXY.value
|
||||
}
|
||||
.onGloballyPositioned {
|
||||
titleHeightPx = it.size.height.toFloat()
|
||||
titleWidthPx = it.size.width.toFloat()
|
||||
}
|
||||
)
|
||||
}
|
||||
+19
-3
@@ -7,20 +7,36 @@ sealed class SettingsEvent {
|
||||
data object Refresh: SettingsEvent()
|
||||
data object Reset: SettingsEvent()
|
||||
data object SetFirstLaunch: SettingsEvent()
|
||||
data object SetFirstSet: SettingsEvent()
|
||||
data object RefreshNextSetTime: SettingsEvent()
|
||||
data class SetDarkMode(val darkMode: Boolean?): SettingsEvent()
|
||||
data class SetAmoledTheme(val amoledTheme: Boolean): SettingsEvent()
|
||||
data class SetDynamicTheming(val dynamicTheming: Boolean): SettingsEvent()
|
||||
data class SetAnimate(val animate: Boolean): SettingsEvent()
|
||||
data class SetDarken(val darken: Boolean): SettingsEvent()
|
||||
data class SetBlur(val blur: Boolean): SettingsEvent()
|
||||
data class SetVignette(val vignette: Boolean): SettingsEvent()
|
||||
data class SetGrayscale(val grayscale: Boolean): SettingsEvent()
|
||||
data class SetLock(val lock: Boolean): SettingsEvent()
|
||||
data class SetHome(val home: Boolean): SettingsEvent()
|
||||
data class SetChangeStartTime(val changeStartTime: Boolean): SettingsEvent()
|
||||
data class SetCurrentHomeWallpaper(val currentHomeWallpaper: String?): SettingsEvent()
|
||||
data class SetCurrentLockWallpaper(val currentLockWallpaper: String?): SettingsEvent()
|
||||
data class SetCurrentWallpaper(val currentHomeWallpaper: String?, val currentLockWallpaper: String?): SettingsEvent()
|
||||
data class SetAlbumName(val homeAlbumName: String? = null, val lockAlbumName: String? = null): SettingsEvent()
|
||||
data class RemoveSelectedAlbumAsType(val removeLock: Boolean = false, val removeHome: Boolean = false): SettingsEvent()
|
||||
data class RemoveSelectedAlbumAsName(val albumName: String): SettingsEvent()
|
||||
data class SetScheduleSeparately(val scheduleSeparately: Boolean): SettingsEvent()
|
||||
data class SetHomeWallpaperInterval(val interval: Int): SettingsEvent()
|
||||
data class SetLockWallpaperInterval(val interval: Int): SettingsEvent()
|
||||
data class SetDarkenPercentage(val darkenPercentage: Int): SettingsEvent()
|
||||
data class SetBlurPercentage(val blurPercentage: Int): SettingsEvent()
|
||||
data class SetDarkenPercentage(val homeDarkenPercentage: Int?, val lockDarkenPercentage: Int?): SettingsEvent()
|
||||
data class SetBlurPercentage(val homeBlurPercentage: Int?, val lockBlurPercentage: Int?): SettingsEvent()
|
||||
data class SetVignettePercentage(val homeVignettePercentage: Int?, val lockVignettePercentage: Int?): SettingsEvent()
|
||||
data class SetGrayscalePercentage(val homeGrayscalePercentage: Int?, val lockGrayscalePercentage: Int?): SettingsEvent()
|
||||
data class SetChangerToggle(val toggle: Boolean): SettingsEvent()
|
||||
data class SetWallpaperScaling(val scaling: ScalingConstants): SettingsEvent()
|
||||
data class SetNextHomeWallpaper(val nextHomeWallpaper: String?): SettingsEvent()
|
||||
data class SetNextLockWallpaper(val nextLockWallpaper: String?): SettingsEvent()
|
||||
data class SetNextWallpaper(val nextHomeWallpaper: String?, val nextLockWallpaper: String?): SettingsEvent()
|
||||
data class SetStartTime(val hour: Int, val minute: Int): SettingsEvent()
|
||||
data object RefreshNextWallpaper: SettingsEvent()
|
||||
}
|
||||
+190
-32
@@ -1,57 +1,215 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.provider.Settings
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.testTagsAsResourceId
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.SettingsScrollableSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.SettingsTitle
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.AmoledListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.AnimationListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ContactListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.DarkModeListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.DynamicThemingListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.LicenseListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ListSectionTitle
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.NotificationListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.PaperizeListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.PrivacyPolicyListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ResetListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.TranslateListItem
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import me.onebone.toolbar.CollapsingToolbarScaffold
|
||||
import me.onebone.toolbar.ScrollStrategy
|
||||
import me.onebone.toolbar.rememberCollapsingToolbarScaffoldState
|
||||
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun SettingsScreen(
|
||||
settingsState: StateFlow<SettingsState>,
|
||||
topInsets: Dp,
|
||||
onBackClick: () -> Unit,
|
||||
onDarkModeClick: (Boolean?) -> Unit,
|
||||
onAmoledClick: (Boolean) -> Unit,
|
||||
onDynamicThemingClick: (Boolean) -> Unit,
|
||||
onAnimateClick: (Boolean) -> Unit,
|
||||
onPrivacyClick: () -> Unit,
|
||||
onLicenseClick: () -> Unit,
|
||||
onResetClick: () -> Unit
|
||||
onResetClick: () -> Unit,
|
||||
onContactClick: () -> Unit
|
||||
) {
|
||||
val scroll: ScrollState = rememberScrollState(0)
|
||||
val largeTopAppBarHeight = TopAppBarDefaults.LargeAppBarExpandedHeight
|
||||
val smallTopAppBarHeight = TopAppBarDefaults.LargeAppBarCollapsedHeight
|
||||
val paddingMedium = 16.dp
|
||||
val topBarState = rememberCollapsingToolbarScaffoldState()
|
||||
val state = settingsState.collectAsStateWithLifecycle()
|
||||
val context = LocalContext.current
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
SettingsScrollableSettings(
|
||||
settingsState = settingsState,
|
||||
largeTopAppBarHeightPx = largeTopAppBarHeight,
|
||||
scroll = scroll,
|
||||
onDarkModeClick = onDarkModeClick,
|
||||
onDynamicThemingClick = onDynamicThemingClick,
|
||||
onAnimateClick = onAnimateClick,
|
||||
onPrivacyClick = onPrivacyClick,
|
||||
onLicenseClick = onLicenseClick,
|
||||
onResetClick = onResetClick,
|
||||
onBackClick = onBackClick,
|
||||
)
|
||||
SettingsTitle(
|
||||
scroll = scroll,
|
||||
largeTopAppBarHeight = largeTopAppBarHeight,
|
||||
smallTopAppBarHeight = smallTopAppBarHeight,
|
||||
paddingMedium = paddingMedium,
|
||||
topInset = topInsets
|
||||
)
|
||||
val translateLink = "https://crowdin.com/project/paperize/invite?h=d8d7a7513d2beb0c96ba9b2a5f85473e2084922"
|
||||
val githubLink = "https://github.com/Anthonyy232/Paperize"
|
||||
val fdroidLink = "https://f-droid.org/en/packages/com.anthonyla.paperize/"
|
||||
val izzyOnDroidLink = "https://apt.izzysoft.de/fdroid/index/apk/com.anthonyla.paperize"
|
||||
|
||||
// Collapsing top bar
|
||||
val largeTopAppBarHeight = TopAppBarDefaults.LargeAppBarExpandedHeight
|
||||
val startPadding = 64.dp
|
||||
val endPadding = 16.dp
|
||||
val titleFontScaleStart = 30
|
||||
val titleFontScaleEnd = 21
|
||||
val titleExtraStartPadding = 32.dp
|
||||
val collapseFraction = topBarState.toolbarState.progress
|
||||
val firstPaddingInterpolation = lerp((endPadding * 5 / 4), endPadding, collapseFraction) + titleExtraStartPadding
|
||||
val secondPaddingInterpolation = lerp(startPadding, (endPadding * 5 / 4), collapseFraction)
|
||||
val dynamicPaddingStart = lerp(firstPaddingInterpolation, secondPaddingInterpolation, collapseFraction)
|
||||
val textSize = (titleFontScaleEnd + (titleFontScaleStart - titleFontScaleEnd) * collapseFraction).sp
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.semantics { testTagsAsResourceId = true },
|
||||
) {
|
||||
CollapsingToolbarScaffold(
|
||||
state = topBarState,
|
||||
modifier = Modifier.fillMaxSize().padding(it),
|
||||
scrollStrategy = ScrollStrategy.ExitUntilCollapsed,
|
||||
toolbar = {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(largeTopAppBarHeight)
|
||||
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp))
|
||||
.pin()
|
||||
)
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
.testTag("paperize:settings_to_home_button"),
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = stringResource(id = R.string.settings_screen),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
fontSize = textSize,
|
||||
modifier = Modifier
|
||||
.road(Alignment.CenterStart, Alignment.BottomStart)
|
||||
.padding(dynamicPaddingStart, 16.dp, 16.dp, 16.dp),
|
||||
)
|
||||
}
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 24.dp)
|
||||
.testTag("paperize:settings_column"),
|
||||
) {
|
||||
ListSectionTitle(stringResource(R.string.appearance))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
DarkModeListItem(
|
||||
darkMode = state.value.darkMode,
|
||||
onDarkModeClick = { onDarkModeClick(it) }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
if (state.value.darkMode == null || state.value.darkMode == true) {
|
||||
AmoledListItem(
|
||||
amoledMode = state.value.amoledTheme,
|
||||
onAmoledClick = { onAmoledClick(it) }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
DynamicThemingListItem(
|
||||
dynamicTheming = state.value.dynamicTheming,
|
||||
onDynamicThemingClick = { onDynamicThemingClick(it) }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
AnimationListItem(
|
||||
animate = state.value.animate,
|
||||
onAnimateClick = { onAnimateClick(it) }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ListSectionTitle(stringResource(R.string.about))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
NotificationListItem(
|
||||
onClick = {
|
||||
val intent = Intent().apply {
|
||||
action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
|
||||
putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
|
||||
}
|
||||
context.startActivity(intent)
|
||||
}
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
TranslateListItem(
|
||||
onClick = {
|
||||
val openURL = Intent(Intent.ACTION_VIEW)
|
||||
openURL.data = Uri.parse(translateLink)
|
||||
context.startActivity(openURL)
|
||||
}
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PrivacyPolicyListItem (onPrivacyPolicyClick = onPrivacyClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
LicenseListItem(onLicenseClick = onLicenseClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ContactListItem(onContactClick = onContactClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PaperizeListItem(
|
||||
onGitHubClick = {
|
||||
val openURL = Intent(Intent.ACTION_VIEW)
|
||||
openURL.data = Uri.parse(githubLink)
|
||||
context.startActivity(openURL)
|
||||
},
|
||||
onFdroidClick = {
|
||||
val openURL = Intent(Intent.ACTION_VIEW)
|
||||
openURL.data = Uri.parse(fdroidLink)
|
||||
context.startActivity(openURL)
|
||||
},
|
||||
onIzzyOnDroidClick = {
|
||||
val openURL = Intent(Intent.ACTION_VIEW)
|
||||
openURL.data = Uri.parse(izzyOnDroidLink)
|
||||
context.startActivity(openURL)
|
||||
},
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ResetListItem(onResetClick = onResetClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
-4
@@ -4,23 +4,39 @@ import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_D
|
||||
|
||||
data class SettingsState(
|
||||
val firstLaunch: Boolean = true,
|
||||
val firstSet: Boolean = true,
|
||||
// App settings
|
||||
val darkMode: Boolean? = null,
|
||||
val amoledTheme: Boolean = false,
|
||||
val dynamicTheming: Boolean = false,
|
||||
val animate: Boolean = true,
|
||||
// Wallpaper settings
|
||||
val enableChanger: Boolean = false,
|
||||
val setHomeWallpaper: Boolean = false,
|
||||
val setLockWallpaper: Boolean = false,
|
||||
val currentHomeWallpaper: String? = null,
|
||||
val currentLockWallpaper: String? = null,
|
||||
val homeAlbumName: String? = null,
|
||||
val lockAlbumName: String? = null,
|
||||
val scheduleSeparately: Boolean = false,
|
||||
val homeInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val lockInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val lastSetTime: String? = null,
|
||||
val nextSetTime: String? = null,
|
||||
val darkenPercentage: Int = 100,
|
||||
val homeDarkenPercentage: Int = 100,
|
||||
val lockDarkenPercentage: Int = 100,
|
||||
val darken: Boolean = false,
|
||||
val blur: Boolean = false,
|
||||
val blurPercentage: Int = 0,
|
||||
val wallpaperScaling: ScalingConstants = ScalingConstants.FILL
|
||||
val homeBlurPercentage: Int = 0,
|
||||
val lockBlurPercentage: Int = 0,
|
||||
val vignette: Boolean = false,
|
||||
val homeVignettePercentage: Int = 0,
|
||||
val lockVignettePercentage: Int = 0,
|
||||
val grayscale: Boolean = false,
|
||||
val homeGrayscalePercentage: Int = 0,
|
||||
val lockGrayscalePercentage: Int = 0,
|
||||
val wallpaperScaling: ScalingConstants = ScalingConstants.FILL,
|
||||
val nextHomeWallpaper: String? = null,
|
||||
val nextLockWallpaper: String? = null,
|
||||
val changeStartTime: Boolean = false,
|
||||
val startTime: Pair<Int, Int> = Pair(0, 0)
|
||||
)
|
||||
+554
-80
@@ -35,44 +35,76 @@ class SettingsViewModel @Inject constructor (
|
||||
init {
|
||||
currentGetJob = viewModelScope.launch(Dispatchers.IO) {
|
||||
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
|
||||
val firstSet = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_SET) ?: false }
|
||||
val darkMode = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) }
|
||||
val amoledTheme = async { settingsDataStoreImpl.getBoolean(SettingsConstants.AMOLED_THEME_TYPE) ?: false }
|
||||
val dynamicTheming = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false }
|
||||
val enableChanger = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: true }
|
||||
val setHomeWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.HOME_WALLPAPER) ?: false }
|
||||
val setLockWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.LOCK_WALLPAPER) ?: false }
|
||||
val enableChanger = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false }
|
||||
val setHomeWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false }
|
||||
val setLockWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false }
|
||||
val setCurrentHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.CURRENT_HOME_WALLPAPER) }
|
||||
val setCurrentLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.CURRENT_LOCK_WALLPAPER) }
|
||||
val homeWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val lockWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val homeAlbumName = async { settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME) }
|
||||
val lockAlbumName = async { settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME) }
|
||||
val lastSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME) }
|
||||
val nextSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME) }
|
||||
val animate = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true }
|
||||
val darkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.DARKEN_PERCENTAGE) ?: 100 }
|
||||
val homeDarkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_DARKEN_PERCENTAGE) ?: 100 }
|
||||
val lockDarkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_DARKEN_PERCENTAGE) ?: 100 }
|
||||
val darken = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false }
|
||||
val wallpaperScaling = async { ScalingConstants.valueOf(settingsDataStoreImpl.getString(SettingsConstants.WALLPAPER_SCALING) ?: ScalingConstants.FILL.name) }
|
||||
val scheduleSeparately = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false }
|
||||
val blur = async { settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false }
|
||||
val blurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.BLUR_PERCENTAGE) ?: 0 }
|
||||
val homeBlurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_BLUR_PERCENTAGE) ?: 0 }
|
||||
val lockBlurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_BLUR_PERCENTAGE) ?: 0 }
|
||||
val vignette = async { settingsDataStoreImpl.getBoolean(SettingsConstants.VIGNETTE) ?: false }
|
||||
val homeVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) ?: 0 }
|
||||
val lockVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE) ?: 0 }
|
||||
val grayscale = async { settingsDataStoreImpl.getBoolean(SettingsConstants.GRAYSCALE) ?: false }
|
||||
val homeGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) ?: 0 }
|
||||
val lockGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) ?: 0 }
|
||||
val nextHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME) }
|
||||
val nextLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME) }
|
||||
val changeStartTime = async { settingsDataStoreImpl.getBoolean(SettingsConstants.CHANGE_START_TIME) ?: false }
|
||||
val startTime = async { Pair(settingsDataStoreImpl.getInt(SettingsConstants.START_HOUR) ?: 0, settingsDataStoreImpl.getInt(SettingsConstants.START_MINUTE) ?: 0) }
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = darkMode.await(),
|
||||
amoledTheme = amoledTheme.await(),
|
||||
dynamicTheming = dynamicTheming.await(),
|
||||
homeInterval = homeWallpaperInterval.await(),
|
||||
lockInterval = lockWallpaperInterval.await(),
|
||||
homeAlbumName = homeAlbumName.await(),
|
||||
lockAlbumName = lockAlbumName.await(),
|
||||
firstLaunch = firstLaunch.await(),
|
||||
firstSet = firstSet.await(),
|
||||
lastSetTime = lastSetTime.await(),
|
||||
nextSetTime = nextSetTime.await(),
|
||||
animate = animate.await(),
|
||||
enableChanger = enableChanger.await(),
|
||||
darkenPercentage = darkenPercentage.await(),
|
||||
homeDarkenPercentage = homeDarkenPercentage.await(),
|
||||
lockDarkenPercentage = lockDarkenPercentage.await(),
|
||||
darken = darken.await(),
|
||||
wallpaperScaling = wallpaperScaling.await(),
|
||||
setHomeWallpaper = setHomeWallpaper.await(),
|
||||
setLockWallpaper = setLockWallpaper.await(),
|
||||
currentHomeWallpaper = setCurrentHomeWallpaper.await(),
|
||||
currentLockWallpaper = setCurrentLockWallpaper.await(),
|
||||
scheduleSeparately = scheduleSeparately.await(),
|
||||
blur = blur.await(),
|
||||
blurPercentage = blurPercentage.await()
|
||||
homeBlurPercentage = homeBlurPercentage.await(),
|
||||
lockBlurPercentage = lockBlurPercentage.await(),
|
||||
nextHomeWallpaper = nextHomeWallpaper.await(),
|
||||
nextLockWallpaper = nextLockWallpaper.await(),
|
||||
vignette = vignette.await(),
|
||||
homeVignettePercentage = homeVignettePercentage.await(),
|
||||
lockVignettePercentage = lockVignettePercentage.await(),
|
||||
grayscale = grayscale.await(),
|
||||
homeGrayscalePercentage = homeGrayscalePercentage.await(),
|
||||
lockGrayscalePercentage = lockGrayscalePercentage.await(),
|
||||
changeStartTime = changeStartTime.await(),
|
||||
startTime = startTime.await()
|
||||
)
|
||||
}
|
||||
setKeepOnScreenCondition = false
|
||||
@@ -97,7 +129,9 @@ class SettingsViewModel @Inject constructor (
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, event.toggle)
|
||||
_state.update {
|
||||
it.copy(
|
||||
enableChanger = event.toggle
|
||||
enableChanger = event.toggle,
|
||||
currentHomeWallpaper = if (!event.toggle) null else it.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (!event.toggle) null else it.currentLockWallpaper
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -106,41 +140,74 @@ class SettingsViewModel @Inject constructor (
|
||||
is SettingsEvent.Refresh -> {
|
||||
currentGetJob = viewModelScope.launch(Dispatchers.IO) {
|
||||
val darkMode = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) }
|
||||
val amoledTheme = async { settingsDataStoreImpl.getBoolean(SettingsConstants.AMOLED_THEME_TYPE) ?: false }
|
||||
val dynamicTheming = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false }
|
||||
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
|
||||
val lastSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME) }
|
||||
val nextSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME) }
|
||||
val animate = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true }
|
||||
val enableChanger = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: true }
|
||||
val darkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.DARKEN_PERCENTAGE) ?: 0 }
|
||||
val enableChanger = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false }
|
||||
val homeDarkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_DARKEN_PERCENTAGE) ?: 0 }
|
||||
val lockDarkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_DARKEN_PERCENTAGE) ?: 0 }
|
||||
val darken = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false }
|
||||
val setHomeWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.HOME_WALLPAPER) ?: false }
|
||||
val setLockWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.LOCK_WALLPAPER) ?: false }
|
||||
val setHomeWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false }
|
||||
val setLockWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false }
|
||||
val homeAlbumName = async { settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME) }
|
||||
val lockAlbumName = async { settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME) }
|
||||
val currentHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.CURRENT_HOME_WALLPAPER) }
|
||||
val currentLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.CURRENT_LOCK_WALLPAPER) }
|
||||
val homeWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val lockWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val scheduleSeparately = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false }
|
||||
val blur = async { settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false }
|
||||
val blurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.BLUR_PERCENTAGE) ?: 0 }
|
||||
val firstSet = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_SET) ?: true }
|
||||
val homeBlurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_BLUR_PERCENTAGE) ?: 0 }
|
||||
val lockBlurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_BLUR_PERCENTAGE) ?: 0 }
|
||||
val nextHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME) }
|
||||
val nextLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME) }
|
||||
val vignette = async { settingsDataStoreImpl.getBoolean(SettingsConstants.VIGNETTE) ?: false }
|
||||
val homeVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) ?: 0 }
|
||||
val lockVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE) ?: 0 }
|
||||
val grayscale = async { settingsDataStoreImpl.getBoolean(SettingsConstants.GRAYSCALE) ?: false }
|
||||
val homeGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) ?: 0 }
|
||||
val lockGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) ?: 0 }
|
||||
val changeStartTime = async { settingsDataStoreImpl.getBoolean(SettingsConstants.CHANGE_START_TIME) ?: false }
|
||||
val startTime = async { Pair(settingsDataStoreImpl.getInt(SettingsConstants.START_HOUR) ?: 0, settingsDataStoreImpl.getInt(SettingsConstants.START_MINUTE) ?: 0) }
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = darkMode.await(),
|
||||
amoledTheme = amoledTheme.await(),
|
||||
dynamicTheming = dynamicTheming.await(),
|
||||
firstLaunch = firstLaunch.await(),
|
||||
lastSetTime = lastSetTime.await(),
|
||||
nextSetTime = nextSetTime.await(),
|
||||
animate = animate.await(),
|
||||
enableChanger = enableChanger.await(),
|
||||
darkenPercentage = darkenPercentage.await(),
|
||||
homeDarkenPercentage = homeDarkenPercentage.await(),
|
||||
lockDarkenPercentage = lockDarkenPercentage.await(),
|
||||
darken = darken.await(),
|
||||
setHomeWallpaper = setHomeWallpaper.await(),
|
||||
setLockWallpaper = setLockWallpaper.await(),
|
||||
homeAlbumName = homeAlbumName.await(),
|
||||
lockAlbumName = lockAlbumName.await(),
|
||||
currentHomeWallpaper = currentHomeWallpaper.await(),
|
||||
currentLockWallpaper = currentLockWallpaper.await(),
|
||||
lockInterval = lockWallpaperInterval.await(),
|
||||
homeInterval = homeWallpaperInterval.await(),
|
||||
scheduleSeparately = scheduleSeparately.await(),
|
||||
blur = blur.await(),
|
||||
blurPercentage = blurPercentage.await(),
|
||||
firstSet = firstSet.await()
|
||||
homeBlurPercentage = homeBlurPercentage.await(),
|
||||
lockBlurPercentage = lockBlurPercentage.await(),
|
||||
nextHomeWallpaper = nextHomeWallpaper.await(),
|
||||
nextLockWallpaper = nextLockWallpaper.await(),
|
||||
vignette = vignette.await(),
|
||||
homeVignettePercentage = homeVignettePercentage.await(),
|
||||
lockVignettePercentage = lockVignettePercentage.await(),
|
||||
grayscale = grayscale.await(),
|
||||
homeGrayscalePercentage = homeGrayscalePercentage.await(),
|
||||
lockGrayscalePercentage = lockGrayscalePercentage.await(),
|
||||
changeStartTime = changeStartTime.await(),
|
||||
startTime = startTime.await()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -161,11 +228,30 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetAmoledTheme -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.AMOLED_THEME_TYPE, event.amoledTheme)
|
||||
if (event.amoledTheme) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.DYNAMIC_THEME_TYPE, false)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
amoledTheme = event.amoledTheme,
|
||||
dynamicTheming = if (event.amoledTheme) false else it.dynamicTheming
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetDynamicTheming -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.DYNAMIC_THEME_TYPE, event.dynamicTheming)
|
||||
if (event.dynamicTheming) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.AMOLED_THEME_TYPE, false)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
amoledTheme = if (event.dynamicTheming) false else it.amoledTheme,
|
||||
dynamicTheming = event.dynamicTheming
|
||||
)
|
||||
}
|
||||
@@ -183,37 +269,30 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetFirstSet -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.FIRST_SET, false)
|
||||
_state.update {
|
||||
it.copy(
|
||||
firstSet = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetHomeWallpaperInterval -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL, event.interval)
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now()
|
||||
val currentTime = if (_state.value.changeStartTime) {
|
||||
LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second)
|
||||
} else {
|
||||
LocalDateTime.now()
|
||||
}
|
||||
val nextSetTime: String?
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
|
||||
if (_state.value.scheduleSeparately) {
|
||||
val nextSetTime1 = currentTime.plusMinutes(event.interval.toLong())
|
||||
val nextSetTime2 = currentTime.plusMinutes(_state.value.lockInterval.toLong())
|
||||
nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)!!.format(formatter)
|
||||
val homeNextSetTime = currentTime.plusMinutes(event.interval.toLong())
|
||||
val lockNextSetTime = currentTime.plusMinutes(_state.value.lockInterval.toLong())
|
||||
nextSetTime = (if (homeNextSetTime!!.isBefore(lockNextSetTime)) homeNextSetTime else lockNextSetTime)!!.format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, nextSetTime1.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, nextSetTime2.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, homeNextSetTime.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, lockNextSetTime.toString())
|
||||
}
|
||||
else {
|
||||
nextSetTime = currentTime.plusMinutes(event.interval.toLong()).format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
@@ -229,7 +308,11 @@ class SettingsViewModel @Inject constructor (
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL, event.interval)
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now()
|
||||
val currentTime = if (_state.value.changeStartTime) {
|
||||
LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second)
|
||||
} else {
|
||||
LocalDateTime.now()
|
||||
}
|
||||
val nextSetTime: String?
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
|
||||
if (_state.value.scheduleSeparately) {
|
||||
@@ -237,14 +320,14 @@ class SettingsViewModel @Inject constructor (
|
||||
val nextSetTime2 = currentTime.plusMinutes(event.interval.toLong())
|
||||
nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)!!.format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, nextSetTime1.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, nextSetTime2.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime1.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime2.toString())
|
||||
}
|
||||
else {
|
||||
nextSetTime = currentTime.plusMinutes(event.interval.toLong()).format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.plusMinutes(event.interval.toLong()).toString())
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
@@ -259,28 +342,48 @@ class SettingsViewModel @Inject constructor (
|
||||
is SettingsEvent.RefreshNextSetTime -> {
|
||||
viewModelScope.launch {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now()
|
||||
val nextSetTime: String?
|
||||
if (_state.value.scheduleSeparately) {
|
||||
val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong())
|
||||
val nextSetTime2 = currentTime.plusMinutes(_state.value.lockInterval.toLong())
|
||||
nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)!!.format(formatter)
|
||||
}
|
||||
else {
|
||||
nextSetTime = currentTime.plusMinutes(_state.value.homeInterval.toLong()).format(formatter)
|
||||
val currentTime = if (_state.value.changeStartTime) {
|
||||
var calculatedTime = LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second)
|
||||
if (calculatedTime.isBefore(LocalDateTime.now())) {
|
||||
calculatedTime = calculatedTime.plusDays(1)
|
||||
}
|
||||
calculatedTime
|
||||
} else {
|
||||
LocalDateTime.now()
|
||||
}
|
||||
val nextSetTime = when {
|
||||
_state.value.changeStartTime -> {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.toString())
|
||||
currentTime
|
||||
}
|
||||
_state.value.scheduleSeparately -> {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.homeInterval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.lockInterval.toLong()).toString())
|
||||
val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong())
|
||||
val nextSetTime2 = currentTime.plusMinutes(_state.value.lockInterval.toLong())
|
||||
if (nextSetTime1.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2
|
||||
}
|
||||
else -> {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.homeInterval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.lockInterval.toLong()).toString())
|
||||
currentTime.plusMinutes(_state.value.homeInterval.toLong())
|
||||
}
|
||||
}.format(formatter)
|
||||
_state.update {
|
||||
it.copy(
|
||||
lastSetTime = currentTime.format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
lastSetTime = LocalDateTime.now().format(formatter),
|
||||
nextSetTime = nextSetTime,
|
||||
)
|
||||
}
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, LocalDateTime.now().format(formatter))
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetHome -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.HOME_WALLPAPER, event.home)
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER, event.home)
|
||||
_state.update {
|
||||
it.copy(
|
||||
setHomeWallpaper = event.home
|
||||
@@ -291,7 +394,7 @@ class SettingsViewModel @Inject constructor (
|
||||
|
||||
is SettingsEvent.SetLock -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.LOCK_WALLPAPER, event.lock)
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER, event.lock)
|
||||
_state.update {
|
||||
it.copy(
|
||||
setLockWallpaper = event.lock
|
||||
@@ -300,17 +403,6 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetDarkenPercentage -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.DARKEN_PERCENTAGE, event.darkenPercentage)
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkenPercentage = event.darkenPercentage
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetDarken -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.DARKEN, event.darken)
|
||||
@@ -355,60 +447,442 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetBlurPercentage -> {
|
||||
is SettingsEvent.SetDarkenPercentage -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.BLUR_PERCENTAGE, event.blurPercentage)
|
||||
if (event.lockDarkenPercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.LOCK_DARKEN_PERCENTAGE, event.lockDarkenPercentage)
|
||||
}
|
||||
if (event.homeDarkenPercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.HOME_DARKEN_PERCENTAGE, event.homeDarkenPercentage)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
blurPercentage = event.blurPercentage
|
||||
homeDarkenPercentage = event.homeDarkenPercentage ?: it.homeDarkenPercentage,
|
||||
lockDarkenPercentage = event.lockDarkenPercentage ?: it.lockDarkenPercentage
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetBlurPercentage -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (event.lockBlurPercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.LOCK_BLUR_PERCENTAGE, event.lockBlurPercentage)
|
||||
}
|
||||
if (event.homeBlurPercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.HOME_BLUR_PERCENTAGE, event.homeBlurPercentage)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeBlurPercentage = event.homeBlurPercentage ?: it.homeBlurPercentage,
|
||||
lockBlurPercentage = event.lockBlurPercentage ?: it.lockBlurPercentage
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetVignette -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.VIGNETTE, event.vignette)
|
||||
_state.update {
|
||||
it.copy(
|
||||
vignette = event.vignette
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetVignettePercentage -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (event.lockVignettePercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE, event.lockVignettePercentage)
|
||||
}
|
||||
if (event.homeVignettePercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE, event.homeVignettePercentage)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeVignettePercentage = event.homeVignettePercentage ?: it.homeVignettePercentage,
|
||||
lockVignettePercentage = event.lockVignettePercentage ?: it.lockVignettePercentage
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetGrayscale -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.GRAYSCALE, event.grayscale)
|
||||
_state.update {
|
||||
it.copy(
|
||||
grayscale = event.grayscale
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetGrayscalePercentage -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (event.lockGrayscalePercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE, event.lockGrayscalePercentage)
|
||||
}
|
||||
if (event.homeGrayscalePercentage != null) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE, event.homeGrayscalePercentage)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeGrayscalePercentage = event.homeGrayscalePercentage ?: it.homeGrayscalePercentage,
|
||||
lockGrayscalePercentage = event.lockGrayscalePercentage ?: it.lockGrayscalePercentage
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetCurrentHomeWallpaper -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (event.currentHomeWallpaper != null) {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.CURRENT_HOME_WALLPAPER, event.currentHomeWallpaper)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
currentHomeWallpaper = event.currentHomeWallpaper
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetCurrentLockWallpaper -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (event.currentLockWallpaper != null) {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.CURRENT_LOCK_WALLPAPER, event.currentLockWallpaper)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
currentLockWallpaper = event.currentLockWallpaper
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetCurrentWallpaper -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (event.currentLockWallpaper != null) {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.CURRENT_LOCK_WALLPAPER, event.currentLockWallpaper)
|
||||
}
|
||||
if (event.currentHomeWallpaper != null) {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.CURRENT_HOME_WALLPAPER, event.currentHomeWallpaper)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
currentLockWallpaper = event.currentLockWallpaper ?: it.currentLockWallpaper,
|
||||
currentHomeWallpaper = event.currentHomeWallpaper ?: it.currentHomeWallpaper
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetAlbumName -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (event.homeAlbumName != null) {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_ALBUM_NAME, event.homeAlbumName)
|
||||
}
|
||||
if (event.lockAlbumName != null) {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_ALBUM_NAME, event.lockAlbumName)
|
||||
}
|
||||
val enableChanger: Boolean = when {
|
||||
event.homeAlbumName != null && event.lockAlbumName != null -> { true }
|
||||
event.homeAlbumName != null && !_state.value.lockAlbumName.isNullOrEmpty() -> { true }
|
||||
event.lockAlbumName != null && !_state.value.homeAlbumName.isNullOrEmpty() -> { true }
|
||||
else -> { false }
|
||||
}
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, enableChanger)
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeAlbumName = event.homeAlbumName ?: it.homeAlbumName,
|
||||
lockAlbumName = event.lockAlbumName ?: it.lockAlbumName,
|
||||
enableChanger = enableChanger
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.RemoveSelectedAlbumAsType -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (_state.value.setLockWallpaper && _state.value.setHomeWallpaper) {
|
||||
if (event.removeLock) {
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME)
|
||||
}
|
||||
if (event.removeHome) {
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.HOME_ALBUM_NAME)
|
||||
}
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_LOCK_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_HOME_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LAST_SET_TIME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME)
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeAlbumName = if (event.removeHome) null else it.homeAlbumName,
|
||||
lockAlbumName = if (event.removeLock) null else it.lockAlbumName,
|
||||
currentHomeWallpaper = null,
|
||||
currentLockWallpaper = null,
|
||||
nextHomeWallpaper = null,
|
||||
nextLockWallpaper = null,
|
||||
enableChanger = false,
|
||||
lastSetTime = null,
|
||||
nextSetTime = null
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (event.removeLock) {
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_LOCK_WALLPAPER)
|
||||
}
|
||||
if (event.removeHome) {
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.HOME_ALBUM_NAME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_HOME_WALLPAPER)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeAlbumName = if (event.removeHome) null else it.homeAlbumName,
|
||||
lockAlbumName = if (event.removeLock) null else it.lockAlbumName,
|
||||
currentHomeWallpaper = if (event.removeHome) null else it.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (event.removeLock) null else it.currentLockWallpaper,
|
||||
enableChanger = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.RemoveSelectedAlbumAsName -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
var enableChanger = _state.value.enableChanger
|
||||
if (event.albumName == _state.value.lockAlbumName) {
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_LOCK_WALLPAPER)
|
||||
enableChanger = false
|
||||
}
|
||||
if (event.albumName == _state.value.homeAlbumName) {
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.HOME_ALBUM_NAME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_HOME_WALLPAPER)
|
||||
enableChanger = false
|
||||
}
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, enableChanger)
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeAlbumName = if (event.albumName == _state.value.homeAlbumName) null else it.homeAlbumName,
|
||||
lockAlbumName = if (event.albumName == _state.value.lockAlbumName) null else it.lockAlbumName,
|
||||
currentHomeWallpaper = if (event.albumName == _state.value.homeAlbumName) null else it.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (event.albumName == _state.value.lockAlbumName) null else it.currentLockWallpaper,
|
||||
enableChanger = enableChanger
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetNextHomeWallpaper -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
event.nextHomeWallpaper?.let {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_HOME_WALLPAPER, it)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
nextHomeWallpaper = event.nextHomeWallpaper
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetNextLockWallpaper -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
event.nextLockWallpaper?.let {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_LOCK_WALLPAPER, it)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
nextLockWallpaper = event.nextLockWallpaper
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetNextWallpaper -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (event.nextHomeWallpaper != null) {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_HOME_WALLPAPER, event.nextHomeWallpaper)
|
||||
}
|
||||
if (event.nextLockWallpaper != null) {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_LOCK_WALLPAPER, event.nextLockWallpaper)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
nextHomeWallpaper = event.nextHomeWallpaper ?: it.nextHomeWallpaper,
|
||||
nextLockWallpaper = event.nextLockWallpaper ?: it.nextLockWallpaper
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.RefreshNextWallpaper -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val nextHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_HOME_WALLPAPER) }
|
||||
val nextLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_LOCK_WALLPAPER) }
|
||||
_state.update {
|
||||
it.copy(
|
||||
nextHomeWallpaper = nextHomeWallpaper.await(),
|
||||
nextLockWallpaper = nextLockWallpaper.await(),
|
||||
currentHomeWallpaper = nextHomeWallpaper.await(),
|
||||
currentLockWallpaper = nextLockWallpaper.await()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetChangeStartTime -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = if (event.changeStartTime) {
|
||||
LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second).let {
|
||||
if (it.isBefore(LocalDateTime.now())) it.plusDays(1) else it
|
||||
}
|
||||
} else {
|
||||
LocalDateTime.now()
|
||||
}
|
||||
val nextSetTime = when {
|
||||
event.changeStartTime -> {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.toString())
|
||||
currentTime.format(formatter)
|
||||
}
|
||||
_state.value.scheduleSeparately -> {
|
||||
val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong())
|
||||
val nextSetTime2 = currentTime.plusMinutes(_state.value.lockInterval.toLong())
|
||||
val nextSetTime = if (nextSetTime1.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime1.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime2.toString())
|
||||
nextSetTime.format(formatter)
|
||||
}
|
||||
else -> {
|
||||
val nextSetTime = currentTime.plusMinutes(_state.value.homeInterval.toLong())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime.toString())
|
||||
nextSetTime.format(formatter)
|
||||
}
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
changeStartTime = event.changeStartTime,
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
}
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.CHANGE_START_TIME, event.changeStartTime)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetStartTime -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now().withHour(event.hour).withMinute(event.minute).let {
|
||||
if (it.isBefore(LocalDateTime.now())) it.plusDays(1) else it
|
||||
}
|
||||
val nextSetTime = currentTime.format(formatter)
|
||||
_state.update {
|
||||
it.copy(
|
||||
startTime = Pair(event.hour, event.minute),
|
||||
changeStartTime = true,
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
}
|
||||
settingsDataStoreImpl.run {
|
||||
putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.toString())
|
||||
putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.toString())
|
||||
putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
putInt(SettingsConstants.START_HOUR, event.hour)
|
||||
putInt(SettingsConstants.START_MINUTE, event.minute)
|
||||
putBoolean(SettingsConstants.CHANGE_START_TIME, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.Reset -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARK_MODE_TYPE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.AMOLED_THEME_TYPE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DYNAMIC_THEME_TYPE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.FIRST_LAUNCH)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LAST_SET_TIME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ANIMATE_TYPE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ENABLE_CHANGER)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.DARKEN_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_DARKEN_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_DARKEN_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARKEN)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.WALLPAPER_SCALING)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.HOME_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.LOCK_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_HOME_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_LOCK_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.HOME_ALBUM_NAME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.SCHEDULE_SEPARATELY)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.BLUR)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.BLUR_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_BLUR_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_BLUR_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.FIRST_SET)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME_1)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME_2)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.HOME_NEXT_SET_TIME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_NEXT_SET_TIME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_HOME_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_LOCK_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.VIGNETTE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.GRAYSCALE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.CHANGE_START_TIME)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.START_HOUR)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.START_MINUTE)
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = null,
|
||||
amoledTheme = false,
|
||||
dynamicTheming = false,
|
||||
firstLaunch = true,
|
||||
lastSetTime = null,
|
||||
nextSetTime = null,
|
||||
animate = true,
|
||||
enableChanger = true,
|
||||
darkenPercentage = 100,
|
||||
enableChanger = false,
|
||||
homeDarkenPercentage = 100,
|
||||
lockDarkenPercentage = 100,
|
||||
homeBlurPercentage = 0,
|
||||
lockBlurPercentage = 0,
|
||||
darken = false,
|
||||
wallpaperScaling = ScalingConstants.FILL,
|
||||
setHomeWallpaper = false,
|
||||
setLockWallpaper = false,
|
||||
currentHomeWallpaper = null,
|
||||
currentLockWallpaper = null,
|
||||
lockInterval = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
homeInterval = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
homeAlbumName = null,
|
||||
lockAlbumName = null,
|
||||
scheduleSeparately = false,
|
||||
blur = false,
|
||||
blurPercentage = 0,
|
||||
firstSet = true
|
||||
nextHomeWallpaper = null,
|
||||
nextLockWallpaper = null,
|
||||
vignette = false,
|
||||
homeVignettePercentage = 0,
|
||||
lockVignettePercentage = 0,
|
||||
grayscale = false,
|
||||
homeGrayscalePercentage = 0,
|
||||
lockGrayscalePercentage = 0,
|
||||
changeStartTime = false,
|
||||
startTime = Pair(0, 0)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.DarkMode
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* AMOLED list item to enable AMOLED mode
|
||||
*/
|
||||
@Composable
|
||||
fun AmoledListItem(amoledMode: Boolean, onAmoledClick: (Boolean) -> Unit) {
|
||||
val context = LocalContext.current
|
||||
Row {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.clickable { onAmoledClick(!amoledMode) },
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.amoled_mode),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.full_dark_mode),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {
|
||||
Switch(
|
||||
modifier = Modifier.semantics { contentDescription = context.getString(R.string.amoled_mode) },
|
||||
checked = amoledMode,
|
||||
onCheckedChange = onAmoledClick,
|
||||
enabled = true
|
||||
) },
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.Filled.DarkMode,
|
||||
contentDescription = stringResource(R.string.amoled_mode),
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
) },
|
||||
tonalElevation = 5.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -15,7 +15,6 @@ import androidx.compose.material.icons.outlined.Brightness6
|
||||
import androidx.compose.material.icons.outlined.BrightnessAuto
|
||||
import androidx.compose.material.icons.outlined.DarkMode
|
||||
import androidx.compose.material.icons.outlined.LightMode
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -38,7 +37,6 @@ import com.anthonyla.paperize.R
|
||||
/**
|
||||
* Three-state selector for dark mode in settings
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun DarkModeListItem(darkMode: Boolean?, onDarkModeClick: (Boolean?) -> Unit) {
|
||||
val options = listOf(
|
||||
@@ -77,7 +75,7 @@ fun DarkModeListItem(darkMode: Boolean?, onDarkModeClick: (Boolean?) -> Unit) {
|
||||
},
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.dark_mode),
|
||||
text = stringResource(R.string.theme),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
|
||||
) },
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Notifications
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Notification list item to send to the notification permission page
|
||||
*/
|
||||
@Composable
|
||||
fun NotificationListItem(onClick: () -> Unit) {
|
||||
Row {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.clickable { onClick() },
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.notifications),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.change_notification_settings),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {},
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.Outlined.Notifications,
|
||||
contentDescription = stringResource(R.string.notifications),
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
) },
|
||||
tonalElevation = 5.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
+16
-20
@@ -36,13 +36,13 @@ import com.anthonyla.paperize.R
|
||||
* List item for app version and link to GitHub and PlayStore
|
||||
*/
|
||||
@Composable
|
||||
fun PaperizeListItem(onGitHubClick: () -> Unit, onPlaystoreClick: () -> Unit, onFdroidClick: () -> Unit) {
|
||||
fun PaperizeListItem(onGitHubClick: () -> Unit, onIzzyOnDroidClick: () -> Unit, onFdroidClick: () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
var version = ""
|
||||
try {
|
||||
val pInfo: PackageInfo =
|
||||
context.packageManager.getPackageInfo(context.packageName, 0)
|
||||
version = pInfo.versionName
|
||||
version = pInfo.versionName.toString()
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
@@ -106,25 +106,7 @@ fun PaperizeListItem(onGitHubClick: () -> Unit, onPlaystoreClick: () -> Unit, on
|
||||
tint = MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
IconButton(
|
||||
onClick = onPlaystoreClick,
|
||||
modifier = Modifier
|
||||
.size(60.dp)
|
||||
.background(MaterialTheme.colorScheme.primary, CircleShape)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(id = R.drawable.google_play),
|
||||
contentDescription = "Playstore",
|
||||
modifier = Modifier.size(12.dp),
|
||||
tint = MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
IconButton(
|
||||
onClick = onFdroidClick,
|
||||
modifier = Modifier
|
||||
@@ -138,6 +120,20 @@ fun PaperizeListItem(onGitHubClick: () -> Unit, onPlaystoreClick: () -> Unit, on
|
||||
tint = MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
IconButton(
|
||||
onClick = onIzzyOnDroidClick,
|
||||
modifier = Modifier
|
||||
.size(60.dp)
|
||||
.background(MaterialTheme.colorScheme.primary, CircleShape)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(id = R.drawable.izzyondroid),
|
||||
contentDescription = "Izzy-On-Droid-Droid",
|
||||
modifier = Modifier.size(32.dp),
|
||||
tint = MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-185
@@ -1,185 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Snackbar
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.data.Contact
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* Scrollable settings screen to wrap all settings components
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SettingsScrollableSettings(
|
||||
settingsState: StateFlow<SettingsState>,
|
||||
largeTopAppBarHeightPx: Dp,
|
||||
scroll: ScrollState,
|
||||
onDynamicThemingClick: (Boolean) -> Unit,
|
||||
onDarkModeClick: (Boolean?) -> Unit,
|
||||
onAnimateClick: (Boolean) -> Unit,
|
||||
onPrivacyClick: () -> Unit,
|
||||
onLicenseClick: () -> Unit,
|
||||
onResetClick: () -> Unit,
|
||||
onBackClick: () -> Unit
|
||||
) {
|
||||
val state = settingsState.collectAsStateWithLifecycle()
|
||||
val context = LocalContext.current
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
var toContact by rememberSaveable { mutableStateOf(false) }
|
||||
if (toContact) {
|
||||
Contact(context)
|
||||
toContact = false
|
||||
}
|
||||
|
||||
val translateLink = "https://crowdin.com/project/paperize/invite?h=d8d7a7513d2beb0c96ba9b2a5f85473e2084922"
|
||||
val githubLink = "https://github.com/Anthonyy232/Paperize"
|
||||
val playstoreLink = "https://play.google.com/store/apps/details?id=com.anthonyla.paperize"
|
||||
val fdroidLink = ""
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = {
|
||||
SnackbarHost(
|
||||
hostState = snackbarHostState,
|
||||
snackbar = { data ->
|
||||
Snackbar(
|
||||
snackbarData = data,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 16.dp, vertical = 24.dp)),
|
||||
shape = RoundedCornerShape(24.dp)
|
||||
)
|
||||
}
|
||||
) },
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
content = { it
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.verticalScroll(scroll)
|
||||
.padding(horizontal = 24.dp),
|
||||
) {
|
||||
Spacer(Modifier.height(largeTopAppBarHeightPx))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ListSectionTitle(stringResource(R.string.appearance))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
DarkModeListItem(
|
||||
darkMode = state.value.darkMode,
|
||||
onDarkModeClick = { onDarkModeClick(it) }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
DynamicThemingListItem(
|
||||
dynamicTheming = state.value.dynamicTheming,
|
||||
onDynamicThemingClick = { onDynamicThemingClick(it) }
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
AnimationListItem(
|
||||
animate = state.value.animate,
|
||||
onAnimateClick = { onAnimateClick(it) }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ListSectionTitle(stringResource(R.string.about))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
TranslateListItem(
|
||||
onClick = {
|
||||
val openURL = Intent(Intent.ACTION_VIEW)
|
||||
openURL.data = Uri.parse(translateLink)
|
||||
context.startActivity(openURL)
|
||||
}
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PrivacyPolicyListItem (onPrivacyPolicyClick = onPrivacyClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
LicenseListItem(onLicenseClick = onLicenseClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ContactListItem(onContactClick = { toContact = true })
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PaperizeListItem(
|
||||
onGitHubClick = {
|
||||
val openURL = Intent(Intent.ACTION_VIEW)
|
||||
openURL.data = Uri.parse(githubLink)
|
||||
context.startActivity(openURL)
|
||||
},
|
||||
onPlaystoreClick = {
|
||||
val openURL = Intent(Intent.ACTION_VIEW)
|
||||
openURL.data = Uri.parse(playstoreLink)
|
||||
context.startActivity(openURL)
|
||||
},
|
||||
onFdroidClick = {
|
||||
coroutineScope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
snackbarHostState.showSnackbar(
|
||||
message = context.getString(R.string.coming_soon),
|
||||
actionLabel = context.getString(R.string.dismiss),
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ResetListItem(onResetClick = onResetClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
-106
@@ -1,106 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Title for the settings screen.
|
||||
*/
|
||||
@Composable
|
||||
fun SettingsTitle(
|
||||
largeTopAppBarHeight: Dp,
|
||||
smallTopAppBarHeight: Dp,
|
||||
paddingMedium: Dp,
|
||||
scroll: ScrollState,
|
||||
topInset: Dp,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val titlePaddingStart = 16.dp
|
||||
val titlePaddingEnd = 64.dp
|
||||
val titleFontScaleStart = 1f
|
||||
val titleFontScaleEnd = 0.7f
|
||||
var titleHeightPx by remember { mutableFloatStateOf(0f) }
|
||||
var titleWidthPx by remember { mutableFloatStateOf(0f) }
|
||||
val fraction = (topInset - 74.dp) / (151.dp - 74.dp)
|
||||
val statusPadding = lerp(0.dp, 24.dp, fraction.coerceIn(0f, 1f))
|
||||
|
||||
Text(
|
||||
text = stringResource(id = R.string.settings_screen),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
fontSize = 30.sp,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
modifier = modifier
|
||||
.graphicsLayer {
|
||||
val collapseRange: Float = (largeTopAppBarHeight.toPx() - smallTopAppBarHeight.toPx())
|
||||
val collapseFraction: Float = (scroll.value / collapseRange).coerceIn(0f, 1f)
|
||||
|
||||
val scaleXY = lerp(
|
||||
titleFontScaleStart.dp,
|
||||
titleFontScaleEnd.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleExtraStartPadding = titleWidthPx.toDp() * (1 - scaleXY.value) / 2f
|
||||
|
||||
val titleYFirstInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium + statusPadding,
|
||||
largeTopAppBarHeight / 2,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleXFirstInterpolatedPoint = lerp(
|
||||
titlePaddingStart,
|
||||
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleYSecondInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight / 2,
|
||||
(smallTopAppBarHeight + statusPadding - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleXSecondInterpolatedPoint = lerp(
|
||||
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
|
||||
titlePaddingEnd - titleExtraStartPadding,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleY = lerp(
|
||||
titleYFirstInterpolatedPoint,
|
||||
titleYSecondInterpolatedPoint,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleX = lerp(
|
||||
titleXFirstInterpolatedPoint,
|
||||
titleXSecondInterpolatedPoint,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
translationY = titleY.toPx()
|
||||
translationX = titleX.toPx()
|
||||
scaleX = scaleXY.value
|
||||
scaleY = scaleXY.value
|
||||
}
|
||||
.onGloballyPositioned {
|
||||
titleHeightPx = it.size.height.toFloat()
|
||||
titleWidthPx = it.size.width.toFloat()
|
||||
}
|
||||
)
|
||||
}
|
||||
+24
-4
@@ -34,11 +34,14 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.testTagsAsResourceId
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.airbnb.lottie.compose.LottieAnimation
|
||||
@@ -50,6 +53,7 @@ import com.anthonyla.paperize.R
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
// Inspired by https://github.com/Ashinch/ReadYou
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun StartupScreen(
|
||||
onAgree: () -> Unit
|
||||
@@ -71,13 +75,20 @@ fun StartupScreen(
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.semantics {
|
||||
testTagsAsResourceId = true
|
||||
},
|
||||
snackbarHost = {
|
||||
SnackbarHost(
|
||||
hostState = snackbarHostState,
|
||||
snackbar = { data ->
|
||||
Snackbar(
|
||||
snackbarData = data,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 8.dp)),
|
||||
modifier = Modifier
|
||||
.padding(PaddingValues(horizontal = 8.dp))
|
||||
.semantics {
|
||||
testTagsAsResourceId = true
|
||||
},
|
||||
shape = RoundedCornerShape(24.dp)
|
||||
)
|
||||
}
|
||||
@@ -118,7 +129,9 @@ fun StartupScreen(
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
showToS = true
|
||||
} },
|
||||
modifier = Modifier.padding(PaddingValues(vertical = 16.dp)),
|
||||
modifier = Modifier
|
||||
.padding(PaddingValues(vertical = 16.dp))
|
||||
.testTag("paperize:privacy_notice_button"),
|
||||
) {
|
||||
Text(text = stringResource(R.string.privacy_notice), textAlign = TextAlign.Start)
|
||||
}
|
||||
@@ -127,7 +140,9 @@ fun StartupScreen(
|
||||
},
|
||||
floatingActionButton = {
|
||||
ExtendedFloatingActionButton(
|
||||
modifier = Modifier.padding(8.dp),
|
||||
modifier = Modifier
|
||||
.padding(8.dp)
|
||||
.testTag("paperize:floating_agree_button"),
|
||||
onClick = {
|
||||
if (seenToS) {
|
||||
onAgree()
|
||||
@@ -161,7 +176,11 @@ fun StartupScreen(
|
||||
if (showToS) {
|
||||
seenToS = true
|
||||
AlertDialog(
|
||||
modifier = Modifier.fillMaxHeight(0.7f),
|
||||
modifier = Modifier
|
||||
.fillMaxHeight(0.7f)
|
||||
.semantics {
|
||||
testTagsAsResourceId = true
|
||||
},
|
||||
onDismissRequest = { showToS = false },
|
||||
title = {
|
||||
Box(modifier = Modifier.fillMaxWidth()) {
|
||||
@@ -176,6 +195,7 @@ fun StartupScreen(
|
||||
confirmButton = {
|
||||
Button(
|
||||
onClick = { showToS = false },
|
||||
modifier = Modifier.testTag("paperize:dismiss_button"),
|
||||
) {
|
||||
Text(stringResource(R.string.dismiss))
|
||||
}
|
||||
|
||||
+36
-1
@@ -10,6 +10,7 @@ import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.core.view.WindowCompat
|
||||
@@ -80,6 +81,38 @@ private val DarkColors = darkColorScheme(
|
||||
scrim = md_theme_dark_scrim,
|
||||
)
|
||||
|
||||
private val AmoledDarkColors = darkColorScheme(
|
||||
primary = md_theme_light_primary,
|
||||
onPrimary = md_theme_light_onPrimary,
|
||||
primaryContainer = md_theme_light_primaryContainer,
|
||||
onPrimaryContainer = md_theme_light_onPrimaryContainer,
|
||||
secondary = Color.Black,
|
||||
onSecondary = Color.White,
|
||||
secondaryContainer = Color.Black,
|
||||
onSecondaryContainer = Color.White,
|
||||
tertiary = md_theme_light_tertiary,
|
||||
onTertiary = md_theme_light_onTertiary,
|
||||
tertiaryContainer = Color.Black,
|
||||
onTertiaryContainer = Color.White,
|
||||
error = Color.Red,
|
||||
errorContainer = Color.Black,
|
||||
onError = Color.White,
|
||||
onErrorContainer = Color.Black,
|
||||
background = Color.Black,
|
||||
onBackground = Color.White,
|
||||
surface = Color.Black,
|
||||
onSurface = Color.White,
|
||||
surfaceVariant = Color.Black,
|
||||
onSurfaceVariant = Color.White,
|
||||
outline = Color.White,
|
||||
inverseOnSurface = Color.Black,
|
||||
inverseSurface = Color.White,
|
||||
inversePrimary = Color.White,
|
||||
surfaceTint = Color.Black,
|
||||
outlineVariant = md_theme_dark_outlineVariant,
|
||||
scrim = md_theme_dark_scrim,
|
||||
)
|
||||
|
||||
|
||||
/**
|
||||
* App theming for dynamic theming when supported and dark mode.
|
||||
@@ -87,6 +120,7 @@ private val DarkColors = darkColorScheme(
|
||||
@Composable
|
||||
fun PaperizeTheme(
|
||||
darkMode: Boolean?,
|
||||
amoledMode: Boolean,
|
||||
dynamicTheming: Boolean,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
@@ -97,7 +131,8 @@ fun PaperizeTheme(
|
||||
val colors = when {
|
||||
isDynamicTheming && dynamicThemingSupported && isDarkMode -> dynamicDarkColorScheme(context)
|
||||
isDynamicTheming && dynamicThemingSupported && !isDarkMode -> dynamicLightColorScheme(context)
|
||||
isDarkMode -> DarkColors
|
||||
isDarkMode && amoledMode -> AmoledDarkColors
|
||||
isDarkMode && !amoledMode -> DarkColors
|
||||
else -> LightColors
|
||||
}
|
||||
|
||||
|
||||
+4
-7
@@ -4,11 +4,8 @@ import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperA
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
|
||||
sealed class WallpaperEvent {
|
||||
data class UpdateSelectedAlbum(
|
||||
val selectedAlbum: SelectedAlbum?,
|
||||
val album: AlbumWithWallpaperAndFolder?,
|
||||
val scheduleSeparately: Boolean = false
|
||||
): WallpaperEvent()
|
||||
object Reset : WallpaperEvent()
|
||||
object Refresh : WallpaperEvent()
|
||||
data class AddSelectedAlbum(val album: AlbumWithWallpaperAndFolder, val deleteAlbumName: String? = null): WallpaperEvent()
|
||||
data class UpdateSelectedAlbum(val album: SelectedAlbum): WallpaperEvent()
|
||||
data class Reset(val album: SelectedAlbum? = null) : WallpaperEvent()
|
||||
data object Refresh : WallpaperEvent()
|
||||
}
|
||||
+149
-216
@@ -1,14 +1,9 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.WallpaperManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
@@ -16,11 +11,13 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Snackbar
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.TimePickerState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -29,87 +26,93 @@ import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.testTagsAsResourceId
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.AlbumBottomSheet
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.BlurSwitchAndSlider
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ChangerSelectionRow
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentAndNextChange
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentSelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.DarkenSwitchAndSlider
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ShowDelayNoticeDialog
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ShowLiveWallpaperEnabledDialog
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.GrayscaleSwitchAndSlider
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.IndividualSchedulingAndToggleRow
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.TimeSliders
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.VignetteSwitchAndSlider
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.WallpaperPreviewAndScale
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun WallpaperScreen(
|
||||
albumsViewModel: AlbumsViewModel = hiltViewModel(),
|
||||
albums: List<AlbumWithWallpaperAndFolder>,
|
||||
animate: Boolean,
|
||||
darken: Boolean,
|
||||
darkenPercentage: Int,
|
||||
homeDarkenPercentage: Int,
|
||||
lockDarkenPercentage: Int,
|
||||
enableChanger: Boolean,
|
||||
homeEnabled: Boolean,
|
||||
interval1: Int,
|
||||
interval2: Int,
|
||||
homeInterval: Int,
|
||||
lockInterval: Int,
|
||||
lastSetTime: String?,
|
||||
lockEnabled: Boolean,
|
||||
nextSetTime: String?,
|
||||
currentHomeWallpaper: String?,
|
||||
currentLockWallpaper: String?,
|
||||
onDarkCheck: (Boolean) -> Unit,
|
||||
onDarkenPercentage: (Int) -> Unit,
|
||||
onDarkenPercentage: (Int, Int) -> Unit,
|
||||
onHomeCheckedChange: (Boolean) -> Unit,
|
||||
onLockCheckedChange: (Boolean) -> Unit,
|
||||
scheduleSeparately: Boolean,
|
||||
onScheduleSeparatelyChange: (Boolean) -> Unit,
|
||||
onScheduleWallpaperChanger1: (Int) -> Unit,
|
||||
onScheduleWallpaperChanger2: (Int) -> Unit,
|
||||
onScheduleWallpaperChanger: () -> Unit,
|
||||
onScalingChange: (ScalingConstants) -> Unit,
|
||||
onSelectAlbum: (AlbumWithWallpaperAndFolder) -> Unit,
|
||||
onTimeChange1: (Int) -> Unit,
|
||||
onTimeChange2: (Int) -> Unit,
|
||||
onStop: () -> Unit,
|
||||
onSelectAlbum: (AlbumWithWallpaperAndFolder, Boolean, Boolean) -> Unit,
|
||||
onHomeTimeChange: (Int) -> Unit,
|
||||
onLockTimeChange: (Int) -> Unit,
|
||||
onStop: (Boolean, Boolean) -> Unit,
|
||||
onToggleChanger: (Boolean) -> Unit,
|
||||
scaling: ScalingConstants,
|
||||
selectedAlbum: SelectedAlbum?,
|
||||
homeSelectedAlbum: SelectedAlbum?,
|
||||
lockSelectedAlbum: SelectedAlbum?,
|
||||
blur: Boolean,
|
||||
onBlurPercentageChange: (Int) -> Unit,
|
||||
onBlurPercentageChange: (Int, Int) -> Unit,
|
||||
onBlurChange: (Boolean) -> Unit,
|
||||
blurPercentage: Int,
|
||||
firstSet: Boolean
|
||||
homeBlurPercentage: Int,
|
||||
lockBlurPercentage: Int,
|
||||
homeVignettePercentage: Int,
|
||||
lockVignettePercentage: Int,
|
||||
onVignettePercentageChange: (Int, Int) -> Unit,
|
||||
onVignetteChange: (Boolean) -> Unit,
|
||||
vignette: Boolean,
|
||||
homeGrayscalePercentage: Int,
|
||||
lockGrayscalePercentage: Int,
|
||||
onGrayscalePercentageChange: (Int, Int) -> Unit,
|
||||
onGrayscaleChange: (Boolean) -> Unit,
|
||||
grayscale: Boolean,
|
||||
changeStartTime: Boolean,
|
||||
onChangeStartTimeToggle: (Boolean) -> Unit,
|
||||
onStartTimeChange: (TimePickerState) -> Unit,
|
||||
startingTime: Pair<Int, Int>
|
||||
) {
|
||||
val shouldShowScreen = homeEnabled || lockEnabled
|
||||
val shouldShowSettings = shouldShowScreen && homeSelectedAlbum != null && lockSelectedAlbum != null
|
||||
val scrollState = rememberScrollState()
|
||||
val context = LocalContext.current
|
||||
val albumState = albumsViewModel.state.collectAsStateWithLifecycle()
|
||||
var openBottomSheet by rememberSaveable { mutableStateOf(false) }
|
||||
val scope = rememberCoroutineScope()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val openLiveDialog = rememberSaveable { mutableStateOf(false) }
|
||||
val openNoticeDialog = rememberSaveable { mutableStateOf(false) }
|
||||
val showInterval = rememberSaveable { mutableStateOf(false) }
|
||||
val scrollState = rememberScrollState()
|
||||
|
||||
if (openLiveDialog.value) {
|
||||
ShowLiveWallpaperEnabledDialog(
|
||||
onDismissRequest = { openLiveDialog.value = false }
|
||||
)
|
||||
}
|
||||
if (openNoticeDialog.value) {
|
||||
ShowDelayNoticeDialog(
|
||||
onDismissRequest = {
|
||||
openNoticeDialog.value = false
|
||||
openBottomSheet = true
|
||||
}
|
||||
)
|
||||
}
|
||||
val lock = rememberSaveable { mutableStateOf(false) }
|
||||
val home = rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = {
|
||||
@@ -123,13 +126,15 @@ fun WallpaperScreen(
|
||||
)
|
||||
}
|
||||
) },
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.semantics { testTagsAsResourceId = true },
|
||||
content = { padding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.verticalScroll(scrollState)
|
||||
.fillMaxSize()
|
||||
.padding(8.dp)
|
||||
.verticalScroll(scrollState),
|
||||
.padding(8.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
ChangerSelectionRow(
|
||||
@@ -138,21 +143,40 @@ fun WallpaperScreen(
|
||||
onHomeCheckedChange = onHomeCheckedChange,
|
||||
onLockCheckedChange = onLockCheckedChange
|
||||
)
|
||||
if (homeEnabled && lockEnabled) {
|
||||
IndividualSchedulingAndToggleRow(
|
||||
animate = animate,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
enableChanger = enableChanger,
|
||||
onToggleChanger = onToggleChanger,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange
|
||||
)
|
||||
}
|
||||
if (homeEnabled || lockEnabled) {
|
||||
CurrentSelectedAlbum(
|
||||
selectedAlbum = selectedAlbum,
|
||||
onOpenBottomSheet = {
|
||||
if (albumState.value.albumsWithWallpapers.firstOrNull() != null) {
|
||||
if (isLiveWallpaperSet(context)) {
|
||||
openLiveDialog.value = true
|
||||
} else {
|
||||
if (firstSet) {
|
||||
openNoticeDialog.value = true
|
||||
}
|
||||
else {
|
||||
openBottomSheet = true
|
||||
}
|
||||
homeSelectedAlbum = homeSelectedAlbum,
|
||||
lockSelectedAlbum = lockSelectedAlbum,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
animate = animate,
|
||||
enableChanger = enableChanger,
|
||||
onToggleChanger = {
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
if (!it) {
|
||||
snackbarHostState.showSnackbar(
|
||||
message = context.getString(R.string.wallpaper_changer_has_been_disabled),
|
||||
actionLabel = context.getString(R.string.dismiss),
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
}
|
||||
}
|
||||
onToggleChanger(it)
|
||||
},
|
||||
onOpenBottomSheet = { changeLock, changeHome ->
|
||||
if (albums.firstOrNull() != null) {
|
||||
openBottomSheet = true
|
||||
lock.value = changeLock
|
||||
home.value = changeHome
|
||||
} else {
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
@@ -164,202 +188,116 @@ fun WallpaperScreen(
|
||||
}
|
||||
}
|
||||
},
|
||||
onStop = {
|
||||
if (selectedAlbum != null) {
|
||||
onStop = { lock, home ->
|
||||
if (homeSelectedAlbum != null || lockSelectedAlbum != null) {
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
snackbarHostState.showSnackbar(
|
||||
message = context.getString(
|
||||
R.string.has_been_unselected,
|
||||
selectedAlbum.album.displayedAlbumName
|
||||
when {
|
||||
home && lock -> homeSelectedAlbum?.album?.displayedAlbumName ?: ""
|
||||
home -> homeSelectedAlbum?.album?.displayedAlbumName ?: ""
|
||||
lock -> lockSelectedAlbum?.album?.displayedAlbumName ?: ""
|
||||
else -> ""
|
||||
}
|
||||
),
|
||||
actionLabel = context.getString(R.string.dismiss),
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
}
|
||||
onStop()
|
||||
onStop(lock, home)
|
||||
}
|
||||
},
|
||||
animate = animate,
|
||||
enableChanger = enableChanger,
|
||||
onToggleChanger = {
|
||||
if (!it) {
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
snackbarHostState.showSnackbar(
|
||||
message = context.getString(R.string.wallpaper_changer_has_been_disabled),
|
||||
actionLabel = context.getString(R.string.dismiss),
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
}
|
||||
}
|
||||
onToggleChanger(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
CurrentAndNextChange(lastSetTime, nextSetTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
CurrentAndNextChange(lastSetTime, nextSetTime)
|
||||
}
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
WallpaperPreviewAndScale(
|
||||
currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = selectedAlbum.album.currentLockWallpaper,
|
||||
animate = true,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
scaling = scaling,
|
||||
onScalingChange = onScalingChange,
|
||||
homeEnabled = homeEnabled,
|
||||
lockEnabled = lockEnabled,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
if (shouldShowSettings) {
|
||||
WallpaperPreviewAndScale(
|
||||
currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = selectedAlbum.album.currentLockWallpaper,
|
||||
animate = false,
|
||||
currentHomeWallpaper = currentHomeWallpaper,
|
||||
currentLockWallpaper = currentLockWallpaper,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
homeDarkenPercentage = homeDarkenPercentage,
|
||||
lockDarkenPercentage = lockDarkenPercentage,
|
||||
scaling = scaling,
|
||||
onScalingChange = onScalingChange,
|
||||
homeEnabled = homeEnabled,
|
||||
lockEnabled = lockEnabled,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage
|
||||
homeBlurPercentage = homeBlurPercentage,
|
||||
lockBlurPercentage = lockBlurPercentage,
|
||||
vignette = vignette,
|
||||
homeVignettePercentage = homeVignettePercentage,
|
||||
lockVignettePercentage = lockVignettePercentage,
|
||||
grayscale = grayscale,
|
||||
homeGrayscalePercentage = homeGrayscalePercentage,
|
||||
lockGrayscalePercentage = lockGrayscalePercentage
|
||||
)
|
||||
}
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
CurrentAndNextChange(lastSetTime, nextSetTime)
|
||||
TimeSliders(
|
||||
timeInMinutes1 = interval1,
|
||||
timeInMinutes2 = interval2,
|
||||
onTimeChange1 = { days, hours, minutes ->
|
||||
homeInterval = homeInterval,
|
||||
lockInterval = lockInterval,
|
||||
onHomeIntervalChange = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
onTimeChange1(totalMinutes)
|
||||
onHomeTimeChange(totalMinutes)
|
||||
},
|
||||
onTimeChange2 = { days, hours, minutes ->
|
||||
onLockIntervalChange = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
onTimeChange2(totalMinutes)
|
||||
onLockTimeChange(totalMinutes)
|
||||
},
|
||||
showInterval = showInterval.value,
|
||||
animate = true,
|
||||
animate = animate,
|
||||
onShowIntervalChange = { showInterval.value = it },
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
|
||||
lockEnabled = lockEnabled,
|
||||
homeEnabled = homeEnabled
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
TimeSliders(
|
||||
timeInMinutes1 = interval1,
|
||||
timeInMinutes2 = interval2,
|
||||
onTimeChange1 = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
onScheduleWallpaperChanger1(totalMinutes)
|
||||
},
|
||||
onTimeChange2 = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
onScheduleWallpaperChanger2(totalMinutes)
|
||||
},
|
||||
showInterval = showInterval.value,
|
||||
animate = false,
|
||||
onShowIntervalChange = { showInterval.value = it },
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
|
||||
lockEnabled = lockEnabled,
|
||||
homeEnabled = homeEnabled,
|
||||
onStartTimeChange = onStartTimeChange,
|
||||
changeStartTime = changeStartTime,
|
||||
startingTime = startingTime,
|
||||
onChangeStartTimeToggle = onChangeStartTimeToggle
|
||||
)
|
||||
}
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
DarkenSwitchAndSlider(
|
||||
onDarkCheck = onDarkCheck,
|
||||
darken = darken,
|
||||
onDarkenChange = onDarkenPercentage,
|
||||
darkenPercentage = darkenPercentage,
|
||||
animate = true
|
||||
homeDarkenPercentage = homeDarkenPercentage,
|
||||
lockDarkenPercentage = lockDarkenPercentage,
|
||||
animate = animate,
|
||||
bothEnabled = homeEnabled && lockEnabled
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
DarkenSwitchAndSlider(
|
||||
onDarkCheck = onDarkCheck,
|
||||
darken = darken,
|
||||
onDarkenChange = onDarkenPercentage,
|
||||
darkenPercentage = darkenPercentage,
|
||||
animate = false
|
||||
)
|
||||
}
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = ((homeEnabled || lockEnabled)) && selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
BlurSwitchAndSlider(
|
||||
onBlurPercentageChange = onBlurPercentageChange,
|
||||
onBlurChange = onBlurChange,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage,
|
||||
animate = true
|
||||
homeBlurPercentage = homeBlurPercentage,
|
||||
lockBlurPercentage = lockBlurPercentage,
|
||||
animate = animate,
|
||||
bothEnabled = homeEnabled && lockEnabled
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (((homeEnabled || lockEnabled)) && selectedAlbum != null) {
|
||||
BlurSwitchAndSlider(
|
||||
onBlurPercentageChange = onBlurPercentageChange,
|
||||
onBlurChange = onBlurChange,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage,
|
||||
animate = false
|
||||
VignetteSwitchAndSlider(
|
||||
onVignettePercentageChange = onVignettePercentageChange,
|
||||
onVignetteChange = onVignetteChange,
|
||||
vignette = vignette,
|
||||
homeVignettePercentage = homeVignettePercentage,
|
||||
lockVignettePercentage = lockVignettePercentage,
|
||||
animate = animate,
|
||||
bothEnabled = homeEnabled && lockEnabled
|
||||
)
|
||||
GrayscaleSwitchAndSlider(
|
||||
onGrayscalePercentageChange = onGrayscalePercentageChange,
|
||||
onGrayscaleChange = onGrayscaleChange,
|
||||
grayscale = grayscale,
|
||||
homeGrayscalePercentage = homeGrayscalePercentage,
|
||||
lockGrayscalePercentage = lockGrayscalePercentage,
|
||||
animate = animate,
|
||||
bothEnabled = homeEnabled && lockEnabled
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (((homeEnabled || lockEnabled)) && openBottomSheet) {
|
||||
if (shouldShowScreen && openBottomSheet) {
|
||||
AlbumBottomSheet(
|
||||
albums = albumState.value.albumsWithWallpapers,
|
||||
currentSelectedAlbum = selectedAlbum,
|
||||
albums = albums,
|
||||
homeSelectedAlbum = homeSelectedAlbum,
|
||||
lockSelectedAlbum = lockSelectedAlbum,
|
||||
onDismiss = { openBottomSheet = false },
|
||||
onSelect = { album ->
|
||||
openBottomSheet = false
|
||||
@@ -372,13 +310,13 @@ fun WallpaperScreen(
|
||||
}
|
||||
}
|
||||
else {
|
||||
onSelectAlbum(album)
|
||||
onScheduleWallpaperChanger1(interval1)
|
||||
onSelectAlbum(album, lock.value, home.value)
|
||||
onScheduleWallpaperChanger()
|
||||
}
|
||||
}
|
||||
else {
|
||||
onSelectAlbum(album)
|
||||
onScheduleWallpaperChanger1(interval1)
|
||||
onSelectAlbum(album, lock.value, home.value)
|
||||
onScheduleWallpaperChanger()
|
||||
}
|
||||
},
|
||||
animate = animate
|
||||
@@ -386,9 +324,4 @@ fun WallpaperScreen(
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fun isLiveWallpaperSet(context: Context): Boolean {
|
||||
val wallpaperManager = WallpaperManager.getInstance(context)
|
||||
return wallpaperManager.wallpaperInfo != null
|
||||
}
|
||||
+58
-40
@@ -31,7 +31,7 @@ class WallpaperScreenViewModel @Inject constructor (
|
||||
repository.getSelectedAlbum().collect { selectedAlbum ->
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedAlbum = selectedAlbum.firstOrNull(),
|
||||
selectedAlbum = selectedAlbum,
|
||||
isDataLoaded = true
|
||||
)
|
||||
}
|
||||
@@ -41,43 +41,51 @@ class WallpaperScreenViewModel @Inject constructor (
|
||||
|
||||
fun onEvent(event: WallpaperEvent) {
|
||||
when (event) {
|
||||
is WallpaperEvent.AddSelectedAlbum -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val deleted = event.deleteAlbumName?.let {
|
||||
repository.cascadeDeleteAlbum(it)
|
||||
true
|
||||
} ?: false
|
||||
val wallpapers = event.album.wallpapers + event.album.folders.flatMap { folder ->
|
||||
folder.wallpapers.map { wallpaper ->
|
||||
Wallpaper(
|
||||
initialAlbumName = event.album.album.initialAlbumName,
|
||||
wallpaperUri = wallpaper,
|
||||
key = wallpaper.hashCode() + event.album.album.initialAlbumName.hashCode() + System.currentTimeMillis().toInt(),
|
||||
)
|
||||
}
|
||||
}
|
||||
val newSelectedAlbum = SelectedAlbum(
|
||||
album = event.album.album.copy(
|
||||
lockWallpapersInQueue = wallpapers.map { it.wallpaperUri }.shuffled(),
|
||||
homeWallpapersInQueue = wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
repository.upsertSelectedAlbum(newSelectedAlbum)
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedAlbum = it.selectedAlbum?.let { selectedAlbums ->
|
||||
selectedAlbums.filterNot { selectedAlbum -> deleted && selectedAlbum.album.initialAlbumName == event.deleteAlbumName } + newSelectedAlbum
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
is WallpaperEvent.UpdateSelectedAlbum -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (event.selectedAlbum != null) {
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedAlbum = event.selectedAlbum
|
||||
)
|
||||
}
|
||||
repository.upsertSelectedAlbum(event.selectedAlbum)
|
||||
}
|
||||
else if (event.album != null) {
|
||||
val wallpapers: List<Wallpaper> = event.album.wallpapers + event.album.folders.asSequence().flatMap { folder ->
|
||||
folder.wallpapers.asSequence().map { wallpaper ->
|
||||
Wallpaper(
|
||||
initialAlbumName = event.album.album.initialAlbumName,
|
||||
wallpaperUri = wallpaper,
|
||||
key = wallpaper.hashCode() + event.album.album.initialAlbumName.hashCode(),
|
||||
)
|
||||
repository.upsertSelectedAlbum(event.album)
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedAlbum = it.selectedAlbum?.map { selectedAlbum ->
|
||||
if (selectedAlbum.album.initialAlbumName == event.album.album.initialAlbumName) {
|
||||
event.album
|
||||
} else {
|
||||
selectedAlbum
|
||||
}
|
||||
}
|
||||
}.toList()
|
||||
val shuffledWallpapers1 = wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
val shuffledWallpapers2 = wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
val newSelectedAlbum = SelectedAlbum(
|
||||
album = event.album.album.copy(
|
||||
homeWallpapersInQueue = shuffledWallpapers1,
|
||||
lockWallpapersInQueue = shuffledWallpapers2,
|
||||
currentHomeWallpaper = shuffledWallpapers1.firstOrNull(),
|
||||
currentLockWallpaper = if (event.scheduleSeparately) shuffledWallpapers2.firstOrNull() else shuffledWallpapers1.firstOrNull(),
|
||||
),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedAlbum = newSelectedAlbum
|
||||
)
|
||||
}
|
||||
repository.upsertSelectedAlbum(newSelectedAlbum)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,12 +94,22 @@ class WallpaperScreenViewModel @Inject constructor (
|
||||
}
|
||||
is WallpaperEvent.Reset -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedAlbum = null
|
||||
)
|
||||
if (event.album == null) {
|
||||
repository.deleteAll()
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedAlbum = null
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
repository.cascadeDeleteAlbum(event.album.album.initialAlbumName)
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedAlbum = it.selectedAlbum?.filter { selectedAlbum -> selectedAlbum.album.initialAlbumName != event.album.album.initialAlbumName }
|
||||
)
|
||||
}
|
||||
}
|
||||
repository.deleteAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,7 +120,7 @@ class WallpaperScreenViewModel @Inject constructor (
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.getSelectedAlbum().collect { selectedAlbum ->
|
||||
_state.update { it.copy(
|
||||
selectedAlbum = selectedAlbum.firstOrNull(),
|
||||
selectedAlbum = selectedAlbum,
|
||||
) }
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,5 +4,5 @@ import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
|
||||
data class WallpaperState (
|
||||
val isDataLoaded: Boolean = false,
|
||||
val selectedAlbum: SelectedAlbum? = null
|
||||
val selectedAlbum: List<SelectedAlbum>? = null
|
||||
)
|
||||
+15
-16
@@ -49,7 +49,8 @@ import kotlinx.coroutines.launch
|
||||
@Composable
|
||||
fun AlbumBottomSheet(
|
||||
onDismiss: () -> Unit,
|
||||
currentSelectedAlbum: SelectedAlbum?,
|
||||
homeSelectedAlbum: SelectedAlbum?,
|
||||
lockSelectedAlbum: SelectedAlbum?,
|
||||
albums: List<AlbumWithWallpaperAndFolder>,
|
||||
onSelect: (AlbumWithWallpaperAndFolder) -> Unit,
|
||||
animate: Boolean
|
||||
@@ -63,7 +64,13 @@ fun AlbumBottomSheet(
|
||||
containerColor = MaterialTheme.colorScheme.background,
|
||||
tonalElevation = 5.dp,
|
||||
modifier = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
||||
Modifier.fillMaxSize().padding(bottom = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding())
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
.padding(
|
||||
bottom = WindowInsets.navigationBars
|
||||
.asPaddingValues()
|
||||
.calculateBottomPadding()
|
||||
)
|
||||
} else {
|
||||
Modifier.padding(bottom = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding())
|
||||
}
|
||||
@@ -124,20 +131,12 @@ fun AlbumBottomSheet(
|
||||
}
|
||||
},
|
||||
trailingContent = {
|
||||
if (currentSelectedAlbum != null) {
|
||||
if (currentSelectedAlbum.album.initialAlbumName == it.album.initialAlbumName) {
|
||||
Icon(
|
||||
contentDescription = stringResource(R.string.currently_selected_album),
|
||||
imageVector = Icons.Filled.RadioButtonChecked,
|
||||
)
|
||||
}
|
||||
else {
|
||||
Icon(
|
||||
contentDescription = stringResource(R.string.currently_selected_album),
|
||||
imageVector = Icons.Filled.RadioButtonUnchecked,
|
||||
)
|
||||
}
|
||||
}
|
||||
val isSelected = (homeSelectedAlbum?.album?.initialAlbumName == it.album.initialAlbumName) ||
|
||||
(lockSelectedAlbum?.album?.displayedAlbumName == it.album.displayedAlbumName)
|
||||
Icon(
|
||||
contentDescription = if (isSelected) stringResource(R.string.currently_selected_album) else stringResource(R.string.unselected_album),
|
||||
imageVector = if (isSelected) Icons.Filled.RadioButtonChecked else Icons.Filled.RadioButtonUnchecked,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
+97
-20
@@ -47,16 +47,19 @@ import kotlin.math.roundToInt
|
||||
*/
|
||||
@Composable
|
||||
fun BlurSwitchAndSlider(
|
||||
onBlurPercentageChange: (Int) -> Unit,
|
||||
onBlurPercentageChange: (Int, Int) -> Unit,
|
||||
onBlurChange: (Boolean) -> Unit,
|
||||
blur: Boolean,
|
||||
blurPercentage: Int,
|
||||
bothEnabled: Boolean,
|
||||
homeBlurPercentage: Int,
|
||||
lockBlurPercentage: Int,
|
||||
animate: Boolean
|
||||
) {
|
||||
val view = LocalView.current
|
||||
val scope = rememberCoroutineScope()
|
||||
var job by remember { mutableStateOf<Job?>(null) }
|
||||
var percentage by rememberSaveable { mutableFloatStateOf(blurPercentage.toFloat()) }
|
||||
var homePercentage by rememberSaveable { mutableFloatStateOf(homeBlurPercentage.toFloat()) }
|
||||
var lockPercentage by rememberSaveable { mutableFloatStateOf(lockBlurPercentage.toFloat()) }
|
||||
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
@@ -94,54 +97,128 @@ fun BlurSwitchAndSlider(
|
||||
easing = LinearOutSlowInEasing
|
||||
)
|
||||
)
|
||||
) {
|
||||
) {
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, percentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
if (bothEnabled) {
|
||||
Text(
|
||||
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
else {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
Slider(
|
||||
value = percentage,
|
||||
value = homePercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
percentage = it
|
||||
homePercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onBlurPercentageChange(it.roundToInt())
|
||||
if (bothEnabled) {
|
||||
onBlurPercentageChange(it.roundToInt(), lockPercentage.roundToInt())
|
||||
} else {
|
||||
onBlurPercentageChange(it.roundToInt(), it.roundToInt())
|
||||
}
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
if (bothEnabled) {
|
||||
Text(
|
||||
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Slider(
|
||||
value = lockPercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
lockPercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onBlurPercentageChange(homePercentage.roundToInt(), it.roundToInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (blur) {
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, percentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
if (bothEnabled) {
|
||||
Text(
|
||||
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
else {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
Slider(
|
||||
value = percentage,
|
||||
value = homePercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
percentage = it
|
||||
homePercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onBlurPercentageChange(it.roundToInt())
|
||||
if (bothEnabled) {
|
||||
onBlurPercentageChange(it.roundToInt(), lockPercentage.roundToInt())
|
||||
} else {
|
||||
onBlurPercentageChange(it.roundToInt(), it.roundToInt())
|
||||
}
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
if (bothEnabled) {
|
||||
Text(
|
||||
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Slider(
|
||||
value = lockPercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
lockPercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onBlurPercentageChange(homePercentage.roundToInt(), it.roundToInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
|
||||
+12
-9
@@ -9,6 +9,7 @@ import androidx.compose.material3.SegmentedButtonDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
@@ -23,21 +24,23 @@ fun ChangerSelectionRow(
|
||||
MultiChoiceSegmentedButtonRow (
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(start = 16.dp, end = 16.dp,))
|
||||
.padding(PaddingValues(start = 16.dp, end = 16.dp))
|
||||
) {
|
||||
SegmentedButton(
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 0, count = 2),
|
||||
onCheckedChange = onHomeCheckedChange,
|
||||
checked = homeEnabled
|
||||
) {
|
||||
Text(text = stringResource(R.string.home_screen_btn))
|
||||
}
|
||||
SegmentedButton(
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 1, count = 2),
|
||||
onCheckedChange = onLockCheckedChange,
|
||||
checked = lockEnabled
|
||||
checked = lockEnabled,
|
||||
modifier = Modifier.testTag("paperize:lock_button"),
|
||||
) {
|
||||
Text(stringResource(R.string.lock_screen_btn))
|
||||
}
|
||||
SegmentedButton(
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 1, count = 2),
|
||||
onCheckedChange = onHomeCheckedChange,
|
||||
checked = homeEnabled,
|
||||
modifier = Modifier.testTag("paperize:home_button"),
|
||||
) {
|
||||
Text(text = stringResource(R.string.home_screen_btn))
|
||||
}
|
||||
}
|
||||
}
|
||||
+246
-83
@@ -5,8 +5,10 @@ import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
@@ -46,11 +48,13 @@ import com.skydoves.landscapist.glide.GlideImage
|
||||
*/
|
||||
@Composable
|
||||
fun CurrentSelectedAlbum(
|
||||
selectedAlbum: SelectedAlbum?,
|
||||
homeSelectedAlbum: SelectedAlbum?,
|
||||
lockSelectedAlbum: SelectedAlbum?,
|
||||
scheduleSeparately: Boolean,
|
||||
enableChanger: Boolean,
|
||||
onOpenBottomSheet: () -> Unit,
|
||||
onStop: () -> Unit,
|
||||
animate: Boolean,
|
||||
onOpenBottomSheet: (Boolean, Boolean) -> Unit, // lock, home
|
||||
onStop: (Boolean, Boolean) -> Unit,
|
||||
onToggleChanger: (Boolean) -> Unit
|
||||
) {
|
||||
fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
@@ -64,94 +68,253 @@ fun CurrentSelectedAlbum(
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
|
||||
val showCoverUri = isValidUri(LocalContext.current, selectedAlbum?.album?.coverUri)
|
||||
val showHomeCoverUri = isValidUri(LocalContext.current, homeSelectedAlbum?.album?.coverUri)
|
||||
val showLockCoverUri = isValidUri(LocalContext.current, lockSelectedAlbum?.album?.coverUri)
|
||||
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.padding(PaddingValues(vertical = 8.dp, horizontal = 16.dp))
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.clickable {
|
||||
if (selectedAlbum != null) {
|
||||
onToggleChanger(!enableChanger)
|
||||
} else {
|
||||
onOpenBottomSheet()
|
||||
}
|
||||
},
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = selectedAlbum?.album?.displayedAlbumName ?: stringResource(R.string.no_album_selected),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
) },
|
||||
supportingContent = {
|
||||
if (selectedAlbum != null) {
|
||||
if (scheduleSeparately) {
|
||||
Row {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.padding(PaddingValues(top = 8.dp, bottom = 8.dp, start = 16.dp, end = 8.dp))
|
||||
.weight(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.clickable { onOpenBottomSheet(true, false) },
|
||||
headlineContent = {
|
||||
Row(modifier = Modifier.fillMaxSize(), horizontalArrangement = Arrangement.SpaceBetween) {
|
||||
Box (modifier = Modifier.weight(1f)) {
|
||||
if (lockSelectedAlbum != null) {
|
||||
IconButton(
|
||||
onClick = { onStop(true, false) }
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Stop,
|
||||
contentDescription = stringResource(R.string.stop_the_album)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.size(8.dp))
|
||||
Box (modifier = Modifier.weight(1f)) {
|
||||
IconButton(
|
||||
onClick = { onOpenBottomSheet(true, false) }
|
||||
) {
|
||||
Icon(
|
||||
contentDescription = stringResource(R.string.click_to_select_a_different_album),
|
||||
imageVector = Icons.Filled.ArrowDropDown,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
supportingContent = {},
|
||||
leadingContent = {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) {
|
||||
Box(modifier = Modifier.size(48.dp)) {
|
||||
if (lockSelectedAlbum != null) {
|
||||
if (showLockCoverUri) {
|
||||
GlideImage(
|
||||
imageModel = { lockSelectedAlbum.album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(150, 150),
|
||||
),
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.align(
|
||||
Alignment.Center
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Image(
|
||||
imageVector = Icons.Default.RadioButtonUnchecked,
|
||||
contentDescription = stringResource(R.string.no_icon),
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
trailingContent = {},
|
||||
tonalElevation = 10.dp
|
||||
)
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.padding(PaddingValues(top = 8.dp, bottom = 8.dp, start = 8.dp, end = 16.dp))
|
||||
.weight(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.clickable { onOpenBottomSheet(false, true) },
|
||||
headlineContent = {
|
||||
Row(modifier = Modifier.fillMaxSize(), horizontalArrangement = Arrangement.SpaceBetween) {
|
||||
Box (modifier = Modifier.weight(1f)) {
|
||||
if (homeSelectedAlbum != null) {
|
||||
IconButton(onClick = { onStop(false, true) }) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Stop,
|
||||
contentDescription = stringResource(R.string.stop_the_album)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.size(8.dp))
|
||||
Box (modifier = Modifier.weight(1f)) {
|
||||
IconButton(onClick = { onOpenBottomSheet(false, true) }) {
|
||||
Icon(
|
||||
contentDescription = stringResource(R.string.click_to_select_a_different_album),
|
||||
imageVector = Icons.Filled.ArrowDropDown,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
supportingContent = {},
|
||||
leadingContent = {
|
||||
Box(modifier = Modifier.size(48.dp)) {
|
||||
if (homeSelectedAlbum != null) {
|
||||
if (showHomeCoverUri) {
|
||||
GlideImage(
|
||||
imageModel = { homeSelectedAlbum.album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(150, 150),
|
||||
),
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.align(
|
||||
Alignment.Center
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Image(
|
||||
imageVector = Icons.Default.RadioButtonUnchecked,
|
||||
contentDescription = stringResource(R.string.no_icon),
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
trailingContent = {
|
||||
|
||||
},
|
||||
tonalElevation = 10.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.padding(PaddingValues(vertical = 8.dp, horizontal = 16.dp))
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.clickable { onOpenBottomSheet(true, true) },
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = LocalContext.current.resources.getQuantityString(R.plurals.wallpaper_count, selectedAlbum.wallpapers.size, selectedAlbum.wallpapers.size),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
text = homeSelectedAlbum?.album?.displayedAlbumName ?: stringResource(R.string.no_album_selected),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
} },
|
||||
leadingContent = {
|
||||
Box (modifier = Modifier.size(60.dp)) {
|
||||
if (selectedAlbum != null) {
|
||||
if (showCoverUri) {
|
||||
GlideImage(
|
||||
imageModel = { selectedAlbum.album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(150, 150),
|
||||
),
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(
|
||||
Alignment.Center))
|
||||
},
|
||||
supportingContent = {
|
||||
if (homeSelectedAlbum != null) {
|
||||
Text(
|
||||
text = LocalContext.current.resources.getQuantityString(
|
||||
R.plurals.wallpaper_count,
|
||||
homeSelectedAlbum.wallpapers.size,
|
||||
homeSelectedAlbum.wallpapers.size
|
||||
),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
},
|
||||
leadingContent = {
|
||||
Box(modifier = Modifier.size(60.dp)) {
|
||||
if (homeSelectedAlbum != null) {
|
||||
if (showHomeCoverUri) {
|
||||
GlideImage(
|
||||
imageModel = { homeSelectedAlbum.album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(150, 150),
|
||||
),
|
||||
loading = {
|
||||
if (animate) {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.align(
|
||||
Alignment.Center
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Image(
|
||||
imageVector = Icons.Default.RadioButtonUnchecked,
|
||||
contentDescription = stringResource(R.string.no_icon),
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Image(
|
||||
imageVector = Icons.Default.RadioButtonUnchecked,
|
||||
contentDescription = stringResource(R.string.no_icon),
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
trailingContent = {
|
||||
Row (
|
||||
horizontalArrangement = Arrangement.spacedBy((-8).dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
if (selectedAlbum != null) {
|
||||
IconButton(onClick = { onStop() }) {
|
||||
Icon(imageVector = Icons.Default.Stop, contentDescription = stringResource(R.string.stop_the_album))
|
||||
},
|
||||
trailingContent = {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy((-8).dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
if (homeSelectedAlbum != null) {
|
||||
IconButton(onClick = { onStop(true, true) }) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Stop,
|
||||
contentDescription = stringResource(R.string.stop_the_album)
|
||||
)
|
||||
}
|
||||
}
|
||||
IconButton(onClick = { onOpenBottomSheet(true, true) }) {
|
||||
Icon(
|
||||
contentDescription = stringResource(R.string.click_to_select_a_different_album),
|
||||
imageVector = Icons.Filled.ArrowDropDown,
|
||||
)
|
||||
}
|
||||
if (homeSelectedAlbum != null) {
|
||||
Switch(
|
||||
checked = enableChanger,
|
||||
onCheckedChange = onToggleChanger,
|
||||
modifier = Modifier
|
||||
.rotate(270f)
|
||||
.scale(0.75f)
|
||||
)
|
||||
}
|
||||
}
|
||||
IconButton(onClick = { onOpenBottomSheet() }) {
|
||||
Icon(
|
||||
contentDescription = stringResource(R.string.click_to_select_a_different_album),
|
||||
imageVector = Icons.Filled.ArrowDropDown,
|
||||
)
|
||||
}
|
||||
if (selectedAlbum != null) {
|
||||
Switch(
|
||||
checked = enableChanger,
|
||||
onCheckedChange = onToggleChanger,
|
||||
modifier = Modifier
|
||||
.rotate(270f)
|
||||
.scale(0.75f)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
tonalElevation = 10.dp
|
||||
)
|
||||
},
|
||||
tonalElevation = 10.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
+99
-20
@@ -48,15 +48,18 @@ import kotlin.math.roundToInt
|
||||
@Composable
|
||||
fun DarkenSwitchAndSlider(
|
||||
onDarkCheck: (Boolean) -> Unit,
|
||||
onDarkenChange: (Int) -> Unit,
|
||||
onDarkenChange: (Int, Int) -> Unit,
|
||||
darken: Boolean,
|
||||
darkenPercentage: Int,
|
||||
bothEnabled: Boolean,
|
||||
homeDarkenPercentage: Int,
|
||||
lockDarkenPercentage: Int,
|
||||
animate: Boolean
|
||||
) {
|
||||
val view = LocalView.current
|
||||
val scope = rememberCoroutineScope()
|
||||
var job by remember { mutableStateOf<Job?>(null) }
|
||||
var percentage by rememberSaveable { mutableFloatStateOf(darkenPercentage.toFloat()) }
|
||||
var homePercentage by rememberSaveable { mutableFloatStateOf(homeDarkenPercentage.toFloat()) }
|
||||
var lockPercentage by rememberSaveable { mutableFloatStateOf(lockDarkenPercentage.toFloat()) }
|
||||
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
@@ -94,54 +97,130 @@ fun DarkenSwitchAndSlider(
|
||||
easing = LinearOutSlowInEasing
|
||||
)
|
||||
)
|
||||
) {
|
||||
) {
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, percentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
if (bothEnabled) {
|
||||
Text(
|
||||
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
else {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
Slider(
|
||||
value = percentage,
|
||||
value = homePercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
percentage = it
|
||||
homePercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onDarkenChange(it.roundToInt())
|
||||
if (bothEnabled) {
|
||||
onDarkenChange(it.roundToInt(), lockPercentage.roundToInt())
|
||||
}
|
||||
else {
|
||||
onDarkenChange(it.roundToInt(), it.roundToInt())
|
||||
}
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
if (bothEnabled) {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Text(
|
||||
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
Slider(
|
||||
value = lockPercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
lockPercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onDarkenChange(homeDarkenPercentage, it.roundToInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (darken) {
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, percentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
if (bothEnabled) {
|
||||
Text(
|
||||
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
else {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
Slider(
|
||||
value = percentage,
|
||||
value = homePercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
percentage = it
|
||||
homePercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onDarkenChange(it.roundToInt())
|
||||
if (bothEnabled) {
|
||||
onDarkenChange(it.roundToInt(), lockPercentage.roundToInt())
|
||||
}
|
||||
else {
|
||||
onDarkenChange(it.roundToInt(), it.roundToInt())
|
||||
}
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
if (bothEnabled) {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Text(
|
||||
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
Slider(
|
||||
value = lockPercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
lockPercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onDarkenChange(homeDarkenPercentage, it.roundToInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import com.anthonyla.paperize.core.grayBitmap
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
|
||||
import com.bumptech.glide.util.Util
|
||||
import java.security.MessageDigest
|
||||
|
||||
/**
|
||||
* A BitmapTransformation that applies a grayscale effect to a bitmap to be used with Glide
|
||||
*/
|
||||
class GrayscaleBitmapTransformation(private val percent: Int): BitmapTransformation() {
|
||||
|
||||
override fun transform(
|
||||
pool: BitmapPool,
|
||||
toTransform: Bitmap,
|
||||
outWidth: Int,
|
||||
outHeight: Int
|
||||
): Bitmap {
|
||||
return grayBitmap(toTransform, percent)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return other is GrayscaleBitmapTransformation && other.percent == percent
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return Util.hashCode(percent)
|
||||
}
|
||||
|
||||
override fun updateDiskCacheKey(messageDigest: MessageDigest) {
|
||||
messageDigest.update((ID + percent).toByteArray(CHARSET))
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ID = "com.bumptech.glide.transformations.GrayscaleBitmapTransformation"
|
||||
}
|
||||
}
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import android.view.HapticFeedbackConstants
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Composable that displays a switch and slider for the grayscale effect
|
||||
*/
|
||||
@Composable
|
||||
fun GrayscaleSwitchAndSlider(
|
||||
onGrayscalePercentageChange: (Int, Int) -> Unit,
|
||||
onGrayscaleChange: (Boolean) -> Unit,
|
||||
grayscale: Boolean,
|
||||
bothEnabled: Boolean,
|
||||
homeGrayscalePercentage: Int,
|
||||
lockGrayscalePercentage: Int,
|
||||
animate: Boolean
|
||||
) {
|
||||
val view = LocalView.current
|
||||
val scope = rememberCoroutineScope()
|
||||
var job by remember { mutableStateOf<Job?>(null) }
|
||||
var homePercentage by rememberSaveable { mutableFloatStateOf(homeGrayscalePercentage.toFloat()) }
|
||||
var lockPercentage by rememberSaveable { mutableFloatStateOf(lockGrayscalePercentage.toFloat()) }
|
||||
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
) {
|
||||
val columnModifier = if (animate) {
|
||||
Modifier.animateContentSize(animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing))
|
||||
} else { Modifier }
|
||||
Column (
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
modifier = columnModifier
|
||||
) {
|
||||
Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
text = stringResource(R.string.gray_filter),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
Switch(
|
||||
checked = grayscale,
|
||||
onCheckedChange = onGrayscaleChange
|
||||
)
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = grayscale,
|
||||
enter = expandVertically(animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)),
|
||||
exit = fadeOut(
|
||||
animationSpec = tween(
|
||||
durationMillis = 300,
|
||||
easing = LinearOutSlowInEasing
|
||||
)
|
||||
)
|
||||
) {
|
||||
Column {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
if (bothEnabled) {
|
||||
Text(
|
||||
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
else {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
Slider(
|
||||
value = homePercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
homePercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
if (bothEnabled) {
|
||||
onGrayscalePercentageChange(it.roundToInt(), lockPercentage.roundToInt())
|
||||
} else {
|
||||
onGrayscalePercentageChange(it.roundToInt(), it.roundToInt())
|
||||
}
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
if (bothEnabled) {
|
||||
Text(
|
||||
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Slider(
|
||||
value = lockPercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
lockPercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onGrayscalePercentageChange(homePercentage.roundToInt(), it.roundToInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (grayscale) {
|
||||
Column {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
if (bothEnabled) {
|
||||
Text(
|
||||
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
else {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
Slider(
|
||||
value = homePercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
homePercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
if (bothEnabled) {
|
||||
onGrayscalePercentageChange(it.roundToInt(), lockPercentage.roundToInt())
|
||||
} else {
|
||||
onGrayscalePercentageChange(it.roundToInt(), it.roundToInt())
|
||||
}
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
if (bothEnabled) {
|
||||
Text(
|
||||
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Slider(
|
||||
value = lockPercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
lockPercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onGrayscalePercentageChange(homePercentage.roundToInt(), it.roundToInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.shrinkVertically
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Composable to toggle individual scheduling settings and toggle wallpaper changer when scheduling separately
|
||||
*/
|
||||
@Composable
|
||||
fun IndividualSchedulingAndToggleRow(
|
||||
animate: Boolean,
|
||||
scheduleSeparately: Boolean,
|
||||
enableChanger : Boolean,
|
||||
onToggleChanger: (Boolean) -> Unit,
|
||||
onScheduleSeparatelyChange: (Boolean) -> Unit,
|
||||
) {
|
||||
val columnModifier = remember {
|
||||
if (animate) {
|
||||
Modifier.animateContentSize(
|
||||
animationSpec = spring(
|
||||
dampingRatio = Spring.DampingRatioMediumBouncy,
|
||||
stiffness = Spring.StiffnessLow
|
||||
)
|
||||
)
|
||||
} else { Modifier }
|
||||
}
|
||||
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
) {
|
||||
Column(
|
||||
modifier = columnModifier
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = 32.dp, end = 32.dp, top = 8.dp, bottom = 8.dp),
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.individual_scheduling),
|
||||
fontWeight = FontWeight.W500,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1
|
||||
)
|
||||
Spacer(modifier = Modifier.padding(8.dp))
|
||||
Switch(
|
||||
checked = scheduleSeparately,
|
||||
onCheckedChange = onScheduleSeparatelyChange,
|
||||
modifier = Modifier.testTag("paperize:individual_scheduling_switch"),
|
||||
)
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = scheduleSeparately,
|
||||
enter = expandVertically() + fadeIn(),
|
||||
exit = shrinkVertically() + fadeOut()
|
||||
) {
|
||||
Row(modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 48.dp)) {
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline, thickness = 2.dp)
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = 32.dp, end = 32.dp, top = 8.dp, bottom = 8.dp),
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.enable_wallpaper_changer),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
fontWeight = FontWeight.W500,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1
|
||||
)
|
||||
Switch(
|
||||
checked = enableChanger,
|
||||
onCheckedChange = onToggleChanger
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (scheduleSeparately) {
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline)
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.enable_wallpaper_changer),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
Switch(
|
||||
checked = enableChanger,
|
||||
onCheckedChange = onToggleChanger
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ErrorOutline
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Dialog to show when a live wallpaper is detected and ask the user to disable it
|
||||
*/
|
||||
@Composable
|
||||
fun ShowLiveWallpaperEnabledDialog(
|
||||
onDismissRequest: () -> Unit
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { onDismissRequest() },
|
||||
icon = { Icon(Icons.Filled.ErrorOutline, stringResource(R.string.disable_live_wallpaper)) },
|
||||
title = {
|
||||
Text(stringResource(R.string.live_wallpaper_detected))
|
||||
},
|
||||
text = {
|
||||
Text(stringResource(R.string.please_disable_your_live_wallpaper_to_use_the_wallpaper_changer))
|
||||
},
|
||||
confirmButton = {
|
||||
Button(
|
||||
onClick = { onDismissRequest() }
|
||||
) {
|
||||
Text(stringResource(R.string.ok))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.blur
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.BlendMode
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.times
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.core.isValidUri
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
|
||||
/**
|
||||
* A composable that displays a wallpaper for preview
|
||||
*/
|
||||
@Composable
|
||||
fun PreviewItem(
|
||||
wallpaperUri: String,
|
||||
darken: Boolean,
|
||||
darkenPercentage: Int,
|
||||
blur: Boolean,
|
||||
blurPercentage: Int,
|
||||
scaling: ScalingConstants,
|
||||
vignette: Boolean,
|
||||
vignettePercentage: Int,
|
||||
grayscale: Boolean,
|
||||
grayscalePercentage: Int
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val showUri by remember { mutableStateOf(isValidUri(context, wallpaperUri)) }
|
||||
val configuration = LocalConfiguration.current
|
||||
val screenWidth = configuration.screenWidthDp.dp
|
||||
val screenHeight = configuration.screenHeightDp.dp
|
||||
if (showUri) {
|
||||
GlideImage(
|
||||
imageModel = { wallpaperUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = when (scaling) {
|
||||
ScalingConstants.FILL -> ContentScale.FillHeight
|
||||
ScalingConstants.FIT -> ContentScale.FillWidth
|
||||
ScalingConstants.STRETCH -> ContentScale.FillBounds
|
||||
ScalingConstants.NONE -> ContentScale.Crop
|
||||
},
|
||||
requestSize = IntSize(300, 300),
|
||||
alignment = if (scaling == ScalingConstants.NONE) Alignment.CenterStart else Alignment.Center,
|
||||
colorFilter = if (darken && darkenPercentage < 100) {
|
||||
ColorFilter.tint(
|
||||
Color.Black.copy(alpha = (100 - darkenPercentage).toFloat().div(100f)),
|
||||
BlendMode.Darken
|
||||
)
|
||||
} else { null },
|
||||
tag = vignette.toString() + vignettePercentage.toString() + grayscale.toString() + grayscalePercentage.toString(),
|
||||
),
|
||||
requestOptions = {
|
||||
when {
|
||||
grayscale && grayscalePercentage > 0 && vignette && vignettePercentage > 0 -> {
|
||||
RequestOptions().transform(
|
||||
VignetteBitmapTransformation(vignettePercentage),
|
||||
GrayscaleBitmapTransformation(grayscalePercentage)
|
||||
)
|
||||
}
|
||||
grayscale && grayscalePercentage > 0 -> {
|
||||
RequestOptions().transform(GrayscaleBitmapTransformation(grayscalePercentage))
|
||||
}
|
||||
vignette && vignettePercentage > 0 -> {
|
||||
RequestOptions().transform(VignetteBitmapTransformation(vignettePercentage))
|
||||
}
|
||||
else -> RequestOptions()
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.size(screenWidth * 0.35f, screenHeight * 0.35f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.border(3.dp, Color.Black, RoundedCornerShape(16.dp))
|
||||
.background(Color.Black)
|
||||
.blur(
|
||||
if (blur && blurPercentage > 0) {
|
||||
blurPercentage
|
||||
.toFloat()
|
||||
.div(100f) * 1.5.dp
|
||||
} else {
|
||||
0.dp
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Notifications
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Dialog to let the user know of the app's potential delays when it comes to scheduling wallpapers.
|
||||
*/
|
||||
@Composable
|
||||
fun ShowDelayNoticeDialog(
|
||||
onDismissRequest: () -> Unit
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { onDismissRequest() },
|
||||
icon = { Icon(Icons.Filled.Notifications, stringResource(R.string.delay_notice)) },
|
||||
title = {
|
||||
Text(stringResource(R.string.delay_notice_dialog))
|
||||
},
|
||||
text = {
|
||||
Text(stringResource(R.string.to_minimize_battery_usage_changing_wallpapers_may_have_some_delays_once_scheduled_when_the_device_is_asleep_the_wallpaper_may_take_longer_to_apply))
|
||||
},
|
||||
confirmButton = {
|
||||
Button(
|
||||
onClick = { onDismissRequest() }
|
||||
) {
|
||||
Text(stringResource(R.string.ok))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
+213
-81
@@ -12,6 +12,7 @@ import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.shrinkVertically
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.IntrinsicSize
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
@@ -22,14 +23,18 @@ import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowDropDown
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TimePicker
|
||||
import androidx.compose.material3.TimePickerState
|
||||
import androidx.compose.material3.rememberTimePickerState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
@@ -44,46 +49,110 @@ import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_MIN
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* TimeSliders is a composable that displays sliders for the user to select the time interval for changing wallpaper
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun TimeSliders(
|
||||
timeInMinutes1: Int,
|
||||
timeInMinutes2: Int,
|
||||
homeInterval: Int,
|
||||
lockInterval: Int,
|
||||
showInterval: Boolean,
|
||||
animate: Boolean,
|
||||
onShowIntervalChange: (Boolean) -> Unit,
|
||||
scheduleSeparately: Boolean,
|
||||
onScheduleSeparatelyChange: (Boolean) -> Unit,
|
||||
onTimeChange1: (Int, Int, Int) -> Unit,
|
||||
onTimeChange2: (Int, Int, Int) -> Unit,
|
||||
onHomeIntervalChange: (Int, Int, Int) -> Unit,
|
||||
onLockIntervalChange: (Int, Int, Int) -> Unit,
|
||||
lockEnabled: Boolean,
|
||||
homeEnabled: Boolean,
|
||||
startingTime: Pair<Int, Int>,
|
||||
changeStartTime: Boolean,
|
||||
onChangeStartTimeToggle: (Boolean) -> Unit,
|
||||
onStartTimeChange: (TimePickerState) -> Unit
|
||||
) {
|
||||
val view = LocalView.current
|
||||
var days1 by rememberSaveable { mutableFloatStateOf((timeInMinutes1 / (24 * 60)).toFloat()) }
|
||||
var hours1 by rememberSaveable { mutableFloatStateOf(((timeInMinutes1 % (24 * 60)) / 60).toFloat()) }
|
||||
var minutes1 by rememberSaveable { mutableFloatStateOf((timeInMinutes1 % 60).toFloat()) }
|
||||
var days2 by rememberSaveable { mutableFloatStateOf((timeInMinutes2 / (24 * 60)).toFloat()) }
|
||||
var hours2 by rememberSaveable { mutableFloatStateOf(((timeInMinutes2 % (24 * 60)) / 60).toFloat()) }
|
||||
var minutes2 by rememberSaveable { mutableFloatStateOf((timeInMinutes2 % 60).toFloat()) }
|
||||
var days1 by rememberSaveable { mutableFloatStateOf((homeInterval / (24 * 60)).toFloat()) }
|
||||
var hours1 by rememberSaveable { mutableFloatStateOf(((homeInterval % (24 * 60)) / 60).toFloat()) }
|
||||
var minutes1 by rememberSaveable { mutableFloatStateOf((homeInterval % 60).toFloat()) }
|
||||
var days2 by rememberSaveable { mutableFloatStateOf((lockInterval / (24 * 60)).toFloat()) }
|
||||
var hours2 by rememberSaveable { mutableFloatStateOf(((lockInterval % (24 * 60)) / 60).toFloat()) }
|
||||
var minutes2 by rememberSaveable { mutableFloatStateOf((lockInterval % 60).toFloat()) }
|
||||
val scope = rememberCoroutineScope()
|
||||
val context = LocalView.current
|
||||
var job by remember { mutableStateOf<Job?>(null) }
|
||||
val shouldShowDialog = remember { mutableStateOf(false) }
|
||||
val timePickerState = rememberTimePickerState(
|
||||
initialHour = startingTime.first,
|
||||
initialMinute = startingTime.second,
|
||||
is24Hour = false,
|
||||
)
|
||||
|
||||
if (shouldShowDialog.value) {
|
||||
val initialHour = startingTime.first
|
||||
val initialMinute = startingTime.second
|
||||
Dialog(
|
||||
onDismissRequest = {
|
||||
timePickerState.hour = initialHour
|
||||
timePickerState.minute = initialMinute
|
||||
shouldShowDialog.value = false
|
||||
}
|
||||
) {
|
||||
Surface(
|
||||
shape = MaterialTheme.shapes.large,
|
||||
tonalElevation = 5.dp,
|
||||
modifier = Modifier
|
||||
.width(IntrinsicSize.Min)
|
||||
.height(IntrinsicSize.Min)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(24.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 24.dp),
|
||||
text = stringResource(R.string.select_starting_time),
|
||||
style = MaterialTheme.typography.labelMedium
|
||||
)
|
||||
TimePicker(state = timePickerState)
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly
|
||||
) {
|
||||
Button(
|
||||
onClick = { shouldShowDialog.value = false }
|
||||
) { Text(stringResource(R.string.dismiss)) }
|
||||
Button(
|
||||
onClick = { onStartTimeChange(timePickerState); shouldShowDialog.value = false }
|
||||
) { Text(stringResource(R.string.confirm)) }
|
||||
}
|
||||
Button(
|
||||
onClick = { onChangeStartTimeToggle(false); shouldShowDialog.value = false }
|
||||
) { Text(stringResource(R.string.reset_to_default)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val columnModifier = remember {
|
||||
if (animate) {
|
||||
Modifier.animateContentSize(
|
||||
animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing)
|
||||
)
|
||||
} else { Modifier }
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
}
|
||||
|
||||
Surface(
|
||||
@@ -93,7 +162,7 @@ fun TimeSliders(
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
) {
|
||||
Column (
|
||||
Column(
|
||||
modifier = columnModifier
|
||||
) {
|
||||
val totalMinutes1 = (days1.toInt() * 24 * 60) + (hours1.toInt() * 60) + minutes1.toInt()
|
||||
@@ -103,22 +172,30 @@ fun TimeSliders(
|
||||
|
||||
val formattedDays1 = if (displayDays1 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.days, displayDays1, displayDays1)
|
||||
} else {""}
|
||||
} else { "" }
|
||||
|
||||
val formattedHours1 = if (displayHours1 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.hours, displayHours1, displayHours1)
|
||||
} else {""}
|
||||
} else { "" }
|
||||
|
||||
val formattedMinutes1 = if (displayMinutes1 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.minutes, displayMinutes1, displayMinutes1)
|
||||
} else {""}
|
||||
context.resources.getQuantityString(
|
||||
R.plurals.minutes,
|
||||
displayMinutes1,
|
||||
displayMinutes1
|
||||
)
|
||||
} else { "" }
|
||||
|
||||
val formattedTime1 = stringResource(
|
||||
if (scheduleSeparately)
|
||||
R.string.interval_home
|
||||
else
|
||||
R.string.interval,
|
||||
listOf(formattedDays1, formattedHours1, formattedMinutes1).filter { it.isNotEmpty() }.joinToString(", ")
|
||||
listOf(
|
||||
formattedDays1,
|
||||
formattedHours1,
|
||||
formattedMinutes1
|
||||
).filter { it.isNotEmpty() }.joinToString(", ")
|
||||
)
|
||||
|
||||
val totalMinutes2 = (days2.toInt() * 24 * 60) + (hours2.toInt() * 60) + minutes2.toInt()
|
||||
@@ -128,25 +205,35 @@ fun TimeSliders(
|
||||
|
||||
val formattedDays2 = if (displayDays2 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.days, displayDays2, displayDays2)
|
||||
} else {""}
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
val formattedHours2 = if (displayHours2 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.hours, displayHours2, displayHours2)
|
||||
} else {""}
|
||||
} else { "" }
|
||||
|
||||
val formattedMinutes2 = if (displayMinutes2 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.minutes, displayMinutes2, displayMinutes2)
|
||||
} else {""}
|
||||
context.resources.getQuantityString(
|
||||
R.plurals.minutes,
|
||||
displayMinutes2,
|
||||
displayMinutes2
|
||||
)
|
||||
} else { "" }
|
||||
|
||||
val formattedTime2 = stringResource(
|
||||
if (scheduleSeparately)
|
||||
R.string.interval_lock
|
||||
else
|
||||
R.string.interval,
|
||||
listOf(formattedDays2, formattedHours2, formattedMinutes2).filter { it.isNotEmpty() }.joinToString(", ")
|
||||
listOf(
|
||||
formattedDays2,
|
||||
formattedHours2,
|
||||
formattedMinutes2
|
||||
).filter { it.isNotEmpty() }.joinToString(", ")
|
||||
)
|
||||
|
||||
Row (
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center
|
||||
@@ -167,7 +254,10 @@ fun TimeSliders(
|
||||
IconButton(
|
||||
onClick = { onShowIntervalChange(!showInterval) },
|
||||
) {
|
||||
Icon(imageVector = Icons.Filled.ArrowDropDown, contentDescription = stringResource(R.string.show_interval_sliders))
|
||||
Icon(
|
||||
imageVector = Icons.Filled.ArrowDropDown,
|
||||
contentDescription = stringResource(R.string.show_interval_sliders)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,20 +285,25 @@ fun TimeSliders(
|
||||
days1 = newDays
|
||||
val totalMinute =
|
||||
(newDays.toInt() * 24 * 60) + (hours1.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (hours1.toInt() * 60)
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
minutes1 =
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (hours1.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange1(newDays.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
onHomeIntervalChange(
|
||||
newDays.toInt(),
|
||||
hours1.toInt(),
|
||||
minutes1.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..30f,
|
||||
steps = 30,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Slider(
|
||||
value = hours1,
|
||||
onValueChange = { newHours ->
|
||||
@@ -216,34 +311,43 @@ fun TimeSliders(
|
||||
hours1 = newHours
|
||||
val totalMinute =
|
||||
(days1.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (newHours.toInt() * 60)
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
minutes1 =
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (newHours.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange1(days1.toInt(), newHours.toInt(), minutes1.toInt())
|
||||
onHomeIntervalChange(
|
||||
days1.toInt(),
|
||||
newHours.toInt(),
|
||||
minutes1.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..24f,
|
||||
steps = 24,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Slider(
|
||||
value = minutes1,
|
||||
onValueChange = { newMinutes ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
minutes1 =
|
||||
if (days1.toInt() == 0 && hours1.toInt() == 0 && newMinutes < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat()
|
||||
if (days1.toInt() == 0 && hours1.toInt() == 0 && newMinutes < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat()
|
||||
} else {
|
||||
newMinutes
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange1(days1.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
onHomeIntervalChange(
|
||||
days1.toInt(),
|
||||
hours1.toInt(),
|
||||
minutes1.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..60f,
|
||||
@@ -271,7 +375,11 @@ fun TimeSliders(
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline)
|
||||
HorizontalDivider(
|
||||
color = MaterialTheme.colorScheme.outline,
|
||||
modifier = Modifier.padding(horizontal = 32.dp),
|
||||
thickness = 2.dp
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Text(
|
||||
text = formattedTime2,
|
||||
@@ -284,13 +392,14 @@ fun TimeSliders(
|
||||
days2 = newDays
|
||||
val totalMinute =
|
||||
(newDays.toInt() * 24 * 60) + (hours2.toInt() * 60) + minutes2.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes2 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (hours2.toInt() * 60)
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
minutes2 =
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (hours2.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange2(
|
||||
onLockIntervalChange(
|
||||
newDays.toInt(),
|
||||
hours2.toInt(),
|
||||
minutes2.toInt()
|
||||
@@ -301,7 +410,7 @@ fun TimeSliders(
|
||||
steps = 30,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Slider(
|
||||
value = hours2,
|
||||
onValueChange = { newHours ->
|
||||
@@ -309,13 +418,14 @@ fun TimeSliders(
|
||||
hours2 = newHours
|
||||
val totalMinute =
|
||||
(days2.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes2.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes2 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (newHours.toInt() * 60)
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
minutes2 =
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (newHours.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange2(
|
||||
onLockIntervalChange(
|
||||
days2.toInt(),
|
||||
newHours.toInt(),
|
||||
minutes2.toInt()
|
||||
@@ -326,21 +436,21 @@ fun TimeSliders(
|
||||
steps = 24,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Slider(
|
||||
value = minutes2,
|
||||
onValueChange = { newMinutes ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
minutes2 =
|
||||
if (days2.toInt() == 0 && hours2.toInt() == 0 && newMinutes < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat()
|
||||
if (days2.toInt() == 0 && hours2.toInt() == 0 && newMinutes < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat()
|
||||
} else {
|
||||
newMinutes
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange2(
|
||||
onLockIntervalChange(
|
||||
days2.toInt(),
|
||||
hours2.toInt(),
|
||||
minutes2.toInt()
|
||||
@@ -353,39 +463,51 @@ fun TimeSliders(
|
||||
)
|
||||
}
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
Text(text = stringResource(R.string.individual_scheduling), fontWeight = FontWeight.W500)
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
Switch(
|
||||
checked = scheduleSeparately,
|
||||
onCheckedChange = onScheduleSeparatelyChange
|
||||
)
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Button(
|
||||
onClick = {
|
||||
shouldShowDialog.value = true
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.align(Alignment.CenterHorizontally)
|
||||
) {
|
||||
val (hour, minute, period) = if (changeStartTime) {
|
||||
val hour = if (timePickerState.hour == 0) 12 else timePickerState.hour % 12
|
||||
val period = if (timePickerState.hour < 12) "AM" else "PM"
|
||||
Triple(hour, timePickerState.minute, period)
|
||||
} else {
|
||||
val currentTime = Calendar.getInstance()
|
||||
val hour = if (currentTime.get(Calendar.HOUR) == 0) 12 else currentTime.get(Calendar.HOUR) % 12
|
||||
val period = if (currentTime.get(Calendar.AM_PM) == 0) "AM" else "PM"
|
||||
Triple(hour, currentTime.get(Calendar.MINUTE), period)
|
||||
}
|
||||
val formattedMinutes = String.format(Locale.getDefault(), "%02d", minute)
|
||||
Text(text = "$hour:$formattedMinutes $period")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (showInterval) {
|
||||
Slider(
|
||||
value = days1,
|
||||
onValueChange = { newDays ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
days1 = newDays
|
||||
val totalMinute = (newDays.toInt() * 24 * 60) + (hours1.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (hours1.toInt() * 60)
|
||||
val totalMinute =
|
||||
(newDays.toInt() * 24 * 60) + (hours1.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
minutes1 =
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (hours1.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange1(newDays.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
onHomeIntervalChange(
|
||||
newDays.toInt(),
|
||||
hours1.toInt(),
|
||||
minutes1.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..30f,
|
||||
@@ -398,14 +520,20 @@ fun TimeSliders(
|
||||
onValueChange = { newHours ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
hours1 = newHours
|
||||
val totalMinute = (days1.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat() - (newHours.toInt() * 60)
|
||||
val totalMinute =
|
||||
(days1.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
minutes1 =
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (newHours.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange1(days1.toInt(), newHours.toInt(), minutes1.toInt())
|
||||
onHomeIntervalChange(
|
||||
days1.toInt(),
|
||||
newHours.toInt(),
|
||||
minutes1.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..24f,
|
||||
@@ -417,15 +545,20 @@ fun TimeSliders(
|
||||
value = minutes1,
|
||||
onValueChange = { newMinutes ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
minutes1 = if (days1.toInt() == 0 && hours1.toInt() == 0 && newMinutes < WALLPAPER_CHANGE_INTERVAL_DEFAULT) {
|
||||
WALLPAPER_CHANGE_INTERVAL_DEFAULT.toFloat()
|
||||
} else {
|
||||
newMinutes
|
||||
}
|
||||
minutes1 =
|
||||
if (days1.toInt() == 0 && hours1.toInt() == 0 && newMinutes < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat()
|
||||
} else {
|
||||
newMinutes
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onTimeChange1(days1.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
onHomeIntervalChange(
|
||||
days1.toInt(),
|
||||
hours1.toInt(),
|
||||
minutes1.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..60f,
|
||||
@@ -436,5 +569,4 @@ fun TimeSliders(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import com.anthonyla.paperize.core.vignetteBitmap
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
|
||||
import com.bumptech.glide.util.Util
|
||||
import java.security.MessageDigest
|
||||
|
||||
/**
|
||||
* A BitmapTransformation that applies a vignette effect to a bitmap to be used with Glide
|
||||
*/
|
||||
class VignetteBitmapTransformation(private val percent: Int): BitmapTransformation() {
|
||||
|
||||
override fun transform(
|
||||
pool: BitmapPool,
|
||||
toTransform: Bitmap,
|
||||
outWidth: Int,
|
||||
outHeight: Int
|
||||
): Bitmap {
|
||||
return vignetteBitmap(toTransform, percent)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return other is VignetteBitmapTransformation && other.percent == percent
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return Util.hashCode(percent)
|
||||
}
|
||||
|
||||
override fun updateDiskCacheKey(messageDigest: MessageDigest) {
|
||||
messageDigest.update((ID + percent).toByteArray(CHARSET))
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ID = "com.bumptech.glide.transformations.VignettedBitmapTransformation"
|
||||
}
|
||||
}
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import android.view.HapticFeedbackConstants
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Composable that displays a switch and slider for the vignette effect
|
||||
*/
|
||||
@Composable
|
||||
fun VignetteSwitchAndSlider(
|
||||
onVignettePercentageChange: (Int, Int) -> Unit,
|
||||
onVignetteChange: (Boolean) -> Unit,
|
||||
vignette: Boolean,
|
||||
bothEnabled: Boolean,
|
||||
homeVignettePercentage: Int,
|
||||
lockVignettePercentage: Int,
|
||||
animate: Boolean
|
||||
) {
|
||||
val view = LocalView.current
|
||||
val scope = rememberCoroutineScope()
|
||||
var job by remember { mutableStateOf<Job?>(null) }
|
||||
var homePercentage by rememberSaveable { mutableFloatStateOf(homeVignettePercentage.toFloat()) }
|
||||
var lockPercentage by rememberSaveable { mutableFloatStateOf(lockVignettePercentage.toFloat()) }
|
||||
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
) {
|
||||
val columnModifier = if (animate) {
|
||||
Modifier.animateContentSize(animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing))
|
||||
} else { Modifier }
|
||||
Column (
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
modifier = columnModifier
|
||||
) {
|
||||
Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
text = stringResource(R.string.change_vignette),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
Switch(
|
||||
checked = vignette,
|
||||
onCheckedChange = onVignetteChange
|
||||
)
|
||||
}
|
||||
if (animate) {
|
||||
AnimatedVisibility(
|
||||
visible = vignette,
|
||||
enter = expandVertically(animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)),
|
||||
exit = fadeOut(
|
||||
animationSpec = tween(
|
||||
durationMillis = 300,
|
||||
easing = LinearOutSlowInEasing
|
||||
)
|
||||
)
|
||||
) {
|
||||
Column {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
if (bothEnabled) {
|
||||
Text(
|
||||
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
else {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
Slider(
|
||||
value = homePercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
homePercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
if (bothEnabled) {
|
||||
onVignettePercentageChange(it.roundToInt(), lockPercentage.roundToInt())
|
||||
} else {
|
||||
onVignettePercentageChange(it.roundToInt(), it.roundToInt())
|
||||
}
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
if (bothEnabled) {
|
||||
Text(
|
||||
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Slider(
|
||||
value = lockPercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
lockPercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onVignettePercentageChange(homePercentage.roundToInt(), it.roundToInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (vignette) {
|
||||
Column {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
if (bothEnabled) {
|
||||
Text(
|
||||
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
else {
|
||||
Text(
|
||||
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
}
|
||||
Slider(
|
||||
value = homePercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
homePercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
if (bothEnabled) {
|
||||
onVignettePercentageChange(it.roundToInt(), lockPercentage.roundToInt())
|
||||
} else {
|
||||
onVignettePercentageChange(it.roundToInt(), it.roundToInt())
|
||||
}
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
if (bothEnabled) {
|
||||
Text(
|
||||
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
|
||||
fontWeight = FontWeight.W400
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Slider(
|
||||
value = lockPercentage,
|
||||
onValueChange = {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
lockPercentage = it
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onVignettePercentageChange(homePercentage.roundToInt(), it.roundToInt())
|
||||
}
|
||||
},
|
||||
valueRange = 0f..100f,
|
||||
steps = 100,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+36
-45
@@ -1,6 +1,5 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
@@ -33,7 +32,6 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
|
||||
|
||||
/**
|
||||
* SetLockScreenSwitch is a composable that displays a switch to set the wallpaper as the lock screen wallpaper
|
||||
@@ -43,15 +41,22 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.Wa
|
||||
fun WallpaperPreviewAndScale(
|
||||
currentHomeWallpaper: String?,
|
||||
currentLockWallpaper: String?,
|
||||
animate: Boolean,
|
||||
darken: Boolean,
|
||||
darkenPercentage: Int,
|
||||
homeDarkenPercentage: Int,
|
||||
lockDarkenPercentage: Int,
|
||||
homeEnabled: Boolean,
|
||||
lockEnabled: Boolean,
|
||||
scaling: ScalingConstants,
|
||||
onScalingChange: (ScalingConstants) -> Unit,
|
||||
blur: Boolean,
|
||||
blurPercentage: Int,
|
||||
homeBlurPercentage: Int,
|
||||
lockBlurPercentage: Int,
|
||||
vignette: Boolean,
|
||||
homeVignettePercentage: Int,
|
||||
lockVignettePercentage: Int,
|
||||
grayscale: Boolean,
|
||||
homeGrayscalePercentage: Int,
|
||||
lockGrayscalePercentage: Int
|
||||
) {
|
||||
var selectedIndex by rememberSaveable {
|
||||
mutableIntStateOf(
|
||||
@@ -59,13 +64,15 @@ fun WallpaperPreviewAndScale(
|
||||
ScalingConstants.FILL -> 0
|
||||
ScalingConstants.FIT -> 1
|
||||
ScalingConstants.STRETCH -> 2
|
||||
ScalingConstants.NONE -> 3
|
||||
}
|
||||
)
|
||||
}
|
||||
val options = listOf(
|
||||
stringResource(R.string.fill),
|
||||
stringResource(R.string.fit),
|
||||
stringResource(R.string.stretch)
|
||||
stringResource(R.string.stretch),
|
||||
stringResource(R.string.none)
|
||||
)
|
||||
|
||||
Surface(
|
||||
@@ -85,9 +92,13 @@ fun WallpaperPreviewAndScale(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
val modifier = if (lockEnabled && homeEnabled) {
|
||||
Modifier.weight(1f).padding(8.dp)
|
||||
Modifier
|
||||
.weight(1f)
|
||||
.padding(8.dp)
|
||||
} else {
|
||||
Modifier.fillMaxSize(0.5f).padding(8.dp)
|
||||
Modifier
|
||||
.fillMaxSize(0.5f)
|
||||
.padding(8.dp)
|
||||
}
|
||||
|
||||
if (lockEnabled) {
|
||||
@@ -97,28 +108,17 @@ fun WallpaperPreviewAndScale(
|
||||
) {
|
||||
Text(text = stringResource(R.string.lock_screen), fontWeight = FontWeight.W500)
|
||||
if (currentLockWallpaper != null) {
|
||||
WallpaperItem(
|
||||
PreviewItem(
|
||||
wallpaperUri = currentLockWallpaper,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(
|
||||
3.dp,
|
||||
color = Color.Black,
|
||||
shape = RoundedCornerShape(16.dp)
|
||||
),
|
||||
aspectRatio = 9f / 19.5f,
|
||||
clickable = false,
|
||||
animate = animate,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
darkenPercentage = if (!homeEnabled) homeDarkenPercentage else lockDarkenPercentage,
|
||||
scaling = scaling,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage
|
||||
blurPercentage = if (!homeEnabled) homeBlurPercentage else lockBlurPercentage,
|
||||
vignette = vignette,
|
||||
vignettePercentage = if (!homeEnabled) homeVignettePercentage else lockVignettePercentage,
|
||||
grayscale = grayscale,
|
||||
grayscalePercentage = if (!homeEnabled) homeGrayscalePercentage else lockGrayscalePercentage
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
@@ -131,28 +131,17 @@ fun WallpaperPreviewAndScale(
|
||||
) {
|
||||
Text(text = stringResource(R.string.home), fontWeight = FontWeight.W500)
|
||||
if (currentHomeWallpaper != null) {
|
||||
WallpaperItem(
|
||||
PreviewItem(
|
||||
wallpaperUri = currentHomeWallpaper,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(
|
||||
3.dp,
|
||||
color = Color.Black,
|
||||
shape = RoundedCornerShape(16.dp)
|
||||
),
|
||||
aspectRatio = 9f / 19.5f,
|
||||
clickable = false,
|
||||
animate = animate,
|
||||
darken = darken,
|
||||
darkenPercentage = darkenPercentage,
|
||||
darkenPercentage = homeDarkenPercentage,
|
||||
scaling = scaling,
|
||||
blur = blur,
|
||||
blurPercentage = blurPercentage
|
||||
blurPercentage = homeBlurPercentage,
|
||||
vignette = vignette,
|
||||
vignettePercentage = homeVignettePercentage,
|
||||
grayscale = grayscale,
|
||||
grayscalePercentage = homeGrayscalePercentage
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
@@ -174,6 +163,7 @@ fun WallpaperPreviewAndScale(
|
||||
0 -> ScalingConstants.FILL
|
||||
1 -> ScalingConstants.FIT
|
||||
2 -> ScalingConstants.STRETCH
|
||||
3 -> ScalingConstants.NONE
|
||||
else -> ScalingConstants.FILL
|
||||
}
|
||||
) },
|
||||
@@ -188,11 +178,12 @@ fun WallpaperPreviewAndScale(
|
||||
0 -> painterResource(id = R.drawable.fill)
|
||||
1 -> painterResource(id = R.drawable.fit)
|
||||
2 -> painterResource(id = R.drawable.stretch)
|
||||
3 -> painterResource(id = R.drawable.none)
|
||||
else -> painterResource(id = R.drawable.fill)
|
||||
},
|
||||
contentDescription = null,
|
||||
tint = Color.Unspecified,
|
||||
modifier = Modifier.size(40.dp)
|
||||
modifier = Modifier.size(32.dp)
|
||||
)
|
||||
Text(text = label, maxLines = 1, overflow = TextOverflow.Ellipsis )
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.tasker_shortcut
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import com.joaomgcd.taskerpluginlibrary.config.TaskerPluginConfig
|
||||
import com.joaomgcd.taskerpluginlibrary.config.TaskerPluginConfigHelperEventNoOutputOrInputOrUpdate
|
||||
import com.joaomgcd.taskerpluginlibrary.config.TaskerPluginConfigNoInput
|
||||
import com.joaomgcd.taskerpluginlibrary.extensions.requestQuery
|
||||
import com.joaomgcd.taskerpluginlibrary.input.TaskerInput
|
||||
|
||||
class BasicEventHelper(config: TaskerPluginConfig<Unit>) : TaskerPluginConfigHelperEventNoOutputOrInputOrUpdate(config) {
|
||||
override fun addToStringBlurb(input: TaskerInput<Unit>, blurbBuilder: StringBuilder) {
|
||||
blurbBuilder.append("Triggers when the app changes the wallpaper")
|
||||
}
|
||||
}
|
||||
|
||||
class ActivityConfigBasicEvent : Activity(), TaskerPluginConfigNoInput {
|
||||
override val context: Context get() = applicationContext
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
BasicEventHelper(this).finishForTasker()
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.triggerWallpaperTaskerEvent() = ActivityConfigBasicEvent::class.java.requestQuery(this)
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.tasker_shortcut
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperBootAndChangeReceiver
|
||||
import com.joaomgcd.taskerpluginlibrary.action.TaskerPluginRunnerActionNoOutputOrInput
|
||||
import com.joaomgcd.taskerpluginlibrary.config.TaskerPluginConfig
|
||||
import com.joaomgcd.taskerpluginlibrary.config.TaskerPluginConfigHelperNoOutputOrInput
|
||||
import com.joaomgcd.taskerpluginlibrary.config.TaskerPluginConfigNoInput
|
||||
import com.joaomgcd.taskerpluginlibrary.input.TaskerInput
|
||||
import com.joaomgcd.taskerpluginlibrary.runner.TaskerPluginResult
|
||||
import com.joaomgcd.taskerpluginlibrary.runner.TaskerPluginResultSucess
|
||||
|
||||
/**
|
||||
* Tasker Shortcut to change wallpaper
|
||||
*/
|
||||
class ShortcutHelper(config: TaskerPluginConfig<Unit>) : TaskerPluginConfigHelperNoOutputOrInput<ShortcutActionRunner>(config) {
|
||||
override val runnerClass: Class<ShortcutActionRunner> get() = ShortcutActionRunner::class.java
|
||||
override fun addToStringBlurb(input: TaskerInput<Unit>, blurbBuilder: StringBuilder) {
|
||||
blurbBuilder.append("Changes the wallpaper")
|
||||
}
|
||||
}
|
||||
|
||||
class ActivityConfigBasicAction : Activity(), TaskerPluginConfigNoInput {
|
||||
override val context: Context get() = applicationContext
|
||||
private val taskerHelper by lazy { ShortcutHelper(this) }
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
taskerHelper.finishForTasker()
|
||||
}
|
||||
}
|
||||
|
||||
class ShortcutActionRunner : TaskerPluginRunnerActionNoOutputOrInput() {
|
||||
override fun run(context: Context, input: TaskerInput<Unit>): TaskerPluginResult<Unit> {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
val intent = Intent(context, WallpaperBootAndChangeReceiver::class.java)
|
||||
context.sendBroadcast(intent)
|
||||
}
|
||||
return TaskerPluginResultSucess()
|
||||
}
|
||||
}
|
||||
+4
-8
@@ -57,12 +57,8 @@ data class AddEdit(val wallpaper: String)
|
||||
@Serializable
|
||||
data class WallpaperView(val wallpaper: String)
|
||||
|
||||
/** Reverted back to passing JSON due to bug in navigation compose causing crash
|
||||
* Data class for FolderView screen
|
||||
@Serializable
|
||||
data class FolderView(val folderName: String?, val wallpapers: List<String>)
|
||||
/**
|
||||
* Object for FolderView screen
|
||||
*/
|
||||
|
||||
sealed class NavScreens(val route: String) {
|
||||
data object FolderView : NavScreens("folder_view_screen")
|
||||
}
|
||||
@Serializable
|
||||
object FolderView
|
||||
+11
-5
@@ -4,12 +4,18 @@ import com.anthonyla.paperize.core.SettingsConstants
|
||||
|
||||
/**
|
||||
* Data class for storing wallpaper alarm item
|
||||
* @param timeInMinutes1: Int - time in minutes for home wallpaper or both if scheduled together
|
||||
* @param timeInMinutes2: Int - time in minutes for lock wallpaper
|
||||
* @param homeInterval: Int - time in minutes for home wallpaper or both if scheduled together
|
||||
* @param lockInterval: Int - time in minutes for lock wallpaper
|
||||
* @param scheduleSeparately: Boolean - schedule wallpapers separately
|
||||
* @param setHome: Boolean - set home wallpaper
|
||||
* @param setLock: Boolean - set lock wallpaper
|
||||
*/
|
||||
data class WallpaperAlarmItem(
|
||||
val timeInMinutes1: Int = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val timeInMinutes2: Int = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val scheduleSeparately: Boolean = false
|
||||
val homeInterval: Int = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val lockInterval: Int = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val scheduleSeparately: Boolean = false,
|
||||
val setHome : Boolean = false,
|
||||
val setLock : Boolean = false,
|
||||
val changeStartTime: Boolean = false,
|
||||
val startTime: Pair<Int, Int> = Pair(0, 0),
|
||||
)
|
||||
+6
-4
@@ -7,21 +7,23 @@ interface WallpaperAlarmScheduler {
|
||||
* @param origin where the request came from (null if not from a specific origin, 0 if home screen, 1 if lock screen, 2 if both)
|
||||
* @param changeImmediate whether to change the wallpaper immediately or just schedule the alarm
|
||||
* @param cancelImmediate whether to cancel all alarms before scheduling the new one
|
||||
* @param setAlarm whether to set the alarm or not
|
||||
* @param firstLaunch whether this is the first launch of the wallpaper changer
|
||||
*/
|
||||
fun scheduleWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem, origin: Int? = null, changeImmediate: Boolean = false, cancelImmediate: Boolean = false)
|
||||
fun scheduleWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem, origin: Int? = null, changeImmediate: Boolean = false, cancelImmediate: Boolean = false, setAlarm: Boolean = true, firstLaunch: Boolean = false)
|
||||
|
||||
/**
|
||||
* Update the wallpaper alarm with new times without changing the wallpaper
|
||||
*/
|
||||
fun updateWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem)
|
||||
fun updateWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem, firstLaunch: Boolean = false)
|
||||
|
||||
/**
|
||||
* Update the wallpaper without changing the alarm
|
||||
*/
|
||||
fun updateWallpaper(scheduleSeparately: Boolean)
|
||||
fun updateWallpaper(scheduleSeparately: Boolean, setHome: Boolean, setLock: Boolean)
|
||||
|
||||
/**
|
||||
* Cancel all wallpaper alarms
|
||||
*/
|
||||
fun cancelWallpaperAlarm()
|
||||
fun cancelWallpaperAlarm(cancelLock: Boolean = true, cancelHome: Boolean = true)
|
||||
}
|
||||
+262
@@ -0,0 +1,262 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import com.anthonyla.paperize.core.Type
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.HomeWallpaperService
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.LockWallpaperService
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
|
||||
/**
|
||||
* This class is responsible for scheduling wallpaper alarms.
|
||||
* It uses the AlarmManager to schedule alarms for the [WallpaperReceiver].
|
||||
* It also uses [HomeWallpaperService] and [LockWallpaperService] to change the wallpaper due to receiver limitations.
|
||||
*/
|
||||
class WallpaperAlarmSchedulerImpl (
|
||||
private val context: Context,
|
||||
): WallpaperAlarmScheduler {
|
||||
private val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
|
||||
/**
|
||||
* Schedules the wallpaper alarm based on the origin and changeImmediate
|
||||
*/
|
||||
override fun scheduleWallpaperAlarm(
|
||||
wallpaperAlarmItem: WallpaperAlarmItem,
|
||||
origin: Int?,
|
||||
changeImmediate: Boolean,
|
||||
cancelImmediate: Boolean,
|
||||
setAlarm: Boolean,
|
||||
firstLaunch: Boolean
|
||||
) {
|
||||
// Cancel previous alarms before setting new ones to prevent stale alarms
|
||||
if (cancelImmediate) cancelWallpaperAlarm()
|
||||
else {
|
||||
when (origin) {
|
||||
Type.HOME.ordinal -> cancelAlarm(Type.HOME)
|
||||
Type.LOCK.ordinal -> cancelAlarm(Type.LOCK)
|
||||
null -> {
|
||||
cancelAlarm(Type.HOME)
|
||||
cancelAlarm(Type.LOCK)
|
||||
cancelAlarm(Type.SINGLE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Schedule new wallpaper alarm
|
||||
if (wallpaperAlarmItem.scheduleSeparately) {
|
||||
when (origin) {
|
||||
Type.LOCK.ordinal -> {
|
||||
if (changeImmediate) changeWallpaperImmediate(wallpaperAlarmItem, Type.LOCK)
|
||||
if (setAlarm) scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, origin, firstLaunch)
|
||||
}
|
||||
Type.HOME.ordinal -> {
|
||||
if (changeImmediate) changeWallpaperImmediate(wallpaperAlarmItem, Type.HOME)
|
||||
if (setAlarm) scheduleWallpaper(wallpaperAlarmItem, Type.HOME, origin, firstLaunch)
|
||||
}
|
||||
null -> {
|
||||
if (changeImmediate) {
|
||||
changeWallpaperImmediate(wallpaperAlarmItem, Type.LOCK)
|
||||
changeWallpaperImmediate(wallpaperAlarmItem, Type.HOME)
|
||||
}
|
||||
if (setAlarm) {
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, Type.LOCK.ordinal, firstLaunch)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, Type.HOME.ordinal, firstLaunch)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (changeImmediate) changeWallpaperImmediate(wallpaperAlarmItem, Type.SINGLE)
|
||||
if (setAlarm) scheduleWallpaper(wallpaperAlarmItem, Type.SINGLE, null, firstLaunch)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the alarms
|
||||
*/
|
||||
override fun updateWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem, firstLaunch: Boolean) {
|
||||
cancelWallpaperAlarm()
|
||||
if (wallpaperAlarmItem.scheduleSeparately) {
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, null, firstLaunch)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, null, firstLaunch)
|
||||
}
|
||||
else {
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.SINGLE, null, firstLaunch)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the wallpaper without scheduling alarms
|
||||
*/
|
||||
override fun updateWallpaper(scheduleSeparately: Boolean, setHome: Boolean, setLock: Boolean) {
|
||||
if (scheduleSeparately) {
|
||||
updateWallpaper(Type.LOCK, setHome, setLock)
|
||||
updateWallpaper(Type.HOME, setHome, setLock)
|
||||
}
|
||||
else {
|
||||
updateWallpaper(Type.SINGLE, setHome, setLock)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels all active alarms
|
||||
*/
|
||||
override fun cancelWallpaperAlarm(cancelLock: Boolean, cancelHome: Boolean) {
|
||||
if (cancelLock) cancelAlarm(Type.LOCK)
|
||||
if (cancelHome) cancelAlarm(Type.HOME)
|
||||
if (cancelLock && cancelHome) {
|
||||
cancelAlarm(Type.SINGLE)
|
||||
cancelAlarm(Type.REFRESH)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules the wallpaper alarm based on type and time
|
||||
*/
|
||||
private fun scheduleWallpaper(wallpaperAlarmItem: WallpaperAlarmItem, type: Type, origin: Int? = null, firstLaunch: Boolean = false) {
|
||||
val startTime = if (wallpaperAlarmItem.changeStartTime && firstLaunch) {
|
||||
var calculatedStartTime = LocalDateTime.now().withHour(wallpaperAlarmItem.startTime.first).withMinute(wallpaperAlarmItem.startTime.second)
|
||||
if (calculatedStartTime.isBefore(LocalDateTime.now())) {
|
||||
calculatedStartTime = calculatedStartTime.plusDays(1)
|
||||
}
|
||||
calculatedStartTime
|
||||
} else {
|
||||
LocalDateTime.now()
|
||||
}
|
||||
val nextTime = when {
|
||||
wallpaperAlarmItem.changeStartTime && firstLaunch -> startTime
|
||||
type == Type.LOCK && wallpaperAlarmItem.scheduleSeparately -> startTime.plusMinutes(wallpaperAlarmItem.lockInterval.toLong())
|
||||
type == Type.HOME && wallpaperAlarmItem.scheduleSeparately -> startTime.plusMinutes(wallpaperAlarmItem.homeInterval.toLong()).plusSeconds(10)
|
||||
else -> startTime.plusMinutes(wallpaperAlarmItem.homeInterval.toLong())
|
||||
}
|
||||
val intent = Intent(context, WallpaperReceiver::class.java).apply {
|
||||
putExtra("homeInterval", wallpaperAlarmItem.homeInterval)
|
||||
putExtra("lockInterval", wallpaperAlarmItem.lockInterval)
|
||||
putExtra("scheduleSeparately", wallpaperAlarmItem.scheduleSeparately)
|
||||
putExtra("type", type.ordinal)
|
||||
putExtra("setHome", wallpaperAlarmItem.setHome)
|
||||
putExtra("setLock", wallpaperAlarmItem.setLock)
|
||||
putExtra("changeStartTime", wallpaperAlarmItem.changeStartTime)
|
||||
putExtra("startTime", wallpaperAlarmItem.startTime)
|
||||
putExtra("origin", origin)
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
if (!alarmManager.canScheduleExactAlarms()) {
|
||||
cancelWallpaperAlarm()
|
||||
}
|
||||
else {
|
||||
alarmManager.setExactAndAllowWhileIdle(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
nextTime.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
type.ordinal,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
alarmManager.setExactAndAllowWhileIdle(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
nextTime.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
type.ordinal,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a refresh alarm every 24hrs
|
||||
*/
|
||||
fun scheduleRefresh() {
|
||||
cancelAlarm(Type.REFRESH)
|
||||
val intent = Intent(context, WallpaperReceiver::class.java).apply {
|
||||
putExtra("refresh", true)
|
||||
}
|
||||
val nextMidnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0)
|
||||
alarmManager.setAndAllowWhileIdle(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
nextMidnight.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
Type.REFRESH.ordinal,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the service to change the wallpaper
|
||||
*/
|
||||
private fun changeWallpaperImmediate(wallpaperAlarmItem: WallpaperAlarmItem, type: Type) {
|
||||
when (type.ordinal) {
|
||||
Type.SINGLE.ordinal -> {
|
||||
if (wallpaperAlarmItem.setLock) startService(context, LockWallpaperService::class.java, LockWallpaperService.Actions.START.toString(), wallpaperAlarmItem.homeInterval, wallpaperAlarmItem.lockInterval, wallpaperAlarmItem.scheduleSeparately, Type.SINGLE.ordinal)
|
||||
if (wallpaperAlarmItem.setHome) startService(context, HomeWallpaperService::class.java, HomeWallpaperService.Actions.START.toString(), wallpaperAlarmItem.homeInterval, wallpaperAlarmItem.lockInterval, wallpaperAlarmItem.scheduleSeparately, Type.SINGLE.ordinal)
|
||||
}
|
||||
Type.LOCK.ordinal -> {
|
||||
startService(context, LockWallpaperService::class.java, LockWallpaperService.Actions.START.toString(), wallpaperAlarmItem.homeInterval, wallpaperAlarmItem.lockInterval, wallpaperAlarmItem.scheduleSeparately, Type.LOCK.ordinal)
|
||||
}
|
||||
Type.HOME.ordinal -> {
|
||||
startService(context, HomeWallpaperService::class.java, HomeWallpaperService.Actions.START.toString(), wallpaperAlarmItem.homeInterval, wallpaperAlarmItem.lockInterval, wallpaperAlarmItem.scheduleSeparately, Type.HOME.ordinal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the wallpaper without changing the alarm
|
||||
*/
|
||||
private fun updateWallpaper(type: Type, setHome: Boolean, setLock: Boolean) {
|
||||
when (type.ordinal) {
|
||||
Type.SINGLE.ordinal -> {
|
||||
if (setLock) startService(context, LockWallpaperService::class.java, LockWallpaperService.Actions.UPDATE.toString())
|
||||
if (setHome) startService(context, HomeWallpaperService::class.java, HomeWallpaperService.Actions.UPDATE.toString())
|
||||
}
|
||||
Type.LOCK.ordinal -> {
|
||||
startService(context, LockWallpaperService::class.java, LockWallpaperService.Actions.UPDATE.toString())
|
||||
}
|
||||
Type.HOME.ordinal -> {
|
||||
startService(context, HomeWallpaperService::class.java, HomeWallpaperService.Actions.UPDATE.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the alarm based on type
|
||||
*/
|
||||
private fun cancelAlarm(type: Type) {
|
||||
val pendingIntent = PendingIntent.getBroadcast(
|
||||
context,
|
||||
type.ordinal,
|
||||
Intent(context, WallpaperReceiver::class.java),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
alarmManager.cancel(pendingIntent)
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the service to change the wallpaper
|
||||
*/
|
||||
private fun startService(context: Context, serviceClass: Class<*>, action: String, homeInterval: Int? = null, lockInterval: Int? = null, scheduleSeparately: Boolean? = null, type: Int? = null) {
|
||||
val serviceIntent = Intent(context, serviceClass).apply {
|
||||
this.action = action
|
||||
homeInterval?.let { putExtra("homeInterval", it) }
|
||||
lockInterval?.let { putExtra("lockInterval", it) }
|
||||
scheduleSeparately?.let { putExtra("scheduleSeparately", it) }
|
||||
type?.let { putExtra("type", it) }
|
||||
}
|
||||
context.startService(serviceIntent)
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
|
||||
/**
|
||||
* Receiver for boot and time change and wallpaper change events to restart alarm manager
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class WallpaperBootAndChangeReceiver : BroadcastReceiver() {
|
||||
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
@SuppressLint("UnsafeProtectedBroadcastReceiver")
|
||||
override fun onReceive(context: Context, intent: Intent) = goAsync {
|
||||
try {
|
||||
val scheduler = WallpaperAlarmSchedulerImpl(context)
|
||||
val toggleChanger = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false
|
||||
val selectedAlbum = settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME) ?: settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME) ?: ""
|
||||
|
||||
if (selectedAlbum.isNotEmpty()) {
|
||||
val homeInterval = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val lockInterval = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val scheduleSeparately = settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false
|
||||
val setLock = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false
|
||||
val setHome = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
homeInterval = homeInterval,
|
||||
lockInterval = lockInterval,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
setLock = setLock,
|
||||
setHome = setHome
|
||||
)
|
||||
alarmItem.let{
|
||||
scheduler.scheduleWallpaperAlarm(
|
||||
wallpaperAlarmItem = it,
|
||||
origin = null,
|
||||
changeImmediate = true,
|
||||
cancelImmediate = true,
|
||||
setAlarm = toggleChanger
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
/* https://stackoverflow.com/questions/74111692/run-coroutine-functions-on-broadcast-receiver */
|
||||
private fun BroadcastReceiver.goAsync(
|
||||
context: CoroutineContext = EmptyCoroutineContext,
|
||||
block: suspend CoroutineScope.() -> Unit
|
||||
) {
|
||||
val pendingResult = goAsync()
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
GlobalScope.launch(context) {
|
||||
try {
|
||||
block()
|
||||
} finally {
|
||||
pendingResult.finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
|
||||
/**
|
||||
* Receiver for boot and time change events to restart alarm manager
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class WallpaperBootAndTimeChangeReceiver : BroadcastReceiver() {
|
||||
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
override fun onReceive(context: Context, intent: Intent) = goAsync {
|
||||
try {
|
||||
if (Intent.ACTION_BOOT_COMPLETED == intent.action || Intent.ACTION_TIME_CHANGED == intent.action || Intent.ACTION_TIMEZONE_CHANGED == intent.action) {
|
||||
val scheduler = WallpaperScheduler(context)
|
||||
val toggleChanger = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false
|
||||
if (toggleChanger) {
|
||||
val timeInMinutes1 = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val timeInMinutes2 = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val scheduleSeparately = settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
timeInMinutes1 = timeInMinutes1,
|
||||
timeInMinutes2 = timeInMinutes2,
|
||||
scheduleSeparately = scheduleSeparately
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, false, true)}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
/* https://stackoverflow.com/questions/74111692/run-coroutine-functions-on-broadcast-receiver */
|
||||
private fun BroadcastReceiver.goAsync(
|
||||
context: CoroutineContext = EmptyCoroutineContext,
|
||||
block: suspend CoroutineScope.() -> Unit
|
||||
) {
|
||||
val pendingResult = goAsync()
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
GlobalScope.launch(context) {
|
||||
try {
|
||||
block()
|
||||
} finally {
|
||||
pendingResult.finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+58
-31
@@ -3,11 +3,10 @@ package com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
import com.anthonyla.paperize.core.Type
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.WallpaperService1
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.WallpaperService2
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.HomeWallpaperService
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.LockWallpaperService
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
/**
|
||||
@@ -17,37 +16,65 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
class WallpaperReceiver: BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (context != null) {
|
||||
val timeInMinutes1 = intent?.getIntExtra("timeInMinutes1", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val timeInMinutes2 = intent?.getIntExtra("timeInMinutes2", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val scheduleSeparately = intent?.getBooleanExtra("scheduleSeparately", false) ?: false
|
||||
val type = intent?.getIntExtra("type", Type.BOTH.ordinal) ?: Type.BOTH.ordinal
|
||||
val serviceIntent = Intent().apply {
|
||||
putExtra("timeInMinutes1", timeInMinutes1)
|
||||
putExtra("timeInMinutes2", timeInMinutes2)
|
||||
putExtra("scheduleSeparately", scheduleSeparately)
|
||||
putExtra("type", type)
|
||||
}
|
||||
if (type == Type.BOTH.ordinal || type == Type.HOME.ordinal) {
|
||||
serviceIntent.setClass(context, WallpaperService1::class.java).apply {
|
||||
action = WallpaperService1.Actions.START.toString()
|
||||
}
|
||||
} else {
|
||||
serviceIntent.setClass(context, WallpaperService2::class.java).apply {
|
||||
action = WallpaperService2.Actions.START.toString()
|
||||
if (intent?.getBooleanExtra("refresh", false) == true) {
|
||||
val serviceIntent = Intent(context, HomeWallpaperService::class.java).apply {
|
||||
action = HomeWallpaperService.Actions.REFRESH.toString()
|
||||
}
|
||||
context.startService(serviceIntent)
|
||||
WallpaperAlarmSchedulerImpl(context).scheduleRefresh()
|
||||
}
|
||||
context.startService(serviceIntent)
|
||||
else {
|
||||
val homeInterval = intent?.getIntExtra("homeInterval", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val lockInterval = intent?.getIntExtra("lockInterval", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val scheduleSeparately = intent?.getBooleanExtra("scheduleSeparately", false) ?: false
|
||||
val type = intent?.getIntExtra("type", Type.SINGLE.ordinal) ?: Type.SINGLE.ordinal
|
||||
val setHome = intent?.getBooleanExtra("setHome", false) ?: false
|
||||
val setLock = intent?.getBooleanExtra("setLock", false) ?: false
|
||||
val changeStartTime = intent?.getBooleanExtra("changeStartTime", false) ?: false
|
||||
val startTime = intent?.getIntArrayExtra("startTime") ?: intArrayOf(0, 0)
|
||||
|
||||
// Schedule next alarm for next wallpaper change
|
||||
val origin = intent?.getIntExtra("origin", -1)?.takeIf { it != -1 }
|
||||
WallpaperScheduler(context).scheduleWallpaperAlarm(
|
||||
WallpaperAlarmItem(
|
||||
timeInMinutes1 = timeInMinutes1,
|
||||
timeInMinutes2 = timeInMinutes2,
|
||||
scheduleSeparately = scheduleSeparately
|
||||
),
|
||||
origin
|
||||
)
|
||||
when (type) {
|
||||
Type.SINGLE.ordinal -> {
|
||||
if (setLock) startService(context, LockWallpaperService::class.java, LockWallpaperService.Actions.START.toString(), homeInterval, lockInterval, scheduleSeparately, type)
|
||||
if (setHome) startService(context, HomeWallpaperService::class.java, HomeWallpaperService.Actions.START.toString(), homeInterval, lockInterval, scheduleSeparately, type)
|
||||
}
|
||||
Type.HOME.ordinal -> {
|
||||
startService(context, HomeWallpaperService::class.java, HomeWallpaperService.Actions.START.toString(), homeInterval, lockInterval, scheduleSeparately, type)
|
||||
}
|
||||
Type.LOCK.ordinal -> {
|
||||
startService(context, LockWallpaperService::class.java, LockWallpaperService.Actions.START.toString(), homeInterval, lockInterval, scheduleSeparately, type)
|
||||
}
|
||||
}
|
||||
|
||||
// Schedule next alarm for next wallpaper change
|
||||
val origin = intent?.getIntExtra("origin", -1)?.takeIf { it != -1 }
|
||||
WallpaperAlarmSchedulerImpl(context).scheduleWallpaperAlarm(
|
||||
WallpaperAlarmItem(
|
||||
homeInterval = homeInterval,
|
||||
lockInterval = lockInterval,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
changeStartTime = changeStartTime,
|
||||
startTime = Pair(startTime[0], startTime[1]),
|
||||
),
|
||||
origin
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the service to change the wallpaper
|
||||
*/
|
||||
private fun startService(context: Context, serviceClass: Class<*>, action: String, homeInterval: Int? = null, lockInterval: Int? = null, scheduleSeparately: Boolean? = null, type: Int? = null) {
|
||||
val serviceIntent = Intent(context, serviceClass).apply {
|
||||
this.action = action
|
||||
homeInterval?.let { putExtra("homeInterval", it) }
|
||||
lockInterval?.let { putExtra("lockInterval", it) }
|
||||
scheduleSeparately?.let { putExtra("scheduleSeparately", it) }
|
||||
type?.let { putExtra("type", it) }
|
||||
}
|
||||
context.startService(serviceIntent)
|
||||
}
|
||||
}
|
||||
Loaded 100 of 175 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user