fix deleting downloads

This commit is contained in:
Bnyro 2022-09-26 19:00:33 +02:00
parent 03701818da
commit c3b2f5baee
2 changed files with 13 additions and 9 deletions

View File

@ -11,6 +11,7 @@ import com.github.libretube.databinding.DownloadedMediaRowBinding
import com.github.libretube.obj.DownloadedFile import com.github.libretube.obj.DownloadedFile
import com.github.libretube.ui.activities.OfflinePlayerActivity import com.github.libretube.ui.activities.OfflinePlayerActivity
import com.github.libretube.ui.viewholders.DownloadsViewHolder import com.github.libretube.ui.viewholders.DownloadsViewHolder
import com.github.libretube.util.DownloadHelper
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.io.File import java.io.File
@ -49,15 +50,19 @@ class DownloadsAdapter(
) { _, index -> ) { _, index ->
when (index) { when (index) {
0 -> { 0 -> {
val downloadDir = File( val audioDir = DownloadHelper.getAudioDir(root.context)
root.context.getExternalFilesDir(null), val videoDir = DownloadHelper.getVideoDir(root.context)
"video"
)
File( listOf(audioDir, videoDir).forEach {
downloadDir, val f = File(it, file.name)
file.name if (f.exists()) {
).delete() try {
f.delete()
} catch (e: Exception) {
e.printStackTrace()
}
}
}
files.removeAt(position) files.removeAt(position)
notifyItemRemoved(position) notifyItemRemoved(position)

View File

@ -9,7 +9,6 @@ import com.github.libretube.R
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.ui.activities.SettingsActivity import com.github.libretube.ui.activities.SettingsActivity
import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.ui.base.BasePreferenceFragment
import com.github.libretube.ui.dialogs.NavBarOptionsDialog
import com.github.libretube.ui.dialogs.RequireRestartDialog import com.github.libretube.ui.dialogs.RequireRestartDialog
import com.github.libretube.util.LocaleHelper import com.github.libretube.util.LocaleHelper
import com.github.libretube.util.PreferenceHelper import com.github.libretube.util.PreferenceHelper