Commit b7214ab8 authored by jyx's avatar jyx

优化样式

parent c7182922
package com.duben.infinitefunjia;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
......@@ -20,6 +19,7 @@ import com.duben.infinitefunjia.manager.UmengManager;
import com.duben.infinitefunjia.net.LoanService;
import com.duben.infinitefunjia.net.V6Service;
import com.duben.infinitefunjia.utils.AppPreferencesManager;
import com.duben.infinitefunjia.utils.LogUtil;
import com.duben.infinitefunjia.utils.MateUtils;
import com.duben.infinitefunjia.utils.ForegroundOrBackground;
import com.orhanobut.logger.AndroidLogAdapter;
......@@ -28,6 +28,11 @@ import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy;
import com.tencent.bugly.crashreport.CrashReport;
import java.io.IOException;
import io.reactivex.exceptions.UndeliverableException;
import io.reactivex.functions.Consumer;
import io.reactivex.plugins.RxJavaPlugins;
import rx.Scheduler;
import rx.schedulers.Schedulers;
......@@ -70,6 +75,8 @@ public class MintsApplication extends MultiDexApplication {
// 三方配置
thirdConfig();
setRxJavaErrorHandler();
}
@Override
......@@ -206,4 +213,44 @@ public class MintsApplication extends MultiDexApplication {
// e.printStackTrace();
// }
}
private void setRxJavaErrorHandler() {
if (RxJavaPlugins.getErrorHandler() != null || RxJavaPlugins.isLockdown()) {
LogUtil.w("caowj", "setRxJavaErrorHandler getErrorHandler()!=null||isLockdown()");
return;
}
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(Throwable e) {
if (e instanceof UndeliverableException) {
e = e.getCause();
LogUtil.w("caowj", "setRxJavaErrorHandler UndeliverableException=" + e);
return;
} else if ((e instanceof IOException)) {
// fine, irrelevant network problem or API that throws on cancellation
return;
} else if (e instanceof InterruptedException) {
// fine, some blocking code was interrupted by a dispose call
return;
} else if ((e instanceof NullPointerException) || (e instanceof IllegalArgumentException)) {
// that's likely a bug in the application
Thread.UncaughtExceptionHandler uncaughtExceptionHandler =
Thread.currentThread().getUncaughtExceptionHandler();
if (uncaughtExceptionHandler != null) {
uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), e);
}
return;
} else if (e instanceof IllegalStateException) {
// that's a bug in RxJava or in a custom operator
Thread.UncaughtExceptionHandler uncaughtExceptionHandler =
Thread.currentThread().getUncaughtExceptionHandler();
if (uncaughtExceptionHandler != null) {
uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), e);
}
return;
}
LogUtil.w("caowj", "setRxJavaErrorHandler unknown exception=" + e);
}
});
}
}
package com.duben.infinitefunjia.manager
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.duben.infinitefunjia.common.Constant
import com.duben.infinitefunjia.mvp.model.BookBean
import com.duben.infinitefunjia.ui.activitys.BookReadActivity
import com.duben.infinitefunjia.ui.activitys.LongBookReadActivity
/**
* @author Assen
* @date 2024/9/27
* @desc
*/
class BookReadManager {
companion object {
val instance: BookReadManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
BookReadManager()
}
}
fun goReadPage(activity: Activity, data: BookBean) {
val bundle = Bundle()
bundle.putString(Constant.ROUTE_BOOK_ID, data.id)
if (data.shortis == "0") {
val intent = Intent(activity, BookReadActivity::class.java)
intent.putExtras(bundle)
activity.startActivity(intent)
} else {
val intent = Intent(activity, LongBookReadActivity::class.java)
intent.putExtras(bundle)
activity.startActivity(intent)
}
}
}
\ No newline at end of file
......@@ -102,24 +102,47 @@ public class NetworkPageLoader extends PageLoader {
@Override
public void loadNextChapters() {
loadNextChapter();
if (chapterChangeListener != null) {
// 提示加载后两章
int begin = curChapterIndex + 1;
int end = begin + 1;
// 判断是否大于最后一章
if (begin >= mChapterList.size()) {
// 如果下一章超出目录了,就没有必要加载了
return;
}
if (end > mChapterList.size()) {
end = mChapterList.size() - 1;
}
requestChapters(begin, end);
}
}
@Override
public void loadPreChapters() {
loadPrevChapter();
// 加载当前页的前面两个章节
if (chapterChangeListener != null) {
int end = curChapterIndex;
int begin = end - 2;
if (begin < 0) {
begin = 0;
}
requestChapters(begin, end);
}
}
@Override
public void preChapter() {
super.preChapter();
loadPrevChapter();
loadPreChapters();
}
@Override
public void nextChapter() {
super.nextChapter();
loadNextChapter();
loadNextChapters();
}
@Override
......@@ -138,25 +161,10 @@ public class NetworkPageLoader extends PageLoader {
loadCurrentChapter(pos);
}
/**
* 加载当前页的前面两个章节
*/
private void loadPrevChapter() {
if (chapterChangeListener != null) {
int end = curChapterIndex;
int begin = end - 2;
if (begin < 0) {
begin = 0;
}
requestChapters(begin, end);
}
}
/**
* 加载前一页,当前页,后一页。
*/
private void loadCurrentChapter(int cur) {
public void loadCurrentChapter(int cur) {
if (chapterChangeListener != null) {
int begin = cur;
int end = cur;
......@@ -181,30 +189,6 @@ public class NetworkPageLoader extends PageLoader {
}
}
/**
* 加载当前页的后两个章节
*/
private void loadNextChapter() {
if (chapterChangeListener != null) {
// 提示加载后两章
int begin = curChapterIndex + 1;
int end = begin + 1;
// 判断是否大于最后一章
if (begin >= mChapterList.size()) {
// 如果下一章超出目录了,就没有必要加载了
return;
}
if (end > mChapterList.size()) {
end = mChapterList.size() - 1;
}
requestChapters(begin, end);
}
}
private void requestChapters(int start, int end) {
// 检验输入值
if (start < 0) {
......@@ -261,44 +245,41 @@ public class NetworkPageLoader extends PageLoader {
titles.add(bookChapter.getTitle());
}
new Thread(() -> {
Flowable<BaseResponse<BookChapterBean>> concat = Single.concat(chapterInfos);
concat.subscribeOn(Schedulers.io());
concat.observeOn(AndroidSchedulers.mainThread());
concat.subscribe(
new Subscriber<BaseResponse<BookChapterBean>>() {
String title = titles.poll();
@Override
public void onSubscribe(Subscription s) {
s.request(Integer.MAX_VALUE);
mChapterSub = s;
}
@Override
public void onNext(BaseResponse<BookChapterBean> bookChapterBean) {
//存储数据
saveChapterInfo(bookId, title, bookChapterBean.getData().getContent());
//将获取到的数据进行存储
title = titles.poll();
}
Flowable<BaseResponse<BookChapterBean>> concat = Single.concat(chapterInfos);
concat.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
new Subscriber<BaseResponse<BookChapterBean>>() {
String title = titles.poll();
@Override
public void onSubscribe(Subscription s) {
s.request(Integer.MAX_VALUE);
mChapterSub = s;
}
@Override
public void onError(java.lang.Throwable t) {
}
@Override
public void onNext(BaseResponse<BookChapterBean> bookChapterBean) {
//存储数据
saveChapterInfo(bookId, title, bookChapterBean.getData().getContent());
//将获取到的数据进行存储
title = titles.poll();
}
@Override
public void onComplete() {
if (isSkip) {
isSkip = !isSkip;
skipToChapterReal(curChapterIndex);
} else {
pageView.showContent();
@Override
public void onError(java.lang.Throwable t) {
}
}
});
}).start();
@Override
public void onComplete() {
if (isSkip) {
isSkip = !isSkip;
skipToChapterReal(curChapterIndex);
} else {
pageView.showContent();
}
}
});
}
/**
......
......@@ -12,6 +12,7 @@ import android.text.TextPaint;
import com.duben.infinitefunjia.read.models.BookModel;
import com.duben.infinitefunjia.read.models.TxtChapterModel;
import com.duben.infinitefunjia.read.models.TxtPageModel;
import com.duben.infinitefunjia.utils.LogUtil;
import com.duben.infinitefunjia.utils.StringUtils;
import com.duben.library.utils.Utils;
......@@ -21,7 +22,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public abstract class PageLoader {
//显示容器
public YPageView pageView;
......@@ -74,7 +74,7 @@ public abstract class PageLoader {
//字体大小 单位dp
int mTextSize = 18;
//背景颜色
int bgColor = 0xFFCEC29C;
int bgColor = Color.WHITE;
//字体颜色
int textColor = Color.BLACK;
//记录上一次颜色 用于恢复
......@@ -110,8 +110,8 @@ public abstract class PageLoader {
mDisplayWidth = pageView.getWidth();
mVisibleWidth = pageView.getWidth() - mMarginWidth * 2;
mVisibleHeight = pageView.getHeight() - mMarginHeight;
mTitleInterval = (int) (mTitleTextPaint.getTextSize() / 2);
mTextInterval = (int) (mContentTextPaint.getTextSize() / 2);
mTitleInterval = (int) (mTitleTextPaint.getTextSize() / 1.6);
mTextInterval = (int) (mContentTextPaint.getTextSize() / 1.6);
}
//初始化画笔
......@@ -161,7 +161,6 @@ public abstract class PageLoader {
if (mChapterList.isEmpty()) return null;
TxtChapterModel chapterModel = mChapterList.get(chapterIndex);
List<TxtPageModel> pageList = null;
try {
BufferedReader br = getChapterReader(chapterModel);
......@@ -399,16 +398,17 @@ public abstract class PageLoader {
//上一页
public boolean prePage() {
if (curPageIndex > 0) {
curPageIndex--;
} else {
if (curChapterIndex == 0) return false;
List<TxtPageModel> tempPageList = loadPageList(curChapterIndex - 1);
if (tempPageList == null) {
loadPreChapters();
return false;
}
if (curChapterIndex == 0) return false;
lastChapterIndex = curChapterIndex--;
mNextPageList = mCurPageList;
mCurPageList = mPrePageList;
......@@ -431,7 +431,7 @@ public abstract class PageLoader {
if (curPageIndex >= 0 && curPageIndex < mCurPageList.size() - 1) {
curPageIndex++;
} else {
List<TxtPageModel> tempPageList = loadPageList(curChapterIndex + 1);
List<TxtPageModel> tempPageList = loadPageList(curChapterIndex + 2);
if (tempPageList == null) {
loadNextChapters();
return false;
......@@ -520,13 +520,11 @@ public abstract class PageLoader {
//下一章
public void nextChapter() {
if (curChapterIndex < mChapterList.size() - 1) skipToChapter(++curChapterIndex);
}
//上一章
public void preChapter() {
if (curChapterIndex > 0) skipToChapter(--curChapterIndex);
}
......@@ -581,6 +579,7 @@ public abstract class PageLoader {
//设置字体大小
public void setTextSize(int textSize) {
mTextSize = textSize;
}
//更新字体大小
......@@ -592,6 +591,8 @@ public abstract class PageLoader {
}
private void updateCurPage() {
LogUtil.d("XXXXXXXXX", mCurPageList.toString());
LogUtil.d("XXXXXXXXX" + curPageIndex);
mCurPage = mCurPageList.get(curPageIndex);
pageView.drawNextPage();
pageView.invalidate();
......
package com.duben.infinitefunjia.read;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import com.duben.infinitefunjia.R;
import com.duben.infinitefunjia.read.models.TxtChapterModel;
import java.util.List;
public class ReadChaptersAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<TxtChapterModel> chapterModels;
private OnChapterClickListener listener;
private Context mContext;
//选中章节
private int selectedChapterIndex = 0;
public ReadChaptersAdapter(List<TxtChapterModel> values, Context context, OnChapterClickListener listener) {
this.chapterModels = values;
this.listener = listener;
this.mContext = context;
}
public void setChapterModels(List<TxtChapterModel> models) {
this.chapterModels = models;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View root = LayoutInflater.from(parent.getContext()).inflate(R.layout.read_chapters_item, parent, false);
ChapterViewHolder viewHolder = new ChapterViewHolder(root);
viewHolder.chapterTextView = root.findViewById(R.id.tv_title);
return viewHolder;
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
final ChapterViewHolder viewHolder = (ChapterViewHolder) holder;
//显示数据
viewHolder.chapterTextView.setText("· " + chapterModels.get(position).getTitle());
if (position == selectedChapterIndex) {
viewHolder.setSelectedChapter();
} else {
viewHolder.chapterTextView.setTextColor(Color.BLACK);
}
viewHolder.chapterTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onItemClick(viewHolder.getAdapterPosition());
}
});
}
@Override
public int getItemCount() {
return chapterModels.size();
}
//item类
class ChapterViewHolder extends RecyclerView.ViewHolder {
TextView chapterTextView;
public ChapterViewHolder(View itemView) {
super(itemView);
}
public void setSelectedChapter() {
chapterTextView.setTextColor(ContextCompat.getColor(mContext, R.color.red_e73a3d));
chapterTextView.setSelected(true);
}
}
public void setChapter(int pos) {
selectedChapterIndex = pos;
notifyDataSetChanged();
}
/**********************interface***************************/
public interface OnChapterClickListener {
void onItemClick(int pos);
}
}
......@@ -3,6 +3,7 @@ package com.duben.infinitefunjia.read;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
......@@ -89,9 +90,9 @@ public class YPageView extends View implements SlideAnim.OnPageChangeListener {
//自定义绘制
@Override
protected void onDraw(Canvas canvas) {
//canvas.drawColor(bgColor);
// mPageLoader.drawPage(coverAnimation.getmNextBitmap());
if (pageAnim == null) return;
// canvas.drawColor(Color.WHITE);
pageAnim.drawViewPages(canvas);
}
......
......@@ -2,6 +2,7 @@ package com.duben.infinitefunjia.read.anim;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View;
......@@ -50,7 +51,7 @@ public abstract class PageAnim {
//是否没下一页或者上一页
protected boolean noNext = false;
public PageAnim(View view, OnPageChangeListener mListener){
public PageAnim(View view, OnPageChangeListener mListener) {
mView = view;
mScroller = new Scroller(mView.getContext());
this.mListener = mListener;
......@@ -59,11 +60,11 @@ public abstract class PageAnim {
/***********************************public***********************************/
//初始化数据
protected void initData(){
protected void initData() {
mViewWidth = mView.getWidth();
mViewHeight = mView.getHeight();
mCurBitmap = Bitmap.createBitmap(mView.getWidth(),mView.getHeight(),Bitmap.Config.RGB_565);
mNextBitmap = Bitmap.createBitmap(mView.getWidth(),mView.getHeight(),Bitmap.Config.RGB_565);
mCurBitmap = Bitmap.createBitmap(mView.getWidth(), mView.getHeight(), Bitmap.Config.RGB_565);
mNextBitmap = Bitmap.createBitmap(mView.getWidth(), mView.getHeight(), Bitmap.Config.RGB_565);
mSrcRect = new Rect(0, 0, mViewWidth, mViewHeight);
mDestRect = new Rect(0, 0, mViewWidth, mViewHeight);
slop = ViewConfiguration.get(mView.getContext()).getScaledTouchSlop();
......@@ -71,14 +72,14 @@ public abstract class PageAnim {
//画页面
public void drawViewPages(Canvas canvas){
if (isAnim){
public void drawViewPages(Canvas canvas) {
if (isAnim) {
drawMove(canvas);
}else {
if (isCancel){
} else {
if (isCancel) {
mNextBitmap = mCurBitmap.copy(Bitmap.Config.RGB_565, true);
canvas.drawBitmap(mCurBitmap, 0, 0, null);
}else {
} else {
canvas.drawBitmap(mNextBitmap, 0, 0, null);
}
}
......@@ -86,15 +87,13 @@ public abstract class PageAnim {
}
public void changePage(){
public void changePage() {
Bitmap bitmap = mCurBitmap;
mCurBitmap = mNextBitmap;
mNextBitmap = bitmap;
}
/************************************abstract****************************************/
//开启翻页动画
......@@ -127,14 +126,15 @@ public abstract class PageAnim {
public abstract void drawMove(Canvas canvas);
/************************************interface****************************************/
//监听界面变化 PageView实现
public interface OnPageChangeListener {
boolean hasPrev();
boolean hasNext();
void pageCancel();
}
}
......@@ -17,7 +17,6 @@ import com.duben.infinitefunjia.utils.AppPreferencesManager
import com.duben.library.utils.GlideUtils
import kotlinx.android.synthetic.main.activity_book_read.*
import kotlinx.android.synthetic.main.header_layout.*
import net.nightwhistler.htmlspanner.HtmlSpanner
class BookReadActivity : BaseActivity(), View.OnClickListener, BookReadView {
......@@ -110,10 +109,10 @@ class BookReadActivity : BaseActivity(), View.OnClickListener, BookReadView {
if (data.isUnlock == 0) {
view_vip.visibility = View.VISIBLE
tv_content.text = HtmlSpanner().fromHtml(data.free)
tv_content.text = data.freeMd
} else {
view_vip.visibility = View.GONE
tv_content.text = HtmlSpanner().fromHtml(data.free + data.charge)
tv_content.text = data.freeMd + data.chargeMd
}
}
......
package com.duben.infinitefunjia.ui.activitys
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.View
......@@ -10,6 +9,7 @@ import com.google.android.flexbox.FlexboxLayoutManager
import com.google.android.flexbox.JustifyContent
import com.duben.infinitefunjia.R
import com.duben.infinitefunjia.common.Constant
import com.duben.infinitefunjia.manager.BookReadManager
import com.duben.infinitefunjia.mvp.model.BookBean
import com.duben.infinitefunjia.mvp.model.BookListBean
import com.duben.infinitefunjia.mvp.presenters.BookSearchPresenter
......@@ -79,9 +79,7 @@ class BookSearchActivity : BaseActivity(), View.OnClickListener, BookSearchView,
private fun initSearchHotBookAdapter() {
searchHotBookAdapter = SearchHotBookAdapter(this)
searchHotBookAdapter?.setOnItemClickListener { _, _, position ->
val bundle = Bundle()
bundle.putString(Constant.ROUTE_BOOK_ID, searchHotBookData[position].id)
readyGo(BookReadActivity::class.java, bundle)
BookReadManager.instance.goReadPage(this, searchBookData[position])
}
rv_hot.layoutManager = LinearLayoutManager(this)
rv_hot.adapter = searchHotBookAdapter
......@@ -90,9 +88,7 @@ class BookSearchActivity : BaseActivity(), View.OnClickListener, BookSearchView,
private fun initSearchBookAdapter() {
searchBookAdapter = SearchBookAdapter(this)
searchBookAdapter?.setOnItemClickListener { _, _, position ->
val bundle = Bundle()
bundle.putString(Constant.ROUTE_BOOK_ID, searchBookData[position].id)
readyGo(BookReadActivity::class.java, bundle)
BookReadManager.instance.goReadPage(this, searchBookData[position])
}
rv_search_show.layoutManager = LinearLayoutManager(this)
rv_search_show.adapter = searchBookAdapter
......
package com.duben.infinitefunjia.ui.activitys
import android.graphics.Color
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import android.view.WindowManager
import androidx.core.view.GravityCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.duben.infinitefunjia.R
import com.duben.infinitefunjia.common.BOOK_CONTENT_COLOR
import com.duben.infinitefunjia.common.BOOK_CONTENT_SIZE
import com.duben.infinitefunjia.common.Constant
import com.duben.infinitefunjia.manager.ReadTimeCount
import com.duben.infinitefunjia.mvp.model.BookContentBean
......@@ -14,16 +14,22 @@ import com.duben.infinitefunjia.mvp.presenters.BookReadPresenter
import com.duben.infinitefunjia.mvp.views.BookReadView
import com.duben.infinitefunjia.read.AnimType
import com.duben.infinitefunjia.read.PageLoader
import com.duben.infinitefunjia.read.ReadChaptersAdapter
import com.duben.infinitefunjia.read.models.BookModel
import com.duben.infinitefunjia.read.models.BookRecordModel
import com.duben.infinitefunjia.read.models.TxtChapterModel
import com.duben.infinitefunjia.ui.activitys.base.BaseActivity
import com.duben.infinitefunjia.ui.widgets.BookSettingDialog
import com.duben.infinitefunjia.utils.AppPreferencesManager
import com.duben.infinitefunjia.utils.LogUtil
import com.duben.infinitefunjia.ui.widgets.LongBookSettingDialog
import kotlinx.android.synthetic.main.activity_long_book_read.*
import kotlinx.android.synthetic.main.header_layout.*
import org.litepal.LitePal
import org.litepal.crud.LitePalSupport
import java.lang.String
import kotlin.Int
import kotlin.getValue
import kotlin.lazy
import kotlin.let
import kotlin.run
import kotlin.toString
class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView {
......@@ -33,7 +39,10 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
private var mBookModel: BookModel? = null
private var mPageLoader: PageLoader? = null
private var bookSettingDialog: BookSettingDialog? = null
private var bookSettingDialog: LongBookSettingDialog? = null
//目录适配器
private var readChaptersAdapter: ReadChaptersAdapter? = null
override fun getContentViewLayoutID() = R.layout.activity_long_book_read
......@@ -48,10 +57,6 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
}
override fun initViewsAndEvents() {
iv_left_icon.visibility = View.VISIBLE
iv_left_icon.setImageResource(R.mipmap.ic_arrow_back)
readPresenter.attachView(this)
initWidgets()
initListener()
popBookSettingDialog()
......@@ -65,14 +70,35 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
override fun onPause() {
super.onPause()
ReadTimeCount.instance.endCountReadTime()
//保存阅读记录
if (LitePal.where("book_id=?", String.valueOf(mBookModel?.id))
.findFirst(TxtChapterModel::class.java) == null
) {
mPageLoader?.let { LitePal.saveAll<LitePalSupport>(it.mChapterList) }
}
val bookRecord = BookRecordModel()
mPageLoader?.let {
bookRecord.chapterPos = it.curChapterIndex
bookRecord.pagePos = it.curPageIndex
bookRecord.book_id = String.valueOf(mBookModel?.id)
bookRecord.page_color = it.bgColor
bookRecord.text_color = it.textColor
bookRecord.text_size = it.getmTextSize()
bookRecord.anim_type = pageview.animType.type
bookRecord.saveOrUpdate("book_id=?", String.valueOf(mBookModel?.id))
}
}
override fun onClick(v: View?) {
when (v?.id) {
R.id.iv_left_icon -> finish()
R.id.tab_setting_chapter -> {
openChaptersCategory()
}
R.id.tab_setting_book -> {
popBookSettingDialog()
bookSettingDialog?.show()
}
R.id.tab_setting_share -> {}
......@@ -85,23 +111,23 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
}
private fun popBookSettingDialog() {
bookSettingDialog = BookSettingDialog(this)
bookSettingDialog = LongBookSettingDialog(this)
bookSettingDialog?.setOnBookSettingCallback(object :
BookSettingDialog.OnBookSettingCallback {
LongBookSettingDialog.OnLongBookSettingCallback {
override fun onFontSize(size: Int) {
// tv_content.textSize = size.toFloat()
AppPreferencesManager.get().put(BOOK_CONTENT_SIZE, size)
mPageLoader?.updateTextSize(size)
}
override fun onBgColor(color: Int) {
// pageview.setBackgroundColor(color)
AppPreferencesManager.get().put(BOOK_CONTENT_COLOR, color)
mPageLoader?.setPageStyle(color, Color.BLACK)
}
})
bookSettingDialog?.loadSetting()
}
private fun initWidgets() {
//隐藏状态栏
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
//书籍
mPageLoader = pageview.getPageLoader(mBookModel)
pageview.animType = AnimType.ALIKE
......@@ -113,6 +139,8 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
val recordModel: BookRecordModel? = LitePal.where("book_id=?", "" + mBookModel?.id)
.findFirst(BookRecordModel::class.java)
if (recordModel != null) {
bookSettingDialog?.setSetting(recordModel.page_color, recordModel.text_size)
mPageLoader?.run {
curChapterIndex = recordModel.chapterPos
curPageIndex = recordModel.pagePos
......@@ -127,32 +155,48 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
else -> pageview.animType = AnimType.NONE
}
}
} else {
mPageLoader?.setPageBgColor(Color.WHITE)
mPageLoader?.setTextSize(18)
mPageLoader?.textColor = Color.BLACK
bookSettingDialog?.setSetting(Color.WHITE, 18)
}
//初始化目录
initChapterRecyclerView()
}
private fun initChapterRecyclerView() {
read_rv_category.layoutManager = LinearLayoutManager(this)
readChaptersAdapter = ReadChaptersAdapter(mPageLoader?.mChapterList, this) { pos ->
mPageLoader?.skipToChapter(pos)
read_drawer.closeDrawers()
}
//章节回调
mPageLoader?.setChapterChangeListener(object : PageLoader.OnChapterChangeListener {
override fun onChapterChange(pos: Int) {
LogUtil.d("XXXIX ----> $pos")
// if (pos >= mPageLoader.){
//
// }
// readChaptersAdapter.setChapter(pos)
readChaptersAdapter?.setChapter(pos)
}
override fun requestChapters(requestChapters: List<TxtChapterModel>) {}
override fun finishedLoadChapters(bookChapters: List<TxtChapterModel>) {
mPageLoader?.pageView?.showCategory()
// readChaptersAdapter.setChapterModels(bookChapters)
readChaptersAdapter?.setChapterModels(bookChapters)
}
})
read_rv_category.adapter = readChaptersAdapter
}
//初始化目录
// initChapterRecyclerView()
//目录
private fun openChaptersCategory() {
mPageLoader?.let {
read_rv_category.scrollToPosition(it.curChapterIndex)
read_drawer.openDrawer(GravityCompat.START)
}
}
private fun initListener() {
iv_left_icon.setOnClickListener(this)
tab_setting_chapter.setOnClickListener(this)
tab_setting_share.setOnClickListener(this)
tab_setting_book.setOnClickListener(this)
......
......@@ -6,6 +6,7 @@ import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.duben.infinitefunjia.R
import com.duben.infinitefunjia.common.Constant
import com.duben.infinitefunjia.manager.BookReadManager
import com.duben.infinitefunjia.mvp.model.*
import com.duben.infinitefunjia.mvp.presenters.WatchRecordPresenter
import com.duben.infinitefunjia.mvp.views.WatchRecordView
......@@ -38,9 +39,7 @@ class WatchRecordActivity : BaseActivity(), WatchRecordView {
mWatchRecordAdapter?.setEmptyView(emptyView)
mWatchRecordAdapter?.setNewInstance(datas)
mWatchRecordAdapter?.setOnItemClickListener { adapter, view, position ->
val bundle = Bundle()
bundle.putString(Constant.ROUTE_BOOK_ID, datas.get(position).id)
readyGo(BookReadActivity::class.java, bundle)
BookReadManager.instance.goReadPage(this,datas[position])
}
mWatchRecordAdapter?.setOnItemCollectClickListener(object :
WatchRecordAdapter.OnItemCollectClickListener {
......
......@@ -16,13 +16,13 @@ import com.duben.infinitefunjia.R
import com.duben.infinitefunjia.ad.AdManager
import com.duben.infinitefunjia.common.AppConfig
import com.duben.infinitefunjia.common.Constant
import com.duben.infinitefunjia.manager.BookReadManager
import com.duben.infinitefunjia.manager.UserManager
import com.duben.infinitefunjia.mvp.model.BookBean
import com.duben.infinitefunjia.mvp.model.BookListBean
import com.duben.infinitefunjia.mvp.model.FirstBookBean
import com.duben.infinitefunjia.mvp.presenters.BookCityPresenter
import com.duben.infinitefunjia.mvp.views.BookCityView
import com.duben.infinitefunjia.ui.activitys.BookReadActivity
import com.duben.infinitefunjia.ui.activitys.BookSearchActivity
import com.duben.infinitefunjia.ui.activitys.VipActivity
import com.duben.infinitefunjia.ui.adapter.HotBookAdapter
......@@ -80,9 +80,7 @@ class BookCityFragment : LazyLoadBaseFragment(), BookCityView, View.OnClickListe
private fun initHotAdapter() {
hotBookAdapter = HotBookAdapter(requireActivity())
hotBookAdapter?.setOnItemClickListener { _, _, position ->
val bundle = Bundle()
bundle.putString(Constant.ROUTE_BOOK_ID, hotBookData[position].id)
readyGo(BookReadActivity::class.java, bundle)
BookReadManager.instance.goReadPage(requireActivity(), hotBookData[position])
}
rv_hotbook.layoutManager = GridLayoutManager(requireContext(), 4)
val itemDecoration = GridSpacingItemDecoration(5, 10, false)
......@@ -114,7 +112,7 @@ class BookCityFragment : LazyLoadBaseFragment(), BookCityView, View.OnClickListe
view.setOnClickListener {
val bundle = Bundle()
bundle.putString(Constant.ROUTE_BOOK_ID, headData.id)
readyGo(BookReadActivity::class.java, bundle)
BookReadManager.instance.goReadPage(requireActivity(), headData)
}
return view
}
......@@ -122,9 +120,7 @@ class BookCityFragment : LazyLoadBaseFragment(), BookCityView, View.OnClickListe
private fun initNewAdapter() {
newBookAdapter = NewBookAdapter(requireActivity())
newBookAdapter?.setOnItemClickListener { _, _, position ->
val bundle = Bundle()
bundle.putString(Constant.ROUTE_BOOK_ID, newBookData[position].id)
readyGo(BookReadActivity::class.java, bundle)
BookReadManager.instance.goReadPage(requireActivity(), newBookData[position])
}
rv_newbook.layoutManager = GridLayoutManager(requireContext(), 2)
rv_newbook.adapter = newBookAdapter
......@@ -184,9 +180,7 @@ class BookCityFragment : LazyLoadBaseFragment(), BookCityView, View.OnClickListe
banner.addBannerLifecycleObserver(this)
.setAdapter(ImageTitleAdapter(data.records))
.setOnBannerListener { data2, _ ->
val bundle = Bundle()
bundle.putString(Constant.ROUTE_BOOK_ID, (data2 as BookBean).id)
readyGo(BookReadActivity::class.java, bundle)
BookReadManager.instance.goReadPage(requireActivity(), data2 as BookBean)
}
}
......@@ -194,9 +188,7 @@ class BookCityFragment : LazyLoadBaseFragment(), BookCityView, View.OnClickListe
override fun getSoltVedioSuc(data: FirstBookBean) {
val firstVedio = AppPreferencesManager.get().getBoolean(Constant.IS_FIRST_VEDIO, true)
if (data.articleMsg != null && firstVedio) {
val bundle = Bundle()
bundle.putString(Constant.ROUTE_BOOK_ID, data.articleMsg.id)
readyGo(BookReadActivity::class.java, bundle)
BookReadManager.instance.goReadPage(requireActivity(), data.articleMsg)
} else {
if (!UserManager.getInstance().vipFlag) {
val bundle = Bundle()
......
......@@ -6,12 +6,11 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.duben.infinitefunjia.R
import com.duben.infinitefunjia.ad.express.MainExpressManager
import com.duben.infinitefunjia.common.Constant
import com.duben.infinitefunjia.mvp.model.BannerList
import com.duben.infinitefunjia.manager.BookReadManager
import com.duben.infinitefunjia.mvp.model.BookBean
import com.duben.infinitefunjia.mvp.model.BookListBean
import com.duben.infinitefunjia.mvp.presenters.PicContentPresenter
import com.duben.infinitefunjia.mvp.views.PicContentView
import com.duben.infinitefunjia.ui.activitys.BookReadActivity
import com.duben.infinitefunjia.ui.adapter.CountAdapter
import com.duben.infinitefunjia.ui.fragment.base.LazyLoadBaseFragment
import com.scwang.smartrefresh.layout.api.RefreshLayout
......@@ -120,9 +119,7 @@ class BookListFragment : LazyLoadBaseFragment(), PicContentView, OnRefreshListen
hotStyleAdapter.setOnCountItemClickListener(object :
CountAdapter.OnCountItemClickListener {
override fun onItemClick(bean: BookBean) {
val bundle = Bundle()
bundle.putString(Constant.ROUTE_BOOK_ID, bean.id)
readyGo(BookReadActivity::class.java, bundle)
BookReadManager.instance.goReadPage(requireActivity(), bean)
}
})
}
......
package com.duben.infinitefunjia.ui.fragment
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import com.duben.infinitefunjia.R
import com.duben.infinitefunjia.common.AppConfig
import com.duben.infinitefunjia.common.Constant
import com.duben.infinitefunjia.manager.BookReadManager
import com.duben.infinitefunjia.manager.ReadTimeCount
import com.duben.infinitefunjia.mvp.model.BookBean
import com.duben.infinitefunjia.mvp.model.BookListBean
import com.duben.infinitefunjia.mvp.presenters.BookShelfPresenter
import com.duben.infinitefunjia.mvp.views.BookShelfView
import com.duben.infinitefunjia.ui.activitys.BookReadActivity
import com.duben.infinitefunjia.ui.activitys.MainActivity
import com.duben.infinitefunjia.ui.adapter.BookShelfAdapter
import com.duben.infinitefunjia.ui.adapter.LikeBookAdapter
......@@ -48,9 +47,7 @@ class BookShelfFragment : LazyLoadBaseFragment(), BookShelfView, View.OnClickLis
return@setOnItemClickListener
}
val bundle = Bundle()
bundle.putString(Constant.ROUTE_BOOK_ID, shelfBookData[position].id)
readyGo(BookReadActivity::class.java, bundle)
BookReadManager.instance.goReadPage(requireActivity(),shelfBookData[position])
}
rv_bookshelf.layoutManager = GridLayoutManager(requireContext(), 3)
val itemDecoration = GridSpacingItemDecoration(3, 10, false)
......@@ -61,9 +58,7 @@ class BookShelfFragment : LazyLoadBaseFragment(), BookShelfView, View.OnClickLis
private fun initLikeAdapter() {
likeBookAdapter = LikeBookAdapter(requireActivity())
likeBookAdapter?.setOnItemClickListener { _, _, position ->
val bundle = Bundle()
bundle.putString(Constant.ROUTE_BOOK_ID, likeBookData[position].id)
readyGo(BookReadActivity::class.java, bundle)
BookReadManager.instance.goReadPage(requireActivity(),likeBookData[position])
}
rv_booklike.layoutManager = GridLayoutManager(requireContext(), 4)
val itemDecoration = GridSpacingItemDecoration(4, 10, false)
......
package com.duben.infinitefunjia.ui.widgets
import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.WindowManager
import android.widget.RadioButton
import android.widget.SeekBar
import com.duben.infinitefunjia.R
import com.duben.infinitefunjia.common.BookConstant
import kotlinx.android.synthetic.main.dialog_book_setting.*
class LongBookSettingDialog(context: Context) : Dialog(context, R.style.dialog) {
private var mOnBookSettingCallback: OnLongBookSettingCallback? = null
init {
setContentView(R.layout.dialog_book_setting)
// 设置window属性
val lp = window!!.attributes
lp.gravity = Gravity.BOTTOM
lp.width = WindowManager.LayoutParams.MATCH_PARENT
lp.windowAnimations = R.style.DialogAnimBottom
// lp.dimAmount = 0f // 去背景遮盖
lp.alpha = 1f//透明效果
window!!.attributes = lp
setCancelable(true)
setCanceledOnTouchOutside(true)
(seekbar as SeekBar).setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
tv_seek.text = "$progress"
mOnBookSettingCallback?.onFontSize(progress)
}
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
override fun onStopTrackingTouch(seekBar: SeekBar?) {}
})
rg_color.setOnCheckedChangeListener { group, checkedId ->
for (i in 0 until group.childCount) {
val rb = group.getChildAt(i) as RadioButton
if (rb.id == checkedId) {
rb.scaleX = 1.2f
rb.scaleY = 1.2f
} else {
rb.scaleX = 1f
rb.scaleY = 1f
}
}
when (checkedId) {
R.id.rb_color1 -> {
mOnBookSettingCallback?.onBgColor(BookConstant.BOOK_CONTENT_COLOR_1.color)
}
R.id.rb_color2 -> {
mOnBookSettingCallback?.onBgColor(BookConstant.BOOK_CONTENT_COLOR_2.color)
}
R.id.rb_color3 -> {
mOnBookSettingCallback?.onBgColor(BookConstant.BOOK_CONTENT_COLOR_3.color)
}
R.id.rb_color4 -> {
mOnBookSettingCallback?.onBgColor(BookConstant.BOOK_CONTENT_COLOR_4.color)
}
R.id.rb_color5 -> {
mOnBookSettingCallback?.onBgColor(BookConstant.BOOK_CONTENT_COLOR_5.color)
}
R.id.rb_color6 -> {
mOnBookSettingCallback?.onBgColor(BookConstant.BOOK_CONTENT_COLOR_6.color)
}
else -> {}
}
}
}
fun setSetting(color: Int, size: Int) {
tv_seek.text = "$size"
seekbar.progress = size
when (color) {
BookConstant.BOOK_CONTENT_COLOR_1.color -> {
rb_color1.scaleX = 1.2f
rb_color1.scaleY = 1.2f
rb_color1.isChecked = true
}
BookConstant.BOOK_CONTENT_COLOR_2.color -> {
rb_color2.scaleX = 1.2f
rb_color2.scaleY = 1.2f
rb_color2.isChecked = true
}
BookConstant.BOOK_CONTENT_COLOR_3.color -> {
rb_color3.scaleX = 1.2f
rb_color3.scaleY = 1.2f
rb_color3.isChecked = true
}
BookConstant.BOOK_CONTENT_COLOR_4.color -> {
rb_color4.scaleX = 1.2f
rb_color4.scaleY = 1.2f
rb_color4.isChecked = true
}
BookConstant.BOOK_CONTENT_COLOR_5.color -> {
rb_color5.scaleX = 1.2f
rb_color5.scaleY = 1.2f
rb_color5.isChecked = true
}
BookConstant.BOOK_CONTENT_COLOR_6.color -> {
rb_color6.scaleX = 1.2f
rb_color6.scaleY = 1.2f
rb_color6.isChecked = true
}
}
}
fun setOnBookSettingCallback(onLongBookSettingCallback: OnLongBookSettingCallback) {
this.mOnBookSettingCallback = onLongBookSettingCallback
}
interface OnLongBookSettingCallback {
fun onFontSize(size: Int)
fun onBgColor(color: Int)
}
}
\ No newline at end of file
......@@ -82,6 +82,7 @@
android:id="@+id/tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="2"
android:textColor="@color/black" />
<LinearLayout
......@@ -189,7 +190,8 @@
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:orientation="vertical">
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:layout_width="20dp"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/view_content"
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/read_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<include layout="@layout/header_layout" />
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/view_book"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
......@@ -100,6 +95,7 @@
<LinearLayout
android:id="@+id/tab_setting_book"
android:layout_width="0dp"
android:background="@color/white"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
......@@ -147,7 +143,38 @@
</LinearLayout>
</LinearLayout>
</LinearLayout>
<!--侧滑栏-->
<LinearLayout
android:layout_width="220dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/white"
android:clickable="true"
android:orientation="vertical"
android:paddingTop="26dp"
android:paddingBottom="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginBottom="8dp"
android:text="目录"
android:textColor="@color/black"
android:textSize="22sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/read_rv_category"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</androidx.drawerlayout.widget.DrawerLayout>
......@@ -32,13 +32,13 @@
android:maxHeight="5dp"
android:min="14"
android:minHeight="5dp"
android:progress="17" />
android:progress="18" />
<TextView
android:id="@+id/tv_seek"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="17"
android:text="18"
android:textColor="@color/black"
android:textSize="14sp" />
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/header_container"
android:layout_width="match_parent"
android:layout_height="70dp"
android:id="@+id/header_container"
android:paddingTop="20dp">
<ImageView
......@@ -20,6 +20,9 @@
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLength="8"
android:singleLine="true"
android:textColor="@color/product_net_text"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:ellipsize="end"
android:lines="1"
android:textAlignment="textStart"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment