Clear and refresh image caches on swipe down
This commit is contained in:
@@ -56,8 +56,12 @@ internal class CoilHandler(private val context: Context, private val settings: S
|
|||||||
fun get() = imageLoader
|
fun get() = imageLoader
|
||||||
|
|
||||||
@OptIn(ExperimentalCoilApi::class)
|
@OptIn(ExperimentalCoilApi::class)
|
||||||
@Throws(IOException::class)
|
|
||||||
fun evict() {
|
fun evict() {
|
||||||
imageLoader.diskCache?.directory?.toFile()?.deleteRecursively()
|
try {
|
||||||
|
imageLoader.diskCache?.clear()
|
||||||
|
imageLoader.memoryCache?.clear()
|
||||||
|
} catch (e: IOException) {
|
||||||
|
Logger.error(e, "Problem evicting Coil cache")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|||||||
import com.google.android.material.navigation.NavigationView
|
import com.google.android.material.navigation.NavigationView
|
||||||
import com.google.android.material.snackbar.BaseTransientBottomBar.BaseCallback
|
import com.google.android.material.snackbar.BaseTransientBottomBar.BaseCallback
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import java.io.IOException
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.tinylog.kotlin.Logger
|
import org.tinylog.kotlin.Logger
|
||||||
@@ -170,19 +169,20 @@ internal class MessagesActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshAll() {
|
private fun refreshAll() {
|
||||||
try {
|
|
||||||
viewModel.coilHandler.evict()
|
viewModel.coilHandler.evict()
|
||||||
} catch (e: IOException) {
|
|
||||||
Logger.error(e, "Problem evicting Coil cache")
|
|
||||||
}
|
|
||||||
startActivity(Intent(this, InitializationActivity::class.java))
|
startActivity(Intent(this, InitializationActivity::class.java))
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onRefresh() {
|
private fun onRefresh() {
|
||||||
|
viewModel.coilHandler.evict()
|
||||||
viewModel.messages.clear()
|
viewModel.messages.clear()
|
||||||
launchCoroutine {
|
launchCoroutine {
|
||||||
loadMore(viewModel.appId)
|
loadMore(viewModel.appId).forEachIndexed { index, message ->
|
||||||
|
if (message.image != null) {
|
||||||
|
listMessageAdapter.notifyItemChanged(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,11 +556,12 @@ internal class MessagesActivity :
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun loadMore(appId: Long) {
|
private suspend fun loadMore(appId: Long): List<MessageWithImage> {
|
||||||
val messagesWithImages = viewModel.messages.loadMore(appId)
|
val messagesWithImages = viewModel.messages.loadMore(appId)
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
updateMessagesAndStopLoading(messagesWithImages)
|
updateMessagesAndStopLoading(messagesWithImages)
|
||||||
}
|
}
|
||||||
|
return messagesWithImages
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun updateMessagesForApplication(withLoadingSpinner: Boolean, appId: Long) {
|
private suspend fun updateMessagesForApplication(withLoadingSpinner: Boolean, appId: Long) {
|
||||||
|
|||||||
Reference in New Issue
Block a user