|
|
@ -15,7 +15,6 @@ import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.base.BaseDialogFragment |
|
|
|
import io.legado.app.base.BaseDialogFragment |
|
|
|
import io.legado.app.constant.EventBus |
|
|
|
|
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.help.permission.Permissions |
|
|
|
import io.legado.app.help.permission.Permissions |
|
|
@ -28,7 +27,6 @@ import io.legado.app.utils.* |
|
|
|
import kotlinx.android.synthetic.main.dialog_font_select.* |
|
|
|
import kotlinx.android.synthetic.main.dialog_font_select.* |
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
|
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
|
@ -170,34 +168,16 @@ class FontSelectDialog : BaseDialogFragment(), |
|
|
|
|
|
|
|
|
|
|
|
override fun onClick(docItem: DocItem) { |
|
|
|
override fun onClick(docItem: DocItem) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
fontFolder.listFiles()?.forEach { |
|
|
|
FileUtils.deleteFile(fontFolder.absolutePath) |
|
|
|
it.delete() |
|
|
|
callBack?.selectFont(docItem.uri.toString()) |
|
|
|
} |
|
|
|
|
|
|
|
if (docItem.isContentPath) { |
|
|
|
|
|
|
|
val file = FileUtils.createFileIfNotExist(fontFolder, docItem.name) |
|
|
|
|
|
|
|
@Suppress("BlockingMethodInNonBlockingContext") |
|
|
|
|
|
|
|
requireActivity().contentResolver.openInputStream(docItem.uri)?.use { input -> |
|
|
|
|
|
|
|
file.outputStream().use { output -> |
|
|
|
|
|
|
|
input.copyTo(output) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
callBack?.selectFile(file.path) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
val file = File(docItem.uri.toString()) |
|
|
|
|
|
|
|
file.copyTo(FileUtils.createFileIfNotExist(fontFolder, file.name), true) |
|
|
|
|
|
|
|
.absolutePath.let { path -> |
|
|
|
|
|
|
|
if (curFilePath != path) { |
|
|
|
|
|
|
|
withContext(Main) { |
|
|
|
|
|
|
|
callBack?.selectFile(path) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.onSuccess { |
|
|
|
}.onSuccess { |
|
|
|
dialog?.dismiss() |
|
|
|
dialog?.dismiss() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 字体文件夹 |
|
|
|
|
|
|
|
*/ |
|
|
|
override fun onFilePicked(requestCode: Int, currentPath: String) { |
|
|
|
override fun onFilePicked(requestCode: Int, currentPath: String) { |
|
|
|
when (requestCode) { |
|
|
|
when (requestCode) { |
|
|
|
fontFolderRequestCode -> { |
|
|
|
fontFolderRequestCode -> { |
|
|
@ -231,11 +211,7 @@ class FontSelectDialog : BaseDialogFragment(), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun onDefaultFontChange() { |
|
|
|
private fun onDefaultFontChange() { |
|
|
|
if (curFilePath == "") { |
|
|
|
callBack?.selectFont("") |
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
callBack?.selectFile("") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override val curFilePath: String get() = callBack?.curFontPath ?: "" |
|
|
|
override val curFilePath: String get() = callBack?.curFontPath ?: "" |
|
|
@ -244,7 +220,7 @@ class FontSelectDialog : BaseDialogFragment(), |
|
|
|
get() = (parentFragment as? CallBack) ?: (activity as? CallBack) |
|
|
|
get() = (parentFragment as? CallBack) ?: (activity as? CallBack) |
|
|
|
|
|
|
|
|
|
|
|
interface CallBack { |
|
|
|
interface CallBack { |
|
|
|
fun selectFile(path: String) |
|
|
|
fun selectFont(path: String) |
|
|
|
val curFontPath: String |
|
|
|
val curFontPath: String |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |