feat: 优化代码

pull/115/head
kunfei 5 years ago
parent 3bd20e995e
commit 76fec52adb
  1. 2
      app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt
  2. 13
      app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt
  3. 4
      app/src/main/res/menu/content_select_action.xml
  4. 1
      app/src/main/res/values/strings.xml

@ -226,14 +226,12 @@ object AnalyzeTxtFile {
private fun getTocRules(): List<TxtTocRule> {
val rules = App.db.txtTocRule().all
if (rules.isEmpty()) {
App.INSTANCE.assets.open("txtTocRule.json").readBytes().let { byteArray ->
GSON.fromJsonArray<TxtTocRule>(String(byteArray))?.let {
App.db.txtTocRule().insert(*it.toTypedArray())
return it
}
}
}
return rules
}
}

@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.pm.ResolveInfo
import android.net.Uri
import android.os.Build
import android.view.LayoutInflater
import android.view.Menu
@ -22,6 +23,7 @@ import io.legado.app.utils.sendToClip
import kotlinx.android.synthetic.main.item_fillet_text.view.*
import kotlinx.android.synthetic.main.popup_action_menu.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.toast
class TextActionMenu(private val context: Context, private val callBack: CallBack) :
@ -77,7 +79,16 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
private fun onMenuItemSelected(item: MenuItemImpl) {
when (item.itemId) {
R.id.menu_copy -> context.sendToClip(callBack.selectedText)
else -> item.intent.let {
R.id.menu_browser -> {
try {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(callBack.selectedText)
context.startActivity(intent)
} catch (e: Exception) {
context.toast(R.string.can_not_open)
}
}
else -> item.intent?.let {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
it.putExtra(Intent.EXTRA_PROCESS_TEXT, callBack.selectedText)
context.startActivity(it)

@ -9,4 +9,8 @@
android:id="@+id/menu_copy"
android:title="@android:string/copy" />
<item
android:id="@+id/menu_browser"
android:title="@string/browser" />
</menu>

@ -619,4 +619,5 @@
<string name="select_start">文本选择开始位置</string>
<string name="share_layout">共用布局</string>
<string name="title_center">标题居中</string>
<string name="browser">浏览器</string>
</resources>

Loading…
Cancel
Save