mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -10,8 +10,18 @@ import io.legado.app.data.entities.BookGroup
|
||||
import io.legado.app.databinding.DialogBookGroupEditBinding
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.lib.theme.primaryColor
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.FileUtils
|
||||
import io.legado.app.utils.MD5Utils
|
||||
import io.legado.app.utils.SelectImageContract
|
||||
import io.legado.app.utils.externalFiles
|
||||
import io.legado.app.utils.gone
|
||||
import io.legado.app.utils.inputStream
|
||||
import io.legado.app.utils.launch
|
||||
import io.legado.app.utils.readUri
|
||||
import io.legado.app.utils.setLayout
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import io.legado.app.utils.visible
|
||||
import splitties.init.appCtx
|
||||
import splitties.views.onClick
|
||||
import java.io.FileOutputStream
|
||||
@@ -28,7 +38,6 @@ class GroupEditDialog() : BaseDialogFragment(R.layout.dialog_book_group_edit) {
|
||||
private val viewModel by viewModels<GroupViewModel>()
|
||||
private var bookGroup: BookGroup? = null
|
||||
private val selectImage = registerForActivityResult(SelectImageContract()) {
|
||||
it ?: return@registerForActivityResult
|
||||
it.uri ?: return@registerForActivityResult
|
||||
readUri(it.uri) { fileDoc, inputStream ->
|
||||
try {
|
||||
|
||||
@@ -78,12 +78,12 @@ abstract class BaseImportBookActivity<VM : ViewModel> : VMBaseActivity<ActivityI
|
||||
val storageHelp = String(assets.open("storageHelp.md").readBytes())
|
||||
val hint = getString(R.string.select_book_folder)
|
||||
alert(hint, storageHelp) {
|
||||
yesButton {
|
||||
okButton {
|
||||
localBookTreeSelect.launch {
|
||||
title = hint
|
||||
}
|
||||
}
|
||||
noButton {
|
||||
cancelButton {
|
||||
localBookTreeSelectListener = null
|
||||
block.resume(false)
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ abstract class BaseReadBookActivity :
|
||||
editEnd.setText(book.totalChapterNum.toString())
|
||||
}
|
||||
customView { alertBinding.root }
|
||||
yesButton {
|
||||
okButton {
|
||||
alertBinding.run {
|
||||
val start = editStart.text!!.toString().let {
|
||||
if (it.isEmpty()) 0 else it.toInt()
|
||||
@@ -282,7 +282,7 @@ abstract class BaseReadBookActivity :
|
||||
CacheBook.start(this@BaseReadBookActivity, book, start - 1, end - 1)
|
||||
}
|
||||
}
|
||||
noButton()
|
||||
cancelButton()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -317,7 +317,7 @@ abstract class BaseReadBookActivity :
|
||||
}
|
||||
alert(titleResource = R.string.simulated_reading) {
|
||||
customView { alertBinding.root }
|
||||
yesButton {
|
||||
okButton {
|
||||
alertBinding.run {
|
||||
val start = editStart.text!!.toString().let {
|
||||
if (it.isEmpty()) 0 else it.toInt()
|
||||
@@ -339,7 +339,7 @@ abstract class BaseReadBookActivity :
|
||||
viewModel.initData(intent)
|
||||
}
|
||||
}
|
||||
noButton()
|
||||
cancelButton()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -352,7 +352,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
|
||||
importNetConfig(url)
|
||||
}
|
||||
}
|
||||
noButton()
|
||||
cancelButton()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,14 +76,14 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
||||
editView.setHint(R.string.group_name)
|
||||
}
|
||||
customView { alertBinding.root }
|
||||
yesButton {
|
||||
okButton {
|
||||
alertBinding.editView.text?.toString()?.let {
|
||||
if (it.isNotBlank()) {
|
||||
viewModel.addGroup(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
noButton()
|
||||
cancelButton()
|
||||
}.requestInputMethod()
|
||||
}
|
||||
|
||||
@@ -95,10 +95,10 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
||||
editView.setText(group)
|
||||
}
|
||||
customView { alertBinding.root }
|
||||
yesButton {
|
||||
okButton {
|
||||
viewModel.upGroup(group, alertBinding.editView.text?.toString())
|
||||
}
|
||||
noButton()
|
||||
cancelButton()
|
||||
}.requestInputMethod()
|
||||
}
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ class ThemeConfigFragment : PreferenceFragment(),
|
||||
}
|
||||
}
|
||||
}
|
||||
noButton()
|
||||
cancelButton()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ class ThemeConfigFragment : PreferenceFragment(),
|
||||
success.invoke()
|
||||
}
|
||||
}
|
||||
noButton()
|
||||
cancelButton()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,10 @@ import android.net.Uri
|
||||
import androidx.activity.result.contract.ActivityResultContract
|
||||
import io.legado.app.help.IntentData
|
||||
import io.legado.app.lib.dialogs.SelectItem
|
||||
import io.legado.app.utils.RealPathUtil
|
||||
import io.legado.app.utils.externalFiles
|
||||
import io.legado.app.utils.putJson
|
||||
import splitties.init.appCtx
|
||||
|
||||
@Suppress("unused")
|
||||
class HandleFileContract :
|
||||
@@ -38,10 +41,15 @@ class HandleFileContract :
|
||||
}
|
||||
|
||||
override fun parseResult(resultCode: Int, intent: Intent?): Result {
|
||||
if (resultCode == RESULT_OK) {
|
||||
return Result(intent?.data, requestCode, intent?.getStringExtra("value"))
|
||||
val uri = if (resultCode != RESULT_OK || intent?.data == null ||
|
||||
RealPathUtil.getPath(appCtx, intent.data!!)
|
||||
?.startsWith(appCtx.externalFiles.parent!!) == true
|
||||
) {
|
||||
null
|
||||
} else {
|
||||
intent.data
|
||||
}
|
||||
return Result(null, requestCode, intent?.getStringExtra("value"))
|
||||
return Result(uri, requestCode, intent?.getStringExtra("value"))
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -217,10 +217,6 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
}
|
||||
val privacyPolicy = String(assets.open("privacyPolicy.md").readBytes())
|
||||
alert(getString(R.string.privacy_policy), privacyPolicy) {
|
||||
noButton {
|
||||
finish()
|
||||
block.resume(false)
|
||||
}
|
||||
positiveButton(R.string.agree) {
|
||||
LocalConfig.privacyPolicyOk = true
|
||||
block.resume(true)
|
||||
|
||||
@@ -157,7 +157,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
||||
viewModel.addBookByUrl(it)
|
||||
}
|
||||
}
|
||||
noButton()
|
||||
cancelButton()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
||||
viewModel.importBookshelf(it, groupId)
|
||||
}
|
||||
}
|
||||
noButton()
|
||||
cancelButton()
|
||||
neutralButton(R.string.select_file) {
|
||||
importBookshelf.launch {
|
||||
mode = HandleFileContract.FILE
|
||||
|
||||
@@ -20,7 +20,7 @@ class QrCodeActivity : BaseActivity<ActivityQrcodeCaptureBinding>(), ScanResultC
|
||||
override val binding by viewBinding(ActivityQrcodeCaptureBinding::inflate)
|
||||
|
||||
private val selectQrImage = registerForActivityResult(SelectImageContract()) {
|
||||
it?.uri?.readBytes(this)?.let { bytes ->
|
||||
it.uri?.readBytes(this)?.let { bytes ->
|
||||
val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
|
||||
onScanResultCallback(QRCodeUtils.parseCodeResult(bitmap))
|
||||
}
|
||||
|
||||
@@ -81,14 +81,14 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
||||
editView.setHint(R.string.group_name)
|
||||
}
|
||||
customView { alertBinding.root }
|
||||
yesButton {
|
||||
okButton {
|
||||
alertBinding.editView.text?.toString()?.let {
|
||||
if (it.isNotBlank()) {
|
||||
viewModel.addGroup(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
noButton()
|
||||
cancelButton()
|
||||
}.requestInputMethod()
|
||||
}
|
||||
|
||||
@@ -100,10 +100,10 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
||||
editView.setText(group)
|
||||
}
|
||||
customView { alertBinding.root }
|
||||
yesButton {
|
||||
okButton {
|
||||
viewModel.upGroup(group, alertBinding.editView.text?.toString())
|
||||
}
|
||||
noButton()
|
||||
cancelButton()
|
||||
}.requestInputMethod()
|
||||
}
|
||||
|
||||
|
||||
@@ -83,14 +83,14 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
||||
editView.setHint(R.string.group_name)
|
||||
}
|
||||
customView { alertBinding.root }
|
||||
yesButton {
|
||||
okButton {
|
||||
alertBinding.editView.text?.toString()?.let {
|
||||
if (it.isNotBlank()) {
|
||||
viewModel.addGroup(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
noButton()
|
||||
cancelButton()
|
||||
}.requestInputMethod()
|
||||
}
|
||||
|
||||
@@ -102,10 +102,10 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
|
||||
editView.setText(group)
|
||||
}
|
||||
customView { alertBinding.root }
|
||||
yesButton {
|
||||
okButton {
|
||||
viewModel.upGroup(group, alertBinding.editView.text?.toString())
|
||||
}
|
||||
noButton()
|
||||
cancelButton()
|
||||
}.requestInputMethod()
|
||||
}
|
||||
|
||||
|
||||
@@ -373,6 +373,8 @@ fun Context.openFileUri(uri: Uri, type: String? = null) {
|
||||
//7.0版本以上
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
}
|
||||
val uri = if (uri.isContentScheme()) uri
|
||||
else FileProvider.getUriForFile(this, AppConst.authority, File(uri.path!!))
|
||||
intent.setDataAndType(uri, type ?: IntentType.from(uri))
|
||||
try {
|
||||
startActivity(intent)
|
||||
|
||||
@@ -54,30 +54,22 @@ object RealPathUtil {
|
||||
"image" -> {
|
||||
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI
|
||||
}
|
||||
|
||||
"video" -> {
|
||||
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI
|
||||
}
|
||||
|
||||
"audio" -> {
|
||||
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
|
||||
}
|
||||
}
|
||||
val selection = "_id=?"
|
||||
val selectionArgs = arrayOf(
|
||||
split[1]
|
||||
)
|
||||
val selectionArgs = arrayOf(split[1])
|
||||
return getDataColumn(context, contentUri, selection, selectionArgs)
|
||||
}
|
||||
} else if ("content".equals(
|
||||
uri.scheme,
|
||||
ignoreCase = true
|
||||
)
|
||||
) { // Return the remote address
|
||||
return if (isGooglePhotosUri(uri)) uri.lastPathSegment else getDataColumn(
|
||||
context,
|
||||
uri,
|
||||
null,
|
||||
null
|
||||
)
|
||||
} else if ("content".equals(uri.scheme, ignoreCase = true)) { // Return the remote address
|
||||
return if (isGooglePhotosUri(uri)) uri.lastPathSegment
|
||||
else getDataColumn(context, uri, null, null)
|
||||
} else if ("file".equals(uri.scheme, ignoreCase = true)) {
|
||||
return uri.path
|
||||
}
|
||||
|
||||
@@ -47,10 +47,7 @@ fun AppCompatActivity.readUri(
|
||||
}
|
||||
} else {
|
||||
PermissionsCompat.Builder()
|
||||
.addPermissions(
|
||||
Permissions.READ_EXTERNAL_STORAGE,
|
||||
Permissions.WRITE_EXTERNAL_STORAGE
|
||||
)
|
||||
.addPermissions(*Permissions.Group.STORAGE)
|
||||
.rationale(R.string.get_storage_per)
|
||||
.onGranted {
|
||||
RealPathUtil.getPath(this, uri)?.let { path ->
|
||||
@@ -87,10 +84,7 @@ fun Fragment.readUri(uri: Uri?, success: (fileDoc: FileDoc, inputStream: InputSt
|
||||
}
|
||||
} else {
|
||||
PermissionsCompat.Builder()
|
||||
.addPermissions(
|
||||
Permissions.READ_EXTERNAL_STORAGE,
|
||||
Permissions.WRITE_EXTERNAL_STORAGE
|
||||
)
|
||||
.addPermissions(*Permissions.Group.STORAGE)
|
||||
.rationale(R.string.get_storage_per)
|
||||
.onGranted {
|
||||
RealPathUtil.getPath(requireContext(), uri)?.let { path ->
|
||||
@@ -99,7 +93,6 @@ fun Fragment.readUri(uri: Uri?, success: (fileDoc: FileDoc, inputStream: InputSt
|
||||
FileInputStream(file).use { inputStream ->
|
||||
success.invoke(fileDoc, inputStream)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
.request()
|
||||
|
||||
Reference in New Issue
Block a user