首次提交

1105075896@qq.com 8 years ago
commit 04cb229e58

8
.gitignore vendored

@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures

@ -0,0 +1 @@
MonkeyBook

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>

@ -0,0 +1,3 @@
<component name="CopyrightManager">
<settings default="" />
</component>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/basemvplib" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
<component name="masterDetails">
<states>
<state key="ProjectJDKs.UI">
<settings>
<last-edited>1.8</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/MonkeyBook.iml" filepath="$PROJECT_DIR$/MonkeyBook.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/basemvplib/basemvplib.iml" filepath="$PROJECT_DIR$/basemvplib/basemvplib.iml" />
</modules>
</component>
</project>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>

1
app/.gitignore vendored

@ -0,0 +1 @@
/build

@ -0,0 +1,111 @@
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.monke.monkeybook"
minSdkVersion 17
targetSdkVersion 25
versionCode 6
versionName "1.2.1"
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "debug"]
}
productFlavors{
baidu {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu"]
}
pyger{
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "pyger"]
}
}
signingConfigs {
config {
keyAlias 'monkeybook'
keyPassword 'zqh19931118'
storeFile file('D:/WorkSpace/Android/PersonalKey/Monke_keystore.jks')
storePassword 'zqh19931118'
}
}
lintOptions {
abortOnError false
}
buildTypes {
release {
buildConfigField "boolean", "IS_RELEASE", "true"
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
//apk
def fileName = APP_NAME +"_"+"${variant.productFlavors[0].name}"+ "_v" + defaultConfig.versionName + "(" + defaultConfig.versionCode + ").apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
debug {
buildConfigField "boolean", "IS_RELEASE", "false"
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// signingConfig signingConfigs.config
}
}
}
repositories{
flatDir{
dirs 'libs'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile(name: 'autoupdatesdk-release', ext: 'aar')
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:support-compat:25.1.0'
compile project(':basemvplib')
//GreenDao
compile 'org.greenrobot:greendao:3.0.1'
compile 'org.greenrobot:greendao-generator:3.0.0'
//JSOUP
compile 'org.jsoup:jsoup:1.10.2'
//
compile 'com.zhangmonke:ImmerseLayout:1.1.1'
//ProgressBar
compile 'com.zhangmonke:MProgressBar:1.0.1'
//Glide
compile 'com.github.bumptech.glide:glide:3.7.0'
//AutofitTextView
compile 'me.grantland:autofittextview:0.2.1'
//
compile 'tyrantgit:explosionfield:1.0.1'
//View
compile 'com.daimajia.easing:library:2.0@aar'
compile 'com.daimajia.androidanimations:library:2.2@aar'
//CircleImageView
compile 'de.hdodenhof:circleimageview:2.1.0'
//SwitchButton
compile 'com.kyleduo.switchbutton:library:1.4.4'
compile 'com.victor:lib:1.0.4'
compile files('libs/commons-codec-1.10-sources.jar')
compile files('libs/juniversalchardet-1.0.3.jar')
compile files('libs/umeng-analytics-v6.1.1.jar')
compile files('libs/utdid4all-1.0.4.jar')
}
greendao {
schemaVersion 1
daoPackage 'com.monke.monkeybook.dao'
targetGenDir 'src/main/java'
}

Binary file not shown.

@ -0,0 +1,206 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:\CodeTool\Android\Android_SDK/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
#
# 对于一些基本指令的添加
#
#############################################
# 代码混淆压缩比在0~7之间默认为5一般不做修改
-optimizationpasses 5
# 混合时不使用大小写混合,混合后的类名为小写
-dontusemixedcaseclassnames
# 指定不去忽略非公共库的类
-dontskipnonpubliclibraryclasses
# 这句话能够使我们的项目混淆后产生映射文件
# 包含有类名->混淆后类名的映射关系
-verbose
# 指定不去忽略非公共库的类成员
-dontskipnonpubliclibraryclassmembers
# 不做预校验preverify是proguard的四个步骤之一Android不需要preverify去掉这一步能够加快混淆速度
-dontpreverify
# 保留Annotation不混淆
-keepattributes *Annotation*,InnerClasses
# 避免混淆泛型
-keepattributes Signature
# 抛出异常时保留代码行号
-keepattributes SourceFile,LineNumberTable
# 指定混淆是采用的算法,后面的参数是一个过滤器
# 这个过滤器是谷歌推荐的算法,一般不做更改
-optimizations !code/simplification/cast,!field/*,!class/merging/*
#############################################
#
# Android开发中一些需要保留的公共部分
#
#############################################
# 保留我们使用的四大组件自定义的Application等等这些类不被混淆
# 因为这些子类都有可能被外部调用
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Appliction
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class * extends android.view.View
-keep public class com.android.vending.licensing.ILicensingService
# 保留support下的所有类及其内部类
-keep class android.support.** {*;}
# 保留继承的
-keep public class * extends android.support.v4.**
-keep public class * extends android.support.v7.**
-keep public class * extends android.support.annotation.**
# 保留R下面的资源
-keep class **.R$* {*;}
# 保留本地native方法不被混淆
-keepclasseswithmembernames class * {
native <methods>;
}
# 保留在Activity中的方法参数是view的方法
# 这样以来我们在layout中写的onClick就不会被影响
-keepclassmembers class * extends android.app.Activity{
public void *(android.view.View);
}
# 保留枚举类不被混淆
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
# 保留我们自定义控件继承自View不被混淆
-keep public class * extends android.view.View{
*** get*();
void set*(***);
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
}
# 保留Parcelable序列化类不被混淆
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
# 保留Serializable序列化的类不被混淆
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
!static !transient <fields>;
!private <fields>;
!private <methods>;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
# 对于带有回调函数的onXXEvent、**On*Listener的,不能被混淆
-keepclassmembers class * {
void *(**On*Event);
void *(**On*Listener);
}
# webView处理项目中没有使用到webView忽略即可
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
public *;
}
-keepclassmembers class * extends android.webkit.webViewClient {
public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap);
public boolean *(android.webkit.WebView, java.lang.String);
}
-keepclassmembers class * extends android.webkit.webViewClient {
public void *(android.webkit.webView, jav.lang.String);
}
# 移除Log类打印各个等级日志的代码打正式包的时候可以做为禁log使用这里可以作为禁止log打印的功能使用
# 记得proguard-android.txt中一定不要加-dontoptimize才起作用
# 另外的一种实现方案是通过BuildConfig.DEBUG的变量来控制
#-assumenosideeffects class android.util.Log {
# public static int v(...);
# public static int i(...);
# public static int w(...);
# public static int d(...);
# public static int e(...);
#}
### greenDAO 3
-keep class org.greenrobot.greendao.**{ *; }
-keepclassmembers class * extends org.greenrobot.greendao.AbstractDao {
public static java.lang.String TABLENAME;
}
-keep class **$Properties
-dontwarn org.greenrobot.greendao.database.**
-dontwarn rx.**
-dontwarn okio.**
-dontwarn retrofit2.**
-dontwarn javax.annotation.**
-keep class retrofit2.**{*;}
-keep class okhttp3.**{*;}
-keep class okio.**{*;}
-keep class com.hwangjr.rxbus.**{*;}
-dontwarn org.apache.log4j.lf5.viewer.**
-dontnote org.apache.log4j.lf5.viewer.**
-dontwarn freemarker.**
-dontnote org.python.core.**
-dontwarn com.hwangjr.rxbus.**
-keep class com.monke.monkeybook.widget.**{*;}
-keep class com.monke.monkeybook.bean.**{*;}
-keep class android.support.**{*;}
-keep class me.grantland.widget.**{*;}
-keep class de.hdodenhof.circleimageview.**{*;}
-keep class retrofit2.**{*;}
-keep class tyrant.explosionfield.**{*;}
-keep class tyrantgit.explosionfield.**{*;}
-keep class freemarker.**{*;}
##JSOUP
-keep class org.jsoup.**{ *; }
-keep class com.monke.mprogressbar.**{ *; }
##友盟统计
-keepclassmembers class * {
public <init> (org.json.JSONObject);
}
-keep public class com.monke.monkeybook.R$*{
public static final int *;
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
##百度自动更新
-keep class com.baidu.**{*;}

@ -0,0 +1,13 @@
package com.monke.monkeybook;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.monke.monkeybook">
<application
android:name=".MApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/CAppTheme"
tools:replace="android:theme">
<activity
android:name=".view.impl.WelcomeActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".view.impl.MainActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait" />
<activity
android:name=".view.impl.SearchActivity"
android:configChanges="locale|keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@style/CAppTransparentTheme"
android:windowSoftInputMode="stateHidden|adjustPan" />
<service android:name=".service.DownloadService" />
<activity
android:name=".view.impl.LibraryActivity"
android:screenOrientation="portrait"
android:theme="@style/CAppTransparentTheme" />
<activity
android:name=".view.impl.ChoiceBookActivity"
android:screenOrientation="portrait" />
<activity
android:name=".view.impl.BookDetailActivity"
android:screenOrientation="portrait"
android:theme="@style/CAppTransparentTheme" />
<activity
android:name=".view.impl.ReadBookActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<data android:mimeType="text/plain"></data>
</intent-filter>
</activity>
<activity
android:name=".view.impl.ImportBookActivity"
android:screenOrientation="portrait"
android:theme="@style/CAppTransparentTheme" />
<meta-data
android:name="BDAPPID"
android:value="@string/baidu_app_id" />
<meta-data
android:name="BDAPPKEY"
android:value="@string/baidu_app_key" />
<meta-data
android:name="UMENG_CHANNEL_VALUE"
android:value="${UMENG_CHANNEL_VALUE}" />
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/bdp_update_filepaths" />
</provider>
</application>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-sdk android:minSdkVersion="8"></uses-sdk>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
</manifest>

@ -0,0 +1,34 @@
package com.monke.monkeybook;
import java.util.HashMap;
import java.util.Map;
public class BitIntentDataManager {
public static Map<String,Object> bigData;
private static BitIntentDataManager instance = null;
public static BitIntentDataManager getInstance(){
if(instance == null){
synchronized (BitIntentDataManager.class){
if(instance == null){
instance = new BitIntentDataManager();
}
}
}
return instance;
}
private BitIntentDataManager(){
bigData = new HashMap<>();
}
public Object getData(String key){
return bigData.get(key);
}
public void putData(String key,Object data){
bigData.put(key,data);
}
public void cleanData(String key){
bigData.remove(key);
}
}

@ -0,0 +1,124 @@
package com.monke.monkeybook;
import com.monke.monkeybook.base.observer.SimpleObserver;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
public class ErrorAnalyContentManager {
private ErrorAnalyContentManager(){
}
private static ErrorAnalyContentManager instance;
public static ErrorAnalyContentManager getInstance(){
if(instance == null){
synchronized (ErrorAnalyContentManager.class){
if(instance == null){
instance = new ErrorAnalyContentManager();
}
}
}
return instance;
}
public void writeNewErrorUrl(final String url){
Observable.create(new ObservableOnSubscribe<Boolean>() {
@Override
public void subscribe(ObservableEmitter<Boolean> e) throws Exception {
String filePath = MApplication.getInstance().getExternalFilesDir("").getPath();
File dir = new File(filePath);
if(!dir.exists()){
dir.mkdirs();
}
File file2 = new File(filePath,"ErrorAnalyUrlsDetail.txt");
if(!file2.exists()) {
file2.createNewFile();
}
FileOutputStream fileOutputStream2 = new FileOutputStream(file2,true);
fileOutputStream2.write((url+" \r\n").getBytes());
fileOutputStream2.flush();
fileOutputStream2.close();
///////////////////////////////////////////////////////////////////////
File file1 = new File(filePath,"ErrorAnalyUrls.txt");
if(!file1.exists()) {
file1.createNewFile();
}
FileInputStream inputStream = new FileInputStream(file1);
byte[] bytes = new byte[1024];
ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
while (inputStream.read(bytes) != -1) {
arrayOutputStream.write(bytes, 0, bytes.length);
}
inputStream.close();
arrayOutputStream.close();
String content = new String(arrayOutputStream.toByteArray());
if(!content.contains(url.substring(0,url.indexOf('/',8)))){
FileOutputStream fileOutputStream1 = new FileOutputStream(file1,true);
fileOutputStream1.write((url.substring(0,url.indexOf('/',8))+" \r\n").getBytes());
fileOutputStream1.flush();
fileOutputStream1.close();
}
e.onNext(true);
e.onComplete();
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SimpleObserver<Boolean>() {
@Override
public void onNext(Boolean value) {
}
@Override
public void onError(Throwable e) {
}
});
}
public void writeMayByNetError(final String url){
Observable.create(new ObservableOnSubscribe<Boolean>() {
@Override
public void subscribe(ObservableEmitter<Boolean> e) throws Exception {
String filePath = MApplication.getInstance().getExternalFilesDir("").getPath();
File dir = new File(filePath);
if(!dir.exists()){
dir.mkdirs();
}
File file = new File(filePath,"ErrorNetUrl.txt");
if(!file.exists()) {
file.createNewFile();
}
FileOutputStream fileOutputStream2 = new FileOutputStream(file,true);
fileOutputStream2.write((url+" \r\n").getBytes());
fileOutputStream2.flush();
fileOutputStream2.close();
e.onNext(true);
e.onComplete();
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SimpleObserver<Boolean>() {
@Override
public void onNext(Boolean value) {
}
@Override
public void onError(Throwable e) {
}
});
}
}

@ -0,0 +1,38 @@
package com.monke.monkeybook;
import android.app.Application;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.widget.Toast;
import com.monke.monkeybook.service.DownloadService;
import com.umeng.analytics.MobclickAgent;
public class MApplication extends Application {
private static MApplication instance;
@Override
public void onCreate() {
super.onCreate();
if (BuildConfig.IS_RELEASE) {
String channel = "debug";
try {
ApplicationInfo appInfo = getPackageManager()
.getApplicationInfo(getPackageName(),
PackageManager.GET_META_DATA);
channel = appInfo.metaData.getString("UMENG_CHANNEL_VALUE");
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
MobclickAgent.startWithConfigure(new MobclickAgent.UMAnalyticsConfig(this, getString(R.string.umeng_key), channel, MobclickAgent.EScenarioType.E_UM_NORMAL, true));
}
instance = this;
startService(new Intent(this, DownloadService.class));
}
public static MApplication getInstance() {
return instance;
}
}

@ -0,0 +1,176 @@
package com.monke.monkeybook;
import android.content.SharedPreferences;
import android.graphics.Color;
import com.monke.monkeybook.utils.DensityUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ReadBookControl {
public static final int DEFAULT_TEXT = 2;
public static final int DEFAULT_BG = 1;
private static List<Map<String,Integer>> textKind;
private static List<Map<String,Integer>> textDrawable;
private int textSize;
private int textExtra;
private int textColor;
private int textBackground;
private int textKindIndex = DEFAULT_TEXT;
private int textDrawableIndex = DEFAULT_BG;
private Boolean canClickTurn = true;
private Boolean canKeyTurn = true;
private SharedPreferences preference;
private static ReadBookControl readBookControl;
public static ReadBookControl getInstance(){
if(readBookControl == null){
synchronized (ReadBookControl.class){
if(readBookControl == null){
readBookControl = new ReadBookControl();
}
}
}
return readBookControl;
}
private ReadBookControl(){
if(null == textKind){
textKind = new ArrayList<>();
Map<String,Integer> temp1 = new HashMap<>();
temp1.put("textSize", 14);
temp1.put("textExtra", DensityUtil.dp2px(MApplication.getInstance(),6.5f));
textKind.add(temp1);
Map<String,Integer> temp2 = new HashMap<>();
temp2.put("textSize", 16);
temp2.put("textExtra", DensityUtil.dp2px(MApplication.getInstance(),8));
textKind.add(temp2);
Map<String,Integer> temp3 = new HashMap<>();
temp3.put("textSize", 17);
temp3.put("textExtra", DensityUtil.dp2px(MApplication.getInstance(),9));
textKind.add(temp3);
Map<String,Integer> temp4 = new HashMap<>();
temp4.put("textSize", 20);
temp4.put("textExtra", DensityUtil.dp2px(MApplication.getInstance(),11));
textKind.add(temp4);
Map<String,Integer> temp5 = new HashMap<>();
temp5.put("textSize", 22);
temp5.put("textExtra", DensityUtil.dp2px(MApplication.getInstance(),13));
textKind.add(temp5);
}
if(null == textDrawable){
textDrawable = new ArrayList<>();
Map<String,Integer> temp1 = new HashMap<>();
temp1.put("textColor",Color.parseColor("#3E3D3B"));
temp1.put("textBackground",R.drawable.shape_bg_readbook_white);
textDrawable.add(temp1);
Map<String,Integer> temp2 = new HashMap<>();
temp2.put("textColor",Color.parseColor("#5E432E"));
temp2.put("textBackground",R.drawable.bg_readbook_yellow);
textDrawable.add(temp2);
Map<String,Integer> temp3 = new HashMap<>();
temp3.put("textColor",Color.parseColor("#22482C"));
temp3.put("textBackground",R.drawable.bg_readbook_green);
textDrawable.add(temp3);
Map<String,Integer> temp4 = new HashMap<>();
temp4.put("textColor",Color.parseColor("#808080"));
temp4.put("textBackground",R.drawable.bg_readbook_black);
textDrawable.add(temp4);
}
preference = MApplication.getInstance().getSharedPreferences("CONFIG", 0);
this.textKindIndex = preference.getInt("textKindIndex",DEFAULT_TEXT);
this.textSize = textKind.get(textKindIndex).get("textSize");
this.textExtra = textKind.get(textKindIndex).get("textExtra");
this.textDrawableIndex = preference.getInt("textDrawableIndex",DEFAULT_BG);
this.textColor = textDrawable.get(textDrawableIndex).get("textColor");
this.textBackground = textDrawable.get(textDrawableIndex).get("textBackground");
this.canClickTurn = preference.getBoolean("canClickTurn",true);
this.canKeyTurn = preference.getBoolean("canClickTurn",true);
}
public int getTextSize() {
return textSize;
}
public int getTextExtra() {
return textExtra;
}
public int getTextColor() {
return textColor;
}
public int getTextBackground() {
return textBackground;
}
public int getTextKindIndex() {
return textKindIndex;
}
public void setTextKindIndex(int textKindIndex) {
this.textKindIndex = textKindIndex;
SharedPreferences.Editor editor = preference.edit();
editor.putInt("textKindIndex",textKindIndex);
editor.commit();
this.textSize = textKind.get(textKindIndex).get("textSize");
this.textExtra = textKind.get(textKindIndex).get("textExtra");
}
public int getTextDrawableIndex() {
return textDrawableIndex;
}
public void setTextDrawableIndex(int textDrawableIndex) {
this.textDrawableIndex = textDrawableIndex;
SharedPreferences.Editor editor = preference.edit();
editor.putInt("textDrawableIndex",textDrawableIndex);
editor.commit();
this.textColor = textDrawable.get(textDrawableIndex).get("textColor");
this.textBackground = textDrawable.get(textDrawableIndex).get("textBackground");
}
public static List<Map<String, Integer>> getTextKind() {
return textKind;
}
public static List<Map<String, Integer>> getTextDrawable() {
return textDrawable;
}
public Boolean getCanKeyTurn() {
return canKeyTurn;
}
public void setCanKeyTurn(Boolean canKeyTurn) {
this.canKeyTurn = canKeyTurn;
SharedPreferences.Editor editor = preference.edit();
editor.putBoolean("canKeyTurn",canKeyTurn);
editor.commit();
}
public Boolean getCanClickTurn() {
return canClickTurn;
}
public void setCanClickTurn(Boolean canClickTurn) {
this.canClickTurn = canClickTurn;
SharedPreferences.Editor editor = preference.edit();
editor.putBoolean("canClickTurn",canClickTurn);
editor.commit();
}
}

@ -0,0 +1,19 @@
package com.monke.monkeybook.base;
import com.monke.basemvplib.IPresenter;
import com.monke.basemvplib.impl.BaseActivity;
import com.umeng.analytics.MobclickAgent;
public abstract class MBaseActivity<T extends IPresenter> extends BaseActivity<T>{
@Override
protected void onResume() {
super.onResume();
MobclickAgent.onResume(this);
}
@Override
protected void onPause() {
super.onPause();
MobclickAgent.onPause(this);
}
}

@ -0,0 +1,37 @@
package com.monke.monkeybook.base.observer;
import com.monke.monkeybook.utils.NetworkUtil;
public class SimpleObserClass<T> {
private int code;
private T t;
public SimpleObserClass(T t){
this(t,NetworkUtil.SUCCESS);
}
public SimpleObserClass(T t,int code){
this.t = t;
this.code = code;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public Boolean success(){
return code == NetworkUtil.SUCCESS;
}
public T getT() {
return t;
}
public void setT(T t) {
this.t = t;
}
}

@ -0,0 +1,17 @@
package com.monke.monkeybook.base.observer;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
public abstract class SimpleObserver<T> implements Observer<T> {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onComplete() {
}
}

@ -0,0 +1,143 @@
package com.monke.monkeybook.bean;
import android.os.Parcel;
import android.os.Parcelable;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Transient;
import org.greenrobot.greendao.annotation.Generated;
import java.util.ArrayList;
import java.util.List;
/**
*
*/
@Entity
public class BookContentBean implements Parcelable{
@Id
private String durChapterUrl; //对应BookInfoBean noteUrl;
private int durChapterIndex; //当前章节 (包括番外)
private String durCapterContent; //当前章节内容
private String tag; //来源 某个网站/本地
@Transient
private Boolean isRight = true;
@Transient
private List<String> lineContent = new ArrayList<>();
@Transient
private float lineSize;
public BookContentBean(){
}
public float getLineSize() {
return lineSize;
}
public void setLineSize(float lineSize) {
this.lineSize = lineSize;
}
protected BookContentBean(Parcel in) {
durChapterUrl = in.readString();
durChapterIndex = in.readInt();
durCapterContent = in.readString();
tag = in.readString();
lineContent = in.createStringArrayList();
isRight = in.readByte()!=0;
}
@Generated(hash = 1355824386)
public BookContentBean(String durChapterUrl, int durChapterIndex,
String durCapterContent, String tag) {
this.durChapterUrl = durChapterUrl;
this.durChapterIndex = durChapterIndex;
this.durCapterContent = durCapterContent;
this.tag = tag;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(durChapterUrl);
dest.writeInt(durChapterIndex);
dest.writeString(durCapterContent);
dest.writeString(tag);
dest.writeStringList(lineContent);
dest.writeByte((byte) (isRight ? 1 : 0));
}
@Override
public int describeContents() {
return 0;
}
@Transient
public static final Creator<BookContentBean> CREATOR = new Creator<BookContentBean>() {
@Override
public BookContentBean createFromParcel(Parcel in) {
return new BookContentBean(in);
}
@Override
public BookContentBean[] newArray(int size) {
return new BookContentBean[size];
}
};
public String getDurChapterUrl() {
return durChapterUrl;
}
public void setDurChapterUrl(String durChapterUrl) {
this.durChapterUrl = durChapterUrl;
}
public int getDurChapterIndex() {
return durChapterIndex;
}
public void setDurChapterIndex(int durChapterIndex) {
this.durChapterIndex = durChapterIndex;
}
public String getDurCapterContent() {
return durCapterContent;
}
public void setDurCapterContent(String durCapterContent) {
this.durCapterContent = durCapterContent;
if(durCapterContent==null || durCapterContent.length()==0)
this.isRight = false;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public List<String> getLineContent() {
return lineContent;
}
public void setLineContent(List<String> lineContent) {
this.lineContent = lineContent;
}
public Boolean getRight() {
return isRight;
}
public void setRight(Boolean right) {
isRight = right;
}
}

@ -0,0 +1,212 @@
package com.monke.monkeybook.bean;
import android.os.Parcel;
import android.os.Parcelable;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Transient;
import org.greenrobot.greendao.annotation.Generated;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
*
*/
@Entity
public class BookInfoBean implements Parcelable,Cloneable{
@Transient
public static final long REFRESH_DUR = 10*60*1000;
private String name; //小说名
private String tag;
@Id
private String noteUrl; //如果是来源网站 则小说根地址 /如果是本地 则是小说本地MD5
private String chapterUrl; //章节目录地址
@Transient
private List<ChapterListBean> chapterlist = new ArrayList<>(); //章节列表
private long finalRefreshData; //章节最后更新时间
private String coverUrl; //小说封面
private String author;//作者
private String introduce; //简介
private String origin; //来源
public BookInfoBean(){
}
protected BookInfoBean(Parcel in) {
name = in.readString();
tag = in.readString();
noteUrl = in.readString();
chapterUrl = in.readString();
chapterlist = in.createTypedArrayList(ChapterListBean.CREATOR);
finalRefreshData = in.readLong();
coverUrl = in.readString();
author = in.readString();
introduce = in.readString();
origin = in.readString();
}
@Generated(hash = 1627552162)
public BookInfoBean(String name, String tag, String noteUrl, String chapterUrl,
long finalRefreshData, String coverUrl, String author, String introduce,
String origin) {
this.name = name;
this.tag = tag;
this.noteUrl = noteUrl;
this.chapterUrl = chapterUrl;
this.finalRefreshData = finalRefreshData;
this.coverUrl = coverUrl;
this.author = author;
this.introduce = introduce;
this.origin = origin;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeString(tag);
dest.writeString(noteUrl);
dest.writeString(chapterUrl);
dest.writeTypedList(chapterlist);
dest.writeLong(finalRefreshData);
dest.writeString(coverUrl);
dest.writeString(author);
dest.writeString(introduce);
dest.writeString(origin);
}
@Override
public int describeContents() {
return 0;
}
@Transient
public static final Creator<BookInfoBean> CREATOR = new Creator<BookInfoBean>() {
@Override
public BookInfoBean createFromParcel(Parcel in) {
return new BookInfoBean(in);
}
@Override
public BookInfoBean[] newArray(int size) {
return new BookInfoBean[size];
}
};
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getNoteUrl() {
return noteUrl;
}
public void setNoteUrl(String noteUrl) {
this.noteUrl = noteUrl;
}
public String getChapterUrl() {
return chapterUrl;
}
public void setChapterUrl(String chapterUrl) {
this.chapterUrl = chapterUrl;
}
public List<ChapterListBean> getChapterlist() {
return chapterlist;
}
public void setChapterlist(List<ChapterListBean> chapterlist) {
this.chapterlist = chapterlist;
}
public void addChapterlist(List<ChapterListBean> chapterlist){
this.chapterlist.addAll(chapterlist);
}
public long getFinalRefreshData() {
return finalRefreshData;
}
public void setFinalRefreshData(long finalRefreshData) {
this.finalRefreshData = finalRefreshData;
}
public String getCoverUrl() {
return coverUrl;
}
public void setCoverUrl(String coverUrl) {
this.coverUrl = coverUrl;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getIntroduce() {
return introduce;
}
public void setIntroduce(String introduce) {
this.introduce = introduce;
}
public String getOrigin() {
return this.origin;
}
public void setOrigin(String origin) {
this.origin = origin;
}
@Override
protected Object clone() throws CloneNotSupportedException {
BookInfoBean bookInfoBean = (BookInfoBean) super.clone();
bookInfoBean.name = new String(name);
bookInfoBean.tag = new String(tag);
bookInfoBean.noteUrl = new String(noteUrl);
bookInfoBean.chapterUrl = new String(chapterUrl);
bookInfoBean.coverUrl = new String(coverUrl);
bookInfoBean.author = new String(author);
bookInfoBean.introduce = new String(introduce);
bookInfoBean.origin = new String(origin);
if(chapterlist!=null){
List<ChapterListBean> newList = new ArrayList<>();
Iterator<ChapterListBean> iterator = chapterlist.iterator();
while(iterator.hasNext()){
newList.add((ChapterListBean) iterator.next().clone());
}
bookInfoBean.setChapterlist(newList);
}
return bookInfoBean;
}
}

@ -0,0 +1,144 @@
package com.monke.monkeybook.bean;
import android.os.Parcel;
import android.os.Parcelable;
import com.monke.monkeybook.widget.contentswitchview.BookContentView;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Transient;
/**
* item Bean
*/
@Entity
public class BookShelfBean implements Parcelable,Cloneable{
@Transient
public static final long REFRESH_TIME = 5*60*1000; //更新时间间隔 至少
@Transient
public static final String LOCAL_TAG = "loc_book";
@Id
private String noteUrl; //对应BookInfoBean noteUrl;
private int durChapter; //当前章节 (包括番外)
private int durChapterPage = BookContentView.DURPAGEINDEXBEGIN; // 当前章节位置 用页码
private long finalDate; //最后阅读时间
private String tag;
@Transient
private BookInfoBean bookInfoBean = new BookInfoBean();
public BookShelfBean(){
}
protected BookShelfBean(Parcel in) {
noteUrl = in.readString();
durChapter = in.readInt();
durChapterPage = in.readInt();
finalDate = in.readLong();
tag = in.readString();
bookInfoBean = in.readParcelable(BookInfoBean.class.getClassLoader());
}
@Generated(hash = 2028192361)
public BookShelfBean(String noteUrl, int durChapter, int durChapterPage, long finalDate,
String tag) {
this.noteUrl = noteUrl;
this.durChapter = durChapter;
this.durChapterPage = durChapterPage;
this.finalDate = finalDate;
this.tag = tag;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(noteUrl);
dest.writeInt(durChapter);
dest.writeInt(durChapterPage);
dest.writeLong(finalDate);
dest.writeString(tag);
dest.writeParcelable(bookInfoBean, flags);
}
@Override
public int describeContents() {
return 0;
}
@Transient
public static final Creator<BookShelfBean> CREATOR = new Creator<BookShelfBean>() {
@Override
public BookShelfBean createFromParcel(Parcel in) {
return new BookShelfBean(in);
}
@Override
public BookShelfBean[] newArray(int size) {
return new BookShelfBean[size];
}
};
public String getNoteUrl() {
return noteUrl;
}
public void setNoteUrl(String noteUrl) {
this.noteUrl = noteUrl;
}
public int getDurChapter() {
return durChapter;
}
public void setDurChapter(int durChapter) {
this.durChapter = durChapter;
}
public int getDurChapterPage() {
return durChapterPage;
}
public void setDurChapterPage(int durChapterPage) {
this.durChapterPage = durChapterPage;
}
public long getFinalDate() {
return finalDate;
}
public void setFinalDate(long finalDate) {
this.finalDate = finalDate;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public BookInfoBean getBookInfoBean() {
return bookInfoBean;
}
public void setBookInfoBean(BookInfoBean bookInfoBean) {
this.bookInfoBean = bookInfoBean;
}
@Override
public Object clone() throws CloneNotSupportedException {
BookShelfBean bookShelfBean = (BookShelfBean) super.clone();
bookShelfBean.noteUrl = new String(noteUrl);
bookShelfBean.tag = new String(tag);
bookShelfBean.bookInfoBean = (BookInfoBean) bookInfoBean.clone();
return bookShelfBean;
}
}

@ -0,0 +1,148 @@
package com.monke.monkeybook.bean;
import android.os.Parcel;
import android.os.Parcelable;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Transient;
import org.greenrobot.greendao.annotation.Generated;
@Entity
public class ChapterListBean implements Parcelable,Cloneable{
private String noteUrl; //对应BookInfoBean noteUrl;
private int durChapterIndex; //当前章节数
@Id
private String durChapterUrl; //当前章节对应的文章地址
private String durChapterName; //当前章节名称
private String tag;
private Boolean hasCache = false;
@Transient
private BookContentBean bookContentBean = new BookContentBean();
protected ChapterListBean(Parcel in) {
noteUrl = in.readString();
durChapterIndex = in.readInt();
durChapterUrl = in.readString();
durChapterName = in.readString();
tag = in.readString();
bookContentBean = in.readParcelable(BookContentBean.class.getClassLoader());
hasCache = in.readByte() != 0;
}
@Generated(hash = 1225922702)
public ChapterListBean(String noteUrl, int durChapterIndex, String durChapterUrl,
String durChapterName, String tag, Boolean hasCache) {
this.noteUrl = noteUrl;
this.durChapterIndex = durChapterIndex;
this.durChapterUrl = durChapterUrl;
this.durChapterName = durChapterName;
this.tag = tag;
this.hasCache = hasCache;
}
@Generated(hash = 1096893365)
public ChapterListBean() {
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(noteUrl);
dest.writeInt(durChapterIndex);
dest.writeString(durChapterUrl);
dest.writeString(durChapterName);
dest.writeString(tag);
dest.writeParcelable(bookContentBean, flags);
dest.writeByte((byte)(hasCache?1:0));
}
@Override
public int describeContents() {
return 0;
}
public BookContentBean getBookContentBean() {
return bookContentBean;
}
public void setBookContentBean(BookContentBean bookContentBean) {
this.bookContentBean = bookContentBean;
}
public Boolean getHasCache() {
return this.hasCache;
}
public void setHasCache(Boolean hasCache) {
this.hasCache = hasCache;
}
public String getTag() {
return this.tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getDurChapterName() {
return this.durChapterName;
}
public void setDurChapterName(String durChapterName) {
this.durChapterName = durChapterName;
}
public String getDurChapterUrl() {
return this.durChapterUrl;
}
public void setDurChapterUrl(String durChapterUrl) {
this.durChapterUrl = durChapterUrl;
}
public int getDurChapterIndex() {
return this.durChapterIndex;
}
public void setDurChapterIndex(int durChapterIndex) {
this.durChapterIndex = durChapterIndex;
}
public String getNoteUrl() {
return this.noteUrl;
}
public void setNoteUrl(String noteUrl) {
this.noteUrl = noteUrl;
}
@Transient
public static final Creator<ChapterListBean> CREATOR = new Creator<ChapterListBean>() {
@Override
public ChapterListBean createFromParcel(Parcel in) {
return new ChapterListBean(in);
}
@Override
public ChapterListBean[] newArray(int size) {
return new ChapterListBean[size];
}
};
@Override
protected Object clone() throws CloneNotSupportedException {
ChapterListBean chapterListBean = (ChapterListBean) super.clone();
chapterListBean.noteUrl = new String(noteUrl);
chapterListBean.durChapterUrl = new String(durChapterUrl);
chapterListBean.durChapterName = new String(durChapterName);
chapterListBean.tag = new String(tag);
chapterListBean.hasCache = new Boolean(hasCache);
chapterListBean.bookContentBean = new BookContentBean();
return chapterListBean;
}
}

@ -0,0 +1,136 @@
package com.monke.monkeybook.bean;
import android.os.Parcel;
import android.os.Parcelable;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Transient;
import org.greenrobot.greendao.annotation.Generated;
@Entity
public class DownloadChapterBean implements Parcelable {
private String noteUrl;
private int durChapterIndex; //当前章节数
@Id
private String durChapterUrl; //当前章节对应的文章地址
private String durChapterName; //当前章节名称
private String tag;
private String bookName;
private String coverUrl; //小说封面
protected DownloadChapterBean(Parcel in) {
noteUrl = in.readString();
durChapterIndex = in.readInt();
durChapterUrl = in.readString();
durChapterName = in.readString();
tag = in.readString();
bookName = in.readString();
coverUrl = in.readString();
}
@Generated(hash = 757008458)
public DownloadChapterBean(String noteUrl, int durChapterIndex, String durChapterUrl,
String durChapterName, String tag, String bookName, String coverUrl) {
this.noteUrl = noteUrl;
this.durChapterIndex = durChapterIndex;
this.durChapterUrl = durChapterUrl;
this.durChapterName = durChapterName;
this.tag = tag;
this.bookName = bookName;
this.coverUrl = coverUrl;
}
@Generated(hash = 301211198)
public DownloadChapterBean() {
}
@Transient
public static final Creator<DownloadChapterBean> CREATOR = new Creator<DownloadChapterBean>() {
@Override
public DownloadChapterBean createFromParcel(Parcel in) {
return new DownloadChapterBean(in);
}
@Override
public DownloadChapterBean[] newArray(int size) {
return new DownloadChapterBean[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(noteUrl);
dest.writeInt(durChapterIndex);
dest.writeString(durChapterUrl);
dest.writeString(durChapterName);
dest.writeString(tag);
dest.writeString(bookName);
dest.writeString(coverUrl);
}
public String getNoteUrl() {
return noteUrl;
}
public void setNoteUrl(String noteUrl) {
this.noteUrl = noteUrl;
}
public int getDurChapterIndex() {
return durChapterIndex;
}
public void setDurChapterIndex(int durChapterIndex) {
this.durChapterIndex = durChapterIndex;
}
public String getDurChapterUrl() {
return durChapterUrl;
}
public void setDurChapterUrl(String durChapterUrl) {
this.durChapterUrl = durChapterUrl;
}
public String getDurChapterName() {
return durChapterName;
}
public void setDurChapterName(String durChapterName) {
this.durChapterName = durChapterName;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getCoverUrl() {
return coverUrl;
}
public void setCoverUrl(String coverUrl) {
this.coverUrl = coverUrl;
}
}

@ -0,0 +1,51 @@
package com.monke.monkeybook.bean;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
import java.util.List;
public class DownloadChapterListBean implements Parcelable {
private List<DownloadChapterBean> data;
public DownloadChapterListBean(List<DownloadChapterBean> result) {
this.data = result;
}
protected DownloadChapterListBean(Parcel in) {
if(data == null)
data = new ArrayList<>();
in.readTypedList(data,DownloadChapterBean.CREATOR);
}
public static final Creator<DownloadChapterListBean> CREATOR = new Creator<DownloadChapterListBean>() {
@Override
public DownloadChapterListBean createFromParcel(Parcel in) {
return new DownloadChapterListBean(in);
}
@Override
public DownloadChapterListBean[] newArray(int size) {
return new DownloadChapterListBean[size];
}
};
public List<DownloadChapterBean> getData() {
return data;
}
public void setData(List<DownloadChapterBean> data) {
this.data = data;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeTypedList(data);
}
}

@ -0,0 +1,24 @@
package com.monke.monkeybook.bean;
import java.util.List;
public class LibraryBean {
private List<LibraryNewBookBean> libraryNewBooks;
private List<LibraryKindBookListBean> kindBooks;
public List<LibraryNewBookBean> getLibraryNewBooks() {
return libraryNewBooks;
}
public void setLibraryNewBooks(List<LibraryNewBookBean> libraryNewBooks) {
this.libraryNewBooks = libraryNewBooks;
}
public List<LibraryKindBookListBean> getKindBooks() {
return kindBooks;
}
public void setKindBooks(List<LibraryKindBookListBean> kindBooks) {
this.kindBooks = kindBooks;
}
}

@ -0,0 +1,33 @@
package com.monke.monkeybook.bean;
import java.util.List;
public class LibraryKindBookListBean {
private String kindName;
private String kindUrl;
private List<SearchBookBean> books;
public String getKindName() {
return kindName;
}
public void setKindName(String kindName) {
this.kindName = kindName;
}
public List<SearchBookBean> getBooks() {
return books;
}
public void setBooks(List<SearchBookBean> books) {
this.books = books;
}
public String getKindUrl() {
return kindUrl;
}
public void setKindUrl(String kindUrl) {
this.kindUrl = kindUrl;
}
}

@ -0,0 +1,47 @@
package com.monke.monkeybook.bean;
public class LibraryNewBookBean {
private String name;
private String url;
private String tag;
private String orgin;
public LibraryNewBookBean(String name, String url, String tag, String orgin) {
this.name = name;
this.url = url;
this.tag = tag;
this.orgin = orgin;
}
public String getOrgin() {
return orgin;
}
public void setOrgin(String orgin) {
this.orgin = orgin;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}

@ -0,0 +1,31 @@
package com.monke.monkeybook.bean;
public class LibraryRankBean {
private String coverUrl;
private String name;
private String author;
public String getCoverUrl() {
return coverUrl;
}
public void setCoverUrl(String coverUrl) {
this.coverUrl = coverUrl;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
}

@ -0,0 +1,27 @@
package com.monke.monkeybook.bean;
public class LocBookShelfBean {
private Boolean isNew;
private BookShelfBean bookShelfBean;
public LocBookShelfBean(Boolean isNew,BookShelfBean bookShelfBean){
this.isNew = isNew;
this.bookShelfBean = bookShelfBean;
}
public Boolean getNew() {
return isNew;
}
public void setNew(Boolean aNew) {
isNew = aNew;
}
public BookShelfBean getBookShelfBean() {
return bookShelfBean;
}
public void setBookShelfBean(BookShelfBean bookShelfBean) {
this.bookShelfBean = bookShelfBean;
}
}

@ -0,0 +1,29 @@
package com.monke.monkeybook.bean;
import java.util.List;
public class ReadBookContentBean {
private List<BookContentBean> bookContentList;
private int pageIndex;
public ReadBookContentBean(List<BookContentBean> bookContentList,int pageIndex){
this.bookContentList = bookContentList;
this.pageIndex = pageIndex;
}
public List<BookContentBean> getBookContentList() {
return bookContentList;
}
public void setBookContentList(List<BookContentBean> bookContentList) {
this.bookContentList = bookContentList;
}
public int getPageIndex() {
return pageIndex;
}
public void setPageIndex(int pageIndex) {
this.pageIndex = pageIndex;
}
}

@ -0,0 +1,179 @@
package com.monke.monkeybook.bean;
import android.os.Parcel;
import android.os.Parcelable;
public class SearchBookBean implements Parcelable{
private String noteUrl;
private String coverUrl;
private String name;
private String author;
private long words;
private String state;
private String lastChapter;
private Boolean isAdd = false;
private String tag;
private String kind;
private String origin;
private String desc;
public SearchBookBean(){
}
protected SearchBookBean(Parcel in) {
noteUrl = in.readString();
coverUrl = in.readString();
name = in.readString();
author = in.readString();
words = in.readLong();
state = in.readString();
lastChapter = in.readString();
isAdd = in.readByte() != 0;
tag = in.readString();
kind = in.readString();
origin = in.readString();
desc = in.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(noteUrl);
dest.writeString(coverUrl);
dest.writeString(name);
dest.writeString(author);
dest.writeLong(words);
dest.writeString(state);
dest.writeString(lastChapter);
dest.writeByte((byte)(isAdd?1:0));
dest.writeString(tag);
dest.writeString(kind);
dest.writeString(origin);
dest.writeString(desc);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<SearchBookBean> CREATOR = new Creator<SearchBookBean>() {
@Override
public SearchBookBean createFromParcel(Parcel in) {
return new SearchBookBean(in);
}
@Override
public SearchBookBean[] newArray(int size) {
return new SearchBookBean[size];
}
};
public String getNoteUrl() {
return noteUrl;
}
public void setNoteUrl(String noteUrl) {
this.noteUrl = noteUrl;
}
public String getCoverUrl() {
return coverUrl;
}
public void setCoverUrl(String coverUrl) {
this.coverUrl = coverUrl;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Boolean getAdd() {
return isAdd;
}
public void setAdd(Boolean add) {
isAdd = add;
}
public long getWords() {
return words;
}
public void setWords(long words) {
this.words = words;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getLastChapter() {
return lastChapter==null?"":lastChapter;
}
public void setLastChapter(String lastChapter) {
this.lastChapter = lastChapter;
}
public String getKind() {
return kind;
}
public void setKind(String kind) {
this.kind = kind;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getOrigin() {
return origin;
}
public void setOrigin(String origin) {
this.origin = origin;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}

@ -0,0 +1,56 @@
package com.monke.monkeybook.bean;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Unique;
import org.greenrobot.greendao.annotation.Generated;
@Entity
public class SearchHistoryBean {
@Id(autoincrement = true)
private Long id = null;
private int type;
private String content;
private long date;
public long getDate() {
return this.date;
}
public void setDate(long date) {
this.date = date;
}
public String getContent() {
return this.content;
}
public void setContent(String content) {
this.content = content;
}
public int getType() {
return this.type;
}
public void setType(int type) {
this.type = type;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public SearchHistoryBean(int type, String content, long date) {
this.type = type;
this.content = content;
this.date = date;
}
@Generated(hash = 488115752)
public SearchHistoryBean(Long id, int type, String content, long date) {
this.id = id;
this.type = type;
this.content = content;
this.date = date;
}
@Generated(hash = 1570282321)
public SearchHistoryBean() {
}
}

@ -0,0 +1,28 @@
package com.monke.monkeybook.bean;
public class WebChapterBean<T> {
private T data;
private Boolean next;
public WebChapterBean(T data,Boolean next){
this.data = data;
this.next = next;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public Boolean getNext() {
return next;
}
public void setNext(Boolean next) {
this.next = next;
}
}

@ -0,0 +1,27 @@
package com.monke.monkeybook.bean;
public class WebContentBean {
private String url;
private String content;
public WebContentBean(String url,String content){
this.url = url;
this.content = content;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}

@ -0,0 +1,912 @@
package com.monke.monkeybook.cache;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.RandomAccessFile;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.json.JSONArray;
import org.json.JSONObject;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
/**
*
*/
public class ACache {
public static final int TIME_HOUR = 60 * 60;
public static final int TIME_DAY = TIME_HOUR * 24;
private static final int MAX_SIZE = 1000 * 1000 * 50; // 50 mb
private static final int MAX_COUNT = Integer.MAX_VALUE; // 不限制存放数据的数量
private static Map<String, ACache> mInstanceMap = new HashMap<String, ACache>();
private ACacheManager mCache;
public static ACache get(Context ctx) {
return get(ctx, "ACache");
}
public static ACache get(Context ctx, String cacheName) {
File f = new File(ctx.getCacheDir(), cacheName);
return get(f, MAX_SIZE, MAX_COUNT);
}
public static ACache get(File cacheDir) {
return get(cacheDir, MAX_SIZE, MAX_COUNT);
}
public static ACache get(Context ctx, long max_zise, int max_count) {
try{
File f = new File(ctx.getCacheDir(), "ACache");
return get(f, max_zise, max_count);
}catch (Exception e){
e.printStackTrace();
}
return null;
}
public static ACache get(File cacheDir, long max_zise, int max_count) {
try{
ACache manager = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());
if (manager == null) {
manager = new ACache(cacheDir, max_zise, max_count);
mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), manager);
}
return manager;
}catch (Exception e){
e.printStackTrace();
}
return null;
}
private static String myPid() {
return "_" + android.os.Process.myPid();
}
private ACache(File cacheDir, long max_size, int max_count) {
try{
if (!cacheDir.exists() && !cacheDir.mkdirs()) {
Log.i("ACache","can't make dirs in "
+ cacheDir.getAbsolutePath());
}
mCache = new ACacheManager(cacheDir, max_size, max_count);
}catch (Exception e){
e.printStackTrace();
}
}
// =======================================
// ============ String数据 读写 ==============
// =======================================
/**
* String
*
* @param key
* key
* @param value
* String
*/
public void put(String key, String value) {
try{
File file = mCache.newFile(key);
BufferedWriter out = null;
try {
out = new BufferedWriter(new FileWriter(file), 1024);
out.write(value);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
mCache.put(file);
}
}catch (Exception e){
e.printStackTrace();
}
}
/**
* String
*
* @param key
* key
* @param value
* String
* @param saveTime
*
*/
public void put(String key, String value, int saveTime) {
put(key, Utils.newStringWithDateInfo(saveTime, value));
}
/**
* String
*
* @param key
* @return String
*/
public String getAsString(String key) {
File file = mCache.get(key);
if (!file.exists())
return null;
boolean removeFile = false;
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(file));
String readString = "";
String currentLine;
while ((currentLine = in.readLine()) != null) {
readString += currentLine;
}
if (!Utils.isDue(readString)) {
return Utils.clearDateInfo(readString);
} else {
removeFile = true;
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (removeFile)
remove(key);
}
}
// =======================================
// ============= JSONObject 数据 读写 ==============
// =======================================
/**
* JSONObject
*
* @param key
* key
* @param value
* JSON
*/
public void put(String key, JSONObject value) {
put(key, value.toString());
}
/**
* JSONObject
*
* @param key
* key
* @param value
* JSONObject
* @param saveTime
*
*/
public void put(String key, JSONObject value, int saveTime) {
put(key, value.toString(), saveTime);
}
/**
* JSONObject
*
* @param key
* @return JSONObject
*/
public JSONObject getAsJSONObject(String key) {
String JSONString = getAsString(key);
try {
JSONObject obj = new JSONObject(JSONString);
return obj;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
// =======================================
// ============ JSONArray 数据 读写 =============
// =======================================
/**
* JSONArray
*
* @param key
* key
* @param value
* JSONArray
*/
public void put(String key, JSONArray value) {
put(key, value.toString());
}
/**
* JSONArray
*
* @param key
* key
* @param value
* JSONArray
* @param saveTime
*
*/
public void put(String key, JSONArray value, int saveTime) {
put(key, value.toString(), saveTime);
}
/**
* JSONArray
*
* @param key
* @return JSONArray
*/
public JSONArray getAsJSONArray(String key) {
String JSONString = getAsString(key);
try {
JSONArray obj = new JSONArray(JSONString);
return obj;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
// =======================================
// ============== byte 数据 读写 =============
// =======================================
/**
* byte
*
* @param key
* key
* @param value
*
*/
public void put(String key, byte[] value) {
File file = mCache.newFile(key);
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
out.write(value);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
mCache.put(file);
}
}
/**
* byte
*
* @param key
* key
* @param value
*
* @param saveTime
*
*/
public void put(String key, byte[] value, int saveTime) {
put(key, Utils.newByteArrayWithDateInfo(saveTime, value));
}
/**
* byte
*
* @param key
* @return byte
*/
public byte[] getAsBinary(String key) {
RandomAccessFile RAFile = null;
boolean removeFile = false;
try {
File file = mCache.get(key);
if (!file.exists())
return null;
RAFile = new RandomAccessFile(file, "r");
byte[] byteArray = new byte[(int) RAFile.length()];
RAFile.read(byteArray);
if (!Utils.isDue(byteArray)) {
return Utils.clearDateInfo(byteArray);
} else {
removeFile = true;
return null;
}
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (RAFile != null) {
try {
RAFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (removeFile)
remove(key);
}
}
// =======================================
// ============= 序列化 数据 读写 ===============
// =======================================
/**
* Serializable
*
* @param key
* key
* @param value
* value
*/
public void put(String key, Serializable value) {
put(key, value, -1);
}
/**
* Serializable
*
* @param key
* key
* @param value
* value
* @param saveTime
*
*/
public void put(String key, Serializable value, int saveTime) {
ByteArrayOutputStream baos = null;
ObjectOutputStream oos = null;
try {
baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
oos.writeObject(value);
byte[] data = baos.toByteArray();
if (saveTime != -1) {
put(key, data, saveTime);
} else {
put(key, data);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
oos.close();
} catch (IOException e) {
}
}
}
/**
* Serializable
*
* @param key
* @return Serializable
*/
public Object getAsObject(String key) {
byte[] data = getAsBinary(key);
if (data != null) {
ByteArrayInputStream bais = null;
ObjectInputStream ois = null;
try {
bais = new ByteArrayInputStream(data);
ois = new ObjectInputStream(bais);
Object reObject = ois.readObject();
return reObject;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
try {
if (bais != null)
bais.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
if (ois != null)
ois.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
// =======================================
// ============== bitmap 数据 读写 =============
// =======================================
/**
* bitmap
*
* @param key
* key
* @param value
* bitmap
*/
public void put(String key, Bitmap value) {
put(key, Utils.Bitmap2Bytes(value));
}
/**
* bitmap
*
* @param key
* key
* @param value
* bitmap
* @param saveTime
*
*/
public void put(String key, Bitmap value, int saveTime) {
put(key, Utils.Bitmap2Bytes(value), saveTime);
}
/**
* bitmap
*
* @param key
* @return bitmap
*/
public Bitmap getAsBitmap(String key) {
if (getAsBinary(key) == null) {
return null;
}
return Utils.Bytes2Bimap(getAsBinary(key));
}
// =======================================
// ============= drawable 数据 读写 =============
// =======================================
/**
* drawable
*
* @param key
* key
* @param value
* drawable
*/
public void put(String key, Drawable value) {
put(key, Utils.drawable2Bitmap(value));
}
/**
* drawable
*
* @param key
* key
* @param value
* drawable
* @param saveTime
*
*/
public void put(String key, Drawable value, int saveTime) {
put(key, Utils.drawable2Bitmap(value), saveTime);
}
/**
* Drawable
*
* @param key
* @return Drawable
*/
public Drawable getAsDrawable(String key) {
if (getAsBinary(key) == null) {
return null;
}
return Utils.bitmap2Drawable(Utils.Bytes2Bimap(getAsBinary(key)));
}
/**
*
*
* @param key
* @return value
*/
public File file(String key) {
try{
File f = mCache.newFile(key);
if (f.exists())
{
return f;
}
}catch (Exception e){
e.printStackTrace();
}
return null;
}
/**
* key
*
* @param key
* @return
*/
public boolean remove(String key) {
return mCache.remove(key);
}
/**
*
*/
public void clear() {
mCache.clear();
}
/**
* @title
* @author michael www.yangfuhai.com
* @version 1.0
*/
public class ACacheManager {
private final AtomicLong cacheSize;
private final AtomicInteger cacheCount;
private final long sizeLimit;
private final int countLimit;
private final Map<File, Long> lastUsageDates = Collections
.synchronizedMap(new HashMap<File, Long>());
protected File cacheDir;
private ACacheManager(File cacheDir, long sizeLimit, int countLimit) {
this.cacheDir = cacheDir;
this.sizeLimit = sizeLimit;
this.countLimit = countLimit;
cacheSize = new AtomicLong();
cacheCount = new AtomicInteger();
calculateCacheSizeAndCacheCount();
}
/**
* cacheSizecacheCount
*/
private void calculateCacheSizeAndCacheCount() {
new Thread(new Runnable() {
@Override
public void run() {
try{
int size = 0;
int count = 0;
File[] cachedFiles = cacheDir.listFiles();
if (cachedFiles != null) {
for (File cachedFile : cachedFiles) {
size += calculateSize(cachedFile);
count += 1;
lastUsageDates.put(cachedFile,
cachedFile.lastModified());
}
cacheSize.set(size);
cacheCount.set(count);
}
}catch (Exception e){
e.printStackTrace();
}
}
}).start();
}
private void put(File file) {
try{
int curCacheCount = cacheCount.get();
while (curCacheCount + 1 > countLimit) {
long freedSize = removeNext();
cacheSize.addAndGet(-freedSize);
curCacheCount = cacheCount.addAndGet(-1);
}
cacheCount.addAndGet(1);
long valueSize = calculateSize(file);
long curCacheSize = cacheSize.get();
while (curCacheSize + valueSize > sizeLimit) {
long freedSize = removeNext();
curCacheSize = cacheSize.addAndGet(-freedSize);
}
cacheSize.addAndGet(valueSize);
Long currentTime = System.currentTimeMillis();
file.setLastModified(currentTime);
lastUsageDates.put(file, currentTime);
}catch (Exception e){
e.printStackTrace();
}
}
private File get(String key) {
File file = newFile(key);
Long currentTime = System.currentTimeMillis();
file.setLastModified(currentTime);
lastUsageDates.put(file, currentTime);
return file;
}
private File newFile(String key) {
return new File(cacheDir, key.hashCode() + "");
}
private boolean remove(String key) {
File image = get(key);
return image.delete();
}
private void clear() {
try{
lastUsageDates.clear();
cacheSize.set(0);
File[] files = cacheDir.listFiles();
if (files != null) {
for (File f : files) {
f.delete();
}
}
}catch (Exception e){
e.printStackTrace();
}
}
/**
*
*
* @return
*/
private long removeNext() {
try{
if (lastUsageDates.isEmpty()) {
return 0;
}
Long oldestUsage = null;
File mostLongUsedFile = null;
Set<Entry<File, Long>> entries = lastUsageDates.entrySet();
synchronized (lastUsageDates) {
for (Entry<File, Long> entry : entries) {
if (mostLongUsedFile == null) {
mostLongUsedFile = entry.getKey();
oldestUsage = entry.getValue();
} else {
Long lastValueUsage = entry.getValue();
if (lastValueUsage < oldestUsage) {
oldestUsage = lastValueUsage;
mostLongUsedFile = entry.getKey();
}
}
}
}
long fileSize = calculateSize(mostLongUsedFile);
if (mostLongUsedFile.delete()) {
lastUsageDates.remove(mostLongUsedFile);
}
return fileSize;
}catch (Exception e){
e.printStackTrace();
return 0;
}
}
private long calculateSize(File file) {
return file.length();
}
}
/**
* @title
* @author michael www.yangfuhai.com
* @version 1.0
*/
private static class Utils {
/**
* String
*
* @param str
* @return true false
*/
private static boolean isDue(String str) {
return isDue(str.getBytes());
}
/**
* byte
*
* @param data
* @return true false
*/
private static boolean isDue(byte[] data) {
try{
String[] strs = getDateInfoFromDate(data);
if (strs != null && strs.length == 2) {
String saveTimeStr = strs[0];
while (saveTimeStr.startsWith("0")) {
saveTimeStr = saveTimeStr
.substring(1, saveTimeStr.length());
}
long saveTime = Long.valueOf(saveTimeStr);
long deleteAfter = Long.valueOf(strs[1]);
if (System.currentTimeMillis() > saveTime + deleteAfter * 1000) {
return true;
}
}
}catch (Exception e){
e.printStackTrace();
}
return false;
}
private static String newStringWithDateInfo(int second, String strInfo) {
return createDateInfo(second) + strInfo;
}
private static byte[] newByteArrayWithDateInfo(int second, byte[] data2) {
byte[] data1 = createDateInfo(second).getBytes();
byte[] retdata = new byte[data1.length + data2.length];
System.arraycopy(data1, 0, retdata, 0, data1.length);
System.arraycopy(data2, 0, retdata, data1.length, data2.length);
return retdata;
}
private static String clearDateInfo(String strInfo) {
if (strInfo != null && hasDateInfo(strInfo.getBytes())) {
strInfo = strInfo.substring(strInfo.indexOf(mSeparator) + 1,
strInfo.length());
}
return strInfo;
}
private static byte[] clearDateInfo(byte[] data) {
if (hasDateInfo(data)) {
return copyOfRange(data, indexOf(data, mSeparator) + 1,
data.length);
}
return data;
}
private static boolean hasDateInfo(byte[] data) {
return data != null && data.length > 15 && data[13] == '-'
&& indexOf(data, mSeparator) > 14;
}
private static String[] getDateInfoFromDate(byte[] data) {
if (hasDateInfo(data)) {
String saveDate = new String(copyOfRange(data, 0, 13));
String deleteAfter = new String(copyOfRange(data, 14,
indexOf(data, mSeparator)));
return new String[] { saveDate, deleteAfter };
}
return null;
}
private static int indexOf(byte[] data, char c) {
for (int i = 0; i < data.length; i++) {
if (data[i] == c) {
return i;
}
}
return -1;
}
private static byte[] copyOfRange(byte[] original, int from, int to) {
int newLength = to - from;
if (newLength < 0)
throw new IllegalArgumentException(from + " > " + to);
byte[] copy = new byte[newLength];
System.arraycopy(original, from, copy, 0,
Math.min(original.length - from, newLength));
return copy;
}
private static final char mSeparator = ' ';
private static String createDateInfo(int second) {
String currentTime = System.currentTimeMillis() + "";
while (currentTime.length() < 13) {
currentTime = "0" + currentTime;
}
return currentTime + "-" + second + mSeparator;
}
/*
* Bitmap byte[]
*/
private static byte[] Bitmap2Bytes(Bitmap bm) {
if (bm == null) {
return null;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}
/*
* byte[] Bitmap
*/
private static Bitmap Bytes2Bimap(byte[] b) {
if (b.length == 0) {
return null;
}
return BitmapFactory.decodeByteArray(b, 0, b.length);
}
/*
* Drawable Bitmap
*/
private static Bitmap drawable2Bitmap(Drawable drawable) {
if (drawable == null) {
return null;
}
// 取 drawable 的长宽
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
// 取 drawable 的颜色格式
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565;
// 建立对应 bitmap
Bitmap bitmap = Bitmap.createBitmap(w, h, config);
// 建立对应 bitmap 的画布
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
// 把 drawable 内容画到画布中
drawable.draw(canvas);
return bitmap;
}
/*
* Bitmap Drawable
*/
@SuppressWarnings("deprecation")
private static Drawable bitmap2Drawable(Bitmap bm) {
if (bm == null) {
return null;
}
return new BitmapDrawable(bm);
}
}
}

@ -0,0 +1,25 @@
package com.monke.monkeybook.common;
public class RxBusTag {
public final static String HAD_ADD_BOOK = "rxbus_add_book";
public final static String HAD_REMOVE_BOOK = "rxbus_remove_book";
public final static String UPDATE_BOOK_PROGRESS = "rxbus_update_book_progress";
public final static String PAUSE_DOWNLOAD_LISTENER = "rxbus_pause_download_listener";
public final static String PROGRESS_DOWNLOAD_LISTENER = "rxbus_progress_download_listener";
public final static String FINISH_DOWNLOAD_LISTENER = "rxbus_finish_download_listener";
public final static String PAUSE_DOWNLOAD = "rxbus_pause_download";
public final static String START_DOWNLOAD = "rxbus_start_download";
public final static String CANCEL_DOWNLOAD = "rxbus_cancel_download";
public final static String ADD_DOWNLOAD_TASK = "rxbus_add_download_task";
}

@ -0,0 +1,44 @@
package com.monke.monkeybook.common.api;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.Url;
public interface IEasouApi {
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Keep-Alive:300",
"Connection:Keep-Alive",
"Cache-Control:no-cache"})
Observable<String> getBookInfo(@Url String url);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Keep-Alive:300",
"Connection:Keep-Alive",
"Cache-Control:no-cache"})
Observable<String> searchBook(@Url String url);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Keep-Alive:300",
"Connection:Keep-Alive",
"Cache-Control:no-cache"})
Observable<String> getBookContent(@Url String url);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Keep-Alive:300",
"Connection:Keep-Alive",
"Cache-Control:no-cache"})
Observable<String> getChapterList(@Url String url);
}

@ -0,0 +1,66 @@
package com.monke.monkeybook.common.api;
import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.Query;
import retrofit2.http.Url;
public interface IGxwztvApi {
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Keep-Alive:300",
"Connection:Keep-Alive",
"Cache-Control:no-cache"})
Observable<String> getBookInfo(@Url String url);
@GET("/search.htm")
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Keep-Alive:300",
"Connection:Keep-Alive",
"Cache-Control:no-cache"})
Observable<String> searchBook(@Query("keyword")String content, @Query("pn")int page);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Keep-Alive:300",
"Connection:Keep-Alive",
"Cache-Control:no-cache"})
Observable<String> getBookContent(@Url String url);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Keep-Alive:300",
"Connection:Keep-Alive",
"Cache-Control:no-cache"})
Observable<String> getChapterList(@Url String url);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Keep-Alive:300",
"Connection:Keep-Alive",
"Cache-Control:no-cache"})
Observable<String> getKindBooks(@Url String url);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Keep-Alive:300",
"Connection:Keep-Alive",
"Cache-Control:no-cache"})
Observable<String> getLibraryData(@Url String url);
}

@ -0,0 +1,46 @@
package com.monke.monkeybook.common.api;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.Query;
import retrofit2.http.Url;
public interface ILingdiankanshuApi {
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Keep-Alive:300",
"Connection:Keep-Alive",
"Cache-Control:no-cache"})
Observable<String> getBookInfo(@Url String url);
@GET("/cse/search")
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Keep-Alive:300",
"Connection:Keep-Alive",
"Cache-Control:no-cache"})
Observable<String> searchBook(@Query("q") String content, @Query("p") int page, @Query("s") String time);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Keep-Alive:300",
"Connection:Keep-Alive",
"Cache-Control:no-cache"})
Observable<String> getBookContent(@Url String url);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Keep-Alive:300",
"Connection:Keep-Alive",
"Cache-Control:no-cache"})
Observable<String> getChapterList(@Url String url);
}

