pda/zhuike/src/main/java/com/novelbook/android/db/Novel.java

358 lines
8.1 KiB
Java
Raw Normal View History

2019-04-03 16:21:00 +08:00
package com.novelbook.android.db;
2019-04-06 23:04:42 +08:00
import android.text.TextUtils;
2019-05-03 00:30:48 +08:00
import android.util.Log;
2019-04-06 23:04:42 +08:00
import com.novelbook.android.utils.Constants;
2019-04-06 23:04:42 +08:00
import org.litepal.LitePal;
2019-04-05 23:59:31 +08:00
import org.litepal.annotation.Column;
2019-04-03 16:21:00 +08:00
import org.litepal.crud.LitePalSupport;
2019-04-06 23:04:42 +08:00
import org.w3c.dom.Text;
2019-04-03 16:21:00 +08:00
import java.io.Serializable;
import java.util.Date;
2019-04-06 23:04:42 +08:00
import java.util.List;
2019-04-03 16:21:00 +08:00
public class Novel extends LitePalSupport implements Serializable{
private int id;
//@Column(unique = true, defaultValue = "0")
private int novelId;
2019-04-05 23:59:31 +08:00
private String name;
private String infoUrl;
2019-04-03 16:21:00 +08:00
private String domain;
2019-05-05 23:31:19 +08:00
private String domainName;
2019-04-03 16:21:00 +08:00
private String muluUrl;
private String novelPath;
private long lastReadPos;
2019-04-05 23:59:31 +08:00
private int lastReadChapt=1;
2019-04-03 16:21:00 +08:00
private String charset;
private String novelType;
private String smallNovelType;
2019-04-03 16:21:00 +08:00
private String author;
private String cover;
private String chapterName;
private String desc;
private String progress;
2019-04-23 22:45:08 +08:00
private long lastUpdateTime;
2019-04-03 18:09:00 +08:00
private boolean isOnShelf; //是否入书架
private boolean isFinished; //是否完本
2019-04-26 00:31:07 +08:00
private boolean isUpdated;
private boolean isTop;//置顶
private long readtime; //阅读时间
private int chaptCnt; //总章数
private long lastVisit;//最近浏览,如何设置默认时间?
public int getChaptCnt() {
return chaptCnt;
}
public void setChaptCnt(int chaptCnt) {
this.chaptCnt = chaptCnt;
}
public long getReadtime() {
return readtime;
}
public void setReadtime(long readtime) {
this.readtime = readtime;
}
2019-05-05 23:31:19 +08:00
public String getDomainName() {
return domainName;
}
2019-05-05 23:31:19 +08:00
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public long getLastVisit() {
return lastVisit;
}
public void setLastVisit(long lastVisit) {
this.lastVisit = lastVisit;
}
2019-04-26 00:31:07 +08:00
public boolean isTop() {
return isTop;
}
public void setTop(boolean top) {
isTop = top;
}
public boolean isUpdated() {
return isUpdated;
}
public void setUpdated(boolean updated) {
isUpdated = updated;
}
2019-04-03 18:09:00 +08:00
public String getInfoUrl() {
return infoUrl;
}
public void setInfoUrl(String infoUrl) {
this.infoUrl = infoUrl;
}
public String getSmallNovelType() {
return smallNovelType;
}
public void setSmallNovelType(String smallNovelType) {
this.smallNovelType = smallNovelType;
}
public String getChapterName() {
return chapterName;
}
public void setChapterName(String chapterName) {
this.chapterName = chapterName;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getProgress() {
return progress;
}
public void setProgress(String progress) {
this.progress = progress;
}
2019-05-05 23:31:19 +08:00
public int getId() {
2019-04-03 16:21:00 +08:00
return id;
}
public void setId(int id) {
this.id = id;
}
public int getNovelId() {
2019-04-03 16:21:00 +08:00
return novelId;
}
public void setNovelId(int novelId) {
2019-04-03 16:21:00 +08:00
this.novelId = novelId;
}
2019-04-05 23:59:31 +08:00
public String getName() {
return name;
2019-04-03 16:21:00 +08:00
}
2019-04-05 23:59:31 +08:00
public void setName(String novelName) {
this.name = novelName;
2019-04-03 16:21:00 +08:00
}
public String getDomain() {
return domain;
}
public void setDomain(String domain) {
this.domain = domain;
}
public String getMuluUrl() {
return muluUrl;
}
public void setMuluUrl(String muluUrl) {
this.muluUrl = muluUrl;
}
public String getNovelPath() {
return novelPath;
}
public void setNovelPath(String novelPath) {
this.novelPath = novelPath;
}
public long getLastReadPos() {
return lastReadPos;
}
public void setLastReadPos(long lastReadPos) {
this.lastReadPos = lastReadPos;
}
2019-04-05 23:59:31 +08:00
public int getLastReadChapt() {
2019-04-16 23:11:00 +08:00
// if(lastReadChapt<=0){lastReadChapt=1;}
2019-04-03 16:21:00 +08:00
return lastReadChapt;
}
2019-04-05 23:59:31 +08:00
public void setLastReadChapt(int lastReadChapt) {
2019-04-16 23:11:00 +08:00
// lastReadChapt = lastReadChapt >0 ? lastReadChapt :1;
2019-04-03 16:21:00 +08:00
this.lastReadChapt = lastReadChapt;
}
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
public String getNovelType() {
return novelType;
}
public void setNovelType(String novelType) {
this.novelType = novelType;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getCover() {
return cover;
}
public void setCover(String cover) {
this.cover = cover;
}
public long getLastUpdateTime() {
2019-04-23 22:45:08 +08:00
return lastUpdateTime;
2019-04-03 16:21:00 +08:00
}
public void setLastUpdateTime(long lastUpateTime) {
2019-04-23 22:45:08 +08:00
this.lastUpdateTime = lastUpateTime;
2019-04-03 16:21:00 +08:00
}
2019-04-03 18:09:00 +08:00
public boolean isOnShelf() {
return isOnShelf;
}
2019-04-03 16:21:00 +08:00
2019-04-03 18:09:00 +08:00
public void setOnShelf(boolean onShelf) {
isOnShelf = onShelf;
}
2019-04-03 16:21:00 +08:00
2019-04-03 18:09:00 +08:00
public boolean isFinished() {
return isFinished;
}
2019-04-03 16:21:00 +08:00
2019-04-03 18:09:00 +08:00
public void setFinished(boolean finished) {
isFinished = finished;
}
2019-04-06 23:04:42 +08:00
public boolean isLocalBook(){
return novelId==0;
2019-04-06 23:04:42 +08:00
}
public static Novel getNovelBySvrId(int novelId){
2019-04-06 23:04:42 +08:00
List<Novel> nvs = LitePal.where("novelId=?",novelId+"").limit(1).find(Novel.class);
2019-04-06 23:04:42 +08:00
if(nvs.size()>0){
return nvs.get(0);
}
return null;
}
public static List<Novel> getNovelsOnShelf(){
2019-05-21 23:30:59 +08:00
// return LitePal.where("isOnShelf=?","1").order("isTop desc,isUpdated desc,lastVisit desc,lastUpdateTime desc" ).find(Novel.class);
return LitePal.where("isOnShelf=?","1").order("isTop desc,lastUpdateTime desc" ).find(Novel.class);
2019-04-06 23:04:42 +08:00
}
public static List<Novel> getLocalNovels(){
return LitePal.where("novelPath !=? ","").find(Novel.class);
}
2019-04-10 22:19:06 +08:00
public static List<Novel> getNovelsHistory(){
2019-04-10 22:19:06 +08:00
return LitePal.where("lastVisit>0").order("lastVisit desc").limit(50).find(Novel.class);
2019-04-10 22:19:06 +08:00
}
2019-04-10 22:19:06 +08:00
/**
* 有没有新的更新
* @return
*/
/* public boolean isUpdated(){
return lastUpdateTime2 >0 && lastUpdateTime > lastUpdateTime2;
}
*/
private void setValues(){
lastVisit = new Date().getTime();
}
@Override
public boolean save(){
setValues();
return super.save();
}
@Override
public int update(long id){
setValues();
checkAndUpdate();
Log.d("checkshelf", String.format("checkshelf:novel %s going to update,isUpdated %s", getName() ,isUpdated));
/* try {
throw new Exception("check update");
}catch (Exception e){
Log.e("checkshelf", "checkshelf ", e);
}*/
try {
2019-05-21 23:30:59 +08:00
return super.update(id);
}catch (Exception e){
Log.e("NOVELDB", "update:error ", e);
}
return 0;
}
2019-05-03 00:30:48 +08:00
public void testUpdate(){
isUpdated=true;
super.update(id);
}
public int checkAndUpdate(){
Novel nv = getNovelBySvrId(novelId);
2019-05-03 00:30:48 +08:00
/* if(lastUpdateTime > nv.lastVisit && lastUpdateTime > nv.lastUpdateTime){
isUpdated =true;
2019-05-03 00:30:48 +08:00
}*/
2019-06-13 00:37:00 +08:00
isUpdated =lastUpdateTime > nv.lastVisit || lastUpdateTime > nv.lastUpdateTime;
2019-05-03 00:30:48 +08:00
Log.d("Novel", String.format("book %s server lastUpdateTime %s, local lastupdatetime %s, local lastvist %s" +
"is updated %s,diff1 %s,diff2 %s"
2019-06-13 00:37:00 +08:00
,name ,lastUpdateTime,nv.lastUpdateTime,nv.lastVisit,isUpdated,
lastUpdateTime - nv.lastVisit,
lastUpdateTime - nv.lastUpdateTime) );
2019-05-03 00:30:48 +08:00
if(!isUpdated){
setToDefault("isUpdated");
}
2019-05-03 00:30:48 +08:00
return super.update(nv.id);
}
public int getMaxAge(){
int maxAge = Constants.MAXAGE_MULU;
if( isFinished){
maxAge =Constants.MAXAGE_MAX;
}else if(isUpdated){
maxAge = 0;
}
return maxAge; // return 0;// maxAge;
}
2019-04-03 16:21:00 +08:00
}