added redownload button on deleted history items

This commit is contained in:
Denis Çerri 2023-03-11 08:59:03 +01:00
parent 6f09746f96
commit cd63e73011
No known key found for this signature in database
GPG key ID: 95C43D517D830350
10 changed files with 80 additions and 21 deletions

View file

@ -119,6 +119,35 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application
} }
fun createDownloadItemFromHistory(historyItem: HistoryItem) : DownloadItem {
val embedSubs = sharedPreferences.getBoolean("embed_subtitles", false)
val addChapters = sharedPreferences.getBoolean("add_chapters", false)
val saveThumb = sharedPreferences.getBoolean("write_thumbnail", false)
val embedThumb = sharedPreferences.getBoolean("embed_thumbnail", false)
val customFileNameTemplate = sharedPreferences.getString("file_name_template", "%(uploader)s - %(title)s")
val downloadPath = when(historyItem.type){
Type.audio -> sharedPreferences.getString("music_path", getApplication<App>().resources.getString(R.string.music_path))
Type.video -> sharedPreferences.getString("video_path", getApplication<App>().resources.getString(R.string.video_path))
else -> sharedPreferences.getString("command_path", getApplication<App>().resources.getString(R.string.command_path))
}
val audioPreferences = AudioPreferences(embedThumb)
val videoPreferences = VideoPreferences(embedSubs, addChapters)
return DownloadItem(0,
historyItem.url,
historyItem.title,
historyItem.author,
historyItem.thumb,
historyItem.duration,
historyItem.type,
historyItem.format,
downloadPath!!, historyItem.website, "", "", audioPreferences, videoPreferences,customFileNameTemplate!!, saveThumb, DownloadRepository.Status.Processing.toString(), 0
)
}
private fun getFormat(resultItem: ResultItem?, type: Type) : Format { private fun getFormat(resultItem: ResultItem?, type: Type) : Format {
when(type) { when(type) {

View file

@ -111,6 +111,7 @@ class DownloadAudioFragment(private var resultItem: ResultItem, private var curr
var formats = resultItem.formats.filter { it.format_note.contains("audio", ignoreCase = true) } var formats = resultItem.formats.filter { it.format_note.contains("audio", ignoreCase = true) }
val containers = requireContext().resources.getStringArray(R.array.audio_containers) val containers = requireContext().resources.getStringArray(R.array.audio_containers)
val containerPreference = sharedPreferences.getString("audio_format", getString(R.string.defaultValue))
val container = view.findViewById<TextInputLayout>(R.id.downloadContainer) val container = view.findViewById<TextInputLayout>(R.id.downloadContainer)
val containerAutoCompleteTextView = val containerAutoCompleteTextView =
view.findViewById<AutoCompleteTextView>(R.id.container_textview) view.findViewById<AutoCompleteTextView>(R.id.container_textview)
@ -125,7 +126,6 @@ class DownloadAudioFragment(private var resultItem: ResultItem, private var curr
val listener = object : OnFormatClickListener { val listener = object : OnFormatClickListener {
override fun onFormatClick(allFormats: List<Format>, item: Format) { override fun onFormatClick(allFormats: List<Format>, item: Format) {
downloadItem.format = item downloadItem.format = item
if (containers.contains(item.container)){ if (containers.contains(item.container)){
downloadItem.format.container = item.container downloadItem.format.container = item.container
containerAutoCompleteTextView.setText(item.container, false) containerAutoCompleteTextView.setText(item.container, false)
@ -157,7 +157,9 @@ class DownloadAudioFragment(private var resultItem: ResultItem, private var curr
) )
) )
containerAutoCompleteTextView!!.setText(downloadItem.format.container, false) downloadItem.format.container = containerPreference!!
containerAutoCompleteTextView.setText(downloadItem.format.container, false)
(container!!.editText as AutoCompleteTextView?)!!.onItemClickListener = (container!!.editText as AutoCompleteTextView?)!!.onItemClickListener =
AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, index: Int, _: Long -> AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, index: Int, _: Long ->
downloadItem.format.container = containers[index] downloadItem.format.container = containers[index]

View file

@ -117,7 +117,7 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
var formats = mutableListOf<Format>() var formats = mutableListOf<Format>()
formats.addAll(resultItem.formats.filter { !it.format_note.contains("audio", ignoreCase = true) }) formats.addAll(resultItem.formats.filter { !it.format_note.contains("audio", ignoreCase = true) })
val videoFormats = resources.getStringArray(R.array.video_formats) val videoFormats = resources.getStringArray(R.array.video_formats)
val containerPreference = sharedPreferences.getString("video_format", "Default") val containerPreference = sharedPreferences.getString("video_format", getString(R.string.defaultValue))
if (formats.isEmpty()) { if (formats.isEmpty()) {
@ -139,14 +139,13 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
) )
) )
downloadItem.format.container = containerPreference!! downloadItem.format.container = containerPreference!!
containerAutoCompleteTextView!!.setText(downloadItem.format.container, false)
(container!!.editText as AutoCompleteTextView?)!!.onItemClickListener = (container!!.editText as AutoCompleteTextView?)!!.onItemClickListener =
AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, index: Int, _: Long -> AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, index: Int, _: Long ->
downloadItem.format.container = containers[index] downloadItem.format.container = containers[index]
} }
containerAutoCompleteTextView!!.setText(downloadItem.format.container, false)
val formatCard = view.findViewById<ConstraintLayout>(R.id.format_card_constraintLayout) val formatCard = view.findViewById<ConstraintLayout>(R.id.format_card_constraintLayout)
val chosenFormat = downloadItem.format val chosenFormat = downloadItem.format
uiUtil.populateFormatCard(formatCard, chosenFormat) uiUtil.populateFormatCard(formatCard, chosenFormat)

View file

@ -4,8 +4,6 @@ import android.app.Activity
import android.content.Context import android.content.Context
import android.content.DialogInterface import android.content.DialogInterface
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
@ -48,6 +46,7 @@ import java.io.File
*/ */
class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{
private lateinit var historyViewModel : HistoryViewModel private lateinit var historyViewModel : HistoryViewModel
private lateinit var downloadViewModel : DownloadViewModel
private var fragmentView: View? = null private var fragmentView: View? = null
private var activity: Activity? = null private var activity: Activity? = null
@ -146,6 +145,8 @@ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{
scrollToTop() scrollToTop()
} }
downloadViewModel = ViewModelProvider(this)[DownloadViewModel::class.java]
initMenu() initMenu()
initChips() initChips()
} }
@ -406,7 +407,7 @@ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{
val codec = bottomSheet!!.findViewById<TextView>(R.id.codec) val codec = bottomSheet!!.findViewById<TextView>(R.id.codec)
val fileSize = bottomSheet!!.findViewById<TextView>(R.id.file_size) val fileSize = bottomSheet!!.findViewById<TextView>(R.id.file_size)
if (item.format.format_note == "?" || item.format.format_note == "") formatNote!!.visibility = View.GONE if (item.format.format_note == "?" || item.format.format_note == "") formatNote!!.visibility = GONE
else formatNote!!.text = item.format.format_note else formatNote!!.text = item.format.format_note
val codecText = val codecText =
@ -418,14 +419,14 @@ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{
item.format.acodec.uppercase() item.format.acodec.uppercase()
} }
if (codecText == "" || codecText == "none"){ if (codecText == "" || codecText == "none"){
codec!!.visibility = View.GONE codec!!.visibility = GONE
}else{ }else{
codec!!.visibility = View.VISIBLE codec!!.visibility = VISIBLE
codec.text = codecText codec.text = codecText
} }
val fileSizeReadable = fileUtil!!.convertFileSize(item.format.filesize) val fileSizeReadable = fileUtil!!.convertFileSize(item.format.filesize)
if (fileSizeReadable == "?") fileSize!!.visibility = View.GONE if (fileSizeReadable == "?") fileSize!!.visibility = GONE
else fileSize!!.text = fileSizeReadable else fileSize!!.text = fileSizeReadable
val link = bottomSheet!!.findViewById<Button>(R.id.bottom_sheet_link) val link = bottomSheet!!.findViewById<Button>(R.id.bottom_sheet_link)
@ -449,7 +450,19 @@ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{
openFile.setOnClickListener{ openFile.setOnClickListener{
uiUtil!!.openFileIntent(requireContext(), item.downloadPath) uiUtil!!.openFileIntent(requireContext(), item.downloadPath)
} }
val redownload = bottomSheet!!.findViewById<Button>(R.id.bottomsheet_redownload_button)
redownload!!.tag = itemID
redownload.setOnClickListener{
val downloadItem = downloadViewModel.createDownloadItemFromHistory(item)
downloadViewModel.queueDownloads(listOf(downloadItem))
historyViewModel.delete(item, false)
bottomSheet!!.cancel()
}
if (!isPresent) openFile.visibility = GONE if (!isPresent) openFile.visibility = GONE
else redownload.visibility = GONE
bottomSheet!!.show() bottomSheet!!.show()
bottomSheet!!.window!!.setLayout( bottomSheet!!.window!!.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,

View file

@ -26,7 +26,7 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout2" android:id="@+id/constraintLayout2"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="55dp" android:layout_height="0dp"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/container" app:layout_constraintStart_toEndOf="@+id/container"
@ -48,12 +48,15 @@
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:orientation="horizontal" android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="@+id/format_note"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"> app:layout_constraintStart_toStartOf="parent">
<TextView <TextView
android:id="@+id/codec" android:id="@+id/codec"
android:ellipsize="end"
android:maxLength="17"
style="@style/Widget.Material3.FloatingActionButton.Large.Secondary" style="@style/Widget.Material3.FloatingActionButton.Large.Secondary"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -95,6 +98,7 @@
android:layout_height="55dp" android:layout_height="55dp"
android:clickable="false" android:clickable="false"
android:gravity="bottom|end" android:gravity="bottom|end"
android:maxLength="10"
android:minWidth="30dp" android:minWidth="30dp"
app:cornerRadius="10dp" app:cornerRadius="10dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"

View file

@ -129,7 +129,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/audio_format" /> android:text="@string/audio_quality" />
<include layout="@layout/format_item" /> <include layout="@layout/format_item" />

View file

@ -123,7 +123,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/video_format" /> android:text="@string/video_quality" />
<include layout="@layout/format_item" /> <include layout="@layout/format_item" />

View file

@ -51,8 +51,9 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingVertical="20dp" app:layout_constraintBottom_toBottomOf="@+id/linearLayout4"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/linearLayout4"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
@ -83,13 +84,12 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/url"> app:layout_constraintTop_toBottomOf="@+id/url">
<TextView <com.google.android.material.chip.Chip
android:id="@+id/format_note" android:id="@+id/format_note"
style="@style/Widget.Material3.FloatingActionButton.Large.Primary" style="@style/Widget.Material3.FloatingActionButton.Large.Primary"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:background="?attr/colorPrimary"
android:clickable="false" android:clickable="false"
android:gravity="center" android:gravity="center"
android:minWidth="30dp" android:minWidth="30dp"
@ -99,13 +99,12 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/> app:layout_constraintTop_toTopOf="parent"/>
<TextView <com.google.android.material.chip.Chip
android:id="@+id/codec" android:id="@+id/codec"
style="@style/Widget.Material3.FloatingActionButton.Large.Secondary" style="@style/Widget.Material3.FloatingActionButton.Large.Secondary"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:background="?attr/colorSecondary"
android:clickable="false" android:clickable="false"
android:gravity="center" android:gravity="center"
android:minWidth="30dp" android:minWidth="30dp"
@ -115,13 +114,12 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView <com.google.android.material.chip.Chip
android:id="@+id/file_size" android:id="@+id/file_size"
style="@style/Widget.Material3.FloatingActionButton.Large.Tertiary" style="@style/Widget.Material3.FloatingActionButton.Large.Tertiary"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:background="?attr/colorSecondary"
android:clickable="false" android:clickable="false"
android:gravity="center" android:gravity="center"
android:minWidth="30dp" android:minWidth="30dp"
@ -169,9 +167,20 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/Open_File" android:text="@string/Open_File"
android:layout_marginEnd="10dp"
app:icon="@drawable/ic_baseline_file_open_24" app:icon="@drawable/ic_baseline_file_open_24"
/> />
<Button
style="@style/Widget.Material3.Button.ElevatedButton.Icon"
android:id="@+id/bottomsheet_redownload_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/redownload"
android:layout_marginEnd="10dp"
app:icon="@drawable/ic_refresh"
/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -44,6 +44,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:maxLines="1"
android:ellipsize="end"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingStart="20dp" android:paddingStart="20dp"

View file

@ -208,4 +208,5 @@
<string name="all_items_selected">All items selected</string> <string name="all_items_selected">All items selected</string>
<string name="access_all_directories">Allow access to all directories</string> <string name="access_all_directories">Allow access to all directories</string>
<string name="access_all_directories_summary">Let the app download on directories that are restricted by default</string> <string name="access_all_directories_summary">Let the app download on directories that are restricted by default</string>
<string name="redownload">Redownload</string>
</resources> </resources>