pull/66/head
kunfei 5 years ago
parent c2df639f94
commit 7533cff6f7
  1. 26
      app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt
  2. 15
      app/src/main/res/menu/font_select.xml
  3. 1
      app/src/main/res/values/strings.xml

@ -7,8 +7,10 @@ import android.net.Uri
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.documentfile.provider.DocumentFile
import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.LinearLayoutManager
@ -33,6 +35,7 @@ import java.io.File
import kotlin.coroutines.CoroutineContext
class FontSelectDialog : DialogFragment(),
Toolbar.OnMenuItemClickListener,
CoroutineScope,
FontAdapter.CallBack {
lateinit var job: Job
@ -62,6 +65,8 @@ class FontSelectDialog : DialogFragment(),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
tool_bar.setTitle(R.string.select_font)
tool_bar.inflateMenu(R.menu.font_select)
tool_bar.setOnMenuItemClickListener(this)
adapter = FontAdapter(requireContext(), this)
recycler_view.layoutManager = LinearLayoutManager(context)
recycler_view.adapter = adapter
@ -79,6 +84,27 @@ class FontSelectDialog : DialogFragment(),
}
}
override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.menu_default -> {
val pf = parentFragment
if (pf is CallBack) {
if ("" != pf.curFontPath) {
pf.selectFile("")
}
}
val activity = activity
if (activity is CallBack) {
if ("" != activity.curFontPath) {
activity.selectFile("")
}
}
dismiss()
}
}
return true
}
override fun onDestroy() {
super.onDestroy()
job.cancel()

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_default"
android:title="@string/default_font"
app:showAsAction="ifRoom" />
<item
android:id="@+id/menu_other"
android:title="@string/other_folder"
app:showAsAction="never" />
</menu>

@ -578,5 +578,6 @@
<string name="no_group">未分组</string>
<string name="prev_sentence">上一句</string>
<string name="next_sentence">下一句</string>
<string name="other_folder">其它目录</string>
</resources>

Loading…
Cancel
Save