Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Nov 4, 2018
1 parent d025fa5 commit 19572fd
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 39 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ dependencies {
}

greendao {
schemaVersion 43
schemaVersion 45
daoPackage 'com.monke.monkeybook.dao'
targetGenDir 'src/main/java'
}
Expand Down
81 changes: 47 additions & 34 deletions app/src/main/java/com/monke/monkeybook/bean/BookInfoBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class BookInfoBean implements Parcelable,Cloneable{
private String author;//作者
private String introduce; //简介
private String origin; //来源
private String charset;//编码

@Transient
private List<ChapterListBean> chapterList = new ArrayList<>(); //章节列表
Expand Down Expand Up @@ -62,19 +63,19 @@ protected BookInfoBean(Parcel in) {
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();
charset = in.readString();
chapterList = in.createTypedArrayList(ChapterListBean.CREATOR);
bookmarkList = in.createTypedArrayList(BookmarkBean.CREATOR);
}

@Generated(hash = 1627552162)
public BookInfoBean(String name, String tag, String noteUrl, String chapterUrl,
long finalRefreshData, String coverUrl, String author, String introduce,
String origin) {
@Generated(hash = 1022173528)
public BookInfoBean(String name, String tag, String noteUrl, String chapterUrl, long finalRefreshData, String coverUrl,
String author, String introduce, String origin, String charset) {
this.name = name;
this.tag = tag;
this.noteUrl = noteUrl;
Expand All @@ -84,6 +85,7 @@ public BookInfoBean(String name, String tag, String noteUrl, String chapterUrl,
this.author = author;
this.introduce = introduce;
this.origin = origin;
this.charset = charset;
}

@Override
Expand All @@ -92,19 +94,51 @@ public void writeToParcel(Parcel dest, int flags) {
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);
dest.writeString(charset);
dest.writeTypedList(chapterList);
dest.writeTypedList(bookmarkList);
}

@Override
public int describeContents() {
return 0;
}

@Override
protected Object clone() throws CloneNotSupportedException {
BookInfoBean bookInfoBean = (BookInfoBean) super.clone();
bookInfoBean.name = name;
bookInfoBean.tag = tag;
bookInfoBean.noteUrl = noteUrl;
bookInfoBean.chapterUrl = chapterUrl;
bookInfoBean.coverUrl = coverUrl;
bookInfoBean.author = author;
bookInfoBean.introduce = introduce;
bookInfoBean.origin = origin;
bookInfoBean.charset = charset;
if(chapterList !=null){
List<ChapterListBean> newListC = new ArrayList<>();
Iterator<ChapterListBean> iteratorC = chapterList.iterator();
while(iteratorC.hasNext()){
newListC.add((ChapterListBean) iteratorC.next().clone());
}
bookInfoBean.setChapterList(newListC);
}
if (bookmarkList != null) {
List<BookmarkBean> newListM = new ArrayList<>();
Iterator<BookmarkBean> iteratorM = bookmarkList.iterator();
while(iteratorM.hasNext()){
newListM.add((BookmarkBean) iteratorM.next().clone());
}
bookInfoBean.setBookmarkList(newListM);
}
return bookInfoBean;
}

public String getName() {
return name;
Expand Down Expand Up @@ -201,33 +235,12 @@ public void setBookmarkList(List<BookmarkBean> bookmarkList) {
this.bookmarkList = bookmarkList;
}

@Override
protected Object clone() throws CloneNotSupportedException {
BookInfoBean bookInfoBean = (BookInfoBean) super.clone();
bookInfoBean.name = name;
bookInfoBean.tag = tag;
bookInfoBean.noteUrl = noteUrl;
bookInfoBean.chapterUrl = chapterUrl;
bookInfoBean.coverUrl = coverUrl;
bookInfoBean.author = author;
bookInfoBean.introduce = introduce;
bookInfoBean.origin = origin;
if(chapterList !=null){
List<ChapterListBean> newListC = new ArrayList<>();
Iterator<ChapterListBean> iteratorC = chapterList.iterator();
while(iteratorC.hasNext()){
newListC.add((ChapterListBean) iteratorC.next().clone());
}
bookInfoBean.setChapterList(newListC);
}
if (bookmarkList != null) {
List<BookmarkBean> newListM = new ArrayList<>();
Iterator<BookmarkBean> iteratorM = bookmarkList.iterator();
while(iteratorM.hasNext()){
newListM.add((BookmarkBean) iteratorM.next().clone());
}
bookInfoBean.setBookmarkList(newListM);
}
return bookInfoBean;
public String getCharset() {
return this.charset;
}

public void setCharset(String charset) {
this.charset = charset;
}

}
18 changes: 16 additions & 2 deletions app/src/main/java/com/monke/monkeybook/dao/BookInfoBeanDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static class Properties {
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 final static Property Charset = new Property(9, String.class, "charset", false, "CHARSET");
}


Expand All @@ -56,7 +57,8 @@ public static void createTable(Database db, boolean ifNotExists) {
"\"COVER_URL\" TEXT," + // 5: coverUrl
"\"AUTHOR\" TEXT," + // 6: author
"\"INTRODUCE\" TEXT," + // 7: introduce
"\"ORIGIN\" TEXT);"); // 8: origin
"\"ORIGIN\" TEXT," + // 8: origin
"\"CHARSET\" TEXT);"); // 9: charset
}

/** Drops the underlying database table. */
Expand Down Expand Up @@ -109,6 +111,11 @@ protected final void bindValues(DatabaseStatement stmt, BookInfoBean entity) {
if (origin != null) {
stmt.bindString(9, origin);
}

String charset = entity.getCharset();
if (charset != null) {
stmt.bindString(10, charset);
}
}

@Override
Expand Down Expand Up @@ -155,6 +162,11 @@ protected final void bindValues(SQLiteStatement stmt, BookInfoBean entity) {
if (origin != null) {
stmt.bindString(9, origin);
}

String charset = entity.getCharset();
if (charset != null) {
stmt.bindString(10, charset);
}
}

@Override
Expand All @@ -173,7 +185,8 @@ public BookInfoBean readEntity(Cursor cursor, int offset) {
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
cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // origin
cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // charset
);
return entity;
}
Expand All @@ -189,6 +202,7 @@ public void readEntity(Cursor cursor, BookInfoBean entity, int offset) {
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));
entity.setCharset(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/monke/monkeybook/dao/DaoMaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* Master of DAO (schema version 43): knows all DAOs.
* Master of DAO (schema version 45): knows all DAOs.
*/
public class DaoMaster extends AbstractDaoMaster {
public static final int SCHEMA_VERSION = 43;
public static final int SCHEMA_VERSION = 45;

/** Creates underlying database table using DAOs. */
public static void createAllTables(Database db, boolean ifNotExists) {
Expand Down

0 comments on commit 19572fd

Please sign in to comment.