pull/66/head
kunfei 5 years ago
parent d1e25c9772
commit 572c5957a2
  1. 30
      app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt

@ -38,10 +38,8 @@ class FontSelectDialog : DialogFragment(),
lateinit var job: Job lateinit var job: Job
private val fontFolderRequestCode = 35485 private val fontFolderRequestCode = 35485
private lateinit var adapter: FontAdapter private lateinit var adapter: FontAdapter
var curPath: String? = null
private val fontFolder = private val fontFolder =
App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator
var selectFile: ((path: String) -> Unit)? = null
override val coroutineContext: CoroutineContext override val coroutineContext: CoroutineContext
get() = job + Main get() = job + Main
@ -141,15 +139,32 @@ class FontSelectDialog : DialogFragment(),
override fun onClick(file: File) { override fun onClick(file: File) {
file.absolutePath.let { file.absolutePath.let {
if (it != curPath) { val pf = parentFragment
selectFile?.invoke(it) if (pf is CallBack) {
dialog?.dismiss() if (it != pf.curPath) {
pf.selectFile(it)
}
} }
val activity = activity
if (activity is CallBack) {
if (it != activity.curPath) {
activity.selectFile(it)
} }
} }
}
dialog?.dismiss()
}
override fun curFilePath(): String { override fun curFilePath(): String {
return curPath ?: "" val pf = parentFragment
if (pf is CallBack) {
return pf.curPath
}
val activity = activity
if (activity is CallBack) {
return activity.curPath
}
return ""
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
@ -169,6 +184,7 @@ class FontSelectDialog : DialogFragment(),
} }
interface CallBack { interface CallBack {
fun selectFile(uri: Uri) fun selectFile(path: String)
val curPath: String
} }
} }
Loading…
Cancel
Save