fix app crashing when opening deleted log, added advanced settings

This commit is contained in:
zaednasr 2024-11-02 19:37:48 +01:00
parent 87ef8c9de4
commit db2d0cb981
No known key found for this signature in database
GPG key ID: 92B1DE23AD3D0E9E
16 changed files with 162 additions and 41 deletions

View file

@ -64,6 +64,7 @@ class App : Application() {
PreferenceManager.setDefaultValues(this, R.xml.processing_preferences, true)
PreferenceManager.setDefaultValues(this, R.xml.folders_preference, true)
PreferenceManager.setDefaultValues(this, R.xml.updating_preferences, true)
PreferenceManager.setDefaultValues(this, R.xml.advanced_preferences, true)
sp.edit().putInt("spl", SPL).apply()
}

View file

@ -243,7 +243,7 @@ class DownloadRepository(private val downloadDao: DownloadDao) {
earliestStart.downloadStartTime.minus(currentTime)
} else 0
if (delay <= 60000L) delay = 0L
inputData.putLongArray("priority_item_ids", queuedItems.map { it.id }.toLongArray())
inputData.putLongArray("priority_item_ids", queuedItems.take(20).map { it.id }.toLongArray())
}
val useAlarmForScheduling = sharedPreferences.getBoolean("use_alarm_for_scheduling", false)

View file

@ -244,19 +244,7 @@ class ResultCardDetailsDialog : BottomSheetDialogFragment(), GenericDownloadAdap
downloadThumb.isVisible = item.thumb.isNotBlank()
downloadThumb.setOnClickListener {
runCatching {
downloadManager.enqueue(
DownloadManager.Request(item.thumb.toUri())
.setAllowedNetworkTypes(
DownloadManager.Request.NETWORK_WIFI or
DownloadManager.Request.NETWORK_MOBILE
)
.setAllowedOverRoaming(true)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "YTDLnis/" + item.title + ".jpg"))
}.onFailure {
Toast.makeText(requireContext(), getString(R.string.failed_download), Toast.LENGTH_SHORT).show()
}
UiUtil.openLinkIntent(requireContext(), item.thumb)
}
title.text = item.title

View file

@ -14,6 +14,7 @@ import android.widget.HorizontalScrollView
import android.widget.LinearLayout
import android.widget.ScrollView
import android.widget.TextView
import android.widget.Toast
import androidx.core.content.edit
import androidx.core.view.children
import androidx.core.view.get
@ -103,9 +104,16 @@ class DownloadLogFragment : Fragment() {
logViewModel = ViewModelProvider(this)[LogViewModel::class.java]
CoroutineScope(Dispatchers.IO).launch {
val logItem = logViewModel.getItemById(id!!)
withContext(Dispatchers.Main){
topAppBar.title = logItem.title
runCatching {
val logItem = logViewModel.getItemById(id!!)
withContext(Dispatchers.Main){
topAppBar.title = logItem.title
}
}.onFailure {
withContext(Dispatchers.Main) {
Toast.makeText(requireContext(), "Log is deleted!", Toast.LENGTH_SHORT).show()
mainActivity.onBackPressedDispatcher.onBackPressed()
}
}
}

View file

@ -0,0 +1,28 @@
package com.deniscerri.ytdl.ui.more.settings
import android.annotation.SuppressLint
import android.content.DialogInterface
import android.graphics.Typeface
import android.os.Bundle
import android.widget.LinearLayout
import android.widget.TextView
import androidx.preference.EditTextPreference
import androidx.preference.Preference
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.afollestad.materialdialogs.utils.MDUtil.getStringArray
import com.deniscerri.ytdl.R
import com.deniscerri.ytdl.ui.adapter.SortableTextItemAdapter
import com.deniscerri.ytdl.util.UiUtil
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class AdvancedSettingsFragment : BaseSettingsFragment() {
override val title: Int = R.string.advanced
@SuppressLint("RestrictedApi")
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.advanced_preferences, rootKey)
}
}

View file

@ -128,6 +128,13 @@ class MainSettingsFragment : PreferenceFragmentCompat() {
true
}
val advanced = findPreference<Preference>("advanced")
advanced?.summary = "PO Token$separator ${getString(R.string.other_youtube_extractor_args)}"
advanced?.setOnPreferenceClickListener {
navController.navigate(R.id.action_mainSettingsFragment_to_advancedSettingsFragment)
true
}
//about section -------------------------
updateUtil = UpdateUtil(requireContext())

View file

