add reverse toggle for multiple download card

This commit is contained in:
deniscerri 2025-07-27 21:39:16 +02:00
parent 3d4e9b6df8
commit f723a549d4
No known key found for this signature in database
GPG key ID: 95C43D517D830350
6 changed files with 53 additions and 0 deletions

View file

@ -356,6 +356,17 @@ interface DownloadDao {
}
}
@Transaction
suspend fun reverseProcessingDownloads() {
val items = getProcessingDownloadsList()
val newIDs = items.reversed().map { it.id }
items.forEach { updateDownloadID(it.id, -(it.id)) }
items.forEachIndexed { idx, it ->
updateDownloadID(-(it.id), newIDs[idx])
}
}
@Query("Update downloads set id=:newId where id=:id")
suspend fun updateDownloadID(id: Long, newId: Long)

View file

@ -144,6 +144,10 @@ class DownloadRepository(private val downloadDao: DownloadDao) {
return downloadDao.getProcessingDownloadsList()
}
suspend fun reverseProcessingDownloads() {
downloadDao.reverseProcessingDownloads()
}
fun getActiveAndQueuedDownloads() : List<DownloadItem> {
return downloadDao.getActiveAndQueuedDownloadsList()
}

View file

@ -127,6 +127,7 @@ class DownloadViewModel(private val application: Application) : AndroidViewModel
var processingItems = MutableStateFlow(false)
var processingItemsJob : Job? = null
var processingSort = MutableStateFlow("ASC")
init {
dbManager = DBManager.getInstance(application)
@ -619,6 +620,13 @@ class DownloadViewModel(private val application: Application) : AndroidViewModel
)
}
suspend fun toggleProcessingSort() : String {
processingItems.emit(true)
processingSort.value = if (processingSort.value == "ASC") "DESC" else "ASC"
repository.reverseProcessingDownloads()
processingItems.emit(false)
return processingSort.value
}
fun turnDownloadItemsToProcessingDownloads(itemIDs: List<Long>, deleteExisting : Boolean = false) = viewModelScope.launch(Dispatchers.IO){
val job = viewModelScope.launch(Dispatchers.IO) {

View file

@ -22,6 +22,7 @@ import android.widget.TextView
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
@ -38,6 +39,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.afollestad.materialdialogs.utils.MDUtil.getStringArray
import com.deniscerri.ytdl.R
import com.deniscerri.ytdl.database.DBManager.SORTING
import com.deniscerri.ytdl.database.models.CommandTemplate
import com.deniscerri.ytdl.database.models.DownloadItem
import com.deniscerri.ytdl.database.models.DownloadItemConfigureMultiple
@ -921,6 +923,22 @@ class DownloadMultipleBottomSheetDialog : BottomSheetDialogFragment(), Configure
updateBottomAppBarMenuItemsVisibility()
}
val sortBtn = view.findViewById<MaterialButton>(R.id.sortBtn)
sortBtn.setOnClickListener {
lifecycleScope.launch {
val newSort = withContext(Dispatchers.IO) {
downloadViewModel.toggleProcessingSort()
}
when(newSort) {
"ASC" -> sortBtn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_down)
"DESC" -> sortBtn.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_up)
}
recyclerView.scrollTo(0, 0)
}
}
}
override fun onResume() {

View file

@ -233,6 +233,7 @@ class WebViewActivity : BaseActivity() {
}
preferences.edit().putString("useragent_header", userAgentString).apply()
}
cookieManager.setAcceptCookie(true)
cookieManager.setAcceptThirdPartyCookies(this, true)
}
}

View file

@ -263,6 +263,17 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/sortBtn"
style="@style/Widget.Material3.Button.IconButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/sort_by"
app:icon="@drawable/ic_down"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/selectItemsMenu"
android:visibility="gone"