pull/1395/head
gedoor 3 years ago
parent 82b442f229
commit 7b7bb0a97e
  1. 19
      app/src/main/java/io/legado/app/service/DownloadService.kt
  2. 3
      app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt
  3. 17
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt

@ -6,15 +6,13 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.Environment import android.os.Environment
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseService import io.legado.app.base.BaseService
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.IntentAction import io.legado.app.constant.IntentAction
import io.legado.app.utils.IntentType import io.legado.app.utils.openFileUri
import io.legado.app.utils.msg
import io.legado.app.utils.servicePendingIntent import io.legado.app.utils.servicePendingIntent
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
@ -172,20 +170,7 @@ class DownloadService : BaseService() {
private fun openDownload(downloadId: Long) { private fun openDownload(downloadId: Long) {
downloadManager.getUriForDownloadedFile(downloadId)?.let { uri -> downloadManager.getUriForDownloadedFile(downloadId)?.let { uri ->
//调用系统安装apk openFileUri(uri)
val intent = Intent()
intent.action = Intent.ACTION_VIEW
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//7.0版本以上
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
intent.setDataAndType(uri, IntentType.from(uri))
try {
startActivity(intent)
} catch (e: Exception) {
toastOnUi(e.msg)
}
} }
} }

@ -1,5 +1,6 @@
package io.legado.app.ui.book.local package io.legado.app.ui.book.local
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri
import android.view.ViewGroup import android.view.ViewGroup
@ -79,6 +80,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
} }
} }
@SuppressLint("NotifyDataSetChanged")
fun upBookHas(bookUrls: List<String>) { fun upBookHas(bookUrls: List<String>) {
bookFileNames.clear() bookFileNames.clear()
bookUrls.forEach { bookUrls.forEach {
@ -99,6 +101,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
callBack.upCountView() callBack.upCountView()
} }
@SuppressLint("NotifyDataSetChanged")
fun selectAll(selectAll: Boolean) { fun selectAll(selectAll: Boolean) {
if (selectAll) { if (selectAll) {
getItems().forEach { getItems().forEach {

@ -15,6 +15,7 @@ import android.graphics.Bitmap
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.net.Uri import android.net.Uri
import android.os.BatteryManager import android.os.BatteryManager
import android.os.Build
import android.provider.Settings import android.provider.Settings
import android.widget.Toast import android.widget.Toast
import androidx.annotation.ColorRes import androidx.annotation.ColorRes
@ -292,6 +293,22 @@ fun Context.openUrl(uri: Uri) {
} }
} }
fun Context.openFileUri(uri: Uri) {
val intent = Intent()
intent.action = Intent.ACTION_VIEW
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//7.0版本以上
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
intent.setDataAndType(uri, IntentType.from(uri))
try {
startActivity(intent)
} catch (e: Exception) {
toastOnUi(e.msg)
}
}
val Context.channel: String val Context.channel: String
get() { get() {
try { try {

Loading…
Cancel
Save