pull/42/head
kunfei 5 years ago
parent 56117c22f9
commit a0390b74cb
  1. 34
      app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt
  2. 2
      app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt
  3. 14
      app/src/main/res/layout/dialog_file_chooser.xml
  4. 2
      app/src/main/res/values/strings.xml

@ -12,6 +12,7 @@ import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.ATH
import io.legado.app.ui.filechooser.adapter.FileAdapter import io.legado.app.ui.filechooser.adapter.FileAdapter
import io.legado.app.ui.filechooser.adapter.PathAdapter import io.legado.app.ui.filechooser.adapter.PathAdapter
import io.legado.app.utils.FileUtils import io.legado.app.utils.FileUtils
@ -29,19 +30,34 @@ class FileChooserDialog : DialogFragment(),
const val DIRECTORY = 0 const val DIRECTORY = 0
const val FILE = 1 const val FILE = 1
fun show(manager: FragmentManager) { fun show(
val fragment = manager: FragmentManager,
(manager.findFragmentByTag(tag) as? FileChooserDialog) ?: FileChooserDialog() mode: Int = FILE,
title: String? = null,
isShowHomeDir: Boolean = false,
isShowUpDir: Boolean = true,
isShowHideDir: Boolean = false
) {
val fragment = (manager.findFragmentByTag(tag) as? FileChooserDialog)
?: FileChooserDialog().apply {
this.mode = mode
this.title = title
this.isShowHomeDir = isShowHomeDir
this.isShowUpDir = isShowUpDir
this.isShowHideDir = isShowHideDir
}
fragment.show(manager, tag) fragment.show(manager, tag)
} }
} }
override var allowExtensions: Array<String?>? = null override var allowExtensions: Array<String?>? = null
override var isOnlyListDir: Boolean = false override val isOnlyListDir: Boolean
get() = mode == DIRECTORY
override var isShowHomeDir: Boolean = false override var isShowHomeDir: Boolean = false
override var isShowUpDir: Boolean = true override var isShowUpDir: Boolean = true
override var isShowHideDir: Boolean = false override var isShowHideDir: Boolean = false
var title: String? = null
private var initPath = FileUtils.getSdCardPath() private var initPath = FileUtils.getSdCardPath()
private var mode: Int = FILE private var mode: Int = FILE
private lateinit var fileAdapter: FileAdapter private lateinit var fileAdapter: FileAdapter
@ -64,7 +80,15 @@ class FileChooserDialog : DialogFragment(),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
tool_bar.title = "文件选择" ATH.applyBackgroundTint(view)
ATH.applyBackgroundTint(rv_path)
tool_bar.title = title ?: let {
if (isOnlyListDir) {
getString(R.string.folder_chooser)
} else {
getString(R.string.file_chooser)
}
}
fileAdapter = FileAdapter(requireContext(), this) fileAdapter = FileAdapter(requireContext(), this)
pathAdapter = PathAdapter(requireContext(), this) pathAdapter = PathAdapter(requireContext(), this)

@ -123,7 +123,7 @@ class FileAdapter(context: Context, val callBack: CallBack) :
/** /**
* 是否仅仅读取目录 * 是否仅仅读取目录
*/ */
var isOnlyListDir: Boolean val isOnlyListDir: Boolean
/** /**
* 是否显示返回主目录 * 是否显示返回主目录
*/ */

@ -9,22 +9,14 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<View
android:layout_width="match_parent"
android:layout_height="0.2dp"
android:background="@color/btn_bg_press_2" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_path" android:id="@+id/rv_path"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="24dp" android:layout_height="24dp"
android:paddingLeft="10dp" android:paddingLeft="10dp"
android:paddingRight="10dp" /> android:paddingRight="10dp"
android:background="@color/background"
<View android:elevation="5dp" />
android:layout_width="match_parent"
android:layout_height="0.2dp"
android:background="@color/btn_bg_press_2" />
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"

@ -536,5 +536,7 @@
<string name="precision_search">精准搜索</string> <string name="precision_search">精准搜索</string>
<string name="service_starting">正在启动服务</string> <string name="service_starting">正在启动服务</string>
<string name="empty"></string> <string name="empty"></string>
<string name="file_chooser">文件选择</string>
<string name="folder_chooser">文件夹选择</string>
</resources> </resources>

Loading…
Cancel
Save