DownloadFragment: Bring back force clear all menu action

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-02-16 17:59:28 +05:30
parent 2e19eac1c4
commit b3f991b8d7
5 changed files with 19 additions and 1 deletions

View File

@@ -24,4 +24,7 @@ interface DownloadDao {
@Query("DELETE FROM download WHERE packageName = :packageName")
suspend fun delete(packageName: String)
@Query("DELETE FROM download")
suspend fun deleteAll()
}

View File

@@ -15,6 +15,7 @@ import com.aurora.store.data.room.download.DownloadDao
import com.aurora.store.data.work.DownloadWorker
import com.google.gson.Gson
import dagger.hilt.android.qualifiers.ApplicationContext
import java.io.File
import javax.inject.Inject
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
@@ -94,6 +95,12 @@ class DownloadWorkerUtil @Inject constructor(
.deleteRecursively()
}
suspend fun clearAllDownloads() {
Log.i(TAG, "Clearing all downloads!")
downloadDao.deleteAll()
File(PathUtil.getDownloadDirectory(context), "Downloads").deleteRecursively()
}
suspend fun clearFinishedDownloads() {
downloadsList.value.filter { it.isFinished }.forEach {
clearDownload(it.packageName, it.versionCode)

View File

@@ -34,7 +34,7 @@ object PathUtil {
private const val libraries = "libraries"
private fun getDownloadDirectory(context: Context): String {
fun getDownloadDirectory(context: Context): String {
return if (context.isExternalStorageEnable()) {
getExternalPath(context)
} else {

View File

@@ -67,6 +67,11 @@ class DownloadFragment : BaseFragment(R.layout.fragment_download) {
setNavigationOnClickListener { findNavController().navigateUp() }
setOnMenuItemClickListener {
when (it.itemId) {
R.id.action_force_clear_all -> {
viewLifecycleOwner.lifecycleScope.launch(NonCancellable) {
downloadWorkerUtil.clearAllDownloads()
}
}
R.id.action_cancel_all -> {
viewLifecycleOwner.lifecycleScope.launch(NonCancellable) {
downloadWorkerUtil.cancelAll()