|
|
@ -12,37 +12,30 @@ import android.view.View |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.view.ViewGroup |
|
|
|
import androidx.appcompat.widget.Toolbar |
|
|
|
import androidx.appcompat.widget.Toolbar |
|
|
|
import androidx.documentfile.provider.DocumentFile |
|
|
|
import androidx.documentfile.provider.DocumentFile |
|
|
|
import androidx.fragment.app.DialogFragment |
|
|
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
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.constant.PreferKey |
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
import io.legado.app.help.permission.Permissions |
|
|
|
import io.legado.app.help.permission.Permissions |
|
|
|
import io.legado.app.help.permission.PermissionsCompat |
|
|
|
import io.legado.app.help.permission.PermissionsCompat |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.* |
|
|
|
import kotlinx.android.synthetic.main.dialog_font_select.* |
|
|
|
import kotlinx.android.synthetic.main.dialog_font_select.* |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
|
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
import kotlinx.coroutines.Job |
|
|
|
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FontSelectDialog : DialogFragment(), |
|
|
|
class FontSelectDialog : BaseDialogFragment(), |
|
|
|
Toolbar.OnMenuItemClickListener, |
|
|
|
Toolbar.OnMenuItemClickListener, |
|
|
|
CoroutineScope, |
|
|
|
|
|
|
|
FontAdapter.CallBack { |
|
|
|
FontAdapter.CallBack { |
|
|
|
private lateinit var job: Job |
|
|
|
|
|
|
|
private val fontFolderRequestCode = 35485 |
|
|
|
private val fontFolderRequestCode = 35485 |
|
|
|
private val fontFolder = |
|
|
|
private val fontFolder = |
|
|
|
App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator |
|
|
|
App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator |
|
|
|
private val fontCacheFolder by lazy { |
|
|
|
private val fontCacheFolder by lazy { |
|
|
|
FileUtils.createFolderIfNotExist(App.INSTANCE.cacheDir, "Fonts") |
|
|
|
FileUtils.createFolderIfNotExist(App.INSTANCE.cacheDir, "Fonts") |
|
|
|
} |
|
|
|
} |
|
|
|
override val coroutineContext: CoroutineContext |
|
|
|
|
|
|
|
get() = job + Main |
|
|
|
|
|
|
|
private var adapter: FontAdapter? = null |
|
|
|
private var adapter: FontAdapter? = null |
|
|
|
|
|
|
|
|
|
|
|
override fun onStart() { |
|
|
|
override fun onStart() { |
|
|
@ -57,7 +50,6 @@ class FontSelectDialog : DialogFragment(), |
|
|
|
container: ViewGroup?, |
|
|
|
container: ViewGroup?, |
|
|
|
savedInstanceState: Bundle? |
|
|
|
savedInstanceState: Bundle? |
|
|
|
): View? { |
|
|
|
): View? { |
|
|
|
job = Job() |
|
|
|
|
|
|
|
return inflater.inflate(R.layout.dialog_font_select, container) |
|
|
|
return inflater.inflate(R.layout.dialog_font_select, container) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -101,11 +93,6 @@ class FontSelectDialog : DialogFragment(), |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onDestroy() { |
|
|
|
|
|
|
|
super.onDestroy() |
|
|
|
|
|
|
|
job.cancel() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun openFolder() { |
|
|
|
private fun openFolder() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) |
|
|
|
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) |
|
|
|