|
@@ -70,12 +70,7 @@ abstract class ReaderActivity : AppCompatActivity() {
|
|
private var w_240: Int = 0
|
|
private var w_240: Int = 0
|
|
private var w_left: Int = 0
|
|
private var w_left: Int = 0
|
|
|
|
|
|
- private var isLeftToolbarOpen = false
|
|
|
|
-
|
|
|
|
- enum class LeftToolbarType {
|
|
|
|
- NONE, THUMBNAIL, BOOKMARK, OUTLINE, SEARCH
|
|
|
|
- }
|
|
|
|
- private var leftToolbarType = LeftToolbarType.NONE
|
|
|
|
|
|
+ private var oldLeftToolbarType = ReaderViewModel.LeftToolbarType.NONE
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
super.onCreate(savedInstanceState)
|
|
@@ -116,6 +111,8 @@ abstract class ReaderActivity : AppCompatActivity() {
|
|
setupRightToolbar()
|
|
setupRightToolbar()
|
|
viewModel.pageIndexLiveData.observe(this, Observer(this::onPageIndexChanged))
|
|
viewModel.pageIndexLiveData.observe(this, Observer(this::onPageIndexChanged))
|
|
viewModel.isPageInBookmarksLiveData.observe(this, Observer(this::onIsPageInBookmarksChanged))
|
|
viewModel.isPageInBookmarksLiveData.observe(this, Observer(this::onIsPageInBookmarksChanged))
|
|
|
|
+ viewModel.isLeftToolbarOpenLiveData.observe(this, Observer(this::onLeftToolbarOpenStateChanged))
|
|
|
|
+ viewModel.leftToolbarTypeLiveData.observe(this, Observer(this::onLeftToolbarTypeChanged))
|
|
}
|
|
}
|
|
|
|
|
|
override fun onBackPressed() {
|
|
override fun onBackPressed() {
|
|
@@ -485,7 +482,16 @@ abstract class ReaderActivity : AppCompatActivity() {
|
|
viewGroup_readerActivity_leftToolbar.smoothScrollTo(w_240, 0, 0)
|
|
viewGroup_readerActivity_leftToolbar.smoothScrollTo(w_240, 0, 0)
|
|
val child = layoutInflater.inflate(R.layout.view_thumbnail, null)
|
|
val child = layoutInflater.inflate(R.layout.view_thumbnail, null)
|
|
linearLayout_readerActivity_leftToolbarContainer.addView(child)
|
|
linearLayout_readerActivity_leftToolbarContainer.addView(child)
|
|
- cloneOriginConstraintSet()
|
|
|
|
|
|
+
|
|
|
|
+ fun onClickLeftToolbarItem(leftToolbarType: ReaderViewModel.LeftToolbarType) {
|
|
|
|
+ viewModel.setLeftToolbarType(leftToolbarType)
|
|
|
|
+ updateLeftToolbarOpenState(leftToolbarType)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ iv_readerActivity_thumbnail.setOnClickListener { onClickLeftToolbarItem(ReaderViewModel.LeftToolbarType.THUMBNAIL) }
|
|
|
|
+ iv_readerActivity_bookmark.setOnClickListener { onClickLeftToolbarItem(ReaderViewModel.LeftToolbarType.BOOKMARK) }
|
|
|
|
+ iv_readerActivity_outline.setOnClickListener { onClickLeftToolbarItem(ReaderViewModel.LeftToolbarType.OUTLINE) }
|
|
|
|
+ iv_readerActivity_search.setOnClickListener { onClickLeftToolbarItem(ReaderViewModel.LeftToolbarType.SEARCH) }
|
|
}
|
|
}
|
|
|
|
|
|
private fun setupRightSideToolbar() {
|
|
private fun setupRightSideToolbar() {
|
|
@@ -642,7 +648,6 @@ abstract class ReaderActivity : AppCompatActivity() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
private fun setLeftToolbarWidth(width: Int) {
|
|
private fun setLeftToolbarWidth(width: Int) {
|
|
var params = viewGroup_readerActivity_leftToolbar.layoutParams as ConstraintLayout.LayoutParams
|
|
var params = viewGroup_readerActivity_leftToolbar.layoutParams as ConstraintLayout.LayoutParams
|
|
params.width = width + w_left
|
|
params.width = width + w_left
|
|
@@ -654,23 +659,9 @@ abstract class ReaderActivity : AppCompatActivity() {
|
|
linearLayout_readerActivity_leftToolbarContainer.layoutParams = params
|
|
linearLayout_readerActivity_leftToolbarContainer.layoutParams = params
|
|
}
|
|
}
|
|
|
|
|
|
- private fun changeLeftToolbarType(type: LeftToolbarType) {
|
|
|
|
- iv_readerActivity_thumbnail.setImageResource(R.drawable.ic_left_toolbar_thumbnails)
|
|
|
|
- iv_readerActivity_bookmark.setImageResource(R.drawable.ic_left_toolbar_bookmarks)
|
|
|
|
- iv_readerActivity_outline.setImageResource(R.drawable.ic_left_toolbar_outline)
|
|
|
|
- iv_readerActivity_search.setImageResource(R.drawable.ic_left_toolbar_search)
|
|
|
|
-
|
|
|
|
- val width = when (type) {
|
|
|
|
- LeftToolbarType.THUMBNAIL -> w_240
|
|
|
|
- else -> w_318
|
|
|
|
- }
|
|
|
|
- setLeftToolbarWidth(width)
|
|
|
|
-
|
|
|
|
- isLeftToolbarOpen = (!isLeftToolbarOpen || leftToolbarType != type)
|
|
|
|
- if (isLeftToolbarOpen)
|
|
|
|
- viewGroup_readerActivity_leftToolbar.smoothScrollTo(0, 0, UI_ANIMATION_DURATION.toInt())
|
|
|
|
- else
|
|
|
|
- viewGroup_readerActivity_leftToolbar.smoothScrollTo(width, 0, UI_ANIMATION_DURATION.toInt())
|
|
|
|
|
|
+ private fun updateLeftToolbarOpenState(type: ReaderViewModel.LeftToolbarType) {
|
|
|
|
+ val isLeftToolbarOpen = viewModel.isLeftToolbarOpenLiveData.value ?: false
|
|
|
|
+ viewModel.setIsLeftToolbarOpen(!isLeftToolbarOpen || oldLeftToolbarType != type)
|
|
cloneOriginConstraintSet()
|
|
cloneOriginConstraintSet()
|
|
}
|
|
}
|
|
|
|
|
|
@@ -683,91 +674,75 @@ abstract class ReaderActivity : AppCompatActivity() {
|
|
viewModel.clearSelection()
|
|
viewModel.clearSelection()
|
|
}
|
|
}
|
|
|
|
|
|
- private fun onThumbnailClick() {
|
|
|
|
- val type = LeftToolbarType.THUMBNAIL
|
|
|
|
- changeLeftToolbarType(type)
|
|
|
|
- if (isLeftToolbarOpen) {
|
|
|
|
- if (leftToolbarType != type) {
|
|
|
|
- linearLayout_readerActivity_leftToolbarContainer.removeAllViews()
|
|
|
|
- val thumbnailView = ThumbnailView(this)
|
|
|
|
- thumbnailView.setHandlers(viewModel.pdfInfoHandler, viewModel.thumbnailHandler)
|
|
|
|
- linearLayout_readerActivity_leftToolbarContainer.addView(thumbnailView)
|
|
|
|
|
|
+ private fun setLeftToolbarContentView(leftToolbarType: ReaderViewModel.LeftToolbarType) {
|
|
|
|
+ if (oldLeftToolbarType != leftToolbarType) {
|
|
|
|
+ linearLayout_readerActivity_leftToolbarContainer.removeAllViews()
|
|
|
|
+ val view = when (leftToolbarType) {
|
|
|
|
+ ReaderViewModel.LeftToolbarType.NONE,
|
|
|
|
+ ReaderViewModel.LeftToolbarType.THUMBNAIL -> {
|
|
|
|
+ val thumbnailView = ThumbnailView(this)
|
|
|
|
+ thumbnailView.setHandlers(viewModel.pdfInfoHandler, viewModel.thumbnailHandler)
|
|
|
|
+ thumbnailView
|
|
|
|
+ }
|
|
|
|
+ ReaderViewModel.LeftToolbarType.BOOKMARK -> {
|
|
|
|
+ val bookmarkView = BookmarkView(this)
|
|
|
|
+ bookmarkView.setHandlers(viewModel.pdfInfoHandler, viewModel.thumbnailHandler, viewModel.bookmarkHandler)
|
|
|
|
+ bookmarkView
|
|
|
|
+ }
|
|
|
|
+ ReaderViewModel.LeftToolbarType.OUTLINE -> {
|
|
|
|
+ val outlineView = OutlineView(this)
|
|
|
|
+ outlineView.setHandlers(viewModel.pdfInfoHandler, viewModel.outlineHandler)
|
|
|
|
+ outlineView
|
|
|
|
+ }
|
|
|
|
+ ReaderViewModel.LeftToolbarType.SEARCH -> {
|
|
|
|
+ val searchView = SearchView(this)
|
|
|
|
+ searchView.setHandlers(viewModel.pdfInfoHandler, viewModel.searchHandler)
|
|
|
|
+ searchView
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- iv_readerActivity_thumbnail.setImageResource(R.drawable.ic_left_toolbar_thumbnails_selected)
|
|
|
|
- } else {
|
|
|
|
- iv_readerActivity_thumbnail.setImageResource(R.drawable.ic_left_toolbar_thumbnails)
|
|
|
|
|
|
+ linearLayout_readerActivity_leftToolbarContainer.addView(view)
|
|
|
|
+ oldLeftToolbarType = leftToolbarType
|
|
}
|
|
}
|
|
- leftToolbarType = type
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private fun onBookmarkClick() {
|
|
|
|
- val type = LeftToolbarType.BOOKMARK
|
|
|
|
- changeLeftToolbarType(type)
|
|
|
|
- if (isLeftToolbarOpen) {
|
|
|
|
- if (leftToolbarType != type) {
|
|
|
|
- linearLayout_readerActivity_leftToolbarContainer.removeAllViews()
|
|
|
|
- val bookmarkView = BookmarkView(this)
|
|
|
|
- bookmarkView.setHandlers(viewModel.pdfInfoHandler, viewModel.thumbnailHandler, viewModel.bookmarkHandler)
|
|
|
|
- linearLayout_readerActivity_leftToolbarContainer.addView(bookmarkView)
|
|
|
|
- }
|
|
|
|
- iv_readerActivity_bookmark.setImageResource(R.drawable.ic_left_toolbar_bookmarks_selected)
|
|
|
|
- } else {
|
|
|
|
- iv_readerActivity_bookmark.setImageResource(R.drawable.ic_left_toolbar_bookmarks)
|
|
|
|
|
|
+ private fun getLeftToolbarContentWidth(): Int {
|
|
|
|
+ return when (viewModel.leftToolbarTypeLiveData.value == ReaderViewModel.LeftToolbarType.THUMBNAIL) {
|
|
|
|
+ true -> w_240
|
|
|
|
+ false -> w_318
|
|
}
|
|
}
|
|
- leftToolbarType = type
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private fun onOutlineClick() {
|
|
|
|
- val type = LeftToolbarType.OUTLINE
|
|
|
|
- changeLeftToolbarType(type)
|
|
|
|
- if (isLeftToolbarOpen) {
|
|
|
|
- if (leftToolbarType != type) {
|
|
|
|
- linearLayout_readerActivity_leftToolbarContainer.removeAllViews()
|
|
|
|
- val outlineView = OutlineView(this)
|
|
|
|
- outlineView.setHandlers(viewModel.pdfInfoHandler, viewModel.outlineHandler)
|
|
|
|
- linearLayout_readerActivity_leftToolbarContainer.addView(outlineView)
|
|
|
|
- }
|
|
|
|
- iv_readerActivity_outline.setImageResource(R.drawable.ic_left_toolbar_outline_selected)
|
|
|
|
- } else {
|
|
|
|
- iv_readerActivity_outline.setImageResource(R.drawable.ic_left_toolbar_outline)
|
|
|
|
|
|
+ private fun onLeftToolbarTypeChanged(leftToolbarType: ReaderViewModel.LeftToolbarType?) {
|
|
|
|
+ updateLeftToolbarIcons()
|
|
|
|
+ setLeftToolbarWidth(getLeftToolbarContentWidth())
|
|
|
|
+ cloneOriginConstraintSet()
|
|
|
|
+
|
|
|
|
+ if (leftToolbarType != null) {
|
|
|
|
+ setLeftToolbarContentView(leftToolbarType)
|
|
}
|
|
}
|
|
- leftToolbarType = type
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private fun onSearchClick() {
|
|
|
|
- val type = LeftToolbarType.SEARCH
|
|
|
|
- changeLeftToolbarType(type)
|
|
|
|
- if (isLeftToolbarOpen) {
|
|
|
|
- if (leftToolbarType != type) {
|
|
|
|
- linearLayout_readerActivity_leftToolbarContainer.removeAllViews()
|
|
|
|
- val searchView = SearchView(this)
|
|
|
|
- searchView.setHandlers(viewModel.pdfInfoHandler, viewModel.searchHandler)
|
|
|
|
- linearLayout_readerActivity_leftToolbarContainer.addView(searchView)
|
|
|
|
- }
|
|
|
|
- iv_readerActivity_search.setImageResource(R.drawable.ic_left_toolbar_search_selected)
|
|
|
|
- } else {
|
|
|
|
- iv_readerActivity_search.setImageResource(R.drawable.ic_left_toolbar_search)
|
|
|
|
- hideSearchViewSoftKeyboard()
|
|
|
|
|
|
+ private fun onLeftToolbarOpenStateChanged(open: Boolean?) {
|
|
|
|
+ updateLeftToolbarIcons()
|
|
|
|
+
|
|
|
|
+ when (open == true) {
|
|
|
|
+ true -> viewGroup_readerActivity_leftToolbar.smoothScrollTo(0, 0, UI_ANIMATION_DURATION.toInt())
|
|
|
|
+ false -> viewGroup_readerActivity_leftToolbar.smoothScrollTo(getLeftToolbarContentWidth(), 0, UI_ANIMATION_DURATION.toInt())
|
|
}
|
|
}
|
|
- leftToolbarType = type
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- fun onClick(view: View) {
|
|
|
|
- when (view.id) {
|
|
|
|
- R.id.iv_readerActivity_thumbnail -> {
|
|
|
|
- onThumbnailClick()
|
|
|
|
- }
|
|
|
|
- R.id.iv_readerActivity_bookmark -> {
|
|
|
|
- onBookmarkClick()
|
|
|
|
- }
|
|
|
|
- R.id.iv_readerActivity_outline -> {
|
|
|
|
- onOutlineClick()
|
|
|
|
- }
|
|
|
|
- R.id.iv_readerActivity_search -> {
|
|
|
|
- onSearchClick()
|
|
|
|
- }
|
|
|
|
- else -> {
|
|
|
|
-
|
|
|
|
|
|
+ private fun updateLeftToolbarIcons() {
|
|
|
|
+ iv_readerActivity_thumbnail.setImageResource(R.drawable.ic_left_toolbar_thumbnails)
|
|
|
|
+ iv_readerActivity_bookmark.setImageResource(R.drawable.ic_left_toolbar_bookmarks)
|
|
|
|
+ iv_readerActivity_outline.setImageResource(R.drawable.ic_left_toolbar_outline)
|
|
|
|
+ iv_readerActivity_search.setImageResource(R.drawable.ic_left_toolbar_search)
|
|
|
|
+ if (viewModel.isLeftToolbarOpenLiveData.value == true) {
|
|
|
|
+ when (viewModel.leftToolbarTypeLiveData.value) {
|
|
|
|
+ ReaderViewModel.LeftToolbarType.NONE -> {}
|
|
|
|
+ ReaderViewModel.LeftToolbarType.THUMBNAIL -> iv_readerActivity_thumbnail.setImageResource(R.drawable.ic_left_toolbar_thumbnails_selected)
|
|
|
|
+ ReaderViewModel.LeftToolbarType.BOOKMARK -> iv_readerActivity_bookmark.setImageResource(R.drawable.ic_left_toolbar_bookmarks_selected)
|
|
|
|
+ ReaderViewModel.LeftToolbarType.OUTLINE -> iv_readerActivity_outline.setImageResource(R.drawable.ic_left_toolbar_outline_selected)
|
|
|
|
+ ReaderViewModel.LeftToolbarType.SEARCH -> iv_readerActivity_search.setImageResource(R.drawable.ic_left_toolbar_search_selected)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|