Compare commits
700 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
865f335b25 | ||
|
|
6b1e89eda8 | ||
|
|
0dbaf919e2 | ||
|
|
7431f46117 | ||
|
|
48ac417189 | ||
|
|
98453c34a7 | ||
|
|
c62e29d995 | ||
|
|
4d0bd9538b | ||
|
|
fdb4e5098e | ||
|
|
758d3c55d4 | ||
|
|
f40ff12250 | ||
|
|
4f3721beea | ||
|
|
346526267e | ||
|
|
6c82c6e9f5 | ||
|
|
11dabd7426 | ||
|
|
056a26b55c | ||
|
|
f1863ddc71 | ||
|
|
437ae4cdae | ||
|
|
98f5615d77 | ||
|
|
44ce3ce66d | ||
|
|
080c2724cd | ||
|
|
43872ffe01 | ||
|
|
5cfad9ab8a | ||
|
|
866f9272ef | ||
|
|
f5a6e1e124 | ||
|
|
5595bc6971 | ||
|
|
e6ed353211 | ||
|
|
4e10908015 | ||
|
|
087ececfdd | ||
|
|
c090018acd | ||
|
|
5f6256a5c6 | ||
|
|
9e6be12707 | ||
|
|
737ca4a916 | ||
|
|
b2958d03e4 | ||
|
|
af8550744f | ||
|
|
2f5fd71bb1 | ||
|
|
271750ad93 | ||
|
|
0281c09dde | ||
|
|
f2ac3c331c | ||
|
|
4fc56f9786 | ||
|
|
a13c498d00 | ||
|
|
e15934bdc6 | ||
|
|
4ec50f83d2 | ||
|
|
d0b9412559 | ||
|
|
9adf209445 | ||
|
|
5d2395b569 | ||
|
|
29114ae8a7 | ||
|
|
47f80085d1 | ||
|
|
73c1d2a616 | ||
|
|
35366ac660 | ||
|
|
dc2dd4e3c9 | ||
|
|
66817ae545 | ||
|
|
b6e3cb929b | ||
|
|
6f29259395 | ||
|
|
c520699f9f | ||
|
|
c09b0150ac | ||
|
|
d7c31f3b3b | ||
|
|
362629bb9a | ||
|
|
4ec4421f69 | ||
|
|
029815e0d7 | ||
|
|
019b41a9f9 | ||
|
|
a56e977058 | ||
|
|
f436a49e5f | ||
|
|
652351f79a | ||
|
|
b6bfef6b50 | ||
|
|
c119db67e9 | ||
|
|
08e036f9fb | ||
|
|
07519b82f3 | ||
|
|
2644756a01 | ||
|
|
f6c715c5a7 | ||
|
|
81f3a40ba8 | ||
|
|
736be6249c | ||
|
|
0add49f32c | ||
|
|
1e2be37fd6 | ||
|
|
529c6c7a08 | ||
|
|
03251cbf9a | ||
|
|
4ab9ace2f2 | ||
|
|
c55be4efc5 | ||
|
|
48b01d0706 | ||
|
|
e2e0d7a53d | ||
|
|
e3a67940d0 | ||
|
|
5ce2bc92d6 | ||
|
|
d05e777b2c | ||
|
|
206673a417 | ||
|
|
95e46249c5 | ||
|
|
ea9ae2263c | ||
|
|
2acbff487e | ||
|
|
26b852365a | ||
|
|
c2e56f7ba6 | ||
|
|
68e8876288 | ||
|
|
5c44a4dbb3 | ||
|
|
7a7ba802f6 | ||
|
|
c5ae9fb087 | ||
|
|
e0f23d2e6d | ||
|
|
e9a972eec9 | ||
|
|
155af8889b | ||
|
|
61b7117b97 | ||
|
|
0f4de329e5 | ||
|
|
9b290bea40 | ||
|
|
fd3c83cb13 | ||
|
|
ec137d2513 | ||
|
|
9da5bdaad4 | ||
|
|
eec1850712 | ||
|
|
802ab4c6c1 | ||
|
|
85d09dc48c | ||
|
|
1daa02af52 | ||
|
|
1729505bfe | ||
|
|
00617d5c64 | ||
|
|
35b8003cf9 | ||
|
|
56ed8a787a | ||
|
|
fd26de7619 | ||
|
|
205a2e10a5 | ||
|
|
8514cc3da7 | ||
|
|
8bc8df7625 | ||
|
|
7ffa15d2d7 | ||
|
|
80be0e403d | ||
|
|
ee2538ba7f | ||
|
|
6ca6ec28ac | ||
|
|
94203785f1 | ||
|
|
3f538d9b78 | ||
|
|
e6a0578884 | ||
|
|
e11e890818 | ||
|
|
3e7a48d27a | ||
|
|
eeba959ba5 | ||
|
|
e7fa1036be | ||
|
|
542a7e1141 | ||
|
|
5951f4438a | ||
|
|
1fbae6bd7b | ||
|
|
b73924aea8 | ||
|
|
005443f4ae | ||
|
|
abb55d4424 | ||
|
|
e0538da079 | ||
|
|
665bf5a034 | ||
|
|
dc7e1282c6 | ||
|
|
3a877d4f4a | ||
|
|
8a23c9a327 | ||
|
|
452c0edfc7 | ||
|
|
2b9307aa17 | ||
|
|
f91d5e1c29 | ||
|
|
2fbfd14252 | ||
|
|
c09dd92cff | ||
|
|
6b08074a70 | ||
|
|
9cb5971182 | ||
|
|
6f37d95c24 | ||
|
|
d290ba24b7 | ||
|
|
f57d23026b | ||
|
|
1a70ccff55 | ||
|
|
bd6a51e58d | ||
|
|
a9c122b144 | ||
|
|
ed56170809 | ||
|
|
a36e5fce29 | ||
|
|
760bfaf4d7 | ||
|
|
24463720b1 | ||
|
|
516470e8ae | ||
|
|
7f530d0476 | ||
|
|
8a2706d70b | ||
|
|
27f09480a0 | ||
|
|
c03dcf6d2e | ||
|
|
bdb2ae9c2f | ||
|
|
3413fe6943 | ||
|
|
e6ae9e8bd6 | ||
|
|
8d9426f257 | ||
|
|
30247e3def | ||
|
|
084dc32d2d | ||
|
|
3393f1397b | ||
|
|
61784bcfc4 | ||
|
|
bd692fc60c | ||
|
|
2c71110fa5 | ||
|
|
738299e8d3 | ||
|
|
c8b6dc27b2 | ||
|
|
1493aa39a3 | ||
|
|
f115031846 | ||
|
|
571b85dfd8 | ||
|
|
75cc9e9030 | ||
|
|
656a707b4c | ||
|
|
04afe7a934 | ||
|
|
689670b3ff | ||
|
|
6273a9decb | ||
|
|
72336d4f71 | ||
|
|
731e998eb2 | ||
|
|
9bf53114de | ||
|
|
0e1b8db688 | ||
|
|
3a62e2e6c0 | ||
|
|
08764cb3cb | ||
|
|
9c52545f63 | ||
|
|
a6c30d33d4 | ||
|
|
25974af229 | ||
|
|
607dfc9be3 | ||
|
|
560e669700 | ||
|
|
ba403c9360 | ||
|
|
0f1c9ff05d | ||
|
|
662f08e115 | ||
|
|
d647a32e9f | ||
|
|
375e72cb98 | ||
|
|
34c7cafdfe | ||
|
|
03e0eefe4d | ||
|
|
f41425f03d | ||
|
|
400b91278f | ||
|
|
9088f77ae5 | ||
|
|
86da3217d1 | ||
|
|
24908e52af | ||
|
|
1261a6790d | ||
|
|
59fa61864a | ||
|
|
1cbfe017ea | ||
|
|
f469369b14 | ||
|
|
1ddcaed483 | ||
|
|
7bb7736f18 | ||
|
|
d1e7e7a2a6 | ||
|
|
0c4b7b0586 | ||
|
|
f320f22863 | ||
|
|
d224cd99bb | ||
|
|
b955d31770 | ||
|
|
46786e32a3 | ||
|
|
eef449af49 | ||
|
|
b4eb8d56a6 | ||
|
|
c896ac72e8 | ||
|
|
b599cb33ff | ||
|
|
b3eab1a2a0 | ||
|
|
79d9dc7b24 | ||
|
|
7b573f8e6b | ||
|
|
7bd769e294 | ||
|
|
fde5f86313 | ||
|
|
3c23bf7ec9 | ||
|
|
4665f8b74e | ||
|
|
0c4c7489e9 | ||
|
|
5a43e677c5 | ||
|
|
38d4274ece | ||
|
|
743098d0b0 | ||
|
|
0e5221fa6e | ||
|
|
b458bde8a1 | ||
|
|
c663d10515 | ||
|
|
cec19c3db3 | ||
|
|
ff58539e2e | ||
|
|
d8e7689a94 | ||
|
|
32cfbb327c | ||
|
|
245e87256b | ||
|
|
ed8c69037f | ||
|
|
3f76d22d67 | ||
|
|
980988e684 | ||
|
|
347811abb6 | ||
|
|
ccb8b0c8e7 | ||
|
|
18137ab48e | ||
|
|
a9f435ae3d | ||
|
|
0758cfef64 | ||
|
|
06d1d56448 | ||
|
|
07c70eaccc | ||
|
|
5ad6413952 | ||
|
|
0b9d9ac7f2 | ||
|
|
3ab87027ab | ||
|
|
7545a774ba | ||
|
|
db16eb8e29 | ||
|
|
e5a27a7c6f | ||
|
|
d26bc102d1 | ||
|
|
fc6a8afd93 | ||
|
|
5a9d401446 | ||
|
|
77ac40b445 | ||
|
|
a29454f672 | ||
|
|
80ee7c8e54 | ||
|
|
fb202f80a5 | ||
|
|
2b2042807b | ||
|
|
45dbd5aa44 | ||
|
|
ee65251bf5 | ||
|
|
eaeb11f9ce | ||
|
|
2f74633abb | ||
|
|
0f346dc725 | ||
|
|
1b92848964 | ||
|
|
3d91583585 | ||
|
|
f76d9fa3e4 | ||
|
|
b00b2e406e | ||
|
|
74717e2b93 | ||
|
|
9b54ed6bc7 | ||
|
|
7b36c64b34 | ||
|
|
da09884136 | ||
|
|
64aaf37556 | ||
|
|
11104223eb | ||
|
|
0c119bc137 | ||
|
|
5c058e626b | ||
|
|
2005ae2bf3 | ||
|
|
d0650c7cf4 | ||
|
|
2df4e6480a | ||
|
|
017a1686dc | ||
|
|
279dc03695 | ||
|
|
c8c482f692 | ||
|
|
02a0e3ebcd | ||
|
|
fc0b3f3b38 | ||
|
|
2925900214 | ||
|
|
eae370e41c | ||
|
|
d0338a604a | ||
|
|
e22b98b476 | ||
|
|
4d838d290d | ||
|
|
048efdf59f | ||
|
|
65dbc6b8e5 | ||
|
|
627a00beb4 | ||
|
|
e00ed13ad1 | ||
|
|
af2adeba13 | ||
|
|
893fa6bd90 | ||
|
|
512188c8dd | ||
|
|
aae6761809 | ||
|
|
c3f055d0c4 | ||
|
|
93c6bec452 | ||
|
|
04d5df20d1 | ||
|
|
665eca0699 | ||
|
|
9a1534464f | ||
|
|
f856fc6fac | ||
|
|
4af8e73303 | ||
|
|
23239f1fec | ||
|
|
853e4d6fde | ||
|
|
14a37ad16e | ||
|
|
c944044465 | ||
|
|
8a63ca2310 | ||
|
|
12e5e3b35e | ||
|
|
553a85ef86 | ||
|
|
d604ff3c24 | ||
|
|
4f9eee7d46 | ||
|
|
fe673a94ed | ||
|
|
bcd891d653 | ||
|
|
1e75edf262 | ||
|
|
73478d6a81 | ||
|
|
982080a930 | ||
|
|
66cd5070dc | ||
|
|
c05b0eaa59 | ||
|
|
29a073d844 | ||
|
|
a0e69428e4 | ||
|
|
de7012cabf | ||
|
|
3f6a103915 | ||
|
|
734765dbdd | ||
|
|
117c4c5978 | ||
|
|
13e33a6614 | ||
|
|
affb495136 | ||
|
|
9b2dafd668 | ||
|
|
5f32c0401f | ||
|
|
f35f40ed27 | ||
|
|
46f0d3ef74 | ||
|
|
c27c785ac2 | ||
|
|
6e844e8c3b | ||
|
|
4186c36f30 | ||
|
|
2d727a0da8 | ||
|
|
39e574e9dc | ||
|
|
efb94cbd67 | ||
|
|
757e33dfb4 | ||
|
|
ab9bdf9f07 | ||
|
|
a68632a888 | ||
|
|
9b0dc8b413 | ||
|
|
f43fe5830e | ||
|
|
ce616b328c | ||
|
|
824a8ff97a | ||
|
|
ef9018b92f | ||
|
|
a088d10935 | ||
|
|
2e561697ac | ||
|
|
d242acd502 | ||
|
|
d37b44d3f6 | ||
|
|
6243fc88c9 | ||
|
|
f74e865b06 | ||
|
|
1a2bc02188 | ||
|
|
b0153e9f61 | ||
|
|
7f3fc1b88a | ||
|
|
40bf0c75bf | ||
|
|
9407bd205c | ||
|
|
3317c8dddc | ||
|
|
fc4b6eb1af | ||
|
|
2aaaf2f4a2 | ||
|
|
92aa96a644 | ||
|
|
6a0a4023ad | ||
|
|
8569610e52 | ||
|
|
51ffa4d469 | ||
|
|
e4c4d2bbf0 | ||
|
|
35d6f1fb34 | ||
|
|
edac5fda8c | ||
|
|
040d3e4433 | ||
|
|
011dd4c069 | ||
|
|
b4f93fc0a5 | ||
|
|
e0d74ba2a9 | ||
|
|
935826617e | ||
|
|
b9f2effb86 | ||
|
|
5c86de555a | ||
|
|
c4e7807d18 | ||
|
|
78dd0588ce | ||
|
|
2d73894880 | ||
|
|
8ac19e557b | ||
|
|
f677a75ad1 | ||
|
|
8e55a4d824 | ||
|
|
6b5d8ff0f1 | ||
|
|
0c7da53349 | ||
|
|
2a3cc11728 | ||
|
|
a806634bc0 | ||
|
|
6879d046f8 | ||
|
|
0248f84ca0 | ||
|
|
ff0706dae5 | ||
|
|
b73fe0398f | ||
|
|
f78ae4a818 | ||
|
|
072f6d8c69 | ||
|
|
68b68eb4c5 | ||
|
|
7f95eead50 | ||
|
|
1935de8f20 | ||
|
|
c1e9fde6e8 | ||
|
|
9ded9b84e0 | ||
|
|
21037529c0 | ||
|
|
ec8bdbe6e1 | ||
|
|
b37fd6f4ab | ||
|
|
d853bb2c62 | ||
|
|
68dcacb918 | ||
|
|
49a7408715 | ||
|
|
5abbddba1e | ||
|
|
2382bf1063 | ||
|
|
f9b409634b | ||
|
|
bb96383d27 | ||
|
|
96a7a46981 | ||
|
|
4b3446ce0e | ||
|
|
6f302e2536 | ||
|
|
53c326ad05 | ||
|
|
7befb88e15 | ||
|
|
68e8ccf6bd | ||
|
|
32e80c7e95 | ||
|
|
c07a3b9d0d | ||
|
|
893d1a881d | ||
|
|
43ef130052 | ||
|
|
d5bea0ca53 | ||
|
|
9c740c5cc1 | ||
|
|
a5b85c296a | ||
|
|
2d453bb553 | ||
|
|
ad1d247694 | ||
|
|
cf7535e2ba | ||
|
|
0077dc2f1c | ||
|
|
59a50e163f | ||
|
|
22e5b958bc | ||
|
|
905c4b362c | ||
|
|
6e71f20470 | ||
|
|
c326136bdb | ||
|
|
21c13835e6 | ||
|
|
deef3bd8b5 | ||
|
|
87afad29ce | ||
|
|
436233e735 | ||
|
|
6e367ddd74 | ||
|
|
fcdfaf5564 | ||
|
|
97884ae25b | ||
|
|
bc2ffef17e | ||
|
|
890c13d83a | ||
|
|
ec8d4b56b5 | ||
|
|
99cdfbc07b | ||
|
|
71efde08a8 | ||
|
|
678cef0a45 | ||
|
|
57f1a48602 | ||
|
|
f5eb1619ed | ||
|
|
032ed27c38 | ||
|
|
78f8407eca | ||
|
|
9a22001289 | ||
|
|
8e08b5003e | ||
|
|
e545c8b897 | ||
|
|
092a265e6d | ||
|
|
dc1f494e92 | ||
|
|
dff17fd11f | ||
|
|
7b702e98da | ||
|
|
17d07f3b14 | ||
|
|
a21087ac9b | ||
|
|
0af1eebd62 | ||
|
|
85af73df99 | ||
|
|
c7a97711c0 | ||
|
|
ffbe05b2ae | ||
|
|
39169d3afe | ||
|
|
c89ba12fb5 | ||
|
|
8fdec72f8d | ||
|
|
13119c95ac | ||
|
|
c70ecd9cfd | ||
|
|
6c43881cf4 | ||
|
|
14f5d5daa4 | ||
|
|
f342cd6b56 | ||
|
|
57929f62ad | ||
|
|
523ee1e2a9 | ||
|
|
8b0f221eef | ||
|
|
656405edbc | ||
|
|
407c04fe2c | ||
|
|
3866d126b7 | ||
|
|
bdf836b7d9 | ||
|
|
997de528b8 | ||
|
|
8faacab53a | ||
|
|
659c327a6d | ||
|
|
bcc2f531c3 | ||
|
|
020df5c1f7 | ||
|
|
0d8e4dee35 | ||
|
|
d6781e1d14 | ||
|
|
c313184666 | ||
|
|
ea3b43ba88 | ||
|
|
0eebddb24c | ||
|
|
d42cd59880 | ||
|
|
6eb859b9f1 | ||
|
|
19f1322246 | ||
|
|
38f45ad483 | ||
|
|
7f46ff6d72 | ||
|
|
be19c32fea | ||
|
|
8da0e98d23 | ||
|
|
73a2f05509 | ||
|
|
bb23f998e0 | ||
|
|
75915ff366 | ||
|
|
517e801580 | ||
|
|
12474e23f9 | ||
|
|
00bdd859a7 | ||
|
|
3a3af9ea00 | ||
|
|
b9244bd11a | ||
|
|
532ec0129a | ||
|
|
464e47d6ad | ||
|
|
2bbdd3f044 | ||
|
|
0757a31381 | ||
|
|
1803b1a2ee | ||
|
|
36634414bc | ||
|
|
802448cb5a | ||
|
|
8ab9b4d1c3 | ||
|
|
02fa33597a | ||
|
|
5edfda6c1a | ||
|
|
5a565a16fe | ||
|
|
652ef7ee51 | ||
|
|
fb47480fba | ||
|
|
fc3ec644b3 | ||
|
|
9f21f5900f | ||
|
|
11710d36d1 | ||
|
|
a975ab58ee | ||
|
|
1306882377 | ||
|
|
b555e24fef | ||
|
|
b8250d5e44 | ||
|
|
4175c84363 | ||
|
|
9917787d6f | ||
|
|
d189e09aba | ||
|
|
7ff20245b3 | ||
|
|
da1696a059 | ||
|
|
e6202103bc | ||
|
|
7c659371a9 | ||
|
|
83886362be | ||
|
|
70de4f750c | ||
|
|
af901baff3 | ||
|
|
d69f4bbcaf | ||
|
|
089e3dc209 | ||
|
|
c158c4e18e | ||
|
|
300d365d8b | ||
|
|
81df005655 | ||
|
|
feb19c4eb5 | ||
|
|
9360787897 | ||
|
|
ac79557e22 | ||
|
|
c9695b1d2f | ||
|
|
27177996d3 | ||
|
|
2306330fd0 | ||
|
|
0d1e85d0c2 | ||
|
|
3b5a305122 | ||
|
|
1840d7b50e | ||
|
|
37b69833b3 | ||
|
|
093f766d1d | ||
|
|
69d8459b1c | ||
|
|
fa8a526642 | ||
|
|
1d35d951e6 | ||
|
|
3c0420f42f | ||
|
|
d000a825d3 | ||
|
|
23b28672d4 | ||
|
|
a076c9f420 | ||
|
|
e1db294b07 | ||
|
|
2004c3a7d5 | ||
|
|
44ac5270e0 | ||
|
|
bdc7a8f5ed | ||
|
|
f9baa4a8ad | ||
|
|
9c94a273ea | ||
|
|
efffbab4a7 | ||
|
|
7b53468c2e | ||
|
|
59243be030 | ||
|
|
57c1d070d1 | ||
|
|
5b2f2b0fd7 | ||
|
|
bdcc3bb1f5 | ||
|
|
18d45aa1a3 | ||
|
|
b5bb8efe0a | ||
|
|
f18c18230b | ||
|
|
1a83d21410 | ||
|
|
094cebe674 | ||
|
|
3963099053 | ||
|
|
f3181cc0f1 | ||
|
|
2fd1e998f4 | ||
|
|
c5a1980e0d | ||
|
|
008863fee8 | ||
|
|
d470ca4b47 | ||
|
|
35f450e444 | ||
|
|
206fb4e584 | ||
|
|
62088b36a4 | ||
|
|
aa5fd530d3 | ||
|
|
f0ee64bafa | ||
|
|
dfa413da6f | ||
|
|
9eb5e699e1 | ||
|
|
1927008c2e | ||
|
|
5d0dac6947 | ||
|
|
71351ad701 | ||
|
|
abf5c8fb3c | ||
|
|
865311d864 | ||
|
|
4e8b8e0bc2 | ||
|
|
c0fbf846bd | ||
|
|
2d4c1b751e | ||
|
|
91b17ef4a2 | ||
|
|
9b748f7334 | ||
|
|
517f2bcee7 | ||
|
|
4607e5ba0f | ||
|
|
29c82177a9 | ||
|
|
69a0c779d9 | ||
|
|
2deaed2067 | ||
|
|
3be9def609 | ||
|
|
bd3d800cde | ||
|
|
cef2449d45 | ||
|
|
8d894c97f3 | ||
|
|
0e1b5b19d2 | ||
|
|
2595c11686 | ||
|
|
334e08730e | ||
|
|
d6ff996dbe | ||
|
|
3040b89a9e | ||
|
|
aed180c845 | ||
|
|
4ba1e2f661 | ||
|
|
8b3ef3a3f3 | ||
|
|
b293fee742 | ||
|
|
fb608ed30a | ||
|
|
2654de96ba | ||
|
|
8e43afe408 | ||
|
|
e2aea345d4 | ||
|
|
78295898cb | ||
|
|
4fcdd9f370 | ||
|
|
73df680214 | ||
|
|
fa4aa154a3 | ||
|
|
cf7cdbc41b | ||
|
|
c2561a1de0 | ||
|
|
a36abe0272 | ||
|
|
5b10d697f6 | ||
|
|
e0f07ccc3b | ||
|
|
938ea8fb73 | ||
|
|
ea6a338128 | ||
|
|
9c66f74a5b | ||
|
|
9dc3ad38fc | ||
|
|
9599cdd2f6 | ||
|
|
4e5becb647 | ||
|
|
1d15a64945 | ||
|
|
21891d2d9d | ||
|
|
5b066c9dde | ||
|
|
e4668cf938 | ||
|
|
3978ebc230 | ||
|
|
4402db33fd | ||
|
|
3511c02c69 | ||
|
|
12be24c050 | ||
|
|
ce3a668103 | ||
|
|
80db7f0b74 | ||
|
|
451b9fc0f1 | ||
|
|
e2ed7f0d77 | ||
|
|
4743f40154 | ||
|
|
53f127987c | ||
|
|
f6c6111459 | ||
|
|
f5dd1c39ce | ||
|
|
b519b53419 | ||
|
|
c5de765e52 | ||
|
|
1381a7d957 | ||
|
|
602a5eb2ab | ||
|
|
7d41318d15 | ||
|
|
dd8cb8dfd0 | ||
|
|
557c2b018a | ||
|
|
3add01d57e | ||
|
|
2ad1ea98f1 | ||
|
|
cfc317cf19 | ||
|
|
242704f853 | ||
|
|
6df56c2d77 | ||
|
|
49634a2f52 | ||
|
|
b7442fe445 | ||
|
|
3121532217 | ||
|
|
20ac12ca0d | ||
|
|
f0b222140e | ||
|
|
2a35ca6094 | ||
|
|
b9428e3898 | ||
|
|
93f9636916 | ||
|
|
6a8a6a08db | ||
|
|
2c24aba558 | ||
|
|
c4b03d1316 | ||
|
|
5d54298a22 | ||
|
|
11e9f1749a | ||
|
|
09105152e4 | ||
|
|
a2b8cfe512 | ||
|
|
f42f244443 | ||
|
|
b81aeaebd3 | ||
|
|
e0d93b0630 | ||
|
|
e4a2897731 | ||
|
|
eda72128da | ||
|
|
ebdc2dfb0e | ||
|
|
0eff85dca3 | ||
|
|
da5796b563 | ||
|
|
310d4e58bb | ||
|
|
455351e3a8 | ||
|
|
b4f2b82a0d | ||
|
|
0e7960fced | ||
|
|
1d2584001f | ||
|
|
d5216e3784 | ||
|
|
bd29c64370 | ||
|
|
a9f3ab259a | ||
|
|
318486d62b | ||
|
|
f5db5c39c3 | ||
|
|
7bc945b243 | ||
|
|
d31d302896 | ||
|
|
1be8760c00 | ||
|
|
32836d05d8 | ||
|
|
1a6b4ae795 | ||
|
|
fbc86f6d3b | ||
|
|
00e1aac984 | ||
|
|
830cc66933 | ||
|
|
8869bafe9e | ||
|
|
6ea98fa056 | ||
|
|
837fb91133 |
@@ -5,15 +5,16 @@ charset = utf-8
|
|||||||
end_of_line = lf
|
end_of_line = lf
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
insert_final_newline = false
|
insert_final_newline = true
|
||||||
max_line_length = 120
|
max_line_length = 120
|
||||||
tab_width = 4
|
tab_width = 4
|
||||||
# noinspection EditorConfigKeyCorrectness
|
# noinspection EditorConfigKeyCorrectness
|
||||||
disabled_rules=no-wildcard-imports,no-unused-imports
|
disabled_rules = no-wildcard-imports, no-unused-imports
|
||||||
|
|
||||||
[{*.ant,*.fxml,*.jhm,*.jnlp,*.jrxml,*.rng,*.tld,*.wsdl,*.xml,*.xsd,*.xsl,*.xslt,*.xul}]
|
[{*.ant,*.fxml,*.jhm,*.jnlp,*.jrxml,*.rng,*.tld,*.wsdl,*.xml,*.xsd,*.xsl,*.xslt,*.xul}]
|
||||||
ij_continuation_indent_size = 4
|
ij_continuation_indent_size = 4
|
||||||
|
|
||||||
[{*.kt,*.kts}]
|
[{*.kt,*.kts}]
|
||||||
|
ij_kotlin_allow_trailing_comma_on_call_site = true
|
||||||
ij_kotlin_allow_trailing_comma = true
|
ij_kotlin_allow_trailing_comma = true
|
||||||
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
|
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
|
||||||
|
|||||||
1
.github/FUNDING.yml
vendored
@@ -1 +1,2 @@
|
|||||||
|
ko_fi: xtimms
|
||||||
custom: ["https://yoomoney.ru/to/410012543938752"]
|
custom: ["https://yoomoney.ru/to/410012543938752"]
|
||||||
|
|||||||
2
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -2,4 +2,4 @@ blank_issues_enabled: false
|
|||||||
contact_links:
|
contact_links:
|
||||||
- name: ⚠️ Source issue
|
- name: ⚠️ Source issue
|
||||||
url: https://github.com/KotatsuApp/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
|
||||||
64
.github/ISSUE_TEMPLATE/report_bug.yml
vendored
Normal file
@@ -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
|
||||||
91
.github/ISSUE_TEMPLATE/report_issue.yml
vendored
@@ -1,91 +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.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/KotatsuApp/kotatsu-parsers/issues/new).
|
|
||||||
required: true
|
|
||||||
- label: I will fill out all of the requested information in this form.
|
|
||||||
required: true
|
|
||||||
25
.github/ISSUE_TEMPLATE/request_feature.yml
vendored
@@ -1,5 +1,5 @@
|
|||||||
name: ⭐ Feature request
|
name: ⭐ Feature request
|
||||||
description: Suggest a feature to improve Kotatsu
|
description: Suggest a new idea how to improve Kotatsu
|
||||||
labels: [feature request]
|
labels: [feature request]
|
||||||
body:
|
body:
|
||||||
|
|
||||||
@@ -14,23 +14,6 @@ body:
|
|||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
|
|
||||||
- type: textarea
|
|
||||||
id: other-details
|
|
||||||
attributes:
|
|
||||||
label: Other details
|
|
||||||
placeholder: |
|
|
||||||
Additional details and attachments.
|
|
||||||
|
|
||||||
- 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: checkboxes
|
- type: checkboxes
|
||||||
id: acknowledgements
|
id: acknowledgements
|
||||||
attributes:
|
attributes:
|
||||||
@@ -38,10 +21,4 @@ body:
|
|||||||
description: Read this carefully, we will close and ignore your issue if you skimmed through this.
|
description: Read this carefully, we will close and ignore your issue if you skimmed through this.
|
||||||
options:
|
options:
|
||||||
- label: I have searched the existing issues and this is a new ticket, **NOT** a duplicate or related to another open issue.
|
- 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/KotatsuApp/kotatsu-parsers/issues/new).
|
|
||||||
required: true
|
|
||||||
- label: I will fill out all of the requested information in this form.
|
|
||||||
required: true
|
required: true
|
||||||
3
.gitignore
vendored
@@ -7,13 +7,16 @@
|
|||||||
/.idea/modules.xml
|
/.idea/modules.xml
|
||||||
/.idea/misc.xml
|
/.idea/misc.xml
|
||||||
/.idea/discord.xml
|
/.idea/discord.xml
|
||||||
|
/.idea/compiler.xml
|
||||||
/.idea/workspace.xml
|
/.idea/workspace.xml
|
||||||
/.idea/navEditor.xml
|
/.idea/navEditor.xml
|
||||||
/.idea/assetWizardSettings.xml
|
/.idea/assetWizardSettings.xml
|
||||||
/.idea/kotlinScripting.xml
|
/.idea/kotlinScripting.xml
|
||||||
|
/.idea/kotlinc.xml
|
||||||
/.idea/deploymentTargetDropDown.xml
|
/.idea/deploymentTargetDropDown.xml
|
||||||
/.idea/androidTestResultsUserPreferences.xml
|
/.idea/androidTestResultsUserPreferences.xml
|
||||||
/.idea/render.experimental.xml
|
/.idea/render.experimental.xml
|
||||||
|
/.idea/inspectionProfiles/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/build
|
/build
|
||||||
/captures
|
/captures
|
||||||
|
|||||||
3
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
6
.idea/compiler.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<bytecodeTargetLevel target="11" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
2
.idea/gradle.xml
generated
@@ -7,7 +7,7 @@
|
|||||||
<option name="testRunner" value="GRADLE" />
|
<option name="testRunner" value="GRADLE" />
|
||||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="gradleJvm" value="Embedded JDK" />
|
<option name="gradleJvm" value="jbr-17" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
|
|||||||
14
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -1,14 +0,0 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<profile version="1.0">
|
|
||||||
<option name="myName" value="Project Default" />
|
|
||||||
<inspection_tool class="BooleanLiteralArgument" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
|
||||||
<inspection_tool class="Destructure" enabled="true" level="INFO" enabled_by_default="true" />
|
|
||||||
<inspection_tool class="KeySetIterationMayUseEntrySet" enabled="true" level="WARNING" enabled_by_default="true" />
|
|
||||||
<inspection_tool class="KotlinFunctionArgumentsHelper" enabled="true" level="INFORMATION" enabled_by_default="true">
|
|
||||||
<option name="withoutDefaultValues" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="ReplaceCollectionCountWithSize" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
|
||||||
<inspection_tool class="TrailingComma" enabled="true" level="INFORMATION" enabled_by_default="true" />
|
|
||||||
<inspection_tool class="ZeroLengthArrayInitialization" enabled="true" level="WARNING" enabled_by_default="true" />
|
|
||||||
</profile>
|
|
||||||
</component>
|
|
||||||
6
.idea/kotlinc.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Kotlin2JvmCompilerArguments">
|
|
||||||
<option name="jvmTarget" value="1.8" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
6
.idea/ktlint.xml
generated
@@ -1,7 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="KtlintProjectConfiguration">
|
<component name="KtlintProjectConfiguration">
|
||||||
|
<enableKtlint>false</enableKtlint>
|
||||||
<androidMode>true</androidMode>
|
<androidMode>true</androidMode>
|
||||||
<treatAsErrors>false</treatAsErrors>
|
<treatAsErrors>false</treatAsErrors>
|
||||||
|
<disabledRules>
|
||||||
|
<list>
|
||||||
|
<option value="no-empty-first-line-in-method-block" />
|
||||||
|
</list>
|
||||||
|
</disabledRules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
32
README.md
@@ -10,22 +10,23 @@ Kotatsu is a free and open source manga reader for Android.
|
|||||||
alt="Get it on F-Droid"
|
alt="Get it on F-Droid"
|
||||||
height="80">](https://f-droid.org/packages/org.koitharu.kotatsu)
|
height="80">](https://f-droid.org/packages/org.koitharu.kotatsu)
|
||||||
|
|
||||||
Download APK from GitHub Releases:
|
Download APK directly from GitHub:
|
||||||
|
|
||||||
- [Latest release](https://github.com/KotatsuApp/Kotatsu/releases/latest)
|
- **[Latest release](https://github.com/KotatsuApp/Kotatsu/releases/latest)**
|
||||||
|
|
||||||
### Main Features
|
### Main Features
|
||||||
|
|
||||||
* Online manga catalogues
|
* Online [manga catalogues](https://github.com/KotatsuApp/kotatsu-parsers)
|
||||||
* Search manga by name and genres
|
* Search manga by name and genres
|
||||||
* Reading history and bookmarks
|
* Reading history and bookmarks
|
||||||
* Favourites organized by user-defined categories
|
* Favourites organized by user-defined categories
|
||||||
* Downloading manga and reading it offline. Third-party CBZ archives also supported
|
* Downloading manga and reading it offline. Third-party CBZ archives also supported
|
||||||
* Tablet-optimized material design UI
|
* Tablet-optimized Material You UI
|
||||||
* Standard and Webtoon-optimized reader
|
* Standard and Webtoon-optimized reader
|
||||||
* Notifications about new chapters with updates feed
|
* Notifications about new chapters with updates feed
|
||||||
* Available in multiple languages
|
* Integration with manga tracking services: Shikimori, AniList, MyAnimeList
|
||||||
* Password protect access to the app
|
* Password/fingerprint protect access to the app
|
||||||
|
* History and favourites [synchronization](https://github.com/KotatsuApp/kotatsu-syncserver) across devices
|
||||||
|
|
||||||
### Screenshots
|
### Screenshots
|
||||||
|
|
||||||
@@ -38,23 +39,20 @@ Download APK from GitHub Releases:
|
|||||||
|
|
||||||
### Localization
|
### Localization
|
||||||
|
|
||||||
<a href="https://hosted.weblate.org/engage/kotatsu/">
|
[<img src="https://hosted.weblate.org/widgets/kotatsu/-/287x66-white.png" alt="Translation status">](https://hosted.weblate.org/engage/kotatsu/)
|
||||||
<img src="https://hosted.weblate.org/widgets/kotatsu/-/287x66-white.png" alt="Translation status" />
|
|
||||||
</a>
|
|
||||||
|
|
||||||
Kotatsu is localized in a number of different languages, if you would like to help improve these or add new languages,
|
Kotatsu is localized in a number of different languages, if you would like to help improve these or add new languages,
|
||||||
please head over to the Weblate <a href="https://hosted.weblate.org/engage/kotatsu/">project page</a>
|
please head over to the [Weblate project page](https://hosted.weblate.org/engage/kotatsu/)
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
||||||
[](http://www.gnu.org/licenses/gpl-3.0.en.html)
|
[](http://www.gnu.org/licenses/gpl-3.0.en.html)
|
||||||
|
|
||||||
Kotatsu is Free Software: You can use, study share and improve it at your
|
You may copy, distribute and modify the software as long as you track changes/dates in source files. Any modifications
|
||||||
will. Specifically you can redistribute and/or modify it under the terms of the
|
to or software including (via compiler) GPL-licensed code must also be made available under the GPL along with build &
|
||||||
[GNU General Public License](https://www.gnu.org/licenses/gpl.html) as
|
install instructions.
|
||||||
published by the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
### Disclaimer
|
### DMCA disclaimer
|
||||||
|
|
||||||
The developers of this application does not have any affiliation with the content providers available.
|
The developers of this application does not have any affiliation with the content available in the app.
|
||||||
|
It is collecting from the sources freely available through any web browser.
|
||||||
|
|||||||
109
app/build.gradle
@@ -3,19 +3,20 @@ plugins {
|
|||||||
id 'kotlin-android'
|
id 'kotlin-android'
|
||||||
id 'kotlin-kapt'
|
id 'kotlin-kapt'
|
||||||
id 'kotlin-parcelize'
|
id 'kotlin-parcelize'
|
||||||
|
id 'dagger.hilt.android.plugin'
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 32
|
compileSdk = 33
|
||||||
buildToolsVersion '32.0.0'
|
buildToolsVersion = '33.0.2'
|
||||||
namespace 'org.koitharu.kotatsu'
|
namespace = 'org.koitharu.kotatsu'
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId 'org.koitharu.kotatsu'
|
applicationId 'org.koitharu.kotatsu'
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 32
|
targetSdkVersion 33
|
||||||
versionCode 412
|
versionCode 523
|
||||||
versionName '3.4'
|
versionName '4.4.7'
|
||||||
generatedDensities = []
|
generatedDensities = []
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
@@ -24,10 +25,6 @@ android {
|
|||||||
arg 'room.schemaLocation', "$projectDir/schemas".toString()
|
arg 'room.schemaLocation', "$projectDir/schemas".toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// define this values in your local.properties file
|
|
||||||
buildConfigField 'String', 'SHIKIMORI_CLIENT_ID', "\"${localProperty('shikimori.clientId')}\""
|
|
||||||
buildConfigField 'String', 'SHIKIMORI_CLIENT_SECRET', "\"${localProperty('shikimori.clientSecret')}\""
|
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
debug {
|
debug {
|
||||||
@@ -53,19 +50,24 @@ android {
|
|||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
||||||
freeCompilerArgs += [
|
freeCompilerArgs += [
|
||||||
|
'-opt-in=kotlin.ExperimentalStdlibApi',
|
||||||
'-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
|
'-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
|
||||||
'-opt-in=kotlinx.coroutines.FlowPreview',
|
'-opt-in=kotlinx.coroutines.FlowPreview',
|
||||||
'-opt-in=kotlin.contracts.ExperimentalContracts',
|
'-opt-in=kotlin.contracts.ExperimentalContracts',
|
||||||
'-opt-in=coil.annotation.ExperimentalCoilApi',
|
'-opt-in=coil.annotation.ExperimentalCoilApi',
|
||||||
|
'-opt-in=com.google.android.material.badge.ExperimentalBadgeUtils',
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
lint {
|
lint {
|
||||||
abortOnError false
|
abortOnError true
|
||||||
disable 'MissingTranslation', 'PrivateResource', 'NotifyDataSetChanged'
|
disable 'MissingTranslation', 'PrivateResource', 'NotifyDataSetChanged'
|
||||||
}
|
}
|
||||||
testOptions {
|
testOptions {
|
||||||
unitTests.includeAndroidResources = true
|
unitTests.includeAndroidResources true
|
||||||
unitTests.returnDefaultValues = false
|
unitTests.returnDefaultValues false
|
||||||
|
kotlinOptions {
|
||||||
|
freeCompilerArgs += ['-opt-in=org.koitharu.kotatsu.parsers.InternalParsersApi']
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
@@ -76,65 +78,74 @@ afterEvaluate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
|
//noinspection GradleDependency
|
||||||
implementation('com.github.nv95:kotatsu-parsers:da3b0ae0cf') {
|
implementation('com.github.KotatsuApp:kotatsu-parsers:a3ffecc00f') {
|
||||||
exclude group: 'org.json', module: 'json'
|
exclude group: 'org.json', module: 'json'
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.3'
|
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.10'
|
||||||
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
|
||||||
|
|
||||||
implementation 'androidx.core:core-ktx:1.8.0'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'androidx.activity:activity-ktx:1.5.0'
|
implementation 'androidx.core:core-ktx:1.9.0'
|
||||||
implementation 'androidx.fragment:fragment-ktx:1.5.0'
|
implementation 'androidx.activity:activity-ktx:1.6.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.0'
|
implementation 'androidx.fragment:fragment-ktx:1.5.5'
|
||||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.0'
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-service:2.5.0'
|
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-process:2.5.0'
|
implementation 'androidx.lifecycle:lifecycle-service:2.5.1'
|
||||||
|
implementation 'androidx.lifecycle:lifecycle-process:2.5.1'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
||||||
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
||||||
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01'
|
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01'
|
||||||
implementation 'androidx.preference:preference-ktx:1.2.0'
|
implementation 'androidx.preference:preference-ktx:1.2.0'
|
||||||
implementation 'androidx.work:work-runtime-ktx:2.7.1'
|
implementation 'androidx.work:work-runtime-ktx:2.8.0'
|
||||||
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha04'
|
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05'
|
||||||
implementation 'com.google.android.material:material:1.7.0-alpha02'
|
implementation 'com.google.android.material:material:1.8.0'
|
||||||
//noinspection LifecycleAnnotationProcessorWithJava8
|
//noinspection LifecycleAnnotationProcessorWithJava8
|
||||||
kapt 'androidx.lifecycle:lifecycle-compiler:2.5.0'
|
kapt 'androidx.lifecycle:lifecycle-compiler:2.5.1'
|
||||||
|
|
||||||
implementation 'androidx.room:room-runtime:2.4.2'
|
implementation 'androidx.room:room-runtime:2.5.0'
|
||||||
implementation 'androidx.room:room-ktx:2.4.2'
|
implementation 'androidx.room:room-ktx:2.5.0'
|
||||||
kapt 'androidx.room:room-compiler:2.4.2'
|
kapt 'androidx.room:room-compiler:2.5.0'
|
||||||
|
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
|
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
|
||||||
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.3'
|
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.3'
|
||||||
implementation 'com.squareup.okio:okio:3.2.0'
|
implementation 'com.squareup.okio:okio:3.3.0'
|
||||||
|
|
||||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
|
||||||
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.2'
|
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl-viewbinding:4.3.2'
|
||||||
|
|
||||||
implementation 'io.insert-koin:koin-android:3.2.0'
|
implementation 'com.google.dagger:hilt-android:2.45'
|
||||||
implementation 'io.coil-kt:coil-base:2.1.0'
|
kapt 'com.google.dagger:hilt-compiler:2.45'
|
||||||
implementation 'com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0'
|
implementation 'androidx.hilt:hilt-work:1.0.0'
|
||||||
|
kapt 'androidx.hilt:hilt-compiler:1.0.0'
|
||||||
|
|
||||||
|
implementation 'io.coil-kt:coil-base:2.2.2'
|
||||||
|
implementation 'io.coil-kt:coil-svg:2.2.2'
|
||||||
|
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:1b19231b2f'
|
||||||
implementation 'com.github.solkin:disk-lru-cache:1.4'
|
implementation 'com.github.solkin:disk-lru-cache:1.4'
|
||||||
|
implementation 'io.noties.markwon:core:4.6.2'
|
||||||
|
|
||||||
implementation 'ch.acra:acra-mail:5.9.3'
|
implementation 'ch.acra:acra-http:5.9.7'
|
||||||
implementation 'ch.acra:acra-dialog:5.9.3'
|
implementation 'ch.acra:acra-dialog:5.9.7'
|
||||||
|
|
||||||
debugImplementation 'org.jsoup:jsoup:1.15.1'
|
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10'
|
||||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
|
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.3'
|
testImplementation 'org.json:json:20230227'
|
||||||
|
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
|
||||||
|
|
||||||
androidTestImplementation 'androidx.test:runner:1.4.0'
|
androidTestImplementation 'androidx.test:runner:1.5.2'
|
||||||
androidTestImplementation 'androidx.test:rules:1.4.0'
|
androidTestImplementation 'androidx.test:rules:1.5.0'
|
||||||
androidTestImplementation 'androidx.test:core-ktx:1.4.0'
|
androidTestImplementation 'androidx.test:core-ktx:1.5.0'
|
||||||
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.3'
|
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.5'
|
||||||
|
|
||||||
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.3'
|
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
|
||||||
androidTestImplementation 'io.insert-koin:koin-test:3.2.0'
|
|
||||||
androidTestImplementation 'io.insert-koin:koin-test-junit4:3.2.0'
|
|
||||||
|
|
||||||
androidTestImplementation 'androidx.room:room-testing:2.4.2'
|
androidTestImplementation 'androidx.room:room-testing:2.5.0'
|
||||||
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.13.0'
|
androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.14.0'
|
||||||
}
|
|
||||||
|
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.45'
|
||||||
|
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.45'
|
||||||
|
}
|
||||||
|
|||||||
6
app/proguard-rules.pro
vendored
@@ -10,4 +10,8 @@
|
|||||||
}
|
}
|
||||||
-keep public class ** extends org.koitharu.kotatsu.base.ui.BaseFragment
|
-keep public class ** extends org.koitharu.kotatsu.base.ui.BaseFragment
|
||||||
-keep class org.koitharu.kotatsu.core.db.entity.* { *; }
|
-keep class org.koitharu.kotatsu.core.db.entity.* { *; }
|
||||||
-dontwarn okhttp3.internal.platform.ConscryptPlatform
|
-dontwarn okhttp3.internal.platform.ConscryptPlatform
|
||||||
|
|
||||||
|
-keep class org.koitharu.kotatsu.core.exceptions.* { *; }
|
||||||
|
-keep class org.koitharu.kotatsu.settings.NotificationSettingsLegacyFragment
|
||||||
|
-keep class org.koitharu.kotatsu.core.prefs.ScreenshotsPolicy { *; }
|
||||||
|
|||||||
BIN
app/sampledata/covers/Forget-me-not Volume 1.jpg
Normal file
|
After Width: | Height: | Size: 213 KiB |
BIN
app/sampledata/covers/Forget-me-not Volume 2.jpg
Normal file
|
After Width: | Height: | Size: 131 KiB |
BIN
app/sampledata/covers/La Pomme Prisoinniere.jpg
Normal file
|
After Width: | Height: | Size: 439 KiB |
BIN
app/sampledata/covers/Momo Kanchou no Himitsu Kichi.jpg
Normal file
|
After Width: | Height: | Size: 495 KiB |
BIN
app/sampledata/covers/Omoide Emanon.jpg
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
app/sampledata/covers/Sasurai Emanon Volume 1.jpg
Normal file
|
After Width: | Height: | Size: 791 KiB |
BIN
app/sampledata/covers/Sasurai Emanon Volume 2.jpg
Normal file
|
After Width: | Height: | Size: 844 KiB |
BIN
app/sampledata/covers/Sasurai Emanon Volume 3.jpg
Normal file
|
After Width: | Height: | Size: 386 KiB |
BIN
app/sampledata/covers/Wandering Island Volume 1.jpg
Normal file
|
After Width: | Height: | Size: 375 KiB |
BIN
app/sampledata/covers/Wandering Island Volume 2.jpg
Normal file
|
After Width: | Height: | Size: 398 KiB |
10
app/sampledata/genres
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
Slice of Life, Mystery
|
||||||
|
Slice of Life, Mystery
|
||||||
|
Psychological, Romance, Comedy, Slice of Life, Supernatural
|
||||||
|
Sci-Fi, Comedy
|
||||||
|
Reincarnation, Sci-Fi, Historical, Psychological, Drama, Slice of Life, Supernatural, Mystery
|
||||||
|
Reincarnation, Sci-Fi, Historical, Psychological, Drama, Slice of Life, Supernatural, Mystery
|
||||||
|
Reincarnation, Sci-Fi, Historical, Psychological, Drama, Slice of Life, Supernatural, Mystery
|
||||||
|
Reincarnation, Sci-Fi, Historical, Psychological, Drama, Slice of Life, Supernatural, Mystery
|
||||||
|
Adventure, Slice of Life, Mystery
|
||||||
|
Adventure, Slice of Life, Mystery
|
||||||
10
app/sampledata/titles
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
Forget-me-not Vol. 1
|
||||||
|
Forget-me-not Vol. 2
|
||||||
|
La Pomme Prisoinniere
|
||||||
|
Momo Kanchou no Himitsu Kichi
|
||||||
|
Omoide Emanon
|
||||||
|
Sasurai Emanon Vol. 1
|
||||||
|
Sasurai Emanon Vol. 2
|
||||||
|
Sasurai Emanon Vol. 3
|
||||||
|
Wandering Island Vol. 1
|
||||||
|
Wandering Island Vol. 2
|
||||||
9
app/src/androidTest/assets/categories/simple.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"id": 4,
|
||||||
|
"title": "Read later",
|
||||||
|
"sortKey": 1,
|
||||||
|
"order": "NEWEST",
|
||||||
|
"createdAt": 1335906000000,
|
||||||
|
"isTrackingEnabled": true,
|
||||||
|
"isVisibleInLibrary": true
|
||||||
|
}
|
||||||
BIN
app/src/androidTest/assets/kotatsu_test.bak
Executable file
35
app/src/androidTest/assets/manga/header.json
Normal file
@@ -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) }
|
||||||
|
}
|
||||||
54
app/src/androidTest/java/org/koitharu/kotatsu/SampleData.kt
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,10 @@ package org.koitharu.kotatsu.core.db
|
|||||||
import androidx.room.testing.MigrationTestHelper
|
import androidx.room.testing.MigrationTestHelper
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import java.io.IOException
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.koitharu.kotatsu.core.db.migrations.*
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
class MangaDatabaseTest {
|
class MangaDatabaseTest {
|
||||||
@@ -18,38 +17,41 @@ class MangaDatabaseTest {
|
|||||||
MangaDatabase::class.java,
|
MangaDatabase::class.java,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val migrations = databaseMigrations
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(IOException::class)
|
fun versions() {
|
||||||
fun migrateAll() {
|
assertEquals(1, migrations.first().startVersion)
|
||||||
helper.createDatabase(TEST_DB, 1).apply {
|
repeat(migrations.size) { i ->
|
||||||
// TODO execSQL("")
|
assertEquals(i + 1, migrations[i].startVersion)
|
||||||
close()
|
assertEquals(i + 2, migrations[i].endVersion)
|
||||||
}
|
}
|
||||||
|
assertEquals(DATABASE_VERSION, migrations.last().endVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun migrateAll() {
|
||||||
|
helper.createDatabase(TEST_DB, 1).close()
|
||||||
for (migration in migrations) {
|
for (migration in migrations) {
|
||||||
helper.runMigrationsAndValidate(
|
helper.runMigrationsAndValidate(
|
||||||
TEST_DB,
|
TEST_DB,
|
||||||
migration.endVersion,
|
migration.endVersion,
|
||||||
true,
|
true,
|
||||||
migration
|
migration,
|
||||||
)
|
).close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun prePopulate() {
|
||||||
|
val resources = InstrumentationRegistry.getInstrumentation().targetContext.resources
|
||||||
|
helper.createDatabase(TEST_DB, DATABASE_VERSION).use {
|
||||||
|
DatabasePrePopulateCallback(resources).onCreate(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
|
|
||||||
const val TEST_DB = "test-db"
|
const val TEST_DB = "test-db"
|
||||||
|
|
||||||
val migrations = arrayOf(
|
|
||||||
Migration1To2(),
|
|
||||||
Migration2To3(),
|
|
||||||
Migration3To4(),
|
|
||||||
Migration4To5(),
|
|
||||||
Migration5To6(),
|
|
||||||
Migration6To7(),
|
|
||||||
Migration7To8(),
|
|
||||||
Migration8To9(),
|
|
||||||
Migration9To10(),
|
|
||||||
Migration10To11(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
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 dagger.hilt.android.testing.HiltAndroidRule
|
||||||
|
import dagger.hilt.android.testing.HiltAndroidTest
|
||||||
|
import javax.inject.Inject
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.koitharu.kotatsu.SampleData
|
||||||
|
import org.koitharu.kotatsu.awaitForIdle
|
||||||
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
|
|
||||||
|
@HiltAndroidTest
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class ShortcutsUpdaterTest {
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
var hiltRule = HiltAndroidRule(this)
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var historyRepository: HistoryRepository
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var shortcutsUpdater: ShortcutsUpdater
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var database: MangaDatabase
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
hiltRule.inject()
|
||||||
|
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,108 @@
|
|||||||
|
package org.koitharu.kotatsu.settings.backup
|
||||||
|
|
||||||
|
import android.content.res.AssetManager
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
|
import dagger.hilt.android.testing.HiltAndroidRule
|
||||||
|
import dagger.hilt.android.testing.HiltAndroidTest
|
||||||
|
import java.io.File
|
||||||
|
import javax.inject.Inject
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.junit.Assert.*
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
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
|
||||||
|
|
||||||
|
@HiltAndroidTest
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class AppBackupAgentTest {
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
var hiltRule = HiltAndroidRule(this)
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var historyRepository: HistoryRepository
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var favouritesRepository: FavouritesRepository
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var backupRepository: BackupRepository
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var database: MangaDatabase
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
hiltRule.inject()
|
||||||
|
database.clearAllTables()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun backupAndRestore() = 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(
|
||||||
|
context = InstrumentationRegistry.getInstrumentation().targetContext,
|
||||||
|
repository = 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))
|
||||||
|
assertEquals(listOf(SampleData.manga), favouritesRepository.getManga(category.id))
|
||||||
|
|
||||||
|
val allTags = database.tagsDao.findTags(SampleData.tag.source.name).toMangaTags()
|
||||||
|
assertTrue(SampleData.tag in allTags)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun restoreOldBackup() {
|
||||||
|
val agent = AppBackupAgent()
|
||||||
|
val backup = File.createTempFile("backup_", ".tmp")
|
||||||
|
InstrumentationRegistry.getInstrumentation().context.assets
|
||||||
|
.open("kotatsu_test.bak", AssetManager.ACCESS_STREAMING)
|
||||||
|
.use { input ->
|
||||||
|
backup.outputStream().use { output ->
|
||||||
|
input.copyTo(output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
backup.inputStream().use {
|
||||||
|
agent.restoreBackupFile(it.fd, backup.length(), backupRepository)
|
||||||
|
}
|
||||||
|
runTest {
|
||||||
|
assertEquals(6, historyRepository.observeAll().first().size)
|
||||||
|
assertEquals(2, favouritesRepository.observeCategories().first().size)
|
||||||
|
assertEquals(15, favouritesRepository.getAllManga().size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,32 +1,39 @@
|
|||||||
package org.koitharu.kotatsu.tracker.domain
|
package org.koitharu.kotatsu.tracker.domain
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import dagger.hilt.android.testing.HiltAndroidRule
|
||||||
import com.squareup.moshi.Moshi
|
import dagger.hilt.android.testing.HiltAndroidTest
|
||||||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
import javax.inject.Inject
|
||||||
import kotlin.test.assertEquals
|
import junit.framework.TestCase.*
|
||||||
import kotlin.test.assertFalse
|
|
||||||
import kotlin.test.assertTrue
|
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import okio.buffer
|
import org.junit.Before
|
||||||
import okio.source
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.koin.test.KoinTest
|
import org.koitharu.kotatsu.SampleData
|
||||||
import org.koin.test.inject
|
|
||||||
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
||||||
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
|
||||||
|
@HiltAndroidTest
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
class TrackerTest : KoinTest {
|
class TrackerTest {
|
||||||
|
|
||||||
private val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
|
@get:Rule
|
||||||
private val mangaAdapter = moshi.adapter(Manga::class.java)
|
var hiltRule = HiltAndroidRule(this)
|
||||||
private val historyRegistry by inject<HistoryRepository>()
|
|
||||||
private val repository by inject<TrackingRepository>()
|
@Inject
|
||||||
private val dataRepository by inject<MangaDataRepository>()
|
lateinit var repository: TrackingRepository
|
||||||
private val tracker by inject<Tracker>()
|
|
||||||
|
@Inject
|
||||||
|
lateinit var dataRepository: MangaDataRepository
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var tracker: Tracker
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
hiltRule.inject()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun noUpdates() = runTest {
|
fun noUpdates() = runTest {
|
||||||
@@ -166,23 +173,26 @@ class TrackerTest : KoinTest {
|
|||||||
}
|
}
|
||||||
assertEquals(3, repository.getNewChaptersCount(mangaFirst.id))
|
assertEquals(3, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
|
|
||||||
val chapter = requireNotNull(mangaFull.chapters).run { get(lastIndex - 1) }
|
var chapter = requireNotNull(mangaFull.chapters).run { get(lastIndex - 1) }
|
||||||
repository.syncWithHistory(mangaFull, chapter.id)
|
repository.syncWithHistory(mangaFull, chapter.id)
|
||||||
|
|
||||||
assertEquals(1, repository.getNewChaptersCount(mangaFirst.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 {
|
tracker.checkUpdates(mangaFull, commit = true).apply {
|
||||||
assertTrue(isValid)
|
assertTrue(isValid)
|
||||||
assert(newChapters.isEmpty())
|
assert(newChapters.isEmpty())
|
||||||
}
|
}
|
||||||
assertEquals(1, repository.getNewChaptersCount(mangaFirst.id))
|
assertEquals(0, repository.getNewChaptersCount(mangaFirst.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun loadManga(name: String): Manga {
|
private suspend fun loadManga(name: String): Manga {
|
||||||
val assets = InstrumentationRegistry.getInstrumentation().context.assets
|
val manga = SampleData.loadAsset("manga/$name", Manga::class)
|
||||||
val manga = assets.open("manga/$name").use {
|
|
||||||
mangaAdapter.fromJson(it.source().buffer())
|
|
||||||
} ?: throw RuntimeException("Cannot read manga from json \"$name\"")
|
|
||||||
dataRepository.storeManga(manga)
|
dataRepository.storeManga(manga)
|
||||||
return manga
|
return manga
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package org.koitharu.kotatsu.core.network
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import okhttp3.Interceptor
|
||||||
|
import okhttp3.Response
|
||||||
|
import okio.Buffer
|
||||||
|
import org.koitharu.kotatsu.core.network.CommonHeaders.ACCEPT_ENCODING
|
||||||
|
|
||||||
|
class CurlLoggingInterceptor(
|
||||||
|
private val curlOptions: String? = null
|
||||||
|
) : Interceptor {
|
||||||
|
|
||||||
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
|
val request = chain.request()
|
||||||
|
var isCompressed = false
|
||||||
|
|
||||||
|
val curlCmd = StringBuilder()
|
||||||
|
curlCmd.append("curl")
|
||||||
|
if (curlOptions != null) {
|
||||||
|
curlCmd.append(' ').append(curlOptions)
|
||||||
|
}
|
||||||
|
curlCmd.append(" -X ").append(request.method)
|
||||||
|
|
||||||
|
for ((name, value) in request.headers) {
|
||||||
|
if (name.equals(ACCEPT_ENCODING, ignoreCase = true) && value.equals("gzip", ignoreCase = true)) {
|
||||||
|
isCompressed = true
|
||||||
|
}
|
||||||
|
curlCmd.append(" -H \"").append(name).append(": ").append(value.escape()).append('\"')
|
||||||
|
}
|
||||||
|
|
||||||
|
val body = request.body
|
||||||
|
if (body != null) {
|
||||||
|
val buffer = Buffer()
|
||||||
|
body.writeTo(buffer)
|
||||||
|
val charset = body.contentType()?.charset() ?: Charsets.UTF_8
|
||||||
|
curlCmd.append(" --data-raw '")
|
||||||
|
.append(buffer.readString(charset).replace("\n", "\\n"))
|
||||||
|
.append("'")
|
||||||
|
}
|
||||||
|
if (isCompressed) {
|
||||||
|
curlCmd.append(" --compressed")
|
||||||
|
}
|
||||||
|
curlCmd.append(" \"").append(request.url).append('"')
|
||||||
|
|
||||||
|
log("---cURL (" + request.url + ")")
|
||||||
|
log(curlCmd.toString())
|
||||||
|
|
||||||
|
return chain.proceed(request)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun String.escape() = replace("\"", "\\\"")
|
||||||
|
|
||||||
|
private fun log(msg: String) {
|
||||||
|
Log.d("CURL", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,20 @@
|
|||||||
package org.koitharu.kotatsu.core.parser
|
package org.koitharu.kotatsu.core.parser
|
||||||
|
|
||||||
import java.util.*
|
|
||||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.parsers.MangaParser
|
import org.koitharu.kotatsu.parsers.MangaParser
|
||||||
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||||
import org.koitharu.kotatsu.parsers.model.*
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
|
import java.util.EnumSet
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This parser is just for parser development, it should not be used in releases
|
* This parser is just for parser development, it should not be used in releases
|
||||||
*/
|
*/
|
||||||
class DummyParser(override val context: MangaLoaderContext) : MangaParser(MangaSource.DUMMY) {
|
class DummyParser(context: MangaLoaderContext) : MangaParser(context, MangaSource.DUMMY) {
|
||||||
|
|
||||||
override val configKeyDomain: ConfigKey.Domain
|
override val configKeyDomain: ConfigKey.Domain
|
||||||
get() = ConfigKey.Domain("", null)
|
get() = ConfigKey.Domain("", null)
|
||||||
@@ -37,4 +42,4 @@ class DummyParser(override val context: MangaLoaderContext) : MangaParser(MangaS
|
|||||||
override suspend fun getTags(): Set<MangaTag> {
|
override suspend fun getTags(): Set<MangaTag> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
<bool name="leak_canary_add_launcher_icon" tools:node="replace">false</bool>
|
<bool name="leak_canary_add_launcher_icon" tools:node="replace">false</bool>
|
||||||
</resources>
|
<bool name="is_sync_enabled">true</bool>
|
||||||
|
</resources>
|
||||||
|
|||||||
@@ -10,16 +10,27 @@
|
|||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||||
|
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||||
|
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
|
||||||
|
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
|
||||||
|
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
|
||||||
|
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
|
||||||
|
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
||||||
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="org.koitharu.kotatsu.KotatsuApp"
|
android:name="org.koitharu.kotatsu.KotatsuApp"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:backupAgent="org.koitharu.kotatsu.settings.backup.AppBackupAgent"
|
android:backupAgent="org.koitharu.kotatsu.settings.backup.AppBackupAgent"
|
||||||
android:dataExtractionRules="@xml/backup_rules"
|
android:dataExtractionRules="@xml/backup_rules"
|
||||||
|
android:enableOnBackInvokedCallback="true"
|
||||||
android:fullBackupContent="@xml/backup_content"
|
android:fullBackupContent="@xml/backup_content"
|
||||||
android:fullBackupOnly="true"
|
android:fullBackupOnly="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
android:largeHeap="true"
|
||||||
|
android:localeConfig="@xml/locales"
|
||||||
android:networkSecurityConfig="@xml/network_security_config"
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
@@ -57,17 +68,25 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.search.ui.MangaListActivity"
|
android:name="org.koitharu.kotatsu.search.ui.MangaListActivity"
|
||||||
android:label="@string/search_manga" />
|
android:label="@string/search_manga" />
|
||||||
|
<activity
|
||||||
|
android:name="org.koitharu.kotatsu.history.ui.HistoryActivity"
|
||||||
|
android:label="@string/history" />
|
||||||
|
<activity
|
||||||
|
android:name="org.koitharu.kotatsu.tracker.ui.updates.UpdatesActivity"
|
||||||
|
android:label="@string/updates" />
|
||||||
|
<activity
|
||||||
|
android:name="org.koitharu.kotatsu.favourites.ui.FavouritesActivity"
|
||||||
|
android:label="@string/favourites" />
|
||||||
|
<activity
|
||||||
|
android:name="org.koitharu.kotatsu.bookmarks.ui.BookmarksActivity"
|
||||||
|
android:label="@string/bookmarks" />
|
||||||
|
<activity
|
||||||
|
android:name="org.koitharu.kotatsu.suggestions.ui.SuggestionsActivity"
|
||||||
|
android:label="@string/suggestions" />
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.settings.SettingsActivity"
|
android:name="org.koitharu.kotatsu.settings.SettingsActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:label="@string/settings">
|
android:label="@string/settings" />
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.VIEW" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<category android:name="android.intent.category.BROWSABLE" />
|
|
||||||
<data android:scheme="kotatsu" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.browser.BrowserActivity"
|
android:name="org.koitharu.kotatsu.browser.BrowserActivity"
|
||||||
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
||||||
@@ -77,14 +96,13 @@
|
|||||||
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
||||||
android:windowSoftInputMode="adjustResize" />
|
android:windowSoftInputMode="adjustResize" />
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.favourites.ui.categories.CategoriesActivity"
|
android:name="org.koitharu.kotatsu.favourites.ui.categories.FavouriteCategoriesActivity"
|
||||||
android:label="@string/favourites_categories"
|
android:label="@string/favourites"
|
||||||
android:windowSoftInputMode="stateAlwaysHidden" />
|
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.widget.shelf.ShelfConfigActivity"
|
android:name="org.koitharu.kotatsu.widget.shelf.ShelfConfigActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:label="@string/manga_shelf"
|
android:label="@string/manga_shelf">
|
||||||
android:theme="@style/Theme.Kotatsu.DialogWhenLarge">
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
@@ -102,23 +120,85 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.download.ui.DownloadsActivity"
|
android:name="org.koitharu.kotatsu.download.ui.DownloadsActivity"
|
||||||
android:label="@string/downloads"
|
android:label="@string/downloads"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTop" />
|
||||||
android:theme="@style/Theme.Kotatsu.DialogWhenLarge" />
|
|
||||||
<activity android:name="org.koitharu.kotatsu.image.ui.ImageActivity" />
|
<activity android:name="org.koitharu.kotatsu.image.ui.ImageActivity" />
|
||||||
|
<activity android:name="org.koitharu.kotatsu.favourites.ui.categories.edit.FavouritesCategoryEditActivity" />
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.favourites.ui.categories.edit.FavouritesCategoryEditActivity"
|
android:name="org.koitharu.kotatsu.sync.ui.SyncAuthActivity"
|
||||||
android:theme="@style/Theme.Kotatsu.DialogWhenLarge" />
|
android:label="@string/sync" />
|
||||||
|
<activity
|
||||||
|
android:name="org.koitharu.kotatsu.reader.ui.colorfilter.ColorFilterConfigActivity"
|
||||||
|
android:label="@string/color_correction" />
|
||||||
|
<activity
|
||||||
|
android:name="org.koitharu.kotatsu.shelf.ui.config.ShelfSettingsActivity"
|
||||||
|
android:label="@string/settings" />
|
||||||
|
<activity
|
||||||
|
android:name="org.koitharu.kotatsu.scrobbling.common.ui.config.ScrobblerConfigActivity"
|
||||||
|
android:exported="true"
|
||||||
|
android:label="@string/settings"
|
||||||
|
android:launchMode="singleTop">
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
|
||||||
|
<data android:scheme="kotatsu" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
</activity>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name="org.koitharu.kotatsu.download.ui.service.DownloadService"
|
android:name="org.koitharu.kotatsu.download.ui.service.DownloadService"
|
||||||
android:foregroundServiceType="dataSync" />
|
android:foregroundServiceType="dataSync"
|
||||||
|
android:stopWithTask="false" />
|
||||||
<service android:name="org.koitharu.kotatsu.local.ui.LocalChaptersRemoveService" />
|
<service android:name="org.koitharu.kotatsu.local.ui.LocalChaptersRemoveService" />
|
||||||
|
<service android:name="org.koitharu.kotatsu.local.ui.ImportService" />
|
||||||
<service
|
<service
|
||||||
android:name="org.koitharu.kotatsu.widget.shelf.ShelfWidgetService"
|
android:name="org.koitharu.kotatsu.widget.shelf.ShelfWidgetService"
|
||||||
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
||||||
<service
|
<service
|
||||||
android:name="org.koitharu.kotatsu.widget.recent.RecentWidgetService"
|
android:name="org.koitharu.kotatsu.widget.recent.RecentWidgetService"
|
||||||
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
||||||
|
<service
|
||||||
|
android:name="org.koitharu.kotatsu.sync.ui.SyncAuthenticatorService"
|
||||||
|
android:exported="true"
|
||||||
|
tools:ignore="ExportedService">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.accounts.AccountAuthenticator" />
|
||||||
|
</intent-filter>
|
||||||
|
<meta-data
|
||||||
|
android:name="android.accounts.AccountAuthenticator"
|
||||||
|
android:resource="@xml/authenticator_sync" />
|
||||||
|
</service>
|
||||||
|
<service
|
||||||
|
android:name="org.koitharu.kotatsu.sync.ui.favourites.FavouritesSyncService"
|
||||||
|
android:exported="false"
|
||||||
|
android:label="@string/favourites"
|
||||||
|
android:process=":sync">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.content.SyncAdapter" />
|
||||||
|
</intent-filter>
|
||||||
|
<meta-data
|
||||||
|
android:name="android.content.SyncAdapter"
|
||||||
|
android:resource="@xml/sync_favourites" />
|
||||||
|
</service>
|
||||||
|
<service
|
||||||
|
android:name="org.koitharu.kotatsu.sync.ui.history.HistorySyncService"
|
||||||
|
android:exported="false"
|
||||||
|
android:label="@string/history"
|
||||||
|
android:process=":sync">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.content.SyncAdapter" />
|
||||||
|
</intent-filter>
|
||||||
|
<meta-data
|
||||||
|
android:name="android.content.SyncAdapter"
|
||||||
|
android:resource="@xml/sync_history" />
|
||||||
|
</service>
|
||||||
|
<service
|
||||||
|
android:name="org.koitharu.kotatsu.details.service.MangaPrefetchService"
|
||||||
|
android:exported="false" />
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name="org.koitharu.kotatsu.search.ui.MangaSuggestionsProvider"
|
android:name="org.koitharu.kotatsu.search.ui.MangaSuggestionsProvider"
|
||||||
@@ -133,6 +213,22 @@
|
|||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
android:resource="@xml/filepaths" />
|
android:resource="@xml/filepaths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
<provider
|
||||||
|
android:name="org.koitharu.kotatsu.sync.ui.favourites.FavouritesSyncProvider"
|
||||||
|
android:authorities="org.koitharu.kotatsu.favourites"
|
||||||
|
android:exported="false"
|
||||||
|
android:label="@string/favourites"
|
||||||
|
android:syncable="true" />
|
||||||
|
<provider
|
||||||
|
android:name="org.koitharu.kotatsu.sync.ui.history.HistorySyncProvider"
|
||||||
|
android:authorities="org.koitharu.kotatsu.history"
|
||||||
|
android:exported="false"
|
||||||
|
android:label="@string/history"
|
||||||
|
android:syncable="true" />
|
||||||
|
<provider
|
||||||
|
android:name="androidx.startup.InitializationProvider"
|
||||||
|
android:authorities="${applicationId}.androidx-startup"
|
||||||
|
tools:node="remove" />
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name="org.koitharu.kotatsu.widget.shelf.ShelfWidgetProvider"
|
android:name="org.koitharu.kotatsu.widget.shelf.ShelfWidgetProvider"
|
||||||
@@ -163,7 +259,10 @@
|
|||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.webkit.WebView.MetricsOptOut"
|
android:name="android.webkit.WebView.MetricsOptOut"
|
||||||
android:value="true" />
|
android:value="true" />
|
||||||
|
<meta-data
|
||||||
|
android:name="com.samsung.android.icon_container.has_icon_container"
|
||||||
|
android:value="@bool/com_samsung_android_icon_container_has_icon_container" />
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -3,81 +3,57 @@ package org.koitharu.kotatsu
|
|||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.StrictMode
|
import android.os.StrictMode
|
||||||
|
import androidx.annotation.WorkerThread
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.fragment.app.strictmode.FragmentStrictMode
|
import androidx.fragment.app.strictmode.FragmentStrictMode
|
||||||
|
import androidx.hilt.work.HiltWorkerFactory
|
||||||
|
import androidx.room.InvalidationTracker
|
||||||
|
import androidx.work.Configuration
|
||||||
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import org.acra.ReportField
|
import org.acra.ReportField
|
||||||
import org.acra.config.dialog
|
import org.acra.config.dialog
|
||||||
import org.acra.config.mailSender
|
import org.acra.config.httpSender
|
||||||
import org.acra.data.StringFormat
|
import org.acra.data.StringFormat
|
||||||
import org.acra.ktx.initAcra
|
import org.acra.ktx.initAcra
|
||||||
import org.koin.android.ext.android.get
|
import org.acra.sender.HttpSender
|
||||||
import org.koin.android.ext.koin.androidContext
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koin.core.context.startKoin
|
|
||||||
import org.koitharu.kotatsu.base.ui.util.ActivityRecreationHandle
|
|
||||||
import org.koitharu.kotatsu.bookmarks.bookmarksModule
|
|
||||||
import org.koitharu.kotatsu.core.db.databaseModule
|
|
||||||
import org.koitharu.kotatsu.core.github.githubModule
|
|
||||||
import org.koitharu.kotatsu.core.network.networkModule
|
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.ui.uiModule
|
|
||||||
import org.koitharu.kotatsu.details.detailsModule
|
|
||||||
import org.koitharu.kotatsu.favourites.favouritesModule
|
|
||||||
import org.koitharu.kotatsu.history.historyModule
|
|
||||||
import org.koitharu.kotatsu.local.data.PagesCache
|
import org.koitharu.kotatsu.local.data.PagesCache
|
||||||
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
||||||
import org.koitharu.kotatsu.local.localModule
|
|
||||||
import org.koitharu.kotatsu.main.mainModule
|
|
||||||
import org.koitharu.kotatsu.main.ui.protect.AppProtectHelper
|
|
||||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.reader.readerModule
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
import org.koitharu.kotatsu.remotelist.remoteListModule
|
import javax.inject.Inject
|
||||||
import org.koitharu.kotatsu.scrobbling.shikimori.shikimoriModule
|
|
||||||
import org.koitharu.kotatsu.search.searchModule
|
|
||||||
import org.koitharu.kotatsu.settings.settingsModule
|
|
||||||
import org.koitharu.kotatsu.suggestions.suggestionsModule
|
|
||||||
import org.koitharu.kotatsu.tracker.trackerModule
|
|
||||||
import org.koitharu.kotatsu.widget.WidgetUpdater
|
|
||||||
import org.koitharu.kotatsu.widget.appWidgetModule
|
|
||||||
|
|
||||||
class KotatsuApp : Application() {
|
@HiltAndroidApp
|
||||||
|
class KotatsuApp : Application(), Configuration.Provider {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var databaseObservers: Set<@JvmSuppressWildcards InvalidationTracker.Observer>
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var activityLifecycleCallbacks: Set<@JvmSuppressWildcards ActivityLifecycleCallbacks>
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var database: MangaDatabase
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var settings: AppSettings
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var workerFactory: HiltWorkerFactory
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
enableStrictMode()
|
enableStrictMode()
|
||||||
}
|
}
|
||||||
initKoin()
|
AppCompatDelegate.setDefaultNightMode(settings.theme)
|
||||||
AppCompatDelegate.setDefaultNightMode(get<AppSettings>().theme)
|
AppCompatDelegate.setApplicationLocales(settings.appLocales)
|
||||||
registerActivityLifecycleCallbacks(get<AppProtectHelper>())
|
setupActivityLifecycleCallbacks()
|
||||||
registerActivityLifecycleCallbacks(get<ActivityRecreationHandle>())
|
processLifecycleScope.launch(Dispatchers.Default) {
|
||||||
val widgetUpdater = WidgetUpdater(applicationContext)
|
setupDatabaseObservers()
|
||||||
widgetUpdater.subscribeToFavourites(get())
|
|
||||||
widgetUpdater.subscribeToHistory(get())
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun initKoin() {
|
|
||||||
startKoin {
|
|
||||||
androidContext(this@KotatsuApp)
|
|
||||||
modules(
|
|
||||||
networkModule,
|
|
||||||
databaseModule,
|
|
||||||
githubModule,
|
|
||||||
uiModule,
|
|
||||||
mainModule,
|
|
||||||
searchModule,
|
|
||||||
localModule,
|
|
||||||
favouritesModule,
|
|
||||||
historyModule,
|
|
||||||
remoteListModule,
|
|
||||||
detailsModule,
|
|
||||||
trackerModule,
|
|
||||||
settingsModule,
|
|
||||||
readerModule,
|
|
||||||
appWidgetModule,
|
|
||||||
suggestionsModule,
|
|
||||||
shikimoriModule,
|
|
||||||
bookmarksModule,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,16 +61,25 @@ class KotatsuApp : Application() {
|
|||||||
super.attachBaseContext(base)
|
super.attachBaseContext(base)
|
||||||
initAcra {
|
initAcra {
|
||||||
buildConfigClass = BuildConfig::class.java
|
buildConfigClass = BuildConfig::class.java
|
||||||
reportFormat = StringFormat.KEY_VALUE_LIST
|
reportFormat = StringFormat.JSON
|
||||||
|
excludeMatchingSharedPreferencesKeys = listOf(
|
||||||
|
"sources_\\w+",
|
||||||
|
)
|
||||||
|
httpSender {
|
||||||
|
uri = getString(R.string.url_error_report)
|
||||||
|
basicAuthLogin = getString(R.string.acra_login)
|
||||||
|
basicAuthPassword = getString(R.string.acra_password)
|
||||||
|
httpMethod = HttpSender.Method.POST
|
||||||
|
}
|
||||||
reportContent = listOf(
|
reportContent = listOf(
|
||||||
ReportField.PACKAGE_NAME,
|
ReportField.PACKAGE_NAME,
|
||||||
|
ReportField.INSTALLATION_ID,
|
||||||
ReportField.APP_VERSION_CODE,
|
ReportField.APP_VERSION_CODE,
|
||||||
ReportField.APP_VERSION_NAME,
|
ReportField.APP_VERSION_NAME,
|
||||||
ReportField.ANDROID_VERSION,
|
ReportField.ANDROID_VERSION,
|
||||||
ReportField.PHONE_MODEL,
|
ReportField.PHONE_MODEL,
|
||||||
ReportField.CRASH_CONFIGURATION,
|
|
||||||
ReportField.STACK_TRACE,
|
ReportField.STACK_TRACE,
|
||||||
ReportField.CUSTOM_DATA,
|
ReportField.CRASH_CONFIGURATION,
|
||||||
ReportField.SHARED_PREFERENCES,
|
ReportField.SHARED_PREFERENCES,
|
||||||
)
|
)
|
||||||
dialog {
|
dialog {
|
||||||
@@ -104,11 +89,26 @@ class KotatsuApp : Application() {
|
|||||||
resIcon = R.drawable.ic_alert_outline
|
resIcon = R.drawable.ic_alert_outline
|
||||||
resTheme = android.R.style.Theme_Material_Light_Dialog_Alert
|
resTheme = android.R.style.Theme_Material_Light_Dialog_Alert
|
||||||
}
|
}
|
||||||
mailSender {
|
}
|
||||||
mailTo = getString(R.string.email_error_report)
|
}
|
||||||
reportAsFile = true
|
|
||||||
reportFileName = "stacktrace.txt"
|
override fun getWorkManagerConfiguration(): Configuration {
|
||||||
}
|
return Configuration.Builder()
|
||||||
|
.setWorkerFactory(workerFactory)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
private fun setupDatabaseObservers() {
|
||||||
|
val tracker = database.invalidationTracker
|
||||||
|
databaseObservers.forEach {
|
||||||
|
tracker.addObserver(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupActivityLifecycleCallbacks() {
|
||||||
|
activityLifecycleCallbacks.forEach {
|
||||||
|
registerActivityLifecycleCallbacks(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ class KotatsuApp : Application() {
|
|||||||
StrictMode.ThreadPolicy.Builder()
|
StrictMode.ThreadPolicy.Builder()
|
||||||
.detectAll()
|
.detectAll()
|
||||||
.penaltyLog()
|
.penaltyLog()
|
||||||
.build()
|
.build(),
|
||||||
)
|
)
|
||||||
StrictMode.setVmPolicy(
|
StrictMode.setVmPolicy(
|
||||||
StrictMode.VmPolicy.Builder()
|
StrictMode.VmPolicy.Builder()
|
||||||
@@ -126,7 +126,7 @@ class KotatsuApp : Application() {
|
|||||||
.setClassInstanceLimit(PagesCache::class.java, 1)
|
.setClassInstanceLimit(PagesCache::class.java, 1)
|
||||||
.setClassInstanceLimit(MangaLoaderContext::class.java, 1)
|
.setClassInstanceLimit(MangaLoaderContext::class.java, 1)
|
||||||
.penaltyLog()
|
.penaltyLog()
|
||||||
.build()
|
.build(),
|
||||||
)
|
)
|
||||||
FragmentStrictMode.defaultPolicy = FragmentStrictMode.Policy.Builder()
|
FragmentStrictMode.defaultPolicy = FragmentStrictMode.Policy.Builder()
|
||||||
.penaltyDeath()
|
.penaltyDeath()
|
||||||
@@ -137,4 +137,4 @@ class KotatsuApp : Application() {
|
|||||||
.detectFragmentTagUsage()
|
.detectFragmentTagUsage()
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,61 @@
|
|||||||
package org.koitharu.kotatsu.base.domain
|
package org.koitharu.kotatsu.base.domain
|
||||||
|
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
|
import android.net.Uri
|
||||||
|
import android.util.Size
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.runInterruptible
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.Request
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.db.entity.*
|
import org.koitharu.kotatsu.core.db.entity.MangaPrefsEntity
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toEntities
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toEntity
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toManga
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
||||||
|
import org.koitharu.kotatsu.core.network.CommonHeaders
|
||||||
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.parsers.util.await
|
||||||
|
import org.koitharu.kotatsu.reader.domain.ReaderColorFilter
|
||||||
|
import java.io.File
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.util.zip.ZipFile
|
||||||
|
import javax.inject.Inject
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
class MangaDataRepository(private val db: MangaDatabase) {
|
private const val MIN_WEBTOON_RATIO = 2
|
||||||
|
|
||||||
suspend fun savePreferences(manga: Manga, mode: ReaderMode) {
|
class MangaDataRepository @Inject constructor(
|
||||||
val tags = manga.tags.toEntities()
|
private val okHttpClient: OkHttpClient,
|
||||||
|
private val db: MangaDatabase,
|
||||||
|
) {
|
||||||
|
|
||||||
|
suspend fun saveReaderMode(manga: Manga, mode: ReaderMode) {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
db.tagsDao.upsert(tags)
|
storeManga(manga)
|
||||||
db.mangaDao.upsert(manga.toEntity(), tags)
|
val entity = db.preferencesDao.find(manga.id) ?: newEntity(manga.id)
|
||||||
|
db.preferencesDao.upsert(entity.copy(mode = mode.id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun saveColorFilter(manga: Manga, colorFilter: ReaderColorFilter?) {
|
||||||
|
db.withTransaction {
|
||||||
|
storeManga(manga)
|
||||||
|
val entity = db.preferencesDao.find(manga.id) ?: newEntity(manga.id)
|
||||||
db.preferencesDao.upsert(
|
db.preferencesDao.upsert(
|
||||||
MangaPrefsEntity(
|
entity.copy(
|
||||||
mangaId = manga.id,
|
cfBrightness = colorFilter?.brightness ?: 0f,
|
||||||
mode = mode.id
|
cfContrast = colorFilter?.contrast ?: 0f,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,6 +64,16 @@ class MangaDataRepository(private val db: MangaDatabase) {
|
|||||||
return db.preferencesDao.find(mangaId)?.let { ReaderMode.valueOf(it.mode) }
|
return db.preferencesDao.find(mangaId)?.let { ReaderMode.valueOf(it.mode) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun getColorFilter(mangaId: Long): ReaderColorFilter? {
|
||||||
|
return db.preferencesDao.find(mangaId)?.getColorFilterOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun observeColorFilter(mangaId: Long): Flow<ReaderColorFilter?> {
|
||||||
|
return db.preferencesDao.observe(mangaId)
|
||||||
|
.map { it?.getColorFilterOrNull() }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun findMangaById(mangaId: Long): Manga? {
|
suspend fun findMangaById(mangaId: Long): Manga? {
|
||||||
return db.mangaDao.find(mangaId)?.toManga()
|
return db.mangaDao.find(mangaId)?.toManga()
|
||||||
}
|
}
|
||||||
@@ -49,4 +95,74 @@ class MangaDataRepository(private val db: MangaDatabase) {
|
|||||||
suspend fun findTags(source: MangaSource): Set<MangaTag> {
|
suspend fun findTags(source: MangaSource): Set<MangaTag> {
|
||||||
return db.tagsDao.findTags(source.name).toMangaTags()
|
return db.tagsDao.findTags(source.name).toMangaTags()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private fun MangaPrefsEntity.getColorFilterOrNull(): ReaderColorFilter? {
|
||||||
|
return if (cfBrightness != 0f || cfContrast != 0f) {
|
||||||
|
ReaderColorFilter(cfBrightness, cfContrast)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatic determine type of manga by page size
|
||||||
|
* @return ReaderMode.WEBTOON if page is wide
|
||||||
|
*/
|
||||||
|
suspend fun determineMangaIsWebtoon(repository: MangaRepository, pages: List<MangaPage>): Boolean {
|
||||||
|
val pageIndex = (pages.size * 0.3).roundToInt()
|
||||||
|
val page = requireNotNull(pages.getOrNull(pageIndex)) { "No pages" }
|
||||||
|
val url = repository.getPageUrl(page)
|
||||||
|
val uri = Uri.parse(url)
|
||||||
|
val size = if (uri.scheme == "cbz") {
|
||||||
|
runInterruptible(Dispatchers.IO) {
|
||||||
|
val zip = ZipFile(uri.schemeSpecificPart)
|
||||||
|
val entry = zip.getEntry(uri.fragment)
|
||||||
|
zip.getInputStream(entry).use {
|
||||||
|
getBitmapSize(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val request = Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.get()
|
||||||
|
.tag(MangaSource::class.java, page.source)
|
||||||
|
.cacheControl(CommonHeaders.CACHE_CONTROL_DISABLED)
|
||||||
|
.build()
|
||||||
|
okHttpClient.newCall(request).await().use {
|
||||||
|
runInterruptible(Dispatchers.IO) {
|
||||||
|
getBitmapSize(it.body?.byteStream())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return size.width * MIN_WEBTOON_RATIO < size.height
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun newEntity(mangaId: Long) = MangaPrefsEntity(
|
||||||
|
mangaId = mangaId,
|
||||||
|
mode = -1,
|
||||||
|
cfBrightness = 0f,
|
||||||
|
cfContrast = 0f,
|
||||||
|
)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
suspend fun getImageMimeType(file: File): String? = runInterruptible(Dispatchers.IO) {
|
||||||
|
val options = BitmapFactory.Options().apply {
|
||||||
|
inJustDecodeBounds = true
|
||||||
|
}
|
||||||
|
BitmapFactory.decodeFile(file.path, options)?.recycle()
|
||||||
|
options.outMimeType
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getBitmapSize(input: InputStream?): Size {
|
||||||
|
val options = BitmapFactory.Options().apply {
|
||||||
|
inJustDecodeBounds = true
|
||||||
|
}
|
||||||
|
BitmapFactory.decodeStream(input, null, options)?.recycle()
|
||||||
|
val imageHeight: Int = options.outHeight
|
||||||
|
val imageWidth: Int = options.outWidth
|
||||||
|
check(imageHeight > 0 && imageWidth > 0)
|
||||||
|
return Size(imageWidth, imageHeight)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import android.net.Uri
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableCompat
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getParcelableExtraCompat
|
||||||
|
|
||||||
class MangaIntent private constructor(
|
class MangaIntent private constructor(
|
||||||
val manga: Manga?,
|
val manga: Manga?,
|
||||||
@@ -13,15 +15,15 @@ class MangaIntent private constructor(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
constructor(intent: Intent?) : this(
|
constructor(intent: Intent?) : this(
|
||||||
manga = intent?.getParcelableExtra<ParcelableManga>(KEY_MANGA)?.manga,
|
manga = intent?.getParcelableExtraCompat<ParcelableManga>(KEY_MANGA)?.manga,
|
||||||
mangaId = intent?.getLongExtra(KEY_ID, ID_NONE) ?: ID_NONE,
|
mangaId = intent?.getLongExtra(KEY_ID, ID_NONE) ?: ID_NONE,
|
||||||
uri = intent?.data
|
uri = intent?.data,
|
||||||
)
|
)
|
||||||
|
|
||||||
constructor(args: Bundle?) : this(
|
constructor(args: Bundle?) : this(
|
||||||
manga = args?.getParcelable<ParcelableManga>(KEY_MANGA)?.manga,
|
manga = args?.getParcelableCompat<ParcelableManga>(KEY_MANGA)?.manga,
|
||||||
mangaId = args?.getLong(KEY_ID, ID_NONE) ?: ID_NONE,
|
mangaId = args?.getLong(KEY_ID, ID_NONE) ?: ID_NONE,
|
||||||
uri = null
|
uri = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.base.domain
|
|
||||||
|
|
||||||
import android.graphics.BitmapFactory
|
|
||||||
import android.net.Uri
|
|
||||||
import android.util.Size
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.runInterruptible
|
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import okhttp3.Request
|
|
||||||
import org.koin.core.component.KoinComponent
|
|
||||||
import org.koin.core.component.get
|
|
||||||
import org.koitharu.kotatsu.core.network.CommonHeaders
|
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
|
||||||
import org.koitharu.kotatsu.parsers.util.await
|
|
||||||
import java.io.File
|
|
||||||
import java.io.InputStream
|
|
||||||
import java.util.zip.ZipFile
|
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
object MangaUtils : KoinComponent {
|
|
||||||
|
|
||||||
private const val MIN_WEBTOON_RATIO = 2
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Automatic determine type of manga by page size
|
|
||||||
* @return ReaderMode.WEBTOON if page is wide
|
|
||||||
*/
|
|
||||||
suspend fun determineMangaIsWebtoon(pages: List<MangaPage>): Boolean {
|
|
||||||
val pageIndex = (pages.size * 0.3).roundToInt()
|
|
||||||
val page = requireNotNull(pages.getOrNull(pageIndex)) { "No pages" }
|
|
||||||
val url = MangaRepository(page.source).getPageUrl(page)
|
|
||||||
val uri = Uri.parse(url)
|
|
||||||
val size = if (uri.scheme == "cbz") {
|
|
||||||
runInterruptible(Dispatchers.IO) {
|
|
||||||
val zip = ZipFile(uri.schemeSpecificPart)
|
|
||||||
val entry = zip.getEntry(uri.fragment)
|
|
||||||
zip.getInputStream(entry).use {
|
|
||||||
getBitmapSize(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val request = Request.Builder()
|
|
||||||
.url(url)
|
|
||||||
.get()
|
|
||||||
.header(CommonHeaders.REFERER, page.referer)
|
|
||||||
.cacheControl(CommonHeaders.CACHE_CONTROL_DISABLED)
|
|
||||||
.build()
|
|
||||||
get<OkHttpClient>().newCall(request).await().use {
|
|
||||||
runInterruptible(Dispatchers.IO) {
|
|
||||||
getBitmapSize(it.body?.byteStream())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return size.width * MIN_WEBTOON_RATIO < size.height
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun getImageMimeType(file: File): String? = runInterruptible(Dispatchers.IO) {
|
|
||||||
val options = BitmapFactory.Options().apply {
|
|
||||||
inJustDecodeBounds = true
|
|
||||||
}
|
|
||||||
BitmapFactory.decodeFile(file.path, options)?.recycle()
|
|
||||||
options.outMimeType
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getBitmapSize(input: InputStream?): Size {
|
|
||||||
val options = BitmapFactory.Options().apply {
|
|
||||||
inJustDecodeBounds = true
|
|
||||||
}
|
|
||||||
BitmapFactory.decodeStream(input, null, options)?.recycle()
|
|
||||||
val imageHeight: Int = options.outHeight
|
|
||||||
val imageWidth: Int = options.outWidth
|
|
||||||
check(imageHeight > 0 && imageWidth > 0)
|
|
||||||
return Size(imageWidth, imageHeight)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
package org.koitharu.kotatsu.base.domain
|
package org.koitharu.kotatsu.base.domain
|
||||||
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.NonCancellable
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
import org.koitharu.kotatsu.utils.ext.processLifecycleScope
|
||||||
|
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
|
||||||
|
|
||||||
fun interface ReversibleHandle {
|
fun interface ReversibleHandle {
|
||||||
|
|
||||||
@@ -10,10 +14,16 @@ fun interface ReversibleHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun ReversibleHandle.reverseAsync() = processLifecycleScope.launch(Dispatchers.Default) {
|
fun ReversibleHandle.reverseAsync() = processLifecycleScope.launch(Dispatchers.Default) {
|
||||||
reverse()
|
runCatchingCancellable {
|
||||||
|
withContext(NonCancellable) {
|
||||||
|
reverse()
|
||||||
|
}
|
||||||
|
}.onFailure {
|
||||||
|
it.printStackTraceDebug()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun ReversibleHandle.plus(other: ReversibleHandle) = ReversibleHandle {
|
operator fun ReversibleHandle.plus(other: ReversibleHandle) = ReversibleHandle {
|
||||||
this.reverse()
|
this.reverse()
|
||||||
other.reverse()
|
other.reverse()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.os.Bundle
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.annotation.CallSuper
|
import androidx.annotation.CallSuper
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
@@ -21,14 +22,14 @@ abstract class AlertDialogFragment<B : ViewBinding> : DialogFragment() {
|
|||||||
viewBinding = binding
|
viewBinding = binding
|
||||||
return MaterialAlertDialogBuilder(requireContext(), theme)
|
return MaterialAlertDialogBuilder(requireContext(), theme)
|
||||||
.setView(binding.root)
|
.setView(binding.root)
|
||||||
.also(::onBuildDialog)
|
.run(::onBuildDialog)
|
||||||
.create()
|
.create()
|
||||||
}
|
}
|
||||||
|
|
||||||
final override fun onCreateView(
|
final override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?,
|
||||||
) = viewBinding?.root
|
) = viewBinding?.root
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
@@ -37,9 +38,11 @@ abstract class AlertDialogFragment<B : ViewBinding> : DialogFragment() {
|
|||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun onBuildDialog(builder: MaterialAlertDialogBuilder) = Unit
|
open fun onBuildDialog(builder: MaterialAlertDialogBuilder): MaterialAlertDialogBuilder = builder
|
||||||
|
|
||||||
|
open fun onDialogCreated(dialog: AlertDialog) = Unit
|
||||||
|
|
||||||
protected fun bindingOrNull(): B? = viewBinding
|
protected fun bindingOrNull(): B? = viewBinding
|
||||||
|
|
||||||
protected abstract fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): B
|
protected abstract fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): B
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,23 +13,32 @@ import androidx.appcompat.view.ActionMode
|
|||||||
import androidx.appcompat.widget.ActionBarContextView
|
import androidx.appcompat.widget.ActionBarContextView
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.graphics.ColorUtils
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import org.koin.android.ext.android.get
|
import dagger.hilt.android.EntryPointAccessors
|
||||||
import org.koitharu.kotatsu.BuildConfig
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.util.ActionModeDelegate
|
import org.koitharu.kotatsu.base.ui.util.ActionModeDelegate
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.BaseActivityEntryPoint
|
||||||
import org.koitharu.kotatsu.base.ui.util.WindowInsetsDelegate
|
import org.koitharu.kotatsu.base.ui.util.WindowInsetsDelegate
|
||||||
|
import org.koitharu.kotatsu.base.ui.util.inject
|
||||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
abstract class BaseActivity<B : ViewBinding> :
|
abstract class BaseActivity<B : ViewBinding> :
|
||||||
AppCompatActivity(),
|
AppCompatActivity(),
|
||||||
WindowInsetsDelegate.WindowInsetsListener {
|
WindowInsetsDelegate.WindowInsetsListener {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var settings: AppSettings
|
||||||
|
|
||||||
protected lateinit var binding: B
|
protected lateinit var binding: B
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@@ -42,14 +51,10 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
val actionModeDelegate = ActionModeDelegate()
|
val actionModeDelegate = ActionModeDelegate()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
val settings = get<AppSettings>()
|
EntryPointAccessors.fromApplication(this, BaseActivityEntryPoint::class.java).inject(this)
|
||||||
val isAmoled = settings.isAmoledTheme
|
setTheme(settings.colorScheme.styleResId)
|
||||||
val isDynamic = settings.isDynamicTheme
|
if (settings.isAmoledTheme) {
|
||||||
// TODO support DialogWhenLarge theme
|
setTheme(R.style.ThemeOverlay_Kotatsu_Amoled)
|
||||||
when {
|
|
||||||
isAmoled && isDynamic -> setTheme(R.style.Theme_Kotatsu_Monet_Amoled)
|
|
||||||
isAmoled -> setTheme(R.style.Theme_Kotatsu_Amoled)
|
|
||||||
isDynamic -> setTheme(R.style.Theme_Kotatsu_Monet)
|
|
||||||
}
|
}
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
@@ -77,12 +82,13 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem) = if (item.itemId == android.R.id.home) {
|
override fun onOptionsItemSelected(item: MenuItem) = if (item.itemId == android.R.id.home) {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
onBackPressed()
|
onBackPressed()
|
||||||
true
|
true
|
||||||
} else super.onOptionsItemSelected(item)
|
} else super.onOptionsItemSelected(item)
|
||||||
|
|
||||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
if (BuildConfig.DEBUG && keyCode == KeyEvent.KEYCODE_VOLUME_UP) { // TODO remove
|
if (BuildConfig.DEBUG && keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
||||||
ActivityCompat.recreate(this)
|
ActivityCompat.recreate(this)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -96,27 +102,37 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
protected fun isDarkAmoledTheme(): Boolean {
|
protected fun isDarkAmoledTheme(): Boolean {
|
||||||
val uiMode = resources.configuration.uiMode
|
val uiMode = resources.configuration.uiMode
|
||||||
val isNight = uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
|
val isNight = uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
|
||||||
return isNight && get<AppSettings>().isAmoledTheme
|
return isNight && settings.isAmoledTheme
|
||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
override fun onSupportActionModeStarted(mode: ActionMode) {
|
override fun onSupportActionModeStarted(mode: ActionMode) {
|
||||||
super.onSupportActionModeStarted(mode)
|
super.onSupportActionModeStarted(mode)
|
||||||
actionModeDelegate.onSupportActionModeStarted(mode)
|
actionModeDelegate.onSupportActionModeStarted(mode)
|
||||||
|
val actionModeColor = ColorUtils.compositeColors(
|
||||||
|
ContextCompat.getColor(this, com.google.android.material.R.color.m3_appbar_overlay_color),
|
||||||
|
getThemeColor(com.google.android.material.R.attr.colorSurface),
|
||||||
|
)
|
||||||
val insets = ViewCompat.getRootWindowInsets(binding.root)
|
val insets = ViewCompat.getRootWindowInsets(binding.root)
|
||||||
?.getInsets(WindowInsetsCompat.Type.systemBars()) ?: return
|
?.getInsets(WindowInsetsCompat.Type.systemBars()) ?: return
|
||||||
val view = findViewById<ActionBarContextView?>(androidx.appcompat.R.id.action_mode_bar)
|
findViewById<ActionBarContextView?>(androidx.appcompat.R.id.action_mode_bar).apply {
|
||||||
view?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
setBackgroundColor(actionModeColor)
|
||||||
topMargin = insets.top
|
updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||||
|
topMargin = insets.top
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
window.statusBarColor = actionModeColor
|
||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
override fun onSupportActionModeFinished(mode: ActionMode) {
|
override fun onSupportActionModeFinished(mode: ActionMode) {
|
||||||
super.onSupportActionModeFinished(mode)
|
super.onSupportActionModeFinished(mode)
|
||||||
actionModeDelegate.onSupportActionModeFinished(mode)
|
actionModeDelegate.onSupportActionModeFinished(mode)
|
||||||
|
window.statusBarColor = getThemeColor(android.R.attr.statusBarColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
|
||||||
|
@Deprecated("Should not be used")
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
if ( // https://issuetracker.google.com/issues/139738913
|
if ( // https://issuetracker.google.com/issues/139738913
|
||||||
Build.VERSION.SDK_INT == Build.VERSION_CODES.Q &&
|
Build.VERSION.SDK_INT == Build.VERSION_CODES.Q &&
|
||||||
@@ -128,4 +144,4 @@ abstract class BaseActivity<B : ViewBinding> :
|
|||||||
super.onBackPressed()
|
super.onBackPressed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.ViewGroup.LayoutParams
|
import android.view.ViewGroup.LayoutParams
|
||||||
|
import androidx.activity.OnBackPressedDispatcher
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
@@ -27,10 +28,16 @@ abstract class BaseBottomSheet<B : ViewBinding> : BottomSheetDialogFragment() {
|
|||||||
protected val behavior: BottomSheetBehavior<*>?
|
protected val behavior: BottomSheetBehavior<*>?
|
||||||
get() = (dialog as? BottomSheetDialog)?.behavior
|
get() = (dialog as? BottomSheetDialog)?.behavior
|
||||||
|
|
||||||
|
val isExpanded: Boolean
|
||||||
|
get() = behavior?.state == BottomSheetBehavior.STATE_EXPANDED
|
||||||
|
|
||||||
|
val onBackPressedDispatcher: OnBackPressedDispatcher
|
||||||
|
get() = (requireDialog() as AppBottomSheetDialog).onBackPressedDispatcher
|
||||||
|
|
||||||
final override fun onCreateView(
|
final override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?,
|
||||||
): View {
|
): View {
|
||||||
val binding = onInflateView(inflater, container)
|
val binding = onInflateView(inflater, container)
|
||||||
viewBinding = binding
|
viewBinding = binding
|
||||||
@@ -83,4 +90,4 @@ abstract class BaseBottomSheet<B : ViewBinding> : BottomSheetDialogFragment() {
|
|||||||
}
|
}
|
||||||
b.isDraggable = !isLocked
|
b.isDraggable = !isLocked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,4 +52,4 @@ abstract class BaseFragment<B : ViewBinding> :
|
|||||||
protected fun bindingOrNull() = viewBinding
|
protected fun bindingOrNull() = viewBinding
|
||||||
|
|
||||||
protected abstract fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): B
|
protected abstract fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): B
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,18 +8,21 @@ import androidx.core.graphics.Insets
|
|||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.koin.android.ext.android.inject
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import javax.inject.Inject
|
||||||
import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner
|
import org.koitharu.kotatsu.base.ui.util.RecyclerViewOwner
|
||||||
import org.koitharu.kotatsu.base.ui.util.WindowInsetsDelegate
|
import org.koitharu.kotatsu.base.ui.util.WindowInsetsDelegate
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.settings.SettingsHeadersFragment
|
import org.koitharu.kotatsu.settings.SettingsHeadersFragment
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
abstract class BasePreferenceFragment(@StringRes private val titleId: Int) :
|
abstract class BasePreferenceFragment(@StringRes private val titleId: Int) :
|
||||||
PreferenceFragmentCompat(),
|
PreferenceFragmentCompat(),
|
||||||
WindowInsetsDelegate.WindowInsetsListener,
|
WindowInsetsDelegate.WindowInsetsListener,
|
||||||
RecyclerViewOwner {
|
RecyclerViewOwner {
|
||||||
|
|
||||||
protected val settings by inject<AppSettings>(mode = LazyThreadSafetyMode.NONE)
|
@Inject
|
||||||
|
lateinit var settings: AppSettings
|
||||||
|
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
protected val insetsDelegate = WindowInsetsDelegate(this)
|
protected val insetsDelegate = WindowInsetsDelegate(this)
|
||||||
@@ -48,7 +51,7 @@ abstract class BasePreferenceFragment(@StringRes private val titleId: Int) :
|
|||||||
@CallSuper
|
@CallSuper
|
||||||
override fun onWindowInsetsChanged(insets: Insets) {
|
override fun onWindowInsetsChanged(insets: Insets) {
|
||||||
listView.updatePadding(
|
listView.updatePadding(
|
||||||
bottom = insets.bottom
|
bottom = insets.bottom,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,4 +60,4 @@ abstract class BasePreferenceFragment(@StringRes private val titleId: Int) :
|
|||||||
(parentFragment as? SettingsHeadersFragment)?.setTitle(title)
|
(parentFragment as? SettingsHeadersFragment)?.setTitle(title)
|
||||||
?: activity?.setTitle(title)
|
?: activity?.setTitle(title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,34 +4,48 @@ import android.app.Service
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
|
||||||
abstract class CoroutineIntentService : BaseService() {
|
abstract class CoroutineIntentService : BaseService() {
|
||||||
|
|
||||||
private val mutex = Mutex()
|
private val mutex = Mutex()
|
||||||
protected open val dispatcher: CoroutineDispatcher = Dispatchers.Default
|
protected open val dispatcher: CoroutineDispatcher = Dispatchers.Default
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
final override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
super.onStartCommand(intent, flags, startId)
|
super.onStartCommand(intent, flags, startId)
|
||||||
launchCoroutine(intent, startId)
|
launchCoroutine(intent, startId)
|
||||||
return Service.START_REDELIVER_INTENT
|
return Service.START_REDELIVER_INTENT
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchCoroutine(intent: Intent?, startId: Int) = lifecycleScope.launch {
|
private fun launchCoroutine(intent: Intent?, startId: Int) = lifecycleScope.launch(errorHandler(startId)) {
|
||||||
mutex.withLock {
|
mutex.withLock {
|
||||||
try {
|
try {
|
||||||
withContext(dispatcher) {
|
if (intent != null) {
|
||||||
processIntent(intent)
|
withContext(dispatcher) {
|
||||||
|
processIntent(startId, intent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
e.printStackTraceDebug()
|
||||||
|
onError(startId, e)
|
||||||
} finally {
|
} finally {
|
||||||
stopSelf(startId)
|
stopSelf(startId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract suspend fun processIntent(intent: Intent?)
|
protected abstract suspend fun processIntent(startId: Int, intent: Intent)
|
||||||
}
|
|
||||||
|
protected abstract fun onError(startId: Int, error: Throwable)
|
||||||
|
|
||||||
|
private fun errorHandler(startId: Int) = CoroutineExceptionHandler { _, throwable ->
|
||||||
|
throwable.printStackTraceDebug()
|
||||||
|
onError(startId, throwable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.app.Application.ActivityLifecycleCallbacks
|
||||||
|
import android.os.Bundle
|
||||||
|
|
||||||
|
interface DefaultActivityLifecycleCallbacks : ActivityLifecycleCallbacks {
|
||||||
|
|
||||||
|
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) = 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) = Unit
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ import android.view.View.OnLongClickListener
|
|||||||
import com.hannesdorfmann.adapterdelegates4.dsl.AdapterDelegateViewBindingViewHolder
|
import com.hannesdorfmann.adapterdelegates4.dsl.AdapterDelegateViewBindingViewHolder
|
||||||
|
|
||||||
class AdapterDelegateClickListenerAdapter<I>(
|
class AdapterDelegateClickListenerAdapter<I>(
|
||||||
private val adapterDelegate: AdapterDelegateViewBindingViewHolder<I, *>,
|
private val adapterDelegate: AdapterDelegateViewBindingViewHolder<out I, *>,
|
||||||
private val clickListener: OnListItemClickListener<I>,
|
private val clickListener: OnListItemClickListener<I>,
|
||||||
) : OnClickListener, OnLongClickListener {
|
) : OnClickListener, OnLongClickListener {
|
||||||
|
|
||||||
@@ -17,4 +17,4 @@ class AdapterDelegateClickListenerAdapter<I>(
|
|||||||
override fun onLongClick(v: View): Boolean {
|
override fun onLongClick(v: View): Boolean {
|
||||||
return clickListener.onItemLongClick(adapterDelegate.item, v)
|
return clickListener.onItemLongClick(adapterDelegate.item, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ import androidx.lifecycle.LifecycleOwner
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.savedstate.SavedStateRegistry
|
import androidx.savedstate.SavedStateRegistry
|
||||||
import androidx.savedstate.SavedStateRegistryOwner
|
import androidx.savedstate.SavedStateRegistryOwner
|
||||||
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration
|
import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration
|
||||||
import kotlin.coroutines.EmptyCoroutineContext
|
|
||||||
|
|
||||||
private const val KEY_SELECTION = "selection"
|
private const val KEY_SELECTION = "selection"
|
||||||
private const val PROVIDER_NAME = "selection_decoration"
|
private const val PROVIDER_NAME = "selection_decoration"
|
||||||
@@ -23,15 +23,18 @@ class ListSelectionController(
|
|||||||
private val activity: Activity,
|
private val activity: Activity,
|
||||||
private val decoration: AbstractSelectionItemDecoration,
|
private val decoration: AbstractSelectionItemDecoration,
|
||||||
private val registryOwner: SavedStateRegistryOwner,
|
private val registryOwner: SavedStateRegistryOwner,
|
||||||
private val callback: Callback,
|
private val callback: Callback2,
|
||||||
) : ActionMode.Callback, SavedStateRegistry.SavedStateProvider {
|
) : ActionMode.Callback, SavedStateRegistry.SavedStateProvider {
|
||||||
|
|
||||||
private var actionMode: ActionMode? = null
|
private var actionMode: ActionMode? = null
|
||||||
private val stateEventObserver = StateEventObserver()
|
|
||||||
|
|
||||||
val count: Int
|
val count: Int
|
||||||
get() = decoration.checkedItemsCount
|
get() = decoration.checkedItemsCount
|
||||||
|
|
||||||
|
init {
|
||||||
|
registryOwner.lifecycle.addObserver(StateEventObserver())
|
||||||
|
}
|
||||||
|
|
||||||
fun snapshot(): Set<Long> {
|
fun snapshot(): Set<Long> {
|
||||||
return peekCheckedIds().toSet()
|
return peekCheckedIds().toSet()
|
||||||
}
|
}
|
||||||
@@ -55,7 +58,6 @@ class ListSelectionController(
|
|||||||
|
|
||||||
fun attachToRecyclerView(recyclerView: RecyclerView) {
|
fun attachToRecyclerView(recyclerView: RecyclerView) {
|
||||||
recyclerView.addItemDecoration(decoration)
|
recyclerView.addItemDecoration(decoration)
|
||||||
registryOwner.lifecycle.addObserver(stateEventObserver)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun saveState(): Bundle {
|
override fun saveState(): Bundle {
|
||||||
@@ -87,19 +89,19 @@ class ListSelectionController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||||
return callback.onCreateActionMode(mode, menu)
|
return callback.onCreateActionMode(this, mode, menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
|
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||||
return callback.onPrepareActionMode(mode, menu)
|
return callback.onPrepareActionMode(this, mode, menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||||
return callback.onActionItemClicked(mode, item)
|
return callback.onActionItemClicked(this, mode, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyActionMode(mode: ActionMode) {
|
override fun onDestroyActionMode(mode: ActionMode) {
|
||||||
callback.onDestroyActionMode(mode)
|
callback.onDestroyActionMode(this, mode)
|
||||||
clear()
|
clear()
|
||||||
actionMode = null
|
actionMode = null
|
||||||
}
|
}
|
||||||
@@ -112,7 +114,7 @@ class ListSelectionController(
|
|||||||
|
|
||||||
private fun notifySelectionChanged() {
|
private fun notifySelectionChanged() {
|
||||||
val count = decoration.checkedItemsCount
|
val count = decoration.checkedItemsCount
|
||||||
callback.onSelectionChanged(count)
|
callback.onSelectionChanged(this, count)
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
actionMode?.finish()
|
actionMode?.finish()
|
||||||
} else {
|
} else {
|
||||||
@@ -129,17 +131,56 @@ class ListSelectionController(
|
|||||||
notifySelectionChanged()
|
notifySelectionChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Callback : ActionMode.Callback {
|
@Deprecated("")
|
||||||
|
interface Callback : Callback2 {
|
||||||
|
|
||||||
fun onSelectionChanged(count: Int)
|
fun onSelectionChanged(count: Int)
|
||||||
|
|
||||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean
|
fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean
|
||||||
|
|
||||||
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean
|
fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean
|
||||||
|
|
||||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean
|
fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean
|
||||||
|
|
||||||
override fun onDestroyActionMode(mode: ActionMode) = Unit
|
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 {
|
||||||
|
mode.title = controller.count.toString()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onActionItemClicked(controller: ListSelectionController, mode: ActionMode, item: MenuItem): Boolean
|
||||||
|
|
||||||
|
fun onDestroyActionMode(controller: ListSelectionController, mode: ActionMode) = Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class StateEventObserver : LifecycleEventObserver {
|
private inner class StateEventObserver : LifecycleEventObserver {
|
||||||
@@ -159,4 +200,4 @@ class ListSelectionController(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,237 @@
|
|||||||
|
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.collection.ArrayMap
|
||||||
|
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 owner: 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 {
|
||||||
|
owner.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()
|
||||||
|
}
|
||||||
|
var shouldAddDecoration = true
|
||||||
|
for (i in (0 until recyclerView.itemDecorationCount).reversed()) {
|
||||||
|
val decor = recyclerView.getItemDecorationAt(i)
|
||||||
|
if (decor === decoration) {
|
||||||
|
shouldAddDecoration = false
|
||||||
|
break
|
||||||
|
} else if (decor.javaClass == decoration.javaClass) {
|
||||||
|
recyclerView.removeItemDecorationAt(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (shouldAddDecoration) {
|
||||||
|
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(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 isInSelectionMode(): Boolean {
|
||||||
|
return decorations.values.any { x -> x.checkedItemsCount > 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun notifySelectionChanged() {
|
||||||
|
val count = this.count
|
||||||
|
callback.onSelectionChanged(this, 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(this, section)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Callback<T : Any> {
|
||||||
|
|
||||||
|
fun onSelectionChanged(controller: SectionedSelectionController<T>, count: Int)
|
||||||
|
|
||||||
|
fun onCreateActionMode(controller: SectionedSelectionController<T>, mode: ActionMode, menu: Menu): Boolean
|
||||||
|
|
||||||
|
fun onPrepareActionMode(controller: SectionedSelectionController<T>, mode: ActionMode, menu: Menu): Boolean {
|
||||||
|
mode.title = controller.count.toString()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onDestroyActionMode(controller: SectionedSelectionController<T>, mode: ActionMode) = Unit
|
||||||
|
|
||||||
|
fun onActionItemClicked(
|
||||||
|
controller: SectionedSelectionController<T>,
|
||||||
|
mode: ActionMode,
|
||||||
|
item: MenuItem,
|
||||||
|
): Boolean
|
||||||
|
|
||||||
|
fun onCreateItemDecoration(
|
||||||
|
controller: SectionedSelectionController<T>,
|
||||||
|
section: T,
|
||||||
|
): AbstractSelectionItemDecoration
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class StateEventObserver : LifecycleEventObserver {
|
||||||
|
|
||||||
|
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
|
||||||
|
if (event == Lifecycle.Event.ON_CREATE) {
|
||||||
|
val registry = owner.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() },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,8 +11,8 @@ class SpacingItemDecoration(@Px private val spacing: Int) : RecyclerView.ItemDec
|
|||||||
outRect: Rect,
|
outRect: Rect,
|
||||||
view: View,
|
view: View,
|
||||||
parent: RecyclerView,
|
parent: RecyclerView,
|
||||||
state: RecyclerView.State
|
state: RecyclerView.State,
|
||||||
) {
|
) {
|
||||||
outRect.set(spacing, spacing, spacing, spacing)
|
outRect.set(spacing, spacing, spacing, spacing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
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 kotlin.math.hypot
|
||||||
|
import org.koitharu.kotatsu.utils.ext.animatorDurationScale
|
||||||
|
import org.koitharu.kotatsu.utils.ext.measureWidth
|
||||||
|
|
||||||
|
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,74 @@
|
|||||||
|
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)
|
||||||
|
.setListener(null)
|
||||||
|
.setDuration(animationDuration)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hide() {
|
||||||
|
if (!scrollbar.isVisible || isHiding) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
animator?.cancel()
|
||||||
|
isHiding = true
|
||||||
|
animator = scrollbar.animate().apply {
|
||||||
|
translationX(scrollbarPaddingEnd)
|
||||||
|
alpha(0f)
|
||||||
|
duration = animationDuration
|
||||||
|
setListener(HideListener(this))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class HideListener(
|
||||||
|
private val viewPropertyAnimator: ViewPropertyAnimator,
|
||||||
|
) : 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 && this@ScrollbarAnimator.animator === viewPropertyAnimator) {
|
||||||
|
scrollbar.isInvisible = true
|
||||||
|
isHiding = false
|
||||||
|
this@ScrollbarAnimator.animator = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
package org.koitharu.kotatsu.base.ui.util
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.Application.ActivityLifecycleCallbacks
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import java.util.*
|
import org.koitharu.kotatsu.base.ui.DefaultActivityLifecycleCallbacks
|
||||||
|
import java.util.WeakHashMap
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
class ActivityRecreationHandle : ActivityLifecycleCallbacks {
|
@Singleton
|
||||||
|
class ActivityRecreationHandle @Inject constructor() : DefaultActivityLifecycleCallbacks {
|
||||||
|
|
||||||
private val activities = WeakHashMap<Activity, Unit>()
|
private val activities = WeakHashMap<Activity, Unit>()
|
||||||
|
|
||||||
@@ -13,16 +16,6 @@ class ActivityRecreationHandle : ActivityLifecycleCallbacks {
|
|||||||
activities[activity] = Unit
|
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) {
|
override fun onActivityDestroyed(activity: Activity) {
|
||||||
activities.remove(activity)
|
activities.remove(activity)
|
||||||
}
|
}
|
||||||
@@ -31,4 +24,4 @@ class ActivityRecreationHandle : ActivityLifecycleCallbacks {
|
|||||||
val snapshot = activities.keys.toList()
|
val snapshot = activities.keys.toList()
|
||||||
snapshot.forEach { it.recreate() }
|
snapshot.forEach { it.recreate() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import dagger.hilt.EntryPoint
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
|
||||||
|
@EntryPoint
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
interface BaseActivityEntryPoint {
|
||||||
|
val settings: AppSettings
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hilt cannot inject into parametrized classes
|
||||||
|
fun BaseActivityEntryPoint.inject(activity: BaseActivity<*>) {
|
||||||
|
activity.settings = settings
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import android.view.MenuItem
|
||||||
|
import android.view.MenuItem.OnActionExpandListener
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
|
|
||||||
|
class CollapseActionViewCallback(
|
||||||
|
private val menuItem: MenuItem
|
||||||
|
) : OnBackPressedCallback(menuItem.isActionViewExpanded), OnActionExpandListener {
|
||||||
|
|
||||||
|
override fun handleOnBackPressed() {
|
||||||
|
menuItem.collapseActionView()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
|
||||||
|
isEnabled = true
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
|
||||||
|
isEnabled = false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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?,
|
||||||
|
)
|
||||||
@@ -8,10 +8,12 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior
|
|||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||||
|
|
||||||
class ShrinkOnScrollBehavior : Behavior<ExtendedFloatingActionButton> {
|
open class ShrinkOnScrollBehavior : Behavior<ExtendedFloatingActionButton> {
|
||||||
|
|
||||||
@Suppress("unused") constructor() : super()
|
@Suppress("unused")
|
||||||
@Suppress("unused") constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
|
constructor() : super()
|
||||||
|
@Suppress("unused")
|
||||||
|
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
|
||||||
|
|
||||||
override fun onStartNestedScroll(
|
override fun onStartNestedScroll(
|
||||||
coordinatorLayout: CoordinatorLayout,
|
coordinatorLayout: CoordinatorLayout,
|
||||||
@@ -45,4 +47,4 @@ class ShrinkOnScrollBehavior : Behavior<ExtendedFloatingActionButton> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.annotation.Px
|
||||||
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.koitharu.kotatsu.parsers.util.toIntUp
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
class SpanSizeResolver(
|
||||||
|
private val recyclerView: RecyclerView,
|
||||||
|
@Px private val minItemWidth: Int,
|
||||||
|
) : View.OnLayoutChangeListener {
|
||||||
|
|
||||||
|
fun attach() {
|
||||||
|
recyclerView.addOnLayoutChangeListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun detach() {
|
||||||
|
recyclerView.removeOnLayoutChangeListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLayoutChange(
|
||||||
|
v: View?,
|
||||||
|
left: Int,
|
||||||
|
top: Int,
|
||||||
|
right: Int,
|
||||||
|
bottom: Int,
|
||||||
|
oldLeft: Int,
|
||||||
|
oldTop: Int,
|
||||||
|
oldRight: Int,
|
||||||
|
oldBottom: Int,
|
||||||
|
) {
|
||||||
|
invalidateInternal(abs(right - left))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun invalidate() {
|
||||||
|
invalidateInternal(recyclerView.width)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun invalidateInternal(width: Int) {
|
||||||
|
if (width <= 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val lm = recyclerView.layoutManager as? GridLayoutManager ?: return
|
||||||
|
val estimatedCount = (width / minItemWidth.toFloat()).toIntUp()
|
||||||
|
if (lm.spanCount != estimatedCount) {
|
||||||
|
lm.spanCount = estimatedCount
|
||||||
|
lm.spanSizeLookup?.run {
|
||||||
|
invalidateSpanGroupIndexCache()
|
||||||
|
invalidateSpanIndexCache()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.util
|
||||||
|
|
||||||
|
import android.animation.ValueAnimator
|
||||||
|
import android.view.animation.AccelerateDecelerateInterpolator
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
|
import com.google.android.material.shape.MaterialShapeDrawable
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getAnimationDuration
|
||||||
|
|
||||||
|
class StatusBarDimHelper : AppBarLayout.OnOffsetChangedListener {
|
||||||
|
|
||||||
|
private var animator: ValueAnimator? = null
|
||||||
|
private val interpolator = AccelerateDecelerateInterpolator()
|
||||||
|
|
||||||
|
override fun onOffsetChanged(appBarLayout: AppBarLayout, verticalOffset: Int) {
|
||||||
|
val foreground = appBarLayout.statusBarForeground ?: return
|
||||||
|
val start = foreground.alpha
|
||||||
|
val collapsed = verticalOffset != 0
|
||||||
|
val end = if (collapsed) 255 else 0
|
||||||
|
animator?.cancel()
|
||||||
|
if (start == end) {
|
||||||
|
animator = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
animator = ValueAnimator.ofInt(start, end).apply {
|
||||||
|
duration = appBarLayout.context.getAnimationDuration(materialR.integer.app_bar_elevation_anim_duration)
|
||||||
|
interpolator = this@StatusBarDimHelper.interpolator
|
||||||
|
addUpdateListener {
|
||||||
|
foreground.alpha = it.animatedValue as Int
|
||||||
|
}
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun attachToAppBar(appBarLayout: AppBarLayout) {
|
||||||
|
appBarLayout.addOnOffsetChangedListener(this)
|
||||||
|
appBarLayout.statusBarForeground =
|
||||||
|
MaterialShapeDrawable.createWithElevationOverlay(appBarLayout.context).apply {
|
||||||
|
alpha = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,312 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
|
import android.animation.LayoutTransition
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.view.WindowInsets
|
||||||
|
import androidx.annotation.AttrRes
|
||||||
|
import androidx.annotation.MenuRes
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.appcompat.widget.Toolbar
|
||||||
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
import androidx.core.content.withStyledAttributes
|
||||||
|
import androidx.core.view.*
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
|
import com.google.android.material.appbar.MaterialToolbar
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.databinding.LayoutSheetHeaderBinding
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getAnimationDuration
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getThemeDrawable
|
||||||
|
import org.koitharu.kotatsu.utils.ext.parents
|
||||||
|
import java.util.*
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
|
private const val THROTTLE_DELAY = 200L
|
||||||
|
|
||||||
|
class BottomSheetHeaderBar @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
@AttrRes defStyleAttr: Int = materialR.attr.appBarLayoutStyle,
|
||||||
|
) : AppBarLayout(context, attrs, defStyleAttr), MenuHost {
|
||||||
|
|
||||||
|
private val binding = LayoutSheetHeaderBinding.inflate(LayoutInflater.from(context), this)
|
||||||
|
private val closeDrawable = context.getThemeDrawable(materialR.attr.actionModeCloseDrawable)
|
||||||
|
private val bottomSheetCallback = Callback()
|
||||||
|
private val adjustStateRunnable = Runnable { adjustState() }
|
||||||
|
private var bottomSheetBehavior: BottomSheetBehavior<*>? = null
|
||||||
|
private val locationBuffer = IntArray(2)
|
||||||
|
private val expansionListeners = LinkedList<OnExpansionChangeListener>()
|
||||||
|
private var fitStatusBar = false
|
||||||
|
private val minHandleHeight = context.resources.getDimensionPixelSize(R.dimen.bottom_sheet_handle_size_min)
|
||||||
|
private val maxHandleHeight = context.resources.getDimensionPixelSize(R.dimen.bottom_sheet_handle_size_max)
|
||||||
|
private var isLayoutSuppressedCompat = false
|
||||||
|
private var isLayoutCalledWhileSuppressed = false
|
||||||
|
private var isBsExpanded = false
|
||||||
|
private var stateAdjustedAt = 0L
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
val toolbar: MaterialToolbar
|
||||||
|
get() = binding.toolbar
|
||||||
|
|
||||||
|
val menu: Menu
|
||||||
|
get() = binding.toolbar.menu
|
||||||
|
|
||||||
|
var title: CharSequence?
|
||||||
|
get() = binding.toolbar.title
|
||||||
|
set(value) {
|
||||||
|
binding.toolbar.title = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var subtitle: CharSequence?
|
||||||
|
get() = binding.toolbar.subtitle
|
||||||
|
set(value) {
|
||||||
|
binding.toolbar.subtitle = value
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
setBackgroundResource(R.drawable.sheet_toolbar_background)
|
||||||
|
layoutTransition = LayoutTransition().apply {
|
||||||
|
setDuration(context.getAnimationDuration(R.integer.config_tinyAnimTime))
|
||||||
|
}
|
||||||
|
context.withStyledAttributes(attrs, R.styleable.BottomSheetHeaderBar, defStyleAttr) {
|
||||||
|
binding.toolbar.title = getString(R.styleable.BottomSheetHeaderBar_title)
|
||||||
|
fitStatusBar = getBoolean(R.styleable.BottomSheetHeaderBar_fitStatusBar, fitStatusBar)
|
||||||
|
val menuResId = getResourceId(R.styleable.BottomSheetHeaderBar_menu, 0)
|
||||||
|
if (menuResId != 0) {
|
||||||
|
binding.toolbar.inflateMenu(menuResId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
binding.toolbar.setNavigationOnClickListener(bottomSheetCallback)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAttachedToWindow() {
|
||||||
|
super.onAttachedToWindow()
|
||||||
|
setBottomSheetBehavior(findParentBottomSheetBehavior())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDetachedFromWindow() {
|
||||||
|
setBottomSheetBehavior(null)
|
||||||
|
super.onDetachedFromWindow()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addView(child: View?, index: Int) {
|
||||||
|
if (shouldAddView(child)) {
|
||||||
|
super.addView(child, index)
|
||||||
|
} else {
|
||||||
|
binding.toolbar.addView(child, index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addView(child: View?, width: Int, height: Int) {
|
||||||
|
if (shouldAddView(child)) {
|
||||||
|
super.addView(child, width, height)
|
||||||
|
} else {
|
||||||
|
binding.toolbar.addView(child, width, height)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addView(child: View?, index: Int, params: ViewGroup.LayoutParams?) {
|
||||||
|
if (shouldAddView(child)) {
|
||||||
|
super.addView(child, index, params)
|
||||||
|
} else {
|
||||||
|
binding.toolbar.addView(child, index, convertLayoutParams(params))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onApplyWindowInsets(insets: WindowInsets?): WindowInsets {
|
||||||
|
dispatchInsets(if (insets != null) WindowInsetsCompat.toWindowInsetsCompat(insets) else null)
|
||||||
|
return super.onApplyWindowInsets(insets)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addMenuProvider(provider: MenuProvider) {
|
||||||
|
binding.toolbar.addMenuProvider(provider)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addMenuProvider(provider: MenuProvider, owner: LifecycleOwner) {
|
||||||
|
binding.toolbar.addMenuProvider(provider, owner)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addMenuProvider(provider: MenuProvider, owner: LifecycleOwner, state: Lifecycle.State) {
|
||||||
|
binding.toolbar.addMenuProvider(provider, owner, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun removeMenuProvider(provider: MenuProvider) {
|
||||||
|
binding.toolbar.removeMenuProvider(provider)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun invalidateMenu() {
|
||||||
|
binding.toolbar.invalidateMenu()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun inflateMenu(@MenuRes resId: Int) {
|
||||||
|
binding.toolbar.inflateMenu(resId)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setNavigationOnClickListener(onClickListener: OnClickListener) {
|
||||||
|
binding.toolbar.setNavigationOnClickListener(onClickListener)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addOnExpansionChangeListener(listener: OnExpansionChangeListener) {
|
||||||
|
expansionListeners.add(listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeOnExpansionChangeListener(listener: OnExpansionChangeListener) {
|
||||||
|
expansionListeners.remove(listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setTitle(@StringRes resId: Int) {
|
||||||
|
binding.toolbar.setTitle(resId)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setSubtitle(@StringRes resId: Int) {
|
||||||
|
binding.toolbar.setSubtitle(resId)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
|
||||||
|
if (isLayoutSuppressedCompat) {
|
||||||
|
isLayoutCalledWhileSuppressed = true
|
||||||
|
} else {
|
||||||
|
super.onLayout(changed, l, t, r, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setBottomSheetBehavior(behavior: BottomSheetBehavior<*>?) {
|
||||||
|
bottomSheetBehavior?.removeBottomSheetCallback(bottomSheetCallback)
|
||||||
|
bottomSheetBehavior = behavior
|
||||||
|
if (behavior != null) {
|
||||||
|
onBottomSheetStateChanged(behavior.state)
|
||||||
|
behavior.addBottomSheetCallback(bottomSheetCallback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onBottomSheetStateChanged(newState: Int) {
|
||||||
|
val expanded = newState == BottomSheetBehavior.STATE_EXPANDED && isOnTopOfScreen()
|
||||||
|
if (isBsExpanded != expanded) {
|
||||||
|
isBsExpanded = expanded
|
||||||
|
postAdjustState()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun suppressLayoutCompat(suppress: Boolean) {
|
||||||
|
if (suppress == isLayoutSuppressedCompat) return
|
||||||
|
isLayoutSuppressedCompat = suppress
|
||||||
|
if (!suppress && isLayoutCalledWhileSuppressed) {
|
||||||
|
requestLayout()
|
||||||
|
}
|
||||||
|
isLayoutCalledWhileSuppressed = false
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun dispatchInsets(insets: WindowInsetsCompat?) {
|
||||||
|
if (!fitStatusBar) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val isExpanded = binding.dragHandle.isGone
|
||||||
|
val topInset = insets?.getInsets(WindowInsetsCompat.Type.systemBars())?.top ?: 0
|
||||||
|
if (isExpanded) {
|
||||||
|
updatePadding(top = topInset)
|
||||||
|
} else {
|
||||||
|
updatePadding(top = 0)
|
||||||
|
binding.dragHandle.updateLayoutParams {
|
||||||
|
height = topInset.coerceIn(minHandleHeight, maxHandleHeight)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun findParentBottomSheetBehavior(): BottomSheetBehavior<*>? {
|
||||||
|
for (p in parents) {
|
||||||
|
val layoutParams = (p as? View)?.layoutParams
|
||||||
|
if (layoutParams is CoordinatorLayout.LayoutParams) {
|
||||||
|
val behavior = layoutParams.behavior
|
||||||
|
if (behavior is BottomSheetBehavior<*>) {
|
||||||
|
return behavior
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isOnTopOfScreen(): Boolean {
|
||||||
|
getLocationInWindow(locationBuffer)
|
||||||
|
val topInset = ViewCompat.getRootWindowInsets(this)
|
||||||
|
?.getInsets(WindowInsetsCompat.Type.systemBars())?.top ?: 0
|
||||||
|
val zeroTop = (layoutParams as? MarginLayoutParams)?.topMargin ?: 0
|
||||||
|
return (locationBuffer[1] - topInset) <= zeroTop
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun dismissBottomSheet() {
|
||||||
|
val behavior = bottomSheetBehavior ?: return
|
||||||
|
if (behavior.isHideable) {
|
||||||
|
behavior.state = BottomSheetBehavior.STATE_HIDDEN
|
||||||
|
} else {
|
||||||
|
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun shouldAddView(child: View?): Boolean {
|
||||||
|
if (child == null) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
val viewId = child.id
|
||||||
|
return viewId == R.id.dragHandle || viewId == R.id.toolbar
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun convertLayoutParams(params: ViewGroup.LayoutParams?): Toolbar.LayoutParams? {
|
||||||
|
return when (params) {
|
||||||
|
null -> null
|
||||||
|
is MarginLayoutParams -> {
|
||||||
|
val lp = Toolbar.LayoutParams(params)
|
||||||
|
if (params is LayoutParams) {
|
||||||
|
lp.gravity = params.gravity
|
||||||
|
}
|
||||||
|
lp
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> Toolbar.LayoutParams(params)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun postAdjustState() {
|
||||||
|
removeCallbacks(adjustStateRunnable)
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
if (stateAdjustedAt + THROTTLE_DELAY < now) {
|
||||||
|
adjustState()
|
||||||
|
} else {
|
||||||
|
postDelayed(adjustStateRunnable, THROTTLE_DELAY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun adjustState() {
|
||||||
|
suppressLayoutCompat(true)
|
||||||
|
binding.toolbar.navigationIcon = (if (isBsExpanded) closeDrawable else null)
|
||||||
|
binding.dragHandle.isGone = isBsExpanded
|
||||||
|
expansionListeners.forEach { it.onExpansionStateChanged(this, isBsExpanded) }
|
||||||
|
dispatchInsets(ViewCompat.getRootWindowInsets(this))
|
||||||
|
stateAdjustedAt = System.currentTimeMillis()
|
||||||
|
suppressLayoutCompat(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class Callback : BottomSheetBehavior.BottomSheetCallback(), OnClickListener {
|
||||||
|
|
||||||
|
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
||||||
|
onBottomSheetStateChanged(newState)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSlide(bottomSheet: View, slideOffset: Float) = Unit
|
||||||
|
|
||||||
|
override fun onClick(v: View?) {
|
||||||
|
dismissBottomSheet()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun interface OnExpansionChangeListener {
|
||||||
|
|
||||||
|
fun onExpansionStateChanged(headerBar: BottomSheetHeaderBar, isExpanded: Boolean)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.base.ui.widgets
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.util.AttributeSet
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.LinearLayout
|
|
||||||
import androidx.annotation.AttrRes
|
|
||||||
import androidx.annotation.IdRes
|
|
||||||
import androidx.core.view.children
|
|
||||||
import com.google.android.material.button.MaterialButton
|
|
||||||
|
|
||||||
class CheckableButtonGroup @JvmOverloads constructor(
|
|
||||||
context: Context,
|
|
||||||
attrs: AttributeSet? = null,
|
|
||||||
@AttrRes defStyleAttr: Int = 0,
|
|
||||||
) : LinearLayout(context, attrs, defStyleAttr), View.OnClickListener {
|
|
||||||
|
|
||||||
var onCheckedChangeListener: OnCheckedChangeListener? = null
|
|
||||||
|
|
||||||
override fun addView(child: View?, index: Int, params: ViewGroup.LayoutParams?) {
|
|
||||||
if (child is MaterialButton) {
|
|
||||||
child.setOnClickListener(this)
|
|
||||||
}
|
|
||||||
super.addView(child, index, params)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onClick(v: View) {
|
|
||||||
setCheckedId(v.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setCheckedId(@IdRes viewRes: Int) {
|
|
||||||
children.forEach {
|
|
||||||
(it as? MaterialButton)?.isChecked = it.id == viewRes
|
|
||||||
}
|
|
||||||
onCheckedChangeListener?.onCheckedChanged(this, viewRes)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun interface OnCheckedChangeListener {
|
|
||||||
fun onCheckedChanged(group: CheckableButtonGroup, checkedId: Int)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,6 +10,7 @@ import android.widget.Checkable
|
|||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
import androidx.appcompat.widget.AppCompatImageView
|
import androidx.appcompat.widget.AppCompatImageView
|
||||||
import androidx.core.os.ParcelCompat
|
import androidx.core.os.ParcelCompat
|
||||||
|
import androidx.customview.view.AbsSavedState
|
||||||
|
|
||||||
class CheckableImageView @JvmOverloads constructor(
|
class CheckableImageView @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
@@ -73,7 +74,7 @@ class CheckableImageView @JvmOverloads constructor(
|
|||||||
fun onCheckedChanged(view: CheckableImageView, isChecked: Boolean)
|
fun onCheckedChanged(view: CheckableImageView, isChecked: Boolean)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SavedState : BaseSavedState {
|
private class SavedState : AbsSavedState {
|
||||||
|
|
||||||
val isChecked: Boolean
|
val isChecked: Boolean
|
||||||
|
|
||||||
@@ -81,7 +82,7 @@ class CheckableImageView @JvmOverloads constructor(
|
|||||||
isChecked = checked
|
isChecked = checked
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(source: Parcel) : super(source) {
|
constructor(source: Parcel, classLoader: ClassLoader?) : super(source, classLoader) {
|
||||||
isChecked = ParcelCompat.readBoolean(source)
|
isChecked = ParcelCompat.readBoolean(source)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,9 +92,10 @@ class CheckableImageView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@Suppress("unused")
|
||||||
@JvmField
|
@JvmField
|
||||||
val CREATOR: Creator<SavedState> = object : Creator<SavedState> {
|
val CREATOR: Creator<SavedState> = object : Creator<SavedState> {
|
||||||
override fun createFromParcel(`in`: Parcel) = SavedState(`in`)
|
override fun createFromParcel(`in`: Parcel) = SavedState(`in`, SavedState::class.java.classLoader)
|
||||||
|
|
||||||
override fun newArray(size: Int): Array<SavedState?> = arrayOfNulls(size)
|
override fun newArray(size: Int): Array<SavedState?> = arrayOfNulls(size)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,23 +5,26 @@ import android.util.AttributeSet
|
|||||||
import android.view.View.OnClickListener
|
import android.view.View.OnClickListener
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.core.view.children
|
import androidx.core.view.children
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import com.google.android.material.chip.ChipDrawable
|
import com.google.android.material.chip.ChipDrawable
|
||||||
import com.google.android.material.chip.ChipGroup
|
import com.google.android.material.chip.ChipGroup
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.utils.ext.castOrNull
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getThemeColorStateList
|
||||||
|
|
||||||
class ChipsView @JvmOverloads constructor(
|
class ChipsView @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
attrs: AttributeSet? = null,
|
attrs: AttributeSet? = null,
|
||||||
defStyleAttr: Int = com.google.android.material.R.attr.chipGroupStyle
|
defStyleAttr: Int = com.google.android.material.R.attr.chipGroupStyle,
|
||||||
) : ChipGroup(context, attrs, defStyleAttr) {
|
) : ChipGroup(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
private var isLayoutSuppressedCompat = false
|
private var isLayoutSuppressedCompat = false
|
||||||
private var isLayoutCalledOnSuppressed = false
|
private var isLayoutCalledOnSuppressed = false
|
||||||
private var chipOnClickListener = OnClickListener {
|
private val chipOnClickListener = OnClickListener {
|
||||||
onChipClickListener?.onChipClick(it as Chip, it.tag)
|
onChipClickListener?.onChipClick(it as Chip, it.tag)
|
||||||
}
|
}
|
||||||
private var chipOnCloseListener = OnClickListener {
|
private val chipOnCloseListener = OnClickListener {
|
||||||
onChipCloseClickListener?.onChipCloseClick(it as Chip, it.tag)
|
onChipCloseClickListener?.onChipCloseClick(it as Chip, it.tag)
|
||||||
}
|
}
|
||||||
var onChipClickListener: OnChipClickListener? = null
|
var onChipClickListener: OnChipClickListener? = null
|
||||||
@@ -60,15 +63,27 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T> getCheckedData(cls: Class<T>): Set<T> {
|
||||||
|
val result = LinkedHashSet<T>(childCount)
|
||||||
|
for (child in children) {
|
||||||
|
if (child is Chip && child.isChecked) {
|
||||||
|
result += cls.castOrNull(child.tag) ?: continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
private fun bindChip(chip: Chip, model: ChipModel) {
|
private fun bindChip(chip: Chip, model: ChipModel) {
|
||||||
chip.text = model.title
|
chip.text = model.title
|
||||||
if (model.icon == 0) {
|
if (model.icon == 0) {
|
||||||
chip.isChipIconVisible = false
|
chip.isChipIconVisible = false
|
||||||
} else {
|
} else {
|
||||||
chip.isCheckedIconVisible = true
|
chip.isChipIconVisible = true
|
||||||
chip.setChipIconResource(model.icon)
|
chip.setChipIconResource(model.icon)
|
||||||
}
|
}
|
||||||
chip.isClickable = onChipClickListener != null
|
chip.isClickable = onChipClickListener != null || model.isCheckable
|
||||||
|
chip.isCheckable = model.isCheckable
|
||||||
|
chip.isChecked = model.isChecked
|
||||||
chip.tag = model.data
|
chip.tag = model.data
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,11 +91,13 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
val chip = Chip(context)
|
val chip = Chip(context)
|
||||||
val drawable = ChipDrawable.createFromAttributes(context, null, 0, R.style.Widget_Kotatsu_Chip)
|
val drawable = ChipDrawable.createFromAttributes(context, null, 0, R.style.Widget_Kotatsu_Chip)
|
||||||
chip.setChipDrawable(drawable)
|
chip.setChipDrawable(drawable)
|
||||||
|
chip.isCheckedIconVisible = true
|
||||||
|
chip.setCheckedIconResource(R.drawable.ic_check)
|
||||||
|
chip.checkedIconTint = context.getThemeColorStateList(materialR.attr.colorControlNormal)
|
||||||
chip.isCloseIconVisible = onChipCloseClickListener != null
|
chip.isCloseIconVisible = onChipCloseClickListener != null
|
||||||
chip.setOnCloseIconClickListener(chipOnCloseListener)
|
chip.setOnCloseIconClickListener(chipOnCloseListener)
|
||||||
chip.setEnsureMinTouchTargetSize(false)
|
chip.setEnsureMinTouchTargetSize(false)
|
||||||
chip.setOnClickListener(chipOnClickListener)
|
chip.setOnClickListener(chipOnClickListener)
|
||||||
chip.isCheckable = false
|
|
||||||
addView(chip)
|
addView(chip)
|
||||||
return chip
|
return chip
|
||||||
}
|
}
|
||||||
@@ -98,7 +115,9 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
class ChipModel(
|
class ChipModel(
|
||||||
@DrawableRes val icon: Int,
|
@DrawableRes val icon: Int,
|
||||||
val title: CharSequence,
|
val title: CharSequence,
|
||||||
val data: Any? = null
|
val isCheckable: Boolean,
|
||||||
|
val isChecked: Boolean,
|
||||||
|
val data: Any? = null,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
@@ -109,6 +128,8 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
|
|
||||||
if (icon != other.icon) return false
|
if (icon != other.icon) return false
|
||||||
if (title != other.title) return false
|
if (title != other.title) return false
|
||||||
|
if (isCheckable != other.isCheckable) return false
|
||||||
|
if (isChecked != other.isChecked) return false
|
||||||
if (data != other.data) return false
|
if (data != other.data) return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@@ -117,7 +138,9 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
var result = icon
|
var result = icon
|
||||||
result = 31 * result + title.hashCode()
|
result = 31 * result + title.hashCode()
|
||||||
result = 31 * result + data.hashCode()
|
result = 31 * result + isCheckable.hashCode()
|
||||||
|
result = 31 * result + isChecked.hashCode()
|
||||||
|
result = 31 * result + (data?.hashCode() ?: 0)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,4 +154,4 @@ class ChipsView @JvmOverloads constructor(
|
|||||||
|
|
||||||
fun onChipCloseClick(chip: Chip, data: Any?)
|
fun onChipCloseClick(chip: Chip, data: Any?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,133 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2018 Google LLC
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.koitharu.kotatsu.base.ui.widgets
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.res.ColorStateList
|
|
||||||
import android.graphics.drawable.Drawable
|
|
||||||
import android.util.AttributeSet
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.widget.FrameLayout
|
|
||||||
import androidx.annotation.ColorInt
|
|
||||||
import androidx.annotation.StringRes
|
|
||||||
import androidx.core.graphics.drawable.DrawableCompat
|
|
||||||
import androidx.core.view.postDelayed
|
|
||||||
import com.google.android.material.color.MaterialColors
|
|
||||||
import com.google.android.material.shape.MaterialShapeDrawable
|
|
||||||
import com.google.android.material.shape.ShapeAppearanceModel
|
|
||||||
import com.google.android.material.snackbar.Snackbar
|
|
||||||
import org.koitharu.kotatsu.databinding.FadingSnackbarLayoutBinding
|
|
||||||
import org.koitharu.kotatsu.utils.ext.getThemeColorStateList
|
|
||||||
import com.google.android.material.R as materialR
|
|
||||||
|
|
||||||
private const val ENTER_DURATION = 300L
|
|
||||||
private const val EXIT_DURATION = 200L
|
|
||||||
private const val SHORT_DURATION_MS = 1_500L
|
|
||||||
private const val LONG_DURATION_MS = 2_750L
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A custom snackbar implementation allowing more control over placement and entry/exit animations.
|
|
||||||
*
|
|
||||||
* Xtimms: Well, my sufferings over the Snackbar in [DetailsActivity] will go away forever... Thanks, Google.
|
|
||||||
*
|
|
||||||
* https://github.com/google/iosched/blob/main/mobile/src/main/java/com/google/samples/apps/iosched/widget/FadingSnackbar.kt
|
|
||||||
*/
|
|
||||||
class FadingSnackbar @JvmOverloads constructor(
|
|
||||||
context: Context,
|
|
||||||
attrs: AttributeSet? = null,
|
|
||||||
defStyleAttr: Int = 0,
|
|
||||||
) : FrameLayout(context, attrs, defStyleAttr) {
|
|
||||||
|
|
||||||
private val binding = FadingSnackbarLayoutBinding.inflate(LayoutInflater.from(context), this)
|
|
||||||
|
|
||||||
init {
|
|
||||||
binding.snackbarLayout.background = createThemedBackground()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun dismiss() {
|
|
||||||
if (visibility == VISIBLE && alpha == 1f) {
|
|
||||||
animate()
|
|
||||||
.alpha(0f)
|
|
||||||
.withEndAction { visibility = GONE }
|
|
||||||
.duration = EXIT_DURATION
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun show(
|
|
||||||
messageText: CharSequence?,
|
|
||||||
@StringRes actionId: Int = 0,
|
|
||||||
duration: Int = Snackbar.LENGTH_SHORT,
|
|
||||||
onActionClick: (FadingSnackbar.() -> Unit)? = null,
|
|
||||||
onDismiss: (() -> Unit)? = null,
|
|
||||||
) {
|
|
||||||
binding.snackbarText.text = messageText
|
|
||||||
if (actionId != 0) {
|
|
||||||
with(binding.snackbarAction) {
|
|
||||||
visibility = VISIBLE
|
|
||||||
text = context.getString(actionId)
|
|
||||||
setOnClickListener {
|
|
||||||
onActionClick?.invoke(this@FadingSnackbar) ?: dismiss()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
binding.snackbarAction.visibility = GONE
|
|
||||||
}
|
|
||||||
alpha = 0f
|
|
||||||
visibility = VISIBLE
|
|
||||||
animate()
|
|
||||||
.alpha(1f)
|
|
||||||
.duration = ENTER_DURATION
|
|
||||||
if (duration == Snackbar.LENGTH_INDEFINITE) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val durationMs = ENTER_DURATION + if (duration == Snackbar.LENGTH_LONG) LONG_DURATION_MS else SHORT_DURATION_MS
|
|
||||||
postDelayed(durationMs) {
|
|
||||||
dismiss()
|
|
||||||
onDismiss?.invoke()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createThemedBackground(): Drawable {
|
|
||||||
val backgroundColor = MaterialColors.layer(this, materialR.attr.colorSurface, materialR.attr.colorOnSurface, 1f)
|
|
||||||
val shapeAppearanceModel = ShapeAppearanceModel.builder(
|
|
||||||
context,
|
|
||||||
materialR.style.ShapeAppearance_Material3_Corner_ExtraSmall,
|
|
||||||
0
|
|
||||||
).build()
|
|
||||||
val background = createMaterialShapeDrawableBackground(
|
|
||||||
backgroundColor,
|
|
||||||
shapeAppearanceModel,
|
|
||||||
)
|
|
||||||
val backgroundTint = context.getThemeColorStateList(materialR.attr.colorSurfaceInverse)
|
|
||||||
return if (backgroundTint != null) {
|
|
||||||
val wrappedDrawable = DrawableCompat.wrap(background)
|
|
||||||
DrawableCompat.setTintList(wrappedDrawable, backgroundTint)
|
|
||||||
wrappedDrawable
|
|
||||||
} else {
|
|
||||||
DrawableCompat.wrap(background)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createMaterialShapeDrawableBackground(
|
|
||||||
@ColorInt backgroundColor: Int,
|
|
||||||
shapeAppearanceModel: ShapeAppearanceModel,
|
|
||||||
): MaterialShapeDrawable {
|
|
||||||
val background = MaterialShapeDrawable(shapeAppearanceModel)
|
|
||||||
background.fillColor = ColorStateList.valueOf(backgroundColor)
|
|
||||||
return background
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
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.animation.DecelerateInterpolator
|
||||||
|
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.R
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getAnimationDuration
|
||||||
|
import org.koitharu.kotatsu.utils.ext.measureHeight
|
||||||
|
|
||||||
|
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 = child.context.getAnimationDuration(R.integer.config_shorterAnimTime)
|
||||||
|
addUpdateListener {
|
||||||
|
child.translationY = it.animatedValue as Float
|
||||||
|
}
|
||||||
|
}
|
||||||
|
offsetAnimator?.setFloatValues(
|
||||||
|
child.translationY,
|
||||||
|
if (isVisible) 0F else child.height.toFloat(),
|
||||||
|
)
|
||||||
|
offsetAnimator?.start()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,16 +9,17 @@ import android.graphics.drawable.Drawable
|
|||||||
import android.graphics.drawable.InsetDrawable
|
import android.graphics.drawable.InsetDrawable
|
||||||
import android.graphics.drawable.RippleDrawable
|
import android.graphics.drawable.RippleDrawable
|
||||||
import android.graphics.drawable.ShapeDrawable
|
import android.graphics.drawable.ShapeDrawable
|
||||||
import android.graphics.drawable.shapes.RectShape
|
import android.graphics.drawable.shapes.RoundRectShape
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
import androidx.appcompat.widget.AppCompatCheckedTextView
|
import androidx.appcompat.widget.AppCompatCheckedTextView
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.withStyledAttributes
|
import androidx.core.content.withStyledAttributes
|
||||||
import com.google.android.material.ripple.RippleUtils
|
import com.google.android.material.ripple.RippleUtils
|
||||||
import com.google.android.material.shape.MaterialShapeDrawable
|
import com.google.android.material.shape.MaterialShapeDrawable
|
||||||
import com.google.android.material.shape.ShapeAppearanceModel
|
import com.google.android.material.shape.ShapeAppearanceModel
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.utils.ext.getThemeColorStateList
|
import org.koitharu.kotatsu.utils.ext.resolveDp
|
||||||
|
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
class ListItemTextView @JvmOverloads constructor(
|
class ListItemTextView @JvmOverloads constructor(
|
||||||
@@ -38,10 +39,11 @@ class ListItemTextView @JvmOverloads constructor(
|
|||||||
context.withStyledAttributes(attrs, R.styleable.ListItemTextView, defStyleAttr) {
|
context.withStyledAttributes(attrs, R.styleable.ListItemTextView, defStyleAttr) {
|
||||||
val itemRippleColor = getRippleColor(context)
|
val itemRippleColor = getRippleColor(context)
|
||||||
val shape = createShapeDrawable(this)
|
val shape = createShapeDrawable(this)
|
||||||
|
val roundCorners = FloatArray(8) { resources.resolveDp(32f) }
|
||||||
background = RippleDrawable(
|
background = RippleDrawable(
|
||||||
RippleUtils.sanitizeRippleDrawableColor(itemRippleColor),
|
RippleUtils.sanitizeRippleDrawableColor(itemRippleColor),
|
||||||
shape,
|
shape,
|
||||||
ShapeDrawable(RectShape()),
|
ShapeDrawable(RoundRectShape(roundCorners, null, null)),
|
||||||
)
|
)
|
||||||
checkedDrawableStart = getDrawable(R.styleable.ListItemTextView_checkedDrawableStart)
|
checkedDrawableStart = getDrawable(R.styleable.ListItemTextView_checkedDrawableStart)
|
||||||
checkedDrawableEnd = getDrawable(R.styleable.ListItemTextView_checkedDrawableEnd)
|
checkedDrawableEnd = getDrawable(R.styleable.ListItemTextView_checkedDrawableEnd)
|
||||||
@@ -118,7 +120,7 @@ class ListItemTextView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getRippleColor(context: Context): ColorStateList {
|
private fun getRippleColor(context: Context): ColorStateList {
|
||||||
return context.getThemeColorStateList(android.R.attr.colorControlHighlight)
|
return ContextCompat.getColorStateList(context, R.color.selector_overlay)
|
||||||
?: ColorStateList.valueOf(Color.TRANSPARENT)
|
?: ColorStateList.valueOf(Color.TRANSPARENT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
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 com.google.android.material.R as materialR
|
||||||
|
import kotlin.random.Random
|
||||||
|
import org.koitharu.kotatsu.parsers.util.replaceWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
|
import org.koitharu.kotatsu.utils.ext.resolveDp
|
||||||
|
|
||||||
|
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 segmentsSizes = ArrayList<Float>()
|
||||||
|
private val outlineColor = context.getThemeColor(materialR.attr.colorOutline)
|
||||||
|
private var cornerSize = 0f
|
||||||
|
|
||||||
|
var segments: List<Segment>
|
||||||
|
get() = segmentsData
|
||||||
|
set(value) {
|
||||||
|
segmentsData.replaceWith(value)
|
||||||
|
updateSizes()
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
paint.strokeWidth = context.resources.resolveDp(1f)
|
||||||
|
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 onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||||
|
super.onSizeChanged(w, h, oldw, oldh)
|
||||||
|
cornerSize = h / 2f
|
||||||
|
updateSizes()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDraw(canvas: Canvas) {
|
||||||
|
if (segmentsSizes.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val w = width.toFloat()
|
||||||
|
var x = w - segmentsSizes.last()
|
||||||
|
for (i in (0 until segmentsData.size).reversed()) {
|
||||||
|
val segment = segmentsData[i]
|
||||||
|
paint.color = segment.color
|
||||||
|
paint.style = Paint.Style.FILL
|
||||||
|
val segmentWidth = segmentsSizes[i]
|
||||||
|
canvas.drawRoundRect(0f, 0f, x + cornerSize, height.toFloat(), cornerSize, cornerSize, paint)
|
||||||
|
paint.color = outlineColor
|
||||||
|
paint.style = Paint.Style.STROKE
|
||||||
|
canvas.drawRoundRect(0f, 0f, x + cornerSize, height.toFloat(), cornerSize, cornerSize, paint)
|
||||||
|
x -= segmentWidth
|
||||||
|
}
|
||||||
|
paint.color = outlineColor
|
||||||
|
paint.style = Paint.Style.STROKE
|
||||||
|
canvas.drawRoundRect(0f, 0f, w, height.toFloat(), cornerSize, cornerSize, paint)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateSizes() {
|
||||||
|
segmentsSizes.clear()
|
||||||
|
segmentsSizes.ensureCapacity(segmentsData.size + 1)
|
||||||
|
var w = width.toFloat()
|
||||||
|
for (segment in segmentsData) {
|
||||||
|
val segmentWidth = (w * segment.percent).coerceAtLeast(cornerSize)
|
||||||
|
segmentsSizes.add(segmentWidth)
|
||||||
|
w -= segmentWidth
|
||||||
|
}
|
||||||
|
segmentsSizes.add(w)
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.text.Selection
|
||||||
|
import android.text.Spannable
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import androidx.annotation.AttrRes
|
||||||
|
import com.google.android.material.textview.MaterialTextView
|
||||||
|
|
||||||
|
class SelectableTextView @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
@AttrRes defStyleAttr: Int = android.R.attr.textViewStyle,
|
||||||
|
) : MaterialTextView(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
|
override fun dispatchTouchEvent(event: MotionEvent?): Boolean {
|
||||||
|
fixSelectionRange()
|
||||||
|
return super.dispatchTouchEvent(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://stackoverflow.com/questions/22810147/error-when-selecting-text-from-textview-java-lang-indexoutofboundsexception-se
|
||||||
|
private fun fixSelectionRange() {
|
||||||
|
if (selectionStart < 0 || selectionEnd < 0) {
|
||||||
|
val spannableText = text as? Spannable ?: return
|
||||||
|
Selection.setSelection(spannableText, text.length)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.Outline
|
||||||
|
import android.graphics.Paint
|
||||||
|
import android.graphics.Path
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewOutlineProvider
|
||||||
|
import androidx.core.content.withStyledAttributes
|
||||||
|
import androidx.core.graphics.withClip
|
||||||
|
import com.google.android.material.drawable.DrawableUtils
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
|
||||||
|
class ShapeView @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
defStyleAttr: Int = 0,
|
||||||
|
) : View(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
|
private val corners = FloatArray(8)
|
||||||
|
private val outlinePath = Path()
|
||||||
|
private val strokePaint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||||
|
|
||||||
|
init {
|
||||||
|
context.withStyledAttributes(attrs, R.styleable.ShapeView, defStyleAttr) {
|
||||||
|
val cornerSize = getDimension(R.styleable.ShapeView_cornerSize, 0f)
|
||||||
|
corners[0] = getDimension(R.styleable.ShapeView_cornerSizeTopLeft, cornerSize)
|
||||||
|
corners[1] = corners[0]
|
||||||
|
corners[2] = getDimension(R.styleable.ShapeView_cornerSizeTopRight, cornerSize)
|
||||||
|
corners[3] = corners[2]
|
||||||
|
corners[4] = getDimension(R.styleable.ShapeView_cornerSizeBottomRight, cornerSize)
|
||||||
|
corners[5] = corners[4]
|
||||||
|
corners[6] = getDimension(R.styleable.ShapeView_cornerSizeBottomLeft, cornerSize)
|
||||||
|
corners[7] = corners[6]
|
||||||
|
strokePaint.color = getColor(R.styleable.ShapeView_strokeColor, Color.TRANSPARENT)
|
||||||
|
strokePaint.strokeWidth = getDimension(R.styleable.ShapeView_strokeWidth, 0f)
|
||||||
|
strokePaint.style = Paint.Style.STROKE
|
||||||
|
}
|
||||||
|
outlineProvider = OutlineProvider()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||||
|
super.onSizeChanged(w, h, oldw, oldh)
|
||||||
|
if (w != oldw || h != oldh) {
|
||||||
|
rebuildPath()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun draw(canvas: Canvas) {
|
||||||
|
canvas.withClip(outlinePath) {
|
||||||
|
super.draw(canvas)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDraw(canvas: Canvas) {
|
||||||
|
super.onDraw(canvas)
|
||||||
|
if (strokePaint.strokeWidth > 0f) {
|
||||||
|
canvas.drawPath(outlinePath, strokePaint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun rebuildPath() {
|
||||||
|
outlinePath.reset()
|
||||||
|
val w = width
|
||||||
|
val h = height
|
||||||
|
if (w > 0 && h > 0) {
|
||||||
|
outlinePath.addRoundRect(0f, 0f, w.toFloat(), h.toFloat(), corners, Path.Direction.CW)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class OutlineProvider : ViewOutlineProvider() {
|
||||||
|
|
||||||
|
@SuppressLint("RestrictedApi")
|
||||||
|
override fun getOutline(view: View?, outline: Outline) {
|
||||||
|
val corner = corners[0]
|
||||||
|
var isRoundRect = true
|
||||||
|
for (item in corners) {
|
||||||
|
if (item != corner) {
|
||||||
|
isRoundRect = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isRoundRect) {
|
||||||
|
outline.setRoundRect(0, 0, width, height, corner)
|
||||||
|
} else {
|
||||||
|
DrawableUtils.setOutlineToPath(outline, outlinePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
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.annotation.AttrRes
|
||||||
|
import androidx.annotation.StyleRes
|
||||||
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
import androidx.customview.view.AbsSavedState
|
||||||
|
import androidx.interpolator.view.animation.FastOutLinearInInterpolator
|
||||||
|
import androidx.interpolator.view.animation.LinearOutSlowInInterpolator
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
|
import org.koitharu.kotatsu.utils.ext.applySystemAnimatorScale
|
||||||
|
import org.koitharu.kotatsu.utils.ext.measureHeight
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
class SlidingBottomNavigationView @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
@AttrRes defStyleAttr: Int = materialR.attr.bottomNavigationStyle,
|
||||||
|
@StyleRes defStyleRes: Int = materialR.style.Widget_Design_BottomNavigationView,
|
||||||
|
) : BottomNavigationView(context, attrs, defStyleAttr, defStyleRes),
|
||||||
|
CoordinatorLayout.AttachedBehavior {
|
||||||
|
|
||||||
|
private var currentAnimator: ViewPropertyAnimator? = null
|
||||||
|
|
||||||
|
private var currentState = STATE_UP
|
||||||
|
private var behavior = HideBottomNavigationOnScrollBehavior()
|
||||||
|
|
||||||
|
override fun getBehavior(): CoordinatorLayout.Behavior<*> {
|
||||||
|
return behavior
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSaveInstanceState(): Parcelable {
|
||||||
|
val superState = super.onSaveInstanceState()
|
||||||
|
return SavedState(superState, currentState, 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) {
|
||||||
|
super.setTranslationY(translationY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun show() {
|
||||||
|
currentAnimator?.cancel()
|
||||||
|
clearAnimation()
|
||||||
|
|
||||||
|
currentState = STATE_UP
|
||||||
|
animateTranslation(
|
||||||
|
0F,
|
||||||
|
SLIDE_UP_ANIMATION_DURATION,
|
||||||
|
LinearOutSlowInInterpolator(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hide() {
|
||||||
|
currentAnimator?.cancel()
|
||||||
|
clearAnimation()
|
||||||
|
|
||||||
|
currentState = STATE_DOWN
|
||||||
|
val target = measureHeight()
|
||||||
|
if (target == 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
animateTranslation(
|
||||||
|
target.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, currentState: Int, translationY: Float) : super(superState) {
|
||||||
|
this.currentState = currentState
|
||||||
|
this.translationY = translationY
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
@JvmField
|
||||||
|
val CREATOR: Parcelable.Creator<SavedState> = object : Parcelable.Creator<SavedState> {
|
||||||
|
override fun createFromParcel(`in`: Parcel) = SavedState(`in`, SavedState::class.java.classLoader)
|
||||||
|
|
||||||
|
override fun newArray(size: Int): Array<SavedState?> = arrayOfNulls(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.base.ui.widgets
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.util.AttributeSet
|
|
||||||
import android.widget.FrameLayout
|
|
||||||
|
|
||||||
class SquareLayout @JvmOverloads constructor(
|
|
||||||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
|
||||||
) : FrameLayout(context, attrs, defStyleAttr) {
|
|
||||||
|
|
||||||
public override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
|
||||||
super.onMeasure(widthMeasureSpec, widthMeasureSpec)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.koitharu.kotatsu.base.ui.widgets
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
@@ -21,8 +20,7 @@ class WindowInsetHolder @JvmOverloads constructor(
|
|||||||
private var desiredHeight = 0
|
private var desiredHeight = 0
|
||||||
private var desiredWidth = 0
|
private var desiredWidth = 0
|
||||||
|
|
||||||
@SuppressLint("RtlHardcoded")
|
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
|
||||||
override fun dispatchApplyWindowInsets(insets: WindowInsets): WindowInsets {
|
|
||||||
val barsInsets = WindowInsetsCompat.toWindowInsetsCompat(insets, this)
|
val barsInsets = WindowInsetsCompat.toWindowInsetsCompat(insets, this)
|
||||||
.getInsets(WindowInsetsCompat.Type.systemBars())
|
.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||||
val gravity = getLayoutGravity()
|
val gravity = getLayoutGravity()
|
||||||
@@ -41,24 +39,26 @@ class WindowInsetHolder @JvmOverloads constructor(
|
|||||||
desiredHeight = newHeight
|
desiredHeight = newHeight
|
||||||
requestLayout()
|
requestLayout()
|
||||||
}
|
}
|
||||||
return super.dispatchApplyWindowInsets(insets)
|
return super.onApplyWindowInsets(insets)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||||
val widthMode = MeasureSpec.getMode(widthMeasureSpec)
|
val widthMode = MeasureSpec.getMode(widthMeasureSpec)
|
||||||
|
val widthSize = MeasureSpec.getSize(widthMeasureSpec)
|
||||||
val heightMode = MeasureSpec.getMode(heightMeasureSpec)
|
val heightMode = MeasureSpec.getMode(heightMeasureSpec)
|
||||||
super.onMeasure(
|
val heightSize = MeasureSpec.getSize(heightMeasureSpec)
|
||||||
if (desiredWidth == 0 || widthMode == MeasureSpec.EXACTLY) {
|
|
||||||
widthMeasureSpec
|
val width: Int = when (widthMode) {
|
||||||
} else {
|
MeasureSpec.EXACTLY -> widthSize
|
||||||
MeasureSpec.makeMeasureSpec(desiredWidth, widthMode)
|
MeasureSpec.AT_MOST -> minOf(desiredWidth, widthSize)
|
||||||
},
|
else -> desiredWidth
|
||||||
if (desiredHeight == 0 || heightMode == MeasureSpec.EXACTLY) {
|
}
|
||||||
heightMeasureSpec
|
val height = when (heightMode) {
|
||||||
} else {
|
MeasureSpec.EXACTLY -> heightSize
|
||||||
MeasureSpec.makeMeasureSpec(desiredHeight, heightMode)
|
MeasureSpec.AT_MOST -> minOf(desiredHeight, heightSize)
|
||||||
},
|
else -> desiredHeight
|
||||||
)
|
}
|
||||||
|
setMeasuredDimension(width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getLayoutGravity(): Int {
|
private fun getLayoutGravity(): Int {
|
||||||
@@ -69,4 +69,4 @@ class WindowInsetHolder @JvmOverloads constructor(
|
|||||||
else -> Gravity.NO_GRAVITY
|
else -> Gravity.NO_GRAVITY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.bookmarks
|
|
||||||
|
|
||||||
import org.koin.dsl.module
|
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository
|
|
||||||
|
|
||||||
val bookmarksModule
|
|
||||||
get() = module {
|
|
||||||
|
|
||||||
factory { BookmarksRepository(get()) }
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,7 @@ import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
|||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
class BookmarkEntity(
|
data class BookmarkEntity(
|
||||||
@ColumnInfo(name = "manga_id", index = true) val mangaId: Long,
|
@ColumnInfo(name = "manga_id", index = true) val mangaId: Long,
|
||||||
@ColumnInfo(name = "page_id", index = true) val pageId: Long,
|
@ColumnInfo(name = "page_id", index = true) val pageId: Long,
|
||||||
@ColumnInfo(name = "chapter_id") val chapterId: Long,
|
@ColumnInfo(name = "chapter_id") val chapterId: Long,
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.bookmarks.data
|
|
||||||
|
|
||||||
import androidx.room.Embedded
|
|
||||||
import androidx.room.Junction
|
|
||||||
import androidx.room.Relation
|
|
||||||
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
|
||||||
import org.koitharu.kotatsu.core.db.entity.MangaTagsEntity
|
|
||||||
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
|
||||||
|
|
||||||
class BookmarkWithManga(
|
|
||||||
@Embedded val bookmark: BookmarkEntity,
|
|
||||||
@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>,
|
|
||||||
)
|
|
||||||
@@ -1,20 +1,27 @@
|
|||||||
package org.koitharu.kotatsu.bookmarks.data
|
package org.koitharu.kotatsu.bookmarks.data
|
||||||
|
|
||||||
import androidx.room.Dao
|
import androidx.room.*
|
||||||
import androidx.room.Delete
|
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.Query
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.MangaWithTags
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
abstract class BookmarksDao {
|
abstract class BookmarksDao {
|
||||||
|
|
||||||
|
@Query("SELECT * FROM bookmarks WHERE manga_id = :mangaId AND page_id = :pageId")
|
||||||
|
abstract suspend fun find(mangaId: Long, pageId: Long): BookmarkEntity?
|
||||||
|
|
||||||
@Query("SELECT * FROM bookmarks WHERE manga_id = :mangaId AND chapter_id = :chapterId AND page = :page")
|
@Query("SELECT * FROM bookmarks WHERE manga_id = :mangaId AND chapter_id = :chapterId AND page = :page")
|
||||||
abstract fun observe(mangaId: Long, chapterId: Long, page: Int): Flow<BookmarkEntity?>
|
abstract fun observe(mangaId: Long, chapterId: Long, page: Int): Flow<BookmarkEntity?>
|
||||||
|
|
||||||
@Query("SELECT * FROM bookmarks WHERE manga_id = :mangaId ORDER BY created_at DESC")
|
@Query("SELECT * FROM bookmarks WHERE manga_id = :mangaId ORDER BY created_at DESC")
|
||||||
abstract fun observe(mangaId: Long): Flow<List<BookmarkEntity>>
|
abstract fun observe(mangaId: Long): Flow<List<BookmarkEntity>>
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
@Query(
|
||||||
|
"SELECT * FROM manga JOIN bookmarks ON bookmarks.manga_id = manga.manga_id ORDER BY bookmarks.created_at"
|
||||||
|
)
|
||||||
|
abstract fun observe(): Flow<Map<MangaWithTags, List<BookmarkEntity>>>
|
||||||
|
|
||||||
@Insert
|
@Insert
|
||||||
abstract suspend fun insert(entity: BookmarkEntity)
|
abstract suspend fun insert(entity: BookmarkEntity)
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
package org.koitharu.kotatsu.bookmarks.data
|
package org.koitharu.kotatsu.bookmarks.data
|
||||||
|
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
import org.koitharu.kotatsu.core.db.entity.toManga
|
|
||||||
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
fun BookmarkWithManga.toBookmark() = bookmark.toBookmark(
|
|
||||||
manga.toManga(tags.toMangaTags())
|
|
||||||
)
|
|
||||||
|
|
||||||
fun BookmarkEntity.toBookmark(manga: Manga) = Bookmark(
|
fun BookmarkEntity.toBookmark(manga: Manga) = Bookmark(
|
||||||
manga = manga,
|
manga = manga,
|
||||||
pageId = pageId,
|
pageId = pageId,
|
||||||
@@ -30,4 +24,10 @@ fun Bookmark.toEntity() = BookmarkEntity(
|
|||||||
imageUrl = imageUrl,
|
imageUrl = imageUrl,
|
||||||
createdAt = createdAt.time,
|
createdAt = createdAt.time,
|
||||||
percent = percent,
|
percent = percent,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun Collection<BookmarkEntity>.toBookmarks(manga: Manga) = map {
|
||||||
|
it.toBookmark(manga)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Collection<Bookmark>.ids() = map { it.pageId }
|
||||||
@@ -1,17 +1,24 @@
|
|||||||
package org.koitharu.kotatsu.bookmarks.domain
|
package org.koitharu.kotatsu.bookmarks.domain
|
||||||
|
|
||||||
|
import android.database.SQLException
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
import org.koitharu.kotatsu.base.domain.ReversibleHandle
|
||||||
|
import org.koitharu.kotatsu.bookmarks.data.BookmarkEntity
|
||||||
import org.koitharu.kotatsu.bookmarks.data.toBookmark
|
import org.koitharu.kotatsu.bookmarks.data.toBookmark
|
||||||
|
import org.koitharu.kotatsu.bookmarks.data.toBookmarks
|
||||||
import org.koitharu.kotatsu.bookmarks.data.toEntity
|
import org.koitharu.kotatsu.bookmarks.data.toEntity
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.db.entity.toEntities
|
import org.koitharu.kotatsu.core.db.entity.toEntities
|
||||||
import org.koitharu.kotatsu.core.db.entity.toEntity
|
import org.koitharu.kotatsu.core.db.entity.toEntity
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toManga
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.utils.ext.mapItems
|
import org.koitharu.kotatsu.utils.ext.mapItems
|
||||||
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
|
||||||
class BookmarksRepository(
|
class BookmarksRepository @Inject constructor(
|
||||||
private val db: MangaDatabase,
|
private val db: MangaDatabase,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -23,6 +30,17 @@ class BookmarksRepository(
|
|||||||
return db.bookmarksDao.observe(manga.id).mapItems { it.toBookmark(manga) }
|
return db.bookmarksDao.observe(manga.id).mapItems { it.toBookmark(manga) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun observeBookmarks(): Flow<Map<Manga, List<Bookmark>>> {
|
||||||
|
return db.bookmarksDao.observe().map { map ->
|
||||||
|
val res = LinkedHashMap<Manga, List<Bookmark>>(map.size)
|
||||||
|
for ((k, v) in map) {
|
||||||
|
val manga = k.toManga()
|
||||||
|
res[manga] = v.toBookmarks(manga)
|
||||||
|
}
|
||||||
|
res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun addBookmark(bookmark: Bookmark) {
|
suspend fun addBookmark(bookmark: Bookmark) {
|
||||||
db.withTransaction {
|
db.withTransaction {
|
||||||
val tags = bookmark.manga.tags.toEntities()
|
val tags = bookmark.manga.tags.toEntities()
|
||||||
@@ -35,4 +53,38 @@ class BookmarksRepository(
|
|||||||
suspend fun removeBookmark(mangaId: Long, pageId: Long) {
|
suspend fun removeBookmark(mangaId: Long, pageId: Long) {
|
||||||
db.bookmarksDao.delete(mangaId, pageId)
|
db.bookmarksDao.delete(mangaId, pageId)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
suspend fun removeBookmarks(ids: Map<Manga, Set<Long>>): ReversibleHandle {
|
||||||
|
val entities = ArrayList<BookmarkEntity>(ids.size)
|
||||||
|
db.withTransaction {
|
||||||
|
val dao = db.bookmarksDao
|
||||||
|
for ((manga, idSet) in ids) {
|
||||||
|
for (pageId in idSet) {
|
||||||
|
val e = dao.find(manga.id, pageId)
|
||||||
|
if (e != null) {
|
||||||
|
entities.add(e)
|
||||||
|
}
|
||||||
|
dao.delete(manga.id, pageId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return BookmarksRestorer(entities)
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class BookmarksRestorer(
|
||||||
|
private val entities: Collection<BookmarkEntity>,
|
||||||
|
) : ReversibleHandle {
|
||||||
|
|
||||||
|
override suspend fun reverse() {
|
||||||
|
db.withTransaction {
|
||||||
|
for (e in entities) {
|
||||||
|
try {
|
||||||
|
db.bookmarksDao.insert(e)
|
||||||
|
} catch (e: SQLException) {
|
||||||
|
e.printStackTraceDebug()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package org.koitharu.kotatsu.bookmarks.ui
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
import androidx.core.graphics.Insets
|
||||||
|
import androidx.core.view.updateLayoutParams
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
|
import androidx.fragment.app.commit
|
||||||
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
|
import org.koitharu.kotatsu.databinding.ActivityContainerBinding
|
||||||
|
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
|
||||||
|
import org.koitharu.kotatsu.main.ui.owners.SnackbarOwner
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
|
class BookmarksActivity :
|
||||||
|
BaseActivity<ActivityContainerBinding>(),
|
||||||
|
AppBarOwner,
|
||||||
|
SnackbarOwner {
|
||||||
|
|
||||||
|
override val appBar: AppBarLayout
|
||||||
|
get() = binding.appbar
|
||||||
|
|
||||||
|
override val snackbarHost: CoordinatorLayout
|
||||||
|
get() = binding.root
|
||||||
|
|
||||||
|
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) {
|
||||||
|
binding.root.updatePadding(
|
||||||
|
left = insets.left,
|
||||||
|
right = insets.right,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
fun newIntent(context: Context) = Intent(context, BookmarksActivity::class.java)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,200 @@
|
|||||||
|
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.updateLayoutParams
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
|
import androidx.fragment.app.viewModels
|
||||||
|
import coil.ImageLoader
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import javax.inject.Inject
|
||||||
|
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.list.fastscroll.FastScroller
|
||||||
|
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.main.ui.owners.AppBarOwner
|
||||||
|
import org.koitharu.kotatsu.main.ui.owners.SnackbarOwner
|
||||||
|
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
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
|
class BookmarksFragment :
|
||||||
|
BaseFragment<FragmentListSimpleBinding>(),
|
||||||
|
ListStateHolderListener,
|
||||||
|
OnListItemClickListener<Bookmark>,
|
||||||
|
SectionedSelectionController.Callback<Manga>,
|
||||||
|
FastScroller.FastScrollListener {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var coil: ImageLoader
|
||||||
|
|
||||||
|
private val viewModel by viewModels<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(),
|
||||||
|
owner = this,
|
||||||
|
callback = this,
|
||||||
|
)
|
||||||
|
adapter = BookmarksGroupAdapter(
|
||||||
|
lifecycleOwner = viewLifecycleOwner,
|
||||||
|
coil = coil,
|
||||||
|
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 onFastScrollStart(fastScroller: FastScroller) {
|
||||||
|
(activity as? AppBarOwner)?.appBar?.setExpanded(false, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFastScrollStop(fastScroller: FastScroller) = Unit
|
||||||
|
|
||||||
|
override fun onSelectionChanged(controller: SectionedSelectionController<Manga>, count: Int) {
|
||||||
|
binding.recyclerView.invalidateNestedItemDecorations()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateActionMode(
|
||||||
|
controller: SectionedSelectionController<Manga>,
|
||||||
|
mode: ActionMode,
|
||||||
|
menu: Menu,
|
||||||
|
): Boolean {
|
||||||
|
mode.menuInflater.inflate(R.menu.mode_bookmarks, menu)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActionItemClicked(
|
||||||
|
controller: SectionedSelectionController<Manga>,
|
||||||
|
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(
|
||||||
|
controller: SectionedSelectionController<Manga>,
|
||||||
|
section: Manga,
|
||||||
|
): AbstractSelectionItemDecoration = BookmarksSelectionDecoration(requireContext())
|
||||||
|
|
||||||
|
override fun onWindowInsetsChanged(insets: Insets) {
|
||||||
|
binding.recyclerView.updatePadding(
|
||||||
|
bottom = insets.bottom,
|
||||||
|
)
|
||||||
|
binding.recyclerView.fastScroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||||
|
bottomMargin = 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((activity as SnackbarOwner).snackbarHost, 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,54 @@
|
|||||||
|
package org.koitharu.kotatsu.bookmarks.ui
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import javax.inject.Inject
|
||||||
|
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
|
||||||
|
|
||||||
|
@HiltViewModel
|
||||||
|
class BookmarksViewModel @Inject constructor(
|
||||||
|
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 -> emit(listOf(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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,51 +1,41 @@
|
|||||||
package org.koitharu.kotatsu.bookmarks.ui
|
package org.koitharu.kotatsu.bookmarks.ui.adapter
|
||||||
|
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import coil.request.Disposable
|
|
||||||
import coil.size.Scale
|
|
||||||
import coil.util.CoilUtils
|
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.list.AdapterDelegateClickListenerAdapter
|
import org.koitharu.kotatsu.base.ui.list.AdapterDelegateClickListenerAdapter
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
import org.koitharu.kotatsu.bookmarks.domain.Bookmark
|
||||||
import org.koitharu.kotatsu.databinding.ItemBookmarkBinding
|
import org.koitharu.kotatsu.databinding.ItemBookmarkBinding
|
||||||
|
import org.koitharu.kotatsu.utils.ext.disposeImageRequest
|
||||||
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
||||||
import org.koitharu.kotatsu.utils.ext.referer
|
|
||||||
|
|
||||||
fun bookmarkListAD(
|
fun bookmarkListAD(
|
||||||
coil: ImageLoader,
|
coil: ImageLoader,
|
||||||
lifecycleOwner: LifecycleOwner,
|
lifecycleOwner: LifecycleOwner,
|
||||||
clickListener: OnListItemClickListener<Bookmark>,
|
clickListener: OnListItemClickListener<Bookmark>,
|
||||||
) = adapterDelegateViewBinding<Bookmark, Bookmark, ItemBookmarkBinding>(
|
) = adapterDelegateViewBinding<Bookmark, Bookmark, ItemBookmarkBinding>(
|
||||||
{ inflater, parent -> ItemBookmarkBinding.inflate(inflater, parent, false) }
|
{ inflater, parent -> ItemBookmarkBinding.inflate(inflater, parent, false) },
|
||||||
) {
|
) {
|
||||||
|
|
||||||
var imageRequest: Disposable? = null
|
|
||||||
val listener = AdapterDelegateClickListenerAdapter(this, clickListener)
|
val listener = AdapterDelegateClickListenerAdapter(this, clickListener)
|
||||||
|
|
||||||
binding.root.setOnClickListener(listener)
|
binding.root.setOnClickListener(listener)
|
||||||
binding.root.setOnLongClickListener(listener)
|
binding.root.setOnLongClickListener(listener)
|
||||||
|
|
||||||
bind {
|
bind {
|
||||||
imageRequest?.dispose()
|
binding.imageViewThumb.newImageRequest(item.imageUrl, item.manga.source)?.run {
|
||||||
imageRequest = binding.imageViewThumb.newImageRequest(item.imageUrl)
|
placeholder(R.drawable.ic_placeholder)
|
||||||
.referer(item.manga.publicUrl)
|
fallback(R.drawable.ic_placeholder)
|
||||||
.placeholder(R.drawable.ic_placeholder)
|
error(R.drawable.ic_error_placeholder)
|
||||||
.fallback(R.drawable.ic_placeholder)
|
allowRgb565(true)
|
||||||
.error(R.drawable.ic_placeholder)
|
lifecycle(lifecycleOwner)
|
||||||
.allowRgb565(true)
|
enqueueWith(coil)
|
||||||
.scale(Scale.FILL)
|
}
|
||||||
.lifecycle(lifecycleOwner)
|
|
||||||
.enqueueWith(coil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onViewRecycled {
|
onViewRecycled {
|
||||||
imageRequest?.dispose()
|
binding.imageViewThumb.disposeImageRequest()
|
||||||
imageRequest = null
|
|
||||||
CoilUtils.dispose(binding.imageViewThumb)
|
|
||||||
binding.imageViewThumb.setImageDrawable(null)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.bookmarks.ui
|
package org.koitharu.kotatsu.bookmarks.ui.adapter
|
||||||
|
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
@@ -19,7 +19,7 @@ class BookmarksAdapter(
|
|||||||
private class DiffCallback : DiffUtil.ItemCallback<Bookmark>() {
|
private class DiffCallback : DiffUtil.ItemCallback<Bookmark>() {
|
||||||
|
|
||||||
override fun areItemsTheSame(oldItem: Bookmark, newItem: Bookmark): Boolean {
|
override fun areItemsTheSame(oldItem: Bookmark, newItem: Bookmark): Boolean {
|
||||||
return oldItem.manga.id == newItem.manga.id && oldItem.chapterId == newItem.chapterId
|
return oldItem.manga.id == newItem.manga.id && oldItem.pageId == newItem.pageId
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun areContentsTheSame(oldItem: Bookmark, newItem: Bookmark): Boolean {
|
override fun areContentsTheSame(oldItem: Bookmark, newItem: Bookmark): Boolean {
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
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.clearItemDecorations
|
||||||
|
import org.koitharu.kotatsu.utils.ext.disposeImageRequest
|
||||||
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
||||||
|
|
||||||
|
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, item.manga.source)?.run {
|
||||||
|
placeholder(R.drawable.ic_placeholder)
|
||||||
|
fallback(R.drawable.ic_placeholder)
|
||||||
|
error(R.drawable.ic_error_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 kotlin.jvm.internal.Intrinsics
|
||||||
|
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
|
||||||
|
|
||||||
|
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(coil, 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,15 +11,17 @@ import android.view.MenuItem
|
|||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import com.google.android.material.R as materialR
|
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.base.ui.BaseActivity
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
import org.koitharu.kotatsu.core.network.UserAgentInterceptor
|
import org.koitharu.kotatsu.core.network.CommonHeadersInterceptor
|
||||||
import org.koitharu.kotatsu.databinding.ActivityBrowserBinding
|
import org.koitharu.kotatsu.databinding.ActivityBrowserBinding
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback {
|
class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback {
|
||||||
|
|
||||||
|
private lateinit var onBackPressedCallback: WebViewBackPressedCallback
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(ActivityBrowserBinding.inflate(layoutInflater))
|
setContentView(ActivityBrowserBinding.inflate(layoutInflater))
|
||||||
@@ -29,10 +31,12 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
}
|
}
|
||||||
with(binding.webView.settings) {
|
with(binding.webView.settings) {
|
||||||
javaScriptEnabled = true
|
javaScriptEnabled = true
|
||||||
userAgentString = UserAgentInterceptor.userAgent
|
userAgentString = CommonHeadersInterceptor.userAgentChrome
|
||||||
}
|
}
|
||||||
binding.webView.webViewClient = BrowserClient(this)
|
binding.webView.webViewClient = BrowserClient(this)
|
||||||
binding.webView.webChromeClient = ProgressChromeClient(binding.progressBar)
|
binding.webView.webChromeClient = ProgressChromeClient(binding.progressBar)
|
||||||
|
onBackPressedCallback = WebViewBackPressedCallback(binding.webView)
|
||||||
|
onBackPressedDispatcher.addCallback(onBackPressedCallback)
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -42,7 +46,7 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
} else {
|
} else {
|
||||||
onTitleChanged(
|
onTitleChanged(
|
||||||
intent?.getStringExtra(EXTRA_TITLE) ?: getString(R.string.loading_),
|
intent?.getStringExtra(EXTRA_TITLE) ?: getString(R.string.loading_),
|
||||||
url
|
url,
|
||||||
)
|
)
|
||||||
binding.webView.loadUrl(url)
|
binding.webView.loadUrl(url)
|
||||||
}
|
}
|
||||||
@@ -59,8 +63,9 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
|
super.onCreateOptionsMenu(menu)
|
||||||
menuInflater.inflate(R.menu.opt_browser, menu)
|
menuInflater.inflate(R.menu.opt_browser, menu)
|
||||||
return super.onCreateOptionsMenu(menu)
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
||||||
@@ -69,6 +74,7 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
finishAfterTransition()
|
finishAfterTransition()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.action_browser -> {
|
R.id.action_browser -> {
|
||||||
val intent = Intent(Intent.ACTION_VIEW)
|
val intent = Intent(Intent.ACTION_VIEW)
|
||||||
intent.data = Uri.parse(binding.webView.url)
|
intent.data = Uri.parse(binding.webView.url)
|
||||||
@@ -78,15 +84,8 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else -> super.onOptionsItemSelected(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBackPressed() {
|
else -> super.onOptionsItemSelected(item)
|
||||||
if (binding.webView.canGoBack()) {
|
|
||||||
binding.webView.goBack()
|
|
||||||
} else {
|
|
||||||
super.onBackPressed()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
@@ -113,11 +112,13 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
supportActionBar?.subtitle = subtitle
|
supportActionBar?.subtitle = subtitle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onHistoryChanged() {
|
||||||
|
onBackPressedCallback.onHistoryChanged()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onWindowInsetsChanged(insets: Insets) {
|
override fun onWindowInsetsChanged(insets: Insets) {
|
||||||
binding.appbar.updatePadding(
|
binding.appbar.updatePadding(
|
||||||
top = insets.top,
|
top = insets.top,
|
||||||
left = insets.left,
|
|
||||||
right = insets.right,
|
|
||||||
)
|
)
|
||||||
binding.root.updatePadding(
|
binding.root.updatePadding(
|
||||||
left = insets.left,
|
left = insets.left,
|
||||||
@@ -136,4 +137,4 @@ class BrowserActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallback
|
|||||||
.putExtra(EXTRA_TITLE, title)
|
.putExtra(EXTRA_TITLE, title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package org.koitharu.kotatsu.browser
|
package org.koitharu.kotatsu.browser
|
||||||
|
|
||||||
interface BrowserCallback {
|
interface BrowserCallback : OnHistoryChangedListener {
|
||||||
|
|
||||||
fun onLoadingStateChanged(isLoading: Boolean)
|
fun onLoadingStateChanged(isLoading: Boolean)
|
||||||
|
|
||||||
fun onTitleChanged(title: CharSequence, subtitle: CharSequence?)
|
fun onTitleChanged(title: CharSequence, subtitle: CharSequence?)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ package org.koitharu.kotatsu.browser
|
|||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import org.koin.core.component.KoinComponent
|
import android.webkit.WebViewClient
|
||||||
import org.koitharu.kotatsu.core.network.WebViewClientCompat
|
|
||||||
|
|
||||||
class BrowserClient(private val callback: BrowserCallback) : WebViewClientCompat(), KoinComponent {
|
open class BrowserClient(private val callback: BrowserCallback) : WebViewClient() {
|
||||||
|
|
||||||
override fun onPageFinished(webView: WebView, url: String) {
|
override fun onPageFinished(webView: WebView, url: String) {
|
||||||
super.onPageFinished(webView, url)
|
super.onPageFinished(webView, url)
|
||||||
@@ -21,4 +20,9 @@ class BrowserClient(private val callback: BrowserCallback) : WebViewClientCompat
|
|||||||
super.onPageCommitVisible(view, url)
|
super.onPageCommitVisible(view, url)
|
||||||
callback.onTitleChanged(view.title.orEmpty(), url)
|
callback.onTitleChanged(view.title.orEmpty(), url)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
override fun doUpdateVisitedHistory(view: WebView?, url: String?, isReload: Boolean) {
|
||||||
|
super.doUpdateVisitedHistory(view, url, isReload)
|
||||||
|
callback.onHistoryChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||