Merge branch 'feature/nextgen' into feature/sync
commit
094cebe674
@ -0,0 +1,29 @@
|
|||||||
|
**PLEASE READ THIS**
|
||||||
|
|
||||||
|
I acknowledge that:
|
||||||
|
|
||||||
|
- I have updated to the latest version of the app (https://github.com/KotatsuApp/Kotatsu/releases/latest)
|
||||||
|
- If this is an issue with a parser, that I should be opening an issue in https://github.com/KotatsuApp/kotatsu-parsers
|
||||||
|
- I have searched the existing issues and this is new ticket **NOT** a duplicate or related to another open or closed issue
|
||||||
|
- I will fill out the title and the information in this template
|
||||||
|
|
||||||
|
Note that the issue will be automatically closed if you do not fill out the title or requested information.
|
||||||
|
|
||||||
|
**DELETE THIS SECTION IF YOU HAVE READ AND ACKNOWLEDGED IT**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Device information
|
||||||
|
* Kotatsu version: ?
|
||||||
|
* Android version: ?
|
||||||
|
* Device: ?
|
||||||
|
|
||||||
|
## Steps to reproduce
|
||||||
|
1. First step
|
||||||
|
2. Second step
|
||||||
|
|
||||||
|
## Issue/Request
|
||||||
|
?
|
||||||
|
|
||||||
|
## Other details
|
||||||
|
Additional details and attachments.
|
||||||
@ -1,5 +1,5 @@
|
|||||||
blank_issues_enabled: false
|
blank_issues_enabled: false
|
||||||
contact_links:
|
contact_links:
|
||||||
- name: ⚠️ Source issue
|
- name: ⚠️ Source issue
|
||||||
url: https://github.com/nv95/kotatsu-parsers/issues/new
|
url: https://github.com/KotatsuApp/kotatsu-parsers/issues/new
|
||||||
about: Issues and requests for sources should be opened in the kotatsu-parsers repository instead
|
about: If you have troubles with a manga parser or want to propose new manga source, please open an issue in the kotatsu-parsers repository instead
|
||||||
@ -0,0 +1,64 @@
|
|||||||
|
name: 🐞 Bug report
|
||||||
|
description: Report a bug in Kotatsu
|
||||||
|
labels: [bug]
|
||||||
|
body:
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: summary
|
||||||
|
attributes:
|
||||||
|
label: Brief summary
|
||||||
|
description: Please describe, what went wrong
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: reproduce-steps
|
||||||
|
attributes:
|
||||||
|
label: Steps to reproduce
|
||||||
|
description: Please provide a way to reproduce this issue. Screenshots or videos can be very helpful
|
||||||
|
placeholder: |
|
||||||
|
Example:
|
||||||
|
1. First step
|
||||||
|
2. Second step
|
||||||
|
3. Issue here
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: kotatsu-version
|
||||||
|
attributes:
|
||||||
|
label: Kotatsu version
|
||||||
|
description: You can find your Kotatsu version in **Settings → About**.
|
||||||
|
placeholder: |
|
||||||
|
Example: "3.3"
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: android-version
|
||||||
|
attributes:
|
||||||
|
label: Android version
|
||||||
|
description: You can find this somewhere in your Android settings.
|
||||||
|
placeholder: |
|
||||||
|
Example: "12.0"
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: device
|
||||||
|
attributes:
|
||||||
|
label: Device
|
||||||
|
description: List your device and model.
|
||||||
|
placeholder: |
|
||||||
|
Example: "LG Nexus 5X"
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
|
||||||
|
- type: checkboxes
|
||||||
|
id: acknowledgements
|
||||||
|
attributes:
|
||||||
|
label: Acknowledgements
|
||||||
|
options:
|
||||||
|
- label: I have searched the existing issues and this is a new ticket, **NOT** a duplicate or related to another open issue.
|
||||||
|
required: true
|
||||||
@ -1,93 +0,0 @@
|
|||||||
name: 🐞 Issue report
|
|
||||||
description: Report an issue in Kotatsu
|
|
||||||
labels: [bug]
|
|
||||||
body:
|
|
||||||
|
|
||||||
- type: textarea
|
|
||||||
id: reproduce-steps
|
|
||||||
attributes:
|
|
||||||
label: Steps to reproduce
|
|
||||||
description: Provide an example of the issue.
|
|
||||||
placeholder: |
|
|
||||||
Example:
|
|
||||||
1. First step
|
|
||||||
2. Second step
|
|
||||||
3. Issue here
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
|
|
||||||
- type: textarea
|
|
||||||
id: expected-behavior
|
|
||||||
attributes:
|
|
||||||
label: Expected behavior
|
|
||||||
description: Explain what you should expect to happen.
|
|
||||||
placeholder: |
|
|
||||||
Example:
|
|
||||||
"This should happen..."
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
|
|
||||||
- type: textarea
|
|
||||||
id: actual-behavior
|
|
||||||
attributes:
|
|
||||||
label: Actual behavior
|
|
||||||
description: Explain what actually happens.
|
|
||||||
placeholder: |
|
|
||||||
Example:
|
|
||||||
"This happened instead..."
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
|
|
||||||
- type: input
|
|
||||||
id: kotatsu-version
|
|
||||||
attributes:
|
|
||||||
label: Kotatsu version
|
|
||||||
description: You can find your Kotatsu version in **Settings → About**.
|
|
||||||
placeholder: |
|
|
||||||
Example: "3.2.3"
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
|
|
||||||
- type: input
|
|
||||||
id: android-version
|
|
||||||
attributes:
|
|
||||||
label: Android version
|
|
||||||
description: You can find this somewhere in your Android settings.
|
|
||||||
placeholder: |
|
|
||||||
Example: "Android 12"
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
|
|
||||||
- type: input
|
|
||||||
id: device
|
|
||||||
attributes:
|
|
||||||
label: Device
|
|
||||||
description: List your device and model.
|
|
||||||
placeholder: |
|
|
||||||
Example: "LG Nexus 5X"
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
|
|
||||||
- type: textarea
|
|
||||||
id: other-details
|
|
||||||
attributes:
|
|
||||||
label: Other details
|
|
||||||
placeholder: |
|
|
||||||
Additional details and attachments.
|
|
||||||
|
|
||||||
- type: checkboxes
|
|
||||||
id: acknowledgements
|
|
||||||
attributes:
|
|
||||||
label: Acknowledgements
|
|
||||||
description: Read this carefully, we will close and ignore your issue if you skimmed through this.
|
|
||||||
options:
|
|
||||||
- label: I have searched the existing issues and this is a new ticket, **NOT** a duplicate or related to another open issue.
|
|
||||||
required: true
|
|
||||||
- label: I have written a short but informative title.
|
|
||||||
required: true
|
|
||||||
- label: If this is an issue with a source, I should be opening an issue in the [parsers repository](https://github.com/nv95/kotatsu-parsers/issues/new).
|
|
||||||
required: true
|
|
||||||
- label: I have updated the app to version **[3.2.3](https://github.com/nv95/Kotatsu/releases/latest)**.
|
|
||||||
required: true
|
|
||||||
- label: I will fill out all of the requested information in this form.
|
|
||||||
required: true
|
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
name: Issue moderator
|
||||||
|
|
||||||
|
on:
|
||||||
|
issues:
|
||||||
|
types: [opened, edited, reopened]
|
||||||
|
issue_comment:
|
||||||
|
types: [created]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
moderate:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Moderate issues
|
||||||
|
uses: tachiyomiorg/issue-moderator-action@v1
|
||||||
|
with:
|
||||||
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
auto-close-rules: |
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "body",
|
||||||
|
"regex": ".*DELETE THIS SECTION IF YOU HAVE READ AND ACKNOWLEDGED IT.*",
|
||||||
|
"message": "The acknowledgment section was not removed."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "body",
|
||||||
|
"regex": ".*\\* (Kotatsu version|Android version|Device): \\?.*",
|
||||||
|
"message": "Requested information in the template was not filled out."
|
||||||
|
}
|
||||||
|
]
|
||||||
@ -0,0 +1,287 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
inkscape:export-ydpi="39.689999"
|
||||||
|
inkscape:export-xdpi="39.689999"
|
||||||
|
inkscape:export-filename="/home/admin/Documents/projects/graphics/k/icon4.png"
|
||||||
|
width="512mm"
|
||||||
|
height="512mm"
|
||||||
|
viewBox="0 0 512 512.00002"
|
||||||
|
version="1.1"
|
||||||
|
id="svg8"
|
||||||
|
inkscape:version="1.0 (4035a4fb49, 2020-05-01)"
|
||||||
|
sodipodi:docname="icon4.svg">
|
||||||
|
<defs
|
||||||
|
id="defs2">
|
||||||
|
<filter
|
||||||
|
style="color-interpolation-filters:sRGB;"
|
||||||
|
inkscape:label="Drop Shadow"
|
||||||
|
id="filter1266">
|
||||||
|
<feFlood
|
||||||
|
flood-opacity="0.498039"
|
||||||
|
flood-color="rgb(0,0,0)"
|
||||||
|
result="flood"
|
||||||
|
id="feFlood1256" />
|
||||||
|
<feComposite
|
||||||
|
in="flood"
|
||||||
|
in2="SourceGraphic"
|
||||||
|
operator="in"
|
||||||
|
result="composite1"
|
||||||
|
id="feComposite1258" />
|
||||||
|
<feGaussianBlur
|
||||||
|
in="composite1"
|
||||||
|
stdDeviation="3"
|
||||||
|
result="blur"
|
||||||
|
id="feGaussianBlur1260" />
|
||||||
|
<feOffset
|
||||||
|
dx="6"
|
||||||
|
dy="6"
|
||||||
|
result="offset"
|
||||||
|
id="feOffset1262" />
|
||||||
|
<feComposite
|
||||||
|
in="SourceGraphic"
|
||||||
|
in2="offset"
|
||||||
|
operator="over"
|
||||||
|
result="composite2"
|
||||||
|
id="feComposite1264" />
|
||||||
|
</filter>
|
||||||
|
<filter
|
||||||
|
style="color-interpolation-filters:sRGB;"
|
||||||
|
inkscape:label="Drop Shadow"
|
||||||
|
id="filter1059">
|
||||||
|
<feFlood
|
||||||
|
flood-opacity="0.498039"
|
||||||
|
flood-color="rgb(0,0,0)"
|
||||||
|
result="flood"
|
||||||
|
id="feFlood1049" />
|
||||||
|
<feComposite
|
||||||
|
in="flood"
|
||||||
|
in2="SourceGraphic"
|
||||||
|
operator="in"
|
||||||
|
result="composite1"
|
||||||
|
id="feComposite1051" />
|
||||||
|
<feGaussianBlur
|
||||||
|
in="composite1"
|
||||||
|
stdDeviation="3"
|
||||||
|
result="blur"
|
||||||
|
id="feGaussianBlur1053" />
|
||||||
|
<feOffset
|
||||||
|
dx="6"
|
||||||
|
dy="6"
|
||||||
|
result="offset"
|
||||||
|
id="feOffset1055" />
|
||||||
|
<feComposite
|
||||||
|
in="SourceGraphic"
|
||||||
|
in2="offset"
|
||||||
|
operator="over"
|
||||||
|
result="composite2"
|
||||||
|
id="feComposite1057" />
|
||||||
|
</filter>
|
||||||
|
<filter
|
||||||
|
style="color-interpolation-filters:sRGB;"
|
||||||
|
inkscape:label="Drop Shadow"
|
||||||
|
id="filter1071">
|
||||||
|
<feFlood
|
||||||
|
flood-opacity="0.498039"
|
||||||
|
flood-color="rgb(0,0,0)"
|
||||||
|
result="flood"
|
||||||
|
id="feFlood1061" />
|
||||||
|
<feComposite
|
||||||
|
in="flood"
|
||||||
|
in2="SourceGraphic"
|
||||||
|
operator="in"
|
||||||
|
result="composite1"
|
||||||
|
id="feComposite1063" />
|
||||||
|
<feGaussianBlur
|
||||||
|
in="composite1"
|
||||||
|
stdDeviation="3"
|
||||||
|
result="blur"
|
||||||
|
id="feGaussianBlur1065" />
|
||||||
|
<feOffset
|
||||||
|
dx="6"
|
||||||
|
dy="6"
|
||||||
|
result="offset"
|
||||||
|
id="feOffset1067" />
|
||||||
|
<feComposite
|
||||||
|
in="SourceGraphic"
|
||||||
|
in2="offset"
|
||||||
|
operator="over"
|
||||||
|
result="composite2"
|
||||||
|
id="feComposite1069" />
|
||||||
|
</filter>
|
||||||
|
</defs>
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#0d47a1"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="0.175"
|
||||||
|
inkscape:cx="-361.03654"
|
||||||
|
inkscape:cy="630.78782"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
inkscape:document-rotation="0"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:window-width="1600"
|
||||||
|
inkscape:window-height="838"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
fit-margin-top="20"
|
||||||
|
fit-margin-left="20"
|
||||||
|
fit-margin-right="20"
|
||||||
|
fit-margin-bottom="20" />
|
||||||
|
<metadata
|
||||||
|
id="metadata5">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title />
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Слой 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(-51.12025,-104.74797)">
|
||||||
|
<g
|
||||||
|
id="g1028"
|
||||||
|
transform="matrix(6.9754464,0,0,6.9754464,32.42507,404.31391)" />
|
||||||
|
<g
|
||||||
|
id="g1030"
|
||||||
|
transform="matrix(6.9754464,0,0,6.9754464,32.42507,404.31391)" />
|
||||||
|
<g
|
||||||
|
id="g1032"
|
||||||
|
transform="matrix(6.9754464,0,0,6.9754464,32.42507,404.31391)" />
|
||||||
|
<g
|
||||||
|
id="g1034"
|
||||||
|
transform="matrix(6.9754464,0,0,6.9754464,32.42507,404.31391)" />
|
||||||
|
<g
|
||||||
|
id="g1036"
|
||||||
|
transform="matrix(6.9754464,0,0,6.9754464,32.42507,404.31391)" />
|
||||||
|
<g
|
||||||
|
id="g1038"
|
||||||
|
transform="matrix(6.9754464,0,0,6.9754464,32.42507,404.31391)" />
|
||||||
|
<g
|
||||||
|
id="g1040"
|
||||||
|
transform="matrix(6.9754464,0,0,6.9754464,32.42507,404.31391)" />
|
||||||
|
<g
|
||||||
|
id="g1042"
|
||||||
|
transform="matrix(6.9754464,0,0,6.9754464,32.42507,404.31391)" />
|
||||||
|
<g
|
||||||
|
id="g1044"
|
||||||
|
transform="matrix(6.9754464,0,0,6.9754464,32.42507,404.31391)" />
|
||||||
|
<g
|
||||||
|
id="g1046"
|
||||||
|
transform="matrix(6.9754464,0,0,6.9754464,32.42507,404.31391)" />
|
||||||
|
<g
|
||||||
|
id="g1048"
|
||||||
|
transform="matrix(6.9754464,0,0,6.9754464,32.42507,404.31391)" />
|
||||||
|
<g
|
||||||
|
id="g1050"
|
||||||
|
transform="matrix(6.9754464,0,0,6.9754464,32.42507,404.31391)" />
|
||||||
|
<g
|
||||||
|
id="g1052"
|
||||||
|
transform="matrix(6.9754464,0,0,6.9754464,32.42507,404.31391)" />
|
||||||
|
<g
|
||||||
|
id="g1054"
|
||||||
|
transform="matrix(6.9754464,0,0,6.9754464,32.42507,404.31391)" />
|
||||||
|
<g
|
||||||
|
id="g1056"
|
||||||
|
transform="matrix(6.9754464,0,0,6.9754464,32.42507,404.31391)" />
|
||||||
|
<path
|
||||||
|
id="path1128"
|
||||||
|
d="m 307.12025,310.74755 c -50.53732,0 -91.66608,44.85688 -91.66608,99.99965 0,55.14277 41.12954,99.99964 91.66608,99.99964 50.53653,0 91.66607,-44.85687 91.66607,-99.99964 0,-55.14277 -41.12875,-99.99965 -91.66607,-99.99965 z m -34.21238,78.72707 c -1.46484,2.91327 -4.41092,4.60623 -7.45466,4.60623 -1.25312,0 -2.52265,-0.27656 -3.72733,-0.8789 l -12.9398,-6.4781 -12.9398,6.4781 c -4.13436,2.06718 -9.11481,0.37421 -11.18199,-3.72733 -2.05077,-4.11796 -0.39062,-9.11481 3.72733,-11.18199 l 16.66635,-8.33357 c 2.34374,-1.17187 5.11092,-1.17187 7.45466,0 l 16.66635,8.33357 c 4.11951,2.06718 5.77966,7.06403 3.72889,11.18199 z m 58.33338,-24.99991 c -1.46484,2.91327 -4.41092,4.60623 -7.45466,4.60623 -1.25312,0 -2.52264,-0.27656 -3.72733,-0.8789 l -12.93901,-6.47811 -12.9398,6.47811 c -4.13436,2.06718 -9.11481,0.37421 -11.18199,-3.72733 -2.05078,-4.11796 -0.39063,-9.11482 3.72733,-11.182 l 16.66634,-8.33356 c 2.34375,-1.17187 5.11092,-1.17187 7.45466,0 l 16.66635,8.33356 c 4.11874,2.06718 5.77889,7.06404 3.72811,11.182 z m 54.60606,13.81792 c 4.11795,2.06718 5.7781,7.06403 3.72733,11.18199 -1.46484,2.91327 -4.41092,4.60623 -7.45466,4.60623 -1.25312,0 -2.52265,-0.27656 -3.72733,-0.8789 l -12.9398,-6.4781 -12.9398,6.4781 c -4.11795,2.06718 -9.11481,0.37421 -11.18199,-3.72733 -2.05077,-4.11796 -0.39062,-9.11481 3.72733,-11.18199 l 16.66635,-8.33357 c 2.34374,-1.17187 5.11092,-1.17187 7.45466,0 z"
|
||||||
|
style="fill:#ffffff;stroke-width:0.781247" />
|
||||||
|
<path
|
||||||
|
id="path1130"
|
||||||
|
d="m 415.36283,274.00237 c -3.48202,-6.90544 -6.92029,-13.41714 -10.20934,-19.37102 l -8.26716,-14.47964 c -6.79607,-11.51871 -12.25699,-19.90305 -14.78354,-23.66554 -0.7164,-43.32797 -19.12415,-53.79356 -21.25617,-54.86777 -3.20624,-1.5789 -7.09607,-0.97656 -9.6195,1.56249 -12.25621,12.25621 -20.23118,24.4632 -24.00695,30.89286 h -40.20141 c -3.77577,-6.42888 -11.75153,-18.63665 -24.00695,-30.89286 -2.52265,-2.53905 -6.39685,-3.14139 -9.6195,-1.56249 -2.13202,1.07421 -20.54055,11.5398 -21.25617,54.86777 -2.52655,3.76327 -7.98669,12.14605 -14.78276,23.66476 l -8.27341,14.49214 c -3.28983,5.95701 -6.73044,12.47105 -10.21403,19.3804 l -7.4445,15.32572 c -17.72572,38.05377 -34.30066,85.4286 -34.30066,129.72766 0,69.32085 58.26776,128.42064 60.75838,130.89485 0.91171,0.91172 2.03437,1.61171 3.25546,2.01796 1.07421,0.35859 26.78974,8.757 69.31928,8.757 2.21327,0 4.32967,-0.8789 5.89217,-2.4414 l 5.89216,-5.89216 h 9.76559 l 5.89217,5.89216 c 1.56249,1.5625 3.67811,2.4414 5.89216,2.4414 42.52954,0 68.24507,-8.39841 69.31929,-8.757 1.22109,-0.40703 2.34374,-1.10703 3.25546,-2.01796 2.48905,-2.47421 60.75681,-61.57322 60.75681,-130.89485 0,-44.29906 -16.57494,-91.67389 -34.30066,-129.72766 z M 348.7865,227.41426 c 4.60624,0 4.41171,7.35466 4.41171,11.96089 4.60623,0 12.25464,0.1 12.25464,4.70624 0,9.19606 -7.47107,16.66634 -16.66635,16.66634 -9.19528,0 -16.66634,-7.47028 -16.66634,-16.66634 0,-9.19606 7.47106,-16.66713 16.66634,-16.66713 z m -57.69823,30.14364 c 1.28593,-3.10858 4.32967,-5.14295 7.69841,-5.14295 h 16.66635 c 3.36952,0 6.41248,2.03437 7.69841,5.14295 1.28593,3.10858 0.56953,6.70545 -1.80703,9.082 l -8.33356,8.33356 c -1.62734,1.62734 -3.76014,2.4414 -5.89217,2.4414 -2.13202,0 -4.26404,-0.81406 -5.89216,-2.4414 l -8.33357,-8.33356 c -2.37421,-2.37655 -3.09061,-5.97342 -1.80468,-9.082 z m -25.63428,-30.14364 c 4.60623,0 4.4117,7.35466 4.4117,11.96089 4.60623,0 12.25465,0.1 12.25465,4.70624 0,9.19606 -7.47107,16.66634 -16.66635,16.66634 -9.19606,0 -16.66635,-7.47106 -16.66635,-16.66634 -7.8e-4,-9.19606 7.47029,-16.66713 16.66635,-16.66713 z m 41.66626,299.99893 c -59.7326,0 -108.33321,-52.34357 -108.33321,-116.66599 0,-64.32243 48.60061,-116.66599 108.33321,-116.66599 59.73259,0 108.3332,52.34356 108.3332,116.66599 0,64.32242 -48.60061,116.66599 -108.3332,116.66599 z"
|
||||||
|
style="fill:#ffffff;stroke-width:0.781247;filter:url(#filter1059)"
|
||||||
|
sodipodi:nodetypes="cccccccccccccccsccssccssccsccscsssssssssssccsscsscssssss" />
|
||||||
|
<g
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="g1138"
|
||||||
|
transform="matrix(0.78124721,0,0,0.78124721,107.12096,160.74809)"
|
||||||
|
inkscape:groupmode="layer" />
|
||||||
|
<g
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="g1140"
|
||||||
|
transform="matrix(0.78124721,0,0,0.78124721,107.12096,160.74809)" />
|
||||||
|
<g
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="g1142"
|
||||||
|
transform="matrix(0.78124721,0,0,0.78124721,107.12096,160.74809)" />
|
||||||
|
<g
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="g1144"
|
||||||
|
transform="matrix(0.78124721,0,0,0.78124721,107.12096,160.74809)" />
|
||||||
|
<g
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="g1146"
|
||||||
|
transform="matrix(0.78124721,0,0,0.78124721,107.12096,160.74809)" />
|
||||||
|
<g
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="g1148"
|
||||||
|
transform="matrix(0.78124721,0,0,0.78124721,107.12096,160.74809)" />
|
||||||
|
<g
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="g1150"
|
||||||
|
transform="matrix(0.78124721,0,0,0.78124721,107.12096,160.74809)" />
|
||||||
|
<g
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="g1152"
|
||||||
|
transform="matrix(0.78124721,0,0,0.78124721,107.12096,160.74809)" />
|
||||||
|
<g
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="g1154"
|
||||||
|
transform="matrix(0.78124721,0,0,0.78124721,107.12096,160.74809)" />
|
||||||
|
<g
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="g1156"
|
||||||
|
transform="matrix(0.78124721,0,0,0.78124721,107.12096,160.74809)" />
|
||||||
|
<g
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="g1158"
|
||||||
|
transform="matrix(0.78124721,0,0,0.78124721,107.12096,160.74809)" />
|
||||||
|
<g
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="g1160"
|
||||||
|
transform="matrix(0.78124721,0,0,0.78124721,107.12096,160.74809)" />
|
||||||
|
<g
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="g1162"
|
||||||
|
transform="matrix(0.78124721,0,0,0.78124721,107.12096,160.74809)" />
|
||||||
|
<g
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="g1164"
|
||||||
|
transform="matrix(0.78124721,0,0,0.78124721,107.12096,160.74809)" />
|
||||||
|
<g
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="g1166"
|
||||||
|
transform="matrix(0.78124721,0,0,0.78124721,107.12096,160.74809)" />
|
||||||
|
<path
|
||||||
|
style="fill:#ef5350;fill-opacity:1;stroke:none;stroke-width:5.18208;stroke-linecap:round;stroke-linejoin:round"
|
||||||
|
d="m 344.3189,392.83707 c -4.60362,-2.75958 -5.36974,-9.69605 -1.45595,-13.18226 0.54459,-0.48508 5.34567,-3.07035 10.66909,-5.74503 7.5498,-3.79328 10.16725,-4.86303 11.89884,-4.86303 1.73503,0 4.42542,1.10391 12.3172,5.05396 11.72559,5.86898 12.60994,6.68326 12.60994,11.61118 0,3.40408 -0.99553,5.20819 -4.00363,7.25549 -3.08358,2.09867 -5.44113,1.68547 -13.60905,-2.38528 l -7.19926,-3.58796 -7.37198,3.59617 c -8.3911,4.09331 -10.26721,4.39753 -13.8552,2.24676 z"
|
||||||
|
id="path944" />
|
||||||
|
<path
|
||||||
|
style="fill:#ef5350;fill-opacity:1;stroke:none;stroke-width:5.18208;stroke-linecap:round;stroke-linejoin:round"
|
||||||
|
d="m 285.98437,367.98056 c -3.86343,-2.35557 -5.1524,-8.06518 -2.66781,-11.81734 1.64304,-2.48125 20.719,-12.23981 23.92632,-12.23981 1.56364,0 4.61398,1.26582 12.2153,5.06905 8.53551,4.27064 10.3157,5.36752 11.30239,6.96403 1.75651,2.84207 1.95178,5.62136 0.58856,8.37633 -1.52635,3.08463 -3.36973,4.32306 -6.86644,4.61304 -2.68142,0.22236 -3.36743,-0.003 -10.22731,-3.35873 l -7.35311,-3.59707 -7.04119,3.52834 c -7.90523,3.96133 -10.62609,4.44409 -13.87671,2.46216 z"
|
||||||
|
id="path946" />
|
||||||
|
<path
|
||||||
|
style="fill:#ef5350;fill-opacity:1;stroke:none;stroke-width:5.18208;stroke-linecap:round;stroke-linejoin:round"
|
||||||
|
d="m 228.11707,393.18031 c -1.0244,-0.54435 -2.42484,-1.80721 -3.11209,-2.80633 -1.05812,-1.53828 -1.2181,-2.32693 -1.04433,-5.14815 0.29039,-4.71472 1.41139,-5.70783 12.90113,-11.42937 7.71258,-3.84061 9.99443,-4.74971 11.92193,-4.74971 1.94819,0 4.22735,0.92952 12.47354,5.08716 8.66324,4.3679 10.26522,5.3693 11.33052,7.08263 3.53608,5.68714 -0.55313,12.95355 -7.28968,12.95355 -1.25225,0 -4.29453,-1.20187 -9.08226,-3.58799 l -7.19927,-3.58796 -7.37197,3.59617 c -8.07507,3.93914 -10.21699,4.34922 -13.52752,2.59 z"
|
||||||
|
id="path948" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 13 KiB |
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RenderSettings">
|
|
||||||
<option name="quality" value="0.25" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"id": 4,
|
||||||
|
"title": "Read later",
|
||||||
|
"sortKey": 1,
|
||||||
|
"order": "NEWEST",
|
||||||
|
"createdAt": 1335906000000,
|
||||||
|
"isTrackingEnabled": true
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"id": -2096681732556647985,
|
||||||
|
"title": "Странствия Эманон",
|
||||||
|
"url": "/stranstviia_emanon",
|
||||||
|
"publicUrl": "https://readmanga.io/stranstviia_emanon",
|
||||||
|
"rating": 0.9400894,
|
||||||
|
"isNsfw": true,
|
||||||
|
"coverUrl": "https://staticrm.rmr.rocks/uploads/pics/01/12/559_p.jpg",
|
||||||
|
"tags": [
|
||||||
|
{
|
||||||
|
"title": "Сверхъестественное",
|
||||||
|
"key": "supernatural",
|
||||||
|
"source": "READMANGA_RU"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Сэйнэн",
|
||||||
|
"key": "seinen",
|
||||||
|
"source": "READMANGA_RU"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Повседневность",
|
||||||
|
"key": "slice_of_life",
|
||||||
|
"source": "READMANGA_RU"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Приключения",
|
||||||
|
"key": "adventure",
|
||||||
|
"source": "READMANGA_RU"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"state": "FINISHED",
|
||||||
|
"largeCoverUrl": "https://staticrm.rmr.rocks/uploads/pics/01/12/559_o.jpg",
|
||||||
|
"description": null,
|
||||||
|
"source": "READMANGA_RU"
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package org.koitharu.kotatsu
|
||||||
|
|
||||||
|
import android.app.Instrumentation
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
|
suspend fun Instrumentation.awaitForIdle() = suspendCoroutine<Unit> { cont ->
|
||||||
|
waitForIdle { cont.resume(Unit) }
|
||||||
|
}
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
package org.koitharu.kotatsu
|
||||||
|
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
|
import com.squareup.moshi.*
|
||||||
|
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||||
|
import okio.buffer
|
||||||
|
import okio.source
|
||||||
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
object SampleData {
|
||||||
|
|
||||||
|
private val moshi = Moshi.Builder()
|
||||||
|
.add(DateAdapter())
|
||||||
|
.add(KotlinJsonAdapterFactory())
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val manga: Manga = loadAsset("manga/header.json", Manga::class)
|
||||||
|
|
||||||
|
val mangaDetails: Manga = loadAsset("manga/full.json", Manga::class)
|
||||||
|
|
||||||
|
val tag = mangaDetails.tags.elementAt(2)
|
||||||
|
|
||||||
|
val chapter = checkNotNull(mangaDetails.chapters)[2]
|
||||||
|
|
||||||
|
val favouriteCategory: FavouriteCategory = loadAsset("categories/simple.json", FavouriteCategory::class)
|
||||||
|
|
||||||
|
fun <T : Any> loadAsset(name: String, cls: KClass<T>): T {
|
||||||
|
val assets = InstrumentationRegistry.getInstrumentation().context.assets
|
||||||
|
return assets.open(name).use {
|
||||||
|
moshi.adapter(cls.java).fromJson(it.source().buffer())
|
||||||
|
} ?: throw RuntimeException("Cannot read asset from json \"$name\"")
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DateAdapter : JsonAdapter<Date>() {
|
||||||
|
|
||||||
|
@FromJson
|
||||||
|
override fun fromJson(reader: JsonReader): Date? {
|
||||||
|
val ms = reader.nextLong()
|
||||||
|
return if (ms == 0L) {
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
Date(ms)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ToJson
|
||||||
|
override fun toJson(writer: JsonWriter, value: Date?) {
|
||||||
|
writer.value(value?.time ?: 0L)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
package org.koitharu.kotatsu.core.os
|
||||||
|
|
||||||
|
import android.content.pm.ShortcutInfo
|
||||||
|
import android.content.pm.ShortcutManager
|
||||||
|
import android.os.Build
|
||||||
|
import androidx.core.content.getSystemService
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.koin.test.KoinTest
|
||||||
|
import org.koin.test.inject
|
||||||
|
import org.koitharu.kotatsu.SampleData
|
||||||
|
import org.koitharu.kotatsu.awaitForIdle
|
||||||
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class ShortcutsUpdaterTest : KoinTest {
|
||||||
|
|
||||||
|
private val historyRepository by inject<HistoryRepository>()
|
||||||
|
private val shortcutsUpdater by inject<ShortcutsUpdater>()
|
||||||
|
private val database by inject<MangaDatabase>()
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
database.clearAllTables()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testUpdateShortcuts() = runTest {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
|
||||||
|
return@runTest
|
||||||
|
}
|
||||||
|
awaitUpdate()
|
||||||
|
assertTrue(getShortcuts().isEmpty())
|
||||||
|
historyRepository.addOrUpdate(
|
||||||
|
manga = SampleData.manga,
|
||||||
|
chapterId = SampleData.chapter.id,
|
||||||
|
page = 4,
|
||||||
|
scroll = 2,
|
||||||
|
percent = 0.3f
|
||||||
|
)
|
||||||
|
awaitUpdate()
|
||||||
|
|
||||||
|
val shortcuts = getShortcuts()
|
||||||
|
assertEquals(1, shortcuts.size)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getShortcuts(): List<ShortcutInfo> {
|
||||||
|
val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||||
|
val manager = checkNotNull(context.getSystemService<ShortcutManager>())
|
||||||
|
return manager.dynamicShortcuts.filterNot { it.id == "com.squareup.leakcanary.dynamic_shortcut" }
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun awaitUpdate() {
|
||||||
|
val instrumentation = InstrumentationRegistry.getInstrumentation()
|
||||||
|
instrumentation.awaitForIdle()
|
||||||
|
shortcutsUpdater.await()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
package org.koitharu.kotatsu.settings.backup
|
||||||
|
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.koin.test.KoinTest
|
||||||
|
import org.koin.test.get
|
||||||
|
import org.koin.test.inject
|
||||||
|
import org.koitharu.kotatsu.SampleData
|
||||||
|
import org.koitharu.kotatsu.core.backup.BackupRepository
|
||||||
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
||||||
|
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
||||||
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
|
import kotlin.test.*
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class AppBackupAgentTest : KoinTest {
|
||||||
|
|
||||||
|
private val historyRepository by inject<HistoryRepository>()
|
||||||
|
private val favouritesRepository by inject<FavouritesRepository>()
|
||||||
|
private val backupRepository by inject<BackupRepository>()
|
||||||
|
private val database by inject<MangaDatabase>()
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
database.clearAllTables()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testBackupRestore() = runTest {
|
||||||
|
val category = favouritesRepository.createCategory(
|
||||||
|
title = SampleData.favouriteCategory.title,
|
||||||
|
sortOrder = SampleData.favouriteCategory.order,
|
||||||
|
isTrackerEnabled = SampleData.favouriteCategory.isTrackingEnabled,
|
||||||
|
)
|
||||||
|
favouritesRepository.addToCategory(categoryId = category.id, mangas = listOf(SampleData.manga))
|
||||||
|
historyRepository.addOrUpdate(
|
||||||
|
manga = SampleData.mangaDetails,
|
||||||
|
chapterId = SampleData.mangaDetails.chapters!![2].id,
|
||||||
|
page = 3,
|
||||||
|
scroll = 40,
|
||||||
|
percent = 0.2f,
|
||||||
|
)
|
||||||
|
val history = checkNotNull(historyRepository.getOne(SampleData.manga))
|
||||||
|
|
||||||
|
val agent = AppBackupAgent()
|
||||||
|
val backup = agent.createBackupFile(get(), backupRepository)
|
||||||
|
|
||||||
|
database.clearAllTables()
|
||||||
|
assertTrue(favouritesRepository.getAllManga().isEmpty())
|
||||||
|
assertNull(historyRepository.getLastOrNull())
|
||||||
|
|
||||||
|
backup.inputStream().use {
|
||||||
|
agent.restoreBackupFile(it.fd, backup.length(), backupRepository)
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(category, favouritesRepository.getCategory(category.id))
|
||||||
|
assertEquals(history, historyRepository.getOne(SampleData.manga))
|
||||||
|
assertContentEquals(listOf(SampleData.manga), favouritesRepository.getManga(category.id))
|
||||||
|
|
||||||
|
val allTags = database.tagsDao.findTags(SampleData.tag.source.name).toMangaTags()
|
||||||
|
assertContains(allTags, SampleData.tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,183 @@
|
|||||||
|
package org.koitharu.kotatsu.tracker.domain
|
||||||
|
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.koin.test.KoinTest
|
||||||
|
import org.koin.test.inject
|
||||||
|
import org.koitharu.kotatsu.SampleData
|
||||||
|
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertFalse
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class TrackerTest : KoinTest {
|
||||||
|
|
||||||
|
private val repository by inject<TrackingRepository>()
|
||||||
|
private val dataRepository by inject<MangaDataRepository>()
|
||||||
|
private val tracker by inject<Tracker>()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun noUpdates() = runTest {
|
||||||
|
val manga = loadManga("full.json")
|
||||||
|
tracker.deleteTrack(manga.id)
|
||||||
|
|
||||||
|
tracker.checkUpdates(manga, commit = true).apply {
|
||||||
|
assertFalse(isValid)
|
||||||
|
assert(newChapters.isEmpty())
|
||||||
|
}
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(manga.id))
|
||||||
|
tracker.checkUpdates(manga, commit = true).apply {
|
||||||
|
assertTrue(isValid)
|
||||||
|
assert(newChapters.isEmpty())
|
||||||
|
}
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(manga.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun hasUpdates() = runTest {
|
||||||
|
val mangaFirst = loadManga("first_chapters.json")
|
||||||
|
val mangaFull = loadManga("full.json")
|
||||||
|
tracker.deleteTrack(mangaFirst.id)
|
||||||
|
|
||||||
|
tracker.checkUpdates(mangaFirst, commit = true).apply {
|
||||||
|
assertFalse(isValid)
|
||||||
|
assert(newChapters.isEmpty())
|
||||||
|
}
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
tracker.checkUpdates(mangaFull, commit = true).apply {
|
||||||
|
assertTrue(isValid)
|
||||||
|
assertEquals(3, newChapters.size)
|
||||||
|
}
|
||||||
|
assertEquals(3, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
tracker.checkUpdates(mangaFull, commit = true).apply {
|
||||||
|
assertTrue(isValid)
|
||||||
|
assert(newChapters.isEmpty())
|
||||||
|
}
|
||||||
|
assertEquals(3, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun badIds() = runTest {
|
||||||
|
val mangaFirst = loadManga("first_chapters.json")
|
||||||
|
val mangaBad = loadManga("bad_ids.json")
|
||||||
|
tracker.deleteTrack(mangaFirst.id)
|
||||||
|
|
||||||
|
tracker.checkUpdates(mangaFirst, commit = true).apply {
|
||||||
|
assertFalse(isValid)
|
||||||
|
assert(newChapters.isEmpty())
|
||||||
|
}
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
tracker.checkUpdates(mangaBad, commit = true).apply {
|
||||||
|
assertFalse(isValid)
|
||||||
|
assert(newChapters.isEmpty())
|
||||||
|
}
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
tracker.checkUpdates(mangaFirst, commit = true).apply {
|
||||||
|
assertFalse(isValid)
|
||||||
|
assert(newChapters.isEmpty())
|
||||||
|
}
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun badIds2() = runTest {
|
||||||
|
val mangaFirst = loadManga("first_chapters.json")
|
||||||
|
val mangaBad = loadManga("bad_ids.json")
|
||||||
|
val mangaFull = loadManga("full.json")
|
||||||
|
tracker.deleteTrack(mangaFirst.id)
|
||||||
|
|
||||||
|
tracker.checkUpdates(mangaFirst, commit = true).apply {
|
||||||
|
assertFalse(isValid)
|
||||||
|
assert(newChapters.isEmpty())
|
||||||
|
}
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
tracker.checkUpdates(mangaFull, commit = true).apply {
|
||||||
|
assertTrue(isValid)
|
||||||
|
assertEquals(3, newChapters.size)
|
||||||
|
}
|
||||||
|
assertEquals(3, repository.getNewChaptersCount(mangaFull.id))
|
||||||
|
tracker.checkUpdates(mangaBad, commit = true).apply {
|
||||||
|
assertFalse(isValid)
|
||||||
|
assert(newChapters.isEmpty())
|
||||||
|
}
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun fullReset() = runTest {
|
||||||
|
val mangaFull = loadManga("full.json")
|
||||||
|
val mangaFirst = loadManga("first_chapters.json")
|
||||||
|
val mangaEmpty = loadManga("empty.json")
|
||||||
|
tracker.deleteTrack(mangaFull.id)
|
||||||
|
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(mangaFull.id))
|
||||||
|
tracker.checkUpdates(mangaFull, commit = true).apply {
|
||||||
|
assertFalse(isValid)
|
||||||
|
assert(newChapters.isEmpty())
|
||||||
|
}
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(mangaFull.id))
|
||||||
|
tracker.checkUpdates(mangaEmpty, commit = true).apply {
|
||||||
|
assert(newChapters.isEmpty())
|
||||||
|
}
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(mangaFull.id))
|
||||||
|
tracker.checkUpdates(mangaFirst, commit = true).apply {
|
||||||
|
assertFalse(isValid)
|
||||||
|
assert(newChapters.isEmpty())
|
||||||
|
}
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(mangaFull.id))
|
||||||
|
tracker.checkUpdates(mangaFull, commit = true).apply {
|
||||||
|
assertTrue(isValid)
|
||||||
|
assertEquals(3, newChapters.size)
|
||||||
|
}
|
||||||
|
assertEquals(3, repository.getNewChaptersCount(mangaFull.id))
|
||||||
|
tracker.checkUpdates(mangaEmpty, commit = true).apply {
|
||||||
|
assertFalse(isValid)
|
||||||
|
assert(newChapters.isEmpty())
|
||||||
|
}
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(mangaFull.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun syncWithHistory() = runTest {
|
||||||
|
val mangaFull = loadManga("full.json")
|
||||||
|
val mangaFirst = loadManga("first_chapters.json")
|
||||||
|
tracker.deleteTrack(mangaFull.id)
|
||||||
|
|
||||||
|
tracker.checkUpdates(mangaFirst, commit = true).apply {
|
||||||
|
assertFalse(isValid)
|
||||||
|
assert(newChapters.isEmpty())
|
||||||
|
}
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
tracker.checkUpdates(mangaFull, commit = true).apply {
|
||||||
|
assertTrue(isValid)
|
||||||
|
assertEquals(3, newChapters.size)
|
||||||
|
}
|
||||||
|
assertEquals(3, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
|
||||||
|
var chapter = requireNotNull(mangaFull.chapters).run { get(lastIndex - 1) }
|
||||||
|
repository.syncWithHistory(mangaFull, chapter.id)
|
||||||
|
|
||||||
|
assertEquals(1, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
|
||||||
|
chapter = requireNotNull(mangaFull.chapters).run { get(lastIndex) }
|
||||||
|
repository.syncWithHistory(mangaFull, chapter.id)
|
||||||
|
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
|
||||||
|
tracker.checkUpdates(mangaFull, commit = true).apply {
|
||||||
|
assertTrue(isValid)
|
||||||
|
assert(newChapters.isEmpty())
|
||||||
|
}
|
||||||
|
assertEquals(0, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun loadManga(name: String): Manga {
|
||||||
|
val manga = SampleData.loadAsset("manga/$name", Manga::class)
|
||||||
|
dataRepository.storeManga(manga)
|
||||||
|
return manga
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,151 @@
|
|||||||
|
package com.google.android.material.appbar
|
||||||
|
|
||||||
|
import android.animation.AnimatorSet
|
||||||
|
import android.animation.ValueAnimator
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.annotation.FloatRange
|
||||||
|
import com.google.android.material.animation.AnimationUtils
|
||||||
|
import com.google.android.material.appbar.AppBarLayout.OnOffsetChangedListener
|
||||||
|
import com.google.android.material.shape.MaterialShapeDrawable
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [AppBarLayout] with our own lift state handler and custom title alpha.
|
||||||
|
*
|
||||||
|
* Inside this package to access some package-private methods.
|
||||||
|
*/
|
||||||
|
class KotatsuAppBarLayout @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null
|
||||||
|
) : AppBarLayout(context, attrs) {
|
||||||
|
|
||||||
|
private var lifted = true
|
||||||
|
|
||||||
|
private val toolbar by lazy { findViewById<MaterialToolbar>(R.id.toolbar) }
|
||||||
|
|
||||||
|
@FloatRange(from = 0.0, to = 1.0)
|
||||||
|
var titleTextAlpha = 1F
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
titleTextView?.alpha = field
|
||||||
|
}
|
||||||
|
|
||||||
|
private var titleTextView: TextView? = null
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
field?.alpha = titleTextAlpha
|
||||||
|
}
|
||||||
|
|
||||||
|
private var animatorSet: AnimatorSet? = null
|
||||||
|
|
||||||
|
private var statusBarForegroundAnimator: ValueAnimator? = null
|
||||||
|
private val offsetListener = OnOffsetChangedListener { appBarLayout, verticalOffset ->
|
||||||
|
// Show status bar foreground when offset
|
||||||
|
val foreground = (appBarLayout?.statusBarForeground as? MaterialShapeDrawable) ?: return@OnOffsetChangedListener
|
||||||
|
val start = foreground.alpha
|
||||||
|
val end = if (verticalOffset != 0) 255 else 0
|
||||||
|
|
||||||
|
statusBarForegroundAnimator?.cancel()
|
||||||
|
if (animatorSet?.isRunning == true) {
|
||||||
|
foreground.alpha = end
|
||||||
|
return@OnOffsetChangedListener
|
||||||
|
}
|
||||||
|
if (start != end) {
|
||||||
|
statusBarForegroundAnimator = ValueAnimator.ofInt(start, end).apply {
|
||||||
|
duration = resources.getInteger(materialR.integer.app_bar_elevation_anim_duration).toLong()
|
||||||
|
interpolator = AnimationUtils.LINEAR_INTERPOLATOR
|
||||||
|
addUpdateListener {
|
||||||
|
foreground.alpha = it.animatedValue as Int
|
||||||
|
}
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var isTransparentWhenNotLifted = false
|
||||||
|
set(value) {
|
||||||
|
if (field != value) {
|
||||||
|
field = value
|
||||||
|
updateStates()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isLiftOnScroll(): Boolean = false
|
||||||
|
|
||||||
|
override fun isLifted(): Boolean = lifted
|
||||||
|
|
||||||
|
override fun setLifted(lifted: Boolean): Boolean {
|
||||||
|
return if (this.lifted != lifted) {
|
||||||
|
this.lifted = lifted
|
||||||
|
updateStates()
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setLiftedState(lifted: Boolean, force: Boolean): Boolean = false
|
||||||
|
|
||||||
|
override fun onAttachedToWindow() {
|
||||||
|
super.onAttachedToWindow()
|
||||||
|
addOnOffsetChangedListener(offsetListener)
|
||||||
|
toolbar.background.alpha = 0 // Use app bar background
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow()
|
||||||
|
removeOnOffsetChangedListener(offsetListener)
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("Recycle")
|
||||||
|
private fun updateStates() {
|
||||||
|
val animators = mutableListOf<ValueAnimator>()
|
||||||
|
|
||||||
|
val fromElevation = elevation
|
||||||
|
val toElevation = if (lifted) {
|
||||||
|
resources.getDimension(materialR.dimen.design_appbar_elevation)
|
||||||
|
} else {
|
||||||
|
0F
|
||||||
|
}
|
||||||
|
if (fromElevation != toElevation) {
|
||||||
|
ValueAnimator.ofFloat(fromElevation, toElevation).apply {
|
||||||
|
addUpdateListener {
|
||||||
|
elevation = it.animatedValue as Float
|
||||||
|
(statusBarForeground as? MaterialShapeDrawable)?.elevation = it.animatedValue as Float
|
||||||
|
}
|
||||||
|
animators.add(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val transparent = if (lifted) false else isTransparentWhenNotLifted
|
||||||
|
val fromAlpha = (background as? MaterialShapeDrawable)?.alpha ?: background.alpha
|
||||||
|
val toAlpha = if (transparent) 0 else 255
|
||||||
|
if (fromAlpha != toAlpha) {
|
||||||
|
ValueAnimator.ofInt(fromAlpha, toAlpha).apply {
|
||||||
|
addUpdateListener {
|
||||||
|
val value = it.animatedValue as Int
|
||||||
|
background.alpha = value
|
||||||
|
}
|
||||||
|
animators.add(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (animators.isNotEmpty()) {
|
||||||
|
animatorSet?.cancel()
|
||||||
|
animatorSet = AnimatorSet().apply {
|
||||||
|
duration = resources.getInteger(materialR.integer.app_bar_elevation_anim_duration).toLong()
|
||||||
|
interpolator = AnimationUtils.LINEAR_INTERPOLATOR
|
||||||
|
playTogether(*animators.toTypedArray())
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
statusBarForeground = MaterialShapeDrawable.createWithElevationOverlay(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.dialog
|
||||||
|
|
||||||
|
import android.content.DialogInterface
|
||||||
|
|
||||||
|
class RememberSelectionDialogListener(initialValue: Int) : DialogInterface.OnClickListener {
|
||||||
|
|
||||||
|
var selection: Int = initialValue
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun onClick(dialog: DialogInterface?, which: Int) {
|
||||||
|
selection = which
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,89 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.base.ui.dialog
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.DialogInterface
|
|
||||||
import android.text.InputFilter
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import androidx.annotation.StringRes
|
|
||||||
import androidx.appcompat.app.AlertDialog
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
||||||
import org.koitharu.kotatsu.databinding.DialogInputBinding
|
|
||||||
|
|
||||||
class TextInputDialog private constructor(
|
|
||||||
private val delegate: AlertDialog,
|
|
||||||
) : DialogInterface by delegate {
|
|
||||||
|
|
||||||
fun show() = delegate.show()
|
|
||||||
|
|
||||||
class Builder(context: Context) {
|
|
||||||
|
|
||||||
private val binding = DialogInputBinding.inflate(LayoutInflater.from(context))
|
|
||||||
|
|
||||||
private val delegate = MaterialAlertDialogBuilder(context)
|
|
||||||
.setView(binding.root)
|
|
||||||
|
|
||||||
fun setTitle(@StringRes titleResId: Int): Builder {
|
|
||||||
delegate.setTitle(titleResId)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setTitle(title: CharSequence): Builder {
|
|
||||||
delegate.setTitle(title)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setHint(@StringRes hintResId: Int): Builder {
|
|
||||||
binding.inputEdit.hint = binding.root.context.getString(hintResId)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setMaxLength(maxLength: Int, strict: Boolean): Builder {
|
|
||||||
with(binding.inputLayout) {
|
|
||||||
counterMaxLength = maxLength
|
|
||||||
isCounterEnabled = maxLength > 0
|
|
||||||
}
|
|
||||||
if (strict && maxLength > 0) {
|
|
||||||
binding.inputEdit.filters += InputFilter.LengthFilter(maxLength)
|
|
||||||
}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setInputType(inputType: Int): Builder {
|
|
||||||
binding.inputEdit.inputType = inputType
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setText(text: String): Builder {
|
|
||||||
binding.inputEdit.setText(text)
|
|
||||||
binding.inputEdit.setSelection(text.length)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setPositiveButton(
|
|
||||||
@StringRes textId: Int,
|
|
||||||
listener: (DialogInterface, String) -> Unit
|
|
||||||
): Builder {
|
|
||||||
delegate.setPositiveButton(textId) { dialog, _ ->
|
|
||||||
listener(dialog, binding.inputEdit.text?.toString().orEmpty())
|
|
||||||
}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setNegativeButton(
|
|
||||||
@StringRes textId: Int,
|
|
||||||
listener: DialogInterface.OnClickListener? = null
|
|
||||||
): Builder {
|
|
||||||
delegate.setNegativeButton(textId, listener)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setOnCancelListener(listener: DialogInterface.OnCancelListener): Builder {
|
|
||||||
delegate.setOnCancelListener(listener)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun create() =
|
|
||||||
TextInputDialog(delegate.create())
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,200 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.appcompat.view.ActionMode
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
|
import androidx.lifecycle.LifecycleEventObserver
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.savedstate.SavedStateRegistry
|
||||||
|
import androidx.savedstate.SavedStateRegistryOwner
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration
|
||||||
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
|
||||||
|
private const val KEY_SELECTION = "selection"
|
||||||
|
private const val PROVIDER_NAME = "selection_decoration"
|
||||||
|
|
||||||
|
class ListSelectionController(
|
||||||
|
private val activity: Activity,
|
||||||
|
private val decoration: AbstractSelectionItemDecoration,
|
||||||
|
private val registryOwner: SavedStateRegistryOwner,
|
||||||
|
private val callback: Callback2,
|
||||||
|
) : ActionMode.Callback, SavedStateRegistry.SavedStateProvider {
|
||||||
|
|
||||||
|
private var actionMode: ActionMode? = null
|
||||||
|
|
||||||
|
val count: Int
|
||||||
|
get() = decoration.checkedItemsCount
|
||||||
|
|
||||||
|
init {
|
||||||
|
registryOwner.lifecycle.addObserver(StateEventObserver())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun snapshot(): Set<Long> {
|
||||||
|
return peekCheckedIds().toSet()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun peekCheckedIds(): Set<Long> {
|
||||||
|
return decoration.checkedItemsIds
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clear() {
|
||||||
|
decoration.clearSelection()
|
||||||
|
notifySelectionChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addAll(ids: Collection<Long>) {
|
||||||
|
if (ids.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
decoration.checkAll(ids)
|
||||||
|
notifySelectionChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun attachToRecyclerView(recyclerView: RecyclerView) {
|
||||||
|
recyclerView.addItemDecoration(decoration)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun saveState(): Bundle {
|
||||||
|
val bundle = Bundle(1)
|
||||||
|
bundle.putLongArray(KEY_SELECTION, peekCheckedIds().toLongArray())
|
||||||
|
return bundle
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onItemClick(id: Long): Boolean {
|
||||||
|
if (decoration.checkedItemsCount != 0) {
|
||||||
|
decoration.toggleItemChecked(id)
|
||||||
|
if (decoration.checkedItemsCount == 0) {
|
||||||
|
actionMode?.finish()
|
||||||
|
} else {
|
||||||
|
actionMode?.invalidate()
|
||||||
|
}
|
||||||
|
notifySelectionChanged()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onItemLongClick(id: Long): Boolean {
|
||||||
|
startActionMode()
|
||||||
|
return actionMode?.also {
|
||||||
|
decoration.setItemIsChecked(id, true)
|
||||||
|
notifySelectionChanged()
|
||||||
|
} != null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||||
|
return callback.onCreateActionMode(this, mode, menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||||
|
return callback.onPrepareActionMode(this, mode, menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||||
|
return callback.onActionItemClicked(this, mode, item)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroyActionMode(mode: ActionMode) {
|
||||||
|
callback.onDestroyActionMode(this, mode)
|
||||||
|
clear()
|
||||||
|
actionMode = null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startActionMode() {
|
||||||
|
if (actionMode == null) {
|
||||||
|
actionMode = (activity as? AppCompatActivity)?.startSupportActionMode(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun notifySelectionChanged() {
|
||||||
|
val count = decoration.checkedItemsCount
|
||||||
|
callback.onSelectionChanged(this, count)
|
||||||
|
if (count == 0) {
|
||||||
|
actionMode?.finish()
|
||||||
|
} else {
|
||||||
|
actionMode?.invalidate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun restoreState(ids: Collection<Long>) {
|
||||||
|
if (ids.isEmpty() || decoration.checkedItemsCount != 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
decoration.checkAll(ids)
|
||||||
|
startActionMode()
|
||||||
|
notifySelectionChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
interface Callback : Callback2 {
|
||||||
|
|
||||||
|
fun onSelectionChanged(count: Int)
|
||||||
|
|
||||||
|
fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean
|
||||||
|
|
||||||
|
fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean
|
||||||
|
|
||||||
|
fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean
|
||||||
|
|
||||||
|
fun onDestroyActionMode(mode: ActionMode) = Unit
|
||||||
|
|
||||||
|
override fun onSelectionChanged(controller: ListSelectionController, count: Int) {
|
||||||
|
onSelectionChanged(count)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateActionMode(controller: ListSelectionController, mode: ActionMode, menu: Menu): Boolean {
|
||||||
|
return onCreateActionMode(mode, menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPrepareActionMode(controller: ListSelectionController, mode: ActionMode, menu: Menu): Boolean {
|
||||||
|
return onPrepareActionMode(mode, menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActionItemClicked(
|
||||||
|
controller: ListSelectionController,
|
||||||
|
mode: ActionMode,
|
||||||
|
item: MenuItem
|
||||||
|
): Boolean = onActionItemClicked(mode, item)
|
||||||
|
|
||||||
|
override fun onDestroyActionMode(controller: ListSelectionController, mode: ActionMode) {
|
||||||
|
onDestroyActionMode(mode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Callback2 {
|
||||||
|
|
||||||
|
fun onSelectionChanged(controller: ListSelectionController, count: Int)
|
||||||
|
|
||||||
|
fun onCreateActionMode(controller: ListSelectionController, mode: ActionMode, menu: Menu): Boolean
|
||||||
|
|
||||||
|
fun onPrepareActionMode(controller: ListSelectionController, mode: ActionMode, menu: Menu): Boolean
|
||||||
|
|
||||||
|
fun onActionItemClicked(controller: ListSelectionController, mode: ActionMode, item: MenuItem): Boolean
|
||||||
|
|
||||||
|
fun onDestroyActionMode(controller: ListSelectionController, mode: ActionMode) = Unit
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class StateEventObserver : LifecycleEventObserver {
|
||||||
|
|
||||||
|
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
|
||||||
|
if (event == Lifecycle.Event.ON_CREATE) {
|
||||||
|
val registry = registryOwner.savedStateRegistry
|
||||||
|
registry.registerSavedStateProvider(PROVIDER_NAME, this@ListSelectionController)
|
||||||
|
val state = registry.consumeRestoredStateForKey(PROVIDER_NAME)
|
||||||
|
if (state != null) {
|
||||||
|
Dispatchers.Main.dispatch(EmptyCoroutineContext) { // == Handler.post
|
||||||
|
if (source.lifecycle.currentState.isAtLeast(Lifecycle.State.CREATED)) {
|
||||||
|
restoreState(state.getLongArray(KEY_SELECTION)?.toList().orEmpty())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,204 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.util.ArrayMap
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.appcompat.view.ActionMode
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
|
import androidx.lifecycle.LifecycleEventObserver
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.savedstate.SavedStateRegistry
|
||||||
|
import androidx.savedstate.SavedStateRegistryOwner
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration
|
||||||
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
|
||||||
|
private const val PROVIDER_NAME = "selection_decoration_sectioned"
|
||||||
|
|
||||||
|
class SectionedSelectionController<T : Any>(
|
||||||
|
private val activity: Activity,
|
||||||
|
private val registryOwner: SavedStateRegistryOwner,
|
||||||
|
private val callback: Callback<T>,
|
||||||
|
) : ActionMode.Callback, SavedStateRegistry.SavedStateProvider {
|
||||||
|
|
||||||
|
private var actionMode: ActionMode? = null
|
||||||
|
|
||||||
|
private var pendingData: MutableMap<String, Collection<Long>>? = null
|
||||||
|
private val decorations = ArrayMap<T, AbstractSelectionItemDecoration>()
|
||||||
|
|
||||||
|
val count: Int
|
||||||
|
get() = decorations.values.sumOf { it.checkedItemsCount }
|
||||||
|
|
||||||
|
init {
|
||||||
|
registryOwner.lifecycle.addObserver(StateEventObserver())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun snapshot(): Map<T, Set<Long>> {
|
||||||
|
return decorations.mapValues { it.value.checkedItemsIds.toSet() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun peekCheckedIds(): Map<T, Set<Long>> {
|
||||||
|
return decorations.mapValues { it.value.checkedItemsIds }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clear() {
|
||||||
|
decorations.values.forEach {
|
||||||
|
it.clearSelection()
|
||||||
|
}
|
||||||
|
notifySelectionChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun attachToRecyclerView(section: T, recyclerView: RecyclerView) {
|
||||||
|
val decoration = getDecoration(section)
|
||||||
|
val pendingIds = pendingData?.remove(section.toString())
|
||||||
|
if (!pendingIds.isNullOrEmpty()) {
|
||||||
|
decoration.checkAll(pendingIds)
|
||||||
|
startActionMode()
|
||||||
|
notifySelectionChanged()
|
||||||
|
}
|
||||||
|
recyclerView.addItemDecoration(decoration)
|
||||||
|
if (pendingData?.isEmpty() == true) {
|
||||||
|
pendingData = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun saveState(): Bundle {
|
||||||
|
val bundle = Bundle(decorations.size)
|
||||||
|
for ((k, v) in decorations) {
|
||||||
|
bundle.putLongArray(k.toString(), v.checkedItemsIds.toLongArray())
|
||||||
|
}
|
||||||
|
return bundle
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onItemClick(section: T, id: Long): Boolean {
|
||||||
|
val decoration = getDecoration(section)
|
||||||
|
if (isInSelectionMode()) {
|
||||||
|
decoration.toggleItemChecked(id)
|
||||||
|
if (isInSelectionMode()) {
|
||||||
|
actionMode?.invalidate()
|
||||||
|
} else {
|
||||||
|
actionMode?.finish()
|
||||||
|
}
|
||||||
|
notifySelectionChanged()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onItemLongClick(section: T, id: Long): Boolean {
|
||||||
|
val decoration = getDecoration(section)
|
||||||
|
startActionMode()
|
||||||
|
return actionMode?.also {
|
||||||
|
decoration.setItemIsChecked(id, true)
|
||||||
|
notifySelectionChanged()
|
||||||
|
} != null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getSectionCount(section: T): Int {
|
||||||
|
return decorations[section]?.checkedItemsCount ?: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addToSelection(section: T, ids: Collection<Long>): Boolean {
|
||||||
|
val decoration = getDecoration(section)
|
||||||
|
startActionMode()
|
||||||
|
return actionMode?.also {
|
||||||
|
decoration.checkAll(ids)
|
||||||
|
notifySelectionChanged()
|
||||||
|
} != null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clearSelection(section: T) {
|
||||||
|
decorations[section]?.clearSelection() ?: return
|
||||||
|
notifySelectionChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||||
|
return callback.onCreateActionMode(mode, menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||||
|
return callback.onPrepareActionMode(mode, menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||||
|
return callback.onActionItemClicked(mode, item)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroyActionMode(mode: ActionMode) {
|
||||||
|
callback.onDestroyActionMode(mode)
|
||||||
|
clear()
|
||||||
|
actionMode = null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startActionMode() {
|
||||||
|
if (actionMode == null) {
|
||||||
|
actionMode = (activity as? AppCompatActivity)?.startSupportActionMode(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isInSelectionMode(): Boolean {
|
||||||
|
return decorations.values.any { x -> x.checkedItemsCount > 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun notifySelectionChanged() {
|
||||||
|
val count = this.count
|
||||||
|
callback.onSelectionChanged(count)
|
||||||
|
if (count == 0) {
|
||||||
|
actionMode?.finish()
|
||||||
|
} else {
|
||||||
|
actionMode?.invalidate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun restoreState(ids: MutableMap<String, Collection<Long>>) {
|
||||||
|
if (ids.isEmpty() || isInSelectionMode()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for ((k, v) in decorations) {
|
||||||
|
val items = ids.remove(k.toString())
|
||||||
|
if (!items.isNullOrEmpty()) {
|
||||||
|
v.checkAll(items)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pendingData = ids
|
||||||
|
if (isInSelectionMode()) {
|
||||||
|
startActionMode()
|
||||||
|
notifySelectionChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getDecoration(section: T): AbstractSelectionItemDecoration {
|
||||||
|
return decorations.getOrPut(section) {
|
||||||
|
callback.onCreateItemDecoration(section)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Callback<T> : ListSelectionController.Callback {
|
||||||
|
|
||||||
|
fun onCreateItemDecoration(section: T): AbstractSelectionItemDecoration
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class StateEventObserver : LifecycleEventObserver {
|
||||||
|
|
||||||
|
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
|
||||||
|
if (event == Lifecycle.Event.ON_CREATE) {
|
||||||
|
val registry = registryOwner.savedStateRegistry
|
||||||
|
registry.registerSavedStateProvider(PROVIDER_NAME, this@SectionedSelectionController)
|
||||||
|
val state = registry.consumeRestoredStateForKey(PROVIDER_NAME)
|
||||||
|
if (state != null) {
|
||||||
|
Dispatchers.Main.dispatch(EmptyCoroutineContext) { // == Handler.post
|
||||||
|
if (source.lifecycle.currentState.isAtLeast(Lifecycle.State.CREATED)) {
|
||||||
|
restoreState(
|
||||||
|
state.keySet().associateWithTo(HashMap()) { state.getLongArray(it)?.toList().orEmpty() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,82 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.list.fastscroll
|
||||||
|
|
||||||
|
import android.animation.Animator
|
||||||
|
import android.animation.AnimatorListenerAdapter
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewAnimationUtils
|
||||||
|
import android.view.animation.AccelerateInterpolator
|
||||||
|
import android.view.animation.DecelerateInterpolator
|
||||||
|
import androidx.core.view.isInvisible
|
||||||
|
import androidx.core.view.isVisible
|
||||||
|
import org.koitharu.kotatsu.utils.ext.animatorDurationScale
|
||||||
|
import org.koitharu.kotatsu.utils.ext.measureWidth
|
||||||
|
import kotlin.math.hypot
|
||||||
|
|
||||||
|
class BubbleAnimator(
|
||||||
|
private val bubble: View,
|
||||||
|
) {
|
||||||
|
|
||||||
|
private val animationDuration = (bubble.resources.getInteger(android.R.integer.config_shortAnimTime) *
|
||||||
|
bubble.context.animatorDurationScale).toLong()
|
||||||
|
private var animator: Animator? = null
|
||||||
|
private var isHiding = false
|
||||||
|
|
||||||
|
fun show() {
|
||||||
|
if (bubble.isVisible && !isHiding) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
isHiding = false
|
||||||
|
animator?.cancel()
|
||||||
|
animator = ViewAnimationUtils.createCircularReveal(
|
||||||
|
bubble,
|
||||||
|
bubble.measureWidth(),
|
||||||
|
bubble.measuredHeight,
|
||||||
|
0f,
|
||||||
|
hypot(bubble.width.toDouble(), bubble.height.toDouble()).toFloat(),
|
||||||
|
).apply {
|
||||||
|
bubble.isVisible = true
|
||||||
|
duration = animationDuration
|
||||||
|
interpolator = DecelerateInterpolator()
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hide() {
|
||||||
|
if (!bubble.isVisible || isHiding) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
animator?.cancel()
|
||||||
|
isHiding = true
|
||||||
|
animator = ViewAnimationUtils.createCircularReveal(
|
||||||
|
bubble,
|
||||||
|
bubble.width,
|
||||||
|
bubble.height,
|
||||||
|
hypot(bubble.width.toDouble(), bubble.height.toDouble()).toFloat(),
|
||||||
|
0f,
|
||||||
|
).apply {
|
||||||
|
duration = animationDuration
|
||||||
|
interpolator = AccelerateInterpolator()
|
||||||
|
addListener(HideListener())
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class HideListener : AnimatorListenerAdapter() {
|
||||||
|
|
||||||
|
private var isCancelled = false
|
||||||
|
|
||||||
|
override fun onAnimationCancel(animation: Animator?) {
|
||||||
|
super.onAnimationCancel(animation)
|
||||||
|
isCancelled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAnimationEnd(animation: Animator?) {
|
||||||
|
super.onAnimationEnd(animation)
|
||||||
|
if (!isCancelled && animation === this@BubbleAnimator.animator) {
|
||||||
|
bubble.isInvisible = true
|
||||||
|
isHiding = false
|
||||||
|
this@BubbleAnimator.animator = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.list.fastscroll
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.annotation.AttrRes
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
|
||||||
|
class FastScrollRecyclerView @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
@AttrRes defStyleAttr: Int = androidx.recyclerview.R.attr.recyclerViewStyle,
|
||||||
|
) : RecyclerView(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
|
val fastScroller = FastScroller(context, attrs)
|
||||||
|
|
||||||
|
init {
|
||||||
|
fastScroller.id = R.id.fast_scroller
|
||||||
|
fastScroller.layoutParams = ViewGroup.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setAdapter(adapter: Adapter<*>?) {
|
||||||
|
super.setAdapter(adapter)
|
||||||
|
fastScroller.setSectionIndexer(adapter as? FastScroller.SectionIndexer)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setVisibility(visibility: Int) {
|
||||||
|
super.setVisibility(visibility)
|
||||||
|
fastScroller.visibility = visibility
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAttachedToWindow() {
|
||||||
|
super.onAttachedToWindow()
|
||||||
|
fastScroller.attachRecyclerView(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDetachedFromWindow() {
|
||||||
|
fastScroller.detachRecyclerView()
|
||||||
|
super.onDetachedFromWindow()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,521 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.list.fastscroll
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.res.TypedArray
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.util.TypedValue
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.*
|
||||||
|
import androidx.annotation.*
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
import androidx.constraintlayout.widget.ConstraintSet
|
||||||
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.content.withStyledAttributes
|
||||||
|
import androidx.core.view.GravityCompat
|
||||||
|
import androidx.core.view.isGone
|
||||||
|
import androidx.core.view.isVisible
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.databinding.FastScrollerBinding
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
|
import org.koitharu.kotatsu.utils.ext.isLayoutReversed
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
|
private const val SCROLLBAR_HIDE_DELAY = 1000L
|
||||||
|
private const val TRACK_SNAP_RANGE = 5
|
||||||
|
|
||||||
|
@Suppress("MemberVisibilityCanBePrivate", "unused")
|
||||||
|
class FastScroller @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
@AttrRes defStyleAttr: Int = R.attr.fastScrollerStyle,
|
||||||
|
) : LinearLayout(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
|
enum class BubbleSize(@DrawableRes val drawableId: Int, @DimenRes val textSizeId: Int) {
|
||||||
|
NORMAL(R.drawable.fastscroll_bubble, R.dimen.fastscroll_bubble_text_size),
|
||||||
|
SMALL(R.drawable.fastscroll_bubble_small, R.dimen.fastscroll_bubble_text_size_small)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val binding = FastScrollerBinding.inflate(LayoutInflater.from(context), this)
|
||||||
|
|
||||||
|
private val scrollbarPaddingEnd = context.resources.getDimension(R.dimen.fastscroll_scrollbar_padding_end)
|
||||||
|
|
||||||
|
@ColorInt
|
||||||
|
private var bubbleColor = 0
|
||||||
|
|
||||||
|
@ColorInt
|
||||||
|
private var handleColor = 0
|
||||||
|
|
||||||
|
private var bubbleHeight = 0
|
||||||
|
private var handleHeight = 0
|
||||||
|
private var viewHeight = 0
|
||||||
|
private var hideScrollbar = true
|
||||||
|
private var showBubble = true
|
||||||
|
private var showBubbleAlways = false
|
||||||
|
private var bubbleSize = BubbleSize.NORMAL
|
||||||
|
private var bubbleImage: Drawable? = null
|
||||||
|
private var handleImage: Drawable? = null
|
||||||
|
private var trackImage: Drawable? = null
|
||||||
|
private var recyclerView: RecyclerView? = null
|
||||||
|
private val scrollbarAnimator = ScrollbarAnimator(binding.scrollbar, scrollbarPaddingEnd)
|
||||||
|
private val bubbleAnimator = BubbleAnimator(binding.bubble)
|
||||||
|
|
||||||
|
private var fastScrollListener: FastScrollListener? = null
|
||||||
|
private var sectionIndexer: SectionIndexer? = null
|
||||||
|
|
||||||
|
private val scrollbarHider = Runnable {
|
||||||
|
hideBubble()
|
||||||
|
hideScrollbar()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val scrollListener: RecyclerView.OnScrollListener = object : RecyclerView.OnScrollListener() {
|
||||||
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||||
|
if (!binding.thumb.isSelected && isEnabled) {
|
||||||
|
val y = recyclerView.scrollProportion
|
||||||
|
setViewPositions(y)
|
||||||
|
|
||||||
|
if (showBubbleAlways) {
|
||||||
|
val targetPos = getRecyclerViewTargetPosition(y)
|
||||||
|
sectionIndexer?.let { binding.bubble.text = it.getSectionText(recyclerView.context, targetPos) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
||||||
|
super.onScrollStateChanged(recyclerView, newState)
|
||||||
|
|
||||||
|
if (isEnabled) {
|
||||||
|
when (newState) {
|
||||||
|
RecyclerView.SCROLL_STATE_DRAGGING -> {
|
||||||
|
handler.removeCallbacks(scrollbarHider)
|
||||||
|
showScrollbar()
|
||||||
|
if (showBubbleAlways && sectionIndexer != null) showBubble()
|
||||||
|
}
|
||||||
|
RecyclerView.SCROLL_STATE_IDLE -> if (hideScrollbar && !binding.thumb.isSelected) {
|
||||||
|
handler.postDelayed(scrollbarHider, SCROLLBAR_HIDE_DELAY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val RecyclerView.scrollProportion: Float
|
||||||
|
get() {
|
||||||
|
val rangeDiff = computeVerticalScrollRange() - computeVerticalScrollExtent()
|
||||||
|
val proportion = computeVerticalScrollOffset() / if (rangeDiff > 0) rangeDiff.toFloat() else 1f
|
||||||
|
return viewHeight * proportion
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
clipChildren = false
|
||||||
|
orientation = HORIZONTAL
|
||||||
|
|
||||||
|
@ColorInt var bubbleColor = context.getThemeColor(materialR.attr.colorControlNormal, Color.DKGRAY)
|
||||||
|
@ColorInt var handleColor = bubbleColor
|
||||||
|
@ColorInt var trackColor = context.getThemeColor(materialR.attr.colorOutline, Color.LTGRAY)
|
||||||
|
@ColorInt var textColor = context.getThemeColor(android.R.attr.textColorPrimaryInverse, Color.WHITE)
|
||||||
|
|
||||||
|
var showTrack = false
|
||||||
|
|
||||||
|
context.withStyledAttributes(attrs, R.styleable.FastScroller, defStyleAttr) {
|
||||||
|
bubbleColor = getColor(R.styleable.FastScroller_bubbleColor, bubbleColor)
|
||||||
|
handleColor = getColor(R.styleable.FastScroller_thumbColor, handleColor)
|
||||||
|
trackColor = getColor(R.styleable.FastScroller_trackColor, trackColor)
|
||||||
|
textColor = getColor(R.styleable.FastScroller_bubbleTextColor, textColor)
|
||||||
|
hideScrollbar = getBoolean(R.styleable.FastScroller_hideScrollbar, hideScrollbar)
|
||||||
|
showBubble = getBoolean(R.styleable.FastScroller_showBubble, showBubble)
|
||||||
|
showBubbleAlways = getBoolean(R.styleable.FastScroller_showBubbleAlways, showBubbleAlways)
|
||||||
|
showTrack = getBoolean(R.styleable.FastScroller_showTrack, showTrack)
|
||||||
|
bubbleSize = getBubbleSize(R.styleable.FastScroller_bubbleSize, BubbleSize.NORMAL)
|
||||||
|
val textSize = getDimension(R.styleable.FastScroller_bubbleTextSize, bubbleSize.textSize)
|
||||||
|
binding.bubble.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
setTrackColor(trackColor)
|
||||||
|
setHandleColor(handleColor)
|
||||||
|
setBubbleColor(bubbleColor)
|
||||||
|
setBubbleTextColor(textColor)
|
||||||
|
setHideScrollbar(hideScrollbar)
|
||||||
|
setBubbleVisible(showBubble, showBubbleAlways)
|
||||||
|
setTrackVisible(showTrack)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSizeChanged(w: Int, h: Int, oldW: Int, oldH: Int) {
|
||||||
|
super.onSizeChanged(w, h, oldW, oldH)
|
||||||
|
viewHeight = h
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
|
val setYPositions: () -> Unit = {
|
||||||
|
val y = event.y
|
||||||
|
setViewPositions(y)
|
||||||
|
setRecyclerViewPosition(y)
|
||||||
|
}
|
||||||
|
|
||||||
|
when (event.actionMasked) {
|
||||||
|
MotionEvent.ACTION_DOWN -> {
|
||||||
|
if (event.x.toInt() !in binding.scrollbar.left..binding.scrollbar.right) return false
|
||||||
|
|
||||||
|
requestDisallowInterceptTouchEvent(true)
|
||||||
|
setHandleSelected(true)
|
||||||
|
|
||||||
|
handler.removeCallbacks(scrollbarHider)
|
||||||
|
showScrollbar()
|
||||||
|
if (showBubble && sectionIndexer != null) showBubble()
|
||||||
|
|
||||||
|
fastScrollListener?.onFastScrollStart(this)
|
||||||
|
|
||||||
|
setYPositions()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_MOVE -> {
|
||||||
|
setYPositions()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||||
|
requestDisallowInterceptTouchEvent(false)
|
||||||
|
setHandleSelected(false)
|
||||||
|
|
||||||
|
if (hideScrollbar) handler.postDelayed(scrollbarHider, SCROLLBAR_HIDE_DELAY)
|
||||||
|
if (!showBubbleAlways) hideBubble()
|
||||||
|
|
||||||
|
fastScrollListener?.onFastScrollStop(this)
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onTouchEvent(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the enabled state of this view.
|
||||||
|
*
|
||||||
|
* @param enabled True if this view is enabled, false otherwise
|
||||||
|
*/
|
||||||
|
override fun setEnabled(enabled: Boolean) {
|
||||||
|
super.setEnabled(enabled)
|
||||||
|
isVisible = enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the [ViewGroup.LayoutParams] associated with this view. These supply
|
||||||
|
* parameters to the *parent* of this view specifying how it should be arranged.
|
||||||
|
*
|
||||||
|
* @param params The [ViewGroup.LayoutParams] for this view, cannot be null
|
||||||
|
*/
|
||||||
|
override fun setLayoutParams(params: ViewGroup.LayoutParams) {
|
||||||
|
params.width = LayoutParams.WRAP_CONTENT
|
||||||
|
super.setLayoutParams(params)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the [ViewGroup.LayoutParams] associated with this view. These supply
|
||||||
|
* parameters to the *parent* of this view specifying how it should be arranged.
|
||||||
|
*
|
||||||
|
* @param viewGroup The parent [ViewGroup] for this view, cannot be null
|
||||||
|
*/
|
||||||
|
fun setLayoutParams(viewGroup: ViewGroup) {
|
||||||
|
val recyclerViewId = recyclerView?.id ?: NO_ID
|
||||||
|
val marginTop = resources.getDimensionPixelSize(R.dimen.fastscroll_scrollbar_margin_top)
|
||||||
|
val marginBottom = resources.getDimensionPixelSize(R.dimen.fastscroll_scrollbar_margin_bottom)
|
||||||
|
|
||||||
|
require(recyclerViewId != NO_ID) { "RecyclerView must have a view ID" }
|
||||||
|
|
||||||
|
when (viewGroup) {
|
||||||
|
is ConstraintLayout -> {
|
||||||
|
val endId = if (recyclerView?.parent === parent) recyclerViewId else ConstraintSet.PARENT_ID
|
||||||
|
val startId = id
|
||||||
|
|
||||||
|
ConstraintSet().apply {
|
||||||
|
clone(viewGroup)
|
||||||
|
connect(startId, ConstraintSet.TOP, endId, ConstraintSet.TOP)
|
||||||
|
connect(startId, ConstraintSet.BOTTOM, endId, ConstraintSet.BOTTOM)
|
||||||
|
connect(startId, ConstraintSet.END, endId, ConstraintSet.END)
|
||||||
|
applyTo(viewGroup)
|
||||||
|
}
|
||||||
|
|
||||||
|
layoutParams = (layoutParams as ConstraintLayout.LayoutParams).apply {
|
||||||
|
height = 0
|
||||||
|
setMargins(0, marginTop, 0, marginBottom)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is CoordinatorLayout -> layoutParams = (layoutParams as CoordinatorLayout.LayoutParams).apply {
|
||||||
|
height = LayoutParams.MATCH_PARENT
|
||||||
|
anchorGravity = GravityCompat.END
|
||||||
|
anchorId = recyclerViewId
|
||||||
|
setMargins(0, marginTop, 0, marginBottom)
|
||||||
|
}
|
||||||
|
is FrameLayout -> layoutParams = (layoutParams as FrameLayout.LayoutParams).apply {
|
||||||
|
height = LayoutParams.MATCH_PARENT
|
||||||
|
gravity = GravityCompat.END
|
||||||
|
setMargins(0, marginTop, 0, marginBottom)
|
||||||
|
}
|
||||||
|
is RelativeLayout -> layoutParams = (layoutParams as RelativeLayout.LayoutParams).apply {
|
||||||
|
height = 0
|
||||||
|
addRule(RelativeLayout.ALIGN_TOP, recyclerViewId)
|
||||||
|
addRule(RelativeLayout.ALIGN_BOTTOM, recyclerViewId)
|
||||||
|
addRule(RelativeLayout.ALIGN_END, recyclerViewId)
|
||||||
|
setMargins(0, marginTop, 0, marginBottom)
|
||||||
|
}
|
||||||
|
else -> throw IllegalArgumentException("Parent ViewGroup must be a ConstraintLayout, CoordinatorLayout, FrameLayout, or RelativeLayout")
|
||||||
|
}
|
||||||
|
|
||||||
|
updateViewHeights()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the [RecyclerView] associated with this [FastScroller]. This allows the
|
||||||
|
* FastScroller to set its layout parameters and listen for scroll changes.
|
||||||
|
*
|
||||||
|
* @param recyclerView The [RecyclerView] to attach, cannot be null
|
||||||
|
* @see detachRecyclerView
|
||||||
|
*/
|
||||||
|
fun attachRecyclerView(recyclerView: RecyclerView) {
|
||||||
|
if (this.recyclerView != null) {
|
||||||
|
detachRecyclerView()
|
||||||
|
}
|
||||||
|
this.recyclerView = recyclerView
|
||||||
|
|
||||||
|
if (parent is ViewGroup) {
|
||||||
|
setLayoutParams(parent as ViewGroup)
|
||||||
|
} else if (recyclerView.parent is ViewGroup) {
|
||||||
|
val viewGroup = recyclerView.parent as ViewGroup
|
||||||
|
viewGroup.addView(this)
|
||||||
|
setLayoutParams(viewGroup)
|
||||||
|
}
|
||||||
|
|
||||||
|
recyclerView.addOnScrollListener(scrollListener)
|
||||||
|
|
||||||
|
// set initial positions for bubble and thumb
|
||||||
|
post { setViewPositions(this.recyclerView?.scrollProportion ?: 0f) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears references to the attached [RecyclerView] and stops listening for scroll changes.
|
||||||
|
*
|
||||||
|
* @see attachRecyclerView
|
||||||
|
*/
|
||||||
|
fun detachRecyclerView() {
|
||||||
|
recyclerView?.removeOnScrollListener(scrollListener)
|
||||||
|
recyclerView = null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a new [FastScrollListener] that will listen to fast scroll events.
|
||||||
|
*
|
||||||
|
* @param fastScrollListener The new [FastScrollListener] to set, or null to set none
|
||||||
|
*/
|
||||||
|
fun setFastScrollListener(fastScrollListener: FastScrollListener?) {
|
||||||
|
this.fastScrollListener = fastScrollListener
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a new [SectionIndexer] that provides section text for this [FastScroller].
|
||||||
|
*
|
||||||
|
* @param sectionIndexer The new [SectionIndexer] to set, or null to set none
|
||||||
|
*/
|
||||||
|
fun setSectionIndexer(sectionIndexer: SectionIndexer?) {
|
||||||
|
this.sectionIndexer = sectionIndexer
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide the scrollbar when not scrolling.
|
||||||
|
*
|
||||||
|
* @param hideScrollbar True to hide the scrollbar, false to show
|
||||||
|
*/
|
||||||
|
fun setHideScrollbar(hideScrollbar: Boolean) {
|
||||||
|
if (this.hideScrollbar != hideScrollbar) {
|
||||||
|
this.hideScrollbar = hideScrollbar
|
||||||
|
binding.scrollbar.isGone = hideScrollbar
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the scroll track while scrolling.
|
||||||
|
*
|
||||||
|
* @param visible True to show scroll track, false to hide
|
||||||
|
*/
|
||||||
|
fun setTrackVisible(visible: Boolean) {
|
||||||
|
binding.track.isVisible = visible
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the color of the scroll track.
|
||||||
|
*
|
||||||
|
* @param color The color for the scroll track
|
||||||
|
*/
|
||||||
|
fun setTrackColor(@ColorInt color: Int) {
|
||||||
|
if (trackImage == null) {
|
||||||
|
trackImage = ContextCompat.getDrawable(context, R.drawable.fastscroll_track)
|
||||||
|
}
|
||||||
|
|
||||||
|
trackImage?.let {
|
||||||
|
it.setTint(color)
|
||||||
|
binding.track.setImageDrawable(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the color of the scroll thumb.
|
||||||
|
*
|
||||||
|
* @param color The color for the scroll thumb
|
||||||
|
*/
|
||||||
|
fun setHandleColor(@ColorInt color: Int) {
|
||||||
|
handleColor = color
|
||||||
|
|
||||||
|
if (handleImage == null) {
|
||||||
|
handleImage = ContextCompat.getDrawable(context, R.drawable.fastscroll_handle)
|
||||||
|
}
|
||||||
|
|
||||||
|
handleImage?.let {
|
||||||
|
it.setTint(handleColor)
|
||||||
|
binding.thumb.setImageDrawable(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the section bubble while scrolling.
|
||||||
|
*
|
||||||
|
* @param visible True to show the bubble, false to hide
|
||||||
|
* @param always True to always show the bubble, false to only show on thumb touch
|
||||||
|
*/
|
||||||
|
@JvmOverloads
|
||||||
|
fun setBubbleVisible(visible: Boolean, always: Boolean = false) {
|
||||||
|
showBubble = visible
|
||||||
|
showBubbleAlways = visible && always
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the background color of the section bubble.
|
||||||
|
*
|
||||||
|
* @param color The background color for the section bubble
|
||||||
|
*/
|
||||||
|
fun setBubbleColor(@ColorInt color: Int) {
|
||||||
|
bubbleColor = color
|
||||||
|
|
||||||
|
if (bubbleImage == null) {
|
||||||
|
bubbleImage = ContextCompat.getDrawable(context, bubbleSize.drawableId)
|
||||||
|
}
|
||||||
|
|
||||||
|
bubbleImage?.let {
|
||||||
|
it.setTint(bubbleColor)
|
||||||
|
binding.bubble.background = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the text color of the section bubble.
|
||||||
|
*
|
||||||
|
* @param color The text color for the section bubble
|
||||||
|
*/
|
||||||
|
fun setBubbleTextColor(@ColorInt color: Int) = binding.bubble.setTextColor(color)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the scaled pixel text size of the section bubble.
|
||||||
|
*
|
||||||
|
* @param size The scaled pixel text size for the section bubble
|
||||||
|
*/
|
||||||
|
fun setBubbleTextSize(size: Int) {
|
||||||
|
binding.bubble.textSize = size.toFloat()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getRecyclerViewTargetPosition(y: Float) = recyclerView?.let { recyclerView ->
|
||||||
|
val itemCount = recyclerView.adapter?.itemCount ?: 0
|
||||||
|
|
||||||
|
val proportion = when {
|
||||||
|
binding.thumb.y == 0f -> 0f
|
||||||
|
binding.thumb.y + handleHeight >= viewHeight - TRACK_SNAP_RANGE -> 1f
|
||||||
|
else -> y / viewHeight.toFloat()
|
||||||
|
}
|
||||||
|
|
||||||
|
var scrolledItemCount = (proportion * itemCount).roundToInt()
|
||||||
|
|
||||||
|
if (recyclerView.layoutManager.isLayoutReversed) {
|
||||||
|
scrolledItemCount = itemCount - scrolledItemCount
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemCount > 0) scrolledItemCount.coerceIn(0, itemCount - 1) else 0
|
||||||
|
} ?: 0
|
||||||
|
|
||||||
|
private fun setRecyclerViewPosition(y: Float) {
|
||||||
|
val layoutManager = recyclerView?.layoutManager ?: return
|
||||||
|
val targetPos = getRecyclerViewTargetPosition(y)
|
||||||
|
layoutManager.scrollToPosition(targetPos)
|
||||||
|
if (showBubble) sectionIndexer?.let { binding.bubble.text = it.getSectionText(context, targetPos) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setViewPositions(y: Float) {
|
||||||
|
bubbleHeight = binding.bubble.measuredHeight
|
||||||
|
handleHeight = binding.thumb.measuredHeight
|
||||||
|
|
||||||
|
val bubbleHandleHeight = bubbleHeight + handleHeight / 2f
|
||||||
|
|
||||||
|
if (showBubble && viewHeight >= bubbleHandleHeight) {
|
||||||
|
binding.bubble.y = (y - bubbleHeight).coerceIn(0f, viewHeight - bubbleHandleHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (viewHeight >= handleHeight) {
|
||||||
|
binding.thumb.y = (y - handleHeight / 2).coerceIn(0f, viewHeight - handleHeight.toFloat())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateViewHeights() {
|
||||||
|
val measureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED)
|
||||||
|
binding.bubble.measure(measureSpec, measureSpec)
|
||||||
|
bubbleHeight = binding.bubble.measuredHeight
|
||||||
|
binding.thumb.measure(measureSpec, measureSpec)
|
||||||
|
handleHeight = binding.thumb.measuredHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showBubble() {
|
||||||
|
bubbleAnimator.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hideBubble() {
|
||||||
|
bubbleAnimator.hide()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showScrollbar() {
|
||||||
|
if (recyclerView?.run { canScrollVertically(1) || canScrollVertically(-1) } == true) {
|
||||||
|
scrollbarAnimator.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hideScrollbar() {
|
||||||
|
scrollbarAnimator.hide()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setHandleSelected(selected: Boolean) {
|
||||||
|
binding.thumb.isSelected = selected
|
||||||
|
handleImage?.setTint(if (selected) bubbleColor else handleColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun TypedArray.getBubbleSize(@StyleableRes index: Int, defaultValue: BubbleSize): BubbleSize {
|
||||||
|
val ordinal = getInt(index, -1)
|
||||||
|
return BubbleSize.values().getOrNull(ordinal) ?: defaultValue
|
||||||
|
}
|
||||||
|
|
||||||
|
private val BubbleSize.textSize
|
||||||
|
@Px get() = resources.getDimension(textSizeId)
|
||||||
|
|
||||||
|
interface FastScrollListener {
|
||||||
|
|
||||||
|
fun onFastScrollStart(fastScroller: FastScroller)
|
||||||
|
|
||||||
|
fun onFastScrollStop(fastScroller: FastScroller)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SectionIndexer {
|
||||||
|
|
||||||
|
fun getSectionText(context: Context, position: Int): CharSequence
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.list.fastscroll
|
||||||
|
|
||||||
|
import android.animation.Animator
|
||||||
|
import android.animation.AnimatorListenerAdapter
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewPropertyAnimator
|
||||||
|
import androidx.core.view.isInvisible
|
||||||
|
import androidx.core.view.isVisible
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.utils.ext.animatorDurationScale
|
||||||
|
|
||||||
|
class ScrollbarAnimator(
|
||||||
|
private val scrollbar: View,
|
||||||
|
private val scrollbarPaddingEnd: Float,
|
||||||
|
) {
|
||||||
|
|
||||||
|
private val animationDuration = (scrollbar.resources.getInteger(R.integer.config_defaultAnimTime) *
|
||||||
|
scrollbar.context.animatorDurationScale).toLong()
|
||||||
|
private var animator: ViewPropertyAnimator? = null
|
||||||
|
private var isHiding = false
|
||||||
|
|
||||||
|
fun show() {
|
||||||
|
if (scrollbar.isVisible && !isHiding) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
isHiding = false
|
||||||
|
animator?.cancel()
|
||||||
|
scrollbar.translationX = scrollbarPaddingEnd
|
||||||
|
scrollbar.isVisible = true
|
||||||
|
animator = scrollbar
|
||||||
|
.animate()
|
||||||
|
.translationX(0f)
|
||||||
|
.alpha(1f)
|
||||||
|
.setDuration(animationDuration)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hide() {
|
||||||
|
if (!scrollbar.isVisible || isHiding) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
animator?.cancel()
|
||||||
|
isHiding = true
|
||||||
|
animator = scrollbar
|
||||||
|
.animate()
|
||||||
|
.translationX(scrollbarPaddingEnd)
|
||||||
|
.alpha(0f)
|
||||||
|
.setDuration(animationDuration)
|
||||||
|
.setListener(HideListener())
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class HideListener : AnimatorListenerAdapter() {
|
||||||
|
|
||||||
|
private var isCancelled = false
|
||||||
|
|
||||||
|
override fun onAnimationCancel(animation: Animator?) {
|
||||||
|
super.onAnimationCancel(animation)
|
||||||
|
isCancelled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAnimationEnd(animation: Animator?) {
|
||||||
|
super.onAnimationEnd(animation)
|
||||||
|
if (!isCancelled && animation === this@ScrollbarAnimator.animator) {
|
||||||
|
scrollbar.isInvisible = true
|
||||||
|
isHiding = false
|
||||||
|
this@ScrollbarAnimator.animator = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.app.Application.ActivityLifecycleCallbacks
|
||||||
|
import android.os.Bundle
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class ActivityRecreationHandle : ActivityLifecycleCallbacks {
|
||||||
|
|
||||||
|
private val activities = WeakHashMap<Activity, Unit>()
|
||||||
|
|
||||||
|
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
||||||
|
activities[activity] = Unit
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActivityStarted(activity: Activity) = Unit
|
||||||
|
|
||||||
|
override fun onActivityResumed(activity: Activity) = Unit
|
||||||
|
|
||||||
|
override fun onActivityPaused(activity: Activity) = Unit
|
||||||
|
|
||||||
|
override fun onActivityStopped(activity: Activity) = Unit
|
||||||
|
|
||||||
|
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) = Unit
|
||||||
|
|
||||||
|
override fun onActivityDestroyed(activity: Activity) {
|
||||||
|
activities.remove(activity)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun recreateAll() {
|
||||||
|
val snapshot = activities.keys.toList()
|
||||||
|
snapshot.forEach { it.recreate() }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import org.koitharu.kotatsu.base.domain.ReversibleHandle
|
||||||
|
|
||||||
|
class ReversibleAction(
|
||||||
|
@StringRes val stringResId: Int,
|
||||||
|
val handle: ReversibleHandle?,
|
||||||
|
)
|
||||||
@ -0,0 +1,104 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
|
import android.animation.ValueAnimator
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.view.animation.DecelerateInterpolator
|
||||||
|
import androidx.appcompat.widget.Toolbar
|
||||||
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
|
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
|
import org.koitharu.kotatsu.utils.ext.animatorDurationScale
|
||||||
|
import org.koitharu.kotatsu.utils.ext.findChild
|
||||||
|
import org.koitharu.kotatsu.utils.ext.measureHeight
|
||||||
|
import kotlin.math.roundToLong
|
||||||
|
|
||||||
|
class HideBottomNavigationOnScrollBehavior @JvmOverloads constructor(
|
||||||
|
context: Context? = null,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
) : CoordinatorLayout.Behavior<BottomNavigationView>(context, attrs) {
|
||||||
|
|
||||||
|
@ViewCompat.NestedScrollType
|
||||||
|
private var lastStartedType: Int = 0
|
||||||
|
|
||||||
|
private var offsetAnimator: ValueAnimator? = null
|
||||||
|
|
||||||
|
private var dyRatio = 1F
|
||||||
|
|
||||||
|
override fun layoutDependsOn(parent: CoordinatorLayout, child: BottomNavigationView, dependency: View): Boolean {
|
||||||
|
return dependency is AppBarLayout
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDependentViewChanged(
|
||||||
|
parent: CoordinatorLayout,
|
||||||
|
child: BottomNavigationView,
|
||||||
|
dependency: View,
|
||||||
|
): Boolean {
|
||||||
|
val appBarSize = dependency.measureHeight()
|
||||||
|
dyRatio = if (appBarSize > 0) {
|
||||||
|
child.measureHeight().toFloat() / appBarSize
|
||||||
|
} else {
|
||||||
|
1F
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStartNestedScroll(
|
||||||
|
coordinatorLayout: CoordinatorLayout,
|
||||||
|
child: BottomNavigationView,
|
||||||
|
directTargetChild: View,
|
||||||
|
target: View,
|
||||||
|
axes: Int,
|
||||||
|
type: Int,
|
||||||
|
): Boolean {
|
||||||
|
if (axes != ViewCompat.SCROLL_AXIS_VERTICAL) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
lastStartedType = type
|
||||||
|
offsetAnimator?.cancel()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNestedPreScroll(
|
||||||
|
coordinatorLayout: CoordinatorLayout,
|
||||||
|
child: BottomNavigationView,
|
||||||
|
target: View,
|
||||||
|
dx: Int,
|
||||||
|
dy: Int,
|
||||||
|
consumed: IntArray,
|
||||||
|
type: Int,
|
||||||
|
) {
|
||||||
|
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type)
|
||||||
|
child.translationY = (child.translationY + (dy * dyRatio)).coerceIn(0F, child.height.toFloat())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStopNestedScroll(
|
||||||
|
coordinatorLayout: CoordinatorLayout,
|
||||||
|
child: BottomNavigationView,
|
||||||
|
target: View,
|
||||||
|
type: Int,
|
||||||
|
) {
|
||||||
|
if (lastStartedType == ViewCompat.TYPE_TOUCH || type == ViewCompat.TYPE_NON_TOUCH) {
|
||||||
|
animateBottomNavigationVisibility(child, child.translationY < child.height / 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun animateBottomNavigationVisibility(child: BottomNavigationView, isVisible: Boolean) {
|
||||||
|
offsetAnimator?.cancel()
|
||||||
|
offsetAnimator = ValueAnimator().apply {
|
||||||
|
interpolator = DecelerateInterpolator()
|
||||||
|
duration = (150 * child.context.animatorDurationScale).roundToLong()
|
||||||
|
addUpdateListener {
|
||||||
|
child.translationY = it.animatedValue as Float
|
||||||
|
}
|
||||||
|
}
|
||||||
|
offsetAnimator?.setFloatValues(
|
||||||
|
child.translationY,
|
||||||
|
if (isVisible) 0F else child.height.toFloat(),
|
||||||
|
)
|
||||||
|
offsetAnimator?.start()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,156 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
|
import android.animation.Animator
|
||||||
|
import android.animation.AnimatorListenerAdapter
|
||||||
|
import android.animation.TimeInterpolator
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.ViewPropertyAnimator
|
||||||
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
import androidx.core.view.doOnLayout
|
||||||
|
import androidx.core.view.updateLayoutParams
|
||||||
|
import androidx.customview.view.AbsSavedState
|
||||||
|
import androidx.interpolator.view.animation.FastOutLinearInInterpolator
|
||||||
|
import androidx.interpolator.view.animation.LinearOutSlowInInterpolator
|
||||||
|
import androidx.lifecycle.findViewTreeLifecycleOwner
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
|
import org.koitharu.kotatsu.utils.ext.applySystemAnimatorScale
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
|
class KotatsuBottomNavigationView @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
defStyleAttr: Int = materialR.attr.bottomNavigationStyle,
|
||||||
|
defStyleRes: Int = materialR.style.Widget_Design_BottomNavigationView,
|
||||||
|
) : BottomNavigationView(context, attrs, defStyleAttr, defStyleRes) {
|
||||||
|
|
||||||
|
private var currentAnimator: ViewPropertyAnimator? = null
|
||||||
|
|
||||||
|
private var currentState = STATE_UP
|
||||||
|
|
||||||
|
init {
|
||||||
|
// Hide on scroll
|
||||||
|
doOnLayout {
|
||||||
|
findViewTreeLifecycleOwner()?.lifecycleScope?.let {
|
||||||
|
updateLayoutParams<CoordinatorLayout.LayoutParams> {
|
||||||
|
behavior = HideBottomNavigationOnScrollBehavior()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSaveInstanceState(): Parcelable {
|
||||||
|
val superState = super.onSaveInstanceState()
|
||||||
|
return SavedState(superState).also {
|
||||||
|
it.currentState = currentState
|
||||||
|
it.translationY = translationY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onRestoreInstanceState(state: Parcelable?) {
|
||||||
|
if (state is SavedState) {
|
||||||
|
super.onRestoreInstanceState(state.superState)
|
||||||
|
super.setTranslationY(state.translationY)
|
||||||
|
currentState = state.currentState
|
||||||
|
} else {
|
||||||
|
super.onRestoreInstanceState(state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setTranslationY(translationY: Float) {
|
||||||
|
// Disallow translation change when state down
|
||||||
|
if (currentState == STATE_DOWN) return
|
||||||
|
super.setTranslationY(translationY)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows this view up.
|
||||||
|
*/
|
||||||
|
fun slideUp() = post {
|
||||||
|
currentAnimator?.cancel()
|
||||||
|
clearAnimation()
|
||||||
|
|
||||||
|
currentState = STATE_UP
|
||||||
|
animateTranslation(
|
||||||
|
0F,
|
||||||
|
SLIDE_UP_ANIMATION_DURATION,
|
||||||
|
LinearOutSlowInInterpolator(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hides this view down. [setTranslationY] won't work until [slideUp] is called.
|
||||||
|
*/
|
||||||
|
fun slideDown() = post {
|
||||||
|
currentAnimator?.cancel()
|
||||||
|
clearAnimation()
|
||||||
|
|
||||||
|
currentState = STATE_DOWN
|
||||||
|
animateTranslation(
|
||||||
|
height.toFloat(),
|
||||||
|
SLIDE_DOWN_ANIMATION_DURATION,
|
||||||
|
FastOutLinearInInterpolator(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun animateTranslation(targetY: Float, duration: Long, interpolator: TimeInterpolator) {
|
||||||
|
currentAnimator = animate()
|
||||||
|
.translationY(targetY)
|
||||||
|
.setInterpolator(interpolator)
|
||||||
|
.setDuration(duration)
|
||||||
|
.applySystemAnimatorScale(context)
|
||||||
|
.setListener(object : AnimatorListenerAdapter() {
|
||||||
|
override fun onAnimationEnd(animation: Animator?) {
|
||||||
|
currentAnimator = null
|
||||||
|
postInvalidate()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class SavedState : AbsSavedState {
|
||||||
|
var currentState = STATE_UP
|
||||||
|
var translationY = 0F
|
||||||
|
|
||||||
|
constructor(superState: Parcelable) : super(superState)
|
||||||
|
|
||||||
|
constructor(source: Parcel, loader: ClassLoader?) : super(source, loader) {
|
||||||
|
currentState = source.readInt()
|
||||||
|
translationY = source.readFloat()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun writeToParcel(out: Parcel, flags: Int) {
|
||||||
|
super.writeToParcel(out, flags)
|
||||||
|
out.writeInt(currentState)
|
||||||
|
out.writeFloat(translationY)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmField
|
||||||
|
val CREATOR: Parcelable.ClassLoaderCreator<SavedState> = object : Parcelable.ClassLoaderCreator<SavedState> {
|
||||||
|
override fun createFromParcel(source: Parcel, loader: ClassLoader): SavedState {
|
||||||
|
return SavedState(source, loader)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createFromParcel(source: Parcel): SavedState {
|
||||||
|
return SavedState(source, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun newArray(size: Int): Array<SavedState> {
|
||||||
|
return newArray(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val STATE_DOWN = 1
|
||||||
|
private const val STATE_UP = 2
|
||||||
|
|
||||||
|
private const val SLIDE_UP_ANIMATION_DURATION = 225L
|
||||||
|
private const val SLIDE_DOWN_ANIMATION_DURATION = 175L
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,111 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.View
|
||||||
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
import androidx.core.view.doOnLayout
|
||||||
|
import androidx.customview.view.AbsSavedState
|
||||||
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
|
import org.koitharu.kotatsu.utils.ext.findChild
|
||||||
|
|
||||||
|
class KotatsuCoordinatorLayout @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
defStyleAttr: Int = androidx.coordinatorlayout.R.attr.coordinatorLayoutStyle
|
||||||
|
) : CoordinatorLayout(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
|
private var appBarLayout: AppBarLayout? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, [AppBarLayout] child will be lifted on nested scroll.
|
||||||
|
*/
|
||||||
|
var isLiftAppBarOnScroll = true
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal check
|
||||||
|
*/
|
||||||
|
private val canLiftAppBarOnScroll
|
||||||
|
get() = isLiftAppBarOnScroll
|
||||||
|
|
||||||
|
override fun onNestedScroll(
|
||||||
|
target: View,
|
||||||
|
dxConsumed: Int,
|
||||||
|
dyConsumed: Int,
|
||||||
|
dxUnconsumed: Int,
|
||||||
|
dyUnconsumed: Int,
|
||||||
|
type: Int,
|
||||||
|
consumed: IntArray
|
||||||
|
) {
|
||||||
|
super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type, consumed)
|
||||||
|
if (canLiftAppBarOnScroll) {
|
||||||
|
appBarLayout?.isLifted = dyConsumed != 0 || dyUnconsumed >= 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAttachedToWindow() {
|
||||||
|
super.onAttachedToWindow()
|
||||||
|
appBarLayout = findChild()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow()
|
||||||
|
appBarLayout = null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSaveInstanceState(): Parcelable? {
|
||||||
|
val superState = super.onSaveInstanceState()
|
||||||
|
return if (superState != null) {
|
||||||
|
SavedState(superState).also {
|
||||||
|
it.appBarLifted = appBarLayout?.isLifted ?: false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
superState
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onRestoreInstanceState(state: Parcelable?) {
|
||||||
|
if (state is SavedState) {
|
||||||
|
super.onRestoreInstanceState(state.superState)
|
||||||
|
doOnLayout {
|
||||||
|
appBarLayout?.isLifted = state.appBarLifted
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.onRestoreInstanceState(state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class SavedState : AbsSavedState {
|
||||||
|
var appBarLifted = false
|
||||||
|
|
||||||
|
constructor(superState: Parcelable) : super(superState)
|
||||||
|
|
||||||
|
constructor(source: Parcel, loader: ClassLoader?) : super(source, loader) {
|
||||||
|
appBarLifted = source.readByte().toInt() == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun writeToParcel(out: Parcel, flags: Int) {
|
||||||
|
super.writeToParcel(out, flags)
|
||||||
|
out.writeByte((if (appBarLifted) 1 else 0).toByte())
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmField
|
||||||
|
val CREATOR: Parcelable.ClassLoaderCreator<SavedState> = object : Parcelable.ClassLoaderCreator<SavedState> {
|
||||||
|
override fun createFromParcel(source: Parcel, loader: ClassLoader): SavedState {
|
||||||
|
return SavedState(source, loader)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createFromParcel(source: Parcel): SavedState {
|
||||||
|
return SavedState(source, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun newArray(size: Int): Array<SavedState> {
|
||||||
|
return newArray(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Outline
|
||||||
|
import android.graphics.Paint
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewOutlineProvider
|
||||||
|
import androidx.annotation.ColorInt
|
||||||
|
import androidx.annotation.FloatRange
|
||||||
|
import androidx.core.graphics.ColorUtils
|
||||||
|
import org.koitharu.kotatsu.parsers.util.replaceWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.resolveDp
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
class SegmentedBarView @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
defStyleAttr: Int = 0,
|
||||||
|
) : View(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
|
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||||
|
private val segmentsData = ArrayList<Segment>()
|
||||||
|
private val minSegmentSize = context.resources.resolveDp(3f)
|
||||||
|
|
||||||
|
var segments: List<Segment>
|
||||||
|
get() = segmentsData
|
||||||
|
set(value) {
|
||||||
|
segmentsData.replaceWith(value)
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
paint.style = Paint.Style.FILL
|
||||||
|
outlineProvider = OutlineProvider()
|
||||||
|
clipToOutline = true
|
||||||
|
|
||||||
|
if (isInEditMode) {
|
||||||
|
segments = List(Random.nextInt(3, 5)) {
|
||||||
|
Segment(
|
||||||
|
percent = Random.nextFloat(),
|
||||||
|
color = ColorUtils.HSLToColor(floatArrayOf(Random.nextInt(0, 360).toFloat(), 0.5f, 0.5f)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDraw(canvas: Canvas) {
|
||||||
|
var x = 0f
|
||||||
|
val w = width.toFloat()
|
||||||
|
for (segment in segmentsData) {
|
||||||
|
paint.color = segment.color
|
||||||
|
val segmentWidth = (w * segment.percent).coerceAtLeast(minSegmentSize)
|
||||||
|
canvas.drawRect(x, 0f, x + segmentWidth, height.toFloat(), paint)
|
||||||
|
x += segmentWidth
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Segment(
|
||||||
|
@FloatRange(from = 0.0, to = 1.0) val percent: Float,
|
||||||
|
@ColorInt val color: Int,
|
||||||
|
) {
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as Segment
|
||||||
|
|
||||||
|
if (percent != other.percent) return false
|
||||||
|
if (color != other.color) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = percent.hashCode()
|
||||||
|
result = 31 * result + color
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class OutlineProvider : ViewOutlineProvider() {
|
||||||
|
override fun getOutline(view: View, outline: Outline) {
|
||||||
|
outline.setRoundRect(0, 0, view.width, view.height, view.height / 2f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,10 +1,14 @@
|
|||||||
package org.koitharu.kotatsu.bookmarks
|
package org.koitharu.kotatsu.bookmarks
|
||||||
|
|
||||||
|
import org.koin.androidx.viewmodel.dsl.viewModel
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository
|
import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository
|
||||||
|
import org.koitharu.kotatsu.bookmarks.ui.BookmarksViewModel
|
||||||
|
|
||||||
val bookmarksModule
|
val bookmarksModule
|
||||||
get() = module {
|
get() = module {
|
||||||
|
|
||||||
factory { BookmarksRepository(get()) }
|
factory { BookmarksRepository(get()) }
|
||||||
|
|
||||||
|
viewModel { BookmarksViewModel(get()) }
|
||||||
}
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
package org.koitharu.kotatsu.bookmarks.ui
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.core.graphics.Insets
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
|
import androidx.fragment.app.commit
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
|
import org.koitharu.kotatsu.databinding.ActivityContainerBinding
|
||||||
|
|
||||||
|
class BookmarksActivity : BaseActivity<ActivityContainerBinding>() {
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(ActivityContainerBinding.inflate(layoutInflater))
|
||||||
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
val fm = supportFragmentManager
|
||||||
|
if (fm.findFragmentById(R.id.container) == null) {
|
||||||
|
fm.commit {
|
||||||
|
val fragment = BookmarksFragment.newInstance()
|
||||||
|
replace(R.id.container, fragment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onWindowInsetsChanged(insets: Insets) {
|
||||||
|
with(binding.toolbar) {
|
||||||
|
updatePadding(
|
||||||
|
left = insets.left,
|
||||||
|
right = insets.right
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
fun newIntent(context: Context) = Intent(context, BookmarksActivity::class.java)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,177 @@
|
|||||||
|
package org.koitharu.kotatsu.bookmarks.ui
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.*
|
||||||
|
import androidx.appcompat.view.ActionMode
|
||||||
|
import androidx.core.graphics.Insets
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
import org.koin.android.ext.android.get
|
||||||
|
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.domain.reverseAsync
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseFragment
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.decor.SpacingItemDecoration
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.ReversibleAction
|
||||||
|
import org.koitharu.kotatsu.bookmarks.data.ids
|
||||||
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
|
import org.koitharu.kotatsu.bookmarks.ui.adapter.BookmarksGroupAdapter
|
||||||
|
import org.koitharu.kotatsu.bookmarks.ui.model.BookmarksGroup
|
||||||
|
import org.koitharu.kotatsu.databinding.FragmentListSimpleBinding
|
||||||
|
import org.koitharu.kotatsu.details.ui.DetailsActivity
|
||||||
|
import org.koitharu.kotatsu.list.ui.adapter.ListStateHolderListener
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.reader.ui.ReaderActivity
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
|
import org.koitharu.kotatsu.utils.ext.invalidateNestedItemDecorations
|
||||||
|
import org.koitharu.kotatsu.utils.ext.scaleUpActivityOptionsOf
|
||||||
|
|
||||||
|
class BookmarksFragment : BaseFragment<FragmentListSimpleBinding>(), ListStateHolderListener,
|
||||||
|
OnListItemClickListener<Bookmark>, SectionedSelectionController.Callback<Manga> {
|
||||||
|
|
||||||
|
private val viewModel by viewModel<BookmarksViewModel>()
|
||||||
|
private var adapter: BookmarksGroupAdapter? = null
|
||||||
|
private var selectionController: SectionedSelectionController<Manga>? = null
|
||||||
|
|
||||||
|
override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): FragmentListSimpleBinding {
|
||||||
|
return FragmentListSimpleBinding.inflate(inflater, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
selectionController = SectionedSelectionController(
|
||||||
|
activity = requireActivity(),
|
||||||
|
registryOwner = this,
|
||||||
|
callback = this,
|
||||||
|
)
|
||||||
|
adapter = BookmarksGroupAdapter(
|
||||||
|
lifecycleOwner = viewLifecycleOwner,
|
||||||
|
coil = get(),
|
||||||
|
listener = this,
|
||||||
|
selectionController = checkNotNull(selectionController),
|
||||||
|
bookmarkClickListener = this,
|
||||||
|
groupClickListener = OnGroupClickListener(),
|
||||||
|
)
|
||||||
|
binding.recyclerView.adapter = adapter
|
||||||
|
binding.recyclerView.setHasFixedSize(true)
|
||||||
|
val spacingDecoration = SpacingItemDecoration(view.resources.getDimensionPixelOffset(R.dimen.grid_spacing))
|
||||||
|
binding.recyclerView.addItemDecoration(spacingDecoration)
|
||||||
|
|
||||||
|
viewModel.content.observe(viewLifecycleOwner, ::onListChanged)
|
||||||
|
viewModel.onError.observe(viewLifecycleOwner, ::onError)
|
||||||
|
viewModel.onActionDone.observe(viewLifecycleOwner, ::onActionDone)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
super.onDestroyView()
|
||||||
|
adapter = null
|
||||||
|
selectionController = null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemClick(item: Bookmark, view: View) {
|
||||||
|
if (selectionController?.onItemClick(item.manga, item.pageId) != true) {
|
||||||
|
val intent = ReaderActivity.newIntent(view.context, item)
|
||||||
|
startActivity(intent, scaleUpActivityOptionsOf(view).toBundle())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemLongClick(item: Bookmark, view: View): Boolean {
|
||||||
|
return selectionController?.onItemLongClick(item.manga, item.pageId) ?: false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onRetryClick(error: Throwable) = Unit
|
||||||
|
|
||||||
|
override fun onEmptyActionClick() = Unit
|
||||||
|
|
||||||
|
override fun onSelectionChanged(count: Int) {
|
||||||
|
binding.recyclerView.invalidateNestedItemDecorations()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||||
|
mode.menuInflater.inflate(R.menu.mode_bookmarks, menu)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||||
|
mode.title = selectionController?.count?.toString()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||||
|
return when (item.itemId) {
|
||||||
|
R.id.action_remove -> {
|
||||||
|
val ids = selectionController?.snapshot() ?: return false
|
||||||
|
viewModel.removeBookmarks(ids)
|
||||||
|
mode.finish()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateItemDecoration(section: Manga): AbstractSelectionItemDecoration {
|
||||||
|
return BookmarksSelectionDecoration(requireContext())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onWindowInsetsChanged(insets: Insets) {
|
||||||
|
binding.root.updatePadding(
|
||||||
|
left = insets.left,
|
||||||
|
right = insets.right,
|
||||||
|
)
|
||||||
|
binding.recyclerView.updatePadding(
|
||||||
|
bottom = insets.bottom,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onListChanged(list: List<ListModel>) {
|
||||||
|
adapter?.items = list
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onError(e: Throwable) {
|
||||||
|
Snackbar.make(
|
||||||
|
binding.recyclerView,
|
||||||
|
e.getDisplayMessage(resources),
|
||||||
|
Snackbar.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onActionDone(action: ReversibleAction) {
|
||||||
|
val handle = action.handle
|
||||||
|
val length = if (handle == null) Snackbar.LENGTH_SHORT else Snackbar.LENGTH_LONG
|
||||||
|
val snackbar = Snackbar.make(binding.recyclerView, action.stringResId, length)
|
||||||
|
if (handle != null) {
|
||||||
|
snackbar.setAction(R.string.undo) { handle.reverseAsync() }
|
||||||
|
}
|
||||||
|
snackbar.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class OnGroupClickListener : OnListItemClickListener<BookmarksGroup> {
|
||||||
|
|
||||||
|
override fun onItemClick(item: BookmarksGroup, view: View) {
|
||||||
|
val controller = selectionController
|
||||||
|
if (controller != null && controller.count > 0) {
|
||||||
|
if (controller.getSectionCount(item.manga) == item.bookmarks.size) {
|
||||||
|
controller.clearSelection(item.manga)
|
||||||
|
} else {
|
||||||
|
controller.addToSelection(item.manga, item.bookmarks.ids())
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val intent = DetailsActivity.newIntent(view.context, item.manga)
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemLongClick(item: BookmarksGroup, view: View): Boolean {
|
||||||
|
return selectionController?.addToSelection(item.manga, item.bookmarks.ids()) ?: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
fun newInstance() = BookmarksFragment()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package org.koitharu.kotatsu.bookmarks.ui
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.View
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
|
import org.koitharu.kotatsu.list.ui.MangaSelectionDecoration
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getItem
|
||||||
|
|
||||||
|
class BookmarksSelectionDecoration(context: Context) : MangaSelectionDecoration(context) {
|
||||||
|
|
||||||
|
override fun getItemId(parent: RecyclerView, child: View): Long {
|
||||||
|
val holder = parent.getChildViewHolder(child) ?: return RecyclerView.NO_ID
|
||||||
|
val item = holder.getItem(Bookmark::class.java) ?: return RecyclerView.NO_ID
|
||||||
|
return item.pageId
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
package org.koitharu.kotatsu.bookmarks.ui
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.catch
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.ReversibleAction
|
||||||
|
import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository
|
||||||
|
import org.koitharu.kotatsu.bookmarks.ui.model.BookmarksGroup
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.EmptyState
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.LoadingState
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.toErrorState
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
|
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||||
|
|
||||||
|
class BookmarksViewModel(
|
||||||
|
private val repository: BookmarksRepository,
|
||||||
|
) : BaseViewModel() {
|
||||||
|
|
||||||
|
val onActionDone = SingleLiveEvent<ReversibleAction>()
|
||||||
|
|
||||||
|
val content: LiveData<List<ListModel>> = repository.observeBookmarks()
|
||||||
|
.map { list ->
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
listOf(
|
||||||
|
EmptyState(
|
||||||
|
icon = R.drawable.ic_empty_favourites,
|
||||||
|
textPrimary = R.string.no_bookmarks_yet,
|
||||||
|
textSecondary = R.string.no_bookmarks_summary,
|
||||||
|
actionStringRes = 0,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else list.map { (manga, bookmarks) ->
|
||||||
|
BookmarksGroup(manga, bookmarks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.catch { e -> e.toErrorState(canRetry = false) }
|
||||||
|
.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState))
|
||||||
|
|
||||||
|
|
||||||
|
fun removeBookmarks(ids: Map<Manga, Set<Long>>) {
|
||||||
|
launchJob(Dispatchers.Default) {
|
||||||
|
val handle = repository.removeBookmarks(ids)
|
||||||
|
onActionDone.postCall(ReversibleAction(R.string.bookmarks_removed, handle))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
package org.koitharu.kotatsu.bookmarks.ui.adapter
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import coil.ImageLoader
|
||||||
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.decor.SpacingItemDecoration
|
||||||
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
|
import org.koitharu.kotatsu.bookmarks.ui.model.BookmarksGroup
|
||||||
|
import org.koitharu.kotatsu.databinding.ItemBookmarksGroupBinding
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.utils.ext.*
|
||||||
|
|
||||||
|
fun bookmarksGroupAD(
|
||||||
|
coil: ImageLoader,
|
||||||
|
lifecycleOwner: LifecycleOwner,
|
||||||
|
sharedPool: RecyclerView.RecycledViewPool,
|
||||||
|
selectionController: SectionedSelectionController<Manga>,
|
||||||
|
bookmarkClickListener: OnListItemClickListener<Bookmark>,
|
||||||
|
groupClickListener: OnListItemClickListener<BookmarksGroup>,
|
||||||
|
) = adapterDelegateViewBinding<BookmarksGroup, ListModel, ItemBookmarksGroupBinding>(
|
||||||
|
{ layoutInflater, parent -> ItemBookmarksGroupBinding.inflate(layoutInflater, parent, false) }
|
||||||
|
) {
|
||||||
|
|
||||||
|
val viewListenerAdapter = object : View.OnClickListener, View.OnLongClickListener {
|
||||||
|
override fun onClick(v: View) = groupClickListener.onItemClick(item, v)
|
||||||
|
override fun onLongClick(v: View) = groupClickListener.onItemLongClick(item, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
val adapter = BookmarksAdapter(coil, lifecycleOwner, bookmarkClickListener)
|
||||||
|
binding.recyclerView.setRecycledViewPool(sharedPool)
|
||||||
|
binding.recyclerView.adapter = adapter
|
||||||
|
val spacingDecoration = SpacingItemDecoration(context.resources.getDimensionPixelOffset(R.dimen.grid_spacing))
|
||||||
|
binding.recyclerView.addItemDecoration(spacingDecoration)
|
||||||
|
binding.root.setOnClickListener(viewListenerAdapter)
|
||||||
|
binding.root.setOnLongClickListener(viewListenerAdapter)
|
||||||
|
|
||||||
|
bind { payloads ->
|
||||||
|
if (payloads.isEmpty()) {
|
||||||
|
binding.recyclerView.clearItemDecorations()
|
||||||
|
binding.recyclerView.addItemDecoration(spacingDecoration)
|
||||||
|
selectionController.attachToRecyclerView(item.manga, binding.recyclerView)
|
||||||
|
}
|
||||||
|
binding.imageViewCover.newImageRequest(item.manga.coverUrl)?.run {
|
||||||
|
referer(item.manga.publicUrl)
|
||||||
|
placeholder(R.drawable.ic_placeholder)
|
||||||
|
fallback(R.drawable.ic_placeholder)
|
||||||
|
error(R.drawable.ic_placeholder)
|
||||||
|
allowRgb565(true)
|
||||||
|
lifecycle(lifecycleOwner)
|
||||||
|
enqueueWith(coil)
|
||||||
|
}
|
||||||
|
binding.textViewTitle.text = item.manga.title
|
||||||
|
adapter.items = item.bookmarks
|
||||||
|
}
|
||||||
|
|
||||||
|
onViewRecycled {
|
||||||
|
binding.imageViewCover.disposeImageRequest()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
package org.koitharu.kotatsu.bookmarks.ui.adapter
|
||||||
|
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import coil.ImageLoader
|
||||||
|
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.SectionedSelectionController
|
||||||
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
|
import org.koitharu.kotatsu.bookmarks.ui.model.BookmarksGroup
|
||||||
|
import org.koitharu.kotatsu.list.ui.adapter.*
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import kotlin.jvm.internal.Intrinsics
|
||||||
|
|
||||||
|
class BookmarksGroupAdapter(
|
||||||
|
coil: ImageLoader,
|
||||||
|
lifecycleOwner: LifecycleOwner,
|
||||||
|
selectionController: SectionedSelectionController<Manga>,
|
||||||
|
listener: ListStateHolderListener,
|
||||||
|
bookmarkClickListener: OnListItemClickListener<Bookmark>,
|
||||||
|
groupClickListener: OnListItemClickListener<BookmarksGroup>,
|
||||||
|
) : AsyncListDifferDelegationAdapter<ListModel>(DiffCallback()) {
|
||||||
|
|
||||||
|
init {
|
||||||
|
val pool = RecyclerView.RecycledViewPool()
|
||||||
|
delegatesManager
|
||||||
|
.addDelegate(
|
||||||
|
bookmarksGroupAD(
|
||||||
|
coil = coil,
|
||||||
|
lifecycleOwner = lifecycleOwner,
|
||||||
|
sharedPool = pool,
|
||||||
|
selectionController = selectionController,
|
||||||
|
bookmarkClickListener = bookmarkClickListener,
|
||||||
|
groupClickListener = groupClickListener,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.addDelegate(loadingStateAD())
|
||||||
|
.addDelegate(loadingFooterAD())
|
||||||
|
.addDelegate(emptyStateListAD(listener))
|
||||||
|
.addDelegate(errorStateListAD(listener))
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DiffCallback : DiffUtil.ItemCallback<ListModel>() {
|
||||||
|
|
||||||
|
override fun areItemsTheSame(oldItem: ListModel, newItem: ListModel): Boolean {
|
||||||
|
return when {
|
||||||
|
oldItem is BookmarksGroup && newItem is BookmarksGroup -> {
|
||||||
|
oldItem.manga.id == newItem.manga.id
|
||||||
|
}
|
||||||
|
else -> oldItem.javaClass == newItem.javaClass
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areContentsTheSame(oldItem: ListModel, newItem: ListModel): Boolean {
|
||||||
|
return Intrinsics.areEqual(oldItem, newItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getChangePayload(oldItem: ListModel, newItem: ListModel): Any? {
|
||||||
|
return when {
|
||||||
|
oldItem is BookmarksGroup && newItem is BookmarksGroup -> Unit
|
||||||
|
else -> super.getChangePayload(oldItem, newItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
package org.koitharu.kotatsu.bookmarks.ui.model
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.util.areItemsEquals
|
||||||
|
|
||||||
|
class BookmarksGroup(
|
||||||
|
val manga: Manga,
|
||||||
|
val bookmarks: List<Bookmark>,
|
||||||
|
) : ListModel {
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as BookmarksGroup
|
||||||
|
|
||||||
|
if (manga != other.manga) return false
|
||||||
|
|
||||||
|
return bookmarks.areItemsEquals(other.bookmarks) { a, b ->
|
||||||
|
a.imageUrl == b.imageUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = manga.hashCode()
|
||||||
|
result = 31 * result + bookmarks.sumOf { it.imageUrl.hashCode() }
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,68 @@
|
|||||||
|
package org.koitharu.kotatsu.core.backup
|
||||||
|
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
||||||
|
import org.koitharu.kotatsu.favourites.data.FavouriteCategoryEntity
|
||||||
|
import org.koitharu.kotatsu.favourites.data.FavouriteEntity
|
||||||
|
import org.koitharu.kotatsu.history.data.HistoryEntity
|
||||||
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
|
import org.koitharu.kotatsu.parsers.util.json.getBooleanOrDefault
|
||||||
|
import org.koitharu.kotatsu.parsers.util.json.getFloatOrDefault
|
||||||
|
import org.koitharu.kotatsu.parsers.util.json.getIntOrDefault
|
||||||
|
import org.koitharu.kotatsu.parsers.util.json.getStringOrNull
|
||||||
|
|
||||||
|
class JsonDeserializer(private val json: JSONObject) {
|
||||||
|
|
||||||
|
fun toFavouriteEntity() = FavouriteEntity(
|
||||||
|
mangaId = json.getLong("manga_id"),
|
||||||
|
categoryId = json.getLong("category_id"),
|
||||||
|
sortKey = json.getIntOrDefault("sort_key", 0),
|
||||||
|
createdAt = json.getLong("created_at"),
|
||||||
|
deletedAt = 0L,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun toMangaEntity() = MangaEntity(
|
||||||
|
id = json.getLong("id"),
|
||||||
|
title = json.getString("title"),
|
||||||
|
altTitle = json.getStringOrNull("alt_title"),
|
||||||
|
url = json.getString("url"),
|
||||||
|
publicUrl = json.getStringOrNull("public_url").orEmpty(),
|
||||||
|
rating = json.getDouble("rating").toFloat(),
|
||||||
|
isNsfw = json.getBooleanOrDefault("nsfw", false),
|
||||||
|
coverUrl = json.getString("cover_url"),
|
||||||
|
largeCoverUrl = json.getStringOrNull("large_cover_url"),
|
||||||
|
state = json.getStringOrNull("state"),
|
||||||
|
author = json.getStringOrNull("author"),
|
||||||
|
source = json.getString("source")
|
||||||
|
)
|
||||||
|
|
||||||
|
fun toTagEntity() = TagEntity(
|
||||||
|
id = json.getLong("id"),
|
||||||
|
title = json.getString("title"),
|
||||||
|
key = json.getString("key"),
|
||||||
|
source = json.getString("source")
|
||||||
|
)
|
||||||
|
|
||||||
|
fun toHistoryEntity() = HistoryEntity(
|
||||||
|
mangaId = json.getLong("manga_id"),
|
||||||
|
createdAt = json.getLong("created_at"),
|
||||||
|
updatedAt = json.getLong("updated_at"),
|
||||||
|
chapterId = json.getLong("chapter_id"),
|
||||||
|
page = json.getInt("page"),
|
||||||
|
scroll = json.getDouble("scroll").toFloat(),
|
||||||
|
percent = json.getFloatOrDefault("percent", -1f),
|
||||||
|
deletedAt = 0L,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun toFavouriteCategoryEntity() = FavouriteCategoryEntity(
|
||||||
|
categoryId = json.getInt("category_id"),
|
||||||
|
createdAt = json.getLong("created_at"),
|
||||||
|
sortKey = json.getInt("sort_key"),
|
||||||
|
title = json.getString("title"),
|
||||||
|
order = json.getStringOrNull("order") ?: SortOrder.NEWEST.name,
|
||||||
|
track = json.getBooleanOrDefault("track", true),
|
||||||
|
isVisibleInLibrary = json.getBooleanOrDefault("show_in_lib", true),
|
||||||
|
deletedAt = 0L,
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -0,0 +1,72 @@
|
|||||||
|
package org.koitharu.kotatsu.core.backup
|
||||||
|
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
||||||
|
import org.koitharu.kotatsu.favourites.data.FavouriteCategoryEntity
|
||||||
|
import org.koitharu.kotatsu.favourites.data.FavouriteEntity
|
||||||
|
import org.koitharu.kotatsu.history.data.HistoryEntity
|
||||||
|
|
||||||
|
class JsonSerializer private constructor(private val json: JSONObject) {
|
||||||
|
|
||||||
|
constructor(e: FavouriteEntity) : this(
|
||||||
|
JSONObject().apply {
|
||||||
|
put("manga_id", e.mangaId)
|
||||||
|
put("category_id", e.categoryId)
|
||||||
|
put("sort_key", e.sortKey)
|
||||||
|
put("created_at", e.createdAt)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
constructor(e: FavouriteCategoryEntity) : this(
|
||||||
|
JSONObject().apply {
|
||||||
|
put("category_id", e.categoryId)
|
||||||
|
put("created_at", e.createdAt)
|
||||||
|
put("sort_key", e.sortKey)
|
||||||
|
put("title", e.title)
|
||||||
|
put("order", e.order)
|
||||||
|
put("track", e.track)
|
||||||
|
put("show_in_lib", e.isVisibleInLibrary)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
constructor(e: HistoryEntity) : this(
|
||||||
|
JSONObject().apply {
|
||||||
|
put("manga_id", e.mangaId)
|
||||||
|
put("created_at", e.createdAt)
|
||||||
|
put("updated_at", e.updatedAt)
|
||||||
|
put("chapter_id", e.chapterId)
|
||||||
|
put("page", e.page)
|
||||||
|
put("scroll", e.scroll)
|
||||||
|
put("percent", e.percent)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
constructor(e: TagEntity) : this(
|
||||||
|
JSONObject().apply {
|
||||||
|
put("id", e.id)
|
||||||
|
put("title", e.title)
|
||||||
|
put("key", e.key)
|
||||||
|
put("source", e.source)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
constructor(e: MangaEntity) : this(
|
||||||
|
JSONObject().apply {
|
||||||
|
put("id", e.id)
|
||||||
|
put("title", e.title)
|
||||||
|
put("alt_title", e.altTitle)
|
||||||
|
put("url", e.url)
|
||||||
|
put("public_url", e.publicUrl)
|
||||||
|
put("rating", e.rating)
|
||||||
|
put("nsfw", e.isNsfw)
|
||||||
|
put("cover_url", e.coverUrl)
|
||||||
|
put("large_cover_url", e.largeCoverUrl)
|
||||||
|
put("state", e.state)
|
||||||
|
put("author", e.author)
|
||||||
|
put("source", e.source)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
fun toJson(): JSONObject = json
|
||||||
|
}
|
||||||
@ -1,118 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.backup
|
|
||||||
|
|
||||||
import androidx.room.withTransaction
|
|
||||||
import org.json.JSONObject
|
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
|
||||||
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
|
||||||
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
|
||||||
import org.koitharu.kotatsu.favourites.data.FavouriteCategoryEntity
|
|
||||||
import org.koitharu.kotatsu.favourites.data.FavouriteEntity
|
|
||||||
import org.koitharu.kotatsu.history.data.HistoryEntity
|
|
||||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
|
||||||
import org.koitharu.kotatsu.parsers.util.json.JSONIterator
|
|
||||||
import org.koitharu.kotatsu.parsers.util.json.getBooleanOrDefault
|
|
||||||
import org.koitharu.kotatsu.parsers.util.json.getStringOrNull
|
|
||||||
import org.koitharu.kotatsu.parsers.util.json.mapJSON
|
|
||||||
|
|
||||||
class RestoreRepository(private val db: MangaDatabase) {
|
|
||||||
|
|
||||||
suspend fun upsertHistory(entry: BackupEntry): CompositeResult {
|
|
||||||
val result = CompositeResult()
|
|
||||||
for (item in entry.data.JSONIterator()) {
|
|
||||||
val mangaJson = item.getJSONObject("manga")
|
|
||||||
val manga = parseManga(mangaJson)
|
|
||||||
val tags = mangaJson.getJSONArray("tags").mapJSON {
|
|
||||||
parseTag(it)
|
|
||||||
}
|
|
||||||
val history = parseHistory(item)
|
|
||||||
result += runCatching {
|
|
||||||
db.withTransaction {
|
|
||||||
db.tagsDao.upsert(tags)
|
|
||||||
db.mangaDao.upsert(manga, tags)
|
|
||||||
db.historyDao.upsert(history)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun upsertCategories(entry: BackupEntry): CompositeResult {
|
|
||||||
val result = CompositeResult()
|
|
||||||
for (item in entry.data.JSONIterator()) {
|
|
||||||
val category = parseCategory(item)
|
|
||||||
result += runCatching {
|
|
||||||
db.favouriteCategoriesDao.upsert(category)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun upsertFavourites(entry: BackupEntry): CompositeResult {
|
|
||||||
val result = CompositeResult()
|
|
||||||
for (item in entry.data.JSONIterator()) {
|
|
||||||
val mangaJson = item.getJSONObject("manga")
|
|
||||||
val manga = parseManga(mangaJson)
|
|
||||||
val tags = mangaJson.getJSONArray("tags").mapJSON {
|
|
||||||
parseTag(it)
|
|
||||||
}
|
|
||||||
val favourite = parseFavourite(item)
|
|
||||||
result += runCatching {
|
|
||||||
db.withTransaction {
|
|
||||||
db.tagsDao.upsert(tags)
|
|
||||||
db.mangaDao.upsert(manga, tags)
|
|
||||||
db.favouritesDao.upsert(favourite)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseManga(json: JSONObject) = MangaEntity(
|
|
||||||
id = json.getLong("id"),
|
|
||||||
title = json.getString("title"),
|
|
||||||
altTitle = json.getStringOrNull("alt_title"),
|
|
||||||
url = json.getString("url"),
|
|
||||||
publicUrl = json.getStringOrNull("public_url").orEmpty(),
|
|
||||||
rating = json.getDouble("rating").toFloat(),
|
|
||||||
isNsfw = json.getBooleanOrDefault("nsfw", false),
|
|
||||||
coverUrl = json.getString("cover_url"),
|
|
||||||
largeCoverUrl = json.getStringOrNull("large_cover_url"),
|
|
||||||
state = json.getStringOrNull("state"),
|
|
||||||
author = json.getStringOrNull("author"),
|
|
||||||
source = json.getString("source"),
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun parseTag(json: JSONObject) = TagEntity(
|
|
||||||
id = json.getLong("id"),
|
|
||||||
title = json.getString("title"),
|
|
||||||
key = json.getString("key"),
|
|
||||||
source = json.getString("source"),
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun parseHistory(json: JSONObject) = HistoryEntity(
|
|
||||||
mangaId = json.getLong("manga_id"),
|
|
||||||
createdAt = json.getLong("created_at"),
|
|
||||||
updatedAt = json.getLong("updated_at"),
|
|
||||||
chapterId = json.getLong("chapter_id"),
|
|
||||||
page = json.getInt("page"),
|
|
||||||
scroll = json.getDouble("scroll").toFloat(),
|
|
||||||
deletedAt = 0L,
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun parseCategory(json: JSONObject) = FavouriteCategoryEntity(
|
|
||||||
categoryId = json.getInt("category_id"),
|
|
||||||
createdAt = json.getLong("created_at"),
|
|
||||||
sortKey = json.getInt("sort_key"),
|
|
||||||
title = json.getString("title"),
|
|
||||||
order = json.getStringOrNull("order") ?: SortOrder.NEWEST.name,
|
|
||||||
track = json.getBooleanOrDefault("track", true),
|
|
||||||
deletedAt = 0L,
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun parseFavourite(json: JSONObject) = FavouriteEntity(
|
|
||||||
mangaId = json.getLong("manga_id"),
|
|
||||||
categoryId = json.getLong("category_id"),
|
|
||||||
createdAt = json.getLong("created_at"),
|
|
||||||
deletedAt = 0L,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.db.entity
|
|
||||||
|
|
||||||
import androidx.room.Embedded
|
|
||||||
import androidx.room.Junction
|
|
||||||
import androidx.room.Relation
|
|
||||||
|
|
||||||
class TrackLogWithManga(
|
|
||||||
@Embedded val trackLog: TrackLogEntity,
|
|
||||||
@Relation(
|
|
||||||
parentColumn = "manga_id",
|
|
||||||
entityColumn = "manga_id"
|
|
||||||
)
|
|
||||||
val manga: MangaEntity,
|
|
||||||
@Relation(
|
|
||||||
parentColumn = "manga_id",
|
|
||||||
entityColumn = "tag_id",
|
|
||||||
associateBy = Junction(MangaTagsEntity::class)
|
|
||||||
)
|
|
||||||
val tags: List<TagEntity>,
|
|
||||||
)
|
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db.migrations
|
||||||
|
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
|
||||||
|
class Migration12To13 : Migration(12, 13) {
|
||||||
|
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("ALTER TABLE favourite_categories ADD COLUMN `show_in_lib` INTEGER NOT NULL DEFAULT 1")
|
||||||
|
database.execSQL("ALTER TABLE favourites ADD COLUMN `sort_key` INTEGER NOT NULL DEFAULT 0")
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db.migrations
|
||||||
|
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
|
||||||
|
class Migration13To14 : Migration(13, 14) {
|
||||||
|
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("ALTER TABLE favourite_categories ADD COLUMN `deleted_at` INTEGER NOT NULL DEFAULT 0")
|
||||||
|
database.execSQL("ALTER TABLE favourites ADD COLUMN `deleted_at` INTEGER NOT NULL DEFAULT 0")
|
||||||
|
database.execSQL("ALTER TABLE history ADD COLUMN `deleted_at` INTEGER NOT NULL DEFAULT 0")
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.core.exceptions
|
package org.koitharu.kotatsu.core.exceptions
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
|
||||||
import okio.IOException
|
import okio.IOException
|
||||||
import org.koitharu.kotatsu.R
|
|
||||||
|
|
||||||
class CloudFlareProtectedException(
|
class CloudFlareProtectedException(
|
||||||
val url: String
|
val url: String
|
||||||
|
|||||||
@ -0,0 +1,8 @@
|
|||||||
|
package org.koitharu.kotatsu.core.exceptions
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.parsers.util.mapNotNullToSet
|
||||||
|
|
||||||
|
class CompositeException(val errors: Collection<Throwable>) : Exception() {
|
||||||
|
|
||||||
|
override val message: String = errors.mapNotNullToSet { it.message }.joinToString()
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package org.koitharu.kotatsu.core.model
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
fun MangaSource.getLocaleTitle(): String? {
|
||||||
|
val lc = Locale(locale ?: return null)
|
||||||
|
return lc.getDisplayLanguage(lc).toTitleCase(lc)
|
||||||
|
}
|
||||||
@ -1,14 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.model
|
|
||||||
|
|
||||||
import android.os.Parcelable
|
|
||||||
import kotlinx.parcelize.Parcelize
|
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
data class MangaTracking(
|
|
||||||
val manga: Manga,
|
|
||||||
val knownChaptersCount: Int,
|
|
||||||
val lastChapterId: Long,
|
|
||||||
val lastNotifiedChapterId: Long,
|
|
||||||
val lastCheck: Date?
|
|
||||||
)
|
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package org.koitharu.kotatsu.core.network
|
||||||
|
|
||||||
|
import okhttp3.Interceptor
|
||||||
|
import okhttp3.Response
|
||||||
|
import org.koitharu.kotatsu.core.network.CommonHeaders.CONTENT_ENCODING
|
||||||
|
|
||||||
|
class GZipInterceptor : Interceptor {
|
||||||
|
|
||||||
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
|
val newRequest = chain.request().newBuilder()
|
||||||
|
newRequest.addHeader(CONTENT_ENCODING, "gzip")
|
||||||
|
return chain.proceed(newRequest.build())
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue