mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Replace the download complete context based receiver for Android 14
This commit is contained in:
parent
9df11a9302
commit
76ea0c32b5
3 changed files with 32 additions and 31 deletions
|
@ -155,6 +155,13 @@
|
|||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver android:name=".util.DownloadCompleteReceiver"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver android:name=".util.NotifyDismissReceiver" android:exported="false" />
|
||||
<receiver android:name=".util.NotifySaveReceiver" android:exported="false" />
|
||||
<receiver android:name=".util.NotifyMarkreadReceiver" android:exported="false" />
|
||||
|
|
|
@ -1,22 +1,18 @@
|
|||
package com.newsblur.activity
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.DownloadManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.webkit.MimeTypeMap
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.newsblur.R
|
||||
import com.newsblur.databinding.ActivityImportExportBinding
|
||||
import com.newsblur.network.APIManager
|
||||
import com.newsblur.service.NBSyncService
|
||||
import com.newsblur.util.DownloadCompleteReceiver
|
||||
import com.newsblur.util.FeedUtils
|
||||
import com.newsblur.util.FileDownloader
|
||||
import com.newsblur.util.NBScope
|
||||
|
@ -38,28 +34,12 @@ class ImportExportActivity : NbActivity() {
|
|||
|
||||
private lateinit var binding: ActivityImportExportBinding
|
||||
|
||||
private var fileDownloaderId: Long? = null
|
||||
|
||||
private val filePickResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
handleFilePickResult(result.data)
|
||||
}
|
||||
}
|
||||
|
||||
private val onOpmlExportReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (intent?.action == DownloadManager.ACTION_DOWNLOAD_COMPLETE) {
|
||||
val id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1L)
|
||||
if (id == fileDownloaderId) {
|
||||
context?.let {
|
||||
val msg = "${it.getString(R.string.newsblur_opml)} download completed"
|
||||
Toast.makeText(it, msg, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityImportExportBinding.inflate(layoutInflater)
|
||||
|
@ -67,10 +47,6 @@ class ImportExportActivity : NbActivity() {
|
|||
|
||||
setupUI()
|
||||
setupListeners()
|
||||
|
||||
ContextCompat.registerReceiver(this, onOpmlExportReceiver, IntentFilter().apply {
|
||||
addAction(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
|
||||
}, ContextCompat.RECEIVER_EXPORTED)
|
||||
}
|
||||
|
||||
private fun setupUI() {
|
||||
|
@ -93,7 +69,7 @@ class ImportExportActivity : NbActivity() {
|
|||
}
|
||||
|
||||
private fun exportOpmlFile() {
|
||||
fileDownloaderId = FileDownloader.exportOpml(this)
|
||||
DownloadCompleteReceiver.expectedFileDownloadId = FileDownloader.exportOpml(this)
|
||||
val msg = "${getString(R.string.newsblur_opml)} download started"
|
||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
@ -155,9 +131,4 @@ class ImportExportActivity : NbActivity() {
|
|||
override fun handleUpdate(updateType: Int) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
unregisterReceiver(onOpmlExportReceiver)
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
|
@ -1,9 +1,12 @@
|
|||
package com.newsblur.util
|
||||
|
||||
import android.app.DownloadManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Environment
|
||||
import android.webkit.MimeTypeMap
|
||||
import android.widget.Toast
|
||||
import androidx.core.net.toUri
|
||||
import com.newsblur.R
|
||||
import com.newsblur.network.APIConstants
|
||||
|
@ -30,4 +33,24 @@ object FileDownloader {
|
|||
.setTitle(context.getString(R.string.newsblur_opml))
|
||||
return manager.enqueue(request)
|
||||
}
|
||||
}
|
||||
|
||||
class DownloadCompleteReceiver : BroadcastReceiver() {
|
||||
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (intent?.action == DownloadManager.ACTION_DOWNLOAD_COMPLETE) {
|
||||
val id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1L)
|
||||
if (id == expectedFileDownloadId) {
|
||||
context?.let {
|
||||
val msg = "${it.getString(R.string.newsblur_opml)} download completed"
|
||||
Toast.makeText(it, msg, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
var expectedFileDownloadId: Long? = null
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue