feat: 优化代码

pull/115/head
kunfei 5 years ago
parent 7af2b7ade0
commit 8af0e0e311
  1. 6
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  3. 6
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  4. 8
      app/src/main/java/io/legado/app/ui/widget/TitleBar.kt
  5. 7
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt

@ -381,7 +381,11 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
textActionMenu = TextActionMenu(this, this)
}
val x = cursor_left.x.toInt() + cursor_left.width
val y = (page_view.height - cursor_left.y + ReadBookConfig.textSize.dp * 1.5).toInt()
val y = if (cursor_left.y - statusBarHeight > ReadBookConfig.textSize.dp * 1.5 + 20.dp) {
(page_view.height - cursor_left.y + ReadBookConfig.textSize.dp * 1.5).toInt()
} else {
(page_view.height - cursor_left.y - cursor_left.height - 40.dp).toInt()
}
textActionMenu?.let { popup ->
if (!popup.isShowing) {
popup.showAtLocation(cursor_left, Gravity.BOTTOM or Gravity.START, x, y)

@ -201,7 +201,7 @@ class ReadMenu : FrameLayout {
height =
if (context.getPrefBoolean(PreferKey.hideNavigationBar)
&& Help.isNavigationBarExist(activity)
) context.getNavigationBarHeight()
) context.navigationBarHeight
else 0
}
}

@ -36,7 +36,7 @@ class ContentView(context: Context) : FrameLayout(context) {
//显示状态栏时隐藏header
if (context.getPrefBoolean(PreferKey.hideStatusBar, false)) {
ll_header.layoutParams =
ll_header.layoutParams.apply { height = context.getStatusBarHeight() }
ll_header.layoutParams.apply { height = context.statusBarHeight }
ll_header.setPadding(
headerPaddingLeft.dp,
headerPaddingTop.dp,
@ -47,7 +47,7 @@ class ContentView(context: Context) : FrameLayout(context) {
page_panel.setPadding(0, 0, 0, 0)
} else {
ll_header.gone()
page_panel.setPadding(0, context.getStatusBarHeight(), 0, 0)
page_panel.setPadding(0, context.statusBarHeight, 0, 0)
}
content_text_view.setPadding(
paddingLeft.dp,
@ -75,7 +75,7 @@ class ContentView(context: Context) : FrameLayout(context) {
return if (context.getPrefBoolean(PreferKey.hideStatusBar, false)) {
ll_header.height
} else {
context.getStatusBarHeight()
context.statusBarHeight
}
}

@ -12,8 +12,8 @@ import com.google.android.material.appbar.AppBarLayout
import io.legado.app.R
import io.legado.app.lib.theme.primaryColor
import io.legado.app.utils.activity
import io.legado.app.utils.getNavigationBarHeight
import io.legado.app.utils.getStatusBarHeight
import io.legado.app.utils.navigationBarHeight
import io.legado.app.utils.statusBarHeight
import org.jetbrains.anko.backgroundColor
import org.jetbrains.anko.bottomPadding
import org.jetbrains.anko.topPadding
@ -132,11 +132,11 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
}
if (a.getBoolean(R.styleable.TitleBar_fitStatusBar, true)) {
topPadding = context.getStatusBarHeight()
topPadding = context.statusBarHeight
}
if (a.getBoolean(R.styleable.TitleBar_fitNavigationBar, false)) {
bottomPadding = context.getNavigationBarHeight()
bottomPadding = context.navigationBarHeight
}
backgroundColor = context.primaryColor

@ -30,7 +30,6 @@ fun Context.getPrefBoolean(key: String, defValue: Boolean = false) =
fun Context.putPrefBoolean(key: String, value: Boolean = false) =
defaultSharedPreferences.edit { putBoolean(key, value) }
fun Context.getPrefInt(key: String, defValue: Int = 0) =
defaultSharedPreferences.getInt(key, defValue)
@ -79,12 +78,14 @@ fun Context.getScreenOffTime(): Int {
return screenOffTime
}
fun Context.getStatusBarHeight(): Int {
val Context.statusBarHeight: Int
get() {
val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
return resources.getDimensionPixelSize(resourceId)
}
fun Context.getNavigationBarHeight(): Int {
val Context.navigationBarHeight: Int
get() {
val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android")
return resources.getDimensionPixelSize(resourceId)
}

Loading…
Cancel
Save