added sorting by file size in history
This commit is contained in:
parent
075dcf874d
commit
3d493e4e58
6 changed files with 89 additions and 102 deletions
|
|
@ -12,7 +12,7 @@ class HistoryRepository(private val historyDao: HistoryDao) {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class HistorySortType {
|
enum class HistorySortType {
|
||||||
DATE, TITLE, AUTHOR
|
DATE, TITLE, AUTHOR, FILESIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getItem(id: Int) : HistoryItem {
|
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.DATE -> historyDao.getHistorySortedByID(query, format, site, sort.toString())
|
||||||
HistorySortType.TITLE -> historyDao.getHistorySortedByTitle(query, format, site, sort.toString())
|
HistorySortType.TITLE -> historyDao.getHistorySortedByTitle(query, format, site, sort.toString())
|
||||||
HistorySortType.AUTHOR -> historyDao.getHistorySortedByAuthor(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.database.viewmodel.ResultViewModel
|
||||||
import com.deniscerri.ytdlnis.receiver.ShareActivity
|
import com.deniscerri.ytdlnis.receiver.ShareActivity
|
||||||
import com.deniscerri.ytdlnis.util.FileUtil
|
import com.deniscerri.ytdlnis.util.FileUtil
|
||||||
|
import com.deniscerri.ytdlnis.util.UiUtil
|
||||||
import com.google.android.material.bottomappbar.BottomAppBar
|
import com.google.android.material.bottomappbar.BottomAppBar
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
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 recyclerView: RecyclerView
|
||||||
private lateinit var behavior: BottomSheetBehavior<View>
|
private lateinit var behavior: BottomSheetBehavior<View>
|
||||||
private lateinit var fileUtil: FileUtil
|
private lateinit var fileUtil: FileUtil
|
||||||
|
private lateinit var uiUtil: UiUtil
|
||||||
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
|
@ -57,6 +59,7 @@ class DownloadMultipleBottomSheetDialog(private var items: MutableList<DownloadI
|
||||||
resultViewModel = ViewModelProvider(this)[ResultViewModel::class.java]
|
resultViewModel = ViewModelProvider(this)[ResultViewModel::class.java]
|
||||||
commandTemplateViewModel = ViewModelProvider(this)[CommandTemplateViewModel::class.java]
|
commandTemplateViewModel = ViewModelProvider(this)[CommandTemplateViewModel::class.java]
|
||||||
fileUtil = FileUtil()
|
fileUtil = FileUtil()
|
||||||
|
uiUtil = UiUtil(fileUtil)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
|
@ -70,7 +73,6 @@ class DownloadMultipleBottomSheetDialog(private var items: MutableList<DownloadI
|
||||||
super.setupDialog(dialog, style)
|
super.setupDialog(dialog, style)
|
||||||
val view = LayoutInflater.from(context).inflate(R.layout.download_multiple_bottom_sheet, null)
|
val view = LayoutInflater.from(context).inflate(R.layout.download_multiple_bottom_sheet, null)
|
||||||
dialog.setContentView(view)
|
dialog.setContentView(view)
|
||||||
//view.minimumHeight = resources.displayMetrics.heightPixels
|
|
||||||
|
|
||||||
dialog.setOnShowListener {
|
dialog.setOnShowListener {
|
||||||
behavior = BottomSheetBehavior.from(view.parent as View)
|
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)
|
val scheduleBtn = view.findViewById<MaterialButton>(R.id.bottomsheet_schedule_button)
|
||||||
scheduleBtn.setOnClickListener{
|
scheduleBtn.setOnClickListener{
|
||||||
val currentDate = Calendar.getInstance()
|
uiUtil.showDatePicker(parentFragmentManager) {
|
||||||
val date = Calendar.getInstance()
|
items.forEach { item ->
|
||||||
|
item.downloadStartTime = it.timeInMillis
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
timepicker.show(parentFragmentManager, "timepicker")
|
downloadViewModel.queueDownloads(items)
|
||||||
|
dismiss()
|
||||||
}
|
}
|
||||||
datepicker.show(parentFragmentManager, "datepicker")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val download = view.findViewById<Button>(R.id.bottomsheet_download_button)
|
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){
|
when(order){
|
||||||
HistorySort.DESC -> (item.getChildAt(0) as ImageView).setImageResource(R.drawable.ic_up)
|
HistorySort.DESC ->{
|
||||||
HistorySort.ASC -> (item.getChildAt(0) as ImageView).setImageResource(R.drawable.ic_down)
|
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!!.requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||||
sortSheet!!.setContentView(R.layout.history_sort_sheet)
|
sortSheet!!.setContentView(R.layout.history_sort_sheet)
|
||||||
|
|
||||||
val date = sortSheet!!.findViewById<LinearLayout>(R.id.date)
|
val date = sortSheet!!.findViewById<TextView>(R.id.date)
|
||||||
val title = sortSheet!!.findViewById<LinearLayout>(R.id.title)
|
val title = sortSheet!!.findViewById<TextView>(R.id.title)
|
||||||
val author = sortSheet!!.findViewById<LinearLayout>(R.id.author)
|
val author = sortSheet!!.findViewById<TextView>(R.id.author)
|
||||||
|
val filesize = sortSheet!!.findViewById<TextView>(R.id.filesize)
|
||||||
|
|
||||||
val sortOptions = listOf(date!!, title!!, author!!)
|
val sortOptions = listOf(date!!, title!!, author!!, filesize!!)
|
||||||
sortOptions.forEach { it.getChildAt(0).visibility = INVISIBLE }
|
sortOptions.forEach { it.setCompoundDrawablesWithIntrinsicBounds(R.drawable.empty,0,0,0) }
|
||||||
when(historyViewModel.sortType.value!!) {
|
when(historyViewModel.sortType.value!!) {
|
||||||
HistoryRepository.HistorySortType.DATE -> changeSortIcon(date, historyViewModel.sortOrder.value!!)
|
HistoryRepository.HistorySortType.DATE -> changeSortIcon(date, historyViewModel.sortOrder.value!!)
|
||||||
HistoryRepository.HistorySortType.TITLE -> changeSortIcon(title, historyViewModel.sortOrder.value!!)
|
HistoryRepository.HistorySortType.TITLE -> changeSortIcon(title, historyViewModel.sortOrder.value!!)
|
||||||
HistoryRepository.HistorySortType.AUTHOR -> changeSortIcon(author, historyViewModel.sortOrder.value!!)
|
HistoryRepository.HistorySortType.AUTHOR -> changeSortIcon(author, historyViewModel.sortOrder.value!!)
|
||||||
|
HistoryRepository.HistorySortType.FILESIZE -> changeSortIcon(filesize, historyViewModel.sortOrder.value!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
date.getChildAt(1).setOnClickListener {
|
date.setOnClickListener {
|
||||||
sortOptions.forEach { it.getChildAt(0).visibility = INVISIBLE }
|
sortOptions.forEach { it.setCompoundDrawablesWithIntrinsicBounds(R.drawable.empty,0,0,0) }
|
||||||
historyViewModel.setSorting(HistoryRepository.HistorySortType.DATE)
|
historyViewModel.setSorting(HistoryRepository.HistorySortType.DATE)
|
||||||
changeSortIcon(date, historyViewModel.sortOrder.value!!)
|
changeSortIcon(date, historyViewModel.sortOrder.value!!)
|
||||||
}
|
}
|
||||||
title.getChildAt(1).setOnClickListener {
|
title.setOnClickListener {
|
||||||
sortOptions.forEach { it.getChildAt(0).visibility = INVISIBLE }
|
sortOptions.forEach { it.setCompoundDrawablesWithIntrinsicBounds(R.drawable.empty,0,0,0) }
|
||||||
historyViewModel.setSorting(HistoryRepository.HistorySortType.TITLE)
|
historyViewModel.setSorting(HistoryRepository.HistorySortType.TITLE)
|
||||||
changeSortIcon(title, historyViewModel.sortOrder.value!!)
|
changeSortIcon(title, historyViewModel.sortOrder.value!!)
|
||||||
}
|
}
|
||||||
author.getChildAt(1).setOnClickListener {
|
author.setOnClickListener {
|
||||||
sortOptions.forEach { it.getChildAt(0).visibility = INVISIBLE }
|
sortOptions.forEach { it.setCompoundDrawablesWithIntrinsicBounds(R.drawable.empty,0,0,0) }
|
||||||
historyViewModel.setSorting(HistoryRepository.HistorySortType.AUTHOR)
|
historyViewModel.setSorting(HistoryRepository.HistorySortType.AUTHOR)
|
||||||
changeSortIcon(author, historyViewModel.sortOrder.value!!)
|
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()
|
sortSheet!!.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
8
app/src/main/res/drawable/empty.xml
Normal file
8
app/src/main/res/drawable/empty.xml
Normal file
|
|
@ -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:paddingBottom="20dp"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
<LinearLayout
|
<TextView
|
||||||
android:id="@+id/date"
|
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_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingBottom="20dp"
|
android:textSize="15sp"
|
||||||
android:orientation="horizontal">
|
android:text="@string/date_added"
|
||||||
|
app:drawableLeftCompat="@drawable/ic_arrow_up" />
|
||||||
<ImageView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="20dp"
|
|
||||||
android:paddingEnd="20dp"
|
|
||||||
android:src="@drawable/ic_up"/>
|
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="15sp"
|
|
||||||
android:text="@string/date_added" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/title"
|
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_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingBottom="20dp"
|
android:textSize="15sp"
|
||||||
android:orientation="horizontal">
|
android:text="@string/title"
|
||||||
|
app:drawableLeftCompat="@drawable/ic_arrow_up" />
|
||||||
<ImageView
|
|
||||||
android:visibility="invisible"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="20dp"
|
|
||||||
android:paddingEnd="20dp"
|
|
||||||
android:src="@drawable/ic_up"/>
|
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="15sp"
|
|
||||||
android:text="@string/title" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/author"
|
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_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingBottom="20dp"
|
android:textSize="15sp"
|
||||||
android:orientation="horizontal">
|
android:text="@string/author"
|
||||||
|
app:drawableLeftCompat="@drawable/ic_arrow_up" />
|
||||||
<ImageView
|
|
||||||
android:visibility="invisible"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="20dp"
|
|
||||||
android:paddingEnd="20dp"
|
|
||||||
android:src="@drawable/ic_up"/>
|
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:id="@+id/filesize"
|
||||||
android:layout_height="wrap_content"
|
android:clickable="true"
|
||||||
android:textSize="15sp"
|
android:focusable="true"
|
||||||
android:text="@string/author" />
|
android:background="?attr/selectableItemBackground"
|
||||||
</LinearLayout>
|
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="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="restart">Restart</string>
|
||||||
<string name="download_rescheduled_to">Download rescheduled to:</string>
|
<string name="download_rescheduled_to">Download rescheduled to:</string>
|
||||||
|
<string name="file_size">File size</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Reference in a new issue