Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Adjust the chapter Read the previous chapter Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
z-chu committed Sep 5, 2017
1 parent 65af511 commit d7f15ac
Show file tree
Hide file tree
Showing 15 changed files with 268 additions and 152 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/youshibi/app/AppRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ public static void showBookDetailActivity(Context context, Book book) {
CountEventHelper.countBookDetail(context, book);
}

public static void showReadActivity(Context context, Book book, int sectionIndex) {
public static void showReadActivity(Context context, Book book, Integer sectionIndex) {
context.startActivity(ReadActivity.newIntent(context, book, sectionIndex));
CountEventHelper.countBookRead(context, book.getId(), book.getName());
}

public static void showReadActivity(Context context, BookTb bookTb, int sectionIndex) {
context.startActivity(ReadActivity.newIntent(context, bookTb, sectionIndex));
public static void showReadActivity(Context context, BookTb bookTb) {
context.startActivity(ReadActivity.newIntent(context, bookTb));
CountEventHelper.countBookRead(context, bookTb.getId(), bookTb.getName());
}

Expand Down
30 changes: 24 additions & 6 deletions app/src/main/java/com/youshibi/app/data/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class DataManager {

private DataManager() {
rxCache = new RxCache.Builder()
.appVersion(1)
.appVersion(BuildConfig.VERSION_CODE)
.diskDir(new File(AppContext.context().getFilesDir().getPath() + File.separator + "data-cache"))
.setDebug(BuildConfig.DEBUG)
.diskConverter(new GsonDiskConverter())//支持Serializable、Json(GsonDiskConverter)
Expand All @@ -71,9 +71,9 @@ public Observable<DataList<Book>> getBookList(int page, int size) {
*/
public Observable<DataList<Book>> getBookList(long bookType, int page, int size) {
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("pageIndex", page);
hashMap.put("pageSize", size);
if (bookType > 0) hashMap.put("bookType", bookType);
hashMap.put("page_index", page);
hashMap.put("page_size", size);
if (bookType > 0) hashMap.put("book_type", bookType);
return RequestClient
.getServerAPI()
.getBookList(hashMap)
Expand All @@ -100,7 +100,7 @@ public Observable<DataList<Book>> searchBook(String keyword, int page, int size)
return Observable.just(new DataList<Book>());
}
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("pageIndex", page);
hashMap.put("page_index", page);
hashMap.put("pageSize", size);
hashMap.put("keyword", keyword);
return RequestClient
Expand Down Expand Up @@ -180,8 +180,26 @@ public List<BookSectionItem> call(CacheResult<List<BookSectionItem>> listCacheRe
* @param sectionIndex 章节索引
*/
public Observable<BookSectionContent> getBookSectionContent(String bookId, int sectionIndex) {
return getBookSectionContent(bookId, sectionIndex, "current");
}

public Observable<BookSectionContent> getBookSectionContentPrev(String bookId, int sectionIndex) {
return getBookSectionContent(bookId, sectionIndex, "last");
}

public Observable<BookSectionContent> getBookSectionContentNext(String bookId, int sectionIndex) {
return getBookSectionContent(bookId, sectionIndex, "next");
}

/**
* 获取小说章节中的内容
*
* @param bookId 小说的id
* @param sectionIndex 章节索引
*/
public Observable<BookSectionContent> getBookSectionContent(String bookId, int sectionIndex, String direction) {
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("queryDirection", "current");
hashMap.put("query_direction", direction);
return RequestClient
.getServerAPI()
.getBookSectionContent(bookId, sectionIndex, hashMap)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/youshibi/app/data/bean/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Book implements Serializable, Parcelable {
@SerializedName("is_finish")
private boolean isFinished;

@SerializedName("book_typeid")
@SerializedName("book_type_id")
private int bookTypeId;

@SerializedName("book_type_name")
Expand All @@ -61,7 +61,7 @@ public class Book implements Serializable, Parcelable {
@SerializedName("recommend_num")
private long recommendNum;

@SerializedName("create_datetime")
@SerializedName("create_date_time")
private String createDateTime;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class BookSectionContent implements Serializable{
@SerializedName("chapter_content")
private String content;

@SerializedName("create_datetime")
@SerializedName("create_date_time")
private String createDateTime;

public int getSectionIndex() {
Expand Down
63 changes: 45 additions & 18 deletions app/src/main/java/com/youshibi/app/data/db/table/BookTb.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public class BookTb implements Parcelable {

private long latestReadTimestamp;//最后一次的阅读时间

private Integer latestReadSection;//最后一次阅读的章节

private int latestReadPage;//最后一次阅读章节的页码

/**
* Used to resolve relations
*/
Expand All @@ -46,9 +50,10 @@ public class BookTb implements Parcelable {
@Generated(hash = 1075074410)
private transient BookTbDao myDao;

@Generated(hash = 847588366)
@Generated(hash = 889121155)
public BookTb(String id, String name, String coverUrl, String describe, String author,
boolean isFinished, int readNumber, long latestReadTimestamp) {
boolean isFinished, int readNumber, long latestReadTimestamp,
Integer latestReadSection, int latestReadPage) {
this.id = id;
this.name = name;
this.coverUrl = coverUrl;
Expand All @@ -57,6 +62,8 @@ public BookTb(String id, String name, String coverUrl, String describe, String a
this.isFinished = isFinished;
this.readNumber = readNumber;
this.latestReadTimestamp = latestReadTimestamp;
this.latestReadSection = latestReadSection;
this.latestReadPage = latestReadPage;
}

@Generated(hash = 1469509304)
Expand Down Expand Up @@ -147,6 +154,38 @@ public void update() {
myDao.update(this);
}

public int getReadNumber() {
return this.readNumber;
}

public void setReadNumber(int readNumber) {
this.readNumber = readNumber;
}

public long getLatestReadTimestamp() {
return this.latestReadTimestamp;
}

public void setLatestReadTimestamp(long latestReadTimestamp) {
this.latestReadTimestamp = latestReadTimestamp;
}

public Integer getLatestReadSection() {
return this.latestReadSection;
}

public void setLatestReadSection(Integer latestReadSection) {
this.latestReadSection = latestReadSection;
}

public int getLatestReadPage() {
return this.latestReadPage;
}

public void setLatestReadPage(int latestReadPage) {
this.latestReadPage = latestReadPage;
}

@Override
public int describeContents() {
return 0;
Expand All @@ -162,22 +201,8 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeByte(this.isFinished ? (byte) 1 : (byte) 0);
dest.writeInt(this.readNumber);
dest.writeLong(this.latestReadTimestamp);
}

public int getReadNumber() {
return this.readNumber;
}

public void setReadNumber(int readNumber) {
this.readNumber = readNumber;
}

public long getLatestReadTimestamp() {
return this.latestReadTimestamp;
}

public void setLatestReadTimestamp(long latestReadTimestamp) {
this.latestReadTimestamp = latestReadTimestamp;
dest.writeValue(this.latestReadSection);
dest.writeInt(this.latestReadPage);
}

/** called by internal mechanisms, do not call yourself. */
Expand All @@ -196,6 +221,8 @@ protected BookTb(Parcel in) {
this.isFinished = in.readByte() != 0;
this.readNumber = in.readInt();
this.latestReadTimestamp = in.readLong();
this.latestReadSection = (Integer) in.readValue(Integer.class.getClassLoader());
this.latestReadPage = in.readInt();
}

public static final Creator<BookTb> CREATOR = new Creator<BookTb>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

public class PreferencesHelper {
private static final String K_SELECTED_ARTICLE_LABELS = "selected_book_labels";
private static final String K_FIRST_START_APP = "first_start_app";


private static PreferencesHelper sPreferencesHelper;
private SharedPreferences mPreferences;
Expand All @@ -27,6 +29,7 @@ public PreferencesHelper(Context context) {
mGson = new Gson();

}

public static PreferencesHelper getInstance() {
if (sPreferencesHelper == null) {
sPreferencesHelper = new PreferencesHelper(AppContext.context());
Expand All @@ -48,6 +51,7 @@ public void setSelectedBookLabels(List<BookType> labels) {
.apply();
}
}

public List<BookType> getSelectedBookLabels() {
String string = mPreferences.getString(K_SELECTED_ARTICLE_LABELS, null);
if (string != null) {
Expand All @@ -61,4 +65,15 @@ public List<BookType> getSelectedBookLabels() {
return null;
}

public boolean isFirstStartApp() {
return mPreferences.getBoolean(K_FIRST_START_APP, true);
}

public void setFirstStartApp(boolean b) {
mPreferences
.edit()
.putBoolean(K_FIRST_START_APP, b)
.apply();
}

}
10 changes: 10 additions & 0 deletions app/src/main/java/com/youshibi/app/presentation/StartActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import android.support.annotation.Nullable;

import com.youshibi.app.AppRouter;
import com.youshibi.app.BuildConfig;
import com.youshibi.app.base.BaseActivity;
import com.youshibi.app.data.prefs.PreferencesHelper;
import com.youshibi.app.util.FileUtil;


/**
Expand All @@ -18,6 +21,13 @@ public class StartActivity extends BaseActivity {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO: 16-11-23 一些UI逻辑、检查缓存版本(更新后缓存是否还可用)
if (PreferencesHelper.getInstance().isFirstStartApp()) {
if (BuildConfig.VERSION_CODE == 2) {
FileUtil.clearFileWithPath(getFilesDir().getPath());
FileUtil.clearFileWithPath(getCacheDir().getPath());
}
PreferencesHelper.getInstance().setFirstStartApp(false);
}
if (isLogin()) {
AppRouter.showMainActivity(this);
finish();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.youshibi.app.presentation.book;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
Expand All @@ -12,8 +11,6 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.youshibi.app.R;
Expand Down Expand Up @@ -149,7 +146,7 @@ public void onClick(View view) {
case R.id.fab:
case R.id.fl_open_book:
if (recyclerView.getAdapter() != null) {
getPresenter().openRead(this, 0);
getPresenter().openRead(this, null);
}
break;
case R.id.fl_add_bookcase:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ interface View extends BaseLceView {
interface Presenter extends MvpPresenter<View> {
void loadData();

void openRead(Context context, int sectionIndex);
void openRead(Context context, Integer sectionIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void onNext(List<BookSectionItem> bookSectionItems) {
}

@Override
public void openRead(Context context, int sectionIndex) {
public void openRead(Context context, Integer sectionIndex) {
AppRouter.showReadActivity(context, book, sectionIndex);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void start() {
@Override
public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
BookTb bookTb = (BookTb) adapter.getItem(position);
AppRouter.showReadActivity(view.getContext(),bookTb,0);
AppRouter.showReadActivity(view.getContext(),bookTb);
// AppRouter.showBookDetailActivity(view.getContext(), DataConvertUtil.bookTb2Book((BookTb) adapter.getItem(position)));
}
});
Expand Down
Loading

0 comments on commit d7f15ac

Please sign in to comment.