@ -0,0 +1,143 @@
package com.monke.monkeybook.dao;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import com.monke.monkeybook.bean.BookContentBean;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table "BOOK_CONTENT_BEAN".
*/
public class BookContentBeanDao extends AbstractDao<BookContentBean, String> {
public static final String TABLENAME = "BOOK_CONTENT_BEAN";
/**
* Properties of entity BookContentBean.<br/>
* Can be used for QueryBuilder and for referencing column names.
*/
public static class Properties {
public final static Property DurChapterUrl = new Property(0, String.class, "durChapterUrl", true, "DUR_CHAPTER_URL");
public final static Property DurChapterIndex = new Property(1, int.class, "durChapterIndex", false, "DUR_CHAPTER_INDEX");
public final static Property DurCapterContent = new Property(2, String.class, "durCapterContent", false, "DUR_CAPTER_CONTENT");
public final static Property Tag = new Property(3, String.class, "tag", false, "TAG");
};
public BookContentBeanDao(DaoConfig config) {
super(config);
}
public BookContentBeanDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
}
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "\"BOOK_CONTENT_BEAN\" (" + //
"\"DUR_CHAPTER_URL\" TEXT PRIMARY KEY NOT NULL ," + // 0: durChapterUrl
"\"DUR_CHAPTER_INDEX\" INTEGER NOT NULL ," + // 1: durChapterIndex
"\"DUR_CAPTER_CONTENT\" TEXT," + // 2: durCapterContent
"\"TAG\" TEXT);"); // 3: tag
}
/** Drops the underlying database table. */
public static void dropTable(Database db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK_CONTENT_BEAN\"";
db.execSQL(sql);
}
@Override
protected final void bindValues(DatabaseStatement stmt, BookContentBean entity) {
stmt.clearBindings();
String durChapterUrl = entity.getDurChapterUrl();
if (durChapterUrl != null) {
stmt.bindString(1, durChapterUrl);
}
stmt.bindLong(2, entity.getDurChapterIndex());
String durCapterContent = entity.getDurCapterContent();
if (durCapterContent != null) {
stmt.bindString(3, durCapterContent);
}
String tag = entity.getTag();
if (tag != null) {
stmt.bindString(4, tag);
}
}
@Override
protected final void bindValues(SQLiteStatement stmt, BookContentBean entity) {
stmt.clearBindings();
String durChapterUrl = entity.getDurChapterUrl();
if (durChapterUrl != null) {
stmt.bindString(1, durChapterUrl);
}
stmt.bindLong(2, entity.getDurChapterIndex());
String durCapterContent = entity.getDurCapterContent();
if (durCapterContent != null) {
stmt.bindString(3, durCapterContent);
}
String tag = entity.getTag();
if (tag != null) {
stmt.bindString(4, tag);
}
}
@Override
public String readKey(Cursor cursor, int offset) {
return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
}
@Override
public BookContentBean readEntity(Cursor cursor, int offset) {
BookContentBean entity = new BookContentBean( //
cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // durChapterUrl
cursor.getInt(offset + 1), // durChapterIndex
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // durCapterContent
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // tag
);
return entity;
}
@Override
public void readEntity(Cursor cursor, BookContentBean entity, int offset) {
entity.setDurChapterUrl(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
entity.setDurChapterIndex(cursor.getInt(offset + 1));
entity.setDurCapterContent(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
entity.setTag(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
}
@Override
protected final String updateKeyAfterInsert(BookContentBean entity, long rowId) {
return entity.getDurChapterUrl();
}
@Override
public String getKey(BookContentBean entity) {
if(entity != null) {
return entity.getDurChapterUrl();
} else {
return null;
}
}
@Override
protected final boolean isEntityUpdateable() {
return true;
}
}

@ -0,0 +1,213 @@
package com.monke.monkeybook.dao;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import com.monke.monkeybook.bean.BookInfoBean;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table "BOOK_INFO_BEAN".
*/
public class BookInfoBeanDao extends AbstractDao<BookInfoBean, String> {
public static final String TABLENAME = "BOOK_INFO_BEAN";
/**
* Properties of entity BookInfoBean.<br/>
* Can be used for QueryBuilder and for referencing column names.
*/
public static class Properties {
public final static Property Name = new Property(0, String.class, "name", false, "NAME");
public final static Property Tag = new Property(1, String.class, "tag", false, "TAG");
public final static Property NoteUrl = new Property(2, String.class, "noteUrl", true, "NOTE_URL");
public final static Property ChapterUrl = new Property(3, String.class, "chapterUrl", false, "CHAPTER_URL");
public final static Property FinalRefreshData = new Property(4, long.class, "finalRefreshData", false, "FINAL_REFRESH_DATA");
public final static Property CoverUrl = new Property(5, String.class, "coverUrl", false, "COVER_URL");
public final static Property Author = new Property(6, String.class, "author", false, "AUTHOR");
public final static Property Introduce = new Property(7, String.class, "introduce", false, "INTRODUCE");
public final static Property Origin = new Property(8, String.class, "origin", false, "ORIGIN");
};
public BookInfoBeanDao(DaoConfig config) {
super(config);
}
public BookInfoBeanDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
}
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "\"BOOK_INFO_BEAN\" (" + //
"\"NAME\" TEXT," + // 0: name
"\"TAG\" TEXT," + // 1: tag
"\"NOTE_URL\" TEXT PRIMARY KEY NOT NULL ," + // 2: noteUrl
"\"CHAPTER_URL\" TEXT," + // 3: chapterUrl
"\"FINAL_REFRESH_DATA\" INTEGER NOT NULL ," + // 4: finalRefreshData
"\"COVER_URL\" TEXT," + // 5: coverUrl
"\"AUTHOR\" TEXT," + // 6: author
"\"INTRODUCE\" TEXT," + // 7: introduce
"\"ORIGIN\" TEXT);"); // 8: origin
}
/** Drops the underlying database table. */
public static void dropTable(Database db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK_INFO_BEAN\"";
db.execSQL(sql);
}
@Override
protected final void bindValues(DatabaseStatement stmt, BookInfoBean entity) {
stmt.clearBindings();
String name = entity.getName();
if (name != null) {
stmt.bindString(1, name);
}
String tag = entity.getTag();
if (tag != null) {
stmt.bindString(2, tag);
}
String noteUrl = entity.getNoteUrl();
if (noteUrl != null) {
stmt.bindString(3, noteUrl);
}
String chapterUrl = entity.getChapterUrl();
if (chapterUrl != null) {
stmt.bindString(4, chapterUrl);
}
stmt.bindLong(5, entity.getFinalRefreshData());
String coverUrl = entity.getCoverUrl();
if (coverUrl != null) {
stmt.bindString(6, coverUrl);
}
String author = entity.getAuthor();
if (author != null) {
stmt.bindString(7, author);
}
String introduce = entity.getIntroduce();
if (introduce != null) {
stmt.bindString(8, introduce);
}
String origin = entity.getOrigin();
if (origin != null) {
stmt.bindString(9, origin);
}
}
@Override
protected final void bindValues(SQLiteStatement stmt, BookInfoBean entity) {
stmt.clearBindings();
String name = entity.getName();
if (name != null) {
stmt.bindString(1, name);
}
String tag = entity.getTag();
if (tag != null) {
stmt.bindString(2, tag);
}
String noteUrl = entity.getNoteUrl();
if (noteUrl != null) {
stmt.bindString(3, noteUrl);
}
String chapterUrl = entity.getChapterUrl();
if (chapterUrl != null) {
stmt.bindString(4, chapterUrl);
}
stmt.bindLong(5, entity.getFinalRefreshData());
String coverUrl = entity.getCoverUrl();
if (coverUrl != null) {
stmt.bindString(6, coverUrl);
}
String author = entity.getAuthor();
if (author != null) {
stmt.bindString(7, author);
}
String introduce = entity.getIntroduce();
if (introduce != null) {
stmt.bindString(8, introduce);
}
String origin = entity.getOrigin();
if (origin != null) {
stmt.bindString(9, origin);
}
}
@Override
public String readKey(Cursor cursor, int offset) {
return cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2);
}
@Override
public BookInfoBean readEntity(Cursor cursor, int offset) {
BookInfoBean entity = new BookInfoBean( //
cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // name
cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // tag
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // noteUrl
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // chapterUrl
cursor.getLong(offset + 4), // finalRefreshData
cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // coverUrl
cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // author
cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // introduce
cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // origin
);
return entity;
}
@Override
public void readEntity(Cursor cursor, BookInfoBean entity, int offset) {
entity.setName(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
entity.setTag(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
entity.setNoteUrl(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
entity.setChapterUrl(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
entity.setFinalRefreshData(cursor.getLong(offset + 4));
entity.setCoverUrl(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
entity.setAuthor(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
entity.setIntroduce(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
entity.setOrigin(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
}
@Override
protected final String updateKeyAfterInsert(BookInfoBean entity, long rowId) {
return entity.getNoteUrl();
}
@Override
public String getKey(BookInfoBean entity) {
if(entity != null) {
return entity.getNoteUrl();
} else {
return null;
}
}
@Override
protected final boolean isEntityUpdateable() {
return true;
}
}

@ -0,0 +1,141 @@
package com.monke.monkeybook.dao;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import com.monke.monkeybook.bean.BookShelfBean;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table "BOOK_SHELF_BEAN".
*/
public class BookShelfBeanDao extends AbstractDao<BookShelfBean, String> {
public static final String TABLENAME = "BOOK_SHELF_BEAN";
/**
* Properties of entity BookShelfBean.<br/>
* Can be used for QueryBuilder and for referencing column names.
*/
public static class Properties {
public final static Property NoteUrl = new Property(0, String.class, "noteUrl", true, "NOTE_URL");
public final static Property DurChapter = new Property(1, int.class, "durChapter", false, "DUR_CHAPTER");
public final static Property DurChapterPage = new Property(2, int.class, "durChapterPage", false, "DUR_CHAPTER_PAGE");
public final static Property FinalDate = new Property(3, long.class, "finalDate", false, "FINAL_DATE");
public final static Property Tag = new Property(4, String.class, "tag", false, "TAG");
};
public BookShelfBeanDao(DaoConfig config) {
super(config);
}
public BookShelfBeanDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
}
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "\"BOOK_SHELF_BEAN\" (" + //
"\"NOTE_URL\" TEXT PRIMARY KEY NOT NULL ," + // 0: noteUrl
"\"DUR_CHAPTER\" INTEGER NOT NULL ," + // 1: durChapter
"\"DUR_CHAPTER_PAGE\" INTEGER NOT NULL ," + // 2: durChapterPage
"\"FINAL_DATE\" INTEGER NOT NULL ," + // 3: finalDate
"\"TAG\" TEXT);"); // 4: tag
}
/** Drops the underlying database table. */
public static void dropTable(Database db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK_SHELF_BEAN\"";
db.execSQL(sql);
}
@Override
protected final void bindValues(DatabaseStatement stmt, BookShelfBean entity) {
stmt.clearBindings();
String noteUrl = entity.getNoteUrl();
if (noteUrl != null) {
stmt.bindString(1, noteUrl);
}
stmt.bindLong(2, entity.getDurChapter());
stmt.bindLong(3, entity.getDurChapterPage());
stmt.bindLong(4, entity.getFinalDate());
String tag = entity.getTag();
if (tag != null) {
stmt.bindString(5, tag);
}
}
@Override
protected final void bindValues(SQLiteStatement stmt, BookShelfBean entity) {
stmt.clearBindings();
String noteUrl = entity.getNoteUrl();
if (noteUrl != null) {
stmt.bindString(1, noteUrl);
}
stmt.bindLong(2, entity.getDurChapter());
stmt.bindLong(3, entity.getDurChapterPage());
stmt.bindLong(4, entity.getFinalDate());
String tag = entity.getTag();
if (tag != null) {
stmt.bindString(5, tag);
}
}
@Override
public String readKey(Cursor cursor, int offset) {
return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
}
@Override
public BookShelfBean readEntity(Cursor cursor, int offset) {
BookShelfBean entity = new BookShelfBean( //
cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // noteUrl
cursor.getInt(offset + 1), // durChapter
cursor.getInt(offset + 2), // durChapterPage
cursor.getLong(offset + 3), // finalDate
cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4) // tag
);
return entity;
}
@Override
public void readEntity(Cursor cursor, BookShelfBean entity, int offset) {
entity.setNoteUrl(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
entity.setDurChapter(cursor.getInt(offset + 1));
entity.setDurChapterPage(cursor.getInt(offset + 2));
entity.setFinalDate(cursor.getLong(offset + 3));
entity.setTag(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
}
@Override
protected final String updateKeyAfterInsert(BookShelfBean entity, long rowId) {
return entity.getNoteUrl();
}
@Override
public String getKey(BookShelfBean entity) {
if(entity != null) {
return entity.getNoteUrl();
} else {
return null;
}
}
@Override
protected final boolean isEntityUpdateable() {
return true;
}
}

@ -0,0 +1,171 @@
package com.monke.monkeybook.dao;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import com.monke.monkeybook.bean.ChapterListBean;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table "CHAPTER_LIST_BEAN".
*/
public class ChapterListBeanDao extends AbstractDao<ChapterListBean, String> {
public static final String TABLENAME = "CHAPTER_LIST_BEAN";
/**
* Properties of entity ChapterListBean.<br/>
* Can be used for QueryBuilder and for referencing column names.
*/
public static class Properties {
public final static Property NoteUrl = new Property(0, String.class, "noteUrl", false, "NOTE_URL");
public final static Property DurChapterIndex = new Property(1, int.class, "durChapterIndex", false, "DUR_CHAPTER_INDEX");
public final static Property DurChapterUrl = new Property(2, String.class, "durChapterUrl", true, "DUR_CHAPTER_URL");
public final static Property DurChapterName = new Property(3, String.class, "durChapterName", false, "DUR_CHAPTER_NAME");
public final static Property Tag = new Property(4, String.class, "tag", false, "TAG");
public final static Property HasCache = new Property(5, Boolean.class, "hasCache", false, "HAS_CACHE");
};
public ChapterListBeanDao(DaoConfig config) {
super(config);
}
public ChapterListBeanDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
}
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "\"CHAPTER_LIST_BEAN\" (" + //
"\"NOTE_URL\" TEXT," + // 0: noteUrl
"\"DUR_CHAPTER_INDEX\" INTEGER NOT NULL ," + // 1: durChapterIndex
"\"DUR_CHAPTER_URL\" TEXT PRIMARY KEY NOT NULL ," + // 2: durChapterUrl
"\"DUR_CHAPTER_NAME\" TEXT," + // 3: durChapterName
"\"TAG\" TEXT," + // 4: tag
"\"HAS_CACHE\" INTEGER);"); // 5: hasCache
}
/** Drops the underlying database table. */
public static void dropTable(Database db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"CHAPTER_LIST_BEAN\"";
db.execSQL(sql);
}
@Override
protected final void bindValues(DatabaseStatement stmt, ChapterListBean entity) {
stmt.clearBindings();
String noteUrl = entity.getNoteUrl();
if (noteUrl != null) {
stmt.bindString(1, noteUrl);
}
stmt.bindLong(2, entity.getDurChapterIndex());
String durChapterUrl = entity.getDurChapterUrl();
if (durChapterUrl != null) {
stmt.bindString(3, durChapterUrl);
}
String durChapterName = entity.getDurChapterName();
if (durChapterName != null) {
stmt.bindString(4, durChapterName);
}
String tag = entity.getTag();
if (tag != null) {
stmt.bindString(5, tag);
}
Boolean hasCache = entity.getHasCache();
if (hasCache != null) {
stmt.bindLong(6, hasCache ? 1L: 0L);
}
}
@Override
protected final void bindValues(SQLiteStatement stmt, ChapterListBean entity) {
stmt.clearBindings();
String noteUrl = entity.getNoteUrl();
if (noteUrl != null) {
stmt.bindString(1, noteUrl);
}
stmt.bindLong(2, entity.getDurChapterIndex());
String durChapterUrl = entity.getDurChapterUrl();
if (durChapterUrl != null) {
stmt.bindString(3, durChapterUrl);
}
String durChapterName = entity.getDurChapterName();
if (durChapterName != null) {
stmt.bindString(4, durChapterName);
}
String tag = entity.getTag();
if (tag != null) {
stmt.bindString(5, tag);
}
Boolean hasCache = entity.getHasCache();
if (hasCache != null) {
stmt.bindLong(6, hasCache ? 1L: 0L);
}
}
@Override
public String readKey(Cursor cursor, int offset) {
return cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2);
}
@Override
public ChapterListBean readEntity(Cursor cursor, int offset) {
ChapterListBean entity = new ChapterListBean( //
cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // noteUrl
cursor.getInt(offset + 1), // durChapterIndex
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // durChapterUrl
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // durChapterName
cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // tag
cursor.isNull(offset + 5) ? null : cursor.getShort(offset + 5) != 0 // hasCache
);
return entity;
}
@Override
public void readEntity(Cursor cursor, ChapterListBean entity, int offset) {
entity.setNoteUrl(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
entity.setDurChapterIndex(cursor.getInt(offset + 1));
entity.setDurChapterUrl(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
entity.setDurChapterName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
entity.setTag(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
entity.setHasCache(cursor.isNull(offset + 5) ? null : cursor.getShort(offset + 5) != 0);
}
@Override
protected final String updateKeyAfterInsert(ChapterListBean entity, long rowId) {
return entity.getDurChapterUrl();
}
@Override
public String getKey(ChapterListBean entity) {
if(entity != null) {
return entity.getDurChapterUrl();
} else {
return null;
}
}
@Override
protected final boolean isEntityUpdateable() {
return true;
}
}

@ -0,0 +1,111 @@
package com.monke.monkeybook.dao;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.util.Log;
import org.greenrobot.greendao.AbstractDaoMaster;
import org.greenrobot.greendao.database.StandardDatabase;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseOpenHelper;
import org.greenrobot.greendao.identityscope.IdentityScopeType;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* Master of DAO (schema version 1): knows all DAOs.
*/
public class DaoMaster extends AbstractDaoMaster {
public static final int SCHEMA_VERSION = 1;
/** Creates underlying database table using DAOs. */
public static void createAllTables(Database db, boolean ifNotExists) {
BookContentBeanDao.createTable(db, ifNotExists);
BookInfoBeanDao.createTable(db, ifNotExists);
BookShelfBeanDao.createTable(db, ifNotExists);
ChapterListBeanDao.createTable(db, ifNotExists);
DownloadChapterBeanDao.createTable(db, ifNotExists);
SearchHistoryBeanDao.createTable(db, ifNotExists);
}
/** Drops underlying database table using DAOs. */
public static void dropAllTables(Database db, boolean ifExists) {
BookContentBeanDao.dropTable(db, ifExists);
BookInfoBeanDao.dropTable(db, ifExists);
BookShelfBeanDao.dropTable(db, ifExists);
ChapterListBeanDao.dropTable(db, ifExists);
DownloadChapterBeanDao.dropTable(db, ifExists);
SearchHistoryBeanDao.dropTable(db, ifExists);
}
/**
* WARNING: Drops all table on Upgrade! Use only during development.
* Convenience method using a {@link DevOpenHelper}.
*/
public static DaoSession newDevSession(Context context, String name) {
Database db = new DevOpenHelper(context, name).getWritableDb();
DaoMaster daoMaster = new DaoMaster(db);
return daoMaster.newSession();
}
public DaoMaster(SQLiteDatabase db) {
this(new StandardDatabase(db));
}
public DaoMaster(Database db) {
super(db, SCHEMA_VERSION);
registerDaoClass(BookContentBeanDao.class);
registerDaoClass(BookInfoBeanDao.class);
registerDaoClass(BookShelfBeanDao.class);
registerDaoClass(ChapterListBeanDao.class);
registerDaoClass(DownloadChapterBeanDao.class);
registerDaoClass(SearchHistoryBeanDao.class);
}
public DaoSession newSession() {
return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
}
public DaoSession newSession(IdentityScopeType type) {
return new DaoSession(db, type, daoConfigMap);
}
/**
* Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} -
*/
public static abstract class OpenHelper extends DatabaseOpenHelper {
public OpenHelper(Context context, String name) {
super(context, name, SCHEMA_VERSION);
}
public OpenHelper(Context context, String name, CursorFactory factory) {
super(context, name, factory, SCHEMA_VERSION);
}
@Override
public void onCreate(Database db) {
Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
createAllTables(db, false);
}
}
/** WARNING: Drops all table on Upgrade! Use only during development. */
public static class DevOpenHelper extends OpenHelper {
public DevOpenHelper(Context context, String name) {
super(context, name);
}
public DevOpenHelper(Context context, String name, CursorFactory factory) {
super(context, name, factory);
}
@Override
public void onUpgrade(Database db, int oldVersion, int newVersion) {
Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
dropAllTables(db, true);
onCreate(db);
}
}
}

@ -0,0 +1,118 @@
package com.monke.monkeybook.dao;
import java.util.Map;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.AbstractDaoSession;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.identityscope.IdentityScopeType;
import org.greenrobot.greendao.internal.DaoConfig;
import com.monke.monkeybook.bean.BookContentBean;
import com.monke.monkeybook.bean.BookInfoBean;
import com.monke.monkeybook.bean.BookShelfBean;
import com.monke.monkeybook.bean.ChapterListBean;
import com.monke.monkeybook.bean.DownloadChapterBean;
import com.monke.monkeybook.bean.SearchHistoryBean;
import com.monke.monkeybook.dao.BookContentBeanDao;
import com.monke.monkeybook.dao.BookInfoBeanDao;
import com.monke.monkeybook.dao.BookShelfBeanDao;
import com.monke.monkeybook.dao.ChapterListBeanDao;
import com.monke.monkeybook.dao.DownloadChapterBeanDao;
import com.monke.monkeybook.dao.SearchHistoryBeanDao;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* {@inheritDoc}
*
* @see org.greenrobot.greendao.AbstractDaoSession
*/
public class DaoSession extends AbstractDaoSession {
private final DaoConfig bookContentBeanDaoConfig;
private final DaoConfig bookInfoBeanDaoConfig;
private final DaoConfig bookShelfBeanDaoConfig;
private final DaoConfig chapterListBeanDaoConfig;
private final DaoConfig downloadChapterBeanDaoConfig;
private final DaoConfig searchHistoryBeanDaoConfig;
private final BookContentBeanDao bookContentBeanDao;
private final BookInfoBeanDao bookInfoBeanDao;
private final BookShelfBeanDao bookShelfBeanDao;
private final ChapterListBeanDao chapterListBeanDao;
private final DownloadChapterBeanDao downloadChapterBeanDao;
private final SearchHistoryBeanDao searchHistoryBeanDao;
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
daoConfigMap) {
super(db);
bookContentBeanDaoConfig = daoConfigMap.get(BookContentBeanDao.class).clone();
bookContentBeanDaoConfig.initIdentityScope(type);
bookInfoBeanDaoConfig = daoConfigMap.get(BookInfoBeanDao.class).clone();
bookInfoBeanDaoConfig.initIdentityScope(type);
bookShelfBeanDaoConfig = daoConfigMap.get(BookShelfBeanDao.class).clone();
bookShelfBeanDaoConfig.initIdentityScope(type);
chapterListBeanDaoConfig = daoConfigMap.get(ChapterListBeanDao.class).clone();
chapterListBeanDaoConfig.initIdentityScope(type);
downloadChapterBeanDaoConfig = daoConfigMap.get(DownloadChapterBeanDao.class).clone();
downloadChapterBeanDaoConfig.initIdentityScope(type);
searchHistoryBeanDaoConfig = daoConfigMap.get(SearchHistoryBeanDao.class).clone();
searchHistoryBeanDaoConfig.initIdentityScope(type);
bookContentBeanDao = new BookContentBeanDao(bookContentBeanDaoConfig, this);
bookInfoBeanDao = new BookInfoBeanDao(bookInfoBeanDaoConfig, this);
bookShelfBeanDao = new BookShelfBeanDao(bookShelfBeanDaoConfig, this);
chapterListBeanDao = new ChapterListBeanDao(chapterListBeanDaoConfig, this);
downloadChapterBeanDao = new DownloadChapterBeanDao(downloadChapterBeanDaoConfig, this);
searchHistoryBeanDao = new SearchHistoryBeanDao(searchHistoryBeanDaoConfig, this);
registerDao(BookContentBean.class, bookContentBeanDao);
registerDao(BookInfoBean.class, bookInfoBeanDao);
registerDao(BookShelfBean.class, bookShelfBeanDao);
registerDao(ChapterListBean.class, chapterListBeanDao);
registerDao(DownloadChapterBean.class, downloadChapterBeanDao);
registerDao(SearchHistoryBean.class, searchHistoryBeanDao);
}
public void clear() {
bookContentBeanDaoConfig.getIdentityScope().clear();
bookInfoBeanDaoConfig.getIdentityScope().clear();
bookShelfBeanDaoConfig.getIdentityScope().clear();
chapterListBeanDaoConfig.getIdentityScope().clear();
downloadChapterBeanDaoConfig.getIdentityScope().clear();
searchHistoryBeanDaoConfig.getIdentityScope().clear();
}
public BookContentBeanDao getBookContentBeanDao() {
return bookContentBeanDao;
}
public BookInfoBeanDao getBookInfoBeanDao() {
return bookInfoBeanDao;
}
public BookShelfBeanDao getBookShelfBeanDao() {
return bookShelfBeanDao;
}
public ChapterListBeanDao getChapterListBeanDao() {
return chapterListBeanDao;
}
public DownloadChapterBeanDao getDownloadChapterBeanDao() {
return downloadChapterBeanDao;
}
public SearchHistoryBeanDao getSearchHistoryBeanDao() {
return searchHistoryBeanDao;
}
}

@ -0,0 +1,40 @@
package com.monke.monkeybook.dao;
import android.database.sqlite.SQLiteDatabase;
import com.monke.monkeybook.MApplication;
public class DbHelper {
private DaoMaster.DevOpenHelper mHelper;
private SQLiteDatabase db;
private DaoMaster mDaoMaster;
private DaoSession mDaoSession;
private DbHelper(){
mHelper = new DaoMaster.DevOpenHelper(MApplication.getInstance(), "monkebook_db", null);
db = mHelper.getWritableDatabase();
// 注意:该数据库连接属于 DaoMaster所以多个 Session 指的是相同的数据库连接。
mDaoMaster = new DaoMaster(db);
mDaoSession = mDaoMaster.newSession();
}
private static DbHelper instance;
public static DbHelper getInstance(){
if(null == instance){
synchronized (DbHelper.class){
if(null == instance){
instance = new DbHelper();
}
}
}
return instance;
}
public DaoSession getmDaoSession() {
return mDaoSession;
}
public SQLiteDatabase getDb() {
return db;
}
}

@ -0,0 +1,185 @@
package com.monke.monkeybook.dao;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import com.monke.monkeybook.bean.DownloadChapterBean;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table "DOWNLOAD_CHAPTER_BEAN".
*/
public class DownloadChapterBeanDao extends AbstractDao<DownloadChapterBean, String> {
public static final String TABLENAME = "DOWNLOAD_CHAPTER_BEAN";
/**
* Properties of entity DownloadChapterBean.<br/>
* Can be used for QueryBuilder and for referencing column names.
*/
public static class Properties {
public final static Property NoteUrl = new Property(0, String.class, "noteUrl", false, "NOTE_URL");
public final static Property DurChapterIndex = new Property(1, int.class, "durChapterIndex", false, "DUR_CHAPTER_INDEX");
public final static Property DurChapterUrl = new Property(2, String.class, "durChapterUrl", true, "DUR_CHAPTER_URL");
public final static Property DurChapterName = new Property(3, String.class, "durChapterName", false, "DUR_CHAPTER_NAME");
public final static Property Tag = new Property(4, String.class, "tag", false, "TAG");
public final static Property BookName = new Property(5, String.class, "bookName", false, "BOOK_NAME");
public final static Property CoverUrl = new Property(6, String.class, "coverUrl", false, "COVER_URL");
};
public DownloadChapterBeanDao(DaoConfig config) {
super(config);
}
public DownloadChapterBeanDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
}
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "\"DOWNLOAD_CHAPTER_BEAN\" (" + //
"\"NOTE_URL\" TEXT," + // 0: noteUrl
"\"DUR_CHAPTER_INDEX\" INTEGER NOT NULL ," + // 1: durChapterIndex
"\"DUR_CHAPTER_URL\" TEXT PRIMARY KEY NOT NULL ," + // 2: durChapterUrl
"\"DUR_CHAPTER_NAME\" TEXT," + // 3: durChapterName
"\"TAG\" TEXT," + // 4: tag
"\"BOOK_NAME\" TEXT," + // 5: bookName
"\"COVER_URL\" TEXT);"); // 6: coverUrl
}
/** Drops the underlying database table. */
public static void dropTable(Database db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"DOWNLOAD_CHAPTER_BEAN\"";
db.execSQL(sql);
}
@Override
protected final void bindValues(DatabaseStatement stmt, DownloadChapterBean entity) {
stmt.clearBindings();
String noteUrl = entity.getNoteUrl();
if (noteUrl != null) {
stmt.bindString(1, noteUrl);
}
stmt.bindLong(2, entity.getDurChapterIndex());
String durChapterUrl = entity.getDurChapterUrl();
if (durChapterUrl != null) {
stmt.bindString(3, durChapterUrl);
}
String durChapterName = entity.getDurChapterName();
if (durChapterName != null) {
stmt.bindString(4, durChapterName);
}
String tag = entity.getTag();
if (tag != null) {
stmt.bindString(5, tag);
}
String bookName = entity.getBookName();
if (bookName != null) {
stmt.bindString(6, bookName);
}
String coverUrl = entity.getCoverUrl();
if (coverUrl != null) {
stmt.bindString(7, coverUrl);
}
}
@Override
protected final void bindValues(SQLiteStatement stmt, DownloadChapterBean entity) {
stmt.clearBindings();
String noteUrl = entity.getNoteUrl();
if (noteUrl != null) {
stmt.bindString(1, noteUrl);
}
stmt.bindLong(2, entity.getDurChapterIndex());
String durChapterUrl = entity.getDurChapterUrl();
if (durChapterUrl != null) {
stmt.bindString(3, durChapterUrl);
}
String durChapterName = entity.getDurChapterName();
if (durChapterName != null) {
stmt.bindString(4, durChapterName);
}
String tag = entity.getTag();
if (tag != null) {
stmt.bindString(5, tag);
}
String bookName = entity.getBookName();
if (bookName != null) {
stmt.bindString(6, bookName);
}
String coverUrl = entity.getCoverUrl();
if (coverUrl != null) {
stmt.bindString(7, coverUrl);
}
}
@Override
public String readKey(Cursor cursor, int offset) {
return cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2);
}
@Override
public DownloadChapterBean readEntity(Cursor cursor, int offset) {
DownloadChapterBean entity = new DownloadChapterBean( //
cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // noteUrl
cursor.getInt(offset + 1), // durChapterIndex
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // durChapterUrl
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // durChapterName
cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // tag
cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // bookName
cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6) // coverUrl
);
return entity;
}
@Override
public void readEntity(Cursor cursor, DownloadChapterBean entity, int offset) {
entity.setNoteUrl(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
entity.setDurChapterIndex(cursor.getInt(offset + 1));
entity.setDurChapterUrl(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
entity.setDurChapterName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
entity.setTag(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
entity.setBookName(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
entity.setCoverUrl(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
}
@Override
protected final String updateKeyAfterInsert(DownloadChapterBean entity, long rowId) {
return entity.getDurChapterUrl();
}
@Override
public String getKey(DownloadChapterBean entity) {
if(entity != null) {
return entity.getDurChapterUrl();
} else {
return null;
}
}
@Override
protected final boolean isEntityUpdateable() {
return true;
}
}

@ -0,0 +1,136 @@
package com.monke.monkeybook.dao;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import com.monke.monkeybook.bean.SearchHistoryBean;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table "SEARCH_HISTORY_BEAN".
*/
public class SearchHistoryBeanDao extends AbstractDao<SearchHistoryBean, Long> {
public static final String TABLENAME = "SEARCH_HISTORY_BEAN";
/**
* Properties of entity SearchHistoryBean.<br/>
* Can be used for QueryBuilder and for referencing column names.
*/
public static class Properties {
public final static Property Id = new Property(0, Long.class, "id", true, "_id");
public final static Property Type = new Property(1, int.class, "type", false, "TYPE");
public final static Property Content = new Property(2, String.class, "content", false, "CONTENT");
public final static Property Date = new Property(3, long.class, "date", false, "DATE");
};
public SearchHistoryBeanDao(DaoConfig config) {
super(config);
}
public SearchHistoryBeanDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
}
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "\"SEARCH_HISTORY_BEAN\" (" + //
"\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
"\"TYPE\" INTEGER NOT NULL ," + // 1: type
"\"CONTENT\" TEXT," + // 2: content
"\"DATE\" INTEGER NOT NULL );"); // 3: date
}
/** Drops the underlying database table. */
public static void dropTable(Database db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SEARCH_HISTORY_BEAN\"";
db.execSQL(sql);
}
@Override
protected final void bindValues(DatabaseStatement stmt, SearchHistoryBean entity) {
stmt.clearBindings();
Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
stmt.bindLong(2, entity.getType());
String content = entity.getContent();
if (content != null) {
stmt.bindString(3, content);
}
stmt.bindLong(4, entity.getDate());
}
@Override
protected final void bindValues(SQLiteStatement stmt, SearchHistoryBean entity) {
stmt.clearBindings();
Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
stmt.bindLong(2, entity.getType());
String content = entity.getContent();
if (content != null) {
stmt.bindString(3, content);
}
stmt.bindLong(4, entity.getDate());
}
@Override
public Long readKey(Cursor cursor, int offset) {
return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
@Override
public SearchHistoryBean readEntity(Cursor cursor, int offset) {
SearchHistoryBean entity = new SearchHistoryBean( //
cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
cursor.getInt(offset + 1), // type
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // content
cursor.getLong(offset + 3) // date
);
return entity;
}
@Override
public void readEntity(Cursor cursor, SearchHistoryBean entity, int offset) {
entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
entity.setType(cursor.getInt(offset + 1));
entity.setContent(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
entity.setDate(cursor.getLong(offset + 3));
}
@Override
protected final Long updateKeyAfterInsert(SearchHistoryBean entity, long rowId) {
entity.setId(rowId);
return rowId;
}
@Override
public Long getKey(SearchHistoryBean entity) {
if(entity != null) {
return entity.getId();
} else {
return null;
}
}
@Override
protected final boolean isEntityUpdateable() {
return true;
}
}

@ -0,0 +1,8 @@
package com.monke.monkeybook.listener;
import com.monke.monkeybook.bean.BookShelfBean;
public interface OnGetChapterListListener {
public void success(BookShelfBean bookShelfBean);
public void error();
}

@ -0,0 +1,34 @@
package com.monke.monkeybook.model;
import com.monke.monkeybook.bean.BookContentBean;
import com.monke.monkeybook.bean.BookShelfBean;
import com.monke.monkeybook.bean.LibraryBean;
import com.monke.monkeybook.bean.SearchBookBean;
import com.monke.monkeybook.cache.ACache;
import com.monke.monkeybook.listener.OnGetChapterListListener;
import java.util.List;
import io.reactivex.Observable;
public interface IEasouBookModel {
/**
*
*/
public Observable<List<SearchBookBean>> searchBook(String content, int page, int rankKind);
/**
*
*/
public Observable<BookShelfBean> getBookInfo(final BookShelfBean bookShelfBean);
/**
*
*/
public void getChapterList(final BookShelfBean bookShelfBean, OnGetChapterListListener getChapterListListener);
/**
*
*/
Observable<BookContentBean> getBookContent(final String durChapterUrl, final int durChapterIndex);
}

@ -0,0 +1,24 @@
package com.monke.monkeybook.model;
import com.monke.monkeybook.bean.LibraryBean;
import com.monke.monkeybook.bean.SearchBookBean;
import com.monke.monkeybook.cache.ACache;
import java.util.List;
import io.reactivex.Observable;
public interface IGxwztvBookModel extends IStationBookModel {
public Observable<List<SearchBookBean>> getKindBook(String url, int page);
/**
*
*/
public Observable<LibraryBean> getLibraryData(ACache aCache);
/**
*
*/
public Observable<LibraryBean> analyLibraryData(String data);
}

@ -0,0 +1,14 @@
package com.monke.monkeybook.model;
import com.monke.monkeybook.bean.BookShelfBean;
import com.monke.monkeybook.bean.LocBookShelfBean;
import java.io.File;
import java.util.List;
import io.reactivex.Observable;
public interface IImportBookModel {
Observable<LocBookShelfBean> importBook(File book);
}

@ -0,0 +1,33 @@
package com.monke.monkeybook.model;
import com.monke.monkeybook.bean.BookContentBean;
import com.monke.monkeybook.bean.BookShelfBean;
import com.monke.monkeybook.bean.SearchBookBean;
import com.monke.monkeybook.listener.OnGetChapterListListener;
import java.util.List;
import io.reactivex.Observable;
public interface IStationBookModel {
/**
*
*/
public Observable<List<SearchBookBean>> searchBook(String content, int page);
/**
*
*/
public Observable<BookShelfBean> getBookInfo(final BookShelfBean bookShelfBean);
/**
*
*/
public void getChapterList(final BookShelfBean bookShelfBean, OnGetChapterListListener getChapterListListener);
/**
*
*/
Observable<BookContentBean> getBookContent(final String durChapterUrl, final int durChapterIndex);
}

@ -0,0 +1,39 @@
package com.monke.monkeybook.model;
import com.monke.monkeybook.bean.BookContentBean;
import com.monke.monkeybook.bean.BookShelfBean;
import com.monke.monkeybook.bean.SearchBookBean;
import com.monke.monkeybook.listener.OnGetChapterListListener;
import java.util.List;
import io.reactivex.Observable;
public interface IWebBookModel {
/**
*
*/
public Observable<BookShelfBean> getBookInfo(final BookShelfBean bookShelfBean);
/**
*
*/
public void getChapterList(final BookShelfBean bookShelfBean,OnGetChapterListListener getChapterListListener);
/**
*
*/
public Observable<BookContentBean> getBookContent(final String durChapterUrl, final int durChapterIndex, String tag);
/**
*
*/
public Observable<List<SearchBookBean>> searchBook(String content, int page,int rankKind);
/**
*
*/
public Observable<List<SearchBookBean>> getKindBook(String url,int page);
/**
*
*/
public Observable<List<SearchBookBean>> searchOtherBook(String content,int page,String tag);
}

@ -0,0 +1,6 @@
package com.monke.monkeybook.model;
public interface IWebContentModel {
public String analyBookcontent(String s,String realUrl) throws Exception;
}

@ -0,0 +1,36 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class Content17duxsModelImpl implements IWebContentModel{
public static final String TAG = "http://www.17duxs.com";
public static Content17duxsModelImpl getInstance() {
return new Content17duxsModelImpl();
}
private Content17duxsModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,39 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class Content17kModelImpl implements IWebContentModel {
public static final String TAG = "http://www.17k.com";
public static Content17kModelImpl getInstance() {
return new Content17kModelImpl();
}
private Content17kModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
Element all = doc.getElementById("chapterContentWapper");
List<TextNode> contentEs = all.getAllElements().get(0).textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,36 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class Content3dllcModelImpl implements IWebContentModel{
public static final String TAG = "http://www.3dllc.cc";
public static Content3dllcModelImpl getInstance() {
return new Content3dllcModelImpl();
}
private Content3dllcModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,36 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class Content44pqModelImpl implements IWebContentModel{
public static final String TAG = "http://www.44pq.net";
public static Content44pqModelImpl getInstance() {
return new Content44pqModelImpl();
}
private Content44pqModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,38 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class Content630bookCCModelImpl implements IWebContentModel{
public static final String TAG = "http://www.630book.cc";
public static Content630bookCCModelImpl getInstance() {
return new Content630bookCCModelImpl();
}
private Content630bookCCModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,36 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class Content92zwModelImpl implements IWebContentModel{
public static final String TAG = "http://www.92zw.la";
public static Content92zwModelImpl getInstance() {
return new Content92zwModelImpl();
}
private Content92zwModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("contents").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,38 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentAszwModelImpl implements IWebContentModel{
public static final String TAG = "http://www.aszw.org";
public static ContentAszwModelImpl getInstance() {
return new ContentAszwModelImpl();
}
private ContentAszwModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("contents").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,38 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentBaishukuModelImpl implements IWebContentModel{
public static final String TAG = "http://baishuku.com";
public static ContentBaishukuModelImpl getInstance() {
return new ContentBaishukuModelImpl();
}
private ContentBaishukuModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,36 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentBxwx9ModelImpl implements IWebContentModel{
public static final String TAG = "http://www.bxwx9.org";
public static ContentBxwx9ModelImpl getInstance() {
return new ContentBxwx9ModelImpl();
}
private ContentBxwx9ModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,45 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.ErrorAnalyContentManager;
import com.monke.monkeybook.bean.BookContentBean;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentCommendModelImpl {
public static ContentCommendModelImpl getInstance() {
return new ContentCommendModelImpl();
}
private ContentCommendModelImpl() {
}
public BookContentBean analyBookcontent(BookContentBean bookContentBean, String s, String realUrl) throws Exception {
ErrorAnalyContentManager.getInstance().writeNewErrorUrl(realUrl);
try{
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
bookContentBean.setDurCapterContent(content.toString());
}catch (Exception e){
e.printStackTrace();
bookContentBean.setDurCapterContent(realUrl.substring(0, realUrl.indexOf('/', 8)) + "站点暂时不支持解析请反馈给Monke QQ:1105075896,半小时内解决,超级效率的程序员");
bookContentBean.setRight(false);
}
return bookContentBean;
}
}

@ -0,0 +1,38 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentDhzwModelImpl implements IWebContentModel{
public static final String TAG = "http://www.dhzw.org";
public static ContentDhzwModelImpl getInstance() {
return new ContentDhzwModelImpl();
}
private ContentDhzwModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("BookText").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + contentEs.get(i).text().trim().replaceAll(" ",""));
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,38 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentEasouModelImpl implements IWebContentModel {
public static final String TAG = "http://book.easou.com";
public static ContentEasouModelImpl getInstance(){
return new ContentEasouModelImpl();
}
private ContentEasouModelImpl(){
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception{
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementsByClass("show").get(0).textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,42 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
/**
*
*/
public class ContentFuheishuModelImpl implements IWebContentModel{
public static final String TAG = "http://fuheishu.com";
public static ContentFuheishuModelImpl getInstance(){
return new ContentFuheishuModelImpl();
}
private ContentFuheishuModelImpl(){
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception{
Document doc = Jsoup.parse(s);
String bookId = realUrl.substring(realUrl.indexOf("/",21)+1,realUrl.indexOf(".html"));
List<TextNode> contentTNs = doc.getElementById("content"+bookId).textNodes();
StringBuilder stringBuilder = new StringBuilder();
for(int i=0;i<contentTNs.size();i++){
String temp = contentTNs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
stringBuilder.append("\u3000\u3000" + temp);
if (i < contentTNs.size() - 1) {
stringBuilder.append("\r\n");
}
}
}
return stringBuilder.toString();
}
}

@ -0,0 +1,38 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentKewaishuModelImpl implements IWebContentModel{
public static final String TAG = "http://www.kewaishu.org";
public static ContentKewaishuModelImpl getInstance() {
return new ContentKewaishuModelImpl();
}
private ContentKewaishuModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").getElementsByTag("p").get(0).textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,36 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentLeduwoModelImpl implements IWebContentModel{
public static final String TAG = "http://leduwo.com";
public static ContentLeduwoModelImpl getInstance() {
return new ContentLeduwoModelImpl();
}
private ContentLeduwoModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,36 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentLewen8ModelImpl implements IWebContentModel{
public static final String TAG = "http://www.lewen8.com";
public static ContentLewen8ModelImpl getInstance() {
return new ContentLewen8ModelImpl();
}
private ContentLewen8ModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,37 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentPbtxtModelImpl implements IWebContentModel{
public static final String TAG = "http://www.pbtxt.com";
public static ContentPbtxtModelImpl getInstance(){
return new ContentPbtxtModelImpl();
}
private ContentPbtxtModelImpl(){
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception{
Document doc = Jsoup.parse(s);
String bookId = realUrl.substring(realUrl.indexOf("/",21)+1,realUrl.indexOf(".html"));
List<TextNode> contentTNs = doc.getElementById("content"+bookId).textNodes();
StringBuilder stringBuilder = new StringBuilder();
for(int i=0;i<contentTNs.size();i++){
String temp = contentTNs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
stringBuilder.append("\u3000\u3000" + temp);
if (i < contentTNs.size() - 1) {
stringBuilder.append("\r\n");
}
}
}
return stringBuilder.toString();
}
}

@ -0,0 +1,38 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentPpxsModelImpl implements IWebContentModel{
public static final String TAG = "http://www.ppxs.net";
public static ContentPpxsModelImpl getInstance() {
return new ContentPpxsModelImpl();
}
private ContentPpxsModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("booktext").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,38 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentQulaModelImpl implements IWebContentModel{
public static final String TAG = "http://www.qu.la";
public static ContentQulaModelImpl getInstance() {
return new ContentQulaModelImpl();
}
private ContentQulaModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,38 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentQzreadModelImpl implements IWebContentModel{
public static final String TAG = "http://www.qzread.com";
public static ContentQzreadModelImpl getInstance() {
return new ContentQzreadModelImpl();
}
private ContentQzreadModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementsByClass("txt").get(0).getElementsByTag("p").get(0).textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,38 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentRanwenaModelImpl implements IWebContentModel{
public static final String TAG = "http://www.ranwena.com";
public static ContentRanwenaModelImpl getInstance() {
return new ContentRanwenaModelImpl();
}
private ContentRanwenaModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,27 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
public class ContentShulouModelImpl implements IWebContentModel{
public static final String TAG = "http://www.shulou.cc";
public static ContentShulouModelImpl getInstance(){
return new ContentShulouModelImpl();
}
private ContentShulouModelImpl(){
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception{
Document doc = Jsoup.parse(s);
Element contentE = doc.getElementById("content");
String contentString = contentE.toString();
contentString = contentString.replaceAll(" ", "").replaceAll("\n", "").replaceAll("&nbsp;", "").replaceAll("<divid=\"content\">", "").replaceAll("</div>", "").replaceAll("<p></p>","").replaceAll("<br><br>", "\r\n\u3000\u3000");
contentString = "\u3000\u3000" + contentString;
return contentString;
}
}

@ -0,0 +1,36 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentSnwx8ModelImpl implements IWebContentModel{
public static final String TAG = "http://www.snwx8.com";
public static ContentSnwx8ModelImpl getInstance() {
return new ContentSnwx8ModelImpl();
}
private ContentSnwx8ModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("BookText").textNodes();
StringBuilder content = new StringBuilder();
for(int i=0;i<contentEs.size();i++){
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if(temp.length()>0){
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,38 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentSuimengModelImpl implements IWebContentModel{
public static final String TAG = "http://www.suimeng.la";
public static ContentSuimengModelImpl getInstance() {
return new ContentSuimengModelImpl();
}
private ContentSuimengModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("ccontent").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,39 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
/**
*
*/
public class ContentSyzwwModelImpl implements IWebContentModel{
public static final String TAG = "http://www.syzww.net";
public static ContentSyzwwModelImpl getInstance() {
return new ContentSyzwwModelImpl();
}
private ContentSyzwwModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,43 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;
import java.util.List;
public class ContentVodtwModelImpl implements IWebContentModel {
public static final String TAG = "http://www.vodtw.com";
public static ContentVodtwModelImpl getInstance() {
return new ContentVodtwModelImpl();
}
private ContentVodtwModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
Element contentE = doc.getElementById("BookText");
StringBuilder content = new StringBuilder();
Elements contentEs = contentE.getElementsByTag("p");
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,36 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import java.util.List;
public class ContentWxguanModelImpl implements IWebContentModel{
public static final String TAG = "http://www.wxguan.com";
public static ContentWxguanModelImpl getInstance() {
return new ContentWxguanModelImpl();
}
private ContentWxguanModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,37 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class ContentXqingdouCCModelImpl implements IWebContentModel {
public static final String TAG = "http://www.xqingdou.cc";
public static ContentXqingdouCCModelImpl getInstance() {
return new ContentXqingdouCCModelImpl();
}
private ContentXqingdouCCModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception{
Document doc = Jsoup.parse(s);
Elements contentEs = doc.getElementById("chapter_content").getElementsByTag("p");
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,36 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class ContentXqingdouModelImpl implements IWebContentModel {
public static final String TAG = "http://www.xqingdou.com";
public static ContentXqingdouModelImpl getInstance() {
return new ContentXqingdouModelImpl();
}
private ContentXqingdouModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception{
Document doc = Jsoup.parse(s);
Elements contentEs = doc.getElementById("chapter_content").getElementsByTag("p");
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,61 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;
import java.util.List;
public class ContentYb3ModelImpl implements IWebContentModel{
public static final String TAG = "http://www.yb3.cc";
public static ContentYb3ModelImpl getInstance() {
return new ContentYb3ModelImpl();
}
private ContentYb3ModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
Element contentE = doc.getElementById("content");
List<TextNode> contentTextNodes = contentE.textNodes();
StringBuilder content = new StringBuilder();
if(contentTextNodes!=null && contentTextNodes.size()>0){
for (int i = 0; i < contentTextNodes.size(); i++) {
if (contentTextNodes.get(i).text().trim().length() > 0) {
content.append("\u3000\u3000" + contentTextNodes.get(i).text().trim());
if (i < contentTextNodes.size() - 1) {
content.append("\r\n");
}
}
}
}else{
Elements contentEs = contentE.children();
for (int i = 0; i < contentEs.size(); i++) {
if (contentEs.get(i).text().toString().trim().replaceAll(" ","").length() > 0) {
List<TextNode> tempTextNodes = contentEs.get(i).textNodes();
if(tempTextNodes!=null && tempTextNodes.size()>0){
for (int j = 0; j < tempTextNodes.size(); j++) {
String temp = tempTextNodes.get(j).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
content.append("\r\n");
}
}
}else{
content.append("\u3000\u3000" + contentEs.get(i).text().trim().replaceAll(" ",""));
content.append("\r\n");
}
}
}
}
return content.toString();
}
}

@ -0,0 +1,39 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.model.IWebContentModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;
import java.util.List;
public class ContentZhulangModelImpl implements IWebContentModel{
public static final String TAG = "http://book.zhulang.com";
public static ContentZhulangModelImpl getInstance() {
return new ContentZhulangModelImpl();
}
private ContentZhulangModelImpl() {
}
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
Elements contentEs = doc.getElementById("read-content").children();
StringBuilder content = new StringBuilder();
for (int i = 3; i < contentEs.size()-1; i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}

@ -0,0 +1,555 @@
package com.monke.monkeybook.model.impl;
import com.monke.basemvplib.impl.BaseModelImpl;
import com.monke.monkeybook.ErrorAnalyContentManager;
import com.monke.monkeybook.base.observer.SimpleObserver;
import com.monke.monkeybook.bean.BookContentBean;
import com.monke.monkeybook.bean.BookInfoBean;
import com.monke.monkeybook.bean.BookShelfBean;
import com.monke.monkeybook.bean.ChapterListBean;
import com.monke.monkeybook.bean.SearchBookBean;
import com.monke.monkeybook.bean.WebChapterBean;
import com.monke.monkeybook.common.api.IEasouApi;
import com.monke.monkeybook.listener.OnGetChapterListListener;
import com.monke.monkeybook.model.IEasouBookModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.ObservableSource;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class EasouBookModelImpl extends BaseModelImpl implements IEasouBookModel {
public static final String TAG = "http://book.easou.com";
public static EasouBookModelImpl getInstance() {
return new EasouBookModelImpl();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*
*/
@Override
public Observable<List<SearchBookBean>> searchBook(String content, int page, int rankKind) {
String temp = "/w/searchNovel/" + content + "_" + rankKind + "_" + page + ".html";
return getRetrofitObject(TAG).create(IEasouApi.class).searchBook(temp).flatMap(new Function<String, ObservableSource<List<SearchBookBean>>>() {
@Override
public ObservableSource<List<SearchBookBean>> apply(String s) throws Exception {
return analySearchBook(s);
}
});
}
public Observable<List<SearchBookBean>> analySearchBook(final String s) {
return Observable.create(new ObservableOnSubscribe<List<SearchBookBean>>() {
@Override
public void subscribe(ObservableEmitter<List<SearchBookBean>> e) throws Exception {
try {
Document doc = Jsoup.parse(s);
Elements booksE = doc.getElementsByClass("resultContent").get(0).getElementsByTag("li");
if (null != booksE && booksE.size() > 1) {
List<SearchBookBean> books = new ArrayList<SearchBookBean>();
for (Element bookItem : booksE) {
SearchBookBean item = new SearchBookBean();
item.setTag(TAG);
item.setAuthor(bookItem.getElementsByClass("attr").get(0).getElementsByTag("a").get(0).text());
item.setKind(bookItem.getElementsByClass("attr").get(0).getElementsByTag("a").get(1).text());
item.setState(bookItem.getElementsByTag("span").get(0).text());
item.setLastChapter(bookItem.getElementsByClass("lastchapter").get(0).text());
item.setOrigin(bookItem.getElementsByClass("source").get(0).text().replaceAll("来源:", ""));
item.setName(bookItem.getElementsByClass("name").get(0).getElementsByClass("common").get(0).text());
item.setNoteUrl(TAG + bookItem.getElementsByClass("name").get(0).getElementsByClass("common").get(0).attr("href"));
item.setCoverUrl(bookItem.getElementsByTag("img").get(0).attr("src"));
books.add(item);
}
e.onNext(books);
} else {
e.onNext(new ArrayList<SearchBookBean>());
}
} catch (Exception ex) {
ex.printStackTrace();
e.onNext(new ArrayList<SearchBookBean>());
}
e.onComplete();
}
});
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*
* return BookShelfBean
*/
@Override
public Observable<BookShelfBean> getBookInfo(final BookShelfBean bookShelfBean) {
return getRetrofitObject(TAG).create(IEasouApi.class).getBookInfo(bookShelfBean.getNoteUrl().replace(TAG, "")).flatMap(new Function<String, ObservableSource<BookShelfBean>>() {
@Override
public ObservableSource<BookShelfBean> apply(String s) throws Exception {
return analyBookInfo(s, bookShelfBean);
}
});
}
private Observable<BookShelfBean> analyBookInfo(final String s, final BookShelfBean bookShelfBean) {
return Observable.create(new ObservableOnSubscribe<BookShelfBean>() {
@Override
public void subscribe(ObservableEmitter<BookShelfBean> e) throws Exception {
bookShelfBean.setTag(TAG);
bookShelfBean.setBookInfoBean(analyBookinfo(s, bookShelfBean.getNoteUrl()));
e.onNext(bookShelfBean);
e.onComplete();
}
});
}
private BookInfoBean analyBookinfo(String s, String novelUrl) {
BookInfoBean bookInfoBean = new BookInfoBean();
bookInfoBean.setNoteUrl(novelUrl); //id
bookInfoBean.setTag(TAG);
Document doc = Jsoup.parse(s);
Element resultE = doc.getElementsByClass("content").get(0);
String coverUrl = resultE.getElementsByClass("imgShow").get(0).getElementsByTag("img").get(0).attr("src");
bookInfoBean.setCoverUrl(coverUrl.startsWith("http") ? coverUrl : (TAG + coverUrl));
bookInfoBean.setName(resultE.getElementsByClass("tit").get(1).getElementsByTag("h1").get(0).text());
bookInfoBean.setAuthor(resultE.getElementsByClass("author").get(0).getElementsByClass("common").get(0).text());
bookInfoBean.setIntroduce("\u3000\u3000" + resultE.getElementsByClass("desc").get(0).text().trim());
bookInfoBean.setChapterUrl(TAG + resultE.getElementsByClass("category").get(0).getElementsByTag("a").get(0).attr("href"));
bookInfoBean.setOrigin(resultE.getElementsByClass("attribute").get(0).getElementsByClass("source").get(0).getElementsByClass("t").get(0).text());
return bookInfoBean;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*
* return BookShelfBean
*/
@Override
public void getChapterList(final BookShelfBean bookShelfBean, OnGetChapterListListener getChapterListListener) {
getChapterListPage(bookShelfBean, getChapterListListener, 1);
}
private void getChapterListPage(final BookShelfBean bookShelfBean, final OnGetChapterListListener getChapterListListener, final int page) {
getRetrofitObject(TAG).create(IEasouApi.class).getChapterList(bookShelfBean.getBookInfoBean().getChapterUrl().replace(TAG, "").replace("1_", page + "_")).flatMap(new Function<String, ObservableSource<WebChapterBean<BookShelfBean>>>() {
@Override
public ObservableSource<WebChapterBean<BookShelfBean>> apply(String s) throws Exception {
return analyChapterList(s, bookShelfBean, page == 1 ? true : false);
}
})
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SimpleObserver<WebChapterBean<BookShelfBean>>() {
@Override
public void onNext(WebChapterBean<BookShelfBean> value) {
if (value.getNext()) {
getChapterListPage(value.getData(), getChapterListListener, page + 1);
} else {
if (value.getData().getBookInfoBean().getChapterlist() != null && value.getData().getBookInfoBean().getChapterlist().size() > 0) {
for (int i = 0; i < value.getData().getBookInfoBean().getChapterlist().size(); i++) {
int temp = i;
for (int j = i; j < value.getData().getBookInfoBean().getChapterlist().size(); j++) {
if (value.getData().getBookInfoBean().getChapterlist().get(temp).getDurChapterIndex() > value.getData().getBookInfoBean().getChapterlist().get(j).getDurChapterIndex()) {
temp = j;
}
}
ChapterListBean tempBean = value.getData().getBookInfoBean().getChapterlist().get(i);
value.getData().getBookInfoBean().getChapterlist().set(i, value.getData().getBookInfoBean().getChapterlist().get(temp));
value.getData().getBookInfoBean().getChapterlist().set(temp, tempBean);
}
for (int i = 0; i < value.getData().getBookInfoBean().getChapterlist().size(); i++) {
value.getData().getBookInfoBean().getChapterlist().get(i).setDurChapterIndex(i);
}
}
if (getChapterListListener != null) {
getChapterListListener.success(value.getData());
}
}
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
if (getChapterListListener != null) {
getChapterListListener.error();
}
}
});
}
private Observable<WebChapterBean<BookShelfBean>> analyChapterList(final String s, final BookShelfBean bookShelfBean, final Boolean isFirstPage) {
return Observable.create(new ObservableOnSubscribe<WebChapterBean<BookShelfBean>>() {
@Override
public void subscribe(ObservableEmitter<WebChapterBean<BookShelfBean>> e) throws Exception {
bookShelfBean.setTag(TAG);
WebChapterBean<List<ChapterListBean>> temp = analyChapterlist(s, bookShelfBean.getNoteUrl(), bookShelfBean.getTag());
if (isFirstPage) {
bookShelfBean.getBookInfoBean().setChapterlist(temp.getData());
} else {
bookShelfBean.getBookInfoBean().addChapterlist(temp.getData());
}
e.onNext(new WebChapterBean<BookShelfBean>(bookShelfBean, temp.getNext()));
e.onComplete();
}
});
}
private WebChapterBean<List<ChapterListBean>> analyChapterlist(String s, String novelUrl, String chapterUrl) {
Document doc = Jsoup.parse(s);
Element element = doc.getElementsByClass("content").get(0);
Elements chapterlist = element.getElementsByClass("category").get(0).getElementsByTag("li");
List<ChapterListBean> chapterBeans = new ArrayList<ChapterListBean>();
for (int i = 0; i < chapterlist.size(); i++) {
ChapterListBean temp = new ChapterListBean();
temp.setDurChapterUrl(chapterUrl + chapterlist.get(i).getElementsByTag("a").get(0).attr("href")); //id
String name = chapterlist.get(i).getElementsByTag("a").get(0).text();
setDurChapterData(i, name, temp);
temp.setNoteUrl(novelUrl);
temp.setTag(TAG);
chapterBeans.add(temp);
}
Elements nextE = doc.getElementsByClass("pager").get(0).getElementsByClass("next unable");
Boolean next = (nextE == null || nextE.size() <= 0) ? true : false;
return new WebChapterBean<List<ChapterListBean>>(chapterBeans, next);
}
private void setDurChapterData(int i, String name, ChapterListBean temp) {
try {
String regex = "第.{1,7}章";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(name);
if (m.find()) {
String indexTemp = m.group();
indexTemp = indexTemp.replace("第", "").replace("章", "").trim();
String regex3 = "[0-9]{1,6}";
Pattern p3 = Pattern.compile(regex3);
Matcher m3 = p3.matcher(indexTemp);
int resultIndex = i;
if (m3.matches()) {
resultIndex = Integer.parseInt(indexTemp);
} else {
resultIndex = parse(indexTemp);
}
temp.setDurChapterIndex(resultIndex);
} else {
String regex2 = "[0-9]{1,6}\\.";
Pattern p2 = Pattern.compile(regex2);
Matcher m2 = p2.matcher(name);
if (m2.find()) {
String indexTemp = m2.group();
indexTemp = indexTemp.replaceAll("\\.", "").trim();
int resultIndex = Integer.parseInt(indexTemp);
temp.setDurChapterIndex(resultIndex);
} else {
temp.setDurChapterIndex(i);
}
}
} catch (Exception e) {
e.printStackTrace();
temp.setDurChapterIndex(i);
}finally {
temp.setDurChapterName(name);
}
}
public static int parse(String money) {
int result = 0;
char c = 0;
boolean flag = Pattern.matches("^.*亿.*万.*$", money);
for (int i = 0; i < money.length(); i++) {
switch (money.charAt(i)) {
case '零':
break;
case '一':
c = 1;
break;
case '二':
c = 2;
break;
case '三':
c = 3;
break;
case '四':
c = 4;
break;
case '五':
c = 5;
break;
case '六':
c = 6;
break;
case '七':
c = 7;
break;
case '八':
c = 8;
break;
case '九':
c = 9;
break;
case '十':
result += (c == 0 ? 10 : c * 10);
c = 0;
break;
case '百':
result += c * 100;
c = 0;
break;
case '千':
result += c * 1000;
c = 0;
break;
case '万':
result = (result + c) * 10000;
c = 0;
break;
case '亿':
if (flag) {
result = (result + c) * 10000;
} else {
result = (result + c) * 100000000;
}
c = 0;
break;
default:
c = 0;
}
}
if (c != 0)
result += c;
return result;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*
*/
@Override
public Observable<BookContentBean> getBookContent(final String durChapterUrl, final int durChapterIndex) {
return Observable.create(new ObservableOnSubscribe<BookContentBean>() {
@Override
public void subscribe(final ObservableEmitter<BookContentBean> e) throws Exception {
OkHttpClient client = clientBuilder.build();
Request.Builder requestBuilder = new Request.Builder().url(durChapterUrl).method("GET", null);
requestBuilder.addHeader("Accept", "text/html,application/xhtml+xml,application/xml");
requestBuilder.addHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3");
requestBuilder.addHeader("Accept-Charset", "UTF-8");
requestBuilder.addHeader("Keep-Alive", "300");
requestBuilder.addHeader("Cache-Control", "no-cache");
requestBuilder.addHeader("Connection", "Keep-Alive");
Call mcall = client.newCall(requestBuilder.build());
mcall.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException ex) {
ex.printStackTrace();
if (!e.isDisposed()) {
e.onError(ex);
}
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String url = response.request().url().toString();
BookContentBean bookContentBean = new BookContentBean();
try {
bookContentBean = choiceAnaly(response, url, durChapterUrl, durChapterIndex);
} catch (Exception e) {
e.printStackTrace();
ErrorAnalyContentManager.getInstance().writeMayByNetError(url);
bookContentBean = new BookContentBean();
bookContentBean.setDurChapterIndex(durChapterIndex);
bookContentBean.setDurChapterUrl(durChapterUrl);
bookContentBean.setDurCapterContent(url.substring(0, url.indexOf('/', 8)) + "站点服务器异常");
bookContentBean.setTag(TAG);
bookContentBean.setRight(false);
}
if (!e.isDisposed()) {
e.onNext(bookContentBean);
e.onComplete();
}
}
});
}
});
}
private BookContentBean choiceAnaly(Response response, String url, String durChapterUrl, int durChapterIndex) throws Exception {
BookContentBean bookContentBean = new BookContentBean();
bookContentBean.setDurChapterIndex(durChapterIndex);
bookContentBean.setDurChapterUrl(durChapterUrl);
bookContentBean.setTag(TAG);
if (url.contains(ContentEasouModelImpl.TAG)) {
String xml = response.body().string();
bookContentBean.setDurCapterContent(ContentEasouModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentShulouModelImpl.TAG)) {
String xml = response.body().string();
bookContentBean.setDurCapterContent(ContentShulouModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentPbtxtModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GBK"));
bookContentBean.setDurCapterContent(ContentPbtxtModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentXqingdouModelImpl.TAG)) {
String xml = response.body().string();
bookContentBean.setDurCapterContent(ContentXqingdouModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentSnwx8ModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GBK"));
bookContentBean.setDurCapterContent(ContentSnwx8ModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(Content17kModelImpl.TAG)) {
String xml = response.body().string();
bookContentBean.setDurCapterContent(Content17kModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(Content92zwModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GBK"));
bookContentBean.setDurCapterContent(Content92zwModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentSuimengModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GBK"));
bookContentBean.setDurCapterContent(ContentSuimengModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentKewaishuModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GBK"));
bookContentBean.setDurCapterContent(ContentKewaishuModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentWxguanModelImpl.TAG)) {
String xml = response.body().string();
bookContentBean.setDurCapterContent(ContentWxguanModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentBaishukuModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GBK"));
bookContentBean.setDurCapterContent(ContentBaishukuModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentAszwModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GBK"));
bookContentBean.setDurCapterContent(ContentAszwModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentXqingdouCCModelImpl.TAG)) {
String xml = response.body().string();
bookContentBean.setDurCapterContent(ContentXqingdouCCModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentFuheishuModelImpl.TAG)) {
String xml = response.body().string();
//站点有问题 未完全解析
bookContentBean.setDurCapterContent(ContentFuheishuModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentSyzwwModelImpl.TAG)) {
String xml = response.body().string();
//站点有问题 未完全解析
bookContentBean.setDurCapterContent(ContentSyzwwModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(Content630bookCCModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GBK"));
bookContentBean.setDurCapterContent(Content630bookCCModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentBxwx9ModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GBK"));
bookContentBean.setDurCapterContent(ContentBxwx9ModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(Content44pqModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GBK"));
bookContentBean.setDurCapterContent(Content44pqModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentQzreadModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GBK"));
bookContentBean.setDurCapterContent(ContentQzreadModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentLeduwoModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GBK"));
bookContentBean.setDurCapterContent(ContentLeduwoModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(Content17duxsModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GBK"));
bookContentBean.setDurCapterContent(Content17duxsModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentDhzwModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GBK"));
bookContentBean.setDurCapterContent(ContentDhzwModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentYb3ModelImpl.TAG)) {
String xml = response.body().string();
bookContentBean.setDurCapterContent(ContentYb3ModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentZhulangModelImpl.TAG)) {
String xml = response.body().string();
bookContentBean.setDurCapterContent(ContentZhulangModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentRanwenaModelImpl.TAG)) {
String xml = response.body().string();
bookContentBean.setDurCapterContent(ContentRanwenaModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentPpxsModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GBK"));
bookContentBean.setDurCapterContent(ContentPpxsModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentVodtwModelImpl.TAG)) {
String xml = response.body().source().readString(Charset.forName("GB2312"));
bookContentBean.setDurCapterContent(ContentVodtwModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentQulaModelImpl.TAG)) {
String xml = response.body().string();
bookContentBean.setDurCapterContent(ContentQulaModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(ContentLewen8ModelImpl.TAG)) {
String xml = response.body().string();
bookContentBean.setDurCapterContent(ContentLewen8ModelImpl.getInstance().analyBookcontent(xml, url));
} else if (url.contains(Content3dllcModelImpl.TAG)) {
String xml = response.body().string();
bookContentBean.setDurCapterContent(Content3dllcModelImpl.getInstance().analyBookcontent(xml, url));
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
else {
byte[] xmlData = response.body().source().readByteArray();
String xml = new String(xmlData, "UTF-8");
String charset = "UTF-8";
try {
Document doc = Jsoup.parse(xml);
String data = doc.getElementsByTag("head").get(0).getElementsByTag("meta").get(0).attr("content").toUpperCase().trim();
if (data.contains("CHARSET")) {
data = data.substring(data.indexOf("CHARSET=") + 8);
if (data.contains(";")) {
data = data.substring(0, data.indexOf(";"));
}
charset = data;
if (!charset.equals("UTF-8")) {
xml = new String(xmlData, charset);
}
}
} catch (Exception e) {
e.printStackTrace();
}
bookContentBean = ContentCommendModelImpl.getInstance().analyBookcontent(bookContentBean, xml, url);
}
return bookContentBean;
}
/*
*/
public static void main(String[] args) {
EasouBookModelImpl.getInstance().getBookContent("http://www.yb3.cc/5200/3186/7426551.html", 0)
.subscribe(new SimpleObserver<BookContentBean>() {
@Override
public void onNext(BookContentBean value) {
value.getRight();
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
});
// EasouBookModelImpl.getInstance().setDurChapterData(1,"第42章学习",new ChapterListBean());
// EasouBookModelImpl.getInstance().getLibraryData(null)
// .subscribe(new SimpleObserver<LibraryBean>() {
// @Override
// public void onNext(LibraryBean value) {
// }
//
// @Override
// public void onError(Throwable e) {
// e.printStackTrace();
// }
// });
}
}

@ -0,0 +1,355 @@
package com.monke.monkeybook.model.impl;
import com.monke.basemvplib.impl.BaseModelImpl;
import com.monke.monkeybook.ErrorAnalyContentManager;
import com.monke.monkeybook.base.observer.SimpleObserver;
import com.monke.monkeybook.bean.BookContentBean;
import com.monke.monkeybook.bean.BookInfoBean;
import com.monke.monkeybook.bean.BookShelfBean;
import com.monke.monkeybook.bean.ChapterListBean;
import com.monke.monkeybook.bean.LibraryBean;
import com.monke.monkeybook.bean.LibraryKindBookListBean;
import com.monke.monkeybook.bean.LibraryNewBookBean;
import com.monke.monkeybook.bean.SearchBookBean;
import com.monke.monkeybook.bean.WebChapterBean;
import com.monke.monkeybook.cache.ACache;
import com.monke.monkeybook.common.api.IGxwztvApi;
import com.monke.monkeybook.listener.OnGetChapterListListener;
import com.monke.monkeybook.model.IGxwztvBookModel;
import com.monke.monkeybook.presenter.impl.LibraryPresenterImpl;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;
import java.util.ArrayList;
import java.util.List;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.ObservableSource;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
public class GxwztvBookModelImpl extends BaseModelImpl implements IGxwztvBookModel {
public static final String TAG = "http://www.gxwztv.com";
public static GxwztvBookModelImpl getInstance() {
return new GxwztvBookModelImpl();
}
/**
*
*/
@Override
public Observable<LibraryBean> getLibraryData(final ACache aCache) {
return getRetrofitObject(TAG).create(IGxwztvApi.class).getLibraryData("").flatMap(new Function<String, ObservableSource<LibraryBean>>() {
@Override
public ObservableSource<LibraryBean> apply(String s) throws Exception {
if (s != null && s.length() > 0 && aCache != null) {
aCache.put(LibraryPresenterImpl.LIBRARY_CACHE_KEY, s);
}
return analyLibraryData(s);
}
});
}
/**
*
*/
@Override
public Observable<LibraryBean> analyLibraryData(final String data) {
return Observable.create(new ObservableOnSubscribe<LibraryBean>() {
@Override
public void subscribe(ObservableEmitter<LibraryBean> e) throws Exception {
LibraryBean result = new LibraryBean();
Document doc = Jsoup.parse(data);
Element contentE = doc.getElementsByClass("container").get(0);
//解析最新书籍
Elements newBookEs = contentE.getElementsByClass("list-group-item text-nowrap modal-open");
List<LibraryNewBookBean> libraryNewBooks = new ArrayList<LibraryNewBookBean>();
for (int i = 0; i < newBookEs.size(); i++) {
Element itemE = newBookEs.get(i).getElementsByTag("a").get(0);
LibraryNewBookBean item = new LibraryNewBookBean(itemE.text(), TAG + itemE.attr("href"), TAG, "gxwztv.com");
libraryNewBooks.add(item);
}
result.setLibraryNewBooks(libraryNewBooks);
//////////////////////////////////////////////////////////////////////
List<LibraryKindBookListBean> kindBooks = new ArrayList<LibraryKindBookListBean>();
//解析男频女频
Elements hotEs = contentE.getElementsByClass("col-xs-12");
for (int i = 1; i < hotEs.size(); i++) {
LibraryKindBookListBean kindItem = new LibraryKindBookListBean();
kindItem.setKindName(hotEs.get(i).getElementsByClass("panel-title").get(0).text());
Elements bookEs = hotEs.get(i).getElementsByClass("panel-body").get(0).getElementsByTag("li");
List<SearchBookBean> books = new ArrayList<SearchBookBean>();
for (int j = 0; j < bookEs.size(); j++) {
SearchBookBean searchBookBean = new SearchBookBean();
searchBookBean.setOrigin("gxwztv.com");
searchBookBean.setTag(TAG);
searchBookBean.setName(bookEs.get(j).getElementsByTag("span").get(0).text());
searchBookBean.setNoteUrl(TAG + bookEs.get(j).getElementsByTag("a").get(0).attr("href"));
searchBookBean.setCoverUrl(bookEs.get(j).getElementsByTag("img").get(0).attr("src"));
books.add(searchBookBean);
}
kindItem.setBooks(books);
kindBooks.add(kindItem);
}
//解析部分分类推荐
Elements kindEs = contentE.getElementsByClass("panel panel-info index-category-qk");
for (int i = 0; i < kindEs.size(); i++) {
LibraryKindBookListBean kindItem = new LibraryKindBookListBean();
kindItem.setKindName(kindEs.get(i).getElementsByClass("panel-title").get(0).text());
kindItem.setKindUrl(TAG + kindEs.get(i).getElementsByClass("listMore").get(0).getElementsByTag("a").get(0).attr("href"));
List<SearchBookBean> books = new ArrayList<SearchBookBean>();
Element firstBookE = kindEs.get(i).getElementsByTag("dl").get(0);
SearchBookBean firstBook = new SearchBookBean();
firstBook.setTag(TAG);
firstBook.setOrigin("gxwztv.com");
firstBook.setName(firstBookE.getElementsByTag("a").get(1).text());
firstBook.setNoteUrl(TAG + firstBookE.getElementsByTag("a").get(0).attr("href"));
firstBook.setCoverUrl(firstBookE.getElementsByTag("a").get(0).getElementsByTag("img").get(0).attr("src"));
firstBook.setKind(kindItem.getKindName());
books.add(firstBook);
Elements otherBookEs = kindEs.get(i).getElementsByClass("book_textList").get(0).getElementsByTag("li");
for (int j = 0; j < otherBookEs.size(); j++) {
SearchBookBean item = new SearchBookBean();
item.setTag(TAG);
item.setOrigin("gxwztv.com");
item.setKind(kindItem.getKindName());
item.setNoteUrl(TAG+otherBookEs.get(j).getElementsByTag("a").get(0).attr("href"));
item.setName(otherBookEs.get(j).getElementsByTag("a").get(0).text());
books.add(item);
}
kindItem.setBooks(books);
kindBooks.add(kindItem);
}
//////////////
result.setKindBooks(kindBooks);
e.onNext(result);
e.onComplete();
}
});
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public Observable<List<SearchBookBean>> searchBook(String content, int page) {
return getRetrofitObject(TAG).create(IGxwztvApi.class).searchBook(content, page).flatMap(new Function<String, ObservableSource<List<SearchBookBean>>>() {
@Override
public ObservableSource<List<SearchBookBean>> apply(String s) throws Exception {
return analySearchBook(s);
}
});
}
public Observable<List<SearchBookBean>> analySearchBook(final String s) {
return Observable.create(new ObservableOnSubscribe<List<SearchBookBean>>() {
@Override
public void subscribe(ObservableEmitter<List<SearchBookBean>> e) throws Exception {
try {
Document doc = Jsoup.parse(s);
Elements booksE = doc.getElementById("novel-list").getElementsByClass("list-group-item clearfix");
if (null != booksE && booksE.size() >= 2) {
List<SearchBookBean> books = new ArrayList<SearchBookBean>();
for (int i = 1; i < booksE.size(); i++) {
SearchBookBean item = new SearchBookBean();
item.setTag(TAG);
item.setAuthor(booksE.get(i).getElementsByClass("col-xs-2").get(0).text());
item.setKind(booksE.get(i).getElementsByClass("col-xs-1").get(0).text());
item.setLastChapter(booksE.get(i).getElementsByClass("col-xs-4").get(0).getElementsByTag("a").get(0).text());
item.setOrigin("gxwztv.com");
item.setName(booksE.get(i).getElementsByClass("col-xs-3").get(0).getElementsByTag("a").get(0).text());
item.setNoteUrl(TAG + booksE.get(i).getElementsByClass("col-xs-3").get(0).getElementsByTag("a").get(0).attr("href"));
item.setCoverUrl("noimage");
books.add(item);
}
e.onNext(books);
} else {
e.onNext(new ArrayList<SearchBookBean>());
}
} catch (Exception ex) {
ex.printStackTrace();
e.onNext(new ArrayList<SearchBookBean>());
}
e.onComplete();
}
});
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public Observable<BookShelfBean> getBookInfo(final BookShelfBean bookShelfBean) {
return getRetrofitObject(TAG).create(IGxwztvApi.class).getBookInfo(bookShelfBean.getNoteUrl().replace(TAG, "")).flatMap(new Function<String, ObservableSource<BookShelfBean>>() {
@Override
public ObservableSource<BookShelfBean> apply(String s) throws Exception {
return analyBookInfo(s, bookShelfBean);
}
});
}
private Observable<BookShelfBean> analyBookInfo(final String s, final BookShelfBean bookShelfBean) {
return Observable.create(new ObservableOnSubscribe<BookShelfBean>() {
@Override
public void subscribe(ObservableEmitter<BookShelfBean> e) throws Exception {
bookShelfBean.setTag(TAG);
bookShelfBean.setBookInfoBean(analyBookinfo(s, bookShelfBean.getNoteUrl()));
e.onNext(bookShelfBean);
e.onComplete();
}
});
}
private BookInfoBean analyBookinfo(String s, String novelUrl) {
BookInfoBean bookInfoBean = new BookInfoBean();
bookInfoBean.setNoteUrl(novelUrl); //id
bookInfoBean.setTag(TAG);
Document doc = Jsoup.parse(s);
Element resultE = doc.getElementsByClass("panel panel-warning").get(0);
bookInfoBean.setCoverUrl(resultE.getElementsByClass("panel-body").get(0).getElementsByClass("img-thumbnail").get(0).attr("src"));
bookInfoBean.setName(resultE.getElementsByClass("active").get(0).text());
bookInfoBean.setAuthor(resultE.getElementsByClass("col-xs-12 list-group-item no-border").get(0).getElementsByTag("small").get(0).text());
Element introduceE = resultE.getElementsByClass("panel panel-default mt20").get(0);
String introduce = "";
if (introduceE.getElementById("all") != null) {
introduce = introduceE.getElementById("all").text().replace("[收起]", "");
} else {
introduce = introduceE.getElementById("shot").text();
}
bookInfoBean.setIntroduce("\u3000\u3000" + introduce);
bookInfoBean.setChapterUrl(TAG + resultE.getElementsByClass("list-group-item tac").get(0).getElementsByTag("a").get(0).attr("href"));
bookInfoBean.setOrigin("gxwztv.com");
return bookInfoBean;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public void getChapterList(final BookShelfBean bookShelfBean, final OnGetChapterListListener getChapterListListener) {
getRetrofitObject(TAG).create(IGxwztvApi.class).getChapterList(bookShelfBean.getBookInfoBean().getChapterUrl().replace(TAG, "")).flatMap(new Function<String, ObservableSource<WebChapterBean<BookShelfBean>>>() {
@Override
public ObservableSource<WebChapterBean<BookShelfBean>> apply(String s) throws Exception {
return analyChapterList(s, bookShelfBean);
}
})
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SimpleObserver<WebChapterBean<BookShelfBean>>() {
@Override
public void onNext(WebChapterBean<BookShelfBean> value) {
if (getChapterListListener != null) {
getChapterListListener.success(value.getData());
}
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
if (getChapterListListener != null) {
getChapterListListener.error();
}
}
});
}
private Observable<WebChapterBean<BookShelfBean>> analyChapterList(final String s, final BookShelfBean bookShelfBean) {
return Observable.create(new ObservableOnSubscribe<WebChapterBean<BookShelfBean>>() {
@Override
public void subscribe(ObservableEmitter<WebChapterBean<BookShelfBean>> e) throws Exception {
bookShelfBean.setTag(TAG);
WebChapterBean<List<ChapterListBean>> temp = analyChapterlist(s, bookShelfBean.getNoteUrl());
bookShelfBean.getBookInfoBean().setChapterlist(temp.getData());
e.onNext(new WebChapterBean<BookShelfBean>(bookShelfBean, temp.getNext()));
e.onComplete();
}
});
}
private WebChapterBean<List<ChapterListBean>> analyChapterlist(String s, String novelUrl) {
Document doc = Jsoup.parse(s);
Elements chapterlist = doc.getElementById("chapters-list").getElementsByTag("a");
List<ChapterListBean> chapterBeans = new ArrayList<ChapterListBean>();
for (int i = 0; i < chapterlist.size(); i++) {
ChapterListBean temp = new ChapterListBean();
temp.setDurChapterUrl(TAG + chapterlist.get(i).attr("href")); //id
temp.setDurChapterIndex(i);
temp.setDurChapterName(chapterlist.get(i).text());
temp.setNoteUrl(novelUrl);
temp.setTag(TAG);
chapterBeans.add(temp);
}
Boolean next = false;
return new WebChapterBean<List<ChapterListBean>>(chapterBeans, next);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public Observable<BookContentBean> getBookContent(final String durChapterUrl, final int durChapterIndex) {
return getRetrofitObject(TAG).create(IGxwztvApi.class).getBookContent(durChapterUrl.replace(TAG, "")).flatMap(new Function<String, ObservableSource<BookContentBean>>() {
@Override
public ObservableSource<BookContentBean> apply(String s) throws Exception {
return analyBookContent(s, durChapterUrl, durChapterIndex);
}
});
}
private Observable<BookContentBean> analyBookContent(final String s, final String durChapterUrl, final int durChapterIndex) {
return Observable.create(new ObservableOnSubscribe<BookContentBean>() {
@Override
public void subscribe(ObservableEmitter<BookContentBean> e) throws Exception {
BookContentBean bookContentBean = new BookContentBean();
bookContentBean.setDurChapterIndex(durChapterIndex);
bookContentBean.setDurChapterUrl(durChapterUrl);
bookContentBean.setTag(TAG);
try {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("txtContent").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ", "").replaceAll(" ", "");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
bookContentBean.setDurCapterContent(content.toString());
bookContentBean.setRight(true);
} catch (Exception ex) {
ex.printStackTrace();
ErrorAnalyContentManager.getInstance().writeNewErrorUrl(durChapterUrl);
bookContentBean.setDurCapterContent(durChapterUrl.substring(0, durChapterUrl.indexOf('/', 8)) + "站点暂时不支持解析请反馈给Monke QQ:1105075896,半小时内解决,超级效率的程序员");
bookContentBean.setRight(false);
}
e.onNext(bookContentBean);
e.onComplete();
}
});
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*
*/
@Override
public Observable<List<SearchBookBean>> getKindBook(String url, int page) {
url = url + page + ".htm";
return getRetrofitObject(GxwztvBookModelImpl.TAG).create(IGxwztvApi.class).getKindBooks(url.replace(GxwztvBookModelImpl.TAG, "")).flatMap(new Function<String, ObservableSource<List<SearchBookBean>>>() {
@Override
public ObservableSource<List<SearchBookBean>> apply(String s) throws Exception {
return analySearchBook(s);
}
});
}
}

@ -0,0 +1,184 @@
package com.monke.monkeybook.model.impl;
import com.monke.basemvplib.impl.BaseModelImpl;
import com.monke.monkeybook.bean.BookShelfBean;
import com.monke.monkeybook.bean.ChapterListBean;
import com.monke.monkeybook.bean.LocBookShelfBean;
import com.monke.monkeybook.dao.BookInfoBeanDao;
import com.monke.monkeybook.dao.BookShelfBeanDao;
import com.monke.monkeybook.dao.ChapterListBeanDao;
import com.monke.monkeybook.dao.DbHelper;
import com.monke.monkeybook.model.IImportBookModel;
import org.mozilla.universalchardet.UniversalDetector;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
public class ImportBookModelImpl extends BaseModelImpl implements IImportBookModel {
public static ImportBookModelImpl getInstance() {
return new ImportBookModelImpl();
}
@Override
public Observable<LocBookShelfBean> importBook(final File book) {
return Observable.create(new ObservableOnSubscribe<LocBookShelfBean>() {
@Override
public void subscribe(ObservableEmitter<LocBookShelfBean> e) throws Exception {
MessageDigest md = MessageDigest.getInstance("MD5");
FileInputStream in = new FileInputStream(book);
byte[] buffer = new byte[2048];
int len;
while ((len = in.read(buffer, 0, 2048)) != -1) {
md.update(buffer, 0, len);
}
in.close();
in = null;
String md5 = new BigInteger(1, md.digest()).toString(16);
BookShelfBean bookShelfBean = null;
List<BookShelfBean> temp = DbHelper.getInstance().getmDaoSession().getBookShelfBeanDao().queryBuilder().where(BookShelfBeanDao.Properties.NoteUrl.eq(md5)).build().list();
Boolean isNew = true;
if (temp!=null && temp.size()>0) {
isNew = false;
bookShelfBean = temp.get(0);
bookShelfBean.setBookInfoBean(DbHelper.getInstance().getmDaoSession().getBookInfoBeanDao().queryBuilder().where(BookInfoBeanDao.Properties.NoteUrl.eq(bookShelfBean.getNoteUrl())).build().list().get(0));
} else {
bookShelfBean = new BookShelfBean();
bookShelfBean.setFinalDate(System.currentTimeMillis());
bookShelfBean.setDurChapter(0);
bookShelfBean.setDurChapterPage(0);
bookShelfBean.setTag(BookShelfBean.LOCAL_TAG);
bookShelfBean.setNoteUrl(md5);
bookShelfBean.getBookInfoBean().setAuthor("佚名");
bookShelfBean.getBookInfoBean().setName(book.getName().replace(".txt", "").replace(".TXT", ""));
bookShelfBean.getBookInfoBean().setFinalRefreshData(System.currentTimeMillis());
bookShelfBean.getBookInfoBean().setCoverUrl("");
bookShelfBean.getBookInfoBean().setNoteUrl(md5);
bookShelfBean.getBookInfoBean().setTag(BookShelfBean.LOCAL_TAG);
saveChapter(book, md5);
DbHelper.getInstance().getmDaoSession().getBookInfoBeanDao().insertOrReplace(bookShelfBean.getBookInfoBean());
DbHelper.getInstance().getmDaoSession().getBookShelfBeanDao().insertOrReplace(bookShelfBean);
}
bookShelfBean.getBookInfoBean().setChapterlist(DbHelper.getInstance().getmDaoSession().getChapterListBeanDao().queryBuilder().where(ChapterListBeanDao.Properties.NoteUrl.eq(bookShelfBean.getNoteUrl())).orderAsc(ChapterListBeanDao.Properties.DurChapterIndex).build().list());
e.onNext(new LocBookShelfBean(isNew,bookShelfBean));
e.onComplete();
}
});
}
private Boolean isAdded(BookShelfBean temp, List<BookShelfBean> shelfs) {
if (shelfs == null || shelfs.size() == 0) {
return false;
} else {
int a = 0;
for (int i = 0; i < shelfs.size(); i++) {
if (temp.getNoteUrl().equals(shelfs.get(i).getNoteUrl())) {
break;
} else {
a++;
}
}
if (a == shelfs.size()) {
return false;
} else
return true;
}
}
private void saveChapter(File book, String md5) throws IOException {
String regex = "第.{1,7}章.{0,}";
String encoding;
FileInputStream fis = new FileInputStream(book);
byte[] buf = new byte[4096];
UniversalDetector detector = new UniversalDetector(null);
int nread;
while ((nread = fis.read(buf)) > 0 && !detector.isDone()) {
detector.handleData(buf, 0, nread);
}
detector.dataEnd();
encoding = detector.getDetectedCharset();
if (encoding == null || encoding.length() == 0)
encoding = "utf-8";
fis.close();
fis = null;
int chapterPageIndex = 0;
String title = null;
StringBuilder contentBuilder = new StringBuilder();
fis = new FileInputStream(book);
InputStreamReader inputreader = new InputStreamReader(fis, encoding);
BufferedReader buffreader = new BufferedReader(inputreader);
String line;
while ((line = buffreader.readLine()) != null) {
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(line);
if (m.find()) {
String temp = line.trim().substring(0,line.trim().indexOf("第"));
if(temp!= null && temp.trim().length()>0){
contentBuilder.append(temp);
}
if (contentBuilder.toString().length() > 0) {
if(contentBuilder.toString().replaceAll(" ","").trim().length()>0){
saveDurChapterContent(md5, chapterPageIndex, title, contentBuilder.toString());
chapterPageIndex++;
}
contentBuilder.delete(0, contentBuilder.length());
}
title = line.trim().substring(line.trim().indexOf("第"));
} else {
if (line.trim().length() == 0) {
if (contentBuilder.length() > 0) {
contentBuilder.append("\r\n\u3000\u3000");
} else {
contentBuilder.append("\r\u3000\u3000");
}
} else {
contentBuilder.append(line);
if (title == null) {
title = line.trim();
}
}
}
}
if (contentBuilder.length() > 0) {
saveDurChapterContent(md5, chapterPageIndex, title, contentBuilder.toString());
contentBuilder.delete(0, contentBuilder.length());
title = null;
}
buffreader.close();
inputreader.close();
fis.close();
fis = null;
}
private void saveDurChapterContent(String md5, int chapterPageIndex, String name, String content) {
ChapterListBean chapterListBean = new ChapterListBean();
chapterListBean.setNoteUrl(md5);
chapterListBean.setDurChapterIndex(chapterPageIndex);
chapterListBean.setTag(BookShelfBean.LOCAL_TAG);
chapterListBean.setDurChapterUrl(md5 + "_" + chapterPageIndex);
chapterListBean.setDurChapterName(name);
chapterListBean.getBookContentBean().setDurChapterUrl(chapterListBean.getDurChapterUrl());
chapterListBean.getBookContentBean().setTag(BookShelfBean.LOCAL_TAG);
chapterListBean.getBookContentBean().setDurChapterIndex(chapterListBean.getDurChapterIndex());
chapterListBean.getBookContentBean().setDurCapterContent(content);
DbHelper.getInstance().getmDaoSession().getBookContentBeanDao().insertOrReplace(chapterListBean.getBookContentBean());
DbHelper.getInstance().getmDaoSession().getChapterListBeanDao().insertOrReplace(chapterListBean);
}
}

@ -0,0 +1,247 @@
package com.monke.monkeybook.model.impl;
import com.monke.basemvplib.impl.BaseModelImpl;
import com.monke.monkeybook.ErrorAnalyContentManager;
import com.monke.monkeybook.base.observer.SimpleObserver;
import com.monke.monkeybook.bean.BookContentBean;
import com.monke.monkeybook.bean.BookInfoBean;
import com.monke.monkeybook.bean.BookShelfBean;
import com.monke.monkeybook.bean.ChapterListBean;
import com.monke.monkeybook.bean.SearchBookBean;
import com.monke.monkeybook.bean.WebChapterBean;
import com.monke.monkeybook.common.api.ILingdiankanshuApi;
import com.monke.monkeybook.listener.OnGetChapterListListener;
import com.monke.monkeybook.model.IStationBookModel;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;
import java.util.ArrayList;
import java.util.List;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.ObservableSource;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
public class LingdiankanshuStationBookModelImpl extends BaseModelImpl implements IStationBookModel {
public static final String TAG = "http://www.lingdiankanshu.co";
public static LingdiankanshuStationBookModelImpl getInstance() {
return new LingdiankanshuStationBookModelImpl();
}
@Override
public Observable<List<SearchBookBean>> searchBook(String content, int page) {
return getRetrofitObject("http://zhannei.baidu.com").create(ILingdiankanshuApi.class).searchBook(content, page - 1, "16865089933227718744").flatMap(new Function<String, ObservableSource<List<SearchBookBean>>>() {
@Override
public ObservableSource<List<SearchBookBean>> apply(String s) throws Exception {
return analySearchBook(s);
}
});
}
public Observable<List<SearchBookBean>> analySearchBook(final String s) {
return Observable.create(new ObservableOnSubscribe<List<SearchBookBean>>() {
@Override
public void subscribe(ObservableEmitter<List<SearchBookBean>> e) throws Exception {
try {
Document doc = Jsoup.parse(s);
Elements booksE = doc.getElementsByClass("result-list").get(0).getElementsByClass("result-item result-game-item");
if (null != booksE && booksE.size() > 1) {
List<SearchBookBean> books = new ArrayList<SearchBookBean>();
for (int i = 0; i < booksE.size(); i++) {
SearchBookBean item = new SearchBookBean();
item.setTag(TAG);
item.setAuthor(booksE.get(i).getElementsByClass("result-game-item-info").get(0).getElementsByClass("result-game-item-info-tag").get(0).getElementsByTag("span").get(1).text());
item.setKind(booksE.get(i).getElementsByClass("result-game-item-info").get(0).getElementsByClass("result-game-item-info-tag").get(1).getElementsByTag("span").get(1).text());
// item.setState();
item.setLastChapter(booksE.get(i).getElementsByClass("result-game-item-info").get(0).getElementsByClass("result-game-item-info-tag").get(3).getElementsByTag("a").get(0).text());
item.setOrigin("lingdiankanshu.co");
item.setName(booksE.get(i).getElementsByClass("result-item-title result-game-item-title").get(0).getElementsByTag("a").get(0).text());
item.setNoteUrl(booksE.get(i).getElementsByClass("result-item-title result-game-item-title").get(0).getElementsByTag("a").get(0).attr("href"));
item.setCoverUrl(booksE.get(i).getElementsByTag("img").get(0).attr("src"));
books.add(item);
}
e.onNext(books);
} else {
e.onNext(new ArrayList<SearchBookBean>());
}
} catch (Exception ex) {
ex.printStackTrace();
e.onNext(new ArrayList<SearchBookBean>());
}
e.onComplete();
}
});
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public Observable<BookShelfBean> getBookInfo(final BookShelfBean bookShelfBean) {
return getRetrofitObject(TAG).create(ILingdiankanshuApi.class).getBookInfo(bookShelfBean.getNoteUrl().replace(TAG, "")).flatMap(new Function<String, ObservableSource<BookShelfBean>>() {
@Override
public ObservableSource<BookShelfBean> apply(String s) throws Exception {
return analyBookInfo(s, bookShelfBean);
}
});
}
private Observable<BookShelfBean> analyBookInfo(final String s, final BookShelfBean bookShelfBean) {
return Observable.create(new ObservableOnSubscribe<BookShelfBean>() {
@Override
public void subscribe(ObservableEmitter<BookShelfBean> e) throws Exception {
bookShelfBean.setTag(TAG);
bookShelfBean.setBookInfoBean(analyBookinfo(s, bookShelfBean.getNoteUrl()));
e.onNext(bookShelfBean);
e.onComplete();
}
});
}
private BookInfoBean analyBookinfo(String s, String novelUrl) {
BookInfoBean bookInfoBean = new BookInfoBean();
bookInfoBean.setNoteUrl(novelUrl); //id
bookInfoBean.setTag(TAG);
Document doc = Jsoup.parse(s);
Element resultE = doc.getElementsByClass("box_con").get(0);
bookInfoBean.setCoverUrl(resultE.getElementById("fmimg").getElementsByTag("img").get(0).attr("src"));
bookInfoBean.setName(resultE.getElementById("info").getElementsByTag("h1").get(0).text());
String author = resultE.getElementById("info").getElementsByTag("p").get(0).text().toString().trim();
author = author.replace(" ", "").replace("  ", "").replace("作者:", "");
bookInfoBean.setAuthor(author);
List<TextNode> contentEs = resultE.getElementById("intro").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ", "").replaceAll(" ", "");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
bookInfoBean.setIntroduce(content.toString());
bookInfoBean.setChapterUrl(novelUrl);
bookInfoBean.setOrigin("gxwztv.com");
return bookInfoBean;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public void getChapterList(final BookShelfBean bookShelfBean, final OnGetChapterListListener getChapterListListener) {
getRetrofitObject(TAG).create(ILingdiankanshuApi.class).getChapterList(bookShelfBean.getBookInfoBean().getChapterUrl().replace(TAG, "")).flatMap(new Function<String, ObservableSource<WebChapterBean<BookShelfBean>>>() {
@Override
public ObservableSource<WebChapterBean<BookShelfBean>> apply(String s) throws Exception {
return analyChapterList(s, bookShelfBean);
}
})
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SimpleObserver<WebChapterBean<BookShelfBean>>() {
@Override
public void onNext(WebChapterBean<BookShelfBean> value) {
if (getChapterListListener != null) {
getChapterListListener.success(value.getData());
}
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
if (getChapterListListener != null) {
getChapterListListener.error();
}
}
});
}
private Observable<WebChapterBean<BookShelfBean>> analyChapterList(final String s, final BookShelfBean bookShelfBean) {
return Observable.create(new ObservableOnSubscribe<WebChapterBean<BookShelfBean>>() {
@Override
public void subscribe(ObservableEmitter<WebChapterBean<BookShelfBean>> e) throws Exception {
bookShelfBean.setTag(TAG);
WebChapterBean<List<ChapterListBean>> temp = analyChapterlist(s, bookShelfBean.getNoteUrl());
bookShelfBean.getBookInfoBean().setChapterlist(temp.getData());
e.onNext(new WebChapterBean<BookShelfBean>(bookShelfBean, temp.getNext()));
e.onComplete();
}
});
}
private WebChapterBean<List<ChapterListBean>> analyChapterlist(String s, String novelUrl) {
Document doc = Jsoup.parse(s);
Elements chapterlist = doc.getElementById("list").getElementsByTag("dd");
List<ChapterListBean> chapterBeans = new ArrayList<ChapterListBean>();
for (int i = 0; i < chapterlist.size(); i++) {
ChapterListBean temp = new ChapterListBean();
temp.setDurChapterUrl(novelUrl + chapterlist.get(i).getElementsByTag("a").get(0).attr("href")); //id
temp.setDurChapterIndex(i);
temp.setDurChapterName(chapterlist.get(i).getElementsByTag("a").get(0).text());
temp.setNoteUrl(novelUrl);
temp.setTag(TAG);
chapterBeans.add(temp);
}
Boolean next = false;
return new WebChapterBean<List<ChapterListBean>>(chapterBeans, next);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public Observable<BookContentBean> getBookContent(final String durChapterUrl, final int durChapterIndex) {
return getRetrofitObject(TAG).create(ILingdiankanshuApi.class).getBookContent(durChapterUrl.replace(TAG, "")).flatMap(new Function<String, ObservableSource<BookContentBean>>() {
@Override
public ObservableSource<BookContentBean> apply(String s) throws Exception {
return analyBookContent(s, durChapterUrl, durChapterIndex);
}
});
}
private Observable<BookContentBean> analyBookContent(final String s, final String durChapterUrl, final int durChapterIndex) {
return Observable.create(new ObservableOnSubscribe<BookContentBean>() {
@Override
public void subscribe(ObservableEmitter<BookContentBean> e) throws Exception {
BookContentBean bookContentBean = new BookContentBean();
bookContentBean.setDurChapterIndex(durChapterIndex);
bookContentBean.setDurChapterUrl(durChapterUrl);
bookContentBean.setTag(TAG);
try {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ", "").replaceAll(" ", "");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
bookContentBean.setDurCapterContent(content.toString());
bookContentBean.setRight(true);
} catch (Exception ex) {
ex.printStackTrace();
ErrorAnalyContentManager.getInstance().writeNewErrorUrl(durChapterUrl);
bookContentBean.setDurCapterContent(durChapterUrl.substring(0, durChapterUrl.indexOf('/', 8)) + "站点暂时不支持解析请反馈给Monke QQ:1105075896,半小时内解决,超级效率的程序员");
bookContentBean.setRight(false);
}
e.onNext(bookContentBean);
e.onComplete();
}
});
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

@ -0,0 +1,130 @@
package com.monke.monkeybook.model.impl;
import com.monke.monkeybook.bean.BookContentBean;
import com.monke.monkeybook.bean.BookShelfBean;
import com.monke.monkeybook.bean.SearchBookBean;
import com.monke.monkeybook.listener.OnGetChapterListListener;
import com.monke.monkeybook.model.IWebBookModel;
import java.util.ArrayList;
import java.util.List;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
public class WebBookModelImpl implements IWebBookModel {
public static WebBookModelImpl getInstance() {
return new WebBookModelImpl();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*
* return BookShelfBean
*/
@Override
public Observable<BookShelfBean> getBookInfo(BookShelfBean bookShelfBean) {
if (bookShelfBean.getTag().equals(EasouBookModelImpl.TAG)) {
return EasouBookModelImpl.getInstance().getBookInfo(bookShelfBean);
}
else if(bookShelfBean.getTag().equals(GxwztvBookModelImpl.TAG)){
return GxwztvBookModelImpl.getInstance().getBookInfo(bookShelfBean);
}
else if(bookShelfBean.getTag().equals(LingdiankanshuStationBookModelImpl.TAG)){
return LingdiankanshuStationBookModelImpl.getInstance().getBookInfo(bookShelfBean);
}
else {
return null;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*
* return BookShelfBean
*/
@Override
public void getChapterList(final BookShelfBean bookShelfBean, OnGetChapterListListener getChapterListListener) {
if (bookShelfBean.getTag().equals(EasouBookModelImpl.TAG)) {
EasouBookModelImpl.getInstance().getChapterList(bookShelfBean, getChapterListListener);
}
else if(bookShelfBean.getTag().equals(GxwztvBookModelImpl.TAG)){
GxwztvBookModelImpl.getInstance().getChapterList(bookShelfBean, getChapterListListener);
}
else if(bookShelfBean.getTag().equals(LingdiankanshuStationBookModelImpl.TAG)){
LingdiankanshuStationBookModelImpl.getInstance().getChapterList(bookShelfBean, getChapterListListener);
}
else{
if(getChapterListListener!=null)
getChapterListListener.success(bookShelfBean);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*
*/
@Override
public Observable<BookContentBean> getBookContent(String durChapterUrl, int durChapterIndex, String tag) {
if (tag.equals(EasouBookModelImpl.TAG)) {
return EasouBookModelImpl.getInstance().getBookContent(durChapterUrl, durChapterIndex);
}
else if(tag.equals(GxwztvBookModelImpl.TAG)){
return GxwztvBookModelImpl.getInstance().getBookContent(durChapterUrl, durChapterIndex);
}
else if(tag.equals(LingdiankanshuStationBookModelImpl.TAG)){
return LingdiankanshuStationBookModelImpl.getInstance().getBookContent(durChapterUrl, durChapterIndex);
}
else
return Observable.create(new ObservableOnSubscribe<BookContentBean>() {
@Override
public void subscribe(ObservableEmitter<BookContentBean> e) throws Exception {
e.onNext(new BookContentBean());
e.onComplete();
}
});
}
/**
*
*/
@Override
public Observable<List<SearchBookBean>> searchOtherBook(String content,int page,String tag){
if(tag.equals(EasouBookModelImpl.TAG)){
return EasouBookModelImpl.getInstance().searchBook(content, page, 0);
}
else if(tag.equals(GxwztvBookModelImpl.TAG)){
return GxwztvBookModelImpl.getInstance().searchBook(content, page);
}
else if(tag.equals(LingdiankanshuStationBookModelImpl.TAG)){
return LingdiankanshuStationBookModelImpl.getInstance().searchBook(content, page);
}
else{
return Observable.create(new ObservableOnSubscribe<List<SearchBookBean>>() {
@Override
public void subscribe(ObservableEmitter<List<SearchBookBean>> e) throws Exception {
e.onNext(new ArrayList<SearchBookBean>());
e.onComplete();
}
});
}
}
/**
* //专用
*/
@Override
public Observable<List<SearchBookBean>> searchBook(String content, int page,int rankKind) {
return EasouBookModelImpl.getInstance().searchBook(content, page, rankKind);
}
/**
*
*/
@Override
public Observable<List<SearchBookBean>> getKindBook(String url,int page) {
return GxwztvBookModelImpl.getInstance().getKindBook(url,page);
}
}

@ -0,0 +1,22 @@
package com.monke.monkeybook.presenter;
import com.monke.basemvplib.IPresenter;
import com.monke.monkeybook.bean.BookShelfBean;
import com.monke.monkeybook.bean.SearchBookBean;
public interface IBookDetailPresenter extends IPresenter{
public int getOpenfrom();
public SearchBookBean getSearchBook();
public BookShelfBean getBookShelf();
public Boolean getInBookShelf();
public void getBookShelfInfo();
public void addToBookShelf();
public void removeFromBookShelf();
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save