added redownload button on deleted history items
This commit is contained in:
parent
6f09746f96
commit
cd63e73011
10 changed files with 80 additions and 21 deletions
|
|
@ -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 {
|
||||
when(type) {
|
||||
|
|
|
|||
|
|
@ -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) }
|
||||
|
||||
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 containerAutoCompleteTextView =
|
||||
view.findViewById<AutoCompleteTextView>(R.id.container_textview)
|
||||
|
|
@ -125,7 +126,6 @@ class DownloadAudioFragment(private var resultItem: ResultItem, private var curr
|
|||
val listener = object : OnFormatClickListener {
|
||||
override fun onFormatClick(allFormats: List<Format>, item: Format) {
|
||||
downloadItem.format = item
|
||||
|
||||
if (containers.contains(item.container)){
|
||||
downloadItem.format.container = item.container
|
||||
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 =
|
||||
AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, index: Int, _: Long ->
|
||||
downloadItem.format.container = containers[index]
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
|
|||
var formats = mutableListOf<Format>()
|
||||
formats.addAll(resultItem.formats.filter { !it.format_note.contains("audio", ignoreCase = true) })
|
||||
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()) {
|
||||
|
||||
|
|
@ -139,14 +139,13 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
|
|||
)
|
||||
)
|
||||
downloadItem.format.container = containerPreference!!
|
||||
containerAutoCompleteTextView!!.setText(downloadItem.format.container, false)
|
||||
|
||||
(container!!.editText as AutoCompleteTextView?)!!.onItemClickListener =
|
||||
AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, index: Int, _: Long ->
|
||||
downloadItem.format.container = containers[index]
|
||||
}
|
||||
|
||||
containerAutoCompleteTextView!!.setText(downloadItem.format.container, false)
|
||||
|
||||
val formatCard = view.findViewById<ConstraintLayout>(R.id.format_card_constraintLayout)
|
||||
val chosenFormat = downloadItem.format
|
||||
uiUtil.populateFormatCard(formatCard, chosenFormat)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ import android.app.Activity
|
|||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.ColorMatrix
|
||||
import android.graphics.ColorMatrixColorFilter
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
|
|
@ -48,6 +46,7 @@ import java.io.File
|
|||
*/
|
||||
class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{
|
||||
private lateinit var historyViewModel : HistoryViewModel
|
||||
private lateinit var downloadViewModel : DownloadViewModel
|
||||
|
||||
private var fragmentView: View? = null
|
||||
private var activity: Activity? = null
|
||||
|
|
@ -146,6 +145,8 @@ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{
|
|||
scrollToTop()
|
||||
}
|
||||
|
||||
downloadViewModel = ViewModelProvider(this)[DownloadViewModel::class.java]
|
||||
|
||||
initMenu()
|
||||
initChips()
|
||||
}
|
||||
|
|
@ -406,7 +407,7 @@ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{
|
|||
val codec = bottomSheet!!.findViewById<TextView>(R.id.codec)
|
||||
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
|
||||
|
||||
val codecText =
|
||||
|
|
@ -418,14 +419,14 @@ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{
|
|||
item.format.acodec.uppercase()
|
||||
}
|
||||
if (codecText == "" || codecText == "none"){
|
||||
codec!!.visibility = View.GONE
|
||||
codec!!.visibility = GONE
|
||||
}else{
|
||||
codec!!.visibility = View.VISIBLE
|
||||
codec!!.visibility = VISIBLE
|
||||
codec.text = codecText
|
||||
}
|
||||
|
||||
val fileSizeReadable = fileUtil!!.convertFileSize(item.format.filesize)
|
||||
if (fileSizeReadable == "?") fileSize!!.visibility = View.GONE
|
||||
if (fileSizeReadable == "?") fileSize!!.visibility = GONE
|
||||
else fileSize!!.text = fileSizeReadable
|
||||
|
||||
val link = bottomSheet!!.findViewById<Button>(R.id.bottom_sheet_link)
|
||||
|
|
@ -449,7 +450,19 @@ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{
|
|||
openFile.setOnClickListener{
|
||||
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
|
||||
else redownload.visibility = GONE
|
||||
|
||||
bottomSheet!!.show()
|
||||
bottomSheet!!.window!!.setLayout(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/constraintLayout2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="55dp"
|
||||
android:layout_height="0dp"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/container"
|
||||
|
|
@ -48,12 +48,15 @@
|
|||
android:layout_gravity="bottom"
|
||||
android:layout_marginStart="10dp"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintTop_toBottomOf="@+id/format_note"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/codec"
|
||||
android:ellipsize="end"
|
||||
android:maxLength="17"
|
||||
style="@style/Widget.Material3.FloatingActionButton.Large.Secondary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -95,6 +98,7 @@
|
|||
android:layout_height="55dp"
|
||||
android:clickable="false"
|
||||
android:gravity="bottom|end"
|
||||
android:maxLength="10"
|
||||
android:minWidth="30dp"
|
||||
app:cornerRadius="10dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@
|
|||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/audio_format" />
|
||||
android:text="@string/audio_quality" />
|
||||
<include layout="@layout/format_item" />
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@
|
|||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/video_format" />
|
||||
android:text="@string/video_quality" />
|
||||
|
||||
<include layout="@layout/format_item" />
|
||||
|
||||
|
|
|
|||
|
|
@ -51,8 +51,9 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:paddingVertical="20dp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/linearLayout4"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/linearLayout4"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
|
|
@ -83,13 +84,12 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/url">
|
||||
|
||||
<TextView
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/format_note"
|
||||
style="@style/Widget.Material3.FloatingActionButton.Large.Primary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:clickable="false"
|
||||
android:gravity="center"
|
||||
android:minWidth="30dp"
|
||||
|
|
@ -99,13 +99,12 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
|
||||
<TextView
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/codec"
|
||||
style="@style/Widget.Material3.FloatingActionButton.Large.Secondary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:background="?attr/colorSecondary"
|
||||
android:clickable="false"
|
||||
android:gravity="center"
|
||||
android:minWidth="30dp"
|
||||
|
|
@ -115,13 +114,12 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/file_size"
|
||||
style="@style/Widget.Material3.FloatingActionButton.Large.Tertiary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:background="?attr/colorSecondary"
|
||||
android:clickable="false"
|
||||
android:gravity="center"
|
||||
android:minWidth="30dp"
|
||||
|
|
@ -169,9 +167,20 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/Open_File"
|
||||
android:layout_marginEnd="10dp"
|
||||
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>
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingStart="20dp"
|
||||
|
|
|
|||
|
|
@ -208,4 +208,5 @@
|
|||
<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_summary">Let the app download on directories that are restricted by default</string>
|
||||
<string name="redownload">Redownload</string>
|
||||
</resources>
|
||||
Loading…
Reference in a new issue