@ -508,6 +508,7 @@ object UiUtil {
btn?.setImageResource(typeImageResource)
val time = bottomSheet.findViewById<Chip>(R.id.time)
val thumbnail = bottomSheet.findViewById<Chip>(R.id.thumbnail)
val formatNote = bottomSheet.findViewById<Chip>(R.id.format_note)
val container = bottomSheet.findViewById<Chip>(R.id.container_chip)
val codec = bottomSheet.findViewById<Chip>(R.id.codec)
@ -533,6 +534,14 @@ object UiUtil {
}
}
thumbnail?.isVisible = item.thumb.isNotBlank()
thumbnail?.apply {
isVisible = item.thumb.isNotBlank()
setOnClickListener {
openLinkIntent(context, item.thumb)
}
}
if (item.type != DownloadViewModel.Type.command){
if (item.format.format_note == "?" || item.format.format_note == "") formatNote!!.visibility =
View.GONE
@ -717,6 +726,7 @@ object UiUtil {
}
val time = bottomSheet.findViewById<TextView>(R.id.time)
val thumbnail = bottomSheet.findViewById<TextView>(R.id.thumbnail)
val formatNote = bottomSheet.findViewById<TextView>(R.id.format_note)
val container = bottomSheet.findViewById<Chip>(R.id.container_chip)
val codec = bottomSheet.findViewById<TextView>(R.id.codec)
@ -730,6 +740,14 @@ object UiUtil {
time!!.text = SimpleDateFormat(DateFormat.getBestDateTimePattern(Locale.getDefault(), "ddMMMyyyy - HHmm"), Locale.getDefault()).format(calendar.time)
time.isClickable = false
thumbnail?.isVisible = item.thumb.isNotBlank()
thumbnail?.apply {
isVisible = item.thumb.isNotBlank()
setOnClickListener {
openLinkIntent(context, item.thumb)
}
}
if (item.type != DownloadViewModel.Type.command){
if (item.format.format_note == "?" || item.format.format_note == "") formatNote!!.visibility =
View.GONE

View file

@ -106,6 +106,10 @@ class YTDLPUtil(private val context: Context) {
}
request.addOption("-P", FileUtil.getCachePath(context) + "/tmp")
val extraCommands = sharedPreferences.getString("data_fetching_extra_commands", "")!!
if (extraCommands.isNotBlank()){
request.addConfig(extraCommands)
}
println(parseYTDLRequestString(request))
val youtubeDLResponse = YoutubeDL.getInstance().execute(request)
@ -267,6 +271,11 @@ class YTDLPUtil(private val context: Context) {
}
request.addOption("-P", FileUtil.getCachePath(context) + "/tmp")
val extraCommands = sharedPreferences.getString("data_fetching_extra_commands", "")!!
if (extraCommands.isNotBlank()){
request.addConfig(extraCommands)
}
val txt = parseYTDLRequestString(request)
println(txt)
@ -360,7 +369,10 @@ class YTDLPUtil(private val context: Context) {
}
request.addOption("-P", FileUtil.getCachePath(context) + "/tmp")
val extraCommands = sharedPreferences.getString("data_fetching_extra_commands", "")!!
if (extraCommands.isNotBlank()){
request.addConfig(extraCommands)
}
val res = YoutubeDL.getInstance().execute(request)
val results: Array<String?> = try {
@ -462,7 +474,10 @@ class YTDLPUtil(private val context: Context) {
}
request.addOption("-P", FileUtil.getCachePath(context) + "/tmp")
val extraCommands = sharedPreferences.getString("data_fetching_extra_commands", "")!!
if (extraCommands.isNotBlank()){
request.addConfig(extraCommands)
}
val youtubeDLResponse = YoutubeDL.getInstance().execute(request)
val json = JSONObject(youtubeDLResponse.out)
@ -1131,4 +1146,13 @@ class YTDLPUtil(private val context: Context) {
return extractorArgs.joinToString(";")
}
private fun YoutubeDLRequest.addConfig(commandString: String) {
this.addOption(
"--config-locations",
File(context.cacheDir.absolutePath + "/${System.currentTimeMillis()}${UUID.randomUUID()}.txt").apply {
writeText(commandString)
}.absolutePath
)
}
}

View file

@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="?attr/colorAccent" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
<path android:fillColor="@android:color/white" android:pathData="M17.41,6.59L15,5.5l2.41,-1.09L18.5,2l1.09,2.41L22,5.5l-2.41,1.09L18.5,9L17.41,6.59zM21.28,12.72L20.5,11l-0.78,1.72L18,13.5l1.72,0.78L20.5,16l0.78,-1.72L23,13.5L21.28,12.72zM16.24,14.37l1.94,1.47l-2.5,4.33l-2.24,-0.94c-0.2,0.13 -0.42,0.26 -0.64,0.37L12.5,22h-5l-0.3,-2.41c-0.22,-0.11 -0.43,-0.23 -0.64,-0.37l-2.24,0.94l-2.5,-4.33l1.94,-1.47C3.75,14.25 3.75,14.12 3.75,14s0,-0.25 0.01,-0.37l-1.94,-1.47l2.5,-4.33l2.24,0.94c0.2,-0.13 0.42,-0.26 0.64,-0.37L7.5,6h5l0.3,2.41c0.22,0.11 0.43,0.23 0.64,0.37l2.24,-0.94l2.5,4.33l-1.94,1.47c0.01,0.12 0.01,0.24 0.01,0.37S16.25,14.25 16.24,14.37zM13,14c0,-1.66 -1.34,-3 -3,-3s-3,1.34 -3,3s1.34,3 3,3S13,15.66 13,14z"/>
</vector>

View file

@ -91,6 +91,20 @@
app:layout_constraintTop_toTopOf="parent"
android:focusable="true" />
<com.google.android.material.chip.Chip
android:id="@+id/thumbnail"
style="@style/Widget.Material3.FloatingActionButton.Large.Primary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:minWidth="30dp"
app:chipIcon="@drawable/ic_image"
app:cornerRadius="10dp"
android:text="@string/thumbnail"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<com.google.android.material.chip.Chip
android:id="@+id/format_note"
style="@style/Widget.Material3.FloatingActionButton.Large.Primary"

View file

@ -24,7 +24,8 @@
android:id="@+id/subtitle_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
android:maxLines="10"
android:inputType="textMultiLine" />
</com.google.android.material.textfield.TextInputLayout>

View file

@ -41,5 +41,12 @@
<action
android:id="@+id/action_mainSettingsFragment_to_updateSettingsFragment"
app:destination="@id/updateSettingsFragment" />
<action
android:id="@+id/action_mainSettingsFragment_to_advancedSettingsFragment"
app:destination="@id/advancedSettingsFragment" />
</fragment>
<fragment
android:id="@+id/advancedSettingsFragment"
android:name="com.deniscerri.ytdl.ui.more.settings.AdvancedSettingsFragment"
android:label="AdvancedSettingsFragment" />
</navigation>

View file

@ -433,4 +433,7 @@
<string name="items">item(s)</string>
<string name="socket_timeout">Socket Timeout</string>
<string name="socket_timeout_description">Time to wait before giving up, in seconds</string>
<string name="advanced">Advanced</string>
<string name="data_fetching_extra_commands">Data Fetching Extra Commands</string>
<string name="thumbnail">Thumbnail</string>
</resources>

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<EditTextPreference
android:defaultValue="default,mediaconnect"
android:icon="@drawable/ic_code"
android:key="youtube_player_client"
app:useSimpleSummaryProvider="true"
android:title="Player Client" />
<EditTextPreference
android:defaultValue=""
android:icon="@drawable/ic_code"
android:key="youtube_po_token"
app:useSimpleSummaryProvider="true"
android:title="PO Token" />
<EditTextPreference
android:defaultValue=""
android:icon="@drawable/ic_code"
android:key="youtube_other_extractor_args"
app:useSimpleSummaryProvider="true"
android:title="@string/other_youtube_extractor_args" />
<EditTextPreference
android:defaultValue=""
android:icon="@drawable/ic_terminal"
android:key="data_fetching_extra_commands"
app:useSimpleSummaryProvider="true"
android:title="@string/data_fetching_extra_commands" />
</PreferenceScreen>

View file

@ -102,27 +102,6 @@
app:useSimpleSummaryProvider="true"
app:title="@string/format_source" />
<EditTextPreference
android:defaultValue="default,mediaconnect"
android:icon="@drawable/ic_code"
android:key="youtube_player_client"
app:useSimpleSummaryProvider="true"
android:title="Player Client" />
<EditTextPreference
android:defaultValue=""
android:icon="@drawable/ic_code"
android:key="youtube_po_token"
app:useSimpleSummaryProvider="true"
android:title="PO Token" />
<EditTextPreference
android:defaultValue=""
android:icon="@drawable/ic_code"
android:key="youtube_other_extractor_args"
app:useSimpleSummaryProvider="true"
android:title="@string/other_youtube_extractor_args" />
<Preference
android:icon="@drawable/ic_dns"
app:key="piped_instance"

View file

@ -26,6 +26,11 @@
app:icon="@drawable/ic_update"
android:title="@string/updating"/>
<Preference
android:key="advanced"
app:icon="@drawable/baseline_settings_suggest_24"
android:title="@string/advanced"/>
<PreferenceCategory android:title="@string/backup_restore">
<Preference
app:icon="@drawable/baseline_save_alt_24"