diff --git a/app/src/main/java/io/legado/app/ui/read/ReadActivity.kt b/app/src/main/java/io/legado/app/ui/read/ReadActivity.kt index f7a5ae999..7a0ce4ece 100644 --- a/app/src/main/java/io/legado/app/ui/read/ReadActivity.kt +++ b/app/src/main/java/io/legado/app/ui/read/ReadActivity.kt @@ -1,21 +1,76 @@ package io.legado.app.ui.read import android.os.Bundle +import android.view.KeyEvent +import android.view.Menu +import android.view.MenuItem +import android.view.animation.Animation +import android.view.animation.AnimationUtils +import androidx.core.view.isVisible import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.utils.getViewModel +import io.legado.app.utils.invisible +import io.legado.app.utils.visible import kotlinx.android.synthetic.main.activity_read.* +import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.sdk27.listeners.onClick class ReadActivity : VMBaseActivity(R.layout.activity_read) { override val viewModel: ReadViewModel get() = getViewModel(ReadViewModel::class.java) + private var menuBarShow: Boolean = false + private lateinit var menuTopIn: Animation + private lateinit var menuTopOut: Animation + private lateinit var menuBottomIn: Animation + private lateinit var menuBottomOut: Animation + override fun onActivityCreated(savedInstanceState: Bundle?) { + setSupportActionBar(toolbar) + initAnimation() initView() viewModel.initData(intent) } + private fun initAnimation() { + menuTopIn = AnimationUtils.loadAnimation(this, R.anim.anim_readbook_top_in) + menuBottomIn = AnimationUtils.loadAnimation(this, R.anim.anim_readbook_bottom_in) + menuBottomIn.setAnimationListener(object : Animation.AnimationListener { + override fun onAnimationStart(animation: Animation) { + + } + + override fun onAnimationEnd(animation: Animation) { + vw_menu_bg.onClick { runMenuOut() } + } + + override fun onAnimationRepeat(animation: Animation) { + + } + }) + + //隐藏菜单 + menuTopOut = AnimationUtils.loadAnimation(this, R.anim.anim_readbook_top_out) + menuBottomOut = AnimationUtils.loadAnimation(this, R.anim.anim_readbook_bottom_out) + menuBottomOut.setAnimationListener(object : Animation.AnimationListener { + override fun onAnimationStart(animation: Animation) { + vw_menu_bg.setOnClickListener(null) + } + + override fun onAnimationEnd(animation: Animation) { + fl_menu.invisible() + title_bar.invisible() + bottom_menu.invisible() + menuBarShow = false + } + + override fun onAnimationRepeat(animation: Animation) { + + } + }) + } + private fun initView() { tv_chapter_name.onClick { @@ -24,4 +79,58 @@ class ReadActivity : VMBaseActivity(R.layout.activity_read) { } } + + override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.read_book, menu) + return super.onCompatCreateOptionsMenu(menu) + } + + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + + } + return super.onCompatOptionsItemSelected(item) + } + + override fun dispatchKeyEvent(event: KeyEvent?): Boolean { + val keyCode = event?.keyCode + val action = event?.action + val isDown = action == 0 + + if (keyCode == KeyEvent.KEYCODE_MENU) { + if (isDown && !menuBarShow) { + runMenuIn() + return true + } + if (!isDown && !menuBarShow) { + menuBarShow = true + return true + } + } + return super.dispatchKeyEvent(event) + } + + override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { + when (keyCode) { + + } + return super.onKeyDown(keyCode, event) + } + + private fun runMenuIn() { + fl_menu.visible() + title_bar.visible() + bottom_menu.visible() + title_bar.startAnimation(menuTopIn) + bottom_menu.startAnimation(menuBottomIn) + } + + private fun runMenuOut() { + if (fl_menu.isVisible) { + if (bottom_menu.isVisible) { + title_bar.startAnimation(menuTopOut) + bottom_menu.startAnimation(menuBottomOut) + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/read/ReadBottomMenu.kt b/app/src/main/java/io/legado/app/ui/read/ReadBottomMenu.kt new file mode 100644 index 000000000..45ea48921 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/read/ReadBottomMenu.kt @@ -0,0 +1,193 @@ +package io.legado.app.ui.read + +import android.content.Context +import android.util.AttributeSet +import android.widget.FrameLayout +import android.widget.SeekBar +import io.legado.app.R +import io.legado.app.utils.gone +import io.legado.app.utils.visible +import kotlinx.android.synthetic.main.view_read_bottom_menu.view.* +import org.jetbrains.anko.sdk27.listeners.onClick +import org.jetbrains.anko.sdk27.listeners.onLongClick + +class ReadBottomMenu : FrameLayout { + + private var callback: Callback? = null + + val readProgress: SeekBar + get() = hpb_read_progress + + constructor(context: Context) : super(context) { + init(context) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(context) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context) + } + + private fun init(context: Context) { + inflate(context, R.layout.view_read_bottom_menu, this) + vw_bg.onClick { } + vwNavigationBar.onClick { } + } + + fun setNavigationBarHeight(height: Int) { + vwNavigationBar.layoutParams.height = height + } + + fun setListener(callback: Callback) { + this.callback = callback + bindEvent() + } + + private fun bindEvent() { + ll_read_aloud_timer.onClick { callback?.dismiss() } + ll_floating_button.onClick { callback?.dismiss() } + + //阅读进度 + hpb_read_progress.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar, i: Int, b: Boolean) { + + } + + override fun onStartTrackingTouch(seekBar: SeekBar) { + + } + + override fun onStopTrackingTouch(seekBar: SeekBar) { + callback!!.skipToPage(seekBar.progress) + } + }) + + //朗读定时 + fab_read_aloud_timer.onClick { } + + //朗读 + fab_read_aloud.onClick { callback?.onMediaButton() } + //长按停止朗读 + fab_read_aloud.onClick { + true + } + + //自动翻页 + fabAutoPage.onClick { callback?.autoPage() } + fabAutoPage.onLongClick { + callback?.toast(R.string.auto_next_page) + true + } + + //替换 + fabReplaceRule.onClick { callback?.openReplaceRule() } + fabReplaceRule.onLongClick { + callback!!.toast(R.string.replace_rule_title) + true + } + + //夜间模式 + fabNightTheme.onClick { callback?.setNightTheme() } + fabNightTheme.onLongClick { + callback?.toast(R.string.night_theme) + true + } + + //上一章 + tv_pre.onClick { callback?.skipPreChapter() } + + //下一章 + tv_next.onClick { callback?.skipNextChapter() } + + //目录 + ll_catalog.onClick { callback?.openChapterList() } + + //调节 + ll_adjust.onClick { callback?.openAdjust() } + + //界面 + ll_font.onClick { callback?.openReadInterface() } + + //设置 + ll_setting.onClick { callback?.openMoreSetting() } + + tv_read_aloud_timer.onClick { } + } + + fun setFabReadAloudImage(id: Int) { + fab_read_aloud.setImageResource(id) + } + + fun setReadAloudTimer(visibility: Boolean) { + if (visibility) { + ll_read_aloud_timer.visible() + } else { + ll_read_aloud_timer.gone() + } + } + + fun setReadAloudTimer(text: String) { + tv_read_aloud_timer.text = text + } + + fun setFabReadAloudText(text: String) { + fab_read_aloud.contentDescription = text + } + + fun setTvPre(enable: Boolean) { + tv_pre.isEnabled = enable + } + + fun setTvNext(enable: Boolean) { + tv_next.isEnabled = enable + } + + fun setAutoPage(autoPage: Boolean) { + if (autoPage) { + fabAutoPage.setImageResource(R.drawable.ic_auto_page_stop) + fabAutoPage.contentDescription = context.getString(R.string.auto_next_page_stop) + } else { + fabAutoPage.setImageResource(R.drawable.ic_auto_page) + fabAutoPage.contentDescription = context.getString(R.string.auto_next_page) + } + } + + fun setFabNightTheme(isNightTheme: Boolean) { + if (isNightTheme) { + fabNightTheme.setImageResource(R.drawable.ic_daytime) + } else { + fabNightTheme.setImageResource(R.drawable.ic_brightness) + } + } + + interface Callback { + fun skipToPage(page: Int) + + fun onMediaButton() + + fun autoPage() + + fun setNightTheme() + + fun skipPreChapter() + + fun skipNextChapter() + + fun openReplaceRule() + + fun openChapterList() + + fun openAdjust() + + fun openReadInterface() + + fun openMoreSetting() + + fun toast(id: Int) + + fun dismiss() + } + +} diff --git a/app/src/main/res/anim/anim_none.xml b/app/src/main/res/anim/anim_none.xml new file mode 100644 index 000000000..fe9ddac3b --- /dev/null +++ b/app/src/main/res/anim/anim_none.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/anim_readbook_bottom_in.xml b/app/src/main/res/anim/anim_readbook_bottom_in.xml new file mode 100644 index 000000000..48fe0c0aa --- /dev/null +++ b/app/src/main/res/anim/anim_readbook_bottom_in.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/anim_readbook_bottom_out.xml b/app/src/main/res/anim/anim_readbook_bottom_out.xml new file mode 100644 index 000000000..2e91beb95 --- /dev/null +++ b/app/src/main/res/anim/anim_readbook_bottom_out.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/anim_readbook_top_in.xml b/app/src/main/res/anim/anim_readbook_top_in.xml new file mode 100644 index 000000000..e36360bc0 --- /dev/null +++ b/app/src/main/res/anim/anim_readbook_top_in.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/anim_readbook_top_out.xml b/app/src/main/res/anim/anim_readbook_top_out.xml new file mode 100644 index 000000000..0b8acbceb --- /dev/null +++ b/app/src/main/res/anim/anim_readbook_top_out.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/moprogress_bottom_in.xml b/app/src/main/res/anim/moprogress_bottom_in.xml new file mode 100644 index 000000000..59904f594 --- /dev/null +++ b/app/src/main/res/anim/moprogress_bottom_in.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/moprogress_bottom_out.xml b/app/src/main/res/anim/moprogress_bottom_out.xml new file mode 100644 index 000000000..2348594fc --- /dev/null +++ b/app/src/main/res/anim/moprogress_bottom_out.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/moprogress_in.xml b/app/src/main/res/anim/moprogress_in.xml new file mode 100644 index 000000000..8e922153b --- /dev/null +++ b/app/src/main/res/anim/moprogress_in.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/moprogress_in_bottom_right.xml b/app/src/main/res/anim/moprogress_in_bottom_right.xml new file mode 100644 index 000000000..93348f5a8 --- /dev/null +++ b/app/src/main/res/anim/moprogress_in_bottom_right.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/moprogress_in_top_right.xml b/app/src/main/res/anim/moprogress_in_top_right.xml new file mode 100644 index 000000000..81bb2e919 --- /dev/null +++ b/app/src/main/res/anim/moprogress_in_top_right.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/moprogress_out.xml b/app/src/main/res/anim/moprogress_out.xml new file mode 100644 index 000000000..546619cc2 --- /dev/null +++ b/app/src/main/res/anim/moprogress_out.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/moprogress_out_bottom_right.xml b/app/src/main/res/anim/moprogress_out_bottom_right.xml new file mode 100644 index 000000000..d0d1eaffa --- /dev/null +++ b/app/src/main/res/anim/moprogress_out_bottom_right.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/moprogress_out_top_right.xml b/app/src/main/res/anim/moprogress_out_top_right.xml new file mode 100644 index 000000000..310b29d7e --- /dev/null +++ b/app/src/main/res/anim/moprogress_out_top_right.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_read.xml b/app/src/main/res/layout/activity_read.xml index 250aeb815..a7396af3d 100644 --- a/app/src/main/res/layout/activity_read.xml +++ b/app/src/main/res/layout/activity_read.xml @@ -1,6 +1,5 @@ @@ -9,33 +8,50 @@ android:layout_width="match_parent" android:layout_height="match_parent"/> - + android:layout_height="match_parent" + android:visibility="gone"> - + android:layout_height="match_parent" /> - + android:visibility="gone" + android:theme="?attr/actionBarStyle"> + + + + - + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_read_bottom_menu.xml b/app/src/main/res/layout/view_read_bottom_menu.xml new file mode 100644 index 000000000..41abf95f3 --- /dev/null +++ b/app/src/main/res/layout/view_read_bottom_menu.xml @@ -0,0 +1,358 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/read_book.xml b/app/src/main/res/menu/read_book.xml new file mode 100644 index 000000000..b141dc68d --- /dev/null +++ b/app/src/main/res/menu/read_book.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +