feat: 优化代码

pull/154/head
kunfei 5 years ago
parent deaceb9840
commit 6956e17e49
  1. 22
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  2. 8
      app/src/main/java/io/legado/app/utils/ViewExtensions.kt
  3. 8
      app/src/main/res/layout/dialog_linear_layout.xml
  4. 2
      app/src/main/res/values/strings.xml

@ -1,11 +1,15 @@
package io.legado.app.ui.book.info
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuItem
import android.widget.CheckBox
import android.widget.LinearLayout
import androidx.lifecycle.Observer
import com.bumptech.glide.RequestBuilder
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
@ -229,23 +233,27 @@ class BookInfoActivity :
}
}
@SuppressLint("InflateParams")
private fun deleteBook() {
viewModel.bookData.value?.let {
if (it.isLocalBook()) {
alert(
titleResource = R.string.sure,
messageResource = R.string.sure_delete_book_file
messageResource = R.string.sure_del
) {
positiveButton(R.string.yes) {
viewModel.delBook(true) {
finish()
}
val checkBox = CheckBox(this@BookInfoActivity).apply {
setText(R.string.delete_book_file)
}
negativeButton(R.string.no) {
viewModel.delBook(false) {
val view = LayoutInflater.from(this@BookInfoActivity)
.inflate(R.layout.dialog_linear_layout, null)
(view as LinearLayout).addView(checkBox)
customView = view
positiveButton(R.string.yes) {
viewModel.delBook(checkBox.isChecked) {
finish()
}
}
negativeButton(R.string.no)
}.show()
} else {
viewModel.delBook {

@ -6,6 +6,7 @@ import android.graphics.Canvas
import android.os.Build
import android.view.View
import android.view.View.*
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.RadioGroup
import android.widget.SeekBar
@ -75,6 +76,13 @@ fun View.screenshot(): Bitmap? {
}.getOrNull()
}
fun View.setMargin(left: Int, top: Int, right: Int, bottom: Int) {
if (layoutParams is ViewGroup.MarginLayoutParams) {
(layoutParams as ViewGroup.MarginLayoutParams).setMargins(left, top, right, bottom)
requestLayout()
}
}
fun SeekBar.progressAdd(int: Int) {
progress += int
}

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp">
</LinearLayout>

@ -630,7 +630,7 @@
<string name="plus"></string>
<string name="other_aloud_setting">其它朗读设置</string>
<string name="system_typeface">系统内置字体样式</string>
<string name="sure_delete_book_file">是否删除源文件</string>
<string name="delete_book_file">删除源文件</string>
<string name="default1">预设一</string>
<string name="default2">预设二</string>
<string name="default3">预设三</string>

Loading…
Cancel
Save