Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Picasso with Coil #337

Merged
merged 7 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/src/main/kotlin/com/github/gotify/CoilHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ internal class CoilHandler(private val context: Context, private val settings: S
fun get() = imageLoader

@OptIn(ExperimentalCoilApi::class)
@Throws(IOException::class)
fun evict() {
imageLoader.diskCache?.directory?.toFile()?.deleteRecursively()
try {
imageLoader.diskCache?.clear()
imageLoader.memoryCache?.clear()
} catch (e: IOException) {
Logger.error(e, "Problem evicting Coil cache")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.navigation.NavigationView
import com.google.android.material.snackbar.BaseTransientBottomBar.BaseCallback
import com.google.android.material.snackbar.Snackbar
import java.io.IOException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.tinylog.kotlin.Logger
Expand Down Expand Up @@ -170,19 +169,20 @@ internal class MessagesActivity :
}

private fun refreshAll() {
try {
viewModel.coilHandler.evict()
} catch (e: IOException) {
Logger.error(e, "Problem evicting Coil cache")
}
viewModel.coilHandler.evict()
startActivity(Intent(this, InitializationActivity::class.java))
finish()
}

private fun onRefresh() {
viewModel.coilHandler.evict()
viewModel.messages.clear()
launchCoroutine {
loadMore(viewModel.appId)
loadMore(viewModel.appId).forEachIndexed { index, message ->
if (message.image != null) {
listMessageAdapter.notifyItemChanged(index)
}
}
jmattheis marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -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)
withContext(Dispatchers.Main) {
updateMessagesAndStopLoading(messagesWithImages)
}
return messagesWithImages
}

private suspend fun updateMessagesForApplication(withLoadingSpinner: Boolean, appId: Long) {
Expand Down
Loading