pull/1434/head
gedoor 3 years ago
parent c29dfbb9ed
commit ba69ae317b
  1. 16
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  2. 5
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  3. 20
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt
  4. 15
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt

@ -1,7 +1,6 @@
package io.legado.app.ui.book.source.manage package io.legado.app.ui.book.source.manage
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
@ -9,13 +8,11 @@ import android.view.SubMenu
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.content.FileProvider
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.data.appDb import io.legado.app.data.appDb
@ -124,18 +121,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
R.id.menu_add_book_source -> startActivity<BookSourceEditActivity>() R.id.menu_add_book_source -> startActivity<BookSourceEditActivity>()
R.id.menu_import_qr -> qrResult.launch(null) R.id.menu_import_qr -> qrResult.launch(null)
R.id.menu_share_source -> viewModel.saveToFile(adapter.selection) { R.id.menu_share_source -> viewModel.saveToFile(adapter.selection) {
val fileUri = FileProvider.getUriForFile(this, AppConst.authority, it) share(it)
val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/*"
intent.putExtra(Intent.EXTRA_STREAM, fileUri)
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(
Intent.createChooser(
intent,
getString(R.string.share_selected_source)
)
)
} }
R.id.menu_group_manage -> showDialogFragment<GroupManageDialog>() R.id.menu_group_manage -> showDialogFragment<GroupManageDialog>()
R.id.menu_import_local -> importDoc.launch { R.id.menu_import_local -> importDoc.launch {

@ -1,7 +1,6 @@
package io.legado.app.ui.rss.source.manage package io.legado.app.ui.rss.source.manage
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
@ -117,8 +116,8 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
R.id.menu_import_onLine -> showImportDialog() R.id.menu_import_onLine -> showImportDialog()
R.id.menu_import_qr -> qrCodeResult.launch(null) R.id.menu_import_qr -> qrCodeResult.launch(null)
R.id.menu_group_manage -> showDialogFragment<GroupManageDialog>() R.id.menu_group_manage -> showDialogFragment<GroupManageDialog>()
R.id.menu_share_source -> viewModel.shareSelection(adapter.selection) { R.id.menu_share_source -> viewModel.saveToFile(adapter.selection) {
startActivity(Intent.createChooser(it, getString(R.string.share_selected_source))) share(it)
} }
R.id.menu_import_default -> viewModel.importDefault() R.id.menu_import_default -> viewModel.importDefault()
R.id.menu_help -> showHelp() R.id.menu_help -> showHelp()

@ -1,15 +1,13 @@
package io.legado.app.ui.rss.source.manage package io.legado.app.ui.rss.source.manage
import android.app.Application import android.app.Application
import android.content.Intent
import android.text.TextUtils import android.text.TextUtils
import androidx.core.content.FileProvider
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppConst
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.help.DefaultData import io.legado.app.help.DefaultData
import io.legado.app.utils.* import io.legado.app.utils.*
import java.io.File
class RssSourceViewModel(application: Application) : BaseViewModel(application) { class RssSourceViewModel(application: Application) : BaseViewModel(application) {
@ -77,19 +75,13 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun shareSelection(sources: List<RssSource>, success: ((intent: Intent) -> Unit)) { fun saveToFile(sources: List<RssSource>, success: (file: File) -> Unit) {
execute { execute {
val tmpSharePath = "${context.filesDir}/shareRssSource.json" val path = "${context.filesDir}/shareRssSource.json"
FileUtils.delete(tmpSharePath) FileUtils.delete(path)
val intent = Intent(Intent.ACTION_SEND) val file = FileUtils.createFileWithReplace(path)
val file = FileUtils.createFileWithReplace(tmpSharePath)
file.writeText(GSON.toJson(sources)) file.writeText(GSON.toJson(sources))
val fileUri = FileProvider.getUriForFile(context, AppConst.authority, file) file
intent.type = "text/*"
intent.putExtra(Intent.EXTRA_STREAM, fileUri)
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent
}.onSuccess { }.onSuccess {
success.invoke(it) success.invoke(it)
}.onError { }.onError {

@ -177,6 +177,21 @@ fun Context.share(text: String, title: String = getString(R.string.share)) {
} }
} }
fun Context.share(file: File, type: String = "text/*") {
val fileUri = FileProvider.getUriForFile(this, AppConst.authority, file)
val intent = Intent(Intent.ACTION_SEND)
intent.type = type
intent.putExtra(Intent.EXTRA_STREAM, fileUri)
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(
Intent.createChooser(
intent,
getString(R.string.share_selected_source)
)
)
}
@SuppressLint("SetWorldReadable") @SuppressLint("SetWorldReadable")
fun Context.shareWithQr( fun Context.shareWithQr(
text: String, text: String,

Loading…
Cancel
Save