Skip to content

Commit

Permalink
Merge pull request smuyyh#1 from smuyyh/master
Browse files Browse the repository at this point in the history
同步代码
  • Loading branch information
ptliao committed May 4, 2019
2 parents e7e6a56 + 857a656 commit 684ee75
Show file tree
Hide file tree
Showing 14 changed files with 218 additions and 42 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@
# BookReader
#### "任阅" 网络小说阅读器,实现追书推荐收藏、书籍/标签检索、模拟翻书的翻页效果、缓存书籍、日夜间模式、本地txt/pdf/epub书籍阅读、字体/主题/亮度设置、Wifi传书等功能!

**此项目停止维护,由于当时做的比较着急,分页、翻页、性能这些都做的相当不好,在 言士创作 中,对这方面做了很多的优化,不过没有开源。 有相关问题欢迎发我邮箱交流!**

## 项目
项目基于RxJava + Retrofit2 + Dagger2,结合MVP模式开发,代码结构清晰。项目中的API均来自追书神器,纯属共享学习之用,不得用于商业!!
有任何疑问或建议可提[issue](https://github.com/JustWayward/BookReader/issues/new)或联系[[email protected]](mailto:https://[email protected])
项目基于RxJava + Retrofit2 + Dagger2,项目中的API均来自追书神器,纯属共享学习之用,不得用于商业!!有任何疑问或建议可联系[[email protected]](mailto:https://[email protected])

demo下载:[任阅.apk](https://github.com/JustWayward/BookReader/raw/master/体验demo/任阅-20170129.apk)

## 郑重声明!
本项目虽然是开源项目,目的是共享学习只用,代码写的不好,也不准备上线!但是,近期不断发现,某些有心之人在不经作者的同意下,直接稍加修改,并且嵌入广告谋取利益,发布到各大应用市场,还请尊重源作者的版权!
**android 本地网络小说爬虫项目:** [CrawlerForReader](https://github.com/smuyyh/CrawlerForReader)

## TODO
* [ ] txt阅读优化模拟翻书效果,提高分页速度以及分页准确性
RN版本:[simplereader](https://github.com/jsntjinjin/simplereader)

* [ ] 增加无翻页效果方式

* [ ] epub阅读优化
任阅改进版:[NovelReader](https://github.com/newbiechen1024/NovelReader)

## 截图

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.justwayward.reader.base.Constant;
import com.justwayward.reader.bean.Recommend;
import com.justwayward.reader.ui.presenter.MainActivityPresenter;
import com.justwayward.reader.utils.ACache;
import com.justwayward.reader.utils.AppUtils;
import com.justwayward.reader.utils.FileUtils;
Expand Down Expand Up @@ -230,6 +231,9 @@ public synchronized void setLastChapterAndLatelyUpdate(String bookId, String las
}
for (Recommend.RecommendBooks bean : list) {
if (TextUtils.equals(bean._id, bookId)) {
if (!bean.lastChapter.equals(lastChapter)) {
MainActivityPresenter.isLastSyncUpdateed = true;
}
bean.lastChapter = lastChapter;
bean.updated = latelyUpdate;
list.remove(bean);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/
package com.justwayward.reader.manager;

import com.justwayward.reader.R;
import com.justwayward.reader.base.Constant;
import com.justwayward.reader.bean.support.BookMark;
import com.justwayward.reader.utils.AppUtils;
import com.justwayward.reader.utils.ScreenUtils;
import com.justwayward.reader.utils.SharedPreferencesUtil;
import com.justwayward.reader.utils.ToastUtils;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -70,8 +72,7 @@ private String getFontSizeKey(String bookId) {
}

public int getReadBrightness() {
return SharedPreferencesUtil.getInstance().getInt(getLightnessKey(),
(int) ScreenUtils.getScreenBrightness(AppUtils.getAppContext()));
return ScreenUtils.getScreenBrightness();
}

/**
Expand All @@ -80,6 +81,10 @@ public int getReadBrightness() {
* @param percent 亮度比例 0~100
*/
public void saveReadBrightness(int percent) {
if(percent > 100){
ToastUtils.showToast("saveReadBrightnessErr CheckRefs");
percent = 100;
}
SharedPreferencesUtil.getInstance().putInt(getLightnessKey(), percent);
}

Expand Down Expand Up @@ -188,6 +193,7 @@ public boolean isAutoBrightness() {
return SharedPreferencesUtil.getInstance().getBoolean("autoBrightness", false);
}


/**
* 保存用户选择的性别
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package com.justwayward.reader.ui.activity;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;

import com.justwayward.reader.R;
import com.justwayward.reader.base.BaseRVActivity;
Expand Down Expand Up @@ -78,6 +80,15 @@ public void initDatas() {
public void configViews() {
mPresenter.attachView(this);
mPresenter.getBookSource("summary", bookId);

new AlertDialog.Builder(this)
.setMessage("换源功能暂未实现,后续更新...")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create().show();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ public void initToolBar() {
setTitle("");
}

public void pullSyncBookShelf() {
mPresenter.syncBookShelf();
}

@Override
public void initDatas() {
startService(new Intent(this, DownloadBookService.class));
Expand Down Expand Up @@ -159,7 +163,13 @@ public void configViews() {
mIndicator.postDelayed(new Runnable() {
@Override
public void run() {
showChooseSexPopupWindow();
if (!SettingManager.getInstance().isUserChooseSex()
&& (genderPopupWindow == null || !genderPopupWindow.isShowing())) {
showChooseSexPopupWindow();
} else {
showDialog();
mPresenter.syncBookShelf();
}
}
}, 500);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Handler;
import android.provider.Settings;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatDelegate;
Expand Down Expand Up @@ -69,6 +72,7 @@
import com.justwayward.reader.ui.contract.BookReadContract;
import com.justwayward.reader.ui.easyadapter.ReadThemeAdapter;
import com.justwayward.reader.ui.presenter.BookReadPresenter;
import com.justwayward.reader.utils.AppUtils;
import com.justwayward.reader.utils.FileUtils;
import com.justwayward.reader.utils.FormatUtils;
import com.justwayward.reader.utils.LogUtils;
Expand All @@ -77,6 +81,7 @@
import com.justwayward.reader.utils.TTSPlayerUtils;
import com.justwayward.reader.utils.ToastUtils;
import com.justwayward.reader.view.readview.BaseReadView;
import com.justwayward.reader.view.readview.NoAimWidget;
import com.justwayward.reader.view.readview.OnReadStateChangeListener;
import com.justwayward.reader.view.readview.OverlappedWidget;
import com.justwayward.reader.view.readview.PageWidget;
Expand Down Expand Up @@ -349,6 +354,21 @@ public void onDismiss() {
});
}

/**
* 时刻监听系统亮度改变事件
*/
private ContentObserver Brightness = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
//LogUtils.d("BrightnessOnChange:" + ScreenUtils.getScreenBrightnessInt255());
if (!ScreenUtils.isAutoBrightness(ReadActivity.this)) {
seekbarLightness.setProgress(ScreenUtils.getScreenBrightness());
}
}
};


private void initAASet() {
curTheme = SettingManager.getInstance().getReadTheme();
ThemeManager.setReaderTheme(curTheme, mRlBookReadRoot);
Expand All @@ -362,8 +382,12 @@ private void initAASet() {

seekbarLightness.setMax(100);
seekbarLightness.setOnSeekBarChangeListener(new SeekBarChangeListener());
seekbarLightness.setProgress(SettingManager.getInstance().getReadBrightness());
seekbarLightness.setProgress(ScreenUtils.getScreenBrightness());
isAutoLightness = ScreenUtils.isAutoBrightness(this);


this.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS), true, Brightness);

if (SettingManager.getInstance().isAutoBrightness()) {
startAutoLightness();
} else {
Expand Down Expand Up @@ -391,11 +415,17 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
}

private void initPagerWidget() {
if (SharedPreferencesUtil.getInstance().getInt(Constant.FLIP_STYLE, 0) == 0) {
mPageWidget = new PageWidget(this, bookId, mChapterList, new ReadListener());
} else {
mPageWidget = new OverlappedWidget(this, bookId, mChapterList, new ReadListener());
switch (SharedPreferencesUtil.getInstance().getInt(Constant.FLIP_STYLE, 0)) {
case 0:
mPageWidget = new PageWidget(this, bookId, mChapterList, new ReadListener());
break;
case 1:
mPageWidget = new OverlappedWidget(this, bookId, mChapterList, new ReadListener());
break;
case 2:
mPageWidget = new NoAimWidget(this, bookId, mChapterList, new ReadListener());
}

registerReceiver(receiver, intentFilter);
if (SharedPreferencesUtil.getInstance().getBoolean(Constant.ISNIGHT, false)) {
mPageWidget.setTextColor(ContextCompat.getColor(this, R.color.chapter_content_night),
Expand Down Expand Up @@ -637,20 +667,18 @@ public void onClickToc() {
@OnClick(R.id.ivBrightnessMinus)
public void brightnessMinus() {
int curBrightness = SettingManager.getInstance().getReadBrightness();
if (curBrightness > 2 && !SettingManager.getInstance().isAutoBrightness()) {
if (curBrightness > 5 && !SettingManager.getInstance().isAutoBrightness()) {
seekbarLightness.setProgress((curBrightness = curBrightness - 2));
ScreenUtils.setScreenBrightness(curBrightness, ReadActivity.this);
SettingManager.getInstance().saveReadBrightness(curBrightness);
ScreenUtils.saveScreenBrightnessInt255(curBrightness, ReadActivity.this);
}
}

@OnClick(R.id.ivBrightnessPlus)
public void brightnessPlus() {
int curBrightness = SettingManager.getInstance().getReadBrightness();
if (curBrightness < 99 && !SettingManager.getInstance().isAutoBrightness()) {
if (!SettingManager.getInstance().isAutoBrightness()) {
seekbarLightness.setProgress((curBrightness = curBrightness + 2));
ScreenUtils.setScreenBrightness(curBrightness, ReadActivity.this);
SettingManager.getInstance().saveReadBrightness(curBrightness);
ScreenUtils.saveScreenBrightnessInt255(curBrightness, ReadActivity.this);
}
}

Expand Down Expand Up @@ -784,7 +812,7 @@ public void onClick(DialogInterface dialog, int which) {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 1:
if(resultCode == RESULT_OK) {
if (resultCode == RESULT_OK) {
BookSource bookSource = (BookSource) data.getSerializableExtra("source");
bookId = bookSource._id;
}
Expand Down Expand Up @@ -853,6 +881,7 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
@Override
protected void onDestroy() {
super.onDestroy();

if (mTtsPlayer.getPlayerState() == TTSCommonPlayer.PLAYER_STATE_PLAYING)
mTtsPlayer.stop();

Expand Down Expand Up @@ -928,8 +957,8 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
calcFontSize(progress);
} else if (seekBar.getId() == seekbarLightness.getId() && fromUser
&& !SettingManager.getInstance().isAutoBrightness()) { // 非自动调节模式下 才可调整屏幕亮度
ScreenUtils.setScreenBrightness(progress, ReadActivity.this);
SettingManager.getInstance().saveReadBrightness(progress);
ScreenUtils.saveScreenBrightnessInt100(progress, ReadActivity.this);
//SettingManager.getInstance().saveReadBrightness(progress);
}
}

Expand All @@ -955,6 +984,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
startAutoLightness();
} else {
stopAutoLightness();
ScreenUtils.saveScreenBrightnessInt255(ScreenUtils.getScreenBrightnessInt255(), AppUtils.getAppContext());
}
}
}
Expand Down Expand Up @@ -984,9 +1014,7 @@ private void startAutoLightness() {
private void stopAutoLightness() {
SettingManager.getInstance().saveAutoBrightness(false);
ScreenUtils.stopAutoBrightness(ReadActivity.this);
int value = SettingManager.getInstance().getReadBrightness();
seekbarLightness.setProgress(value);
ScreenUtils.setScreenBrightness(value, ReadActivity.this);
seekbarLightness.setProgress((int) (ScreenUtils.getScreenBrightnessInt255() / 255.0F * 100));
seekbarLightness.setEnabled(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.justwayward.reader.ui.fragment;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
Expand Down Expand Up @@ -61,7 +62,6 @@ public void initDatas() {
mList.add(new FindBean("排行榜", R.drawable.home_find_rank));
mList.add(new FindBean("主题书单", R.drawable.home_find_topic));
mList.add(new FindBean("分类", R.drawable.home_find_category));
mList.add(new FindBean("有声小说", R.drawable.home_find_listen));
}

@Override
Expand Down Expand Up @@ -97,8 +97,6 @@ public void onItemClick(View view, int position, FindBean data) {
case 2:
startActivity(new Intent(activity, TopCategoryListActivity.class));
break;
case 3:
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,27 @@ public void delete() {
@Override
public void onRefresh() {
super.onRefresh();
StackTraceElement stack[] = (new Throwable()).getStackTrace();


boolean hasRefBookShelfInCallStack = false;
boolean isMRefresh = false;
for (int i = 0; i < stack.length; i++) {
StackTraceElement ste = stack[i];
if (ste.getMethodName().equals("pullSyncBookShelf")) {
hasRefBookShelfInCallStack = true;
}
if (ste.getMethodName().equals("onAnimationEnd") && ste.getFileName().equals("SwipeRefreshLayout.java")) {
isMRefresh = true;
}
}

if (!hasRefBookShelfInCallStack && isMRefresh) {
((MainActivity) activity).pullSyncBookShelf();
return;
}


gone(llBatchManagement);
List<Recommend.RecommendBooks> data = CollectionsManager.getInstance().getCollectionListBySort();
mAdapter.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
public class MainActivityPresenter extends RxPresenter<MainContract.View> implements MainContract.Presenter<MainContract.View> {

private BookApi bookApi;
public static boolean isLastSyncUpdateed = false;

@Inject
public MainActivityPresenter(BookApi bookApi) {
Expand Down Expand Up @@ -100,7 +101,7 @@ public BookMixAToc.mixToc call(BookMixAToc data) {
mView.syncBookShelfCompleted();
return;
}

isLastSyncUpdateed = false;
Subscription rxSubscription = Observable.mergeDelayError(observables)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
Expand All @@ -114,6 +115,12 @@ public void onNext(BookMixAToc.mixToc data) {
@Override
public void onCompleted() {
mView.syncBookShelfCompleted();
if(isLastSyncUpdateed){
ToastUtils.showSingleToast("小説已更新");
}else{
ToastUtils.showSingleToast("你追的小説沒有更新");
}

}

@Override
Expand Down
Loading

0 comments on commit 684ee75

Please sign in to comment.