pull/517/head
gedoor 4 years ago
parent 8c9ef11fcc
commit a4c4edfe83
  1. 28
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  2. 26
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt
  3. 4
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt

@ -2,7 +2,6 @@ package io.legado.app.ui.book.source.manage
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
@ -10,7 +9,6 @@ import android.view.MenuItem
import android.view.SubMenu import android.view.SubMenu
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.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
@ -18,7 +16,6 @@ import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import io.legado.app.App import io.legado.app.App
import io.legado.app.BuildConfig
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.AppPattern import io.legado.app.constant.AppPattern
@ -99,30 +96,7 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
when (item.itemId) { when (item.itemId) {
R.id.menu_add_book_source -> startActivity<BookSourceEditActivity>() R.id.menu_add_book_source -> startActivity<BookSourceEditActivity>()
R.id.menu_import_source_qr -> startActivityForResult<QrCodeActivity>(qrRequestCode) R.id.menu_import_source_qr -> startActivityForResult<QrCodeActivity>(qrRequestCode)
R.id.menu_share_source -> { R.id.menu_share_source -> viewModel.shareSelection(adapter.getSelection())
try {
val json = GSON.toJson(adapter.getSelection())
val intent = Intent(Intent.ACTION_SEND)
val file = FileUtils.createFileWithReplace("$filesDir/shareBookSource.json")
file.writeText(json)
val fileUri = FileProvider.getUriForFile(
this,
BuildConfig.APPLICATION_ID + ".fileProvider",
file
)
intent.type = "text/*"
intent.putExtra(Intent.EXTRA_STREAM, fileUri)
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
startActivity(
Intent.createChooser(
intent,
getString(R.string.share_selected_source)
)
)
} catch (e: ActivityNotFoundException) {
e.printStackTrace()
}
}
R.id.menu_group_manage -> R.id.menu_group_manage ->
GroupManageDialog().show(supportFragmentManager, "groupManage") GroupManageDialog().show(supportFragmentManager, "groupManage")
R.id.menu_import_source_local -> FilePicker R.id.menu_import_source_local -> FilePicker

@ -1,9 +1,13 @@
package io.legado.app.ui.book.source.manage package io.legado.app.ui.book.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 androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import io.legado.app.App import io.legado.app.App
import io.legado.app.BuildConfig
import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
@ -163,6 +167,28 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun shareSelection(sources: List<BookSource>) {
execute {
val intent = Intent(Intent.ACTION_SEND)
val file = FileUtils.createFileWithReplace("${context.filesDir}/shareBookSource.json")
file.writeText(GSON.toJson(sources))
val fileUri = FileProvider.getUriForFile(
context,
BuildConfig.APPLICATION_ID + ".fileProvider",
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 {
context.startActivity(
Intent.createChooser(it, context.getString(R.string.share_selected_source))
)
}
}
fun addGroup(group: String) { fun addGroup(group: String) {
execute { execute {
val sources = App.db.bookSourceDao().noGroup val sources = App.db.bookSourceDao().noGroup

@ -126,7 +126,7 @@ fun Context.shareWithQr(title: String, text: String) {
file file
) )
val intent = Intent(Intent.ACTION_SEND) val intent = Intent(Intent.ACTION_SEND)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.putExtra(Intent.EXTRA_STREAM, contentUri) intent.putExtra(Intent.EXTRA_STREAM, contentUri)
intent.type = "image/png" intent.type = "image/png"
startActivity(Intent.createChooser(intent, title)) startActivity(Intent.createChooser(intent, title))
@ -160,6 +160,7 @@ fun Context.sendMail(mail: String) {
try { try {
val intent = Intent(Intent.ACTION_SENDTO) val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("mailto:$mail") intent.data = Uri.parse("mailto:$mail")
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent) startActivity(intent)
} catch (e: Exception) { } catch (e: Exception) {
toast(e.localizedMessage ?: "Error") toast(e.localizedMessage ?: "Error")
@ -197,6 +198,7 @@ fun Context.openUrl(url: String) {
fun Context.openUrl(uri: Uri) { fun Context.openUrl(uri: Uri) {
val intent = Intent(Intent.ACTION_VIEW) val intent = Intent(Intent.ACTION_VIEW)
intent.data = uri intent.data = uri
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
if (intent.resolveActivity(packageManager) != null) { if (intent.resolveActivity(packageManager) != null) {
try { try {
startActivity(intent) startActivity(intent)

Loading…
Cancel
Save