clean up old db queries and DownloadIconWorker
This commit is contained in:
parent
80cc011852
commit
fcce44bef1
3 changed files with 10 additions and 14 deletions
|
@ -383,9 +383,6 @@ interface NotificationDao {
|
||||||
@Query("SELECT DISTINCT icon_contentUri FROM notification WHERE deleted != 1 AND icon_contentUri <> ''")
|
@Query("SELECT DISTINCT icon_contentUri FROM notification WHERE deleted != 1 AND icon_contentUri <> ''")
|
||||||
fun listActiveIconUris(): List<String>
|
fun listActiveIconUris(): List<String>
|
||||||
|
|
||||||
@Query("SELECT DISTINCT icon_contentUri FROM notification WHERE deleted = 1 AND icon_contentUri <> ''")
|
|
||||||
fun listDeletedIconUris(): List<String>
|
|
||||||
|
|
||||||
@Query("UPDATE notification SET icon_contentUri = null WHERE icon_contentUri = :uri")
|
@Query("UPDATE notification SET icon_contentUri = null WHERE icon_contentUri = :uri")
|
||||||
fun clearIconUri(uri: String)
|
fun clearIconUri(uri: String)
|
||||||
|
|
||||||
|
|
|
@ -96,10 +96,6 @@ class Repository(private val sharedPrefs: SharedPreferences, private val databas
|
||||||
return notificationDao.listActiveIconUris().toSet()
|
return notificationDao.listActiveIconUris().toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDeletedIconUris(): Set<String> {
|
|
||||||
return notificationDao.listDeletedIconUris().toSet()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun clearIconUri(uri: String) {
|
fun clearIconUri(uri: String) {
|
||||||
notificationDao.clearIconUri(uri)
|
notificationDao.clearIconUri(uri)
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,14 +90,9 @@ class DownloadIconWorker(private val context: Context, params: WorkerParameters)
|
||||||
this.uri = uri // Required for cleanup in onStopped()
|
this.uri = uri // Required for cleanup in onStopped()
|
||||||
|
|
||||||
Log.d(TAG, "Starting download to content URI: $uri")
|
Log.d(TAG, "Starting download to content URI: $uri")
|
||||||
val contentLength = response.headers["Content-Length"]?.toLongOrNull()
|
|
||||||
var bytesCopied: Long = 0
|
var bytesCopied: Long = 0
|
||||||
val outFile = resolver.openOutputStream(uri) ?: throw Exception("Cannot open output stream")
|
val outFile = resolver.openOutputStream(uri) ?: throw Exception("Cannot open output stream")
|
||||||
val downloadLimit = if (repository.getAutoDownloadMaxSize() != Repository.AUTO_DOWNLOAD_NEVER && repository.getAutoDownloadMaxSize() != Repository.AUTO_DOWNLOAD_ALWAYS) {
|
val downloadLimit = getDownloadLimit()
|
||||||
repository.getAutoDownloadMaxSize()
|
|
||||||
} else {
|
|
||||||
MAX_ICON_DOWNLOAD_SIZE.toLong()
|
|
||||||
}
|
|
||||||
outFile.use { fileOut ->
|
outFile.use { fileOut ->
|
||||||
val fileIn = response.body!!.byteStream()
|
val fileIn = response.body!!.byteStream()
|
||||||
val buffer = ByteArray(BUFFER_SIZE)
|
val buffer = ByteArray(BUFFER_SIZE)
|
||||||
|
@ -144,11 +139,19 @@ class DownloadIconWorker(private val context: Context, params: WorkerParameters)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun shouldAbortDownload(response: Response): Boolean {
|
private fun shouldAbortDownload(response: Response): Boolean {
|
||||||
val maxAutoDownloadSize = MAX_ICON_DOWNLOAD_SIZE
|
val maxAutoDownloadSize = getDownloadLimit()
|
||||||
val size = response.headers["Content-Length"]?.toLongOrNull() ?: return false // Don't abort here if size unknown
|
val size = response.headers["Content-Length"]?.toLongOrNull() ?: return false // Don't abort here if size unknown
|
||||||
return size > maxAutoDownloadSize
|
return size > maxAutoDownloadSize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getDownloadLimit(): Long {
|
||||||
|
return if (repository.getAutoDownloadMaxSize() != Repository.AUTO_DOWNLOAD_NEVER && repository.getAutoDownloadMaxSize() != Repository.AUTO_DOWNLOAD_ALWAYS) {
|
||||||
|
repository.getAutoDownloadMaxSize()
|
||||||
|
} else {
|
||||||
|
MAX_ICON_DOWNLOAD_SIZE.toLong()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun createIconFile(icon: Icon): File {
|
private fun createIconFile(icon: Icon): File {
|
||||||
val iconDir = File(context.cacheDir, ICON_CACHE_DIR)
|
val iconDir = File(context.cacheDir, ICON_CACHE_DIR)
|
||||||
if (!iconDir.exists() && !iconDir.mkdirs()) {
|
if (!iconDir.exists() && !iconDir.mkdirs()) {
|
||||||
|
|
Loading…
Reference in a new issue