|
@@ -72,6 +72,7 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
|
|
open fun loadCurrentPageIndex(filename: String, defaultValue: Int): Int = 0
|
|
open fun loadCurrentPageIndex(filename: String, defaultValue: Int): Int = 0
|
|
open fun onOpenedFile() { /* do nothing */ }
|
|
open fun onOpenedFile() { /* do nothing */ }
|
|
open fun onFilePathOrUriError(filePath: String?) { println("onFilePathOrUriError: $filePath") }
|
|
open fun onFilePathOrUriError(filePath: String?) { println("onFilePathOrUriError: $filePath") }
|
|
|
|
+ protected open fun onEvent(hookEvent: HookEvent) { /* do nothing */ }
|
|
|
|
|
|
companion object {
|
|
companion object {
|
|
const val KEY_FILE_ABSOLUTE = "file_absolutepath"
|
|
const val KEY_FILE_ABSOLUTE = "file_absolutepath"
|
|
@@ -208,6 +209,7 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
|
|
viewModel.isPageInBookmarksLiveData.observe(this, Observer(this::onIsPageInBookmarksChanged))
|
|
viewModel.isPageInBookmarksLiveData.observe(this, Observer(this::onIsPageInBookmarksChanged))
|
|
viewModel.isLeftToolbarOpenLiveData.observe(this, Observer(this::onLeftToolbarOpenStateChanged))
|
|
viewModel.isLeftToolbarOpenLiveData.observe(this, Observer(this::onLeftToolbarOpenStateChanged))
|
|
viewModel.leftToolbarTypeLiveData.observe(this, Observer(this::onLeftToolbarTypeChanged))
|
|
viewModel.leftToolbarTypeLiveData.observe(this, Observer(this::onLeftToolbarTypeChanged))
|
|
|
|
+ viewModel.eventLiveData.observe(this , Observer(this::onEvent))
|
|
isHidePdfPage = true
|
|
isHidePdfPage = true
|
|
applySetting()
|
|
applySetting()
|
|
|
|
|
|
@@ -677,6 +679,7 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
|
|
}
|
|
}
|
|
|
|
|
|
private fun onClickBookmark() {
|
|
private fun onClickBookmark() {
|
|
|
|
+ onEvent(HookEvent.OnClickTopBookmarkBtn())
|
|
viewModel.isPageInBookmarksLiveData.value?.let {
|
|
viewModel.isPageInBookmarksLiveData.value?.let {
|
|
if (!it) {
|
|
if (!it) {
|
|
showAddBookmarkDialog()
|
|
showAddBookmarkDialog()
|
|
@@ -871,17 +874,23 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
|
|
}
|
|
}
|
|
|
|
|
|
private fun setupBottomToolbar() {
|
|
private fun setupBottomToolbar() {
|
|
- ib_readerActivity_bottomToolbarMediaBox.setOnClickListener { mediaBoxView.show() }
|
|
|
|
|
|
+ ib_readerActivity_bottomToolbarMediaBox.setOnClickListener {
|
|
|
|
+ onEvent(HookEvent.OnClickBottomMediaBoxBtn())
|
|
|
|
+ mediaBoxView.show()
|
|
|
|
+ }
|
|
ib_readerActivity_bottomToolbarViewAll.setOnClickListener {
|
|
ib_readerActivity_bottomToolbarViewAll.setOnClickListener {
|
|
|
|
+ onEvent(HookEvent.OnClickBottomThumbnailBtn())
|
|
onClickBottomThumb1()
|
|
onClickBottomThumb1()
|
|
}
|
|
}
|
|
ib_readerActivity_bottomToolbarPrevious.setOnClickListener {
|
|
ib_readerActivity_bottomToolbarPrevious.setOnClickListener {
|
|
|
|
+ onEvent(HookEvent.OnClickBottomPreviousBtn())
|
|
val handler = viewModel.pdfInfoHandler
|
|
val handler = viewModel.pdfInfoHandler
|
|
val pageIndex = handler.getCurrentPage()
|
|
val pageIndex = handler.getCurrentPage()
|
|
val previousPageIndex = Math.max(pageIndex - 1, 0)
|
|
val previousPageIndex = Math.max(pageIndex - 1, 0)
|
|
handler.goToCurrentPage(previousPageIndex)
|
|
handler.goToCurrentPage(previousPageIndex)
|
|
}
|
|
}
|
|
ib_readerActivity_bottomToolbarNext.setOnClickListener {
|
|
ib_readerActivity_bottomToolbarNext.setOnClickListener {
|
|
|
|
+ onEvent(HookEvent.OnClickBottomNextBtn())
|
|
val handler = viewModel.pdfInfoHandler
|
|
val handler = viewModel.pdfInfoHandler
|
|
val pageIndex = handler.getCurrentPage()
|
|
val pageIndex = handler.getCurrentPage()
|
|
val nextPageIndex = Math.min(pageIndex + 1, handler.getPdfPageCount() - 1)
|
|
val nextPageIndex = Math.min(pageIndex + 1, handler.getPdfPageCount() - 1)
|
|
@@ -967,8 +976,12 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
|
|
private fun setupRightToolbar() {
|
|
private fun setupRightToolbar() {
|
|
viewGroup_readerActivity_rightToolbar.setScroll(false)
|
|
viewGroup_readerActivity_rightToolbar.setScroll(false)
|
|
iv_readerActivity_highLight.apply {
|
|
iv_readerActivity_highLight.apply {
|
|
- setOnClickListener { viewModel.onClickHighlightBtn() }
|
|
|
|
|
|
+ setOnClickListener {
|
|
|
|
+ onEvent(HookEvent.OnClickHighlightBtn())
|
|
|
|
+ viewModel.onClickHighlightBtn()
|
|
|
|
+ }
|
|
setOnLongClickListener { btn ->
|
|
setOnLongClickListener { btn ->
|
|
|
|
+ onEvent(HookEvent.OnLongClickHighlightBtn())
|
|
viewModel.onLongClickHighlightBtn()
|
|
viewModel.onLongClickHighlightBtn()
|
|
val context = this@ReaderActivity
|
|
val context = this@ReaderActivity
|
|
AnnotationAttributeWindow(context, true).also { window ->
|
|
AnnotationAttributeWindow(context, true).also { window ->
|
|
@@ -977,6 +990,7 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
|
|
}
|
|
}
|
|
window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
|
|
window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
|
|
override fun onChange(annotationAttributeView: AnnotationAttributeView) {
|
|
override fun onChange(annotationAttributeView: AnnotationAttributeView) {
|
|
|
|
+ onEvent(HookEvent.OnUserChangeHighlightPropertySuccess())
|
|
viewModel.setHighLightAttributes(annotationAttributeView.annotationAttribute)
|
|
viewModel.setHighLightAttributes(annotationAttributeView.annotationAttribute)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -994,8 +1008,12 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
|
|
}
|
|
}
|
|
}
|
|
}
|
|
iv_readerActivity_strike.apply {
|
|
iv_readerActivity_strike.apply {
|
|
- setOnClickListener { viewModel.onClickStrikeBtn() }
|
|
|
|
|
|
+ setOnClickListener {
|
|
|
|
+ onEvent(HookEvent.OnClickStrikeoutBtn())
|
|
|
|
+ viewModel.onClickStrikeBtn()
|
|
|
|
+ }
|
|
setOnLongClickListener { btn ->
|
|
setOnLongClickListener { btn ->
|
|
|
|
+ onEvent(HookEvent.OnLongClickStrikeoutBtn())
|
|
viewModel.onLongClickStrikeBtn()
|
|
viewModel.onLongClickStrikeBtn()
|
|
val context = this@ReaderActivity
|
|
val context = this@ReaderActivity
|
|
AnnotationAttributeWindow(context, true).also { window ->
|
|
AnnotationAttributeWindow(context, true).also { window ->
|
|
@@ -1004,6 +1022,7 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
|
|
}
|
|
}
|
|
window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
|
|
window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
|
|
override fun onChange(annotationAttributeView: AnnotationAttributeView) {
|
|
override fun onChange(annotationAttributeView: AnnotationAttributeView) {
|
|
|
|
+ onEvent(HookEvent.OnUserChangeStrikeoutPropertySuccess())
|
|
viewModel.setStrikeOutAttributes(annotationAttributeView.annotationAttribute)
|
|
viewModel.setStrikeOutAttributes(annotationAttributeView.annotationAttribute)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1021,8 +1040,12 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
|
|
}
|
|
}
|
|
}
|
|
}
|
|
iv_readerActivity_underline.apply {
|
|
iv_readerActivity_underline.apply {
|
|
- setOnClickListener { viewModel.onClickUnderlineBtn() }
|
|
|
|
|
|
+ setOnClickListener {
|
|
|
|
+ onEvent(HookEvent.OnClickUnderlineBtn())
|
|
|
|
+ viewModel.onClickUnderlineBtn()
|
|
|
|
+ }
|
|
setOnLongClickListener { btn ->
|
|
setOnLongClickListener { btn ->
|
|
|
|
+ onEvent(HookEvent.OnLongClickUnderlineBtn())
|
|
viewModel.onLongClickUnderlineBtn()
|
|
viewModel.onLongClickUnderlineBtn()
|
|
val context = this@ReaderActivity
|
|
val context = this@ReaderActivity
|
|
AnnotationAttributeWindow(context, true).also { window ->
|
|
AnnotationAttributeWindow(context, true).also { window ->
|
|
@@ -1031,6 +1054,7 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
|
|
}
|
|
}
|
|
window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
|
|
window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
|
|
override fun onChange(annotationAttributeView: AnnotationAttributeView) {
|
|
override fun onChange(annotationAttributeView: AnnotationAttributeView) {
|
|
|
|
+ onEvent(HookEvent.OnUserChangeUnderlinePropertySuccess())
|
|
viewModel.setUnderLineAttributes(annotationAttributeView.annotationAttribute)
|
|
viewModel.setUnderLineAttributes(annotationAttributeView.annotationAttribute)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1049,6 +1073,7 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
|
|
}
|
|
}
|
|
iv_readerActivity_ink.apply {
|
|
iv_readerActivity_ink.apply {
|
|
setOnClickListener {
|
|
setOnClickListener {
|
|
|
|
+ onEvent(HookEvent.OnClickInkBtn())
|
|
if (viewModel.annotationModeLiveData.value == ReaderViewModel.AnnotationMode.INK) {
|
|
if (viewModel.annotationModeLiveData.value == ReaderViewModel.AnnotationMode.INK) {
|
|
AnimationUtil.hideViewAlpha(view_ink_menu)
|
|
AnimationUtil.hideViewAlpha(view_ink_menu)
|
|
} else {
|
|
} else {
|
|
@@ -1057,6 +1082,7 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
|
|
viewModel.onClickInkBtn()
|
|
viewModel.onClickInkBtn()
|
|
}
|
|
}
|
|
setOnLongClickListener { btn ->
|
|
setOnLongClickListener { btn ->
|
|
|
|
+ onEvent(HookEvent.OnLongClickInkBtn())
|
|
viewModel.onLongClickInkBtn()
|
|
viewModel.onLongClickInkBtn()
|
|
val context = this@ReaderActivity
|
|
val context = this@ReaderActivity
|
|
AnnotationAttributeWindow(context, false).also { window ->
|
|
AnnotationAttributeWindow(context, false).also { window ->
|
|
@@ -1065,6 +1091,7 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
|
|
}
|
|
}
|
|
window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
|
|
window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
|
|
override fun onChange(annotationAttributeView: AnnotationAttributeView) {
|
|
override fun onChange(annotationAttributeView: AnnotationAttributeView) {
|
|
|
|
+ onEvent(HookEvent.OnUserChangeInkPropertySuccess())
|
|
viewModel.setInkAttributes(annotationAttributeView.inkAttribute)
|
|
viewModel.setInkAttributes(annotationAttributeView.inkAttribute)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1232,4 +1259,41 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private fun onEvent(event: ReaderViewModel.Event?) {
|
|
|
|
+ if (event == null) return
|
|
|
|
+ when (event) {
|
|
|
|
+ is ReaderViewModel.Event.OnFinishedHighlight -> HookEvent.OnFinishedHighlight()
|
|
|
|
+ is ReaderViewModel.Event.OnFinishedStrikeout -> HookEvent.OnFinishedStrikeout()
|
|
|
|
+ is ReaderViewModel.Event.OnFinishedUnderLine -> HookEvent.OnFinishedUnderline()
|
|
|
|
+ is ReaderViewModel.Event.OnFinishedInk -> HookEvent.OnFinishedInk()
|
|
|
|
+ }.also {
|
|
|
|
+ onEvent(it)
|
|
|
|
+ }
|
|
|
|
+ viewModel.onEventConsumed(event)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected sealed class HookEvent {
|
|
|
|
+ class OnClickTopBookmarkBtn : HookEvent()
|
|
|
|
+ class OnClickBottomPreviousBtn : HookEvent()
|
|
|
|
+ class OnClickBottomNextBtn : HookEvent()
|
|
|
|
+ class OnClickBottomMediaBoxBtn : HookEvent()
|
|
|
|
+ class OnClickBottomThumbnailBtn : HookEvent()
|
|
|
|
+ class OnClickHighlightBtn : HookEvent()
|
|
|
|
+ class OnClickStrikeoutBtn : HookEvent()
|
|
|
|
+ class OnClickUnderlineBtn : HookEvent()
|
|
|
|
+ class OnClickInkBtn : HookEvent()
|
|
|
|
+ class OnLongClickHighlightBtn : HookEvent()
|
|
|
|
+ class OnLongClickStrikeoutBtn : HookEvent()
|
|
|
|
+ class OnLongClickUnderlineBtn : HookEvent()
|
|
|
|
+ class OnLongClickInkBtn : HookEvent()
|
|
|
|
+ class OnFinishedHighlight : HookEvent()
|
|
|
|
+ class OnFinishedStrikeout : HookEvent()
|
|
|
|
+ class OnFinishedUnderline : HookEvent()
|
|
|
|
+ class OnFinishedInk : HookEvent()
|
|
|
|
+ class OnUserChangeHighlightPropertySuccess : HookEvent()
|
|
|
|
+ class OnUserChangeStrikeoutPropertySuccess : HookEvent()
|
|
|
|
+ class OnUserChangeUnderlinePropertySuccess : HookEvent()
|
|
|
|
+ class OnUserChangeInkPropertySuccess : HookEvent()
|
|
|
|
+ }
|
|
}
|
|
}
|