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