fixed custom command not scrolling properly in the download card

This commit is contained in:
deniscerri 2023-03-24 22:15:00 +01:00
parent badf4fb0d9
commit 1eca31ab5d
No known key found for this signature in database
GPG key ID: 95C43D517D830350
12 changed files with 115 additions and 114 deletions

View file

@ -17,12 +17,15 @@ import android.view.MenuItem
import android.view.View
import android.view.WindowInsets
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.deniscerri.ytdlnis.database.viewmodel.ResultViewModel
import com.deniscerri.ytdlnis.databinding.ActivityMainBinding
import com.deniscerri.ytdlnis.ui.HomeFragment
import com.deniscerri.ytdlnis.ui.downloads.DownloadQueueActivity
@ -33,6 +36,7 @@ import com.deniscerri.ytdlnis.util.UpdateUtil
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader
@ -49,6 +53,7 @@ class MainActivity : AppCompatActivity() {
private lateinit var homeFragment: HomeFragment
private lateinit var historyFragment: HistoryFragment
private lateinit var preferences: SharedPreferences
private lateinit var resultViewModel: ResultViewModel
override fun onCreate(savedInstanceState: Bundle?) {
@ -58,9 +63,13 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)
setContentView(binding.root)
context = baseContext
resultViewModel = ViewModelProvider(this)[ResultViewModel::class.java]
preferences = context.getSharedPreferences("root_preferences", MODE_PRIVATE)
if (preferences.getBoolean("incognito", false)){
resultViewModel.deleteAll()
}
askPermissions()
checkUpdate()
fm = supportFragmentManager

View file

@ -222,7 +222,7 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application
"",
"",
0,
c.content
c.content.replace("\n", " ")
)
}
}

View file

@ -1,7 +1,6 @@
package com.deniscerri.ytdlnis.ui.downloadcard
import android.app.Activity
import android.app.AlertDialog
import android.content.ClipboardManager
import android.content.DialogInterface
import android.content.Intent
@ -22,8 +21,6 @@ import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.preference.MultiSelectListPreference
import androidx.preference.Preference
import com.deniscerri.ytdlnis.R
import com.deniscerri.ytdlnis.database.models.DownloadItem
import com.deniscerri.ytdlnis.database.models.Format
@ -123,9 +120,9 @@ class DownloadAudioFragment(private var resultItem: ResultItem, private var curr
audioPathResultLauncher.launch(intent)
}
freeSpace = view.findViewById(R.id.freespace)
freeSpace.text = getString(R.string.freespace) + ": " + fileUtil.convertFileSize(
freeSpace.text = String.format( getString(R.string.freespace) + ": " + fileUtil.convertFileSize(
File(fileUtil.formatPath(downloadItem.downloadPath)).freeSpace
)
))
var formats = mutableListOf<Format>()
formats.addAll(resultItem.formats.filter { it.format_note.contains("audio", ignoreCase = true) })
@ -271,9 +268,9 @@ class DownloadAudioFragment(private var resultItem: ResultItem, private var curr
//downloadViewModel.updateDownload(downloadItem)
saveDir.editText?.setText(fileUtil.formatPath(result.data?.data.toString()), TextView.BufferType.EDITABLE)
freeSpace.text = getString(R.string.freespace) + ": " + fileUtil.convertFileSize(
freeSpace.text = String.format( getString(R.string.freespace) + ": " + fileUtil.convertFileSize(
File(fileUtil.formatPath(downloadItem.downloadPath)).freeSpace
)
))
}
}

View file

@ -1,5 +1,6 @@
package com.deniscerri.ytdlnis.ui.downloadcard
import android.annotation.SuppressLint
import android.app.Activity
import android.content.ClipboardManager
import android.content.Intent
@ -7,12 +8,10 @@ import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.AutoCompleteTextView
import android.widget.TextView
import android.widget.*
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
@ -116,6 +115,7 @@ class DownloadCommandFragment(private val resultItem: ResultItem, private var cu
chosenCommandView.editText!!.setText("")
}
}
chosenCommandView.editText!!.enableScrollText()
val commandTemplates = view.findViewById<TextInputLayout>(R.id.template)
val autoCompleteTextView =
@ -140,8 +140,8 @@ class DownloadCommandFragment(private val resultItem: ResultItem, private var cu
saveDir.editText!!.setText(
fileUtil.formatPath(downloadItem.downloadPath)
)
saveDir.editText!!.isFocusable = false;
saveDir.editText!!.isClickable = true;
saveDir.editText!!.isFocusable = false
saveDir.editText!!.isClickable = true
saveDir.editText!!.setOnClickListener {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
@ -151,9 +151,9 @@ class DownloadCommandFragment(private val resultItem: ResultItem, private var cu
}
freeSpace = view.findViewById(R.id.freespace)
freeSpace.text = getString(R.string.freespace) + ": " + fileUtil.convertFileSize(
freeSpace.text = String.format(getString(R.string.freespace) + ": " + fileUtil.convertFileSize(
File(fileUtil.formatPath(downloadItem.downloadPath)).freeSpace
)
))
val newTemplate : Chip = view.findViewById(R.id.newTemplate)
newTemplate.setOnClickListener {
@ -233,12 +233,30 @@ class DownloadCommandFragment(private val resultItem: ResultItem, private var cu
)
}
downloadItem.downloadPath = result.data?.data.toString()
//downloadviewmodel.updateDownload(downloadItem)
saveDir.editText?.setText(fileUtil.formatPath(result.data?.data.toString()), TextView.BufferType.EDITABLE)
freeSpace.text = getString(R.string.freespace) + ": " + fileUtil.convertFileSize(
freeSpace.text = String.format(getString(R.string.freespace) + ": " + fileUtil.convertFileSize(
File(fileUtil.formatPath(downloadItem.downloadPath)).freeSpace
)
))
}
}
@SuppressLint("ClickableViewAccessibility")
fun EditText.enableScrollText()
{
overScrollMode = View.OVER_SCROLL_ALWAYS
scrollBarStyle = View.SCROLLBARS_INSIDE_INSET
isVerticalScrollBarEnabled = true
setOnTouchListener { view, event ->
if (view is EditText) {
if(!view.text.isNullOrEmpty()) {
view.parent.requestDisallowInterceptTouchEvent(true)
when (event.action and MotionEvent.ACTION_MASK) {
MotionEvent.ACTION_UP -> view.parent.requestDisallowInterceptTouchEvent(false)
}
}
}
false
}
}
}

