Compare commits
416
Commits
v0.1.0-alpha
...
v2.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c7ae9771a | ||
|
|
f1c6f3e36f | ||
|
|
a04da0801a | ||
|
|
9ef38cb086 | ||
|
|
3fe29db05b | ||
|
|
09626a9226 | ||
|
|
e822b18624 | ||
|
|
5bb7ba9399 | ||
|
|
c794ea0b60 | ||
|
|
4a72f8dbc0 | ||
|
|
ef61d3b028 | ||
|
|
ead7bd36fe | ||
|
|
240f30b187 | ||
|
|
24eb0bc20c | ||
|
|
b0bf5d875a | ||
|
|
cea07a185b | ||
|
|
2db9a330ad | ||
|
|
3f952796a3 | ||
|
|
350addbefa | ||
|
|
23c8a82390 | ||
|
|
c063814b93 | ||
|
|
3c4fa741c6 | ||
|
|
49da709574 | ||
|
|
177f3e21bf | ||
|
|
82ce78fc0e | ||
|
|
346a4640c1 | ||
|
|
d9998715cb | ||
|
|
842a77b8c5 | ||
|
|
4b235d07ba | ||
|
|
f615dfe527 | ||
|
|
92e530432f | ||
|
|
4a0f0f371a | ||
|
|
333d0692e8 | ||
|
|
241d0ce861 | ||
|
|
77d2deae0c | ||
|
|
7cc31f43b1 | ||
|
|
bdd89a27b9 | ||
|
|
77481770a6 | ||
|
|
c9f616e1c0 | ||
|
|
167f82edea | ||
|
|
8032f13f0e | ||
|
|
71fe478d54 | ||
|
|
e3af22bbeb | ||
|
|
87ee6b7041 | ||
|
|
b6b26f6732 | ||
|
|
ab1a9ab5af | ||
|
|
0fe8dc724e | ||
|
|
b5836bea95 | ||
|
|
3fd427afc1 | ||
|
|
d2bd26ba38 | ||
|
|
6ffeebb6a2 | ||
|
|
ccd4bab93d | ||
|
|
bbaa0cf9ee | ||
|
|
19b65999fd | ||
|
|
04ef14e5f1 | ||
|
|
c500fb773e | ||
|
|
8c325ed5de | ||
|
|
4fde150bbe | ||
|
|
cebb14e60b | ||
|
|
0fc6a38b12 | ||
|
|
17340fb74e | ||
|
|
9ec4c5d20b | ||
|
|
a8164da137 | ||
|
|
886b7cb27e | ||
|
|
9f67243f0d | ||
|
|
78d7e0972b | ||
|
|
683f434030 | ||
|
|
df0ac6191f | ||
|
|
1d3ad86341 | ||
|
|
bac5c662ef | ||
|
|
8d447f0068 | ||
|
|
7a2b67ed57 | ||
|
|
c55b8f44f0 | ||
|
|
43806aa694 | ||
|
|
90efcaaae1 | ||
|
|
8fdb0920e6 | ||
|
|
e74f6a258a | ||
|
|
54e8b1816f | ||
|
|
efa3cbc6e1 | ||
|
|
12165d41c2 | ||
|
|
fe3aa1bda8 | ||
|
|
83ae1c721e | ||
|
|
50cae3e04e | ||
|
|
e6b2a2af18 | ||
|
|
02671c0804 | ||
|
|
a3c57bf6ef | ||
|
|
72c8d1313f | ||
|
|
89ca480c0c | ||
|
|
b2a6b17c5a | ||
|
|
a6926f25bc | ||
|
|
335a3f7084 | ||
|
|
58c35c1bbb | ||
|
|
27000d9fa2 | ||
|
|
c5ed7684cf | ||
|
|
d8b92d5cdb | ||
|
|
c7989db3c7 | ||
|
|
353e3c3610 | ||
|
|
2d35dc0620 | ||
|
|
5a1f11ba4f | ||
|
|
c1de9ec1a9 | ||
|
|
b02bb044a3 | ||
|
|
002ad6e4f9 | ||
|
|
c05ea1ced5 | ||
|
|
6537ecfac7 | ||
|
|
0d8fee5929 | ||
|
|
9563bf2057 | ||
|
|
7b75db3437 | ||
|
|
6273412d9e | ||
|
|
87f71c599c | ||
|
|
3261862c7d | ||
|
|
afadfc0d2d | ||
|
|
f6fdaf1673 | ||
|
|
7e21d6c564 | ||
|
|
89c0bb3b1b | ||
|
|
f18b751714 | ||
|
|
250817ffbf | ||
|
|
5e52b7098d | ||
|
|
ffdbf54561 | ||
|
|
b11d89ceda | ||
|
|
045ee268e1 | ||
|
|
f5915bff31 | ||
|
|
d153ec969e | ||
|
|
bfcabe29c0 | ||
|
|
08c71e275e | ||
|
|
d211b6416c | ||
|
|
010a197b94 | ||
|
|
bd4a809cac | ||
|
|
cd5c53a662 | ||
|
|
5e6211035c | ||
|
|
2260f7032c | ||
|
|
1cab7cca82 | ||
|
|
018aa9d3a9 | ||
|
|
423e65990f | ||
|
|
644e2ace3c | ||
|
|
e61a1dc7f4 | ||
|
|
03378e6947 | ||
|
|
0d22efa21b | ||
|
|
72175fd7b2 | ||
|
|
94576238c4 | ||
|
|
6dda721a0b | ||
|
|
9db120bce9 | ||
|
|
1c48dcd01d | ||
|
|
62b296a293 | ||
|
|
5ad27fd477 | ||
|
|
d846384bdc | ||
|
|
5c18fa1074 | ||
|
|
9b13a2158a | ||
|
|
6edbc2560f | ||
|
|
3a1f53b7fc | ||
|
|
cad7839a36 | ||
|
|
219121f400 | ||
|
|
3afbb1dbe0 | ||
|
|
d39a670e4d | ||
|
|
7036b17b93 | ||
|
|
624c9c3dbb | ||
|
|
99cc362fdb | ||
|
|
92563b84ec | ||
|
|
873d68a715 | ||
|
|
7c3c64149a | ||
|
|
7615d7786a | ||
|
|
064237bed4 | ||
|
|
e8f8a145ea | ||
|
|
b03e860dee | ||
|
|
359c4b40e9 | ||
|
|
c4852b3830 | ||
|
|
e006bea84e | ||
|
|
766d54cc13 | ||
|
|
f9b6a96fc5 | ||
|
|
4467aa9085 | ||
|
|
9240a89663 | ||
|
|
c15bea8b37 | ||
|
|
e58de859cd | ||
|
|
22a219e985 | ||
|
|
7823fe0327 | ||
|
|
d0d48f4ad1 | ||
|
|
cd1ed25ba1 | ||
|
|
9e864858c0 | ||
|
|
d72596f3a0 | ||
|
|
f56d0c7d1b | ||
|
|
98e0b4ae2f | ||
|
|
8cb643b8c9 | ||
|
|
0df52203be | ||
|
|
7cf4f85b0d | ||
|
|
e89403dff3 | ||
|
|
9a63bffca9 | ||
|
|
b8a14332c5 | ||
|
|
65342ed8f5 | ||
|
|
f76313b998 | ||
|
|
6e821e9db4 | ||
|
|
696ec185bf | ||
|
|
3f7cfcd079 | ||
|
|
38c5b91eb2 | ||
|
|
2138c0b22c | ||
|
|
c32ffbae68 | ||
|
|
100422fc63 | ||
|
|
3f7984808c | ||
|
|
524baa1271 | ||
|
|
b0fe869954 | ||
|
|
e88f83dd15 | ||
|
|
2b9ed09211 | ||
|
|
9278dd1e76 | ||
|
|
a2f66c29be | ||
|
|
086ca2e049 | ||
|
|
6a8648728b | ||
|
|
5e796605be | ||
|
|
abe1d10440 | ||
|
|
adddb21fbf | ||
|
|
67ad5f3bad | ||
|
|
0cf2302d00 | ||
|
|
e23b95b514 | ||
|
|
ba8fe59bf0 | ||
|
|
380328b401 | ||
|
|
15fc31b131 | ||
|
|
65972a9ae6 | ||
|
|
5351f95cf4 | ||
|
|
e0bc6ccb22 | ||
|
|
58b82e87be | ||
|
|
54c7066a4a | ||
|
|
da2e085e7b | ||
|
|
69e9f91814 | ||
|
|
edfc942a6d | ||
|
|
71f8ee26de | ||
|
|
02ac267c27 | ||
|
|
8ae92ef552 | ||
|
|
4006671f99 | ||
|
|
a19ac36801 | ||
|
|
86d718b5f5 | ||
|
|
e95c923a6a | ||
|
|
ee0a04bf09 | ||
|
|
4f7129f5f4 | ||
|
|
4e5f0d63cc | ||
|
|
c40e70d18e | ||
|
|
b3ca913921 | ||
|
|
99bdcf6637 | ||
|
|
8f8650ef7c | ||
|
|
da2747306b | ||
|
|
bb7dc87027 | ||
|
|
4464cbf7f0 | ||
|
|
c33d567a6a | ||
|
|
2c626db54f | ||
|
|
fec52ca412 | ||
|
|
2cece3dc05 | ||
|
|
37e85c4a6b | ||
|
|
b9f3f158b0 | ||
|
|
e9c4c41d3e | ||
|
|
f2b87a5e0e | ||
|
|
6175338b99 | ||
|
|
729b5bd45a | ||
|
|
5139692f2c | ||
|
|
d6bd048012 | ||
|
|
ca839b2e1f | ||
|
|
02ba6f986b | ||
|
|
417cabcaeb | ||
|
|
5218dd4174 | ||
|
|
35836d7778 | ||
|
|
be9cb13971 | ||
|
|
2a7191b7be | ||
|
|
4b930308f8 | ||
|
|
2567781e63 | ||
|
|
13485cb19c | ||
|
|
eae4e344b6 | ||
|
|
e5fab5cb5e | ||
|
|
5fd233e790 | ||
|
|
48a730e4a9 | ||
|
|
4c3d5af7f7 | ||
|
|
829d982d23 | ||
|
|
b01b9a87d6 | ||
|
|
c4395b364c | ||
|
|
dc1f8b9802 | ||
|
|
4279dd3be7 | ||
|
|
373f784fb6 | ||
|
|
fe12b2116c | ||
|
|
9f906aa11c | ||
|
|
e20b3c7c49 | ||
|
|
9bab8ad4b6 | ||
|
|
31b976c258 | ||
|
|
660116fb60 | ||
|
|
984e34f425 | ||
|
|
cd06c87263 | ||
|
|
633ae66a80 | ||
|
|
005843ec00 | ||
|
|
4327a94c14 | ||
|
|
fb4ffea292 | ||
|
|
7570ab5405 | ||
|
|
8899c5c743 | ||
|
|
cc69b4b63b | ||
|
|
0f77761380 | ||
|
|
cdf124319f | ||
|
|
63fe703a6d | ||
|
|
84043b06e7 | ||
|
|
bf35b34ce2 | ||
|
|
1cde08bef6 | ||
|
|
e37f7e36db | ||
|
|
e6c6184c9d | ||
|
|
512637b23c | ||
|
|
398e43469f | ||
|
|
1f5cab1d5b | ||
|
|
a185c727a2 | ||
|
|
28b9a74c3d | ||
|
|
2e8d8b8603 | ||
|
|
a0a4bc9e4e | ||
|
|
97c23f9d44 | ||
|
|
bde2f7dd1f | ||
|
|
d005102716 | ||
|
|
953dc65428 | ||
|
|
69f8a09ceb | ||
|
|
bf56df28fa | ||
|
|
3e49bc1836 | ||
|
|
ad069e5e9f | ||
|
|
5adfac4db2 | ||
|
|
1ecfa1566f | ||
|
|
724cb5e9f5 | ||
|
|
69a9f36100 | ||
|
|
450dfed0a3 | ||
|
|
c1404ec522 | ||
|
|
bcff2f338f | ||
|
|
5582a5851f | ||
|
|
1d0794d135 | ||
|
|
0e20f211f2 | ||
|
|
6f4a2bec97 | ||
|
|
85e5e3007b | ||
|
|
4760ab01d5 | ||
|
|
d8fc106a89 | ||
|
|
f4bf2786de | ||
|
|
c2e7e38f97 | ||
|
|
343d358d22 | ||
|
|
c219aa2b30 | ||
|
|
5ba325b93f | ||
|
|
dc1a65f234 | ||
|
|
48a198091e | ||
|
|
81020c9ba0 | ||
|
|
c47f3957bf | ||
|
|
68e94fe284 | ||
|
|
265edf8f63 | ||
|
|
322a10bf0c | ||
|
|
f6688c84ab | ||
|
|
62a5934220 | ||
|
|
64dedae516 | ||
|
|
1ff2539574 | ||
|
|
219a4cdb52 | ||
|
|
322e6907ab | ||
|
|
c39527b3b5 | ||
|
|
068f78f86c | ||
|
|
87ef7ebaf0 | ||
|
|
996208b03d | ||
|
|
ec54bbb8c5 | ||
|
|
b52a47770d | ||
|
|
61e3144de4 | ||
|
|
895af4f865 | ||
|
|
c956f6a3e3 | ||
|
|
d52effa343 | ||
|
|
4313e4a442 | ||
|
|
9ecc96e92b | ||
|
|
3df28a3a9a | ||
|
|
fff8b241c0 | ||
|
|
46d1284550 | ||
|
|
25717d83fd | ||
|
|
bca711a50d | ||
|
|
0449a93b31 | ||
|
|
58b24e50ff | ||
|
|
0cc477b7e8 | ||
|
|
4117ffb90a | ||
|
|
a8302ff3e2 | ||
|
|
5d9e87ff63 | ||
|
|
9a5b40ba7f | ||
|
|
dab5e4fe97 | ||
|
|
a635595ade | ||
|
|
f6fb087104 | ||
|
|
e3f56445d8 | ||
|
|
d8d6d4897d | ||
|
|
626b0a4de5 | ||
|
|
742d14ae3b | ||
|
|
a58a0c1e9a | ||
|
|
7b216d5534 | ||
|
|
65e4f38f83 | ||
|
|
fe43b4f631 | ||
|
|
7aab2a39d9 | ||
|
|
162d73e4e0 | ||
|
|
0f49241d7b | ||
|
|
df1bc642fc | ||
|
|
8eb9cb2aaa | ||
|
|
3f412f4724 | ||
|
|
047d519e80 | ||
|
|
b4041cc8ea | ||
|
|
fc57f14d2a | ||
|
|
4fd1e06b8e | ||
|
|
6a08e0eff9 | ||
|
|
d7edb40a9b | ||
|
|
ac889ed7b1 | ||
|
|
c97f9f7e3d | ||
|
|
4429355a1e | ||
|
|
00fbdf1e42 | ||
|
|
48aefd2aaa | ||
|
|
2c3330742e | ||
|
|
8022aa0f01 | ||
|
|
10397bbbbf | ||
|
|
379d6b21be | ||
|
|
41b32f3154 | ||
|
|
1906a3f170 | ||
|
|
f9207309a8 | ||
|
|
ca31e655ac | ||
|
|
047b2197e0 | ||
|
|
685168b0a6 | ||
|
|
d0fd31cf8c | ||
|
|
30783c6806 | ||
|
|
96f2a1337e | ||
|
|
e0c0fee8f0 | ||
|
|
060e1b8a07 | ||
|
|
19fc3a34e3 | ||
|
|
18582c2291 | ||
|
|
ea9977c511 | ||
|
|
c84b1c47ea | ||
|
|
902be61924 | ||
|
|
e9f6861d60 | ||
|
|
8f0c5aa309 | ||
|
|
a32ca75126 |
No files matched your search
@@ -0,0 +1,14 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: Anthonyy232
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
polar: # Replace with a single Polar username
|
||||
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: "[Bug] <BUG_NAME>"
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Smartphone (please complete the following information):**
|
||||
- Device: [e.g. Pixel 32 Pro]
|
||||
- OS: [e.g. OneUI 21]
|
||||
- Version [e.g. v2.1.0]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: "[Feature request] <FEATURE_NAME>"
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
@@ -0,0 +1,43 @@
|
||||
# Simple workflow for deploying static content to GitHub Pages
|
||||
name: Deploy static content to Pages
|
||||
|
||||
on:
|
||||
# Runs on pushes targeting the default branch
|
||||
push:
|
||||
branches: ["master"]
|
||||
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
|
||||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
|
||||
concurrency:
|
||||
group: "pages"
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
# Single deploy job since we're just deploying
|
||||
deploy:
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Pages
|
||||
uses: actions/configure-pages@v5
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
# Upload entire repository
|
||||
path: '.'
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
@@ -1,5 +1,6 @@
|
||||
*.iml
|
||||
.gradle
|
||||
.idea
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
@@ -13,3 +14,8 @@
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
local.properties
|
||||
/app/build
|
||||
/app/release
|
||||
/app/schemas
|
||||
.kotlin
|
||||
/.kotlin/sessions
|
||||
Generated
-3
@@ -1,3 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
Generated
-1
@@ -1 +0,0 @@
|
||||
Paperize
|
||||
Generated
-26
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AppInsightsSettings">
|
||||
<option name="tabSettings">
|
||||
<map>
|
||||
<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-24T06:32:43.708081Z" />
|
||||
</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
-6
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="1.9.0" />
|
||||
</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,59 +1,75 @@
|
||||
<div align="center">
|
||||
<h1>Paperize</h1>
|
||||
<p align="center">
|
||||
</p>
|
||||
</p>
|
||||
<p>Paperize is a dynamic wallpaper changer application designed to keep your device's aesthetic fresh and exciting</p>
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
<img style="display: block; border-radius: 9999px;" src="https://github.com/user-attachments/assets/e8fb14f5-ec8e-440e-a2ac-8065322b0e28">
|
||||
<h1>
|
||||
Paperize
|
||||
<p><img style="display: block; border-radius: 9999px;" src="https://img.shields.io/github/downloads/Anthonyy232/Paperize/total"></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>
|
||||
|
||||
|
||||
## Features
|
||||
- **Dynamic Wallpaper Changer**: Set your wallpaper to change at specific time intervals
|
||||
- **Supports Various Image Types**: Paperize can handle a wide range of image types, offering you flexibility in your wallpaper choices
|
||||
- **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/eebec922-70a6-4d54-97d9-ab02cbfb7a36" width="30%" alt="onboarding" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/60a4d68d-5e19-49f2-8822-e702d02651c6" width="30%" alt="wallpaper" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/e106c0dc-23ff-4f4a-adfc-5ebe93219ae0" width="30%" alt="album" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/7093a1ea-91ab-4da8-a82b-43e24d88d376" width="30%" alt="settings" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/54ebd285-8da4-4446-83f1-ba0e7ee9476d" width="30%" alt="adding" />
|
||||
<img src="https://github.com/Anthonyy232/Paperize/assets/60626873/57122f72-78f8-45ed-a9ac-de943061d6a2" width="30%" alt="onboarding" />
|
||||
<img src="https://github.com/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/user-attachments/assets/d23f290d-bb2c-4b89-9321-b426e45864f9" width="30%" alt="settings" />
|
||||
<br/>
|
||||
<video controls src="https://github.com/user-attachments/assets/ce7f5c7c-66a7-45fc-bb28-a53d8d9cf733" muted="true"></video>
|
||||
</div>
|
||||
|
||||
|
||||
## 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)
|
||||
|
||||
Playstore and F-Droid will be added soon
|
||||
## Localization
|
||||
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)!
|
||||
|
||||
[](https://crowdin.com/project/paperize)
|
||||
|
||||
## Technologies
|
||||
|
||||
- [Kotlin]([https://kotlinlang.org/) - A programming language that is used for Android app development
|
||||
- [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
|
||||
- [Lottie Compose](https://github.com/airbnb/lottie) - A library that provides Lottie animation support for Jetpack Compose
|
||||
- [Landscapist](https://github.com/skydoves/landscapist) - A Compose and KPP image loading library that streamlines Glide, Coil, and Fresco
|
||||
- [Zoomable](https://github.com/usuiat/Zoomable) - A library that provides a zoomable and pannable view, which can be used with any view you want
|
||||
- [AnimatedFABMenu](https://github.com/rajaumair7890/AnimatedFABMenu) - A animated floating action button with Material 3 design
|
||||
- [DocumentFileCompat](https://github.com/ItzNotABug/DocumentFileCompat) - A DocumentFile wrapper that caches the result to improve efficiency
|
||||
- [LazyColumnScrollbar](https://github.com/nanihadesuka/LazyColumnScrollbar) - A Jetpack Compose scrollbar library
|
||||
|
||||
Thanks to the creators and maintainers of the open-source libraries used in this project.
|
||||
|
||||
|
||||
## Build
|
||||
|
||||
This project is built using Kotlin, Java, and Gradle. Here are the steps to build the project:
|
||||
|
||||
### Prerequisites
|
||||
- Java 8 (1.8)
|
||||
- Android Studio Iguana | 2023.2.1 or later
|
||||
- Gradle 8.3.2 or later
|
||||
- Android Studio Jellyfish | 2024.1.1 or later
|
||||
- Android Gradle Plugin 8.5.1 or later
|
||||
- Gradle 8.9
|
||||
- Minimum SDK 26
|
||||
|
||||
### Steps
|
||||
@@ -67,8 +83,14 @@ This project is built using Kotlin, Java, and Gradle. Here are the steps to buil
|
||||
|
||||
All contributions to the app is welcome. Feel free to report any issues and create pull requests for any issues or pull requests.
|
||||
|
||||
Inspiration from j4velin for their wallpaper changer app
|
||||
|
||||
## 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
|
||||
|
||||
Paperize © GNU GPL v3.0
|
||||
[Anthony La](https://github.com/Anthonyy232) © GNU GPL v3.0
|
||||
+76
-40
@@ -3,22 +3,24 @@ plugins {
|
||||
id("org.jetbrains.kotlin.android")
|
||||
id("com.google.devtools.ksp")
|
||||
id("com.google.dagger.hilt.android")
|
||||
id ("com.mikepenz.aboutlibraries.plugin")
|
||||
id("com.mikepenz.aboutlibraries.plugin")
|
||||
id("org.jetbrains.kotlin.plugin.serialization")
|
||||
id("org.jetbrains.kotlin.plugin.compose")
|
||||
}
|
||||
ksp {
|
||||
arg("room.schemaLocation", "$projectDir/schemas")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.anthonyla.paperize"
|
||||
compileSdk = 34
|
||||
compileSdk = 35
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.anthonyla.paperize"
|
||||
minSdk = 26
|
||||
targetSdk = 34
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
|
||||
targetSdk = 35
|
||||
versionCode = 31
|
||||
versionName = "2.2.0"
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
useSupportLibrary = true
|
||||
@@ -32,21 +34,45 @@ android {
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
ndk {
|
||||
debugSymbolLevel = "FULL"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
freeCompilerArgs += strongSkippingConfiguration()
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
compose = true
|
||||
viewBinding = true
|
||||
buildConfig = true
|
||||
}
|
||||
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion = "1.5.1"
|
||||
kotlinCompilerExtensionVersion = "1.5.15"
|
||||
}
|
||||
|
||||
androidResources {
|
||||
generateLocaleConfig = true
|
||||
}
|
||||
|
||||
ndkVersion = "26.3.11579264"
|
||||
buildToolsVersion = "34.0.0"
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
includeInBundle = false
|
||||
}
|
||||
|
||||
aboutLibraries {
|
||||
excludeFields = arrayOf("generated")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,44 +83,54 @@ androidComponents {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("androidx.core:core-ktx:1.13.0")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
|
||||
implementation("androidx.activity:activity-compose:1.9.0")
|
||||
implementation(platform("androidx.compose:compose-bom:2024.04.01"))
|
||||
implementation("androidx.compose.ui:ui:1.6.6")
|
||||
implementation("androidx.compose.ui:ui-graphics:1.6.6")
|
||||
implementation("androidx.compose.ui:ui-tooling-preview:1.6.6")
|
||||
implementation("androidx.compose.material3:material3:1.2.1")
|
||||
implementation("androidx.navigation:navigation-compose:2.8.0-alpha07")
|
||||
implementation("androidx.compose.material:material:1.6.6")
|
||||
implementation("androidx.datastore:datastore:1.1.0")
|
||||
implementation("androidx.datastore:datastore-preferences:1.1.0")
|
||||
implementation("androidx.compose.material:material-icons-extended:1.6.6")
|
||||
implementation("com.google.accompanist:accompanist-adaptive:0.34.0")
|
||||
implementation("androidx.core:core-ktx:1.13.1")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.6")
|
||||
implementation("androidx.activity:activity-compose:1.9.2")
|
||||
implementation(platform("androidx.compose:compose-bom:2024.09.02"))
|
||||
implementation("androidx.compose.ui:ui:1.7.2")
|
||||
implementation("androidx.compose.ui:ui-graphics:1.7.2")
|
||||
implementation("androidx.compose.ui:ui-tooling-preview:1.7.2")
|
||||
implementation("androidx.compose.material3:material3:1.3.0")
|
||||
implementation("androidx.navigation:navigation-compose:2.8.1")
|
||||
implementation("androidx.compose.material:material:1.7.2")
|
||||
implementation("androidx.datastore:datastore:1.1.1")
|
||||
implementation("androidx.datastore:datastore-preferences:1.1.1")
|
||||
implementation("androidx.compose.material:material-icons-extended:1.7.2")
|
||||
implementation("androidx.hilt:hilt-navigation-compose:1.2.0")
|
||||
implementation("androidx.compose.animation:animation:1.7.0-alpha07")
|
||||
implementation("androidx.core:core-splashscreen:1.1.0-rc01")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0")
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
implementation("androidx.compose.animation:animation:1.7.2")
|
||||
implementation("androidx.core:core-splashscreen:1.2.0-alpha02")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.6")
|
||||
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("net.engawapg.lib:zoomable:2.0.0-beta01")
|
||||
implementation("com.github.skydoves:landscapist-glide:2.3.8")
|
||||
implementation("androidx.work:work-runtime-ktx:2.10.0-alpha04")
|
||||
implementation("androidx.hilt:hilt-work:1.2.0")
|
||||
implementation("com.airbnb.android:lottie-compose:6.4.0")
|
||||
implementation("com.google.accompanist:accompanist-permissions:0.35.0-alpha")
|
||||
implementation("com.mikepenz:aboutlibraries-core:11.1.3")
|
||||
implementation("com.mikepenz:aboutlibraries-compose-m3:11.1.3")
|
||||
implementation("com.airbnb.android:lottie-compose:6.5.2")
|
||||
implementation("com.google.accompanist:accompanist-permissions:0.36.0")
|
||||
implementation("com.mikepenz:aboutlibraries-core:11.2.3")
|
||||
implementation("com.mikepenz:aboutlibraries-compose-m3:11.2.3")
|
||||
implementation("androidx.compose.foundation:foundation:1.7.2")
|
||||
implementation("com.github.nanihadesuka:LazyColumnScrollbar:2.2.0")
|
||||
implementation("com.joaomgcd:taskerpluginlibrary:0.4.10")
|
||||
implementation("com.google.ar.sceneform:filament-android:1.17.1")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.0-alpha03")
|
||||
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.6.6")
|
||||
debugImplementation("androidx.compose.ui:ui-tooling:1.6.6")
|
||||
debugImplementation("androidx.compose.ui:ui-test-manifest:1.6.6")
|
||||
implementation("com.google.dagger:hilt-android:2.51.1")
|
||||
ksp("com.google.dagger:hilt-android-compiler:2.51.1")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.2.1")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
|
||||
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.7.2")
|
||||
debugImplementation("androidx.compose.ui:ui-tooling:1.7.2")
|
||||
debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.2")
|
||||
implementation("com.google.dagger:hilt-android:2.52")
|
||||
ksp("com.google.dagger:hilt-android-compiler:2.52")
|
||||
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.7.3")
|
||||
implementation("com.github.android:renderscript-intrinsics-replacement-toolkit:b6363490c3")
|
||||
}
|
||||
|
||||
private fun strongSkippingConfiguration() = listOf(
|
||||
"-P",
|
||||
"plugin:androidx.compose.compiler.plugins.kotlin:experimentalStrongSkipping=true",
|
||||
)
|
||||
Vendored
+2
-2
@@ -14,7 +14,7 @@
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
@@ -26,7 +26,7 @@
|
||||
-keepclassmembers class com.anthonyla.paperize.feature.wallpaper.domain.model.Album {
|
||||
!transient <fields>;
|
||||
}
|
||||
-keepclassmembers class com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper {
|
||||
-keepclassmembers class com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder {
|
||||
!transient <fields>;
|
||||
}
|
||||
-keepclassmembers class com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper {
|
||||
|
||||
@@ -2,43 +2,72 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-feature
|
||||
android:name="android.software.paperize"
|
||||
android:required="true" />
|
||||
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" tools:node="remove"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:allowBackup="false"
|
||||
android:name=".App"
|
||||
android:persistent="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:icon="@mipmap/app_icon"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Paperize"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
tools:targetApi="tiramisu">
|
||||
android:theme="@style/Theme.Paperize" tools:targetApi="tiramisu">
|
||||
<activity
|
||||
android:name=".feature.wallpaper.presentation.MainActivity"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.Paperize">
|
||||
<intent-filter>
|
||||
<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>
|
||||
<service android:name=".feature.wallpaper.wallpaperservice.WallpaperService" android:foregroundServiceType="mediaPlayback"/>
|
||||
<receiver android:name=".feature.wallpaper.wallpaperservice.WallpaperBootReceiver"
|
||||
android:exported="true">
|
||||
<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.HomeWallpaperService"/>
|
||||
<service android:name=".feature.wallpaper.wallpaper_service.LockWallpaperService"/>
|
||||
<service
|
||||
android:name=".feature.wallpaper.wallpaper_tile.ChangeWallpaperTileService"
|
||||
android:exported="true"
|
||||
android:label="@string/change_wallpaper"
|
||||
android:icon="@drawable/notification_icon"
|
||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||
<intent-filter> <action android:name="android.service.quicksettings.action.QS_TILE" /> </intent-filter>
|
||||
</service>
|
||||
<receiver android:name=".feature.wallpaper.wallpaper_alarmmanager.WallpaperBootAndChangeReceiver"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.TIME_SET" />
|
||||
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<provider
|
||||
android:name="androidx.startup.InitializationProvider"
|
||||
android:authorities="${applicationId}.androidx-startup"
|
||||
android:exported="false"
|
||||
tools:node="merge">
|
||||
<meta-data android:name="androidx.emoji2.text.EmojiCompatInitializer"
|
||||
tools:node="remove" />
|
||||
</provider>
|
||||
<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>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -4,7 +4,6 @@ import android.app.Application
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.anthonyla.paperize.core
|
||||
|
||||
enum class ScalingConstants {
|
||||
FIT,
|
||||
FILL,
|
||||
STRETCH,
|
||||
NONE
|
||||
}
|
||||
@@ -6,12 +6,37 @@ 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 WALLPAPER_CHANGE_INTERVAL = "wallpaper_change_interval"
|
||||
const val ENABLE_CHANGER = "enable_changer"
|
||||
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 SET_LOCK_WITH_HOME = "set_lock_with_home"
|
||||
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 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 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"
|
||||
}
|
||||
@@ -0,0 +1,482 @@
|
||||
package com.anthonyla.paperize.core
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.ColorMatrix
|
||||
import android.graphics.ColorMatrixColorFilter
|
||||
import android.graphics.ImageDecoder
|
||||
import android.graphics.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, SINGLE, REFRESH }
|
||||
|
||||
/**
|
||||
* Get the dimensions of the image from the uri
|
||||
*/
|
||||
fun Uri.getImageDimensions(context: Context): Size? {
|
||||
return try {
|
||||
context.contentResolver.openInputStream(this)?.use { inputStream ->
|
||||
val exif = ExifInterface(inputStream)
|
||||
var width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0)
|
||||
var height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0)
|
||||
if (width == 0 || height == 0) {
|
||||
val options = BitmapFactory.Options().apply {
|
||||
inJustDecodeBounds = true
|
||||
}
|
||||
BitmapFactory.decodeStream(
|
||||
context.contentResolver.openInputStream(this),
|
||||
null,
|
||||
options
|
||||
)
|
||||
width = options.outWidth
|
||||
height = options.outHeight
|
||||
}
|
||||
Size(width, height)
|
||||
}
|
||||
} 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 {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale a bitmap using the fit width method
|
||||
* The bitmap will fit into the given width while maintaining the same aspect ratio
|
||||
*/
|
||||
fun fitBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
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 fit method
|
||||
*/
|
||||
fun fillBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
return try {
|
||||
val aspectRatio = source.width.toFloat() / source.height.toFloat()
|
||||
val newWidth: Int
|
||||
val newHeight: Int
|
||||
if (width > height * aspectRatio) {
|
||||
newWidth = width
|
||||
newHeight = (width / aspectRatio).toInt()
|
||||
} else {
|
||||
newHeight = height
|
||||
newWidth = (height * aspectRatio).toInt()
|
||||
}
|
||||
val scaledBitmap = Bitmap.createScaledBitmap(source, newWidth, newHeight, true)
|
||||
val x = ((width - newWidth) / 2f)
|
||||
val y = ((height - newHeight) / 2f)
|
||||
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(bitmap)
|
||||
canvas.drawBitmap(scaledBitmap, x, y, null)
|
||||
scaledBitmap.recycle()
|
||||
bitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error filling bitmap: $e")
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stretch the bitmap to fit the given width and height
|
||||
*/
|
||||
fun stretchBitmap(source: Bitmap, width: Int, height: Int): Bitmap {
|
||||
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()
|
||||
newBitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error stretching bitmap: $e")
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Darken the bitmap by a certain percentage - 0 is darkest, 100 is original
|
||||
*/
|
||||
fun darkenBitmap(source: Bitmap, percent: Int): Bitmap {
|
||||
return try {
|
||||
val safePercentage = (100 - percent).coerceIn(0, 100)
|
||||
val factor = 1 - safePercentage / 100f
|
||||
val canvas = Canvas(source)
|
||||
val paint = Paint().apply {
|
||||
colorFilter = ColorMatrixColorFilter(ColorMatrix().apply {
|
||||
setScale(factor, factor, factor, 1f)
|
||||
})
|
||||
}
|
||||
canvas.drawBitmap(source, 0f, 0f, paint)
|
||||
source
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error darkening bitmap: $e")
|
||||
source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Blur the bitmap by a certain percentage
|
||||
*/
|
||||
fun blurBitmap(source: Bitmap, percent: Int): Bitmap {
|
||||
return try {
|
||||
val factor = percent.toFloat().div(100f) * 20f
|
||||
Toolkit.blur(source, factor.toInt())
|
||||
} catch (e: Exception) {
|
||||
Log.e("WallpaperUtil", "Error darkening bitmap: $e")
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve wallpaper URIs from a folder directory URI
|
||||
*/
|
||||
fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
|
||||
return try {
|
||||
val folderDocumentFile = DocumentFileCompat.fromTreeUri(context, folderUri.toUri())
|
||||
listFilesRecursive(folderDocumentFile, context)
|
||||
} catch (e: Exception) {
|
||||
val folderDocumentFile = DocumentFile.fromTreeUri(context, folderUri.toUri())
|
||||
listFilesRecursive(folderDocumentFile, context)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to recursively list files in a directory for DocumentFileCompat
|
||||
*/
|
||||
fun listFilesRecursive(parent: DocumentFileCompat?, context: Context): List<String> {
|
||||
val files = mutableListOf<String>()
|
||||
parent?.listFiles()?.forEach { file ->
|
||||
if (file.isDirectory()) {
|
||||
files.addAll(listFilesRecursive(file, context))
|
||||
} else {
|
||||
val allowedExtensions = listOf("jpg", "jpeg", "png", "heif", "webp", "JPG", "JPEG", "PNG", "HEIF", "WEBP")
|
||||
if (file.extension in allowedExtensions) {
|
||||
files.add(file.uri.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
/** Overloaded version of the function for DocumentFile */
|
||||
fun listFilesRecursive(parent: DocumentFile?, context: Context): List<String> {
|
||||
val files = mutableListOf<String>()
|
||||
parent?.listFiles()?.forEach { file ->
|
||||
if (file.isDirectory) {
|
||||
files.addAll(listFilesRecursive(file, context))
|
||||
} else {
|
||||
val allowedExtensions = listOf("jpg", "jpeg", "png", "heif", "webp", "JPG", "JPEG", "PNG", "HEIF", "WEBP")
|
||||
if ((file.name?.substringAfterLast(".") ?: "") in allowedExtensions) {
|
||||
files.add(file.uri.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to find the first valid URI from a list of wallpapers
|
||||
* It will search through all wallpapers of an album first, and then all wallpapers of every folder of an album
|
||||
*/
|
||||
fun findFirstValidUri(context: Context, wallpapers: List<Wallpaper>, folders: List<Folder>): String? {
|
||||
wallpapers.forEach { wallpaper ->
|
||||
try {
|
||||
val file = DocumentFileCompat.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
|
||||
if (file?.exists() == true) {
|
||||
return wallpaper.wallpaperUri
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
val file = DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
|
||||
if (file?.exists() == true) {
|
||||
return wallpaper.wallpaperUri
|
||||
}
|
||||
}
|
||||
}
|
||||
folders.forEach { folder ->
|
||||
folder.wallpapers.forEach { wallpaper ->
|
||||
try {
|
||||
val file = DocumentFileCompat.fromSingleUri(context, wallpaper.toUri())
|
||||
if (file?.exists() == true) {
|
||||
return wallpaper
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
val file = DocumentFile.fromSingleUri(context, wallpaper.toUri())
|
||||
if (file?.exists() == true) {
|
||||
return wallpaper
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the folder name from the folder URI
|
||||
*/
|
||||
fun getFolderNameFromUri(folderUri: String, context: Context): String? {
|
||||
return try {
|
||||
DocumentFileCompat.fromTreeUri(context, folderUri.toUri())?.name
|
||||
} catch (e: Exception) {
|
||||
DocumentFile.fromTreeUri(context, folderUri.toUri())?.name
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a URI is valid
|
||||
*/
|
||||
fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.toUri()
|
||||
return try {
|
||||
uri?.let {
|
||||
val inputStream = context.contentResolver.openInputStream(it)
|
||||
inputStream?.close()
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
}
|
||||
|
||||
/**
|
||||
* Darkens the bitmap by the given percentage and returns it
|
||||
* 0 - lightest, 100 - darkest
|
||||
*/
|
||||
fun processBitmap(
|
||||
width: Int,
|
||||
height: Int,
|
||||
source: Bitmap,
|
||||
darken: Boolean,
|
||||
darkenPercent: Int,
|
||||
scaling: ScalingConstants,
|
||||
blur: Boolean,
|
||||
blurPercent: Int,
|
||||
vignette: Boolean,
|
||||
vignettePercent: Int
|
||||
): 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)
|
||||
}
|
||||
|
||||
return processedBitmap
|
||||
} catch (e: Exception) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error darkening bitmap", e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -31,7 +31,7 @@ object AppModule {
|
||||
app,
|
||||
AlbumDatabase::class.java,
|
||||
AlbumDatabase.DATABASE_NAME
|
||||
).build()
|
||||
).fallbackToDestructiveMigration().addMigrations().build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@@ -41,7 +41,7 @@ object AppModule {
|
||||
app,
|
||||
SelectedAlbumDatabase::class.java,
|
||||
SelectedAlbumDatabase.DATABASE_NAME
|
||||
).build()
|
||||
).fallbackToDestructiveMigration().addMigrations().build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
+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()
|
||||
}
|
||||
}
|
||||
+16
@@ -66,4 +66,20 @@ interface AlbumDao {
|
||||
|
||||
@Update
|
||||
suspend fun updateFolder(folder: Folder)
|
||||
|
||||
@Query("DELETE FROM album")
|
||||
suspend fun deleteAllAlbums()
|
||||
|
||||
@Query("DELETE FROM wallpaper")
|
||||
suspend fun deleteAllWallpapers()
|
||||
|
||||
@Query("DELETE FROM folder")
|
||||
suspend fun deleteAllFolders()
|
||||
|
||||
@Transaction
|
||||
suspend fun deleteAllData() {
|
||||
deleteAllWallpapers()
|
||||
deleteAllFolders()
|
||||
deleteAllAlbums()
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -13,7 +13,7 @@ import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
*/
|
||||
@Database(
|
||||
entities = [Album::class, Wallpaper::class, Folder::class],
|
||||
version = 1
|
||||
version = 5
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class AlbumDatabase: RoomDatabase() {
|
||||
|
||||
-1
@@ -2,7 +2,6 @@ package com.anthonyla.paperize.feature.wallpaper.data.data_source
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
|
||||
/**
|
||||
* Converters for Room database to convert list of strings to json string and vice versa
|
||||
|
||||
+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 = 1
|
||||
version = 5
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class SelectedAlbumDatabase: RoomDatabase() {
|
||||
|
||||
+4
@@ -86,4 +86,8 @@ class AlbumRepositoryImpl(
|
||||
override suspend fun deleteWallpaperList(wallpapers: List<Wallpaper>) {
|
||||
dao.deleteWallpaperList(wallpapers)
|
||||
}
|
||||
|
||||
override suspend fun deleteAllData() {
|
||||
dao.deleteAllData()
|
||||
}
|
||||
}
|
||||
+6
-24
@@ -1,9 +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.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.SelectedAlbumRepository
|
||||
@@ -17,37 +14,22 @@ class SelectedAlbumRepositoryImpl(
|
||||
}
|
||||
|
||||
override suspend fun upsertSelectedAlbum(selectedAlbum: SelectedAlbum) {
|
||||
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,7 +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 wallpapersInQueue The wallpapers in the queue to be displayed
|
||||
* @param homeWallpapersInQueue The list of home wallpapers in the queue
|
||||
* @param lockWallpapersInQueue The list of lock wallpapers in the queue
|
||||
*/
|
||||
@Entity
|
||||
data class Album(
|
||||
@@ -18,5 +19,6 @@ data class Album(
|
||||
val displayedAlbumName: String,
|
||||
val coverUri: String?,
|
||||
val initialized: Boolean = false,
|
||||
val wallpapersInQueue: List<String> = emptyList(),
|
||||
val homeWallpapersInQueue: List<String> = emptyList(),
|
||||
val lockWallpapersInQueue: List<String> = emptyList(),
|
||||
)
|
||||
+5
@@ -96,4 +96,9 @@ interface AlbumRepository {
|
||||
* Delete folder list in one transaction
|
||||
*/
|
||||
suspend fun deleteFolderList(folders: List<Folder>)
|
||||
|
||||
/**
|
||||
* Delete all data in database
|
||||
*/
|
||||
suspend fun deleteAllData()
|
||||
}
|
||||
+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
|
||||
|
||||
+160
-4
@@ -1,25 +1,50 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation
|
||||
|
||||
import android.Manifest
|
||||
import android.animation.ObjectAnimator
|
||||
import android.app.Activity
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.view.View
|
||||
import android.view.animation.AccelerateInterpolator
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.SystemBarStyle
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.viewModels
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.animation.doOnEnd
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.compose.LifecycleEventEffect
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.core.Type
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.themes.PaperizeTheme
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreenViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmSchedulerImpl
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperReceiver
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -30,22 +55,153 @@ class MainActivity : ComponentActivity() {
|
||||
private val settingsViewModel: SettingsViewModel by viewModels()
|
||||
private val wallpaperScreenViewModel: WallpaperScreenViewModel by viewModels()
|
||||
private val context = this
|
||||
private var topInset = 0.dp
|
||||
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (ContextCompat.checkSelfPermission(context, Manifest.permission.SET_WALLPAPER) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(context as Activity, arrayOf(Manifest.permission.SET_WALLPAPER), 0)
|
||||
}
|
||||
enableEdgeToEdge()
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge(
|
||||
statusBarStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT),
|
||||
navigationBarStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT)
|
||||
)
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
val splashScreen = installSplashScreen()
|
||||
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) {
|
||||
splashScreen.setOnExitAnimationListener { splashScreenViewProvider ->
|
||||
val fadeOut = ObjectAnimator.ofFloat(splashScreenViewProvider.view, View.ALPHA, 1f, 0f)
|
||||
fadeOut.interpolator = AccelerateInterpolator()
|
||||
fadeOut.duration = 300L
|
||||
fadeOut.doOnEnd { splashScreenViewProvider.remove() }
|
||||
fadeOut.start()
|
||||
}
|
||||
}
|
||||
splashScreen.setKeepOnScreenCondition { settingsViewModel.setKeepOnScreenCondition }
|
||||
|
||||
setContent {
|
||||
val scheduler = WallpaperAlarmSchedulerImpl(context)
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
val isFirstLaunch = runBlocking { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) } ?: true
|
||||
PaperizeTheme(settingsViewModel.state) {
|
||||
if (isFirstLaunch) {
|
||||
scheduler.cancelWallpaperAlarm()
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset())
|
||||
settingsViewModel.onEvent(SettingsEvent.Reset)
|
||||
albumsViewModel.onEvent(AlbumsEvent.Reset)
|
||||
val contentResolver = context.contentResolver
|
||||
val persistedUris = contentResolver.persistedUriPermissions
|
||||
for (permission in persistedUris) {
|
||||
contentResolver.releasePersistableUriPermission(permission.uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||
}
|
||||
}
|
||||
LifecycleEventEffect(Lifecycle.Event.ON_CREATE) {
|
||||
lifecycleScope.launch {
|
||||
if (settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) == true) {
|
||||
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))
|
||||
}
|
||||
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
|
||||
),
|
||||
origin = null,
|
||||
changeImmediate = true,
|
||||
cancelImmediate = 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.amoledTheme, settingsState.value.dynamicTheming) {
|
||||
Surface(tonalElevation = 5.dp) {
|
||||
PaperizeApp(isFirstLaunch)
|
||||
PaperizeApp(isFirstLaunch, scheduler, topInset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val alarmManager = ContextCompat.getSystemService(context, AlarmManager::class.java)
|
||||
if (alarmManager?.canScheduleExactAlarms() == false) {
|
||||
Intent().also { intent ->
|
||||
intent.action = Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.P)
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
topInset = window.decorView.rootWindowInsets.stableInsetTop.dp
|
||||
}
|
||||
|
||||
private fun isPendingIntentSet(requestCode: Int): Boolean {
|
||||
val intent = Intent(context.applicationContext, WallpaperReceiver::class.java)
|
||||
val pendingIntent = PendingIntent.getBroadcast(
|
||||
context.applicationContext,
|
||||
requestCode,
|
||||
intent,
|
||||
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_NO_CREATE
|
||||
)
|
||||
return pendingIntent != null
|
||||
}
|
||||
}
|
||||
+772
-228
File diff suppressed because it is too large.
Load diff
+3
-3
@@ -2,7 +2,7 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
|
||||
sealed class AddAlbumEvent {
|
||||
data object SaveAlbum: AddAlbumEvent()
|
||||
data object ClearState: AddAlbumEvent()
|
||||
data object Reset: AddAlbumEvent()
|
||||
data object DeleteSelected: AddAlbumEvent()
|
||||
data object SelectAll: AddAlbumEvent()
|
||||
data object DeselectAll: AddAlbumEvent()
|
||||
@@ -12,8 +12,8 @@ sealed class AddAlbumEvent {
|
||||
data class ReflectAlbumName(
|
||||
val newAlbumName: String
|
||||
): AddAlbumEvent()
|
||||
data class AddWallpaper(
|
||||
val wallpaperUri: String
|
||||
data class AddWallpapers(
|
||||
val wallpaperUris: List<String>
|
||||
): AddAlbumEvent()
|
||||
data class AddFolder(
|
||||
val directoryUri: String
|
||||
|
||||
+155
-106
@@ -2,23 +2,21 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.scaleIn
|
||||
import androidx.compose.animation.scaleOut
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.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
|
||||
@@ -31,54 +29,48 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumAnimatedFab
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumFabMenuOptions
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumSmallTopBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.FolderItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
|
||||
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, 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 {
|
||||
if (selectionMode) {
|
||||
selectionMode = false
|
||||
BackHandler(
|
||||
enabled = selectionMode,
|
||||
onBack = {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
|
||||
} else {
|
||||
onBackClick()
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.ClearState)
|
||||
selectionMode = false
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/** Image picker **/
|
||||
val imagePickerLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.OpenMultipleDocuments(),
|
||||
onResult = { uris: List<Uri> ->
|
||||
for (uri in uris) {
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
val uriList = uris.mapNotNull { uri ->
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
|
||||
if (persistedUriPermissions.any { it.uri == uri }) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.AddWallpaper(wallpaperUri = uri.toString()))
|
||||
} else {
|
||||
Log.e("AddAlbumScreen", "Failed to persist permission for $uri")
|
||||
}
|
||||
if (persistedUriPermissions.any { it.uri == uri }) uri.toString() else null
|
||||
}
|
||||
if (uriList.isNotEmpty()) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.AddWallpapers(uriList))
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -92,9 +84,7 @@ fun AddAlbumScreen(
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
|
||||
if (persistedUriPermissions.any { it.uri == uri }) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.AddFolder(directoryUri = uri.toString()))
|
||||
} else {
|
||||
Log.e("AddAlbumScreen", "Failed to persist permission for $uri")
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.AddFolder(uri.toString()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,14 +97,17 @@ fun AddAlbumScreen(
|
||||
isEmpty = addAlbumState.value.isEmpty,
|
||||
selectionMode = selectionMode,
|
||||
albumState = addAlbumViewModel.state,
|
||||
showSpotlight = showSpotlight,
|
||||
onBackClick = {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.ClearState)
|
||||
showSpotlight = false
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.Reset)
|
||||
onBackClick()
|
||||
},
|
||||
onConfirmationClick = {
|
||||
showSpotlight = false
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.ReflectAlbumName(it))
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.SaveAlbum)
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.ClearState)
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.Reset)
|
||||
onConfirmation()
|
||||
},
|
||||
onSelectAllClick = {
|
||||
@@ -129,85 +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(
|
||||
menuOptions = AddAlbumFabMenuOptions(),
|
||||
onImageClick = { imagePickerLauncher.launch(arrayOf("image/*")) },
|
||||
onFolderClick = { folderPickerLauncher.launch(null) },
|
||||
animate = true
|
||||
)
|
||||
AddAlbumAnimatedFab(
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
}
|
||||
}
|
||||
else {
|
||||
AddAlbumAnimatedFab(
|
||||
menuOptions = AddAlbumFabMenuOptions(),
|
||||
onImageClick = { imagePickerLauncher.launch(arrayOf("image/*")) },
|
||||
onFolderClick = { folderPickerLauncher.launch(null) },
|
||||
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.hashCode()}
|
||||
) { 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 = {
|
||||
onShowFolderView(folder.folderUri, folder.folderName, folder.wallpapers)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp)
|
||||
)
|
||||
) {
|
||||
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.hashCode()}
|
||||
) { 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)
|
||||
)
|
||||
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)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
+95
-123
@@ -3,16 +3,15 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.core.getFolderNameFromUri
|
||||
import com.anthonyla.paperize.core.getWallpaperFromFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import com.lazygeniouz.dfc.file.DocumentFileCompat
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
@@ -54,36 +53,25 @@ 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)
|
||||
|
||||
//Clear viewModel state after adding album
|
||||
_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 -> {
|
||||
viewModelScope.launch {
|
||||
val wallpapersRemoved = _state.value.wallpapers.filterNot { it.wallpaperUri in _state.value.selectedWallpapers }
|
||||
val foldersRemoved = _state.value.folders.filterNot { it.folderUri in _state.value.selectedFolders }
|
||||
_state.update { it.copy(
|
||||
wallpapers = wallpapersRemoved,
|
||||
folders = foldersRemoved
|
||||
) }
|
||||
updateIsEmpty()
|
||||
_state.update {
|
||||
val wallpapersRemoved = it.wallpapers.filterNot { it.wallpaperUri in _state.value.selectedWallpapers }
|
||||
val foldersRemoved = it.folders.filterNot { it.folderUri in _state.value.selectedFolders }
|
||||
it.copy(
|
||||
wallpapers = wallpapersRemoved,
|
||||
folders = foldersRemoved,
|
||||
isEmpty = wallpapersRemoved.isEmpty() && foldersRemoved.isEmpty()
|
||||
) }
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.SetAlbumName -> {
|
||||
@@ -98,55 +86,71 @@ class AddAlbumViewModel @Inject constructor(
|
||||
is AddAlbumEvent.ReflectAlbumName -> {
|
||||
if (event.newAlbumName != _state.value.initialAlbumName) {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
initialAlbumName = event.newAlbumName,
|
||||
displayedAlbumName = event.newAlbumName,
|
||||
coverUri = it.coverUri,
|
||||
wallpapers = it.wallpapers.map { wallpaper ->
|
||||
_state.update {
|
||||
val wallpapers = it.wallpapers.map { wallpaper ->
|
||||
wallpaper.copy(initialAlbumName = event.newAlbumName)
|
||||
},
|
||||
folders = it.folders.map { folder ->
|
||||
}
|
||||
val folders = it.folders.map { folder ->
|
||||
folder.copy(initialAlbumName = event.newAlbumName)
|
||||
},
|
||||
) }
|
||||
updateIsEmpty()
|
||||
}
|
||||
it.copy(
|
||||
initialAlbumName = event.newAlbumName,
|
||||
displayedAlbumName = event.newAlbumName,
|
||||
coverUri = it.coverUri,
|
||||
wallpapers = wallpapers,
|
||||
folders = folders,
|
||||
isEmpty = wallpapers.isEmpty() && folders.isEmpty()
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.AddWallpaper -> {
|
||||
is AddAlbumEvent.AddWallpapers -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.wallpapers.any { it.wallpaperUri == event.wallpaperUri }) {
|
||||
_state.update { it.copy(
|
||||
wallpapers = it.wallpapers.plus(
|
||||
Wallpaper(
|
||||
initialAlbumName = it.initialAlbumName,
|
||||
wallpaperUri = event.wallpaperUri,
|
||||
key = event.wallpaperUri.hashCode() + it.initialAlbumName.hashCode(),
|
||||
)
|
||||
),
|
||||
) }
|
||||
updateIsEmpty()
|
||||
val newWallpaperUris = event.wallpaperUris.filterNot { it in _state.value.wallpapers.map { wallpaper -> wallpaper.wallpaperUri } }
|
||||
val newWallpapers = newWallpaperUris.map { uri ->
|
||||
Wallpaper(
|
||||
initialAlbumName = _state.value.initialAlbumName,
|
||||
wallpaperUri = uri,
|
||||
key = uri.hashCode() + _state.value.initialAlbumName.hashCode() + System.currentTimeMillis().toInt()
|
||||
)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
wallpapers = it.wallpapers.plus(newWallpapers),
|
||||
isEmpty = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.AddFolder -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.folders.any { it.folderUri == event.directoryUri }) {
|
||||
if (event.directoryUri !in _state.value.folders.map { it.folderUri }) {
|
||||
val wallpapers: List<String> = getWallpaperFromFolder(event.directoryUri, context)
|
||||
if (wallpapers.isEmpty()) { return@launch }
|
||||
val folderName = getFolderNameFromUri(event.directoryUri, context)
|
||||
_state.update { state ->
|
||||
state.copy( folders = state.folders.plus(
|
||||
Folder(
|
||||
initialAlbumName = state.initialAlbumName,
|
||||
folderName = folderName,
|
||||
folderUri = event.directoryUri,
|
||||
coverUri = wallpapers.randomOrNull(),
|
||||
wallpapers = wallpapers,
|
||||
key = event.directoryUri.hashCode() + state.initialAlbumName.hashCode()
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
isEmpty = false,
|
||||
folders = it.folders.plus(
|
||||
Folder(
|
||||
initialAlbumName = it.initialAlbumName,
|
||||
folderName = folderName,
|
||||
folderUri = event.directoryUri,
|
||||
coverUri = wallpapers.randomOrNull(),
|
||||
wallpapers = wallpapers,
|
||||
key = event.directoryUri.hashCode() + it.initialAlbumName.hashCode() + System.currentTimeMillis().toInt()
|
||||
)
|
||||
)
|
||||
),
|
||||
) }
|
||||
updateIsEmpty()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,9 +160,9 @@ class AddAlbumViewModel @Inject constructor(
|
||||
_state.update { it.copy(
|
||||
selectedFolders = _state.value.folders.map { folder -> folder.folderUri },
|
||||
selectedWallpapers = _state.value.wallpapers.map { wallpaper -> wallpaper.wallpaperUri },
|
||||
selectedCount = it.folders.size + it.wallpapers.size
|
||||
selectedCount = it.folders.size + it.wallpapers.size,
|
||||
allSelected = true
|
||||
) }
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,48 +179,57 @@ class AddAlbumViewModel @Inject constructor(
|
||||
is AddAlbumEvent.SelectFolder -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.selectedFolders.any { it == event.directoryUri }) {
|
||||
_state.update { it.copy(
|
||||
selectedFolders = it.selectedFolders.plus(event.directoryUri),
|
||||
selectedCount = it.selectedCount + 1
|
||||
) }
|
||||
updateAllSelected()
|
||||
_state.update {
|
||||
val folders = it.selectedFolders.plus(event.directoryUri)
|
||||
it.copy(
|
||||
selectedFolders = folders,
|
||||
selectedCount = it.selectedCount + 1,
|
||||
allSelected = folders.size + it.selectedWallpapers.size >= it.wallpapers.size + it.folders.size
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.SelectWallpaper -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.selectedWallpapers.any { it == event.wallpaperUri }) {
|
||||
_state.update { it.copy(
|
||||
selectedWallpapers = it.selectedWallpapers.plus(event.wallpaperUri),
|
||||
selectedCount = it.selectedCount + 1
|
||||
) }
|
||||
updateAllSelected()
|
||||
_state.update {
|
||||
val wallpapers = it.selectedWallpapers.plus(event.wallpaperUri)
|
||||
it.copy(
|
||||
selectedWallpapers = wallpapers,
|
||||
selectedCount = it.selectedCount + 1,
|
||||
allSelected = it.selectedFolders.size + wallpapers.size >= it.wallpapers.size + it.folders.size
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.RemoveFolderFromSelection -> {
|
||||
viewModelScope.launch {
|
||||
if (_state.value.selectedFolders.find { it == event.directoryUri } != null ) {
|
||||
_state.update { it.copy(
|
||||
selectedFolders = it.selectedFolders.minus(event.directoryUri),
|
||||
selectedCount = it.selectedCount - 1
|
||||
) }
|
||||
updateAllSelected()
|
||||
_state.update {
|
||||
val folders = it.selectedFolders.minus(event.directoryUri)
|
||||
it.copy(
|
||||
selectedFolders = folders,
|
||||
selectedCount = it.selectedCount - 1,
|
||||
allSelected = folders.size + it.selectedWallpapers.size >= it.wallpapers.size + it.folders.size
|
||||
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.RemoveWallpaperFromSelection -> {
|
||||
viewModelScope.launch {
|
||||
if (_state.value.selectedWallpapers.find { it == event.wallpaperUri } != null ) {
|
||||
_state.update { it.copy(
|
||||
selectedWallpapers = it.selectedWallpapers.minus(event.wallpaperUri),
|
||||
selectedCount = it.selectedCount - 1
|
||||
) }
|
||||
updateAllSelected()
|
||||
_state.update {
|
||||
val wallpapers = it.selectedWallpapers.minus(event.wallpaperUri)
|
||||
it.copy(
|
||||
selectedWallpapers = wallpapers,
|
||||
selectedCount = it.selectedCount - 1,
|
||||
allSelected = it.selectedFolders.size + wallpapers.size >= it.wallpapers.size + it.folders.size
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.ClearState -> {
|
||||
is AddAlbumEvent.Reset -> {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
initialAlbumName = "",
|
||||
@@ -234,45 +247,4 @@ class AddAlbumViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateIsEmpty() {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
isEmpty = it.wallpapers.isEmpty() && it.folders.isEmpty()
|
||||
) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateAllSelected() {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
allSelected = it.selectedFolders.size + it.selectedWallpapers.size >= it.wallpapers.size + it.folders.size
|
||||
) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
|
||||
val folderDocumentFile = DocumentFileCompat.fromTreeUri(context, folderUri.toUri())
|
||||
return listFilesRecursive(folderDocumentFile, context)
|
||||
}
|
||||
|
||||
private fun listFilesRecursive(parent: DocumentFileCompat?, context: Context): List<String> {
|
||||
val files = mutableListOf<String>()
|
||||
parent?.listFiles()?.forEach { file ->
|
||||
if (file.isDirectory()) {
|
||||
files.addAll(listFilesRecursive(file, context))
|
||||
} else {
|
||||
val extension = MimeTypeMap.getFileExtensionFromUrl(file.uri.toString())
|
||||
val allowedExtensions = listOf("jpg", "png", "heif", "webp")
|
||||
if (extension in allowedExtensions) {
|
||||
files.add(file.uri.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
private fun getFolderNameFromUri(folderUri: String, context: Context): String? {
|
||||
return DocumentFileCompat.fromTreeUri(context, folderUri.toUri())?.name
|
||||
}
|
||||
}
|
||||
+147
-131
@@ -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,22 +12,31 @@ 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
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.Folder
|
||||
import androidx.compose.material.icons.filled.PhotoLibrary
|
||||
import androidx.compose.material.icons.filled.Remove
|
||||
import androidx.compose.material3.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
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -34,11 +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.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
|
||||
@@ -46,162 +54,170 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.comp
|
||||
*/
|
||||
@Composable
|
||||
fun AddAlbumAnimatedFab(
|
||||
menuOptions: AddAlbumFabMenuOptions,
|
||||
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(155.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(
|
||||
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 = menuOptions.imageOption.text,
|
||||
icon = menuOptions.imageOption.icon,
|
||||
horizontalExpansion = expandHorizontally,
|
||||
onClick = {
|
||||
expanded = false
|
||||
onImageClick()
|
||||
}
|
||||
)
|
||||
MenuRow(
|
||||
text = menuOptions.folderOption.text,
|
||||
icon = menuOptions.folderOption.icon,
|
||||
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(
|
||||
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 = menuOptions.imageOption.text,
|
||||
icon = menuOptions.imageOption.icon,
|
||||
horizontalExpansion = if (expanded) expandHorizontalSize.first else expandHorizontalSize.second,
|
||||
onClick = {
|
||||
expanded = false
|
||||
onImageClick()
|
||||
}
|
||||
)
|
||||
MenuRow(
|
||||
text = menuOptions.folderOption.text,
|
||||
icon = menuOptions.folderOption.icon,
|
||||
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),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -60,7 +60,7 @@ fun AddAlbumDialog(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Text(
|
||||
text = "New Album",
|
||||
text = stringResource(R.string.new_album),
|
||||
modifier = Modifier.padding(20.dp),
|
||||
fontSize = 25.sp
|
||||
)
|
||||
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Folder
|
||||
import androidx.compose.material.icons.filled.PhotoLibrary
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components.SelectionOptions
|
||||
|
||||
/**
|
||||
* Options for the FAB menu in the Add Album screen
|
||||
*/
|
||||
data class AddAlbumFabMenuOptions (
|
||||
val imageOption: SelectionOptions = SelectionOptions("add_images", "Add Image", null, Icons.Filled.PhotoLibrary),
|
||||
val folderOption: SelectionOptions = SelectionOptions("add_folder", "Add Folder", null, Icons.Filled.Folder)
|
||||
)
|
||||
+74
-14
@@ -1,8 +1,16 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components
|
||||
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.RepeatMode
|
||||
import androidx.compose.animation.core.animateFloat
|
||||
import androidx.compose.animation.core.infiniteRepeatable
|
||||
import androidx.compose.animation.core.rememberInfiniteTransition
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.requiredSize
|
||||
@@ -33,7 +41,9 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
@@ -54,17 +64,44 @@ fun AddAlbumSmallTopBar(
|
||||
title: String,
|
||||
isEmpty: Boolean,
|
||||
selectionMode: Boolean,
|
||||
showSpotlight: Boolean,
|
||||
onSelectAllClick: () -> Unit,
|
||||
onBackClick: () -> Unit,
|
||||
onDeleteSelected: () -> Unit,
|
||||
onConfirmationClick: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
onConfirmationClick: (String) -> Unit
|
||||
) {
|
||||
val state = albumState.collectAsStateWithLifecycle()
|
||||
val focusManager = LocalFocusManager.current
|
||||
var editableTitle by rememberSaveable { mutableStateOf(title) }
|
||||
var showSelectionDeleteDialog by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
val infiniteTransition = rememberInfiniteTransition(label = stringResource(R.string.spotlight_animation))
|
||||
val radius1 by infiniteTransition.animateFloat(
|
||||
initialValue = 25f,
|
||||
targetValue = 50f,
|
||||
animationSpec = infiniteRepeatable(
|
||||
animation = tween(2000, easing = LinearOutSlowInEasing),
|
||||
repeatMode = RepeatMode.Reverse
|
||||
), label = stringResource(R.string.circle_1_animation)
|
||||
)
|
||||
val radius2 by infiniteTransition.animateFloat(
|
||||
initialValue = 25f,
|
||||
targetValue = 60f,
|
||||
animationSpec = infiniteRepeatable(
|
||||
animation = tween(2000, easing = LinearOutSlowInEasing),
|
||||
repeatMode = RepeatMode.Reverse
|
||||
), label = stringResource(R.string.circle_2_animation)
|
||||
)
|
||||
|
||||
val radius3 by infiniteTransition.animateFloat(
|
||||
initialValue = 25f,
|
||||
targetValue = 75f,
|
||||
animationSpec = infiniteRepeatable(
|
||||
animation = tween(2000, easing = LinearOutSlowInEasing),
|
||||
repeatMode = RepeatMode.Reverse
|
||||
), label = stringResource(R.string.circle_3_animation)
|
||||
)
|
||||
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||
title = {
|
||||
@@ -109,9 +146,7 @@ fun AddAlbumSmallTopBar(
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
IconButton(
|
||||
onClick = onSelectAllClick
|
||||
) {
|
||||
IconButton(onClick = onSelectAllClick) {
|
||||
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
if (state.value.allSelected) {
|
||||
Icon(
|
||||
@@ -127,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)
|
||||
)
|
||||
}
|
||||
@@ -138,13 +172,39 @@ fun AddAlbumSmallTopBar(
|
||||
},
|
||||
actions = {
|
||||
if(!selectionMode) {
|
||||
if (!isEmpty) {
|
||||
IconButton(onClick = { onConfirmationClick(editableTitle) }) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Add,
|
||||
contentDescription = stringResource(R.string.add_album),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
if (!isEmpty && editableTitle.isNotEmpty()) {
|
||||
Box {
|
||||
val primaryColor = MaterialTheme.colorScheme.inversePrimary
|
||||
val secondaryColor = MaterialTheme.colorScheme.secondary
|
||||
IconButton(onClick = { onConfirmationClick(editableTitle) }) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Add,
|
||||
contentDescription = stringResource(R.string.add_album),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
}
|
||||
if (!showSpotlight) {
|
||||
Canvas(modifier = Modifier.matchParentSize()) {
|
||||
drawCircle(
|
||||
color = primaryColor,
|
||||
radius = radius1,
|
||||
center = Offset(size.width / 2, size.height / 2),
|
||||
style = Stroke(width = 5f)
|
||||
)
|
||||
drawCircle(
|
||||
color = secondaryColor,
|
||||
radius = radius2,
|
||||
center = Offset(size.width / 2, size.height / 2),
|
||||
style = Stroke(width = 5f)
|
||||
)
|
||||
drawCircle(
|
||||
color = primaryColor,
|
||||
radius = radius3,
|
||||
center = Offset(size.width / 2, size.height / 2),
|
||||
style = Stroke(width = 5f)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -22,17 +22,17 @@ fun DeleteImagesAlertDialog(
|
||||
icon = {
|
||||
Icon(Icons.Outlined.Delete, contentDescription = stringResource(R.string.delete_confirmation))
|
||||
},
|
||||
title = { Text(text = "Delete these?") },
|
||||
text = { Text(text = "Are you sure you want to delete these wallpapers?") },
|
||||
title = { Text(text = stringResource(R.string.delete_these)) },
|
||||
text = { Text(text = stringResource(R.string.are_you_sure_you_want_to_delete_these_wallpapers)) },
|
||||
onDismissRequest = { onDismissRequest() },
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onConfirmation() }) {
|
||||
Text("Confirm")
|
||||
Text(stringResource(R.string.confirm))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { onDismissRequest() }) {
|
||||
Text("Cancel")
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
+1
@@ -3,6 +3,7 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
sealed class AlbumsEvent {
|
||||
data object RefreshAlbums: AlbumsEvent()
|
||||
data object Reset: AlbumsEvent()
|
||||
|
||||
data class DeleteAlbumWithWallpapers(
|
||||
val albumWithWallpaperAndFolder: AlbumWithWallpaperAndFolder
|
||||
|
||||
+164
-94
@@ -2,19 +2,16 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.album
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.core.findFirstValidUri
|
||||
import com.anthonyla.paperize.core.getWallpaperFromFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import com.lazygeniouz.dfc.file.DocumentFileCompat
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.first
|
||||
@@ -37,42 +34,79 @@ class AlbumsViewModel @Inject constructor (
|
||||
)
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
updateAlbums()
|
||||
refreshAlbums()
|
||||
}
|
||||
updateAlbums()
|
||||
refreshAlbums()
|
||||
}
|
||||
|
||||
|
||||
fun onEvent(event: AlbumsEvent) {
|
||||
when (event) {
|
||||
is AlbumsEvent.DeleteAlbumWithWallpapers -> {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.cascadeDeleteAlbum(event.albumWithWallpaperAndFolder.album)
|
||||
}
|
||||
}
|
||||
is AlbumsEvent.ChangeAlbumName -> {
|
||||
viewModelScope.launch {
|
||||
if (!(_state.value.albumsWithWallpapers.any { it.album.displayedAlbumName == event.title })) {
|
||||
repository.updateAlbum(
|
||||
event.albumWithWallpaperAndFolder.album.copy(displayedAlbumName = event.title)
|
||||
_state.update {
|
||||
it.copy(
|
||||
albumsWithWallpapers = it.albumsWithWallpapers.filterNot { albumWithWallpaper ->
|
||||
albumWithWallpaper.album == event.albumWithWallpaperAndFolder.album
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
is AlbumsEvent.RefreshAlbums -> {
|
||||
viewModelScope.launch {
|
||||
updateAlbums()
|
||||
refreshAlbums()
|
||||
is AlbumsEvent.ChangeAlbumName -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (!(_state.value.albumsWithWallpapers.any { it.album.displayedAlbumName == event.title })) {
|
||||
repository.updateAlbum(
|
||||
event.albumWithWallpaperAndFolder.album.copy(displayedAlbumName = event.title)
|
||||
)
|
||||
_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.InitializeAlbum -> {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.updateAlbum(
|
||||
event.albumWithWallpaperAndFolder.album.copy(
|
||||
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) {
|
||||
repository.deleteAllData()
|
||||
_state.update { AlbumsState() }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,39 +116,124 @@ class AlbumsViewModel @Inject constructor (
|
||||
* Verify and remove stale data in Room database
|
||||
*/
|
||||
private fun updateAlbums() {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
var albumWithWallpapers = repository.getAlbumsWithWallpaperAndFolder().first()
|
||||
albumWithWallpapers.forEach { albumWithWallpaper ->
|
||||
// Delete wallpaper if the URI is invalid
|
||||
val invalidWallpapers = albumWithWallpaper.wallpapers.filterNot { wallpaper ->
|
||||
val file = DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
|
||||
file?.exists() == true
|
||||
try {
|
||||
val file = DocumentFileCompat.fromSingleUri(
|
||||
context,
|
||||
wallpaper.wallpaperUri.toUri()
|
||||
)
|
||||
file?.exists() == true
|
||||
} catch (e: Exception) {
|
||||
val file =
|
||||
DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
|
||||
file?.exists() == true
|
||||
}
|
||||
}
|
||||
if (invalidWallpapers.isNotEmpty()) {
|
||||
repository.deleteWallpaperList(invalidWallpapers)
|
||||
}
|
||||
|
||||
// Update folder cover uri and children uri
|
||||
// Update folder cover uri and wallpapers uri
|
||||
albumWithWallpaper.folders.forEach { folder ->
|
||||
DocumentFile.fromTreeUri(context, folder.folderUri.toUri())?.let { folderDirectory ->
|
||||
if (!folderDirectory.isDirectory) {
|
||||
repository.deleteFolder(folder)
|
||||
} else {
|
||||
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
|
||||
val folderCoverFile = folder.coverUri?.let { DocumentFile.fromSingleUri(context, it.toUri()) }
|
||||
val folderCover = folderCoverFile?.takeIf { it.exists() }?.uri?.toString() ?: wallpapers.randomOrNull()
|
||||
repository.updateFolder(folder.copy(coverUri = folderCover, wallpapers = wallpapers))
|
||||
}
|
||||
try {
|
||||
DocumentFileCompat.fromTreeUri(context, folder.folderUri.toUri())
|
||||
?.let { folderDirectory ->
|
||||
if (!folderDirectory.isDirectory()) {
|
||||
repository.deleteFolder(folder)
|
||||
} else {
|
||||
val wallpapers =
|
||||
getWallpaperFromFolder(folder.folderUri, context)
|
||||
val folderCoverFile = folder.coverUri?.let {
|
||||
DocumentFileCompat.fromSingleUri(
|
||||
context,
|
||||
it.toUri()
|
||||
)
|
||||
}
|
||||
val folderCover =
|
||||
folderCoverFile?.takeIf { it.exists() }?.uri?.toString()
|
||||
?: wallpapers.randomOrNull()
|
||||
repository.updateFolder(
|
||||
folder.copy(
|
||||
coverUri = folderCover,
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
DocumentFile.fromTreeUri(context, folder.folderUri.toUri())
|
||||
?.let { folderDirectory ->
|
||||
if (!folderDirectory.isDirectory) {
|
||||
repository.deleteFolder(folder)
|
||||
} else {
|
||||
val wallpapers =
|
||||
getWallpaperFromFolder(folder.folderUri, context)
|
||||
try {
|
||||
val folderCoverFile = folder.coverUri?.let {
|
||||
DocumentFileCompat.fromSingleUri(
|
||||
context,
|
||||
it.toUri()
|
||||
)
|
||||
}
|
||||
val folderCover =
|
||||
folderCoverFile?.takeIf { it.exists() }?.uri?.toString()
|
||||
?: wallpapers.randomOrNull()
|
||||
repository.updateFolder(
|
||||
folder.copy(
|
||||
coverUri = folderCover,
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
val folderCoverFile = folder.coverUri?.let {
|
||||
DocumentFile.fromSingleUri(
|
||||
context,
|
||||
it.toUri()
|
||||
)
|
||||
}
|
||||
val folderCover =
|
||||
folderCoverFile?.takeIf { it.exists() }?.uri?.toString()
|
||||
?: wallpapers.randomOrNull()
|
||||
repository.updateFolder(
|
||||
folder.copy(
|
||||
coverUri = folderCover,
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
albumWithWallpapers = repository.getAlbumsWithWallpaperAndFolder().first()
|
||||
albumWithWallpapers.forEach { albumWithWallpaper ->
|
||||
// Update album cover uri if null or invalid
|
||||
val albumCoverFile = albumWithWallpaper.album.coverUri?.toUri()?.let { DocumentFile.fromSingleUri(context, it) }
|
||||
if (albumCoverFile == null || !albumCoverFile.exists()) {
|
||||
val newCoverUri = findFirstValidUri(albumWithWallpaper.wallpapers, albumWithWallpaper.folders)
|
||||
repository.updateAlbum(albumWithWallpaper.album.copy(coverUri = newCoverUri))
|
||||
albumWithWallpapers = repository.getAlbumsWithWallpaperAndFolder().first()
|
||||
albumWithWallpapers.forEach { album ->
|
||||
// Delete empty albums
|
||||
if (album.wallpapers.isEmpty() && album.folders.all { it.wallpapers.isEmpty() }) {
|
||||
repository.deleteAlbum(album.album)
|
||||
} else {
|
||||
// Update album cover uri if null or invalid
|
||||
try {
|
||||
val albumCoverFile = album.album.coverUri?.toUri()
|
||||
?.let { DocumentFileCompat.fromSingleUri(context, it) }
|
||||
if (albumCoverFile == null || !albumCoverFile.exists()) {
|
||||
val newCoverUri =
|
||||
findFirstValidUri(context, album.wallpapers, album.folders)
|
||||
repository.updateAlbum(album.album.copy(coverUri = newCoverUri))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
val albumCoverFile = album.album.coverUri?.toUri()
|
||||
?.let { DocumentFile.fromSingleUri(context, it) }
|
||||
if (albumCoverFile == null || !albumCoverFile.exists()) {
|
||||
val newCoverUri =
|
||||
findFirstValidUri(context, album.wallpapers, album.folders)
|
||||
repository.updateAlbum(album.album.copy(coverUri = newCoverUri))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,7 +243,7 @@ class AlbumsViewModel @Inject constructor (
|
||||
* Retrieve albums from database into viewModel
|
||||
*/
|
||||
private fun refreshAlbums() {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.getAlbumsWithWallpaperAndFolder().collect { albumWithWallpapers ->
|
||||
_state.update { it.copy(
|
||||
albumsWithWallpapers = albumWithWallpapers
|
||||
@@ -132,54 +251,5 @@ class AlbumsViewModel @Inject constructor (
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve wallpaper URIs from a folder directory URI
|
||||
*/
|
||||
private fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
|
||||
val folderDocumentFile = DocumentFileCompat.fromTreeUri(context, folderUri.toUri())
|
||||
return listFilesRecursive(folderDocumentFile, context)
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to recursively list files in a directory
|
||||
*/
|
||||
private fun listFilesRecursive(parent: DocumentFileCompat?, context: Context): List<String> {
|
||||
val files = mutableListOf<String>()
|
||||
parent?.listFiles()?.forEach { file ->
|
||||
if (file.isDirectory()) {
|
||||
files.addAll(listFilesRecursive(file, context))
|
||||
} else {
|
||||
val extension = MimeTypeMap.getFileExtensionFromUrl(file.uri.toString())
|
||||
val allowedExtensions = listOf("jpg", "png", "heif", "webp")
|
||||
if (extension in allowedExtensions) {
|
||||
files.add(file.uri.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to find the first valid URI from a list of wallpapers
|
||||
* It will search through all wallpapers of an album first, and then all wallpapers of every folder of an album
|
||||
*/
|
||||
private fun findFirstValidUri(wallpapers: List<Wallpaper>, folders: List<Folder>): String? {
|
||||
wallpapers.forEach { wallpaper ->
|
||||
val file = DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
|
||||
if (file?.exists() == true) {
|
||||
return wallpaper.wallpaperUri
|
||||
}
|
||||
}
|
||||
folders.forEach { folder ->
|
||||
folder.wallpapers.forEach { wallpaper ->
|
||||
val file = DocumentFile.fromSingleUri(context, wallpaper.toUri())
|
||||
if (file?.exists() == true) {
|
||||
return wallpaper
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
+25
-29
@@ -10,20 +10,22 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.anthonyla.paperize.core.isValidUri
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
|
||||
@@ -34,13 +36,14 @@ import com.skydoves.landscapist.glide.GlideImage
|
||||
fun AlbumItem(
|
||||
album: Album,
|
||||
onAlbumViewClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
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
|
||||
) {
|
||||
@@ -49,27 +52,19 @@ fun AlbumItem(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Box {
|
||||
GlideImage(
|
||||
imageModel = { album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
)
|
||||
if (showCoverUri) {
|
||||
GlideImage(
|
||||
imageModel = { album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(300, 300),
|
||||
),
|
||||
modifier = Modifier
|
||||
.aspectRatio(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.padding(6.dp))
|
||||
@@ -78,7 +73,8 @@ fun AlbumItem(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 24.dp)
|
||||
.align(Alignment.Start),
|
||||
fontSize = 16.sp
|
||||
fontSize = 16.sp,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
Spacer(modifier = Modifier.padding(8.dp))
|
||||
}
|
||||
|
||||
+46
-45
@@ -9,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.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
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
|
||||
@@ -20,30 +20,30 @@ 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
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.isValidUri
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
|
||||
@@ -59,9 +59,9 @@ fun FolderItem(
|
||||
onActivateSelectionMode: (Boolean) -> Unit,
|
||||
onItemSelection: () -> Unit,
|
||||
onFolderViewClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val configuration = LocalConfiguration.current
|
||||
val context = LocalContext.current
|
||||
val haptics = LocalHapticFeedback.current
|
||||
val transition = updateTransition(itemSelected, label = "")
|
||||
|
||||
@@ -73,6 +73,8 @@ fun FolderItem(
|
||||
if (selected) 24.dp else 16.dp
|
||||
}
|
||||
|
||||
val showCoverUri by remember { mutableStateOf(folder.coverUri != null && isValidUri(context, folder.coverUri)) }
|
||||
|
||||
Card(
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
|
||||
modifier = modifier
|
||||
@@ -81,8 +83,11 @@ fun FolderItem(
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (!selectionMode) { onFolderViewClick() }
|
||||
else { onItemSelection() }
|
||||
if (!selectionMode) {
|
||||
onFolderViewClick()
|
||||
} else {
|
||||
onItemSelection()
|
||||
}
|
||||
},
|
||||
onLongClick = {
|
||||
if (!selectionMode) {
|
||||
@@ -92,34 +97,25 @@ fun FolderItem(
|
||||
}
|
||||
}
|
||||
),
|
||||
shape = RoundedCornerShape(roundedCornerShapeTransition),
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Top,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Box {
|
||||
if (folder.coverUri != null) {
|
||||
Box (
|
||||
modifier = Modifier.fillMaxHeight(0.8f)
|
||||
) {
|
||||
if (showCoverUri) {
|
||||
GlideImage(
|
||||
imageModel = { folder.coverUri.toUri() },
|
||||
imageModel = { folder.coverUri?.toUri() },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center
|
||||
alignment = Alignment.Center,
|
||||
requestSize = IntSize(300, 300),
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.height(configuration.screenHeightDp.dp / 4.0f)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.fillMaxSize()
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
)
|
||||
}
|
||||
if (selectionMode) {
|
||||
@@ -128,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)
|
||||
@@ -143,25 +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(" wallpapers"),
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 24.dp)
|
||||
.align(Alignment.Start),
|
||||
fontSize = 12.sp,
|
||||
color = MaterialTheme.colorScheme.tertiary
|
||||
)
|
||||
Spacer(modifier = Modifier.padding(8.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
+47
-56
@@ -1,8 +1,6 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
@@ -10,34 +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.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
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.core.net.toUri
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import com.anthonyla.paperize.R
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions.withCrossFade
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
|
||||
@@ -50,11 +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,
|
||||
wallpaperDrawable : Bitmap? = null
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val haptics = LocalHapticFeedback.current
|
||||
@@ -67,46 +63,51 @@ fun WallpaperItem(
|
||||
if (selected) 24.dp else 16.dp
|
||||
}
|
||||
|
||||
val dimension = wallpaperDrawable?.let { Pair(it.width, it.height) } ?: wallpaperUri.toUri().getImageDimensions(context)
|
||||
val aspectRatio = (dimension.first.toFloat()/dimension.second.toFloat())
|
||||
fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
val uri = uriString?.toUri()
|
||||
return try {
|
||||
uri?.let {
|
||||
val inputStream = context.contentResolver.openInputStream(it)
|
||||
inputStream?.close()
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
val showUri by remember { mutableStateOf(isValidUri(context, wallpaperUri)) }
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.padding(paddingTransition)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (!selectionMode) { onWallpaperViewClick() }
|
||||
else { onItemSelection() }
|
||||
},
|
||||
onLongClick = {
|
||||
if (!selectionMode) {
|
||||
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onActivateSelectionMode(true)
|
||||
onItemSelection()
|
||||
}
|
||||
}
|
||||
)
|
||||
) {
|
||||
GlideImage(
|
||||
imageModel = { wallpaperDrawable ?: wallpaperUri.toUri() },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.Crop,
|
||||
alignment = Alignment.Center
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
.padding(paddingTransition)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (!selectionMode) {
|
||||
onWallpaperViewClick()
|
||||
} else {
|
||||
onItemSelection()
|
||||
}
|
||||
},
|
||||
modifier = Modifier.aspectRatio(aspectRatio)
|
||||
onLongClick = {
|
||||
if (!selectionMode) {
|
||||
if (allowHapticFeedback) haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onActivateSelectionMode(true)
|
||||
onItemSelection()
|
||||
}
|
||||
}
|
||||
)
|
||||
) {
|
||||
if (showUri) {
|
||||
GlideImage(
|
||||
imageModel = { wallpaperUri },
|
||||
imageOptions = ImageOptions(
|
||||
requestSize = IntSize(200, 200),
|
||||
alignment = Alignment.Center,
|
||||
),
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
)
|
||||
}
|
||||
if (selectionMode) {
|
||||
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
if (itemSelected) {
|
||||
@@ -114,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(
|
||||
@@ -129,14 +130,4 @@ fun WallpaperItem(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Uri.getImageDimensions(context: Context): Pair<Int, Int> {
|
||||
val inputStream = context.contentResolver.openInputStream(this)!!
|
||||
val exif = ExifInterface(inputStream)
|
||||
|
||||
val width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0)
|
||||
val height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0)
|
||||
|
||||
return Pair(width, height)
|
||||
}
|
||||
+11
@@ -11,6 +11,17 @@ sealed class AlbumViewEvent {
|
||||
data class DeleteSelected(
|
||||
val albumsWithWallpaper: AlbumWithWallpaperAndFolder
|
||||
): AlbumViewEvent()
|
||||
|
||||
data class AddWallpapers(
|
||||
val album: AlbumWithWallpaperAndFolder,
|
||||
val wallpaperUris: List<String>
|
||||
): AlbumViewEvent()
|
||||
|
||||
data class AddFolder(
|
||||
val album: AlbumWithWallpaperAndFolder,
|
||||
val directoryUri: String
|
||||
): AlbumViewEvent()
|
||||
|
||||
data class SelectWallpaper(
|
||||
val wallpaperUri: String
|
||||
): AlbumViewEvent()
|
||||
|
||||
+206
-74
@@ -1,14 +1,22 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
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
|
||||
@@ -16,120 +24,244 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumAnimatedFab
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.FolderItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen.components.AlbumViewTopBar
|
||||
import my.nanihadesuka.compose.LazyVerticalGridScrollbar
|
||||
import my.nanihadesuka.compose.ScrollbarSettings
|
||||
|
||||
@Composable
|
||||
fun AlbumViewScreen(
|
||||
albumViewModel: AlbumViewScreenViewModel = hiltViewModel(),
|
||||
albumViewScreenViewModel: AlbumViewScreenViewModel = hiltViewModel(),
|
||||
album: AlbumWithWallpaperAndFolder,
|
||||
animate: Boolean,
|
||||
onBackClick: () -> Unit,
|
||||
onShowWallpaperView: (String) -> Unit,
|
||||
onShowFolderView: (String, String?, List<String>) -> Unit,
|
||||
onShowFolderView: (String?, List<String>) -> Unit,
|
||||
onDeleteAlbum: () -> Unit,
|
||||
onTitleChange: (String, AlbumWithWallpaperAndFolder) -> Unit,
|
||||
onSelectionDeleted: () -> Unit
|
||||
onAlbumNameChange: (String, AlbumWithWallpaperAndFolder) -> Unit,
|
||||
onSelectionDeleted: () -> Unit,
|
||||
) {
|
||||
albumViewModel.onEvent(AlbumViewEvent.SetSize(album.wallpapers.size + album.folders.size))
|
||||
val lazyListState = rememberLazyStaggeredGridState()
|
||||
val albumState = albumViewModel.state.collectAsStateWithLifecycle()
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.SetSize(album.wallpapers.size + album.folders.size)) // For selectedAll state
|
||||
val lazyListState = rememberLazyGridState()
|
||||
val albumState = albumViewScreenViewModel.state.collectAsStateWithLifecycle()
|
||||
var selectionMode by rememberSaveable { mutableStateOf(false) }
|
||||
val context = LocalContext.current
|
||||
|
||||
BackHandler {
|
||||
if (selectionMode) {
|
||||
selectionMode = false
|
||||
albumViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
} else {
|
||||
onBackClick()
|
||||
albumViewModel.onEvent(AlbumViewEvent.ClearState)
|
||||
/** Image picker **/
|
||||
val imagePickerLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.OpenMultipleDocuments(),
|
||||
onResult = { uris: List<Uri> ->
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
val uriList = uris.mapNotNull { uri ->
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
|
||||
if (persistedUriPermissions.any { it.uri == uri }) uri.toString() else null
|
||||
}
|
||||
if (uriList.isNotEmpty()) {
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.AddWallpapers(album, uriList))
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/** Folder picker **/
|
||||
val folderPickerLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.OpenDocumentTree(),
|
||||
onResult = { uri: Uri? ->
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
if (uri != null) {
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
|
||||
if (persistedUriPermissions.any { it.uri == uri }) {
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.AddFolder(album, uri.toString()))
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
BackHandler(
|
||||
enabled = selectionMode,
|
||||
onBack = {
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
selectionMode = false
|
||||
}
|
||||
)
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
AlbumViewTopBar(
|
||||
title = album.album.displayedAlbumName,
|
||||
selectionMode = selectionMode,
|
||||
albumState = albumViewModel.state,
|
||||
albumState = albumViewScreenViewModel.state,
|
||||
onBackClick = {
|
||||
albumViewModel.onEvent(AlbumViewEvent.ClearState)
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.ClearState)
|
||||
onBackClick()
|
||||
},
|
||||
onDeleteAlbum = onDeleteAlbum,
|
||||
onTitleChange = { onTitleChange(it, album) },
|
||||
onTitleChange = { onAlbumNameChange(it, album) },
|
||||
onSelectAllClick = {
|
||||
if (!albumState.value.allSelected) albumViewModel.onEvent(AlbumViewEvent.SelectAll(album))
|
||||
else albumViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
if (!albumState.value.allSelected) albumViewScreenViewModel.onEvent(AlbumViewEvent.SelectAll(album))
|
||||
else albumViewScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
},
|
||||
onDeleteSelected = {
|
||||
selectionMode = false
|
||||
albumViewModel.onEvent(AlbumViewEvent.DeleteSelected(album))
|
||||
albumViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.DeleteSelected(album))
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
onSelectionDeleted()
|
||||
}
|
||||
)
|
||||
},
|
||||
floatingActionButton = {
|
||||
AddAlbumAnimatedFab(
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
}
|
||||
)
|
||||
},
|
||||
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.hashCode() }
|
||||
) { folder ->
|
||||
FolderItem(
|
||||
folder = folder,
|
||||
itemSelected = albumState.value.selectedFolders.contains(folder.folderUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
albumViewModel.onEvent(
|
||||
if (!albumState.value.selectedFolders.contains(folder.folderUri))
|
||||
AlbumViewEvent.SelectFolder(folder.folderUri)
|
||||
else {
|
||||
AlbumViewEvent.RemoveFolderFromSelection(folder.folderUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onFolderViewClick = {
|
||||
onShowFolderView(folder.folderUri, folder.folderName, folder.wallpapers)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp)
|
||||
)
|
||||
) {
|
||||
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 = 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(album.folders[index].folderUri))
|
||||
AlbumViewEvent.SelectFolder(album.folders[index].folderUri)
|
||||
else {
|
||||
AlbumViewEvent.RemoveFolderFromSelection(album.folders[index].folderUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onFolderViewClick = {
|
||||
if (album.folders[index].wallpapers.isNotEmpty()) onShowFolderView(album.folders[index].folderName, album.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 = 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(album.folders[index].folderUri))
|
||||
AlbumViewEvent.SelectFolder(album.folders[index].folderUri)
|
||||
else {
|
||||
AlbumViewEvent.RemoveFolderFromSelection(album.folders[index].folderUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onFolderViewClick = {
|
||||
if (album.folders[index].wallpapers.isNotEmpty()) onShowFolderView(album.folders[index].folderName, album.folders[index].wallpapers)
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.size(150.dp, 350.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
items (items = album.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri.hashCode()}
|
||||
) { wallpaper ->
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper.wallpaperUri,
|
||||
itemSelected = albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
albumViewModel.onEvent(
|
||||
if (!albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri))
|
||||
AlbumViewEvent.SelectWallpaper(wallpaper.wallpaperUri)
|
||||
else {
|
||||
AlbumViewEvent.RemoveWallpaperFromSelection(wallpaper.wallpaperUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper.wallpaperUri)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp)
|
||||
)
|
||||
items(count = album.wallpapers.size, key = { index -> album.wallpapers[index].wallpaperUri }) { index ->
|
||||
if (animate) {
|
||||
WallpaperItem(
|
||||
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(album.wallpapers[index].wallpaperUri))
|
||||
AlbumViewEvent.SelectWallpaper(album.wallpapers[index].wallpaperUri)
|
||||
else {
|
||||
AlbumViewEvent.RemoveWallpaperFromSelection(album.wallpapers[index].wallpaperUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(album.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 = 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(album.wallpapers[index].wallpaperUri))
|
||||
AlbumViewEvent.SelectWallpaper(album.wallpapers[index].wallpaperUri)
|
||||
else {
|
||||
AlbumViewEvent.RemoveWallpaperFromSelection(album.wallpapers[index].wallpaperUri)
|
||||
}
|
||||
)
|
||||
},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(album.wallpapers[index].wallpaperUri)
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.size(150.dp, 350.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
+76
-25
@@ -5,6 +5,10 @@ import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.core.getFolderNameFromUri
|
||||
import com.anthonyla.paperize.core.getWallpaperFromFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@@ -34,10 +38,10 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
event.albumsWithWallpaper.let { album ->
|
||||
val folders = album.folders.filter { _state.value.selectedFolders.contains(it.folderUri)}
|
||||
val wallpapers = album.wallpapers.filter { _state.value.selectedWallpapers.contains(it.wallpaperUri)}
|
||||
val doesContainCover = wallpapers.any { it.wallpaperUri == album.album.coverUri }
|
||||
val containsCoverUri = wallpapers.any { it.wallpaperUri == album.album.coverUri }
|
||||
repository.deleteFolderList(folders)
|
||||
repository.deleteWallpaperList(wallpapers)
|
||||
if (doesContainCover) {
|
||||
if (containsCoverUri) {
|
||||
repository.updateAlbum(album.album.copy(coverUri = null))
|
||||
}
|
||||
}
|
||||
@@ -47,15 +51,15 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
viewModelScope.launch {
|
||||
event.albumsWithWallpaper.let { album ->
|
||||
if (!_state.value.allSelected) {
|
||||
_state.update { state ->
|
||||
state.copy(
|
||||
_state.update { it ->
|
||||
it.copy(
|
||||
selectedFolders = album.folders.map { it.folderUri },
|
||||
selectedWallpapers = album.wallpapers.map { it.wallpaperUri },
|
||||
selectedCount = album.folders.size + album.wallpapers.size,
|
||||
maxSize = album.folders.size + album.wallpapers.size
|
||||
maxSize = album.folders.size + album.wallpapers.size,
|
||||
allSelected = true
|
||||
)
|
||||
}
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,12 +82,13 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.selectedFolders.any { it == event.directoryUri }) {
|
||||
_state.update {
|
||||
val folders = it.selectedFolders.plus(event.directoryUri)
|
||||
it.copy(
|
||||
selectedFolders = it.selectedFolders.plus(event.directoryUri),
|
||||
selectedCount = it.selectedCount + 1
|
||||
selectedFolders = folders,
|
||||
selectedCount = it.selectedCount + 1,
|
||||
allSelected = folders.size + it.selectedWallpapers.size >= it.maxSize
|
||||
)
|
||||
}
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,12 +97,13 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.selectedWallpapers.any { it == event.wallpaperUri }) {
|
||||
_state.update {
|
||||
val wallpapers = it.selectedWallpapers.plus(event.wallpaperUri)
|
||||
it.copy(
|
||||
selectedWallpapers = it.selectedWallpapers.plus(event.wallpaperUri),
|
||||
selectedCount = it.selectedCount + 1
|
||||
selectedCount = it.selectedCount + 1,
|
||||
allSelected = it.selectedFolders.size + wallpapers.size >= it.maxSize
|
||||
)
|
||||
}
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,12 +112,13 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
viewModelScope.launch {
|
||||
if (_state.value.selectedFolders.find { it == event.directoryUri } != null) {
|
||||
_state.update {
|
||||
val folders = it.selectedFolders.minus(event.directoryUri)
|
||||
it.copy(
|
||||
selectedFolders = it.selectedFolders.minus(event.directoryUri),
|
||||
selectedCount = it.selectedCount - 1
|
||||
selectedFolders = folders,
|
||||
selectedCount = it.selectedCount - 1,
|
||||
allSelected = folders.size + it.selectedWallpapers.size >= it.maxSize
|
||||
)
|
||||
}
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,12 +127,13 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
viewModelScope.launch {
|
||||
if (_state.value.selectedWallpapers.find { it == event.wallpaperUri } != null) {
|
||||
_state.update {
|
||||
val wallpapers = it.selectedWallpapers.minus(event.wallpaperUri)
|
||||
it.copy(
|
||||
selectedWallpapers = it.selectedWallpapers.minus(event.wallpaperUri),
|
||||
selectedCount = it.selectedCount - 1
|
||||
selectedWallpapers = wallpapers,
|
||||
selectedCount = it.selectedCount - 1,
|
||||
allSelected = it.selectedFolders.size + wallpapers.size >= it.maxSize
|
||||
)
|
||||
}
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,16 +161,59 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateAllSelected() {
|
||||
viewModelScope.launch {
|
||||
_state.update {
|
||||
it.copy(
|
||||
allSelected = it.selectedFolders.size + it.selectedWallpapers.size >= _state.value.maxSize
|
||||
)
|
||||
is AlbumViewEvent.AddWallpapers -> {
|
||||
viewModelScope.launch {
|
||||
val wallpaperUris = event.wallpaperUris.filterNot { it in event.album.wallpapers.map { wallpaper -> wallpaper.wallpaperUri } }
|
||||
val wallpapers = wallpaperUris.map { uri ->
|
||||
Wallpaper(
|
||||
initialAlbumName = event.album.album.initialAlbumName,
|
||||
wallpaperUri = uri,
|
||||
key = uri.hashCode() + event.album.album.initialAlbumName.hashCode(),
|
||||
)
|
||||
}
|
||||
repository.upsertWallpaperList(wallpapers)
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
maxSize = it.maxSize + wallpapers.size
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.AddFolder -> {
|
||||
viewModelScope.launch {
|
||||
if (event.directoryUri !in event.album.folders.map { it.folderUri }) {
|
||||
val wallpapers: List<String> = getWallpaperFromFolder(event.directoryUri, context)
|
||||
if (wallpapers.isEmpty()) { return@launch }
|
||||
val folderName = getFolderNameFromUri(event.directoryUri, context)
|
||||
repository.upsertFolder(
|
||||
Folder(
|
||||
folderUri = event.directoryUri,
|
||||
folderName = folderName,
|
||||
initialAlbumName = event.album.album.initialAlbumName,
|
||||
key = event.directoryUri.hashCode() + event.album.album.initialAlbumName.hashCode(),
|
||||
coverUri = wallpapers.randomOrNull(),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
)
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
maxSize = it.maxSize + 1
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-4
@@ -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
|
||||
@@ -56,7 +55,6 @@ fun AlbumViewTopBar(
|
||||
onDeleteAlbum: () -> Unit,
|
||||
onDeleteSelected: () -> Unit,
|
||||
onTitleChange: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val state = albumState.collectAsStateWithLifecycle()
|
||||
var showDeleteAlertDialog by rememberSaveable { mutableStateOf(false) }
|
||||
@@ -104,12 +102,11 @@ 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)
|
||||
)
|
||||
}
|
||||
}
|
||||
Text("${state.value.selectedCount} selected")
|
||||
Text(stringResource(R.string.selected_count, state.value.selectedCount))
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
+4
-4
@@ -22,17 +22,17 @@ fun DeleteAlbumAlertDialog(
|
||||
icon = {
|
||||
Icon(Icons.Outlined.Delete, contentDescription = stringResource(R.string.delete_confirmation))
|
||||
},
|
||||
title = { Text(text = "Delete album?") },
|
||||
text = { Text(text = "Are you sure you want to delete this?") },
|
||||
title = { Text(text = stringResource(R.string.delete_album_question)) },
|
||||
text = { Text(text = stringResource(R.string.are_you_sure_you_want_to_delete_this)) },
|
||||
onDismissRequest = { onDismissRequest() },
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onConfirmation() }) {
|
||||
Text("Confirm")
|
||||
Text(stringResource(R.string.confirm))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { onDismissRequest() }) {
|
||||
Text("Cancel")
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
+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)
|
||||
}
|
||||
+72
-30
@@ -1,66 +1,108 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.folder_view_screen
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
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(
|
||||
folder: String,
|
||||
folderName: String?,
|
||||
wallpapers: List<String>,
|
||||
onBackClick: () -> Unit,
|
||||
onShowWallpaperView: (String) -> Unit
|
||||
onShowWallpaperView: (String) -> Unit,
|
||||
animate: Boolean
|
||||
) {
|
||||
val lazyListState = rememberLazyStaggeredGridState()
|
||||
val lazyListState = rememberLazyGridState()
|
||||
BackHandler { onBackClick() }
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
FolderViewTopBar(
|
||||
title = folderName ?: "",
|
||||
) {
|
||||
onBackClick()
|
||||
}
|
||||
onBackClick = onBackClick
|
||||
)
|
||||
},
|
||||
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 ->
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper,
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp)
|
||||
)
|
||||
) {
|
||||
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 = wallpapers[index],
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
allowHapticFeedback = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpapers[index])
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.size(150.dp, 350.dp)
|
||||
.animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
else {
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpapers[index],
|
||||
itemSelected = false,
|
||||
selectionMode = false,
|
||||
allowHapticFeedback = false,
|
||||
onActivateSelectionMode = {},
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpapers[index])
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.size(150.dp, 350.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
+104
-29
@@ -1,6 +1,5 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.home_screen
|
||||
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
@@ -20,33 +19,79 @@ import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumDialog
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components.HomeTopBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components.getTabItems
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.LibraryScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.tabItems
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreen
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun HomeScreen(
|
||||
onSettingsClick: () -> Unit,
|
||||
albums: List<AlbumWithWallpaperAndFolder>,
|
||||
animate : Boolean,
|
||||
darken: Boolean,
|
||||
homeDarkenPercentage: Int,
|
||||
lockDarkenPercentage: Int,
|
||||
enableChanger: Boolean,
|
||||
homeEnabled : Boolean,
|
||||
homeInterval: Int,
|
||||
lockInterval: Int,
|
||||
lastSetTime: String?,
|
||||
lockEnabled : Boolean,
|
||||
navigateToAddWallpaperScreen: (String) -> Unit,
|
||||
onAlbumViewClick: (String) -> Unit,
|
||||
onScheduleWallpaperChanger: (Int) -> Unit,
|
||||
onStop: () -> Unit
|
||||
nextSetTime: String?,
|
||||
onViewAlbum: (String) -> Unit,
|
||||
onDarkCheck: (Boolean) -> Unit,
|
||||
onDarkenPercentage: (Int, Int) -> Unit,
|
||||
onHomeCheckedChange: (Boolean) -> Unit,
|
||||
onLockCheckedChange: (Boolean) -> Unit,
|
||||
onScalingChange: (ScalingConstants) -> Unit,
|
||||
onScheduleWallpaperChanger: () -> Unit,
|
||||
onSelectAlbum: (AlbumWithWallpaperAndFolder, Boolean, Boolean) -> Unit,
|
||||
onScheduleSeparatelyChange: (Boolean) -> Unit,
|
||||
onHomeTimeChange: (Int) -> Unit,
|
||||
onLockTimeChange: (Int) -> Unit,
|
||||
onSettingsClick: () -> Unit,
|
||||
onStop: (Boolean, Boolean) -> Unit,
|
||||
onToggleChanger: (Boolean) -> Unit,
|
||||
scaling: ScalingConstants,
|
||||
scheduleSeparately: Boolean,
|
||||
blur: Boolean,
|
||||
onBlurPercentageChange: (Int, Int) -> Unit,
|
||||
onBlurChange: (Boolean) -> Unit,
|
||||
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
|
||||
) {
|
||||
var tabIndex by rememberSaveable { mutableIntStateOf(0) }
|
||||
val pagerState = rememberPagerState { tabItems.size }
|
||||
|
||||
val tabItems = getTabItems()
|
||||
val pagerState = rememberPagerState(0) { tabItems.size }
|
||||
var tabIndex by rememberSaveable { mutableIntStateOf(pagerState.currentPage) }
|
||||
var addAlbumDialog by rememberSaveable { mutableStateOf(false) }
|
||||
if (addAlbumDialog) AddAlbumDialog(
|
||||
onDismissRequest = { addAlbumDialog = false },
|
||||
onConfirmation = { navigateToAddWallpaperScreen(it) }
|
||||
)
|
||||
|
||||
LaunchedEffect(tabIndex) {
|
||||
pagerState.animateScrollToPage(tabIndex)
|
||||
}
|
||||
LaunchedEffect(pagerState.currentPage) {
|
||||
tabIndex = pagerState.currentPage
|
||||
}
|
||||
|
||||
Scaffold (
|
||||
topBar = {
|
||||
HomeTopBar(
|
||||
@@ -55,16 +100,12 @@ fun HomeScreen(
|
||||
onSettingsClick = onSettingsClick,
|
||||
)
|
||||
}
|
||||
) { padding ->
|
||||
LaunchedEffect(tabIndex) { pagerState.animateScrollToPage(tabIndex) }
|
||||
LaunchedEffect(pagerState) {
|
||||
snapshotFlow { pagerState.currentPage }.collect { page -> tabIndex = page }
|
||||
}
|
||||
Column(modifier = Modifier.padding(padding)) {
|
||||
) {
|
||||
Column(modifier = Modifier.padding(it)) {
|
||||
TabRow(
|
||||
selectedTabIndex = tabIndex,
|
||||
indicator = { tabPositions ->
|
||||
if (tabIndex < tabPositions.size) {
|
||||
if (tabIndex in tabPositions.indices) {
|
||||
TabRowDefaults.PrimaryIndicator(
|
||||
modifier = Modifier.tabIndicatorOffset(tabPositions[tabIndex]),
|
||||
shape = RoundedCornerShape(
|
||||
@@ -85,11 +126,7 @@ fun HomeScreen(
|
||||
text = { Text(text = item.title) },
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector =
|
||||
if (index == tabIndex)
|
||||
item.filledIcon
|
||||
else
|
||||
item.unfilledIcon,
|
||||
imageVector = if (index == tabIndex) item.filledIcon else item.unfilledIcon,
|
||||
contentDescription = item.title
|
||||
)
|
||||
}
|
||||
@@ -98,17 +135,55 @@ fun HomeScreen(
|
||||
}
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
beyondViewportPageCount = 1,
|
||||
userScrollEnabled = true,
|
||||
beyondViewportPageCount = 1
|
||||
) { index ->
|
||||
when(index) {
|
||||
when (index.coerceIn(tabItems.indices)) {
|
||||
0 -> WallpaperScreen(
|
||||
albums = albums,
|
||||
animate = animate,
|
||||
darken = darken,
|
||||
homeDarkenPercentage = homeDarkenPercentage,
|
||||
lockDarkenPercentage = lockDarkenPercentage,
|
||||
enableChanger = enableChanger,
|
||||
homeEnabled = homeEnabled,
|
||||
homeInterval = homeInterval,
|
||||
lockInterval = lockInterval,
|
||||
lastSetTime = lastSetTime,
|
||||
lockEnabled = lockEnabled,
|
||||
nextSetTime = nextSetTime,
|
||||
onDarkCheck = onDarkCheck,
|
||||
onDarkenPercentage = onDarkenPercentage,
|
||||
onHomeCheckedChange = onHomeCheckedChange,
|
||||
onLockCheckedChange = onLockCheckedChange,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
|
||||
onScheduleWallpaperChanger = onScheduleWallpaperChanger,
|
||||
onStop = onStop
|
||||
onScalingChange = onScalingChange,
|
||||
onSelectAlbum = onSelectAlbum,
|
||||
onHomeTimeChange = onHomeTimeChange,
|
||||
onLockTimeChange = onLockTimeChange,
|
||||
onStop = onStop,
|
||||
onToggleChanger = onToggleChanger,
|
||||
scaling = scaling,
|
||||
homeSelectedAlbum = homeSelectedAlbum,
|
||||
lockSelectedAlbum = lockSelectedAlbum,
|
||||
blur = blur,
|
||||
onBlurPercentageChange = onBlurPercentageChange,
|
||||
onBlurChange = onBlurChange,
|
||||
homeBlurPercentage = homeBlurPercentage,
|
||||
lockBlurPercentage = lockBlurPercentage,
|
||||
currentHomeWallpaper = currentHomeWallpaper,
|
||||
currentLockWallpaper = currentLockWallpaper,
|
||||
homeVignettePercentage = homeVignettePercentage,
|
||||
lockVignettePercentage = lockVignettePercentage,
|
||||
onVignettePercentageChange = onVignettePercentageChange,
|
||||
onVignetteChange = onVignetteChange,
|
||||
vignette = vignette
|
||||
)
|
||||
1 -> LibraryScreen(
|
||||
else -> LibraryScreen(
|
||||
albums = albums,
|
||||
onAddNewAlbumClick = { addAlbumDialog = true },
|
||||
onViewAlbum = onAlbumViewClick
|
||||
onViewAlbum = onViewAlbum,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -5,7 +5,6 @@ import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
@@ -45,7 +44,7 @@ fun HomeTopBar (
|
||||
) {
|
||||
CenterAlignedTopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
|
||||
title = { if (!showSelectionModeAppBar) Text(stringResource(R.string.appname)) },
|
||||
title = { if (!showSelectionModeAppBar) Text(stringResource(R.string.app_name)) },
|
||||
actions = {
|
||||
if (showSelectionModeAppBar) {
|
||||
var showAlertDialog by rememberSaveable { mutableStateOf(false) }
|
||||
@@ -87,7 +86,7 @@ fun HomeTopBar (
|
||||
.background(bgColor)
|
||||
)
|
||||
}
|
||||
Text("$selectionCount selected")
|
||||
Text(stringResource(R.string.selected_count, selectionCount))
|
||||
}
|
||||
} else {
|
||||
IconButton(
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.AddToPhotos
|
||||
import androidx.compose.material.icons.filled.Image
|
||||
import androidx.compose.material.icons.outlined.AddToPhotos
|
||||
import androidx.compose.material.icons.outlined.Image
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Data class representing a tab item
|
||||
*/
|
||||
data class TabItem(
|
||||
val title: String,
|
||||
val filledIcon: ImageVector,
|
||||
val unfilledIcon: ImageVector,
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun getTabItems(): List<TabItem> {
|
||||
val context = LocalContext.current
|
||||
return listOf(
|
||||
TabItem(
|
||||
title = context.getString(R.string.wallpaper_screen),
|
||||
filledIcon = Icons.Filled.Image,
|
||||
unfilledIcon = Icons.Outlined.Image
|
||||
),
|
||||
TabItem(
|
||||
title = context.getString(R.string.library_screen),
|
||||
filledIcon = Icons.Filled.AddToPhotos,
|
||||
unfilledIcon = Icons.Outlined.AddToPhotos
|
||||
)
|
||||
)
|
||||
}
|
||||
+6
-9
@@ -18,20 +18,17 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.AlbumItem
|
||||
|
||||
@Composable
|
||||
fun LibraryScreen(
|
||||
albumsViewModel: AlbumsViewModel = hiltViewModel(),
|
||||
albums: List<AlbumWithWallpaperAndFolder>,
|
||||
onAddNewAlbumClick: () -> Unit,
|
||||
onViewAlbum: (String) -> Unit
|
||||
) {
|
||||
) {
|
||||
val lazyListState = rememberLazyGridState()
|
||||
val state = albumsViewModel.state.collectAsStateWithLifecycle()
|
||||
Scaffold(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
floatingActionButton = {
|
||||
@@ -51,16 +48,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)
|
||||
modifier = Modifier.padding(4.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -5,14 +5,15 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.data.rememberCurrentOffset
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components.LicenseScrollableSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components.LicenseSmallTopAppBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components.LicenseTitle
|
||||
|
||||
@Composable
|
||||
fun LicensesScreen(
|
||||
topInsets: Dp,
|
||||
onBackClick: () -> Unit,
|
||||
) {
|
||||
val lazyListState = rememberLazyListState()
|
||||
@@ -25,14 +26,15 @@ fun LicensesScreen(
|
||||
LicenseScrollableSettings(
|
||||
largeTopAppBarHeightPx = largeTopAppBarHeight,
|
||||
lazyListState = lazyListState,
|
||||
offset = offset
|
||||
offset = offset,
|
||||
onBackClick = onBackClick
|
||||
)
|
||||
LicenseSmallTopAppBar(onBackClick = onBackClick)
|
||||
LicenseTitle(
|
||||
largeTopAppBarHeight = largeTopAppBarHeight,
|
||||
smallTopAppBarHeight = smallTopAppBarHeight,
|
||||
paddingMedium = paddingMedium,
|
||||
offset = offset
|
||||
offset = offset,
|
||||
topInset = topInsets
|
||||
)
|
||||
}
|
||||
}
|
||||
+57
-24
@@ -6,50 +6,83 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
|
||||
import com.mikepenz.aboutlibraries.ui.compose.m3.LibraryDefaults
|
||||
|
||||
/**
|
||||
* Scrollable license screen to display open source licenses
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LicenseScrollableSettings(
|
||||
largeTopAppBarHeightPx: Dp,
|
||||
lazyListState: LazyListState,
|
||||
offset: State<Int>
|
||||
offset: State<Int>,
|
||||
onBackClick: () -> Unit
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 24.dp),
|
||||
) {
|
||||
val offsetInDp = offset.value.toFloat() / 2f.dp.value
|
||||
val newHeight = largeTopAppBarHeightPx - offsetInDp.dp
|
||||
Spacer(Modifier.height(newHeight))
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
LibrariesContainer(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
lazyListState = lazyListState,
|
||||
showVersion = false,
|
||||
colors = LibraryDefaults.libraryColors(
|
||||
backgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
contentColor = MaterialTheme.colorScheme.onSurface,
|
||||
badgeBackgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
badgeContentColor = MaterialTheme.colorScheme.primary,
|
||||
dialogConfirmButtonColor = MaterialTheme.colorScheme.onSurface
|
||||
Scaffold (
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
) { it
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 24.dp),
|
||||
) {
|
||||
val offsetInDp = offset.value.toFloat() / 2f.dp.value
|
||||
val newHeight = largeTopAppBarHeightPx - offsetInDp.dp
|
||||
Spacer(Modifier.height(newHeight))
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
LibrariesContainer(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
lazyListState = lazyListState,
|
||||
showVersion = false,
|
||||
colors = LibraryDefaults.libraryColors(
|
||||
backgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
contentColor = MaterialTheme.colorScheme.onSurface,
|
||||
badgeBackgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
|
||||
badgeContentColor = MaterialTheme.colorScheme.primary,
|
||||
dialogConfirmButtonColor = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Small top app bar for license screen to replace [LicenseLargeTopAppBar] when scrolling down
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LicenseSmallTopAppBar(onBackClick: () -> Unit) {
|
||||
Surface {
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
|
||||
title = {},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
+7
-11
@@ -1,19 +1,11 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -35,7 +27,8 @@ fun LicenseTitle(
|
||||
smallTopAppBarHeight: Dp,
|
||||
paddingMedium: Dp,
|
||||
modifier: Modifier = Modifier,
|
||||
offset: State<Int>
|
||||
offset: State<Int>,
|
||||
topInset: Dp,
|
||||
) {
|
||||
val titlePaddingStart = 16.dp
|
||||
val titlePaddingEnd = 64.dp
|
||||
@@ -44,6 +37,9 @@ fun LicenseTitle(
|
||||
var titleHeightPx by remember { mutableFloatStateOf(0f) }
|
||||
var titleWidthPx by remember { mutableFloatStateOf(0f) }
|
||||
|
||||
val fraction = (topInset - 74.dp) / (151.dp - 74.dp)
|
||||
val statusPadding = lerp(0.dp, 24.dp, fraction.coerceIn(0f, 1f))
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.licenses),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
@@ -63,7 +59,7 @@ fun LicenseTitle(
|
||||
val titleExtraStartPadding = titleWidthPx.toDp() * (1 - scaleXY.value) / 2f
|
||||
|
||||
val titleYFirstInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium,
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium + statusPadding,
|
||||
largeTopAppBarHeight / 2,
|
||||
collapseFraction
|
||||
)
|
||||
@@ -76,7 +72,7 @@ fun LicenseTitle(
|
||||
|
||||
val titleYSecondInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight / 2,
|
||||
(smallTopAppBarHeight - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
(smallTopAppBarHeight + statusPadding - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
|
||||
+11
-47
@@ -18,23 +18,18 @@ import androidx.compose.material3.ExtendedFloatingActionButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Snackbar
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.SnackbarResult
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.airbnb.lottie.compose.LottieAnimation
|
||||
@@ -43,46 +38,21 @@ import com.airbnb.lottie.compose.LottieConstants
|
||||
import com.airbnb.lottie.compose.animateLottieCompositionAsState
|
||||
import com.airbnb.lottie.compose.rememberLottieComposition
|
||||
import com.anthonyla.paperize.R
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun NotificationScreen(
|
||||
onAgree: () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val scope = rememberCoroutineScope()
|
||||
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.notification_animation))
|
||||
val progress by animateLottieCompositionAsState(
|
||||
composition = composition,
|
||||
iterations = LottieConstants.IterateForever,
|
||||
)
|
||||
val askPermission = rememberSaveable { mutableStateOf(false) }
|
||||
val askCount = rememberSaveable { mutableIntStateOf(0) }
|
||||
|
||||
val requestPermissionLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.RequestPermission()
|
||||
) { isGranted: Boolean ->
|
||||
if (isGranted) {
|
||||
onAgree()
|
||||
} else {
|
||||
if (++askCount.intValue >= 2) {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
onAgree()
|
||||
}
|
||||
scope.launch {
|
||||
val result = snackbarHostState.showSnackbar(
|
||||
message = context.getString(R.string.notification_permission_is_required_for_this_app_to_work_properly),
|
||||
actionLabel = context.getString(R.string.allow),
|
||||
duration = SnackbarDuration.Short,
|
||||
)
|
||||
when (result) {
|
||||
SnackbarResult.Dismissed -> {}
|
||||
SnackbarResult.ActionPerformed -> { askPermission.value = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
) { onAgree() }
|
||||
|
||||
fun handleFabClick() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
@@ -100,30 +70,24 @@ fun NotificationScreen(
|
||||
LaunchedEffect (askPermission.value) {
|
||||
if (askPermission.value) {
|
||||
handleFabClick()
|
||||
askPermission.value = false
|
||||
}
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = {
|
||||
SnackbarHost(
|
||||
hostState = snackbarHostState,
|
||||
snackbar = { data ->
|
||||
Snackbar(
|
||||
snackbarData = data,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 8.dp, vertical = 8.dp))
|
||||
)
|
||||
}
|
||||
) },
|
||||
content = { it
|
||||
Column (modifier = Modifier.padding(32.dp)) {
|
||||
Spacer(modifier = Modifier.height(120.dp))
|
||||
Text(text = "Notifications", style = MaterialTheme.typography.headlineLarge)
|
||||
Text(text = stringResource(id = R.string.notifications), style = MaterialTheme.typography.headlineLarge)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
LottieAnimation(
|
||||
composition = composition,
|
||||
progress = { progress },
|
||||
modifier = Modifier.fillMaxHeight(0.5f)
|
||||
modifier = Modifier
|
||||
.fillMaxHeight(0.5f)
|
||||
.align(Alignment.CenterHorizontally)
|
||||
.semantics { contentDescription = context.getString(R.string.notification_bell_animation) },
|
||||
safeMode = true,
|
||||
enableMergePaths = true
|
||||
)
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Info,
|
||||
|
||||
+5
-3
@@ -6,13 +6,14 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components.PrivacyScrollableSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components.PrivacySmallTopAppBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components.PrivacyTitle
|
||||
|
||||
@Composable
|
||||
fun PrivacyScreen(
|
||||
topInsets: Dp,
|
||||
onBackClick: () -> Unit,
|
||||
) {
|
||||
val scroll: ScrollState = rememberScrollState(0)
|
||||
@@ -24,13 +25,14 @@ fun PrivacyScreen(
|
||||
PrivacyScrollableSettings(
|
||||
largeTopAppBarHeightPx = largeTopAppBarHeight,
|
||||
scroll = scroll,
|
||||
onBackClick = onBackClick
|
||||
)
|
||||
PrivacySmallTopAppBar(onBackClick = onBackClick)
|
||||
PrivacyTitle(
|
||||
scroll = scroll,
|
||||
largeTopAppBarHeight = largeTopAppBarHeight,
|
||||
smallTopAppBarHeight = smallTopAppBarHeight,
|
||||
paddingMedium = paddingMedium
|
||||
paddingMedium = paddingMedium,
|
||||
topInset = topInsets
|
||||
)
|
||||
}
|
||||
}
|
||||
+54
-21
@@ -7,47 +7,80 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Scrollable privacy screen to display privacy policy
|
||||
* Scrollable privacy screen to display privacy note
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun PrivacyScrollableSettings(
|
||||
largeTopAppBarHeightPx: Dp,
|
||||
scroll: ScrollState,
|
||||
onBackClick: () -> Unit
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.verticalScroll(scroll)
|
||||
.padding(horizontal = 24.dp),
|
||||
) {
|
||||
Spacer(Modifier.height(largeTopAppBarHeightPx))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PrivacyPolicyText()
|
||||
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 PrivacyPolicyText() {
|
||||
SectionText("Introduction", "Welcome to Paperize! This privacy policy outlines how we collect, use, and protect your personal information when you use our mobile application. By using Paperize, you agree to the terms described in this policy.")
|
||||
SectionText("Data Collection", "Notification Access: Paperize requests notification access to provide you with personalized wallpaper recommendations based on your notifications. We do not store any notification content or personally identifiable information (PII) outside of your device.\n\nLocal Files: Paperize accesses files stored on your device to allow you to set them as wallpapers. We do not upload or transfer these files to any external servers.")
|
||||
SectionText("Information Usage", "Personal Data: We do not collect or store any personal data such as names, email addresses, or phone numbers.\n\nUsage Analytics: Paperize does not track your usage behavior or collect analytics data.")
|
||||
SectionText("Data Security", "On-Device Storage: All data used by Paperize remains on your device. We do not transmit or store any data externally.\n\nEncryption: We use encryption protocols to secure communication between the app and your device.")
|
||||
SectionText("Third-Party Services", "Advertisements: Paperize does not display third-party ads.\n\nExternal Links: Our app may contain links to external websites. Please note that we are not responsible for the privacy practices of these sites.")
|
||||
SectionText("Children’s Privacy", "Paperize is not intended for children under the age of 13. We do not knowingly collect any information from children.")
|
||||
SectionText("Changes to this Policy", "We may update this privacy policy from time to time. Any changes will be reflected in the app and on our website.")
|
||||
SectionText("Contact Us", "If you have any questions or concerns about this privacy policy, please contact me at anthonyyla.dev@gmail.com.")
|
||||
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
|
||||
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Small top app bar for privacy screen to replace [PrivacyLargeTopAppBar] when scrolling down
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun PrivacySmallTopAppBar(onBackClick: () -> Unit) {
|
||||
Surface {
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
|
||||
title = {},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -27,7 +27,8 @@ fun PrivacyTitle(
|
||||
smallTopAppBarHeight: Dp,
|
||||
paddingMedium: Dp,
|
||||
scroll: ScrollState,
|
||||
modifier: Modifier = Modifier
|
||||
modifier: Modifier = Modifier,
|
||||
topInset: Dp,
|
||||
) {
|
||||
val titlePaddingStart = 16.dp
|
||||
val titlePaddingEnd = 64.dp
|
||||
@@ -36,6 +37,9 @@ fun PrivacyTitle(
|
||||
var titleHeightPx by remember { mutableFloatStateOf(0f) }
|
||||
var titleWidthPx by remember { mutableFloatStateOf(0f) }
|
||||
|
||||
val fraction = (topInset - 74.dp) / (151.dp - 74.dp)
|
||||
val statusPadding = lerp(0.dp, 24.dp, fraction.coerceIn(0f, 1f))
|
||||
|
||||
Text(
|
||||
text = stringResource(id = R.string.privacy_policy),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
@@ -55,7 +59,7 @@ fun PrivacyTitle(
|
||||
val titleExtraStartPadding = titleWidthPx.toDp() * (1 - scaleXY.value) / 2f
|
||||
|
||||
val titleYFirstInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium,
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium + statusPadding,
|
||||
largeTopAppBarHeight / 2,
|
||||
collapseFraction
|
||||
)
|
||||
@@ -68,7 +72,7 @@ fun PrivacyTitle(
|
||||
|
||||
val titleYSecondInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight / 2,
|
||||
(smallTopAppBarHeight - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
(smallTopAppBarHeight + statusPadding - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
|
||||
+28
-2
@@ -1,12 +1,38 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen
|
||||
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
|
||||
|
||||
sealed class SettingsEvent {
|
||||
data object Refresh: SettingsEvent()
|
||||
data object Reset: SettingsEvent()
|
||||
data object SetFirstLaunch: SettingsEvent()
|
||||
data object RefreshNextSetTime: SettingsEvent()
|
||||
data class SetDarkMode(val darkMode: Boolean?): SettingsEvent()
|
||||
data class SetAmoledTheme(val amoledTheme: Boolean): SettingsEvent()
|
||||
data class SetDynamicTheming(val dynamicTheming: Boolean): SettingsEvent()
|
||||
data class SetAnimate(val animate: Boolean): SettingsEvent()
|
||||
data class SetWallpaperInterval(val interval: Int): SettingsEvent()
|
||||
data class SetLockWithHome(val lockWithHome: Boolean): SettingsEvent()
|
||||
data class SetDarken(val darken: Boolean): SettingsEvent()
|
||||
data class SetBlur(val blur: Boolean): SettingsEvent()
|
||||
data class SetVignette(val vignette: Boolean): SettingsEvent()
|
||||
data class SetLock(val lock: Boolean): SettingsEvent()
|
||||
data class SetHome(val home: 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 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 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 object RefreshNextWallpaper: SettingsEvent()
|
||||
}
|
||||
+17
-7
@@ -4,27 +4,34 @@ import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.SettingsScrollableSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.SettingsTitle
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.SettingsSmallTopAppBar
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::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
|
||||
onLicenseClick: () -> Unit,
|
||||
onResetClick: () -> Unit
|
||||
) {
|
||||
val scroll: ScrollState = rememberScrollState(0)
|
||||
val largeTopAppBarHeight = 152.dp
|
||||
val smallTopAppBarHeight = 64.dp
|
||||
val largeTopAppBarHeight = TopAppBarDefaults.LargeAppBarExpandedHeight
|
||||
val smallTopAppBarHeight = TopAppBarDefaults.LargeAppBarCollapsedHeight
|
||||
val paddingMedium = 16.dp
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
@@ -33,17 +40,20 @@ fun SettingsScreen(
|
||||
largeTopAppBarHeightPx = largeTopAppBarHeight,
|
||||
scroll = scroll,
|
||||
onDarkModeClick = onDarkModeClick,
|
||||
onAmoledClick = onAmoledClick,
|
||||
onDynamicThemingClick = onDynamicThemingClick,
|
||||
onAnimateClick = onAnimateClick,
|
||||
onPrivacyClick = onPrivacyClick,
|
||||
onLicenseClick = onLicenseClick
|
||||
onLicenseClick = onLicenseClick,
|
||||
onResetClick = onResetClick,
|
||||
onBackClick = onBackClick
|
||||
)
|
||||
SettingsSmallTopAppBar(onBackClick = onBackClick)
|
||||
SettingsTitle(
|
||||
scroll = scroll,
|
||||
largeTopAppBarHeight = largeTopAppBarHeight,
|
||||
smallTopAppBarHeight = smallTopAppBarHeight,
|
||||
paddingMedium = paddingMedium
|
||||
paddingMedium = paddingMedium,
|
||||
topInset = topInsets
|
||||
)
|
||||
}
|
||||
}
|
||||
+28
-4
@@ -1,13 +1,37 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
|
||||
data class SettingsState (
|
||||
data class SettingsState(
|
||||
val firstLaunch: Boolean = true,
|
||||
// App settings
|
||||
val darkMode: Boolean? = null,
|
||||
val amoledTheme: Boolean = false,
|
||||
val dynamicTheming: Boolean = false,
|
||||
val animate: Boolean = true,
|
||||
val interval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val setLockWithHome: Boolean = false,
|
||||
// Wallpaper settings
|
||||
val enableChanger: Boolean = false,
|
||||
val setHomeWallpaper: Boolean = false,
|
||||
val setLockWallpaper: Boolean = false,
|
||||
val 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 nextSetTime: String? = null,
|
||||
val homeDarkenPercentage: Int = 100,
|
||||
val lockDarkenPercentage: Int = 100,
|
||||
val darken: Boolean = false,
|
||||
val blur: Boolean = false,
|
||||
val homeBlurPercentage: Int = 0,
|
||||
val lockBlurPercentage: Int = 0,
|
||||
val vignette: Boolean = false,
|
||||
val homeVignettePercentage: Int = 0,
|
||||
val lockVignettePercentage: Int = 0,
|
||||
val wallpaperScaling: ScalingConstants = ScalingConstants.FILL,
|
||||
val nextHomeWallpaper: String? = null,
|
||||
val nextLockWallpaper: String? = null
|
||||
)
|
||||
+661
-73
@@ -1,8 +1,8 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen
|
||||
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
@@ -14,9 +14,9 @@ import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.format.FormatStyle
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
@@ -33,26 +33,70 @@ class SettingsViewModel @Inject constructor (
|
||||
var setKeepOnScreenCondition: Boolean = true
|
||||
|
||||
init {
|
||||
currentGetJob = viewModelScope.launch {
|
||||
val darkMode = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) }
|
||||
val dynamicTheming = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false }
|
||||
val wallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
currentGetJob = viewModelScope.launch(Dispatchers.IO) {
|
||||
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
|
||||
val setLockWithHome = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SET_LOCK_WITH_HOME) ?: 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) ?: 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 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 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 nextHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME) }
|
||||
val nextLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME) }
|
||||
|
||||
_state.update { it.copy(
|
||||
darkMode = darkMode.await(),
|
||||
dynamicTheming = dynamicTheming.await(),
|
||||
interval = wallpaperInterval.await(),
|
||||
setLockWithHome = setLockWithHome.await(),
|
||||
firstLaunch = firstLaunch.await(),
|
||||
lastSetTime = lastSetTime.await(),
|
||||
nextSetTime = nextSetTime.await(),
|
||||
animate = animate.await()
|
||||
) }
|
||||
_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(),
|
||||
lastSetTime = lastSetTime.await(),
|
||||
nextSetTime = nextSetTime.await(),
|
||||
animate = animate.await(),
|
||||
enableChanger = enableChanger.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(),
|
||||
homeBlurPercentage = homeBlurPercentage.await(),
|
||||
lockBlurPercentage = lockBlurPercentage.await(),
|
||||
nextHomeWallpaper = nextHomeWallpaper.await(),
|
||||
nextLockWallpaper = nextLockWallpaper.await(),
|
||||
vignette = vignette.await(),
|
||||
homeVignettePercentage = homeVignettePercentage.await(),
|
||||
lockVignettePercentage = lockVignettePercentage.await()
|
||||
)
|
||||
}
|
||||
setKeepOnScreenCondition = false
|
||||
}
|
||||
}
|
||||
@@ -60,95 +104,639 @@ class SettingsViewModel @Inject constructor (
|
||||
fun onEvent(event: SettingsEvent) {
|
||||
when (event) {
|
||||
is SettingsEvent.SetFirstLaunch -> {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.FIRST_LAUNCH, false)
|
||||
_state.update { it.copy(
|
||||
firstLaunch = false
|
||||
) }
|
||||
_state.update {
|
||||
it.copy(
|
||||
firstLaunch = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetChangerToggle -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, event.toggle)
|
||||
_state.update {
|
||||
it.copy(
|
||||
enableChanger = event.toggle
|
||||
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.Refresh -> {
|
||||
currentGetJob = viewModelScope.launch {
|
||||
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 wallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
|
||||
val setLockWithHome = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SET_LOCK_WITH_HOME) ?: false }
|
||||
val lastSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME) }
|
||||
val nextSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME) }
|
||||
val animate = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true }
|
||||
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.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 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 }
|
||||
|
||||
_state.update { it.copy(
|
||||
darkMode = darkMode.await(),
|
||||
dynamicTheming = dynamicTheming.await(),
|
||||
interval = wallpaperInterval.await(),
|
||||
setLockWithHome = setLockWithHome.await(),
|
||||
firstLaunch = firstLaunch.await(),
|
||||
lastSetTime = lastSetTime.await(),
|
||||
nextSetTime = nextSetTime.await(),
|
||||
animate = animate.await()
|
||||
) }
|
||||
_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(),
|
||||
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(),
|
||||
homeBlurPercentage = homeBlurPercentage.await(),
|
||||
lockBlurPercentage = lockBlurPercentage.await(),
|
||||
nextHomeWallpaper = nextHomeWallpaper.await(),
|
||||
nextLockWallpaper = nextLockWallpaper.await(),
|
||||
vignette = vignette.await(),
|
||||
homeVignettePercentage = homeVignettePercentage.await(),
|
||||
lockVignettePercentage = lockVignettePercentage.await()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetDarkMode -> {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
when (event.darkMode) {
|
||||
true -> { settingsDataStoreImpl.putBoolean(SettingsConstants.DARK_MODE_TYPE, true) }
|
||||
false -> { settingsDataStoreImpl.putBoolean(SettingsConstants.DARK_MODE_TYPE, false) }
|
||||
null -> { settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARK_MODE_TYPE) }
|
||||
}
|
||||
_state.update { it.copy(
|
||||
darkMode = event.darkMode
|
||||
) }
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = event.darkMode
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
when (event.dynamicTheming) {
|
||||
true -> { settingsDataStoreImpl.putBoolean(SettingsConstants.DYNAMIC_THEME_TYPE, true) }
|
||||
false -> { settingsDataStoreImpl.putBoolean(SettingsConstants.DYNAMIC_THEME_TYPE, false) }
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.DYNAMIC_THEME_TYPE, event.dynamicTheming)
|
||||
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
|
||||
)
|
||||
}
|
||||
_state.update { it.copy(
|
||||
dynamicTheming = event.dynamicTheming
|
||||
) }
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetAnimate -> {
|
||||
viewModelScope.launch {
|
||||
when (event.animate) {
|
||||
true -> { settingsDataStoreImpl.putBoolean(SettingsConstants.ANIMATE_TYPE, true) }
|
||||
false -> { settingsDataStoreImpl.putBoolean(SettingsConstants.ANIMATE_TYPE, false) }
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ANIMATE_TYPE, event.animate)
|
||||
_state.update {
|
||||
it.copy(
|
||||
animate = event.animate
|
||||
)
|
||||
}
|
||||
_state.update { it.copy(
|
||||
animate = event.animate
|
||||
) }
|
||||
}
|
||||
}
|
||||
is SettingsEvent.SetWallpaperInterval -> {
|
||||
viewModelScope.launch {
|
||||
val formatter = DateTimeFormatter.ofPattern("MM/dd/yy hh:mm\na")
|
||||
val time = LocalDateTime.now()
|
||||
val formattedLastSetTime = time.format(formatter)
|
||||
val formattedNextSetTime = time.plusMinutes(event.interval.toLong()).format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, formattedLastSetTime)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, formattedNextSetTime)
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL, event.interval)
|
||||
_state.update { it.copy(
|
||||
interval = event.interval,
|
||||
lastSetTime = formattedLastSetTime,
|
||||
nextSetTime = formattedNextSetTime
|
||||
) }
|
||||
|
||||
is SettingsEvent.SetHomeWallpaperInterval -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL, event.interval)
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now()
|
||||
val nextSetTime: String?
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
|
||||
if (_state.value.scheduleSeparately) {
|
||||
val 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.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.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(
|
||||
homeInterval = event.interval,
|
||||
lastSetTime = currentTime.format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
is SettingsEvent.SetLockWithHome -> {
|
||||
|
||||
is SettingsEvent.SetLockWallpaperInterval -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL, event.interval)
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now()
|
||||
val nextSetTime: String?
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
|
||||
if (_state.value.scheduleSeparately) {
|
||||
val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong())
|
||||
val nextSetTime2 = currentTime.plusMinutes(event.interval.toLong())
|
||||
nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)!!.format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.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.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(
|
||||
lockInterval = event.interval,
|
||||
lastSetTime = currentTime.format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.RefreshNextSetTime -> {
|
||||
viewModelScope.launch {
|
||||
when (event.lockWithHome) {
|
||||
true -> { settingsDataStoreImpl.putBoolean(SettingsConstants.SET_LOCK_WITH_HOME, true) }
|
||||
false -> { settingsDataStoreImpl.putBoolean(SettingsConstants.SET_LOCK_WITH_HOME, false) }
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now()
|
||||
val nextSetTime: String?
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
|
||||
if (_state.value.scheduleSeparately) {
|
||||
val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong())
|
||||
val nextSetTime2 = currentTime.plusMinutes(_state.value.lockInterval.toLong())
|
||||
nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)!!.format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime1.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime2.toString())
|
||||
}
|
||||
else {
|
||||
nextSetTime = currentTime.plusMinutes(_state.value.homeInterval.toLong()).format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
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())
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
lastSetTime = currentTime.format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetHome -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER, event.home)
|
||||
_state.update {
|
||||
it.copy(
|
||||
setHomeWallpaper = event.home
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetLock -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER, event.lock)
|
||||
_state.update {
|
||||
it.copy(
|
||||
setLockWallpaper = event.lock
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetDarken -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.DARKEN, event.darken)
|
||||
_state.update {
|
||||
it.copy(
|
||||
darken = event.darken
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetWallpaperScaling -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.WALLPAPER_SCALING, event.scaling.name)
|
||||
_state.update {
|
||||
it.copy(
|
||||
wallpaperScaling = event.scaling
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetScheduleSeparately -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.SCHEDULE_SEPARATELY, event.scheduleSeparately)
|
||||
_state.update {
|
||||
it.copy(
|
||||
scheduleSeparately = event.scheduleSeparately
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetBlur -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.BLUR, event.blur)
|
||||
_state.update {
|
||||
it.copy(
|
||||
blur = event.blur
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetDarkenPercentage -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
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(
|
||||
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.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.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.HOME_DARKEN_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_DARKEN_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARKEN)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.WALLPAPER_SCALING)
|
||||
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.HOME_BLUR_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_BLUR_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.FIRST_SET)
|
||||
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)
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = null,
|
||||
amoledTheme = false,
|
||||
dynamicTheming = false,
|
||||
firstLaunch = true,
|
||||
lastSetTime = null,
|
||||
nextSetTime = null,
|
||||
animate = true,
|
||||
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,
|
||||
nextHomeWallpaper = null,
|
||||
nextLockWallpaper = null,
|
||||
vignette = false,
|
||||
homeVignettePercentage = 0,
|
||||
lockVignettePercentage = 0
|
||||
)
|
||||
}
|
||||
_state.update { it.copy(
|
||||
setLockWithHome = event.lockWithHome
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+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
|
||||
)
|
||||
}
|
||||
}
|
||||
+8
-5
@@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Animation
|
||||
import androidx.compose.material.icons.outlined.Palette
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -14,15 +13,19 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Enable animation switch
|
||||
*/
|
||||
@Composable
|
||||
fun AnimationListItem(animate: Boolean, onAnimateClick: (Boolean) -> Unit) {
|
||||
val context = LocalContext.current
|
||||
Row {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
@@ -30,17 +33,17 @@ fun AnimationListItem(animate: Boolean, onAnimateClick: (Boolean) -> Unit) {
|
||||
.clickable { onAnimateClick(!animate) },
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = "Animation",
|
||||
text = stringResource(R.string.animation),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = "Increase visual appeal",
|
||||
text = stringResource(R.string.increase_visual_appeal),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {
|
||||
Switch(
|
||||
modifier = Modifier.semantics { contentDescription = "Animation" },
|
||||
modifier = Modifier.semantics { contentDescription = context.getString(R.string.animation) },
|
||||
checked = animate,
|
||||
onCheckedChange = onAnimateClick,
|
||||
enabled = true
|
||||
@@ -48,7 +51,7 @@ fun AnimationListItem(animate: Boolean, onAnimateClick: (Boolean) -> Unit) {
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.Outlined.Animation,
|
||||
contentDescription = "Animation",
|
||||
contentDescription = stringResource(R.string.animation),
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
) },
|
||||
tonalElevation = 5.dp
|
||||
|
||||
-3
@@ -4,10 +4,7 @@ import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.ArrowCircleRight
|
||||
import androidx.compose.material.icons.outlined.Email
|
||||
import androidx.compose.material.icons.outlined.PrivacyTip
|
||||
import androidx.compose.material.icons.outlined.SubdirectoryArrowRight
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
|
||||
+12
-10
@@ -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
|
||||
@@ -30,19 +29,20 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Three-state selector for dark mode in settings
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun DarkModeListItem(darkMode: Boolean?, onDarkModeClick: (Boolean?) -> Unit) {
|
||||
val options = listOf(
|
||||
Triple("Dark Mode", Icons.Outlined.DarkMode, Icons.Filled.DarkMode),
|
||||
Triple("Automatic Device Mode", Icons.Outlined.BrightnessAuto, Icons.Filled.BrightnessAuto),
|
||||
Triple("Light Mode", Icons.Outlined.LightMode, Icons.Filled.LightMode)
|
||||
Triple(stringResource(R.string.dark_mode), Icons.Outlined.DarkMode, Icons.Filled.DarkMode),
|
||||
Triple(stringResource(R.string.automatic_device_mode), Icons.Outlined.BrightnessAuto, Icons.Filled.BrightnessAuto),
|
||||
Triple(stringResource(R.string.light_mode), Icons.Outlined.LightMode, Icons.Filled.LightMode)
|
||||
)
|
||||
var selectedIndex by remember {
|
||||
mutableIntStateOf(
|
||||
@@ -51,7 +51,8 @@ fun DarkModeListItem(darkMode: Boolean?, onDarkModeClick: (Boolean?) -> Unit) {
|
||||
false -> 2
|
||||
else -> 1
|
||||
}
|
||||
) }
|
||||
)
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
@@ -70,16 +71,17 @@ fun DarkModeListItem(darkMode: Boolean?, onDarkModeClick: (Boolean?) -> Unit) {
|
||||
2 -> false
|
||||
else -> null
|
||||
}
|
||||
) },
|
||||
)
|
||||
},
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = "Dark Mode",
|
||||
text = stringResource(R.string.theme),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = "Easier on the eyes",
|
||||
text = stringResource(R.string.easier_on_the_eyes),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
) },
|
||||
@@ -116,7 +118,7 @@ fun DarkModeListItem(darkMode: Boolean?, onDarkModeClick: (Boolean?) -> Unit) {
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.Outlined.Brightness6,
|
||||
contentDescription = "Dark Mode",
|
||||
contentDescription = stringResource(R.string.dark_mode),
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
},
|
||||
|
||||
+8
-4
@@ -13,15 +13,19 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Dynamic theming switch
|
||||
*/
|
||||
@Composable
|
||||
fun DynamicThemingListItem(dynamicTheming: Boolean, onDynamicThemingClick: (Boolean) -> Unit) {
|
||||
val context = LocalContext.current
|
||||
Row {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
@@ -29,18 +33,18 @@ fun DynamicThemingListItem(dynamicTheming: Boolean, onDynamicThemingClick: (Bool
|
||||
.clickable { onDynamicThemingClick(!dynamicTheming) },
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = "Dynamic Theme",
|
||||
text = stringResource(R.string.dynamic_theme),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = "Material You",
|
||||
text = stringResource(R.string.material_you),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {
|
||||
Switch(
|
||||
modifier = Modifier.semantics { contentDescription = "Dynamic Theme" },
|
||||
modifier = Modifier.semantics { contentDescription = context.getString(R.string.dynamic_theme) },
|
||||
checked = dynamicTheming,
|
||||
onCheckedChange = onDynamicThemingClick,
|
||||
enabled = true
|
||||
@@ -48,7 +52,7 @@ fun DynamicThemingListItem(dynamicTheming: Boolean, onDynamicThemingClick: (Bool
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.Outlined.Palette,
|
||||
contentDescription = "Dynamic Theming",
|
||||
contentDescription = stringResource(R.string.dynamic_theming),
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
) },
|
||||
tonalElevation = 5.dp
|
||||
|
||||
+1
-3
@@ -4,8 +4,6 @@ import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.outlined.LibraryBooks
|
||||
import androidx.compose.material.icons.outlined.Newspaper
|
||||
import androidx.compose.material.icons.outlined.PrivacyTip
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -34,7 +32,7 @@ fun LicenseListItem(onLicenseClick: () -> Unit) {
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = "Click here to view the licenses",
|
||||
text = stringResource(R.string.click_here_to_view_the_licenses),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {},
|
||||
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.scale
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
|
||||
/**
|
||||
* List item for app version and link to GitHub and PlayStore
|
||||
*/
|
||||
@Composable
|
||||
fun PaperizeListItem(onGitHubClick: () -> Unit, onIzzyOnDroidClick: () -> Unit, onFdroidClick: () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
var version = ""
|
||||
try {
|
||||
val pInfo: PackageInfo =
|
||||
context.packageManager.getPackageInfo(context.packageName, 0)
|
||||
version = pInfo.versionName.toString()
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(16.dp)),
|
||||
elevation = CardDefaults.cardElevation(10.dp),
|
||||
colors = CardDefaults.cardColors(MaterialTheme.colorScheme.primaryContainer)
|
||||
) {
|
||||
Row (
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.padding(16.dp)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.weight(2f)
|
||||
.padding(16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(id = R.drawable.app_icon_foreground),
|
||||
contentDescription = stringResource(id = R.string.app_name),
|
||||
modifier = Modifier
|
||||
.size(160.dp)
|
||||
.scale(1.5f),
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
Text(
|
||||
text = stringResource(id = R.string.app_name),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontSize = MaterialTheme.typography.titleLarge.fontSize
|
||||
)
|
||||
Text(
|
||||
text = stringResource(R.string.version, version),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
fontSize = MaterialTheme.typography.bodyMedium.fontSize
|
||||
)
|
||||
Text(
|
||||
text = "Anthony La",
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
)
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier.weight(1f),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
IconButton(
|
||||
onClick = onGitHubClick,
|
||||
modifier = Modifier
|
||||
.size(60.dp)
|
||||
.background(MaterialTheme.colorScheme.primary, CircleShape)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(id = R.drawable.github),
|
||||
contentDescription = "GitHub",
|
||||
modifier = Modifier.size(20.dp),
|
||||
tint = MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
IconButton(
|
||||
onClick = onFdroidClick,
|
||||
modifier = Modifier
|
||||
.size(60.dp)
|
||||
.background(MaterialTheme.colorScheme.primary, CircleShape)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = ImageVector.vectorResource(id = R.drawable.fdroid),
|
||||
contentDescription = "F-Droid",
|
||||
modifier = Modifier.size(20.dp),
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -33,7 +33,7 @@ fun PrivacyPolicyListItem(onPrivacyPolicyClick: () -> Unit) {
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = "Click here to view our privacy policy",
|
||||
text = stringResource(R.string.click_here_to_view_our_privacy_policy),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {},
|
||||
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
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
|
||||
|
||||
/**
|
||||
* List item to reset all settings and data to default
|
||||
*/
|
||||
@Composable
|
||||
fun ResetListItem(onResetClick: () -> Unit) {
|
||||
var showDialog by remember { mutableStateOf(false) }
|
||||
|
||||
if (showDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showDialog = false },
|
||||
title = { Text(stringResource(R.string.reset_all_data)) },
|
||||
text = { Text(stringResource(R.string.are_you_sure_you_want_to_reset_all_settings_and_data_to_default)) },
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
onResetClick()
|
||||
showDialog = false
|
||||
}
|
||||
) {
|
||||
Text(stringResource(R.string.confirm))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(
|
||||
onClick = { showDialog = false }
|
||||
) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Box (
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
){
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.align(Alignment.Center)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.clickable(onClick = { showDialog = true }),
|
||||
elevation = CardDefaults.cardElevation(10.dp),
|
||||
colors = CardDefaults.cardColors(MaterialTheme.colorScheme.errorContainer)
|
||||
) {
|
||||
Row (
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
modifier = Modifier.padding(16.dp)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.reset_to_default),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontSize = MaterialTheme.typography.titleSmall.fontSize,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+118
-43
@@ -1,5 +1,8 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
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
|
||||
@@ -7,7 +10,15 @@ 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.Scaffold
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -16,17 +27,20 @@ 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 com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
/**
|
||||
* Scrollable settings screen to wrap all settings components
|
||||
*/
|
||||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SettingsScrollableSettings(
|
||||
settingsState: StateFlow<SettingsState>,
|
||||
@@ -34,58 +48,119 @@ fun SettingsScrollableSettings(
|
||||
scroll: ScrollState,
|
||||
onDynamicThemingClick: (Boolean) -> Unit,
|
||||
onDarkModeClick: (Boolean?) -> Unit,
|
||||
onAmoledClick: (Boolean) -> Unit,
|
||||
onAnimateClick: (Boolean) -> Unit,
|
||||
onPrivacyClick: () -> Unit,
|
||||
onLicenseClick: () -> Unit
|
||||
onLicenseClick: () -> Unit,
|
||||
onResetClick: () -> Unit,
|
||||
onBackClick: () -> Unit,
|
||||
) {
|
||||
val state = settingsState.collectAsStateWithLifecycle()
|
||||
val context = LocalContext.current
|
||||
|
||||
var toContact by rememberSaveable { mutableStateOf(false) }
|
||||
if (toContact) {
|
||||
Contact(context)
|
||||
toContact = false
|
||||
}
|
||||
|
||||
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))
|
||||
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"
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
ListSectionTitle("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("About")
|
||||
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 })
|
||||
//GPL and License and link to github etc, contact, terms of service, privacy policy
|
||||
}
|
||||
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)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
content = {
|
||||
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))
|
||||
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))
|
||||
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)
|
||||
},
|
||||
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))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Small top app bar for settings screen to replace [SettingsLargeTopAppBar] when scrolling down
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SettingsSmallTopAppBar(onBackClick: () -> Unit) {
|
||||
Surface {
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
|
||||
title = {},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -27,6 +27,7 @@ fun SettingsTitle(
|
||||
smallTopAppBarHeight: Dp,
|
||||
paddingMedium: Dp,
|
||||
scroll: ScrollState,
|
||||
topInset: Dp,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val titlePaddingStart = 16.dp
|
||||
@@ -35,6 +36,8 @@ fun SettingsTitle(
|
||||
val titleFontScaleEnd = 0.7f
|
||||
var titleHeightPx by remember { mutableFloatStateOf(0f) }
|
||||
var titleWidthPx by remember { mutableFloatStateOf(0f) }
|
||||
val fraction = (topInset - 74.dp) / (151.dp - 74.dp)
|
||||
val statusPadding = lerp(0.dp, 24.dp, fraction.coerceIn(0f, 1f))
|
||||
|
||||
Text(
|
||||
text = stringResource(id = R.string.settings_screen),
|
||||
@@ -55,7 +58,7 @@ fun SettingsTitle(
|
||||
val titleExtraStartPadding = titleWidthPx.toDp() * (1 - scaleXY.value) / 2f
|
||||
|
||||
val titleYFirstInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium,
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium + statusPadding,
|
||||
largeTopAppBarHeight / 2,
|
||||
collapseFraction
|
||||
)
|
||||
@@ -68,7 +71,7 @@ fun SettingsTitle(
|
||||
|
||||
val titleYSecondInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight / 2,
|
||||
(smallTopAppBarHeight - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
(smallTopAppBarHeight + statusPadding - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.AddToPhotos
|
||||
import androidx.compose.material.icons.filled.Image
|
||||
import androidx.compose.material.icons.outlined.AddToPhotos
|
||||
import androidx.compose.material.icons.outlined.Image
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
|
||||
/**
|
||||
* Data class representing a tab item
|
||||
*/
|
||||
data class TabItem(
|
||||
val title: String,
|
||||
val filledIcon: ImageVector,
|
||||
val unfilledIcon: ImageVector,
|
||||
)
|
||||
|
||||
/**
|
||||
* List of tab items
|
||||
*/
|
||||
val tabItems = listOf(
|
||||
TabItem(
|
||||
title = "Wallpaper",
|
||||
filledIcon = Icons.Filled.Image,
|
||||
unfilledIcon = Icons.Outlined.Image
|
||||
),
|
||||
TabItem(
|
||||
title = "Library",
|
||||
filledIcon = Icons.Filled.AddToPhotos,
|
||||
unfilledIcon = Icons.Outlined.AddToPhotos
|
||||
)
|
||||
)
|
||||
+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.Translate
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* A list item that links the user to the translation page
|
||||
*/
|
||||
@Composable
|
||||
fun TranslateListItem(onClick: () -> Unit) {
|
||||
Row {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.clickable { onClick() },
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.translation),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.help_translate_the_app_on_crowdin),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {},
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.Outlined.Translate,
|
||||
contentDescription = stringResource(R.string.translation),
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
) },
|
||||
tonalElevation = 5.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
+39
-36
@@ -1,5 +1,7 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.startup_screen
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
@@ -9,6 +11,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Info
|
||||
import androidx.compose.material.icons.sharp.CheckCircleOutline
|
||||
@@ -34,6 +37,8 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.airbnb.lottie.compose.LottieAnimation
|
||||
@@ -44,11 +49,11 @@ import com.airbnb.lottie.compose.rememberLottieComposition
|
||||
import com.anthonyla.paperize.R
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
// Inspired by https://github.com/Ashinch/ReadYou
|
||||
@Composable
|
||||
fun StartupScreen(
|
||||
onAgree: () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.onboarding_animation))
|
||||
val progress by animateLottieCompositionAsState(
|
||||
composition = composition,
|
||||
@@ -59,6 +64,12 @@ fun StartupScreen(
|
||||
var showToS by remember { mutableStateOf(false) }
|
||||
var seenToS by remember { mutableStateOf(false) }
|
||||
|
||||
val context = LocalContext.current
|
||||
val activity = context as? Activity
|
||||
BackHandler {
|
||||
activity?.moveTaskToBack(true)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = {
|
||||
SnackbarHost(
|
||||
@@ -66,7 +77,8 @@ fun StartupScreen(
|
||||
snackbar = { data ->
|
||||
Snackbar(
|
||||
snackbarData = data,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 8.dp))
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 8.dp)),
|
||||
shape = RoundedCornerShape(24.dp)
|
||||
)
|
||||
}
|
||||
) },
|
||||
@@ -78,7 +90,14 @@ fun StartupScreen(
|
||||
LottieAnimation(
|
||||
composition = composition,
|
||||
progress = { progress },
|
||||
modifier = Modifier.fillMaxHeight(0.5f)
|
||||
modifier = Modifier
|
||||
.fillMaxHeight(0.5f)
|
||||
.align(Alignment.CenterHorizontally)
|
||||
.semantics {
|
||||
contentDescription = context.getString(R.string.welcome_animation)
|
||||
},
|
||||
safeMode = true,
|
||||
enableMergePaths = true
|
||||
)
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Info,
|
||||
@@ -86,7 +105,7 @@ fun StartupScreen(
|
||||
modifier = Modifier.padding(PaddingValues(vertical = 16.dp))
|
||||
)
|
||||
Text(
|
||||
text = "Please read and agree to the following privacy policy to use the app.",
|
||||
text = stringResource(R.string.please_read_and_agree_to_the_following_privacy_notice_to_use_the_app),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
)
|
||||
Box(
|
||||
@@ -101,7 +120,7 @@ fun StartupScreen(
|
||||
} },
|
||||
modifier = Modifier.padding(PaddingValues(vertical = 16.dp)),
|
||||
) {
|
||||
Text(text = "Privacy Policy", textAlign = TextAlign.Start)
|
||||
Text(text = stringResource(R.string.privacy_notice), textAlign = TextAlign.Start)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,8 +134,8 @@ fun StartupScreen(
|
||||
} else {
|
||||
scope.launch {
|
||||
val result = snackbarHostState.showSnackbar(
|
||||
message = "Please read and agree to the privacy policy.",
|
||||
actionLabel = "View",
|
||||
message = context.getString(R.string.please_read_and_agree_to_the_privacy_notice),
|
||||
actionLabel = context.getString(R.string.view),
|
||||
duration = SnackbarDuration.Short,
|
||||
)
|
||||
when (result) {
|
||||
@@ -142,23 +161,23 @@ fun StartupScreen(
|
||||
if (showToS) {
|
||||
seenToS = true
|
||||
AlertDialog(
|
||||
modifier = Modifier.fillMaxHeight(0.8f),
|
||||
modifier = Modifier.fillMaxHeight(0.7f),
|
||||
onDismissRequest = { showToS = false },
|
||||
title = {
|
||||
Box(modifier = Modifier.fillMaxWidth()) {
|
||||
Text(
|
||||
text = "Privacy Policy",
|
||||
text = stringResource(R.string.privacy_notice),
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.align(Alignment.Center)
|
||||
)
|
||||
}
|
||||
},
|
||||
text = { PrivacyPolicyText() },
|
||||
text = { PrivacyNoticeText() },
|
||||
confirmButton = {
|
||||
Button(
|
||||
onClick = { showToS = false },
|
||||
) {
|
||||
Text("Dismiss")
|
||||
Text(stringResource(R.string.dismiss))
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -166,32 +185,16 @@ fun StartupScreen(
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun PrivacyPolicyText() {
|
||||
fun PrivacyNoticeText() {
|
||||
LazyColumn {
|
||||
item {
|
||||
SectionText("Introduction", "Welcome to Paperize! This privacy policy outlines how we collect, use, and protect your personal information when you use our mobile application. By using Paperize, you agree to the terms described in this policy.")
|
||||
}
|
||||
item {
|
||||
SectionText("Data Collection", "Notification Access: Paperize requests notification access to provide you with personalized wallpaper recommendations based on your notifications. We do not store any notification content or personally identifiable information (PII) outside of your device.\n\nLocal Files: Paperize accesses files stored on your device to allow you to set them as wallpapers. We do not upload or transfer these files to any external servers.")
|
||||
}
|
||||
item {
|
||||
SectionText("Information Usage", "Personal Data: We do not collect or store any personal data such as names, email addresses, or phone numbers.\n\nUsage Analytics: Paperize does not track your usage behavior or collect analytics data.")
|
||||
}
|
||||
item {
|
||||
SectionText("Data Security", "On-Device Storage: All data used by Paperize remains on your device. We do not transmit or store any data externally.\n\nEncryption: We use encryption protocols to secure communication between the app and your device.")
|
||||
}
|
||||
item {
|
||||
SectionText("Third-Party Services", "Advertisements: Paperize does not display third-party ads.\n\nExternal Links: Our app may contain links to external websites. Please note that we are not responsible for the privacy practices of these sites.")
|
||||
}
|
||||
item {
|
||||
SectionText("Children’s Privacy", "Paperize is not intended for children under the age of 13. We do not knowingly collect any information from children.")
|
||||
}
|
||||
item {
|
||||
SectionText("Changes to this Policy", "We may update this privacy policy from time to time. Any changes will be reflected in the app and on our website.")
|
||||
}
|
||||
item {
|
||||
SectionText("Contact Us", "If you have any questions or concerns about this privacy policy, please contact me at anthonyyla.dev@gmail.com.")
|
||||
}
|
||||
item { SectionText(stringResource(R.string.privacy_intro_title), stringResource(R.string.privacy_intro_content, stringResource(R.string.app_name))) }
|
||||
item { SectionText(stringResource(R.string.privacy_data_collection_title), stringResource(R.string.privacy_data_collection_content, stringResource(R.string.app_name))) }
|
||||
item { SectionText(stringResource(R.string.privacy_information_usage_title), stringResource(R.string.privacy_information_usage_content, stringResource(R.string.app_name))) }
|
||||
item { SectionText(stringResource(R.string.privacy_data_security_title), stringResource(R.string.privacy_data_security_content, stringResource(R.string.app_name))) }
|
||||
item { SectionText(stringResource(R.string.privacy_third_party_services_title), stringResource(R.string.privacy_third_party_services_content, stringResource(R.string.app_name))) }
|
||||
item { SectionText(stringResource(R.string.privacy_children_privacy_title), stringResource(R.string.privacy_children_privacy_content, stringResource(R.string.app_name))) }
|
||||
item { SectionText(stringResource(R.string.privacy_changes_notice_title), stringResource(R.string.privacy_changes_notice_content, stringResource(R.string.app_name))) }
|
||||
item { SectionText(stringResource(R.string.privacy_contact_us_title), stringResource(R.string.privacy_contact_us_content, "anthonyyla.dev@gmail.com")) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.example.compose
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.themes
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
val md_theme_light_primary = Color(0xFF984061)
|
||||
|
||||
+42
-72
@@ -1,81 +1,19 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.themes
|
||||
|
||||
import android.app.Activity
|
||||
import android.graphics.Color.TRANSPARENT
|
||||
import android.os.Build
|
||||
import androidx.activity.SystemBarStyle
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState
|
||||
import com.example.compose.md_theme_dark_background
|
||||
import com.example.compose.md_theme_dark_error
|
||||
import com.example.compose.md_theme_dark_errorContainer
|
||||
import com.example.compose.md_theme_dark_inverseOnSurface
|
||||
import com.example.compose.md_theme_dark_inversePrimary
|
||||
import com.example.compose.md_theme_dark_inverseSurface
|
||||
import com.example.compose.md_theme_dark_onBackground
|
||||
import com.example.compose.md_theme_dark_onError
|
||||
import com.example.compose.md_theme_dark_onErrorContainer
|
||||
import com.example.compose.md_theme_dark_onPrimary
|
||||
import com.example.compose.md_theme_dark_onPrimaryContainer
|
||||
import com.example.compose.md_theme_dark_onSecondary
|
||||
import com.example.compose.md_theme_dark_onSecondaryContainer
|
||||
import com.example.compose.md_theme_dark_onSurface
|
||||
import com.example.compose.md_theme_dark_onSurfaceVariant
|
||||
import com.example.compose.md_theme_dark_onTertiary
|
||||
import com.example.compose.md_theme_dark_onTertiaryContainer
|
||||
import com.example.compose.md_theme_dark_outline
|
||||
import com.example.compose.md_theme_dark_outlineVariant
|
||||
import com.example.compose.md_theme_dark_primary
|
||||
import com.example.compose.md_theme_dark_primaryContainer
|
||||
import com.example.compose.md_theme_dark_scrim
|
||||
import com.example.compose.md_theme_dark_secondary
|
||||
import com.example.compose.md_theme_dark_secondaryContainer
|
||||
import com.example.compose.md_theme_dark_surface
|
||||
import com.example.compose.md_theme_dark_surfaceTint
|
||||
import com.example.compose.md_theme_dark_surfaceVariant
|
||||
import com.example.compose.md_theme_dark_tertiary
|
||||
import com.example.compose.md_theme_dark_tertiaryContainer
|
||||
import com.example.compose.md_theme_light_background
|
||||
import com.example.compose.md_theme_light_error
|
||||
import com.example.compose.md_theme_light_errorContainer
|
||||
import com.example.compose.md_theme_light_inverseOnSurface
|
||||
import com.example.compose.md_theme_light_inversePrimary
|
||||
import com.example.compose.md_theme_light_inverseSurface
|
||||
import com.example.compose.md_theme_light_onBackground
|
||||
import com.example.compose.md_theme_light_onError
|
||||
import com.example.compose.md_theme_light_onErrorContainer
|
||||
import com.example.compose.md_theme_light_onPrimary
|
||||
import com.example.compose.md_theme_light_onPrimaryContainer
|
||||
import com.example.compose.md_theme_light_onSecondary
|
||||
import com.example.compose.md_theme_light_onSecondaryContainer
|
||||
import com.example.compose.md_theme_light_onSurface
|
||||
import com.example.compose.md_theme_light_onSurfaceVariant
|
||||
import com.example.compose.md_theme_light_onTertiary
|
||||
import com.example.compose.md_theme_light_onTertiaryContainer
|
||||
import com.example.compose.md_theme_light_outline
|
||||
import com.example.compose.md_theme_light_outlineVariant
|
||||
import com.example.compose.md_theme_light_primary
|
||||
import com.example.compose.md_theme_light_primaryContainer
|
||||
import com.example.compose.md_theme_light_scrim
|
||||
import com.example.compose.md_theme_light_secondary
|
||||
import com.example.compose.md_theme_light_secondaryContainer
|
||||
import com.example.compose.md_theme_light_surface
|
||||
import com.example.compose.md_theme_light_surfaceTint
|
||||
import com.example.compose.md_theme_light_surfaceVariant
|
||||
import com.example.compose.md_theme_light_tertiary
|
||||
import com.example.compose.md_theme_light_tertiaryContainer
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
|
||||
private val LightColors = lightColorScheme(
|
||||
@@ -143,25 +81,58 @@ 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.
|
||||
*/
|
||||
@Composable
|
||||
fun PaperizeTheme(
|
||||
settingsState: StateFlow<SettingsState>,
|
||||
darkMode: Boolean?,
|
||||
amoledMode: Boolean,
|
||||
dynamicTheming: Boolean,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val state = settingsState.collectAsStateWithLifecycle()
|
||||
val context = LocalContext.current
|
||||
|
||||
val isDarkMode = isDarkMode(darkMode = state.value.darkMode)
|
||||
val isDynamicTheming = isDynamicTheming(dynamicTheming = state.value.dynamicTheming)
|
||||
val isDarkMode = isDarkMode(darkMode = darkMode)
|
||||
val isDynamicTheming = isDynamicTheming(dynamicTheming = dynamicTheming)
|
||||
val dynamicThemingSupported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
||||
val colors = when {
|
||||
isDynamicTheming && dynamicThemingSupported && isDarkMode -> dynamicDarkColorScheme(context)
|
||||
isDynamicTheming && dynamicThemingSupported && !isDarkMode -> dynamicLightColorScheme(context)
|
||||
isDarkMode -> DarkColors
|
||||
isDarkMode && amoledMode -> AmoledDarkColors
|
||||
isDarkMode && !amoledMode -> DarkColors
|
||||
else -> LightColors
|
||||
}
|
||||
|
||||
@@ -170,9 +141,8 @@ fun PaperizeTheme(
|
||||
if (!view.isInEditMode) {
|
||||
SideEffect {
|
||||
val window = (view.context as Activity).window
|
||||
window.statusBarColor = TRANSPARENT
|
||||
SystemBarStyle.light(TRANSPARENT, TRANSPARENT)
|
||||
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !isDarkMode
|
||||
WindowCompat.getInsetsController(window, view).isAppearanceLightNavigationBars = !isDarkMode
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -2,10 +2,10 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
|
||||
sealed class WallpaperEvent {
|
||||
data class UpdateSelectedAlbum(val selectedAlbum: SelectedAlbum): WallpaperEvent()
|
||||
object Reset : WallpaperEvent()
|
||||
object Refresh : WallpaperEvent()
|
||||
data class 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()
|
||||
}
|
||||
+217
-139
@@ -1,14 +1,16 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.view.HapticFeedbackConstants
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import android.provider.Settings
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Snackbar
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
@@ -23,36 +25,78 @@ 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.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.AlbumBottomSheet
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.BlurSwitchAndSlider
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ChangerSelectionRow
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentAndNextChange
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentSelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.SetLockScreenSwitch
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.DarkenSwitchAndSlider
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.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
|
||||
|
||||
@Composable
|
||||
fun WallpaperScreen(
|
||||
albumsViewModel: AlbumsViewModel = hiltViewModel(),
|
||||
wallpaperScreenViewModel: WallpaperScreenViewModel = hiltViewModel(),
|
||||
settingsViewModel: SettingsViewModel = hiltViewModel(),
|
||||
onScheduleWallpaperChanger: (Int) -> Unit,
|
||||
onStop: () -> Unit
|
||||
albums: List<AlbumWithWallpaperAndFolder>,
|
||||
animate: Boolean,
|
||||
darken: Boolean,
|
||||
homeDarkenPercentage: Int,
|
||||
lockDarkenPercentage: Int,
|
||||
enableChanger: Boolean,
|
||||
homeEnabled: Boolean,
|
||||
homeInterval: Int,
|
||||
lockInterval: Int,
|
||||
lastSetTime: String?,
|
||||
lockEnabled: Boolean,
|
||||
nextSetTime: String?,
|
||||
currentHomeWallpaper: String?,
|
||||
currentLockWallpaper: String?,
|
||||
onDarkCheck: (Boolean) -> Unit,
|
||||
onDarkenPercentage: (Int, Int) -> Unit,
|
||||
onHomeCheckedChange: (Boolean) -> Unit,
|
||||
onLockCheckedChange: (Boolean) -> Unit,
|
||||
scheduleSeparately: Boolean,
|
||||
onScheduleSeparatelyChange: (Boolean) -> Unit,
|
||||
onScheduleWallpaperChanger: () -> Unit,
|
||||
onScalingChange: (ScalingConstants) -> Unit,
|
||||
onSelectAlbum: (AlbumWithWallpaperAndFolder, Boolean, Boolean) -> Unit,
|
||||
onHomeTimeChange: (Int) -> Unit,
|
||||
onLockTimeChange: (Int) -> Unit,
|
||||
onStop: (Boolean, Boolean) -> Unit,
|
||||
onToggleChanger: (Boolean) -> Unit,
|
||||
scaling: ScalingConstants,
|
||||
homeSelectedAlbum: SelectedAlbum?,
|
||||
lockSelectedAlbum: SelectedAlbum?,
|
||||
blur: Boolean,
|
||||
onBlurPercentageChange: (Int, Int) -> Unit,
|
||||
onBlurChange: (Boolean) -> Unit,
|
||||
homeBlurPercentage: Int,
|
||||
lockBlurPercentage: Int,
|
||||
homeVignettePercentage: Int,
|
||||
lockVignettePercentage: Int,
|
||||
onVignettePercentageChange: (Int, Int) -> Unit,
|
||||
onVignetteChange: (Boolean) -> Unit,
|
||||
vignette: Boolean
|
||||
) {
|
||||
val albumState = albumsViewModel.state.collectAsStateWithLifecycle()
|
||||
val selectedState = wallpaperScreenViewModel.state.collectAsStateWithLifecycle()
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
val shouldShowScreen = homeEnabled || lockEnabled
|
||||
val shouldShowSettings = shouldShowScreen && homeSelectedAlbum != null && lockSelectedAlbum != null
|
||||
val scrollState = rememberScrollState()
|
||||
val context = LocalContext.current
|
||||
var openBottomSheet by rememberSaveable { mutableStateOf(false) }
|
||||
val scope = rememberCoroutineScope()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val showInterval = rememberSaveable { mutableStateOf(false) }
|
||||
val lock = rememberSaveable { mutableStateOf(false) }
|
||||
val home = rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = {
|
||||
@@ -61,153 +105,187 @@ fun WallpaperScreen(
|
||||
snackbar = { data ->
|
||||
Snackbar(
|
||||
snackbarData = data,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 16.dp, vertical = 24.dp))
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 16.dp, vertical = 24.dp)),
|
||||
shape = RoundedCornerShape(24.dp)
|
||||
)
|
||||
}
|
||||
) },
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
content = { it
|
||||
LazyColumn(
|
||||
content = { padding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.verticalScroll(scrollState)
|
||||
.fillMaxSize()
|
||||
.padding(8.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
item {
|
||||
ChangerSelectionRow(
|
||||
homeEnabled = homeEnabled,
|
||||
lockEnabled = lockEnabled,
|
||||
onHomeCheckedChange = onHomeCheckedChange,
|
||||
onLockCheckedChange = onLockCheckedChange
|
||||
)
|
||||
if (homeEnabled && lockEnabled) {
|
||||
IndividualSchedulingAndToggleRow(
|
||||
animate = animate,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
enableChanger = enableChanger,
|
||||
onToggleChanger = onToggleChanger,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange
|
||||
)
|
||||
}
|
||||
if (homeEnabled || lockEnabled) {
|
||||
CurrentSelectedAlbum(
|
||||
selectedAlbum = selectedState.value.selectedAlbum,
|
||||
onOpenBottomSheet = {
|
||||
if (albumState.value.albumsWithWallpapers.firstOrNull() != null) openBottomSheet = true
|
||||
},
|
||||
onStop = {
|
||||
if (selectedState.value.selectedAlbum != null) {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
homeSelectedAlbum = homeSelectedAlbum,
|
||||
lockSelectedAlbum = lockSelectedAlbum,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
animate = animate,
|
||||
enableChanger = enableChanger,
|
||||
onToggleChanger = {
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
if (!it) {
|
||||
snackbarHostState.showSnackbar(
|
||||
message = "${selectedState.value.selectedAlbum?.album?.displayedAlbumName} has been unselected.",
|
||||
actionLabel = "Dismiss",
|
||||
message = context.getString(R.string.wallpaper_changer_has_been_disabled),
|
||||
actionLabel = context.getString(R.string.dismiss),
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
}
|
||||
onStop()
|
||||
}
|
||||
onToggleChanger(it)
|
||||
},
|
||||
onOpenBottomSheet = { changeLock, changeHome ->
|
||||
if (albums.firstOrNull() != null) {
|
||||
openBottomSheet = true
|
||||
lock.value = changeLock
|
||||
home.value = changeHome
|
||||
} else {
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
snackbarHostState.showSnackbar(
|
||||
message = context.getString(R.string.no_albums_found),
|
||||
actionLabel = context.getString(R.string.dismiss),
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
onStop = { lock, home ->
|
||||
if (homeSelectedAlbum != null || lockSelectedAlbum != null) {
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
snackbarHostState.showSnackbar(
|
||||
message = context.getString(
|
||||
R.string.has_been_unselected,
|
||||
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(lock, home)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
if (settingsState.value.animate) {
|
||||
item {
|
||||
AnimatedVisibility(
|
||||
visible = selectedState.value.selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
if (selectedState.value.selectedAlbum != null) {
|
||||
CurrentAndNextChange(
|
||||
settingsState.value.lastSetTime,
|
||||
settingsState.value.nextSetTime
|
||||
)
|
||||
}
|
||||
}
|
||||
AnimatedVisibility(
|
||||
visible = selectedState.value.selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
if (selectedState.value.selectedAlbum != null) {
|
||||
SetLockScreenSwitch(
|
||||
albumUri = selectedState.value.selectedAlbum!!.album.coverUri,
|
||||
checked = settingsState.value.setLockWithHome,
|
||||
onCheckedChange = { isChecked ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetLockWithHome(isChecked))
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
AnimatedVisibility(
|
||||
visible = selectedState.value.selectedAlbum != null,
|
||||
enter = slideInVertically(initialOffsetY = { -it }),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
TimeSliders(
|
||||
timeInMinutes = settingsState.value.interval,
|
||||
onTimeChange = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
settingsViewModel.onEvent(
|
||||
SettingsEvent.SetWallpaperInterval(totalMinutes)
|
||||
)
|
||||
onScheduleWallpaperChanger(totalMinutes)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
item {
|
||||
if (selectedState.value.selectedAlbum != null) {
|
||||
CurrentAndNextChange(
|
||||
settingsState.value.lastSetTime,
|
||||
settingsState.value.nextSetTime
|
||||
)
|
||||
}
|
||||
}
|
||||
item {
|
||||
if (selectedState.value.selectedAlbum != null) {
|
||||
SetLockScreenSwitch(
|
||||
albumUri = selectedState.value.selectedAlbum!!.album.coverUri,
|
||||
checked = settingsState.value.setLockWithHome,
|
||||
onCheckedChange = { isChecked ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetLockWithHome(isChecked))
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
item {
|
||||
if (shouldShowSettings) {
|
||||
WallpaperPreviewAndScale(
|
||||
currentHomeWallpaper = currentHomeWallpaper,
|
||||
currentLockWallpaper = currentLockWallpaper,
|
||||
darken = darken,
|
||||
homeDarkenPercentage = homeDarkenPercentage,
|
||||
lockDarkenPercentage = lockDarkenPercentage,
|
||||
scaling = scaling,
|
||||
onScalingChange = onScalingChange,
|
||||
homeEnabled = homeEnabled,
|
||||
lockEnabled = lockEnabled,
|
||||
blur = blur,
|
||||
homeBlurPercentage = homeBlurPercentage,
|
||||
lockBlurPercentage = lockBlurPercentage,
|
||||
vignette = vignette,
|
||||
homeVignettePercentage = homeVignettePercentage,
|
||||
lockVignettePercentage = lockVignettePercentage
|
||||
)
|
||||
CurrentAndNextChange(lastSetTime, nextSetTime)
|
||||
TimeSliders(
|
||||
timeInMinutes = settingsState.value.interval,
|
||||
onTimeChange = { days, hours, minutes ->
|
||||
homeInterval = homeInterval,
|
||||
lockInterval = lockInterval,
|
||||
onHomeIntervalChange = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
settingsViewModel.onEvent(
|
||||
SettingsEvent.SetWallpaperInterval(totalMinutes)
|
||||
)
|
||||
onScheduleWallpaperChanger(totalMinutes)
|
||||
}
|
||||
onHomeTimeChange(totalMinutes)
|
||||
},
|
||||
onLockIntervalChange = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
onLockTimeChange(totalMinutes)
|
||||
},
|
||||
showInterval = showInterval.value,
|
||||
animate = animate,
|
||||
onShowIntervalChange = { showInterval.value = it },
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
lockEnabled = lockEnabled,
|
||||
homeEnabled = homeEnabled
|
||||
)
|
||||
DarkenSwitchAndSlider(
|
||||
onDarkCheck = onDarkCheck,
|
||||
darken = darken,
|
||||
onDarkenChange = onDarkenPercentage,
|
||||
homeDarkenPercentage = homeDarkenPercentage,
|
||||
lockDarkenPercentage = lockDarkenPercentage,
|
||||
animate = animate,
|
||||
bothEnabled = homeEnabled && lockEnabled
|
||||
)
|
||||
BlurSwitchAndSlider(
|
||||
onBlurPercentageChange = onBlurPercentageChange,
|
||||
onBlurChange = onBlurChange,
|
||||
blur = blur,
|
||||
homeBlurPercentage = homeBlurPercentage,
|
||||
lockBlurPercentage = lockBlurPercentage,
|
||||
animate = animate,
|
||||
bothEnabled = homeEnabled && lockEnabled
|
||||
)
|
||||
VignetteSwitchAndSlider(
|
||||
onVignettePercentageChange = onVignettePercentageChange,
|
||||
onVignetteChange = onVignetteChange,
|
||||
vignette = vignette,
|
||||
homeVignettePercentage = homeVignettePercentage,
|
||||
lockVignettePercentage = lockVignettePercentage,
|
||||
animate = animate,
|
||||
bothEnabled = homeEnabled && lockEnabled
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (openBottomSheet) {
|
||||
if (shouldShowScreen && openBottomSheet) {
|
||||
AlbumBottomSheet(
|
||||
albums = albumState.value.albumsWithWallpapers,
|
||||
currentSelectedAlbum = selectedState.value.selectedAlbum,
|
||||
albums = albums,
|
||||
homeSelectedAlbum = homeSelectedAlbum,
|
||||
lockSelectedAlbum = lockSelectedAlbum,
|
||||
onDismiss = { openBottomSheet = false },
|
||||
onSelect = { album ->
|
||||
val wallpapers: List<Wallpaper> = album.wallpapers + album.folders.flatMap { folder ->
|
||||
folder.wallpapers.map { wallpaper ->
|
||||
Wallpaper(
|
||||
initialAlbumName = album.album.initialAlbumName,
|
||||
wallpaperUri = wallpaper,
|
||||
key = wallpaper.hashCode() + album.album.initialAlbumName.hashCode(),
|
||||
)
|
||||
openBottomSheet = false
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val alarmManager = ContextCompat.getSystemService(context, AlarmManager::class.java)
|
||||
if (alarmManager?.canScheduleExactAlarms() == false) {
|
||||
Intent().also { intent ->
|
||||
intent.action = Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
else {
|
||||
onSelectAlbum(album, lock.value, home.value)
|
||||
onScheduleWallpaperChanger()
|
||||
}
|
||||
}
|
||||
val newSelectedAlbum = SelectedAlbum(
|
||||
album = album.album.copy(
|
||||
wallpapersInQueue = wallpapers.map { it.wallpaperUri }.shuffled()
|
||||
),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
openBottomSheet = false
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
snackbarHostState.showSnackbar(
|
||||
message = "${album.album.displayedAlbumName} has been selected.",
|
||||
actionLabel = "Dismiss",
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
else {
|
||||
onSelectAlbum(album, lock.value, home.value)
|
||||
onScheduleWallpaperChanger()
|
||||
}
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(newSelectedAlbum))
|
||||
onScheduleWallpaperChanger(settingsState.value.interval)
|
||||
}
|
||||
},
|
||||
animate = animate
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
+68
-17
@@ -1,10 +1,6 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
@@ -14,11 +10,9 @@ import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
@@ -33,18 +27,65 @@ class WallpaperScreenViewModel @Inject constructor (
|
||||
)
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
refreshAlbums()
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.getSelectedAlbum().collect { selectedAlbum ->
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedAlbum = selectedAlbum,
|
||||
isDataLoaded = true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
withContext(Dispatchers.IO) {
|
||||
repository.deleteAll()
|
||||
repository.upsertSelectedAlbum(event.selectedAlbum)
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
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
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,11 +93,21 @@ class WallpaperScreenViewModel @Inject constructor (
|
||||
refreshAlbums()
|
||||
}
|
||||
is WallpaperEvent.Reset -> {
|
||||
viewModelScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (event.album == null) {
|
||||
repository.deleteAll()
|
||||
_state.update {
|
||||
it.copy(selectedAlbum = null)
|
||||
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 }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,10 +117,10 @@ class WallpaperScreenViewModel @Inject constructor (
|
||||
|
||||
// Retrieve album from database into viewModel
|
||||
private fun refreshAlbums() {
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.getSelectedAlbum().collect { selectedAlbum ->
|
||||
_state.update { it.copy(
|
||||
selectedAlbum = selectedAlbum.firstOrNull()
|
||||
selectedAlbum = selectedAlbum,
|
||||
) }
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -3,5 +3,6 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
|
||||
data class WallpaperState (
|
||||
val selectedAlbum: SelectedAlbum? = null
|
||||
val isDataLoaded: Boolean = false,
|
||||
val selectedAlbum: List<SelectedAlbum>? = null
|
||||
)
|
||||
+57
-43
@@ -1,9 +1,13 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.asPaddingValues
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.navigationBars
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
@@ -28,12 +32,12 @@ import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.isValidUri
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions
|
||||
import com.skydoves.landscapist.ImageOptions
|
||||
import com.skydoves.landscapist.glide.GlideImage
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -45,9 +49,11 @@ import kotlinx.coroutines.launch
|
||||
@Composable
|
||||
fun AlbumBottomSheet(
|
||||
onDismiss: () -> Unit,
|
||||
currentSelectedAlbum: SelectedAlbum?,
|
||||
homeSelectedAlbum: SelectedAlbum?,
|
||||
lockSelectedAlbum: SelectedAlbum?,
|
||||
albums: List<AlbumWithWallpaperAndFolder>,
|
||||
onSelect: (AlbumWithWallpaperAndFolder) -> Unit
|
||||
onSelect: (AlbumWithWallpaperAndFolder) -> Unit,
|
||||
animate: Boolean
|
||||
) {
|
||||
val modalBottomSheetState = rememberModalBottomSheetState()
|
||||
val scope = rememberCoroutineScope()
|
||||
@@ -55,12 +61,24 @@ fun AlbumBottomSheet(
|
||||
onDismissRequest = { onDismiss() },
|
||||
sheetState = modalBottomSheetState,
|
||||
dragHandle = { BottomSheetDefaults.DragHandle() },
|
||||
windowInsets = WindowInsets(0.dp)
|
||||
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()
|
||||
)
|
||||
} else {
|
||||
Modifier.padding(bottom = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding())
|
||||
}
|
||||
) {
|
||||
albums.forEach {
|
||||
if (it.folders.sumOf { folder -> folder.wallpapers.size } + it.wallpapers.size == 0) return@forEach
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.clickable {
|
||||
scope.launch {
|
||||
modalBottomSheetState.hide()
|
||||
@@ -74,8 +92,9 @@ fun AlbumBottomSheet(
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
) },
|
||||
supportingContent = {
|
||||
val totalWallpapers = it.folders.sumOf { folder -> folder.wallpapers.size } + it.wallpapers.size
|
||||
Text(
|
||||
text = (it.folders.sumOf { folder -> folder.wallpapers.size } + it.wallpapers.size).toString() + stringResource(R.string.wallpaper),
|
||||
text = LocalContext.current.resources.getQuantityString(R.plurals.wallpaper_count, totalWallpapers, totalWallpapers),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
@@ -84,45 +103,40 @@ fun AlbumBottomSheet(
|
||||
Box (
|
||||
modifier = Modifier.size(60.dp)
|
||||
) {
|
||||
GlideImage(
|
||||
imageModel = { it.album.coverUri },
|
||||
imageOptions = ImageOptions(
|
||||
contentScale = ContentScale.FillBounds,
|
||||
alignment = Alignment.Center,
|
||||
),
|
||||
requestBuilder = {
|
||||
Glide
|
||||
.with(LocalContext.current)
|
||||
.asBitmap()
|
||||
.transition(BitmapTransitionOptions.withCrossFade())
|
||||
},
|
||||
loading = {
|
||||
Box(modifier = Modifier.matchParentSize()) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(
|
||||
Alignment.Center))
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.aspectRatio(1f)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
)
|
||||
val showCoverUri = isValidUri(LocalContext.current, it.album.coverUri)
|
||||
if (showCoverUri) {
|
||||
GlideImage(
|
||||
imageModel = { it.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))
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
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,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Loaded 100 of 233 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user