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

@ -6,6 +6,7 @@ import android.graphics.Canvas
import android.os.Build import android.os.Build
import android.view.View import android.view.View
import android.view.View.* import android.view.View.*
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.RadioGroup import android.widget.RadioGroup
import android.widget.SeekBar import android.widget.SeekBar
@ -75,6 +76,13 @@ fun View.screenshot(): Bitmap? {
}.getOrNull() }.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) { fun SeekBar.progressAdd(int: Int) {
progress += 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="plus"></string>
<string name="other_aloud_setting">其它朗读设置</string> <string name="other_aloud_setting">其它朗读设置</string>
<string name="system_typeface">系统内置字体样式</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="default1">预设一</string>
<string name="default2">预设二</string> <string name="default2">预设二</string>
<string name="default3">预设三</string> <string name="default3">预设三</string>

Loading…
Cancel
Save