View file

@ -111,8 +111,8 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
saveDir.editText!!.setText(
fileUtil.formatPath(downloadItem.downloadPath)
)
saveDir.editText!!.isFocusable = false;
saveDir.editText!!.isClickable = true;
saveDir.editText!!.isFocusable = false
saveDir.editText!!.isClickable = true
saveDir.editText!!.setOnClickListener {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
@ -122,9 +122,9 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
}
freeSpace = view.findViewById(R.id.freespace)
freeSpace.text = getString(R.string.freespace) + ": " + fileUtil.convertFileSize(
freeSpace.text = String.format(getString(R.string.freespace) + ": " + fileUtil.convertFileSize(
File(fileUtil.formatPath(downloadItem.downloadPath)).freeSpace
)
))
var formats = mutableListOf<Format>()
formats.addAll(resultItem.formats.filter { !it.format_note.contains("audio", ignoreCase = true) })
@ -235,13 +235,13 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
builder.setMultiChoiceItems(
entries,
checkedItems.toBooleanArray()
) { dialog, which, isChecked ->
) { _, which, isChecked ->
checkedItems[which] = isChecked
}
builder.setPositiveButton(
getString(R.string.ok)
) { dialog: DialogInterface?, which: Int ->
) { _: DialogInterface?, _: Int ->
downloadItem.videoPreferences.sponsorBlockFilters.clear()
for (i in 0 until checkedItems.size) {
if (checkedItems[i]) {
@ -253,7 +253,7 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
// handle the negative button of the alert dialog
builder.setNegativeButton(
getString(R.string.cancel)
) { dialog: DialogInterface?, which: Int -> }
) { _: DialogInterface?, _: Int -> }
val dialog = builder.create()
@ -288,9 +288,9 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
//downloadviewmodel.updateDownload(downloadItem)
saveDir.editText?.setText(fileUtil.formatPath(result.data?.data.toString()), TextView.BufferType.EDITABLE)
freeSpace.text = getString(R.string.freespace) + ": " + fileUtil.convertFileSize(
freeSpace.text = String.format(getString(R.string.freespace) + ": " + fileUtil.convertFileSize(
File(fileUtil.formatPath(downloadItem.downloadPath)).freeSpace
)
))
}
}

View file

@ -137,8 +137,7 @@ class TerminalActivity : AppCompatActivity() {
}.absolutePath
)
request.addOption("-P", tempFileDir.absolutePath)
//request.addOption("-P", tempFileDir.absolutePath)
cancelFab!!.visibility = View.VISIBLE
fab!!.visibility = View.GONE

View file

@ -433,7 +433,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
requireContext().getString(R.string.you_are_in_latest_version),
Toast.LENGTH_LONG
).show()
else -> Toast.makeText(context, this.toString(), Toast.LENGTH_LONG).show()
else -> Toast.makeText(context, getString(R.string.errored), Toast.LENGTH_LONG).show()
}
}
true

View file

