fixes
This commit is contained in:
parent
d10b15f96f
commit
334b42a908
20 changed files with 105 additions and 26 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package com.deniscerri.ytdlnis.adapter
|
||||
|
||||
import android.app.Activity
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
|
@ -53,7 +54,7 @@ class TemplatesAdapter(onItemClickListener: OnItemClickListener, activity: Activ
|
|||
// }
|
||||
|
||||
card.setOnClickListener {
|
||||
onItemClickListener.onItemClick(item!!)
|
||||
onItemClickListener.onItemClick(item!!, position)
|
||||
}
|
||||
|
||||
card.setOnLongClickListener {
|
||||
|
|
@ -62,7 +63,7 @@ class TemplatesAdapter(onItemClickListener: OnItemClickListener, activity: Activ
|
|||
}
|
||||
|
||||
interface OnItemClickListener {
|
||||
fun onItemClick(commandTemplate: CommandTemplate)
|
||||
fun onItemClick(commandTemplate: CommandTemplate, index: Int)
|
||||
fun onSelected(commandTemplate: CommandTemplate)
|
||||
fun onDelete(commandTemplate: CommandTemplate)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ interface CommandTemplateDao {
|
|||
@Query("SELECT COUNT(id) FROM commandTemplates")
|
||||
fun getTotalNumber() : Int
|
||||
|
||||
@Query("SELECT COUNT(id) FROM templateShortcuts")
|
||||
fun getTotalShortcutNumber() : Int
|
||||
|
||||
@Query("SELECT * FROM commandTemplates WHERE id=:id LIMIT 1")
|
||||
fun getTemplate(id: Long) : CommandTemplate
|
||||
|
||||
|
|
@ -46,6 +49,6 @@ interface CommandTemplateDao {
|
|||
@Query("DELETE FROM templateShortcuts WHERE id=:itemId")
|
||||
suspend fun deleteShortcut(itemId: Long)
|
||||
|
||||
@Update(onConflict = OnConflictStrategy.REPLACE)
|
||||
@Update
|
||||
suspend fun update(item: CommandTemplate)
|
||||
}
|
||||
|
|
@ -17,6 +17,10 @@ class CommandTemplateRepository(private val commandDao: CommandTemplateDao) {
|
|||
return commandDao.getTotalNumber()
|
||||
}
|
||||
|
||||
fun getTotalShortcutNumber() : Int {
|
||||
return commandDao.getTotalShortcutNumber()
|
||||
}
|
||||
|
||||
fun getItem(id: Long) : CommandTemplate {
|
||||
return commandDao.getTemplate(id)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,10 @@ class CommandTemplateViewModel(private val application: Application) : AndroidVi
|
|||
return repository.getTotalNumber()
|
||||
}
|
||||
|
||||
fun getTotalShortcutNumber(): Int {
|
||||
return repository.getTotalShortcutNumber()
|
||||
}
|
||||
|
||||
fun insert(item: CommandTemplate) = viewModelScope.launch(Dispatchers.IO) {
|
||||
repository.insert(item)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -301,14 +301,13 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application
|
|||
} else 0
|
||||
if (delay < 0L) delay = 0L
|
||||
|
||||
val workConstraints = Constraints.Builder()
|
||||
if (!allowMeteredNetworks) workConstraints.setRequiredNetworkType(NetworkType.UNMETERED)
|
||||
|
||||
val workRequest = OneTimeWorkRequestBuilder<DownloadWorker>()
|
||||
.setInputData(Data.Builder().putLong("id", it.id).build())
|
||||
.addTag("download")
|
||||
.setConstraints(
|
||||
Constraints.Builder()
|
||||
.setRequiredNetworkType(if (allowMeteredNetworks) NetworkType.CONNECTED else NetworkType.UNMETERED)
|
||||
.build()
|
||||
)
|
||||
.setConstraints(workConstraints.build())
|
||||
.setInitialDelay(delay, TimeUnit.MILLISECONDS)
|
||||
.build()
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import android.util.DisplayMetrics
|
|||
import android.util.Log
|
||||
import android.view.*
|
||||
import android.widget.Button
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
|
|
@ -22,6 +21,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import com.deniscerri.ytdlnis.R
|
||||
import com.deniscerri.ytdlnis.adapter.ConfigureMultipleDownloadsAdapter
|
||||
import com.deniscerri.ytdlnis.database.models.DownloadItem
|
||||
import com.deniscerri.ytdlnis.database.models.Format
|
||||
import com.deniscerri.ytdlnis.database.viewmodel.CommandTemplateViewModel
|
||||
import com.deniscerri.ytdlnis.database.viewmodel.DownloadViewModel
|
||||
import com.deniscerri.ytdlnis.database.viewmodel.ResultViewModel
|
||||
|
|
@ -33,7 +33,9 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
|
|||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.common.collect.Sets
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
|
|
@ -194,11 +196,43 @@ class DownloadMultipleBottomSheetDialog(private var items: MutableList<DownloadI
|
|||
)
|
||||
}
|
||||
|
||||
} else if (itemId == R.id.format){
|
||||
// val formatListCollection = items.map { it.format }
|
||||
// val commonFormats = getCommonFormats(formatListCollection)
|
||||
//
|
||||
// val listener = object : OnFormatClickListener {
|
||||
// override fun onFormatClick(allFormats: List<Format>, item: Format) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// if (parentFragmentManager.findFragmentByTag("formatSheet") == null){
|
||||
// val bottomSheet = FormatSelectionBottomSheetDialog(null, commonFormats.toList(), listener)
|
||||
// bottomSheet.show(parentFragmentManager, "formatSheet")
|
||||
// }
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
val itemsLiveData = items.asFlow()
|
||||
}
|
||||
|
||||
// private fun getCommonFormats(vararg lists: MutableList<List<Format>>): Set<Format> {
|
||||
// val commons: MutableList<Format> = mutableListOf()
|
||||
// commons.addAll(lists[1])
|
||||
// {
|
||||
// lists[1].forEach {
|
||||
// commons.retainAll(it)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for (numbers in list) {
|
||||
// result = Sets.intersection(result, Sets.newHashSet(numbers))
|
||||
// }
|
||||
// return result
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
private var pathResultLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import kotlinx.coroutines.withContext
|
|||
import java.util.*
|
||||
|
||||
|
||||
class FormatSelectionBottomSheetDialog(private val item: DownloadItem, private var formats: List<Format>, private val listener: OnFormatClickListener) : BottomSheetDialogFragment() {
|
||||
class FormatSelectionBottomSheetDialog(private val item: DownloadItem?, private var formats: List<Format>, private val listener: OnFormatClickListener) : BottomSheetDialogFragment() {
|
||||
private lateinit var behavior: BottomSheetBehavior<View>
|
||||
private lateinit var fileUtil: FileUtil
|
||||
private lateinit var infoUtil: InfoUtil
|
||||
|
|
@ -64,7 +64,7 @@ class FormatSelectionBottomSheetDialog(private val item: DownloadItem, private v
|
|||
addFormatsToView(linearLayout)
|
||||
|
||||
val refreshBtn = view.findViewById<Button>(R.id.format_refresh)
|
||||
if (formats.none { it.filesize == 0L }) refreshBtn.visibility = View.GONE
|
||||
if (formats.none { it.filesize == 0L } || item == null) refreshBtn.visibility = View.GONE
|
||||
refreshBtn.setOnClickListener {
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
|
|
@ -74,10 +74,10 @@ class FormatSelectionBottomSheetDialog(private val item: DownloadItem, private v
|
|||
shimmers.startShimmer()
|
||||
|
||||
val res = withContext(Dispatchers.IO){
|
||||
infoUtil.getFormats(item.url)
|
||||
infoUtil.getFormats(item!!.url)
|
||||
}
|
||||
formats = res.formats.filter { it.filesize != 0L }
|
||||
formats = when(item.type){
|
||||
formats = when(item?.type){
|
||||
Type.audio -> formats.filter { it.format_note.contains("audio", ignoreCase = true) }
|
||||
else -> formats.filter { !it.format_note.contains("audio", ignoreCase = true) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.deniscerri.ytdlnis.ui.more
|
|||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.MenuItem
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
|
@ -96,8 +97,10 @@ class CommandTemplatesActivity : AppCompatActivity(), TemplatesAdapter.OnItemCli
|
|||
private const val TAG = "DownloadLogActivity"
|
||||
}
|
||||
|
||||
override fun onItemClick(commandTemplate: CommandTemplate) {
|
||||
uiUtil.showCommandTemplateCreationOrUpdatingSheet(commandTemplate,this@CommandTemplatesActivity, this, commandTemplateViewModel) {}
|
||||
override fun onItemClick(commandTemplate: CommandTemplate, index: Int) {
|
||||
uiUtil.showCommandTemplateCreationOrUpdatingSheet(commandTemplate,this@CommandTemplatesActivity, this, commandTemplateViewModel) {
|
||||
templatesAdapter.notifyItemChanged(index)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ class TerminalActivity : AppCompatActivity() {
|
|||
private var downloadID by Delegates.notNull<Int>()
|
||||
private lateinit var downloadFile : File
|
||||
private lateinit var observer: FileObserver
|
||||
private lateinit var imm : InputMethodManager
|
||||
var context: Context? = null
|
||||
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
|
@ -60,6 +61,7 @@ class TerminalActivity : AppCompatActivity() {
|
|||
downloadID = System.currentTimeMillis().toInt() % 100000
|
||||
downloadFile = File(cacheDir.absolutePath + "/$downloadID.txt")
|
||||
if (! downloadFile.exists()) downloadFile.createNewFile()
|
||||
imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
|
||||
context = baseContext
|
||||
scrollView = findViewById(R.id.custom_command_scrollview)
|
||||
|
|
@ -71,6 +73,17 @@ class TerminalActivity : AppCompatActivity() {
|
|||
|
||||
|
||||
bottomAppBar = findViewById(R.id.bottomAppBar)
|
||||
lifecycleScope.launch {
|
||||
val templateCount = withContext(Dispatchers.IO){
|
||||
commandTemplateViewModel.getTotalNumber()
|
||||
}
|
||||
if (templateCount == 0) bottomAppBar.menu.getItem(0).isEnabled = false
|
||||
|
||||
val shortcutCount = withContext(Dispatchers.IO){
|
||||
commandTemplateViewModel.getTotalShortcutNumber()
|
||||
}
|
||||
if (shortcutCount == 0) bottomAppBar.menu.getItem(1).isEnabled = false
|
||||
}
|
||||
bottomAppBar.setOnMenuItemClickListener {
|
||||
when(it.itemId){
|
||||
R.id.command_templates -> showCommandTemplates()
|
||||
|
|
@ -91,6 +104,7 @@ class TerminalActivity : AppCompatActivity() {
|
|||
output!!.text = "${output!!.text}\n~ $ ${input!!.text}\n"
|
||||
showCancelFab()
|
||||
downloadFile.appendText("~ $ ${input!!.text}\n")
|
||||
imm.hideSoftInputFromWindow(input?.windowToken, 0)
|
||||
startDownload(
|
||||
input!!.text.toString()
|
||||
)
|
||||
|
|
@ -141,6 +155,7 @@ class TerminalActivity : AppCompatActivity() {
|
|||
input!!.setText("yt-dlp ")
|
||||
input!!.visibility = View.VISIBLE
|
||||
input!!.requestFocus()
|
||||
input!!.setSelection(input!!.text.length)
|
||||
hideCancelFab()
|
||||
}
|
||||
}
|
||||
|
|
@ -211,7 +226,6 @@ class TerminalActivity : AppCompatActivity() {
|
|||
item.setOnClickListener {
|
||||
input!!.text.insert(input!!.selectionStart, template.content + " ")
|
||||
bottomSheet.cancel()
|
||||
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
input!!.postDelayed({
|
||||
input!!.requestFocus()
|
||||
imm.showSoftInput(input!!, 0)
|
||||
|
|
|
|||
|
|
@ -581,6 +581,7 @@ class InfoUtil(private val context: Context) {
|
|||
}
|
||||
e.printStackTrace()
|
||||
}
|
||||
Log.e("aa", items.toString())
|
||||
return items
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -142,6 +142,7 @@ class UiUtil(private val fileUtil: FileUtil) {
|
|||
}else{
|
||||
item.title = title.editText!!.text.toString()
|
||||
item.content = content.editText!!.text.toString()
|
||||
Log.e("aa", item.toString())
|
||||
commandTemplateViewModel.update(item)
|
||||
newTemplate(item)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ class DownloadWorker(
|
|||
Log.e(TAG, formatArgument)
|
||||
request.addOption("-f", formatArgument)
|
||||
val format = downloadItem.format.container
|
||||
if(format.isNotEmpty() || format != context.resources.getString(R.string.defaultValue)){
|
||||
if(format.isNotEmpty() && format != context.resources.getString(R.string.defaultValue)){
|
||||
request.addOption("--merge-output-format", format)
|
||||
if (format != "webm") {
|
||||
val embedThumb = sharedPreferences.getBoolean("embed_thumbnail", false)
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class TerminalDownloadWorker(
|
|||
|
||||
val intent = Intent(context, MainActivity::class.java)
|
||||
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)
|
||||
val notification = notificationUtil.createDownloadServiceNotification(pendingIntent, command.take(20), itemId, NotificationUtil.DOWNLOAD_SERVICE_CHANNEL_ID)
|
||||
val notification = notificationUtil.createDownloadServiceNotification(pendingIntent, command.take(65), itemId, NotificationUtil.DOWNLOAD_SERVICE_CHANNEL_ID)
|
||||
val foregroundInfo = ForegroundInfo(itemId, notification)
|
||||
setForegroundAsync(foregroundInfo)
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ class TerminalDownloadWorker(
|
|||
|
||||
YoutubeDL.getInstance().execute(request, itemId.toString()){ progress, _, line ->
|
||||
outputFile.appendText("${line}\n")
|
||||
val title: String = command.take(20)
|
||||
val title: String = command.take(65)
|
||||
notificationUtil.updateDownloadNotification(
|
||||
itemId,
|
||||
line, progress.toInt(), 0, title,
|
||||
|
|
@ -123,7 +123,7 @@ class TerminalDownloadWorker(
|
|||
Log.e(TAG, context.getString(R.string.failed_download), it)
|
||||
notificationUtil.updateDownloadNotification(
|
||||
itemId,
|
||||
context.getString(R.string.failed_download), 0, 0, command.take(20),
|
||||
context.getString(R.string.failed_download), 0, 0, command.take(65),
|
||||
NotificationUtil.DOWNLOAD_SERVICE_CHANNEL_ID
|
||||
)
|
||||
|
||||
|
|
|
|||
5
app/src/main/res/drawable/baseline_high_quality_24.xml
Normal file
5
app/src/main/res/drawable/baseline_high_quality_24.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="?android:textColorPrimary" android:pathData="M19,4L5,4c-1.11,0 -2,0.9 -2,2v12c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,6c0,-1.1 -0.9,-2 -2,-2zM11,15L9.5,15v-2h-2v2L6,15L6,9h1.5v2.5h2L9.5,9L11,9v6zM18,14c0,0.55 -0.45,1 -1,1h-0.75v1.5h-1.5L14.75,15L14,15c-0.55,0 -1,-0.45 -1,-1v-4c0,-0.55 0.45,-1 1,-1h3c0.55,0 1,0.45 1,1v4zM14.5,13.5h2v-3h-2v3z"/>
|
||||
</vector>
|
||||
|
|
@ -61,6 +61,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:fontFamily="monospace"
|
||||
android:gravity="bottom"
|
||||
android:textSize="15sp"
|
||||
android:scrollbars="horizontal|vertical"
|
||||
android:scrollHorizontally="true"
|
||||
android:textIsSelectable="true" />
|
||||
|
|
@ -74,7 +75,7 @@
|
|||
android:background="@android:color/transparent"
|
||||
android:fontFamily="monospace"
|
||||
android:gravity="start"
|
||||
android:inputType="textMultiLine"
|
||||
android:inputType="textMultiLine|textNoSuggestions"
|
||||
android:maxLines="100"
|
||||
android:text="yt-dlp "
|
||||
android:textSize="15sp" />
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@
|
|||
android:id="@+id/audio_quality_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingHorizontal="10dp"
|
||||
android:text="@string/audio_quality" />
|
||||
<include layout="@layout/format_item" />
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="10dp"
|
||||
android:paddingTop="10dp"
|
||||
android:text="@string/video_quality" />
|
||||
|
||||
<include layout="@layout/format_item" />
|
||||
|
|
|
|||
|
|
@ -83,7 +83,8 @@
|
|||
android:focusable="true"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:paddingHorizontal="15dp"
|
||||
app:drawableStartCompat="@drawable/ic_concurrent_downloads" />
|
||||
app:drawableTint="?android:colorAccent"
|
||||
app:drawableStartCompat="@drawable/baseline_downloading_24" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/cookies"
|
||||
|
|
|
|||
|
|
@ -15,5 +15,11 @@
|
|||
android:icon="@drawable/baseline_insert_drive_file_24"
|
||||
app:showAsAction="collapseActionView|ifRoom"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/format"
|
||||
android:title="@string/format"
|
||||
android:icon="@drawable/baseline_high_quality_24"
|
||||
app:showAsAction="collapseActionView|ifRoom"/>
|
||||
|
||||
</menu>
|
||||
|
||||
|
|
|
|||
|
|
@ -212,21 +212,21 @@
|
|||
app:title="@string/save_thumb" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="mp3"
|
||||
android:defaultValue="@string/defaultValue"
|
||||
android:entries="@array/audio_containers"
|
||||
android:entryValues="@array/audio_containers"
|
||||
android:icon="@drawable/ic_code"
|
||||
app:key="audio_format"
|
||||
app:summary="mp3"
|
||||
app:summary="@string/defaultValue"
|
||||
app:title="@string/audio_format" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="mkv"
|
||||
android:defaultValue="@string/defaultValue"
|
||||
android:entries="@array/video_containers"
|
||||
android:entryValues="@array/video_containers"
|
||||
android:icon="@drawable/ic_code"
|
||||
app:key="video_format"
|
||||
app:summary="DEFAULT"
|
||||
app:summary="@string/defaultValue"
|
||||
app:title="@string/video_format" />
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue