|
@@ -0,0 +1,144 @@
|
|
|
|
+package com.kdanmobile.reader.screen
|
|
|
|
+
|
|
|
|
+import android.arch.lifecycle.Observer
|
|
|
|
+import android.arch.lifecycle.ViewModelProviders
|
|
|
|
+import android.support.v7.app.AppCompatActivity
|
|
|
|
+import android.os.Bundle
|
|
|
|
+import android.view.MenuItem
|
|
|
|
+import android.widget.CompoundButton
|
|
|
|
+import com.kdanmobile.reader.R
|
|
|
|
+import com.kdanmobile.reader.screen.model.SharePrefsModel
|
|
|
|
+import com.kdanmobile.reader.screen.view.ReadingModeSelectView
|
|
|
|
+import com.kdanmobile.reader.screen.view.TurnPageModeSelectView
|
|
|
|
+import kotlinx.android.synthetic.main.activity_viewer_setting.*
|
|
|
|
+
|
|
|
|
+class ViewerSettingActivity : AppCompatActivity() {
|
|
|
|
+
|
|
|
|
+ private lateinit var viewModel: ViewerSettingViewModel
|
|
|
|
+
|
|
|
|
+ override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
+ super.onCreate(savedInstanceState)
|
|
|
|
+ setContentView(R.layout.activity_viewer_setting)
|
|
|
|
+
|
|
|
|
+ viewModel = ViewModelProviders.of(this, ViewerSettingViewModelFactory(SharePrefsModel(applicationContext)))
|
|
|
|
+ .get(ViewerSettingViewModel::class.java)
|
|
|
|
+
|
|
|
|
+ viewModel.readMode.observe(this, Observer(this::onReadModeChanged))
|
|
|
|
+ viewModel.isCropModeEnable.observe(this, Observer(this::onCropModeEnableChanged))
|
|
|
|
+ viewModel.isShowStateBarEnable.observe(this, Observer(this::onShowStateBarEnableChanged))
|
|
|
|
+ viewModel.turnPageDirection.observe(this, Observer(this::onTurnPageDirectionChanged))
|
|
|
|
+ viewModel.isShowTurnPageBtnEnable.observe(this, Observer(this::onShowTurnPageBtnEnableChange))
|
|
|
|
+ viewModel.isLockScreenSleepEnable.observe(this, Observer(this::onLockScreenSleepEnableChange))
|
|
|
|
+ viewModel.isShowCommentToolEnable.observe(this, Observer(this::onShowCommentToolEnableChange))
|
|
|
|
+ viewModel.isShowBOTAToolEnable.observe(this, Observer(this::onShowBOTAToolEnableChange))
|
|
|
|
+
|
|
|
|
+ setupToolbar()
|
|
|
|
+ setupReadingModeView()
|
|
|
|
+ setupTurnPageView()
|
|
|
|
+ setupScreenSettingView()
|
|
|
|
+ setupToolbarSettingView()
|
|
|
|
+
|
|
|
|
+ rowSwitchView_smartCrop.onCheckedChangeListener = CompoundButton.OnCheckedChangeListener { _, isChecked ->
|
|
|
|
+ viewModel.setCropModeEnable(isChecked)
|
|
|
|
+ }
|
|
|
|
+ rowSwitchView_showStateBar.onCheckedChangeListener = CompoundButton.OnCheckedChangeListener { _, isChecked ->
|
|
|
|
+ viewModel.setShowStateBarEnable(isChecked)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun setupToolbar() {
|
|
|
|
+ setSupportActionBar(toolbar_viewerSetting)
|
|
|
|
+ supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_black_24dp)
|
|
|
|
+ supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
|
|
|
+ when (item?.itemId) {
|
|
|
|
+ android.R.id.home -> finish()
|
|
|
|
+ }
|
|
|
|
+ return super.onOptionsItemSelected(item)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun setupReadingModeView() {
|
|
|
|
+ readingModeSelectView.isLock = true
|
|
|
|
+ readingModeSelectView.onReadModeSelectListener = object : ReadingModeSelectView.OnReadModeSelectListener {
|
|
|
|
+ override fun onReadModeSelect(readMode: Int) {
|
|
|
|
+ viewModel.setReadMode(readMode)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun setupTurnPageView() {
|
|
|
|
+ turnPageModeSelectView.onTurnPageModeChangedListener = object : TurnPageModeSelectView.OnTurnPageModeChangedListener {
|
|
|
|
+ override fun onTurnPageModeChanged(direction: Int) {
|
|
|
|
+ viewModel.setTurnPageDirection(direction)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ turnPageModeSelectView.onShowTurnPageBtnEnableChangedListener = CompoundButton.OnCheckedChangeListener { _, isChecked ->
|
|
|
|
+ viewModel.setTurnPageButtonEnable(isChecked)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun setupScreenSettingView() {
|
|
|
|
+ screenSettingView.onCheckedChangeListener = CompoundButton.OnCheckedChangeListener { _, isChecked ->
|
|
|
|
+ viewModel.setLockScreenSleepEnable(isChecked)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun setupToolbarSettingView() {
|
|
|
|
+ toolbarSettingView.onCheckedChangeListenerComment = CompoundButton.OnCheckedChangeListener { _, isChecked ->
|
|
|
|
+ viewModel.setShowCommentToolEnable(isChecked)
|
|
|
|
+ }
|
|
|
|
+ toolbarSettingView.onCheckedChangeListenerBOTA = CompoundButton.OnCheckedChangeListener { _, isChecked ->
|
|
|
|
+ viewModel.setShowBOTAToolEnable(isChecked)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onReadModeChanged(readMode: Int?) {
|
|
|
|
+ readMode?.let {
|
|
|
|
+ readingModeSelectView.currentReadMode = it
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onCropModeEnableChanged(enable: Boolean?) {
|
|
|
|
+ enable?.let {
|
|
|
|
+ rowSwitchView_smartCrop.isChecked = it
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onShowStateBarEnableChanged(enable: Boolean?) {
|
|
|
|
+ enable?.let {
|
|
|
|
+ rowSwitchView_showStateBar.isChecked = it
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onTurnPageDirectionChanged(direction: Int?) {
|
|
|
|
+ direction?.let {
|
|
|
|
+ turnPageModeSelectView.direction = it
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onShowTurnPageBtnEnableChange(enable: Boolean?) {
|
|
|
|
+ enable?.let {
|
|
|
|
+ turnPageModeSelectView.isTurnPageBtnEnable = it
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onLockScreenSleepEnableChange(enable: Boolean?) {
|
|
|
|
+ enable?.let {
|
|
|
|
+ screenSettingView.isLockScreenSleepEnable = it
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onShowCommentToolEnableChange(enable: Boolean?) {
|
|
|
|
+ enable?.let {
|
|
|
|
+ toolbarSettingView.isShowCommentToolEnable = it
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun onShowBOTAToolEnableChange(enable: Boolean?) {
|
|
|
|
+ enable?.let {
|
|
|
|
+ toolbarSettingView.isShowBOTAToolEnable = it
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|