feat: 优化代码

pull/115/head
kunfei 5 years ago
parent c1318a66d7
commit e2463037a4
  1. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 44
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt
  3. 1
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  4. 49
      app/src/main/res/layout/dialog_toc_regex.xml

@ -214,6 +214,10 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
R.id.menu_book_info -> ReadBook.book?.let {
startActivity<BookInfoActivity>(Pair("bookUrl", it.bookUrl))
}
R.id.menu_toc_regex -> TocRegexDialog.show(
supportFragmentManager,
ReadBook.book?.tocUrl
)
}
return super.onCompatOptionsItemSelected(item)
}

@ -0,0 +1,44 @@
package io.legado.app.ui.book.read.config
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
class TocRegexDialog : BaseDialogFragment() {
companion object {
fun show(fragmentManager: FragmentManager, tocRegex: String? = null) {
val dialog = TocRegexDialog()
val bundle = Bundle()
bundle.putString("tocRegex", tocRegex)
dialog.arguments = bundle
dialog.show(fragmentManager, "tocRegexDialog")
}
}
override fun onStart() {
super.onStart()
val dm = DisplayMetrics()
activity?.windowManager?.defaultDisplay?.getMetrics(dm)
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.8).toInt())
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.dialog_toc_regex, container)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
}

@ -130,6 +130,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
pageOffset = 0f
}
val cHeight = if (textPage.height > 0) textPage.height else height
}

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/tool_bar"
android:background="@color/background_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:background="@color/background_card"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:padding="12dp"
android:text="@string/cancel"
tools:ignore="RtlHardcoded" />
<TextView
android:id="@+id/tv_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:padding="12dp"
android:text="@string/ok"
tools:ignore="RtlHardcoded" />
</LinearLayout>
</LinearLayout>
Loading…
Cancel
Save