1
0
mirror of https://github.com/libre-tube/LibreTube.git synced 2024-12-15 14:50:30 +05:30

Convert delete download dialog to confirmation dialog

This commit is contained in:
Bnyro 2023-02-07 19:31:43 +01:00
parent 74ebd2f4f3
commit b5e7aeb5cd
5 changed files with 20 additions and 27 deletions
app/src/main/java/com/github/libretube

View File

@ -8,9 +8,9 @@ import android.os.Binder
import android.os.IBinder import android.os.IBinder
import android.util.SparseBooleanArray import android.util.SparseBooleanArray
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.app.ServiceCompat
import androidx.core.util.set import androidx.core.util.set
import androidx.core.util.valueIterator import androidx.core.util.valueIterator
import androidx.core.app.ServiceCompat
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.api.CronetHelper import com.github.libretube.api.CronetHelper
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance

View File

@ -91,29 +91,23 @@ class DownloadsAdapter(
root.setOnLongClickListener { root.setOnLongClickListener {
MaterialAlertDialogBuilder(root.context) MaterialAlertDialogBuilder(root.context)
.setItems( .setTitle(R.string.delete)
arrayOf( .setMessage(R.string.irreversible)
root.context.getString(R.string.delete) .setPositiveButton(R.string.okay) { _, _ ->
) items.map { File(it.path) }.forEach { file ->
) { _, index -> if (file.exists()) {
when (index) { try {
0 -> { file.delete()
items.map { File(it.path) }.forEach { file -> } catch (_: Exception) { }
if (file.exists()) {
try {
file.delete()
} catch (_: Exception) { }
}
}
query {
DatabaseHolder.Database.downloadDao().deleteDownload(download)
}
downloads.removeAt(position)
notifyItemRemoved(position)
notifyItemRangeChanged(position, itemCount)
} }
} }
query {
DatabaseHolder.Database.downloadDao().deleteDownload(download)
}
downloads.removeAt(position)
notifyItemRemoved(position)
notifyItemRangeChanged(position, itemCount)
} }
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show() .show()

View File

@ -9,7 +9,6 @@ import android.os.IBinder
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.view.size
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -109,7 +108,7 @@ class DownloadsFragment : BaseFragment() {
binding.downloads.adapter?.registerAdapterDataObserver( binding.downloads.adapter?.registerAdapterDataObserver(
object : RecyclerView.AdapterDataObserver() { object : RecyclerView.AdapterDataObserver() {
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) { override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
if (binding.downloads.size == 0) { if (itemCount == 0) {
binding.downloads.visibility = View.GONE binding.downloads.visibility = View.GONE
binding.downloadsEmpty.visibility = View.VISIBLE binding.downloadsEmpty.visibility = View.VISIBLE
} }

View File

@ -19,9 +19,9 @@ import com.github.libretube.extensions.hideKeyboard
import com.github.libretube.helpers.PreferenceHelper import com.github.libretube.helpers.PreferenceHelper
import com.github.libretube.ui.adapters.SearchAdapter import com.github.libretube.ui.adapters.SearchAdapter
import com.github.libretube.ui.base.BaseFragment import com.github.libretube.ui.base.BaseFragment
import java.io.IOException
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.io.IOException
import retrofit2.HttpException import retrofit2.HttpException
class SearchResultFragment : BaseFragment() { class SearchResultFragment : BaseFragment() {

View File

@ -11,10 +11,10 @@ import com.github.libretube.helpers.ImportHelper
import com.github.libretube.obj.BackupFile import com.github.libretube.obj.BackupFile
import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.ui.base.BasePreferenceFragment
import com.github.libretube.ui.dialogs.BackupDialog import com.github.libretube.ui.dialogs.BackupDialog
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.time.LocalDateTime import java.time.LocalDateTime
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class BackupRestoreSettings : BasePreferenceFragment() { class BackupRestoreSettings : BasePreferenceFragment() {
private val backupDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH:mm:ss") private val backupDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH:mm:ss")