mirror of
https://github.com/seven332/EhViewer
synced 2026-11-28 01:58:06 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba6d41b91f | ||
|
|
6a9e0198a2 | ||
|
|
92f716170c | ||
|
|
d72f686d5a | ||
|
|
28eade9451 | ||
|
|
7b95bc804a | ||
|
|
47c9d48787 | ||
|
|
8a7adbe838 | ||
|
|
0248fd4e02 | ||
|
|
1cd5f7bbf7 | ||
|
|
db893b899d | ||
|
|
d86dd3bc06 | ||
|
|
49f420c1eb | ||
|
|
c9103caad8 | ||
|
|
ee0ffc48d2 | ||
|
|
ed7eba7ef4 | ||
|
|
b6a16d1d58 | ||
|
|
04521dfeb6 | ||
|
|
d00f6e6cc6 | ||
|
|
7a47b2504d | ||
|
|
2da10a5855 | ||
|
|
323b36c58a | ||
|
|
9834d45ca9 | ||
|
|
c058bb01f0 | ||
|
|
f578c6cb8b | ||
|
|
2c43589c1c | ||
|
|
6e73f03c19 | ||
|
|
b7e2c5bce1 | ||
|
|
9707ac470a | ||
|
|
06fd28290c | ||
|
|
21ef5897ef | ||
|
|
bdd45b5f10 | ||
|
|
e68d4ad2c4 | ||
|
|
2e56ba4ed0 | ||
|
|
54b6dd99a9 | ||
|
|
6389b09d64 | ||
|
|
998d87b206 | ||
|
|
0b6a9da664 | ||
|
|
6086175ef6 | ||
|
|
5e690c6983 | ||
|
|
a898f289fe | ||
|
|
a215389b98 | ||
|
|
60af7937c7 | ||
|
|
4064510b14 | ||
|
|
c9146324f8 | ||
|
|
bd7c806ad9 | ||
|
|
efe7d4757a | ||
|
|
3554fe1188 | ||
|
|
06357b37d6 | ||
|
|
ae2443fbf0 | ||
|
|
19403975ba | ||
|
|
5087311b26 | ||
|
|
de854ac7ac | ||
|
|
40c0506f6e | ||
|
|
7beb49e599 | ||
|
|
7c5486aa08 | ||
|
|
120124101a | ||
|
|
c286d2c543 | ||
|
|
5f411661e9 | ||
|
|
981a7c7851 | ||
|
|
43b169371d | ||
|
|
311dabba17 | ||
|
|
c7d7ce8225 | ||
|
|
4b1c6ac917 | ||
|
|
24612b7d14 | ||
|
|
3530faabf1 | ||
|
|
0f3a95575c | ||
|
|
0334833bf8 | ||
|
|
1b1d94a98d | ||
|
|
dfa1de9745 | ||
|
|
84fe397c18 | ||
|
|
07b1b5034d | ||
|
|
7f73eb0bd4 | ||
|
|
f129ac649d | ||
|
|
e9d5569e81 | ||
|
|
db31e5c740 | ||
|
|
c83fcee21a | ||
|
|
6270e1695d | ||
|
|
a8b11c8e21 | ||
|
|
a12b2c4eac | ||
|
|
31412b78cf | ||
|
|
4a986a8428 | ||
|
|
d58b2ba03e | ||
|
|
176c64330f | ||
|
|
342ed0c709 | ||
|
|
d8ee689db7 | ||
|
|
229e429809 | ||
|
|
f5128cd17a | ||
|
|
5e5a736f1c | ||
|
|
1ec3681b7c | ||
|
|
67f9b6cb83 | ||
|
|
58ac39cf2c | ||
|
|
3cd4fc7ce9 | ||
|
|
d731719f1c | ||
|
|
be0c394de1 | ||
|
|
a739300260 | ||
|
|
da9940d581 | ||
|
|
a2523aae75 | ||
|
|
3ae3602671 | ||
|
|
6350fc1ece | ||
|
|
29a27cbe00 | ||
|
|
5fc0fb997a | ||
|
|
aa01ddd594 | ||
|
|
8774268adf | ||
|
|
265cbd0df5 | ||
|
|
82cdfeb1b2 | ||
|
|
71dd9d3693 | ||
|
|
fd9f1bd219 | ||
|
|
956b7455a3 | ||
|
|
b3c855a5dc | ||
|
|
06e624a1e3 | ||
|
|
871c0a43ca | ||
|
|
6775246d4c | ||
|
|
a0b0109424 | ||
|
|
c5566aa5e8 | ||
|
|
1d70572d92 | ||
|
|
5dc6446d64 | ||
|
|
13eb9e2f16 | ||
|
|
7e1e4a0f57 | ||
|
|
c0933eb8f0 | ||
|
|
a0e6a847ab | ||
|
|
23a7053597 | ||
|
|
d463cf2295 | ||
|
|
94db37c899 | ||
|
|
94f6eecbc7 | ||
|
|
c0f20ca975 | ||
|
|
749f2610af | ||
|
|
a2a6422917 | ||
|
|
df72243bb6 | ||
|
|
50c7a23566 | ||
|
|
1cbb725920 | ||
|
|
8b76eaa740 | ||
|
|
65f320f8f7 | ||
|
|
a7e4a2cd61 | ||
|
|
88baeeb335 | ||
|
|
00289d106d | ||
|
|
08d1ef87d4 | ||
|
|
388d507257 | ||
|
|
89209a3c44 | ||
|
|
9208c53d4f | ||
|
|
defa670a26 | ||
|
|
2ec229c8ef | ||
|
|
e5df5714de | ||
|
|
5b8e031e50 | ||
|
|
b0ccfe4793 | ||
|
|
b101ae142d | ||
|
|
c165c9071d | ||
|
|
7fc9ef9e1f | ||
|
|
c4514589c0 | ||
|
|
0305c541aa | ||
|
|
7631e3b4f9 | ||
|
|
350d846a39 | ||
|
|
c119562c16 | ||
|
|
37de170729 | ||
|
|
8d992d737e | ||
|
|
81434a682f | ||
|
|
b3a446ffcd | ||
|
|
e659ba91b4 | ||
|
|
7866722ec4 | ||
|
|
2a944f5e0a | ||
|
|
34eccad8be | ||
|
|
57a18b7215 | ||
|
|
6c253238ad | ||
|
|
c08068eeea | ||
|
|
303c51f93d | ||
|
|
e1a88cdfe3 | ||
|
|
6adad86bc5 | ||
|
|
0dbb030663 | ||
|
|
169f4c3eb8 | ||
|
|
dd700a0f2d | ||
|
|
77a2875b9f | ||
|
|
fd5f6c3466 | ||
|
|
3380389453 | ||
|
|
fc9270d48c | ||
|
|
a3aa4ba17f | ||
|
|
cca6e2a72e | ||
|
|
cc9205700c | ||
|
|
ced2139703 | ||
|
|
2ad5edfe3b | ||
|
|
b6e822e6d1 | ||
|
|
4d4571aa30 | ||
|
|
c326adfe48 | ||
|
|
b8cb9f66b6 | ||
|
|
c5a6526171 | ||
|
|
6d72349ee7 | ||
|
|
334c248acb | ||
|
|
41ef8d2374 | ||
|
|
fef42c0832 | ||
|
|
8ffd959659 | ||
|
|
5c0772e5b9 | ||
|
|
0afb78da3f | ||
|
|
04a5c762dd | ||
|
|
1eaad6f669 | ||
|
|
beeb083cb3 | ||
|
|
ce5655def6 | ||
|
|
f1c446f7de | ||
|
|
ca6b2c6917 | ||
|
|
95bb75c9b4 | ||
|
|
073934a2a0 | ||
|
|
1edb8941ee | ||
|
|
81195726d5 | ||
|
|
bc2b21b0f5 | ||
|
|
ec132440e7 | ||
|
|
9d49973504 | ||
|
|
016ec23fbd | ||
|
|
59d141fc8e | ||
|
|
3d3c3a9273 | ||
|
|
c580938806 | ||
|
|
3904406d74 | ||
|
|
879b8fa50a | ||
|
|
7228736c95 | ||
|
|
e8eb126135 | ||
|
|
0eb86e37e6 | ||
|
|
eff2ed94fe | ||
|
|
fb2011a408 | ||
|
|
a442578927 | ||
|
|
673735ab2e | ||
|
|
f1bab7e3d4 | ||
|
|
1d5b26ee51 | ||
|
|
a1a82b0ce9 | ||
|
|
5b961d71b8 | ||
|
|
0353c1cebb | ||
|
|
7b07bdc51f | ||
|
|
cf1ac32e17 | ||
|
|
bb28dd97cc | ||
|
|
a33bd63e6e | ||
|
|
a0b786b2a6 | ||
|
|
9dd39412d4 | ||
|
|
3fdf9453ef | ||
|
|
116f30e496 | ||
|
|
e8d05c273f | ||
|
|
29e3a50cd3 | ||
|
|
1409571ad8 | ||
|
|
8a7e72c412 | ||
|
|
948cb9ef9c | ||
|
|
926391a0fe | ||
|
|
24195430ab | ||
|
|
c9afa597d5 | ||
|
|
adf38af673 | ||
|
|
17f2bb670e | ||
|
|
2293654da8 | ||
|
|
36067c9fac | ||
|
|
8d20621ad4 | ||
|
|
a1d1db14c6 | ||
|
|
44cf2b67d0 | ||
|
|
74c0e478ef | ||
|
|
7496534b30 | ||
|
|
415ffbc21d | ||
|
|
ed4267cb36 | ||
|
|
2de859398b | ||
|
|
62348433df | ||
|
|
b64b14c69a | ||
|
|
28e8e91303 | ||
|
|
44026f0ccc | ||
|
|
95f2d46420 | ||
|
|
8f76f50526 | ||
|
|
ecd215d632 | ||
|
|
b138de9563 | ||
|
|
9bd344cc58 | ||
|
|
ababfd57a6 | ||
|
|
45c760a507 | ||
|
|
e721a6da1f | ||
|
|
9eeba868d5 | ||
|
|
8f3247bac4 | ||
|
|
e5a375c3fe | ||
|
|
8d75752835 | ||
|
|
8af786e687 | ||
|
|
4b1c516b3e | ||
|
|
f32b79ba72 | ||
|
|
92b5f2d766 | ||
|
|
a5767e0fe6 | ||
|
|
2fc48bb726 | ||
|
|
4a5a426fd3 | ||
|
|
06adf8594c | ||
|
|
1ac43e6293 | ||
|
|
ceeb84812b | ||
|
|
bfd85e9bc7 | ||
|
|
8c3796605e | ||
|
|
3214bae157 | ||
|
|
a5b178df49 | ||
|
|
c2a93f2ce4 | ||
|
|
257758b27d | ||
|
|
2681e4a6e6 | ||
|
|
722653ac46 | ||
|
|
cb706941c5 | ||
|
|
195e9a5655 | ||
|
|
ed2043ab7a | ||
|
|
405655d0e2 | ||
|
|
0cead11180 | ||
|
|
141ab73089 | ||
|
|
7c349153de | ||
|
|
168b701cca | ||
|
|
0b67e685d2 | ||
|
|
741bb10a1c | ||
|
|
829591229d | ||
|
|
cbed5ee8cb | ||
|
|
a2db9038e3 | ||
|
|
14328eaf83 | ||
|
|
a11fb869e2 | ||
|
|
1285abdf71 | ||
|
|
f0fa226b16 | ||
|
|
88aebbd075 | ||
|
|
2c08a7b56f | ||
|
|
561e396c97 | ||
|
|
f8676b71dc | ||
|
|
259550e5cc | ||
|
|
478e53ab96 | ||
|
|
286b39e679 | ||
|
|
af771c7086 | ||
|
|
24d386da44 | ||
|
|
419405f4e2 | ||
|
|
e8de8ac5c8 | ||
|
|
934ec87390 | ||
|
|
46bd8e4297 | ||
|
|
70ceb83205 | ||
|
|
0553fda3fa | ||
|
|
b5f36dafdc | ||
|
|
77fd0eb73e | ||
|
|
ff6b0bf01d | ||
|
|
6734ace077 | ||
|
|
c013c82f90 | ||
|
|
618ca14eca | ||
|
|
700ebdfee3 | ||
|
|
9899552e4b | ||
|
|
7104fddded | ||
|
|
54f1c4806f | ||
|
|
9c66298cb8 | ||
|
|
bb266d46d3 | ||
|
|
8cd7d01e10 | ||
|
|
9692224dec | ||
|
|
41b4f00b91 | ||
|
|
611a4c8853 | ||
|
|
c8f1080b9e | ||
|
|
92ecf84c5e | ||
|
|
d9c0c80172 | ||
|
|
74a7b16252 | ||
|
|
5ccbeda6d5 | ||
|
|
75a2be5d38 | ||
|
|
c5d5778961 | ||
|
|
eb16df63e1 | ||
|
|
1bb2f6eb5f | ||
|
|
4a905a5226 | ||
|
|
fe60b26eec | ||
|
|
3b1028b9cc | ||
|
|
36b7a6211e | ||
|
|
8cd89f8a06 | ||
|
|
b599f6e71c | ||
|
|
2e38237a99 | ||
|
|
d23c145790 | ||
|
|
c3e0bbaa0a | ||
|
|
4582556f65 | ||
|
|
e07316f25a | ||
|
|
7379bdaa67 | ||
|
|
c4519c5914 | ||
|
|
358d9861f5 | ||
|
|
bdf2df0ed1 | ||
|
|
291a6515c1 | ||
|
|
2667bacd9d | ||
|
|
7967f289b7 | ||
|
|
31e1cb7e6d | ||
|
|
a472d0509a | ||
|
|
3f71a97cbd | ||
|
|
ed8c818d4f | ||
|
|
1db14cd998 | ||
|
|
d06dd87ff4 | ||
|
|
a31a64efd6 | ||
|
|
cfa87a5a02 | ||
|
|
2833691c34 | ||
|
|
22d6ed8c39 | ||
|
|
110bae7cb7 | ||
|
|
5bd7d6fae3 | ||
|
|
afa45fd8d9 | ||
|
|
2c544607ec | ||
|
|
730b52d6cd | ||
|
|
0704579d26 | ||
|
|
cb92fbad3d | ||
|
|
c7c6f8f706 | ||
|
|
fdd81e21b1 | ||
|
|
1093da6565 | ||
|
|
c625315a76 | ||
|
|
1deb4c2d6c | ||
|
|
9201b9baed | ||
|
|
557bd9f54b | ||
|
|
0353dbdb27 | ||
|
|
8b07cf62a9 | ||
|
|
111025cb98 | ||
|
|
b3d9c4c2b9 | ||
|
|
f2695b6a2c | ||
|
|
f6ec40e8ed | ||
|
|
9bc6920448 | ||
|
|
abb8483723 | ||
|
|
81eadbb794 | ||
|
|
22cc32778d | ||
|
|
c9d432b7c8 | ||
|
|
168a1dcfb2 | ||
|
|
b6718078f2 | ||
|
|
960a7751ad | ||
|
|
e5335de859 | ||
|
|
1eb960eaf9 | ||
|
|
6bc9f0da64 | ||
|
|
f4d986a5bd | ||
|
|
9aa22aab34 | ||
|
|
afa839ed0b | ||
|
|
f2725331fe | ||
|
|
590963024a | ||
|
|
1f55977182 | ||
|
|
4bed3d5b8e | ||
|
|
7eab4e00e1 | ||
|
|
776813df17 | ||
|
|
12beeedf29 | ||
|
|
d0e7f25fd9 | ||
|
|
ab2a066992 | ||
|
|
596f95e463 | ||
|
|
79d07f98a8 | ||
|
|
22ec2e8926 | ||
|
|
bc4d20d0a4 | ||
|
|
84ed520c1c | ||
|
|
34eb6a423a | ||
|
|
7dc1491c26 | ||
|
|
6ecce9ddc5 | ||
|
|
029373a8d2 | ||
|
|
e8c06fd876 | ||
|
|
8c9218e8af | ||
|
|
f922d41775 | ||
|
|
e483105eb2 | ||
|
|
9aecb79b17 | ||
|
|
bfc6bf07d9 | ||
|
|
b671999e5a | ||
|
|
3ed2cb329c | ||
|
|
fe9970523f | ||
|
|
62944f7b71 | ||
|
|
a7e1101c87 | ||
|
|
b79d991b25 | ||
|
|
10a15fc5cf | ||
|
|
428a5ab20e | ||
|
|
b3d19d752b | ||
|
|
73b702aa56 | ||
|
|
3360035402 | ||
|
|
b97069a04e | ||
|
|
9df8d050b2 | ||
|
|
ba4ca96b77 | ||
|
|
fd93baf583 | ||
|
|
0a9a1976cd | ||
|
|
450e05c819 | ||
|
|
59d36d29da | ||
|
|
f0cd92f82e | ||
|
|
e847338ef4 | ||
|
|
23c34258ff | ||
|
|
d441960107 | ||
|
|
185ae6beb4 | ||
|
|
d84376e4dc | ||
|
|
dcc6af3367 | ||
|
|
1cd8ef1b47 | ||
|
|
f8c5caf6bc | ||
|
|
8e84b5b67b | ||
|
|
dc697af081 | ||
|
|
a69f36b652 | ||
|
|
d5c788fe80 | ||
|
|
021fe45c8d | ||
|
|
18881e549f | ||
|
|
ed2f3510d8 | ||
|
|
5290340b97 | ||
|
|
9514d42032 | ||
|
|
2cc140eaf4 | ||
|
|
c4934fc89e | ||
|
|
7feb5552c1 | ||
|
|
fce659c41c | ||
|
|
2e899f5fa8 | ||
|
|
4580d781db | ||
|
|
6fdab6f89c | ||
|
|
145b6523e9 | ||
|
|
1d03d35685 | ||
|
|
71396bc632 | ||
|
|
511d70838a | ||
|
|
1e31052767 | ||
|
|
e1c88c53f3 | ||
|
|
de16081c79 | ||
|
|
e9d1ce1720 | ||
|
|
3bce3c41f2 | ||
|
|
c71729c560 | ||
|
|
3cbf5d0a8f | ||
|
|
6f99f5a226 | ||
|
|
252dcb6175 | ||
|
|
72971341b2 | ||
|
|
32f4205240 | ||
|
|
36e66a8714 | ||
|
|
7ee1777e7b | ||
|
|
d8dc9ad576 | ||
|
|
8ae8842f81 | ||
|
|
ddb82292f9 | ||
|
|
83ade321bb | ||
|
|
a4ea8a6bfc | ||
|
|
2d32852d18 | ||
|
|
3ef3510ad3 | ||
|
|
82cb0eb7d6 | ||
|
|
2c428d3306 | ||
|
|
5fa9e8677d | ||
|
|
b57abfdc57 | ||
|
|
2f7906d3db | ||
|
|
d56f86b47e | ||
|
|
e558be2b89 | ||
|
|
66cab7b41e | ||
|
|
4f431bb7ea | ||
|
|
d411623da6 | ||
|
|
d121e839c9 | ||
|
|
c397bd0211 | ||
|
|
ec2782ddad | ||
|
|
6b6a60ae02 | ||
|
|
f870674bd2 | ||
|
|
6af75a9758 | ||
|
|
e4fc925b04 | ||
|
|
2262779ba0 | ||
|
|
b52cd2a619 | ||
|
|
8bad20e58c | ||
|
|
30ca44b9c6 | ||
|
|
cf43ed965e | ||
|
|
dab29819bd | ||
|
|
5fb090f241 | ||
|
|
ff84c63445 | ||
|
|
140ace739e | ||
|
|
5f8c078367 | ||
|
|
faddb37557 | ||
|
|
5d8fe06d5c | ||
|
|
2e34913c7d | ||
|
|
6cc607469b | ||
|
|
26eff55e6d | ||
|
|
9a5743dd67 | ||
|
|
0b547147b1 | ||
|
|
6bd3bd5e80 | ||
|
|
af93a6730e | ||
|
|
27e4bd4e0b | ||
|
|
459b27253a | ||
|
|
bb99570cd4 | ||
|
|
3f2b62c119 | ||
|
|
91e9975a24 | ||
|
|
00485efd0e | ||
|
|
c5d56243e0 | ||
|
|
b8c3229d9f | ||
|
|
8cf935accc | ||
|
|
2cf5589369 | ||
|
|
89addaf211 | ||
|
|
f5409c7b8a | ||
|
|
733ddb5964 | ||
|
|
537380eeb7 | ||
|
|
e44473f26b | ||
|
|
a503832016 | ||
|
|
4935995342 | ||
|
|
a367373c87 | ||
|
|
62cd2e4809 | ||
|
|
7df7defa92 | ||
|
|
56b42c67d5 | ||
|
|
d1afcc2f54 | ||
|
|
f6b05ed42b | ||
|
|
095334d338 | ||
|
|
dac0ef178d | ||
|
|
c23a502e9e | ||
|
|
5ddd652076 | ||
|
|
3f9e3f620d | ||
|
|
1c62fe9615 | ||
|
|
8703102c97 | ||
|
|
28ab591769 | ||
|
|
8cc2bfbced | ||
|
|
7612dde6d4 | ||
|
|
5188fe7170 | ||
|
|
c31048e829 | ||
|
|
44629bb405 | ||
|
|
3e387b1833 | ||
|
|
080693656a | ||
|
|
bc5479fa96 | ||
|
|
b95892d3b6 | ||
|
|
e1eea40fd7 | ||
|
|
c00fb901a0 | ||
|
|
029bca22ed | ||
|
|
facb931cb6 | ||
|
|
2f319afd40 | ||
|
|
95114502c9 | ||
|
|
2eef9b8fb0 | ||
|
|
6180ea3302 | ||
|
|
bf3ebc5ff8 | ||
|
|
5f77728a7b | ||
|
|
e823834889 | ||
|
|
35c97a7772 | ||
|
|
d59a520aa5 | ||
|
|
6bcdbfeaa4 | ||
|
|
dcb11102f6 | ||
|
|
a0e957b1fd | ||
|
|
c8c0a3aae0 | ||
|
|
aed7acfdc8 | ||
|
|
6707f0ee35 | ||
|
|
44694f351e | ||
|
|
8e3585b32d | ||
|
|
25312953af | ||
|
|
c8a32ba76e | ||
|
|
a97a6682fb | ||
|
|
ed8151632e | ||
|
|
aca061ecf6 | ||
|
|
b2bef7a4b0 | ||
|
|
db63a8f05b | ||
|
|
998f57f435 | ||
|
|
46c9197cce | ||
|
|
3f3c0c6c6a | ||
|
|
ff34acfe59 | ||
|
|
b969177244 | ||
|
|
32efad2b33 | ||
|
|
bad4cdac1a | ||
|
|
5cebca42e9 | ||
|
|
3ef2447eef | ||
|
|
a8faa2930a | ||
|
|
02abba52a7 | ||
|
|
6da2bc352d | ||
|
|
cc39e0dda3 | ||
|
|
c81145d46e | ||
|
|
a56c79d4bb | ||
|
|
fa3f409a70 | ||
|
|
1865924469 | ||
|
|
b3a23ad4e8 | ||
|
|
7a02103e05 |
No files matched your search
@@ -1,28 +0,0 @@
|
||||
感谢您提交 Issue,请在提交前仔细阅读以下信息。
|
||||
|
||||
请在阅读完毕后,删除这些文字,并写下对该 Issue 的描述。
|
||||
|
||||
Issue 的内容仅可为
|
||||
* Bug 反馈
|
||||
* 功能申请
|
||||
|
||||
若您希望得到使用指导(譬如如何删除快速搜索),请至 [G+ 社区](https://plus.google.com/u/1/communities/103823982034655188459) 发贴。若有其他问题,可在应用内找到开发者的邮箱地址,使用电子邮件与开发者交流。
|
||||
|
||||
若内容为 Bug 反馈,请先查看 [release 页面](https://github.com/seven332/EhViewer/releases),以帮助确认该 bug 是否存在于最新版中;同时应详细描述 bug 内容与重现方法,必要时可附加截图,但请确定截图符合风序良俗。
|
||||
|
||||
功能申请包括添加新功能与改进现有功能。
|
||||
|
||||
一个 Issue 只包含一个 Bug 反馈或者功能申请。若有多个需求,请提交多个 Issue。
|
||||
|
||||
尽量不提交重复的 Issue,可先进行搜索。对于重复的 Issue,开发者可能会直接关闭并添加 Duplicate 标签。
|
||||
|
||||
|
||||
Thank you for taking the time to submit an issue. Before you proceed, please consider the following.
|
||||
|
||||
An issue can only be about:
|
||||
* Bug Report
|
||||
* Feature Request
|
||||
|
||||
If you need application instructions, please post your question in [G+ community](https://plus.google.com/u/1/communities/103823982034655188459). If you have other questions, please get the developer's email address in the application, and send him/her an email.
|
||||
|
||||
One issue one bug report or feature request.
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: 功能申请 / Feature request
|
||||
about: 有个想法 / Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**这个功能是用来解决问题的吗? / Is your feature request related to a problem? Please describe.**
|
||||
描述这个问题。
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**描述你想要的解决方法 / Describe the solution you'd like**
|
||||
描述应通过何种行为来解决这个问题。
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**备注 / Additional context**
|
||||
还有别的想说的吗?
|
||||
Add any other context or screenshots about the feature request here.
|
||||
@@ -0,0 +1,41 @@
|
||||
---
|
||||
name: Bug 反馈 / Bug report
|
||||
about: 出问题了 / Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**简略描述 / Describe the bug**
|
||||
大概说下是什么问题。
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**如何重现 / To Reproduce**
|
||||
重现的步骤:
|
||||
1. 打开什么什么
|
||||
2. 点击什么什么
|
||||
3. 出现什么什么问题
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**预期行为 / Expected behavior**
|
||||
应该是什么样子的?
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**截图 / Screenshots**
|
||||
能截图的话就发截图,请注意风序良俗。
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**设备型号与 Android 版本 / Device model and Android version**
|
||||
- 设备型号:【比如 Pixel 6 XXXL】
|
||||
- Android 版本:【比如 Android 12.1】
|
||||
- Device model: [e.g. Pixel 6 XXXL]
|
||||
- Android version: [e.g. Android 12.1]
|
||||
|
||||
**备注 / Additional context**
|
||||
还有什么想说的?
|
||||
Add any other context about the problem here.
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
name: Sad Panda / 下载太慢 / Slow download speed
|
||||
about: 所有其他问题 / All other questions
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
加入我们的 Telegram 群组,[https://t.me/ehviewer](https://t.me/ehviewer)。温柔[大小]姐姐手把手帮你解决问题。
|
||||
Join our Telegram group, [https://t.me/ehviewer](https://t.me/ehviewer). Administrators will help you solve the problem.
|
||||
@@ -6,3 +6,5 @@
|
||||
*.iml
|
||||
.idea
|
||||
/captures
|
||||
release
|
||||
google-services.json
|
||||
@@ -1,4 +1,6 @@
|
||||
[](https://t.me/ehviewer) [](https://plus.google.com/communities/103823982034655188459)
|
||||
# DEPRECATED
|
||||
|
||||
[](https://t.me/ehviewer)
|
||||
|
||||
# EhViewer
|
||||
|
||||
@@ -33,6 +35,13 @@ Linux
|
||||
The apk is in app\build\outputs\apk
|
||||
|
||||
|
||||
# Download
|
||||
|
||||
[下载](https://github.com/seven332/EhViewer/releases)
|
||||
|
||||
[Download](https://github.com/seven332/EhViewer/releases)
|
||||
|
||||
|
||||
# Thanks
|
||||
|
||||
本项目受到了诸多开源项目的帮助
|
||||
@@ -57,7 +66,7 @@ Here is the libraries
|
||||
|
||||
# License
|
||||
|
||||
Copyright (C) 2014-2016 Hippo Seven
|
||||
Copyright (C) 2014-2019 Hippo Seven
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
+71
-46
@@ -1,32 +1,48 @@
|
||||
import com.android.build.gradle.internal.tasks.DefaultAndroidTask
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'android-chinese-string'
|
||||
|
||||
if (file('google-services.json').exists()) {
|
||||
apply plugin: 'com.google.gms.google-services'
|
||||
apply plugin: 'io.fabric'
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion "25.0.3"
|
||||
compileSdkVersion 28
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.hippo.ehviewer"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 25
|
||||
versionCode 79
|
||||
versionName "1.0.26"
|
||||
targetSdkVersion 28
|
||||
versionCode 104
|
||||
versionName "1.7.3"
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
resConfigs "zh", "zh-rCN", "zh-rHK", "zh-rTW",
|
||||
"es"
|
||||
"es", "ja", "ko", "fr", "de", "th"
|
||||
testOptions.unitTests.includeAndroidResources = true
|
||||
ndk {
|
||||
abiFilters "armeabi-v7a", "x86"
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
checkReleaseBuilds false
|
||||
disable 'MissingTranslation'
|
||||
abortOnError true
|
||||
checkReleaseBuilds true
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
buildConfigField 'String', 'FILE_PROVIDER_AUTHORITY', '"com.hippo.ehviewer.fileprovider"'
|
||||
}
|
||||
debug {
|
||||
applicationIdSuffix ".debug"
|
||||
buildConfigField 'String', 'FILE_PROVIDER_AUTHORITY', '"com.hippo.ehviewer.debug.fileprovider"'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +59,7 @@ task copyNotice(type: Copy) {
|
||||
finalizedBy ":daogenerator:executeDaoGenerator"
|
||||
}
|
||||
|
||||
tasks.withType(DefaultAndroidTask) {
|
||||
tasks.withType(JavaCompile) {
|
||||
task -> task.dependsOn copyNotice
|
||||
}
|
||||
|
||||
@@ -52,43 +68,52 @@ clean {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||
compile "com.android.support:appcompat-v7:$supportLibrary"
|
||||
compile "com.android.support:design:$supportLibrary"
|
||||
compile 'com.github.amlcurran.showcaseview:library:5.4.3'
|
||||
compile 'com.github.seven332:android-recaptcha:2bbb3459a8'
|
||||
compile 'com.github.seven332:animator:0.1.0'
|
||||
compile 'com.github.seven332:beerbelly:0.1.4'
|
||||
compile 'com.github.seven332:conaco:0.1.5-eh'
|
||||
compile 'com.github.seven332:drawerlayout:0.2.1'
|
||||
compile 'com.github.seven332:easyrecyclerview:0.1.1'
|
||||
compile 'com.github.seven332:glgallery:0.1.2'
|
||||
compile 'com.github.seven332:glview:0.1.0'
|
||||
compile 'com.github.seven332:glview-image:0.1.0'
|
||||
compile 'com.github.seven332:hotspot:0.1.0'
|
||||
compile 'com.github.seven332:image:0.1.12'
|
||||
compile 'com.github.seven332:okhttp:3.5.0'
|
||||
compile 'com.github.seven332:refreshlayout:0.1.0'
|
||||
compile 'com.github.seven332:ripple:0.1.2'
|
||||
compile 'com.github.seven332:streampipe:0.1.0'
|
||||
compile 'com.github.seven332:tuxiang:0.1.2'
|
||||
compile 'com.github.seven332:unifile:0.2.0'
|
||||
compile 'com.github.seven332:yorozuya:0.1.2'
|
||||
compile 'com.github.seven332:yorozuya-thread:0.1.1'
|
||||
compile 'com.github.seven332:yorozuya-collect:0.1.4'
|
||||
compile 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.9.2'
|
||||
compile 'org.ccil.cowan.tagsoup:tagsoup:1.2.1'
|
||||
compile 'org.greenrobot:greendao:2.2.0'
|
||||
compile 'org.jsoup:jsoup:1.9.2'
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile 'org.robolectric:robolectric:3.4'
|
||||
testCompile 'org.jooq:joor:0.9.6'
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'androidx.appcompat:appcompat:1.0.2'
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
implementation 'com.google.android.material:material:1.0.0'
|
||||
implementation 'com.google.firebase:firebase-core:16.0.9'
|
||||
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
|
||||
implementation 'com.getkeepsafe.relinker:relinker:1.3.1'
|
||||
implementation 'com.github.amlcurran.showcaseview:library:5.4.3'
|
||||
implementation 'com.github.seven332.a7zip:extract-lite:d4ddec5793'
|
||||
implementation 'com.github.seven332:android-recaptcha:2bbb3459a8'
|
||||
implementation 'com.github.seven332:android-resource:0.1.0'
|
||||
implementation 'com.github.seven332:animator:0.1.0'
|
||||
implementation 'com.github.seven332:beerbelly:0.1.4'
|
||||
implementation 'com.github.seven332:conaco:0.1.5-eh'
|
||||
implementation 'com.github.seven332:drawerlayout:ea2bb388f0'
|
||||
implementation 'com.github.seven332:easyrecyclerview:0.1.1'
|
||||
implementation 'com.github.seven332:glgallery:0.1.2'
|
||||
implementation 'com.github.seven332:glview:0.1.0'
|
||||
implementation 'com.github.seven332:glview-image:0.1.0'
|
||||
implementation 'com.github.seven332:hotspot:0.1.0'
|
||||
implementation 'com.github.seven332:image:0.1.12'
|
||||
implementation 'com.github.seven332:refreshlayout:0.1.0'
|
||||
implementation 'com.github.seven332:ripple:0.1.2'
|
||||
implementation 'com.github.seven332:streampipe:0.1.0'
|
||||
implementation 'com.github.seven332:tuxiang:0.1.6'
|
||||
implementation 'com.github.seven332:unifile:9ec57bcd8f'
|
||||
implementation 'com.github.seven332:yorozuya:0.1.2'
|
||||
implementation 'com.github.seven332:yorozuya-thread:0.1.1'
|
||||
implementation 'com.github.seven332:yorozuya-collect:0.1.4'
|
||||
implementation 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:1.0.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.12.3'
|
||||
implementation 'org.ccil.cowan.tagsoup:tagsoup:1.2.1'
|
||||
implementation 'org.greenrobot:greendao:2.2.1'
|
||||
implementation 'org.jsoup:jsoup:1.12.1'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
testImplementation 'org.robolectric:robolectric:4.2.1'
|
||||
testImplementation 'org.jooq:joor:0.9.6'
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
resolutionStrategy {
|
||||
force 'com.github.seven332:glgallery:0f276c0'
|
||||
force 'com.github.seven332:glview-image:4c744db'
|
||||
force 'com.github.seven332:image:bab9b11'
|
||||
force 'com.github.seven332:glgallery:25893283ca'
|
||||
force 'com.github.seven332:glview:ba6aee61d7'
|
||||
force 'com.github.seven332:glview-image:68d94b0fc2'
|
||||
force 'com.github.seven332:image:09b43c0c68'
|
||||
|
||||
exclude group: 'com.github.seven332', module: 'okhttp'
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Executable
+22
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright 2016 Hippo Seven
|
||||
~
|
||||
~ 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
|
||||
~
|
||||
~ http://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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<string name="app_name">EhViewer Debug</string>
|
||||
|
||||
</resources>
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright 2016 Hippo Seven
|
||||
~
|
||||
~ 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
|
||||
~
|
||||
~ http://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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<string name="app_name">EhViewer Debug</string>
|
||||
|
||||
</resources>
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright 2016 Hippo Seven
|
||||
~
|
||||
~ 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
|
||||
~
|
||||
~ http://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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<string name="app_name">EhViewer Debug</string>
|
||||
|
||||
</resources>
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright 2016 Hippo Seven
|
||||
~
|
||||
~ 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
|
||||
~
|
||||
~ http://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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<string name="app_name">EhViewer Debug</string>
|
||||
|
||||
</resources>
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright 2016 Hippo Seven
|
||||
~
|
||||
~ 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
|
||||
~
|
||||
~ http://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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<string name="app_name">EhViewer Debug</string>
|
||||
|
||||
</resources>
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright 2016 Hippo Seven
|
||||
~
|
||||
~ 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
|
||||
~
|
||||
~ http://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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<string name="app_name">EhViewer Debug</string>
|
||||
|
||||
</resources>
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright 2016 Hippo Seven
|
||||
~
|
||||
~ 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
|
||||
~
|
||||
~ http://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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<string name="app_name">EhViewer Debug</string>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<shortcut
|
||||
android:shortcutId="start_all"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_shortcut_start"
|
||||
android:shortcutShortLabel="@string/download_start_all"
|
||||
android:shortcutLongLabel="@string/download_start_all"
|
||||
android:shortcutDisabledMessage="@string/download_start_all">
|
||||
<intent
|
||||
android:action="start_all"
|
||||
android:targetPackage="com.hippo.ehviewer.debug"
|
||||
android:targetClass="com.hippo.ehviewer.shortcuts.ShortcutsActivity"/>
|
||||
<categories android:name="android.shortcut.conversation" />
|
||||
</shortcut>
|
||||
|
||||
<shortcut
|
||||
android:shortcutId="stop_all"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_shortcut_stop"
|
||||
android:shortcutShortLabel="@string/download_stop_all"
|
||||
android:shortcutLongLabel="@string/download_stop_all"
|
||||
android:shortcutDisabledMessage="@string/download_stop_all">
|
||||
<intent
|
||||
android:action="stop_all"
|
||||
android:targetPackage="com.hippo.ehviewer.debug"
|
||||
android:targetClass="com.hippo.ehviewer.shortcuts.ShortcutsActivity" />
|
||||
<categories android:name="android.shortcut.conversation" />
|
||||
</shortcut>
|
||||
|
||||
</shortcuts>
|
||||
@@ -22,7 +22,9 @@
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
||||
<uses-permission android:name="android.permission.USE_BIOMETRIC"/>
|
||||
<uses-permission android:name="android.permission.USE_FINGERPRINT"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
|
||||
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
|
||||
|
||||
@@ -34,7 +36,12 @@
|
||||
android:theme="@style/AppTheme"
|
||||
android:allowBackup="true"
|
||||
android:fullBackupContent="@xml/backup_scheme"
|
||||
android:largeHeap="true">
|
||||
android:largeHeap="true"
|
||||
android:networkSecurityConfig="@xml/network_security_config">
|
||||
|
||||
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
|
||||
|
||||
<meta-data android:name="android.max_aspect" android:value="2.1"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.MainActivity"
|
||||
@@ -48,6 +55,9 @@
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
|
||||
<meta-data android:name="android.app.shortcuts"
|
||||
android:resource="@xml/shortcuts" />
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
@@ -82,17 +92,41 @@
|
||||
<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="file"/>
|
||||
<data android:scheme="content"/>
|
||||
<data android:host="*"/>
|
||||
<data android:mimeType="application/octet-stream"/>
|
||||
<data android:mimeType="application/7z"/>
|
||||
<data android:mimeType="application/rar"/>
|
||||
<data android:mimeType="application/zip"/>
|
||||
<data android:mimeType="application/x-7z-compressed"/>
|
||||
<data android:mimeType="application/x-rar-compressed"/>
|
||||
<data android:mimeType="application/x-zip-compressed"/>
|
||||
</intent-filter>
|
||||
|
||||
<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="file"/>
|
||||
<data android:scheme="content"/>
|
||||
<data android:host="*"/>
|
||||
<data android:pathPattern=".*\\.7z"/>
|
||||
<data android:pathPattern=".*\\.rar"/>
|
||||
<data android:pathPattern=".*\\.zip"/>
|
||||
</intent-filter>
|
||||
|
||||
<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="file"/>
|
||||
<data android:scheme="content"/>
|
||||
<data android:host="*"/>
|
||||
<data android:mimeType="*/*"/>
|
||||
<data android:pathPattern=".*\\.7z"/>
|
||||
<data android:pathPattern=".*\\.rar"/>
|
||||
<data android:pathPattern=".*\\.zip"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
@@ -100,56 +134,76 @@
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.SettingsActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme"/>
|
||||
android:theme="@style/AppTheme.Settings"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.ExcludedLanguagesActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:theme="@style/AppTheme.Toolbar"
|
||||
android:label="@string/excluded_languages"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.DirPickerActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:theme="@style/AppTheme.Toolbar"
|
||||
android:label="@string/dir_picker"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.LicenseActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:theme="@style/AppTheme.Toolbar"
|
||||
android:label="@string/license"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.FilterActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:theme="@style/AppTheme.Toolbar"
|
||||
android:label="@string/filter"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.SetSecurityActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:theme="@style/AppTheme.Toolbar"
|
||||
android:label="@string/set_pattern_protection"/>
|
||||
|
||||
<activity
|
||||
android:name=".ui.UConfigActivity"
|
||||
android:name="com.hippo.ehviewer.ui.UConfigActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:theme="@style/AppTheme.Toolbar"
|
||||
android:label="@string/u_config"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.MyTagsActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.Toolbar"
|
||||
android:label="@string/my_tags"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.HostsActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.Toolbar"
|
||||
android:label="@string/hosts"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.shortcuts.ShortcutsActivity"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||
android:excludeFromRecents="true"
|
||||
android:taskAffinity=""
|
||||
android:launchMode="singleTask">
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name="com.hippo.ehviewer.download.DownloadService"
|
||||
android:label="@string/download_service_label"/>
|
||||
|
||||
<provider
|
||||
android:name="com.hippo.content.FileProvider"
|
||||
android:authorities="com.hippo.ehviewer.fileprovider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:grantUriPermissions="true"
|
||||
android:exported="false">
|
||||
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:name="com.hippo.content.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/filepaths"/>
|
||||
|
||||
</provider>
|
||||
|
||||
@@ -16,39 +16,70 @@
|
||||
|
||||
package com.hippo.app;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.support.v4.app.TaskStackBuilder;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatCallback;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
import android.support.v7.view.ActionMode;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StyleRes;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AppCompatCallback;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.appcompat.view.ActionMode;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.appcompat.widget.VectorEnabledTintResources;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.app.NavUtils;
|
||||
import androidx.core.app.TaskStackBuilder;
|
||||
|
||||
public abstract class AppCompatPreferenceActivity extends PreferenceActivity implements AppCompatCallback,
|
||||
TaskStackBuilder.SupportParentable, ActionBarDrawerToggle.DelegateProvider {
|
||||
TaskStackBuilder.SupportParentable, ActionBarDrawerToggle.DelegateProvider {
|
||||
|
||||
private AppCompatDelegate mDelegate;
|
||||
private int mThemeId = 0;
|
||||
private Resources mResources;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
getDelegate().installViewFactory();
|
||||
getDelegate().onCreate(savedInstanceState);
|
||||
final AppCompatDelegate delegate = getDelegate();
|
||||
delegate.installViewFactory();
|
||||
delegate.onCreate(savedInstanceState);
|
||||
if (delegate.applyDayNight() && mThemeId != 0) {
|
||||
// If DayNight has been applied, we need to re-apply the theme for
|
||||
// the changes to take effect. On API 23+, we should bypass
|
||||
// setTheme(), which will no-op if the theme ID is identical to the
|
||||
// current theme ID.
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
onApplyThemeResource(getTheme(), mThemeId, false);
|
||||
} else {
|
||||
setTheme(mThemeId);
|
||||
}
|
||||
}
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTheme(@StyleRes final int resid) {
|
||||
super.setTheme(resid);
|
||||
// Keep hold of the theme id so that we can re-set it later if needed
|
||||
mThemeId = resid;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
@@ -68,26 +99,25 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a {@link android.widget.Toolbar Toolbar} to act as the {@link android.support.v7.app.ActionBar} for this
|
||||
* Activity window.
|
||||
* Set a {@link android.widget.Toolbar Toolbar} to act as the
|
||||
* {@link androidx.appcompat.app.ActionBar} for this Activity window.
|
||||
*
|
||||
* <p>When set to a non-null value the {@link #getActionBar()} method will return
|
||||
* an {@link android.support.v7.app.ActionBar} object that can be used to control the given toolbar as if it were
|
||||
* a traditional window decor action bar. The toolbar's menu will be populated with the
|
||||
* Activity's options menu and the navigation button will be wired through the standard
|
||||
* {@link android.R.id#home home} menu select action.</p>
|
||||
* an {@link androidx.appcompat.app.ActionBar} object that can be used to control the given
|
||||
* toolbar as if it were a traditional window decor action bar. The toolbar's menu will be
|
||||
* populated with the Activity's options menu and the navigation button will be wired through
|
||||
* the standard {@link android.R.id#home home} menu select action.</p>
|
||||
*
|
||||
* <p>In order to use a Toolbar within the Activity's window content the application
|
||||
* must not request the window feature
|
||||
* {@link android.view.Window#FEATURE_ACTION_BAR FEATURE_SUPPORT_ACTION_BAR}.</p>
|
||||
*
|
||||
* @param toolbar Toolbar to set as the Activity's action bar
|
||||
* @param toolbar Toolbar to set as the Activity's action bar, or {@code null} to clear it
|
||||
*/
|
||||
public void setSupportActionBar(@Nullable Toolbar toolbar) {
|
||||
getDelegate().setSupportActionBar(toolbar);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public MenuInflater getMenuInflater() {
|
||||
return getDelegate().getMenuInflater();
|
||||
@@ -117,6 +147,24 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
getDelegate().onConfigurationChanged(newConfig);
|
||||
if (mResources != null) {
|
||||
// The real (and thus managed) resources object was already updated
|
||||
// by ResourcesManager, so pull the current metrics from there.
|
||||
final DisplayMetrics newMetrics = super.getResources().getDisplayMetrics();
|
||||
mResources.updateConfiguration(newConfig, newMetrics);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostResume() {
|
||||
super.onPostResume();
|
||||
getDelegate().onPostResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
getDelegate().onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -125,10 +173,10 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
getDelegate().onStop();
|
||||
}
|
||||
|
||||
@SuppressWarnings("TypeParameterUnusedInFormals")
|
||||
@Override
|
||||
protected void onPostResume() {
|
||||
super.onPostResume();
|
||||
getDelegate().onPostResume();
|
||||
public <T extends View> T findViewById(@IdRes int id) {
|
||||
return getDelegate().findViewById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,7 +187,7 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
|
||||
final ActionBar ab = getSupportActionBar();
|
||||
if (item.getItemId() == android.R.id.home && ab != null &&
|
||||
(ab.getDisplayOptions() & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
|
||||
(ab.getDisplayOptions() & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
|
||||
return onSupportNavigateUp();
|
||||
}
|
||||
return false;
|
||||
@@ -165,7 +213,7 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
* </p>
|
||||
*
|
||||
* @param featureId The desired feature as defined in
|
||||
* {@link android.view.Window} or {@link android.support.v4.view.WindowCompat}.
|
||||
* {@link android.view.Window} or {@link androidx.core.view.WindowCompat}.
|
||||
* @return Returns true if the requested feature is supported and now enabled.
|
||||
*
|
||||
* @see android.app.Activity#requestWindowFeature
|
||||
@@ -192,7 +240,7 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
*/
|
||||
@Override
|
||||
@CallSuper
|
||||
public void onSupportActionModeStarted(ActionMode mode) {
|
||||
public void onSupportActionModeStarted(@NonNull ActionMode mode) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,7 +251,7 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
*/
|
||||
@Override
|
||||
@CallSuper
|
||||
public void onSupportActionModeFinished(ActionMode mode) {
|
||||
public void onSupportActionModeFinished(@NonNull ActionMode mode) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,14 +265,49 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public ActionMode onWindowStartingSupportActionMode(ActionMode.Callback callback) {
|
||||
public ActionMode onWindowStartingSupportActionMode(@NonNull ActionMode.Callback callback) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ActionMode startSupportActionMode(ActionMode.Callback callback) {
|
||||
/**
|
||||
* Start an action mode.
|
||||
*
|
||||
* @param callback Callback that will manage lifecycle events for this context mode
|
||||
* @return The ContextMode that was started, or null if it was canceled
|
||||
*/
|
||||
@Nullable
|
||||
public ActionMode startSupportActionMode(@NonNull ActionMode.Callback callback) {
|
||||
return getDelegate().startSupportActionMode(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Progress bars are no longer provided in AppCompat.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setSupportProgressBarVisibility(boolean visible) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Progress bars are no longer provided in AppCompat.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setSupportProgressBarIndeterminateVisibility(boolean visible) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Progress bars are no longer provided in AppCompat.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setSupportProgressBarIndeterminate(boolean indeterminate) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Progress bars are no longer provided in AppCompat.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setSupportProgress(int progress) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Support version of {@link #onCreateNavigateUpTaskStack(android.app.TaskStackBuilder)}.
|
||||
* This method will be called on all platform versions.
|
||||
@@ -233,7 +316,7 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
* a different task.
|
||||
*
|
||||
* <p>The default implementation of this method adds the parent chain of this activity
|
||||
* as specified in the manifest to the supplied {@link android.support.v4.app.TaskStackBuilder}. Applications
|
||||
* as specified in the manifest to the supplied {@link androidx.core.app.TaskStackBuilder}. Applications
|
||||
* may choose to override this method to construct the desired task stack in a different
|
||||
* way.</p>
|
||||
*
|
||||
@@ -243,12 +326,12 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
*
|
||||
* <p>Applications that wish to supply extra Intent parameters to the parent stack defined
|
||||
* by the manifest should override
|
||||
* {@link #onPrepareSupportNavigateUpTaskStack(android.support.v4.app.TaskStackBuilder)}.</p>
|
||||
* {@link #onPrepareSupportNavigateUpTaskStack(androidx.core.app.TaskStackBuilder)}.</p>
|
||||
*
|
||||
* @param builder An empty TaskStackBuilder - the application should add intents representing
|
||||
* the desired task stack
|
||||
*/
|
||||
public void onCreateSupportNavigateUpTaskStack(TaskStackBuilder builder) {
|
||||
public void onCreateSupportNavigateUpTaskStack(@NonNull TaskStackBuilder builder) {
|
||||
builder.addParentStack(this);
|
||||
}
|
||||
|
||||
@@ -259,15 +342,15 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
* Prepare the synthetic task stack that will be generated during Up navigation
|
||||
* from a different task.
|
||||
*
|
||||
* <p>This method receives the {@link android.support.v4.app.TaskStackBuilder} with the constructed series of
|
||||
* Intents as generated by {@link #onCreateSupportNavigateUpTaskStack(android.support.v4.app.TaskStackBuilder)}.
|
||||
* <p>This method receives the {@link androidx.core.app.TaskStackBuilder} with the constructed series of
|
||||
* Intents as generated by {@link #onCreateSupportNavigateUpTaskStack(androidx.core.app.TaskStackBuilder)}.
|
||||
* If any extra data should be added to these intents before launching the new task,
|
||||
* the application should override this method and add that data here.</p>
|
||||
*
|
||||
* @param builder A TaskStackBuilder that has been populated with Intents by
|
||||
* onCreateNavigateUpTaskStack.
|
||||
*/
|
||||
public void onPrepareSupportNavigateUpTaskStack(TaskStackBuilder builder) {
|
||||
public void onPrepareSupportNavigateUpTaskStack(@NonNull TaskStackBuilder builder) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,7 +361,7 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
* default Up navigation will be handled automatically. See
|
||||
* {@link #getSupportParentActivityIntent()} for how to specify the parent. If any activity
|
||||
* along the parent chain requires extra Intent arguments, the Activity subclass
|
||||
* should override the method {@link #onPrepareSupportNavigateUpTaskStack(android.support.v4.app.TaskStackBuilder)}
|
||||
* should override the method {@link #onPrepareSupportNavigateUpTaskStack(androidx.core.app.TaskStackBuilder)}
|
||||
* to supply those arguments.</p>
|
||||
*
|
||||
* <p>See <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and
|
||||
@@ -286,7 +369,7 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
* <a href="{@docRoot}design/patterns/navigation.html">Navigation</a> from the design guide
|
||||
* for more information about navigating within your app.</p>
|
||||
*
|
||||
* <p>See the {@link android.support.v4.app.TaskStackBuilder} class and the Activity methods
|
||||
* <p>See the {@link androidx.core.app.TaskStackBuilder} class and the Activity methods
|
||||
* {@link #getSupportParentActivityIntent()}, {@link #supportShouldUpRecreateTask(android.content.Intent)}, and
|
||||
* {@link #supportNavigateUpTo(android.content.Intent)} for help implementing custom Up navigation.</p>
|
||||
*
|
||||
@@ -322,15 +405,15 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
|
||||
/**
|
||||
* Obtain an {@link android.content.Intent} that will launch an explicit target activity
|
||||
* specified by sourceActivity's {@link android.support.v4.app.NavUtils#PARENT_ACTIVITY} <meta-data>
|
||||
* specified by sourceActivity's {@link androidx.core.app.NavUtils#PARENT_ACTIVITY} <meta-data>
|
||||
* element in the application's manifest. If the device is running
|
||||
* Jellybean or newer, the android:parentActivityName attribute will be preferred
|
||||
* if it is present.
|
||||
*
|
||||
* @return a new Intent targeting the defined parent activity of sourceActivity
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
@Override
|
||||
public Intent getSupportParentActivityIntent() {
|
||||
return NavUtils.getParentActivityIntent(this);
|
||||
}
|
||||
@@ -342,13 +425,13 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
* <p>If this method returns false the app can trivially call
|
||||
* {@link #supportNavigateUpTo(android.content.Intent)} using the same parameters to correctly perform
|
||||
* up navigation. If this method returns false, the app should synthesize a new task stack
|
||||
* by using {@link android.support.v4.app.TaskStackBuilder} or another similar mechanism to perform up navigation.</p>
|
||||
* by using {@link androidx.core.app.TaskStackBuilder} or another similar mechanism to perform up navigation.</p>
|
||||
*
|
||||
* @param targetIntent An intent representing the target destination for up navigation
|
||||
* @return true if navigating up should recreate a new task stack, false if the same task
|
||||
* should be used for the destination
|
||||
*/
|
||||
public boolean supportShouldUpRecreateTask(Intent targetIntent) {
|
||||
public boolean supportShouldUpRecreateTask(@NonNull Intent targetIntent) {
|
||||
return NavUtils.shouldUpRecreateTask(this, targetIntent);
|
||||
}
|
||||
|
||||
@@ -364,7 +447,7 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
*
|
||||
* @param upIntent An intent representing the target destination for up navigation
|
||||
*/
|
||||
public void supportNavigateUpTo(Intent upIntent) {
|
||||
public void supportNavigateUpTo(@NonNull Intent upIntent) {
|
||||
NavUtils.navigateUpTo(this, upIntent);
|
||||
}
|
||||
|
||||
@@ -374,13 +457,114 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity imp
|
||||
return getDelegate().getDrawerToggleDelegate();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>Please note: AppCompat uses its own feature id for the action bar:
|
||||
* {@link AppCompatDelegate#FEATURE_SUPPORT_ACTION_BAR FEATURE_SUPPORT_ACTION_BAR}.</p>
|
||||
*/
|
||||
@Override
|
||||
public boolean onMenuOpened(int featureId, Menu menu) {
|
||||
return super.onMenuOpened(featureId, menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>Please note: AppCompat uses its own feature id for the action bar:
|
||||
* {@link AppCompatDelegate#FEATURE_SUPPORT_ACTION_BAR FEATURE_SUPPORT_ACTION_BAR}.</p>
|
||||
*/
|
||||
@Override
|
||||
public void onPanelClosed(int featureId, Menu menu) {
|
||||
super.onPanelClosed(featureId, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
getDelegate().onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The {@link AppCompatDelegate} being used by this Activity.
|
||||
*/
|
||||
@NonNull
|
||||
public AppCompatDelegate getDelegate() {
|
||||
if (mDelegate == null) {
|
||||
mDelegate = AppCompatDelegate.create(this, this);
|
||||
}
|
||||
return mDelegate;
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
// Let support action bars open menus in response to the menu key prioritized over
|
||||
// the window handling it
|
||||
final int keyCode = event.getKeyCode();
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
if (keyCode == KeyEvent.KEYCODE_MENU
|
||||
&& actionBar != null && actionBar.onMenuKeyEvent(event)) {
|
||||
return true;
|
||||
}
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
@Override
|
||||
public Resources getResources() {
|
||||
if (mResources == null && VectorEnabledTintResources.shouldBeUsed()) {
|
||||
mResources = new VectorEnabledTintResources(this, super.getResources());
|
||||
}
|
||||
return mResources == null ? super.getResources() : mResources;
|
||||
}
|
||||
|
||||
/**
|
||||
* KeyEvents with non-default modifiers are not dispatched to menu's performShortcut in API 25
|
||||
* or lower. Here, we check if the keypress corresponds to a menuitem's shortcut combination
|
||||
* and perform the corresponding action.
|
||||
*/
|
||||
private boolean performMenuItemShortcut(int keycode, KeyEvent event) {
|
||||
if (!(Build.VERSION.SDK_INT >= 26) && !event.isCtrlPressed()
|
||||
&& !KeyEvent.metaStateHasNoModifiers(event.getMetaState())
|
||||
&& event.getRepeatCount() == 0
|
||||
&& !KeyEvent.isModifierKey(event.getKeyCode())) {
|
||||
final Window currentWindow = getWindow();
|
||||
if (currentWindow != null && currentWindow.getDecorView() != null) {
|
||||
final View decorView = currentWindow.getDecorView();
|
||||
if (decorView.dispatchKeyShortcutEvent(event)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (performMenuItemShortcut(keyCode, event)) {
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
@Override
|
||||
public void openOptionsMenu() {
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (getWindow().hasFeature(Window.FEATURE_OPTIONS_PANEL)
|
||||
&& (actionBar == null || !actionBar.openOptionsMenu())) {
|
||||
super.openOptionsMenu();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
@Override
|
||||
public void closeOptionsMenu() {
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (getWindow().hasFeature(Window.FEATURE_OPTIONS_PANEL)
|
||||
&& (actionBar == null || !actionBar.closeOptionsMenu())) {
|
||||
super.closeOptionsMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,11 @@ package com.hippo.app;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class CheckBoxDialogBuilder extends AlertDialog.Builder {
|
||||
|
||||
@@ -19,15 +19,14 @@ package com.hippo.app;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class EditTextDialogBuilder extends AlertDialog.Builder implements EditText.OnEditorActionListener {
|
||||
|
||||
@@ -18,14 +18,13 @@ package com.hippo.app;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ListView;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.app;
|
||||
|
||||
import android.content.Context;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.hippo.ehviewer.R;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class PrettyPreferenceActivity extends AppCompatPreferenceActivity {
|
||||
|
||||
@Override
|
||||
public void setListAdapter(ListAdapter adapter) {
|
||||
if (adapter == null) {
|
||||
super.setListAdapter(null);
|
||||
return;
|
||||
}
|
||||
|
||||
int count = adapter.getCount();
|
||||
List<PreferenceActivity.Header> headers = new ArrayList<>(count);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
headers.add((PreferenceActivity.Header) adapter.getItem(i));
|
||||
}
|
||||
|
||||
super.setListAdapter(new HeaderAdapter(this, headers, R.layout.item_preference_header, true));
|
||||
}
|
||||
|
||||
private static class HeaderAdapter extends ArrayAdapter<PreferenceActivity.Header> {
|
||||
private static class HeaderViewHolder {
|
||||
ImageView icon;
|
||||
TextView title;
|
||||
TextView summary;
|
||||
}
|
||||
|
||||
private LayoutInflater mInflater;
|
||||
private int mLayoutResId;
|
||||
private boolean mRemoveIconIfEmpty;
|
||||
|
||||
private HeaderAdapter(Context context, List<PreferenceActivity.Header> objects, int layoutResId,
|
||||
boolean removeIconBehavior) {
|
||||
super(context, 0, objects);
|
||||
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
mLayoutResId = layoutResId;
|
||||
mRemoveIconIfEmpty = removeIconBehavior;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
|
||||
HeaderViewHolder holder;
|
||||
View view;
|
||||
|
||||
if (convertView == null) {
|
||||
view = mInflater.inflate(mLayoutResId, parent, false);
|
||||
holder = new HeaderViewHolder();
|
||||
holder.icon = view.findViewById(android.R.id.icon);
|
||||
holder.title = view.findViewById(android.R.id.title);
|
||||
holder.summary = view.findViewById(android.R.id.summary);
|
||||
view.setTag(holder);
|
||||
} else {
|
||||
view = convertView;
|
||||
holder = (HeaderViewHolder) view.getTag();
|
||||
}
|
||||
|
||||
// All view fields must be updated every time, because the view may be recycled
|
||||
PreferenceActivity.Header header = getItem(position);
|
||||
if (mRemoveIconIfEmpty) {
|
||||
if (header.iconRes == 0) {
|
||||
holder.icon.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.icon.setVisibility(View.VISIBLE);
|
||||
holder.icon.setImageResource(header.iconRes);
|
||||
}
|
||||
} else {
|
||||
holder.icon.setImageResource(header.iconRes);
|
||||
}
|
||||
holder.title.setText(header.getTitle(getContext().getResources()));
|
||||
CharSequence summary = header.getSummary(getContext().getResources());
|
||||
if (!TextUtils.isEmpty(summary)) {
|
||||
holder.summary.setVisibility(View.VISIBLE);
|
||||
holder.summary.setText(summary);
|
||||
} else {
|
||||
holder.summary.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,6 @@ import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.StyleSpan;
|
||||
@@ -29,9 +28,8 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.content;
|
||||
|
||||
/*
|
||||
* Created by Hippo on 2018/3/27.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.LocaleList;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ContextLocalWrapper extends ContextWrapper {
|
||||
|
||||
public ContextLocalWrapper(Context base) {
|
||||
super(base);
|
||||
}
|
||||
|
||||
public static ContextLocalWrapper wrap(Context context, Locale newLocale) {
|
||||
Resources res = context.getResources();
|
||||
Configuration configuration = res.getConfiguration();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
configuration.setLocale(newLocale);
|
||||
|
||||
LocaleList localeList = new LocaleList(newLocale);
|
||||
LocaleList.setDefault(localeList);
|
||||
configuration.setLocales(localeList);
|
||||
|
||||
context = context.createConfigurationContext(configuration);
|
||||
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
configuration.setLocale(newLocale);
|
||||
context = context.createConfigurationContext(configuration);
|
||||
|
||||
} else {
|
||||
configuration.locale = newLocale;
|
||||
res.updateConfiguration(configuration, res.getDisplayMetrics());
|
||||
}
|
||||
|
||||
return new ContextLocalWrapper(context);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.hippo.content;
|
||||
|
||||
import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
|
||||
import static org.xmlpull.v1.XmlPullParser.START_TAG;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentValues;
|
||||
@@ -31,20 +34,15 @@ import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
|
||||
import static org.xmlpull.v1.XmlPullParser.START_TAG;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* FileProvider is a special subclass of {@link ContentProvider} that facilitates secure sharing
|
||||
@@ -331,7 +329,7 @@ public class FileProvider extends ContentProvider {
|
||||
};
|
||||
|
||||
private static final String
|
||||
META_DATA_FILE_PROVIDER_PATHS = "android.support.FILE_PROVIDER_PATHS";
|
||||
META_DATA_FILE_PROVIDER_PATHS = "com.hippo.content.FILE_PROVIDER_PATHS";
|
||||
|
||||
private static final String TAG_ROOT_PATH = "root-path";
|
||||
private static final String TAG_FILES_PATH = "files-path";
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.content;
|
||||
|
||||
/*
|
||||
* Created by Hippo on 2018/3/27.
|
||||
*/
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import com.hippo.scene.SceneApplication;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class RecordingApplication extends SceneApplication {
|
||||
|
||||
private List<WeakReference<Activity>> list = new LinkedList<>();
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
|
||||
@Override
|
||||
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
|
||||
list.add(new java.lang.ref.WeakReference<>(activity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityDestroyed(Activity activity) {
|
||||
Iterator<WeakReference<Activity>> iterator = list.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
WeakReference<Activity> reference = iterator.next();
|
||||
Activity a = reference.get();
|
||||
// Remove current activity and null
|
||||
if (a == null || a == activity) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStarted(Activity activity) {}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed(Activity activity) {}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(Activity activity) {}
|
||||
|
||||
@Override
|
||||
public void onActivityStopped(Activity activity) {}
|
||||
|
||||
@Override
|
||||
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {}
|
||||
});
|
||||
}
|
||||
|
||||
public void recreate() {
|
||||
// Copy list
|
||||
ArrayList<Activity> listCopy = new ArrayList<>(list.size());
|
||||
for (WeakReference<Activity> reference: list) {
|
||||
Activity activity = reference.get();
|
||||
if (activity == null) continue;
|
||||
listCopy.add(activity);
|
||||
}
|
||||
|
||||
// Finish all activities
|
||||
for (int i = listCopy.size() - 1; i >= 0; --i) {
|
||||
listCopy.get(i).recreate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,13 +46,13 @@ public class AddDeleteDrawable extends Drawable {
|
||||
/**
|
||||
* @param context used to get the configuration for the drawable from
|
||||
*/
|
||||
public AddDeleteDrawable(Context context) {
|
||||
public AddDeleteDrawable(Context context, int color) {
|
||||
Resources resources = context.getResources();
|
||||
|
||||
mSize = resources.getDimensionPixelSize(R.dimen.add_size);
|
||||
float barThickness = Math.round(resources.getDimension(R.dimen.add_thickness));
|
||||
|
||||
mPaint.setColor(resources.getColor(R.color.primary_drawable_light));
|
||||
mPaint.setColor(color);
|
||||
mPaint.setStyle(Paint.Style.STROKE);
|
||||
mPaint.setStrokeJoin(Paint.Join.MITER);
|
||||
mPaint.setStrokeCap(Paint.Cap.BUTT);
|
||||
|
||||
@@ -17,9 +17,8 @@
|
||||
package com.hippo.drawable;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.drawable;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Region;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
|
||||
public class DrawableWrapper extends Drawable implements Drawable.Callback {
|
||||
private Drawable mDrawable;
|
||||
|
||||
public DrawableWrapper(Drawable drawable) {
|
||||
this.setWrappedDrawable(drawable);
|
||||
}
|
||||
|
||||
public void draw(@NonNull Canvas canvas) {
|
||||
this.mDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
protected void onBoundsChange(Rect bounds) {
|
||||
this.mDrawable.setBounds(bounds);
|
||||
}
|
||||
|
||||
public void setChangingConfigurations(int configs) {
|
||||
this.mDrawable.setChangingConfigurations(configs);
|
||||
}
|
||||
|
||||
public int getChangingConfigurations() {
|
||||
return this.mDrawable.getChangingConfigurations();
|
||||
}
|
||||
|
||||
public void setDither(boolean dither) {
|
||||
this.mDrawable.setDither(dither);
|
||||
}
|
||||
|
||||
public void setFilterBitmap(boolean filter) {
|
||||
this.mDrawable.setFilterBitmap(filter);
|
||||
}
|
||||
|
||||
public void setAlpha(int alpha) {
|
||||
this.mDrawable.setAlpha(alpha);
|
||||
}
|
||||
|
||||
public void setColorFilter(ColorFilter cf) {
|
||||
this.mDrawable.setColorFilter(cf);
|
||||
}
|
||||
|
||||
public boolean isStateful() {
|
||||
return this.mDrawable.isStateful();
|
||||
}
|
||||
|
||||
public boolean setState(@NonNull int[] stateSet) {
|
||||
return this.mDrawable.setState(stateSet);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public int[] getState() {
|
||||
return this.mDrawable.getState();
|
||||
}
|
||||
|
||||
public void jumpToCurrentState() {
|
||||
this.mDrawable.jumpToCurrentState();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Drawable getCurrent() {
|
||||
return this.mDrawable.getCurrent();
|
||||
}
|
||||
|
||||
public boolean setVisible(boolean visible, boolean restart) {
|
||||
return super.setVisible(visible, restart) || this.mDrawable.setVisible(visible, restart);
|
||||
}
|
||||
|
||||
public int getOpacity() {
|
||||
return this.mDrawable.getOpacity();
|
||||
}
|
||||
|
||||
public Region getTransparentRegion() {
|
||||
return this.mDrawable.getTransparentRegion();
|
||||
}
|
||||
|
||||
public int getIntrinsicWidth() {
|
||||
return this.mDrawable.getIntrinsicWidth();
|
||||
}
|
||||
|
||||
public int getIntrinsicHeight() {
|
||||
return this.mDrawable.getIntrinsicHeight();
|
||||
}
|
||||
|
||||
public int getMinimumWidth() {
|
||||
return this.mDrawable.getMinimumWidth();
|
||||
}
|
||||
|
||||
public int getMinimumHeight() {
|
||||
return this.mDrawable.getMinimumHeight();
|
||||
}
|
||||
|
||||
public boolean getPadding(@NonNull Rect padding) {
|
||||
return this.mDrawable.getPadding(padding);
|
||||
}
|
||||
|
||||
public void invalidateDrawable(@NonNull Drawable who) {
|
||||
this.invalidateSelf();
|
||||
}
|
||||
|
||||
public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when) {
|
||||
this.scheduleSelf(what, when);
|
||||
}
|
||||
|
||||
public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what) {
|
||||
this.unscheduleSelf(what);
|
||||
}
|
||||
|
||||
protected boolean onLevelChange(int level) {
|
||||
return this.mDrawable.setLevel(level);
|
||||
}
|
||||
|
||||
public void setAutoMirrored(boolean mirrored) {
|
||||
DrawableCompat.setAutoMirrored(this.mDrawable, mirrored);
|
||||
}
|
||||
|
||||
public boolean isAutoMirrored() {
|
||||
return DrawableCompat.isAutoMirrored(this.mDrawable);
|
||||
}
|
||||
|
||||
public void setTint(int tint) {
|
||||
DrawableCompat.setTint(this.mDrawable, tint);
|
||||
}
|
||||
|
||||
public void setTintList(ColorStateList tint) {
|
||||
DrawableCompat.setTintList(this.mDrawable, tint);
|
||||
}
|
||||
|
||||
public void setTintMode(@NonNull PorterDuff.Mode tintMode) {
|
||||
DrawableCompat.setTintMode(this.mDrawable, tintMode);
|
||||
}
|
||||
|
||||
public void setHotspot(float x, float y) {
|
||||
DrawableCompat.setHotspot(this.mDrawable, x, y);
|
||||
}
|
||||
|
||||
public void setHotspotBounds(int left, int top, int right, int bottom) {
|
||||
DrawableCompat.setHotspotBounds(this.mDrawable, left, top, right, bottom);
|
||||
}
|
||||
|
||||
public Drawable getWrappedDrawable() {
|
||||
return this.mDrawable;
|
||||
}
|
||||
|
||||
public void setWrappedDrawable(Drawable drawable) {
|
||||
if (this.mDrawable != null) {
|
||||
this.mDrawable.setCallback(null);
|
||||
}
|
||||
|
||||
this.mDrawable = drawable;
|
||||
if (drawable != null) {
|
||||
drawable.setCallback(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
|
||||
@@ -66,11 +66,11 @@ public class DrawerArrowDrawable extends Drawable {
|
||||
/**
|
||||
* @param context used to get the configuration for the drawable from
|
||||
*/
|
||||
public DrawerArrowDrawable(Context context) {
|
||||
public DrawerArrowDrawable(Context context, int color) {
|
||||
Resources resources = context.getResources();
|
||||
|
||||
mPaint.setAntiAlias(true);
|
||||
mPaint.setColor(resources.getColor(R.color.primary_drawable_light));
|
||||
mPaint.setColor(color);
|
||||
mSize = resources.getDimensionPixelSize(R.dimen.dad_drawable_size);
|
||||
// round this because having this floating may cause bad measurements
|
||||
mBarSize = Math.round(resources.getDimension(R.dimen.dad_bar_size));
|
||||
@@ -144,6 +144,11 @@ public class DrawerArrowDrawable extends Drawable {
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
public void setColor(@ColorInt int color) {
|
||||
mPaint.setColor(color);
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int i) {
|
||||
mPaint.setAlpha(i);
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v7.graphics.drawable.DrawableWrapper;
|
||||
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.drawable;
|
||||
|
||||
/*
|
||||
* Created by Hippo on 2017/9/6.
|
||||
*/
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.IntRange;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
public class TextDrawable extends Drawable {
|
||||
|
||||
private static final float STANDARD_TEXT_SIZE = 1000.0f;
|
||||
private static final Paint STANDARD_PAINT = new Paint();
|
||||
|
||||
static {
|
||||
STANDARD_PAINT.setTextSize(STANDARD_TEXT_SIZE);
|
||||
}
|
||||
|
||||
private String text;
|
||||
private float contentPercent;
|
||||
|
||||
private Paint backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
private Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
|
||||
private int textColor = Color.BLACK;
|
||||
private int backgroundColor = Color.BLACK;
|
||||
|
||||
private float x = 0.0f;
|
||||
private float y = 0.0f;
|
||||
private boolean textSizeDirty = false;
|
||||
private Rect textBounds = new Rect();
|
||||
|
||||
public TextDrawable(String text, float contentPercent) {
|
||||
this.text = text;
|
||||
this.contentPercent = contentPercent;
|
||||
STANDARD_PAINT.getTextBounds(text, 0, text.length(), textBounds);
|
||||
}
|
||||
|
||||
public int getTextColor() {
|
||||
return textColor;
|
||||
}
|
||||
|
||||
public void setTextColor(int textColor) {
|
||||
if (this.textColor != textColor) {
|
||||
this.textColor = textColor;
|
||||
invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
public int getBackgroundColor() {
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
public void setBackgroundColor(int backgroundColor) {
|
||||
if (this.backgroundColor != backgroundColor) {
|
||||
this.backgroundColor = backgroundColor;
|
||||
invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBoundsChange(Rect bounds) {
|
||||
super.onBoundsChange(bounds);
|
||||
textSizeDirty = true;
|
||||
}
|
||||
|
||||
private void updateTextSizeIfDirty(Rect bounds) {
|
||||
if (!textSizeDirty) {
|
||||
return;
|
||||
}
|
||||
textSizeDirty = false;
|
||||
|
||||
int contentWidth = (int) (bounds.width() * contentPercent);
|
||||
int contentHeight = (int) (bounds.height() * contentPercent);
|
||||
float widthRatio = (float) contentWidth / (float) textBounds.width();
|
||||
float heightRatio = (float) contentHeight / (float) textBounds.height();
|
||||
float ratio = Math.min(widthRatio, heightRatio);
|
||||
float textSize = STANDARD_TEXT_SIZE * ratio;
|
||||
textPaint.setTextSize(textSize);
|
||||
x = (bounds.width() - textBounds.width() * ratio) / 2 - textBounds.left * ratio;
|
||||
y = (bounds.height() - textBounds.height() * ratio) / 2 - textBounds.top * ratio;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(@NonNull Canvas canvas) {
|
||||
Rect bounds = getBounds();
|
||||
if (!bounds.isEmpty()) {
|
||||
// Draw background
|
||||
backgroundPaint.setColor(backgroundColor);
|
||||
canvas.drawRect(bounds, backgroundPaint);
|
||||
|
||||
if (!TextUtils.isEmpty(text)) {
|
||||
// Draw text
|
||||
updateTextSizeIfDirty(bounds);
|
||||
textPaint.setColor(textColor);
|
||||
canvas.drawText(text, x, y, textPaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(@IntRange(from = 0, to = 255) int alpha) {}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(@Nullable ColorFilter colorFilter) {
|
||||
backgroundPaint.setColorFilter(colorFilter);
|
||||
textPaint.setColorFilter(colorFilter);
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
return PixelFormat.TRANSLUCENT;
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,8 @@
|
||||
package com.hippo.drawable;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.hippo.conaco.Conaco;
|
||||
import com.hippo.conaco.ConacoTask;
|
||||
import com.hippo.conaco.Unikery;
|
||||
|
||||
@@ -17,15 +17,47 @@
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.google.analytics.tracking.android.EasyTracker;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class Analytics {
|
||||
|
||||
private static final String DEVICE_LANGUAGE = "device_language";
|
||||
|
||||
private static FirebaseAnalytics analytics;
|
||||
|
||||
private Analytics() {}
|
||||
|
||||
public static void start(Context context) {
|
||||
EasyTracker.getInstance(context).set("&uid", Settings.getUserID());
|
||||
analytics = FirebaseAnalytics.getInstance(context);
|
||||
analytics.setUserId(Settings.getUserID());
|
||||
|
||||
Locale locale = Locale.getDefault();
|
||||
String language = locale.getLanguage();
|
||||
if (TextUtils.isEmpty(language)) {
|
||||
language = "none";
|
||||
}
|
||||
String country = locale.getCountry();
|
||||
if (!TextUtils.isEmpty(country)) {
|
||||
language = language + "-" + country;
|
||||
}
|
||||
language = language.toLowerCase();
|
||||
analytics.setUserProperty(DEVICE_LANGUAGE, language);
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return analytics != null && Settings.getEnableAnalytics();
|
||||
}
|
||||
|
||||
public static void onSceneView(SceneFragment scene) {
|
||||
if (isEnabled()) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("scene_simple_class", scene.getClass().getSimpleName());
|
||||
bundle.putString("scene_class", scene.getClass().getName());
|
||||
analytics.logEvent("scene_view", bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,11 @@ package com.hippo.ehviewer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.ReadableTime;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -37,10 +35,10 @@ public class AppConfig {
|
||||
private static final String DOWNLOAD = "download";
|
||||
private static final String TEMP = "temp";
|
||||
private static final String IMAGE = "image";
|
||||
private static final String CRASH = "crash";
|
||||
private static final String PARSE_ERROR = "parse_error";
|
||||
private static final String LOGCAT = "logcat";
|
||||
private static final String DATA = "data";
|
||||
private static final String CRASH = "crash";
|
||||
|
||||
private static Context sContext;
|
||||
|
||||
@@ -95,11 +93,6 @@ public class AppConfig {
|
||||
return getDirInExternalAppDir(IMAGE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getExternalCrashDir() {
|
||||
return getDirInExternalAppDir(CRASH);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getExternalParseErrorDir() {
|
||||
return getDirInExternalAppDir(PARSE_ERROR);
|
||||
@@ -115,6 +108,11 @@ public class AppConfig {
|
||||
return getDirInExternalAppDir(DATA);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getExternalCrashDir() {
|
||||
return getDirInExternalAppDir(CRASH);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File createExternalTempFile() {
|
||||
return FileUtils.createTempFile(getExternalTempDir(), null);
|
||||
@@ -162,4 +160,19 @@ public class AppConfig {
|
||||
IOUtils.closeQuietly(os);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getFilesDir(String name) {
|
||||
File dir = sContext.getFilesDir();
|
||||
if (dir == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
dir = new File(dir, name);
|
||||
if (dir.isDirectory() || dir.mkdirs()) {
|
||||
return dir;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,184 +22,135 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Debug;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.util.PackageUtils;
|
||||
import com.hippo.util.ReadableTime;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.OSUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public final class Crash {
|
||||
private Crash() {}
|
||||
private Crash() {}
|
||||
|
||||
@NonNull
|
||||
private static String avoidNull(String str) {
|
||||
return null != str ? str : "null";
|
||||
}
|
||||
@NonNull
|
||||
private static String avoidNull(String str) {
|
||||
return null != str ? str : "null";
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static void collectInfo(Context context, FileWriter fw) throws IOException {
|
||||
try {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
PackageInfo pi = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES);
|
||||
if (pi != null) {
|
||||
String versionName = pi.versionName == null ? "null" : pi.versionName;
|
||||
String versionCode = String.valueOf(pi.versionCode);
|
||||
fw.write("======== PackageInfo ========\r\n");
|
||||
fw.write("PackageName=");fw.write(pi.packageName);fw.write("\r\n");
|
||||
fw.write("VersionName=");fw.write(versionName);fw.write("\r\n");
|
||||
fw.write("VersionCode=");fw.write(versionCode);fw.write("\r\n");
|
||||
String signature = PackageUtils.getSignature(context, pi.packageName);
|
||||
fw.write("Signature=");fw.write(null != signature ? signature : "null");fw.write("\r\n");
|
||||
fw.write("\r\n");
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
fw.write("======== PackageInfo ========\r\n");
|
||||
fw.write("Can't get package information\r\n");
|
||||
fw.write("\r\n");
|
||||
}
|
||||
|
||||
// Runtime
|
||||
String topActivityClazzName = "null";
|
||||
String topSceneClazzName = "null";
|
||||
try {
|
||||
Activity topActivity = ((EhApplication) context.getApplicationContext()).getTopActivity();
|
||||
if (null != topActivity) {
|
||||
topActivityClazzName = topActivity.getClass().getName();
|
||||
if (topActivity instanceof StageActivity) {
|
||||
Class<?> clazz = ((StageActivity) topActivity).getTopSceneClass();
|
||||
if (clazz != null) {
|
||||
topSceneClazzName = clazz.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// Ignore
|
||||
}
|
||||
fw.write("======== Runtime ========\r\n");
|
||||
fw.write("TopActivity=");fw.write(avoidNull(topActivityClazzName));fw.write("\r\n");
|
||||
fw.write("TopScene=");fw.write(avoidNull(topSceneClazzName));fw.write("\r\n");
|
||||
fw.write("\r\n");
|
||||
|
||||
// Device info
|
||||
fw.write("======== DeviceInfo ========\r\n");
|
||||
fw.write("BOARD=");fw.write(Build.BOARD);fw.write("\r\n");
|
||||
fw.write("BOOTLOADER=");fw.write(Build.BOOTLOADER);fw.write("\r\n");
|
||||
fw.write("CPU_ABI=");fw.write(Build.CPU_ABI);fw.write("\r\n");
|
||||
fw.write("CPU_ABI2=");fw.write(Build.CPU_ABI2);fw.write("\r\n");
|
||||
fw.write("DEVICE=");fw.write(Build.DEVICE);fw.write("\r\n");
|
||||
fw.write("DISPLAY=");fw.write(Build.DISPLAY);fw.write("\r\n");
|
||||
fw.write("FINGERPRINT=");fw.write(Build.FINGERPRINT);fw.write("\r\n");
|
||||
fw.write("HARDWARE=");fw.write(Build.HARDWARE);fw.write("\r\n");
|
||||
fw.write("HOST=");fw.write(Build.HOST);fw.write("\r\n");
|
||||
fw.write("ID=");fw.write(Build.ID);fw.write("\r\n");
|
||||
fw.write("MANUFACTURER=");fw.write(Build.MANUFACTURER);fw.write("\r\n");
|
||||
fw.write("MODEL=");fw.write(Build.MODEL);fw.write("\r\n");
|
||||
fw.write("PRODUCT=");fw.write(Build.PRODUCT);fw.write("\r\n");
|
||||
fw.write("RADIO=");fw.write(Build.getRadioVersion());fw.write("\r\n");
|
||||
fw.write("SERIAL=");fw.write(Build.SERIAL);fw.write("\r\n");
|
||||
fw.write("TAGS=");fw.write(Build.TAGS);fw.write("\r\n");
|
||||
fw.write("TYPE=");fw.write(Build.TYPE);fw.write("\r\n");
|
||||
fw.write("USER=");fw.write(Build.USER);fw.write("\r\n");
|
||||
fw.write("CODENAME=");fw.write(Build.VERSION.CODENAME);fw.write("\r\n");
|
||||
fw.write("INCREMENTAL=");fw.write(Build.VERSION.INCREMENTAL);fw.write("\r\n");
|
||||
fw.write("RELEASE=");fw.write(Build.VERSION.RELEASE);fw.write("\r\n");
|
||||
fw.write("SDK=");fw.write(Integer.toString(Build.VERSION.SDK_INT));fw.write("\r\n");
|
||||
fw.write("MEMORY=");fw.write(FileUtils.humanReadableByteCount(OSUtils.getAppAllocatedMemory(), false));fw.write("\r\n");
|
||||
fw.write("MEMORY_NATIVE=");fw.write(FileUtils.humanReadableByteCount(Debug.getNativeHeapAllocatedSize(), false));fw.write("\r\n");
|
||||
fw.write("MEMORY_MAX=");fw.write(FileUtils.humanReadableByteCount(OSUtils.getAppMaxMemory(), false));fw.write("\r\n");
|
||||
fw.write("MEMORY_TOTAL=");fw.write(FileUtils.humanReadableByteCount(OSUtils.getTotalMemory(), false));fw.write("\r\n");
|
||||
private static void collectInfo(Context context, FileWriter fw) throws IOException {
|
||||
try {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
PackageInfo pi = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES);
|
||||
if (pi != null) {
|
||||
String versionName = pi.versionName == null ? "null" : pi.versionName;
|
||||
String versionCode = String.valueOf(pi.versionCode);
|
||||
fw.write("======== PackageInfo ========\r\n");
|
||||
fw.write("PackageName=");fw.write(pi.packageName);fw.write("\r\n");
|
||||
fw.write("VersionName=");fw.write(versionName);fw.write("\r\n");
|
||||
fw.write("VersionCode=");fw.write(versionCode);fw.write("\r\n");
|
||||
String signature = PackageUtils.getSignature(context, pi.packageName);
|
||||
fw.write("Signature=");fw.write(null != signature ? signature : "null");fw.write("\r\n");
|
||||
fw.write("\r\n");
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
fw.write("======== PackageInfo ========\r\n");
|
||||
fw.write("Can't get package information\r\n");
|
||||
fw.write("\r\n");
|
||||
}
|
||||
|
||||
public static void getThrowableInfo(Throwable t, FileWriter fw) {
|
||||
PrintWriter printWriter = new PrintWriter(fw);
|
||||
t.printStackTrace(printWriter);
|
||||
Throwable cause = t.getCause();
|
||||
while (cause != null) {
|
||||
cause.printStackTrace(printWriter);
|
||||
cause = cause.getCause();
|
||||
// Runtime
|
||||
String topActivityClazzName = "null";
|
||||
String topSceneClazzName = "null";
|
||||
try {
|
||||
Activity topActivity = ((EhApplication) context.getApplicationContext()).getTopActivity();
|
||||
if (null != topActivity) {
|
||||
topActivityClazzName = topActivity.getClass().getName();
|
||||
if (topActivity instanceof StageActivity) {
|
||||
Class<?> clazz = ((StageActivity) topActivity).getTopSceneClass();
|
||||
if (clazz != null) {
|
||||
topSceneClazzName = clazz.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// Ignore
|
||||
}
|
||||
fw.write("======== Runtime ========\r\n");
|
||||
fw.write("TopActivity=");fw.write(avoidNull(topActivityClazzName));fw.write("\r\n");
|
||||
fw.write("TopScene=");fw.write(avoidNull(topSceneClazzName));fw.write("\r\n");
|
||||
fw.write("\r\n");
|
||||
|
||||
// Device info
|
||||
fw.write("======== DeviceInfo ========\r\n");
|
||||
fw.write("BOARD=");fw.write(Build.BOARD);fw.write("\r\n");
|
||||
fw.write("BOOTLOADER=");fw.write(Build.BOOTLOADER);fw.write("\r\n");
|
||||
fw.write("CPU_ABI=");fw.write(Build.CPU_ABI);fw.write("\r\n");
|
||||
fw.write("CPU_ABI2=");fw.write(Build.CPU_ABI2);fw.write("\r\n");
|
||||
fw.write("DEVICE=");fw.write(Build.DEVICE);fw.write("\r\n");
|
||||
fw.write("DISPLAY=");fw.write(Build.DISPLAY);fw.write("\r\n");
|
||||
fw.write("FINGERPRINT=");fw.write(Build.FINGERPRINT);fw.write("\r\n");
|
||||
fw.write("HARDWARE=");fw.write(Build.HARDWARE);fw.write("\r\n");
|
||||
fw.write("HOST=");fw.write(Build.HOST);fw.write("\r\n");
|
||||
fw.write("ID=");fw.write(Build.ID);fw.write("\r\n");
|
||||
fw.write("MANUFACTURER=");fw.write(Build.MANUFACTURER);fw.write("\r\n");
|
||||
fw.write("MODEL=");fw.write(Build.MODEL);fw.write("\r\n");
|
||||
fw.write("PRODUCT=");fw.write(Build.PRODUCT);fw.write("\r\n");
|
||||
fw.write("RADIO=");fw.write(Build.getRadioVersion());fw.write("\r\n");
|
||||
fw.write("SERIAL=");fw.write(Build.SERIAL);fw.write("\r\n");
|
||||
fw.write("TAGS=");fw.write(Build.TAGS);fw.write("\r\n");
|
||||
fw.write("TYPE=");fw.write(Build.TYPE);fw.write("\r\n");
|
||||
fw.write("USER=");fw.write(Build.USER);fw.write("\r\n");
|
||||
fw.write("CODENAME=");fw.write(Build.VERSION.CODENAME);fw.write("\r\n");
|
||||
fw.write("INCREMENTAL=");fw.write(Build.VERSION.INCREMENTAL);fw.write("\r\n");
|
||||
fw.write("RELEASE=");fw.write(Build.VERSION.RELEASE);fw.write("\r\n");
|
||||
fw.write("SDK=");fw.write(Integer.toString(Build.VERSION.SDK_INT));fw.write("\r\n");
|
||||
fw.write("MEMORY=");fw.write(
|
||||
FileUtils.humanReadableByteCount(OSUtils.getAppAllocatedMemory(), false));fw.write("\r\n");
|
||||
fw.write("MEMORY_NATIVE=");fw.write(FileUtils.humanReadableByteCount(Debug.getNativeHeapAllocatedSize(), false));fw.write("\r\n");
|
||||
fw.write("MEMORY_MAX=");fw.write(FileUtils.humanReadableByteCount(OSUtils.getAppMaxMemory(), false));fw.write("\r\n");
|
||||
fw.write("MEMORY_TOTAL=");fw.write(FileUtils.humanReadableByteCount(OSUtils.getTotalMemory(), false));fw.write("\r\n");
|
||||
fw.write("\r\n");
|
||||
}
|
||||
|
||||
private static void getThrowableInfo(Throwable t, FileWriter fw) {
|
||||
PrintWriter printWriter = new PrintWriter(fw);
|
||||
t.printStackTrace(printWriter);
|
||||
Throwable cause = t.getCause();
|
||||
while (cause != null) {
|
||||
cause.printStackTrace(printWriter);
|
||||
cause = cause.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveCrashLog(Context context, Throwable t) {
|
||||
File dir = AppConfig.getExternalCrashDir();
|
||||
if (dir == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
public static void saveCrashInfo2File(Context context, Throwable ex) {
|
||||
File dir = AppConfig.getExternalCrashDir();
|
||||
if (dir == null) {
|
||||
return;
|
||||
}
|
||||
String nowString = ReadableTime.getFilenamableTime(System.currentTimeMillis());
|
||||
String fileName = "crash-" + nowString + ".log";
|
||||
File file = new File(dir, fileName);
|
||||
|
||||
String nowString = ReadableTime.getFilenamableTime(System.currentTimeMillis());
|
||||
String fileName = "crash-" + nowString + ".log";
|
||||
File file = new File(dir, fileName);
|
||||
|
||||
FileWriter fw = null;
|
||||
try {
|
||||
fw = new FileWriter(file);
|
||||
fw.write("TIME=");fw.write(nowString);fw.write("\r\n");
|
||||
fw.write("\r\n");
|
||||
collectInfo(context, fw);
|
||||
fw.write("======== CrashInfo ========\r\n");
|
||||
getThrowableInfo(ex, fw);
|
||||
fw.write("\r\n");
|
||||
|
||||
fw.flush();
|
||||
|
||||
Settings.putCrashFilename(fileName);
|
||||
} catch (Exception e) {
|
||||
file.delete();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(fw);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasCrashFile() {
|
||||
String filename = Settings.getCrashFilename();
|
||||
if (filename == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
File dir = AppConfig.getExternalCrashDir();
|
||||
if (dir == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return new File(dir, filename).isFile();
|
||||
}
|
||||
|
||||
public static String getCrashContent() {
|
||||
String filename = Settings.getCrashFilename();
|
||||
if (filename == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
File dir = AppConfig.getExternalCrashDir();
|
||||
if (dir == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
File file = new File(dir, filename);
|
||||
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(file);
|
||||
return IOUtils.readString(is, "UTF-8");
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
} finally {
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetCrashFile() {
|
||||
Settings.putCrashFilename(null);
|
||||
FileWriter fw = null;
|
||||
try {
|
||||
fw = new FileWriter(file);
|
||||
fw.write("TIME=");fw.write(nowString);fw.write("\r\n");
|
||||
fw.write("\r\n");
|
||||
collectInfo(context, fw);
|
||||
fw.write("======== CrashInfo ========\r\n");
|
||||
getThrowableInfo(t, fw);
|
||||
fw.write("\r\n");
|
||||
fw.flush();
|
||||
} catch (Exception e) {
|
||||
file.delete();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(fw);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,21 +16,30 @@
|
||||
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentCallbacks2;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Debug;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.collection.LruCache;
|
||||
import com.getkeepsafe.relinker.ReLinker;
|
||||
import com.hippo.a7zip.A7Zip;
|
||||
import com.hippo.a7zip.A7ZipExtractLite;
|
||||
import com.hippo.beerbelly.SimpleDiskCache;
|
||||
import com.hippo.conaco.Conaco;
|
||||
import com.hippo.content.RecordingApplication;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.client.EhCookieStore;
|
||||
import com.hippo.ehviewer.client.EhDns;
|
||||
import com.hippo.ehviewer.client.EhEngine;
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail;
|
||||
import com.hippo.ehviewer.download.DownloadManager;
|
||||
@@ -39,28 +48,28 @@ import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.image.ImageBitmap;
|
||||
import com.hippo.network.StatusCodeException;
|
||||
import com.hippo.scene.SceneApplication;
|
||||
import com.hippo.text.Html;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.BitmapUtils;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.IoThreadPoolExecutor;
|
||||
import com.hippo.util.ReadableTime;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
import com.hippo.yorozuya.OSUtils;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class EhApplication extends SceneApplication implements Thread.UncaughtExceptionHandler {
|
||||
public class EhApplication extends RecordingApplication {
|
||||
|
||||
private static final String TAG = EhApplication.class.getSimpleName();
|
||||
private static final String KEY_GLOBAL_STUFF_NEXT_ID = "global_stuff_next_id";
|
||||
|
||||
public static final boolean BETA = false;
|
||||
|
||||
@@ -69,26 +78,48 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
private static final boolean DEBUG_PRINT_IMAGE_COUNT = false;
|
||||
private static final long DEBUG_PRINT_INTERVAL = 3000L;
|
||||
|
||||
private Thread.UncaughtExceptionHandler mDefaultHandler;
|
||||
private static EhApplication instance;
|
||||
|
||||
private final IntIdGenerator mIdGenerator = new IntIdGenerator();
|
||||
private final HashMap<Integer, Object> mGlobalStuffMap = new HashMap<>();
|
||||
private EhCookieStore mEhCookieStore;
|
||||
private EhClient mEhClient;
|
||||
private EhProxySelector mEhProxySelector;
|
||||
private OkHttpClient mOkHttpClient;
|
||||
private ImageBitmapHelper mImageBitmapHelper;
|
||||
private Conaco<ImageBitmap> mConaco;
|
||||
private LruCache<Long, GalleryDetail> mGalleryDetailCache;
|
||||
private SimpleDiskCache mSpiderInfoCache;
|
||||
private DownloadManager mDownloadManager;
|
||||
private Hosts mHosts;
|
||||
private FavouriteStatusRouter mFavouriteStatusRouter;
|
||||
|
||||
private final List<Activity> mActivityList = new ArrayList<>();
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
public static EhApplication getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
@Override
|
||||
public void onCreate() {
|
||||
// Prepare to catch crash
|
||||
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
Thread.setDefaultUncaughtExceptionHandler(this);
|
||||
instance = this;
|
||||
|
||||
Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
|
||||
try {
|
||||
// Always save crash file if onCreate() is not done
|
||||
if (!initialized || Settings.getSaveCrashLog()) {
|
||||
Crash.saveCrashLog(instance, e);
|
||||
}
|
||||
} catch (Throwable ignored) { }
|
||||
|
||||
if (handler != null) {
|
||||
handler.uncaughtException(t, e);
|
||||
}
|
||||
});
|
||||
|
||||
super.onCreate();
|
||||
|
||||
@@ -102,6 +133,8 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
EhDB.initialize(this);
|
||||
EhEngine.initialize();
|
||||
BitmapUtils.initialize(this);
|
||||
Image.initialize(this);
|
||||
A7Zip.loadLibrary(A7ZipExtractLite.LIBRARY, libname -> ReLinker.loadLibrary(EhApplication.this, libname));
|
||||
|
||||
if (EhDB.needMerge()) {
|
||||
EhDB.mergeOldDB(this);
|
||||
@@ -111,16 +144,32 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
Analytics.start(this);
|
||||
}
|
||||
|
||||
// Check no media file
|
||||
UniFile downloadLocation = Settings.getDownloadLocation();
|
||||
if (Settings.getMediaScan()) {
|
||||
CommonOperations.removeNoMediaFile(downloadLocation);
|
||||
} else {
|
||||
CommonOperations.ensureNoMediaFile(downloadLocation);
|
||||
}
|
||||
// Do io tasks in new thread
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
// Check no media file
|
||||
try {
|
||||
UniFile downloadLocation = Settings.getDownloadLocation();
|
||||
if (Settings.getMediaScan()) {
|
||||
CommonOperations.removeNoMediaFile(downloadLocation);
|
||||
} else {
|
||||
CommonOperations.ensureNoMediaFile(downloadLocation);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.throwIfFatal(t);
|
||||
}
|
||||
|
||||
// Clear temp dir
|
||||
clearTempDir();
|
||||
// Clear temp files
|
||||
try {
|
||||
clearTempDir();
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.throwIfFatal(t);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}.executeOnExecutor(IoThreadPoolExecutor.getInstance());
|
||||
|
||||
// Check app update
|
||||
update();
|
||||
@@ -133,9 +182,13 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
// Ignore
|
||||
}
|
||||
|
||||
mIdGenerator.setNextId(Settings.getInt(KEY_GLOBAL_STUFF_NEXT_ID, 0));
|
||||
|
||||
if (DEBUG_PRINT_NATIVE_MEMORY || DEBUG_PRINT_IMAGE_COUNT) {
|
||||
debugPrint();
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
private void clearTempDir() {
|
||||
@@ -147,6 +200,9 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
if (null != dir) {
|
||||
FileUtils.deleteContent(dir);
|
||||
}
|
||||
|
||||
// Add .nomedia to external temp dir
|
||||
CommonOperations.ensureNoMediaFile(UniFile.fromFile(AppConfig.getExternalTempDir()));
|
||||
}
|
||||
|
||||
private void update() {
|
||||
@@ -193,6 +249,7 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
public int putGlobalStuff(@NonNull Object o) {
|
||||
int id = mIdGenerator.nextId();
|
||||
mGlobalStuffMap.put(id, o);
|
||||
Settings.putInt(KEY_GLOBAL_STUFF_NEXT_ID, mIdGenerator.nextId());
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -229,6 +286,15 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
return application.mEhClient;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static EhProxySelector getEhProxySelector(@NonNull Context context) {
|
||||
EhApplication application = ((EhApplication) context.getApplicationContext());
|
||||
if (application.mEhProxySelector == null) {
|
||||
application.mEhProxySelector = new EhProxySelector();
|
||||
}
|
||||
return application.mEhProxySelector;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static OkHttpClient getOkHttpClient(@NonNull Context context) {
|
||||
EhApplication application = ((EhApplication) context.getApplicationContext());
|
||||
@@ -238,6 +304,8 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
.readTimeout(10, TimeUnit.SECONDS)
|
||||
.writeTimeout(10, TimeUnit.SECONDS)
|
||||
.cookieJar(getEhCookieStore(application))
|
||||
.dns(new EhDns(application))
|
||||
.proxySelector(getEhProxySelector(application))
|
||||
.build();
|
||||
}
|
||||
return application.mOkHttpClient;
|
||||
@@ -280,6 +348,12 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
if (application.mGalleryDetailCache == null) {
|
||||
// Max size 25, 3 min timeout
|
||||
application.mGalleryDetailCache = new LruCache<>(25);
|
||||
getFavouriteStatusRouter().addListener((gid, slot) -> {
|
||||
GalleryDetail gd = application.mGalleryDetailCache.get(gid);
|
||||
if (gd != null) {
|
||||
gd.favoriteSlot = slot;
|
||||
}
|
||||
});
|
||||
}
|
||||
return application.mGalleryDetailCache;
|
||||
}
|
||||
@@ -294,6 +368,11 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
return application.mSpiderInfoCache;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static DownloadManager getDownloadManager() {
|
||||
return getDownloadManager(instance);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static DownloadManager getDownloadManager(@NonNull Context context) {
|
||||
EhApplication application = ((EhApplication) context.getApplicationContext());
|
||||
@@ -303,32 +382,27 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
return application.mDownloadManager;
|
||||
}
|
||||
|
||||
private boolean handleException(Throwable ex) {
|
||||
if (ex == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
ex.printStackTrace();
|
||||
Crash.saveCrashInfo2File(this, ex);
|
||||
return true;
|
||||
} catch (Throwable tr) {
|
||||
return false;
|
||||
@NonNull
|
||||
public static Hosts getHosts(@NonNull Context context) {
|
||||
EhApplication application = ((EhApplication) context.getApplicationContext());
|
||||
if (application.mHosts == null) {
|
||||
application.mHosts = new Hosts(application, "hosts.db");
|
||||
}
|
||||
return application.mHosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uncaughtException(Thread thread, Throwable ex) {
|
||||
if (!handleException(ex) && mDefaultHandler != null) {
|
||||
mDefaultHandler.uncaughtException(thread, ex);
|
||||
}
|
||||
@NonNull
|
||||
public static FavouriteStatusRouter getFavouriteStatusRouter() {
|
||||
return getFavouriteStatusRouter(getInstance());
|
||||
}
|
||||
|
||||
Activity activity = getTopActivity();
|
||||
if (activity != null) {
|
||||
activity.finish();
|
||||
@NonNull
|
||||
public static FavouriteStatusRouter getFavouriteStatusRouter(@NonNull Context context) {
|
||||
EhApplication application = ((EhApplication) context.getApplicationContext());
|
||||
if (application.mFavouriteStatusRouter == null) {
|
||||
application.mFavouriteStatusRouter = new FavouriteStatusRouter();
|
||||
}
|
||||
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
System.exit(1);
|
||||
return application.mFavouriteStatusRouter;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -352,4 +426,36 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid crash on some "energy saving" devices
|
||||
@Override
|
||||
public ComponentName startService(Intent service) {
|
||||
try {
|
||||
return super.startService(service);
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.throwIfFatal(t);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid crash on some "energy saving" devices
|
||||
@Override
|
||||
public boolean bindService(Intent service, ServiceConnection conn, int flags) {
|
||||
try {
|
||||
return super.bindService(service, conn, flags);
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.throwIfFatal(t);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid crash on some "energy saving" devices
|
||||
@Override
|
||||
public void unbindService(ServiceConnection conn) {
|
||||
try {
|
||||
super.unbindService(conn);
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.throwIfFatal(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,9 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.dao.DaoMaster;
|
||||
@@ -43,12 +42,14 @@ import com.hippo.ehviewer.dao.LocalFavoritesDao;
|
||||
import com.hippo.ehviewer.dao.QuickSearch;
|
||||
import com.hippo.ehviewer.dao.QuickSearchDao;
|
||||
import com.hippo.ehviewer.download.DownloadManager;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.SqlUtils;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.ObjectUtils;
|
||||
import com.hippo.yorozuya.collect.SparseJLArray;
|
||||
|
||||
import de.greenrobot.dao.AbstractDao;
|
||||
import de.greenrobot.dao.query.CloseableListIterator;
|
||||
import de.greenrobot.dao.query.LazyList;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -58,8 +59,6 @@ import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.greenrobot.dao.query.LazyList;
|
||||
|
||||
public class EhDB {
|
||||
|
||||
private static final String TAG = EhDB.class.getSimpleName();
|
||||
@@ -91,10 +90,9 @@ public class EhDB {
|
||||
|
||||
private static void upgradeDB(SQLiteDatabase db, int oldVersion) {
|
||||
switch (oldVersion) {
|
||||
case 1: // 1 to 2
|
||||
case 1: // 1 to 2, add FILTER
|
||||
FilterDao.createTable(db, true);
|
||||
break;
|
||||
case 2: // add ENABLE column to table FILTER
|
||||
case 2: // 2 to 3, add ENABLE column to table FILTER
|
||||
db.execSQL("CREATE TABLE " + "\"FILTER2\" (" +
|
||||
"\"_id\" INTEGER PRIMARY KEY ," +
|
||||
"\"MODE\" INTEGER NOT NULL ," +
|
||||
@@ -104,8 +102,24 @@ public class EhDB {
|
||||
"_id, MODE, TEXT, ENABLE)" +
|
||||
"SELECT _id, MODE, TEXT, 1 FROM FILTER;");
|
||||
db.execSQL("DROP TABLE FILTER");
|
||||
db.execSQL("ALTER TABLE FILTER2 RENAME TO FILTER");
|
||||
break;
|
||||
db.execSQL("ALTER TABLE FILTER2 RENAME TO FILTER");
|
||||
case 3: // 3 to 4, add PAGE_FROM and PAGE_TO column to QUICK_SEARCH
|
||||
db.execSQL("CREATE TABLE " + "\"QUICK_SEARCH2\" (" +
|
||||
"\"_id\" INTEGER PRIMARY KEY ," +
|
||||
"\"NAME\" TEXT," +
|
||||
"\"MODE\" INTEGER NOT NULL ," +
|
||||
"\"CATEGORY\" INTEGER NOT NULL ," +
|
||||
"\"KEYWORD\" TEXT," +
|
||||
"\"ADVANCE_SEARCH\" INTEGER NOT NULL ," +
|
||||
"\"MIN_RATING\" INTEGER NOT NULL ," +
|
||||
"\"PAGE_FROM\" INTEGER NOT NULL ," +
|
||||
"\"PAGE_TO\" INTEGER NOT NULL ," +
|
||||
"\"TIME\" INTEGER NOT NULL );");
|
||||
db.execSQL("INSERT INTO \"QUICK_SEARCH2\" (" +
|
||||
"_id, NAME, MODE, CATEGORY, KEYWORD, ADVANCE_SEARCH, MIN_RATING, PAGE_FROM, PAGE_TO, TIME)" +
|
||||
"SELECT _id, NAME, MODE, CATEGORY, KEYWORD, ADVANCE_SEARCH, MIN_RATING, -1, -1, TIME FROM QUICK_SEARCH;");
|
||||
db.execSQL("DROP TABLE QUICK_SEARCH");
|
||||
db.execSQL("ALTER TABLE QUICK_SEARCH2 RENAME TO QUICK_SEARCH");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +170,8 @@ public class EhDB {
|
||||
SQLiteDatabase oldDB;
|
||||
try {
|
||||
oldDB = oldDBHelper.getReadableDatabase();
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -178,7 +193,8 @@ public class EhDB {
|
||||
try {
|
||||
// In 0.6.x version, NaN is stored
|
||||
gi.rating = cursor.getFloat(7);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
gi.rating = -1.0f;
|
||||
}
|
||||
|
||||
@@ -189,7 +205,8 @@ public class EhDB {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -219,7 +236,8 @@ public class EhDB {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -255,7 +273,8 @@ public class EhDB {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -296,7 +315,8 @@ public class EhDB {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -325,13 +345,15 @@ public class EhDB {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
try {
|
||||
oldDBHelper.close();
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
@@ -624,30 +646,64 @@ public class EhDB {
|
||||
sDaoSession.getFilterDao().update(filter);
|
||||
}
|
||||
|
||||
public static synchronized boolean exportDB(Context context, File file) {
|
||||
File dbFile = context.getDatabasePath("eh.db");
|
||||
if (null == dbFile || !dbFile.isFile()) {
|
||||
return false;
|
||||
}
|
||||
if (null == file || !FileUtils.ensureFile(file)) {
|
||||
return false;
|
||||
}
|
||||
InputStream is = null;
|
||||
OutputStream os = null;
|
||||
try {
|
||||
is = new FileInputStream(dbFile);
|
||||
os = new FileOutputStream(file);
|
||||
IOUtils.copy(is, os);
|
||||
return true;
|
||||
private static <T> boolean copyDao(AbstractDao<T, ?> from, AbstractDao<T, ?> to) {
|
||||
try (CloseableListIterator<T> iterator = from.queryBuilder().listIterator()) {
|
||||
while (iterator.hasNext()) {
|
||||
to.insert(iterator.next());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static synchronized boolean exportDB(Context context, File file) {
|
||||
final String ehExportName = "eh.export.db";
|
||||
|
||||
// Delete old export db
|
||||
context.deleteDatabase(ehExportName);
|
||||
|
||||
DBOpenHelper helper = new DBOpenHelper(context.getApplicationContext(), ehExportName, null);
|
||||
|
||||
try {
|
||||
// Copy data to a export db
|
||||
try (SQLiteDatabase db = helper.getWritableDatabase()) {
|
||||
DaoMaster daoMaster = new DaoMaster(db);
|
||||
DaoSession exportSession = daoMaster.newSession();
|
||||
if (!copyDao(sDaoSession.getDownloadsDao(), exportSession.getDownloadsDao())) return false;
|
||||
if (!copyDao(sDaoSession.getDownloadLabelDao(), exportSession.getDownloadLabelDao())) return false;
|
||||
if (!copyDao(sDaoSession.getDownloadDirnameDao(), exportSession.getDownloadDirnameDao())) return false;
|
||||
if (!copyDao(sDaoSession.getHistoryDao(), exportSession.getHistoryDao())) return false;
|
||||
if (!copyDao(sDaoSession.getQuickSearchDao(), exportSession.getQuickSearchDao())) return false;
|
||||
if (!copyDao(sDaoSession.getLocalFavoritesDao(), exportSession.getLocalFavoritesDao())) return false;
|
||||
if (!copyDao(sDaoSession.getBookmarksBao(), exportSession.getBookmarksBao())) return false;
|
||||
if (!copyDao(sDaoSession.getFilterDao(), exportSession.getFilterDao())) return false;
|
||||
}
|
||||
|
||||
// Copy export db to data dir
|
||||
File dbFile = context.getDatabasePath(ehExportName);
|
||||
if (dbFile == null || !dbFile.isFile()) {
|
||||
return false;
|
||||
}
|
||||
InputStream is = null;
|
||||
OutputStream os = null;
|
||||
try {
|
||||
is = new FileInputStream(dbFile);
|
||||
os = new FileOutputStream(file);
|
||||
IOUtils.copy(is, os);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(is);
|
||||
IOUtils.closeQuietly(os);
|
||||
}
|
||||
// Delete failed file
|
||||
file.delete();
|
||||
return false;
|
||||
} finally {
|
||||
IOUtils.closeQuietly(is);
|
||||
IOUtils.closeQuietly(os);
|
||||
context.deleteDatabase(ehExportName);
|
||||
}
|
||||
// Delete failed file
|
||||
file.delete();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -726,7 +782,8 @@ public class EhDB {
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
return context.getString(R.string.cant_read_the_file);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.hippo.network.InetValidator;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.ProxySelector;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class EhProxySelector extends ProxySelector {
|
||||
|
||||
public static final int TYPE_DIRECT = 0;
|
||||
public static final int TYPE_SYSTEM = 1;
|
||||
public static final int TYPE_HTTP = 2;
|
||||
public static final int TYPE_SOCKS = 3;
|
||||
|
||||
private ProxySelector delegation;
|
||||
private ProxySelector alternative;
|
||||
|
||||
EhProxySelector() {
|
||||
alternative = ProxySelector.getDefault();
|
||||
if (alternative == null) {
|
||||
alternative = new NullProxySelector();
|
||||
}
|
||||
|
||||
updateProxy();
|
||||
}
|
||||
|
||||
public void updateProxy() {
|
||||
switch (Settings.getProxyType()) {
|
||||
case TYPE_DIRECT:
|
||||
delegation = new NullProxySelector();
|
||||
break;
|
||||
default:
|
||||
case TYPE_SYSTEM:
|
||||
delegation = alternative;
|
||||
break;
|
||||
case TYPE_HTTP:
|
||||
case TYPE_SOCKS:
|
||||
delegation = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Proxy> select(URI uri) {
|
||||
int type = Settings.getProxyType();
|
||||
if (type == TYPE_HTTP || type == TYPE_SOCKS) {
|
||||
try {
|
||||
String ip = Settings.getProxyIp();
|
||||
int port = Settings.getProxyPort();
|
||||
if (!TextUtils.isEmpty(ip) && InetValidator.isValidInetPort(port)) {
|
||||
InetAddress inetAddress = InetAddress.getByName(ip);
|
||||
SocketAddress socketAddress = new InetSocketAddress(inetAddress, port);
|
||||
return Collections.singletonList(new Proxy(type == TYPE_HTTP ? Proxy.Type.HTTP : Proxy.Type.SOCKS, socketAddress));
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.throwIfFatal(t);
|
||||
}
|
||||
}
|
||||
|
||||
if (delegation != null) {
|
||||
return delegation.select(uri);
|
||||
}
|
||||
|
||||
return alternative.select(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
|
||||
if (delegation != null) {
|
||||
delegation.select(uri);
|
||||
}
|
||||
}
|
||||
|
||||
private static class NullProxySelector extends ProxySelector {
|
||||
@Override
|
||||
public List<Proxy> select(URI uri) {
|
||||
return Collections.singletonList(Proxy.NO_PROXY);
|
||||
}
|
||||
@Override
|
||||
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FavouriteStatusRouter {
|
||||
|
||||
private static final String KEY_DATA_MAP_NEXT_ID = "data_map_next_id";
|
||||
|
||||
private final IntIdGenerator idGenerator = new IntIdGenerator(Settings.getInt(KEY_DATA_MAP_NEXT_ID, 0));
|
||||
@SuppressLint("UseSparseArrays")
|
||||
private final HashMap<Integer, Map<Long, GalleryInfo>> maps = new HashMap<>();
|
||||
|
||||
private List<Listener> listeners = new ArrayList<>();
|
||||
|
||||
public int saveDataMap(Map<Long, GalleryInfo> map) {
|
||||
int id = idGenerator.nextId();
|
||||
maps.put(id, map);
|
||||
Settings.putInt(KEY_DATA_MAP_NEXT_ID, idGenerator.nextId());
|
||||
return id;
|
||||
}
|
||||
|
||||
public Map<Long, GalleryInfo> restoreDataMap(int id) {
|
||||
return maps.remove(id);
|
||||
}
|
||||
|
||||
public void modifyFavourites(long gid, int slot) {
|
||||
for (Map<Long, GalleryInfo> map : maps.values()) {
|
||||
GalleryInfo info = map.get(gid);
|
||||
if (info != null) {
|
||||
info.favoriteSlot = slot;
|
||||
}
|
||||
}
|
||||
|
||||
for (Listener listener : listeners) {
|
||||
listener.onModifyFavourites(gid, slot);
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(Listener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(Listener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
public interface Listener {
|
||||
void onModifyFavourites(long gid, int slot);
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@ package com.hippo.ehviewer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.StringRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
public class GetText {
|
||||
|
||||
|
||||
@@ -0,0 +1,350 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer;
|
||||
|
||||
/*
|
||||
* Created by Hippo on 2018/3/21.
|
||||
*/
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.util.Pair;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.database.MSQLiteBuilder;
|
||||
import com.hippo.util.SqlUtils;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Hosts {
|
||||
|
||||
private static final int VERSION_1 = 1;
|
||||
private static final String TABLE_HOSTS = "HOSTS";
|
||||
private static final String COLUMN_HOST = "HOST";
|
||||
private static final String COLUMN_IP = "IP";
|
||||
|
||||
private static final int DB_VERSION = VERSION_1;
|
||||
|
||||
private final SQLiteOpenHelper helper;
|
||||
private final SQLiteDatabase db;
|
||||
|
||||
public Hosts(Context context, String name) {
|
||||
helper = new MSQLiteBuilder()
|
||||
.version(VERSION_1)
|
||||
.createTable(TABLE_HOSTS)
|
||||
.insertColumn(TABLE_HOSTS, COLUMN_HOST, String.class)
|
||||
.insertColumn(TABLE_HOSTS, COLUMN_IP, String.class)
|
||||
.build(context, name, DB_VERSION);
|
||||
db = helper.getWritableDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a InetAddress with the host.
|
||||
*/
|
||||
@Nullable
|
||||
public InetAddress get(String host) {
|
||||
if (!isValidHost(host)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_HOSTS + " WHERE " + COLUMN_HOST + " = ?;", new String[] {host});
|
||||
try {
|
||||
if (cursor.moveToNext()) {
|
||||
String ip = SqlUtils.getString(cursor, COLUMN_IP, null);
|
||||
return toInetAddress(host, ip);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean contains(String host) {
|
||||
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_HOSTS + " WHERE " + COLUMN_HOST + " = ?;", new String[] {host});
|
||||
try {
|
||||
return cursor.moveToNext();
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the host-ip pair into this hosts.
|
||||
*/
|
||||
public boolean put(String host, String ip) {
|
||||
if (!isValidHost(host) || !isValidIp(ip)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(COLUMN_HOST, host);
|
||||
values.put(COLUMN_IP, ip);
|
||||
|
||||
if (contains(host)) {
|
||||
db.update(TABLE_HOSTS, values, COLUMN_HOST + " = ?", new String[] { host });
|
||||
} else {
|
||||
db.insert(TABLE_HOSTS, null, values);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts delete the entry with the host.
|
||||
*/
|
||||
public void delete(String host) {
|
||||
db.delete(TABLE_HOSTS, COLUMN_HOST + " = ?", new String[] { host });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all data from this host.
|
||||
*/
|
||||
public List<Pair<String, String>> getAll() {
|
||||
List<Pair<String, String>> result = new ArrayList<>();
|
||||
|
||||
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_HOSTS + ";", null);
|
||||
try {
|
||||
while (cursor.moveToNext()) {
|
||||
String host = SqlUtils.getString(cursor, COLUMN_HOST, null);
|
||||
String ip = SqlUtils.getString(cursor, COLUMN_IP, null);
|
||||
|
||||
InetAddress inetAddress = toInetAddress(host, ip);
|
||||
if (inetAddress == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.add(new Pair<>(host, ip));
|
||||
}
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static InetAddress toInetAddress(String host, String ip) {
|
||||
if (!isValidHost(host)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ip == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] bytes = parseV4(ip);
|
||||
if (bytes == null) {
|
||||
bytes = parseV6(ip);
|
||||
}
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return InetAddress.getByAddress(host, bytes);
|
||||
} catch (UnknownHostException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the host is valid.
|
||||
*/
|
||||
public static boolean isValidHost(String host) {
|
||||
if (host == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (host.length() > 253) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int labelLength = 0;
|
||||
for (int i = 0, n = host.length(); i < n; i++) {
|
||||
char ch = host.charAt(i);
|
||||
|
||||
if (ch == '.') {
|
||||
if (labelLength < 1 || labelLength > 63) {
|
||||
return false;
|
||||
}
|
||||
labelLength = 0;
|
||||
} else {
|
||||
labelLength++;
|
||||
}
|
||||
|
||||
if ((ch < 'a' || ch > 'z') && (ch < '0' || ch > '9') && ch != '-' && ch != '.') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (labelLength < 1 || labelLength > 63) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the ip is valid.
|
||||
*/
|
||||
public static boolean isValidIp(String ip) {
|
||||
return ip != null && (parseV4(ip) != null || parseV6(ip) != null);
|
||||
}
|
||||
|
||||
// org.xbill.DNS.Address.parseV4
|
||||
@Nullable
|
||||
private static byte[] parseV4(String s) {
|
||||
int numDigits;
|
||||
int currentOctet;
|
||||
byte [] values = new byte[4];
|
||||
int currentValue;
|
||||
int length = s.length();
|
||||
|
||||
currentOctet = 0;
|
||||
currentValue = 0;
|
||||
numDigits = 0;
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = s.charAt(i);
|
||||
if (c >= '0' && c <= '9') {
|
||||
/* Can't have more than 3 digits per octet. */
|
||||
if (numDigits == 3)
|
||||
return null;
|
||||
/* Octets shouldn't start with 0, unless they are 0. */
|
||||
if (numDigits > 0 && currentValue == 0)
|
||||
return null;
|
||||
numDigits++;
|
||||
currentValue *= 10;
|
||||
currentValue += (c - '0');
|
||||
/* 255 is the maximum value for an octet. */
|
||||
if (currentValue > 255)
|
||||
return null;
|
||||
} else if (c == '.') {
|
||||
/* Can't have more than 3 dots. */
|
||||
if (currentOctet == 3)
|
||||
return null;
|
||||
/* Two consecutive dots are bad. */
|
||||
if (numDigits == 0)
|
||||
return null;
|
||||
values[currentOctet++] = (byte) currentValue;
|
||||
currentValue = 0;
|
||||
numDigits = 0;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
/* Must have 4 octets. */
|
||||
if (currentOctet != 3)
|
||||
return null;
|
||||
/* The fourth octet can't be empty. */
|
||||
if (numDigits == 0)
|
||||
return null;
|
||||
values[currentOctet] = (byte) currentValue;
|
||||
return values;
|
||||
}
|
||||
|
||||
// org.xbill.DNS.Address.parseV6
|
||||
@Nullable
|
||||
private static byte[] parseV6(String s) {
|
||||
int range = -1;
|
||||
byte [] data = new byte[16];
|
||||
|
||||
String [] tokens = s.split(":", -1);
|
||||
|
||||
int first = 0;
|
||||
int last = tokens.length - 1;
|
||||
|
||||
if (tokens[0].length() == 0) {
|
||||
// If the first two tokens are empty, it means the string
|
||||
// started with ::, which is fine. If only the first is
|
||||
// empty, the string started with :, which is bad.
|
||||
if (last - first > 0 && tokens[1].length() == 0)
|
||||
first++;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
if (tokens[last].length() == 0) {
|
||||
// If the last two tokens are empty, it means the string
|
||||
// ended with ::, which is fine. If only the last is
|
||||
// empty, the string ended with :, which is bad.
|
||||
if (last - first > 0 && tokens[last - 1].length() == 0)
|
||||
last--;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
if (last - first + 1 > 8)
|
||||
return null;
|
||||
|
||||
int i, j;
|
||||
for (i = first, j = 0; i <= last; i++) {
|
||||
if (tokens[i].length() == 0) {
|
||||
if (range >= 0)
|
||||
return null;
|
||||
range = j;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tokens[i].indexOf('.') >= 0) {
|
||||
// An IPv4 address must be the last component
|
||||
if (i < last)
|
||||
return null;
|
||||
// There can't have been more than 6 components.
|
||||
if (i > 6)
|
||||
return null;
|
||||
byte [] v4addr = parseV4(tokens[i]);
|
||||
if (v4addr == null)
|
||||
return null;
|
||||
for (int k = 0; k < 4; k++)
|
||||
data[j++] = v4addr[k];
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
for (int k = 0; k < tokens[i].length(); k++) {
|
||||
char c = tokens[i].charAt(k);
|
||||
if (Character.digit(c, 16) < 0)
|
||||
return null;
|
||||
}
|
||||
int x = Integer.parseInt(tokens[i], 16);
|
||||
if (x > 0xFFFF || x < 0)
|
||||
return null;
|
||||
data[j++] = (byte)(x >>> 8);
|
||||
data[j++] = (byte)(x & 0xFF);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (j < 16 && range < 0)
|
||||
return null;
|
||||
|
||||
if (range >= 0) {
|
||||
int empty = 16 - j;
|
||||
System.arraycopy(data, range, data, range + empty, j - range);
|
||||
for (i = range; i < range + empty; i++)
|
||||
data[i] = 0;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -16,13 +16,11 @@
|
||||
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.conaco.ValueHelper;
|
||||
import com.hippo.image.ImageBitmap;
|
||||
import com.hippo.streampipe.InputStreamPipe;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ImageBitmapHelper implements ValueHelper<ImageBitmap> {
|
||||
|
||||
@@ -16,29 +16,28 @@
|
||||
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.DimenRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.DimenRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.client.EhConfig;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.FavListUrlBuilder;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.ui.scene.GalleryListScene;
|
||||
import com.hippo.glgallery.GalleryView;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Settings {
|
||||
|
||||
@@ -52,6 +51,16 @@ public class Settings {
|
||||
sContext = context.getApplicationContext();
|
||||
sSettingsPre = PreferenceManager.getDefaultSharedPreferences(sContext);
|
||||
sEhConfig = loadEhConfig();
|
||||
fixDefaultValue(context);
|
||||
}
|
||||
|
||||
private static void fixDefaultValue(Context context) {
|
||||
// Enable builtin hosts if the country is CN
|
||||
if (!sSettingsPre.contains(KEY_BUILT_IN_HOSTS)) {
|
||||
if ("CN".equals(Locale.getDefault().getCountry())) {
|
||||
putBuiltInHosts(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static EhConfig loadEhConfig() {
|
||||
@@ -237,6 +246,28 @@ public class Settings {
|
||||
/********************
|
||||
****** Eh
|
||||
********************/
|
||||
|
||||
public static final String KEY_THEME = "theme";
|
||||
public static final int THEME_LIGHT = 0;
|
||||
public static final int THEME_DARK = 1;
|
||||
public static final int THEME_BLACK = 2;
|
||||
private static final int DEFAULT_THEME = THEME_LIGHT;
|
||||
|
||||
public static int getTheme() {
|
||||
return getIntFromStr(KEY_THEME, DEFAULT_THEME);
|
||||
}
|
||||
|
||||
public static void putTheme(int theme) {
|
||||
putIntToStr(KEY_THEME, theme);
|
||||
}
|
||||
|
||||
public static final String KEY_APPLY_NAV_BAR_THEME_COLOR = "apply_nav_bar_theme_color";
|
||||
private static final boolean DEFAULT_APPLY_NAV_BAR_THEME_COLOR = true;
|
||||
|
||||
public static boolean getApplyNavBarThemeColor() {
|
||||
return getBoolean(KEY_APPLY_NAV_BAR_THEME_COLOR, DEFAULT_APPLY_NAV_BAR_THEME_COLOR);
|
||||
}
|
||||
|
||||
public static final String KEY_GALLERY_SITE = "gallery_site";
|
||||
private static final int DEFAULT_GALLERY_SITE = 1;
|
||||
|
||||
@@ -248,6 +279,22 @@ public class Settings {
|
||||
putIntToStr(KEY_GALLERY_SITE, value);
|
||||
}
|
||||
|
||||
private static final String KEY_LAUNCH_PAGE = "launch_page";
|
||||
private static final int DEFAULT_LAUNCH_PAGE = 0;
|
||||
|
||||
public static String getLaunchPageGalleryListSceneAction() {
|
||||
int value = getIntFromStr(KEY_LAUNCH_PAGE, DEFAULT_LAUNCH_PAGE);
|
||||
switch (value) {
|
||||
default:
|
||||
case 0:
|
||||
return GalleryListScene.ACTION_HOMEPAGE;
|
||||
case 1:
|
||||
return GalleryListScene.ACTION_SUBSCRIPTION;
|
||||
case 2:
|
||||
return GalleryListScene.ACTION_WHATS_HOT;
|
||||
}
|
||||
}
|
||||
|
||||
public static final String KEY_LIST_MODE = "list_mode";
|
||||
private static final int DEFAULT_LIST_MODE = 0;
|
||||
|
||||
@@ -314,6 +361,20 @@ public class Settings {
|
||||
return getBoolean(KEY_SHOW_JPN_TITLE, DEFAULT_SHOW_JPN_TITLE);
|
||||
}
|
||||
|
||||
private static final String KEY_SHOW_GALLERY_PAGES = "show_gallery_pages";
|
||||
private static final boolean DEFAULT_SHOW_GALLERY_PAGES = false;
|
||||
|
||||
public static boolean getShowGalleryPages() {
|
||||
return getBoolean(KEY_SHOW_GALLERY_PAGES, DEFAULT_SHOW_GALLERY_PAGES);
|
||||
}
|
||||
|
||||
public static final String KEY_SHOW_TAG_TRANSLATIONS = "show_tag_translations";
|
||||
private static final boolean DEFAULT_SHOW_TAG_TRANSLATIONS = false;
|
||||
|
||||
public static boolean getShowTagTranslations() {
|
||||
return getBoolean(KEY_SHOW_TAG_TRANSLATIONS, DEFAULT_SHOW_TAG_TRANSLATIONS);
|
||||
}
|
||||
|
||||
public static final String KEY_DEFAULT_CATEGORIES = "default_categories";
|
||||
public static final int DEFAULT_DEFAULT_CATEGORIES = EhUtils.ALL_CATEGORY;
|
||||
|
||||
@@ -353,72 +414,6 @@ public class Settings {
|
||||
putString(KEY_EXCLUDED_LANGUAGES, value);
|
||||
}
|
||||
|
||||
private static final String KEY_HATH_PROXY = "hath_proxy";
|
||||
private static final boolean DEFAULT_HATH_PROXY = false;
|
||||
|
||||
public static boolean getHathProxy() {
|
||||
return getBoolean(KEY_HATH_PROXY, DEFAULT_HATH_PROXY);
|
||||
}
|
||||
|
||||
public static void putHathProxy(boolean value) {
|
||||
if (value) {
|
||||
sEhConfig.hahClientIp = Settings.getHathIp();
|
||||
sEhConfig.hahClientPort = Settings.getHathPort();
|
||||
sEhConfig.hahClientPasskey = Settings.getHathPasskey();
|
||||
} else {
|
||||
sEhConfig.hahClientIp = DEFAULT_HATH_IP;
|
||||
sEhConfig.hahClientPort = DEFAULT_HATH_PORT;
|
||||
sEhConfig.hahClientPasskey = DEFAULT_HATH_PASSKEY;
|
||||
}
|
||||
sEhConfig.setDirty();
|
||||
putBoolean(KEY_HATH_PROXY, value);
|
||||
}
|
||||
|
||||
private static final String KEY_HATH_IP = "hath_ip";
|
||||
private static final String DEFAULT_HATH_IP = null;
|
||||
|
||||
public static String getHathIp() {
|
||||
return getString(KEY_HATH_IP, DEFAULT_HATH_IP);
|
||||
}
|
||||
|
||||
public static void putHathIp(String value) {
|
||||
if (Settings.getHathProxy()) {
|
||||
sEhConfig.hahClientIp = value;
|
||||
sEhConfig.setDirty();
|
||||
}
|
||||
putString(KEY_HATH_IP, value);
|
||||
}
|
||||
|
||||
private static final String KEY_HATH_PORT = "hath_port";
|
||||
private static final int DEFAULT_HATH_PORT = -1;
|
||||
|
||||
public static int getHathPort() {
|
||||
return getInt(KEY_HATH_PORT, DEFAULT_HATH_PORT);
|
||||
}
|
||||
|
||||
public static void putHathPort(int value) {
|
||||
if (Settings.getHathProxy()) {
|
||||
sEhConfig.hahClientPort = value;
|
||||
sEhConfig.setDirty();
|
||||
}
|
||||
putInt(KEY_HATH_PORT, value);
|
||||
}
|
||||
|
||||
private static final String KEY_HATH_PASSKEY = "hath_passkey";
|
||||
private static final String DEFAULT_HATH_PASSKEY = null;
|
||||
|
||||
public static String getHathPasskey() {
|
||||
return getString(KEY_HATH_PASSKEY, DEFAULT_HATH_PASSKEY);
|
||||
}
|
||||
|
||||
public static void putHathPasskey(String value) {
|
||||
if (Settings.getHathProxy()) {
|
||||
sEhConfig.hahClientPasskey = value;
|
||||
sEhConfig.setDirty();
|
||||
}
|
||||
putString(KEY_HATH_PASSKEY, value);
|
||||
}
|
||||
|
||||
private static final String KEY_CELLULAR_NETWORK_WARNING = "cellular_network_warning";
|
||||
private static final boolean DEFAULT_CELLULAR_NETWORK_WARNING = false;
|
||||
|
||||
@@ -575,6 +570,19 @@ public class Settings {
|
||||
putInt(KEY_SCREEN_LIGHTNESS, value);
|
||||
}
|
||||
|
||||
/********************
|
||||
****** Privacy and Security
|
||||
********************/
|
||||
public static final String KEY_SEC_SECURITY = "enable_secure";
|
||||
public static final boolean VALUE_SEC_SECURITY = false;
|
||||
|
||||
public static boolean getEnabledSecurity() {
|
||||
return getBoolean(KEY_SEC_SECURITY, VALUE_SEC_SECURITY);
|
||||
}
|
||||
public static void putEnabledSecurity(boolean value) {
|
||||
putBoolean(KEY_READING_FULLSCREEN, value);
|
||||
}
|
||||
|
||||
/********************
|
||||
****** Download
|
||||
********************/
|
||||
@@ -595,7 +603,8 @@ public class Settings {
|
||||
builder.encodedQuery(getString(KEY_DOWNLOAD_SAVE_QUERY, null));
|
||||
builder.encodedFragment(getString(KEY_DOWNLOAD_SAVE_FRAGMENT, null));
|
||||
dir = UniFile.fromUri(sContext, builder.build());
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
return dir != null ? dir : UniFile.fromFile(AppConfig.getDefaultDownloadDir());
|
||||
@@ -705,26 +714,42 @@ public class Settings {
|
||||
/********************
|
||||
****** Favorites
|
||||
********************/
|
||||
public static final String KEY_FAV_CAT_0 = "fav_cat_0";
|
||||
public static final String KEY_FAV_CAT_1 = "fav_cat_1";
|
||||
public static final String KEY_FAV_CAT_2 = "fav_cat_2";
|
||||
public static final String KEY_FAV_CAT_3 = "fav_cat_3";
|
||||
public static final String KEY_FAV_CAT_4 = "fav_cat_4";
|
||||
public static final String KEY_FAV_CAT_5 = "fav_cat_5";
|
||||
public static final String KEY_FAV_CAT_6 = "fav_cat_6";
|
||||
public static final String KEY_FAV_CAT_7 = "fav_cat_7";
|
||||
public static final String KEY_FAV_CAT_8 = "fav_cat_8";
|
||||
public static final String KEY_FAV_CAT_9 = "fav_cat_9";
|
||||
public static final String DEFAULT_FAV_CAT_0 = "Favorites 0";
|
||||
public static final String DEFAULT_FAV_CAT_1 = "Favorites 1";
|
||||
public static final String DEFAULT_FAV_CAT_2 = "Favorites 2";
|
||||
public static final String DEFAULT_FAV_CAT_3 = "Favorites 3";
|
||||
public static final String DEFAULT_FAV_CAT_4 = "Favorites 4";
|
||||
public static final String DEFAULT_FAV_CAT_5 = "Favorites 5";
|
||||
public static final String DEFAULT_FAV_CAT_6 = "Favorites 6";
|
||||
public static final String DEFAULT_FAV_CAT_7 = "Favorites 7";
|
||||
public static final String DEFAULT_FAV_CAT_8 = "Favorites 8";
|
||||
public static final String DEFAULT_FAV_CAT_9 = "Favorites 9";
|
||||
private static final String KEY_FAV_CAT_0 = "fav_cat_0";
|
||||
private static final String KEY_FAV_CAT_1 = "fav_cat_1";
|
||||
private static final String KEY_FAV_CAT_2 = "fav_cat_2";
|
||||
private static final String KEY_FAV_CAT_3 = "fav_cat_3";
|
||||
private static final String KEY_FAV_CAT_4 = "fav_cat_4";
|
||||
private static final String KEY_FAV_CAT_5 = "fav_cat_5";
|
||||
private static final String KEY_FAV_CAT_6 = "fav_cat_6";
|
||||
private static final String KEY_FAV_CAT_7 = "fav_cat_7";
|
||||
private static final String KEY_FAV_CAT_8 = "fav_cat_8";
|
||||
private static final String KEY_FAV_CAT_9 = "fav_cat_9";
|
||||
private static final String DEFAULT_FAV_CAT_0 = "Favorites 0";
|
||||
private static final String DEFAULT_FAV_CAT_1 = "Favorites 1";
|
||||
private static final String DEFAULT_FAV_CAT_2 = "Favorites 2";
|
||||
private static final String DEFAULT_FAV_CAT_3 = "Favorites 3";
|
||||
private static final String DEFAULT_FAV_CAT_4 = "Favorites 4";
|
||||
private static final String DEFAULT_FAV_CAT_5 = "Favorites 5";
|
||||
private static final String DEFAULT_FAV_CAT_6 = "Favorites 6";
|
||||
private static final String DEFAULT_FAV_CAT_7 = "Favorites 7";
|
||||
private static final String DEFAULT_FAV_CAT_8 = "Favorites 8";
|
||||
private static final String DEFAULT_FAV_CAT_9 = "Favorites 9";
|
||||
|
||||
private static final String KEY_FAV_COUNT_0 = "fav_count_0";
|
||||
private static final String KEY_FAV_COUNT_1 = "fav_count_1";
|
||||
private static final String KEY_FAV_COUNT_2 = "fav_count_2";
|
||||
private static final String KEY_FAV_COUNT_3 = "fav_count_3";
|
||||
private static final String KEY_FAV_COUNT_4 = "fav_count_4";
|
||||
private static final String KEY_FAV_COUNT_5 = "fav_count_5";
|
||||
private static final String KEY_FAV_COUNT_6 = "fav_count_6";
|
||||
private static final String KEY_FAV_COUNT_7 = "fav_count_7";
|
||||
private static final String KEY_FAV_COUNT_8 = "fav_count_8";
|
||||
private static final String KEY_FAV_COUNT_9 = "fav_count_9";
|
||||
|
||||
private static final String KEY_FAV_LOCAL = "fav_local";
|
||||
private static final String KEY_FAV_CLOUD = "fav_cloud";
|
||||
|
||||
private static final int DEFAULT_FAV_COUNT = 0;
|
||||
|
||||
public static String[] getFavCat() {
|
||||
String[] favCat = new String[10];
|
||||
@@ -742,7 +767,7 @@ public class Settings {
|
||||
}
|
||||
|
||||
public static void putFavCat(String[] value) {
|
||||
Assert.assertEquals(10, value.length);
|
||||
AssertUtils.assertEquals(10, value.length);
|
||||
sSettingsPre.edit()
|
||||
.putString(KEY_FAV_CAT_0, value[0])
|
||||
.putString(KEY_FAV_CAT_1, value[1])
|
||||
@@ -757,6 +782,53 @@ public class Settings {
|
||||
.apply();
|
||||
}
|
||||
|
||||
public static int[] getFavCount() {
|
||||
int[] favCount = new int[10];
|
||||
favCount[0] = sSettingsPre.getInt(KEY_FAV_COUNT_0, DEFAULT_FAV_COUNT);
|
||||
favCount[1] = sSettingsPre.getInt(KEY_FAV_COUNT_1, DEFAULT_FAV_COUNT);
|
||||
favCount[2] = sSettingsPre.getInt(KEY_FAV_COUNT_2, DEFAULT_FAV_COUNT);
|
||||
favCount[3] = sSettingsPre.getInt(KEY_FAV_COUNT_3, DEFAULT_FAV_COUNT);
|
||||
favCount[4] = sSettingsPre.getInt(KEY_FAV_COUNT_4, DEFAULT_FAV_COUNT);
|
||||
favCount[5] = sSettingsPre.getInt(KEY_FAV_COUNT_5, DEFAULT_FAV_COUNT);
|
||||
favCount[6] = sSettingsPre.getInt(KEY_FAV_COUNT_6, DEFAULT_FAV_COUNT);
|
||||
favCount[7] = sSettingsPre.getInt(KEY_FAV_COUNT_7, DEFAULT_FAV_COUNT);
|
||||
favCount[8] = sSettingsPre.getInt(KEY_FAV_COUNT_8, DEFAULT_FAV_COUNT);
|
||||
favCount[9] = sSettingsPre.getInt(KEY_FAV_COUNT_9, DEFAULT_FAV_COUNT);
|
||||
return favCount;
|
||||
}
|
||||
|
||||
public static void putFavCount(int[] count) {
|
||||
AssertUtils.assertEquals(10, count.length);
|
||||
sSettingsPre.edit()
|
||||
.putInt(KEY_FAV_COUNT_0, count[0])
|
||||
.putInt(KEY_FAV_COUNT_1, count[1])
|
||||
.putInt(KEY_FAV_COUNT_2, count[2])
|
||||
.putInt(KEY_FAV_COUNT_3, count[3])
|
||||
.putInt(KEY_FAV_COUNT_4, count[4])
|
||||
.putInt(KEY_FAV_COUNT_5, count[5])
|
||||
.putInt(KEY_FAV_COUNT_6, count[6])
|
||||
.putInt(KEY_FAV_COUNT_7, count[7])
|
||||
.putInt(KEY_FAV_COUNT_8, count[8])
|
||||
.putInt(KEY_FAV_COUNT_9, count[9])
|
||||
.apply();
|
||||
}
|
||||
|
||||
public static int getFavLocalCount() {
|
||||
return sSettingsPre.getInt(KEY_FAV_LOCAL, DEFAULT_FAV_COUNT);
|
||||
}
|
||||
|
||||
public static void putFavLocalCount(int count) {
|
||||
sSettingsPre.edit().putInt(KEY_FAV_LOCAL, count).apply();
|
||||
}
|
||||
|
||||
public static int getFavCloudCount() {
|
||||
return sSettingsPre.getInt(KEY_FAV_CLOUD, DEFAULT_FAV_COUNT);
|
||||
}
|
||||
|
||||
public static void putFavCloudCount(int count) {
|
||||
sSettingsPre.edit().putInt(KEY_FAV_CLOUD, count).apply();
|
||||
}
|
||||
|
||||
private static final String KEY_RECENT_FAV_CAT = "recent_fav_cat";
|
||||
private static final int DEFAULT_RECENT_FAV_CAT = FavListUrlBuilder.FAV_CAT_ALL;
|
||||
|
||||
@@ -873,6 +945,8 @@ public class Settings {
|
||||
********************/
|
||||
private static final String KEY_BETA_UPDATE_CHANNEL = "beta_update_channel";
|
||||
private static final boolean DEFAULT_BETA_UPDATE_CHANNEL = EhApplication.BETA;
|
||||
private static final String KEY_SKIP_UPDATE_VERSION = "skip_update_version";
|
||||
private static final int DEFAULT_SKIP_UPDATE_VERSION = 0;
|
||||
|
||||
public static boolean getBetaUpdateChannel() {
|
||||
return getBoolean(KEY_BETA_UPDATE_CHANNEL, DEFAULT_BETA_UPDATE_CHANNEL);
|
||||
@@ -882,19 +956,12 @@ public class Settings {
|
||||
putBoolean(KEY_BETA_UPDATE_CHANNEL, value);
|
||||
}
|
||||
|
||||
/********************
|
||||
****** Crash
|
||||
********************/
|
||||
private static final String KEY_CRASH_FILENAME = "crash_filename";
|
||||
private static final String DEFAULT_CRASH_FILENAME = null;
|
||||
|
||||
public static String getCrashFilename() {
|
||||
return getString(KEY_CRASH_FILENAME, DEFAULT_CRASH_FILENAME);
|
||||
public static int getSkipUpdateVersion() {
|
||||
return getInt(KEY_SKIP_UPDATE_VERSION, DEFAULT_SKIP_UPDATE_VERSION);
|
||||
}
|
||||
|
||||
@SuppressLint("CommitPrefEdits")
|
||||
public static void putCrashFilename(String value) {
|
||||
sSettingsPre.edit().putString(KEY_CRASH_FILENAME, value).commit();
|
||||
public static void putSkipUpdateVersion(int value) {
|
||||
putInt(KEY_SKIP_UPDATE_VERSION, value);
|
||||
}
|
||||
|
||||
/********************
|
||||
@@ -911,6 +978,13 @@ public class Settings {
|
||||
putBoolean(KEY_SAVE_PARSE_ERROR_BODY, value);
|
||||
}
|
||||
|
||||
private static final String KEY_SAVE_CRASH_LOG = "save_crash_log";
|
||||
private static final boolean DEFAULT_SAVE_CRASH_LOG = false;
|
||||
|
||||
public static boolean getSaveCrashLog() {
|
||||
return getBoolean(KEY_SAVE_CRASH_LOG, DEFAULT_SAVE_CRASH_LOG);
|
||||
}
|
||||
|
||||
public static final String KEY_SECURITY = "security";
|
||||
public static final String DEFAULT_SECURITY = "";
|
||||
|
||||
@@ -939,6 +1013,61 @@ public class Settings {
|
||||
return getIntFromStr(KEY_READ_CACHE_SIZE, DEFAULT_READ_CACHE_SIZE);
|
||||
}
|
||||
|
||||
public static final String KEY_BUILT_IN_HOSTS = "built_in_hosts";
|
||||
private static final boolean DEFAULT_BUILT_IN_HOSTS = false;
|
||||
|
||||
public static boolean getBuiltInHosts() {
|
||||
return getBoolean(KEY_BUILT_IN_HOSTS, DEFAULT_BUILT_IN_HOSTS);
|
||||
}
|
||||
|
||||
public static void putBuiltInHosts(boolean value) {
|
||||
putBoolean(KEY_BUILT_IN_HOSTS, value);
|
||||
}
|
||||
|
||||
public static final String KEY_APP_LANGUAGE = "app_language";
|
||||
private static final String DEFAULT_APP_LANGUAGE = "system";
|
||||
|
||||
public static String getAppLanguage() {
|
||||
return getString(KEY_APP_LANGUAGE, DEFAULT_APP_LANGUAGE);
|
||||
}
|
||||
|
||||
public static void putAppLanguage(String value) {
|
||||
putString(KEY_APP_LANGUAGE, value);
|
||||
}
|
||||
|
||||
private static final String KEY_PROXY_TYPE = "proxy_type";
|
||||
private static final int DEFAULT_PROXY_TYPE = EhProxySelector.TYPE_SYSTEM;
|
||||
|
||||
public static int getProxyType() {
|
||||
return getInt(KEY_PROXY_TYPE, DEFAULT_PROXY_TYPE);
|
||||
}
|
||||
|
||||
public static void putProxyType(int value) {
|
||||
putInt(KEY_PROXY_TYPE, value);
|
||||
}
|
||||
|
||||
private static final String KEY_PROXY_IP = "proxy_ip";
|
||||
private static final String DEFAULT_PROXY_IP = null;
|
||||
|
||||
public static String getProxyIp() {
|
||||
return getString(KEY_PROXY_IP, DEFAULT_PROXY_IP);
|
||||
}
|
||||
|
||||
public static void putProxyIp(String value) {
|
||||
putString(KEY_PROXY_IP, value);
|
||||
}
|
||||
|
||||
private static final String KEY_PROXY_PORT = "proxy_port";
|
||||
private static final int DEFAULT_PROXY_PORT = -1;
|
||||
|
||||
public static int getProxyPort() {
|
||||
return getInt(KEY_PROXY_PORT, DEFAULT_PROXY_PORT);
|
||||
}
|
||||
|
||||
public static void putProxyPort(int value) {
|
||||
putInt(KEY_PROXY_PORT, value);
|
||||
}
|
||||
|
||||
/********************
|
||||
****** Guide
|
||||
********************/
|
||||
@@ -996,4 +1125,15 @@ public class Settings {
|
||||
public static void putGuideGallery(boolean value) {
|
||||
putBoolean(KEY_GUIDE_GALLERY, value);
|
||||
}
|
||||
|
||||
private static final String KEY_CLIPBOARD_TEXT_HASH_CODE = "clipboard_text_hash_code";
|
||||
private static final int DEFAULT_CLIPBOARD_TEXT_HASH_CODE = 0;
|
||||
|
||||
public static int getClipboardTextHashCode() {
|
||||
return getInt(KEY_CLIPBOARD_TEXT_HASH_CODE, DEFAULT_CLIPBOARD_TEXT_HASH_CODE);
|
||||
}
|
||||
|
||||
public static void putClipboardTextHashCode(int value) {
|
||||
putInt(KEY_CLIPBOARD_TEXT_HASH_CODE, value);
|
||||
}
|
||||
}
|
||||
@@ -16,19 +16,18 @@
|
||||
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.Browser;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.hippo.ehviewer.client.EhUrlOpener;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
|
||||
public final class UrlOpener {
|
||||
|
||||
@@ -61,7 +60,8 @@ public final class UrlOpener {
|
||||
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
|
||||
try {
|
||||
context.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
Toast.makeText(context, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,15 @@ package com.hippo.ehviewer.client;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.CancelledException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.IoThreadPoolExecutor;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.thread.PriorityThreadFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
@@ -44,7 +36,6 @@ public class EhClient {
|
||||
|
||||
public static final int METHOD_SIGN_IN = 0;
|
||||
public static final int METHOD_GET_GALLERY_LIST = 1;
|
||||
public static final int METHOD_FILL_GALLERY_LIST_BY_API = 2;
|
||||
public static final int METHOD_GET_GALLERY_DETAIL = 3;
|
||||
public static final int METHOD_GET_PREVIEW_SET = 4;
|
||||
public static final int METHOD_GET_RATE_GALLERY = 5;
|
||||
@@ -55,7 +46,6 @@ public class EhClient {
|
||||
public static final int METHOD_ADD_FAVORITES_RANGE = 10;
|
||||
public static final int METHOD_MODIFY_FAVORITES = 11;
|
||||
public static final int METHOD_GET_TORRENT_LIST = 12;
|
||||
public static final int METHOD_GET_WHATS_HOT = 13;
|
||||
public static final int METHOD_GET_PROFILE = 14;
|
||||
public static final int METHOD_VOTE_COMMENT = 15;
|
||||
public static final int METHOD_IMAGE_SEARCH = 16;
|
||||
@@ -66,12 +56,7 @@ public class EhClient {
|
||||
private final OkHttpClient mOkHttpClient;
|
||||
|
||||
public EhClient(Context context) {
|
||||
int poolSize = 3;
|
||||
BlockingQueue<Runnable> requestWorkQueue = new LinkedBlockingQueue<>();
|
||||
ThreadFactory threadFactory = new PriorityThreadFactory(TAG,
|
||||
android.os.Process.THREAD_PRIORITY_BACKGROUND);
|
||||
mRequestThreadPool = new ThreadPoolExecutor(poolSize, poolSize,
|
||||
1L, TimeUnit.SECONDS, requestWorkQueue, threadFactory);
|
||||
mRequestThreadPool = IoThreadPoolExecutor.getInstance();
|
||||
mOkHttpClient = EhApplication.getOkHttpClient(context);
|
||||
}
|
||||
|
||||
@@ -153,11 +138,9 @@ public class EhClient {
|
||||
try {
|
||||
switch (mMethod) {
|
||||
case METHOD_SIGN_IN:
|
||||
return EhEngine.signIn(this, mOkHttpClient, (String) params[0], (String) params[1], (String) params[2], (String) params[3]);
|
||||
return EhEngine.signIn(this, mOkHttpClient, (String) params[0], (String) params[1]);
|
||||
case METHOD_GET_GALLERY_LIST:
|
||||
return EhEngine.getGalleryList(this, mOkHttpClient, (String) params[0]);
|
||||
case METHOD_FILL_GALLERY_LIST_BY_API:
|
||||
return EhEngine.fillGalleryListByApi(this, mOkHttpClient, (List<GalleryInfo>) params[0]);
|
||||
case METHOD_GET_GALLERY_DETAIL:
|
||||
return EhEngine.getGalleryDetail(this, mOkHttpClient, (String) params[0]);
|
||||
case METHOD_GET_PREVIEW_SET:
|
||||
@@ -165,7 +148,7 @@ public class EhClient {
|
||||
case METHOD_GET_RATE_GALLERY:
|
||||
return EhEngine.rateGallery(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (String) params[3], (Float) params[4]);
|
||||
case METHOD_GET_COMMENT_GALLERY:
|
||||
return EhEngine.commentGallery(this, mOkHttpClient, (String) params[0], (String) params[1]);
|
||||
return EhEngine.commentGallery(this, mOkHttpClient, (String) params[0], (String) params[1], (String) params[2]);
|
||||
case METHOD_GET_GALLERY_TOKEN:
|
||||
return EhEngine.getGalleryToken(this, mOkHttpClient, (Long) params[0], (String) params[1], (Integer) params[2]);
|
||||
case METHOD_GET_FAVORITES:
|
||||
@@ -177,9 +160,7 @@ public class EhClient {
|
||||
case METHOD_MODIFY_FAVORITES:
|
||||
return EhEngine.modifyFavorites(this, mOkHttpClient, (String) params[0], (long[]) params[1], (Integer) params[2], (Boolean) params[3]);
|
||||
case METHOD_GET_TORRENT_LIST:
|
||||
return EhEngine.getTorrentList(this, mOkHttpClient, (String) params[0]);
|
||||
case METHOD_GET_WHATS_HOT:
|
||||
return EhEngine.getWhatsHot(this, mOkHttpClient);
|
||||
return EhEngine.getTorrentList(this, mOkHttpClient, (String) params[0], (Long) params[1], (String) params[2]);
|
||||
case METHOD_GET_PROFILE:
|
||||
return EhEngine.getProfile(this, mOkHttpClient);
|
||||
case METHOD_VOTE_COMMENT:
|
||||
@@ -187,13 +168,14 @@ public class EhClient {
|
||||
case METHOD_IMAGE_SEARCH:
|
||||
return EhEngine.imageSearch(this, mOkHttpClient, (File) params[0], (Boolean) params[1], (Boolean) params[2], (Boolean) params[3]);
|
||||
case METHOD_ARCHIVE_LIST:
|
||||
return EhEngine.getArchiveList(this, mOkHttpClient, (String) params[0]);
|
||||
return EhEngine.getArchiveList(this, mOkHttpClient, (String) params[0], (Long) params[1], (String) params[2]);
|
||||
case METHOD_DOWNLOAD_ARCHIVE:
|
||||
return EhEngine.downloadArchive(this, mOkHttpClient, (Long) params[0], (String) params[1], (String) params[2], (String) params[3]);
|
||||
default:
|
||||
return new IllegalStateException("Can't detect method " + mMethod);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,6 +289,7 @@ public class EhConfig implements Cloneable {
|
||||
public static final int ASIAN_PORN = 0x80;
|
||||
public static final int NON_H = 0x100;
|
||||
public static final int WESTERN = 0x200;
|
||||
public static final int ALL_CATEGORY = 0x3ff;
|
||||
|
||||
public static final int NAMESPACES_RECLASS = 0x1;
|
||||
public static final int NAMESPACES_LANGUAGE = 0x2;
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.util.List;
|
||||
|
||||
import okhttp3.Cookie;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Request;
|
||||
|
||||
public class EhCookieStore extends CookieRepository {
|
||||
|
||||
@@ -86,41 +85,26 @@ public class EhCookieStore extends CookieRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Cookie> loadForRequest(HttpUrl url, Request request) {
|
||||
List<Cookie> cookies = super.loadForRequest(url, request);
|
||||
Object tag = request.tag();
|
||||
public List<Cookie> loadForRequest(HttpUrl url) {
|
||||
List<Cookie> cookies = super.loadForRequest(url);
|
||||
|
||||
boolean checkTips = domainMatch(url, EhUrl.DOMAIN_E);
|
||||
boolean checkUconfig = (domainMatch(url, EhUrl.DOMAIN_E) || domainMatch(url, EhUrl.DOMAIN_EX)) && tag instanceof EhConfig;
|
||||
|
||||
if (checkTips || checkUconfig) {
|
||||
if (checkTips) {
|
||||
List<Cookie> result = new ArrayList<>(cookies.size() + 1);
|
||||
// Add all but skip some
|
||||
for (Cookie cookie: cookies) {
|
||||
String name = cookie.name();
|
||||
if (checkTips && EhConfig.KEY_CONTENT_WARNING.equals(name)) {
|
||||
if (EhConfig.KEY_CONTENT_WARNING.equals(name)) {
|
||||
continue;
|
||||
}
|
||||
if (checkUconfig && EhConfig.KEY_UCONFIG.equals(name)) {
|
||||
if (EhConfig.KEY_UCONFIG.equals(name)) {
|
||||
continue;
|
||||
}
|
||||
result.add(cookie);
|
||||
}
|
||||
// Add some
|
||||
if (checkTips) {
|
||||
result.add(sTipsCookie);
|
||||
}
|
||||
if (checkUconfig) {
|
||||
EhConfig ehConfig = (EhConfig) tag;
|
||||
Cookie uconfigCookie = new Cookie.Builder()
|
||||
.name(EhConfig.KEY_UCONFIG)
|
||||
.value(ehConfig.uconfig())
|
||||
.domain(url.host())
|
||||
.path("/")
|
||||
.expiresAt(Long.MAX_VALUE)
|
||||
.build();
|
||||
result.add(uconfigCookie);
|
||||
}
|
||||
result.add(sTipsCookie);
|
||||
return Collections.unmodifiableList(result);
|
||||
} else {
|
||||
return cookies;
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer.client;
|
||||
|
||||
/*
|
||||
* Created by Hippo on 2018/3/23.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.Hosts;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import okhttp3.Dns;
|
||||
|
||||
public class EhDns implements Dns {
|
||||
|
||||
private static final Map<String, InetAddress> builtInHosts;
|
||||
|
||||
static {
|
||||
Map<String, InetAddress> map = new HashMap<>();
|
||||
put(map, "e-hentai.org", "104.20.26.25");
|
||||
put(map, "repo.e-hentai.org", "94.100.29.73");
|
||||
put(map, "forums.e-hentai.org", "94.100.18.243");
|
||||
put(map, "ehgt.org", "81.171.14.118");
|
||||
put(map, "ul.ehgt.org", "94.100.24.82");
|
||||
put(map, "github.com", "192.30.255.112");
|
||||
put(map, "raw.githubusercontent.com", "151.101.0.133");
|
||||
builtInHosts = map;
|
||||
}
|
||||
|
||||
private static void put(Map<String, InetAddress> map, String host, String ip) {
|
||||
InetAddress address = Hosts.toInetAddress(host, ip);
|
||||
if (address != null) {
|
||||
map.put(host, address);
|
||||
}
|
||||
}
|
||||
|
||||
private final Hosts hosts;
|
||||
|
||||
public EhDns(Context context) {
|
||||
hosts = EhApplication.getHosts(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InetAddress> lookup(String hostname) throws UnknownHostException {
|
||||
if (hostname == null) throw new UnknownHostException("hostname == null");
|
||||
|
||||
InetAddress inetAddress = hosts.get(hostname);
|
||||
if (inetAddress != null) {
|
||||
return Collections.singletonList(inetAddress);
|
||||
}
|
||||
|
||||
if (Settings.getBuiltInHosts()) {
|
||||
inetAddress = builtInHosts.get(hostname);
|
||||
if (inetAddress != null) {
|
||||
return Collections.singletonList(inetAddress);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return Arrays.asList(InetAddress.getAllByName(hostname));
|
||||
} catch (NullPointerException e) {
|
||||
UnknownHostException unknownHostException =
|
||||
new UnknownHostException("Broken system behaviour for dns lookup of " + hostname);
|
||||
unknownHostException.initCause(e);
|
||||
throw unknownHostException;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,16 +16,15 @@
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.GetText;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.data.GalleryComment;
|
||||
import com.hippo.ehviewer.client.data.GalleryCommentList;
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.data.PreviewSet;
|
||||
@@ -39,6 +38,7 @@ import com.hippo.ehviewer.client.parser.ForumsParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryApiParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryDetailParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryListParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryPageApiParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryPageParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryTokenApiParser;
|
||||
import com.hippo.ehviewer.client.parser.ProfileParser;
|
||||
@@ -46,22 +46,14 @@ import com.hippo.ehviewer.client.parser.RateGalleryParser;
|
||||
import com.hippo.ehviewer.client.parser.SignInParser;
|
||||
import com.hippo.ehviewer.client.parser.TorrentParser;
|
||||
import com.hippo.ehviewer.client.parser.VoteCommentParser;
|
||||
import com.hippo.ehviewer.client.parser.WhatsHotParser;
|
||||
import com.hippo.network.StatusCodeException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.Headers;
|
||||
@@ -71,6 +63,11 @@ import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
public class EhEngine {
|
||||
|
||||
@@ -80,6 +77,8 @@ public class EhEngine {
|
||||
private static final String SAD_PANDA_TYPE = "image/gif";
|
||||
private static final String SAD_PANDA_LENGTH = "9615";
|
||||
|
||||
private static final String KOKOMADE_URL = "https://exhentai.org/img/kokomade.jpg";
|
||||
|
||||
public static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
|
||||
private static final MediaType MEDIA_TYPE_JPEG = MediaType.parse("image/jpeg");
|
||||
|
||||
@@ -91,8 +90,8 @@ public class EhEngine {
|
||||
sEhFilter = EhFilter.getInstance();
|
||||
}
|
||||
|
||||
private static void throwException(Call call, int code, @Nullable Headers headers,
|
||||
@Nullable String body, Exception e) throws Exception {
|
||||
private static void doThrowException(Call call, int code, @Nullable Headers headers,
|
||||
@Nullable String body, Throwable e) throws Throwable {
|
||||
if (call.isCanceled()) {
|
||||
throw new CancelledException();
|
||||
}
|
||||
@@ -104,9 +103,16 @@ public class EhEngine {
|
||||
throw new EhException("Sad Panda");
|
||||
}
|
||||
|
||||
// Check kokomade
|
||||
if (body != null && body.contains(KOKOMADE_URL)) {
|
||||
throw new EhException("今回はここまで\n\n" + GetText.getString(R.string.kokomade_tip));
|
||||
}
|
||||
|
||||
if (e instanceof ParseException) {
|
||||
if (body != null && !body.contains("<")){
|
||||
if (body != null && !body.contains("<")) {
|
||||
throw new EhException(body);
|
||||
} else if (TextUtils.isEmpty(body)) {
|
||||
throw new EhException(GetText.getString(R.string.error_empty_html));
|
||||
} else {
|
||||
if (Settings.getSaveParseErrorBody()) {
|
||||
AppConfig.saveParseErrorBody((ParseException) e);
|
||||
@@ -118,23 +124,35 @@ public class EhEngine {
|
||||
if (code >= 400) {
|
||||
throw new StatusCodeException(code);
|
||||
}
|
||||
|
||||
if (e != null) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private static void throwException(Call call, int code, @Nullable Headers headers,
|
||||
@Nullable String body, Throwable e) throws Throwable {
|
||||
try {
|
||||
doThrowException(call, code, headers, body, e);
|
||||
} catch (Throwable error) {
|
||||
error.printStackTrace();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
public static String signIn(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String username, String password, String recaptchaChallenge, String recaptchaResponse) throws Exception {
|
||||
String username, String password) throws Throwable {
|
||||
FormBody.Builder builder = new FormBody.Builder()
|
||||
.add("UserName", username)
|
||||
.add("PassWord", password)
|
||||
.add("submit", "Log me in")
|
||||
.add("CookieDate", "1")
|
||||
.add("temporary_https", "off");
|
||||
if (!TextUtils.isEmpty(recaptchaChallenge) && !TextUtils.isEmpty(recaptchaResponse)) {
|
||||
builder.add("recaptcha_challenge_field", recaptchaChallenge);
|
||||
builder.add("recaptcha_response_field", recaptchaResponse);
|
||||
}
|
||||
String url = EhUrl.API_SIGN_IN;
|
||||
String referer = "https://forums.e-hentai.org/index.php?act=Login&CODE=00";
|
||||
String origin = "https://forums.e-hentai.org";
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
Request request = new EhRequestBuilder(url, referer, origin)
|
||||
.post(builder.build())
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -153,16 +171,71 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return SignInParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private static void fillGalleryList(@Nullable EhClient.Task task, OkHttpClient okHttpClient, List<GalleryInfo> list, String url, boolean filter) throws Throwable {
|
||||
// Filter title and uploader
|
||||
if (filter) {
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
GalleryInfo info = list.get(i);
|
||||
if (!sEhFilter.filterTitle(info) || !sEhFilter.filterUploader(info)) {
|
||||
list.remove(i);
|
||||
i--;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean hasTags = false;
|
||||
boolean hasPages = false;
|
||||
boolean hasRated = false;
|
||||
for (GalleryInfo gi : list) {
|
||||
if (gi.simpleTags != null) {
|
||||
hasTags = true;
|
||||
}
|
||||
if (gi.pages != 0) {
|
||||
hasPages = true;
|
||||
}
|
||||
if (gi.rated) {
|
||||
hasRated = true;
|
||||
}
|
||||
}
|
||||
|
||||
boolean needApi = (filter && sEhFilter.needTags() && !hasTags) ||
|
||||
(Settings.getShowGalleryPages() && !hasPages) ||
|
||||
hasRated;
|
||||
if (needApi) {
|
||||
fillGalleryListByApi(task, okHttpClient, list, url);
|
||||
}
|
||||
|
||||
// Filter tag
|
||||
if (filter) {
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
GalleryInfo info = list.get(i);
|
||||
// Thumbnail mode need filter uploader again
|
||||
if (!sEhFilter.filterUploader(info) || !sEhFilter.filterTag(info) || !sEhFilter.filterTagNamespace(info)) {
|
||||
list.remove(i);
|
||||
i--;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (GalleryInfo info : list) {
|
||||
info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb);
|
||||
}
|
||||
}
|
||||
|
||||
public static GalleryListParser.Result getGalleryList(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url) throws Exception {
|
||||
String url) throws Throwable {
|
||||
String referer = EhUrl.getReferer();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, referer).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
@@ -180,54 +253,27 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = GalleryListParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Filter title and uploader
|
||||
List<GalleryInfo> list = result.galleryInfoList;
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
GalleryInfo info = list.get(i);
|
||||
if (!sEhFilter.filterTitle(info) || !sEhFilter.filterUploader(info)) {
|
||||
list.remove(i);
|
||||
i--;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
|
||||
if (list.size() > 0 && (Settings.getShowJpnTitle() || sEhFilter.needCallApi())) {
|
||||
// Fill by api
|
||||
fillGalleryListByApi(task, okHttpClient, list);
|
||||
|
||||
// Filter tag
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
GalleryInfo info = list.get(i);
|
||||
if (!sEhFilter.filterTag(info) || !sEhFilter.filterTagNamespace(info)) {
|
||||
list.remove(i);
|
||||
i--;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (GalleryInfo info : list) {
|
||||
info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb);
|
||||
}
|
||||
fillGalleryList(task, okHttpClient, result.galleryInfoList, url, true);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// At least, GalleryInfo contain valid gid and token
|
||||
public static List<GalleryInfo> fillGalleryListByApi(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
List<GalleryInfo> galleryInfoList) throws Exception {
|
||||
List<GalleryInfo> galleryInfoList, String referer) throws Throwable {
|
||||
// We can only request 25 items one time at most
|
||||
final int MAX_REQUEST_SIZE = 25;
|
||||
List<GalleryInfo> requestItems = new ArrayList<>(MAX_REQUEST_SIZE);
|
||||
for (int i = 0, size = galleryInfoList.size(); i < size; i++) {
|
||||
requestItems.add(galleryInfoList.get(i));
|
||||
if (requestItems.size() == MAX_REQUEST_SIZE || i == size - 1) {
|
||||
doFillGalleryListByApi(task, okHttpClient, requestItems);
|
||||
doFillGalleryListByApi(task, okHttpClient, requestItems, referer);
|
||||
requestItems.clear();
|
||||
}
|
||||
}
|
||||
@@ -235,7 +281,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
private static void doFillGalleryListByApi(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
List<GalleryInfo> galleryInfoList) throws Exception {
|
||||
List<GalleryInfo> galleryInfoList, String referer) throws Throwable {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("method", "gdata");
|
||||
JSONArray ja = new JSONArray();
|
||||
@@ -249,8 +295,9 @@ public class EhEngine {
|
||||
json.put("gidlist", ja);
|
||||
json.put("namespace", 1);
|
||||
String url = EhUrl.getApiUrl();
|
||||
String origin = EhUrl.getOrigin();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url)
|
||||
Request request = new EhRequestBuilder(url, referer, origin)
|
||||
.post(RequestBody.create(MEDIA_TYPE_JSON, json.toString()))
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -269,16 +316,18 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
GalleryApiParser.parse(body, galleryInfoList);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static GalleryDetail getGalleryDetail(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url) throws Exception {
|
||||
String url) throws Throwable {
|
||||
String referer = EhUrl.getReferer();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, referer).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
@@ -295,7 +344,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return GalleryDetailParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -303,9 +353,10 @@ public class EhEngine {
|
||||
|
||||
|
||||
public static Pair<PreviewSet, Integer> getPreviewSet(
|
||||
@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url) throws Exception {
|
||||
@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url) throws Throwable {
|
||||
String referer = EhUrl.getReferer();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, referer).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
@@ -323,7 +374,8 @@ public class EhEngine {
|
||||
body = response.body().string();
|
||||
return Pair.create(GalleryDetailParser.parsePreviewSet(body),
|
||||
GalleryDetailParser.parsePreviewPages(body));
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -331,7 +383,7 @@ public class EhEngine {
|
||||
|
||||
public static RateGalleryParser.Result rateGallery(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, long apiUid, String apiKey, long gid,
|
||||
String token, float rating) throws Exception {
|
||||
String token, float rating) throws Throwable {
|
||||
final JSONObject json = new JSONObject();
|
||||
json.put("method", "rategallery");
|
||||
json.put("apiuid", apiUid);
|
||||
@@ -341,8 +393,10 @@ public class EhEngine {
|
||||
json.put("rating", (int) Math.ceil(rating * 2));
|
||||
final RequestBody requestBody = RequestBody.create(MEDIA_TYPE_JSON, json.toString());
|
||||
String url = EhUrl.getApiUrl();
|
||||
String referer = EhUrl.getGalleryDetailUrl(gid, token);
|
||||
String origin = EhUrl.getOrigin();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
Request request = new EhRequestBuilder(url, referer, origin)
|
||||
.post(requestBody)
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -361,19 +415,25 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return RateGalleryParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static GalleryComment[] commentGallery(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, String url, String comment) throws Exception {
|
||||
FormBody.Builder builder = new FormBody.Builder()
|
||||
.add("commenttext", comment)
|
||||
.add("postcomment", "Post New");
|
||||
public static GalleryCommentList commentGallery(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, String url, String comment, String id) throws Throwable {
|
||||
FormBody.Builder builder = new FormBody.Builder();
|
||||
if (id == null) {
|
||||
builder.add("commenttext_new", comment);
|
||||
} else {
|
||||
builder.add("commenttext_edit", comment);
|
||||
builder.add("edit_comment", id);
|
||||
}
|
||||
String origin = EhUrl.getOrigin();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
Request request = new EhRequestBuilder(url, url, origin)
|
||||
.post(builder.build())
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -392,23 +452,32 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
Document document = Jsoup.parse(body);
|
||||
|
||||
Elements elements = document.select("#chd + p");
|
||||
if (elements.size() > 0) {
|
||||
throw new EhException(elements.get(0).text());
|
||||
}
|
||||
|
||||
return GalleryDetailParser.parseComments(document);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getGalleryToken(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long gid, String gtoken, int page) throws Exception {
|
||||
long gid, String gtoken, int page) throws Throwable {
|
||||
JSONObject json = new JSONObject()
|
||||
.put("method", "gtoken")
|
||||
.put("pagelist", new JSONArray().put(
|
||||
new JSONArray().put(gid).put(gtoken).put(page + 1)));
|
||||
final RequestBody requestBody = RequestBody.create(MEDIA_TYPE_JSON, json.toString());
|
||||
String url = EhUrl.getApiUrl();
|
||||
String referer = EhUrl.getReferer();
|
||||
String origin = EhUrl.getOrigin();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
Request request = new EhRequestBuilder(url, referer, origin)
|
||||
.post(requestBody)
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -427,16 +496,18 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return GalleryTokenApiParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static FavoritesParser.Result getFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url, boolean callApi) throws Exception {
|
||||
String url, boolean callApi) throws Throwable {
|
||||
String referer = EhUrl.getReferer();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, referer).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
@@ -454,18 +525,13 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = FavoritesParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (callApi && result.galleryInfoList.size() > 0) {
|
||||
fillGalleryListByApi(task, okHttpClient, result.galleryInfoList);
|
||||
}
|
||||
|
||||
for (GalleryInfo info : result.galleryInfoList) {
|
||||
info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb);
|
||||
}
|
||||
fillGalleryList(task, okHttpClient, result.galleryInfoList, url, false);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -475,7 +541,7 @@ public class EhEngine {
|
||||
* @param note max 250 characters
|
||||
*/
|
||||
public static Void addFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long gid, String token, int dstCat, String note) throws Exception {
|
||||
long gid, String token, int dstCat, String note) throws Throwable {
|
||||
String catStr;
|
||||
if (dstCat == -1) {
|
||||
catStr = "favdel";
|
||||
@@ -491,8 +557,9 @@ public class EhEngine {
|
||||
builder.add("submit", "Apply Changes");
|
||||
builder.add("update", "1");
|
||||
String url = EhUrl.getAddFavorites(gid, token);
|
||||
String origin = EhUrl.getOrigin();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
Request request = new EhRequestBuilder(url, url, origin)
|
||||
.post(builder.build())
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -511,7 +578,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
throwException(call, code, headers, body, null);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -520,8 +588,8 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static Void addFavoritesRange(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long[] gidArray, String[] tokenArray, int dstCat) throws Exception {
|
||||
Assert.assertEquals(gidArray.length, tokenArray.length);
|
||||
long[] gidArray, String[] tokenArray, int dstCat) throws Throwable {
|
||||
AssertUtils.assertEquals(gidArray.length, tokenArray.length);
|
||||
for (int i = 0, n = gidArray.length; i < n; i++) {
|
||||
addFavorites(task, okHttpClient, gidArray[i], tokenArray[i], dstCat, null);
|
||||
}
|
||||
@@ -529,7 +597,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static FavoritesParser.Result modifyFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url, long[] gidArray, int dstCat, boolean callApi) throws Exception {
|
||||
String url, long[] gidArray, int dstCat, boolean callApi) throws Throwable {
|
||||
String catStr;
|
||||
if (dstCat == -1) {
|
||||
catStr = "delete";
|
||||
@@ -544,8 +612,9 @@ public class EhEngine {
|
||||
builder.add("modifygids[]", Long.toString(gid));
|
||||
}
|
||||
builder.add("apply", "Apply");
|
||||
String origin = EhUrl.getOrigin();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
Request request = new EhRequestBuilder(url, url, origin)
|
||||
.post(builder.build())
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -565,26 +634,22 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = FavoritesParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (callApi && result.galleryInfoList.size() > 0) {
|
||||
fillGalleryListByApi(task, okHttpClient, result.galleryInfoList);
|
||||
}
|
||||
|
||||
for (GalleryInfo info : result.galleryInfoList) {
|
||||
info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb);
|
||||
}
|
||||
fillGalleryList(task, okHttpClient, result.galleryInfoList, url, false);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Pair<String, String>[] getTorrentList(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url) throws Exception {
|
||||
String url, long gid, String token) throws Throwable {
|
||||
String referer = EhUrl.getGalleryDetailUrl(gid, token);
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, referer).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
@@ -602,7 +667,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = TorrentParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -611,9 +677,10 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static Pair<String, Pair<String, String>[]> getArchiveList(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url) throws Exception {
|
||||
String url, long gid, String token) throws Throwable {
|
||||
String referer = EhUrl.getGalleryDetailUrl(gid, token);
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, referer).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
@@ -631,7 +698,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = ArchiveParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -640,7 +708,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static Void downloadArchive(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long gid, String token, String or, String res) throws Exception {
|
||||
long gid, String token, String or, String res) throws Throwable {
|
||||
if (or == null || or.length() == 0) {
|
||||
throw new EhException("Invalid form param or: " + or);
|
||||
}
|
||||
@@ -650,8 +718,10 @@ public class EhEngine {
|
||||
FormBody.Builder builder = new FormBody.Builder();
|
||||
builder.add("hathdl_xres", res);
|
||||
String url = EhUrl.getDownloadArchive(gid, token, or);
|
||||
String referer = EhUrl.getGalleryDetailUrl(gid, token);
|
||||
String origin = EhUrl.getOrigin();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
Request request = new EhRequestBuilder(url, referer, origin)
|
||||
.post(builder.build())
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -670,7 +740,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
throwException(call, code, headers, body, null);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -683,49 +754,10 @@ public class EhEngine {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<GalleryInfo> getWhatsHot(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient) throws Exception {
|
||||
String url = EhUrl.HOST_E;
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
List<GalleryInfo> list;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
list = WhatsHotParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (list.size() > 0) {
|
||||
// Fill by api
|
||||
fillGalleryListByApi(task, okHttpClient, list);
|
||||
}
|
||||
|
||||
for (GalleryInfo info : list) {
|
||||
info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static ProfileParser.Result getProfileInternal(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, String url) throws Exception {
|
||||
OkHttpClient okHttpClient, String url, String referer) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, referer).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
@@ -742,17 +774,18 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return ProfileParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static ProfileParser.Result getProfile(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient) throws Exception {
|
||||
OkHttpClient okHttpClient) throws Throwable {
|
||||
String url = EhUrl.URL_FORUMS;
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, null).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
@@ -768,15 +801,16 @@ public class EhEngine {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return getProfileInternal(task, okHttpClient, ForumsParser.parse(body));
|
||||
} catch (Exception e) {
|
||||
return getProfileInternal(task, okHttpClient, ForumsParser.parse(body), url);
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static VoteCommentParser.Result voteComment(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long apiUid, String apiKey, long gid, String token, long commentId, int commentVote) throws Exception {
|
||||
long apiUid, String apiKey, long gid, String token, long commentId, int commentVote) throws Throwable {
|
||||
final JSONObject json = new JSONObject();
|
||||
json.put("method", "votecomment");
|
||||
json.put("apiuid", apiUid);
|
||||
@@ -787,8 +821,10 @@ public class EhEngine {
|
||||
json.put("comment_vote", commentVote);
|
||||
final RequestBody requestBody = RequestBody.create(MEDIA_TYPE_JSON, json.toString());
|
||||
String url = EhUrl.getApiUrl();
|
||||
String referer = EhUrl.getReferer();
|
||||
String origin = EhUrl.getOrigin();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
Request request = new EhRequestBuilder(url, referer, origin)
|
||||
.post(requestBody)
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -807,7 +843,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return VoteCommentParser.parse(body, commentVote);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -817,7 +854,7 @@ public class EhEngine {
|
||||
* @param image Must be jpeg
|
||||
*/
|
||||
public static GalleryListParser.Result imageSearch(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
File image, boolean uss, boolean osc, boolean se) throws Exception {
|
||||
File image, boolean uss, boolean osc, boolean se) throws Throwable {
|
||||
MultipartBody.Builder builder = new MultipartBody.Builder();
|
||||
builder.setType(MultipartBody.FORM);
|
||||
builder.addPart(
|
||||
@@ -847,8 +884,10 @@ public class EhEngine {
|
||||
RequestBody.create(null, "File Search")
|
||||
);
|
||||
String url = EhUrl.getImageSearchUrl();
|
||||
String referer = EhUrl.getReferer();
|
||||
String origin = EhUrl.getOrigin();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
Request request = new EhRequestBuilder(url, referer, origin)
|
||||
.post(builder.build())
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -871,48 +910,22 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = GalleryListParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Filter title and uploader
|
||||
List<GalleryInfo> list = result.galleryInfoList;
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
GalleryInfo info = list.get(i);
|
||||
if (!sEhFilter.filterTitle(info) || !sEhFilter.filterUploader(info)) {
|
||||
list.remove(i);
|
||||
i--;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
|
||||
if (list.size() > 0 && (Settings.getShowJpnTitle() || sEhFilter.needCallApi())) {
|
||||
// Fill by api
|
||||
fillGalleryListByApi(task, okHttpClient, list);
|
||||
|
||||
// Filter tag
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
GalleryInfo info = list.get(i);
|
||||
if (!sEhFilter.filterTag(info) || !sEhFilter.filterTagNamespace(info)) {
|
||||
list.remove(i);
|
||||
i--;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (GalleryInfo info : list) {
|
||||
info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb);
|
||||
}
|
||||
fillGalleryList(task, okHttpClient, result.galleryInfoList, url, true);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static GalleryPageParser.Result getGalleryPage(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, String url) throws Exception {
|
||||
OkHttpClient okHttpClient, String url, long gid, String token) throws Throwable {
|
||||
String referer = EhUrl.getGalleryDetailUrl(gid, token);
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, referer).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
@@ -929,7 +942,50 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return GalleryPageParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static GalleryPageApiParser.Result getGalleryPageApi(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, long gid, int index, String pToken, String showKey, String previousPToken) throws Throwable {
|
||||
final JSONObject json = new JSONObject();
|
||||
json.put("method", "showpage");
|
||||
json.put("gid", gid);
|
||||
json.put("page", index + 1);
|
||||
json.put("imgkey", pToken);
|
||||
json.put("showkey", showKey);
|
||||
final RequestBody requestBody = RequestBody.create(MEDIA_TYPE_JSON, json.toString());
|
||||
String url = EhUrl.getApiUrl();
|
||||
String referer = null;
|
||||
if (index > 0 && previousPToken != null) {
|
||||
referer = EhUrl.getPageUrl(gid, index - 1, previousPToken);
|
||||
}
|
||||
String origin = EhUrl.getOrigin();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, referer, origin)
|
||||
.post(requestBody)
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return GalleryPageApiParser.parse(body);
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public final class EhFilter {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized boolean needCallApi() {
|
||||
public synchronized boolean needTags() {
|
||||
return 0 != mTagFilterList.size() || 0 != mTagNamespaceFilterList.size();
|
||||
}
|
||||
|
||||
@@ -157,9 +157,8 @@ public final class EhFilter {
|
||||
String title = info.title;
|
||||
List<Filter> filters = mTitleFilterList;
|
||||
if (null != title && filters.size() > 0) {
|
||||
title = title.toLowerCase();
|
||||
for (int i = 0, n = filters.size(); i < n; i++) {
|
||||
if (filters.get(i).enable && title.contains(filters.get(i).text)) {
|
||||
if (filters.get(i).enable && title.toLowerCase().contains(filters.get(i).text)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,19 +16,21 @@
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.okhttp.ChromeRequestBuilder;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
public class EhRequestBuilder extends ChromeRequestBuilder {
|
||||
|
||||
public EhRequestBuilder(String url) throws MalformedURLException {
|
||||
this(url, Settings.getEhConfig());
|
||||
public EhRequestBuilder(String url, String referer) {
|
||||
this(url, referer, null);
|
||||
}
|
||||
|
||||
public EhRequestBuilder(String url, EhConfig ehConfig) throws MalformedURLException {
|
||||
public EhRequestBuilder(String url, String referer, String origin) {
|
||||
super(url);
|
||||
tag(ehConfig);
|
||||
if (referer != null) {
|
||||
addHeader("Referer", referer);
|
||||
}
|
||||
if (origin != null) {
|
||||
addHeader("Origin", origin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,357 @@
|
||||
/*
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer.client;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Base64;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.IoThreadPoolExecutor;
|
||||
import com.hippo.util.TextUrl;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okio.BufferedSource;
|
||||
import okio.Okio;
|
||||
|
||||
public class EhTagDatabase {
|
||||
|
||||
private final String name;
|
||||
private final byte[] tags;
|
||||
|
||||
public EhTagDatabase(String name, BufferedSource source) throws IOException {
|
||||
this.name = name;
|
||||
int totalBytes = source.readInt();
|
||||
tags = new byte[totalBytes];
|
||||
source.readFully(tags);
|
||||
}
|
||||
|
||||
public String getTranslation(String tag) {
|
||||
return search(tags, tag.getBytes(TextUrl.UTF_8));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String search(byte[] tags, byte[] tag) {
|
||||
int low = 0;
|
||||
int high = tags.length;
|
||||
while (low < high) {
|
||||
int start = (low + high) / 2;
|
||||
// Look for the starting '\n'
|
||||
while (start > -1 && tags[start] != '\n') {
|
||||
start--;
|
||||
}
|
||||
start++;
|
||||
|
||||
// Look for the middle '\r'.
|
||||
int middle = 1;
|
||||
while (tags[start + middle] != '\r') {
|
||||
middle++;
|
||||
}
|
||||
|
||||
// Look for the ending '\n'
|
||||
int end = middle + 1;
|
||||
while (tags[start + end] != '\n') {
|
||||
end++;
|
||||
}
|
||||
|
||||
int compare;
|
||||
int tagIndex = 0;
|
||||
int curIndex = start;
|
||||
|
||||
for (;;) {
|
||||
int tagByte = tag[tagIndex] & 0xff;
|
||||
int curByte = tags[curIndex] & 0xff;
|
||||
compare = tagByte - curByte;
|
||||
if (compare != 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
tagIndex++;
|
||||
curIndex++;
|
||||
if (tagIndex == tag.length && curIndex == start + middle) {
|
||||
break;
|
||||
}
|
||||
if (tagIndex == tag.length) {
|
||||
compare = -1;
|
||||
break;
|
||||
}
|
||||
if (curIndex == start + middle) {
|
||||
compare = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (compare < 0) {
|
||||
high = start - 1;
|
||||
} else if (compare > 0) {
|
||||
low = start + end + 1;
|
||||
} else {
|
||||
byte[] bytes = Base64.decode(tags, start + middle + 1, end - middle - 1, Base64.DEFAULT);
|
||||
return new String(bytes, TextUrl.UTF_8);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static final Map<String, String> NAMESPACE_TO_PREFIX = new HashMap<>();
|
||||
|
||||
static {
|
||||
NAMESPACE_TO_PREFIX.put("artist", "a:");
|
||||
NAMESPACE_TO_PREFIX.put("character", "c:");
|
||||
NAMESPACE_TO_PREFIX.put("female", "f:");
|
||||
NAMESPACE_TO_PREFIX.put("group", "g:");
|
||||
NAMESPACE_TO_PREFIX.put("language", "l:");
|
||||
NAMESPACE_TO_PREFIX.put("male", "m:");
|
||||
NAMESPACE_TO_PREFIX.put("misc", "");
|
||||
NAMESPACE_TO_PREFIX.put("parody", "p:");
|
||||
NAMESPACE_TO_PREFIX.put("reclass", "r:");
|
||||
}
|
||||
|
||||
private static volatile EhTagDatabase instance;
|
||||
// TODO more lock for different language
|
||||
private static Lock lock = new ReentrantLock();
|
||||
|
||||
@Nullable
|
||||
public static EhTagDatabase getInstance(Context context) {
|
||||
if (isPossible(context)) {
|
||||
return instance;
|
||||
} else {
|
||||
instance = null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String namespaceToPrefix(String namespace) {
|
||||
return NAMESPACE_TO_PREFIX.get(namespace);
|
||||
}
|
||||
|
||||
private static String[] getMetadata(Context context) {
|
||||
String[] metadata = context.getResources().getStringArray(R.array.tag_translation_metadata);
|
||||
if (metadata.length == 4) {
|
||||
return metadata;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPossible(Context context) {
|
||||
return getMetadata(context) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static byte[] getFileContent(File file, int length) {
|
||||
try (BufferedSource source = Okio.buffer(Okio.source(file))) {
|
||||
byte[] content = new byte[length];
|
||||
source.readFully(content);
|
||||
return content;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static byte[] getFileSha1(File file) {
|
||||
try (InputStream is = new FileInputStream(file)) {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
||||
int n;
|
||||
byte[] buffer = new byte[4 * 1024];
|
||||
while ((n = is.read(buffer)) != -1) {
|
||||
digest.update(buffer, 0, n);
|
||||
}
|
||||
return digest.digest();
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean equals(byte[] b1, byte[] b2) {
|
||||
if (b1 == null && b2 == null) {
|
||||
return true;
|
||||
}
|
||||
if (b1 == null || b2 == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (b1.length != b2.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < b1.length; i++) {
|
||||
if (b1[i] != b2[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean checkData(File sha1File, File dataFile) {
|
||||
byte[] s1 = getFileContent(sha1File, 20);
|
||||
if (s1 == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
byte[] s2 = getFileSha1(dataFile);
|
||||
if (s2 == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return equals(s1, s2);
|
||||
}
|
||||
|
||||
private static boolean save(OkHttpClient client, String url, File file) {
|
||||
Request request = new Request.Builder().url(url).build();
|
||||
Call call = client.newCall(request);
|
||||
try (Response response = call.execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return false;
|
||||
}
|
||||
ResponseBody body = response.body();
|
||||
if (body == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try (InputStream is = body.byteStream(); OutputStream os = new FileOutputStream(file)) {
|
||||
IOUtils.copy(is, os);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.throwIfFatal(t);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void update(Context context) {
|
||||
String[] urls = getMetadata(context);
|
||||
if (urls == null || urls.length != 4) {
|
||||
// Clear tags if it's not possible
|
||||
instance = null;
|
||||
return;
|
||||
}
|
||||
|
||||
String sha1Name = urls[0];
|
||||
String sha1Url = urls[1];
|
||||
String dataName = urls[2];
|
||||
String dataUrl = urls[3];
|
||||
|
||||
// Clear tags if name if different
|
||||
EhTagDatabase tmp = instance;
|
||||
if (tmp != null && !tmp.name.equals(dataName)) {
|
||||
instance = null;
|
||||
}
|
||||
|
||||
IoThreadPoolExecutor.getInstance().execute(() -> {
|
||||
if (!lock.tryLock()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
File dir = AppConfig.getFilesDir("tag-translations");
|
||||
if (dir == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check current sha1 and current data
|
||||
File sha1File = new File(dir, sha1Name);
|
||||
File dataFile = new File(dir, dataName);
|
||||
if (!checkData(sha1File, dataFile)) {
|
||||
FileUtils.delete(sha1File);
|
||||
FileUtils.delete(dataFile);
|
||||
}
|
||||
|
||||
// Read current EhTagDatabase
|
||||
if (instance == null && dataFile.exists()) {
|
||||
try (BufferedSource source = Okio.buffer(Okio.source(dataFile))) {
|
||||
instance = new EhTagDatabase(dataName, source);
|
||||
} catch (IOException e) {
|
||||
FileUtils.delete(sha1File);
|
||||
FileUtils.delete(dataFile);
|
||||
}
|
||||
}
|
||||
|
||||
OkHttpClient client = EhApplication.getOkHttpClient(EhApplication.getInstance());
|
||||
|
||||
// Save new sha1
|
||||
File tempSha1File = new File(dir, sha1Name + ".tmp");
|
||||
if (!save(client, sha1Url, tempSha1File)) {
|
||||
FileUtils.delete(tempSha1File);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check new sha1 and current data
|
||||
if (checkData(tempSha1File, dataFile)) {
|
||||
// The data is the same
|
||||
FileUtils.delete(tempSha1File);
|
||||
return;
|
||||
}
|
||||
|
||||
// Save new data
|
||||
File tempDataFile = new File(dir, dataName + ".tmp");
|
||||
if (!save(client, dataUrl, tempDataFile)) {
|
||||
FileUtils.delete(tempDataFile);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check new sha1 and new data
|
||||
if (!checkData(tempSha1File, tempDataFile)) {
|
||||
FileUtils.delete(tempSha1File);
|
||||
FileUtils.delete(tempDataFile);
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace current sha1 and current data with new sha1 and new data
|
||||
FileUtils.delete(sha1File);
|
||||
FileUtils.delete(dataFile);
|
||||
tempSha1File.renameTo(sha1File);
|
||||
tempDataFile.renameTo(dataFile);
|
||||
|
||||
// Read new EhTagDatabase
|
||||
try (BufferedSource source = Okio.buffer(Okio.source(dataFile))) {
|
||||
instance = new EhTagDatabase(dataName, source);
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -16,14 +16,11 @@
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.network.UrlBuilder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
public class EhUrl {
|
||||
@@ -43,6 +40,9 @@ public class EhUrl {
|
||||
public static final String API_E = HOST_E + "api.php";
|
||||
public static final String API_EX = HOST_EX + "api.php";
|
||||
|
||||
public static final String URL_POPULAR_E = "https://e-hentai.org/popular";
|
||||
public static final String URL_POPULAR_EX = "https://exhentai.org/popular";
|
||||
|
||||
public static final String URL_IMAGE_SEARCH_E = "https://upload.e-hentai.org/image_lookup.php";
|
||||
public static final String URL_IMAGE_SEARCH_EX = "https://exhentai.org/upload/image_lookup.php";
|
||||
|
||||
@@ -52,10 +52,22 @@ public class EhUrl {
|
||||
public static final String URL_FAVORITES_EX = HOST_EX + "favorites.php";
|
||||
public static final String URL_FORUMS = "https://forums.e-hentai.org/";
|
||||
|
||||
public static final String UCONFIG_E = HOST_E + "uconfig.php";
|
||||
public static final String UCONFIG_EX = HOST_EX + "uconfig.php";
|
||||
public static final String REFERER_EX = "https://" + DOMAIN_EX;
|
||||
public static final String REFERER_E = "https://" + DOMAIN_E;
|
||||
|
||||
private static final String URL_PREFIX_THUMB_E = "https://ehgt.org/t/";
|
||||
public static final String ORIGIN_EX = REFERER_EX;
|
||||
public static final String ORIGIN_E = REFERER_E;
|
||||
|
||||
public static final String URL_UCONFIG_E = HOST_E + "uconfig.php";
|
||||
public static final String URL_UCONFIG_EX = HOST_EX + "uconfig.php";
|
||||
|
||||
public static final String URL_MY_TAGS_E = HOST_E + "mytags";
|
||||
public static final String URL_MY_TAGS_EX = HOST_EX + "mytags";
|
||||
|
||||
public static final String URL_WATCHED_E = HOST_E + "watched";
|
||||
public static final String URL_WATCHED_EX = HOST_EX + "watched";
|
||||
|
||||
private static final String URL_PREFIX_THUMB_E = "https://ehgt.org/";
|
||||
private static final String URL_PREFIX_THUMB_EX = "https://exhentai.org/t/";
|
||||
|
||||
public static String getGalleryDetailUrl(long gid, String token) {
|
||||
@@ -92,13 +104,43 @@ public class EhUrl {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getReferer() {
|
||||
switch (Settings.getGallerySite()) {
|
||||
default:
|
||||
case SITE_E:
|
||||
return REFERER_E;
|
||||
case SITE_EX:
|
||||
return REFERER_EX;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getOrigin() {
|
||||
switch (Settings.getGallerySite()) {
|
||||
default:
|
||||
case SITE_E:
|
||||
return ORIGIN_E;
|
||||
case SITE_EX:
|
||||
return ORIGIN_EX;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getUConfigUrl() {
|
||||
switch (Settings.getGallerySite()) {
|
||||
default:
|
||||
case SITE_E:
|
||||
return UCONFIG_E;
|
||||
return URL_UCONFIG_E;
|
||||
case SITE_EX:
|
||||
return UCONFIG_EX;
|
||||
return URL_UCONFIG_EX;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getMyTagsUrl() {
|
||||
switch (Settings.getGallerySite()) {
|
||||
default:
|
||||
case SITE_E:
|
||||
return URL_MY_TAGS_E;
|
||||
case SITE_EX:
|
||||
return URL_MY_TAGS_EX;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +171,17 @@ public class EhUrl {
|
||||
return "https://ehwiki.org/wiki/" + tag.replace(' ', '_');
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String getPopularUrl() {
|
||||
switch (Settings.getGallerySite()) {
|
||||
default:
|
||||
case SITE_E:
|
||||
return URL_POPULAR_E;
|
||||
case SITE_EX:
|
||||
return URL_POPULAR_EX;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String getImageSearchUrl() {
|
||||
switch (Settings.getGallerySite()) {
|
||||
@@ -140,6 +193,17 @@ public class EhUrl {
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String getWatchedUrl() {
|
||||
switch (Settings.getGallerySite()) {
|
||||
default:
|
||||
case SITE_E:
|
||||
return URL_WATCHED_E;
|
||||
case SITE_EX:
|
||||
return URL_WATCHED_EX;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getThumbUrlPrefix() {
|
||||
switch (Settings.getGallerySite()) {
|
||||
default:
|
||||
|
||||
@@ -17,10 +17,9 @@
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.client.parser.GalleryDetailUrlParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryListUrlParser;
|
||||
|
||||
@@ -18,13 +18,11 @@ package com.hippo.ehviewer.client;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class EhUtils {
|
||||
@@ -72,9 +70,9 @@ public class EhUtils {
|
||||
new String[] { "misc" },
|
||||
new String[] { "doujinshi" },
|
||||
new String[] { "manga" },
|
||||
new String[] { "artistcg", "Artist CG Sets" },
|
||||
new String[] { "gamecg", "Game CG Sets" },
|
||||
new String[] { "imageset", "Image Sets" },
|
||||
new String[] { "artistcg", "Artist CG Sets", "Artist CG" },
|
||||
new String[] { "gamecg", "Game CG Sets", "Game CG" },
|
||||
new String[] { "imageset", "Image Sets", "Image Set" },
|
||||
new String[] { "cosplay" },
|
||||
new String[] { "asianporn", "Asian Porn" },
|
||||
new String[] { "non-h" },
|
||||
|
||||
@@ -69,11 +69,18 @@ public class FavListUrlBuilder implements Parcelable {
|
||||
UrlBuilder ub = new UrlBuilder(EhUrl.getFavoritesUrl());
|
||||
if (isValidFavCat(mFavCat)) {
|
||||
ub.addQuery("favcat", Integer.toString(mFavCat));
|
||||
} else if (mFavCat == FAV_CAT_ALL) {
|
||||
ub.addQuery("favcat", "all");
|
||||
}
|
||||
if (!TextUtils.isEmpty(mKeyword)) {
|
||||
try {
|
||||
ub.addQuery("f_search", URLEncoder.encode(mKeyword, "UTF-8"));
|
||||
ub.addQuery("f_apply", "Search+Favorites");
|
||||
// Name
|
||||
ub.addQuery("sn", "on");
|
||||
// Tags
|
||||
ub.addQuery("st", "on");
|
||||
// Note
|
||||
ub.addQuery("sf", "on");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Log.e(TAG, "Can't URLEncoder.encode " + mKeyword);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package com.hippo.ehviewer.client.data;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.Nullable;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class GalleryApiInfo implements Parcelable {
|
||||
|
||||
|
||||
@@ -24,12 +24,16 @@ public class GalleryComment implements Parcelable {
|
||||
// 0 for uploader comment. can't vote
|
||||
public long id;
|
||||
public int score;
|
||||
public boolean voteUp;
|
||||
public boolean voteDown;
|
||||
public boolean editable;
|
||||
public boolean voteUpAble;
|
||||
public boolean voteUpEd;
|
||||
public boolean voteDownAble;
|
||||
public boolean voteDownEd;
|
||||
public String voteState;
|
||||
public long time;
|
||||
public String user;
|
||||
public String comment;
|
||||
public long lastEdited;
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
@@ -40,12 +44,16 @@ public class GalleryComment implements Parcelable {
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeLong(this.id);
|
||||
dest.writeInt(this.score);
|
||||
dest.writeByte(voteUp ? (byte) 1 : (byte) 0);
|
||||
dest.writeByte(voteDown ? (byte) 1 : (byte) 0);
|
||||
dest.writeByte(editable ? (byte) 1 : (byte) 0);
|
||||
dest.writeByte(voteUpAble ? (byte) 1 : (byte) 0);
|
||||
dest.writeByte(voteUpEd ? (byte) 1 : (byte) 0);
|
||||
dest.writeByte(voteDownAble ? (byte) 1 : (byte) 0);
|
||||
dest.writeByte(voteDownEd ? (byte) 1 : (byte) 0);
|
||||
dest.writeString(this.voteState);
|
||||
dest.writeLong(this.time);
|
||||
dest.writeString(this.user);
|
||||
dest.writeString(this.comment);
|
||||
dest.writeLong(this.lastEdited);
|
||||
}
|
||||
|
||||
public GalleryComment() {
|
||||
@@ -54,12 +62,16 @@ public class GalleryComment implements Parcelable {
|
||||
protected GalleryComment(Parcel in) {
|
||||
this.id = in.readLong();
|
||||
this.score = in.readInt();
|
||||
this.voteUp = in.readByte() != 0;
|
||||
this.voteDown = in.readByte() != 0;
|
||||
this.editable = in.readByte() != 0;
|
||||
this.voteUpAble = in.readByte() != 0;
|
||||
this.voteUpEd = in.readByte() != 0;
|
||||
this.voteDownAble = in.readByte() != 0;
|
||||
this.voteDownEd = in.readByte() != 0;
|
||||
this.voteState = in.readString();
|
||||
this.time = in.readLong();
|
||||
this.user = in.readString();
|
||||
this.comment = in.readString();
|
||||
this.lastEdited = in.readLong();
|
||||
}
|
||||
|
||||
public static final Creator<GalleryComment> CREATOR = new Creator<GalleryComment>() {
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer.client.data;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GalleryCommentList implements Parcelable {
|
||||
|
||||
public GalleryComment[] comments;
|
||||
public boolean hasMore;
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeParcelableArray(comments, flags);
|
||||
dest.writeByte(hasMore ? (byte) 1 : (byte) 0);
|
||||
}
|
||||
|
||||
public GalleryCommentList(GalleryComment[] comments, boolean hasMore) {
|
||||
this.comments = comments;
|
||||
this.hasMore = hasMore;
|
||||
}
|
||||
|
||||
protected GalleryCommentList(Parcel in) {
|
||||
Parcelable[] array = in.readParcelableArray(getClass().getClassLoader());
|
||||
if (array != null) {
|
||||
comments = Arrays.copyOf(array, array.length, GalleryComment[].class);
|
||||
} else {
|
||||
comments = null;
|
||||
}
|
||||
hasMore = in.readByte() != 0;
|
||||
}
|
||||
|
||||
public static final Creator<GalleryCommentList> CREATOR = new Creator<GalleryCommentList>() {
|
||||
@Override
|
||||
public GalleryCommentList createFromParcel(Parcel in) {
|
||||
return new GalleryCommentList(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GalleryCommentList[] newArray(int size) {
|
||||
return new GalleryCommentList[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class GalleryDetail extends GalleryInfo {
|
||||
public boolean isFavorited;
|
||||
public int ratingCount;
|
||||
public GalleryTagGroup[] tags;
|
||||
public GalleryComment[] comments;
|
||||
public GalleryCommentList comments;
|
||||
public int previewPages;
|
||||
public PreviewSet previewSet;
|
||||
|
||||
@@ -60,8 +60,8 @@ public class GalleryDetail extends GalleryInfo {
|
||||
dest.writeInt(this.favoriteCount);
|
||||
dest.writeByte(isFavorited ? (byte) 1 : (byte) 0);
|
||||
dest.writeInt(this.ratingCount);
|
||||
dest.writeParcelableArray(this.tags, 0);
|
||||
dest.writeParcelableArray(this.comments, 0);
|
||||
dest.writeParcelableArray(this.tags, flags);
|
||||
dest.writeParcelable(this.comments, flags);
|
||||
dest.writeInt(this.previewPages);
|
||||
dest.writeParcelable(previewSet, flags);
|
||||
}
|
||||
@@ -88,12 +88,7 @@ public class GalleryDetail extends GalleryInfo {
|
||||
} else {
|
||||
this.tags = null;
|
||||
}
|
||||
array = in.readParcelableArray(GalleryComment.class.getClassLoader());
|
||||
if (array != null) {
|
||||
this.comments = Arrays.copyOf(array, array.length, GalleryComment[].class);
|
||||
} else {
|
||||
this.comments = null;
|
||||
}
|
||||
this.comments = in.readParcelable(getClass().getClassLoader());
|
||||
this.previewPages = in.readInt();
|
||||
this.previewSet = in.readParcelable(PreviewSet.class.getClassLoader());
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@ package com.hippo.ehviewer.client.data;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class GalleryInfo implements Parcelable {
|
||||
@@ -62,21 +61,38 @@ public class GalleryInfo implements Parcelable {
|
||||
};
|
||||
|
||||
public static final Pattern[] S_LANG_PATTERNS = {
|
||||
Pattern.compile("[(\\[]eng(?:lish)?[)\\]]", Pattern.CASE_INSENSITIVE),
|
||||
// [((\[]ch(?:inese)?[))\]]|[汉漢]化|中[国國][语語]|中文
|
||||
Pattern.compile("[(\uFF08\\[]ch(?:inese)?[)\uFF09\\]]|[汉漢]化|中[国國][语語]|中文", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]spanish[)\\]]|[(\\[]Español[)\\]]", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]korean?[)\\]]", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]rus(?:sian)?[)\\]]", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]fr(?:ench)?[)\\]]", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]portuguese", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]thai(?: ภาษาไทย)?[)\\]]|แปลไทย", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]german[)\\]]", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]italiano?[)\\]]", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]vietnamese(?: Tiếng Việt)?[)\\]]", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]polish[)\\]]", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]hun(?:garian)?[)\\]]", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]dutch[)\\]]", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]eng(?:lish)?[)\\]]|英訳", Pattern.CASE_INSENSITIVE),
|
||||
// [((\[]ch(?:inese)?[))\]]|[汉漢]化|中[国國][语語]|中文|中国翻訳
|
||||
Pattern.compile("[(\uFF08\\[]ch(?:inese)?[)\uFF09\\]]|[汉漢]化|中[国國][语語]|中文|中国翻訳", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]spanish[)\\]]|[(\\[]Español[)\\]]|スペイン翻訳", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]korean?[)\\]]|韓国翻訳", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]rus(?:sian)?[)\\]]|ロシア翻訳", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]fr(?:ench)?[)\\]]|フランス翻訳", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]portuguese|ポルトガル翻訳", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]thai(?: ภาษาไทย)?[)\\]]|แปลไทย|タイ翻訳", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]german[)\\]]|ドイツ翻訳", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]italiano?[)\\]]|イタリア翻訳", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]vietnamese(?: Tiếng Việt)?[)\\]]|ベトナム翻訳", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]polish[)\\]]|ポーランド翻訳", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]hun(?:garian)?[)\\]]|ハンガリー翻訳", Pattern.CASE_INSENSITIVE),
|
||||
Pattern.compile("[(\\[]dutch[)\\]]|オランダ翻訳", Pattern.CASE_INSENSITIVE),
|
||||
};
|
||||
|
||||
public static final String[] S_LANG_TAGS = {
|
||||
"language:english",
|
||||
"language:chinese",
|
||||
"language:spanish",
|
||||
"language:korean",
|
||||
"language:russian",
|
||||
"language:french",
|
||||
"language:portuguese",
|
||||
"language:thai",
|
||||
"language:german",
|
||||
"language:italian",
|
||||
"language:vietnamese",
|
||||
"language:polish",
|
||||
"language:hungarian",
|
||||
"language:dutch",
|
||||
};
|
||||
|
||||
public long gid ;
|
||||
@@ -88,8 +104,10 @@ public class GalleryInfo implements Parcelable {
|
||||
public String posted;
|
||||
public String uploader;
|
||||
public float rating;
|
||||
public boolean rated;
|
||||
@Nullable
|
||||
public String[] simpleTags;
|
||||
public int pages;
|
||||
|
||||
public int thumbWidth;
|
||||
public int thumbHeight;
|
||||
@@ -103,7 +121,30 @@ public class GalleryInfo implements Parcelable {
|
||||
*/
|
||||
public String simpleLanguage;
|
||||
|
||||
public int favoriteSlot = -2;
|
||||
public String favoriteName;
|
||||
|
||||
public final void generateSLang() {
|
||||
if (simpleTags != null) {
|
||||
generateSLangFromTags();
|
||||
}
|
||||
if (simpleLanguage == null && title != null) {
|
||||
generateSLangFromTitle();
|
||||
}
|
||||
}
|
||||
|
||||
private void generateSLangFromTags() {
|
||||
for (String tag : simpleTags) {
|
||||
for (int i = 0; i < S_LANGS.length; i++) {
|
||||
if (S_LANG_TAGS[i].equals(tag)) {
|
||||
simpleLanguage = S_LANGS[i];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void generateSLangFromTitle() {
|
||||
for (int i = 0; i < S_LANGS.length; i++) {
|
||||
if (S_LANG_PATTERNS[i].matcher(title).find()) {
|
||||
simpleLanguage = S_LANGS[i];
|
||||
@@ -129,6 +170,7 @@ public class GalleryInfo implements Parcelable {
|
||||
dest.writeString(this.posted);
|
||||
dest.writeString(this.uploader);
|
||||
dest.writeFloat(this.rating);
|
||||
dest.writeByte(this.rated ? (byte) 1 : (byte) 0);
|
||||
dest.writeString(this.simpleLanguage);
|
||||
dest.writeStringArray(this.simpleTags);
|
||||
dest.writeInt(this.thumbWidth);
|
||||
@@ -136,6 +178,8 @@ public class GalleryInfo implements Parcelable {
|
||||
dest.writeInt(this.spanSize);
|
||||
dest.writeInt(this.spanIndex);
|
||||
dest.writeInt(this.spanGroupIndex);
|
||||
dest.writeInt(this.favoriteSlot);
|
||||
dest.writeString(this.favoriteName);
|
||||
}
|
||||
|
||||
public GalleryInfo() {}
|
||||
@@ -150,6 +194,7 @@ public class GalleryInfo implements Parcelable {
|
||||
this.posted = in.readString();
|
||||
this.uploader = in.readString();
|
||||
this.rating = in.readFloat();
|
||||
this.rated = in.readByte() != 0;
|
||||
this.simpleLanguage = in.readString();
|
||||
this.simpleTags = in.createStringArray();
|
||||
this.thumbWidth = in.readInt();
|
||||
@@ -157,6 +202,8 @@ public class GalleryInfo implements Parcelable {
|
||||
this.spanSize = in.readInt();
|
||||
this.spanIndex = in.readInt();
|
||||
this.spanGroupIndex = in.readInt();
|
||||
this.favoriteSlot = in.readInt();
|
||||
this.favoriteName = in.readString();
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<GalleryInfo> CREATOR = new Parcelable.Creator<GalleryInfo>() {
|
||||
|
||||
@@ -18,18 +18,17 @@ package com.hippo.ehviewer.client.data;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.client.EhConfig;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.dao.QuickSearch;
|
||||
import com.hippo.ehviewer.widget.AdvanceSearchTable;
|
||||
import com.hippo.network.UrlBuilder;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -38,7 +37,7 @@ import java.net.URLEncoder;
|
||||
|
||||
public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
|
||||
@IntDef({MODE_NORMAL, MODE_UPLOADER, MODE_TAG, MODE_WHATS_HOT, MODE_IMAGE_SEARCH})
|
||||
@IntDef({MODE_NORMAL, MODE_UPLOADER, MODE_TAG, MODE_WHATS_HOT, MODE_IMAGE_SEARCH, MODE_SUBSCRIPTION})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
private @interface Mode {}
|
||||
|
||||
@@ -48,6 +47,7 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
public static final int MODE_TAG = 0x2;
|
||||
public static final int MODE_WHATS_HOT = 0x3;
|
||||
public static final int MODE_IMAGE_SEARCH = 0x4;
|
||||
public static final int MODE_SUBSCRIPTION = 0x5;
|
||||
|
||||
public static final int DEFAULT_ADVANCE = AdvanceSearchTable.SNAME | AdvanceSearchTable.STAGS;
|
||||
public static final int DEFAULT_MIN_RATING = 2;
|
||||
@@ -62,6 +62,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
|
||||
private int mAdvanceSearch = -1;
|
||||
private int mMinRating = -1;
|
||||
private int mPageFrom = -1;
|
||||
private int mPageTo = -1;
|
||||
|
||||
private String mImagePath;
|
||||
private boolean mUseSimilarityScan;
|
||||
@@ -78,6 +80,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
mKeyword = null;
|
||||
mAdvanceSearch = -1;
|
||||
mMinRating = -1;
|
||||
mPageFrom = -1;
|
||||
mPageTo = -1;
|
||||
mImagePath = null;
|
||||
mUseSimilarityScan = false;
|
||||
mOnlySearchCovers = false;
|
||||
@@ -142,6 +146,22 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
mMinRating = minRating;
|
||||
}
|
||||
|
||||
public int getPageFrom() {
|
||||
return mPageFrom;
|
||||
}
|
||||
|
||||
public void setPageFrom(int pageFrom) {
|
||||
mPageFrom = pageFrom;
|
||||
}
|
||||
|
||||
public int getPageTo() {
|
||||
return mPageTo;
|
||||
}
|
||||
|
||||
public void setPageTo(int pageTo) {
|
||||
mPageTo = pageTo;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getImagePath() {
|
||||
return mImagePath;
|
||||
@@ -186,6 +206,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
mKeyword = lub.mKeyword;
|
||||
mAdvanceSearch = lub.mAdvanceSearch;
|
||||
mMinRating = lub.mMinRating;
|
||||
mPageFrom = lub.mPageFrom;
|
||||
mPageTo = lub.mPageTo;
|
||||
mImagePath = lub.mImagePath;
|
||||
mUseSimilarityScan = lub.mUseSimilarityScan;
|
||||
mOnlySearchCovers = lub.mOnlySearchCovers;
|
||||
@@ -198,6 +220,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
mKeyword = q.keyword;
|
||||
mAdvanceSearch = q.advanceSearch;
|
||||
mMinRating = q.minRating;
|
||||
mPageFrom = q.pageFrom;
|
||||
mPageTo = q.pageTo;
|
||||
mImagePath = null;
|
||||
mUseSimilarityScan = false;
|
||||
mOnlySearchCovers = false;
|
||||
@@ -211,6 +235,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
q.keyword = mKeyword;
|
||||
q.advanceSearch = mAdvanceSearch;
|
||||
q.minRating = mMinRating;
|
||||
q.pageFrom = mPageFrom;
|
||||
q.pageTo = mPageTo;
|
||||
return q;
|
||||
}
|
||||
|
||||
@@ -234,6 +260,12 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
if (q.minRating != mMinRating) {
|
||||
return false;
|
||||
}
|
||||
if (q.pageFrom != mPageFrom) {
|
||||
return false;
|
||||
}
|
||||
if (q.pageTo != mPageTo) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -250,124 +282,166 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
}
|
||||
|
||||
String[] querys = StringUtils.split(query, '&');
|
||||
boolean apply = false;
|
||||
int category = 0;
|
||||
String keyword = null;
|
||||
boolean enableAdvanceSearch = false;
|
||||
int advanceSearch = 0;
|
||||
boolean enableMinRating = false;
|
||||
int minRating = 0;
|
||||
for (int i = 0, size = querys.length; i < size; i++) {
|
||||
String str = querys[i];
|
||||
int minRating = -1;
|
||||
boolean enablePage = false;
|
||||
int pageFrom = -1;
|
||||
int pageTo = -1;
|
||||
for (String str : querys) {
|
||||
int index = str.indexOf('=');
|
||||
if (index < 0) {
|
||||
continue;
|
||||
}
|
||||
String key = str.substring(0, index);
|
||||
String value = str.substring(index + 1);
|
||||
if ("f_doujinshi".equals(key)) {
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.DOUJINSHI;
|
||||
}
|
||||
} else if ("f_manga".equals(key)) {
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.MANGA;
|
||||
}
|
||||
} else if ("f_artistcg".equals(key)) {
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.ARTIST_CG;
|
||||
}
|
||||
} else if ("f_gamecg".equals(key)) {
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.GAME_CG;
|
||||
}
|
||||
} else if ("f_western".equals(key)) {
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.WESTERN;
|
||||
}
|
||||
} else if ("f_non-h".equals(key)) {
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.NON_H;
|
||||
}
|
||||
} else if ("f_imageset".equals(key)) {
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.IMAGE_SET;
|
||||
}
|
||||
} else if ("f_cosplay".equals(key)) {
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.COSPLAY;
|
||||
}
|
||||
} else if ("f_asianporn".equals(key)) {
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.ASIAN_PORN;
|
||||
}
|
||||
} else if ("f_misc".equals(key)) {
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.MISC;
|
||||
}
|
||||
} else if ("f_search".equals(key)) {
|
||||
try {
|
||||
keyword = URLDecoder.decode(value, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Ignore
|
||||
}
|
||||
} else if ("advsearch".equals(key)) {
|
||||
if ("1".equals(value)) {
|
||||
enableAdvanceSearch = true;
|
||||
}
|
||||
} else if ("f_sname".equals(key)) {
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.SNAME;
|
||||
}
|
||||
} else if ("f_stags".equals(key)) {
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.STAGS;
|
||||
}
|
||||
} else if ("f_sdesc".equals(key)) {
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.SDESC;
|
||||
}
|
||||
} else if ("f_storr".equals(key)) {
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.STORR;
|
||||
}
|
||||
} else if ("f_sto".equals(key)) {
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.STO;
|
||||
}
|
||||
} else if ("f_sdt1".equals(key)) {
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.SDT1;
|
||||
}
|
||||
} else if ("f_sdt2".equals(key)) {
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.SDT2;
|
||||
}
|
||||
} else if ("f_sh".equals(key)) {
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.SH;
|
||||
}
|
||||
} else if ("f_sr".equals(key)) {
|
||||
if ("on".equals(value)) {
|
||||
enableMinRating = true;
|
||||
}
|
||||
} else if ("f_srdd".equals(key)) {
|
||||
try {
|
||||
minRating = Integer.parseInt(value);
|
||||
} catch (NumberFormatException e) {
|
||||
// Ignore
|
||||
}
|
||||
} else if ("f_apply".equals(key)) {
|
||||
if ("Apply+Filter".equals(value)) {
|
||||
apply = true;
|
||||
}
|
||||
switch (key) {
|
||||
case "f_cats":
|
||||
int cats = NumberUtils.parseIntSafely(value, EhConfig.ALL_CATEGORY);
|
||||
category |= (~cats) & EhConfig.ALL_CATEGORY;
|
||||
break;
|
||||
case "f_doujinshi":
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.DOUJINSHI;
|
||||
}
|
||||
break;
|
||||
case "f_manga":
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.MANGA;
|
||||
}
|
||||
break;
|
||||
case "f_artistcg":
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.ARTIST_CG;
|
||||
}
|
||||
break;
|
||||
case "f_gamecg":
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.GAME_CG;
|
||||
}
|
||||
break;
|
||||
case "f_western":
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.WESTERN;
|
||||
}
|
||||
break;
|
||||
case "f_non-h":
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.NON_H;
|
||||
}
|
||||
break;
|
||||
case "f_imageset":
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.IMAGE_SET;
|
||||
}
|
||||
break;
|
||||
case "f_cosplay":
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.COSPLAY;
|
||||
}
|
||||
break;
|
||||
case "f_asianporn":
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.ASIAN_PORN;
|
||||
}
|
||||
break;
|
||||
case "f_misc":
|
||||
if ("1".equals(value)) {
|
||||
category |= EhConfig.MISC;
|
||||
}
|
||||
break;
|
||||
case "f_search":
|
||||
try {
|
||||
keyword = URLDecoder.decode(value, "utf-8");
|
||||
} catch (UnsupportedEncodingException | IllegalArgumentException e) {
|
||||
// Ignore
|
||||
}
|
||||
break;
|
||||
case "advsearch":
|
||||
if ("1".equals(value)) {
|
||||
enableAdvanceSearch = true;
|
||||
}
|
||||
break;
|
||||
case "f_sname":
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.SNAME;
|
||||
}
|
||||
break;
|
||||
case "f_stags":
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.STAGS;
|
||||
}
|
||||
break;
|
||||
case "f_sdesc":
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.SDESC;
|
||||
}
|
||||
break;
|
||||
case "f_storr":
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.STORR;
|
||||
}
|
||||
break;
|
||||
case "f_sto":
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.STO;
|
||||
}
|
||||
break;
|
||||
case "f_sdt1":
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.SDT1;
|
||||
}
|
||||
break;
|
||||
case "f_sdt2":
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.SDT2;
|
||||
}
|
||||
break;
|
||||
case "f_sh":
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.SH;
|
||||
}
|
||||
break;
|
||||
case "f_sfl":
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.SFL;
|
||||
}
|
||||
break;
|
||||
case "f_sfu":
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.SFU;
|
||||
}
|
||||
break;
|
||||
case "f_sft":
|
||||
if ("on".equals(value)) {
|
||||
advanceSearch |= AdvanceSearchTable.SFT;
|
||||
}
|
||||
break;
|
||||
case "f_sr":
|
||||
if ("on".equals(value)) {
|
||||
enableMinRating = true;
|
||||
}
|
||||
break;
|
||||
case "f_srdd":
|
||||
minRating = NumberUtils.parseIntSafely(value, -1);
|
||||
break;
|
||||
case "f_sp":
|
||||
if ("on".equals(value)) {
|
||||
enablePage = true;
|
||||
}
|
||||
break;
|
||||
case "f_spf":
|
||||
pageFrom = NumberUtils.parseIntSafely(value, -1);
|
||||
break;
|
||||
case "f_spt":
|
||||
pageTo = NumberUtils.parseIntSafely(value, -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!apply) {
|
||||
return;
|
||||
}
|
||||
|
||||
mCategory = category;
|
||||
mKeyword = keyword;
|
||||
if (enableAdvanceSearch) {
|
||||
@@ -377,6 +451,13 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
} else {
|
||||
mMinRating = -1;
|
||||
}
|
||||
if (enablePage) {
|
||||
mPageFrom = pageFrom;
|
||||
mPageTo = pageTo;
|
||||
} else {
|
||||
mPageFrom = -1;
|
||||
mPageTo = -1;
|
||||
}
|
||||
} else {
|
||||
mAdvanceSearch = -1;
|
||||
}
|
||||
@@ -385,29 +466,28 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
public String build() {
|
||||
switch (mMode) {
|
||||
default:
|
||||
case MODE_NORMAL: {
|
||||
boolean filter = false;
|
||||
UrlBuilder ub = new UrlBuilder(EhUrl.getHost());
|
||||
case MODE_NORMAL:
|
||||
case MODE_SUBSCRIPTION: {
|
||||
String url;
|
||||
if (mMode == MODE_NORMAL) {
|
||||
url = EhUrl.getHost();
|
||||
} else {
|
||||
url = EhUrl.getWatchedUrl();
|
||||
}
|
||||
|
||||
UrlBuilder ub = new UrlBuilder(url);
|
||||
if (mCategory != EhUtils.NONE) {
|
||||
ub.addQuery("f_doujinshi", ((mCategory & EhConfig.DOUJINSHI) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_manga", ((mCategory & EhConfig.MANGA) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_artistcg", ((mCategory & EhConfig.ARTIST_CG) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_gamecg", ((mCategory & EhConfig.GAME_CG) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_western", ((mCategory & EhConfig.WESTERN) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_non-h", ((mCategory & EhConfig.NON_H) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_imageset", ((mCategory & EhConfig.IMAGE_SET) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_cosplay", ((mCategory & EhConfig.COSPLAY) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_asianporn", ((mCategory & EhConfig.ASIAN_PORN) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_misc", ((mCategory & EhConfig.MISC) == 0) ? "0" : "1");
|
||||
filter = true;
|
||||
ub.addQuery("f_cats", (~mCategory) & EhConfig.ALL_CATEGORY);
|
||||
}
|
||||
// Search key
|
||||
if (mKeyword != null) {
|
||||
try {
|
||||
ub.addQuery("f_search", URLEncoder.encode(mKeyword, "UTF-8"));
|
||||
filter = true;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Empty
|
||||
String keyword = mKeyword.trim();
|
||||
if (!keyword.isEmpty()) {
|
||||
try {
|
||||
ub.addQuery("f_search", URLEncoder.encode(mKeyword, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Empty
|
||||
}
|
||||
}
|
||||
}
|
||||
// Page index
|
||||
@@ -425,16 +505,20 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
if((mAdvanceSearch & AdvanceSearchTable.SDT1) != 0) ub.addQuery("f_sdt1", "on");
|
||||
if((mAdvanceSearch & AdvanceSearchTable.SDT2) != 0) ub.addQuery("f_sdt2", "on");
|
||||
if((mAdvanceSearch & AdvanceSearchTable.SH) != 0) ub.addQuery("f_sh", "on");
|
||||
if((mAdvanceSearch & AdvanceSearchTable.SFL) != 0) ub.addQuery("f_sfl", "on");
|
||||
if((mAdvanceSearch & AdvanceSearchTable.SFU) != 0) ub.addQuery("f_sfu", "on");
|
||||
if((mAdvanceSearch & AdvanceSearchTable.SFT) != 0) ub.addQuery("f_sft", "on");
|
||||
// Set min star
|
||||
if (mMinRating != -1) {
|
||||
ub.addQuery("f_sr", "on");
|
||||
ub.addQuery("f_srdd", mMinRating);
|
||||
}
|
||||
filter = true;
|
||||
}
|
||||
// Add filter foot
|
||||
if (filter) {
|
||||
ub.addQuery("f_apply", "Apply+Filter");
|
||||
// Pages
|
||||
if (mPageFrom != -1 || mPageTo != -1) {
|
||||
ub.addQuery("f_sp", "on");
|
||||
ub.addQuery("f_spf", mPageFrom != -1 ? Integer.toString(mPageFrom) : "");
|
||||
ub.addQuery("f_spt", mPageTo != -1 ? Integer.toString(mPageTo) : "");
|
||||
}
|
||||
}
|
||||
return ub.build();
|
||||
}
|
||||
@@ -464,6 +548,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
case MODE_WHATS_HOT:
|
||||
return EhUrl.getPopularUrl();
|
||||
case MODE_IMAGE_SEARCH:
|
||||
return EhUrl.getImageSearchUrl();
|
||||
}
|
||||
@@ -482,6 +568,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
dest.writeString(this.mKeyword);
|
||||
dest.writeInt(this.mAdvanceSearch);
|
||||
dest.writeInt(this.mMinRating);
|
||||
dest.writeInt(this.mPageFrom);
|
||||
dest.writeInt(this.mPageTo);
|
||||
dest.writeString(this.mImagePath);
|
||||
dest.writeByte(mUseSimilarityScan ? (byte) 1 : (byte) 0);
|
||||
dest.writeByte(mOnlySearchCovers ? (byte) 1 : (byte) 0);
|
||||
@@ -499,6 +587,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
this.mKeyword = in.readString();
|
||||
this.mAdvanceSearch = in.readInt();
|
||||
this.mMinRating = in.readInt();
|
||||
this.mPageFrom = in.readInt();
|
||||
this.mPageTo = in.readInt();
|
||||
this.mImagePath = in.readString();
|
||||
this.mUseSimilarityScan = in.readByte() != 0;
|
||||
this.mOnlySearchCovers = in.readByte() != 0;
|
||||
|
||||
@@ -21,4 +21,8 @@ public class EhException extends Exception {
|
||||
public EhException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
|
||||
public EhException(String detailMessage, Throwable cause) {
|
||||
super(detailMessage, cause);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,11 @@ public class ParseException extends EhException {
|
||||
mBody = body;
|
||||
}
|
||||
|
||||
public ParseException(String detailMessage, String body, Throwable cause) {
|
||||
super(detailMessage, cause);
|
||||
mBody = body;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return mBody;
|
||||
}
|
||||
|
||||
@@ -21,23 +21,22 @@ import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.EhException;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import java.util.List;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FavoritesParser {
|
||||
|
||||
public static class Result {
|
||||
public String[] catArray; // Size 10
|
||||
public int[] countArray; // Size 10
|
||||
public int pages;
|
||||
public int nextPage;
|
||||
public List<GalleryInfo> galleryInfoList;
|
||||
}
|
||||
|
||||
@@ -54,14 +53,15 @@ public class FavoritesParser {
|
||||
//noinspection ConstantConditions
|
||||
Elements fps = ido.getElementsByClass("fp");
|
||||
// Last one is "fp fps"
|
||||
Assert.assertEquals(11, fps.size());
|
||||
AssertUtils.assertEquals(11, fps.size());
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Element fp = fps.get(i);
|
||||
countArray[i] = ParserUtils.parseInt(fp.child(0).text());
|
||||
countArray[i] = ParserUtils.parseInt(fp.child(0).text(), 0);
|
||||
catArray[i] = ParserUtils.trim(fp.child(2).text());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
throw new ParseException("Parse favorites error", body);
|
||||
}
|
||||
@@ -72,6 +72,7 @@ public class FavoritesParser {
|
||||
re.catArray = catArray;
|
||||
re.countArray = countArray;
|
||||
re.pages = result.pages;
|
||||
re.nextPage = result.nextPage;
|
||||
re.galleryInfoList = result.galleryInfoList;
|
||||
|
||||
return re;
|
||||
|
||||
@@ -18,7 +18,7 @@ package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
@@ -31,7 +31,8 @@ public class ForumsParser {
|
||||
Element userlinks = d.getElementById("userlinks");
|
||||
Element child = userlinks.child(0).child(0).child(0);
|
||||
return child.attr("href");
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Parse forums error", body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.hippo.ehviewer.client.parser;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -43,8 +44,8 @@ public class GalleryApiParser {
|
||||
gi.category = EhUtils.getCategory(g.getString("category"));
|
||||
gi.thumb = EhUtils.handleThumbUrlResolution(g.getString("thumb"));
|
||||
gi.uploader = g.getString("uploader");
|
||||
gi.posted = ParserUtils.formatDate(ParserUtils.parseLong(g.getString("posted")) * 1000);
|
||||
gi.rating = Float.parseFloat(g.getString("rating"));
|
||||
gi.posted = ParserUtils.formatDate(ParserUtils.parseLong(g.getString("posted"), 0) * 1000);
|
||||
gi.rating = NumberUtils.parseFloatSafely(g.getString("rating"), 0.0f);
|
||||
// tags
|
||||
JSONArray tagJa = g.getJSONArray("tags");
|
||||
int tagLength = tagJa.length();
|
||||
@@ -53,6 +54,8 @@ public class GalleryApiParser {
|
||||
tags[j] = tagJa.getString(j);
|
||||
}
|
||||
gi.simpleTags = tags;
|
||||
gi.pages = NumberUtils.parseIntSafely(g.getString("filecount"), 0);
|
||||
gi.generateSLang();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryComment;
|
||||
import com.hippo.ehviewer.client.data.GalleryCommentList;
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail;
|
||||
import com.hippo.ehviewer.client.data.GalleryTagGroup;
|
||||
import com.hippo.ehviewer.client.data.LargePreviewSet;
|
||||
@@ -33,15 +32,11 @@ import com.hippo.ehviewer.client.exception.EhException;
|
||||
import com.hippo.ehviewer.client.exception.OffensiveException;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.ehviewer.client.exception.PiningException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
import com.hippo.util.MutableBoolean;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
@@ -52,6 +47,13 @@ import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.nodes.Node;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.jsoup.select.NodeTraversor;
|
||||
import org.jsoup.select.NodeVisitor;
|
||||
|
||||
public class GalleryDetailParser {
|
||||
|
||||
@@ -69,7 +71,7 @@ public class GalleryDetailParser {
|
||||
private static final Pattern PATTERN_LARGE_PREVIEW = Pattern.compile("<div class=\"gdtl\".+?<a href=\"(.+?)\"><img alt=\"([\\d,]+)\".+?src=\"(.+?)\"");
|
||||
|
||||
private static final GalleryTagGroup[] EMPTY_GALLERY_TAG_GROUP_ARRAY = new GalleryTagGroup[0];
|
||||
private static final GalleryComment[] EMPTY_GALLERY_COMMENT_ARRAY = new GalleryComment[0];
|
||||
private static final GalleryCommentList EMPTY_GALLERY_COMMENT_ARRAY = new GalleryCommentList(new GalleryComment[0], false);
|
||||
|
||||
private static final DateFormat WEB_COMMENT_DATE_FORMAT = new SimpleDateFormat("dd MMMMM yyyy, HH:mm z", Locale.US);
|
||||
|
||||
@@ -111,13 +113,16 @@ public class GalleryDetailParser {
|
||||
private static void parseDetail(GalleryDetail gd, Document d, String body) throws ParseException {
|
||||
Matcher matcher = PATTERN_DETAIL.matcher(body);
|
||||
if (matcher.find()) {
|
||||
gd.gid = Long.parseLong(matcher.group(1));
|
||||
gd.gid = NumberUtils.parseLongSafely(matcher.group(1), -1L);
|
||||
gd.token = matcher.group(2);
|
||||
gd.apiUid = NumberUtils.parseLongSafely(matcher.group(3), -1L);
|
||||
gd.apiKey = matcher.group(4);
|
||||
} else {
|
||||
throw new ParseException("Can't parse gallery detail", body);
|
||||
}
|
||||
if (gd.gid == -1L) {
|
||||
throw new ParseException("Can't parse gallery detail", body);
|
||||
}
|
||||
|
||||
matcher = PATTERN_TORRENT.matcher(body);
|
||||
if (matcher.find()) {
|
||||
@@ -142,7 +147,8 @@ public class GalleryDetailParser {
|
||||
Element gd1 = gm.getElementById("gd1");
|
||||
try {
|
||||
gd.thumb = parseCoverStyle(StringUtils.trim(gd1.child(0).attr("style")));
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
gd.thumb = "";
|
||||
}
|
||||
|
||||
@@ -165,10 +171,13 @@ public class GalleryDetailParser {
|
||||
// Category
|
||||
Element gdc = gm.getElementById("gdc");
|
||||
try {
|
||||
String href = gdc.child(0).attr("href");
|
||||
String category = href.substring(href.lastIndexOf('/') + 1);
|
||||
gd.category = EhUtils.getCategory(category);
|
||||
} catch (Exception e) {
|
||||
Element ce = JsoupUtils.getElementByClass(gdc, "cn");
|
||||
if (ce == null) {
|
||||
ce = JsoupUtils.getElementByClass(gdc, "cs");
|
||||
}
|
||||
gd.category = EhUtils.getCategory(ce.text());
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
gd.category = EhUtils.UNKNOWN;
|
||||
}
|
||||
|
||||
@@ -193,7 +202,8 @@ public class GalleryDetailParser {
|
||||
for (int i = 0, n = es.size(); i < n; i++) {
|
||||
parseDetailInfo(gd, es.get(i), body);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -227,7 +237,16 @@ public class GalleryDetailParser {
|
||||
// isFavorited
|
||||
Element gdf = gm.getElementById("gdf");
|
||||
gd.isFavorited = null != gdf && !StringUtils.trim(gdf.text()).equals("Add to Favorites");
|
||||
} catch (Exception e) {
|
||||
if (gdf != null) {
|
||||
final String favoriteName = StringUtils.trim(gdf.text());
|
||||
if (favoriteName.equals("Add to Favorites")) {
|
||||
gd.favoriteName = null;
|
||||
} else {
|
||||
gd.favoriteName = StringUtils.trim(gdf.text());
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Can't parse gallery detail", body);
|
||||
}
|
||||
}
|
||||
@@ -253,7 +272,10 @@ public class GalleryDetailParser {
|
||||
if (key.startsWith("Posted")) {
|
||||
gd.posted = value;
|
||||
} else if (key.startsWith("Parent")) {
|
||||
gd.parent = value;
|
||||
Element a = es.get(1).children().first();
|
||||
if (a != null) {
|
||||
gd.parent = a.attr("href");
|
||||
}
|
||||
} else if (key.startsWith("Visible")) {
|
||||
gd.visible = value;
|
||||
} else if (key.startsWith("Language")) {
|
||||
@@ -309,7 +331,8 @@ public class GalleryDetailParser {
|
||||
}
|
||||
|
||||
return group.size() > 0 ? group : null;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@@ -323,16 +346,27 @@ public class GalleryDetailParser {
|
||||
try {
|
||||
Element taglist = document.getElementById("taglist");
|
||||
Elements tagGroups = taglist.child(0).child(0).children();
|
||||
return parseTagGroups(tagGroups);
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return EMPTY_GALLERY_TAG_GROUP_ARRAY;
|
||||
}
|
||||
}
|
||||
|
||||
List<GalleryTagGroup> list = new ArrayList<>(tagGroups.size());
|
||||
for (int i = 0, n = tagGroups.size(); i < n; i++) {
|
||||
GalleryTagGroup group = parseTagGroup(tagGroups.get(i));
|
||||
@NonNull
|
||||
public static GalleryTagGroup[] parseTagGroups(Elements trs) {
|
||||
try {
|
||||
List<GalleryTagGroup> list = new ArrayList<>(trs.size());
|
||||
for (int i = 0, n = trs.size(); i < n; i++) {
|
||||
GalleryTagGroup group = parseTagGroup(trs.get(i));
|
||||
if (null != group) {
|
||||
list.add(group);
|
||||
}
|
||||
}
|
||||
return list.toArray(new GalleryTagGroup[list.size()]);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return EMPTY_GALLERY_TAG_GROUP_ARRAY;
|
||||
}
|
||||
@@ -372,13 +406,23 @@ public class GalleryDetailParser {
|
||||
Element a = element.previousElementSibling();
|
||||
String name = a.attr("name");
|
||||
comment.id = Integer.parseInt(StringUtils.trim(name).substring(1));
|
||||
// Vote up and vote down
|
||||
// Editable, vote up and vote down
|
||||
Element c4 = JsoupUtils.getElementByClass(element, "c4");
|
||||
if (null != c4) {
|
||||
Elements es = c4.children();
|
||||
if (2 == es.size()) {
|
||||
comment.voteUp = !TextUtils.isEmpty(StringUtils.trim(es.get(0).attr("style")));
|
||||
comment.voteDown = !TextUtils.isEmpty(StringUtils.trim(es.get(1).attr("style")));
|
||||
for (Element e : c4.children()) {
|
||||
switch (e.text()) {
|
||||
case "Vote+":
|
||||
comment.voteUpAble = true;
|
||||
comment.voteUpEd = !StringUtils.trim(e.attr("style")).isEmpty();
|
||||
break;
|
||||
case "Vote-":
|
||||
comment.voteDownAble = true;
|
||||
comment.voteDownEd = !StringUtils.trim(e.attr("style")).isEmpty();
|
||||
break;
|
||||
case "Edit":
|
||||
comment.editable = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Vote state
|
||||
@@ -397,14 +441,23 @@ public class GalleryDetailParser {
|
||||
// time
|
||||
Element c3 = JsoupUtils.getElementByClass(element, "c3");
|
||||
String temp = c3.ownText();
|
||||
temp = temp.substring("Posted on ".length(), temp.length() - " by: ".length());
|
||||
temp = temp.substring("Posted on ".length(), temp.length() - " by:".length());
|
||||
comment.time = WEB_COMMENT_DATE_FORMAT.parse(temp).getTime();
|
||||
// user
|
||||
comment.user = c3.child(0).text();
|
||||
// comment
|
||||
comment.comment = JsoupUtils.getElementByClass(element, "c6").html();
|
||||
// last edited
|
||||
Element c8 = JsoupUtils.getElementByClass(element, "c8");
|
||||
if (c8 != null) {
|
||||
Element e = c8.children().first();
|
||||
if (e != null) {
|
||||
comment.lastEdited = WEB_COMMENT_DATE_FORMAT.parse(temp).getTime();
|
||||
}
|
||||
}
|
||||
return comment;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@@ -414,7 +467,7 @@ public class GalleryDetailParser {
|
||||
* Parse comments with html parser
|
||||
*/
|
||||
@NonNull
|
||||
public static GalleryComment[] parseComments(Document document) {
|
||||
public static GalleryCommentList parseComments(Document document) {
|
||||
try {
|
||||
Element cdiv = document.getElementById("cdiv");
|
||||
Elements c1s = cdiv.getElementsByClass("c1");
|
||||
@@ -426,8 +479,24 @@ public class GalleryDetailParser {
|
||||
list.add(comment);
|
||||
}
|
||||
}
|
||||
return list.toArray(new GalleryComment[list.size()]);
|
||||
} catch (Exception e) {
|
||||
|
||||
Element chd = cdiv.getElementById("chd");
|
||||
MutableBoolean hasMore = new MutableBoolean(false);
|
||||
NodeTraversor.traverse(new NodeVisitor() {
|
||||
@Override
|
||||
public void head(Node node, int depth) {
|
||||
if (node instanceof Element && ((Element) node).text().equals("click to show all")) {
|
||||
hasMore.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tail(Node node, int depth) { }
|
||||
}, chd);
|
||||
|
||||
return new GalleryCommentList(list.toArray(new GalleryComment[list.size()]), hasMore.value);
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return EMPTY_GALLERY_COMMENT_ARRAY;
|
||||
}
|
||||
@@ -466,7 +535,8 @@ public class GalleryDetailParser {
|
||||
try {
|
||||
Elements elements = document.getElementsByClass("ptt").first().child(0).child(0).children();
|
||||
return Integer.parseInt(elements.get(elements.size() - 2).text());
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
throw new ParseException("Can't parse preview pages", body);
|
||||
}
|
||||
@@ -479,7 +549,7 @@ public class GalleryDetailParser {
|
||||
Matcher m = PATTERN_PREVIEW_PAGES.matcher(body);
|
||||
int previewPages = -1;
|
||||
if (m.find()) {
|
||||
previewPages = ParserUtils.parseInt(m.group(1));
|
||||
previewPages = ParserUtils.parseInt(m.group(1), -1);
|
||||
}
|
||||
|
||||
if (previewPages <= 0) {
|
||||
@@ -493,12 +563,18 @@ public class GalleryDetailParser {
|
||||
* Parse pages with regular expressions
|
||||
*/
|
||||
public static int parsePages(String body) throws ParseException {
|
||||
int pages = -1;
|
||||
|
||||
Matcher m = PATTERN_PAGES.matcher(body);
|
||||
if (m.find()) {
|
||||
return ParserUtils.parseInt(m.group(1));
|
||||
} else {
|
||||
pages = ParserUtils.parseInt(m.group(1), -1);
|
||||
}
|
||||
|
||||
if (pages < 0) {
|
||||
throw new ParseException("Parse pages error", body);
|
||||
}
|
||||
|
||||
return pages;
|
||||
}
|
||||
|
||||
public static PreviewSet parsePreviewSet(Document d, String body) throws ParseException {
|
||||
@@ -541,7 +617,8 @@ public class GalleryDetailParser {
|
||||
largePreviewSet.addItem(index, imageUrl, pageUrl);
|
||||
}
|
||||
return largePreviewSet;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
throw new ParseException("Can't parse large preview", body);
|
||||
}
|
||||
@@ -555,7 +632,10 @@ public class GalleryDetailParser {
|
||||
LargePreviewSet largePreviewSet = new LargePreviewSet();
|
||||
|
||||
while (m.find()) {
|
||||
int index = ParserUtils.parseInt(m.group(2)) - 1;
|
||||
int index = ParserUtils.parseInt(m.group(2), 0) - 1;
|
||||
if (index < 0) {
|
||||
continue;
|
||||
}
|
||||
String imageUrl = ParserUtils.trim(m.group(3));
|
||||
String pageUrl = ParserUtils.trim(m.group(1));
|
||||
if (Settings.getFixThumbUrl()) {
|
||||
@@ -578,10 +658,23 @@ public class GalleryDetailParser {
|
||||
Matcher m = PATTERN_NORMAL_PREVIEW.matcher(body);
|
||||
NormalPreviewSet normalPreviewSet = new NormalPreviewSet();
|
||||
while (m.find()) {
|
||||
normalPreviewSet.addItem(ParserUtils.parseInt(m.group(6)) - 1,
|
||||
ParserUtils.trim(m.group(3)), ParserUtils.parseInt((m.group(4))), 0,
|
||||
ParserUtils.parseInt(m.group(1)), ParserUtils.parseInt(m.group(2)),
|
||||
ParserUtils.trim(m.group(5)));
|
||||
int position = ParserUtils.parseInt(m.group(6), 0) - 1;
|
||||
if (position < 0) {
|
||||
continue;
|
||||
}
|
||||
String imageUrl = ParserUtils.trim(m.group(3));
|
||||
int xOffset = ParserUtils.parseInt(m.group(4), 0);
|
||||
int yOffset = 0;
|
||||
int width = ParserUtils.parseInt(m.group(1), 0);
|
||||
if (width <= 0) {
|
||||
continue;
|
||||
}
|
||||
int height = ParserUtils.parseInt(m.group(2), 0);
|
||||
if (height <= 0) {
|
||||
continue;
|
||||
}
|
||||
String pageUrl = ParserUtils.trim(m.group(5));
|
||||
normalPreviewSet.addItem(position, imageUrl, xOffset, yOffset, width, height, pageUrl);
|
||||
}
|
||||
|
||||
if (normalPreviewSet.size() == 0) {
|
||||
|
||||
@@ -16,10 +16,9 @@
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -29,20 +28,32 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public final class GalleryDetailUrlParser {
|
||||
|
||||
public static final Pattern URL_PATTERN = Pattern.compile("https?://(?:" +
|
||||
EhUrl.DOMAIN_EX + "|" + EhUrl.DOMAIN_E + "|" + EhUrl.DOMAIN_LOFI + ")/g/(\\d+)/(\\w+)");
|
||||
private static final Pattern URL_STRICT_PATTERN = Pattern.compile(
|
||||
"https?://(?:" + EhUrl.DOMAIN_EX + "|" + EhUrl.DOMAIN_E + "|" + EhUrl.DOMAIN_LOFI + ")/(?:g|mpv)/(\\d+)/([0-9a-f]{10})");
|
||||
|
||||
private static final Pattern URL_PATTERN = Pattern.compile(
|
||||
"(\\d+)/([0-9a-f]{10})(?:[^0-9a-f]|$)");
|
||||
|
||||
@Nullable
|
||||
public static Result parse(String url) {
|
||||
return parse(url, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Result parse(String url, boolean strict) {
|
||||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Matcher m = URL_PATTERN.matcher(url);
|
||||
Pattern pattern = strict ? URL_STRICT_PATTERN : URL_PATTERN;
|
||||
Matcher m = pattern.matcher(url);
|
||||
if (m.find()) {
|
||||
Result result = new Result();
|
||||
result.gid = Long.parseLong(m.group(1));
|
||||
result.gid = NumberUtils.parseLongSafely(m.group(1), -1L);
|
||||
result.token = m.group(2);
|
||||
if (result.gid < 0) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@@ -16,37 +16,54 @@
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.data.GalleryTagGroup;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
public class GalleryListParser {
|
||||
|
||||
private static final String TAG = GalleryListParser.class.getSimpleName();
|
||||
|
||||
private static final Pattern PATTERN_RATING = Pattern.compile("\\d+px");
|
||||
private static final Pattern PATTERN_THUMB_SIZE = Pattern.compile("height:(\\d+)px; width:(\\d+)px");
|
||||
private static final Pattern PATTERN_THUMB_SIZE = Pattern.compile("height:(\\d+)px;width:(\\d+)px");
|
||||
private static final Pattern PATTERN_FAVORITE_SLOT = Pattern.compile("background-color:rgba\\((\\d+),(\\d+),(\\d+),");
|
||||
private static final Pattern PATTERN_PAGES = Pattern.compile("(\\d+) page");
|
||||
private static final Pattern PATTERN_NEXT_PAGE = Pattern.compile("page=(\\d+)");
|
||||
|
||||
private static final String[][] FAVORITE_SLOT_RGB = new String[][] {
|
||||
new String[] { "0", "0", "0"},
|
||||
new String[] { "240", "0", "0"},
|
||||
new String[] { "240", "160", "0"},
|
||||
new String[] { "208", "208", "0"},
|
||||
new String[] { "0", "128", "0"},
|
||||
new String[] { "144", "240", "64"},
|
||||
new String[] { "64", "176", "240"},
|
||||
new String[] { "0", "0", "240"},
|
||||
new String[] { "80", "0", "128"},
|
||||
new String[] { "224", "128", "224"},
|
||||
};
|
||||
|
||||
public static class Result {
|
||||
public int pages;
|
||||
public int nextPage;
|
||||
public boolean noWatchedTags;
|
||||
public List<GalleryInfo> galleryInfoList;
|
||||
}
|
||||
|
||||
@@ -54,25 +71,25 @@ public class GalleryListParser {
|
||||
try {
|
||||
Elements es = d.getElementsByClass("ptt").first().child(0).child(0).children();
|
||||
return Integer.parseInt(es.get(es.size() - 2).text().trim());
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Can't parse gallery list pages", body);
|
||||
}
|
||||
}
|
||||
|
||||
private static String parseRating(String ratingStyle) {
|
||||
Matcher m = PATTERN_RATING.matcher(ratingStyle);
|
||||
int num1;
|
||||
int num2;
|
||||
int num1 = Integer.MIN_VALUE;
|
||||
int num2 = Integer.MIN_VALUE;
|
||||
int rate = 5;
|
||||
String re;
|
||||
if (m.find()) {
|
||||
num1 = ParserUtils.parseInt(m.group().replace("px", ""));
|
||||
} else {
|
||||
return null;
|
||||
num1 = ParserUtils.parseInt(m.group().replace("px", ""), Integer.MIN_VALUE);
|
||||
}
|
||||
if (m.find()) {
|
||||
num2 = ParserUtils.parseInt(m.group().replace("px", ""));
|
||||
} else {
|
||||
num2 = ParserUtils.parseInt(m.group().replace("px", ""), Integer.MIN_VALUE);
|
||||
}
|
||||
if (num1 == Integer.MIN_VALUE || num2 == Integer.MIN_VALUE) {
|
||||
return null;
|
||||
}
|
||||
rate = rate - num1 / 16;
|
||||
@@ -85,96 +102,191 @@ public class GalleryListParser {
|
||||
return re;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static int parseFavoriteSlot(String style) {
|
||||
Matcher m = PATTERN_FAVORITE_SLOT.matcher(style);
|
||||
if (m.find()) {
|
||||
String r = m.group(1);
|
||||
String g = m.group(2);
|
||||
String b = m.group(3);
|
||||
int slot = 0;
|
||||
for (String[] rgb : FAVORITE_SLOT_RGB) {
|
||||
if (r.equals(rgb[0]) && g.equals(rgb[1]) && b.equals(rgb[2])) {
|
||||
return slot;
|
||||
}
|
||||
slot++;
|
||||
}
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
private static GalleryInfo parseGalleryInfo(Element e) {
|
||||
GalleryInfo gi = new GalleryInfo();
|
||||
// Get category
|
||||
Element ic = JsoupUtils.getElementByClass(e, "ic");
|
||||
if (null != ic) {
|
||||
gi.category = EhUtils.getCategory(ic.attr("alt").trim());
|
||||
} else {
|
||||
Log.w(TAG, "Can't parse gallery info category");
|
||||
gi.category = EhUtils.UNKNOWN;
|
||||
}
|
||||
// Posted
|
||||
Element itd = JsoupUtils.getElementByClass(e, "itd");
|
||||
if (null != itd) {
|
||||
gi.posted = itd.text().trim();
|
||||
} else {
|
||||
Log.w(TAG, "Can't parse gallery info posted");
|
||||
gi.posted = "";
|
||||
}
|
||||
// Thumb
|
||||
Element it2 = JsoupUtils.getElementByClass(e, "it2");
|
||||
if (null != it2) {
|
||||
// Thumb size
|
||||
Matcher m = PATTERN_THUMB_SIZE.matcher(it2.attr("style"));
|
||||
if (m.find()) {
|
||||
gi.thumbWidth = NumberUtils.parseIntSafely(m.group(2), 0);
|
||||
gi.thumbHeight = NumberUtils.parseIntSafely(m.group(1), 0);
|
||||
} else {
|
||||
Log.w(TAG, "Can't parse gallery info thumb size");
|
||||
gi.thumbWidth = 0;
|
||||
gi.thumbHeight = 0;
|
||||
}
|
||||
|
||||
// Thumb url
|
||||
Elements es = it2.children();
|
||||
if (null != es && es.size() >= 1) {
|
||||
gi.thumb = EhUtils.handleThumbUrlResolution(es.get(0).attr("src"));
|
||||
} else {
|
||||
String html = it2.html();
|
||||
int index1 = html.indexOf('~');
|
||||
int index2 = StringUtils.ordinalIndexOf(html, '~', 2);
|
||||
if (index1 < index2) {
|
||||
gi.thumb = EhUtils.handleThumbUrlResolution(
|
||||
"http://" +StringUtils.replace(html.substring(index1 + 1, index2), "~", "/"));
|
||||
} else {
|
||||
Log.w(TAG, "Can't parse gallery info thumb url");
|
||||
gi.thumb = "";
|
||||
// Title, gid, token (required), tags
|
||||
Element glname = JsoupUtils.getElementByClass(e, "glname");
|
||||
if (glname != null) {
|
||||
Element a = JsoupUtils.getElementByTag(glname, "a");
|
||||
if (a == null) {
|
||||
Element parent = glname.parent();
|
||||
if (parent != null && "a".equals(parent.tagName())) {
|
||||
a = parent;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log.w(TAG, "Can't parse gallery info thumb");
|
||||
gi.thumbWidth = 0;
|
||||
gi.thumbHeight = 0;
|
||||
gi.thumb = "";
|
||||
if (a != null) {
|
||||
GalleryDetailUrlParser.Result result = GalleryDetailUrlParser.parse(a.attr("href"));
|
||||
if (result != null) {
|
||||
gi.gid = result.gid;
|
||||
gi.token = result.token;
|
||||
}
|
||||
}
|
||||
|
||||
Element child = glname;
|
||||
Elements children = glname.children();
|
||||
while (children.size() != 0) {
|
||||
child = children.get(0);
|
||||
children = child.children();
|
||||
}
|
||||
gi.title = child.text().trim();
|
||||
|
||||
Element tbody = JsoupUtils.getElementByTag(glname, "tbody");
|
||||
if (tbody != null) {
|
||||
ArrayList<String> tags = new ArrayList<>();
|
||||
GalleryTagGroup[] groups = GalleryDetailParser.parseTagGroups(tbody.children());
|
||||
for (GalleryTagGroup group : groups) {
|
||||
for (int j = 0; j < group.size(); j++) {
|
||||
tags.add(group.groupName + ":" + group.getTagAt(j));
|
||||
}
|
||||
}
|
||||
gi.simpleTags = tags.toArray(new String[tags.size()]);
|
||||
}
|
||||
}
|
||||
// Title (required)
|
||||
Element it5 = JsoupUtils.getElementByClass(e, "it5");
|
||||
if (null == it5) {
|
||||
Log.e(TAG, "Can't parse gallery info title, step 1");
|
||||
if (gi.title == null) {
|
||||
return null;
|
||||
}
|
||||
Elements es = it5.children();
|
||||
if (null == es || es.size() <= 0) {
|
||||
Log.e(TAG, "Can't parse gallery info title, step 2");
|
||||
return null;
|
||||
|
||||
// Category
|
||||
gi.category = EhUtils.UNKNOWN;
|
||||
Element ce = JsoupUtils.getElementByClass(e, "cn");
|
||||
if (ce == null) {
|
||||
ce = JsoupUtils.getElementByClass(e, "cs");
|
||||
}
|
||||
Element a = es.get(0);
|
||||
GalleryDetailUrlParser.Result result = GalleryDetailUrlParser.parse(a.attr("href"));
|
||||
if (null == result) {
|
||||
Log.e(TAG, "Can't parse gallery info title, step 3");
|
||||
return null;
|
||||
if (ce != null) {
|
||||
gi.category = EhUtils.getCategory(ce.text());
|
||||
}
|
||||
gi.gid = result.gid;
|
||||
gi.token = result.token;
|
||||
gi.title = a.text().trim();
|
||||
|
||||
// Thumb
|
||||
Element glthumb = JsoupUtils.getElementByClass(e, "glthumb");
|
||||
if (glthumb != null) {
|
||||
Element img = glthumb.select("div:nth-child(1)>img").first();
|
||||
if (img != null) {
|
||||
// Thumb size
|
||||
Matcher m = PATTERN_THUMB_SIZE.matcher(img.attr("style"));
|
||||
if (m.find()) {
|
||||
gi.thumbWidth = NumberUtils.parseIntSafely(m.group(2), 0);
|
||||
gi.thumbHeight = NumberUtils.parseIntSafely(m.group(1), 0);
|
||||
} else {
|
||||
Log.w(TAG, "Can't parse gallery info thumb size");
|
||||
gi.thumbWidth = 0;
|
||||
gi.thumbHeight = 0;
|
||||
}
|
||||
// Thumb url
|
||||
String url = img.attr("data-src");
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
url = img.attr("src");
|
||||
}
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
url = null;
|
||||
}
|
||||
gi.thumb = EhUtils.handleThumbUrlResolution(url);
|
||||
}
|
||||
|
||||
// Pages
|
||||
Element div = glthumb.select("div:nth-child(2)>div:nth-child(2)>div:nth-child(2)").first();
|
||||
if (div != null) {
|
||||
Matcher matcher = PATTERN_PAGES.matcher(div.text());
|
||||
if (matcher.find()) {
|
||||
gi.pages = NumberUtils.parseIntSafely(matcher.group(1), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Try extended and thumbnail version
|
||||
if (gi.thumb == null) {
|
||||
Element gl = JsoupUtils.getElementByClass(e, "gl1e");
|
||||
if (gl == null) {
|
||||
gl = JsoupUtils.getElementByClass(e, "gl3t");
|
||||
}
|
||||
if (gl != null) {
|
||||
Element img = JsoupUtils.getElementByTag(gl, "img");
|
||||
if (img != null) {
|
||||
// Thumb size
|
||||
Matcher m = PATTERN_THUMB_SIZE.matcher(img.attr("style"));
|
||||
if (m.find()) {
|
||||
gi.thumbWidth = NumberUtils.parseIntSafely(m.group(2), 0);
|
||||
gi.thumbHeight = NumberUtils.parseIntSafely(m.group(1), 0);
|
||||
} else {
|
||||
Log.w(TAG, "Can't parse gallery info thumb size");
|
||||
gi.thumbWidth = 0;
|
||||
gi.thumbHeight = 0;
|
||||
}
|
||||
gi.thumb = EhUtils.handleThumbUrlResolution(img.attr("src"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Posted
|
||||
gi.favoriteSlot = -2;
|
||||
Element posted = e.getElementById("posted_" + gi.gid);
|
||||
if (posted != null) {
|
||||
gi.posted = posted.text().trim();
|
||||
gi.favoriteSlot = parseFavoriteSlot(posted.attr("style"));
|
||||
}
|
||||
if (gi.favoriteSlot == -2) {
|
||||
gi.favoriteSlot = EhDB.containLocalFavorites(gi.gid) ? -1 : -2;
|
||||
}
|
||||
|
||||
// Rating
|
||||
Element it4r = JsoupUtils.getElementByClass(e, "it4r");
|
||||
if (null != it4r) {
|
||||
gi.rating = NumberUtils.parseFloatSafely(parseRating(it4r.attr("style")), -1.0f);
|
||||
} else {
|
||||
Log.w(TAG, "Can't parse gallery info rating");
|
||||
gi.rating = -1.0f;
|
||||
Element ir = JsoupUtils.getElementByClass(e, "ir");
|
||||
if (ir != null) {
|
||||
gi.rating = NumberUtils.parseFloatSafely(parseRating(ir.attr("style")), -1.0f);
|
||||
// TODO The gallery may be rated even if it doesn't has one of these classes
|
||||
gi.rated = ir.hasClass("irr") || ir.hasClass("irg") || ir.hasClass("irb");
|
||||
}
|
||||
// Uploader
|
||||
Element itu = JsoupUtils.getElementByClass(e, "itu");
|
||||
if (null != itu) {
|
||||
gi.uploader = itu.text().trim();
|
||||
} else {
|
||||
Log.w(TAG, "Can't parse gallery info uploader");
|
||||
gi.uploader = "";
|
||||
|
||||
// Uploader and pages
|
||||
Element gl = JsoupUtils.getElementByClass(e, "glhide");
|
||||
int uploaderIndex = 0;
|
||||
int pagesIndex = 1;
|
||||
if (gl == null) {
|
||||
// For extended
|
||||
gl = JsoupUtils.getElementByClass(e, "gl3e");
|
||||
uploaderIndex = 3;
|
||||
pagesIndex = 4;
|
||||
}
|
||||
if (gl != null) {
|
||||
Elements children = gl.children();
|
||||
if (children.size() > uploaderIndex) {
|
||||
Element a = children.get(uploaderIndex).children().first();
|
||||
if (a != null) {
|
||||
gi.uploader = a.text().trim();
|
||||
}
|
||||
}
|
||||
if (children.size() > pagesIndex) {
|
||||
Matcher matcher = PATTERN_PAGES.matcher(children.get(pagesIndex).text());
|
||||
if (matcher.find()) {
|
||||
gi.pages = NumberUtils.parseIntSafely(matcher.group(1), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
// For thumbnail
|
||||
Element gl5t = JsoupUtils.getElementByClass(e, "gl5t");
|
||||
if (gl5t != null) {
|
||||
Element div = gl5t.select("div:nth-child(2)>div:nth-child(2)").first();
|
||||
if (div != null) {
|
||||
Matcher matcher = PATTERN_PAGES.matcher(div.text());
|
||||
if (matcher.find()) {
|
||||
gi.pages = NumberUtils.parseIntSafely(matcher.group(1), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gi.generateSLang();
|
||||
@@ -187,29 +299,59 @@ public class GalleryListParser {
|
||||
Document d = Jsoup.parse(body);
|
||||
|
||||
try {
|
||||
result.pages = parsePages(d, body);
|
||||
} catch (ParseException e) {
|
||||
Element ptt = d.getElementsByClass("ptt").first();
|
||||
Elements es = ptt.child(0).child(0).children();
|
||||
result.pages = Integer.parseInt(es.get(es.size() - 2).text().trim());
|
||||
|
||||
Element e = es.get(es.size() - 1);
|
||||
if (e != null) {
|
||||
e = e.children().first();
|
||||
if (e != null) {
|
||||
String href = e.attr("href");
|
||||
Matcher matcher = PATTERN_NEXT_PAGE.matcher(href);
|
||||
if (matcher.find()) {
|
||||
result.nextPage = NumberUtils.parseIntSafely(matcher.group(1), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
result.noWatchedTags = body.contains("<p>You do not have any watched tags");
|
||||
if (body.contains("No hits found</p>")) {
|
||||
result.pages = 0;
|
||||
//noinspection unchecked
|
||||
result.galleryInfoList = Collections.EMPTY_LIST;
|
||||
return result;
|
||||
} else if (d.getElementsByClass("ptt").isEmpty()) {
|
||||
result.pages = 1;
|
||||
} else {
|
||||
throw e;
|
||||
result.pages = Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Elements es = d.getElementsByClass("itg").first().child(0).children();
|
||||
List<GalleryInfo> list = new ArrayList<>(es.size() - 1);
|
||||
for (int i = 1; i < es.size(); i++) { // First one is table header, skip it
|
||||
Element itg = d.getElementsByClass("itg").first();
|
||||
Elements es;
|
||||
if ("table".equalsIgnoreCase(itg.tagName())) {
|
||||
es = itg.child(0).children();
|
||||
} else {
|
||||
es = itg.children();
|
||||
}
|
||||
List<GalleryInfo> list = new ArrayList<>(es.size());
|
||||
// First one is table header, skip it
|
||||
for (int i = 0; i < es.size(); i++) {
|
||||
GalleryInfo gi = parseGalleryInfo(es.get(i));
|
||||
if (null != gi) {
|
||||
list.add(gi);
|
||||
}
|
||||
}
|
||||
if (list.isEmpty()) {
|
||||
throw new ParseException("No gallery", body);
|
||||
}
|
||||
result.galleryInfoList = list;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
throw new ParseException("Can't parse gallery list", body);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer.client.parser;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class GalleryPageApiParser {
|
||||
|
||||
private static final Pattern PATTERN_IMAGE_URL = Pattern.compile("<img[^>]*src=\"([^\"]+)\" style");
|
||||
private static final Pattern PATTERN_SKIP_HATH_KEY = Pattern.compile("onclick=\"return nl\\('([^\\)]+)'\\)");
|
||||
private static final Pattern PATTERN_ORIGIN_IMAGE_URL = Pattern.compile("<a href=\"([^\"]+)fullimg.php([^\"]+)\">");
|
||||
|
||||
public static Result parse(String body) throws ParseException {
|
||||
try {
|
||||
Matcher m;
|
||||
Result result = new Result();
|
||||
|
||||
JSONObject jo = new JSONObject(body);
|
||||
if (jo.has("error")) {
|
||||
throw new ParseException(jo.getString("error"), body);
|
||||
}
|
||||
|
||||
String i3 = jo.getString("i3");
|
||||
m = PATTERN_IMAGE_URL.matcher(i3);
|
||||
if (m.find()) {
|
||||
result.imageUrl = StringUtils.unescapeXml(StringUtils.trim(m.group(1)));
|
||||
}
|
||||
String i6 = jo.getString("i6");
|
||||
m = PATTERN_SKIP_HATH_KEY.matcher(i6);
|
||||
if (m.find()) {
|
||||
result.skipHathKey = StringUtils.unescapeXml(StringUtils.trim(m.group(1)));
|
||||
}
|
||||
String i7 = jo.getString("i7");
|
||||
m = PATTERN_ORIGIN_IMAGE_URL.matcher(i7);
|
||||
if (m.find()) {
|
||||
result.originImageUrl = StringUtils.unescapeXml(m.group(1)) + "fullimg.php" + StringUtils.unescapeXml(m.group(2));
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(result.imageUrl)) {
|
||||
return result;
|
||||
} else {
|
||||
throw new ParseException("Parse image url and skip hath key error", body);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new ParseException("Can't parse json", body, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Result {
|
||||
public String imageUrl;
|
||||
public String skipHathKey;
|
||||
public String originImageUrl;
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,8 @@
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -29,6 +27,8 @@ public class GalleryPageParser {
|
||||
private static final Pattern PATTERN_IMAGE_URL = Pattern.compile("<img[^>]*src=\"([^\"]+)\" style");
|
||||
private static final Pattern PATTERN_SKIP_HATH_KEY = Pattern.compile("onclick=\"return nl\\('([^\\)]+)'\\)");
|
||||
private static final Pattern PATTERN_ORIGIN_IMAGE_URL = Pattern.compile("<a href=\"([^\"]+)fullimg.php([^\"]+)\">");
|
||||
// TODO Not sure about the size of show keys
|
||||
private static final Pattern PATTERN_SHOW_KEY = Pattern.compile("var showkey=\"([0-9a-z]+)\";");
|
||||
|
||||
public static Result parse(String body) throws ParseException {
|
||||
Matcher m;
|
||||
@@ -45,11 +45,15 @@ public class GalleryPageParser {
|
||||
if (m.find()) {
|
||||
result.originImageUrl = StringUtils.unescapeXml(m.group(1)) + "fullimg.php" + StringUtils.unescapeXml(m.group(2));
|
||||
}
|
||||
m = PATTERN_SHOW_KEY.matcher(body);
|
||||
if (m.find()) {
|
||||
result.showKey = m.group(1);
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(result.imageUrl)) {
|
||||
if (!TextUtils.isEmpty(result.imageUrl) && !TextUtils.isEmpty(result.showKey)) {
|
||||
return result;
|
||||
} else {
|
||||
throw new ParseException("Parse image url and skip hath key error", body);
|
||||
throw new ParseException("Parse image url and show error", body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,5 +61,6 @@ public class GalleryPageParser {
|
||||
public String imageUrl;
|
||||
public String skipHathKey;
|
||||
public String originImageUrl;
|
||||
public String showKey;
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,9 @@
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -26,20 +27,33 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public final class GalleryPageUrlParser {
|
||||
|
||||
public static final Pattern URL_PATTERN = Pattern.compile("https?://(?:" +
|
||||
EhUrl.DOMAIN_EX + "|" + EhUrl.DOMAIN_E + "|" + EhUrl.DOMAIN_LOFI + ")/s/(\\w+)/(\\d+)-(\\d+)");
|
||||
private static final Pattern URL_STRICT_PATTERN = Pattern.compile(
|
||||
"https?://(?:" + EhUrl.DOMAIN_EX + "|" + EhUrl.DOMAIN_E + "|" + EhUrl.DOMAIN_LOFI + ")/s/([0-9a-f]{10})/(\\d+)-(\\d+)");
|
||||
|
||||
private static final Pattern URL_PATTERN = Pattern.compile(
|
||||
"([0-9a-f]{10})/(\\d+)-(\\d+)");
|
||||
|
||||
@Nullable
|
||||
public static Result parse(String url) {
|
||||
return parse(url, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Result parse(String url, boolean strict) {
|
||||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Matcher m = URL_PATTERN.matcher(url);
|
||||
Pattern pattern = strict ? URL_STRICT_PATTERN : URL_PATTERN;
|
||||
Matcher m = pattern.matcher(url);
|
||||
if (m.find()) {
|
||||
Result result = new Result();
|
||||
result.gid = Long.parseLong(m.group(2));
|
||||
result.gid = NumberUtils.parseLongSafely(m.group(2), -1L);
|
||||
result.pToken = m.group(1);
|
||||
result.page = Integer.parseInt(m.group(3)) - 1;
|
||||
result.page = NumberUtils.parseIntSafely(m.group(3), 0) - 1;
|
||||
if (result.gid < 0 || result.page < 0) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import com.hippo.ehviewer.client.exception.EhException;
|
||||
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class GalleryTokenApiParser {
|
||||
@@ -36,7 +36,8 @@ public class GalleryTokenApiParser {
|
||||
JSONObject jo = new JSONObject(body).getJSONArray("tokenlist").getJSONObject(0);
|
||||
try {
|
||||
return jo.getString("token");
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new EhException(jo.getString("error"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
|
||||
import java.text.DateFormat;
|
||||
@@ -39,11 +40,15 @@ public class ParserUtils {
|
||||
return StringUtils.unescapeXml(str).trim();
|
||||
}
|
||||
|
||||
public static int parseInt(String str) {
|
||||
return Integer.parseInt(trim(str).replace(",", ""));
|
||||
public static int parseInt(String str, int defValue) {
|
||||
return NumberUtils.parseIntSafely(trim(str).replace(",", ""), defValue);
|
||||
}
|
||||
|
||||
public static long parseLong(String str) {
|
||||
return Long.parseLong(trim(str).replace(",", ""));
|
||||
public static long parseLong(String str, long defValue) {
|
||||
return NumberUtils.parseLongSafely(trim(str).replace(",", ""), defValue);
|
||||
}
|
||||
|
||||
public static float parseFloat(String str, float defValue) {
|
||||
return NumberUtils.parseFloatSafely(trim(str).replace(",", ""), defValue);
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,9 @@ package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
@@ -43,11 +42,13 @@ public class ProfileParser {
|
||||
} else if (!result.avatar.startsWith("http")) {
|
||||
result.avatar = EhUrl.URL_FORUMS + result.avatar;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
Log.i(TAG, "No avatar");
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Parse forums error", body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer.client.parser;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WhatsHotParser {
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public static List<GalleryInfo> parse(String body) throws ParseException {
|
||||
try {
|
||||
List<GalleryInfo> galleryInfoList = new ArrayList<>(15);
|
||||
Document d = Jsoup.parse(body);
|
||||
Element pp = d.getElementById("pp");
|
||||
Elements id1List = pp.getElementsByClass("id1");
|
||||
for (int i = 0, n = id1List.size(); i < n; i++) {
|
||||
GalleryInfo galleryInfo = new GalleryInfo();
|
||||
Element id1 = id1List.get(i);
|
||||
Element id3 = JsoupUtils.getElementByClass(id1, "id3");
|
||||
Element temp = JsoupUtils.getElementByTag(id3, "a");
|
||||
String url = temp.attr("href");
|
||||
GalleryDetailUrlParser.Result result = GalleryDetailUrlParser.parse(url);
|
||||
galleryInfo.gid = result.gid;
|
||||
galleryInfo.token = result.token;
|
||||
temp = JsoupUtils.getElementByTag(temp, "img");
|
||||
galleryInfo.thumb = EhUtils.handleThumbUrlResolution(temp.attr("src"));
|
||||
galleryInfo.title = temp.attr("title");
|
||||
galleryInfo.generateSLang();
|
||||
galleryInfoList.add(galleryInfo);
|
||||
}
|
||||
return galleryInfoList;
|
||||
} catch (Exception e) {
|
||||
throw new ParseException("Parse whats hot error", body);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,17 +16,22 @@
|
||||
|
||||
package com.hippo.ehviewer.download;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.dao.DownloadInfo;
|
||||
import com.hippo.ehviewer.dao.DownloadLabel;
|
||||
import com.hippo.ehviewer.spider.SpiderDen;
|
||||
import com.hippo.ehviewer.spider.SpiderInfo;
|
||||
import com.hippo.ehviewer.spider.SpiderQueen;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.IoThreadPoolExecutor;
|
||||
import com.hippo.yorozuya.ConcurrentPool;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.ObjectUtils;
|
||||
@@ -34,7 +39,7 @@ import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.collect.LongList;
|
||||
import com.hippo.yorozuya.collect.SparseIJArray;
|
||||
import com.hippo.yorozuya.collect.SparseJLArray;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -289,6 +294,9 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
}
|
||||
// Make sure download is running
|
||||
ensureDownload();
|
||||
|
||||
// Add it to history
|
||||
EhDB.putHistoryInfo(info);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,6 +568,52 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
for (DownloadInfoListener l: mDownloadInfoListeners) {
|
||||
l.onReload();
|
||||
}
|
||||
|
||||
// Ensure download
|
||||
ensureDownload();
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public void resetAllReadingProgress() {
|
||||
LinkedList<DownloadInfo> list = new LinkedList<>(mAllInfoList);
|
||||
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
GalleryInfo galleryInfo = new GalleryInfo();
|
||||
for (DownloadInfo downloadInfo : list) {
|
||||
galleryInfo.gid = downloadInfo.gid;
|
||||
galleryInfo.token = downloadInfo.token;
|
||||
galleryInfo.title = downloadInfo.title;
|
||||
galleryInfo.thumb = downloadInfo.thumb;
|
||||
galleryInfo.category = downloadInfo.category;
|
||||
galleryInfo.posted = downloadInfo.posted;
|
||||
galleryInfo.uploader = downloadInfo.uploader;
|
||||
galleryInfo.rating = downloadInfo.rating;
|
||||
|
||||
UniFile downloadDir = SpiderDen.getGalleryDownloadDir(galleryInfo);
|
||||
if (downloadDir == null) {
|
||||
continue;
|
||||
}
|
||||
UniFile file = downloadDir.findFile(".ehviewer");
|
||||
if (file == null) {
|
||||
continue;
|
||||
}
|
||||
SpiderInfo spiderInfo = SpiderInfo.read(file);
|
||||
if (spiderInfo == null) {
|
||||
continue;
|
||||
}
|
||||
spiderInfo.startPage = 0;
|
||||
|
||||
try {
|
||||
spiderInfo.write(file.openOutputStream());
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Can't write SpiderInfo", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}.executeOnExecutor(IoThreadPoolExecutor.getInstance());
|
||||
}
|
||||
|
||||
// Update in DB
|
||||
|
||||
@@ -16,20 +16,21 @@
|
||||
|
||||
package com.hippo.ehviewer.download;
|
||||
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
@@ -44,7 +45,6 @@ import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.collect.LongList;
|
||||
import com.hippo.yorozuya.collect.SparseJBArray;
|
||||
import com.hippo.yorozuya.collect.SparseJLArray;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@@ -90,6 +90,8 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
private static int sFinishedCount;
|
||||
private static int sDownloadedCount;
|
||||
|
||||
private String CHANNEL_ID;
|
||||
|
||||
public static void clear() {
|
||||
sFailedCount = 0;
|
||||
sFinishedCount = 0;
|
||||
@@ -102,7 +104,12 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
CHANNEL_ID = getPackageName()+".download";
|
||||
mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
|
||||
mNotifyManager.createNotificationChannel(new NotificationChannel(CHANNEL_ID, getString(R.string.download_service),
|
||||
NotificationManager.IMPORTANCE_LOW));
|
||||
}
|
||||
mDownloadManager = EhApplication.getDownloadManager(getApplicationContext());
|
||||
mDownloadManager.setDownloadListener(this);
|
||||
}
|
||||
@@ -208,14 +215,15 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
stopAllIntent.setAction(ACTION_STOP_ALL);
|
||||
PendingIntent piStopAll = PendingIntent.getService(this, 0, stopAllIntent, 0);
|
||||
|
||||
mDownloadingBuilder = new NotificationCompat.Builder(getApplicationContext())
|
||||
mDownloadingBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID)
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download)
|
||||
.setOngoing(true)
|
||||
.setAutoCancel(false)
|
||||
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
|
||||
.setColor(getResources().getColor(R.color.colorPrimary))
|
||||
.addAction(R.drawable.ic_pause_x24, getString(R.string.stat_download_action_stop_all), piStopAll)
|
||||
.setShowWhen(false);
|
||||
.setShowWhen(false)
|
||||
.setChannelId(CHANNEL_ID);
|
||||
|
||||
mDownloadingDelay = new NotificationDelay(this, mNotifyManager, mDownloadingBuilder, ID_DOWNLOADING);
|
||||
}
|
||||
@@ -238,14 +246,15 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
PendingIntent piActivity = PendingIntent.getActivity(DownloadService.this, 0,
|
||||
activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
mDownloadedBuilder = new NotificationCompat.Builder(getApplicationContext())
|
||||
mDownloadedBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID)
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download_done)
|
||||
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
|
||||
.setContentTitle(getString(R.string.stat_download_done_title))
|
||||
.setDeleteIntent(piClear)
|
||||
.setOngoing(false)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(piActivity);
|
||||
.setContentIntent(piActivity)
|
||||
.setChannelId(CHANNEL_ID);
|
||||
|
||||
mDownloadedDelay = new NotificationDelay(this, mNotifyManager, mDownloadedBuilder, ID_DOWNLOADED);
|
||||
}
|
||||
@@ -255,14 +264,15 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
return;
|
||||
}
|
||||
|
||||
m509dBuilder = new NotificationCompat.Builder(getApplicationContext())
|
||||
m509dBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID)
|
||||
.setSmallIcon(R.drawable.ic_stat_alert)
|
||||
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
|
||||
.setContentText(getString(R.string.stat_509_alert_title))
|
||||
.setContentText(getString(R.string.stat_509_alert_text))
|
||||
.setAutoCancel(true)
|
||||
.setOngoing(false)
|
||||
.setCategory(NotificationCompat.CATEGORY_ERROR);
|
||||
.setCategory(NotificationCompat.CATEGORY_ERROR)
|
||||
.setChannelId(CHANNEL_ID);
|
||||
|
||||
m509Delay = new NotificationDelay(this, mNotifyManager, m509dBuilder, ID_509);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer.gallery;
|
||||
|
||||
import com.hippo.a7zip.ArchiveException;
|
||||
import com.hippo.a7zip.InArchive;
|
||||
import com.hippo.a7zip.InStream;
|
||||
import com.hippo.a7zip.PropID;
|
||||
import com.hippo.a7zip.PropType;
|
||||
import com.hippo.a7zip.SequentialOutStream;
|
||||
import com.hippo.unifile.UniRandomAccessFile;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class A7ZipArchive implements Closeable {
|
||||
|
||||
private InArchive archive;
|
||||
|
||||
private A7ZipArchive(InArchive archive) {
|
||||
this.archive = archive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
archive.close();
|
||||
}
|
||||
|
||||
private static boolean isSupportedFilename(String name) {
|
||||
for (String extension : GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS) {
|
||||
if (name.endsWith(extension)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
List<A7ZipArchiveEntry> getArchiveEntries() {
|
||||
List<A7ZipArchiveEntry> entries = new ArrayList<>();
|
||||
|
||||
for (int i = 0, n = archive.getNumberOfEntries(); i < n; i++) {
|
||||
if (!archive.getEntryBooleanProperty(i, PropID.ENCRYPTED)
|
||||
&& !archive.getEntryBooleanProperty(i, PropID.IS_DIR)
|
||||
&& !archive.getEntryBooleanProperty(i, PropID.IS_VOLUME)
|
||||
&& !archive.getEntryBooleanProperty(i, PropID.SOLID)) {
|
||||
String path = archive.getEntryPath(i);
|
||||
if (isSupportedFilename(path.toLowerCase())) {
|
||||
entries.add(new A7ZipArchiveEntry(archive, i, path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
static A7ZipArchive create(UniRandomAccessFile file) throws ArchiveException {
|
||||
InStream store = new UniRandomAccessFileInStream(file);
|
||||
InArchive archive = InArchive.open(store);
|
||||
if ((archive.getArchivePropertyType(PropID.ENCRYPTED) == PropType.BOOL && archive.getArchiveBooleanProperty(PropID.ENCRYPTED))
|
||||
|| (archive.getArchivePropertyType(PropID.SOLID) == PropType.BOOL && archive.getArchiveBooleanProperty(PropID.SOLID))
|
||||
|| (archive.getArchivePropertyType(PropID.IS_VOLUME) == PropType.BOOL && archive.getArchiveBooleanProperty(PropID.IS_VOLUME))) {
|
||||
throw new ArchiveException("Unsupported archive");
|
||||
}
|
||||
return new A7ZipArchive(archive);
|
||||
}
|
||||
|
||||
static class A7ZipArchiveEntry {
|
||||
|
||||
private InArchive archive;
|
||||
private int index;
|
||||
private String path;
|
||||
|
||||
private A7ZipArchiveEntry(InArchive archive, int index, String path) {
|
||||
this.archive = archive;
|
||||
this.index = index;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
void extract(OutputStream os) throws ArchiveException {
|
||||
archive.extractEntry(index, new OutputStreamSequentialOutStream(os));
|
||||
}
|
||||
}
|
||||
|
||||
private static class UniRandomAccessFileInStream implements InStream {
|
||||
|
||||
private UniRandomAccessFile file;
|
||||
|
||||
public UniRandomAccessFileInStream(UniRandomAccessFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seek(long pos) throws IOException {
|
||||
file.seek(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long tell() throws IOException {
|
||||
return file.getFilePointer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long size() throws IOException {
|
||||
return file.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
return file.read(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static class OutputStreamSequentialOutStream implements SequentialOutStream {
|
||||
|
||||
private OutputStream stream;
|
||||
|
||||
public OutputStreamSequentialOutStream(OutputStream stream) {
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
stream.write(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
/*
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer.gallery;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Process;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.a7zip.ArchiveException;
|
||||
import com.hippo.ehviewer.GetText;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.glgallery.GalleryPageView;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.unifile.UniRandomAccessFile;
|
||||
import com.hippo.util.NaturalComparator;
|
||||
import com.hippo.yorozuya.thread.PriorityThread;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ArchiveGalleryProvider extends GalleryProvider2 {
|
||||
|
||||
private static final AtomicInteger sIdGenerator = new AtomicInteger();
|
||||
|
||||
private final UniFile file;
|
||||
|
||||
private Thread archiveThread;
|
||||
private Thread decodeThread;
|
||||
|
||||
private volatile int size = STATE_WAIT;
|
||||
private String error;
|
||||
|
||||
private final Stack<Integer> requests = new Stack<>();
|
||||
private final AtomicInteger extractingIndex = new AtomicInteger(GalleryPageView.INVALID_INDEX);
|
||||
private final LinkedHashMap<Integer, InputStream> streams = new LinkedHashMap<>();
|
||||
private final AtomicInteger decodingIndex = new AtomicInteger(GalleryPageView.INVALID_INDEX);
|
||||
|
||||
public ArchiveGalleryProvider(Context context, Uri uri) {
|
||||
file = UniFile.fromUri(context, uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
super.start();
|
||||
|
||||
int id = sIdGenerator.incrementAndGet();
|
||||
|
||||
archiveThread = new PriorityThread(
|
||||
new ArchiveTask(), "ArchiveTask" + '-' + id, Process.THREAD_PRIORITY_BACKGROUND);
|
||||
archiveThread.start();
|
||||
|
||||
decodeThread = new PriorityThread(
|
||||
new DecodeTask(), "DecodeTask" + '-' + id, Process.THREAD_PRIORITY_BACKGROUND);
|
||||
decodeThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
super.stop();
|
||||
|
||||
if (archiveThread != null) {
|
||||
archiveThread.interrupt();
|
||||
archiveThread = null;
|
||||
}
|
||||
if (decodeThread != null) {
|
||||
decodeThread.interrupt();
|
||||
decodeThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRequest(int index) {
|
||||
boolean inDecodeTask;
|
||||
synchronized (streams) {
|
||||
inDecodeTask = streams.keySet().contains(index) || index == decodingIndex.get();
|
||||
}
|
||||
|
||||
synchronized (requests) {
|
||||
boolean inArchiveTask = requests.contains(index) || index == extractingIndex.get();
|
||||
if (!inArchiveTask && !inDecodeTask) {
|
||||
requests.add(index);
|
||||
requests.notify();
|
||||
}
|
||||
}
|
||||
notifyPageWait(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onForceRequest(int index) {
|
||||
onRequest(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelRequest(int index) {
|
||||
synchronized (requests) {
|
||||
requests.remove(Integer.valueOf(index));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getImageFilename(int index) {
|
||||
// TODO
|
||||
return Integer.toString(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(int index, @NonNull UniFile file) {
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public UniFile save(int index, @NonNull UniFile dir, @NonNull String filename) {
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
private class ArchiveTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
UniRandomAccessFile uraf = null;
|
||||
if (file != null) {
|
||||
try {
|
||||
uraf = file.createRandomAccessFile("r");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (uraf == null) {
|
||||
size = STATE_ERROR;
|
||||
error = GetText.getString(R.string.error_reading_failed);
|
||||
notifyDataChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
A7ZipArchive archive = null;
|
||||
try {
|
||||
archive = A7ZipArchive.create(uraf);
|
||||
} catch (ArchiveException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (archive == null) {
|
||||
size = STATE_ERROR;
|
||||
error = GetText.getString(R.string.error_invalid_archive);
|
||||
notifyDataChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
List<A7ZipArchive.A7ZipArchiveEntry> entries = archive.getArchiveEntries();
|
||||
Collections.sort(entries, naturalComparator);
|
||||
|
||||
// Update size and notify changed
|
||||
size = entries.size();
|
||||
notifyDataChanged();
|
||||
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
int index;
|
||||
synchronized (requests) {
|
||||
if (requests.isEmpty()) {
|
||||
try {
|
||||
requests.wait();
|
||||
} catch (InterruptedException e) {
|
||||
// Interrupted
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
index = requests.pop();
|
||||
extractingIndex.lazySet(index);
|
||||
}
|
||||
|
||||
// Check index valid
|
||||
if (index < 0 || index >= entries.size()) {
|
||||
extractingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_out_of_range));
|
||||
continue;
|
||||
}
|
||||
|
||||
Pipe pipe = new Pipe(4 * 1024);
|
||||
|
||||
synchronized (streams) {
|
||||
if (streams.get(index) != null) {
|
||||
continue;
|
||||
}
|
||||
streams.put(index, pipe.getInputStream());
|
||||
streams.notify();
|
||||
}
|
||||
|
||||
try {
|
||||
entries.get(index).extract(pipe.getOutputStream());
|
||||
} catch (ArchiveException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
extractingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class DecodeTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
int index;
|
||||
InputStream stream;
|
||||
synchronized (streams) {
|
||||
if (streams.isEmpty()) {
|
||||
try {
|
||||
streams.wait();
|
||||
} catch (InterruptedException e) {
|
||||
// Interrupted
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
Iterator<Map.Entry<Integer, InputStream>> iterator = streams.entrySet().iterator();
|
||||
Map.Entry<Integer, InputStream> entry = iterator.next();
|
||||
iterator.remove();
|
||||
index = entry.getKey();
|
||||
stream = entry.getValue();
|
||||
decodingIndex.lazySet(index);
|
||||
}
|
||||
|
||||
try {
|
||||
Image image = Image.decode(stream, true);
|
||||
if (image != null) {
|
||||
notifyPageSucceed(index, image);
|
||||
} else {
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_decoding_failed));
|
||||
}
|
||||
} finally {
|
||||
decodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Comparator<A7ZipArchive.A7ZipArchiveEntry> naturalComparator = new Comparator<A7ZipArchive.A7ZipArchiveEntry>() {
|
||||
private NaturalComparator comparator = new NaturalComparator();
|
||||
@Override
|
||||
public int compare(A7ZipArchive.A7ZipArchiveEntry o1, A7ZipArchive.A7ZipArchiveEntry o2) {
|
||||
return comparator.compare(o1.getPath(), o2.getPath());
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -17,26 +17,25 @@
|
||||
package com.hippo.ehviewer.gallery;
|
||||
|
||||
import android.os.Process;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.GetText;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.glgallery.GalleryPageView;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.unifile.FilenameFilter;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.NaturalComparator;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
import com.hippo.yorozuya.thread.PriorityThread;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -173,7 +172,7 @@ public class DirGalleryProvider extends GalleryProvider2 implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
// It may take a long time, so run it in new thread
|
||||
UniFile[] files = mDir.listFiles();
|
||||
UniFile[] files = mDir.listFiles(imageFilter);
|
||||
|
||||
if (files == null) {
|
||||
mSize = STATE_ERROR;
|
||||
@@ -187,7 +186,7 @@ public class DirGalleryProvider extends GalleryProvider2 implements Runnable {
|
||||
}
|
||||
|
||||
// Sort it
|
||||
Arrays.sort(files);
|
||||
Arrays.sort(files, naturalComparator);
|
||||
|
||||
// Put file list
|
||||
mFileList.lazySet(files);
|
||||
@@ -244,11 +243,14 @@ public class DirGalleryProvider extends GalleryProvider2 implements Runnable {
|
||||
Log.i(TAG, "ImageDecoder end");
|
||||
}
|
||||
|
||||
private static class ImageFilter implements FilenameFilter {
|
||||
private static FilenameFilter imageFilter =
|
||||
(dir, name) -> StringUtils.endsWith(name.toLowerCase(), SUPPORT_IMAGE_EXTENSIONS);
|
||||
|
||||
private static Comparator<UniFile> naturalComparator = new Comparator<UniFile>() {
|
||||
private NaturalComparator comparator = new NaturalComparator();
|
||||
@Override
|
||||
public boolean accept(File dir, String filename) {
|
||||
return StringUtils.endsWith(filename.toLowerCase(), SUPPORT_IMAGE_EXTENSIONS);
|
||||
public int compare(UniFile o1, UniFile o2) {
|
||||
return comparator.compare(o1.getName(), o2.getName());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -17,16 +17,14 @@
|
||||
package com.hippo.ehviewer.gallery;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.spider.SpiderQueen;
|
||||
import com.hippo.glgallery.GalleryProvider;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class EhGalleryProvider extends GalleryProvider2 implements SpiderQueen.OnSpiderListener {
|
||||
@@ -73,7 +71,7 @@ public class EhGalleryProvider extends GalleryProvider2 implements SpiderQueen.O
|
||||
@NonNull
|
||||
@Override
|
||||
public String getImageFilename(int index) {
|
||||
return String.format(Locale.US, "%d-%08d", mGalleryInfo.gid, index + 1);
|
||||
return String.format(Locale.US, "%d-%s-%08d", mGalleryInfo.gid, mGalleryInfo.token, index + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
package com.hippo.ehviewer.gallery;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.glgallery.GalleryProvider;
|
||||
import com.hippo.unifile.UniFile;
|
||||
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer.gallery;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
class Pipe {
|
||||
|
||||
private final int capacity;
|
||||
private final byte[] buffer;
|
||||
|
||||
private int head = 0;
|
||||
private int tail = 0;
|
||||
private boolean full = false;
|
||||
|
||||
private boolean inClosed = false;
|
||||
private boolean outClosed = false;
|
||||
|
||||
private InputStream inputStream = new InputStream() {
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
synchronized (Pipe.this) {
|
||||
byte[] bytes = new byte[1];
|
||||
if (read(bytes, 0, 1) != -1) {
|
||||
return bytes[0];
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(@NonNull byte[] b, int off, int len) throws IOException {
|
||||
synchronized (Pipe.this) {
|
||||
for (;;) {
|
||||
if (inClosed) {
|
||||
throw new IOException("The InputStream is closed");
|
||||
}
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (head == tail && !full) {
|
||||
if (outClosed) {
|
||||
// No bytes available and the OutputStream is closed. So it's the end.
|
||||
return -1;
|
||||
} else {
|
||||
// Wait for OutputStream write bytes
|
||||
try {
|
||||
Pipe.this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
throw new IOException("The thread interrupted", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int read = Math.min(len, (head < tail ? tail : capacity) - head);
|
||||
System.arraycopy(buffer, head, b, off, read);
|
||||
head += read;
|
||||
if (head == capacity) {
|
||||
head = 0;
|
||||
}
|
||||
full = false;
|
||||
Pipe.this.notifyAll();
|
||||
return read;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
synchronized (Pipe.this) {
|
||||
inClosed = true;
|
||||
Pipe.this.notifyAll();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private OutputStream outputStream = new OutputStream() {
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
synchronized (Pipe.this) {
|
||||
byte[] bytes = new byte[] { (byte) b};
|
||||
write(bytes, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NonNull byte[] b, int off, int len) throws IOException {
|
||||
synchronized (Pipe.this) {
|
||||
while (len != 0) {
|
||||
if (outClosed) {
|
||||
throw new IOException("The OutputStream is closed");
|
||||
}
|
||||
if (inClosed) {
|
||||
throw new IOException("The InputStream is closed");
|
||||
}
|
||||
|
||||
if (head == tail && full) {
|
||||
// The buffer is full, wait for InputStream read bytes
|
||||
try {
|
||||
Pipe.this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
throw new IOException("The thread interrupted", e);
|
||||
}
|
||||
} else {
|
||||
int write = Math.min(len, (head <= tail ? capacity : head) - tail);
|
||||
System.arraycopy(b, off, buffer, tail, write);
|
||||
off += write;
|
||||
len -= write;
|
||||
tail += write;
|
||||
if (tail == capacity) {
|
||||
tail = 0;
|
||||
}
|
||||
if (head == tail) {
|
||||
full = true;
|
||||
}
|
||||
Pipe.this.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
synchronized (Pipe.this) {
|
||||
outClosed = true;
|
||||
Pipe.this.notifyAll();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Pipe(int capacity) {
|
||||
this.capacity = capacity;
|
||||
this.buffer = new byte[capacity];
|
||||
}
|
||||
|
||||
InputStream getInputStream() {
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
OutputStream getOutputStream() {
|
||||
return outputStream;
|
||||
}
|
||||
}
|
||||
@@ -1,228 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer.gallery;
|
||||
|
||||
import android.os.Process;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hippo.ehviewer.GetText;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.glgallery.GalleryPageView;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
import com.hippo.yorozuya.thread.PriorityThread;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipException;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
public class ZipGalleryProvider extends GalleryProvider2 implements Runnable {
|
||||
|
||||
private static final String TAG = ZipGalleryProvider.class.getSimpleName();
|
||||
private static final AtomicInteger sIdGenerator = new AtomicInteger();
|
||||
|
||||
private final File mFile;
|
||||
private final Stack<Integer> mRequests = new Stack<>();
|
||||
private final AtomicInteger mDecodingIndex = new AtomicInteger(GalleryPageView.INVALID_INDEX);
|
||||
@Nullable
|
||||
private Thread mBgThread;
|
||||
private volatile int mSize = STATE_WAIT;
|
||||
private String mError;
|
||||
|
||||
public ZipGalleryProvider(File file) {
|
||||
mFile = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
super.start();
|
||||
|
||||
mBgThread = new PriorityThread(this, TAG + '-' + sIdGenerator.incrementAndGet(),
|
||||
Process.THREAD_PRIORITY_BACKGROUND);
|
||||
mBgThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
super.stop();
|
||||
|
||||
if (mBgThread != null) {
|
||||
mBgThread.interrupt();
|
||||
mBgThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRequest(int index) {
|
||||
synchronized (mRequests) {
|
||||
if (!mRequests.contains(index) && index != mDecodingIndex.get()) {
|
||||
mRequests.add(index);
|
||||
mRequests.notify();
|
||||
}
|
||||
}
|
||||
notifyPageWait(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onForceRequest(int index) {
|
||||
onRequest(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelRequest(int index) {
|
||||
synchronized (mRequests) {
|
||||
mRequests.remove(Integer.valueOf(index));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getError() {
|
||||
return mError;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getImageFilename(int index) {
|
||||
// TODO
|
||||
return Integer.toString(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(int index, @NonNull UniFile file) {
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public UniFile save(int index, @NonNull UniFile dir, @NonNull String filename) {
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ZipFile zipFile = null;
|
||||
try {
|
||||
zipFile = new ZipFile(mFile);
|
||||
} catch (ZipException e) {
|
||||
mError = GetText.getString(R.string.error_invalid_zip_file);
|
||||
} catch (FileNotFoundException e) {
|
||||
mError = GetText.getString(R.string.error_not_found);
|
||||
} catch (IOException e) {
|
||||
mError = GetText.getString(R.string.error_reading_failed);
|
||||
}
|
||||
|
||||
// Check zip file null
|
||||
if (zipFile == null) {
|
||||
mSize = STATE_ERROR;
|
||||
|
||||
// Notify to to show error
|
||||
notifyDataChanged();
|
||||
|
||||
Log.i(TAG, "ImageDecoder end with error");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all image name
|
||||
List<String> filenames = new ArrayList<>(zipFile.size());
|
||||
Enumeration<? extends ZipEntry> enumeration = zipFile.entries();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
ZipEntry zipEntry = enumeration.nextElement();
|
||||
String filename = zipEntry.getName();
|
||||
if (!zipEntry.isDirectory() && StringUtils.endsWith(filename, SUPPORT_IMAGE_EXTENSIONS)) {
|
||||
filenames.add(filename);
|
||||
}
|
||||
}
|
||||
Collections.sort(filenames);
|
||||
|
||||
// Update size and notify changed
|
||||
mSize = filenames.size();
|
||||
notifyDataChanged();
|
||||
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
int index;
|
||||
synchronized (mRequests) {
|
||||
if (mRequests.isEmpty()) {
|
||||
try {
|
||||
mRequests.wait();
|
||||
} catch (InterruptedException e) {
|
||||
// Interrupted
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
index = mRequests.pop();
|
||||
mDecodingIndex.lazySet(index);
|
||||
}
|
||||
|
||||
// Check index valid
|
||||
if (index < 0 || index >= filenames.size()) {
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_out_of_range));
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
ZipEntry zipEntry = zipFile.getEntry(filenames.get(index));
|
||||
if (zipEntry != null) {
|
||||
InputStream is = zipFile.getInputStream(zipEntry);
|
||||
Image image = Image.decode(is, true);
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
if (image != null) {
|
||||
notifyPageSucceed(index, image);
|
||||
} else {
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_decoding_failed));
|
||||
}
|
||||
} else {
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_reading_failed));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_reading_failed));
|
||||
}
|
||||
}
|
||||
|
||||
// Clear
|
||||
try {
|
||||
zipFile.close();
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
Log.i(TAG, "ImageDecoder end");
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,9 @@
|
||||
package com.hippo.ehviewer.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
@@ -62,6 +61,9 @@ public class CleanRedundancyPreference extends TaskPreference {
|
||||
// True for cleared
|
||||
private boolean clearFile(UniFile file) {
|
||||
String name = file.getName();
|
||||
if (name == null) {
|
||||
return false;
|
||||
}
|
||||
int index = name.indexOf('-');
|
||||
if (index >= 0) {
|
||||
name = name.substring(0, index);
|
||||
|
||||
+1
-2
@@ -17,9 +17,8 @@
|
||||
package com.hippo.ehviewer.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.preference.MessagePreference;
|
||||
|
||||
@@ -17,10 +17,9 @@
|
||||
package com.hippo.ehviewer.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.widget.CategoryTable;
|
||||
|
||||
+1
-2
@@ -17,11 +17,10 @@
|
||||
package com.hippo.ehviewer.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.preference.DialogPreference;
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.GetText;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.util.ReadableTime;
|
||||
import java.io.File;
|
||||
|
||||
public class ExportDataPreference extends TaskPreference {
|
||||
|
||||
public ExportDataPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ExportDataPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public ExportDataPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected Task onCreateTask() {
|
||||
return new ExportDataTask(getContext());
|
||||
}
|
||||
|
||||
private static class ExportDataTask extends Task {
|
||||
|
||||
public ExportDataTask(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doInBackground(Void... voids) {
|
||||
File dir = AppConfig.getExternalDataDir();
|
||||
if (dir != null) {
|
||||
File file = new File(dir, ReadableTime.getFilenamableTime(System.currentTimeMillis()) + ".db");
|
||||
if (EhDB.exportDB(getApplication(), file)) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Object o) {
|
||||
Toast.makeText(getApplication(),
|
||||
(o instanceof File)
|
||||
? GetText.getString(R.string.settings_advanced_export_data_to, ((File) o).getPath())
|
||||
: GetText.getString(R.string.settings_advanced_export_data_failed),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
super.onPostExecute(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer.preference;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.Toast;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhCookieStore;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.preference.MessagePreference;
|
||||
import com.hippo.text.Html;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import okhttp3.Cookie;
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
public class IdentityCookiePreference extends MessagePreference {
|
||||
|
||||
private String message;
|
||||
|
||||
public IdentityCookiePreference(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public IdentityCookiePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public IdentityCookiePreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
EhCookieStore store = EhApplication.getEhCookieStore(getContext());
|
||||
List<Cookie> eCookies = store.getCookies(HttpUrl.get(EhUrl.HOST_E));
|
||||
List<Cookie> exCookies = store.getCookies(HttpUrl.get(EhUrl.HOST_EX));
|
||||
List<Cookie> cookies = new LinkedList<>(eCookies);
|
||||
cookies.addAll(exCookies);
|
||||
|
||||
String ipbMemberId = null;
|
||||
String ipbPassHash = null;
|
||||
String igneous = null;
|
||||
|
||||
for (int i = 0, n = cookies.size(); i < n; i++) {
|
||||
Cookie cookie = cookies.get(i);
|
||||
switch (cookie.name()) {
|
||||
case EhCookieStore.KEY_IPD_MEMBER_ID:
|
||||
ipbMemberId = cookie.value();
|
||||
break;
|
||||
case EhCookieStore.KEY_IPD_PASS_HASH:
|
||||
ipbPassHash = cookie.value();
|
||||
break;
|
||||
case EhCookieStore.KEY_IGNEOUS:
|
||||
igneous = cookie.value();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ipbMemberId != null || ipbPassHash != null || igneous != null) {
|
||||
message = EhCookieStore.KEY_IPD_MEMBER_ID + ": " + ipbMemberId + "<br>"
|
||||
+ EhCookieStore.KEY_IPD_PASS_HASH + ": " + ipbPassHash + "<br>"
|
||||
+ EhCookieStore.KEY_IGNEOUS + ": " + igneous;
|
||||
setDialogMessage(Html.fromHtml(getContext().getString(R.string.settings_eh_identity_cookies_signed, message)));
|
||||
message = message.replace("<br>", "\n");
|
||||
} else {
|
||||
setDialogMessage(getContext().getString(R.string.settings_eh_identity_cookies_tourist));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
||||
super.onPrepareDialogBuilder(builder);
|
||||
if (message != null) {
|
||||
builder.setPositiveButton(R.string.settings_eh_identity_cookies_copy, (dialog, which) -> {
|
||||
ClipboardManager cmb = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cmb.setPrimaryClip(ClipData.newPlainText(null, message));
|
||||
Toast.makeText(getContext(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
|
||||
|
||||
IdentityCookiePreference.this.onClick(dialog, which);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+56
-59
@@ -20,64 +20,71 @@ import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
|
||||
import android.widget.Spinner;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.EhProxySelector;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.network.InetValidator;
|
||||
import com.hippo.preference.DialogPreference;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
public class HatHProxyPreference extends DialogPreference implements View.OnClickListener {
|
||||
public class ProxyPreference extends DialogPreference implements View.OnClickListener {
|
||||
|
||||
@Nullable
|
||||
private SwitchCompat mEnable;
|
||||
@Nullable
|
||||
private Spinner mType;
|
||||
private TextInputLayout mIpInputLayout;
|
||||
@Nullable
|
||||
private EditText mIp;
|
||||
@Nullable
|
||||
private TextInputLayout mPortInputLayout;
|
||||
@Nullable
|
||||
private EditText mPort;
|
||||
@Nullable
|
||||
private TextInputLayout mPasskeyInputLayout;
|
||||
@Nullable
|
||||
private EditText mPasskey;
|
||||
|
||||
public HatHProxyPreference(Context context) {
|
||||
public ProxyPreference(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public HatHProxyPreference(Context context, AttributeSet attrs) {
|
||||
public ProxyPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public HatHProxyPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
public ProxyPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setDialogLayoutResource(R.layout.preference_dialog_hath_proxy);
|
||||
updateSummary(Settings.getHathProxy(), Settings.getHathIp(), Settings.getHathPort());
|
||||
setDialogLayoutResource(R.layout.preference_dialog_proxy);
|
||||
updateSummary(Settings.getProxyType(), Settings.getProxyIp(), Settings.getProxyPort());
|
||||
}
|
||||
|
||||
private void updateSummary(boolean hathProxy, String hathIp, int hathPort) {
|
||||
if (InetValidator.isValidInet4Address(hathIp) && InetValidator.isValidInetPort(hathPort)) {
|
||||
private String getProxyTypeText(Context context, int type) {
|
||||
String[] array = context.getResources().getStringArray(R.array.proxy_types);
|
||||
return array[MathUtils.clamp(type, 0, array.length - 1)];
|
||||
}
|
||||
|
||||
private void updateSummary(int type, String ip, int port) {
|
||||
if ((type == EhProxySelector.TYPE_HTTP || type == EhProxySelector.TYPE_SOCKS)
|
||||
&& (TextUtils.isEmpty(ip) || !InetValidator.isValidInetPort(port)) ) {
|
||||
type = EhProxySelector.TYPE_SYSTEM;
|
||||
}
|
||||
|
||||
if (type == EhProxySelector.TYPE_HTTP || type == EhProxySelector.TYPE_SOCKS) {
|
||||
Context context = getContext();
|
||||
setSummary(context.getString(R.string.settings_eh_hath_proxy_summary_1,
|
||||
context.getString(hathProxy ? R.string.enabled : R.string.disabled), hathIp, hathPort));
|
||||
setSummary(context.getString(R.string.settings_advanced_proxy_summary_1,
|
||||
getProxyTypeText(context, type),
|
||||
ip,
|
||||
port));
|
||||
} else {
|
||||
setSummary(R.string.settings_eh_hath_proxy_summary_2);
|
||||
Context context = getContext();
|
||||
setSummary(context.getString(R.string.settings_advanced_proxy_summary_2,
|
||||
getProxyTypeText(context, type)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,73 +101,63 @@ public class HatHProxyPreference extends DialogPreference implements View.OnClic
|
||||
|
||||
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(this);
|
||||
|
||||
mEnable = (SwitchCompat) ViewUtils.$$(dialog, R.id.enable);
|
||||
mType = (Spinner) ViewUtils.$$(dialog, R.id.type);
|
||||
mIpInputLayout = (TextInputLayout) ViewUtils.$$(dialog, R.id.ip_input_layout);
|
||||
mIp = (EditText) ViewUtils.$$(dialog, R.id.ip);
|
||||
mPortInputLayout = (TextInputLayout) ViewUtils.$$(dialog, R.id.port_input_layout);
|
||||
mPort = (EditText) ViewUtils.$$(dialog, R.id.port);
|
||||
mPasskeyInputLayout = (TextInputLayout) ViewUtils.$$(dialog, R.id.passkey_input_layout);
|
||||
mPasskey = (EditText) ViewUtils.$$(dialog, R.id.passkey);
|
||||
|
||||
mEnable.setChecked(Settings.getHathProxy());
|
||||
String ip = Settings.getHathIp();
|
||||
if (!InetValidator.isValidInet4Address(ip)) {
|
||||
ip = null;
|
||||
}
|
||||
int type = Settings.getProxyType();
|
||||
String[] array = getContext().getResources().getStringArray(R.array.proxy_types);
|
||||
mType.setSelection(MathUtils.clamp(type, 0, array.length));
|
||||
|
||||
mIp.setText(Settings.getProxyIp());
|
||||
|
||||
String portString;
|
||||
int port = Settings.getHathPort();
|
||||
int port = Settings.getProxyPort();
|
||||
if (!InetValidator.isValidInetPort(port)) {
|
||||
portString = null;
|
||||
} else {
|
||||
portString = Integer.toString(Settings.getHathPort());
|
||||
portString = Integer.toString(port);
|
||||
}
|
||||
mIp.setText(ip);
|
||||
mPort.setText(portString);
|
||||
mPasskey.setText(Settings.getHathPasskey());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
mEnable = null;
|
||||
mType = null;
|
||||
mIpInputLayout = null;
|
||||
mIp = null;
|
||||
mPortInputLayout = null;
|
||||
mPort = null;
|
||||
mPasskeyInputLayout = null;
|
||||
mPasskey = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Dialog dialog = getDialog();
|
||||
Context context = getContext();
|
||||
if (null == dialog || null == context || null == mEnable ||
|
||||
if (null == dialog || null == context || null == mType ||
|
||||
null == mIpInputLayout || null == mIp ||
|
||||
null == mPortInputLayout || null == mPort ||
|
||||
null == mPasskeyInputLayout || null == mPasskey) {
|
||||
null == mPortInputLayout || null == mPort) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean enable = mEnable.isChecked();
|
||||
int type = mType.getSelectedItemPosition();
|
||||
|
||||
String ip = mIp.getText().toString().trim();
|
||||
if (ip.isEmpty()) {
|
||||
if (enable) {
|
||||
if (type == EhProxySelector.TYPE_HTTP || type == EhProxySelector.TYPE_SOCKS) {
|
||||
mIpInputLayout.setError(context.getString(R.string.text_is_empty));
|
||||
return;
|
||||
}
|
||||
} else if (!InetValidator.isValidInet4Address(ip)) {
|
||||
mIpInputLayout.setError(context.getString(R.string.domain_not_supported));
|
||||
return;
|
||||
} else {
|
||||
mIpInputLayout.setError(null);
|
||||
}
|
||||
mIpInputLayout.setError(null);
|
||||
|
||||
int port;
|
||||
String portString = mPort.getText().toString().trim();
|
||||
if (portString.isEmpty()) {
|
||||
if (enable) {
|
||||
if (type == EhProxySelector.TYPE_HTTP || type == EhProxySelector.TYPE_SOCKS) {
|
||||
mPortInputLayout.setError(context.getString(R.string.text_is_empty));
|
||||
return;
|
||||
} else {
|
||||
@@ -173,19 +170,19 @@ public class HatHProxyPreference extends DialogPreference implements View.OnClic
|
||||
port = -1;
|
||||
}
|
||||
if (!InetValidator.isValidInetPort(port)) {
|
||||
mPortInputLayout.setError(context.getString(R.string.invalid_port));
|
||||
mPortInputLayout.setError(context.getString(R.string.proxy_invalid_port));
|
||||
return;
|
||||
}
|
||||
}
|
||||
mPortInputLayout.setError(null);
|
||||
|
||||
String passkey = mPasskey.getText().toString();
|
||||
Settings.putProxyType(type);
|
||||
Settings.putProxyIp(ip);
|
||||
Settings.putProxyPort(port);
|
||||
|
||||
Settings.putHathProxy(enable);
|
||||
Settings.putHathIp(ip);
|
||||
Settings.putHathPort(port);
|
||||
Settings.putHathPasskey(passkey);
|
||||
updateSummary(type, ip, port);
|
||||
|
||||
updateSummary(enable, ip, port);
|
||||
EhApplication.getEhProxySelector(getContext()).updateProxy();
|
||||
|
||||
dialog.dismiss();
|
||||
}
|
||||
@@ -20,28 +20,27 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.preference.Preference;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhEngine;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.download.DownloadManager;
|
||||
import com.hippo.ehviewer.spider.SpiderInfo;
|
||||
import com.hippo.ehviewer.spider.SpiderQueen;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class RestoreDownloadPreference extends TaskPreference {
|
||||
@@ -120,6 +119,10 @@ public class RestoreDownloadPreference extends TaskPreference {
|
||||
List<RestoreItem> restoreItemList = new ArrayList<>();
|
||||
|
||||
UniFile[] files = dir.listFiles();
|
||||
if (files == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (UniFile file: files) {
|
||||
RestoreItem restoreItem = getRestoreItem(file);
|
||||
if (null != restoreItem) {
|
||||
@@ -132,8 +135,9 @@ public class RestoreDownloadPreference extends TaskPreference {
|
||||
}
|
||||
|
||||
try {
|
||||
return EhEngine.fillGalleryListByApi(null, mHttpClient, new ArrayList<GalleryInfo>(restoreItemList));
|
||||
} catch (Exception e) {
|
||||
return EhEngine.fillGalleryListByApi(null, mHttpClient, new ArrayList<GalleryInfo>(restoreItemList), EhUrl.getReferer());
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhCookieStore;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.preference.ActivityPreference;
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
public class SignInRequiredActivityPreference extends ActivityPreference {
|
||||
|
||||
private View view;
|
||||
|
||||
public SignInRequiredActivityPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public SignInRequiredActivityPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public SignInRequiredActivityPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View onCreateView(ViewGroup parent) {
|
||||
return view = super.onCreateView(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
EhCookieStore store = EhApplication.getEhCookieStore(getContext());
|
||||
HttpUrl e = HttpUrl.get(EhUrl.HOST_E);
|
||||
HttpUrl ex = HttpUrl.get(EhUrl.HOST_EX);
|
||||
|
||||
if (store.contains(e, EhCookieStore.KEY_IPD_MEMBER_ID) ||
|
||||
store.contains(e, EhCookieStore.KEY_IPD_PASS_HASH) ||
|
||||
store.contains(ex, EhCookieStore.KEY_IPD_MEMBER_ID) ||
|
||||
store.contains(ex, EhCookieStore.KEY_IPD_PASS_HASH)) {
|
||||
super.onClick();
|
||||
} else {
|
||||
if (view != null) {
|
||||
Snackbar.make(view, R.string.error_please_login_first, 3000).show();
|
||||
} else {
|
||||
Toast.makeText(getContext(), R.string.error_please_login_first, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,9 @@
|
||||
package com.hippo.ehviewer.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.preference.MessagePreference;
|
||||
|
||||
@@ -21,15 +21,16 @@ import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.customview.view.AbsSavedState;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.preference.DialogPreference;
|
||||
import com.hippo.util.IoThreadPoolExecutor;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
|
||||
public abstract class TaskPreference extends DialogPreference {
|
||||
@@ -62,7 +63,7 @@ public abstract class TaskPreference extends DialogPreference {
|
||||
mTask = onCreateTask();
|
||||
mTask.setPreference(this);
|
||||
mTaskId = ((EhApplication) getContext().getApplicationContext()).putGlobalStuff(mTask);
|
||||
mTask.execute();
|
||||
mTask.executeOnExecutor(IoThreadPoolExecutor.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,11 +124,11 @@ public abstract class TaskPreference extends DialogPreference {
|
||||
super.onRestoreInstanceState(myState.getSuperState());
|
||||
}
|
||||
|
||||
private static class SavedState extends BaseSavedState {
|
||||
private static class SavedState extends AbsSavedState {
|
||||
int asyncTaskId;
|
||||
|
||||
public SavedState(Parcel source) {
|
||||
super(source);
|
||||
super(source, SavedState.class.getClassLoader());
|
||||
asyncTaskId = source.readInt();
|
||||
}
|
||||
|
||||
@@ -165,6 +166,10 @@ public abstract class TaskPreference extends DialogPreference {
|
||||
mApplication = (EhApplication) context.getApplicationContext();
|
||||
}
|
||||
|
||||
public EhApplication getApplication() {
|
||||
return mApplication;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TaskPreference getPreference() {
|
||||
return mPreference;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.hippo.ehviewer.shortcuts;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.hippo.ehviewer.download.DownloadService;
|
||||
|
||||
/**
|
||||
* Created by onlymash on 3/25/18.
|
||||
*/
|
||||
|
||||
public class ShortcutsActivity extends Activity{
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
String action = null;
|
||||
Intent intent = getIntent();
|
||||
if (intent != null){
|
||||
action = intent.getAction();
|
||||
if (action != null && (action.equals(DownloadService.ACTION_START_ALL) ||
|
||||
action.equals(DownloadService.ACTION_STOP_ALL))){
|
||||
startService(new Intent(this, DownloadService.class).setAction(action));
|
||||
}
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,8 @@ package com.hippo.ehviewer.spider;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.beerbelly.SimpleDiskCache;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
@@ -38,7 +37,6 @@ import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.Utilities;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@@ -323,7 +321,12 @@ public final class SpiderDen {
|
||||
@Nullable
|
||||
public OutputStreamPipe openOutputStreamPipe(int index, @Nullable String extension) {
|
||||
if (mMode == SpiderQueen.MODE_READ) {
|
||||
return openCacheOutputStreamPipe(index);
|
||||
// Return the download pipe is the gallery has been downloaded
|
||||
OutputStreamPipe pipe = openDownloadOutputStreamPipe(index, extension);
|
||||
if (pipe == null) {
|
||||
pipe = openCacheOutputStreamPipe(index);
|
||||
}
|
||||
return pipe;
|
||||
} else if (mMode == SpiderQueen.MODE_DOWNLOAD) {
|
||||
return openDownloadOutputStreamPipe(index, extension);
|
||||
} else {
|
||||
|
||||
Loaded 100 of 443 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user