Compare commits
148 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a4f2f848e | ||
|
|
85fc3a024c | ||
|
|
eeb536b1ac | ||
|
|
5b8e8d76c0 | ||
|
|
73cf2964b2 | ||
|
|
8372f9b5de | ||
|
|
d7181e35e7 | ||
|
|
55d824bb94 | ||
|
|
229d9fa2ae | ||
|
|
3eb68e1ff9 | ||
|
|
b103589bba | ||
|
|
0726c037a4 | ||
|
|
0ff64931e0 | ||
|
|
2374c96009 | ||
|
|
2dd51117e9 | ||
|
|
6c5f3c7d97 | ||
|
|
626bb20edb | ||
|
|
d363869dab | ||
|
|
774f33c63d | ||
|
|
079427346a | ||
|
|
a1a3125834 | ||
|
|
fc9c8f8a79 | ||
|
|
c06923dbdf | ||
|
|
66ca51cc73 | ||
|
|
bf45480366 | ||
|
|
28618e394e | ||
|
|
9762a466ce | ||
|
|
367a97a95b | ||
|
|
c3ab197aa0 | ||
|
|
a0aa33a499 | ||
|
|
b27bc86141 | ||
|
|
84ef2af82f | ||
|
|
a2f09d8763 | ||
|
|
79058440a1 | ||
|
|
7f9cfdbf7a | ||
|
|
85f7477450 | ||
|
|
0e08d75626 | ||
|
|
1b4a65f476 | ||
|
|
2e69395ade | ||
|
|
3f61f13b7b | ||
|
|
10a0f0ad53 | ||
|
|
680fc66f21 | ||
|
|
e01b74ee3d | ||
|
|
3539e6a892 | ||
|
|
ff56f5a343 | ||
|
|
9ce43a39c8 | ||
|
|
0e3aa3f380 | ||
|
|
7927bf0c9a | ||
|
|
aec2d71688 | ||
|
|
140a0f4d66 | ||
|
|
7cf57535ab | ||
|
|
31fe924157 | ||
|
|
6d193baa69 | ||
|
|
3bd7b54405 | ||
|
|
d99450c5a3 | ||
|
|
6444122c0a | ||
|
|
fe14ccb5ec | ||
|
|
e38e5fdf0f | ||
|
|
c1c2b11bd8 | ||
|
|
7d147b3c37 | ||
|
|
260ff32cd1 | ||
|
|
ccc5f3e423 | ||
|
|
8b32a60743 | ||
|
|
c1faf2fe06 | ||
|
|
3588270742 | ||
|
|
01607ec1e2 | ||
|
|
50f8cb9193 | ||
|
|
0100974508 | ||
|
|
b438898456 | ||
|
|
c3c43dce3d | ||
|
|
e33dfd63e4 | ||
|
|
1927500f5a | ||
|
|
f9ccd0851d | ||
|
|
23412e5c17 | ||
|
|
1b7c8355ec | ||
|
|
8378b3dd90 | ||
|
|
9ff5bb6352 | ||
|
|
b2bb1d22df | ||
|
|
34acf5bb55 | ||
|
|
5af32898f8 | ||
|
|
ef7108f6c9 | ||
|
|
941d992793 | ||
|
|
de9a07a680 | ||
|
|
0dc74f9188 | ||
|
|
f95cf9b231 | ||
|
|
0d0982b244 | ||
|
|
ef4dd82e92 | ||
|
|
bc825681a8 | ||
|
|
da6204f44f | ||
|
|
10c68bdd72 | ||
|
|
b1e90dde8f | ||
|
|
e0d45961f8 | ||
|
|
b732a220f6 | ||
|
|
582adae11f | ||
|
|
3014ebdfd4 | ||
|
|
12b13f98f8 | ||
|
|
c13c43c616 | ||
|
|
ab1eacea3f | ||
|
|
ac4b97928a | ||
|
|
aa8281678b | ||
|
|
0be4f56538 | ||
|
|
679c06557e | ||
|
|
1d387709f2 | ||
|
|
a78774d10e | ||
|
|
390639e9e3 | ||
|
|
b98ec2199d | ||
|
|
8b28f1cd74 | ||
|
|
904b78a01e | ||
|
|
a774d2d915 | ||
|
|
9d19b5fec0 | ||
|
|
b6c0f3ca8c | ||
|
|
e06cb1230f | ||
|
|
1720fde4c4 | ||
|
|
4c3dbe1643 | ||
|
|
3f31bd5ad1 | ||
|
|
3a79b4667b | ||
|
|
de49877178 | ||
|
|
65e92fa206 | ||
|
|
9cb181d53e | ||
|
|
a2d4a63eb1 | ||
|
|
c4f712be3a | ||
|
|
9e8367e45e | ||
|
|
fa2d1de2f2 | ||
|
|
f8f4573486 | ||
|
|
f15f0ce769 | ||
|
|
450daf17fd | ||
|
|
aad26d24ec | ||
|
|
80c8344f8d | ||
|
|
44b23d0b69 | ||
|
|
7ee486e4f2 | ||
|
|
f230f2d198 | ||
|
|
cf50b608a7 | ||
|
|
1314c601b2 | ||
|
|
c5970c5606 | ||
|
|
85b18d118b | ||
|
|
e7a150bd9a | ||
|
|
2c66edda68 | ||
|
|
1a93cc228d | ||
|
|
798ae6aeb7 | ||
|
|
418d0247f5 | ||
|
|
db0ee268f9 | ||
|
|
032d671c38 | ||
|
|
127978d3d7 | ||
|
|
fddc3e41cf | ||
|
|
e0e6f0dab4 | ||
|
|
beaa825a9f | ||
|
|
cae27dda05 | ||
|
|
0d041e9a0a |
120
.idea/codeStyles
generated
@@ -1,120 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectCodeStyleConfiguration">
|
|
||||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
|
||||||
<code_scheme name="Project" version="173">
|
|
||||||
<codeStyleSettings language="XML">
|
|
||||||
<indentOptions>
|
|
||||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
|
||||||
</indentOptions>
|
|
||||||
<arrangement>
|
|
||||||
<rules>
|
|
||||||
<section>
|
|
||||||
<rule>
|
|
||||||
<match>
|
|
||||||
<AND>
|
|
||||||
<NAME>xmlns:android</NAME>
|
|
||||||
<XML_ATTRIBUTE />
|
|
||||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
|
||||||
</AND>
|
|
||||||
</match>
|
|
||||||
</rule>
|
|
||||||
</section>
|
|
||||||
<section>
|
|
||||||
<rule>
|
|
||||||
<match>
|
|
||||||
<AND>
|
|
||||||
<NAME>xmlns:.*</NAME>
|
|
||||||
<XML_ATTRIBUTE />
|
|
||||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
|
||||||
</AND>
|
|
||||||
</match>
|
|
||||||
<order>BY_NAME</order>
|
|
||||||
</rule>
|
|
||||||
</section>
|
|
||||||
<section>
|
|
||||||
<rule>
|
|
||||||
<match>
|
|
||||||
<AND>
|
|
||||||
<NAME>.*:id</NAME>
|
|
||||||
<XML_ATTRIBUTE />
|
|
||||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
|
||||||
</AND>
|
|
||||||
</match>
|
|
||||||
</rule>
|
|
||||||
</section>
|
|
||||||
<section>
|
|
||||||
<rule>
|
|
||||||
<match>
|
|
||||||
<AND>
|
|
||||||
<NAME>.*:name</NAME>
|
|
||||||
<XML_ATTRIBUTE />
|
|
||||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
|
||||||
</AND>
|
|
||||||
</match>
|
|
||||||
</rule>
|
|
||||||
</section>
|
|
||||||
<section>
|
|
||||||
<rule>
|
|
||||||
<match>
|
|
||||||
<AND>
|
|
||||||
<NAME>name</NAME>
|
|
||||||
<XML_ATTRIBUTE />
|
|
||||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
|
||||||
</AND>
|
|
||||||
</match>
|
|
||||||
</rule>
|
|
||||||
</section>
|
|
||||||
<section>
|
|
||||||
<rule>
|
|
||||||
<match>
|
|
||||||
<AND>
|
|
||||||
<NAME>style</NAME>
|
|
||||||
<XML_ATTRIBUTE />
|
|
||||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
|
||||||
</AND>
|
|
||||||
</match>
|
|
||||||
</rule>
|
|
||||||
</section>
|
|
||||||
<section>
|
|
||||||
<rule>
|
|
||||||
<match>
|
|
||||||
<AND>
|
|
||||||
<NAME>.*</NAME>
|
|
||||||
<XML_ATTRIBUTE />
|
|
||||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
|
||||||
</AND>
|
|
||||||
</match>
|
|
||||||
<order>BY_NAME</order>
|
|
||||||
</rule>
|
|
||||||
</section>
|
|
||||||
<section>
|
|
||||||
<rule>
|
|
||||||
<match>
|
|
||||||
<AND>
|
|
||||||
<NAME>.*</NAME>
|
|
||||||
<XML_ATTRIBUTE />
|
|
||||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
|
||||||
</AND>
|
|
||||||
</match>
|
|
||||||
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
|
||||||
</rule>
|
|
||||||
</section>
|
|
||||||
<section>
|
|
||||||
<rule>
|
|
||||||
<match>
|
|
||||||
<AND>
|
|
||||||
<NAME>.*</NAME>
|
|
||||||
<XML_ATTRIBUTE />
|
|
||||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
|
||||||
</AND>
|
|
||||||
</match>
|
|
||||||
<order>BY_NAME</order>
|
|
||||||
</rule>
|
|
||||||
</section>
|
|
||||||
</rules>
|
|
||||||
</arrangement>
|
|
||||||
</codeStyleSettings>
|
|
||||||
</code_scheme>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
186
.idea/codeStyles/Project.xml
generated
Executable file
@@ -0,0 +1,186 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<code_scheme name="Project" version="173">
|
||||||
|
<option name="OTHER_INDENT_OPTIONS">
|
||||||
|
<value>
|
||||||
|
<option name="USE_TAB_CHARACTER" value="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<AndroidXmlCodeStyleSettings>
|
||||||
|
<option name="LAYOUT_SETTINGS">
|
||||||
|
<value>
|
||||||
|
<option name="INSERT_LINE_BREAK_BEFORE_NAMESPACE_DECLARATION" value="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="MANIFEST_SETTINGS">
|
||||||
|
<value>
|
||||||
|
<option name="INSERT_LINE_BREAK_BEFORE_NAMESPACE_DECLARATION" value="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="OTHER_SETTINGS">
|
||||||
|
<value>
|
||||||
|
<option name="INSERT_LINE_BREAK_BEFORE_NAMESPACE_DECLARATION" value="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
</AndroidXmlCodeStyleSettings>
|
||||||
|
<JetCodeStyleSettings>
|
||||||
|
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||||
|
</JetCodeStyleSettings>
|
||||||
|
<codeStyleSettings language="CMake">
|
||||||
|
<indentOptions>
|
||||||
|
<option name="USE_TAB_CHARACTER" value="true" />
|
||||||
|
</indentOptions>
|
||||||
|
</codeStyleSettings>
|
||||||
|
<codeStyleSettings language="Groovy">
|
||||||
|
<indentOptions>
|
||||||
|
<option name="USE_TAB_CHARACTER" value="true" />
|
||||||
|
</indentOptions>
|
||||||
|
</codeStyleSettings>
|
||||||
|
<codeStyleSettings language="HTML">
|
||||||
|
<indentOptions>
|
||||||
|
<option name="USE_TAB_CHARACTER" value="true" />
|
||||||
|
</indentOptions>
|
||||||
|
</codeStyleSettings>
|
||||||
|
<codeStyleSettings language="JAVA">
|
||||||
|
<indentOptions>
|
||||||
|
<option name="USE_TAB_CHARACTER" value="true" />
|
||||||
|
</indentOptions>
|
||||||
|
</codeStyleSettings>
|
||||||
|
<codeStyleSettings language="JSON">
|
||||||
|
<indentOptions>
|
||||||
|
<option name="USE_TAB_CHARACTER" value="true" />
|
||||||
|
</indentOptions>
|
||||||
|
</codeStyleSettings>
|
||||||
|
<codeStyleSettings language="ObjectiveC">
|
||||||
|
<indentOptions>
|
||||||
|
<option name="USE_TAB_CHARACTER" value="true" />
|
||||||
|
</indentOptions>
|
||||||
|
</codeStyleSettings>
|
||||||
|
<codeStyleSettings language="Shell Script">
|
||||||
|
<indentOptions>
|
||||||
|
<option name="USE_TAB_CHARACTER" value="true" />
|
||||||
|
</indentOptions>
|
||||||
|
</codeStyleSettings>
|
||||||
|
<codeStyleSettings language="XML">
|
||||||
|
<indentOptions>
|
||||||
|
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||||
|
<option name="USE_TAB_CHARACTER" value="true" />
|
||||||
|
</indentOptions>
|
||||||
|
<arrangement>
|
||||||
|
<rules>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>xmlns:android</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>xmlns:.*</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*:id</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*:name</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>name</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>style</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
</rules>
|
||||||
|
</arrangement>
|
||||||
|
</codeStyleSettings>
|
||||||
|
<codeStyleSettings language="kotlin">
|
||||||
|
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||||
|
<option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" />
|
||||||
|
<option name="BLOCK_COMMENT_AT_FIRST_COLUMN" value="false" />
|
||||||
|
<option name="LINE_COMMENT_ADD_SPACE" value="true" />
|
||||||
|
<indentOptions>
|
||||||
|
<option name="USE_TAB_CHARACTER" value="true" />
|
||||||
|
</indentOptions>
|
||||||
|
</codeStyleSettings>
|
||||||
|
</code_scheme>
|
||||||
|
</component>
|
||||||
5
.idea/codeStyles/codeStyleConfig.xml
generated
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||||
|
</state>
|
||||||
|
</component>
|
||||||
6
.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<bytecodeTargetLevel target="1.8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
3
.idea/dictionaries/admin.xml
generated
@@ -1,6 +1,9 @@
|
|||||||
<component name="ProjectDictionaryState">
|
<component name="ProjectDictionaryState">
|
||||||
<dictionary name="admin">
|
<dictionary name="admin">
|
||||||
<words>
|
<words>
|
||||||
|
<w>chucker</w>
|
||||||
|
<w>desu</w>
|
||||||
|
<w>failsafe</w>
|
||||||
<w>koin</w>
|
<w>koin</w>
|
||||||
<w>kotatsu</w>
|
<w>kotatsu</w>
|
||||||
<w>manga</w>
|
<w>manga</w>
|
||||||
|
|||||||
1
.idea/gradle.xml
generated
@@ -15,6 +15,7 @@
|
|||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
<option name="resolveModulePerSourceSet" value="false" />
|
<option name="resolveModulePerSourceSet" value="false" />
|
||||||
|
<option name="useQualifiedModuleNames" value="true" />
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
7
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="BooleanLiteralArgument" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="TrailingComma" enabled="true" level="INFORMATION" enabled_by_default="true" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
10
.idea/jarRepositories.xml
generated
@@ -21,5 +21,15 @@
|
|||||||
<option name="name" value="Google" />
|
<option name="name" value="Google" />
|
||||||
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="maven" />
|
||||||
|
<option name="name" value="maven" />
|
||||||
|
<option name="url" value="https://jitpack.io" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="maven2" />
|
||||||
|
<option name="name" value="maven2" />
|
||||||
|
<option name="url" value="https://dl.bintray.com/kotlin/kotlin-eap" />
|
||||||
|
</remote-repository>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
6
.idea/kotlinc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Kotlin2JvmCompilerArguments">
|
||||||
|
<option name="jvmTarget" value="1.8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
2
.idea/misc.xml
generated
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|||||||
9
.idea/vcs.xml
generated
@@ -1,5 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GitSharedSettings">
|
||||||
|
<option name="FORCE_PUSH_PROHIBITED_PATTERNS">
|
||||||
|
<list>
|
||||||
|
<option value="master" />
|
||||||
|
<option value="devel" />
|
||||||
|
<option value="legacy" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ jdk:
|
|||||||
android:
|
android:
|
||||||
components:
|
components:
|
||||||
- tools
|
- tools
|
||||||
- platform-tools-29.0.6
|
- platform-tools-30.0.3
|
||||||
- build-tools-29.0.3
|
- build-tools-30.0.2
|
||||||
- android-29
|
- android-30
|
||||||
licenses:
|
licenses:
|
||||||
- android-sdk-preview-license-.+
|
- android-sdk-preview-license-.+
|
||||||
- android-sdk-license-.+
|
- android-sdk-license-.+
|
||||||
|
|||||||
19
README.md
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
Kotatsu is a free and open source manga reader for Android.
|
Kotatsu is a free and open source manga reader for Android.
|
||||||
|
|
||||||
  [](https://travis-ci.org/nv95/Kotatsu)  [](http://4pda.ru/forum/index.php?showtopic=697669)
|
  [](https://travis-ci.org/nv95/Kotatsu)  [](http://4pda.ru/forum/index.php?showtopic=697669)
|
||||||
|
|
||||||
### Download
|
### Download
|
||||||
|
|
||||||
Latest unstable build: [get here](https://github.com/nv95/Kotatsu/releases/latest)
|
Latest release: [get here](https://github.com/nv95/Kotatsu/releases/latest)
|
||||||
|
|
||||||
Stable release: _Coming soon_
|
Legacy build (Android 4.1+): [available here](https://github.com/nv95/Kotatsu/releases/tag/v0.4-legacy)
|
||||||
|
|
||||||
### Main Features
|
### Main Features
|
||||||
|
|
||||||
@@ -20,16 +20,15 @@ Stable release: _Coming soon_
|
|||||||
* Tablet-optimized modern UI
|
* Tablet-optimized modern UI
|
||||||
* Reading third-party comics from CBZ
|
* Reading third-party comics from CBZ
|
||||||
* Standard and Webtoon-optimized reader
|
* Standard and Webtoon-optimized reader
|
||||||
|
* Notifications about new chapters
|
||||||
### Coming Features
|
* Updates feed
|
||||||
|
* Global search
|
||||||
* Checking for new chapters
|
|
||||||
|
|
||||||
### Screenshots
|
### Screenshots
|
||||||
|
|
||||||
|  |  |  |
|
|  |  |  |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
|  |  |  |
|
|  |  |  |
|
||||||
|
|
||||||
### License
|
### License
|
||||||
[](http://www.gnu.org/licenses/gpl-3.0.en.html)
|
[](http://www.gnu.org/licenses/gpl-3.0.en.html)
|
||||||
@@ -42,4 +41,4 @@ published by the Free Software Foundation, either version 3 of the License, or
|
|||||||
|
|
||||||
### Disclaimer
|
### Disclaimer
|
||||||
|
|
||||||
The developers of this application does not have any affiliation with the content providers available.
|
The developers of this application does not have any affiliation with the content providers available.
|
||||||
|
|||||||
@@ -1,43 +1,39 @@
|
|||||||
apply plugin: 'com.android.application'
|
plugins {
|
||||||
apply plugin: 'kotlin-android'
|
id 'com.android.application'
|
||||||
apply plugin: 'kotlin-android-extensions'
|
id 'kotlin-android'
|
||||||
apply plugin: 'kotlin-kapt'
|
id 'kotlin-android-extensions'
|
||||||
|
id 'kotlin-kapt'
|
||||||
|
}
|
||||||
|
|
||||||
def gitCommits = 'git rev-list --all --count'.execute([], rootDir).text.trim().toInteger()
|
def gitCommits = 'git rev-list --count HEAD'.execute([], rootDir).text.trim().toInteger()
|
||||||
def gitBranch = 'git branch --show-current'.execute([], rootDir).text.trim()
|
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 29
|
compileSdkVersion 30
|
||||||
buildToolsVersion '29.0.3'
|
buildToolsVersion '30.0.2'
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId 'org.koitharu.kotatsu'
|
applicationId 'org.koitharu.kotatsu'
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 29
|
targetSdkVersion 30
|
||||||
versionCode gitCommits
|
versionCode gitCommits
|
||||||
versionName '0.1'
|
versionName '0.5.2'
|
||||||
|
|
||||||
buildConfigField 'String', 'GIT_BRANCH', "\"${gitBranch}\""
|
|
||||||
|
|
||||||
kapt {
|
kapt {
|
||||||
arguments {
|
arguments {
|
||||||
arg('room.schemaLocation', "$projectDir/schemas".toString())
|
arg 'room.schemaLocation', "$projectDir/schemas".toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
archivesBaseName = "kotatsu_${gitCommits}"
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
|
||||||
}
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
debug {
|
debug {
|
||||||
applicationIdSuffix = '.debug'
|
applicationIdSuffix = '.debug'
|
||||||
}
|
}
|
||||||
release {
|
release {
|
||||||
|
multiDexEnabled false
|
||||||
minifyEnabled true
|
minifyEnabled true
|
||||||
shrinkResources true
|
shrinkResources true
|
||||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
@@ -55,41 +51,55 @@ android {
|
|||||||
androidExtensions {
|
androidExtensions {
|
||||||
experimental = true
|
experimental = true
|
||||||
}
|
}
|
||||||
|
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
||||||
|
freeCompilerArgs += ['-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi', '-Xjvm-default=all']
|
||||||
|
}
|
||||||
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
|
||||||
|
|
||||||
implementation 'androidx.core:core-ktx:1.3.0-alpha02'
|
implementation 'androidx.core:core-ktx:1.5.0-alpha03'
|
||||||
implementation 'androidx.fragment:fragment-ktx:1.2.2'
|
implementation 'androidx.activity:activity-ktx:1.2.0-alpha08'
|
||||||
implementation 'androidx.appcompat:appcompat:1.2.0-alpha03'
|
implementation 'androidx.fragment:fragment-ktx:1.3.0-alpha08'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
|
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0-alpha07'
|
||||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-beta01'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
|
||||||
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha01'
|
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
||||||
implementation 'androidx.preference:preference:1.1.0'
|
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha05'
|
||||||
implementation 'com.google.android.material:material:1.2.0-alpha05'
|
implementation 'androidx.viewpager2:viewpager2:1.1.0-alpha01'
|
||||||
|
implementation 'androidx.preference:preference-ktx:1.1.1'
|
||||||
|
implementation 'androidx.work:work-runtime-ktx:2.4.0'
|
||||||
|
implementation 'com.google.android.material:material:1.3.0-alpha02'
|
||||||
|
//noinspection LifecycleAnnotationProcessorWithJava8
|
||||||
|
kapt 'androidx.lifecycle:lifecycle-compiler:2.3.0-alpha07'
|
||||||
|
|
||||||
implementation 'androidx.room:room-runtime:2.2.4'
|
implementation 'androidx.room:room-runtime:2.2.5'
|
||||||
implementation 'androidx.room:room-ktx:2.2.4'
|
implementation 'androidx.room:room-ktx:2.2.5'
|
||||||
kapt 'androidx.room:room-compiler:2.2.4'
|
kapt 'androidx.room:room-compiler:2.2.5'
|
||||||
|
|
||||||
implementation 'com.github.moxy-community:moxy:2.1.1'
|
implementation 'com.github.moxy-community:moxy:2.1.2'
|
||||||
implementation 'com.github.moxy-community:moxy-androidx:2.1.1'
|
implementation 'com.github.moxy-community:moxy-androidx:2.1.2'
|
||||||
implementation 'com.github.moxy-community:moxy-material:2.1.1'
|
implementation 'com.github.moxy-community:moxy-material:2.1.2'
|
||||||
implementation 'com.github.moxy-community:moxy-ktx:2.1.1'
|
implementation 'com.github.moxy-community:moxy-ktx:2.1.2'
|
||||||
kapt 'com.github.moxy-community:moxy-compiler:2.1.1'
|
kapt 'com.github.moxy-community:moxy-compiler:2.1.2'
|
||||||
|
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.4.0'
|
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
|
||||||
implementation 'com.squareup.okio:okio:2.4.3'
|
implementation 'com.squareup.okio:okio:2.8.0'
|
||||||
implementation 'org.jsoup:jsoup:1.12.2'
|
implementation 'org.jsoup:jsoup:1.13.1'
|
||||||
|
|
||||||
implementation 'org.koin:koin-android:2.1.3'
|
implementation 'org.koin:koin-android:2.2.0-beta-1'
|
||||||
implementation 'io.coil-kt:coil:0.9.5'
|
implementation 'io.coil-kt:coil:1.0.0-rc2'
|
||||||
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
|
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
|
||||||
implementation 'com.tomclaw.cache:cache:1.0'
|
implementation 'com.tomclaw.cache:cache:1.0'
|
||||||
|
|
||||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.2'
|
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.3'
|
||||||
|
debugImplementation 'com.github.ChuckerTeam.Chucker:library:3.2.0'
|
||||||
|
releaseImplementation 'com.github.ChuckerTeam.Chucker:library-no-op:3.2.0'
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.13'
|
testImplementation 'junit:junit:4.13'
|
||||||
|
testImplementation 'org.json:json:20200518'
|
||||||
}
|
}
|
||||||
1
app/libs/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
3
app/proguard-rules.pro
vendored
@@ -9,4 +9,5 @@
|
|||||||
-keep class org.koitharu.kotatsu.core.db.entity.* { *; }
|
-keep class org.koitharu.kotatsu.core.db.entity.* { *; }
|
||||||
-keepclassmembers public class * extends org.koitharu.kotatsu.core.parser.MangaRepository {
|
-keepclassmembers public class * extends org.koitharu.kotatsu.core.parser.MangaRepository {
|
||||||
public <init>(...);
|
public <init>(...);
|
||||||
}
|
}
|
||||||
|
-dontwarn okhttp3.internal.platform.ConscryptPlatform
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="108dp"
|
|
||||||
android:height="108dp"
|
|
||||||
android:viewportWidth="108"
|
|
||||||
android:viewportHeight="108"
|
|
||||||
android:tint="#E6000A">
|
|
||||||
<group android:scaleX="0.40188664"
|
|
||||||
android:scaleY="0.40188664"
|
|
||||||
android:translateX="32.90095"
|
|
||||||
android:translateY="18.7272">
|
|
||||||
<group android:translateY="139.39206">
|
|
||||||
<path android:pathData="M83.796875,-0L105.6875,-0L60.765625,-55.828125L103.09375,-101L82.078125,-101L32.25,-49.1875L32.25,-101L13.53125,-101L13.53125,-0L32.25,-0L32.25,-25.8125L48.234375,-42.265625L83.796875,-0Z"
|
|
||||||
android:fillColor="#E6000A"/>
|
|
||||||
</group>
|
|
||||||
</group>
|
|
||||||
</vector>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@color/ic_launcher_background"/>
|
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
|
||||||
</adaptive-icon>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@color/ic_launcher_background"/>
|
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
|
||||||
</adaptive-icon>
|
|
||||||
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 1016 B |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 7.1 KiB |
|
Before Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 10 KiB |
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<color name="ic_launcher_background">#FFFFFF</color>
|
|
||||||
</resources>
|
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest
|
<manifest
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="org.koitharu.kotatsu">
|
package="org.koitharu.kotatsu">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="org.koitharu.kotatsu.KotatsuApp"
|
android:name="org.koitharu.kotatsu.KotatsuApp"
|
||||||
@@ -18,8 +21,9 @@
|
|||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
android:usesCleartextTraffic="true">
|
android:usesCleartextTraffic="true"
|
||||||
<activity android:name=".ui.main.MainActivity">
|
tools:ignore="UnusedAttribute">
|
||||||
|
<activity android:name=".ui.list.MainActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
@@ -42,16 +46,46 @@
|
|||||||
android:label="@string/settings" />
|
android:label="@string/settings" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.reader.SimpleSettingsActivity"
|
android:name=".ui.reader.SimpleSettingsActivity"
|
||||||
android:label="@string/settings" />
|
android:label="@string/settings">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MANAGE_NETWORK_USAGE" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
<activity android:name=".ui.browser.BrowserActivity" />
|
||||||
|
<activity
|
||||||
|
android:name=".ui.utils.CrashActivity"
|
||||||
|
android:label="@string/error_occurred"
|
||||||
|
android:theme="@android:style/Theme.DeviceDefault.Dialog"
|
||||||
|
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||||
|
<activity
|
||||||
|
android:name="org.koitharu.kotatsu.ui.list.favourites.categories.CategoriesActivity"
|
||||||
|
android:label="@string/favourites_categories"
|
||||||
|
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||||
|
<activity
|
||||||
|
android:name=".ui.widget.shelf.ShelfConfigActivity"
|
||||||
|
android:label="@string/manga_shelf">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
<activity android:name=".ui.search.global.GlobalSearchActivity"
|
||||||
|
android:label="@string/search" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".ui.download.DownloadService"
|
android:name=".ui.download.DownloadService"
|
||||||
android:foregroundServiceType="dataSync" />
|
android:foregroundServiceType="dataSync" />
|
||||||
<service android:name=".ui.settings.AppUpdateService" />
|
<service
|
||||||
|
android:name=".ui.widget.shelf.ShelfWidgetService"
|
||||||
|
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
||||||
|
<service
|
||||||
|
android:name=".ui.widget.recent.RecentWidgetService"
|
||||||
|
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name=".ui.search.MangaSuggestionsProvider"
|
android:name=".ui.search.MangaSuggestionsProvider"
|
||||||
android:authorities="${applicationId}.MangaSuggestionsProvider" />
|
android:authorities="${applicationId}.MangaSuggestionsProvider"
|
||||||
|
android:exported="false" />
|
||||||
<provider
|
<provider
|
||||||
android:name="androidx.core.content.FileProvider"
|
android:name="androidx.core.content.FileProvider"
|
||||||
android:authorities="${applicationId}.files"
|
android:authorities="${applicationId}.files"
|
||||||
@@ -62,6 +96,27 @@
|
|||||||
android:resource="@xml/filepaths" />
|
android:resource="@xml/filepaths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:name=".ui.widget.shelf.ShelfWidgetProvider"
|
||||||
|
android:label="@string/manga_shelf">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||||
|
</intent-filter>
|
||||||
|
<meta-data
|
||||||
|
android:name="android.appwidget.provider"
|
||||||
|
android:resource="@xml/widget_shelf" />
|
||||||
|
</receiver>
|
||||||
|
<receiver
|
||||||
|
android:name=".ui.widget.recent.RecentWidgetProvider"
|
||||||
|
android:label="@string/recent_manga">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||||
|
</intent-filter>
|
||||||
|
<meta-data
|
||||||
|
android:name="android.appwidget.provider"
|
||||||
|
android:resource="@xml/widget_recent" />
|
||||||
|
</receiver>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -1,25 +1,37 @@
|
|||||||
package org.koitharu.kotatsu
|
package org.koitharu.kotatsu
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.os.StrictMode
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import coil.Coil
|
import coil.Coil
|
||||||
|
import coil.ComponentRegistry
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import coil.util.CoilUtils
|
import coil.util.CoilUtils
|
||||||
import com.itkacher.okhttpprofiler.OkHttpProfilerInterceptor
|
import com.chuckerteam.chucker.api.ChuckerCollector
|
||||||
|
import com.chuckerteam.chucker.api.ChuckerInterceptor
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import org.koin.android.ext.koin.androidContext
|
import org.koin.android.ext.koin.androidContext
|
||||||
import org.koin.android.ext.koin.androidLogger
|
import org.koin.android.ext.koin.androidLogger
|
||||||
import org.koin.core.context.startKoin
|
import org.koin.core.context.startKoin
|
||||||
|
import org.koin.core.logger.Level
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
import org.koitharu.kotatsu.core.db.DatabasePrePopulateCallback
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
|
import org.koitharu.kotatsu.core.db.migrations.*
|
||||||
import org.koitharu.kotatsu.core.local.CbzFetcher
|
import org.koitharu.kotatsu.core.local.CbzFetcher
|
||||||
import org.koitharu.kotatsu.core.local.PagesCache
|
import org.koitharu.kotatsu.core.local.PagesCache
|
||||||
import org.koitharu.kotatsu.core.local.cookies.PersistentCookieJar
|
import org.koitharu.kotatsu.core.local.cookies.PersistentCookieJar
|
||||||
import org.koitharu.kotatsu.core.local.cookies.cache.SetCookieCache
|
import org.koitharu.kotatsu.core.local.cookies.cache.SetCookieCache
|
||||||
import org.koitharu.kotatsu.core.local.cookies.persistence.SharedPrefsCookiePersistor
|
import org.koitharu.kotatsu.core.local.cookies.persistence.SharedPrefsCookiePersistor
|
||||||
|
import org.koitharu.kotatsu.core.parser.LocalMangaRepository
|
||||||
|
import org.koitharu.kotatsu.core.parser.UserAgentInterceptor
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||||
|
import org.koitharu.kotatsu.domain.favourites.FavouritesRepository
|
||||||
|
import org.koitharu.kotatsu.domain.history.HistoryRepository
|
||||||
|
import org.koitharu.kotatsu.ui.utils.AppCrashHandler
|
||||||
|
import org.koitharu.kotatsu.ui.widget.WidgetUpdater
|
||||||
import org.koitharu.kotatsu.utils.CacheUtils
|
import org.koitharu.kotatsu.utils.CacheUtils
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
@@ -29,16 +41,40 @@ class KotatsuApp : Application() {
|
|||||||
PersistentCookieJar(SetCookieCache(), SharedPrefsCookiePersistor(applicationContext))
|
PersistentCookieJar(SetCookieCache(), SharedPrefsCookiePersistor(applicationContext))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val chuckerCollector by lazy(LazyThreadSafetyMode.NONE) {
|
||||||
|
ChuckerCollector(applicationContext)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
|
||||||
|
.detectAll()
|
||||||
|
.penaltyLog()
|
||||||
|
.build())
|
||||||
|
StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder()
|
||||||
|
.detectAll()
|
||||||
|
.setClassInstanceLimit(LocalMangaRepository::class.java, 1)
|
||||||
|
.setClassInstanceLimit(PagesCache::class.java, 1)
|
||||||
|
.setClassInstanceLimit(MangaLoaderContext::class.java, 1)
|
||||||
|
.penaltyLog()
|
||||||
|
.build())
|
||||||
|
}
|
||||||
initKoin()
|
initKoin()
|
||||||
initCoil()
|
initCoil()
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(AppCrashHandler(applicationContext))
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
initErrorHandler()
|
||||||
|
}
|
||||||
AppCompatDelegate.setDefaultNightMode(AppSettings(this).theme)
|
AppCompatDelegate.setDefaultNightMode(AppSettings(this).theme)
|
||||||
|
val widgetUpdater = WidgetUpdater(applicationContext)
|
||||||
|
FavouritesRepository.subscribe(widgetUpdater)
|
||||||
|
HistoryRepository.subscribe(widgetUpdater)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initKoin() {
|
private fun initKoin() {
|
||||||
startKoin {
|
startKoin {
|
||||||
androidLogger()
|
androidLogger(Level.ERROR)
|
||||||
androidContext(applicationContext)
|
androidContext(applicationContext)
|
||||||
modules(
|
modules(
|
||||||
module {
|
module {
|
||||||
@@ -53,7 +89,7 @@ class KotatsuApp : Application() {
|
|||||||
single {
|
single {
|
||||||
MangaLoaderContext()
|
MangaLoaderContext()
|
||||||
}
|
}
|
||||||
factory {
|
single {
|
||||||
AppSettings(applicationContext)
|
AppSettings(applicationContext)
|
||||||
}
|
}
|
||||||
single {
|
single {
|
||||||
@@ -65,16 +101,27 @@ class KotatsuApp : Application() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initCoil() {
|
private fun initCoil() {
|
||||||
Coil.setDefaultImageLoader(ImageLoader(applicationContext) {
|
Coil.setImageLoader(
|
||||||
okHttpClient {
|
ImageLoader.Builder(applicationContext)
|
||||||
okHttp()
|
.okHttpClient(
|
||||||
.cache(CoilUtils.createDefaultCache(applicationContext))
|
okHttp()
|
||||||
.build()
|
.cache(CoilUtils.createDefaultCache(applicationContext))
|
||||||
}
|
.build()
|
||||||
componentRegistry {
|
).componentRegistry(
|
||||||
add(CbzFetcher())
|
ComponentRegistry.Builder()
|
||||||
}
|
.add(CbzFetcher())
|
||||||
})
|
.build()
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initErrorHandler() {
|
||||||
|
val exceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler { t, e ->
|
||||||
|
chuckerCollector.onError("CRASH", e)
|
||||||
|
exceptionHandler?.uncaughtException(t, e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun okHttp() = OkHttpClient.Builder().apply {
|
private fun okHttp() = OkHttpClient.Builder().apply {
|
||||||
@@ -82,8 +129,9 @@ class KotatsuApp : Application() {
|
|||||||
readTimeout(60, TimeUnit.SECONDS)
|
readTimeout(60, TimeUnit.SECONDS)
|
||||||
writeTimeout(20, TimeUnit.SECONDS)
|
writeTimeout(20, TimeUnit.SECONDS)
|
||||||
cookieJar(cookieJar)
|
cookieJar(cookieJar)
|
||||||
|
addInterceptor(UserAgentInterceptor)
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
addInterceptor(OkHttpProfilerInterceptor())
|
addInterceptor(ChuckerInterceptor(applicationContext, collector = chuckerCollector))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,5 +139,6 @@ class KotatsuApp : Application() {
|
|||||||
applicationContext,
|
applicationContext,
|
||||||
MangaDatabase::class.java,
|
MangaDatabase::class.java,
|
||||||
"kotatsu-db"
|
"kotatsu-db"
|
||||||
)
|
).addMigrations(Migration1To2, Migration2To3, Migration3To4, Migration4To5, Migration5To6)
|
||||||
|
.addCallback(DatabasePrePopulateCallback(resources))
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db
|
||||||
|
|
||||||
|
import android.content.res.Resources
|
||||||
|
import androidx.room.RoomDatabase
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
|
||||||
|
class DatabasePrePopulateCallback(private val resources: Resources) : RoomDatabase.Callback() {
|
||||||
|
|
||||||
|
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||||
|
db.execSQL(
|
||||||
|
"INSERT INTO favourite_categories (created_at, sort_key, title) VALUES (?,?,?)",
|
||||||
|
arrayOf(System.currentTimeMillis(), 1, resources.getString(R.string.read_later))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,12 +9,25 @@ import org.koitharu.kotatsu.core.db.entity.FavouriteCategoryEntity
|
|||||||
@Dao
|
@Dao
|
||||||
abstract class FavouriteCategoriesDao {
|
abstract class FavouriteCategoriesDao {
|
||||||
|
|
||||||
@Query("SELECT category_id,title,created_at FROM favourite_categories ORDER BY :orderBy")
|
@Query("SELECT * FROM favourite_categories ORDER BY sort_key")
|
||||||
abstract suspend fun findAll(orderBy: String): List<FavouriteCategoryEntity>
|
abstract suspend fun findAll(): List<FavouriteCategoryEntity>
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.ABORT)
|
@Insert(onConflict = OnConflictStrategy.ABORT)
|
||||||
abstract suspend fun insert(category: FavouriteCategoryEntity): Long
|
abstract suspend fun insert(category: FavouriteCategoryEntity): Long
|
||||||
|
|
||||||
@Query("DELETE FROM favourite_categories WHERE category_id = :id")
|
@Query("DELETE FROM favourite_categories WHERE category_id = :id")
|
||||||
abstract suspend fun delete(id: Long)
|
abstract suspend fun delete(id: Long)
|
||||||
|
|
||||||
|
@Query("UPDATE favourite_categories SET title = :title WHERE category_id = :id")
|
||||||
|
abstract suspend fun update(id: Long, title: String)
|
||||||
|
|
||||||
|
@Query("UPDATE favourite_categories SET sort_key = :sortKey WHERE category_id = :id")
|
||||||
|
abstract suspend fun update(id: Long, sortKey: Int)
|
||||||
|
|
||||||
|
@Query("SELECT MAX(sort_key) FROM favourite_categories")
|
||||||
|
protected abstract suspend fun getMaxSortKey(): Int?
|
||||||
|
|
||||||
|
suspend fun getNextSortKey(): Int {
|
||||||
|
return (getMaxSortKey() ?: 0) + 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,29 @@ package org.koitharu.kotatsu.core.db
|
|||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import org.koitharu.kotatsu.core.db.entity.FavouriteEntity
|
import org.koitharu.kotatsu.core.db.entity.FavouriteEntity
|
||||||
import org.koitharu.kotatsu.core.db.entity.FavouriteManga
|
import org.koitharu.kotatsu.core.db.entity.FavouriteManga
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
abstract class FavouritesDao {
|
abstract class FavouritesDao {
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM favourites GROUP BY manga_id ORDER BY :orderBy LIMIT :limit OFFSET :offset")
|
@Query("SELECT * FROM favourites GROUP BY manga_id ORDER BY created_at")
|
||||||
abstract suspend fun findAll(offset: Int, limit: Int, orderBy: String): List<FavouriteManga>
|
abstract suspend fun findAll(): List<FavouriteManga>
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
@Query("SELECT * FROM favourites GROUP BY manga_id ORDER BY created_at LIMIT :limit OFFSET :offset")
|
||||||
|
abstract suspend fun findAll(offset: Int, limit: Int): List<FavouriteManga>
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
@Query("SELECT * FROM favourites WHERE category_id = :categoryId GROUP BY manga_id ORDER BY created_at")
|
||||||
|
abstract suspend fun findAll(categoryId: Long): List<FavouriteManga>
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
@Query("SELECT * FROM favourites WHERE category_id = :categoryId GROUP BY manga_id ORDER BY created_at LIMIT :limit OFFSET :offset")
|
||||||
|
abstract suspend fun findAll(categoryId: Long, offset: Int, limit: Int): List<FavouriteManga>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM manga WHERE manga_id IN (SELECT manga_id FROM favourites)")
|
||||||
|
abstract suspend fun findAllManga(): List<MangaEntity>
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM favourites WHERE manga_id = :id GROUP BY manga_id")
|
@Query("SELECT * FROM favourites WHERE manga_id = :id GROUP BY manga_id")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.koitharu.kotatsu.core.db
|
|||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import org.koitharu.kotatsu.core.db.entity.HistoryEntity
|
import org.koitharu.kotatsu.core.db.entity.HistoryEntity
|
||||||
import org.koitharu.kotatsu.core.db.entity.HistoryWithManga
|
import org.koitharu.kotatsu.core.db.entity.HistoryWithManga
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
||||||
|
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
@@ -15,6 +16,9 @@ abstract class HistoryDao {
|
|||||||
@Query("SELECT * FROM history ORDER BY updated_at DESC LIMIT :limit OFFSET :offset")
|
@Query("SELECT * FROM history ORDER BY updated_at DESC LIMIT :limit OFFSET :offset")
|
||||||
abstract suspend fun findAll(offset: Int, limit: Int): List<HistoryWithManga>
|
abstract suspend fun findAll(offset: Int, limit: Int): List<HistoryWithManga>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM manga WHERE manga_id IN (SELECT manga_id FROM history)")
|
||||||
|
abstract suspend fun findAllManga(): List<MangaEntity>
|
||||||
|
|
||||||
@Query("SELECT * FROM history WHERE manga_id = :id")
|
@Query("SELECT * FROM history WHERE manga_id = :id")
|
||||||
abstract suspend fun find(id: Long): HistoryEntity?
|
abstract suspend fun find(id: Long): HistoryEntity?
|
||||||
|
|
||||||
@@ -24,19 +28,20 @@ abstract class HistoryDao {
|
|||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
abstract suspend fun insert(entity: HistoryEntity): Long
|
abstract suspend fun insert(entity: HistoryEntity): Long
|
||||||
|
|
||||||
@Query("UPDATE history SET page = :page, chapter_id = :chapterId, updated_at = :updatedAt WHERE manga_id = :mangaId")
|
@Query("UPDATE history SET page = :page, chapter_id = :chapterId, scroll = :scroll, updated_at = :updatedAt WHERE manga_id = :mangaId")
|
||||||
abstract suspend fun update(mangaId: Long, page: Int, chapterId: Long, updatedAt: Long): Int
|
abstract suspend fun update(mangaId: Long, page: Int, chapterId: Long, scroll: Float, updatedAt: Long): Int
|
||||||
|
|
||||||
@Query("DELETE FROM history WHERE manga_id = :mangaId")
|
@Query("DELETE FROM history WHERE manga_id = :mangaId")
|
||||||
abstract suspend fun delete(mangaId: Long)
|
abstract suspend fun delete(mangaId: Long)
|
||||||
|
|
||||||
suspend fun update(entity: HistoryEntity) = update(entity.mangaId, entity.page, entity.chapterId, entity.updatedAt)
|
suspend fun update(entity: HistoryEntity) = update(entity.mangaId, entity.page, entity.chapterId, entity.scroll, entity.updatedAt)
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
open suspend fun upsert(entity: HistoryEntity) {
|
open suspend fun upsert(entity: HistoryEntity): Boolean {
|
||||||
if (update(entity) == 0) {
|
return if (update(entity) == 0) {
|
||||||
insert(entity)
|
insert(entity)
|
||||||
}
|
true
|
||||||
|
} else false
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,20 +7,25 @@ import org.koitharu.kotatsu.core.db.entity.*
|
|||||||
@Database(
|
@Database(
|
||||||
entities = [
|
entities = [
|
||||||
MangaEntity::class, TagEntity::class, HistoryEntity::class, MangaTagsEntity::class,
|
MangaEntity::class, TagEntity::class, HistoryEntity::class, MangaTagsEntity::class,
|
||||||
FavouriteCategoryEntity::class, FavouriteEntity::class, MangaPrefsEntity::class
|
FavouriteCategoryEntity::class, FavouriteEntity::class, MangaPrefsEntity::class,
|
||||||
], version = 1
|
TrackEntity::class, TrackLogEntity::class
|
||||||
|
], version = 6
|
||||||
)
|
)
|
||||||
abstract class MangaDatabase : RoomDatabase() {
|
abstract class MangaDatabase : RoomDatabase() {
|
||||||
|
|
||||||
abstract fun historyDao(): HistoryDao
|
abstract val historyDao: HistoryDao
|
||||||
|
|
||||||
abstract fun tagsDao(): TagsDao
|
abstract val tagsDao: TagsDao
|
||||||
|
|
||||||
abstract fun mangaDao(): MangaDao
|
abstract val mangaDao: MangaDao
|
||||||
|
|
||||||
abstract fun favouritesDao(): FavouritesDao
|
abstract val favouritesDao: FavouritesDao
|
||||||
|
|
||||||
abstract fun preferencesDao(): PreferencesDao
|
abstract val preferencesDao: PreferencesDao
|
||||||
|
|
||||||
abstract fun favouriteCategoriesDao(): FavouriteCategoriesDao
|
abstract val favouriteCategoriesDao: FavouriteCategoriesDao
|
||||||
|
|
||||||
|
abstract val tracksDao: TracksDao
|
||||||
|
|
||||||
|
abstract val trackLogsDao: TrackLogsDao
|
||||||
}
|
}
|
||||||
@@ -4,19 +4,19 @@ import androidx.room.*
|
|||||||
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface TagsDao {
|
abstract class TagsDao {
|
||||||
|
|
||||||
@Query("SELECT * FROM tags")
|
@Query("SELECT * FROM tags")
|
||||||
suspend fun getAllTags(): List<TagEntity>
|
abstract suspend fun getAllTags(): List<TagEntity>
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
suspend fun insert(tag: TagEntity): Long
|
abstract suspend fun insert(tag: TagEntity): Long
|
||||||
|
|
||||||
@Update(onConflict = OnConflictStrategy.IGNORE)
|
@Update(onConflict = OnConflictStrategy.IGNORE)
|
||||||
suspend fun update(tag: TagEntity): Int
|
abstract suspend fun update(tag: TagEntity): Int
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
suspend fun upsert(tags: Iterable<TagEntity>) {
|
open suspend fun upsert(tags: Iterable<TagEntity>) {
|
||||||
tags.forEach { tag ->
|
tags.forEach { tag ->
|
||||||
if (update(tag) <= 0) {
|
if (update(tag) <= 0) {
|
||||||
insert(tag)
|
insert(tag)
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db
|
||||||
|
|
||||||
|
import androidx.room.*
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.TrackLogEntity
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.TrackLogWithManga
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface TrackLogsDao {
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
@Query("SELECT * FROM track_logs ORDER BY created_at DESC LIMIT :limit OFFSET :offset")
|
||||||
|
suspend fun findAll(offset: Int, limit: Int): List<TrackLogWithManga>
|
||||||
|
|
||||||
|
@Query("DELETE FROM track_logs")
|
||||||
|
suspend fun clear()
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
suspend fun insert(entity: TrackLogEntity): Long
|
||||||
|
|
||||||
|
@Query("DELETE FROM track_logs WHERE manga_id = :mangaId")
|
||||||
|
suspend fun removeAll(mangaId: Long)
|
||||||
|
|
||||||
|
@Query("DELETE FROM track_logs WHERE manga_id NOT IN (SELECT manga_id FROM tracks)")
|
||||||
|
suspend fun cleanup()
|
||||||
|
|
||||||
|
@Query("SELECT COUNT(*) FROM track_logs")
|
||||||
|
suspend fun count(): Int
|
||||||
|
}
|
||||||
37
app/src/main/java/org/koitharu/kotatsu/core/db/TracksDao.kt
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db
|
||||||
|
|
||||||
|
import androidx.room.*
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.TrackEntity
|
||||||
|
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
abstract class TracksDao {
|
||||||
|
|
||||||
|
@Query("SELECT * FROM tracks")
|
||||||
|
abstract suspend fun findAll(): List<TrackEntity>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM tracks WHERE manga_id = :mangaId")
|
||||||
|
abstract suspend fun find(mangaId: Long): TrackEntity?
|
||||||
|
|
||||||
|
@Query("DELETE FROM tracks")
|
||||||
|
abstract suspend fun clear()
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
|
abstract suspend fun insert(entity: TrackEntity): Long
|
||||||
|
|
||||||
|
@Update
|
||||||
|
abstract suspend fun update(entity: TrackEntity): Int
|
||||||
|
|
||||||
|
@Query("DELETE FROM tracks WHERE manga_id = :mangaId")
|
||||||
|
abstract suspend fun delete(mangaId: Long)
|
||||||
|
|
||||||
|
@Query("DELETE FROM tracks WHERE manga_id NOT IN (SELECT manga_id FROM history UNION SELECT manga_id FROM favourites)")
|
||||||
|
abstract suspend fun cleanup()
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
open suspend fun upsert(entity: TrackEntity) {
|
||||||
|
if (update(entity) == 0) {
|
||||||
|
insert(entity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,12 +11,14 @@ data class FavouriteCategoryEntity(
|
|||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
@ColumnInfo(name = "category_id") val categoryId: Int,
|
@ColumnInfo(name = "category_id") val categoryId: Int,
|
||||||
@ColumnInfo(name = "created_at") val createdAt: Long,
|
@ColumnInfo(name = "created_at") val createdAt: Long,
|
||||||
|
@ColumnInfo(name = "sort_key") val sortKey: Int,
|
||||||
@ColumnInfo(name = "title") val title: String
|
@ColumnInfo(name = "title") val title: String
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun toFavouriteCategory(id: Long? = null) = FavouriteCategory(
|
fun toFavouriteCategory(id: Long? = null) = FavouriteCategory(
|
||||||
id = id ?: categoryId.toLong(),
|
id = id ?: categoryId.toLong(),
|
||||||
title = title,
|
title = title,
|
||||||
|
sortKey = sortKey,
|
||||||
createdAt = Date(createdAt)
|
createdAt = Date(createdAt)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,26 @@ package org.koitharu.kotatsu.core.db.entity
|
|||||||
|
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
|
import androidx.room.ForeignKey
|
||||||
|
|
||||||
@Entity(tableName = "favourites", primaryKeys = ["manga_id", "category_id"])
|
@Entity(
|
||||||
|
tableName = "favourites", primaryKeys = ["manga_id", "category_id"], foreignKeys = [
|
||||||
|
ForeignKey(
|
||||||
|
entity = MangaEntity::class,
|
||||||
|
parentColumns = ["manga_id"],
|
||||||
|
childColumns = ["manga_id"],
|
||||||
|
onDelete = ForeignKey.CASCADE
|
||||||
|
),
|
||||||
|
ForeignKey(
|
||||||
|
entity = FavouriteCategoryEntity::class,
|
||||||
|
parentColumns = ["category_id"],
|
||||||
|
childColumns = ["category_id"],
|
||||||
|
onDelete = ForeignKey.CASCADE
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
data class FavouriteEntity(
|
data class FavouriteEntity(
|
||||||
@ColumnInfo(name = "manga_id") val mangaId: Long,
|
@ColumnInfo(name = "manga_id", index = true) val mangaId: Long,
|
||||||
@ColumnInfo(name = "category_id") val categoryId: Long,
|
@ColumnInfo(name = "category_id", index = true) val categoryId: Long,
|
||||||
@ColumnInfo(name = "created_at") val createdAt: Long
|
@ColumnInfo(name = "created_at") val createdAt: Long
|
||||||
)
|
)
|
||||||
@@ -2,24 +2,36 @@ package org.koitharu.kotatsu.core.db.entity
|
|||||||
|
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
|
import androidx.room.ForeignKey
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import org.koitharu.kotatsu.core.model.MangaHistory
|
import org.koitharu.kotatsu.core.model.MangaHistory
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@Entity(tableName = "history")
|
@Entity(
|
||||||
|
tableName = "history", foreignKeys = [
|
||||||
|
ForeignKey(
|
||||||
|
entity = MangaEntity::class,
|
||||||
|
parentColumns = ["manga_id"],
|
||||||
|
childColumns = ["manga_id"],
|
||||||
|
onDelete = ForeignKey.CASCADE
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
data class HistoryEntity(
|
data class HistoryEntity(
|
||||||
@PrimaryKey(autoGenerate = false)
|
@PrimaryKey(autoGenerate = false)
|
||||||
@ColumnInfo(name = "manga_id") val mangaId: Long,
|
@ColumnInfo(name = "manga_id") val mangaId: Long,
|
||||||
@ColumnInfo(name = "created_at") val createdAt: Long = System.currentTimeMillis(),
|
@ColumnInfo(name = "created_at") val createdAt: Long = System.currentTimeMillis(),
|
||||||
@ColumnInfo(name = "updated_at") val updatedAt: Long,
|
@ColumnInfo(name = "updated_at") val updatedAt: Long,
|
||||||
@ColumnInfo(name = "chapter_id") val chapterId: Long,
|
@ColumnInfo(name = "chapter_id") val chapterId: Long,
|
||||||
@ColumnInfo(name = "page") val page: Int
|
@ColumnInfo(name = "page") val page: Int,
|
||||||
|
@ColumnInfo(name = "scroll") val scroll: Float
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun toMangaHistory() = MangaHistory(
|
fun toMangaHistory() = MangaHistory(
|
||||||
createdAt = Date(createdAt),
|
createdAt = Date(createdAt),
|
||||||
updatedAt = Date(updatedAt),
|
updatedAt = Date(updatedAt),
|
||||||
chapterId = chapterId,
|
chapterId = chapterId,
|
||||||
page = page
|
page = page,
|
||||||
)
|
scroll = scroll.toInt()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
@@ -2,9 +2,18 @@ package org.koitharu.kotatsu.core.db.entity
|
|||||||
|
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
|
import androidx.room.ForeignKey
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
@Entity(tableName = "preferences")
|
@Entity(
|
||||||
|
tableName = "preferences", foreignKeys = [
|
||||||
|
ForeignKey(
|
||||||
|
entity = MangaEntity::class,
|
||||||
|
parentColumns = ["manga_id"],
|
||||||
|
childColumns = ["manga_id"],
|
||||||
|
onDelete = ForeignKey.CASCADE
|
||||||
|
)]
|
||||||
|
)
|
||||||
data class MangaPrefsEntity(
|
data class MangaPrefsEntity(
|
||||||
@PrimaryKey(autoGenerate = false)
|
@PrimaryKey(autoGenerate = false)
|
||||||
@ColumnInfo(name = "manga_id") val mangaId: Long,
|
@ColumnInfo(name = "manga_id") val mangaId: Long,
|
||||||
|
|||||||
@@ -2,9 +2,25 @@ package org.koitharu.kotatsu.core.db.entity
|
|||||||
|
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
|
import androidx.room.ForeignKey
|
||||||
|
|
||||||
@Entity(tableName = "manga_tags", primaryKeys = ["manga_id", "tag_id"])
|
@Entity(
|
||||||
|
tableName = "manga_tags", primaryKeys = ["manga_id", "tag_id"], foreignKeys = [
|
||||||
|
ForeignKey(
|
||||||
|
entity = MangaEntity::class,
|
||||||
|
parentColumns = ["manga_id"],
|
||||||
|
childColumns = ["manga_id"],
|
||||||
|
onDelete = ForeignKey.CASCADE
|
||||||
|
),
|
||||||
|
ForeignKey(
|
||||||
|
entity = TagEntity::class,
|
||||||
|
parentColumns = ["tag_id"],
|
||||||
|
childColumns = ["tag_id"],
|
||||||
|
onDelete = ForeignKey.CASCADE
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
data class MangaTagsEntity(
|
data class MangaTagsEntity(
|
||||||
@ColumnInfo(name = "manga_id") val mangaId: Long,
|
@ColumnInfo(name = "manga_id", index = true) val mangaId: Long,
|
||||||
@ColumnInfo(name = "tag_id") val tagId: Long
|
@ColumnInfo(name = "tag_id", index = true) val tagId: Long
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db.entity
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.ForeignKey
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(
|
||||||
|
tableName = "tracks", foreignKeys = [
|
||||||
|
ForeignKey(
|
||||||
|
entity = MangaEntity::class,
|
||||||
|
parentColumns = ["manga_id"],
|
||||||
|
childColumns = ["manga_id"],
|
||||||
|
onDelete = ForeignKey.CASCADE
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
data class TrackEntity (
|
||||||
|
@PrimaryKey(autoGenerate = false)
|
||||||
|
@ColumnInfo(name = "manga_id") val mangaId: Long,
|
||||||
|
@ColumnInfo(name = "chapters_total") val totalChapters: Int,
|
||||||
|
@ColumnInfo(name = "last_chapter_id") val lastChapterId: Long,
|
||||||
|
@ColumnInfo(name = "chapters_new") val newChapters: Int,
|
||||||
|
@ColumnInfo(name = "last_check") val lastCheck: Long,
|
||||||
|
@ColumnInfo(name = "last_notified_id") val lastNotifiedChapterId: Long
|
||||||
|
)
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db.entity
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.ForeignKey
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(
|
||||||
|
tableName = "track_logs", foreignKeys = [
|
||||||
|
ForeignKey(
|
||||||
|
entity = MangaEntity::class,
|
||||||
|
parentColumns = ["manga_id"],
|
||||||
|
childColumns = ["manga_id"],
|
||||||
|
onDelete = ForeignKey.CASCADE
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
data class TrackLogEntity(
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
@ColumnInfo(name = "id") val id: Long = 0L,
|
||||||
|
@ColumnInfo(name = "manga_id", index = true) val mangaId: Long,
|
||||||
|
@ColumnInfo(name = "chapters") val chapters: String,
|
||||||
|
@ColumnInfo(name = "created_at") val createdAt: Long = System.currentTimeMillis()
|
||||||
|
)
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db.entity
|
||||||
|
|
||||||
|
import androidx.room.Embedded
|
||||||
|
import androidx.room.Junction
|
||||||
|
import androidx.room.Relation
|
||||||
|
import org.koitharu.kotatsu.core.model.TrackingLogItem
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
data class TrackLogWithManga(
|
||||||
|
@Embedded val trackLog: TrackLogEntity,
|
||||||
|
@Relation(
|
||||||
|
parentColumn = "manga_id",
|
||||||
|
entityColumn = "manga_id"
|
||||||
|
)
|
||||||
|
val manga: MangaEntity,
|
||||||
|
@Relation(
|
||||||
|
parentColumn = "manga_id",
|
||||||
|
entityColumn = "tag_id",
|
||||||
|
associateBy = Junction(MangaTagsEntity::class)
|
||||||
|
)
|
||||||
|
val tags: List<TagEntity>
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun toTrackingLogItem() = TrackingLogItem(
|
||||||
|
id = trackLog.id,
|
||||||
|
chapters = trackLog.chapters.split('\n').filterNot { x -> x.isEmpty() },
|
||||||
|
manga = manga.toManga(tags.map { x -> x.toMangaTag() }.toSet()),
|
||||||
|
createdAt = Date(trackLog.createdAt)
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db.migrations
|
||||||
|
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
|
||||||
|
object Migration1To2 : Migration(1, 2) {
|
||||||
|
/**
|
||||||
|
* Adding foreign keys
|
||||||
|
*/
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
/* manga_tags */
|
||||||
|
database.execSQL(
|
||||||
|
"CREATE TABLE IF NOT EXISTS manga_tags_tmp (manga_id INTEGER NOT NULL, tag_id INTEGER NOT NULL, " +
|
||||||
|
"PRIMARY KEY(manga_id, tag_id), " +
|
||||||
|
"FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE, " +
|
||||||
|
"FOREIGN KEY(tag_id) REFERENCES tags(tag_id) ON UPDATE NO ACTION ON DELETE CASCADE )"
|
||||||
|
)
|
||||||
|
database.execSQL("CREATE INDEX IF NOT EXISTS index_manga_tags_manga_id ON manga_tags_tmp (manga_id)")
|
||||||
|
database.execSQL("CREATE INDEX IF NOT EXISTS index_manga_tags_tag_id ON manga_tags_tmp (tag_id)")
|
||||||
|
database.execSQL("INSERT INTO manga_tags_tmp (manga_id, tag_id) SELECT manga_id, tag_id FROM manga_tags")
|
||||||
|
database.execSQL("DROP TABLE manga_tags")
|
||||||
|
database.execSQL("ALTER TABLE manga_tags_tmp RENAME TO manga_tags")
|
||||||
|
/* favourites */
|
||||||
|
database.execSQL(
|
||||||
|
"CREATE TABLE IF NOT EXISTS favourites_tmp (manga_id INTEGER NOT NULL, category_id INTEGER NOT NULL, created_at INTEGER NOT NULL, " +
|
||||||
|
"PRIMARY KEY(manga_id, category_id), " +
|
||||||
|
"FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE , " +
|
||||||
|
"FOREIGN KEY(category_id) REFERENCES favourite_categories(category_id) ON UPDATE NO ACTION ON DELETE CASCADE )"
|
||||||
|
)
|
||||||
|
database.execSQL("CREATE INDEX IF NOT EXISTS index_favourites_manga_id ON favourites_tmp (manga_id)")
|
||||||
|
database.execSQL("CREATE INDEX IF NOT EXISTS index_favourites_category_id ON favourites_tmp (category_id)")
|
||||||
|
database.execSQL("INSERT INTO favourites_tmp (manga_id, category_id, created_at) SELECT manga_id, category_id, created_at FROM favourites")
|
||||||
|
database.execSQL("DROP TABLE favourites")
|
||||||
|
database.execSQL("ALTER TABLE favourites_tmp RENAME TO favourites")
|
||||||
|
/* history */
|
||||||
|
database.execSQL(
|
||||||
|
"CREATE TABLE IF NOT EXISTS history_tmp (manga_id INTEGER NOT NULL, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL, chapter_id INTEGER NOT NULL, page INTEGER NOT NULL, " +
|
||||||
|
"PRIMARY KEY(manga_id), " +
|
||||||
|
"FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE )"
|
||||||
|
)
|
||||||
|
database.execSQL("INSERT INTO history_tmp (manga_id, created_at, updated_at, chapter_id, page) SELECT manga_id, created_at, updated_at, chapter_id, page FROM history")
|
||||||
|
database.execSQL("DROP TABLE history")
|
||||||
|
database.execSQL("ALTER TABLE history_tmp RENAME TO history")
|
||||||
|
/* preferences */
|
||||||
|
database.execSQL(
|
||||||
|
"CREATE TABLE IF NOT EXISTS preferences_tmp (manga_id INTEGER NOT NULL, mode INTEGER NOT NULL," +
|
||||||
|
" PRIMARY KEY(manga_id), " +
|
||||||
|
"FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE )"
|
||||||
|
)
|
||||||
|
database.execSQL("INSERT INTO preferences_tmp (manga_id, mode) SELECT manga_id, mode FROM preferences")
|
||||||
|
database.execSQL("DROP TABLE preferences")
|
||||||
|
database.execSQL("ALTER TABLE preferences_tmp RENAME TO preferences")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db.migrations
|
||||||
|
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
|
||||||
|
object Migration2To3 : Migration(2, 3) {
|
||||||
|
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("ALTER TABLE history ADD COLUMN scroll REAL NOT NULL DEFAULT 0")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db.migrations
|
||||||
|
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
|
||||||
|
object Migration3To4 : Migration(3, 4) {
|
||||||
|
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("CREATE TABLE IF NOT EXISTS tracks (manga_id INTEGER NOT NULL, chapters_total INTEGER NOT NULL, last_chapter_id INTEGER NOT NULL, chapters_new INTEGER NOT NULL, last_check INTEGER NOT NULL, last_notified_id INTEGER NOT NULL, PRIMARY KEY(manga_id), FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE )")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db.migrations
|
||||||
|
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
|
||||||
|
object Migration4To5 : Migration(4, 5) {
|
||||||
|
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("ALTER TABLE favourite_categories ADD COLUMN sort_key INTEGER NOT NULL DEFAULT 0")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db.migrations
|
||||||
|
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
|
||||||
|
object Migration5To6 : Migration(5, 6) {
|
||||||
|
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("CREATE TABLE IF NOT EXISTS track_logs (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, manga_id INTEGER NOT NULL, chapters TEXT NOT NULL, created_at INTEGER NOT NULL, FOREIGN KEY(manga_id) REFERENCES manga(manga_id) ON UPDATE NO ACTION ON DELETE CASCADE)")
|
||||||
|
database.execSQL("CREATE INDEX IF NOT EXISTS index_track_logs_manga_id ON track_logs (manga_id)")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
package org.koitharu.kotatsu.core.exceptions
|
package org.koitharu.kotatsu.core.exceptions
|
||||||
|
|
||||||
import java.lang.NullPointerException
|
|
||||||
|
|
||||||
class MangaNotFoundException(s: String? = null) : RuntimeException(s)
|
class MangaNotFoundException(s: String? = null) : RuntimeException(s)
|
||||||
@@ -9,11 +9,6 @@ data class AppVersion(
|
|||||||
val name: String,
|
val name: String,
|
||||||
val url: String,
|
val url: String,
|
||||||
val apkSize: Long,
|
val apkSize: Long,
|
||||||
val apkUrl: String
|
val apkUrl: String,
|
||||||
) : Parcelable {
|
val description: String
|
||||||
|
) : Parcelable
|
||||||
fun isGreaterThen(version: String) {
|
|
||||||
val thisParts = name.substringBeforeLast('-').split('.')
|
|
||||||
val parts = version.substringBeforeLast('-').split('.')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,7 +22,8 @@ class GithubRepository : KoinComponent {
|
|||||||
url = json.getString("html_url"),
|
url = json.getString("html_url"),
|
||||||
name = json.getString("name").removePrefix("v"),
|
name = json.getString("name").removePrefix("v"),
|
||||||
apkSize = asset.getLong("size"),
|
apkSize = asset.getLong("size"),
|
||||||
apkUrl = asset.getString("browser_download_url")
|
apkUrl = asset.getString("browser_download_url"),
|
||||||
|
description = json.getString("body")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ package org.koitharu.kotatsu.core.local
|
|||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.webkit.MimeTypeMap
|
import android.webkit.MimeTypeMap
|
||||||
import coil.bitmappool.BitmapPool
|
import coil.bitmap.BitmapPool
|
||||||
import coil.decode.DataSource
|
import coil.decode.DataSource
|
||||||
import coil.decode.Options
|
import coil.decode.Options
|
||||||
import coil.fetch.FetchResult
|
import coil.fetch.FetchResult
|
||||||
@@ -15,6 +15,7 @@ import java.util.zip.ZipFile
|
|||||||
|
|
||||||
class CbzFetcher : Fetcher<Uri> {
|
class CbzFetcher : Fetcher<Uri> {
|
||||||
|
|
||||||
|
@Suppress("BlockingMethodInNonBlockingContext")
|
||||||
override suspend fun fetch(
|
override suspend fun fetch(
|
||||||
pool: BitmapPool,
|
pool: BitmapPool,
|
||||||
data: Uri,
|
data: Uri,
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class SetCookieCache : CookieCache {
|
|||||||
|
|
||||||
override fun iterator(): MutableIterator<Cookie> = SetCookieCacheIterator()
|
override fun iterator(): MutableIterator<Cookie> = SetCookieCacheIterator()
|
||||||
|
|
||||||
private inner class SetCookieCacheIterator internal constructor() : MutableIterator<Cookie> {
|
private inner class SetCookieCacheIterator : MutableIterator<Cookie> {
|
||||||
|
|
||||||
private val iterator = cookies.iterator()
|
private val iterator = cookies.iterator()
|
||||||
|
|
||||||
|
|||||||
@@ -41,27 +41,24 @@ class SharedPrefsCookiePersistor(private val sharedPreferences: SharedPreference
|
|||||||
return cookies
|
return cookies
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
|
||||||
override fun saveAll(cookies: Collection<Cookie>) {
|
override fun saveAll(cookies: Collection<Cookie>) {
|
||||||
val editor = sharedPreferences.edit()
|
val editor = sharedPreferences.edit()
|
||||||
for (cookie in cookies) {
|
for (cookie in cookies) {
|
||||||
editor.putString(createCookieKey(cookie), SerializableCookie().encode(cookie))
|
editor.putString(createCookieKey(cookie), SerializableCookie().encode(cookie))
|
||||||
}
|
}
|
||||||
editor.commit()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
|
||||||
override fun removeAll(cookies: Collection<Cookie>) {
|
override fun removeAll(cookies: Collection<Cookie>) {
|
||||||
val editor = sharedPreferences.edit()
|
val editor = sharedPreferences.edit()
|
||||||
for (cookie in cookies) {
|
for (cookie in cookies) {
|
||||||
editor.remove(createCookieKey(cookie))
|
editor.remove(createCookieKey(cookie))
|
||||||
}
|
}
|
||||||
editor.commit()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
|
||||||
override fun clear() {
|
override fun clear() {
|
||||||
sharedPreferences.edit().clear().commit()
|
sharedPreferences.edit().clear().apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
|
|||||||
@@ -8,5 +8,6 @@ import java.util.*
|
|||||||
data class FavouriteCategory(
|
data class FavouriteCategory(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val title: String,
|
val title: String,
|
||||||
|
val sortKey: Int,
|
||||||
val createdAt: Date
|
val createdAt: Date
|
||||||
) : Parcelable
|
) : Parcelable
|
||||||
@@ -9,5 +9,6 @@ data class MangaHistory(
|
|||||||
val createdAt: Date,
|
val createdAt: Date,
|
||||||
val updatedAt: Date,
|
val updatedAt: Date,
|
||||||
val chapterId: Long,
|
val chapterId: Long,
|
||||||
val page: Int
|
val page: Int,
|
||||||
|
val scroll: Int
|
||||||
) : Parcelable
|
) : Parcelable
|
||||||
@@ -18,6 +18,10 @@ enum class MangaSource(
|
|||||||
MINTMANGA("MintManga", "ru", MintMangaRepository::class.java),
|
MINTMANGA("MintManga", "ru", MintMangaRepository::class.java),
|
||||||
SELFMANGA("SelfManga", "ru", SelfMangaRepository::class.java),
|
SELFMANGA("SelfManga", "ru", SelfMangaRepository::class.java),
|
||||||
MANGACHAN("Манга-тян", "ru", MangaChanRepository::class.java),
|
MANGACHAN("Манга-тян", "ru", MangaChanRepository::class.java),
|
||||||
|
DESUME("Desu.me", "ru", DesuMeRepository::class.java),
|
||||||
HENCHAN("Хентай-тян", "ru", HenChanRepository::class.java),
|
HENCHAN("Хентай-тян", "ru", HenChanRepository::class.java),
|
||||||
YAOICHAN("Яой-тян", "ru", YaoiChanRepository::class.java)
|
YAOICHAN("Яой-тян", "ru", YaoiChanRepository::class.java),
|
||||||
|
MANGATOWN("MangaTown", "en", MangaTownRepository::class.java),
|
||||||
|
MANGALIB("MangaLib", "ru", MangaLibRepository::class.java)
|
||||||
|
// HENTAILIB("HentaiLib", "ru", HentaiLibRepository::class.java)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package org.koitharu.kotatsu.core.model
|
||||||
|
|
||||||
|
import android.os.Parcelable
|
||||||
|
import kotlinx.android.parcel.Parcelize
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
data class MangaTracking (
|
||||||
|
val manga: Manga,
|
||||||
|
val knownChaptersCount: Int,
|
||||||
|
val lastChapterId: Long,
|
||||||
|
val lastNotifiedChapterId: Long,
|
||||||
|
val lastCheck: Date?
|
||||||
|
): Parcelable
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.koitharu.kotatsu.core.model
|
||||||
|
|
||||||
|
import android.os.Parcelable
|
||||||
|
import kotlinx.android.parcel.Parcelize
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
data class TrackingLogItem (
|
||||||
|
val id: Long,
|
||||||
|
val manga: Manga,
|
||||||
|
val chapters: List<String>,
|
||||||
|
val createdAt: Date
|
||||||
|
): Parcelable
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
package org.koitharu.kotatsu.core.parser
|
package org.koitharu.kotatsu.core.parser
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.webkit.MimeTypeMap
|
||||||
|
import androidx.collection.ArraySet
|
||||||
import androidx.core.net.toFile
|
import androidx.core.net.toFile
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import org.koin.core.KoinComponent
|
import org.koin.core.KoinComponent
|
||||||
@@ -14,6 +17,7 @@ import org.koitharu.kotatsu.utils.AlphanumComparator
|
|||||||
import org.koitharu.kotatsu.utils.ext.longHashCode
|
import org.koitharu.kotatsu.utils.ext.longHashCode
|
||||||
import org.koitharu.kotatsu.utils.ext.readText
|
import org.koitharu.kotatsu.utils.ext.readText
|
||||||
import org.koitharu.kotatsu.utils.ext.safe
|
import org.koitharu.kotatsu.utils.ext.safe
|
||||||
|
import org.koitharu.kotatsu.utils.ext.sub
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
@@ -29,8 +33,8 @@ class LocalMangaRepository : MangaRepository, KoinComponent {
|
|||||||
sortOrder: SortOrder?,
|
sortOrder: SortOrder?,
|
||||||
tag: MangaTag?
|
tag: MangaTag?
|
||||||
): List<Manga> {
|
): List<Manga> {
|
||||||
val files = context.getExternalFilesDirs("manga")
|
val files = getAvailableStorageDirs(context)
|
||||||
.flatMap { x -> x?.listFiles(CbzFilter())?.toList().orEmpty() }
|
.flatMap { x -> x.listFiles(CbzFilter())?.toList().orEmpty() }
|
||||||
return files.mapNotNull { x -> safe { getFromFile(x) } }
|
return files.mapNotNull { x -> safe { getFromFile(x) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,80 +42,114 @@ class LocalMangaRepository : MangaRepository, KoinComponent {
|
|||||||
getFromFile(Uri.parse(manga.url).toFile())
|
getFromFile(Uri.parse(manga.url).toFile())
|
||||||
} else manga
|
} else manga
|
||||||
|
|
||||||
|
@Suppress("BlockingMethodInNonBlockingContext")
|
||||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
||||||
val file = Uri.parse(chapter.url).toFile()
|
val uri = Uri.parse(chapter.url)
|
||||||
|
val file = uri.toFile()
|
||||||
val zip = ZipFile(file)
|
val zip = ZipFile(file)
|
||||||
val pattern = zip.getEntry(MangaZip.INDEX_ENTRY)?.let(zip::readText)?.let(::MangaIndex)
|
val index = zip.getEntry(MangaZip.INDEX_ENTRY)?.let(zip::readText)?.let(::MangaIndex)
|
||||||
?.getChapterNamesPattern(chapter)
|
var entries = zip.entries().asSequence()
|
||||||
val entries = if (pattern != null) {
|
entries = if (index != null) {
|
||||||
zip.entries().asSequence()
|
val pattern = index.getChapterNamesPattern(chapter)
|
||||||
.filter { x -> !x.isDirectory && x.name.substringBefore('.').matches(pattern) }
|
entries.filter { x -> !x.isDirectory && x.name.substringBefore('.').matches(pattern) }
|
||||||
} else {
|
} else {
|
||||||
zip.entries().asSequence().filter { x -> !x.isDirectory }
|
val parent = uri.fragment.orEmpty()
|
||||||
}.toList().sortedWith(compareBy(AlphanumComparator()) { x -> x.name })
|
entries.filter { x ->
|
||||||
return entries.map { x ->
|
!x.isDirectory && x.name.substringBeforeLast(
|
||||||
val uri = zipUri(file, x.name)
|
File.separatorChar,
|
||||||
MangaPage(
|
""
|
||||||
id = uri.longHashCode(),
|
) == parent
|
||||||
url = uri,
|
}
|
||||||
source = MangaSource.LOCAL
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
return entries
|
||||||
|
.toList()
|
||||||
|
.sortedWith(compareBy(AlphanumComparator()) { x -> x.name })
|
||||||
|
.map { x ->
|
||||||
|
val entryUri = zipUri(file, x.name)
|
||||||
|
MangaPage(
|
||||||
|
id = entryUri.longHashCode(),
|
||||||
|
url = entryUri,
|
||||||
|
source = MangaSource.LOCAL
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun delete(manga: Manga): Boolean {
|
fun delete(manga: Manga): Boolean {
|
||||||
val file = Uri.parse(manga.url).toFile()
|
val file = Uri.parse(manga.url).toFile()
|
||||||
return file.delete()
|
return file.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFromFile(file: File): Manga {
|
@SuppressLint("DefaultLocale")
|
||||||
val zip = ZipFile(file)
|
fun getFromFile(file: File): Manga = ZipFile(file).use { zip ->
|
||||||
val fileUri = file.toUri().toString()
|
val fileUri = file.toUri().toString()
|
||||||
val entry = zip.getEntry(MangaZip.INDEX_ENTRY)
|
val entry = zip.getEntry(MangaZip.INDEX_ENTRY)
|
||||||
val index = entry?.let(zip::readText)?.let(::MangaIndex)
|
val index = entry?.let(zip::readText)?.let(::MangaIndex)
|
||||||
return index?.let {
|
val info = index?.getMangaInfo()
|
||||||
it.getMangaInfo()?.let { x ->
|
if (index != null && info != null) {
|
||||||
x.copy(
|
return info.copy(
|
||||||
source = MangaSource.LOCAL,
|
|
||||||
url = fileUri,
|
|
||||||
coverUrl = zipUri(
|
|
||||||
file,
|
|
||||||
entryName = it.getCoverEntry()
|
|
||||||
?: findFirstEntry(zip.entries())?.name.orEmpty()
|
|
||||||
),
|
|
||||||
chapters = x.chapters?.map { c -> c.copy(url = fileUri) }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} ?: run {
|
|
||||||
val title = file.nameWithoutExtension.replace("_", " ").capitalize()
|
|
||||||
Manga(
|
|
||||||
id = file.absolutePath.longHashCode(),
|
|
||||||
title = title,
|
|
||||||
url = fileUri,
|
|
||||||
source = MangaSource.LOCAL,
|
source = MangaSource.LOCAL,
|
||||||
coverUrl = zipUri(file, findFirstEntry(zip.entries())?.name.orEmpty()),
|
url = fileUri,
|
||||||
chapters = listOf(
|
coverUrl = zipUri(
|
||||||
MangaChapter(
|
file,
|
||||||
id = file.absolutePath.longHashCode(),
|
entryName = index.getCoverEntry()
|
||||||
url = fileUri,
|
?: findFirstEntry(zip.entries(), isImage = true)?.name.orEmpty()
|
||||||
number = 1,
|
),
|
||||||
source = MangaSource.LOCAL,
|
chapters = info.chapters?.map { c -> c.copy(url = fileUri) }
|
||||||
name = title
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
// fallback
|
||||||
|
val title = file.nameWithoutExtension.replace("_", " ").capitalize()
|
||||||
|
val chapters = ArraySet<String>()
|
||||||
|
for (x in zip.entries()) {
|
||||||
|
if (!x.isDirectory) {
|
||||||
|
chapters += x.name.substringBeforeLast(File.separatorChar, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val uriBuilder = file.toUri().buildUpon()
|
||||||
|
Manga(
|
||||||
|
id = file.absolutePath.longHashCode(),
|
||||||
|
title = title,
|
||||||
|
url = fileUri,
|
||||||
|
source = MangaSource.LOCAL,
|
||||||
|
coverUrl = zipUri(file, findFirstEntry(zip.entries(), isImage = true)?.name.orEmpty()),
|
||||||
|
chapters = chapters.sortedWith(AlphanumComparator()).mapIndexed { i, s ->
|
||||||
|
MangaChapter(
|
||||||
|
id = "$i$s".longHashCode(),
|
||||||
|
name = if (s.isEmpty()) title else s,
|
||||||
|
number = i + 1,
|
||||||
|
source = MangaSource.LOCAL,
|
||||||
|
url = uriBuilder.fragment(s).build().toString()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getRemoteManga(localManga: Manga): Manga? {
|
||||||
|
val file = safe {
|
||||||
|
Uri.parse(localManga.url).toFile()
|
||||||
|
} ?: return null
|
||||||
|
val zip = ZipFile(file)
|
||||||
|
val entry = zip.getEntry(MangaZip.INDEX_ENTRY)
|
||||||
|
val index = entry?.let(zip::readText)?.let(::MangaIndex) ?: return null
|
||||||
|
return index.getMangaInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun zipUri(file: File, entryName: String) =
|
private fun zipUri(file: File, entryName: String) =
|
||||||
Uri.fromParts("cbz", file.path, entryName).toString()
|
Uri.fromParts("cbz", file.path, entryName).toString()
|
||||||
|
|
||||||
private fun findFirstEntry(entries: Enumeration<out ZipEntry>): ZipEntry? {
|
private fun findFirstEntry(entries: Enumeration<out ZipEntry>, isImage: Boolean): ZipEntry? {
|
||||||
val list = entries.toList()
|
val list = entries.toList()
|
||||||
.filterNot { it.isDirectory }
|
.filterNot { it.isDirectory }
|
||||||
.sortedWith(compareBy(AlphanumComparator()) { x -> x.name })
|
.sortedWith(compareBy(AlphanumComparator()) { x -> x.name })
|
||||||
return list.firstOrNull()
|
return if (isImage) {
|
||||||
|
val map = MimeTypeMap.getSingleton()
|
||||||
|
list.firstOrNull {
|
||||||
|
map.getMimeTypeFromExtension(it.name.substringAfterLast('.'))
|
||||||
|
?.startsWith("image/") == true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
list.firstOrNull()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val sortOrders = emptySet<SortOrder>()
|
override val sortOrders = emptySet<SortOrder>()
|
||||||
@@ -122,9 +160,24 @@ class LocalMangaRepository : MangaRepository, KoinComponent {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
private const val DIR_NAME = "manga"
|
||||||
|
|
||||||
fun isFileSupported(name: String): Boolean {
|
fun isFileSupported(name: String): Boolean {
|
||||||
val ext = name.substringAfterLast('.').toLowerCase(Locale.ROOT)
|
val ext = name.substringAfterLast('.').toLowerCase(Locale.ROOT)
|
||||||
return ext == "cbz" || ext == "zip"
|
return ext == "cbz" || ext == "zip"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getAvailableStorageDirs(context: Context): List<File> {
|
||||||
|
val result = ArrayList<File>(5)
|
||||||
|
result += context.filesDir.sub(DIR_NAME)
|
||||||
|
result += context.getExternalFilesDirs(DIR_NAME)
|
||||||
|
return result.distinctBy { it.canonicalPath }.filter { it.exists() || it.mkdir() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getFallbackStorageDir(context: Context): File? {
|
||||||
|
return context.getExternalFilesDir(DIR_NAME) ?: context.filesDir.sub(DIR_NAME).takeIf {
|
||||||
|
(it.exists() || it.mkdir()) && it.canWrite()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,15 @@
|
|||||||
package org.koitharu.kotatsu.core.parser
|
package org.koitharu.kotatsu.core.parser
|
||||||
|
|
||||||
import org.koin.core.KoinComponent
|
|
||||||
import org.koin.core.inject
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaPage
|
import org.koitharu.kotatsu.core.model.MangaPage
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
import org.koitharu.kotatsu.core.model.MangaTag
|
import org.koitharu.kotatsu.core.model.MangaTag
|
||||||
import org.koitharu.kotatsu.core.model.SortOrder
|
import org.koitharu.kotatsu.core.model.SortOrder
|
||||||
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||||
|
|
||||||
abstract class RemoteMangaRepository : MangaRepository, KoinComponent {
|
abstract class RemoteMangaRepository(protected val loaderContext: MangaLoaderContext) : MangaRepository {
|
||||||
|
|
||||||
protected abstract val source: MangaSource
|
protected abstract val source: MangaSource
|
||||||
|
|
||||||
protected val loaderContext by inject<MangaLoaderContext>()
|
|
||||||
protected val conf by lazy(LazyThreadSafetyMode.NONE) {
|
protected val conf by lazy(LazyThreadSafetyMode.NONE) {
|
||||||
loaderContext.getSettings(source)
|
loaderContext.getSettings(source)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.koitharu.kotatsu.core.parser
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.os.Build
|
||||||
|
import okhttp3.Interceptor
|
||||||
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
@SuppressLint("ConstantLocale")
|
||||||
|
object UserAgentInterceptor : Interceptor {
|
||||||
|
|
||||||
|
private val userAgent = "Kotatsu/%s (Android %s; %s; %s %s; %s)".format(
|
||||||
|
BuildConfig.VERSION_NAME,
|
||||||
|
Build.VERSION.RELEASE,
|
||||||
|
Build.MODEL,
|
||||||
|
Build.BRAND,
|
||||||
|
Build.DEVICE,
|
||||||
|
Locale.getDefault().language
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun intercept(chain: Interceptor.Chain) = chain.proceed(
|
||||||
|
chain.request().newBuilder()
|
||||||
|
.header("User-Agent", userAgent)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -4,9 +4,12 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
import org.koitharu.kotatsu.core.exceptions.ParseException
|
||||||
import org.koitharu.kotatsu.core.model.*
|
import org.koitharu.kotatsu.core.model.*
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
||||||
|
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.*
|
||||||
|
|
||||||
abstract class ChanRepository : RemoteMangaRepository() {
|
abstract class ChanRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepository(
|
||||||
|
loaderContext
|
||||||
|
) {
|
||||||
|
|
||||||
protected abstract val defaultDomain: String
|
protected abstract val defaultDomain: String
|
||||||
|
|
||||||
@@ -20,7 +23,12 @@ abstract class ChanRepository : RemoteMangaRepository() {
|
|||||||
): List<Manga> {
|
): List<Manga> {
|
||||||
val domain = conf.getDomain(defaultDomain)
|
val domain = conf.getDomain(defaultDomain)
|
||||||
val url = when {
|
val url = when {
|
||||||
query != null -> "https://$domain/?do=search&subaction=search&story=${query.urlEncoded()}"
|
!query.isNullOrEmpty() -> {
|
||||||
|
if (offset != 0) {
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
|
"https://$domain/?do=search&subaction=search&story=${query.urlEncoded()}"
|
||||||
|
}
|
||||||
tag != null -> "https://$domain/tags/${tag.key}&n=${getSortKey2(sortOrder)}?offset=$offset"
|
tag != null -> "https://$domain/tags/${tag.key}&n=${getSortKey2(sortOrder)}?offset=$offset"
|
||||||
else -> "https://$domain/${getSortKey(sortOrder)}?offset=$offset"
|
else -> "https://$domain/${getSortKey(sortOrder)}?offset=$offset"
|
||||||
}
|
}
|
||||||
@@ -93,7 +101,7 @@ abstract class ChanRepository : RemoteMangaRepository() {
|
|||||||
val json = data.substring(pos).substringAfter('[').substringBefore(';')
|
val json = data.substring(pos).substringAfter('[').substringBefore(';')
|
||||||
.substringBeforeLast(']')
|
.substringBeforeLast(']')
|
||||||
return json.split(",").mapNotNull {
|
return json.split(",").mapNotNull {
|
||||||
it.trim().removeSurrounding('"').takeUnless(String::isBlank)
|
it.trim().removeSurrounding('"','\'').takeUnless(String::isBlank)
|
||||||
}.map { url ->
|
}.map { url ->
|
||||||
MangaPage(
|
MangaPage(
|
||||||
id = url.longHashCode(),
|
id = url.longHashCode(),
|
||||||
@@ -123,7 +131,7 @@ abstract class ChanRepository : RemoteMangaRepository() {
|
|||||||
override fun onCreatePreferences() = setOf(R.string.key_parser_domain)
|
override fun onCreatePreferences() = setOf(R.string.key_parser_domain)
|
||||||
|
|
||||||
private fun getSortKey(sortOrder: SortOrder?) =
|
private fun getSortKey(sortOrder: SortOrder?) =
|
||||||
when (sortOrder ?: sortOrders.minBy { it.ordinal }) {
|
when (sortOrder ?: sortOrders.minByOrNull { it.ordinal }) {
|
||||||
SortOrder.ALPHABETICAL -> "catalog"
|
SortOrder.ALPHABETICAL -> "catalog"
|
||||||
SortOrder.POPULARITY -> "mostfavorites"
|
SortOrder.POPULARITY -> "mostfavorites"
|
||||||
SortOrder.NEWEST -> "manga/new"
|
SortOrder.NEWEST -> "manga/new"
|
||||||
@@ -131,7 +139,7 @@ abstract class ChanRepository : RemoteMangaRepository() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getSortKey2(sortOrder: SortOrder?) =
|
private fun getSortKey2(sortOrder: SortOrder?) =
|
||||||
when (sortOrder ?: sortOrders.minBy { it.ordinal }) {
|
when (sortOrder ?: sortOrders.minByOrNull { it.ordinal }) {
|
||||||
SortOrder.ALPHABETICAL -> "abcasc"
|
SortOrder.ALPHABETICAL -> "abcasc"
|
||||||
SortOrder.POPULARITY -> "favdesc"
|
SortOrder.POPULARITY -> "favdesc"
|
||||||
SortOrder.NEWEST -> "datedesc"
|
SortOrder.NEWEST -> "datedesc"
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
package org.koitharu.kotatsu.core.parser.site
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.exceptions.ParseException
|
||||||
|
import org.koitharu.kotatsu.core.model.*
|
||||||
|
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
||||||
|
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||||
|
import org.koitharu.kotatsu.utils.ext.map
|
||||||
|
import org.koitharu.kotatsu.utils.ext.mapIndexed
|
||||||
|
import org.koitharu.kotatsu.utils.ext.parseHtml
|
||||||
|
import org.koitharu.kotatsu.utils.ext.parseJson
|
||||||
|
|
||||||
|
class DesuMeRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepository(loaderContext) {
|
||||||
|
|
||||||
|
override val source = MangaSource.DESUME
|
||||||
|
|
||||||
|
override val sortOrders = setOf(
|
||||||
|
SortOrder.UPDATED,
|
||||||
|
SortOrder.POPULARITY,
|
||||||
|
SortOrder.NEWEST,
|
||||||
|
SortOrder.ALPHABETICAL
|
||||||
|
)
|
||||||
|
|
||||||
|
override suspend fun getList(
|
||||||
|
offset: Int,
|
||||||
|
query: String?,
|
||||||
|
sortOrder: SortOrder?,
|
||||||
|
tag: MangaTag?
|
||||||
|
): List<Manga> {
|
||||||
|
val domain = conf.getDomain(DOMAIN)
|
||||||
|
val url = buildString {
|
||||||
|
append("https://")
|
||||||
|
append(domain)
|
||||||
|
append("/manga/api/?limit=20&order=")
|
||||||
|
append(getSortKey(sortOrder))
|
||||||
|
append("&page=")
|
||||||
|
append((offset / 20) + 1)
|
||||||
|
if (tag != null) {
|
||||||
|
append("&genres=")
|
||||||
|
append(tag.key)
|
||||||
|
}
|
||||||
|
if (query != null) {
|
||||||
|
append("&search=")
|
||||||
|
append(query)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val json = loaderContext.httpGet(url).parseJson().getJSONArray("response")
|
||||||
|
?: throw ParseException("Invalid response")
|
||||||
|
val total = json.length()
|
||||||
|
val list = ArrayList<Manga>(total)
|
||||||
|
for (i in 0 until total) {
|
||||||
|
val jo = json.getJSONObject(i)
|
||||||
|
val cover = jo.getJSONObject("image")
|
||||||
|
list += Manga(
|
||||||
|
url = jo.getString("url"),
|
||||||
|
source = MangaSource.DESUME,
|
||||||
|
title = jo.getString("russian"),
|
||||||
|
altTitle = jo.getString("name"),
|
||||||
|
coverUrl = cover.getString("preview"),
|
||||||
|
largeCoverUrl = cover.getString("original"),
|
||||||
|
state = when {
|
||||||
|
jo.getInt("ongoing") == 1 -> MangaState.ONGOING
|
||||||
|
else -> null
|
||||||
|
},
|
||||||
|
rating = jo.getDouble("score").toFloat().coerceIn(0f, 1f),
|
||||||
|
id = ID_MASK + jo.getLong("id"),
|
||||||
|
description = jo.getString("description")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getDetails(manga: Manga): Manga {
|
||||||
|
val domain = conf.getDomain(DOMAIN)
|
||||||
|
val url = "https://$domain/manga/api/${manga.id - ID_MASK}"
|
||||||
|
val json = loaderContext.httpGet(url).parseJson().getJSONObject("response")
|
||||||
|
?: throw ParseException("Invalid response")
|
||||||
|
return manga.copy(
|
||||||
|
tags = json.getJSONArray("genres").map {
|
||||||
|
MangaTag(
|
||||||
|
key = it.getString("text"),
|
||||||
|
title = it.getString("russian"),
|
||||||
|
source = manga.source
|
||||||
|
)
|
||||||
|
}.toSet(),
|
||||||
|
description = json.getString("description"),
|
||||||
|
chapters = json.getJSONObject("chapters").getJSONArray("list").mapIndexed { i, it ->
|
||||||
|
val chid = it.getLong("id")
|
||||||
|
MangaChapter(
|
||||||
|
id = ID_MASK + chid,
|
||||||
|
source = manga.source,
|
||||||
|
url = "$url/chapter/$chid",
|
||||||
|
name = it.optString("title", "${manga.title} #${it.getDouble("ch")}"),
|
||||||
|
number = i + 1
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
||||||
|
val json = loaderContext.httpGet(chapter.url).parseJson().getJSONObject("response")
|
||||||
|
?: throw ParseException("Invalid response")
|
||||||
|
return json.getJSONObject("pages").getJSONArray("list").map {
|
||||||
|
MangaPage(
|
||||||
|
id = it.getLong("id"),
|
||||||
|
source = chapter.source,
|
||||||
|
url = it.getString("img")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getTags(): Set<MangaTag> {
|
||||||
|
val domain = conf.getDomain(DOMAIN)
|
||||||
|
val doc = loaderContext.httpGet("https://$domain/manga/").parseHtml()
|
||||||
|
val root = doc.body().getElementById("animeFilter").selectFirst(".catalog-genres")
|
||||||
|
return root.select("li").map {
|
||||||
|
MangaTag(
|
||||||
|
source = source,
|
||||||
|
key = it.selectFirst("input").attr("data-genre"),
|
||||||
|
title = it.selectFirst("label").text()
|
||||||
|
)
|
||||||
|
}.toSet()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreatePreferences() = setOf(R.string.key_parser_domain)
|
||||||
|
|
||||||
|
private fun getSortKey(sortOrder: SortOrder?) =
|
||||||
|
when (sortOrder) {
|
||||||
|
SortOrder.ALPHABETICAL -> "name"
|
||||||
|
SortOrder.POPULARITY -> "popular"
|
||||||
|
SortOrder.UPDATED -> "updated"
|
||||||
|
SortOrder.NEWEST -> "id"
|
||||||
|
else -> "updated"
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
|
||||||
|
private const val ID_MASK = 1000
|
||||||
|
private const val DOMAIN = "desu.me"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,9 +4,11 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
import org.koitharu.kotatsu.core.exceptions.ParseException
|
||||||
import org.koitharu.kotatsu.core.model.*
|
import org.koitharu.kotatsu.core.model.*
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
||||||
|
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.utils.ext.*
|
import org.koitharu.kotatsu.utils.ext.*
|
||||||
|
|
||||||
abstract class GroupleRepository : RemoteMangaRepository() {
|
abstract class GroupleRepository(loaderContext: MangaLoaderContext) :
|
||||||
|
RemoteMangaRepository(loaderContext) {
|
||||||
|
|
||||||
protected abstract val defaultDomain: String
|
protected abstract val defaultDomain: String
|
||||||
|
|
||||||
@@ -26,9 +28,13 @@ abstract class GroupleRepository : RemoteMangaRepository() {
|
|||||||
val doc = when {
|
val doc = when {
|
||||||
!query.isNullOrEmpty() -> loaderContext.httpPost(
|
!query.isNullOrEmpty() -> loaderContext.httpPost(
|
||||||
"https://$domain/search",
|
"https://$domain/search",
|
||||||
mapOf("q" to query, "offset" to offset.toString())
|
mapOf("q" to query.urlEncoded(), "offset" to offset.toString())
|
||||||
|
)
|
||||||
|
tag == null -> loaderContext.httpGet(
|
||||||
|
"https://$domain/list?sortType=${getSortKey(
|
||||||
|
sortOrder
|
||||||
|
)}&offset=$offset"
|
||||||
)
|
)
|
||||||
tag == null -> loaderContext.httpGet("https://$domain/list?sortType=${getSortKey(sortOrder)}&offset=$offset")
|
|
||||||
else -> loaderContext.httpGet(
|
else -> loaderContext.httpGet(
|
||||||
"https://$domain/list/genre/${tag.key}?sortType=${getSortKey(
|
"https://$domain/list/genre/${tag.key}?sortType=${getSortKey(
|
||||||
sortOrder
|
sortOrder
|
||||||
@@ -85,19 +91,29 @@ abstract class GroupleRepository : RemoteMangaRepository() {
|
|||||||
override suspend fun getDetails(manga: Manga): Manga {
|
override suspend fun getDetails(manga: Manga): Manga {
|
||||||
val domain = conf.getDomain(defaultDomain)
|
val domain = conf.getDomain(defaultDomain)
|
||||||
val doc = loaderContext.httpGet(manga.url).parseHtml()
|
val doc = loaderContext.httpGet(manga.url).parseHtml()
|
||||||
val root = doc.body().getElementById("mangaBox") ?: throw ParseException("Cannot find root")
|
val root = doc.body().getElementById("mangaBox")?.selectFirst("div.leftContent")
|
||||||
|
?: throw ParseException("Cannot find root")
|
||||||
return manga.copy(
|
return manga.copy(
|
||||||
description = root.selectFirst("div.manga-description")?.html(),
|
description = root.selectFirst("div.manga-description")?.html(),
|
||||||
largeCoverUrl = root.selectFirst("div.subject-cower")?.selectFirst("img")?.attr(
|
largeCoverUrl = root.selectFirst("div.subject-cower")?.selectFirst("img")?.attr(
|
||||||
"data-full"
|
"data-full"
|
||||||
),
|
),
|
||||||
|
tags = manga.tags + root.select("div.subject-meta").select("span.elem_genre ")
|
||||||
|
.mapNotNull {
|
||||||
|
val a = it.selectFirst("a.element-link") ?: return@mapNotNull null
|
||||||
|
MangaTag(
|
||||||
|
title = a.text(),
|
||||||
|
key = a.attr("href").substringAfterLast('/'),
|
||||||
|
source = source
|
||||||
|
)
|
||||||
|
},
|
||||||
chapters = root.selectFirst("div.chapters-link")?.selectFirst("table")
|
chapters = root.selectFirst("div.chapters-link")?.selectFirst("table")
|
||||||
?.select("a")?.asReversed()?.mapIndexedNotNull { i, a ->
|
?.select("a")?.asReversed()?.mapIndexedNotNull { i, a ->
|
||||||
val href =
|
val href =
|
||||||
a.attr("href")?.withDomain(domain) ?: return@mapIndexedNotNull null
|
a.attr("href")?.withDomain(domain) ?: return@mapIndexedNotNull null
|
||||||
MangaChapter(
|
MangaChapter(
|
||||||
id = href.longHashCode(),
|
id = href.longHashCode(),
|
||||||
name = a.ownText(),
|
name = a.ownText().removePrefix(manga.title).trim(),
|
||||||
number = i + 1,
|
number = i + 1,
|
||||||
url = href,
|
url = href,
|
||||||
source = source
|
source = source
|
||||||
@@ -149,7 +165,7 @@ abstract class GroupleRepository : RemoteMangaRepository() {
|
|||||||
override fun onCreatePreferences() = setOf(R.string.key_parser_domain)
|
override fun onCreatePreferences() = setOf(R.string.key_parser_domain)
|
||||||
|
|
||||||
private fun getSortKey(sortOrder: SortOrder?) =
|
private fun getSortKey(sortOrder: SortOrder?) =
|
||||||
when (sortOrder ?: sortOrders.minBy { it.ordinal }) {
|
when (sortOrder ?: sortOrders.minByOrNull { it.ordinal }) {
|
||||||
SortOrder.ALPHABETICAL -> "name"
|
SortOrder.ALPHABETICAL -> "name"
|
||||||
SortOrder.POPULARITY -> "rate"
|
SortOrder.POPULARITY -> "rate"
|
||||||
SortOrder.UPDATED -> "updated"
|
SortOrder.UPDATED -> "updated"
|
||||||
|
|||||||
@@ -1,39 +1,59 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
package org.koitharu.kotatsu.core.parser.site
|
||||||
|
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
import org.koitharu.kotatsu.core.exceptions.ParseException
|
||||||
import org.koitharu.kotatsu.core.model.Manga
|
import org.koitharu.kotatsu.core.model.*
|
||||||
import org.koitharu.kotatsu.core.model.MangaChapter
|
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
|
||||||
import org.koitharu.kotatsu.utils.ext.longHashCode
|
import org.koitharu.kotatsu.utils.ext.longHashCode
|
||||||
import org.koitharu.kotatsu.utils.ext.parseHtml
|
import org.koitharu.kotatsu.utils.ext.parseHtml
|
||||||
import org.koitharu.kotatsu.utils.ext.withDomain
|
import org.koitharu.kotatsu.utils.ext.withDomain
|
||||||
|
|
||||||
class HenChanRepository : ChanRepository() {
|
class HenChanRepository(loaderContext: MangaLoaderContext) : ChanRepository(loaderContext) {
|
||||||
|
|
||||||
override val defaultDomain = "h-chan.me"
|
override val defaultDomain = "hentaichan.pro"
|
||||||
override val source = MangaSource.HENCHAN
|
override val source = MangaSource.HENCHAN
|
||||||
|
|
||||||
|
override suspend fun getList(
|
||||||
|
offset: Int,
|
||||||
|
query: String?,
|
||||||
|
sortOrder: SortOrder?,
|
||||||
|
tag: MangaTag?
|
||||||
|
): List<Manga> {
|
||||||
|
return super.getList(offset, query, sortOrder, tag).map {
|
||||||
|
val cover = it.coverUrl
|
||||||
|
if (cover.contains("_blur")) {
|
||||||
|
it.copy(coverUrl = cover.replace("_blur", ""))
|
||||||
|
} else {
|
||||||
|
it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getDetails(manga: Manga): Manga {
|
override suspend fun getDetails(manga: Manga): Manga {
|
||||||
val domain = conf.getDomain(defaultDomain)
|
val domain = conf.getDomain(defaultDomain)
|
||||||
val doc = loaderContext.httpGet(manga.url).parseHtml()
|
val doc = loaderContext.httpGet(manga.url).parseHtml()
|
||||||
val root =
|
val root =
|
||||||
doc.body().getElementById("dle-content") ?: throw ParseException("Cannot find root")
|
doc.body().getElementById("dle-content") ?: throw ParseException("Cannot find root")
|
||||||
|
val readLink = manga.url.replace("manga", "online")
|
||||||
return manga.copy(
|
return manga.copy(
|
||||||
description = root.getElementById("description")?.html()?.substringBeforeLast("<div"),
|
description = root.getElementById("description")?.html()?.substringBeforeLast("<div"),
|
||||||
largeCoverUrl = root.getElementById("cover")?.attr("src")?.withDomain(domain),
|
largeCoverUrl = root.getElementById("cover")?.attr("src")?.withDomain(domain),
|
||||||
chapters = root.getElementById("right").select("table.table_cha").flatMap { table ->
|
tags = root.selectFirst("div.sidetags")?.select("li.sidetag")?.map {
|
||||||
table.select("div.manga2")
|
val a = it.children().last()
|
||||||
}.mapNotNull { it.selectFirst("a") }.reversed().mapIndexedNotNull { i, a ->
|
MangaTag(
|
||||||
val href = a.attr("href")
|
title = a.text(),
|
||||||
?.withDomain(domain) ?: return@mapIndexedNotNull null
|
key = a.attr("href").substringAfterLast('/'),
|
||||||
MangaChapter(
|
|
||||||
id = href.longHashCode(),
|
|
||||||
name = a.text().trim(),
|
|
||||||
number = i + 1,
|
|
||||||
url = href,
|
|
||||||
source = source
|
source = source
|
||||||
)
|
)
|
||||||
}
|
}?.toSet() ?: manga.tags,
|
||||||
|
chapters = listOf(
|
||||||
|
MangaChapter(
|
||||||
|
id = readLink.longHashCode(),
|
||||||
|
url = readLink,
|
||||||
|
source = source,
|
||||||
|
number = 1,
|
||||||
|
name = manga.title
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package org.koitharu.kotatsu.core.parser.site
|
||||||
|
|
||||||
|
/*
|
||||||
|
class HentaiLibRepository(loaderContext: MangaLoaderContext) : MangaLibRepository(loaderContext) {
|
||||||
|
|
||||||
|
protected override val defaultDomain = "hentailib.me"
|
||||||
|
|
||||||
|
override val source = MangaSource.HENTAILIB
|
||||||
|
|
||||||
|
}*/
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
package org.koitharu.kotatsu.core.parser.site
|
||||||
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||||
|
|
||||||
class MangaChanRepository : ChanRepository() {
|
class MangaChanRepository(loaderContext: MangaLoaderContext) : ChanRepository(loaderContext) {
|
||||||
|
|
||||||
override val defaultDomain = "manga-chan.me"
|
override val defaultDomain = "manga-chan.me"
|
||||||
override val source = MangaSource.MANGACHAN
|
override val source = MangaSource.MANGACHAN
|
||||||
|
|||||||
@@ -0,0 +1,223 @@
|
|||||||
|
package org.koitharu.kotatsu.core.parser.site
|
||||||
|
|
||||||
|
import org.json.JSONArray
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.exceptions.ParseException
|
||||||
|
import org.koitharu.kotatsu.core.model.*
|
||||||
|
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
||||||
|
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||||
|
import org.koitharu.kotatsu.utils.ext.*
|
||||||
|
|
||||||
|
open class MangaLibRepository(loaderContext: MangaLoaderContext) :
|
||||||
|
RemoteMangaRepository(loaderContext) {
|
||||||
|
|
||||||
|
protected open val defaultDomain = "mangalib.me"
|
||||||
|
|
||||||
|
override val source = MangaSource.MANGALIB
|
||||||
|
|
||||||
|
override val sortOrders = setOf(
|
||||||
|
SortOrder.RATING,
|
||||||
|
SortOrder.ALPHABETICAL,
|
||||||
|
SortOrder.POPULARITY,
|
||||||
|
SortOrder.UPDATED,
|
||||||
|
SortOrder.NEWEST
|
||||||
|
)
|
||||||
|
|
||||||
|
override suspend fun getList(
|
||||||
|
offset: Int,
|
||||||
|
query: String?,
|
||||||
|
sortOrder: SortOrder?,
|
||||||
|
tag: MangaTag?
|
||||||
|
): List<Manga> {
|
||||||
|
if (!query.isNullOrEmpty()) {
|
||||||
|
return search(query)
|
||||||
|
}
|
||||||
|
val domain = conf.getDomain(defaultDomain)
|
||||||
|
val page = (offset / 60f).toIntUp()
|
||||||
|
val url = buildString {
|
||||||
|
append("https://")
|
||||||
|
append(domain)
|
||||||
|
append("/manga-list?dir=")
|
||||||
|
append(getSortKey(sortOrder))
|
||||||
|
append("&page=")
|
||||||
|
append(page)
|
||||||
|
if (tag != null) {
|
||||||
|
append("&includeGenres[]=")
|
||||||
|
append(tag.key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val doc = loaderContext.httpGet(url).parseHtml()
|
||||||
|
val root = doc.body().getElementById("manga-list") ?: throw ParseException("Root not found")
|
||||||
|
val items = root.selectFirst("div.media-cards-grid").select("div.media-card-wrap")
|
||||||
|
return items.mapNotNull { card ->
|
||||||
|
val a = card.selectFirst("a.media-card") ?: return@mapNotNull null
|
||||||
|
val href = a.attr("href").withDomain(domain)
|
||||||
|
Manga(
|
||||||
|
id = href.longHashCode(),
|
||||||
|
title = card.selectFirst("h3").text(),
|
||||||
|
coverUrl = a.attr("data-src").withDomain(domain),
|
||||||
|
altTitle = null,
|
||||||
|
author = null,
|
||||||
|
rating = Manga.NO_RATING,
|
||||||
|
url = href,
|
||||||
|
tags = emptySet(),
|
||||||
|
state = null,
|
||||||
|
source = source
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreatePreferences() = setOf(R.string.key_parser_domain)
|
||||||
|
|
||||||
|
override suspend fun getDetails(manga: Manga): Manga {
|
||||||
|
val doc = loaderContext.httpGet(manga.url + "?section=info").parseHtml()
|
||||||
|
val root = doc.body().getElementById("main-page") ?: throw ParseException("Root not found")
|
||||||
|
val title = root.selectFirst("div.media-header__wrap")?.children()
|
||||||
|
val info = root.selectFirst("div.media-content")
|
||||||
|
val chaptersDoc = loaderContext.httpGet(manga.url + "?section=chapters").parseHtml()
|
||||||
|
val scripts = chaptersDoc.body().select("script")
|
||||||
|
var chapters: ArrayList<MangaChapter>? = null
|
||||||
|
scripts@ for (script in scripts) {
|
||||||
|
val raw = script.html().lines()
|
||||||
|
for (line in raw) {
|
||||||
|
if (line.startsWith("window.__CHAPTERS_DATA__")) {
|
||||||
|
val json = JSONObject(line.substringAfter('=').substringBeforeLast(';'))
|
||||||
|
val list = json.getJSONArray("list")
|
||||||
|
val total = list.length()
|
||||||
|
chapters = ArrayList(total)
|
||||||
|
for (i in 0 until total) {
|
||||||
|
val item = list.getJSONObject(i)
|
||||||
|
val url = buildString {
|
||||||
|
append(manga.url)
|
||||||
|
append("/v")
|
||||||
|
append(item.getInt("chapter_volume"))
|
||||||
|
append("/c")
|
||||||
|
append(item.getString("chapter_number"))
|
||||||
|
append('/')
|
||||||
|
append(item.getJSONArray("teams").getJSONObject(0).getString("slug"))
|
||||||
|
}
|
||||||
|
var name = item.getString("chapter_name")
|
||||||
|
if (name.isNullOrBlank() || name == "null") {
|
||||||
|
name = "Том " + item.getInt("chapter_volume") +
|
||||||
|
" Глава " + item.getString("chapter_number")
|
||||||
|
}
|
||||||
|
chapters.add(
|
||||||
|
MangaChapter(
|
||||||
|
id = url.longHashCode(),
|
||||||
|
url = url,
|
||||||
|
source = source,
|
||||||
|
number = total - i,
|
||||||
|
name = name
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
chapters.reverse()
|
||||||
|
break@scripts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return manga.copy(
|
||||||
|
title = title?.getOrNull(0)?.text()?.takeUnless(String::isBlank) ?: manga.title,
|
||||||
|
altTitle = title?.getOrNull(1)?.text()?.substringBefore('/')?.trim(),
|
||||||
|
rating = root.selectFirst("div.media-stats-item__score")
|
||||||
|
?.selectFirst("span")
|
||||||
|
?.text()?.toFloatOrNull()?.div(5f) ?: manga.rating,
|
||||||
|
author = info.getElementsMatchingOwnText("Автор").firstOrNull()
|
||||||
|
?.nextElementSibling()?.text() ?: manga.author,
|
||||||
|
tags = info.getElementsMatchingOwnText("Жанры")?.firstOrNull()
|
||||||
|
?.nextElementSibling()?.select("a")?.mapNotNull { a ->
|
||||||
|
MangaTag(
|
||||||
|
title = a.text().capitalize(),
|
||||||
|
key = a.attr("href").substringAfterLast('='),
|
||||||
|
source = source
|
||||||
|
)
|
||||||
|
}?.toSet() ?: manga.tags,
|
||||||
|
description = info.getElementsMatchingOwnText("Описание")?.firstOrNull()
|
||||||
|
?.nextElementSibling()?.html(),
|
||||||
|
chapters = chapters
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
||||||
|
val doc = loaderContext.httpGet(chapter.url).parseHtml()
|
||||||
|
val scripts = doc.head().select("script")
|
||||||
|
val pg = doc.body().getElementById("pg").html().substringAfter('=').substringBeforeLast(';')
|
||||||
|
val pages = JSONArray(pg)
|
||||||
|
for (script in scripts) {
|
||||||
|
val raw = script.html().trim()
|
||||||
|
if (raw.startsWith("window.__info")) {
|
||||||
|
val json = JSONObject(raw.substringAfter('=').substringBeforeLast(';'))
|
||||||
|
val domain = json.getJSONObject("servers").run {
|
||||||
|
getStringOrNull("main") ?: getString(
|
||||||
|
json.getJSONObject("img").getString("server")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val url = json.getJSONObject("img").getString("url")
|
||||||
|
return pages.map { x ->
|
||||||
|
val pageUrl = "$domain$url${x.getString("u")}"
|
||||||
|
MangaPage(
|
||||||
|
id = pageUrl.longHashCode(),
|
||||||
|
source = source,
|
||||||
|
url = pageUrl
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw ParseException("Script with info not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getTags(): Set<MangaTag> {
|
||||||
|
val domain = conf.getDomain(defaultDomain)
|
||||||
|
val url = "https://$domain/manga-list"
|
||||||
|
val doc = loaderContext.httpGet(url).parseHtml()
|
||||||
|
val scripts = doc.body().select("script")
|
||||||
|
for (script in scripts) {
|
||||||
|
val raw = script.html().trim()
|
||||||
|
if (raw.startsWith("window.__DATA")) {
|
||||||
|
val json = JSONObject(raw.substringAfter('=').substringBeforeLast(';'))
|
||||||
|
val genres = json.getJSONObject("filters").getJSONArray("genres")
|
||||||
|
val result = HashSet<MangaTag>(genres.length())
|
||||||
|
for (x in genres) {
|
||||||
|
result += MangaTag(
|
||||||
|
source = source,
|
||||||
|
key = x.getInt("id").toString(),
|
||||||
|
title = x.getString("name").capitalize()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw ParseException("Script with genres not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getSortKey(sortOrder: SortOrder?) = when (sortOrder) {
|
||||||
|
SortOrder.RATING -> "desc&sort=rate"
|
||||||
|
SortOrder.ALPHABETICAL -> "asc&sort=name"
|
||||||
|
SortOrder.POPULARITY -> "desc&sort=views"
|
||||||
|
SortOrder.UPDATED -> "desc&sort=last_chapter_at"
|
||||||
|
SortOrder.NEWEST -> "desc&sort=created_at"
|
||||||
|
else -> "desc&sort=last_chapter_at"
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun search(query: String): List<Manga> {
|
||||||
|
val domain = conf.getDomain(defaultDomain)
|
||||||
|
val json = loaderContext.httpGet("https://$domain/search?query=${query.urlEncoded()}")
|
||||||
|
.parseJsonArray()
|
||||||
|
return json.map { jo ->
|
||||||
|
val url = "https://$domain/${jo.getString("slug")}"
|
||||||
|
Manga(
|
||||||
|
id = url.longHashCode(),
|
||||||
|
url = url,
|
||||||
|
title = jo.getString("rus_name"),
|
||||||
|
altTitle = jo.getString("name"),
|
||||||
|
author = null,
|
||||||
|
tags = emptySet(),
|
||||||
|
rating = Manga.NO_RATING,
|
||||||
|
state = null,
|
||||||
|
source = source,
|
||||||
|
coverUrl = "https://$domain/uploads/cover/${jo.getString("slug")}/${jo.getString("cover")}/cover_thumb.jpg"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,178 @@
|
|||||||
|
package org.koitharu.kotatsu.core.parser.site
|
||||||
|
|
||||||
|
import org.intellij.lang.annotations.Language
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.exceptions.ParseException
|
||||||
|
import org.koitharu.kotatsu.core.model.*
|
||||||
|
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
||||||
|
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||||
|
import org.koitharu.kotatsu.utils.ext.*
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class MangaTownRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepository(loaderContext) {
|
||||||
|
|
||||||
|
override val source = MangaSource.MANGATOWN
|
||||||
|
|
||||||
|
override val sortOrders = setOf(
|
||||||
|
SortOrder.ALPHABETICAL,
|
||||||
|
SortOrder.RATING,
|
||||||
|
SortOrder.POPULARITY,
|
||||||
|
SortOrder.UPDATED
|
||||||
|
)
|
||||||
|
|
||||||
|
override suspend fun getList(
|
||||||
|
offset: Int,
|
||||||
|
query: String?,
|
||||||
|
sortOrder: SortOrder?,
|
||||||
|
tag: MangaTag?
|
||||||
|
): List<Manga> {
|
||||||
|
val domain = conf.getDomain(DOMAIN)
|
||||||
|
val ssl = conf.isUseSsl(false)
|
||||||
|
val scheme = if (ssl) "https" else "http"
|
||||||
|
val sortKey = when (sortOrder) {
|
||||||
|
SortOrder.ALPHABETICAL -> "?name.az"
|
||||||
|
SortOrder.RATING -> "?rating.za"
|
||||||
|
SortOrder.UPDATED -> "?last_chapter_time.za"
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
val page = (offset / 30) + 1
|
||||||
|
val url = when {
|
||||||
|
!query.isNullOrEmpty() -> {
|
||||||
|
if (offset != 0) {
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
|
"$scheme://$domain/search?name=${query.urlEncoded()}"
|
||||||
|
}
|
||||||
|
tag != null -> "$scheme://$domain/directory/${tag.key}/$page.htm$sortKey"
|
||||||
|
else -> "$scheme://$domain/directory/$page.htm$sortKey"
|
||||||
|
}
|
||||||
|
val doc = loaderContext.httpGet(url).parseHtml()
|
||||||
|
val root = doc.body().selectFirst("ul.manga_pic_list")
|
||||||
|
?: throw ParseException("Root not found")
|
||||||
|
return root.select("li").mapNotNull { li ->
|
||||||
|
val a = li.selectFirst("a.manga_cover")
|
||||||
|
val href = a.attr("href").withDomain(domain, ssl)
|
||||||
|
val views = li.select("p.view")
|
||||||
|
val status = views.findOwnText { x -> x.startsWith("Status:") }
|
||||||
|
?.substringAfter(':')?.trim()?.toLowerCase(Locale.ROOT)
|
||||||
|
Manga(
|
||||||
|
id = href.longHashCode(),
|
||||||
|
title = a.attr("title"),
|
||||||
|
coverUrl = a.selectFirst("img").attr("src"),
|
||||||
|
source = MangaSource.MANGATOWN,
|
||||||
|
altTitle = null,
|
||||||
|
rating = li.selectFirst("p.score")?.selectFirst("b")
|
||||||
|
?.ownText()?.toFloatOrNull()?.div(5f) ?: Manga.NO_RATING,
|
||||||
|
largeCoverUrl = null,
|
||||||
|
author = views.findText { x -> x.startsWith("Author:") }?.substringAfter(':')
|
||||||
|
?.trim(),
|
||||||
|
state = when (status) {
|
||||||
|
"ongoing" -> MangaState.ONGOING
|
||||||
|
"completed" -> MangaState.FINISHED
|
||||||
|
else -> null
|
||||||
|
},
|
||||||
|
tags = li.selectFirst("p.keyWord")?.select("a")?.mapNotNull tags@{ x ->
|
||||||
|
MangaTag(
|
||||||
|
title = x.attr("title"),
|
||||||
|
key = x.attr("href").parseTagKey() ?: return@tags null,
|
||||||
|
source = MangaSource.MANGATOWN
|
||||||
|
)
|
||||||
|
}?.toSet().orEmpty(),
|
||||||
|
url = href
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getDetails(manga: Manga): Manga {
|
||||||
|
val domain = conf.getDomain(DOMAIN)
|
||||||
|
val ssl = conf.isUseSsl(false)
|
||||||
|
val doc = loaderContext.httpGet(manga.url).parseHtml()
|
||||||
|
val root = doc.body().selectFirst("section.main")
|
||||||
|
?.selectFirst("div.article_content") ?: throw ParseException("Cannot find root")
|
||||||
|
val info = root.selectFirst("div.detail_info").selectFirst("ul")
|
||||||
|
val chaptersList = root.selectFirst("div.chapter_content")
|
||||||
|
?.selectFirst("ul.chapter_list")?.select("li")?.asReversed()
|
||||||
|
return manga.copy(
|
||||||
|
tags = manga.tags + info.select("li").find { x ->
|
||||||
|
x.selectFirst("b")?.ownText() == "Genre(s):"
|
||||||
|
}?.select("a")?.mapNotNull { a ->
|
||||||
|
MangaTag(
|
||||||
|
title = a.attr("title"),
|
||||||
|
key = a.attr("href").parseTagKey() ?: return@mapNotNull null,
|
||||||
|
source = MangaSource.MANGATOWN
|
||||||
|
)
|
||||||
|
}.orEmpty(),
|
||||||
|
description = info.getElementById("show")?.ownText(),
|
||||||
|
chapters = chaptersList?.mapIndexedNotNull { i, li ->
|
||||||
|
val href = li.selectFirst("a").attr("href").withDomain(domain, ssl)
|
||||||
|
val name = li.select("span").filter { it.className().isEmpty() }.joinToString(" - ") { it.text() }.trim()
|
||||||
|
MangaChapter(
|
||||||
|
id = href.longHashCode(),
|
||||||
|
url = href,
|
||||||
|
source = MangaSource.MANGATOWN,
|
||||||
|
number = i + 1,
|
||||||
|
name = if (name.isEmpty()) "${manga.title} - ${i + 1}" else name
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
||||||
|
val domain = conf.getDomain(DOMAIN)
|
||||||
|
val ssl = conf.isUseSsl(false)
|
||||||
|
val doc = loaderContext.httpGet(chapter.url).parseHtml()
|
||||||
|
val root = doc.body().selectFirst("div.page_select")
|
||||||
|
?: throw ParseException("Cannot find root")
|
||||||
|
return root.selectFirst("select").select("option").mapNotNull {
|
||||||
|
val href = it.attr("value").withDomain(domain, ssl)
|
||||||
|
if (href.endsWith("featured.html")) {
|
||||||
|
return@mapNotNull null
|
||||||
|
}
|
||||||
|
MangaPage(
|
||||||
|
id = href.longHashCode(),
|
||||||
|
url = href,
|
||||||
|
source = MangaSource.MANGATOWN
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getPageFullUrl(page: MangaPage): String {
|
||||||
|
val domain = conf.getDomain(DOMAIN)
|
||||||
|
val ssl = conf.isUseSsl(false)
|
||||||
|
val doc = loaderContext.httpGet(page.url).parseHtml()
|
||||||
|
return doc.getElementById("image").attr("src").withDomain(domain, ssl)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getTags(): Set<MangaTag> {
|
||||||
|
val domain = conf.getDomain(DOMAIN)
|
||||||
|
val doc = loaderContext.httpGet("http://$domain/directory/").parseHtml()
|
||||||
|
val root = doc.body().selectFirst("aside.right")
|
||||||
|
.getElementsContainingOwnText("Genres")
|
||||||
|
.first()
|
||||||
|
.nextElementSibling()
|
||||||
|
return root.select("li").mapNotNull { li ->
|
||||||
|
val a = li.selectFirst("a") ?: return@mapNotNull null
|
||||||
|
val key = a.attr("href").parseTagKey()
|
||||||
|
if (key.isNullOrEmpty()) {
|
||||||
|
return@mapNotNull null
|
||||||
|
}
|
||||||
|
MangaTag(
|
||||||
|
source = MangaSource.MANGATOWN,
|
||||||
|
key = key,
|
||||||
|
title = a.text()
|
||||||
|
)
|
||||||
|
}.toSet()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override fun onCreatePreferences() = setOf(R.string.key_parser_domain, R.string.key_parser_ssl)
|
||||||
|
|
||||||
|
private fun String.parseTagKey() = split('/').findLast { TAG_REGEX matches it }
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
|
||||||
|
@Language("RegExp")
|
||||||
|
val TAG_REGEX = Regex("[^\\-]+-[^\\-]+-[^\\-]+-[^\\-]+-[^\\-]+-[^\\-]+")
|
||||||
|
const val DOMAIN = "www.mangatown.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
package org.koitharu.kotatsu.core.parser.site
|
||||||
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||||
|
|
||||||
class MintMangaRepository : GroupleRepository() {
|
class MintMangaRepository(loaderContext: MangaLoaderContext) : GroupleRepository(loaderContext) {
|
||||||
|
|
||||||
override val source = MangaSource.MINTMANGA
|
override val source = MangaSource.MINTMANGA
|
||||||
override val defaultDomain: String = "mintmanga.live"
|
override val defaultDomain: String = "mintmanga.live"
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
package org.koitharu.kotatsu.core.parser.site
|
||||||
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||||
|
|
||||||
class ReadmangaRepository : GroupleRepository() {
|
class ReadmangaRepository(loaderContext: MangaLoaderContext) : GroupleRepository(loaderContext) {
|
||||||
|
|
||||||
override val defaultDomain = "readmanga.me"
|
override val defaultDomain = "readmanga.live"
|
||||||
override val source = MangaSource.READMANGA_RU
|
override val source = MangaSource.READMANGA_RU
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
package org.koitharu.kotatsu.core.parser.site
|
||||||
|
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||||
|
|
||||||
class SelfMangaRepository : GroupleRepository() {
|
class SelfMangaRepository(loaderContext: MangaLoaderContext) : GroupleRepository(loaderContext) {
|
||||||
|
|
||||||
override val defaultDomain = "selfmanga.ru"
|
override val defaultDomain = "selfmanga.ru"
|
||||||
override val source = MangaSource.SELFMANGA
|
override val source = MangaSource.SELFMANGA
|
||||||
|
|||||||
@@ -1,9 +1,40 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
package org.koitharu.kotatsu.core.parser.site
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.core.exceptions.ParseException
|
||||||
|
import org.koitharu.kotatsu.core.model.Manga
|
||||||
|
import org.koitharu.kotatsu.core.model.MangaChapter
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||||
|
import org.koitharu.kotatsu.utils.ext.longHashCode
|
||||||
|
import org.koitharu.kotatsu.utils.ext.parseHtml
|
||||||
|
import org.koitharu.kotatsu.utils.ext.withDomain
|
||||||
|
|
||||||
class YaoiChanRepository : ChanRepository() {
|
class YaoiChanRepository(loaderContext: MangaLoaderContext) : ChanRepository(loaderContext) {
|
||||||
|
|
||||||
override val source = MangaSource.YAOICHAN
|
override val source = MangaSource.YAOICHAN
|
||||||
override val defaultDomain = "yaoi-chan.me"
|
override val defaultDomain = "yaoi-chan.me"
|
||||||
|
|
||||||
|
override suspend fun getDetails(manga: Manga): Manga {
|
||||||
|
val domain = conf.getDomain(defaultDomain)
|
||||||
|
val doc = loaderContext.httpGet(manga.url).parseHtml()
|
||||||
|
val root =
|
||||||
|
doc.body().getElementById("dle-content") ?: throw ParseException("Cannot find root")
|
||||||
|
return manga.copy(
|
||||||
|
description = root.getElementById("description")?.html()?.substringBeforeLast("<div"),
|
||||||
|
largeCoverUrl = root.getElementById("cover")?.attr("src")?.withDomain(domain),
|
||||||
|
chapters = root.select("table.table_cha").flatMap { table ->
|
||||||
|
table.select("div.manga")
|
||||||
|
}.mapNotNull { it.selectFirst("a") }.reversed().mapIndexedNotNull { i, a ->
|
||||||
|
val href = a.attr("href")
|
||||||
|
?.withDomain(domain) ?: return@mapIndexedNotNull null
|
||||||
|
MangaChapter(
|
||||||
|
id = href.longHashCode(),
|
||||||
|
name = a.text().trim(),
|
||||||
|
number = i + 1,
|
||||||
|
url = href,
|
||||||
|
source = source
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package org.koitharu.kotatsu.core.prefs
|
||||||
|
|
||||||
|
enum class AppSection {
|
||||||
|
|
||||||
|
LOCAL, FAVOURITES, HISTORY, FEED
|
||||||
|
}
|
||||||
@@ -3,10 +3,14 @@ package org.koitharu.kotatsu.core.prefs
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
|
import android.provider.Settings
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
|
import androidx.core.content.edit
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.parser.LocalMangaRepository
|
||||||
import org.koitharu.kotatsu.utils.delegates.prefs.*
|
import org.koitharu.kotatsu.utils.delegates.prefs.*
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class AppSettings private constructor(resources: Resources, private val prefs: SharedPreferences) :
|
class AppSettings private constructor(resources: Resources, private val prefs: SharedPreferences) :
|
||||||
SharedPreferences by prefs {
|
SharedPreferences by prefs {
|
||||||
@@ -22,6 +26,12 @@ class AppSettings private constructor(resources: Resources, private val prefs: S
|
|||||||
ListMode.DETAILED_LIST
|
ListMode.DETAILED_LIST
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var defaultSection by EnumPreferenceDelegate(
|
||||||
|
AppSection::class.java,
|
||||||
|
resources.getString(R.string.key_app_section),
|
||||||
|
AppSection.HISTORY
|
||||||
|
)
|
||||||
|
|
||||||
val theme by StringIntPreferenceDelegate(
|
val theme by StringIntPreferenceDelegate(
|
||||||
resources.getString(R.string.key_theme),
|
resources.getString(R.string.key_theme),
|
||||||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||||
@@ -52,6 +62,31 @@ class AppSettings private constructor(resources: Resources, private val prefs: S
|
|||||||
0L
|
0L
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val trackerNotifications by BoolPreferenceDelegate(
|
||||||
|
resources.getString(R.string.key_tracker_notifications),
|
||||||
|
true
|
||||||
|
)
|
||||||
|
|
||||||
|
var notificationSound by StringPreferenceDelegate(
|
||||||
|
resources.getString(R.string.key_notifications_sound),
|
||||||
|
Settings.System.DEFAULT_NOTIFICATION_URI.toString()
|
||||||
|
)
|
||||||
|
|
||||||
|
val notificationVibrate by BoolPreferenceDelegate(
|
||||||
|
resources.getString(R.string.key_notifications_vibrate),
|
||||||
|
false
|
||||||
|
)
|
||||||
|
|
||||||
|
val notificationLight by BoolPreferenceDelegate(
|
||||||
|
resources.getString(R.string.key_notifications_light),
|
||||||
|
true
|
||||||
|
)
|
||||||
|
|
||||||
|
val readerAnimation by BoolPreferenceDelegate(
|
||||||
|
resources.getString(R.string.key_reader_animation),
|
||||||
|
false
|
||||||
|
)
|
||||||
|
|
||||||
private var sourcesOrderStr by NullableStringPreferenceDelegate(resources.getString(R.string.key_sources_order))
|
private var sourcesOrderStr by NullableStringPreferenceDelegate(resources.getString(R.string.key_sources_order))
|
||||||
|
|
||||||
var sourcesOrder: List<Int>
|
var sourcesOrder: List<Int>
|
||||||
@@ -60,6 +95,26 @@ class AppSettings private constructor(resources: Resources, private val prefs: S
|
|||||||
sourcesOrderStr = value.joinToString("|")
|
sourcesOrderStr = value.joinToString("|")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var hiddenSources by StringSetPreferenceDelegate(resources.getString(R.string.key_sources_hidden))
|
||||||
|
|
||||||
|
fun getStorageDir(context: Context): File? {
|
||||||
|
val value = prefs.getString(context.getString(R.string.key_local_storage), null)?.let {
|
||||||
|
File(it)
|
||||||
|
}?.takeIf { it.exists() && it.canWrite() }
|
||||||
|
return value ?: LocalMangaRepository.getFallbackStorageDir(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setStorageDir(context: Context, file: File?) {
|
||||||
|
val key = context.getString(R.string.key_local_storage)
|
||||||
|
prefs.edit {
|
||||||
|
if (file == null) {
|
||||||
|
remove(key)
|
||||||
|
} else {
|
||||||
|
putString(key, file.path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun subscribe(listener: SharedPreferences.OnSharedPreferenceChangeListener) {
|
fun subscribe(listener: SharedPreferences.OnSharedPreferenceChangeListener) {
|
||||||
prefs.registerOnSharedPreferenceChangeListener(listener)
|
prefs.registerOnSharedPreferenceChangeListener(listener)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.koitharu.kotatsu.core.prefs
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import org.koitharu.kotatsu.utils.delegates.prefs.LongPreferenceDelegate
|
||||||
|
|
||||||
|
class AppWidgetConfig private constructor(
|
||||||
|
private val prefs: SharedPreferences,
|
||||||
|
val widgetId: Int
|
||||||
|
) : SharedPreferences by prefs {
|
||||||
|
|
||||||
|
var categoryId by LongPreferenceDelegate(CATEGORY_ID, 0L)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
private const val CATEGORY_ID = "cat_id"
|
||||||
|
|
||||||
|
fun getInstance(context: Context, widgetId: Int) = AppWidgetConfig(
|
||||||
|
context.getSharedPreferences(
|
||||||
|
"appwidget_$widgetId",
|
||||||
|
Context.MODE_PRIVATE
|
||||||
|
), widgetId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,13 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.core.prefs
|
package org.koitharu.kotatsu.core.prefs
|
||||||
|
|
||||||
enum class ListMode(val id: Int) {
|
enum class ListMode {
|
||||||
|
|
||||||
LIST(0),
|
LIST, DETAILED_LIST, GRID;
|
||||||
DETAILED_LIST(1),
|
|
||||||
GRID(2);
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
fun valueOf(id: Int) = values().firstOrNull { it.id == id }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -8,16 +8,20 @@ interface SourceConfig {
|
|||||||
|
|
||||||
fun getDomain(defaultValue: String): String
|
fun getDomain(defaultValue: String): String
|
||||||
|
|
||||||
|
fun isUseSsl(defaultValue: Boolean): Boolean
|
||||||
|
|
||||||
private class PrefSourceConfig(context: Context, source: MangaSource) : SourceConfig {
|
private class PrefSourceConfig(context: Context, source: MangaSource) : SourceConfig {
|
||||||
|
|
||||||
private val prefs = context.getSharedPreferences(source.name, Context.MODE_PRIVATE)
|
private val prefs = context.getSharedPreferences(source.name, Context.MODE_PRIVATE)
|
||||||
|
|
||||||
private val keyDomain = context.getString(R.string.key_parser_domain)
|
private val keyDomain = context.getString(R.string.key_parser_domain)
|
||||||
|
private val keySsl = context.getString(R.string.key_parser_ssl)
|
||||||
|
|
||||||
override fun getDomain(defaultValue: String) = prefs.getString(keyDomain, defaultValue)
|
override fun getDomain(defaultValue: String) = prefs.getString(keyDomain, defaultValue)
|
||||||
?.takeUnless(String::isBlank)
|
?.takeUnless(String::isBlank)
|
||||||
?: defaultValue
|
?: defaultValue
|
||||||
|
|
||||||
|
override fun isUseSsl(defaultValue: Boolean) = prefs.getBoolean(keySsl, defaultValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.domain
|
package org.koitharu.kotatsu.domain
|
||||||
|
|
||||||
|
import androidx.room.withTransaction
|
||||||
import org.koin.core.KoinComponent
|
import org.koin.core.KoinComponent
|
||||||
import org.koin.core.inject
|
import org.koin.core.inject
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
@@ -13,24 +14,33 @@ class MangaDataRepository : KoinComponent {
|
|||||||
|
|
||||||
private val db: MangaDatabase by inject()
|
private val db: MangaDatabase by inject()
|
||||||
|
|
||||||
suspend fun savePreferences(mangaId: Long, mode: ReaderMode) {
|
suspend fun savePreferences(manga: Manga, mode: ReaderMode) {
|
||||||
db.preferencesDao().upsert(
|
val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
|
||||||
MangaPrefsEntity(
|
db.withTransaction {
|
||||||
mangaId = mangaId,
|
db.tagsDao.upsert(tags)
|
||||||
mode = mode.id
|
db.mangaDao.upsert(MangaEntity.from(manga), tags)
|
||||||
|
db.preferencesDao.upsert(
|
||||||
|
MangaPrefsEntity(
|
||||||
|
mangaId = manga.id,
|
||||||
|
mode = mode.id
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getReaderMode(mangaId: Long): ReaderMode? {
|
suspend fun getReaderMode(mangaId: Long): ReaderMode? {
|
||||||
return db.preferencesDao().find(mangaId)?.let { ReaderMode.valueOf(it.mode) }
|
return db.preferencesDao.find(mangaId)?.let { ReaderMode.valueOf(it.mode) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun findMangaById(mangaId: Long): Manga? {
|
suspend fun findMangaById(mangaId: Long): Manga? {
|
||||||
return db.mangaDao().find(mangaId)?.toManga()
|
return db.mangaDao.find(mangaId)?.toManga()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun storeManga(manga: Manga) {
|
suspend fun storeManga(manga: Manga) {
|
||||||
db.mangaDao().upsert(MangaEntity.from(manga), manga.tags.map(TagEntity.Companion::fromMangaTag))
|
val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
|
||||||
|
db.withTransaction {
|
||||||
|
db.tagsDao.upsert(tags)
|
||||||
|
db.mangaDao.upsert(MangaEntity.from(manga), tags)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,26 +2,69 @@ package org.koitharu.kotatsu.domain
|
|||||||
|
|
||||||
import org.koin.core.KoinComponent
|
import org.koin.core.KoinComponent
|
||||||
import org.koin.core.get
|
import org.koin.core.get
|
||||||
|
import org.koin.core.inject
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
import org.koitharu.kotatsu.core.parser.LocalMangaRepository
|
import org.koitharu.kotatsu.core.parser.LocalMangaRepository
|
||||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
import java.lang.ref.WeakReference
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
object MangaProviderFactory : KoinComponent {
|
object MangaProviderFactory : KoinComponent {
|
||||||
|
|
||||||
val sources: List<MangaSource>
|
private val loaderContext by inject<MangaLoaderContext>()
|
||||||
get() {
|
private val cache =
|
||||||
val list = MangaSource.values().toList() - MangaSource.LOCAL
|
EnumMap<MangaSource, WeakReference<MangaRepository>>(MangaSource::class.java)
|
||||||
val order = get<AppSettings>().sourcesOrder
|
|
||||||
return list.sortedBy { x ->
|
fun getSources(includeHidden: Boolean): List<MangaSource> {
|
||||||
val e = order.indexOf(x.ordinal)
|
val settings = get<AppSettings>()
|
||||||
if (e == -1) order.size + x.ordinal else e
|
val list = MangaSource.values().toList() - MangaSource.LOCAL
|
||||||
|
val order = settings.sourcesOrder
|
||||||
|
val hidden = settings.hiddenSources
|
||||||
|
val sorted = list.sortedBy { x ->
|
||||||
|
val e = order.indexOf(x.ordinal)
|
||||||
|
if (e == -1) order.size + x.ordinal else e
|
||||||
|
}
|
||||||
|
return if (includeHidden) {
|
||||||
|
sorted
|
||||||
|
} else {
|
||||||
|
sorted.filterNot { x ->
|
||||||
|
x.name in hidden
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun createLocal() = LocalMangaRepository()
|
fun createLocal(): LocalMangaRepository {
|
||||||
|
var instance = cache[MangaSource.LOCAL]?.get()
|
||||||
|
if (instance == null) {
|
||||||
|
synchronized(cache) {
|
||||||
|
instance = cache[MangaSource.LOCAL]?.get()
|
||||||
|
if (instance == null) {
|
||||||
|
instance = LocalMangaRepository()
|
||||||
|
cache[MangaSource.LOCAL] = WeakReference<MangaRepository>(instance)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instance as LocalMangaRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(Throwable::class)
|
||||||
fun create(source: MangaSource): MangaRepository {
|
fun create(source: MangaSource): MangaRepository {
|
||||||
return source.cls.newInstance()
|
var instance = cache[source]?.get()
|
||||||
|
if (instance == null) {
|
||||||
|
synchronized(cache) {
|
||||||
|
instance = cache[source]?.get()
|
||||||
|
if (instance == null) {
|
||||||
|
instance = try {
|
||||||
|
source.cls.getDeclaredConstructor(MangaLoaderContext::class.java)
|
||||||
|
.newInstance(loaderContext)
|
||||||
|
} catch (e: NoSuchMethodException) {
|
||||||
|
source.cls.newInstance()
|
||||||
|
}
|
||||||
|
cache[source] = WeakReference(instance!!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instance!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package org.koitharu.kotatsu.domain
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
|
import org.koin.core.KoinComponent
|
||||||
|
import org.koitharu.kotatsu.core.model.Manga
|
||||||
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.core.model.SortOrder
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class MangaSearchRepository : KoinComponent {
|
||||||
|
|
||||||
|
fun globalSearch(query: String, batchSize: Int = 4): Flow<List<Manga>> = flow {
|
||||||
|
val sources = MangaProviderFactory.getSources(false)
|
||||||
|
val lists = EnumMap<MangaSource, List<Manga>>(MangaSource::class.java)
|
||||||
|
var i = 0
|
||||||
|
while (true) {
|
||||||
|
var isEmitted = false
|
||||||
|
for (source in sources) {
|
||||||
|
val list = lists.getOrPut(source) {
|
||||||
|
try {
|
||||||
|
MangaProviderFactory.create(source).getList(0, query, SortOrder.POPULARITY)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
e.printStackTrace()
|
||||||
|
emptyList<Manga>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i < list.size) {
|
||||||
|
emit(list.subList(i, (i + batchSize).coerceAtMost(list.lastIndex)))
|
||||||
|
isEmitted = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i += batchSize
|
||||||
|
if (!isEmitted) {
|
||||||
|
return@flow
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package org.koitharu.kotatsu.domain
|
package org.koitharu.kotatsu.domain
|
||||||
|
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
|
import android.net.Uri
|
||||||
import android.util.Size
|
import android.util.Size
|
||||||
|
import androidx.annotation.WorkerThread
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import org.koin.core.KoinComponent
|
import org.koin.core.KoinComponent
|
||||||
@@ -12,6 +14,7 @@ import org.koitharu.kotatsu.core.prefs.ReaderMode
|
|||||||
import org.koitharu.kotatsu.utils.ext.await
|
import org.koitharu.kotatsu.utils.ext.await
|
||||||
import org.koitharu.kotatsu.utils.ext.medianOrNull
|
import org.koitharu.kotatsu.utils.ext.medianOrNull
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
import java.util.zip.ZipFile
|
||||||
|
|
||||||
object MangaUtils : KoinComponent {
|
object MangaUtils : KoinComponent {
|
||||||
|
|
||||||
@@ -19,17 +22,28 @@ object MangaUtils : KoinComponent {
|
|||||||
* Automatic determine type of manga by page size
|
* Automatic determine type of manga by page size
|
||||||
* @return ReaderMode.WEBTOON if page is wide
|
* @return ReaderMode.WEBTOON if page is wide
|
||||||
*/
|
*/
|
||||||
|
@WorkerThread
|
||||||
|
@Suppress("BlockingMethodInNonBlockingContext")
|
||||||
suspend fun determineReaderMode(pages: List<MangaPage>): ReaderMode? {
|
suspend fun determineReaderMode(pages: List<MangaPage>): ReaderMode? {
|
||||||
try {
|
try {
|
||||||
val page = pages.medianOrNull() ?: return null
|
val page = pages.medianOrNull() ?: return null
|
||||||
val url = MangaProviderFactory.create(page.source).getPageFullUrl(page)
|
val url = MangaProviderFactory.create(page.source).getPageFullUrl(page)
|
||||||
val client = get<OkHttpClient>()
|
val uri = Uri.parse(url)
|
||||||
val request = Request.Builder()
|
val size = if (uri.scheme == "cbz") {
|
||||||
.url(url)
|
val zip = ZipFile(uri.schemeSpecificPart)
|
||||||
.get()
|
val entry = zip.getEntry(uri.fragment)
|
||||||
.build()
|
zip.getInputStream(entry).use {
|
||||||
val size = client.newCall(request).await().use {
|
getBitmapSize(it)
|
||||||
getBitmapSize(it.body?.byteStream())
|
}
|
||||||
|
} else {
|
||||||
|
val client = get<OkHttpClient>()
|
||||||
|
val request = Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.get()
|
||||||
|
.build()
|
||||||
|
client.newCall(request).await().use {
|
||||||
|
getBitmapSize(it.body?.byteStream())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return when {
|
return when {
|
||||||
size.width * 2 < size.height -> ReaderMode.WEBTOON
|
size.width * 2 < size.height -> ReaderMode.WEBTOON
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.koitharu.kotatsu.domain.favourites
|
package org.koitharu.kotatsu.domain.favourites
|
||||||
|
|
||||||
|
import androidx.collection.ArraySet
|
||||||
|
import androidx.room.withTransaction
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.koin.core.KoinComponent
|
import org.koin.core.KoinComponent
|
||||||
@@ -11,24 +13,38 @@ import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
|||||||
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
import org.koitharu.kotatsu.core.model.Manga
|
import org.koitharu.kotatsu.core.model.Manga
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class FavouritesRepository : KoinComponent {
|
class FavouritesRepository : KoinComponent {
|
||||||
|
|
||||||
private val db: MangaDatabase by inject()
|
private val db: MangaDatabase by inject()
|
||||||
|
|
||||||
|
suspend fun getAllManga(): List<Manga> {
|
||||||
|
val entities = db.favouritesDao.findAll()
|
||||||
|
return entities.map { it.manga.toManga(it.tags.map(TagEntity::toMangaTag).toSet()) }
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun getAllManga(offset: Int): List<Manga> {
|
suspend fun getAllManga(offset: Int): List<Manga> {
|
||||||
val entities = db.favouritesDao().findAll(offset, 20, "created_at")
|
val entities = db.favouritesDao.findAll(offset, 20)
|
||||||
|
return entities.map { it.manga.toManga(it.tags.map(TagEntity::toMangaTag).toSet()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getManga(categoryId: Long): List<Manga> {
|
||||||
|
val entities = db.favouritesDao.findAll(categoryId)
|
||||||
|
return entities.map { it.manga.toManga(it.tags.map(TagEntity::toMangaTag).toSet()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getManga(categoryId: Long, offset: Int): List<Manga> {
|
||||||
|
val entities = db.favouritesDao.findAll(categoryId, offset, 20)
|
||||||
return entities.map { it.manga.toManga(it.tags.map(TagEntity::toMangaTag).toSet()) }
|
return entities.map { it.manga.toManga(it.tags.map(TagEntity::toMangaTag).toSet()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getAllCategories(): List<FavouriteCategory> {
|
suspend fun getAllCategories(): List<FavouriteCategory> {
|
||||||
val entities = db.favouriteCategoriesDao().findAll("created_at")
|
val entities = db.favouriteCategoriesDao.findAll()
|
||||||
return entities.map { it.toFavouriteCategory() }
|
return entities.map { it.toFavouriteCategory() }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getCategories(mangaId: Long): List<FavouriteCategory> {
|
suspend fun getCategories(mangaId: Long): List<FavouriteCategory> {
|
||||||
val entities = db.favouritesDao().find(mangaId)?.categories
|
val entities = db.favouritesDao.find(mangaId)?.categories
|
||||||
return entities?.map { it.toFavouriteCategory() }.orEmpty()
|
return entities?.map { it.toFavouriteCategory() }.orEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,40 +52,60 @@ class FavouritesRepository : KoinComponent {
|
|||||||
val entity = FavouriteCategoryEntity(
|
val entity = FavouriteCategoryEntity(
|
||||||
title = title,
|
title = title,
|
||||||
createdAt = System.currentTimeMillis(),
|
createdAt = System.currentTimeMillis(),
|
||||||
|
sortKey = db.favouriteCategoriesDao.getNextSortKey(),
|
||||||
categoryId = 0
|
categoryId = 0
|
||||||
)
|
)
|
||||||
val id = db.favouriteCategoriesDao().insert(entity)
|
val id = db.favouriteCategoriesDao.insert(entity)
|
||||||
|
notifyCategoriesChanged()
|
||||||
return entity.toFavouriteCategory(id)
|
return entity.toFavouriteCategory(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun renameCategory(id: Long, title: String) {
|
||||||
|
db.favouriteCategoriesDao.update(id, title)
|
||||||
|
notifyCategoriesChanged()
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun removeCategory(id: Long) {
|
suspend fun removeCategory(id: Long) {
|
||||||
db.favouriteCategoriesDao().delete(id)
|
db.favouriteCategoriesDao.delete(id)
|
||||||
|
notifyCategoriesChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun reorderCategories(orderedIds: List<Long>) {
|
||||||
|
val dao = db.favouriteCategoriesDao
|
||||||
|
db.withTransaction {
|
||||||
|
for ((i, id) in orderedIds.withIndex()) {
|
||||||
|
dao.update(id, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notifyCategoriesChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun addToCategory(manga: Manga, categoryId: Long) {
|
suspend fun addToCategory(manga: Manga, categoryId: Long) {
|
||||||
val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
|
val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
|
||||||
db.tagsDao().upsert(tags)
|
db.withTransaction {
|
||||||
db.mangaDao().upsert(MangaEntity.from(manga), tags)
|
db.tagsDao.upsert(tags)
|
||||||
val entity = FavouriteEntity(manga.id, categoryId, System.currentTimeMillis())
|
db.mangaDao.upsert(MangaEntity.from(manga), tags)
|
||||||
db.favouritesDao().add(entity)
|
val entity = FavouriteEntity(manga.id, categoryId, System.currentTimeMillis())
|
||||||
|
db.favouritesDao.add(entity)
|
||||||
|
}
|
||||||
notifyFavouritesChanged(manga.id)
|
notifyFavouritesChanged(manga.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun removeFromCategory(manga: Manga, categoryId: Long) {
|
suspend fun removeFromCategory(manga: Manga, categoryId: Long) {
|
||||||
db.favouritesDao().delete(categoryId, manga.id)
|
db.favouritesDao.delete(categoryId, manga.id)
|
||||||
notifyFavouritesChanged(manga.id)
|
notifyFavouritesChanged(manga.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val listeners = HashSet<OnFavouritesChangeListener>()
|
private val listeners = ArraySet<OnFavouritesChangeListener>()
|
||||||
|
|
||||||
fun subscribe(listener: OnFavouritesChangeListener) {
|
fun subscribe(listener: OnFavouritesChangeListener) {
|
||||||
listeners += listener
|
listeners += listener
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unsubscribe(listener: OnFavouritesChangeListener) {
|
fun unsubscribe(listener: OnFavouritesChangeListener) {
|
||||||
listeners += listener
|
listeners -= listener
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun notifyFavouritesChanged(mangaId: Long) {
|
private suspend fun notifyFavouritesChanged(mangaId: Long) {
|
||||||
@@ -77,5 +113,11 @@ class FavouritesRepository : KoinComponent {
|
|||||||
listeners.forEach { x -> x.onFavouritesChanged(mangaId) }
|
listeners.forEach { x -> x.onFavouritesChanged(mangaId) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun notifyCategoriesChanged() {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
listeners.forEach { x -> x.onCategoriesChanged() }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,4 +3,6 @@ package org.koitharu.kotatsu.domain.favourites
|
|||||||
interface OnFavouritesChangeListener {
|
interface OnFavouritesChangeListener {
|
||||||
|
|
||||||
fun onFavouritesChanged(mangaId: Long)
|
fun onFavouritesChanged(mangaId: Long)
|
||||||
|
|
||||||
|
fun onCategoriesChanged()
|
||||||
}
|
}
|
||||||
@@ -2,5 +2,5 @@ package org.koitharu.kotatsu.domain.history
|
|||||||
|
|
||||||
enum class ChapterExtra {
|
enum class ChapterExtra {
|
||||||
|
|
||||||
READ, CURRENT, UNREAD, NEW
|
READ, CURRENT, UNREAD, NEW, CHECKED
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.koitharu.kotatsu.domain.history
|
package org.koitharu.kotatsu.domain.history
|
||||||
|
|
||||||
|
import androidx.collection.ArraySet
|
||||||
|
import androidx.room.withTransaction
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.koin.core.KoinComponent
|
import org.koin.core.KoinComponent
|
||||||
@@ -10,64 +12,74 @@ import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
|||||||
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
||||||
import org.koitharu.kotatsu.core.model.Manga
|
import org.koitharu.kotatsu.core.model.Manga
|
||||||
import org.koitharu.kotatsu.core.model.MangaHistory
|
import org.koitharu.kotatsu.core.model.MangaHistory
|
||||||
|
import org.koitharu.kotatsu.domain.tracking.TrackingRepository
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class HistoryRepository : KoinComponent {
|
class HistoryRepository : KoinComponent {
|
||||||
|
|
||||||
private val db: MangaDatabase by inject()
|
private val db: MangaDatabase by inject()
|
||||||
|
private val trackingRepository by lazy(::TrackingRepository)
|
||||||
|
|
||||||
suspend fun getList(offset: Int, limit: Int = 20): List<Manga> {
|
suspend fun getList(offset: Int, limit: Int = 20): List<Manga> {
|
||||||
val entities = db.historyDao().findAll(offset, limit)
|
val entities = db.historyDao.findAll(offset, limit)
|
||||||
return entities.map { it.manga.toManga(it.tags.map(TagEntity::toMangaTag).toSet()) }
|
return entities.map { it.manga.toManga(it.tags.map(TagEntity::toMangaTag).toSet()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun addOrUpdate(manga: Manga, chapterId: Long, page: Int) {
|
suspend fun addOrUpdate(manga: Manga, chapterId: Long, page: Int, scroll: Int) {
|
||||||
val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
|
val tags = manga.tags.map(TagEntity.Companion::fromMangaTag)
|
||||||
db.tagsDao().upsert(tags)
|
db.withTransaction {
|
||||||
db.mangaDao().upsert(MangaEntity.from(manga), tags)
|
db.tagsDao.upsert(tags)
|
||||||
db.historyDao().upsert(
|
db.mangaDao.upsert(MangaEntity.from(manga), tags)
|
||||||
HistoryEntity(
|
db.historyDao.upsert(
|
||||||
mangaId = manga.id,
|
HistoryEntity(
|
||||||
createdAt = System.currentTimeMillis(),
|
mangaId = manga.id,
|
||||||
updatedAt = System.currentTimeMillis(),
|
createdAt = System.currentTimeMillis(),
|
||||||
chapterId = chapterId,
|
updatedAt = System.currentTimeMillis(),
|
||||||
page = page
|
chapterId = chapterId,
|
||||||
|
page = page,
|
||||||
|
scroll = scroll.toFloat() // we migrate to int, but decide to not update database
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
trackingRepository.upsert(manga)
|
||||||
|
}
|
||||||
notifyHistoryChanged()
|
notifyHistoryChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getOne(manga: Manga): MangaHistory? {
|
suspend fun getOne(manga: Manga): MangaHistory? {
|
||||||
return db.historyDao().find(manga.id)?.let {
|
return db.historyDao.find(manga.id)?.toMangaHistory()
|
||||||
MangaHistory(
|
|
||||||
createdAt = Date(it.createdAt),
|
|
||||||
updatedAt = Date(it.updatedAt),
|
|
||||||
chapterId = it.chapterId,
|
|
||||||
page = it.page
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun clear() {
|
suspend fun clear() {
|
||||||
db.historyDao().clear()
|
db.historyDao.clear()
|
||||||
notifyHistoryChanged()
|
notifyHistoryChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun delete(manga: Manga) {
|
suspend fun delete(manga: Manga) {
|
||||||
db.historyDao().delete(manga.id)
|
db.historyDao.delete(manga.id)
|
||||||
notifyHistoryChanged()
|
notifyHistoryChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to replace one manga with another one
|
||||||
|
* Useful for replacing saved manga on deleting it with remove source
|
||||||
|
*/
|
||||||
|
suspend fun deleteOrSwap(manga: Manga, alternative: Manga?) {
|
||||||
|
if (alternative == null || db.mangaDao.update(MangaEntity.from(alternative)) <= 0) {
|
||||||
|
db.historyDao.delete(manga.id)
|
||||||
|
notifyHistoryChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val listeners = HashSet<OnHistoryChangeListener>()
|
private val listeners = ArraySet<OnHistoryChangeListener>()
|
||||||
|
|
||||||
fun subscribe(listener: OnHistoryChangeListener) {
|
fun subscribe(listener: OnHistoryChangeListener) {
|
||||||
listeners += listener
|
listeners += listener
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unsubscribe(listener: OnHistoryChangeListener) {
|
fun unsubscribe(listener: OnHistoryChangeListener) {
|
||||||
listeners += listener
|
listeners -= listener
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun notifyHistoryChanged() {
|
private suspend fun notifyHistoryChanged() {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.koitharu.kotatsu.core.model.Manga
|
|||||||
import org.koitharu.kotatsu.core.model.MangaChapter
|
import org.koitharu.kotatsu.core.model.MangaChapter
|
||||||
import org.koitharu.kotatsu.core.model.MangaSource
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
import org.koitharu.kotatsu.core.model.MangaTag
|
import org.koitharu.kotatsu.core.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getStringOrNull
|
||||||
import org.koitharu.kotatsu.utils.ext.map
|
import org.koitharu.kotatsu.utils.ext.map
|
||||||
import org.koitharu.kotatsu.utils.ext.safe
|
import org.koitharu.kotatsu.utils.ext.safe
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ class MangaIndex(source: String?) {
|
|||||||
|
|
||||||
private val json: JSONObject = source?.let(::JSONObject) ?: JSONObject()
|
private val json: JSONObject = source?.let(::JSONObject) ?: JSONObject()
|
||||||
|
|
||||||
fun setMangaInfo(manga: Manga) {
|
fun setMangaInfo(manga: Manga, append: Boolean) {
|
||||||
json.put("id", manga.id)
|
json.put("id", manga.id)
|
||||||
json.put("title", manga.title)
|
json.put("title", manga.title)
|
||||||
json.put("title_alt", manga.altTitle)
|
json.put("title_alt", manga.altTitle)
|
||||||
@@ -32,7 +33,9 @@ class MangaIndex(source: String?) {
|
|||||||
a.put(jo)
|
a.put(jo)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
json.put("chapters", JSONObject())
|
if (!append || !json.has("chapters")) {
|
||||||
|
json.put("chapters", JSONObject())
|
||||||
|
}
|
||||||
json.put("app_id", BuildConfig.APPLICATION_ID)
|
json.put("app_id", BuildConfig.APPLICATION_ID)
|
||||||
json.put("app_version", BuildConfig.VERSION_CODE)
|
json.put("app_version", BuildConfig.VERSION_CODE)
|
||||||
}
|
}
|
||||||
@@ -42,12 +45,12 @@ class MangaIndex(source: String?) {
|
|||||||
Manga(
|
Manga(
|
||||||
id = json.getLong("id"),
|
id = json.getLong("id"),
|
||||||
title = json.getString("title"),
|
title = json.getString("title"),
|
||||||
altTitle = json.getString("title_alt"),
|
altTitle = json.getStringOrNull("title_alt"),
|
||||||
url = json.getString("url"),
|
url = json.getString("url"),
|
||||||
source = source,
|
source = source,
|
||||||
rating = json.getDouble("rating").toFloat(),
|
rating = json.getDouble("rating").toFloat(),
|
||||||
coverUrl = json.getString("cover"),
|
coverUrl = json.getString("cover"),
|
||||||
description = json.getString("description"),
|
description = json.getStringOrNull("description"),
|
||||||
tags = json.getJSONArray("tags").map { x ->
|
tags = json.getJSONArray("tags").map { x ->
|
||||||
MangaTag(
|
MangaTag(
|
||||||
title = x.getString("title"),
|
title = x.getString("title"),
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import org.koitharu.kotatsu.core.model.Manga
|
|||||||
import org.koitharu.kotatsu.core.model.MangaChapter
|
import org.koitharu.kotatsu.core.model.MangaChapter
|
||||||
import org.koitharu.kotatsu.utils.ext.sub
|
import org.koitharu.kotatsu.utils.ext.sub
|
||||||
import org.koitharu.kotatsu.utils.ext.takeIfReadable
|
import org.koitharu.kotatsu.utils.ext.takeIfReadable
|
||||||
import org.koitharu.kotatsu.utils.ext.toFileName
|
import org.koitharu.kotatsu.utils.ext.toFileNameSafe
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipInputStream
|
import java.util.zip.ZipInputStream
|
||||||
@@ -17,11 +17,12 @@ class MangaZip(val file: File) {
|
|||||||
private val dir = file.parentFile?.sub(file.name + ".tmp")?.takeIf { it.mkdir() }
|
private val dir = file.parentFile?.sub(file.name + ".tmp")?.takeIf { it.mkdir() }
|
||||||
?: throw RuntimeException("Cannot create temporary directory")
|
?: throw RuntimeException("Cannot create temporary directory")
|
||||||
|
|
||||||
private val index = MangaIndex(dir.sub(INDEX_ENTRY).takeIfReadable()?.readText())
|
private var index = MangaIndex(null)
|
||||||
|
|
||||||
fun prepare(manga: Manga) {
|
fun prepare(manga: Manga) {
|
||||||
extract()
|
extract()
|
||||||
index.setMangaInfo(manga)
|
index = MangaIndex(dir.sub(INDEX_ENTRY).takeIfReadable()?.readText())
|
||||||
|
index.setMangaInfo(manga, append = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cleanup() {
|
fun cleanup() {
|
||||||
@@ -90,7 +91,7 @@ class MangaZip(val file: File) {
|
|||||||
const val INDEX_ENTRY = "index.json"
|
const val INDEX_ENTRY = "index.json"
|
||||||
|
|
||||||
fun findInDir(root: File, manga: Manga): MangaZip {
|
fun findInDir(root: File, manga: Manga): MangaZip {
|
||||||
val name = manga.title.toFileName() + ".cbz"
|
val name = manga.title.toFileNameSafe() + ".cbz"
|
||||||
val file = File(root, name)
|
val file = File(root, name)
|
||||||
return MangaZip(file)
|
return MangaZip(file)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package org.koitharu.kotatsu.domain.tracking
|
||||||
|
|
||||||
|
import androidx.room.withTransaction
|
||||||
|
import org.koin.core.KoinComponent
|
||||||
|
import org.koin.core.inject
|
||||||
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.TrackEntity
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.TrackLogEntity
|
||||||
|
import org.koitharu.kotatsu.core.model.*
|
||||||
|
import org.koitharu.kotatsu.domain.MangaProviderFactory
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class TrackingRepository : KoinComponent {
|
||||||
|
|
||||||
|
private val db: MangaDatabase by inject()
|
||||||
|
|
||||||
|
suspend fun getNewChaptersCount(mangaId: Long): Int {
|
||||||
|
val entity = db.tracksDao.find(mangaId) ?: return 0
|
||||||
|
return entity.newChapters
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getAllTracks(): List<MangaTracking> {
|
||||||
|
val favourites = db.favouritesDao.findAllManga()
|
||||||
|
val history = db.historyDao.findAllManga()
|
||||||
|
val mangas = (favourites + history).distinctBy { it.id }
|
||||||
|
val tracks = db.tracksDao.findAll().groupBy { it.mangaId }
|
||||||
|
return mangas.mapNotNull { me ->
|
||||||
|
var manga = me.toManga()
|
||||||
|
if (manga.source == MangaSource.LOCAL) {
|
||||||
|
manga = MangaProviderFactory.createLocal().getRemoteManga(manga) ?: return@mapNotNull null
|
||||||
|
}
|
||||||
|
val track = tracks[manga.id]?.singleOrNull()
|
||||||
|
MangaTracking(
|
||||||
|
manga = manga,
|
||||||
|
knownChaptersCount = track?.totalChapters ?: -1,
|
||||||
|
lastChapterId = track?.lastChapterId ?: 0L,
|
||||||
|
lastNotifiedChapterId = track?.lastNotifiedChapterId ?: 0L,
|
||||||
|
lastCheck = track?.lastCheck?.takeUnless { it == 0L }?.let(::Date)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getTrackingLog(offset: Int, limit: Int): List<TrackingLogItem> {
|
||||||
|
return db.trackLogsDao.findAll(offset, limit).map { x ->
|
||||||
|
x.toTrackingLogItem()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun count() = db.trackLogsDao.count()
|
||||||
|
|
||||||
|
suspend fun clearLogs() = db.trackLogsDao.clear()
|
||||||
|
|
||||||
|
suspend fun cleanup() {
|
||||||
|
db.withTransaction {
|
||||||
|
db.tracksDao.cleanup()
|
||||||
|
db.trackLogsDao.cleanup()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun storeTrackResult(
|
||||||
|
mangaId: Long,
|
||||||
|
knownChaptersCount: Int,
|
||||||
|
lastChapterId: Long,
|
||||||
|
newChapters: List<MangaChapter>,
|
||||||
|
previousTrackChapterId: Long
|
||||||
|
) {
|
||||||
|
db.withTransaction {
|
||||||
|
val entity = TrackEntity(
|
||||||
|
mangaId = mangaId,
|
||||||
|
newChapters = newChapters.size,
|
||||||
|
lastCheck = System.currentTimeMillis(),
|
||||||
|
lastChapterId = lastChapterId,
|
||||||
|
totalChapters = knownChaptersCount,
|
||||||
|
lastNotifiedChapterId = newChapters.lastOrNull()?.id ?: previousTrackChapterId
|
||||||
|
)
|
||||||
|
db.tracksDao.upsert(entity)
|
||||||
|
val foundChapters = newChapters.takeLastWhile { x -> x.id != previousTrackChapterId }
|
||||||
|
if (foundChapters.isNotEmpty()) {
|
||||||
|
val logEntity = TrackLogEntity(
|
||||||
|
mangaId = mangaId,
|
||||||
|
chapters = foundChapters.joinToString("\n") { x -> x.name },
|
||||||
|
createdAt = System.currentTimeMillis()
|
||||||
|
)
|
||||||
|
db.trackLogsDao.insert(logEntity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun upsert(manga: Manga) {
|
||||||
|
val chapters = manga.chapters ?: return
|
||||||
|
val entity = TrackEntity(
|
||||||
|
mangaId = manga.id,
|
||||||
|
totalChapters = chapters.size,
|
||||||
|
lastChapterId = chapters.lastOrNull()?.id ?: 0L,
|
||||||
|
newChapters = 0,
|
||||||
|
lastCheck = System.currentTimeMillis(),
|
||||||
|
lastNotifiedChapterId = 0L
|
||||||
|
)
|
||||||
|
db.tracksDao.upsert(entity)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package org.koitharu.kotatsu.ui.browser
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.ActivityNotFoundException
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
|
import androidx.core.view.isVisible
|
||||||
|
import kotlinx.android.synthetic.main.activity_browser.*
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.ui.common.BaseActivity
|
||||||
|
|
||||||
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
|
class BrowserActivity : BaseActivity(), BrowserCallback {
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(R.layout.activity_browser)
|
||||||
|
supportActionBar?.run {
|
||||||
|
setDisplayHomeAsUpEnabled(true)
|
||||||
|
setHomeAsUpIndicator(R.drawable.ic_cross)
|
||||||
|
}
|
||||||
|
with(webView.settings) {
|
||||||
|
javaScriptEnabled = true
|
||||||
|
}
|
||||||
|
webView.webViewClient = BrowserClient(this)
|
||||||
|
val url = intent?.dataString
|
||||||
|
if (url.isNullOrEmpty()) {
|
||||||
|
finishAfterTransition()
|
||||||
|
} else {
|
||||||
|
webView.loadUrl(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||||
|
menuInflater.inflate(R.menu.opt_browser, menu)
|
||||||
|
return super.onCreateOptionsMenu(menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
||||||
|
android.R.id.home -> {
|
||||||
|
webView.stopLoading()
|
||||||
|
finishAfterTransition()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
R.id.action_browser -> {
|
||||||
|
val intent = Intent(Intent.ACTION_VIEW)
|
||||||
|
intent.data = Uri.parse(webView.url)
|
||||||
|
try {
|
||||||
|
startActivity(Intent.createChooser(intent, item.title))
|
||||||
|
} catch (_: ActivityNotFoundException) {
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> super.onOptionsItemSelected(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBackPressed() {
|
||||||
|
if (webView.canGoBack()) {
|
||||||
|
webView.goBack()
|
||||||
|
} else {
|
||||||
|
super.onBackPressed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
webView.onPause()
|
||||||
|
super.onPause()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
webView.onResume()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLoadingStateChanged(isLoading: Boolean) {
|
||||||
|
progressBar.isVisible = isLoading
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTitleChanged(title: CharSequence, subtitle: CharSequence?) {
|
||||||
|
this.title = title
|
||||||
|
supportActionBar?.subtitle = subtitle
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun newIntent(context: Context, url: String) = Intent(context, BrowserActivity::class.java)
|
||||||
|
.setData(Uri.parse(url))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package org.koitharu.kotatsu.ui.browser
|
||||||
|
|
||||||
|
interface BrowserCallback {
|
||||||
|
|
||||||
|
fun onLoadingStateChanged(isLoading: Boolean)
|
||||||
|
|
||||||
|
fun onTitleChanged(title: CharSequence, subtitle: CharSequence?)
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package org.koitharu.kotatsu.ui.browser
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.webkit.WebResourceRequest
|
||||||
|
import android.webkit.WebResourceResponse
|
||||||
|
import android.webkit.WebView
|
||||||
|
import android.webkit.WebViewClient
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.Request
|
||||||
|
import org.koin.core.KoinComponent
|
||||||
|
import org.koin.core.inject
|
||||||
|
import org.koitharu.kotatsu.utils.ext.safe
|
||||||
|
|
||||||
|
class BrowserClient(private val callback: BrowserCallback) : WebViewClient(), KoinComponent {
|
||||||
|
|
||||||
|
private val okHttp by inject<OkHttpClient>()
|
||||||
|
|
||||||
|
override fun onPageFinished(webView: WebView, url: String) {
|
||||||
|
super.onPageFinished(webView, url)
|
||||||
|
callback.onLoadingStateChanged(isLoading = false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
|
||||||
|
super.onPageStarted(view, url, favicon)
|
||||||
|
callback.onLoadingStateChanged(isLoading = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPageCommitVisible(view: WebView, url: String?) {
|
||||||
|
super.onPageCommitVisible(view, url)
|
||||||
|
callback.onTitleChanged(view.title.orEmpty(), url)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?) = false
|
||||||
|
|
||||||
|
override fun shouldOverrideUrlLoading(view: WebView, url: String) = false
|
||||||
|
|
||||||
|
override fun shouldInterceptRequest(view: WebView?, url: String?): WebResourceResponse? {
|
||||||
|
return url?.let(::doRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldInterceptRequest(view: WebView?, request: WebResourceRequest?): WebResourceResponse? {
|
||||||
|
return request?.url?.toString()?.let(::doRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun doRequest(url: String): WebResourceResponse? = safe {
|
||||||
|
val request = Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.build()
|
||||||
|
val response = okHttp.newCall(request).execute()
|
||||||
|
val ct = response.body?.contentType()
|
||||||
|
WebResourceResponse(
|
||||||
|
"${ct?.type}/${ct?.subtype}",
|
||||||
|
ct?.charset()?.name() ?: "utf-8",
|
||||||
|
response.body?.byteStream()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ import android.os.Bundle
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.annotation.LayoutRes
|
import androidx.annotation.LayoutRes
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.fragment.app.DialogFragment
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import moxy.MvpAppCompatDialogFragment
|
import moxy.MvpAppCompatDialogFragment
|
||||||
|
|
||||||
abstract class AlertDialogFragment(@LayoutRes private val layoutResId: Int) : MvpAppCompatDialogFragment() {
|
abstract class AlertDialogFragment(@LayoutRes private val layoutResId: Int) : MvpAppCompatDialogFragment() {
|
||||||
@@ -18,7 +18,7 @@ abstract class AlertDialogFragment(@LayoutRes private val layoutResId: Int) : Mv
|
|||||||
if (view != null) {
|
if (view != null) {
|
||||||
onViewCreated(view, savedInstanceState)
|
onViewCreated(view, savedInstanceState)
|
||||||
}
|
}
|
||||||
return AlertDialog.Builder(requireContext(), theme)
|
return MaterialAlertDialogBuilder(requireContext(), theme)
|
||||||
.setView(view)
|
.setView(view)
|
||||||
.also(::onBuildDialog)
|
.also(::onBuildDialog)
|
||||||
.create()
|
.create()
|
||||||
|
|||||||