From b727be0076b2f60b704f4d3e0f653ae8e5245d91 Mon Sep 17 00:00:00 2001 From: deniscerri <64997243+deniscerri@users.noreply.github.com> Date: Tue, 26 Aug 2025 16:24:17 +0200 Subject: [PATCH] small design tinkering --- .../ytdl/database/viewmodel/FormatViewModel.kt | 10 ++++------ .../com/deniscerri/ytdl/ui/adapter/FormatAdapter.kt | 4 ++-- .../downloadcard/FormatSelectionBottomSheetDialog.kt | 5 +++-- .../ytdl/util/extractors/newpipe/NewPipeUtil.kt | 7 ++++++- app/src/main/res/layout/active_terminal_card.xml | 2 +- app/src/main/res/layout/adjust_audio.xml | 1 + app/src/main/res/layout/format_select_bottom_sheet.xml | 2 ++ app/src/main/res/layout/history_card.xml | 2 +- app/src/main/res/layout/history_card_multiple.xml | 4 ++-- app/src/main/res/layout/observe_sources_item.xml | 2 +- app/src/main/res/layout/result_card.xml | 2 +- app/src/main/res/layout/result_card_shimmer.xml | 2 +- 12 files changed, 25 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/deniscerri/ytdl/database/viewmodel/FormatViewModel.kt b/app/src/main/java/com/deniscerri/ytdl/database/viewmodel/FormatViewModel.kt index 7def02c2..042dc1e0 100644 --- a/app/src/main/java/com/deniscerri/ytdl/database/viewmodel/FormatViewModel.kt +++ b/app/src/main/java/com/deniscerri/ytdl/database/viewmodel/FormatViewModel.kt @@ -45,8 +45,8 @@ class FormatViewModel(private val application: Application) : AndroidViewModel(a val selectedItems = MutableStateFlow(listOf()) val selectedItemsSharedFlow = MutableSharedFlow>(replay = 1) var formats : Flow> - var showFilterBtn = MutableStateFlow(false) - var showRefreshBtn = MutableStateFlow(false) + var showFilterBtn = MutableSharedFlow(1) + var showRefreshBtn = MutableSharedFlow(1) private var canUpdate = true var canMultiSelectAudio = MutableStateFlow(false) var isMissingFormats = MutableStateFlow(false) @@ -114,12 +114,10 @@ class FormatViewModel(private val application: Application) : AndroidViewModel(a showFilterBtn.apply { val vl = chosenFormats.isNotEmpty() || items.all { it.url.isYoutubeURL() } - value = vl emit(vl) } showRefreshBtn.apply { val vl = (isMissingFormats.value || items.isEmpty() || items.first().url.isEmpty()) && canUpdate - value = vl emit(vl) } @@ -214,21 +212,21 @@ class FormatViewModel(private val application: Application) : AndroidViewModel(a } fun setItems(list: List, updateFormats: Boolean? = null) = viewModelScope.launch { + canUpdate = updateFormats ?: canUpdate selectedItems.apply { value = list emit(list) } selectedItemsSharedFlow.emit(list) - canUpdate = updateFormats ?: canUpdate } fun setItem(item: DownloadItem, updateFormats: Boolean? = null) = viewModelScope.launch { + canUpdate = updateFormats ?: canUpdate selectedItems.apply { value = listOf(item) emit(listOf(item)) } selectedItemsSharedFlow.emit(listOf(item)) - canUpdate = updateFormats ?: canUpdate } diff --git a/app/src/main/java/com/deniscerri/ytdl/ui/adapter/FormatAdapter.kt b/app/src/main/java/com/deniscerri/ytdl/ui/adapter/FormatAdapter.kt index 22eac194..40ab05a8 100644 --- a/app/src/main/java/com/deniscerri/ytdl/ui/adapter/FormatAdapter.kt +++ b/app/src/main/java/com/deniscerri/ytdl/ui/adapter/FormatAdapter.kt @@ -138,11 +138,11 @@ class FormatAdapter(onItemClickListener: OnItemClickListener, activity: Activity companion object { private val DIFF_CALLBACK: DiffUtil.ItemCallback = object : DiffUtil.ItemCallback() { override fun areItemsTheSame(oldItem: FormatRecyclerView, newItem: FormatRecyclerView): Boolean { - return oldItem.label == newItem.label && oldItem.format?.format_id == newItem.format?.format_id + return oldItem.label == newItem.label && oldItem.format?.format_id == newItem.format?.format_id && oldItem.format?.format_note == newItem.format?.format_note } override fun areContentsTheSame(oldItem: FormatRecyclerView, newItem: FormatRecyclerView): Boolean { - return oldItem.label == newItem.label && oldItem.format?.format_id == newItem.format?.format_id + return oldItem.label == newItem.label && oldItem.format?.format_id == newItem.format?.format_id && oldItem.format?.format_note == newItem.format?.format_note } } } diff --git a/app/src/main/java/com/deniscerri/ytdl/ui/downloadcard/FormatSelectionBottomSheetDialog.kt b/app/src/main/java/com/deniscerri/ytdl/ui/downloadcard/FormatSelectionBottomSheetDialog.kt index 7964de5d..7dc9e259 100644 --- a/app/src/main/java/com/deniscerri/ytdl/ui/downloadcard/FormatSelectionBottomSheetDialog.kt +++ b/app/src/main/java/com/deniscerri/ytdl/ui/downloadcard/FormatSelectionBottomSheetDialog.kt @@ -225,7 +225,7 @@ class FormatSelectionBottomSheetDialog( items.first().allFormats.addAll(chosenFormats) withContext(Dispatchers.Main){ - formatViewModel.setItem(items.first()) + formatViewModel.setItem(items.first(), false) listener.onFormatsUpdated(res) } }.onFailure { err -> @@ -269,12 +269,13 @@ class FormatSelectionBottomSheetDialog( } } - formatViewModel.setItems(items) + formatViewModel.setItems(items, false) } withContext(Dispatchers.Main){ filterBtn.isEnabled = true okBtn.isEnabled = true + refreshBtn.isEnabled = true } }catch (e: Exception){ withContext(Dispatchers.Main) { diff --git a/app/src/main/java/com/deniscerri/ytdl/util/extractors/newpipe/NewPipeUtil.kt b/app/src/main/java/com/deniscerri/ytdl/util/extractors/newpipe/NewPipeUtil.kt index a43e6e4c..9b854fa0 100644 --- a/app/src/main/java/com/deniscerri/ytdl/util/extractors/newpipe/NewPipeUtil.kt +++ b/app/src/main/java/com/deniscerri/ytdl/util/extractors/newpipe/NewPipeUtil.kt @@ -339,6 +339,12 @@ class NewPipeUtil(context: Context) { formats.add(formatObj) } + + val hasDefaultFormat = formats.firstOrNull { it.format_note.contains("ORIGINAL", true) } + if (hasDefaultFormat != null) { + formats.remove(hasDefaultFormat) + formats.add(0, hasDefaultFormat) + } } if (stream.videoStreams.isNotEmpty()){ @@ -385,7 +391,6 @@ class NewPipeUtil(context: Context) { defaultLang?.format_id = (defaultLang?.format_id?.split("-")?.get(0) ?: "") + "-${it.value.size-1}" } } - formats.sortByDescending { it.filesize } } val chapters = ArrayList() diff --git a/app/src/main/res/layout/active_terminal_card.xml b/app/src/main/res/layout/active_terminal_card.xml index cd1e0dae..81289341 100644 --- a/app/src/main/res/layout/active_terminal_card.xml +++ b/app/src/main/res/layout/active_terminal_card.xml @@ -20,7 +20,7 @@ android:clickable="true" android:focusable="true" app:cardCornerRadius="20dp" - app:cardElevation="10dp" + app:cardElevation="0dp" app:cardMaxElevation="12dp" android:checkable="true" app:strokeWidth="0dp" diff --git a/app/src/main/res/layout/adjust_audio.xml b/app/src/main/res/layout/adjust_audio.xml index 4e118a57..7df63740 100644 --- a/app/src/main/res/layout/adjust_audio.xml +++ b/app/src/main/res/layout/adjust_audio.xml @@ -39,6 +39,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="false" + android:outlineProvider="none" android:visibility="gone" android:text="@string/crop_thumb"/> diff --git a/app/src/main/res/layout/format_select_bottom_sheet.xml b/app/src/main/res/layout/format_select_bottom_sheet.xml index 60f3bc35..39d031f3 100644 --- a/app/src/main/res/layout/format_select_bottom_sheet.xml +++ b/app/src/main/res/layout/format_select_bottom_sheet.xml @@ -64,6 +64,7 @@ android:id="@+id/format_filter" style="@style/Widget.Material3.Button.IconButton.Filled" android:layout_width="wrap_content" + android:stateListAnimator="@null" android:layout_height="wrap_content" app:icon="@drawable/baseline_align_horizontal_left_24" app:layout_constraintBottom_toBottomOf="@id/format_refresh" @@ -76,6 +77,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:autoLink="all" + android:stateListAnimator="@null" android:text="@string/update" android:contentDescription="@string/update_formats" android:layout_marginStart="10dp" diff --git a/app/src/main/res/layout/history_card.xml b/app/src/main/res/layout/history_card.xml index 6c42a60e..c02f04ed 100644 --- a/app/src/main/res/layout/history_card.xml +++ b/app/src/main/res/layout/history_card.xml @@ -17,7 +17,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" app:cardCornerRadius="20dp" - app:cardElevation="5dp" + app:cardElevation="0dp" app:checkedIcon="@null" app:cardMaxElevation="12dp" android:checkable="true" diff --git a/app/src/main/res/layout/history_card_multiple.xml b/app/src/main/res/layout/history_card_multiple.xml index d38317b7..272d52c7 100644 --- a/app/src/main/res/layout/history_card_multiple.xml +++ b/app/src/main/res/layout/history_card_multiple.xml @@ -25,7 +25,7 @@ android:layout_marginVertical="5dp" android:checkable="false" app:cardCornerRadius="15dp" - app:cardElevation="5dp" + app:cardElevation="0dp" app:cardMaxElevation="12dp" app:cardPreventCornerOverlap="true" app:checkedIcon="@null" @@ -39,7 +39,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" app:cardCornerRadius="20dp" - app:cardElevation="5dp" + app:cardElevation="0dp" app:checkedIcon="@null" app:cardMaxElevation="12dp" android:checkable="true" diff --git a/app/src/main/res/layout/observe_sources_item.xml b/app/src/main/res/layout/observe_sources_item.xml index 36ab8918..9982c4ec 100644 --- a/app/src/main/res/layout/observe_sources_item.xml +++ b/app/src/main/res/layout/observe_sources_item.xml @@ -20,7 +20,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" app:cardCornerRadius="20dp" - app:cardElevation="5dp" + app:cardElevation="0dp" app:strokeColor="?attr/colorPrimary" app:checkedIconTint="?attr/colorPrimary" app:cardMaxElevation="12dp" diff --git a/app/src/main/res/layout/result_card.xml b/app/src/main/res/layout/result_card.xml index 3fe671b1..04faacf4 100644 --- a/app/src/main/res/layout/result_card.xml +++ b/app/src/main/res/layout/result_card.xml @@ -20,7 +20,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" app:cardCornerRadius="20dp" - app:cardElevation="5dp" + app:cardElevation="0dp" app:cardBackgroundColor="?attr/colorSurfaceContainer" app:strokeColor="?attr/colorPrimary" app:checkedIconTint="?attr/colorPrimary" diff --git a/app/src/main/res/layout/result_card_shimmer.xml b/app/src/main/res/layout/result_card_shimmer.xml index d1ae5c46..c83f43b5 100644 --- a/app/src/main/res/layout/result_card_shimmer.xml +++ b/app/src/main/res/layout/result_card_shimmer.xml @@ -16,7 +16,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" app:cardCornerRadius="20dp" - app:cardElevation="10dp" + app:cardElevation="0dp" app:cardMaxElevation="12dp" app:cardBackgroundColor="@color/grey" app:cardPreventCornerOverlap="true"