pull/42/head
kunfei 5 years ago
parent 7bf5f6c20b
commit e6701ef574
  1. 30
      app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt
  2. 12
      app/src/main/res/menu/file_chooser.xml

@ -2,7 +2,10 @@ package io.legado.app.ui.filechooser
import android.os.Bundle import android.os.Bundle
import android.util.DisplayMetrics import android.util.DisplayMetrics
import android.view.* import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
@ -108,9 +111,21 @@ class FileChooserDialog : DialogFragment(),
getString(R.string.file_chooser) getString(R.string.file_chooser)
} }
} }
initMenu() initMenu()
initContentView()
refreshCurrentDirPath(initPath)
}
private fun initMenu() {
tool_bar.inflateMenu(R.menu.file_chooser)
if (isOnlyListDir) {
tool_bar.menu.findItem(R.id.menu_ok).isVisible = true
}
tool_bar.menu.applyTint(requireContext(), false)
tool_bar.setOnMenuItemClickListener(this)
}
private fun initContentView() {
fileAdapter = FileAdapter(requireContext(), this) fileAdapter = FileAdapter(requireContext(), this)
pathAdapter = PathAdapter(requireContext(), this) pathAdapter = PathAdapter(requireContext(), this)
@ -121,20 +136,11 @@ class FileChooserDialog : DialogFragment(),
rv_path.layoutManager = LinearLayoutManager(activity, RecyclerView.HORIZONTAL, false) rv_path.layoutManager = LinearLayoutManager(activity, RecyclerView.HORIZONTAL, false)
rv_path.adapter = pathAdapter rv_path.adapter = pathAdapter
refreshCurrentDirPath(initPath)
}
private fun initMenu() {
if (isOnlyListDir) {
tool_bar.menu.add(Menu.NONE, R.id.menu_add, Menu.NONE, R.string.ok)
}
tool_bar.menu.applyTint(requireContext(), false)
tool_bar.setOnMenuItemClickListener(this)
} }
override fun onMenuItemClick(item: MenuItem?): Boolean { override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) { when (item?.itemId) {
R.id.menu_add -> fileAdapter.currentPath?.let { R.id.menu_ok -> fileAdapter.currentPath?.let {
(parentFragment as? CallBack)?.onFilePicked(requestCode, it) (parentFragment as? CallBack)?.onFilePicked(requestCode, it)
(activity as? CallBack)?.onFilePicked(requestCode, it) (activity as? CallBack)?.onFilePicked(requestCode, it)
dismiss() dismiss()

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_ok"
android:title="@string/ok"
android:visible="false"
app:showAsAction="always" />
</menu>
Loading…
Cancel
Save