added sorting by file size in history

pull/48/head^2
deniscerri 3 years ago
parent 075dcf874d
commit 3d493e4e58
No known key found for this signature in database
GPG Key ID: 95C43D517D830350

@ -12,7 +12,7 @@ class HistoryRepository(private val historyDao: HistoryDao) {
}
enum class HistorySortType {
DATE, TITLE, AUTHOR
DATE, TITLE, AUTHOR, FILESIZE
}
suspend fun getItem(id: Int) : HistoryItem {
@ -24,6 +24,13 @@ class HistoryRepository(private val historyDao: HistoryDao) {
HistorySortType.DATE -> historyDao.getHistorySortedByID(query, format, site, sort.toString())
HistorySortType.TITLE -> historyDao.getHistorySortedByTitle(query, format, site, sort.toString())
HistorySortType.AUTHOR -> historyDao.getHistorySortedByAuthor(query, format, site, sort.toString())
HistorySortType.FILESIZE -> {
val items = historyDao.getHistorySortedByID(query, format, site, sort.toString())
when(sort){
HistorySort.DESC -> items.sortedByDescending { it.format.filesize }
HistorySort.ASC -> items.sortedBy { it.format.filesize }
}
}
}
}

@ -25,6 +25,7 @@ import com.deniscerri.ytdlnis.database.viewmodel.DownloadViewModel
import com.deniscerri.ytdlnis.database.viewmodel.ResultViewModel
import com.deniscerri.ytdlnis.receiver.ShareActivity
import com.deniscerri.ytdlnis.util.FileUtil
import com.deniscerri.ytdlnis.util.UiUtil
import com.google.android.material.bottomappbar.BottomAppBar
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
@ -49,6 +50,7 @@ class DownloadMultipleBottomSheetDialog(private var items: MutableList<DownloadI
private lateinit var recyclerView: RecyclerView
private lateinit var behavior: BottomSheetBehavior<View>
private lateinit var fileUtil: FileUtil
private lateinit var uiUtil: UiUtil
override fun onCreate(savedInstanceState: Bundle?) {
@ -57,6 +59,7 @@ class DownloadMultipleBottomSheetDialog(private var items: MutableList<DownloadI
resultViewModel = ViewModelProvider(this)[ResultViewModel::class.java]
commandTemplateViewModel = ViewModelProvider(this)[CommandTemplateViewModel::class.java]
fileUtil = FileUtil()
uiUtil = UiUtil(fileUtil)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -70,7 +73,6 @@ class DownloadMultipleBottomSheetDialog(private var items: MutableList<DownloadI
super.setupDialog(dialog, style)
val view = LayoutInflater.from(context).inflate(R.layout.download_multiple_bottom_sheet, null)
dialog.setContentView(view)
//view.minimumHeight = resources.displayMetrics.heightPixels
dialog.setOnShowListener {
behavior = BottomSheetBehavior.from(view.parent as View)
@ -92,44 +94,13 @@ class DownloadMultipleBottomSheetDialog(private var items: MutableList<DownloadI
val scheduleBtn = view.findViewById<MaterialButton>(R.id.bottomsheet_schedule_button)
scheduleBtn.setOnClickListener{
val currentDate = Calendar.getInstance()
val date = Calendar.getInstance()
val datepicker = MaterialDatePicker.Builder.datePicker()
.setCalendarConstraints(
CalendarConstraints.Builder()
.setValidator(DateValidatorPointForward.now())
.build()
)
.setSelection(MaterialDatePicker.todayInUtcMilliseconds())
.build()
datepicker.addOnPositiveButtonClickListener{
date.timeInMillis = it
val timepicker = MaterialTimePicker.Builder()
.setTimeFormat(TimeFormat.CLOCK_24H)
.setHour(currentDate.get(Calendar.HOUR_OF_DAY))
.setMinute(currentDate.get(Calendar.MINUTE))
.build()
timepicker.addOnPositiveButtonClickListener{
date[Calendar.HOUR_OF_DAY] = timepicker.hour
date[Calendar.MINUTE] = timepicker.minute
items.forEach { item ->
item.downloadStartTime = date.timeInMillis
}
downloadViewModel.queueDownloads(items)
dismiss()
uiUtil.showDatePicker(parentFragmentManager) {
items.forEach { item ->
item.downloadStartTime = it.timeInMillis
}
timepicker.show(parentFragmentManager, "timepicker")
downloadViewModel.queueDownloads(items)
dismiss()
}
datepicker.show(parentFragmentManager, "datepicker")
}
val download = view.findViewById<Button>(R.id.bottomsheet_download_button)

@ -240,12 +240,15 @@ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{
}
}
private fun changeSortIcon(item: LinearLayout, order: HistorySort){
private fun changeSortIcon(item: TextView, order: HistorySort){
when(order){
HistorySort.DESC -> (item.getChildAt(0) as ImageView).setImageResource(R.drawable.ic_up)
HistorySort.ASC -> (item.getChildAt(0) as ImageView).setImageResource(R.drawable.ic_down)
HistorySort.DESC ->{
item.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_up, 0,0,0)
}
HistorySort.ASC -> {
item.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_down, 0,0,0)
}
}
item.getChildAt(0).visibility = VISIBLE
}
@ -256,33 +259,40 @@ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{
sortSheet!!.requestWindowFeature(Window.FEATURE_NO_TITLE)
sortSheet!!.setContentView(R.layout.history_sort_sheet)
val date = sortSheet!!.findViewById<LinearLayout>(R.id.date)
val title = sortSheet!!.findViewById<LinearLayout>(R.id.title)
val author = sortSheet!!.findViewById<LinearLayout>(R.id.author)
val date = sortSheet!!.findViewById<TextView>(R.id.date)
val title = sortSheet!!.findViewById<TextView>(R.id.title)
val author = sortSheet!!.findViewById<TextView>(R.id.author)
val filesize = sortSheet!!.findViewById<TextView>(R.id.filesize)
val sortOptions = listOf(date!!, title!!, author!!)
sortOptions.forEach { it.getChildAt(0).visibility = INVISIBLE }
val sortOptions = listOf(date!!, title!!, author!!, filesize!!)
sortOptions.forEach { it.setCompoundDrawablesWithIntrinsicBounds(R.drawable.empty,0,0,0) }
when(historyViewModel.sortType.value!!) {
HistoryRepository.HistorySortType.DATE -> changeSortIcon(date, historyViewModel.sortOrder.value!!)
HistoryRepository.HistorySortType.TITLE -> changeSortIcon(title, historyViewModel.sortOrder.value!!)
HistoryRepository.HistorySortType.AUTHOR -> changeSortIcon(author, historyViewModel.sortOrder.value!!)
HistoryRepository.HistorySortType.FILESIZE -> changeSortIcon(filesize, historyViewModel.sortOrder.value!!)
}
date.getChildAt(1).setOnClickListener {
sortOptions.forEach { it.getChildAt(0).visibility = INVISIBLE }
date.setOnClickListener {
sortOptions.forEach { it.setCompoundDrawablesWithIntrinsicBounds(R.drawable.empty,0,0,0) }
historyViewModel.setSorting(HistoryRepository.HistorySortType.DATE)
changeSortIcon(date, historyViewModel.sortOrder.value!!)
}
title.getChildAt(1).setOnClickListener {
sortOptions.forEach { it.getChildAt(0).visibility = INVISIBLE }
title.setOnClickListener {
sortOptions.forEach { it.setCompoundDrawablesWithIntrinsicBounds(R.drawable.empty,0,0,0) }
historyViewModel.setSorting(HistoryRepository.HistorySortType.TITLE)
changeSortIcon(title, historyViewModel.sortOrder.value!!)
}
author.getChildAt(1).setOnClickListener {
sortOptions.forEach { it.getChildAt(0).visibility = INVISIBLE }
author.setOnClickListener {
sortOptions.forEach { it.setCompoundDrawablesWithIntrinsicBounds(R.drawable.empty,0,0,0) }
historyViewModel.setSorting(HistoryRepository.HistorySortType.AUTHOR)
changeSortIcon(author, historyViewModel.sortOrder.value!!)
}
filesize.setOnClickListener {
sortOptions.forEach { it.setCompoundDrawablesWithIntrinsicBounds(R.drawable.empty,0,0,0) }
historyViewModel.setSorting(HistoryRepository.HistorySortType.FILESIZE)
changeSortIcon(filesize, historyViewModel.sortOrder.value!!)
}
sortSheet!!.show()
}

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:strokeAlpha="0" android:pathData="M0,12h24"/>
</vector>

@ -21,70 +21,60 @@
android:paddingBottom="20dp"
android:layout_height="wrap_content"/>
<LinearLayout
<TextView
android:id="@+id/date"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground"
android:paddingVertical="10dp"
android:drawablePadding="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:paddingEnd="20dp"
android:src="@drawable/ic_up"/>
android:textSize="15sp"
android:text="@string/date_added"
app:drawableLeftCompat="@drawable/ic_arrow_up" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:text="@string/date_added" />
</LinearLayout>
<LinearLayout
<TextView
android:id="@+id/title"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground"
android:paddingVertical="10dp"
android:drawablePadding="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:orientation="horizontal">
<ImageView
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:paddingEnd="20dp"
android:src="@drawable/ic_up"/>
android:textSize="15sp"
android:text="@string/title"
app:drawableLeftCompat="@drawable/ic_arrow_up" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:text="@string/title" />
</LinearLayout>
<LinearLayout
<TextView
android:id="@+id/author"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground"
android:paddingVertical="10dp"
android:drawablePadding="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:orientation="horizontal">
<ImageView
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:paddingEnd="20dp"
android:src="@drawable/ic_up"/>
android:textSize="15sp"
android:text="@string/author"
app:drawableLeftCompat="@drawable/ic_arrow_up" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:text="@string/author" />
</LinearLayout>
<TextView
android:id="@+id/filesize"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground"
android:drawablePadding="30dp"
android:paddingVertical="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:text="@string/file_size"
app:drawableLeftCompat="@drawable/ic_arrow_up" />

@ -220,4 +220,5 @@
<string name="workmanager_updated">You need to restart the app and have no active downloads for this preference to take effect!</string>
<string name="restart">Restart</string>
<string name="download_rescheduled_to">Download rescheduled to:</string>
<string name="file_size">File size</string>
</resources>
Loading…
Cancel
Save