|  |  |  | @ -5,13 +5,19 @@ import android.content.Context | 
			
		
	
		
			
				
					|  |  |  |  | import android.graphics.drawable.Drawable | 
			
		
	
		
			
				
					|  |  |  |  | import android.view.MotionEvent | 
			
		
	
		
			
				
					|  |  |  |  | import android.widget.FrameLayout | 
			
		
	
		
			
				
					|  |  |  |  | import androidx.core.view.isGone | 
			
		
	
		
			
				
					|  |  |  |  | import androidx.core.view.isInvisible | 
			
		
	
		
			
				
					|  |  |  |  | import com.hankcs.hanlp.HanLP | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.R | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.constant.AppConst.timeFormat | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.help.AppConfig | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.help.ReadBookConfig | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.help.ReadTipConfig | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.ui.book.read.page.entities.TextPage | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.utils.* | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.utils.dp | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.utils.getCompatColor | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.utils.statusBarHeight | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.utils.visible | 
			
		
	
		
			
				
					|  |  |  |  | import kotlinx.android.synthetic.main.view_book_page.view.* | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.* | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -20,13 +26,15 @@ class ContentView(context: Context) : FrameLayout(context) { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private var battery = 100 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     val headerHeight: Int | 
			
		
	
		
			
				
					|  |  |  |  |         get() = if (ReadBookConfig.hideStatusBar) ll_header.height else context.statusBarHeight | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     init { | 
			
		
	
		
			
				
					|  |  |  |  |         //设置背景防止切换背景时文字重叠 | 
			
		
	
		
			
				
					|  |  |  |  |         setBackgroundColor(context.getCompatColor(R.color.background)) | 
			
		
	
		
			
				
					|  |  |  |  |         inflate(context, R.layout.view_book_page, this) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         upTipStyle() | 
			
		
	
		
			
				
					|  |  |  |  |         upStyle() | 
			
		
	
		
			
				
					|  |  |  |  |         upTime() | 
			
		
	
		
			
				
					|  |  |  |  |         content_text_view.upView = { | 
			
		
	
		
			
				
					|  |  |  |  |             setProgress(it) | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
	
		
			
				
					|  |  |  | @ -34,25 +42,27 @@ class ContentView(context: Context) : FrameLayout(context) { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     fun upStyle() { | 
			
		
	
		
			
				
					|  |  |  |  |         ReadBookConfig.apply { | 
			
		
	
		
			
				
					|  |  |  |  |             tv_top_left.typeface = ChapterProvider.typeface | 
			
		
	
		
			
				
					|  |  |  |  |             tv_top_right.typeface = ChapterProvider.typeface | 
			
		
	
		
			
				
					|  |  |  |  |             tv_bottom_left.typeface = ChapterProvider.typeface | 
			
		
	
		
			
				
					|  |  |  |  |             tv_bottom_right.typeface = ChapterProvider.typeface | 
			
		
	
		
			
				
					|  |  |  |  |             battery_view.typeface = ChapterProvider.typeface | 
			
		
	
		
			
				
					|  |  |  |  |             tv_header_left.typeface = ChapterProvider.typeface | 
			
		
	
		
			
				
					|  |  |  |  |             tv_header_middle.typeface = ChapterProvider.typeface | 
			
		
	
		
			
				
					|  |  |  |  |             tv_header_right.typeface = ChapterProvider.typeface | 
			
		
	
		
			
				
					|  |  |  |  |             tv_footer_left.typeface = ChapterProvider.typeface | 
			
		
	
		
			
				
					|  |  |  |  |             tv_footer_middle.typeface = ChapterProvider.typeface | 
			
		
	
		
			
				
					|  |  |  |  |             tv_footer_right.typeface = ChapterProvider.typeface | 
			
		
	
		
			
				
					|  |  |  |  |             tv_header_left.setColor(durConfig.textColor()) | 
			
		
	
		
			
				
					|  |  |  |  |             tv_header_middle.setColor(durConfig.textColor()) | 
			
		
	
		
			
				
					|  |  |  |  |             tv_header_right.setColor(durConfig.textColor()) | 
			
		
	
		
			
				
					|  |  |  |  |             tv_footer_left.setColor(durConfig.textColor()) | 
			
		
	
		
			
				
					|  |  |  |  |             tv_footer_middle.setColor(durConfig.textColor()) | 
			
		
	
		
			
				
					|  |  |  |  |             tv_footer_right.setColor(durConfig.textColor()) | 
			
		
	
		
			
				
					|  |  |  |  |             //显示状态栏时隐藏header | 
			
		
	
		
			
				
					|  |  |  |  |             if (hideStatusBar) { | 
			
		
	
		
			
				
					|  |  |  |  |                 ll_header.setPadding( | 
			
		
	
		
			
				
					|  |  |  |  |                     headerPaddingLeft.dp, | 
			
		
	
		
			
				
					|  |  |  |  |                     headerPaddingTop.dp, | 
			
		
	
		
			
				
					|  |  |  |  |                     headerPaddingRight.dp, | 
			
		
	
		
			
				
					|  |  |  |  |                     headerPaddingBottom.dp | 
			
		
	
		
			
				
					|  |  |  |  |                 ) | 
			
		
	
		
			
				
					|  |  |  |  |                 ll_header.visible() | 
			
		
	
		
			
				
					|  |  |  |  |                 page_panel.setPadding(0, 0, 0, 0) | 
			
		
	
		
			
				
					|  |  |  |  |             } else { | 
			
		
	
		
			
				
					|  |  |  |  |                 ll_header.gone() | 
			
		
	
		
			
				
					|  |  |  |  |                 page_panel.setPadding(0, context.statusBarHeight, 0, 0) | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             vw_status_bar.setPadding(0, context.statusBarHeight, 0, 0) | 
			
		
	
		
			
				
					|  |  |  |  |             vw_status_bar.isGone = hideStatusBar | 
			
		
	
		
			
				
					|  |  |  |  |             ll_header.setPadding( | 
			
		
	
		
			
				
					|  |  |  |  |                 headerPaddingLeft.dp, | 
			
		
	
		
			
				
					|  |  |  |  |                 headerPaddingTop.dp, | 
			
		
	
		
			
				
					|  |  |  |  |                 headerPaddingRight.dp, | 
			
		
	
		
			
				
					|  |  |  |  |                 headerPaddingBottom.dp | 
			
		
	
		
			
				
					|  |  |  |  |             ) | 
			
		
	
		
			
				
					|  |  |  |  |             ll_footer.setPadding( | 
			
		
	
		
			
				
					|  |  |  |  |                 footerPaddingLeft.dp, | 
			
		
	
		
			
				
					|  |  |  |  |                 footerPaddingTop.dp, | 
			
		
	
	
		
			
				
					|  |  |  | @ -62,47 +72,61 @@ class ContentView(context: Context) : FrameLayout(context) { | 
			
		
	
		
			
				
					|  |  |  |  |             vw_top_divider.visible(showHeaderLine) | 
			
		
	
		
			
				
					|  |  |  |  |             vw_bottom_divider.visible(showFooterLine) | 
			
		
	
		
			
				
					|  |  |  |  |             content_text_view.upVisibleRect() | 
			
		
	
		
			
				
					|  |  |  |  |             durConfig.textColor().let { | 
			
		
	
		
			
				
					|  |  |  |  |                 tv_top_left.setTextColor(it) | 
			
		
	
		
			
				
					|  |  |  |  |                 tv_top_right.setTextColor(it) | 
			
		
	
		
			
				
					|  |  |  |  |                 tv_bottom_left.setTextColor(it) | 
			
		
	
		
			
				
					|  |  |  |  |                 tv_bottom_right.setTextColor(it) | 
			
		
	
		
			
				
					|  |  |  |  |                 battery_view.setColor(it) | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             if (hideStatusBar) { | 
			
		
	
		
			
				
					|  |  |  |  |                 tv_bottom_left.text = timeFormat.format(Date(System.currentTimeMillis())) | 
			
		
	
		
			
				
					|  |  |  |  |                 battery_view.visible() | 
			
		
	
		
			
				
					|  |  |  |  |                 battery_view.setBattery(battery) | 
			
		
	
		
			
				
					|  |  |  |  |             } else { | 
			
		
	
		
			
				
					|  |  |  |  |                 battery_view.gone() | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     val headerHeight: Int | 
			
		
	
		
			
				
					|  |  |  |  |         get() { | 
			
		
	
		
			
				
					|  |  |  |  |             return if (ReadBookConfig.hideStatusBar) { | 
			
		
	
		
			
				
					|  |  |  |  |                 ll_header.height | 
			
		
	
		
			
				
					|  |  |  |  |             } else { | 
			
		
	
		
			
				
					|  |  |  |  |                 context.statusBarHeight | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         upTime() | 
			
		
	
		
			
				
					|  |  |  |  |         upBattery(battery) | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     fun upTipStyle() { | 
			
		
	
		
			
				
					|  |  |  |  |         ReadTipConfig.apply { | 
			
		
	
		
			
				
					|  |  |  |  |             val tipHeaderLeftNone = tipHeaderLeft == none | 
			
		
	
		
			
				
					|  |  |  |  |             val tipHeaderRightNone = tipHeaderRight == none | 
			
		
	
		
			
				
					|  |  |  |  |             val tipHeaderMiddleNone = tipHeaderMiddle == none | 
			
		
	
		
			
				
					|  |  |  |  |             val tipFooterLeftNone = tipFooterLeft == none | 
			
		
	
		
			
				
					|  |  |  |  |             val tipFooterRightNone = tipFooterRight == none | 
			
		
	
		
			
				
					|  |  |  |  |             val tipFooterMiddleNone = tipFooterMiddle == none | 
			
		
	
		
			
				
					|  |  |  |  |             tv_header_left.isInvisible = tipHeaderLeftNone | 
			
		
	
		
			
				
					|  |  |  |  |             tv_header_right.isGone = tipHeaderRightNone | 
			
		
	
		
			
				
					|  |  |  |  |             tv_header_middle.isGone = tipHeaderMiddleNone | 
			
		
	
		
			
				
					|  |  |  |  |             tv_footer_left.isInvisible = tipFooterLeftNone | 
			
		
	
		
			
				
					|  |  |  |  |             tv_footer_right.isGone = tipFooterRightNone | 
			
		
	
		
			
				
					|  |  |  |  |             tv_footer_middle.isGone = tipFooterMiddleNone | 
			
		
	
		
			
				
					|  |  |  |  |             ll_header.isGone = hideHeader | 
			
		
	
		
			
				
					|  |  |  |  |             ll_footer.isGone = hideFooter | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     fun setBg(bg: Drawable?) { | 
			
		
	
		
			
				
					|  |  |  |  |         page_panel.background = bg | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     fun upTime() { | 
			
		
	
		
			
				
					|  |  |  |  |         if (ReadBookConfig.hideStatusBar) { | 
			
		
	
		
			
				
					|  |  |  |  |             tv_bottom_right.text = timeFormat.format(Date(System.currentTimeMillis())) | 
			
		
	
		
			
				
					|  |  |  |  |         val tvTime = when (ReadTipConfig.time) { | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipHeaderLeft -> tv_header_left | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipHeaderMiddle -> tv_header_middle | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipHeaderRight -> tv_header_right | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipFooterLeft -> tv_footer_left | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipFooterMiddle -> tv_footer_middle | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipFooterRight -> tv_footer_right | 
			
		
	
		
			
				
					|  |  |  |  |             else -> null | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         tvTime?.isBattery = false | 
			
		
	
		
			
				
					|  |  |  |  |         tvTime?.text = timeFormat.format(Date(System.currentTimeMillis())) | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     fun upBattery(battery: Int) { | 
			
		
	
		
			
				
					|  |  |  |  |         this.battery = battery | 
			
		
	
		
			
				
					|  |  |  |  |         if (ReadBookConfig.hideStatusBar) { | 
			
		
	
		
			
				
					|  |  |  |  |             battery_view.setBattery(battery) | 
			
		
	
		
			
				
					|  |  |  |  |         val tvBattery = when (ReadTipConfig.battery) { | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipHeaderLeft -> tv_header_left | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipHeaderMiddle -> tv_header_middle | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipHeaderRight -> tv_header_right | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipFooterLeft -> tv_footer_left | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipFooterMiddle -> tv_footer_middle | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipFooterRight -> tv_footer_right | 
			
		
	
		
			
				
					|  |  |  |  |             else -> null | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         tvBattery?.isBattery = true | 
			
		
	
		
			
				
					|  |  |  |  |         tvBattery?.setBattery(battery) | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) { | 
			
		
	
	
		
			
				
					|  |  |  | @ -123,14 +147,28 @@ class ContentView(context: Context) : FrameLayout(context) { | 
			
		
	
		
			
				
					|  |  |  |  |             2 -> HanLP.convertToTraditionalChinese(textPage.title) | 
			
		
	
		
			
				
					|  |  |  |  |             else -> textPage.title | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         if (ReadBookConfig.hideStatusBar) { | 
			
		
	
		
			
				
					|  |  |  |  |             tv_top_left.text = title | 
			
		
	
		
			
				
					|  |  |  |  |             tv_top_right.text = readProgress | 
			
		
	
		
			
				
					|  |  |  |  |             tv_bottom_left.text = "${index.plus(1)}/$pageSize" | 
			
		
	
		
			
				
					|  |  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |  |             tv_bottom_left.text = title | 
			
		
	
		
			
				
					|  |  |  |  |             tv_bottom_right.text = "${index.plus(1)}/$pageSize  $readProgress" | 
			
		
	
		
			
				
					|  |  |  |  |         val tvTitle = when (ReadTipConfig.chapterTitle) { | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipHeaderLeft -> tv_header_left | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipHeaderMiddle -> tv_header_middle | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipHeaderRight -> tv_header_right | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipFooterLeft -> tv_footer_left | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipFooterMiddle -> tv_footer_middle | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipFooterRight -> tv_footer_right | 
			
		
	
		
			
				
					|  |  |  |  |             else -> null | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         tvTitle?.isBattery = false | 
			
		
	
		
			
				
					|  |  |  |  |         tvTitle?.text = title | 
			
		
	
		
			
				
					|  |  |  |  |         val tvPage = when (ReadTipConfig.page) { | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipHeaderLeft -> tv_header_left | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipHeaderMiddle -> tv_header_middle | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipHeaderRight -> tv_header_right | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipFooterLeft -> tv_footer_left | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipFooterMiddle -> tv_footer_middle | 
			
		
	
		
			
				
					|  |  |  |  |             ReadTipConfig.tipFooterRight -> tv_footer_right | 
			
		
	
		
			
				
					|  |  |  |  |             else -> null | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         tvPage?.isBattery = false | 
			
		
	
		
			
				
					|  |  |  |  |         tvPage?.text = "${index.plus(1)}/$pageSize  $readProgress" | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     fun onScroll(offset: Float) { | 
			
		
	
	
		
			
				
					|  |  |  | 
 |