重新定义本地db类
This commit is contained in:
parent
9a20761209
commit
9ad85f7c2e
|
@ -17,7 +17,7 @@ import android.widget.Button;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.netsubscribe.MovieSubscribe;
|
||||
import com.novelbook.android.netutils.OnSuccessAndFaultListener;
|
||||
import com.novelbook.android.netutils.OnSuccessAndFaultSub;
|
||||
|
@ -73,7 +73,7 @@ public abstract class Activity_base extends AppCompatActivity {
|
|||
|
||||
protected abstract void initData() ;
|
||||
|
||||
protected BookListAdapter getBookListAdapter(List<Book> mDatas){
|
||||
protected BookListAdapter getBookListAdapter(List<Novel> mDatas){
|
||||
BookListAdapter mAdapter = new BookListAdapter(this ,mDatas,R.layout.recycle_list_item_horizon,new OnItemClickListener()
|
||||
{
|
||||
|
||||
|
@ -113,15 +113,15 @@ public abstract class Activity_base extends AppCompatActivity {
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
protected List<Book> getFakeData(int max ){
|
||||
List<Book> mDatas = new ArrayList<Book>();
|
||||
protected List<Novel> getFakeData(int max ){
|
||||
List<Novel> mDatas = new ArrayList<Novel>();
|
||||
for (int i = 0; i <max; i++)
|
||||
{
|
||||
Book bk = new Book();
|
||||
Novel bk = new Novel();
|
||||
bk.setAuthor("金庸");
|
||||
bk.setBookname("射雕英雄传" +(char)i);
|
||||
bk.setCate("武侠");
|
||||
bk.setDesc("南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事");
|
||||
bk.setNovelName("射雕英雄传" +(char)i);
|
||||
bk.setNovelType("武侠");
|
||||
bk.setDescription("南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事");
|
||||
mDatas.add(bk);
|
||||
}
|
||||
return mDatas;
|
||||
|
|
|
@ -11,7 +11,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.db.BookDan;
|
||||
import com.novelbook.android.utils.OnItemClickListener;
|
||||
|
||||
|
@ -26,7 +26,7 @@ public class Activity_createShudan extends Activity_base {
|
|||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar ;
|
||||
BookListAdapter mAdapter;
|
||||
private List<Book> mData;
|
||||
private List<Novel> mData;
|
||||
@Override
|
||||
public int getLayoutRes() {
|
||||
return R.layout.activity_create_shudan;
|
||||
|
@ -104,14 +104,14 @@ public class Activity_createShudan extends Activity_base {
|
|||
|
||||
@Override
|
||||
protected void initData() {
|
||||
mData = new ArrayList<Book>();
|
||||
mData = new ArrayList<Novel>();
|
||||
for (int i = 0; i <5; i++)
|
||||
{
|
||||
Book bk = new Book ();
|
||||
Novel bk = new Novel ();
|
||||
bk.setAuthor("金庸" +i);
|
||||
bk.setBookname("射雕" +(char)i);
|
||||
bk.setCate("cate" +i);
|
||||
bk.setDesc(" 南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事");
|
||||
bk.setNovelName("射雕" +(char)i);
|
||||
bk.setNovelType("cate" +i);
|
||||
bk.setDescription(" 南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事");
|
||||
mData .add(bk);
|
||||
}
|
||||
|
||||
|
@ -136,11 +136,11 @@ public class Activity_createShudan extends Activity_base {
|
|||
private final int IMAGE_VIEW = 3;
|
||||
|
||||
private Context context;
|
||||
private List<Book> mDatas = new ArrayList<Book>();
|
||||
private List<Novel> mDatas = new ArrayList<Novel>();
|
||||
private OnItemClickListener mOnItemClickListener;
|
||||
private int listItemID;
|
||||
|
||||
public BookListAdapter(Context context, List<Book> mDatas, int listItemID, OnItemClickListener clicklistener) {
|
||||
public BookListAdapter(Context context, List<Novel> mDatas, int listItemID, OnItemClickListener clicklistener) {
|
||||
this.context = context;
|
||||
this.mDatas = mDatas;
|
||||
this.mOnItemClickListener = clicklistener;
|
||||
|
@ -173,7 +173,7 @@ public class Activity_createShudan extends Activity_base {
|
|||
}
|
||||
|
||||
|
||||
public void setParameters(List<Book> mDatas, int listItemID) {
|
||||
public void setParameters(List<Novel> mDatas, int listItemID) {
|
||||
this.mDatas = mDatas;
|
||||
this.listItemID = listItemID;
|
||||
}
|
||||
|
@ -185,10 +185,10 @@ public class Activity_createShudan extends Activity_base {
|
|||
@Override
|
||||
public void onBindViewHolder(MyViewHolder holder, int position) {
|
||||
|
||||
holder.tvTitle.setText(mDatas.get(position).getBookname());
|
||||
holder.tvTitle.setText(mDatas.get(position).getNovelName());
|
||||
holder.tvAuthor.setText(mDatas.get(position).getAuthor());
|
||||
holder.tvCate.setText(mDatas.get(position).getCate());
|
||||
holder.tvDesc.setText(mDatas.get(position).getDesc());
|
||||
holder.tvCate.setText(mDatas.get(position).getNovelType());
|
||||
holder.tvDesc.setText(mDatas.get(position).getDescription());
|
||||
|
||||
|
||||
// 如果设置了回调,则设置点击事件
|
||||
|
|
|
@ -4,13 +4,13 @@ import android.support.v7.widget.LinearLayoutManager;
|
|||
|
||||
|
||||
import com.novelbook.android.adapter.BookListAdapter;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Activity_shudan extends Activity_base {
|
||||
|
||||
private List<Book> mData;
|
||||
private List<Novel> mData;
|
||||
private BookListAdapter mAdapter;
|
||||
@Override
|
||||
public int getLayoutRes() {
|
||||
|
|
|
@ -5,28 +5,41 @@ import android.content.DialogInterface;
|
|||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.novelbook.android.adapter.BookListAdapter;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.netsubscribe.MovieSubscribe;
|
||||
import com.novelbook.android.netutils.HttpMethods;
|
||||
import com.novelbook.android.netutils.OnSuccessAndFaultListener;
|
||||
import com.novelbook.android.netutils.OnSuccessAndFaultSub;
|
||||
import com.novelbook.android.utils.NovelParseUtil;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.litepal.LitePal;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
public class BookActivity extends Activity_base {
|
||||
|
||||
static String TAG = BookActivity.class.getSimpleName();
|
||||
BookListAdapter mAdapter;
|
||||
// private BookListAdapter mAdapter;
|
||||
private List<Book> mData;;
|
||||
private List<Novel> mData;;
|
||||
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
@ -77,7 +90,8 @@ public class BookActivity extends Activity_base {
|
|||
|
||||
switch (view.getId()) {
|
||||
case R.id.btnRead:
|
||||
openBook(new Book() );
|
||||
testBook();
|
||||
// openBook(new Novel() );
|
||||
break;
|
||||
case R.id.btnCacheBook:
|
||||
cachBook();
|
||||
|
@ -103,11 +117,11 @@ public class BookActivity extends Activity_base {
|
|||
},BookActivity.this));
|
||||
}
|
||||
|
||||
void openBook(Book book ) {
|
||||
void openBook(Novel book ) {
|
||||
|
||||
final String path = book.getBookpath();
|
||||
final String path = book.getNovelPath();
|
||||
if(null ==path) {
|
||||
List<Book> bookLists = LitePal.findAll(Book.class);
|
||||
List<Novel> bookLists = LitePal.findAll(Novel.class);
|
||||
if(bookLists.size()>0) {
|
||||
openBook(bookLists.get(0) );
|
||||
}
|
||||
|
@ -123,7 +137,7 @@ public class BookActivity extends Activity_base {
|
|||
.setPositiveButton("删除", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
LitePal.deleteAll(Book.class, "bookpath = ?", path);
|
||||
LitePal.deleteAll(Novel.class, "bookpath = ?", path);
|
||||
|
||||
}
|
||||
}).setCancelable(true).show();
|
||||
|
@ -133,6 +147,88 @@ public class BookActivity extends Activity_base {
|
|||
|
||||
}
|
||||
|
||||
void testBook(){
|
||||
|
||||
String url = "https://www.qu.la/book/161/";//"https://www.qu.la/book/746/";
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
// .header("User-Agent", "OkHttp Example")
|
||||
.build();
|
||||
HttpMethods.getOkClient().newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
Log.d(TAG, "onFailure: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response){
|
||||
ResponseBody body = response.body();
|
||||
if (body != null) {
|
||||
|
||||
try {
|
||||
String bodyStr = body.string();
|
||||
Log.d(TAG, "onResponse: " +bodyStr);
|
||||
onResponseProcess(bodyStr,url);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
body.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void onResponseProcess( String content ,String url){
|
||||
// HttpResult result ;
|
||||
// HttpResult result2 = null;
|
||||
try {
|
||||
|
||||
|
||||
JSONObject siteJson = new JSONObject();
|
||||
siteJson.put("chapterUrlRegexOnMulu", "");
|
||||
siteJson.put("chapterUrlPattern", "/book/[\\d]+/[\\d]+\\.html$");
|
||||
|
||||
/*
|
||||
String[] chapters = NovelParseUtil.getChapters(url, content, siteJson);
|
||||
|
||||
|
||||
if (chapters != null) {
|
||||
for (int i = 0; i < chapters.length; i += 2) {
|
||||
Log.d(TAG,String.format("%s-->%s", chapters[i], chapters[i+1]));
|
||||
}
|
||||
}
|
||||
*/
|
||||
siteJson.put("chapterUrlRegexOnMulu", "<dd> <a[^>]*href=\"(/book/[\\d]+/[\\d]+\\.html)\">([^<]+)</a></dd>");
|
||||
String[] chapters2 = NovelParseUtil.getChapters(url, content, siteJson);
|
||||
if (chapters2 != null) {
|
||||
for (int i = 0; i < chapters2.length; i += 2) {
|
||||
Log.d(TAG, String.format("%s-->%s", chapters2[i], chapters2[i + 1]));
|
||||
}
|
||||
siteJson.put("chapterContentRegex", "<div id=\"content\">([\\s\\S]+?)</div>");
|
||||
siteJson.put("chapterContentDumpRegex", "<script>chaptererror();</script>");
|
||||
|
||||
|
||||
for (int i = 0; i < chapters2.length; i += 2) {
|
||||
Request request = new Request.Builder()
|
||||
.url(chapters2[i])
|
||||
// .header("User-Agent", "OkHttp Example")
|
||||
.build();
|
||||
Response response = HttpMethods.getOkClient().newCall(request).execute();
|
||||
// Log.d(TAG,String.format("%s-->%s\n%s" , chapters2[i], chapters2[i+1] , NovelParseUtil.getChapterContent(response.body().string(), siteJson)));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// result.close();
|
||||
// if (result2 != null) result2.close();
|
||||
}
|
||||
}
|
||||
|
||||
//----------------绑定列表
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ import android.widget.ListView;
|
|||
import android.widget.Toast;
|
||||
|
||||
import com.novelbook.android.adapter.FileAdapter;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.utils.FileUtils;
|
||||
import com.novelbook.android.utils.Fileutil;
|
||||
import org.litepal.LitePal;
|
||||
|
@ -153,12 +153,12 @@ public class FileActivity extends Activity_base {
|
|||
private void saveBookList(){
|
||||
List<File> files = adapter.getCheckFiles();
|
||||
if (files.size() > 0) {
|
||||
List<Book> bookLists = new ArrayList<Book>();
|
||||
List<Novel> bookLists = new ArrayList<Novel>();
|
||||
for (File file : files) {
|
||||
Book bookList = new Book();
|
||||
Novel bookList = new Novel();
|
||||
String bookName = Fileutil.getFileNameNoEx(file.getName());
|
||||
bookList.setBookname(bookName);
|
||||
bookList.setBookpath(file.getAbsolutePath());
|
||||
bookList.setNovelName(bookName);
|
||||
bookList.setNovelPath(file.getAbsolutePath());
|
||||
bookLists.add(bookList);
|
||||
}
|
||||
mSaveBookToSqlLiteTask = new SaveBookToSqlLiteTask();
|
||||
|
@ -166,17 +166,17 @@ public class FileActivity extends Activity_base {
|
|||
}
|
||||
}
|
||||
|
||||
private class SaveBookToSqlLiteTask extends AsyncTask<List<Book>,Void,Integer>{
|
||||
private class SaveBookToSqlLiteTask extends AsyncTask<List<Novel>,Void,Integer>{
|
||||
private static final int FAIL = 0;
|
||||
private static final int SUCCESS = 1;
|
||||
private static final int REPEAT = 2;
|
||||
private Book repeatBookList;
|
||||
private Novel repeatBookList;
|
||||
|
||||
@Override
|
||||
protected Integer doInBackground(List<Book>... params) {
|
||||
List<Book> bookLists = params[0];
|
||||
for (Book bookList : bookLists){
|
||||
List<Book> books = LitePal.where("bookpath = ?", bookList.getBookpath()).find(Book.class);
|
||||
protected Integer doInBackground(List<Novel>... params) {
|
||||
List<Novel> bookLists = params[0];
|
||||
for (Novel bookList : bookLists){
|
||||
List<Novel> books = LitePal.where("bookpath = ?", bookList.getNovelPath()).find(Novel.class);
|
||||
if (books.size() > 0){
|
||||
repeatBookList = bookList;
|
||||
return REPEAT;
|
||||
|
@ -206,7 +206,7 @@ public class FileActivity extends Activity_base {
|
|||
adapter.cancel();
|
||||
break;
|
||||
case REPEAT:
|
||||
msg = "书本" + repeatBookList.getBookname() + "重复了";
|
||||
msg = "书本" + repeatBookList.getNovelName() + "重复了";
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ import com.novelbook.android.BookActivity;
|
|||
import com.novelbook.android.R;
|
||||
import com.novelbook.android.ReadActivity;
|
||||
import com.novelbook.android.adapter.BookListAdapter;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.utils.OnItemClickListener;
|
||||
|
||||
import org.litepal.LitePal;
|
||||
|
@ -112,16 +112,16 @@ public abstract class BasicFragment extends Fragment {
|
|||
}
|
||||
*/
|
||||
|
||||
protected List<Book> initData(List<Book> mDatas, char x)
|
||||
protected List<Novel> initData(List<Novel> mDatas, char x)
|
||||
{
|
||||
mDatas = new ArrayList<Book>();
|
||||
mDatas = new ArrayList<Novel>();
|
||||
for (int i = 'A'; i < x; i++)
|
||||
{
|
||||
Book bk = new Book();
|
||||
Novel bk = new Novel();
|
||||
bk.setAuthor("金庸");
|
||||
bk.setBookname("射雕英雄传" +(char)i);
|
||||
bk.setCate("武侠");
|
||||
bk.setDesc("南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事");
|
||||
bk.setNovelName("射雕英雄传" +(char)i);
|
||||
bk.setNovelType("武侠");
|
||||
bk.setDescription("南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事南宋时期的武林故事");
|
||||
mDatas.add(bk);
|
||||
}
|
||||
return mDatas;
|
||||
|
@ -134,20 +134,20 @@ public abstract class BasicFragment extends Fragment {
|
|||
}
|
||||
|
||||
|
||||
void openBook(Book book, BookListAdapter mAdapter) {
|
||||
void openBook(Novel book, BookListAdapter mAdapter) {
|
||||
|
||||
//从新从数据库抓取该书的最新阅读进度
|
||||
|
||||
Book book1 = (Book)LitePal.find(Book.class,book.getId());
|
||||
Novel book1 = (Novel)LitePal.find(Novel.class,book.getId());
|
||||
if(book1!=null) { //读取本地最新进度
|
||||
book.setBegin(book1.getBegin());
|
||||
book.setBiginChapt(book1.getBiginChapt());
|
||||
book.setLastReadPos(book1.getLastReadPos());
|
||||
book.setLastReadChapt(book1.getLastReadChapt());
|
||||
}
|
||||
Toast.makeText(activity, book.getBookname() + "加载", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(activity, book.getNovelName() + "加载", Toast.LENGTH_SHORT).show();
|
||||
|
||||
final String path = book.getBookpath();
|
||||
final String path = book.getNovelPath();
|
||||
if(null ==path) {
|
||||
List<Book> bookLists = LitePal.findAll(Book.class);
|
||||
List<Novel> bookLists = LitePal.findAll(Novel.class);
|
||||
if(bookLists.size()>0) {
|
||||
openBook(bookLists.get(0),null);
|
||||
}
|
||||
|
@ -161,8 +161,8 @@ public abstract class BasicFragment extends Fragment {
|
|||
.setPositiveButton("删除", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
LitePal.deleteAll(Book.class, "bookpath = ?", path);
|
||||
if(mAdapter!=null) {mAdapter.setBookList( LitePal.findAll(Book.class));}
|
||||
LitePal.deleteAll(Novel.class, "bookpath = ?", path);
|
||||
if(mAdapter!=null) {mAdapter.setBookList( LitePal.findAll(Novel.class));}
|
||||
}
|
||||
}).setCancelable(true).show();
|
||||
return;
|
||||
|
|
|
@ -10,7 +10,7 @@ import android.widget.ListView;
|
|||
|
||||
import com.novelbook.android.R;
|
||||
import com.novelbook.android.adapter.CatalogueAdapter;
|
||||
import com.novelbook.android.db.BookChapter;
|
||||
import com.novelbook.android.db.Chapter;
|
||||
import com.novelbook.android.utils.PageFactory;
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ public class CatalogFragment extends BasicFragment {
|
|||
public static final String ARGUMENT = "argument";
|
||||
|
||||
private PageFactory pageFactory;
|
||||
ArrayList<BookChapter> catalogueList = new ArrayList<>();
|
||||
ArrayList<Chapter> catalogueList = new ArrayList<>();
|
||||
|
||||
@BindView(R.id.lv_catalogue)
|
||||
ListView lv_catalogue;
|
||||
|
|
|
@ -22,7 +22,7 @@ import android.widget.TextView;
|
|||
|
||||
import com.novelbook.android.Main2Activity;
|
||||
import com.novelbook.android.R;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
|
||||
import com.novelbook.android.filechooser.FileChooserActivity;
|
||||
import com.novelbook.android.utils.OnItemClickListener;
|
||||
|
@ -52,10 +52,10 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
LinearLayout llShelfBottom;
|
||||
@BindView(R.id.id_recyclerview)
|
||||
RecyclerView mRecyclerView;
|
||||
// private List<Book> mDatas;
|
||||
// private List<Novel> mDatas;
|
||||
private BookListAdapter mAdapter;
|
||||
|
||||
private List<Book> bookLists;
|
||||
private List<Novel> bookLists;
|
||||
// private ShelfAdapter adapter;
|
||||
|
||||
public Fragment_Shelf() {
|
||||
|
@ -85,7 +85,7 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
flag = new boolean[100];
|
||||
// mDatas = initData(mDatas,'X');
|
||||
|
||||
bookLists = LitePal.findAll(Book.class);
|
||||
bookLists = LitePal.findAll(Novel.class);
|
||||
|
||||
|
||||
|
||||
|
@ -95,7 +95,7 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
@Override
|
||||
public void onItemClick(View view, int position)
|
||||
{
|
||||
Book book = bookLists.get(position);
|
||||
Novel book = bookLists.get(position);
|
||||
|
||||
openBook(book,mAdapter);
|
||||
|
||||
|
@ -128,7 +128,7 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
if(hidden){
|
||||
//pause
|
||||
}else{
|
||||
bookLists = LitePal.findAll(Book.class);
|
||||
bookLists = LitePal.findAll(Novel.class);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (isVisibleToUser) {
|
||||
//相当于Fragment的onResume,为true时,Fragment已经可见
|
||||
bookLists = LitePal.findAll(Book.class);
|
||||
bookLists = LitePal.findAll(Novel.class);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
//相当于Fragment的onPause,为false时,Fragment不可见
|
||||
|
@ -187,7 +187,7 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
}
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data){
|
||||
// bookLists = LitePal.findAll(Book.class);
|
||||
// bookLists = LitePal.findAll(Novel.class);
|
||||
// mAdapter.notifyDataSetChanged();
|
||||
initViews();
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
.setBackgroundColor(getResources().getColor(android.R.color.transparent));
|
||||
|
||||
TextView tv =(TextView) bottomSheetDialog.findViewById(R.id.bdTitle);
|
||||
tv.setText(bookLists.get(position).getBookname());
|
||||
tv.setText(bookLists.get(position).getNovelName());
|
||||
|
||||
bottomSheetDialog.show();
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
// bookLists = LitePal.findAll(Book.class);
|
||||
// bookLists = LitePal.findAll(Novel.class);
|
||||
// mAdapter.notifyDataSetChanged();
|
||||
// synchronized (mAdapter) {
|
||||
|
||||
|
@ -348,10 +348,10 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
private final int IMAGE_VIEW = 3;
|
||||
|
||||
private Context context;
|
||||
private List<Book> mDatas = new ArrayList<Book>();
|
||||
private List<Novel> mDatas = new ArrayList<Novel>();
|
||||
private OnItemClickListener mOnItemClickListener;
|
||||
private int listItemID;
|
||||
public CheckAdapter(Context context,List<Book> mDatas,int listItemID,OnItemClickListener clickLitener) {
|
||||
public CheckAdapter(Context context,List<Novel> mDatas,int listItemID,OnItemClickListener clickLitener) {
|
||||
this.context = context;
|
||||
this.mDatas = mDatas;
|
||||
this.mOnItemClickListener = clickLitener;
|
||||
|
@ -385,7 +385,7 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
|
||||
|
||||
|
||||
public void setParameters(List<Book> mDatas,int listItemID ) {
|
||||
public void setParameters(List<Novel> mDatas,int listItemID ) {
|
||||
this.mDatas = mDatas;
|
||||
this.listItemID = listItemID;
|
||||
}
|
||||
|
@ -399,10 +399,10 @@ public class Fragment_Shelf extends BasicFragment {
|
|||
public void onBindViewHolder(MyViewHolder holder, int position)
|
||||
{
|
||||
|
||||
holder.tvTitle.setText(mDatas.get(position).getBookname());
|
||||
holder.tvTitle.setText(mDatas.get(position).getNovelName());
|
||||
if(holder.tvAuthor!=null) holder.tvAuthor.setText(mDatas.get(position).getAuthor());
|
||||
if(holder.tvCate!=null) holder.tvCate.setText(mDatas.get(position).getCate());
|
||||
if(holder.tvDesc!=null) holder.tvDesc.setText(mDatas.get(position).getDesc());
|
||||
if(holder.tvCate!=null) holder.tvCate.setText(mDatas.get(position).getNovelType());
|
||||
if(holder.tvDesc!=null) holder.tvDesc.setText(mDatas.get(position).getDescription());
|
||||
if(holder.checkBox!=null) holder.checkBox.setVisibility(View.VISIBLE);
|
||||
// 如果设置了回调,则设置点击事件
|
||||
if (mOnItemClickListener != null)
|
||||
|
|
|
@ -6,7 +6,7 @@ import android.support.v7.widget.RecyclerView;
|
|||
import android.view.View;
|
||||
|
||||
import com.novelbook.android.R;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.utils.BandanAdapter;
|
||||
import com.novelbook.android.utils.OnItemClickListener;
|
||||
|
||||
|
@ -21,7 +21,7 @@ public class Fragment_bangdan extends BasicFragment {
|
|||
private static final String ARG_PARAM1 = "param1";
|
||||
private static final String ARG_PARAM2 = "param2";
|
||||
private BandanAdapter mAdapter;
|
||||
private List<Book> mData;
|
||||
private List<Novel> mData;
|
||||
@BindView(R.id.rvBangdan)
|
||||
RecyclerView rvBandan;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import android.view.View;
|
|||
import android.widget.Toast;
|
||||
|
||||
import com.novelbook.android.R;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.utils.OnItemClickListener;
|
||||
import com.novelbook.android.adapter.BookListAdapter;
|
||||
|
||||
|
@ -19,7 +19,7 @@ import butterknife.BindView;
|
|||
public class Fragment_booklist extends BasicFragment {
|
||||
private BookListAdapter mAdapter;
|
||||
// private BookListAdapter mAdapter;
|
||||
private List<Book> mData;;
|
||||
private List<Novel> mData;;
|
||||
|
||||
@BindView(R.id.rvBooklist)
|
||||
RecyclerView rvBooklist;
|
||||
|
|
|
@ -14,7 +14,7 @@ import android.widget.LinearLayout;
|
|||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.novelbook.android.R;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.utils.CyclePageIndicator;
|
||||
import com.novelbook.android.utils.MyViewPager;
|
||||
import com.novelbook.android.utils.OnItemClickListener;
|
||||
|
@ -238,7 +238,7 @@ public class Fragment_jingxuan extends BasicFragment implements OnBannerListener
|
|||
//---------------------------------------------------book cate list-------------------------------begin
|
||||
|
||||
// private BookListAdapter mAdapter;
|
||||
private List<Book> mHotNewData_l,mHotNewData_g,mHotLianZaiData_l, mHotLianZaiData_g,mFinishedData_l, mFinishedData_g;
|
||||
private List<Novel> mHotNewData_l,mHotNewData_g,mHotLianZaiData_l, mHotLianZaiData_g,mFinishedData_l, mFinishedData_g;
|
||||
|
||||
@BindView(R.id.rvHotNewL) RecyclerView rvHotNewL;
|
||||
@BindView(R.id.rvHotNewG) RecyclerView rvHotNewG;
|
||||
|
|
|
@ -10,7 +10,7 @@ import android.widget.TextView;
|
|||
import android.widget.Toast;
|
||||
|
||||
import com.novelbook.android.R;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.utils.OnItemClickListener;
|
||||
import com.novelbook.android.adapter.BookListAdapter;
|
||||
import com.flyco.tablayout.CommonTabLayout;
|
||||
|
@ -33,7 +33,7 @@ public class Fragment_paihang extends BasicFragment {
|
|||
private int tab1Pos,tab2Pos,tab3Pos;
|
||||
private BookListAdapter mAdapter;
|
||||
// private BookListAdapter mAdapter;
|
||||
private List<Book> mData;;
|
||||
private List<Novel> mData;;
|
||||
|
||||
@BindView(R.id.rvPaihang)
|
||||
RecyclerView rvPaihang;
|
||||
|
|
|
@ -9,7 +9,7 @@ import android.widget.Toast;
|
|||
|
||||
import com.novelbook.android.R;
|
||||
import com.novelbook.android.adapter.ShudanAdapter;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.db.BookDan;
|
||||
import com.novelbook.android.utils.OnItemClickListener;
|
||||
import com.novelbook.android.adapter.BookListAdapter;
|
||||
|
|
|
@ -11,7 +11,7 @@ import android.view.View;
|
|||
|
||||
import com.astuetz.PagerSlidingTabStrip;
|
||||
import com.novelbook.android.adapter.MyPagerAdapter;
|
||||
import com.novelbook.android.db.BookChapter;
|
||||
import com.novelbook.android.db.Chapter;
|
||||
import com.novelbook.android.utils.FileUtils;
|
||||
import com.novelbook.android.utils.PageFactory;
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class MarkActivity extends Activity_base {
|
|||
private PageFactory pageFactory;
|
||||
private Config config;
|
||||
private Typeface typeface;
|
||||
private ArrayList<BookChapter> catalogueList = new ArrayList<>();
|
||||
private ArrayList<Chapter> catalogueList = new ArrayList<>();
|
||||
private DisplayMetrics dm;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -35,7 +35,7 @@ import com.baidu.tts.client.SpeechError;
|
|||
import com.baidu.tts.client.SpeechSynthesizer;
|
||||
import com.baidu.tts.client.SpeechSynthesizerListener;
|
||||
import com.baidu.tts.client.TtsMode;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.db.BookMarks;
|
||||
import com.novelbook.android.dialog.PageModeDialog;
|
||||
import com.novelbook.android.dialog.SettingDialog;
|
||||
|
@ -102,7 +102,7 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
|
||||
private Config config;
|
||||
private WindowManager.LayoutParams lp;
|
||||
private Book book;
|
||||
private Novel book;
|
||||
private PageFactory pageFactory;
|
||||
private int screenWidth, screenHeight;
|
||||
// popwindow是否显示
|
||||
|
@ -193,7 +193,7 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
}
|
||||
//获取intent中的携带的信息
|
||||
Intent intent = getIntent();
|
||||
book = (Book) intent.getSerializableExtra(EXTRA_BOOK);
|
||||
book = (Novel) intent.getSerializableExtra(EXTRA_BOOK);
|
||||
|
||||
bookpage.setPageMode(config.getPageMode());
|
||||
pageFactory.setPageWidget(bookpage);
|
||||
|
@ -523,9 +523,9 @@ public class ReadActivity extends Activity_base implements SpeechSynthesizerLis
|
|||
}
|
||||
|
||||
|
||||
public static boolean openBook(final Book book, Activity context) {
|
||||
public static boolean openBook(final Novel book, Activity context) {
|
||||
if (book == null){
|
||||
throw new NullPointerException("Book can not be null");
|
||||
throw new NullPointerException("Novel can not be null");
|
||||
}
|
||||
|
||||
Intent intent = new Intent(context, ReadActivity.class);
|
||||
|
|
|
@ -16,7 +16,7 @@ import android.widget.TextView;
|
|||
import android.widget.Toast;
|
||||
|
||||
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
|
@ -6,7 +6,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
|
||||
import com.novelbook.android.utils.OnItemClickListener;
|
||||
|
||||
|
@ -19,13 +19,13 @@ public class BookListAdapter extends RecyclerView.Adapter< MyViewHolder> {
|
|||
private final int IMAGE_VIEW = 3;
|
||||
|
||||
private Context context;
|
||||
private List<Book> mDatas ;
|
||||
private List<Novel> mDatas ;
|
||||
private OnItemClickListener mOnItemClickListener;
|
||||
private int listItemID;
|
||||
|
||||
private List<Book> mBooks;
|
||||
private List<Novel> mBooks;
|
||||
|
||||
public BookListAdapter(Context context, List<Book> mBooks, int listItemID, OnItemClickListener clickLitener) {
|
||||
public BookListAdapter(Context context, List<Novel> mBooks, int listItemID, OnItemClickListener clickLitener) {
|
||||
this.context = context;
|
||||
this.mDatas = mBooks;
|
||||
this.mOnItemClickListener = clickLitener;
|
||||
|
@ -65,11 +65,11 @@ public class BookListAdapter extends RecyclerView.Adapter< MyViewHolder> {
|
|||
return holder;
|
||||
}
|
||||
|
||||
public void setBookList(List<Book> bookLists){
|
||||
public void setBookList(List<Novel> bookLists){
|
||||
this.mDatas = bookLists;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
public void setParameters(List<Book> mDatas, int listItemID) {
|
||||
public void setParameters(List<Novel> mDatas, int listItemID) {
|
||||
this.mDatas = mDatas;
|
||||
this.listItemID = listItemID;
|
||||
}
|
||||
|
@ -80,10 +80,10 @@ public class BookListAdapter extends RecyclerView.Adapter< MyViewHolder> {
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(MyViewHolder holder, int position) {
|
||||
holder.tvTitle.setText(mDatas.get(position).getBookname());
|
||||
holder.tvTitle.setText(mDatas.get(position).getNovelName());
|
||||
if (holder.tvAuthor != null) holder.tvAuthor.setText(mDatas.get(position).getAuthor());
|
||||
if (holder.tvCate != null) holder.tvCate.setText(mDatas.get(position).getCate());
|
||||
if (holder.tvDesc != null) holder.tvDesc.setText(mDatas.get(position).getDesc());
|
||||
if (holder.tvCate != null) holder.tvCate.setText(mDatas.get(position).getNovelType());
|
||||
if (holder.tvDesc != null) holder.tvDesc.setText(mDatas.get(position).getDescription());
|
||||
if(holder.tvNum!=null)holder.tvNum.setText("999");
|
||||
// 如果设置了回调,则设置点击事件
|
||||
if (mOnItemClickListener != null) {
|
||||
|
|
|
@ -10,7 +10,7 @@ import android.widget.TextView;
|
|||
|
||||
import com.novelbook.android.Config;
|
||||
import com.novelbook.android.R;
|
||||
import com.novelbook.android.db.BookChapter;
|
||||
import com.novelbook.android.db.Chapter;
|
||||
|
||||
|
||||
|
||||
|
@ -18,12 +18,12 @@ import java.util.List;
|
|||
|
||||
public class CatalogueAdapter extends BaseAdapter {
|
||||
private Context mContext;
|
||||
private List<BookChapter> bookCatalogueList;
|
||||
private List<Chapter> bookCatalogueList;
|
||||
private Typeface typeface;
|
||||
private Config config;
|
||||
private int currentCharter = 0;
|
||||
|
||||
public CatalogueAdapter(Context context, List<BookChapter> bookCatalogueList) {
|
||||
public CatalogueAdapter(Context context, List<Chapter> bookCatalogueList) {
|
||||
mContext = context;
|
||||
this.bookCatalogueList = bookCatalogueList;
|
||||
config = config.getInstance();
|
||||
|
|
|
@ -13,7 +13,7 @@ import android.widget.TextView;
|
|||
|
||||
import com.novelbook.android.Config;
|
||||
import com.novelbook.android.R;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.view.DragGridListener;
|
||||
import com.novelbook.android.view.DragGridView;
|
||||
|
||||
|
@ -32,14 +32,14 @@ import butterknife.ButterKnife;
|
|||
|
||||
public class ShelfAdapter extends BaseAdapter implements DragGridListener {
|
||||
private Context mContex;
|
||||
private List<Book> bilist;
|
||||
private List<Novel> bilist;
|
||||
private static LayoutInflater inflater = null;
|
||||
private int mHidePosition = -1;
|
||||
private Typeface typeface;
|
||||
protected List<AsyncTask<Void, Void, Boolean>> myAsyncTasks = new ArrayList<>();
|
||||
private int[] firstLocation;
|
||||
private Config config;
|
||||
public ShelfAdapter(Context context, List<Book> bilist){
|
||||
public ShelfAdapter(Context context, List<Novel> bilist){
|
||||
this.mContex = context;
|
||||
this.bilist = bilist;
|
||||
config = Config.getInstance();
|
||||
|
@ -96,7 +96,7 @@ public class ShelfAdapter extends BaseAdapter implements DragGridListener {
|
|||
viewHolder.deleteItem_IB.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
viewHolder.name.setVisibility(View.VISIBLE);
|
||||
String fileName = bilist.get(position).getBookname();
|
||||
String fileName = bilist.get(position).getNovelName();
|
||||
viewHolder.name.setText(fileName);
|
||||
}else {
|
||||
contentView.setVisibility(View.INVISIBLE);
|
||||
|
@ -123,9 +123,9 @@ public class ShelfAdapter extends BaseAdapter implements DragGridListener {
|
|||
@Override
|
||||
public void reorderItems(int oldPosition, int newPosition) {
|
||||
|
||||
Book temp = bilist.get(oldPosition);
|
||||
List<Book> bookLists1 = new ArrayList<>();
|
||||
bookLists1 = LitePal.findAll(Book.class);
|
||||
Novel temp = bilist.get(oldPosition);
|
||||
List<Novel> bookLists1 = new ArrayList<>();
|
||||
bookLists1 = LitePal.findAll(Novel.class);
|
||||
|
||||
int tempId = bookLists1.get(newPosition).getId();
|
||||
// Log.d("oldposotion is",oldPosition+"");
|
||||
|
@ -133,8 +133,8 @@ public class ShelfAdapter extends BaseAdapter implements DragGridListener {
|
|||
if(oldPosition < newPosition){
|
||||
for(int i=oldPosition; i<newPosition; i++){
|
||||
//获得交换前的ID,必须是数据库的真正的ID,如果使用bilist获取id是错误的,因为bilist交换后id是跟着交换的
|
||||
List<Book> bookLists = new ArrayList<>();
|
||||
bookLists = LitePal.findAll(Book.class);
|
||||
List<Novel> bookLists = new ArrayList<>();
|
||||
bookLists = LitePal.findAll(Novel.class);
|
||||
int dataBasesId = bookLists.get(i).getId();
|
||||
Collections.swap(bilist, i, i + 1);
|
||||
|
||||
|
@ -143,8 +143,8 @@ public class ShelfAdapter extends BaseAdapter implements DragGridListener {
|
|||
}
|
||||
}else if(oldPosition > newPosition){
|
||||
for(int i=oldPosition; i>newPosition; i--) {
|
||||
List<Book> bookLists = new ArrayList<>();
|
||||
bookLists = LitePal.findAll(Book.class);
|
||||
List<Novel> bookLists = new ArrayList<>();
|
||||
bookLists = LitePal.findAll(Novel.class);
|
||||
int dataBasesId = bookLists.get(i).getId();
|
||||
|
||||
Collections.swap(bilist, i, i - 1);
|
||||
|
@ -164,14 +164,14 @@ public class ShelfAdapter extends BaseAdapter implements DragGridListener {
|
|||
* @param position
|
||||
* @param bookLists
|
||||
*/
|
||||
public void updateBookPosition (int position,int databaseId,List<Book> bookLists) {
|
||||
Book book = new Book();
|
||||
String bookpath = bookLists.get(position).getBookpath();
|
||||
String bookname = bookLists.get(position).getBookname();
|
||||
book.setBookpath(bookpath);
|
||||
book.setBookname(bookname);
|
||||
book.setBegin(bookLists.get(position).getBegin());
|
||||
book.setBiginChapt(bookLists.get(position).getBiginChapt());
|
||||
public void updateBookPosition (int position,int databaseId,List<Novel> bookLists) {
|
||||
Novel book = new Novel();
|
||||
String bookpath = bookLists.get(position).getNovelPath();
|
||||
String bookname = bookLists.get(position).getNovelName();
|
||||
book.setNovelPath(bookpath);
|
||||
book.setNovelName(bookname);
|
||||
book.setLastReadPos(bookLists.get(position).getLastReadPos());
|
||||
book.setLastReadChapt(bookLists.get(position).getLastReadChapt());
|
||||
book.setCharset(bookLists.get(position).getCharset());
|
||||
//开线程保存改动的数据到数据库
|
||||
//使用litepal数据库框架update时每次只能update一个id中的一条信息,如果相同则不更新。
|
||||
|
@ -195,8 +195,8 @@ public class ShelfAdapter extends BaseAdapter implements DragGridListener {
|
|||
@Override
|
||||
public void removeItem(int deletePosition) {
|
||||
|
||||
String bookpath = bilist.get(deletePosition).getBookpath();
|
||||
LitePal.deleteAll(Book.class, "bookpath = ?", bookpath);
|
||||
String bookpath = bilist.get(deletePosition).getNovelPath();
|
||||
LitePal.deleteAll(Novel.class, "bookpath = ?", bookpath);
|
||||
bilist.remove(deletePosition);
|
||||
// Log.d("删除的书本是", bookpath);
|
||||
|
||||
|
@ -204,7 +204,7 @@ public class ShelfAdapter extends BaseAdapter implements DragGridListener {
|
|||
|
||||
}
|
||||
|
||||
public void setBookList(List<Book> bookLists){
|
||||
public void setBookList(List<Novel> bookLists){
|
||||
this.bilist = bookLists;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
@ -215,15 +215,15 @@ public class ShelfAdapter extends BaseAdapter implements DragGridListener {
|
|||
@Override
|
||||
public void setItemToFirst(int openPosition) {
|
||||
|
||||
List<Book> bookLists1 = new ArrayList<>();
|
||||
bookLists1 = LitePal.findAll(Book.class);
|
||||
List<Novel> bookLists1 = new ArrayList<>();
|
||||
bookLists1 = LitePal.findAll(Novel.class);
|
||||
int tempId = bookLists1.get(0).getId();
|
||||
Book temp = bookLists1.get(openPosition);
|
||||
Novel temp = bookLists1.get(openPosition);
|
||||
// Log.d("setitem adapter ",""+openPosition);
|
||||
if(openPosition!=0) {
|
||||
for (int i = openPosition; i > 0 ; i--) {
|
||||
List<Book> bookListsList = new ArrayList<>();
|
||||
bookListsList = LitePal.findAll(Book.class);
|
||||
List<Novel> bookListsList = new ArrayList<>();
|
||||
bookListsList = LitePal.findAll(Novel.class);
|
||||
int dataBasesId = bookListsList.get(i).getId();
|
||||
|
||||
Collections.swap(bookLists1, i, i - 1);
|
||||
|
@ -233,7 +233,7 @@ public class ShelfAdapter extends BaseAdapter implements DragGridListener {
|
|||
bookLists1.set(0, temp);
|
||||
updateBookPosition(0, tempId, bookLists1);
|
||||
for (int j = 0 ;j<bookLists1.size();j++) {
|
||||
String bookpath = bookLists1.get(j).getBookpath();
|
||||
String bookpath = bookLists1.get(j).getNovelPath();
|
||||
// Log.d("移动到第一位",bookpath);
|
||||
}
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ public class ShelfAdapter extends BaseAdapter implements DragGridListener {
|
|||
* @param databaseId 要更新的数据库的书本ID
|
||||
* @param bookList
|
||||
*/
|
||||
public void upDateBookToSqlite3(final int databaseId,final Book bookList) {
|
||||
public void upDateBookToSqlite3(final int databaseId,final Novel bookList) {
|
||||
|
||||
putAsyncTask(new AsyncTask<Void, Void, Boolean>() {
|
||||
@Override
|
||||
|
|
|
@ -6,7 +6,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.db.BookDan;
|
||||
import com.novelbook.android.utils.OnItemClickListener;
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class ShudanAdapter extends RecyclerView.Adapter< MyViewHolder> {
|
|||
private OnItemClickListener mOnItemClickListener;
|
||||
private int listItemID;
|
||||
|
||||
private List<Book> mBooks;
|
||||
private List<Novel> mBooks;
|
||||
|
||||
public ShudanAdapter(Context context, List<BookDan> mBooks, int listItemID, OnItemClickListener clickLitener) {
|
||||
this.context = context;
|
||||
|
|
|
@ -1,118 +0,0 @@
|
|||
package com.novelbook.android.db;
|
||||
|
||||
|
||||
import org.litepal.crud.LitePalSupport;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
public class Book extends LitePalSupport implements Serializable{
|
||||
private int id;
|
||||
private int bookId;
|
||||
private String bookname;
|
||||
private String bookpath;
|
||||
private long begin;
|
||||
private long biginChapt=1;
|
||||
private String charset;
|
||||
private String cate;
|
||||
private String author;
|
||||
private String lastChapter;
|
||||
private String desc;
|
||||
private long lastUpdate;
|
||||
|
||||
public int getBookId() {
|
||||
return bookId;
|
||||
}
|
||||
|
||||
public void setBookId(int bookId) {
|
||||
this.bookId = bookId;
|
||||
}
|
||||
public String getCate() {
|
||||
return cate;
|
||||
}
|
||||
|
||||
public void setCate(String cate) {
|
||||
this.cate = cate;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public long getLastUpdate() {
|
||||
return lastUpdate;
|
||||
}
|
||||
|
||||
public void setLastUpdate(long lastUpdate) {
|
||||
this.lastUpdate = lastUpdate;
|
||||
}
|
||||
public String getLastChapter() {
|
||||
return lastChapter;
|
||||
}
|
||||
|
||||
public void setLastChapter(String lastChapter) {
|
||||
this.lastChapter = lastChapter;
|
||||
}
|
||||
|
||||
public String getBookname() {
|
||||
return this.bookname;
|
||||
}
|
||||
|
||||
public void setBookname(String bookname) {
|
||||
this.bookname = bookname;
|
||||
}
|
||||
|
||||
public String getBookpath() {
|
||||
return this.bookpath;
|
||||
}
|
||||
|
||||
public void setBookpath(String bookpath) {
|
||||
this.bookpath = bookpath;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getBegin() {
|
||||
return begin;
|
||||
}
|
||||
|
||||
public void setBegin(long begin) {
|
||||
this.begin = begin;
|
||||
}
|
||||
|
||||
public String getCharset() {
|
||||
return charset;
|
||||
}
|
||||
|
||||
public void setCharset(String charset) {
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public long getBiginChapt() {
|
||||
return biginChapt;
|
||||
}
|
||||
|
||||
public void setBiginChapt(long biginChapt) {
|
||||
this.biginChapt = biginChapt;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -4,53 +4,38 @@ package com.novelbook.android.db;
|
|||
import org.litepal.crud.LitePalSupport;
|
||||
|
||||
|
||||
public class BookChapter extends LitePalSupport {
|
||||
public class Chapter extends LitePalSupport {
|
||||
private int id;
|
||||
private int bookId;
|
||||
private String bookpath;
|
||||
private int novelId;
|
||||
private String novelPath;
|
||||
private String chapterName;
|
||||
private long bookChapterStartPos;
|
||||
private long novelChapterStartPos;
|
||||
private String chapterUrl;
|
||||
private int length;
|
||||
private String chapterPath;
|
||||
|
||||
public String getChapterPath() {
|
||||
return chapterPath;
|
||||
}
|
||||
public void setChapterPath(String chapterPath) {
|
||||
this.chapterPath = chapterPath;
|
||||
}
|
||||
public String getChapterUrl() {
|
||||
return chapterUrl;
|
||||
}
|
||||
public void setChapterUrl(String chapterUrl) {
|
||||
this.chapterUrl = chapterUrl;
|
||||
}
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
public void setLength(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public int getBookId() {
|
||||
return bookId;
|
||||
}
|
||||
public void setBookId(int bookId) {
|
||||
this.bookId = bookId;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getBookpath() {
|
||||
return bookpath;
|
||||
public int getNovelId() {
|
||||
return novelId;
|
||||
}
|
||||
|
||||
public void setBookpath(String bookpath) {
|
||||
this.bookpath = bookpath;
|
||||
public void setNovelId(int novelId) {
|
||||
this.novelId = novelId;
|
||||
}
|
||||
|
||||
public String getNovelPath() {
|
||||
return novelPath;
|
||||
}
|
||||
|
||||
public void setNovelPath(String novelPath) {
|
||||
this.novelPath = novelPath;
|
||||
}
|
||||
|
||||
public String getChapterName() {
|
||||
|
@ -61,12 +46,40 @@ public class BookChapter extends LitePalSupport {
|
|||
this.chapterName = chapterName;
|
||||
}
|
||||
|
||||
public long getBookChapterStartPos() {
|
||||
return bookChapterStartPos;
|
||||
public long getNovelChapterStartPos() {
|
||||
return novelChapterStartPos;
|
||||
}
|
||||
|
||||
public void setBookChapterStartPos(long bookChapterStartPos) {
|
||||
this.bookChapterStartPos = bookChapterStartPos;
|
||||
public void setNovelChapterStartPos(long novelChapterStartPos) {
|
||||
this.novelChapterStartPos = novelChapterStartPos;
|
||||
}
|
||||
|
||||
public String getChapterUrl() {
|
||||
return chapterUrl;
|
||||
}
|
||||
|
||||
public void setChapterUrl(String chapterUrl) {
|
||||
this.chapterUrl = chapterUrl;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public String getChapterPath() {
|
||||
return chapterPath;
|
||||
}
|
||||
|
||||
public void setChapterPath(String chapterPath) {
|
||||
this.chapterPath = chapterPath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
package com.novelbook.android.db;
|
||||
|
||||
|
||||
import org.litepal.crud.LitePalSupport;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
public class Novel extends LitePalSupport implements Serializable{
|
||||
private int id;
|
||||
private String novelId;
|
||||
private String novelName;
|
||||
private String domain;
|
||||
private String muluUrl;
|
||||
private String novelPath;
|
||||
private long lastReadPos;
|
||||
private long lastReadChapt=1;
|
||||
private String charset;
|
||||
private String novelType;
|
||||
private String novelType2;
|
||||
private String author;
|
||||
private String cover;
|
||||
private String lastestChapterName;
|
||||
private String description;
|
||||
private long lastUpateTime;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNovelId() {
|
||||
return novelId;
|
||||
}
|
||||
|
||||
public void setNovelId(String novelId) {
|
||||
this.novelId = novelId;
|
||||
}
|
||||
|
||||
public String getNovelName() {
|
||||
return novelName;
|
||||
}
|
||||
|
||||
public void setNovelName(String novelName) {
|
||||
this.novelName = novelName;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public long getLastReadChapt() {
|
||||
return lastReadChapt;
|
||||
}
|
||||
|
||||
public void setLastReadChapt(long lastReadChapt) {
|
||||
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 getNovelType2() {
|
||||
return novelType2;
|
||||
}
|
||||
|
||||
public void setNovelType2(String novelType2) {
|
||||
this.novelType2 = novelType2;
|
||||
}
|
||||
|
||||
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 String getLastestChapterName() {
|
||||
return lastestChapterName;
|
||||
}
|
||||
|
||||
public void setLastestChapterName(String lastestChapterName) {
|
||||
this.lastestChapterName = lastestChapterName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public long getLastUpateTime() {
|
||||
return lastUpateTime;
|
||||
}
|
||||
|
||||
public void setLastUpateTime(long lastUpateTime) {
|
||||
this.lastUpateTime = lastUpateTime;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -30,7 +30,7 @@ import android.widget.Toast;
|
|||
|
||||
import com.novelbook.android.R;
|
||||
import com.novelbook.android.ReadActivity;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.utils.FileUtils;
|
||||
|
||||
|
||||
|
@ -67,7 +67,7 @@ public class DirectoryFragment extends Fragment implements View.OnClickListener
|
|||
private ArrayList<ListItem> checkItems = new ArrayList<ListItem>();
|
||||
private ArrayList<HistoryEntry> history = new ArrayList<HistoryEntry>();
|
||||
private HashMap<String, ListItem> selectedFiles = new HashMap<String, ListItem>();
|
||||
private List<Book> bookLists;
|
||||
private List<Novel> bookLists;
|
||||
private long sizeLimit = 1024 * 1024 * 1024;
|
||||
|
||||
private String[] chhosefileType = {".txt"};
|
||||
|
@ -177,7 +177,7 @@ public class DirectoryFragment extends Fragment implements View.OnClickListener
|
|||
getActivity().registerReceiver(receiver, filter);
|
||||
}
|
||||
|
||||
// bookLists = LitePal.findAll(Book.class);
|
||||
// bookLists = LitePal.findAll(Novel.class);
|
||||
|
||||
if (fragmentView == null) {
|
||||
fragmentView = inflater.inflate(R.layout.zdocument_select_layout,
|
||||
|
@ -289,7 +289,7 @@ public class DirectoryFragment extends Fragment implements View.OnClickListener
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
bookLists = LitePal.findAll(Book.class);
|
||||
bookLists = LitePal.findAll(Novel.class);
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
@ -317,12 +317,12 @@ public class DirectoryFragment extends Fragment implements View.OnClickListener
|
|||
|
||||
private void addCheckBook(){
|
||||
if (checkItems.size() > 0) {
|
||||
List<Book> bookLists = new ArrayList<Book>();
|
||||
List<Novel> bookLists = new ArrayList<Novel>();
|
||||
for (ListItem item : checkItems) {
|
||||
Book bookList = new Book();
|
||||
Novel bookList = new Novel();
|
||||
String bookName = FileUtils.getFileName(item.thumb);
|
||||
bookList.setBookname(bookName);
|
||||
bookList.setBookpath(item.thumb);
|
||||
bookList.setNovelName(bookName);
|
||||
bookList.setNovelPath(item.thumb);
|
||||
bookLists.add(bookList);
|
||||
}
|
||||
SaveBookToSqlLiteTask mSaveBookToSqlLiteTask = new SaveBookToSqlLiteTask();
|
||||
|
@ -340,8 +340,8 @@ public class DirectoryFragment extends Fragment implements View.OnClickListener
|
|||
break;
|
||||
}
|
||||
}
|
||||
for (Book list : bookLists){
|
||||
if (list.getBookpath().equals(listItem.thumb)){
|
||||
for (Novel list : bookLists){
|
||||
if (list.getNovelPath().equals(listItem.thumb)){
|
||||
isCheck = true;
|
||||
break;
|
||||
}
|
||||
|
@ -353,17 +353,17 @@ public class DirectoryFragment extends Fragment implements View.OnClickListener
|
|||
}
|
||||
}
|
||||
|
||||
private class SaveBookToSqlLiteTask extends AsyncTask<List<Book>,Void,Integer> {
|
||||
private class SaveBookToSqlLiteTask extends AsyncTask<List<Novel>,Void,Integer> {
|
||||
private static final int FAIL = 0;
|
||||
private static final int SUCCESS = 1;
|
||||
private static final int REPEAT = 2;
|
||||
private Book repeatBookList;
|
||||
private Novel repeatBookList;
|
||||
|
||||
@Override
|
||||
protected Integer doInBackground(List<Book>... params) {
|
||||
List<Book> bookLists = params[0];
|
||||
for (Book bookList : bookLists){
|
||||
List<Book> books = LitePal.where("bookpath = ?", bookList.getBookpath()).find(Book.class);
|
||||
protected Integer doInBackground(List<Novel>... params) {
|
||||
List<Novel> bookLists = params[0];
|
||||
for (Novel bookList : bookLists){
|
||||
List<Novel> books = LitePal.where("bookpath = ?", bookList.getNovelPath()).find(Novel.class);
|
||||
if (books.size() > 0){
|
||||
repeatBookList = bookList;
|
||||
return REPEAT;
|
||||
|
@ -390,12 +390,12 @@ public class DirectoryFragment extends Fragment implements View.OnClickListener
|
|||
case SUCCESS:
|
||||
msg = "导入书本成功";
|
||||
checkItems.clear();
|
||||
bookLists = LitePal.findAll(Book.class);
|
||||
bookLists = LitePal.findAll(Novel.class);
|
||||
listAdapter.notifyDataSetChanged();
|
||||
changgeCheckBookNum();
|
||||
break;
|
||||
case REPEAT:
|
||||
msg = "书本" + repeatBookList.getBookname() + "重复了";
|
||||
msg = "书本" + repeatBookList.getNovelName() + "重复了";
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -634,14 +634,14 @@ public class DirectoryFragment extends Fragment implements View.OnClickListener
|
|||
.setMessage(path).setPositiveButton("阅读", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Book bookList = new Book();
|
||||
Novel bookList = new Novel();
|
||||
String bookName = FileUtils.getFileName(path);
|
||||
bookList.setBookname(bookName);
|
||||
bookList.setBookpath(path);
|
||||
bookList.setNovelName(bookName);
|
||||
bookList.setNovelPath(path);
|
||||
|
||||
boolean isSave = false;
|
||||
for (Book book : bookLists){
|
||||
if (book.getBookpath().equals(bookList.getBookpath())){
|
||||
for (Novel book : bookLists){
|
||||
if (book.getNovelPath().equals(bookList.getNovelPath())){
|
||||
isSave = true;
|
||||
}
|
||||
}
|
||||
|
@ -763,8 +763,8 @@ public class DirectoryFragment extends Fragment implements View.OnClickListener
|
|||
|
||||
private boolean isStorage(String path){
|
||||
boolean isStore = false;
|
||||
for (Book bookList : bookLists){
|
||||
if (bookList.getBookpath().equals(path)){
|
||||
for (Novel bookList : bookLists){
|
||||
if (bookList.getNovelPath().equals(path)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,4 +33,7 @@ public interface HttpApi {
|
|||
@Streaming
|
||||
Call<ResponseBody> downloadFile(@Url String fileUrl);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package com.novelbook.android.netsubscribe;
|
||||
|
||||
import com.novelbook.android.netutils.HttpMethods;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.observers.DisposableObserver;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
public class BookSubscribe {
|
||||
public static void getData(int pageNumber, int count, DisposableObserver<ResponseBody> subscriber) {
|
||||
Map<String,Integer> map = new HashMap<>();
|
||||
map.put("start",pageNumber);
|
||||
map.put("count",count);
|
||||
Observable<ResponseBody> observable = HttpMethods.getInstance().getHttpApi().getDataForMap(map);
|
||||
HttpMethods.getInstance().toSubscribe(observable, subscriber);
|
||||
}
|
||||
}
|
|
@ -51,108 +51,14 @@ public class HttpMethods {
|
|||
*/
|
||||
private int RETRY_COUNT = 0;
|
||||
private OkHttpClient.Builder okHttpBuilder;
|
||||
|
||||
private OkHttpClient okHttpClient;
|
||||
//构造方法私有
|
||||
private HttpMethods() {
|
||||
//手动创建一个OkHttpClient并设置超时时间
|
||||
okHttpBuilder = new OkHttpClient.Builder();
|
||||
/**
|
||||
* 设置缓存
|
||||
*/
|
||||
File cacheFile = new File(FileUtils.getDiskCacheDir(MyApp.applicationContext), CACHE_NAME);
|
||||
Cache cache = new Cache(cacheFile, 1024 * 1024 * 50);
|
||||
Interceptor cacheInterceptor = new Interceptor() {
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
if (!NetUtil.isNetworkConnected()) {
|
||||
request = request.newBuilder()
|
||||
.removeHeader("Pragma")
|
||||
.cacheControl(CacheControl.FORCE_CACHE)
|
||||
.build();
|
||||
}
|
||||
Response response = chain.proceed(request);
|
||||
if (NetUtil.isNetworkConnected()) {
|
||||
int maxAge = 60*60;
|
||||
// 有网络时 设置缓存超时时间0个小时
|
||||
response.newBuilder()
|
||||
.removeHeader("Pragma")
|
||||
.header("Cache-Control", "public, max-age=" + maxAge)
|
||||
.removeHeader(CACHE_NAME)// 清除头信息,因为服务器如果不支持,会返回一些干扰信息,不清除下面无法生效
|
||||
.build();
|
||||
} else {
|
||||
// 无网络时,设置超时为4周
|
||||
int maxStale = 60 * 60 * 24 * 28;
|
||||
response.newBuilder()
|
||||
.removeHeader("Pragma")
|
||||
.header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
|
||||
.removeHeader(CACHE_NAME)
|
||||
.build();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
};
|
||||
// okHttpBuilder.cache(cache).addInterceptor(cacheInterceptor);
|
||||
okHttpBuilder.cache(cache) .addNetworkInterceptor(REWRITE_RESPONSE_INTERCEPTOR)
|
||||
.addInterceptor(REWRITE_RESPONSE_INTERCEPTOR_OFFLINE);
|
||||
|
||||
/**
|
||||
* 设置头信息
|
||||
*/
|
||||
Interceptor headerInterceptor = new Interceptor() {
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request originalRequest = chain.request();
|
||||
/* Request.Builder requestBuilder = originalRequest.newBuilder()
|
||||
.addHeader("Accept-Encoding", Locale.getDefault().toString())
|
||||
// .addHeader("Host", "testapi.wujike.com.cn")
|
||||
.addHeader("Connection", "Keep-Alive")
|
||||
.addHeader("Device", "Android")
|
||||
.method(originalRequest.method(), originalRequest.body());
|
||||
*/
|
||||
Request.Builder requestBuilder = originalRequest.newBuilder()
|
||||
// .addHeader("Accept-Encoding", "gzip")
|
||||
.addHeader("Accept-Encoding", Locale.getDefault().toString() )
|
||||
// .addHeader("Accept", "application/json")
|
||||
// .addHeader("Content-Type", "application/json; charset=utf-8")
|
||||
.addHeader("Device", "Android")
|
||||
.removeHeader("User-Agent").addHeader("User-Agent",NetUtil.getUserAgent()) //加 随机agent
|
||||
.method(originalRequest.method(), originalRequest.body());
|
||||
|
||||
// requestBuilder.addHeader("Authorization", "Bearer" + BaseConstant.TOKEN);//添加请求头信息,服务器进行token有效性验证
|
||||
Request request = requestBuilder.build();
|
||||
return chain.proceed(request);
|
||||
}
|
||||
};
|
||||
okHttpBuilder.addInterceptor(headerInterceptor);
|
||||
|
||||
|
||||
// if (BuildConfig.DEBUG) {
|
||||
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
|
||||
@Override
|
||||
public void log(String message) {
|
||||
Log.d(TAG, message);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
//设置 Debug Log 模式
|
||||
okHttpBuilder.addInterceptor(loggingInterceptor);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 设置超时和重新连接
|
||||
*/
|
||||
okHttpBuilder.connectTimeout(DEFAULT_CONNECT_TIMEOUT, TimeUnit.SECONDS);
|
||||
okHttpBuilder.readTimeout(DEFAULT_WRITE_TIMEOUT, TimeUnit.SECONDS);
|
||||
okHttpBuilder.writeTimeout(DEFAULT_READ_TIMEOUT, TimeUnit.SECONDS);
|
||||
//错误重连
|
||||
okHttpBuilder.retryOnConnectionFailure(true);
|
||||
|
||||
|
||||
okHttpClient = getClient();
|
||||
retrofit = new Retrofit.Builder()
|
||||
.client(okHttpBuilder.build())
|
||||
.client(okHttpClient)
|
||||
.addConverterFactory(GsonConverterFactory.create())//json转换成JavaBean
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.baseUrl(BASE_URL)
|
||||
|
@ -164,12 +70,16 @@ public class HttpMethods {
|
|||
private static class SingletonHolder {
|
||||
private static final HttpMethods INSTANCE = new HttpMethods();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//获取单例
|
||||
public static HttpMethods getInstance() {
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
//获取单例
|
||||
public static OkHttpClient getOkClient() {
|
||||
return SingletonHolder.INSTANCE.okHttpClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取retrofit
|
||||
|
@ -199,6 +109,121 @@ public class HttpMethods {
|
|||
return httpApi;
|
||||
}
|
||||
|
||||
|
||||
private OkHttpClient getClient(){
|
||||
//手动创建一个OkHttpClient并设置超时时间
|
||||
okHttpBuilder = new OkHttpClient.Builder();
|
||||
/**
|
||||
* 设置缓存
|
||||
*/
|
||||
File cacheFile = new File(FileUtils.getDiskCacheDir(MyApp.applicationContext), CACHE_NAME);
|
||||
Cache cache = new Cache(cacheFile, 1024 * 1024 * 50);
|
||||
Interceptor cacheInterceptor = new Interceptor() {
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
if (!NetUtil.isNetworkConnected()) {
|
||||
request = request.newBuilder()
|
||||
.removeHeader("Pragma")
|
||||
.cacheControl(CacheControl.FORCE_CACHE)
|
||||
.build();
|
||||
}
|
||||
Response response = chain.proceed(request);
|
||||
if (NetUtil.isNetworkConnected()) {
|
||||
int maxAge = 60*60;
|
||||
// 有网络时 设置缓存超时时间0个小时
|
||||
response.newBuilder()
|
||||
.removeHeader("Pragma")
|
||||
.header("Cache-Control", "public, max-age=" + maxAge)
|
||||
.removeHeader(CACHE_NAME)// 清除头信息,因为服务器如果不支持,会返回一些干扰信息,不清除下面无法生效
|
||||
.build();
|
||||
} else {
|
||||
// 无网络时,设置超时为4周
|
||||
int maxStale = 60 * 60 * 24 * 28;
|
||||
response.newBuilder()
|
||||
.removeHeader("Pragma")
|
||||
.header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
|
||||
.removeHeader(CACHE_NAME)
|
||||
.build();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
};
|
||||
// okHttpBuilder.cache(cache).addInterceptor(cacheInterceptor);
|
||||
okHttpBuilder.cache(cache) .addNetworkInterceptor(REWRITE_RESPONSE_INTERCEPTOR)
|
||||
.addInterceptor(REWRITE_RESPONSE_INTERCEPTOR_OFFLINE);
|
||||
|
||||
/**
|
||||
* 设置头信息
|
||||
*/
|
||||
Interceptor headerInterceptor = new Interceptor() {
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request originalRequest = chain.request();
|
||||
/* Request.Builder requestBuilder = originalRequest.newBuilder()
|
||||
.addHeader("Accept-Encoding", Locale.getDefault().toString())
|
||||
// .addHeader("Host", "testapi.wujike.com.cn")
|
||||
.addHeader("Connection", "Keep-Alive")
|
||||
.addHeader("Device", "Android")
|
||||
.method(originalRequest.method(), originalRequest.body());
|
||||
*/
|
||||
Request.Builder requestBuilder = originalRequest.newBuilder()
|
||||
// .addHeader("Accept-Encoding", "gzip")
|
||||
.addHeader("Accept-Encoding", Locale.getDefault().toString() )
|
||||
// .addHeader("Accept", "application/json")
|
||||
// .addHeader("Content-Type", "application/json; charset=utf-8")
|
||||
.addHeader("Device", "Android")
|
||||
.removeHeader("User-Agent").addHeader("User-Agent",NetUtil.getUserAgent()) //加 随机agent
|
||||
.method(originalRequest.method(), originalRequest.body());
|
||||
|
||||
// requestBuilder.addHeader("Authorization", "Bearer" + BaseConstant.TOKEN);//添加请求头信息,服务器进行token有效性验证
|
||||
Request request = requestBuilder.build();
|
||||
return chain.proceed(request);
|
||||
}
|
||||
};
|
||||
okHttpBuilder.addInterceptor(headerInterceptor);
|
||||
|
||||
|
||||
// if (BuildConfig.DEBUG) {
|
||||
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
|
||||
@Override
|
||||
public void log(String message) {
|
||||
Log.d(TAG, message);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
//设置 Debug Log 模式
|
||||
okHttpBuilder.addInterceptor(loggingInterceptor);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 设置超时和重新连接
|
||||
*/
|
||||
okHttpBuilder.connectTimeout(DEFAULT_CONNECT_TIMEOUT, TimeUnit.SECONDS);
|
||||
okHttpBuilder.readTimeout(DEFAULT_WRITE_TIMEOUT, TimeUnit.SECONDS);
|
||||
okHttpBuilder.writeTimeout(DEFAULT_READ_TIMEOUT, TimeUnit.SECONDS);
|
||||
//错误重连
|
||||
okHttpBuilder.retryOnConnectionFailure(true);
|
||||
return okHttpBuilder.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 设置订阅 和 所在的线程环境
|
||||
*/
|
||||
|
|
|
@ -153,7 +153,7 @@ public class NetUtil {
|
|||
// UCOpenwave
|
||||
"Openwave/ UCWEB7.0.2.37/28/999",
|
||||
// UC Opera
|
||||
"Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999"
|
||||
"Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999",
|
||||
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1",
|
||||
"Mozilla/5.0 (X11; CrOS i686 2268.111.0) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11",
|
||||
|
|
|
@ -9,7 +9,7 @@ import android.widget.LinearLayout;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.novelbook.android.R;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -23,10 +23,10 @@ import butterknife.ButterKnife;
|
|||
private final int IMAGE_VIEW = 3;
|
||||
|
||||
private Context context;
|
||||
private List<Book> mDatas = new ArrayList<Book>();
|
||||
private List<Novel> mDatas = new ArrayList<Novel>();
|
||||
private OnItemClickListener mOnItemClickLitener;
|
||||
private int listItemID;
|
||||
public BandanAdapter(Context context, List<Book> mDatas, int listItemID, OnItemClickListener clickLitener) {
|
||||
public BandanAdapter(Context context, List<Novel> mDatas, int listItemID, OnItemClickListener clickLitener) {
|
||||
this.context = context;
|
||||
this.mDatas = mDatas;
|
||||
this.mOnItemClickLitener = clickLitener;
|
||||
|
@ -60,7 +60,7 @@ import butterknife.ButterKnife;
|
|||
|
||||
|
||||
|
||||
public void setParameters(List<Book> mDatas,int listItemID ) {
|
||||
public void setParameters(List<Novel> mDatas,int listItemID ) {
|
||||
this.mDatas = mDatas;
|
||||
this.listItemID = listItemID;
|
||||
}
|
||||
|
@ -73,22 +73,22 @@ import butterknife.ButterKnife;
|
|||
@Override
|
||||
public void onBindViewHolder(MyViewHolder holder, int position)
|
||||
{
|
||||
holder.tvCateName .setText(mDatas.get(0).getCate());
|
||||
holder.tvCateName .setText(mDatas.get(0).getNovelType());
|
||||
|
||||
holder.tvTitle.setText(mDatas.get(0).getBookname());
|
||||
holder.tvTitle.setText(mDatas.get(0).getNovelName());
|
||||
holder.tvAuthor.setText(mDatas.get(0).getAuthor());
|
||||
holder.tvCate.setText(mDatas.get(0).getCate());
|
||||
holder.tvDesc.setText(mDatas.get(0).getDesc());
|
||||
holder.tvCate.setText(mDatas.get(0).getNovelType());
|
||||
holder.tvDesc.setText(mDatas.get(0).getDescription());
|
||||
|
||||
holder.tvTitle2.setText(mDatas.get(1).getBookname());
|
||||
holder.tvTitle2.setText(mDatas.get(1).getNovelName());
|
||||
holder.tvAuthor2.setText(mDatas.get(1).getAuthor());
|
||||
holder.tvCate2.setText(mDatas.get(1).getCate());
|
||||
holder.tvDesc2.setText(mDatas.get(1).getDesc());
|
||||
holder.tvCate2.setText(mDatas.get(1).getNovelType());
|
||||
holder.tvDesc2.setText(mDatas.get(1).getDescription());
|
||||
|
||||
holder.tvTitle3.setText(mDatas.get(2).getBookname());
|
||||
holder.tvTitle3.setText(mDatas.get(2).getNovelName());
|
||||
holder.tvAuthor3.setText(mDatas.get(2).getAuthor());
|
||||
holder.tvCate3.setText(mDatas.get(2).getCate());
|
||||
holder.tvDesc3.setText(mDatas.get(2).getDesc());
|
||||
holder.tvCate3.setText(mDatas.get(2).getNovelType());
|
||||
holder.tvDesc3.setText(mDatas.get(2).getDescription());
|
||||
|
||||
// 如果设置了回调,则设置点击事件
|
||||
if (mOnItemClickLitener != null)
|
||||
|
|
|
@ -8,8 +8,8 @@ import android.text.TextUtils;
|
|||
import android.util.Log;
|
||||
|
||||
import com.novelbook.android.bean.Cache;
|
||||
import com.novelbook.android.db.BookChapter;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Chapter;
|
||||
import com.novelbook.android.db.Novel;
|
||||
|
||||
|
||||
import org.litepal.LitePal;
|
||||
|
@ -40,7 +40,7 @@ public class BookUtil {
|
|||
public static final String lineBreakChar ="\n";
|
||||
protected final ArrayList<Cache> myArray = new ArrayList<>();
|
||||
//目录
|
||||
private List<BookChapter> directoryList = new ArrayList<>();
|
||||
private List<Chapter> directoryList = new ArrayList<>();
|
||||
|
||||
private String m_strCharsetName;
|
||||
private String bookName;
|
||||
|
@ -52,7 +52,7 @@ public class BookUtil {
|
|||
|
||||
private long bookLen;
|
||||
private long position;
|
||||
private Book book;
|
||||
private Novel book;
|
||||
|
||||
public void setChapterNo(int chapterNo) {
|
||||
this.chapterNo = chapterNo;
|
||||
|
@ -83,24 +83,24 @@ public class BookUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized void openBook(Book book) throws IOException {
|
||||
public synchronized void openBook(Novel book) throws IOException {
|
||||
this.book = book;
|
||||
//如果当前缓存不是要打开的书本就缓存书本同时删除缓存
|
||||
|
||||
//TODO 构建新的缓存策略,几个选项,1:每本书一个缓存 2:控制缓存总大小,超过限制删除旧缓存 3:网络小说的缓存
|
||||
|
||||
directoryList = LitePal.where("bookId=?",book.getId()+"").find(BookChapter.class);
|
||||
directoryList = LitePal.where("bookId=?",book.getId()+"").find(Chapter.class);
|
||||
|
||||
for(BookChapter c :directoryList){
|
||||
for(Chapter c :directoryList){
|
||||
Log.d(TAG, String.format("bookchapter :%s,fileName :%s, chapter Size %s",c.getChapterName(),c.getChapterPath(),c.getLength()));
|
||||
}
|
||||
|
||||
chaptCache = new HashMap<Integer,Cache>();
|
||||
if(directoryList.isEmpty()) {
|
||||
if(directoryList.isEmpty()) { //1. 首次打开 本地导入的书 2. 首次打开 未缓存的在线小说
|
||||
|
||||
if (bookPath == null || !bookPath.equals(book.getBookpath())) {
|
||||
if (bookPath == null || !bookPath.equals(book.getNovelPath())) {
|
||||
cleanCacheFile();
|
||||
this.bookPath = book.getBookpath();
|
||||
this.bookPath = book.getNovelPath();
|
||||
bookName = FileUtils.getFileName(bookPath);
|
||||
cacheBook();
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ public class BookUtil {
|
|||
}
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("charset",m_strCharsetName);
|
||||
LitePal.update(Book.class,values,book.getId());
|
||||
LitePal.update(Novel.class,values,book.getId());
|
||||
}else{
|
||||
m_strCharsetName = book.getCharset();
|
||||
}
|
||||
|
@ -321,7 +321,7 @@ public class BookUtil {
|
|||
long start =0;
|
||||
int chaptFileId=0;
|
||||
|
||||
BookChapter bookChapter = null;
|
||||
Chapter bookChapter = null;
|
||||
OutputStreamWriter writer = null;
|
||||
for (int i = startblk-1; i < endblk; i++) {
|
||||
char[] buf = block(i);
|
||||
|
@ -351,11 +351,11 @@ public class BookUtil {
|
|||
directoryList.add(bookChapter);
|
||||
}
|
||||
|
||||
bookChapter = new BookChapter();
|
||||
bookChapter.setBookId(book.getId());
|
||||
bookChapter.setBookChapterStartPos(start);
|
||||
bookChapter = new Chapter();
|
||||
bookChapter.setNovelId(book.getId());
|
||||
bookChapter.setNovelChapterStartPos(start);
|
||||
bookChapter.setChapterName(str.replaceAll("###",""));
|
||||
bookChapter.setBookpath(bookPath);
|
||||
bookChapter.setNovelPath(bookPath);
|
||||
bookChapter.save();
|
||||
int id= bookChapter.getId();
|
||||
Log.d(TAG,str + " chaptId is " + id);
|
||||
|
@ -375,11 +375,11 @@ public class BookUtil {
|
|||
}
|
||||
|
||||
if(writer==null) {
|
||||
bookChapter = new BookChapter();
|
||||
bookChapter.setBookId(book.getId());
|
||||
bookChapter.setBookChapterStartPos(start);
|
||||
bookChapter = new Chapter();
|
||||
bookChapter.setNovelId(book.getId());
|
||||
bookChapter.setNovelChapterStartPos(start);
|
||||
bookChapter.setChapterName(str.replaceAll("###",""));
|
||||
bookChapter.setBookpath(bookPath);
|
||||
bookChapter.setNovelPath(bookPath);
|
||||
bookChapter.save();
|
||||
writer = new OutputStreamWriter(new FileOutputStream(fileChapterName(++chaptId)), charachterType); //序
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ public class BookUtil {
|
|||
}
|
||||
|
||||
/*
|
||||
BookChapter bookChapter = new BookChapter();
|
||||
Chapter bookChapter = new Chapter();
|
||||
bookChapter.setBookId(book.getId());
|
||||
|
||||
bookChapter.setBookChapterStartPos(start);
|
||||
|
@ -428,7 +428,7 @@ public class BookUtil {
|
|||
|
||||
}
|
||||
|
||||
public List<BookChapter> getDirectoryList(){
|
||||
public List<Chapter> getDirectoryList(){
|
||||
return directoryList;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package com.novelbook.android.utils;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 按照插入顺序排序的Map,当超出容量时,将最早插入的对象移除。
|
||||
*
|
||||
* @param <K>
|
||||
* @param <V>
|
||||
*/
|
||||
public class FIFOMap<K, V> extends LinkedHashMap<K, V> {
|
||||
private static final long serialVersionUID = 27034646516234314L;
|
||||
|
||||
protected int maxSize;
|
||||
public FIFOMap(int maxSize) {
|
||||
super(maxSize, 0.75f, false);
|
||||
this.maxSize = maxSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Entry<K, V> eldest) {
|
||||
return maxSize < size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized V put(K key, V value) {
|
||||
return super.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void putAll(Map<? extends K, ? extends V> m) {
|
||||
super.putAll(m);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized V remove(Object key) {
|
||||
return super.remove(key);
|
||||
}
|
||||
|
||||
public void setCapacity(int size) {
|
||||
maxSize = size;
|
||||
}
|
||||
public int getCapacity() {
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int maxSize = 100;
|
||||
FIFOMap<Integer, Integer> map = new FIFOMap<Integer, Integer>(maxSize);
|
||||
for (int i = 1; i <= maxSize; i++) {
|
||||
map.put(i, i);
|
||||
assertTrue(map.size() == i);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= maxSize; i++) {
|
||||
map.put(i, i);
|
||||
assertTrue(map.size() == maxSize);
|
||||
}
|
||||
|
||||
for (int i = 101; i <= 100 + maxSize; i++) {
|
||||
map.put(i, i);
|
||||
assertTrue(map.size() == maxSize);
|
||||
}
|
||||
for (int i = 191; i <= 100 + maxSize; i++) {
|
||||
map.remove(i);
|
||||
assertTrue(map.size()== maxSize + 190 - i );
|
||||
}
|
||||
|
||||
for (int i = 101; i <= 100 + maxSize; i++) {
|
||||
map.put(i, i);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= 10000 + maxSize; i++) {
|
||||
map.put(i, i);
|
||||
}
|
||||
assertTrue(map.size() == maxSize);
|
||||
}
|
||||
|
||||
private static void assertTrue(boolean flag) {
|
||||
if ( !flag ) System.out.println("should be true. but is false.");
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ import android.util.Log;
|
|||
import android.widget.Toast;
|
||||
|
||||
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Novel;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -255,7 +255,7 @@ public class Fileutil {
|
|||
* @param //本地文件夹路径
|
||||
*/
|
||||
public static List<File> getFileListByPath( String path) {
|
||||
Book bookList = new Book();
|
||||
Novel bookList = new Novel();
|
||||
|
||||
int fileNum = 0 ;
|
||||
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
package com.novelbook.android.utils;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class NovelParseUtil {
|
||||
|
||||
private static final String A_Regex = "<a[^>]+href[\\s]*=[\\s]*['\"]?([^'\"]+)['\"\\s]?[^>]*>([^<]+)<";
|
||||
public static String[] getChapters(String muluUrl, String html, JSONObject siteJson) throws JSONException {
|
||||
String chapterUrlRegexOnMulu = siteJson.getString("chapterUrlRegexOnMulu");
|
||||
String chapterUrlPattern = siteJson.getString("chapterUrlPattern");
|
||||
|
||||
|
||||
Map<String, String> muluMap = new LinkedHashMap<String, String>();
|
||||
String regex = A_Regex;
|
||||
if (!isBlank(chapterUrlRegexOnMulu)) {
|
||||
regex = chapterUrlRegexOnMulu;
|
||||
}
|
||||
|
||||
String[] rows = REUtil.matchs(regex, html);;
|
||||
if (rows == null || rows.length == 0) return null;
|
||||
for (int i = rows.length - 1; i >= 0; i--) {
|
||||
String row = rows[i];
|
||||
String[] parts = REUtil.groups(regex, row);
|
||||
if (parts == null || parts.length == 0) continue;
|
||||
String href = getFullUrl(parts[0], muluUrl);
|
||||
if (muluMap.containsKey(href)) continue;
|
||||
if (isBlank(REUtil.match(chapterUrlPattern, href))) continue;
|
||||
String name = parts[1];
|
||||
muluMap.put(href, name);
|
||||
}
|
||||
|
||||
String[] values = new String[muluMap.size() * 2];
|
||||
|
||||
Set<Map.Entry<String, String>> es = muluMap.entrySet();
|
||||
int pos = values.length - 2;
|
||||
for (Map.Entry<String, String> e : es) {
|
||||
values[pos] = e.getKey();
|
||||
values[pos + 1] = e.getValue();
|
||||
pos -= 2;
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public static String getChapterContent(String html, JSONObject siteJson) throws JSONException {
|
||||
String chapterContentRegex = siteJson.getString("chapterContentRegex");
|
||||
String text = REUtil.group(chapterContentRegex, html, 1);
|
||||
if (isBlank(text)) return "";
|
||||
|
||||
String chapterContentDumpRegex = siteJson.getString("chapterContentDumpRegex");
|
||||
if (!isBlank(chapterContentDumpRegex)) {
|
||||
text = text.replaceAll(chapterContentDumpRegex, "");
|
||||
}
|
||||
text = text.replaceAll("<![^>]+?>", "");
|
||||
// p br --> \n
|
||||
text = text.replaceAll("(?i)<[/]?[\\s]*p[^>]*>|<[/]*br[/ ]*>", "\n");
|
||||
text = text.replaceAll("[']+", "‘");
|
||||
text = text.replaceAll("&#[\\w\\d]+;", "");
|
||||
|
||||
|
||||
text = text.replaceAll("(?i) ", " ");
|
||||
text = text.replaceAll("[ ]{2}", " ");
|
||||
text = text.replaceAll("[ ]{3,}", " ");
|
||||
|
||||
text = text.replaceAll("<<", "<");
|
||||
text = text.replaceAll("&[\\w\\d]{4};", "").replaceAll("[\\w\\d]{4};", "");
|
||||
text = text.replaceAll("(?i)<script[\\s\\S]+</Script>", "")
|
||||
.replaceAll("<[^>]*>", "");
|
||||
|
||||
text = text.replaceAll("\\n[\\s ]+\\n", "\n");
|
||||
if (!text.startsWith(" ")) text = " " + text;
|
||||
|
||||
return text.trim();
|
||||
}
|
||||
|
||||
private static boolean isBlank(String value) {
|
||||
return value == null || "".equals(value);
|
||||
}
|
||||
|
||||
public static String getFullUrl(String url, String referer) {
|
||||
if ( isBlank(referer) ) {
|
||||
if (url.startsWith("//")) {
|
||||
return "http:" + url;
|
||||
} else {
|
||||
return url;
|
||||
}
|
||||
} else if (url.startsWith("//")) {
|
||||
if (referer.toLowerCase().startsWith("https:")) {
|
||||
return "https:" + url;
|
||||
} else {
|
||||
return "http:" + url;
|
||||
}
|
||||
}
|
||||
|
||||
String lowerCaseUrl = url.toLowerCase();
|
||||
if (lowerCaseUrl.startsWith("http://") || lowerCaseUrl.startsWith("https://")) {
|
||||
return url;
|
||||
}
|
||||
if (url.startsWith("/")) {
|
||||
int index = referer.indexOf("/", 8);
|
||||
String host = referer;
|
||||
if (index > -1) {
|
||||
host = referer.substring(0, index);
|
||||
}
|
||||
return host + url;
|
||||
} else {
|
||||
int index = referer.lastIndexOf("/");
|
||||
String prefix = referer;
|
||||
if (index > 7) {
|
||||
prefix = referer.substring(0, index);
|
||||
}
|
||||
return prefix + "/" + url;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,8 +20,8 @@ import android.widget.Toast;
|
|||
|
||||
import com.novelbook.android.Config;
|
||||
import com.novelbook.android.R;
|
||||
import com.novelbook.android.db.BookChapter;
|
||||
import com.novelbook.android.db.Book;
|
||||
import com.novelbook.android.db.Chapter;
|
||||
import com.novelbook.android.db.Novel;
|
||||
import com.novelbook.android.view.PageWidget;
|
||||
|
||||
import org.litepal.LitePal;
|
||||
|
@ -131,12 +131,12 @@ public class PageFactory {
|
|||
//现在的进度
|
||||
private float currentProgress;
|
||||
//目录
|
||||
// private List<BookChapter> directoryList = new ArrayList<>();
|
||||
// private List<Chapter> directoryList = new ArrayList<>();
|
||||
//书本路径
|
||||
private String bookPath = "";
|
||||
//书本名字
|
||||
private String bookName = "";
|
||||
private Book bookList;
|
||||
private Novel mBook;
|
||||
//书本章节
|
||||
private int currentChapter = 0;
|
||||
//当前电量
|
||||
|
@ -345,16 +345,16 @@ public class PageFactory {
|
|||
currentChapter = getCurrentCharter();
|
||||
}
|
||||
//更新数据库进度
|
||||
if (currentPage != null && bookList != null){
|
||||
if (currentPage != null && mBook != null){
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
values.put("begin",currentPage.getBegin());
|
||||
values.put("biginChapt",currentChapter);
|
||||
Log.d(TAG,String.format("begin to update book %s chapter%s bigin %s ",bookList.getBookname(),currentChapter, currentPage.getBegin() ) );
|
||||
int rows = LitePal.update(Book.class,values,bookList.getId());
|
||||
Log.d(TAG,String.format("update book %s chapter%s bigin %s, result %s",bookList.getBookname(),currentChapter, currentPage.getBegin(),rows) );
|
||||
Log.d(TAG,String.format("begin to update book %s chapter%s bigin %s ",mBook.getNovelName(),currentChapter, currentPage.getBegin() ) );
|
||||
int rows = LitePal.update(Novel.class,values,mBook.getId());
|
||||
Log.d(TAG,String.format("update book %s chapter%s bigin %s, result %s",mBook.getNovelName(),currentChapter, currentPage.getBegin(),rows) );
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
@ -498,14 +498,14 @@ public class PageFactory {
|
|||
* 打开书本
|
||||
* @throws IOException
|
||||
*/
|
||||
public void openBook(Book book ) throws IOException {
|
||||
public void openBook(Novel book ) throws IOException {
|
||||
//清空数据
|
||||
currentChapter = 0;
|
||||
// m_mbBufLen = 0;
|
||||
initBg(config.getDayOrNight());
|
||||
|
||||
this.bookList = book ;
|
||||
bookPath = bookList.getBookpath();
|
||||
this.mBook = book ;
|
||||
bookPath = mBook.getNovelPath();
|
||||
bookName = FileUtils.getFileName(bookPath);
|
||||
|
||||
mStatus = Status.OPENING;
|
||||
|
@ -516,7 +516,7 @@ public class PageFactory {
|
|||
}
|
||||
bookTask = new BookTask();
|
||||
|
||||
bookTask.execute(book.getBiginChapt(),book .getBegin());
|
||||
bookTask.execute(book.getLastReadChapt(),book .getLastReadPos());
|
||||
}
|
||||
|
||||
private class BookTask extends AsyncTask<Long,Void,Boolean>{
|
||||
|
@ -564,7 +564,7 @@ public class PageFactory {
|
|||
begin = params[1];
|
||||
currentChapter = (int) chapter;
|
||||
try {
|
||||
mBookUtil.openBook(bookList);
|
||||
mBookUtil.openBook(mBook);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
|
@ -842,7 +842,7 @@ public class PageFactory {
|
|||
public int getCurrentCharter(){
|
||||
/*int num = 0;
|
||||
for (int i = 0;getDirectoryList().size() > i;i++){
|
||||
BookChapter bookCatalogue = getDirectoryList().get(i);
|
||||
Chapter bookCatalogue = getDirectoryList().get(i);
|
||||
if (currentPage.getEnd() >= bookCatalogue.getBookChapterStartPos()){
|
||||
num = i;
|
||||
}else{
|
||||
|
@ -1002,7 +1002,7 @@ public class PageFactory {
|
|||
currentChapter = 0;
|
||||
bookPath = "";
|
||||
bookName = "";
|
||||
bookList = null;
|
||||
mBook = null;
|
||||
mBookPageWidget = null;
|
||||
mPageEvent = null;
|
||||
cancelPage = null;
|
||||
|
@ -1027,7 +1027,7 @@ public class PageFactory {
|
|||
}
|
||||
|
||||
//获取书本的章
|
||||
public List<BookChapter> getDirectoryList(){
|
||||
public List<Chapter> getDirectoryList(){
|
||||
return mBookUtil.getDirectoryList();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.Map;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.zhuike.util.collections.FIFOMap;
|
||||
|
||||
|
||||
public class REUtil {
|
||||
private static final String[] EMPTY = new String[0];
|
||||
|
|
Loading…
Reference in New Issue