Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_book
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
android
android_book
Commits
64b8bfe2
Commit
64b8bfe2
authored
Sep 29, 2024
by
jyx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码优化
parent
06eb05e5
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
121 additions
and
66 deletions
+121
-66
BookConstant.kt
...main/java/com/duben/infinitefunjia/common/BookConstant.kt
+9
-5
NetworkPageLoader.java
...java/com/duben/infinitefunjia/read/NetworkPageLoader.java
+1
-1
PageLoader.java
...c/main/java/com/duben/infinitefunjia/read/PageLoader.java
+13
-8
BookRecordModel.java
...com/duben/infinitefunjia/read/models/BookRecordModel.java
+22
-0
BookReadActivity.kt
...com/duben/infinitefunjia/ui/activitys/BookReadActivity.kt
+7
-0
LongBookReadActivity.kt
...duben/infinitefunjia/ui/activitys/LongBookReadActivity.kt
+45
-45
LongBookSettingDialog.kt
.../duben/infinitefunjia/ui/widgets/LongBookSettingDialog.kt
+10
-0
activity_long_book_read.xml
book/app/src/main/res/layout/activity_long_book_read.xml
+9
-2
colors.xml
book/app/src/main/res/values/colors.xml
+5
-5
No files found.
book/app/src/main/java/com/duben/infinitefunjia/common/BookConstant.kt
View file @
64b8bfe2
...
...
@@ -2,14 +2,18 @@ package com.duben.infinitefunjia.common
import
android.graphics.Color
const
val
BOOK_CONTENT_COLOR
=
"BOOK_CONTENT_COLOR"
const
val
BOOK_CONTENT_SIZE
=
"BOOK_CONTENT_SIZE"
enum
class
BookConstant
(
var
color
:
Int
)
{
BOOK_CONTENT_COLOR_1
(
Color
.
parseColor
(
"#E0E4E7"
)),
BOOK_CONTENT_COLOR_2
(
Color
.
parseColor
(
"#e7e7e7"
)),
BOOK_CONTENT_COLOR_3
(
Color
.
parseColor
(
"#d4e0c6"
)),
BOOK_CONTENT_COLOR_4
(
Color
.
parseColor
(
"#ccd8e4"
)),
BOOK_CONTENT_COLOR_5
(
Color
.
parseColor
(
"#f9d4d4"
)),
BOOK_CONTENT_COLOR_6
(
Color
.
parseColor
(
"#b1b1b1"
)),
BOOK_CONTENT_COLOR_2
(
Color
.
parseColor
(
"#d4e0c6"
)),
BOOK_CONTENT_COLOR_3
(
Color
.
parseColor
(
"#ccd8e4"
)),
BOOK_CONTENT_COLOR_4
(
Color
.
parseColor
(
"#f9d4d4"
)),
BOOK_CONTENT_COLOR_5
(
Color
.
parseColor
(
"#b1b1b1"
)),
BOOK_CONTENT_COLOR_6
(
Color
.
parseColor
(
"#000000"
)),
BOOK_CONTENT_TEXT_COLOR_1
(
Color
.
BLACK
),
BOOK_CONTENT_TEXT_COLOR_2
(
Color
.
WHITE
),
}
\ No newline at end of file
book/app/src/main/java/com/duben/infinitefunjia/read/NetworkPageLoader.java
View file @
64b8bfe2
...
...
@@ -65,6 +65,7 @@ public class NetworkPageLoader extends PageLoader {
//已缓存
if
(
mChapterList
!=
null
&&
!
mChapterList
.
isEmpty
())
{
loadCurrentChapter
(
curChapterIndex
);
chapterChangeListener
.
finishedLoadChapters
(
mChapterList
);
return
;
}
...
...
@@ -249,7 +250,6 @@ public class NetworkPageLoader extends PageLoader {
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
TxtChapterModel
bookChapter
=
bookChapters
.
get
(
i
);
if
(!
bookChapter
.
isLock
)
{
Log
.
v
(
"yzll"
,
"缓存章节:"
+
bookChapter
.
getTitle
());
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"articleId"
,
bookModel
.
getBookId
());
params
.
put
(
"chapterId"
,
bookChapter
.
getChapterId
());
...
...
book/app/src/main/java/com/duben/infinitefunjia/read/PageLoader.java
View file @
64b8bfe2
...
...
@@ -2,13 +2,13 @@ package com.duben.infinitefunjia.read;
import
android.graphics.Bitmap
;
import
android.graphics.Canvas
;
import
android.graphics.Color
;
import
android.graphics.Paint
;
import
android.graphics.Rect
;
import
android.graphics.RectF
;
import
android.graphics.Typeface
;
import
android.text.TextPaint
;
import
com.duben.infinitefunjia.common.BookConstant
;
import
com.duben.infinitefunjia.manager.UserManager
;
import
com.duben.infinitefunjia.read.models.BookModel
;
import
com.duben.infinitefunjia.read.models.TxtChapterModel
;
...
...
@@ -76,9 +76,9 @@ public abstract class PageLoader {
//字体大小 单位dp
int
mTextSize
=
18
;
//背景颜色
int
bgColor
=
Color
.
WHITE
;
int
bgColor
=
BookConstant
.
BOOK_CONTENT_COLOR_1
.
getColor
()
;
//字体颜色
int
textColor
=
Color
.
BLACK
;
int
textColor
=
BookConstant
.
BOOK_CONTENT_TEXT_COLOR_1
.
getColor
()
;
//记录上一次颜色 用于恢复
int
lastBgColor
;
int
lastTextColor
;
...
...
@@ -122,14 +122,14 @@ public abstract class PageLoader {
private
void
initPaint
()
{
// 绘制页面内容的画笔
mContentTextPaint
=
new
TextPaint
();
mContentTextPaint
.
setColor
(
Color
.
BLACK
);
mContentTextPaint
.
setColor
(
textColor
);
mContentTextPaint
.
setTextSize
(
dp2px
(
mTextSize
));
mContentTextPaint
.
setAntiAlias
(
true
);
mContentTextPaint
.
setSubpixelText
(
true
);
// 绘制标题的画笔
mTitleTextPaint
=
new
TextPaint
();
mTitleTextPaint
.
setColor
(
Color
.
BLACK
);
mTitleTextPaint
.
setColor
(
textColor
);
mTitleTextPaint
.
setTextSize
(
dp2px
(
mTextSize
+
5
));
mTitleTextPaint
.
setStyle
(
Paint
.
Style
.
FILL_AND_STROKE
);
mTitleTextPaint
.
setTypeface
(
Typeface
.
DEFAULT_BOLD
);
...
...
@@ -143,7 +143,6 @@ public abstract class PageLoader {
mTipPaint
.
setAntiAlias
(
true
);
mTipPaint
.
setSubpixelText
(
true
);
// 绘制电池的画笔
mBatteryPaint
=
new
Paint
();
mBatteryPaint
.
setAntiAlias
(
true
);
...
...
@@ -170,9 +169,10 @@ public abstract class PageLoader {
BufferedReader
br
=
getChapterReader
(
chapterModel
);
if
(
br
!=
null
)
{
pageList
=
loadPages
(
chapterModel
,
br
);
}
else
{
// reloadPageList();
}
// else {
// reloadPageList();
// }
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
...
...
@@ -597,6 +597,8 @@ public abstract class PageLoader {
//设置字体大小
public
void
setTextSize
(
int
textSize
)
{
mTextSize
=
textSize
;
mTitleTextPaint
.
setTextSize
(
dp2px
(
textSize
+
5
));
mContentTextPaint
.
setTextSize
(
dp2px
(
textSize
));
}
//更新字体大小
...
...
@@ -608,6 +610,9 @@ public abstract class PageLoader {
}
private
void
updateCurPage
()
{
if
(
mCurPageList
==
null
||
mCurPageList
.
size
()
<=
0
)
{
return
;
}
if
(
curPageIndex
>=
mCurPageList
.
size
())
{
mCurPage
=
mCurPageList
.
get
(
0
);
}
else
{
...
...
book/app/src/main/java/com/duben/infinitefunjia/read/models/BookRecordModel.java
View file @
64b8bfe2
...
...
@@ -4,6 +4,7 @@ import org.litepal.crud.LitePalSupport;
public
class
BookRecordModel
extends
LitePalSupport
{
private
String
book_id
;
private
String
book_title
;
private
int
chapterPos
;
private
int
pagePos
;
...
...
@@ -12,6 +13,14 @@ public class BookRecordModel extends LitePalSupport {
private
int
text_size
;
private
int
anim_type
;
public
String
getBook_title
()
{
return
book_title
;
}
public
void
setBook_title
(
String
book_title
)
{
this
.
book_title
=
book_title
;
}
public
String
getBook_id
()
{
return
book_id
;
}
...
...
@@ -67,4 +76,17 @@ public class BookRecordModel extends LitePalSupport {
public
void
setAnim_type
(
int
anim_type
)
{
this
.
anim_type
=
anim_type
;
}
@Override
public
String
toString
()
{
return
"BookRecordModel{"
+
"book_id='"
+
book_id
+
'\''
+
", chapterPos="
+
chapterPos
+
", pagePos="
+
pagePos
+
", text_color="
+
text_color
+
", page_color="
+
page_color
+
", text_size="
+
text_size
+
", anim_type="
+
anim_type
+
'}'
;
}
}
book/app/src/main/java/com/duben/infinitefunjia/ui/activitys/BookReadActivity.kt
View file @
64b8bfe2
package
com.duben.infinitefunjia.ui.activitys
import
android.graphics.Color
import
android.os.Bundle
import
android.view.View
import
androidx.core.content.ContextCompat
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.BookConstant
import
com.duben.infinitefunjia.common.Constant
import
com.duben.infinitefunjia.manager.ReadTimeCount
import
com.duben.infinitefunjia.mvp.model.BookContentBean
...
...
@@ -89,6 +91,11 @@ class BookReadActivity : BaseActivity(), View.OnClickListener, BookReadView {
}
override
fun
onBgColor
(
color
:
Int
)
{
var
textColor
=
Color
.
BLACK
if
(
color
==
BookConstant
.
BOOK_CONTENT_COLOR_6
.
color
)
{
textColor
=
Color
.
WHITE
}
tv_content
.
setTextColor
(
textColor
)
view_book
.
setBackgroundColor
(
color
)
AppPreferencesManager
.
get
().
put
(
BOOK_CONTENT_COLOR
,
color
)
}
...
...
book/app/src/main/java/com/duben/infinitefunjia/ui/activitys/LongBookReadActivity.kt
View file @
64b8bfe2
package
com.duben.infinitefunjia.ui.activitys
import
android.app.Dialog
import
android.graphics.Color
import
android.os.Bundle
import
android.text.TextUtils
import
android.view.View
import
androidx.core.view.GravityCompat
import
androidx.recyclerview.widget.LinearLayoutManager
...
...
@@ -58,9 +58,9 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
}
override
fun
initViewsAndEvents
()
{
popBookSettingDialog
()
initWidgets
()
initListener
()
popBookSettingDialog
()
popBookVipDialog
()
readPresenter
.
attachView
(
this
)
mBookModel
?.
let
{
readPresenter
.
addReadRecord
(
it
.
bookId
)
}
...
...
@@ -74,23 +74,24 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
override
fun
onPause
()
{
super
.
onPause
()
ReadTimeCount
.
instance
.
endCountReadTime
()
//保存阅读记录
if
(
LitePal
.
where
(
"book_id=?"
,
(
mBookModel
?.
id
).
toString
())
.
findFirst
(
TxtChapterModel
::
class
.
java
)
==
null
)
{
mPageLoader
?.
let
{
LitePal
.
saveAll
<
LitePalSupport
>(
it
.
mChapterList
)
}
}
val
bookRecord
=
BookRecordModel
()
mPageLoader
?.
let
{
//保存阅读记录
if
(
LitePal
.
where
(
"book_id=?"
,
(
mBookModel
?.
id
).
toString
())
.
findFirst
(
TxtChapterModel
::
class
.
java
)
==
null
)
{
it
.
let
{
LitePal
.
saveAll
<
LitePalSupport
>(
it
.
mChapterList
)
}
}
bookRecord
.
chapterPos
=
it
.
curChapterIndex
bookRecord
.
pagePos
=
it
.
curPageIndex
bookRecord
.
book_id
=
(
mBookModel
?.
id
).
toString
()
bookRecord
.
book_title
=
it
.
bookTitle
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=?"
,
(
mBookModel
?.
id
).
toString
())
bookRecord
.
saveOrUpdate
(
"book_id=?"
,
mBookModel
?.
id
.
toString
())
}
}
...
...
@@ -129,8 +130,12 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
}
override
fun
onBgColor
(
color
:
Int
)
{
var
textColor
=
BookConstant
.
BOOK_CONTENT_TEXT_COLOR_1
.
color
if
(
color
==
BookConstant
.
BOOK_CONTENT_COLOR_6
.
color
)
{
textColor
=
BookConstant
.
BOOK_CONTENT_TEXT_COLOR_2
.
color
}
bookSettingDialog
?.
setSetting
(
color
)
mPageLoader
?.
setPageStyle
(
color
,
Color
.
BLACK
)
mPageLoader
?.
setPageStyle
(
color
,
textColor
)
}
})
}
...
...
@@ -153,7 +158,7 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
//书籍
mPageLoader
=
pageview
.
getPageLoader
(
mBookModel
)
pageview
.
animType
=
AnimType
.
ALIKE
pageview
.
animType
=
AnimType
.
COVER
//从数据库加载分章信息
mPageLoader
?.
mChapterList
=
LitePal
.
where
(
"book_id=?"
,
""
+
mBookModel
?.
id
)
.
find
(
TxtChapterModel
::
class
.
java
)
...
...
@@ -165,11 +170,11 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
bookSettingDialog
?.
setSetting
(
recordModel
.
page_color
,
recordModel
.
text_size
)
mPageLoader
?.
run
{
tv_title
.
text
=
"${recordModel.book_title}"
curChapterIndex
=
recordModel
.
chapterPos
curPageIndex
=
recordModel
.
pagePos
setTextSize
(
recordModel
.
text_size
)
textColor
=
recordModel
.
text_color
setPageBgColor
(
recordModel
.
page_color
)
setPageStyle
(
recordModel
.
page_color
,
recordModel
.
text_color
)
when
(
recordModel
.
anim_type
)
{
1
->
pageview
.
animType
=
AnimType
.
SLIDE
...
...
@@ -178,38 +183,8 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
else
->
pageview
.
animType
=
AnimType
.
NONE
}
}
}
else
{
mPageLoader
?.
let
{
it
.
setPageBgColor
(
BookConstant
.
BOOK_CONTENT_COLOR_1
.
color
)
it
.
setTextSize
(
18
)
it
.
textColor
=
Color
.
BLACK
}
// pageview.animType = AnimType.SLIDE
bookSettingDialog
?.
setSetting
(
BookConstant
.
BOOK_CONTENT_COLOR_1
.
color
,
18
)
}
pageview
.
setOnCenterClickListener
(
object
:
OnCenterClickListener
{
override
fun
centerClicked
()
{
if
(
isShowSetting
)
{
view_setting
.
visibility
=
View
.
VISIBLE
tab_setting_top
.
visibility
=
View
.
VISIBLE
}
else
{
view_setting
.
visibility
=
View
.
GONE
tab_setting_top
.
visibility
=
View
.
GONE
}
isShowSetting
=
!
isShowSetting
}
override
fun
touPage
()
{
if
(
isShowSetting
)
{
view_setting
.
visibility
=
View
.
GONE
tab_setting_top
.
visibility
=
View
.
GONE
isShowSetting
=
false
}
}
})
//初始化目录
initChapterRecyclerView
()
}
...
...
@@ -236,8 +211,11 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
override
fun
requestChapters
(
requestChapters
:
List
<
TxtChapterModel
>)
{}
override
fun
finishedLoadChapters
(
bookChapters
:
List
<
TxtChapterModel
>)
{
mPageLoader
?.
let
{
tv_title
.
text
=
"阅读:${it.bookTitle}"
it
.
pageView
.
showCategory
()
readChaptersAdapter
?.
setChapter
(
it
.
curChapterIndex
)
}
if
(
TextUtils
.
isEmpty
(
tv_title
.
text
))
{
tv_title
.
text
=
"${mBookModel?.bookTitle}"
}
readChaptersAdapter
?.
setChapterModels
(
bookChapters
)
}
...
...
@@ -247,6 +225,28 @@ class LongBookReadActivity : BaseActivity(), View.OnClickListener, BookReadView
}
})
read_rv_category
.
adapter
=
readChaptersAdapter
pageview
.
setOnCenterClickListener
(
object
:
OnCenterClickListener
{
override
fun
centerClicked
()
{
if
(
isShowSetting
)
{
view_setting
.
visibility
=
View
.
VISIBLE
tab_setting_top
.
visibility
=
View
.
VISIBLE
}
else
{
view_setting
.
visibility
=
View
.
GONE
tab_setting_top
.
visibility
=
View
.
GONE
}
isShowSetting
=
!
isShowSetting
}
override
fun
touPage
()
{
if
(
isShowSetting
)
{
view_setting
.
visibility
=
View
.
GONE
tab_setting_top
.
visibility
=
View
.
GONE
isShowSetting
=
false
}
}
})
}
//目录
...
...
book/app/src/main/java/com/duben/infinitefunjia/ui/widgets/LongBookSettingDialog.kt
View file @
64b8bfe2
...
...
@@ -27,6 +27,10 @@ class LongBookSettingDialog(context: Context) : Dialog(context, R.style.dialog)
setCancelable
(
true
)
setCanceledOnTouchOutside
(
true
)
// setListener()
}
private
fun
setListener
()
{
(
seekbar
as
SeekBar
).
setOnSeekBarChangeListener
(
object
:
SeekBar
.
OnSeekBarChangeListener
{
override
fun
onProgressChanged
(
seekBar
:
SeekBar
?,
progress
:
Int
,
fromUser
:
Boolean
)
{
tv_seek
.
text
=
"$progress"
...
...
@@ -75,6 +79,9 @@ class LongBookSettingDialog(context: Context) : Dialog(context, R.style.dialog)
fun
setSetting
(
color
:
Int
?
=
null
,
size
:
Int
?
=
null
)
{
(
seekbar
as
SeekBar
).
setOnSeekBarChangeListener
(
null
)
rg_color
.
setOnCheckedChangeListener
(
null
)
size
?.
let
{
tv_seek
.
text
=
"$it"
seekbar
.
progress
=
it
...
...
@@ -111,7 +118,10 @@ class LongBookSettingDialog(context: Context) : Dialog(context, R.style.dialog)
rb_color6
.
scaleY
=
1.2f
rb_color6
.
isChecked
=
true
}
else
->
{}
}
setListener
()
}
fun
setOnBookSettingCallback
(
onLongBookSettingCallback
:
OnLongBookSettingCallback
)
{
...
...
book/app/src/main/res/layout/activity_long_book_read.xml
View file @
64b8bfe2
...
...
@@ -119,14 +119,21 @@
android:src=
"@mipmap/ic_arrow_back"
/>
<TextView
android:id=
"@+id/tv_title"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"10dp"
android:text=
"阅读:"
android:textColor=
"@color/black"
android:textSize=
"16sp"
android:textStyle=
"bold"
/>
<TextView
android:id=
"@+id/tv_title"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:ellipsize=
"end"
android:lines=
"1"
android:maxLength=
"13"
android:text=
"阅读:"
android:textColor=
"@color/black"
android:textSize=
"16sp"
android:textStyle=
"bold"
/>
...
...
book/app/src/main/res/values/colors.xml
View file @
64b8bfe2
...
...
@@ -40,11 +40,11 @@
<color
name=
"book_content_color1"
>
#E0E4E7
</color>
<color
name=
"book_content_color2"
>
#
e7e7e7
</color>
<color
name=
"book_content_color3"
>
#
d4e0c6
</color>
<color
name=
"book_content_color4"
>
#
ccd8e
4
</color>
<color
name=
"book_content_color5"
>
#
f9d4d4
</color>
<color
name=
"book_content_color6"
>
#
b1b1b1
</color>
<color
name=
"book_content_color2"
>
#
d4e0c6
</color>
<color
name=
"book_content_color3"
>
#
ccd8e4
</color>
<color
name=
"book_content_color4"
>
#
f9d4d
4
</color>
<color
name=
"book_content_color5"
>
#
b1b1b1
</color>
<color
name=
"book_content_color6"
>
#
000000
</color>
</resources>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment