Commit b7214ab8 authored by jyx's avatar jyx

优化样式

parent c7182922
package com.duben.infinitefunjia; package com.duben.infinitefunjia;
import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
...@@ -20,6 +19,7 @@ import com.duben.infinitefunjia.manager.UmengManager; ...@@ -20,6 +19,7 @@ import com.duben.infinitefunjia.manager.UmengManager;
import com.duben.infinitefunjia.net.LoanService; import com.duben.infinitefunjia.net.LoanService;
import com.duben.infinitefunjia.net.V6Service; import com.duben.infinitefunjia.net.V6Service;
import com.duben.infinitefunjia.utils.AppPreferencesManager; import com.duben.infinitefunjia.utils.AppPreferencesManager;
import com.duben.infinitefunjia.utils.LogUtil;
import com.duben.infinitefunjia.utils.MateUtils; import com.duben.infinitefunjia.utils.MateUtils;
import com.duben.infinitefunjia.utils.ForegroundOrBackground; import com.duben.infinitefunjia.utils.ForegroundOrBackground;
import com.orhanobut.logger.AndroidLogAdapter; import com.orhanobut.logger.AndroidLogAdapter;
...@@ -28,6 +28,11 @@ import com.orhanobut.logger.Logger; ...@@ -28,6 +28,11 @@ import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy; import com.orhanobut.logger.PrettyFormatStrategy;
import com.tencent.bugly.crashreport.CrashReport; 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.Scheduler;
import rx.schedulers.Schedulers; import rx.schedulers.Schedulers;
...@@ -70,6 +75,8 @@ public class MintsApplication extends MultiDexApplication { ...@@ -70,6 +75,8 @@ public class MintsApplication extends MultiDexApplication {
// 三方配置 // 三方配置
thirdConfig(); thirdConfig();
setRxJavaErrorHandler();
} }
@Override @Override
...@@ -206,4 +213,44 @@ public class MintsApplication extends MultiDexApplication { ...@@ -206,4 +213,44 @@ public class MintsApplication extends MultiDexApplication {
// e.printStackTrace(); // 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 { ...@@ -102,24 +102,47 @@ public class NetworkPageLoader extends PageLoader {
@Override @Override
public void loadNextChapters() { 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 @Override
public void loadPreChapters() { public void loadPreChapters() {
loadPrevChapter(); // 加载当前页的前面两个章节
if (chapterChangeListener != null) {
int end = curChapterIndex;
int begin = end - 2;
if (begin < 0) {
begin = 0;
}
requestChapters(begin, end);
}
} }
@Override @Override
public void preChapter() { public void preChapter() {
super.preChapter(); super.preChapter();
loadPrevChapter(); loadPreChapters();
} }
@Override @Override
public void nextChapter() { public void nextChapter() {
super.nextChapter(); super.nextChapter();
loadNextChapter(); loadNextChapters();
} }
@Override @Override
...@@ -138,25 +161,10 @@ public class NetworkPageLoader extends PageLoader { ...@@ -138,25 +161,10 @@ public class NetworkPageLoader extends PageLoader {
loadCurrentChapter(pos); 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) { if (chapterChangeListener != null) {
int begin = cur; int begin = cur;
int end = cur; int end = cur;
...@@ -181,30 +189,6 @@ public class NetworkPageLoader extends PageLoader { ...@@ -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) { private void requestChapters(int start, int end) {
// 检验输入值 // 检验输入值
if (start < 0) { if (start < 0) {
...@@ -261,44 +245,41 @@ public class NetworkPageLoader extends PageLoader { ...@@ -261,44 +245,41 @@ public class NetworkPageLoader extends PageLoader {
titles.add(bookChapter.getTitle()); titles.add(bookChapter.getTitle());
} }
new Thread(() -> { Flowable<BaseResponse<BookChapterBean>> concat = Single.concat(chapterInfos);
Flowable<BaseResponse<BookChapterBean>> concat = Single.concat(chapterInfos); concat.subscribeOn(Schedulers.io())
concat.subscribeOn(Schedulers.io()); .observeOn(AndroidSchedulers.mainThread())
concat.observeOn(AndroidSchedulers.mainThread()); .subscribe(
concat.subscribe( new Subscriber<BaseResponse<BookChapterBean>>() {
new Subscriber<BaseResponse<BookChapterBean>>() { String title = titles.poll();
String title = titles.poll();
@Override
@Override public void onSubscribe(Subscription s) {
public void onSubscribe(Subscription s) { s.request(Integer.MAX_VALUE);
s.request(Integer.MAX_VALUE); mChapterSub = s;
mChapterSub = s; }
}
@Override
public void onNext(BaseResponse<BookChapterBean> bookChapterBean) {
//存储数据
saveChapterInfo(bookId, title, bookChapterBean.getData().getContent());
//将获取到的数据进行存储
title = titles.poll();
}
@Override @Override
public void onError(java.lang.Throwable t) { public void onNext(BaseResponse<BookChapterBean> bookChapterBean) {
} //存储数据
saveChapterInfo(bookId, title, bookChapterBean.getData().getContent());
//将获取到的数据进行存储
title = titles.poll();
}
@Override @Override
public void onComplete() { public void onError(java.lang.Throwable t) {
if (isSkip) {
isSkip = !isSkip;
skipToChapterReal(curChapterIndex);
} else {
pageView.showContent();
} }
}
});
}).start();
@Override
public void onComplete() {
if (isSkip) {
isSkip = !isSkip;
skipToChapterReal(curChapterIndex);
} else {
pageView.showContent();
}
}
});
} }
/** /**
......
...@@ -12,6 +12,7 @@ import android.text.TextPaint; ...@@ -12,6 +12,7 @@ import android.text.TextPaint;
import com.duben.infinitefunjia.read.models.BookModel; import com.duben.infinitefunjia.read.models.BookModel;
import com.duben.infinitefunjia.read.models.TxtChapterModel; import com.duben.infinitefunjia.read.models.TxtChapterModel;
import com.duben.infinitefunjia.read.models.TxtPageModel; import com.duben.infinitefunjia.read.models.TxtPageModel;
import com.duben.infinitefunjia.utils.LogUtil;
import com.duben.infinitefunjia.utils.StringUtils; import com.duben.infinitefunjia.utils.StringUtils;
import com.duben.library.utils.Utils; import com.duben.library.utils.Utils;
...@@ -21,7 +22,6 @@ import java.io.IOException; ...@@ -21,7 +22,6 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public abstract class PageLoader { public abstract class PageLoader {
//显示容器 //显示容器
public YPageView pageView; public YPageView pageView;
...@@ -74,7 +74,7 @@ public abstract class PageLoader { ...@@ -74,7 +74,7 @@ public abstract class PageLoader {
//字体大小 单位dp //字体大小 单位dp
int mTextSize = 18; int mTextSize = 18;
//背景颜色 //背景颜色
int bgColor = 0xFFCEC29C; int bgColor = Color.WHITE;
//字体颜色 //字体颜色
int textColor = Color.BLACK; int textColor = Color.BLACK;
//记录上一次颜色 用于恢复 //记录上一次颜色 用于恢复
...@@ -110,8 +110,8 @@ public abstract class PageLoader { ...@@ -110,8 +110,8 @@ public abstract class PageLoader {
mDisplayWidth = pageView.getWidth(); mDisplayWidth = pageView.getWidth();
mVisibleWidth = pageView.getWidth() - mMarginWidth * 2; mVisibleWidth = pageView.getWidth() - mMarginWidth * 2;
mVisibleHeight = pageView.getHeight() - mMarginHeight; mVisibleHeight = pageView.getHeight() - mMarginHeight;
mTitleInterval = (int) (mTitleTextPaint.getTextSize() / 2); mTitleInterval = (int) (mTitleTextPaint.getTextSize() / 1.6);
mTextInterval = (int) (mContentTextPaint.getTextSize() / 2); mTextInterval = (int) (mContentTextPaint.getTextSize() / 1.6);
} }
//初始化画笔 //初始化画笔
...@@ -161,7 +161,6 @@ public abstract class PageLoader { ...@@ -161,7 +161,6 @@ public abstract class PageLoader {
if (mChapterList.isEmpty()) return null; if (mChapterList.isEmpty()) return null;
TxtChapterModel chapterModel = mChapterList.get(chapterIndex); TxtChapterModel chapterModel = mChapterList.get(chapterIndex);
List<TxtPageModel> pageList = null; List<TxtPageModel> pageList = null;
try { try {
BufferedReader br = getChapterReader(chapterModel); BufferedReader br = getChapterReader(chapterModel);
...@@ -399,16 +398,17 @@ public abstract class PageLoader { ...@@ -399,16 +398,17 @@ public abstract class PageLoader {
//上一页 //上一页
public boolean prePage() { public boolean prePage() {
if (curPageIndex > 0) { if (curPageIndex > 0) {
curPageIndex--; curPageIndex--;
} else { } else {
if (curChapterIndex == 0) return false;
List<TxtPageModel> tempPageList = loadPageList(curChapterIndex - 1); List<TxtPageModel> tempPageList = loadPageList(curChapterIndex - 1);
if (tempPageList == null) { if (tempPageList == null) {
loadPreChapters(); loadPreChapters();
return false; return false;
} }
if (curChapterIndex == 0) return false;
lastChapterIndex = curChapterIndex--; lastChapterIndex = curChapterIndex--;
mNextPageList = mCurPageList; mNextPageList = mCurPageList;
mCurPageList = mPrePageList; mCurPageList = mPrePageList;
...@@ -431,7 +431,7 @@ public abstract class PageLoader { ...@@ -431,7 +431,7 @@ public abstract class PageLoader {
if (curPageIndex >= 0 && curPageIndex < mCurPageList.size() - 1) { if (curPageIndex >= 0 && curPageIndex < mCurPageList.size() - 1) {
curPageIndex++; curPageIndex++;
} else { } else {
List<TxtPageModel> tempPageList = loadPageList(curChapterIndex + 1); List<TxtPageModel> tempPageList = loadPageList(curChapterIndex + 2);
if (tempPageList == null) { if (tempPageList == null) {
loadNextChapters(); loadNextChapters();
return false; return false;
...@@ -520,13 +520,11 @@ public abstract class PageLoader { ...@@ -520,13 +520,11 @@ public abstract class PageLoader {
//下一章 //下一章
public void nextChapter() { public void nextChapter() {
if (curChapterIndex < mChapterList.size() - 1) skipToChapter(++curChapterIndex); if (curChapterIndex < mChapterList.size() - 1) skipToChapter(++curChapterIndex);
} }
//上一章 //上一章
public void preChapter() { public void preChapter() {
if (curChapterIndex > 0) skipToChapter(--curChapterIndex); if (curChapterIndex > 0) skipToChapter(--curChapterIndex);
} }
...@@ -581,6 +579,7 @@ public abstract class PageLoader { ...@@ -581,6 +579,7 @@ public abstract class PageLoader {
//设置字体大小 //设置字体大小
public void setTextSize(int textSize) { public void setTextSize(int textSize) {
mTextSize = textSize; mTextSize = textSize;
} }
//更新字体大小 //更新字体大小
...@@ -592,6 +591,8 @@ public abstract class PageLoader { ...@@ -592,6 +591,8 @@ public abstract class PageLoader {
} }
private void updateCurPage() { private void updateCurPage() {
LogUtil.d("XXXXXXXXX", mCurPageList.toString());
LogUtil.d("XXXXXXXXX" + curPageIndex);
mCurPage = mCurPageList.get(curPageIndex); mCurPage = mCurPageList.get(curPageIndex);
pageView.drawNextPage(); pageView.drawNextPage();
pageView.invalidate(); 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; ...@@ -3,6 +3,7 @@ package com.duben.infinitefunjia.read;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.RectF; import android.graphics.RectF;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
...@@ -89,9 +90,9 @@ public class YPageView extends View implements SlideAnim.OnPageChangeListener { ...@@ -89,9 +90,9 @@ public class YPageView extends View implements SlideAnim.OnPageChangeListener {
//自定义绘制 //自定义绘制
@Override @Override
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
//canvas.drawColor(bgColor);
// mPageLoader.drawPage(coverAnimation.getmNextBitmap()); // mPageLoader.drawPage(coverAnimation.getmNextBitmap());
if (pageAnim == null) return; if (pageAnim == null) return;
// canvas.drawColor(Color.WHITE);
pageAnim.drawViewPages(canvas); pageAnim.drawViewPages(canvas);
} }
......
...@@ -2,6 +2,7 @@ package com.duben.infinitefunjia.read.anim; ...@@ -2,6 +2,7 @@ package com.duben.infinitefunjia.read.anim;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect; import android.graphics.Rect;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
...@@ -50,7 +51,7 @@ public abstract class PageAnim { ...@@ -50,7 +51,7 @@ public abstract class PageAnim {
//是否没下一页或者上一页 //是否没下一页或者上一页
protected boolean noNext = false; protected boolean noNext = false;
public PageAnim(View view, OnPageChangeListener mListener){ public PageAnim(View view, OnPageChangeListener mListener) {
mView = view; mView = view;
mScroller = new Scroller(mView.getContext()); mScroller = new Scroller(mView.getContext());
this.mListener = mListener; this.mListener = mListener;
...@@ -59,11 +60,11 @@ public abstract class PageAnim { ...@@ -59,11 +60,11 @@ public abstract class PageAnim {
/***********************************public***********************************/ /***********************************public***********************************/
//初始化数据 //初始化数据
protected void initData(){ protected void initData() {
mViewWidth = mView.getWidth(); mViewWidth = mView.getWidth();
mViewHeight = mView.getHeight(); mViewHeight = mView.getHeight();
mCurBitmap = 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); mNextBitmap = Bitmap.createBitmap(mView.getWidth(), mView.getHeight(), Bitmap.Config.RGB_565);
mSrcRect = new Rect(0, 0, mViewWidth, mViewHeight); mSrcRect = new Rect(0, 0, mViewWidth, mViewHeight);
mDestRect = new Rect(0, 0, mViewWidth, mViewHeight); mDestRect = new Rect(0, 0, mViewWidth, mViewHeight);
slop = ViewConfiguration.get(mView.getContext()).getScaledTouchSlop(); slop = ViewConfiguration.get(mView.getContext()).getScaledTouchSlop();
...@@ -71,14 +72,14 @@ public abstract class PageAnim { ...@@ -71,14 +72,14 @@ public abstract class PageAnim {
//画页面 //画页面
public void drawViewPages(Canvas canvas){ public void drawViewPages(Canvas canvas) {
if (isAnim){ if (isAnim) {
drawMove(canvas); drawMove(canvas);
}else { } else {
if (isCancel){ if (isCancel) {
mNextBitmap = mCurBitmap.copy(Bitmap.Config.RGB_565, true); mNextBitmap = mCurBitmap.copy(Bitmap.Config.RGB_565, true);
canvas.drawBitmap(mCurBitmap, 0, 0, null); canvas.drawBitmap(mCurBitmap, 0, 0, null);
}else { } else {
canvas.drawBitmap(mNextBitmap, 0, 0, null); canvas.drawBitmap(mNextBitmap, 0, 0, null);
} }
} }
...@@ -86,15 +87,13 @@ public abstract class PageAnim { ...@@ -86,15 +87,13 @@ public abstract class PageAnim {
} }
public void changePage(){ public void changePage() {
Bitmap bitmap = mCurBitmap; Bitmap bitmap = mCurBitmap;
mCurBitmap = mNextBitmap; mCurBitmap = mNextBitmap;
mNextBitmap = bitmap; mNextBitmap = bitmap;
} }
/************************************abstract****************************************/ /************************************abstract****************************************/
//开启翻页动画 //开启翻页动画
...@@ -127,14 +126,15 @@ public abstract class PageAnim { ...@@ -127,14 +126,15 @@ public abstract class PageAnim {
public abstract void drawMove(Canvas canvas); public abstract void drawMove(Canvas canvas);
/************************************interface****************************************/ /************************************interface****************************************/
//监听界面变化 PageView实现 //监听界面变化 PageView实现
public interface OnPageChangeListener { public interface OnPageChangeListener {
boolean hasPrev(); boolean hasPrev();
boolean hasNext(); boolean hasNext();
void pageCancel(); void pageCancel();
} }
} }
...@@ -17,7 +17,6 @@ import com.duben.infinitefunjia.utils.AppPreferencesManager ...@@ -17,7 +17,6 @@ import com.duben.infinitefunjia.utils.AppPreferencesManager
import com.duben.library.utils.GlideUtils import com.duben.library.utils.GlideUtils
import kotlinx.android.synthetic.main.activity_book_read.* import kotlinx.android.synthetic.main.activity_book_read.*
import kotlinx.android.synthetic.main.header_layout.* import kotlinx.android.synthetic.main.header_layout.*
import net.nightwhistler.htmlspanner.HtmlSpanner
class BookReadActivity : BaseActivity(), View.OnClickListener, BookReadView { class BookReadActivity : BaseActivity(), View.OnClickListener, BookReadView {
...@@ -110,10 +109,10 @@ class BookReadActivity : BaseActivity(), View.OnClickListener, BookReadView { ...@@ -110,10 +109,10 @@ class BookReadActivity : BaseActivity(), View.OnClickListener, BookReadView {
if (data.isUnlock == 0) { if (data.isUnlock == 0) {
view_vip.visibility = View.VISIBLE view_vip.visibility = View.VISIBLE
tv_content.text = HtmlSpanner().fromHtml(data.free) tv_content.text = data.freeMd
} else { } else {
view_vip.visibility = View.GONE 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 package com.duben.infinitefunjia.ui.activitys
import android.os.Bundle
import android.text.Editable import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
import android.view.View import android.view.View
...@@ -10,6 +9,7 @@ import com.google.android.flexbox.FlexboxLayoutManager ...@@ -10,6 +9,7 @@ import com.google.android.flexbox.FlexboxLayoutManager
import com.google.android.flexbox.JustifyContent import com.google.android.flexbox.JustifyContent
import com.duben.infinitefunjia.R import com.duben.infinitefunjia.R
import com.duben.infinitefunjia.common.Constant 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.BookBean
import com.duben.infinitefunjia.mvp.model.BookListBean import com.duben.infinitefunjia.mvp.model.BookListBean
import com.duben.infinitefunjia.mvp.presenters.BookSearchPresenter import com.duben.infinitefunjia.mvp.presenters.BookSearchPresenter
...@@ -79,9 +79,7 @@ class BookSearchActivity : BaseActivity(), View.OnClickListener, BookSearchView, ...@@ -79,9 +79,7 @@ class BookSearchActivity : BaseActivity(), View.OnClickListener, BookSearchView,
private fun initSearchHotBookAdapter() { private fun initSearchHotBookAdapter() {
searchHotBookAdapter = SearchHotBookAdapter(this) searchHotBookAdapter = SearchHotBookAdapter(this)
searchHotBookAdapter?.setOnItemClickListener { _, _, position -> searchHotBookAdapter?.setOnItemClickListener { _, _, position ->
val bundle = Bundle() BookReadManager.instance.goReadPage(this, searchBookData[position])
bundle.putString(Constant.ROUTE_BOOK_ID, searchHotBookData[position].id)
readyGo(BookReadActivity::class.java, bundle)
} }
rv_hot.layoutManager = LinearLayoutManager(this) rv_hot.layoutManager = LinearLayoutManager(this)
rv_hot.adapter = searchHotBookAdapter rv_hot.adapter = searchHotBookAdapter
...@@ -90,9 +88,7 @@ class BookSearchActivity : BaseActivity(), View.OnClickListener, BookSearchView, ...@@ -90,9 +88,7 @@ class BookSearchActivity : BaseActivity(), View.OnClickListener, BookSearchView,
private fun initSearchBookAdapter() { private fun initSearchBookAdapter() {
searchBookAdapter = SearchBookAdapter(this) searchBookAdapter = SearchBookAdapter(this)
searchBookAdapter?.setOnItemClickListener { _, _, position -> searchBookAdapter?.setOnItemClickListener { _, _, position ->
val bundle = Bundle() BookReadManager.instance.goReadPage(this, searchBookData[position])
bundle.putString(Constant.ROUTE_BOOK_ID, searchBookData[position].id)
readyGo(BookReadActivity::class.java, bundle)
} }
rv_search_show.layoutManager = LinearLayoutManager(this) rv_search_show.layoutManager = LinearLayoutManager(this)
rv_search_show.adapter = searchBookAdapter rv_search_show.adapter = searchBookAdapter
......
package com.duben.infinitefunjia.ui.activitys package com.duben.infinitefunjia.ui.activitys
import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View 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.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.common.Constant
import com.duben.infinitefunjia.manager.ReadTimeCount import com.duben.infinitefunjia.manager.ReadTimeCount
import com.duben.infinitefunjia.mvp.model.BookContentBean import com.duben.infinitefunjia.mvp.model.BookContentBean
...@@ -14,16 +14,22 @@ import com.duben.infinitefunjia.mvp.presenters.BookReadPresenter ...@@ -14,16 +14,22 @@ import com.duben.infinitefunjia.mvp.presenters.BookReadPresenter
import com.duben.infinitefunjia.mvp.views.BookReadView import com.duben.infinitefunjia.mvp.views.BookReadView
import com.duben.infinitefunjia.read.AnimType import com.duben.infinitefunjia.read.AnimType
import com.duben.infinitefunjia.read.PageLoader 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.BookModel
import com.duben.infinitefunjia.read.models.BookRecordModel import com.duben.infinitefunjia.read.models.BookRecordModel
import com.duben.infinitefunjia.read.models.TxtChapterModel import com.duben.infinitefunjia.read.models.TxtChapterModel
import com.duben.infinitefunjia.ui.activitys.base.BaseActivity import com.duben.infinitefunjia.ui.activitys.base.BaseActivity
import com.duben.infinitefunjia.ui.widgets.BookSettingDialog import com.duben.infinitefunjia.ui.widgets.LongBookSettingDialog
import com.duben.infinitefunjia.utils.AppPreferencesManager
import com.duben.infinitefunjia.utils.LogUtil
import kotlinx.android.synthetic.main.activity_long_book_read.* import kotlinx.android.synthetic.main.activity_long_book_read.*
import kotlinx.android.synthetic.main.header_layout.*
import org.litepal.LitePal 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 { class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView {
...@@ -33,7 +39,10 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView ...@@ -33,7 +39,10 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
private var mBookModel: BookModel? = null private var mBookModel: BookModel? = null
private var mPageLoader: PageLoader? = 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 override fun getContentViewLayoutID() = R.layout.activity_long_book_read
...@@ -48,10 +57,6 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView ...@@ -48,10 +57,6 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
} }
override fun initViewsAndEvents() { override fun initViewsAndEvents() {
iv_left_icon.visibility = View.VISIBLE
iv_left_icon.setImageResource(R.mipmap.ic_arrow_back)
readPresenter.attachView(this)
initWidgets() initWidgets()
initListener() initListener()
popBookSettingDialog() popBookSettingDialog()
...@@ -65,14 +70,35 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView ...@@ -65,14 +70,35 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
ReadTimeCount.instance.endCountReadTime() 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?) { override fun onClick(v: View?) {
when (v?.id) { when (v?.id) {
R.id.iv_left_icon -> finish() R.id.iv_left_icon -> finish()
R.id.tab_setting_chapter -> { R.id.tab_setting_chapter -> {
openChaptersCategory()
} }
R.id.tab_setting_book -> { R.id.tab_setting_book -> {
popBookSettingDialog()
bookSettingDialog?.show() bookSettingDialog?.show()
} }
R.id.tab_setting_share -> {} R.id.tab_setting_share -> {}
...@@ -85,23 +111,23 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView ...@@ -85,23 +111,23 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
} }
private fun popBookSettingDialog() { private fun popBookSettingDialog() {
bookSettingDialog = BookSettingDialog(this) bookSettingDialog = LongBookSettingDialog(this)
bookSettingDialog?.setOnBookSettingCallback(object : bookSettingDialog?.setOnBookSettingCallback(object :
BookSettingDialog.OnBookSettingCallback { LongBookSettingDialog.OnLongBookSettingCallback {
override fun onFontSize(size: Int) { override fun onFontSize(size: Int) {
// tv_content.textSize = size.toFloat() mPageLoader?.updateTextSize(size)
AppPreferencesManager.get().put(BOOK_CONTENT_SIZE, size)
} }
override fun onBgColor(color: Int) { override fun onBgColor(color: Int) {
// pageview.setBackgroundColor(color) mPageLoader?.setPageStyle(color, Color.BLACK)
AppPreferencesManager.get().put(BOOK_CONTENT_COLOR, color)
} }
}) })
bookSettingDialog?.loadSetting()
} }
private fun initWidgets() { private fun initWidgets() {
//隐藏状态栏
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
//书籍 //书籍
mPageLoader = pageview.getPageLoader(mBookModel) mPageLoader = pageview.getPageLoader(mBookModel)
pageview.animType = AnimType.ALIKE pageview.animType = AnimType.ALIKE
...@@ -113,6 +139,8 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView ...@@ -113,6 +139,8 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
val recordModel: BookRecordModel? = LitePal.where("book_id=?", "" + mBookModel?.id) val recordModel: BookRecordModel? = LitePal.where("book_id=?", "" + mBookModel?.id)
.findFirst(BookRecordModel::class.java) .findFirst(BookRecordModel::class.java)
if (recordModel != null) { if (recordModel != null) {
bookSettingDialog?.setSetting(recordModel.page_color, recordModel.text_size)
mPageLoader?.run { mPageLoader?.run {
curChapterIndex = recordModel.chapterPos curChapterIndex = recordModel.chapterPos
curPageIndex = recordModel.pagePos curPageIndex = recordModel.pagePos
...@@ -127,32 +155,48 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView ...@@ -127,32 +155,48 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
else -> pageview.animType = AnimType.NONE 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 { mPageLoader?.setChapterChangeListener(object : PageLoader.OnChapterChangeListener {
override fun onChapterChange(pos: Int) { override fun onChapterChange(pos: Int) {
LogUtil.d("XXXIX ----> $pos") readChaptersAdapter?.setChapter(pos)
// if (pos >= mPageLoader.){
//
// }
// readChaptersAdapter.setChapter(pos)
} }
override fun requestChapters(requestChapters: List<TxtChapterModel>) {} override fun requestChapters(requestChapters: List<TxtChapterModel>) {}
override fun finishedLoadChapters(bookChapters: List<TxtChapterModel>) { override fun finishedLoadChapters(bookChapters: List<TxtChapterModel>) {
mPageLoader?.pageView?.showCategory() 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() { private fun initListener() {
iv_left_icon.setOnClickListener(this)
tab_setting_chapter.setOnClickListener(this) tab_setting_chapter.setOnClickListener(this)
tab_setting_share.setOnClickListener(this) tab_setting_share.setOnClickListener(this)
tab_setting_book.setOnClickListener(this) tab_setting_book.setOnClickListener(this)
......
...@@ -6,6 +6,7 @@ import android.view.View ...@@ -6,6 +6,7 @@ import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.duben.infinitefunjia.R import com.duben.infinitefunjia.R
import com.duben.infinitefunjia.common.Constant import com.duben.infinitefunjia.common.Constant
import com.duben.infinitefunjia.manager.BookReadManager
import com.duben.infinitefunjia.mvp.model.* import com.duben.infinitefunjia.mvp.model.*
import com.duben.infinitefunjia.mvp.presenters.WatchRecordPresenter import com.duben.infinitefunjia.mvp.presenters.WatchRecordPresenter
import com.duben.infinitefunjia.mvp.views.WatchRecordView import com.duben.infinitefunjia.mvp.views.WatchRecordView
...@@ -38,9 +39,7 @@ class WatchRecordActivity : BaseActivity(), WatchRecordView { ...@@ -38,9 +39,7 @@ class WatchRecordActivity : BaseActivity(), WatchRecordView {
mWatchRecordAdapter?.setEmptyView(emptyView) mWatchRecordAdapter?.setEmptyView(emptyView)
mWatchRecordAdapter?.setNewInstance(datas) mWatchRecordAdapter?.setNewInstance(datas)
mWatchRecordAdapter?.setOnItemClickListener { adapter, view, position -> mWatchRecordAdapter?.setOnItemClickListener { adapter, view, position ->
val bundle = Bundle() BookReadManager.instance.goReadPage(this,datas[position])
bundle.putString(Constant.ROUTE_BOOK_ID, datas.get(position).id)
readyGo(BookReadActivity::class.java, bundle)
} }
mWatchRecordAdapter?.setOnItemCollectClickListener(object : mWatchRecordAdapter?.setOnItemCollectClickListener(object :
WatchRecordAdapter.OnItemCollectClickListener { WatchRecordAdapter.OnItemCollectClickListener {
......
...@@ -16,13 +16,13 @@ import com.duben.infinitefunjia.R ...@@ -16,13 +16,13 @@ import com.duben.infinitefunjia.R
import com.duben.infinitefunjia.ad.AdManager import com.duben.infinitefunjia.ad.AdManager
import com.duben.infinitefunjia.common.AppConfig import com.duben.infinitefunjia.common.AppConfig
import com.duben.infinitefunjia.common.Constant import com.duben.infinitefunjia.common.Constant
import com.duben.infinitefunjia.manager.BookReadManager
import com.duben.infinitefunjia.manager.UserManager import com.duben.infinitefunjia.manager.UserManager
import com.duben.infinitefunjia.mvp.model.BookBean import com.duben.infinitefunjia.mvp.model.BookBean
import com.duben.infinitefunjia.mvp.model.BookListBean import com.duben.infinitefunjia.mvp.model.BookListBean
import com.duben.infinitefunjia.mvp.model.FirstBookBean import com.duben.infinitefunjia.mvp.model.FirstBookBean
import com.duben.infinitefunjia.mvp.presenters.BookCityPresenter import com.duben.infinitefunjia.mvp.presenters.BookCityPresenter
import com.duben.infinitefunjia.mvp.views.BookCityView 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.BookSearchActivity
import com.duben.infinitefunjia.ui.activitys.VipActivity import com.duben.infinitefunjia.ui.activitys.VipActivity
import com.duben.infinitefunjia.ui.adapter.HotBookAdapter import com.duben.infinitefunjia.ui.adapter.HotBookAdapter
...@@ -80,9 +80,7 @@ class BookCityFragment : LazyLoadBaseFragment(), BookCityView, View.OnClickListe ...@@ -80,9 +80,7 @@ class BookCityFragment : LazyLoadBaseFragment(), BookCityView, View.OnClickListe
private fun initHotAdapter() { private fun initHotAdapter() {
hotBookAdapter = HotBookAdapter(requireActivity()) hotBookAdapter = HotBookAdapter(requireActivity())
hotBookAdapter?.setOnItemClickListener { _, _, position -> hotBookAdapter?.setOnItemClickListener { _, _, position ->
val bundle = Bundle() BookReadManager.instance.goReadPage(requireActivity(), hotBookData[position])
bundle.putString(Constant.ROUTE_BOOK_ID, hotBookData[position].id)
readyGo(BookReadActivity::class.java, bundle)
} }
rv_hotbook.layoutManager = GridLayoutManager(requireContext(), 4) rv_hotbook.layoutManager = GridLayoutManager(requireContext(), 4)
val itemDecoration = GridSpacingItemDecoration(5, 10, false) val itemDecoration = GridSpacingItemDecoration(5, 10, false)
...@@ -114,7 +112,7 @@ class BookCityFragment : LazyLoadBaseFragment(), BookCityView, View.OnClickListe ...@@ -114,7 +112,7 @@ class BookCityFragment : LazyLoadBaseFragment(), BookCityView, View.OnClickListe
view.setOnClickListener { view.setOnClickListener {
val bundle = Bundle() val bundle = Bundle()
bundle.putString(Constant.ROUTE_BOOK_ID, headData.id) bundle.putString(Constant.ROUTE_BOOK_ID, headData.id)
readyGo(BookReadActivity::class.java, bundle) BookReadManager.instance.goReadPage(requireActivity(), headData)
} }
return view return view
} }
...@@ -122,9 +120,7 @@ class BookCityFragment : LazyLoadBaseFragment(), BookCityView, View.OnClickListe ...@@ -122,9 +120,7 @@ class BookCityFragment : LazyLoadBaseFragment(), BookCityView, View.OnClickListe
private fun initNewAdapter() { private fun initNewAdapter() {
newBookAdapter = NewBookAdapter(requireActivity()) newBookAdapter = NewBookAdapter(requireActivity())
newBookAdapter?.setOnItemClickListener { _, _, position -> newBookAdapter?.setOnItemClickListener { _, _, position ->
val bundle = Bundle() BookReadManager.instance.goReadPage(requireActivity(), newBookData[position])
bundle.putString(Constant.ROUTE_BOOK_ID, newBookData[position].id)
readyGo(BookReadActivity::class.java, bundle)
} }
rv_newbook.layoutManager = GridLayoutManager(requireContext(), 2) rv_newbook.layoutManager = GridLayoutManager(requireContext(), 2)
rv_newbook.adapter = newBookAdapter rv_newbook.adapter = newBookAdapter
...@@ -184,9 +180,7 @@ class BookCityFragment : LazyLoadBaseFragment(), BookCityView, View.OnClickListe ...@@ -184,9 +180,7 @@ class BookCityFragment : LazyLoadBaseFragment(), BookCityView, View.OnClickListe
banner.addBannerLifecycleObserver(this) banner.addBannerLifecycleObserver(this)
.setAdapter(ImageTitleAdapter(data.records)) .setAdapter(ImageTitleAdapter(data.records))
.setOnBannerListener { data2, _ -> .setOnBannerListener { data2, _ ->
val bundle = Bundle() BookReadManager.instance.goReadPage(requireActivity(), data2 as BookBean)
bundle.putString(Constant.ROUTE_BOOK_ID, (data2 as BookBean).id)
readyGo(BookReadActivity::class.java, bundle)
} }
} }
...@@ -194,9 +188,7 @@ class BookCityFragment : LazyLoadBaseFragment(), BookCityView, View.OnClickListe ...@@ -194,9 +188,7 @@ class BookCityFragment : LazyLoadBaseFragment(), BookCityView, View.OnClickListe
override fun getSoltVedioSuc(data: FirstBookBean) { override fun getSoltVedioSuc(data: FirstBookBean) {
val firstVedio = AppPreferencesManager.get().getBoolean(Constant.IS_FIRST_VEDIO, true) val firstVedio = AppPreferencesManager.get().getBoolean(Constant.IS_FIRST_VEDIO, true)
if (data.articleMsg != null && firstVedio) { if (data.articleMsg != null && firstVedio) {
val bundle = Bundle() BookReadManager.instance.goReadPage(requireActivity(), data.articleMsg)
bundle.putString(Constant.ROUTE_BOOK_ID, data.articleMsg.id)
readyGo(BookReadActivity::class.java, bundle)
} else { } else {
if (!UserManager.getInstance().vipFlag) { if (!UserManager.getInstance().vipFlag) {
val bundle = Bundle() val bundle = Bundle()
......
...@@ -6,12 +6,11 @@ import androidx.recyclerview.widget.LinearLayoutManager ...@@ -6,12 +6,11 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.duben.infinitefunjia.R import com.duben.infinitefunjia.R
import com.duben.infinitefunjia.ad.express.MainExpressManager import com.duben.infinitefunjia.ad.express.MainExpressManager
import com.duben.infinitefunjia.common.Constant 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.BookBean
import com.duben.infinitefunjia.mvp.model.BookListBean import com.duben.infinitefunjia.mvp.model.BookListBean
import com.duben.infinitefunjia.mvp.presenters.PicContentPresenter import com.duben.infinitefunjia.mvp.presenters.PicContentPresenter
import com.duben.infinitefunjia.mvp.views.PicContentView 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.adapter.CountAdapter
import com.duben.infinitefunjia.ui.fragment.base.LazyLoadBaseFragment import com.duben.infinitefunjia.ui.fragment.base.LazyLoadBaseFragment
import com.scwang.smartrefresh.layout.api.RefreshLayout import com.scwang.smartrefresh.layout.api.RefreshLayout
...@@ -120,9 +119,7 @@ class BookListFragment : LazyLoadBaseFragment(), PicContentView, OnRefreshListen ...@@ -120,9 +119,7 @@ class BookListFragment : LazyLoadBaseFragment(), PicContentView, OnRefreshListen
hotStyleAdapter.setOnCountItemClickListener(object : hotStyleAdapter.setOnCountItemClickListener(object :
CountAdapter.OnCountItemClickListener { CountAdapter.OnCountItemClickListener {
override fun onItemClick(bean: BookBean) { override fun onItemClick(bean: BookBean) {
val bundle = Bundle() BookReadManager.instance.goReadPage(requireActivity(), bean)
bundle.putString(Constant.ROUTE_BOOK_ID, bean.id)
readyGo(BookReadActivity::class.java, bundle)
} }
}) })
} }
......
package com.duben.infinitefunjia.ui.fragment package com.duben.infinitefunjia.ui.fragment
import android.os.Bundle
import android.view.View import android.view.View
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import com.duben.infinitefunjia.R import com.duben.infinitefunjia.R
import com.duben.infinitefunjia.common.AppConfig import com.duben.infinitefunjia.common.AppConfig
import com.duben.infinitefunjia.common.Constant import com.duben.infinitefunjia.common.Constant
import com.duben.infinitefunjia.manager.BookReadManager
import com.duben.infinitefunjia.manager.ReadTimeCount import com.duben.infinitefunjia.manager.ReadTimeCount
import com.duben.infinitefunjia.mvp.model.BookBean import com.duben.infinitefunjia.mvp.model.BookBean
import com.duben.infinitefunjia.mvp.model.BookListBean import com.duben.infinitefunjia.mvp.model.BookListBean
import com.duben.infinitefunjia.mvp.presenters.BookShelfPresenter import com.duben.infinitefunjia.mvp.presenters.BookShelfPresenter
import com.duben.infinitefunjia.mvp.views.BookShelfView 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.activitys.MainActivity
import com.duben.infinitefunjia.ui.adapter.BookShelfAdapter import com.duben.infinitefunjia.ui.adapter.BookShelfAdapter
import com.duben.infinitefunjia.ui.adapter.LikeBookAdapter import com.duben.infinitefunjia.ui.adapter.LikeBookAdapter
...@@ -48,9 +47,7 @@ class BookShelfFragment : LazyLoadBaseFragment(), BookShelfView, View.OnClickLis ...@@ -48,9 +47,7 @@ class BookShelfFragment : LazyLoadBaseFragment(), BookShelfView, View.OnClickLis
return@setOnItemClickListener return@setOnItemClickListener
} }
val bundle = Bundle() BookReadManager.instance.goReadPage(requireActivity(),shelfBookData[position])
bundle.putString(Constant.ROUTE_BOOK_ID, shelfBookData[position].id)
readyGo(BookReadActivity::class.java, bundle)
} }
rv_bookshelf.layoutManager = GridLayoutManager(requireContext(), 3) rv_bookshelf.layoutManager = GridLayoutManager(requireContext(), 3)
val itemDecoration = GridSpacingItemDecoration(3, 10, false) val itemDecoration = GridSpacingItemDecoration(3, 10, false)
...@@ -61,9 +58,7 @@ class BookShelfFragment : LazyLoadBaseFragment(), BookShelfView, View.OnClickLis ...@@ -61,9 +58,7 @@ class BookShelfFragment : LazyLoadBaseFragment(), BookShelfView, View.OnClickLis
private fun initLikeAdapter() { private fun initLikeAdapter() {
likeBookAdapter = LikeBookAdapter(requireActivity()) likeBookAdapter = LikeBookAdapter(requireActivity())
likeBookAdapter?.setOnItemClickListener { _, _, position -> likeBookAdapter?.setOnItemClickListener { _, _, position ->
val bundle = Bundle() BookReadManager.instance.goReadPage(requireActivity(),likeBookData[position])
bundle.putString(Constant.ROUTE_BOOK_ID, likeBookData[position].id)
readyGo(BookReadActivity::class.java, bundle)
} }
rv_booklike.layoutManager = GridLayoutManager(requireContext(), 4) rv_booklike.layoutManager = GridLayoutManager(requireContext(), 4)
val itemDecoration = GridSpacingItemDecoration(4, 10, false) 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 @@ ...@@ -82,6 +82,7 @@
android:id="@+id/tv_content" android:id="@+id/tv_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:lineSpacingMultiplier="2"
android:textColor="@color/black" /> android:textColor="@color/black" />
<LinearLayout <LinearLayout
...@@ -189,7 +190,8 @@ ...@@ -189,7 +190,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1.0" android:layout_weight="1.0"
android:gravity="center" android:gravity="center"
android:orientation="vertical"> android:orientation="vertical"
android:visibility="gone">
<ImageView <ImageView
android:layout_width="20dp" android:layout_width="20dp"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/view_content" android:id="@+id/read_drawer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:background="@color/white"
android:orientation="vertical">
<include layout="@layout/header_layout" />
<LinearLayout <LinearLayout
android:id="@+id/view_book"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
...@@ -100,6 +95,7 @@ ...@@ -100,6 +95,7 @@
<LinearLayout <LinearLayout
android:id="@+id/tab_setting_book" android:id="@+id/tab_setting_book"
android:layout_width="0dp" android:layout_width="0dp"
android:background="@color/white"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:gravity="center" android:gravity="center"
...@@ -147,7 +143,38 @@ ...@@ -147,7 +143,38 @@
</LinearLayout> </LinearLayout>
</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>
</LinearLayout> </androidx.drawerlayout.widget.DrawerLayout>
...@@ -32,13 +32,13 @@ ...@@ -32,13 +32,13 @@
android:maxHeight="5dp" android:maxHeight="5dp"
android:min="14" android:min="14"
android:minHeight="5dp" android:minHeight="5dp"
android:progress="17" /> android:progress="18" />
<TextView <TextView
android:id="@+id/tv_seek" android:id="@+id/tv_seek"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="17" android:text="18"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="14sp" /> android:textSize="14sp" />
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/header_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="70dp" android:layout_height="70dp"
android:id="@+id/header_container"
android:paddingTop="20dp"> android:paddingTop="20dp">
<ImageView <ImageView
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
android:id="@+id/tv_title" android:id="@+id/tv_title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLength="8"
android:singleLine="true"
android:textColor="@color/product_net_text" android:textColor="@color/product_net_text"
android:textSize="18sp" android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent" 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