@ -171,22 +171,17 @@ class UpdateUtil(var context: Context) {
updatingYTDL = true
YoutubeDL.getInstance().updateYoutubeDL(
context, if (sharedPreferences.getBoolean("nightly_ytdl", false) ) ytdlpNightly else null
).apply {
try {
YoutubeDL.getInstance().updateYoutubeDL(
context, if (sharedPreferences.getBoolean("nightly_ytdl", false) ) ytdlpNightly else null
).apply {
updatingYTDL = false
}
}catch (e: Exception){
e.printStackTrace()
updatingYTDL = false
null
}
// .onFailure {
// if (BuildConfig.DEBUG) Log.e(tag, context.getString(R.string.ytdl_update_failed), e)
// Toast.makeText(
// context,
// context.getString(R.string.ytdl_update_failed),
// Toast.LENGTH_LONG
// ).show()
// updatingYTDL = false
// }
//}
}
companion object {

View file

@ -68,7 +68,6 @@ class DownloadWorker(
val type = downloadItem.type
val downloadLocation = downloadItem.downloadPath
val titleRegex = Regex("[^A-Za-z\\d ]")
val tempFileDir = File(context.cacheDir.absolutePath + downloadItem.id)
tempFileDir.delete()
tempFileDir.mkdir()
@ -129,7 +128,7 @@ class DownloadWorker(
DownloadViewModel.Type.audio -> {
request.addOption("-x")
var audioQualityId : String = downloadItem.format.format_id
if (audioQualityId.isBlank() || audioQualityId == "0") audioQualityId = ""
if (audioQualityId.isBlank() || audioQualityId == "0" || audioQualityId == context.getString(R.string.best_quality)) audioQualityId = ""
else if (audioQualityId == context.getString(R.string.worst_quality)) audioQualityId = "worstaudio"
if (audioQualityId.isNotBlank()){
@ -223,14 +222,15 @@ class DownloadWorker(
}
runCatching {
val titleRegex = Regex("[^A-Za-z\\d ]")
val logDownloads = sharedPreferences.getBoolean("log_downloads", false) && !sharedPreferences.getBoolean("incognito", false)
val logFolder = File(context.filesDir.absolutePath + "/logs")
val logFile = File(context.filesDir.absolutePath + """/logs/${downloadItem.id} - ${titleRegex.replace(downloadItem.title, "")}##${downloadItem.type}##${downloadItem.format.format_id}.log""")
Log.e("aa", logFile.name)
if (logDownloads){
logFolder.mkdirs()
logFile.createNewFile()
logFile.writeText("Downloading:\n" +
"Title: ${downloadItem.title}\n" +
"URL: ${downloadItem.url}\n" +
"Type: ${downloadItem.type}\n" +
"Format: ${downloadItem.format}\n\n")

View file

@ -169,6 +169,7 @@
android:textSize="15sp" />
<HorizontalScrollView
android:scrollbars="none"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
@ -195,14 +196,6 @@
android:checked="false"
android:text="@string/add_chapter" />
<com.google.android.material.chip.Chip
android:id="@+id/split_by_chapters"
style="@style/Widget.Material3.Chip.Filter.Elevated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/split_by_chapters"/>
<com.google.android.material.chip.Chip
android:id="@+id/save_thumbnail"
style="@style/Widget.Material3.Chip.Filter.Elevated"
@ -217,6 +210,7 @@
</HorizontalScrollView>
<HorizontalScrollView
android:scrollbars="none"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
@ -240,6 +234,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.chip.Chip
android:id="@+id/split_by_chapters"
style="@style/Widget.Material3.Chip.Filter.Elevated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/split_by_chapters"/>
<com.google.android.material.chip.Chip
android:id="@+id/copy_url"
android:layout_width="wrap_content"

View file

@ -5,65 +5,45 @@
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id="@+id/downloads_relative_layout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="H,6:1"
<LinearLayout
android:paddingHorizontal="10dp"
android:paddingVertical="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.card.MaterialCardView
android:id="@+id/downloads_card_view"
android:layout_width="match_parent"
<TextView
android:id="@+id/suggestion_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:cardBackgroundColor="@android:color/transparent"
android:checkable="true"
app:strokeWidth="0dp"
app:cardPreventCornerOverlap="true"
android:layout_margin="10dp">
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:drawablePadding="20dp"
android:ellipsize="end"
android:focusable="true"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingEnd="20dp"
android:textSize="16sp"
android:textStyle="bold"
app:drawableLeftCompat="@drawable/ic_search" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="@+id/set_search_query_button"
style="?attr/materialIconButtonStyle"
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_weight="0.01"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:scrollbars="none"
android:src="@drawable/ic_arrow_outward" />
<TextView
android:id="@+id/suggestion_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:maxLines="1"
android:background="?attr/selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:ellipsize="end"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:paddingEnd="20dp"
android:textSize="16sp"
android:textStyle="bold"
android:drawablePadding="20dp"
app:drawableLeftCompat="@drawable/ic_search" />
<ImageButton
style="?attr/materialIconButtonStyle"
android:id="@+id/set_search_query_button"
android:layout_width="40dp"
android:scrollbars="none"
android:background="?attr/selectableItemBackground"
android:focusable="true"
android:clickable="true"
android:layout_height="match_parent"
android:src="@drawable/ic_arrow_outward"
android:layout_weight="0.01"
/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</RelativeLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -145,7 +145,7 @@
<SwitchPreferenceCompat
android:widgetLayout="@layout/preferece_material_switch"
app:defaultValue="true"
app:defaultValue="false"
app:icon="@drawable/if_file_rename"
app:key="restrict_filenames"
app:summary="@string/restrict_filenames_summary"
@ -293,7 +293,7 @@
<Preference
app:icon="@drawable/ic_translate"
app:key="telegram"
app:key="translate"
app:summary="@string/help_translate_summary"
app:title="@string/help_translate">
<intent