Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Jul 31, 2018
1 parent 72d72ae commit 08252aa
Show file tree
Hide file tree
Showing 14 changed files with 1,017 additions and 79 deletions.
97 changes: 61 additions & 36 deletions app/src/main/java/com/monke/monkeybook/bean/ChapterListBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
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 Long start;
//章节内容在文章中的终止位置(本地)
private Long end;
//是否缓存
private Boolean hasCache = false;

@Transient
private BookContentBean bookContentBean = new BookContentBean();

Expand All @@ -37,18 +39,22 @@ protected ChapterListBean(Parcel in) {
durChapterUrl = in.readString();
durChapterName = in.readString();
tag = in.readString();
start = in.readLong();
end = in.readLong();
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) {
@Generated(hash = 1638492836)
public ChapterListBean(String noteUrl, int durChapterIndex, String durChapterUrl, String durChapterName, String tag,
Long start, Long end, Boolean hasCache) {
this.noteUrl = noteUrl;
this.durChapterIndex = durChapterIndex;
this.durChapterUrl = durChapterUrl;
this.durChapterName = durChapterName;
this.tag = tag;
this.start = start;
this.end = end;
this.hasCache = hasCache;
}

Expand All @@ -63,6 +69,8 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(durChapterUrl);
dest.writeString(durChapterName);
dest.writeString(tag);
dest.writeLong(start);
dest.writeLong(end);
dest.writeParcelable(bookContentBean, flags);
dest.writeByte((byte)(hasCache?1:0));
}
Expand All @@ -71,6 +79,41 @@ public void writeToParcel(Parcel dest, int flags) {
public int describeContents() {
return 0;
}

@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 = noteUrl;
chapterListBean.durChapterUrl = durChapterUrl;
chapterListBean.durChapterName = durChapterName;
chapterListBean.tag = tag;
chapterListBean.hasCache = hasCache;
chapterListBean.bookContentBean = new BookContentBean();
return chapterListBean;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof ChapterListBean) {
ChapterListBean chapterListBean = (ChapterListBean) obj;
return Objects.equals(chapterListBean.durChapterUrl, durChapterUrl);
} else {
return false;
}
}

public BookContentBean getBookContentBean() {
return bookContentBean;
Expand Down Expand Up @@ -132,38 +175,20 @@ 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);
}
public Long getStart() {
return this.start;
}

@Override
public ChapterListBean[] newArray(int size) {
return new ChapterListBean[size];
}
};
public void setStart(Long start) {
this.start = start;
}

@Override
protected Object clone() throws CloneNotSupportedException {
ChapterListBean chapterListBean = (ChapterListBean) super.clone();
chapterListBean.noteUrl = noteUrl;
chapterListBean.durChapterUrl = durChapterUrl;
chapterListBean.durChapterName = durChapterName;
chapterListBean.tag = tag;
chapterListBean.hasCache = hasCache;
chapterListBean.bookContentBean = new BookContentBean();
return chapterListBean;
public Long getEnd() {
return this.end;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof ChapterListBean) {
ChapterListBean chapterListBean = (ChapterListBean) obj;
return Objects.equals(chapterListBean.durChapterUrl, durChapterUrl);
} else {
return false;
}
public void setEnd(Long end) {
this.end = end;
}

}
40 changes: 34 additions & 6 deletions app/src/main/java/com/monke/monkeybook/dao/ChapterListBeanDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public static class Properties {
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 final static Property Start = new Property(5, Long.class, "start", false, "START");
public final static Property End = new Property(6, Long.class, "end", false, "END");
public final static Property HasCache = new Property(7, Boolean.class, "hasCache", false, "HAS_CACHE");
}


Expand All @@ -50,7 +52,9 @@ public static void createTable(Database db, boolean ifNotExists) {
"\"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
"\"START\" INTEGER," + // 5: start
"\"END\" INTEGER," + // 6: end
"\"HAS_CACHE\" INTEGER);"); // 7: hasCache
}

/** Drops the underlying database table. */
Expand Down Expand Up @@ -84,9 +88,19 @@ protected final void bindValues(DatabaseStatement stmt, ChapterListBean entity)
stmt.bindString(5, tag);
}

