更新界面
This commit is contained in:
@@ -184,4 +184,5 @@ object PreferKey {
|
||||
|
||||
const val themePref = "themePref"
|
||||
const val bookshelfSortOrder = "bookshelfSortOrder"
|
||||
const val showBottomView = "showBottomView"
|
||||
}
|
||||
|
||||
@@ -224,6 +224,9 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
val showRSS: Boolean
|
||||
get() = appCtx.getPrefBoolean(PreferKey.showRss, true)
|
||||
|
||||
val showBottomView: Boolean
|
||||
get() = appCtx.getPrefBoolean(PreferKey.showBottomView, true)
|
||||
|
||||
val autoRefreshBook: Boolean
|
||||
get() = appCtx.getPrefBoolean(PreferKey.autoRefresh)
|
||||
|
||||
|
||||
@@ -5,15 +5,12 @@ import android.app.SearchManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.ResolveInfo
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.PopupWindow
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.view.SupportMenuInflater
|
||||
import androidx.appcompat.view.menu.MenuBuilder
|
||||
import androidx.appcompat.view.menu.MenuItemImpl
|
||||
@@ -43,6 +40,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
|
||||
private val adapter = Adapter(context).apply {
|
||||
setHasStableIds(true)
|
||||
}
|
||||
|
||||
private val menuItems: List<MenuItemImpl>
|
||||
private val visibleMenuItems = arrayListOf<MenuItemImpl>()
|
||||
private val moreMenuItems = arrayListOf<MenuItemImpl>()
|
||||
@@ -55,13 +53,12 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
|
||||
isTouchable = true
|
||||
isOutsideTouchable = false
|
||||
isFocusable = false
|
||||
animationStyle = R.style.TextActionMenuAnimation
|
||||
|
||||
val myMenu = MenuBuilder(context)
|
||||
val otherMenu = MenuBuilder(context)
|
||||
SupportMenuInflater(context).inflate(R.menu.content_select_action, myMenu)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
onInitializeMenu(otherMenu)
|
||||
}
|
||||
onInitializeMenu(otherMenu)
|
||||
menuItems = myMenu.visibleItems + otherMenu.visibleItems
|
||||
visibleMenuItems.addAll(menuItems.subList(0, 5))
|
||||
moreMenuItems.addAll(menuItems.subList(5, menuItems.size))
|
||||
@@ -114,10 +111,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
|
||||
when {
|
||||
startTopY > 500 -> {
|
||||
showAtLocation(
|
||||
view,
|
||||
Gravity.BOTTOM or Gravity.START,
|
||||
startX,
|
||||
windowHeight - startTopY
|
||||
view, Gravity.BOTTOM or Gravity.START, startX, windowHeight - startTopY
|
||||
)
|
||||
}
|
||||
|
||||
@@ -138,28 +132,19 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
|
||||
when {
|
||||
startBottomY > 500 -> {
|
||||
showAtLocation(
|
||||
view,
|
||||
Gravity.TOP or Gravity.START,
|
||||
startX,
|
||||
startTopY - popupHeight
|
||||
view, Gravity.TOP or Gravity.START, startX, startTopY - popupHeight
|
||||
)
|
||||
}
|
||||
|
||||
endBottomY - startBottomY > 500 -> {
|
||||
showAtLocation(
|
||||
view,
|
||||
Gravity.TOP or Gravity.START,
|
||||
startX,
|
||||
startBottomY
|
||||
view, Gravity.TOP or Gravity.START, startX, startBottomY
|
||||
)
|
||||
}
|
||||
|
||||
else -> {
|
||||
showAtLocation(
|
||||
view,
|
||||
Gravity.TOP or Gravity.START,
|
||||
endX,
|
||||
endBottomY
|
||||
view, Gravity.TOP or Gravity.START, endX, endBottomY
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -233,28 +218,23 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
|
||||
}
|
||||
|
||||
else -> item.intent?.let {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
it.putExtra(Intent.EXTRA_PROCESS_TEXT, callBack.selectedText)
|
||||
context.startActivity(it)
|
||||
}
|
||||
it.putExtra(Intent.EXTRA_PROCESS_TEXT, callBack.selectedText)
|
||||
context.startActivity(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
private fun createProcessTextIntent(): Intent {
|
||||
return Intent()
|
||||
.setAction(Intent.ACTION_PROCESS_TEXT)
|
||||
.setType("text/plain")
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
private fun getSupportedActivities(): List<ResolveInfo> {
|
||||
return context.packageManager
|
||||
.queryIntentActivities(createProcessTextIntent(), 0)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
private fun createProcessTextIntentForResolveInfo(info: ResolveInfo): Intent {
|
||||
return createProcessTextIntent()
|
||||
.putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false)
|
||||
@@ -266,7 +246,6 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
|
||||
* so that your "PROCESS_TEXT" menu items appear after the
|
||||
* standard selection menu items like Cut, Copy, Paste.
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
private fun onInitializeMenu(menu: Menu) {
|
||||
kotlin.runCatching {
|
||||
var menuItemOrder = 100
|
||||
|
||||
@@ -10,8 +10,6 @@ import io.legato.kazusa.databinding.DialogTipConfigBinding
|
||||
import io.legato.kazusa.help.config.ReadBookConfig
|
||||
import io.legato.kazusa.help.config.ReadTipConfig
|
||||
import io.legato.kazusa.lib.dialogs.selector
|
||||
import io.legato.kazusa.utils.checkByIndex
|
||||
import io.legato.kazusa.utils.getIndexById
|
||||
import io.legato.kazusa.utils.hexString
|
||||
import io.legato.kazusa.utils.observeEvent
|
||||
import io.legato.kazusa.utils.postEvent
|
||||
@@ -41,7 +39,14 @@ class TipConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_tip_config
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
binding.rgTitleMode.checkByIndex(ReadBookConfig.titleMode)
|
||||
|
||||
when (ReadBookConfig.titleMode) {
|
||||
0 -> binding.rgTitleMode.check(R.id.rb_title_mode1)
|
||||
1 -> binding.rgTitleMode.check(R.id.rb_title_mode2)
|
||||
2 -> binding.rgTitleMode.check(R.id.rb_title_mode3)
|
||||
else -> { }
|
||||
}
|
||||
|
||||
binding.dsbTitleSize.progress = ReadBookConfig.titleSize
|
||||
binding.dsbTitleTop.progress = ReadBookConfig.titleTopSpacing
|
||||
binding.dsbTitleBottom.progress = ReadBookConfig.titleBottomSpacing
|
||||
@@ -91,9 +96,11 @@ class TipConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_tip_config
|
||||
}
|
||||
|
||||
private fun initEvent() = binding.run {
|
||||
rgTitleMode.setOnCheckedChangeListener { _, checkedId ->
|
||||
ReadBookConfig.titleMode = rgTitleMode.getIndexById(checkedId)
|
||||
postEvent(EventBus.UP_CONFIG, arrayListOf(5))
|
||||
binding.rgTitleMode.setOnCheckedStateChangeListener { group, checkedIds ->
|
||||
if (checkedIds.isNotEmpty()) {
|
||||
ReadBookConfig.titleMode = group.indexOfChild(group.findViewById(checkedIds.first()))
|
||||
postEvent(EventBus.UP_CONFIG, arrayListOf(5))
|
||||
}
|
||||
}
|
||||
dsbTitleSize.onChanged = {
|
||||
ReadBookConfig.titleSize = it
|
||||
|
||||
@@ -194,7 +194,7 @@ class OtherConfigFragment : PreferenceFragment(),
|
||||
setProcessTextEnable(it.getBoolean(key, true))
|
||||
}
|
||||
|
||||
PreferKey.showDiscovery, PreferKey.showRss -> postEvent(EventBus.NOTIFY_MAIN, true)
|
||||
PreferKey.showDiscovery, PreferKey.showRss, PreferKey.showBottomView -> postEvent(EventBus.NOTIFY_MAIN, true)
|
||||
PreferKey.language -> listView.postDelayed(1000) {
|
||||
appCtx.restart()
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@ import kotlin.coroutines.suspendCoroutine
|
||||
import androidx.core.view.get
|
||||
import com.google.android.material.navigation.NavigationBarView
|
||||
import io.legato.kazusa.ui.main.bookshelf.books.BookshelfFragment3
|
||||
import io.legato.kazusa.utils.gone
|
||||
import io.legato.kazusa.utils.visible
|
||||
|
||||
/**
|
||||
* 主界面
|
||||
@@ -382,40 +384,46 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
|
||||
|
||||
private fun upBottomMenu() {
|
||||
if (AppConfig.showBottomView)
|
||||
{
|
||||
getNavigationBarView().visible()
|
||||
val showDiscovery = AppConfig.showDiscovery
|
||||
val showRss = AppConfig.showRSS
|
||||
val menu = getNavigationBarView().menu
|
||||
menu.findItem(R.id.menu_discovery).isVisible = showDiscovery
|
||||
menu.findItem(R.id.menu_rss).isVisible = showRss
|
||||
|
||||
val showDiscovery = AppConfig.showDiscovery
|
||||
val showRss = AppConfig.showRSS
|
||||
val menu = getNavigationBarView().menu
|
||||
menu.findItem(R.id.menu_discovery).isVisible = showDiscovery
|
||||
menu.findItem(R.id.menu_rss).isVisible = showRss
|
||||
|
||||
var index = 0
|
||||
if (showDiscovery) {
|
||||
var index = 0
|
||||
if (showDiscovery) {
|
||||
index++
|
||||
realPositions[index] = idExplore
|
||||
}
|
||||
if (showRss) {
|
||||
index++
|
||||
realPositions[index] = idRss
|
||||
}
|
||||
index++
|
||||
realPositions[index] = idExplore
|
||||
realPositions[index] = idMy
|
||||
bottomMenuCount = index + 1
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
if (showRss) {
|
||||
index++
|
||||
realPositions[index] = idRss
|
||||
}
|
||||
index++
|
||||
realPositions[index] = idMy
|
||||
bottomMenuCount = index + 1
|
||||
adapter.notifyDataSetChanged()
|
||||
else getNavigationBarView().gone()
|
||||
}
|
||||
|
||||
private fun upHomePage() {
|
||||
when (AppConfig.defaultHomePage) {
|
||||
"bookshelf" -> {}
|
||||
"explore" -> if (AppConfig.showDiscovery) {
|
||||
"explore" -> if (AppConfig.showDiscovery && AppConfig.showBottomView) {
|
||||
binding.viewPagerMain.setCurrentItem(realPositions.indexOf(idExplore), false)
|
||||
}
|
||||
|
||||
"rss" -> if (AppConfig.showRSS) {
|
||||
"rss" -> if (AppConfig.showRSS && AppConfig.showBottomView) {
|
||||
binding.viewPagerMain.setCurrentItem(realPositions.indexOf(idRss), false)
|
||||
}
|
||||
|
||||
"my" -> binding.viewPagerMain.setCurrentItem(realPositions.indexOf(idMy), false)
|
||||
"my" -> if (AppConfig.showBottomView) {
|
||||
binding.viewPagerMain.setCurrentItem(realPositions.indexOf(idMy), false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -154,8 +154,8 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
|
||||
}
|
||||
}
|
||||
|
||||
private fun showMenu(view: View, position: Int): Boolean {
|
||||
val source = getItem(position) ?: return true
|
||||
private fun showMenu(view: View, position: Int) {
|
||||
val source = getItem(position) ?: return
|
||||
val popupMenu = PopupMenu(context, view)
|
||||
popupMenu.inflate(R.menu.explore_item)
|
||||
popupMenu.menu.findItem(R.id.menu_login).isVisible = source.hasLoginUrl
|
||||
@@ -180,7 +180,6 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
|
||||
true
|
||||
}
|
||||
popupMenu.show()
|
||||
return true
|
||||
}
|
||||
|
||||
interface CallBack {
|
||||
|
||||
Reference in New Issue
Block a user