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.IntentFilter
import android.net.Uri
import android.os.Build
import android.os.Environment
import androidx.core.app.NotificationCompat
import io.legado.app.R
import io.legado.app.base.BaseService
import io.legado.app.constant.AppConst
import io.legado.app.constant.IntentAction
import io.legado.app.utils.IntentType
import io.legado.app.utils.msg
import io.legado.app.utils.openFileUri
import io.legado.app.utils.servicePendingIntent
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.Job
@ -172,20 +170,7 @@ class DownloadService : BaseService() {
private fun openDownload(downloadId: Long) {
downloadManager.getUriForDownloadedFile(downloadId)?.let { uri ->
//调用系统安装apk
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)
}
openFileUri(uri)
}
}

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

@ -15,6 +15,7 @@ import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.BatteryManager
import android.os.Build
import android.provider.Settings
import android.widget.Toast
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
get() {
try {

Loading…
Cancel
Save