Long start = entity.getStart();
if (start != null) {
stmt.bindLong(6, start);
}

Long end = entity.getEnd();
if (end != null) {
stmt.bindLong(7, end);
}

Boolean hasCache = entity.getHasCache();
if (hasCache != null) {
stmt.bindLong(6, hasCache ? 1L: 0L);
stmt.bindLong(8, hasCache ? 1L: 0L);
}
}

Expand Down Expand Up @@ -115,9 +129,19 @@ protected final void bindValues(SQLiteStatement stmt, ChapterListBean entity) {
stmt.bindString(5, tag);
}

Long start = entity.getStart();
if (start != null) {
stmt.bindLong(6, start);
}

Long end = entity.getEnd();
if (end != null) {
stmt.bindLong(7, end);
}

Boolean hasCache = entity.getHasCache();
if (hasCache != null) {
stmt.bindLong(6, hasCache ? 1L: 0L);
stmt.bindLong(8, hasCache ? 1L: 0L);
}
}

Expand All @@ -134,7 +158,9 @@ public ChapterListBean readEntity(Cursor cursor, int offset) {
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
cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5), // start
cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6), // end
cursor.isNull(offset + 7) ? null : cursor.getShort(offset + 7) != 0 // hasCache
);
return entity;
}
Expand All @@ -146,7 +172,9 @@ public void readEntity(Cursor cursor, ChapterListBean entity, int offset) {
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);
entity.setStart(cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5));
entity.setEnd(cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6));
entity.setHasCache(cursor.isNull(offset + 7) ? null : cursor.getShort(offset + 7) != 0);
}

@Override
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/monke/monkeybook/help/BookshelfHelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import com.monke.monkeybook.dao.BookmarkBeanDao;
import com.monke.monkeybook.dao.ChapterListBeanDao;
import com.monke.monkeybook.dao.DbHelper;
import com.monke.monkeybook.utils.FileUtils;

import java.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -27,6 +29,18 @@
*/

public class BookshelfHelp {
/**
* 根据文件名判断是否被缓存过 (因为可能数据库显示被缓存过,但是文件中却没有的情况,所以需要根据文件判断是否被缓存
* 过)
* @param folderName : bookId
* @param fileName: chapterName
* @return
*/
public static boolean isChapterCached(String folderName, String fileName){
File file = new File(Constant.BOOK_CACHE_PATH + folderName
+ File.separator + fileName + FileUtils.SUFFIX_NB);
return file.exists();
}

public static List<BookShelfBean> getAllBook() {
List<BookShelfBean> bookShelfList = DbHelper.getInstance().getmDaoSession().getBookShelfBeanDao().queryBuilder()
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/monke/monkeybook/help/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.support.annotation.StringDef;

import com.monke.monkeybook.utils.FileUtils;

import java.io.File;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down Expand Up @@ -35,6 +37,13 @@ public class Constant {
public static final String FORMAT_FILE_DATE = "yyyy-MM-dd";
//RxBus
public static final int MSG_SELECTOR = 1;
//BookCachePath (因为getCachePath引用了Context,所以必须是静态变量,不能够是静态常量)
public static String BOOK_CACHE_PATH = FileUtils.getCachePath()+File.separator
+ "book_cache"+ File.separator ;
//文件阅读记录保存的路径
public static String BOOK_RECORD_PATH = FileUtils.getCachePath() + File.separator
+ "book_record" + File.separator;


//BookType
@StringDef({
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/monke/monkeybook/help/Void.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.monke.monkeybook.help;

/**
* Created by newbiechen on 17-5-27.
*/

public final class Void {
}
22 changes: 22 additions & 0 deletions app/src/main/java/com/monke/monkeybook/utils/Charset.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.monke.monkeybook.utils;

/**
* 编码类型
*/
public enum Charset {
UTF8("UTF-8"),
UTF16LE("UTF-16LE"),
UTF16BE("UTF-16BE"),
GBK("GBK");

private String mName;
public static final byte BLANK = 0x0a;

private Charset(String name) {
mName = name;
}

public String getName() {
return mName;
}
}
Loading

0 comments on commit 08252aa

Please sign in to comment.