|
|
|
@ -7,8 +7,12 @@ import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import io.legado.app.R |
|
|
|
|
import io.legado.app.base.BaseDialogFragment |
|
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
|
import io.legado.app.lib.dialogs.selector |
|
|
|
|
import io.legado.app.ui.book.read.ReadBookActivity |
|
|
|
|
import io.legado.app.utils.getCompatColor |
|
|
|
|
import io.legado.app.utils.putPrefInt |
|
|
|
|
import kotlinx.android.synthetic.main.dialog_click_action_config.* |
|
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
|
|
|
|
|
@ -38,10 +42,87 @@ class ClickActionConfigDialog : BaseDialogFragment() { |
|
|
|
|
|
|
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
|
view.setBackgroundColor(getCompatColor(R.color.translucent)) |
|
|
|
|
initData() |
|
|
|
|
initViewEvent() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun initData() = with(AppConfig) { |
|
|
|
|
tv_top_left.text = getActionString(clickActionTopLeft) |
|
|
|
|
tv_top_center.text = getActionString(clickActionTopCenter) |
|
|
|
|
tv_top_right.text = getActionString(clickActionTopRight) |
|
|
|
|
tv_middle_left.text = getActionString(clickActionMiddleLeft) |
|
|
|
|
tv_middle_right.text = getActionString(clickActionMiddleRight) |
|
|
|
|
tv_bottom_left.text = getActionString(clickActionBottomLeft) |
|
|
|
|
tv_bottom_center.text = getActionString(clickActionBottomCenter) |
|
|
|
|
tv_bottom_right.text = getActionString(clickActionBottomRight) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun getActionString(action: Int): String { |
|
|
|
|
return when (action) { |
|
|
|
|
0 -> getString(R.string.menu) |
|
|
|
|
2 -> getString(R.string.prev_page) |
|
|
|
|
else -> getString(R.string.next_page) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun initViewEvent() { |
|
|
|
|
iv_close.onClick { |
|
|
|
|
dismiss() |
|
|
|
|
} |
|
|
|
|
tv_top_left.onClick { |
|
|
|
|
selectAction { action -> |
|
|
|
|
putPrefInt(PreferKey.clickActionTopLeft, action) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
tv_top_center.onClick { |
|
|
|
|
selectAction { action -> |
|
|
|
|
putPrefInt(PreferKey.clickActionTopCenter, action) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
tv_top_right.onClick { |
|
|
|
|
selectAction { action -> |
|
|
|
|
putPrefInt(PreferKey.clickActionTopRight, action) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
tv_middle_left.onClick { |
|
|
|
|
selectAction { action -> |
|
|
|
|
putPrefInt(PreferKey.clickActionMiddleLeft, action) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
tv_middle_right.onClick { |
|
|
|
|
selectAction { action -> |
|
|
|
|
putPrefInt(PreferKey.clickActionMiddleRight, action) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
tv_bottom_left.onClick { |
|
|
|
|
selectAction { action -> |
|
|
|
|
putPrefInt(PreferKey.clickActionBottomLeft, action) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
tv_bottom_center.onClick { |
|
|
|
|
selectAction { action -> |
|
|
|
|
putPrefInt(PreferKey.clickActionBottomCenter, action) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
tv_bottom_right.onClick { |
|
|
|
|
selectAction { action -> |
|
|
|
|
putPrefInt(PreferKey.clickActionBottomRight, action) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun selectAction(success: (action: Int) -> Unit) { |
|
|
|
|
val actions = arrayListOf( |
|
|
|
|
getString(R.string.menu), |
|
|
|
|
getString(R.string.next_page), |
|
|
|
|
getString(R.string.prev_page) |
|
|
|
|
) |
|
|
|
|
selector( |
|
|
|
|
getString(R.string.select_action), |
|
|
|
|
actions |
|
|
|
|
) { _, index -> |
|
|
|
|
success.invoke(index) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |