add preference to disable text color highlight

This commit is contained in:
deniscerri 2025-03-01 12:30:47 +01:00
parent 85352bad91
commit 5697d1b4f4
No known key found for this signature in database
GPG key ID: 95C43D517D830350
17 changed files with 46 additions and 14 deletions

View file

@ -93,8 +93,12 @@ class AddExtraCommandsDialog(private val item: DownloadItem? = null, private val
view.findViewById<View>(R.id.current).visibility = View.GONE view.findViewById<View>(R.id.current).visibility = View.GONE
} }
text.enableTextHighlight() if (sharedPreferences.getBoolean("use_code_color_highlighter", true)) {
currentText.enableTextHighlight() text.enableTextHighlight()
currentText.enableTextHighlight()
}
text?.setText(item?.extraCommands) text?.setText(item?.extraCommands)
val imm = activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager val imm = activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager

View file

@ -104,7 +104,9 @@ class DownloadCommandFragment(private val resultItem: ResultItem? = null, privat
val chosenCommandView = view.findViewById<TextInputLayout>(R.id.content) val chosenCommandView = view.findViewById<TextInputLayout>(R.id.content)
chosenCommandView.editText?.setText(downloadItem.format.format_note) chosenCommandView.editText?.setText(downloadItem.format.format_note)
chosenCommandView.editText?.enableTextHighlight() if (preferences.getBoolean("use_code_color_highlighter", true)) {
chosenCommandView.editText?.enableTextHighlight()
}
chosenCommandView.endIconDrawable = AppCompatResources.getDrawable(requireContext(), R.drawable.ic_delete_all) chosenCommandView.endIconDrawable = AppCompatResources.getDrawable(requireContext(), R.drawable.ic_delete_all)
chosenCommandView.editText!!.addTextChangedListener(object : TextWatcher { chosenCommandView.editText!!.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {} override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}

View file

@ -168,7 +168,7 @@ class DownloadsAlreadyExistDialog : BottomSheetDialogFragment(), AlreadyExistsAd
val historyItem = withContext(Dispatchers.IO){ val historyItem = withContext(Dispatchers.IO){
downloadViewModel.getHistoryItemById(historyItemID) downloadViewModel.getHistoryItemById(historyItemID)
} }
UiUtil.showHistoryItemDetailsCard(historyItem, requireActivity(), isPresent = true, UiUtil.showHistoryItemDetailsCard(historyItem, requireActivity(), isPresent = true, preferences,
removeItem = { item, deleteFile -> removeItem = { item, deleteFile ->
historyViewModel.delete(item, deleteFile) historyViewModel.delete(item, deleteFile)
}, },

View file

@ -450,6 +450,7 @@ class ResultCardDetailsDialog : BottomSheetDialogFragment(), GenericDownloadAdap
requireActivity(), requireActivity(),
DownloadRepository.Status.valueOf(item.status), DownloadRepository.Status.valueOf(item.status),
ytdlpViewModel, ytdlpViewModel,
sharedPreferences,
removeItem = { it: DownloadItem, sheet: BottomSheetDialog -> removeItem = { it: DownloadItem, sheet: BottomSheetDialog ->
sheet.hide() sheet.hide()
removeQueuedItem(itemID) removeQueuedItem(itemID)

View file

@ -178,6 +178,7 @@ class CancelledDownloadsFragment : Fragment(), GenericDownloadAdapter.OnItemClic
requireActivity(), requireActivity(),
DownloadRepository.Status.valueOf(item.status), DownloadRepository.Status.valueOf(item.status),
ytdlpViewModel, ytdlpViewModel,
preferences,
removeItem = { it: DownloadItem, sheet: BottomSheetDialog -> removeItem = { it: DownloadItem, sheet: BottomSheetDialog ->
removeItem(it, sheet) removeItem(it, sheet)
}, },

View file

@ -178,6 +178,7 @@ class ErroredDownloadsFragment : Fragment(), GenericDownloadAdapter.OnItemClickL
requireActivity(), requireActivity(),
DownloadRepository.Status.valueOf(item.status), DownloadRepository.Status.valueOf(item.status),
ytdlpViewModel, ytdlpViewModel,
preferences,
removeItem = { it: DownloadItem, sheet: BottomSheetDialog -> removeItem = { it: DownloadItem, sheet: BottomSheetDialog ->
removeItem(it, sheet) removeItem(it, sheet)

View file

@ -506,7 +506,7 @@ class HistoryFragment : Fragment(), HistoryPaginatedAdapter.OnItemClickListener{
historyViewModel.getByID(itemID) historyViewModel.getByID(itemID)
} }
UiUtil.showHistoryItemDetailsCard(item, requireActivity(), filePresent, UiUtil.showHistoryItemDetailsCard(item, requireActivity(), filePresent, sharedPreferences,
removeItem = { it, deleteFile -> removeItem = { it, deleteFile ->
historyViewModel.delete(it, deleteFile) historyViewModel.delete(it, deleteFile)
}, },

View file

@ -454,6 +454,7 @@ class QueuedDownloadsFragment : Fragment(), QueuedDownloadAdapter.OnItemClickLis
requireActivity(), requireActivity(),
DownloadRepository.Status.valueOf(item.status), DownloadRepository.Status.valueOf(item.status),
ytdlpViewModel, ytdlpViewModel,
sharedPreferences,
removeItem = { it: DownloadItem, sheet: BottomSheetDialog -> removeItem = { it: DownloadItem, sheet: BottomSheetDialog ->
sheet.hide() sheet.hide()
removeItem(it.id) removeItem(it.id)

View file

@ -187,6 +187,7 @@ class SavedDownloadsFragment : Fragment(), GenericDownloadAdapter.OnItemClickLis
requireActivity(), requireActivity(),
DownloadRepository.Status.valueOf(item.status), DownloadRepository.Status.valueOf(item.status),
ytdlpViewModel, ytdlpViewModel,
preferences,
removeItem = { it: DownloadItem, sheet: BottomSheetDialog -> removeItem = { it: DownloadItem, sheet: BottomSheetDialog ->
removeItem(it, sheet) removeItem(it, sheet)
}, },

View file

@ -183,6 +183,7 @@ class ScheduledDownloadsFragment : Fragment(), ScheduledDownloadAdapter.OnItemCl
requireActivity(), requireActivity(),
DownloadRepository.Status.valueOf(item.status), DownloadRepository.Status.valueOf(item.status),
ytdlpViewModel, ytdlpViewModel,
preferences,
removeItem = { it: DownloadItem, sheet: BottomSheetDialog -> removeItem = { it: DownloadItem, sheet: BottomSheetDialog ->
sheet.hide() sheet.hide()
removeItem(it, sheet) removeItem(it, sheet)

View file

@ -190,7 +190,9 @@ class CookiesFragment : Fragment(), CookieAdapter.OnItemClickListener {
item?.apply { item?.apply {
current.findViewById<TextView>(R.id.currentText).apply { current.findViewById<TextView>(R.id.currentText).apply {
setText(item.content) setText(item.content)
enableTextHighlight() if (preferences.getBoolean("use_code_color_highlighter", true)) {
enableTextHighlight()
}
} }
} }

View file

@ -126,7 +126,9 @@ class DownloadLogFragment : Fragment() {
lifecycleScope.launch(Dispatchers.IO){ lifecycleScope.launch(Dispatchers.IO){
content.isFocusable = true content.isFocusable = true
content.enableTextHighlight() if (sharedPreferences.getBoolean("use_code_color_highlighter", true)) {
content.enableTextHighlight()
}
} }
contentScrollView.enableFastScroll() contentScrollView.enableFastScroll()

View file

@ -227,7 +227,11 @@ class TerminalFragment : Fragment() {
notificationUtil = NotificationUtil(requireContext()) notificationUtil = NotificationUtil(requireContext())
initMenu() initMenu()
input?.enableTextHighlight() lifecycleScope.launch(Dispatchers.IO) {
if (sharedPreferences.getBoolean("use_code_color_highlighter", true)) {
input?.enableTextHighlight()
}
}
input?.append(bundle?.getString("input") ?: "") input?.append(bundle?.getString("input") ?: "")
input!!.requestFocus() input!!.requestFocus()

View file

@ -66,14 +66,14 @@ class FormatUtil(private var context: Context) {
val orderPreferences = sharedPreferences.getString("format_importance_video", itemValues.joinToString(","))!!.split(",").toMutableList() val orderPreferences = sharedPreferences.getString("format_importance_video", itemValues.joinToString(","))!!.split(",").toMutableList()
if (preferSmallerFormats) { if (preferSmallerFormats) {
orderPreferences.remove("file_size") orderPreferences.remove("file_size")
orderPreferences.add(0, "smallsize") orderPreferences.add("smallsize")
} }
return orderPreferences return orderPreferences
}else { }else {
val formatImportance = mutableListOf("resolution", "codec", "container") val formatImportance = mutableListOf("resolution", "codec", "container")
if (sharedPreferences.getBoolean("prefer_smaller_formats", false)) { if (sharedPreferences.getBoolean("prefer_smaller_formats", false)) {
formatImportance.add(0, "smallsize") formatImportance.add("smallsize")
} }
return formatImportance return formatImportance

View file

@ -533,6 +533,7 @@ object UiUtil {
context: Activity, context: Activity,
status: DownloadRepository.Status, status: DownloadRepository.Status,
ytdlpViewModel: YTDLPViewModel, ytdlpViewModel: YTDLPViewModel,
preferences: SharedPreferences,
removeItem : (DownloadItem, BottomSheetDialog) -> Unit, removeItem : (DownloadItem, BottomSheetDialog) -> Unit,
downloadItem: (DownloadItem) -> Unit, downloadItem: (DownloadItem) -> Unit,
longClickDownloadButton: (DownloadItem) -> Unit, longClickDownloadButton: (DownloadItem) -> Unit,
@ -642,7 +643,7 @@ object UiUtil {
else fileSize!!.text = fileSizeReadable else fileSize!!.text = fileSizeReadable
command?.setOnClickListener { command?.setOnClickListener {
showGeneratedCommand(context, ytdlpViewModel.parseYTDLRequestString(item)) showGeneratedCommand(context, preferences, ytdlpViewModel.parseYTDLRequestString(item))
} }
val link = bottomSheet.findViewById<Button>(R.id.bottom_sheet_link) val link = bottomSheet.findViewById<Button>(R.id.bottom_sheet_link)
@ -736,6 +737,7 @@ object UiUtil {
item: HistoryItem?, item: HistoryItem?,
context: Activity, context: Activity,
isPresent: Boolean, isPresent: Boolean,
preferences: SharedPreferences,
removeItem: (item:HistoryItem, removeFiles: Boolean) -> Unit, removeItem: (item:HistoryItem, removeFiles: Boolean) -> Unit,
redownloadItem: (HistoryItem) -> Unit, redownloadItem: (HistoryItem) -> Unit,
redownloadShowDownloadCard: (HistoryItem) -> Unit, redownloadShowDownloadCard: (HistoryItem) -> Unit,
@ -861,7 +863,7 @@ object UiUtil {
else fileSize!!.text = fileSizeReadable else fileSize!!.text = fileSizeReadable
command?.setOnClickListener { command?.setOnClickListener {
showGeneratedCommand(context, item.command) showGeneratedCommand(context, preferences, item.command)
} }
val availableFiles = item.downloadPath.filter { FileUtil.exists(it) } val availableFiles = item.downloadPath.filter { FileUtil.exists(it) }
@ -2094,7 +2096,7 @@ object UiUtil {
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).gravity = Gravity.START dialog.getButton(AlertDialog.BUTTON_NEUTRAL).gravity = Gravity.START
} }
private fun showGeneratedCommand(context: Activity, command: String){ private fun showGeneratedCommand(context: Activity, preferences: SharedPreferences, command: String) {
val builder = MaterialAlertDialogBuilder(context) val builder = MaterialAlertDialogBuilder(context)
builder.setTitle(context.getString(R.string.command)) builder.setTitle(context.getString(R.string.command))
val view = context.layoutInflater.inflate(R.layout.command_dialog, null) val view = context.layoutInflater.inflate(R.layout.command_dialog, null)
@ -2102,7 +2104,9 @@ object UiUtil {
text = command text = command
isLongClickable = true isLongClickable = true
setTextIsSelectable(true) setTextIsSelectable(true)
enableTextHighlight() if (preferences.getBoolean("use_code_color_highlighter", true)) {
enableTextHighlight()
}
setPadding(20, 0, 20, 0) setPadding(20, 0, 20, 0)
} }

View file

@ -465,4 +465,5 @@
<string name="cache_directory_warning">Changing the Cache Folder might cause unexpected issues. If the app cannot write to the configured path, it will resort to the default internal cache directory</string> <string name="cache_directory_warning">Changing the Cache Folder might cause unexpected issues. If the app cannot write to the configured path, it will resort to the default internal cache directory</string>
<string name="app_icon_change">Icon could change and Application will close</string> <string name="app_icon_change">Icon could change and Application will close</string>
<string name="use_format_sorting">Use Format Importance Ordering</string> <string name="use_format_sorting">Use Format Importance Ordering</string>
<string name="use_code_highlighter">Use Code Color Highlighter</string>
</resources> </resources>

View file

@ -190,6 +190,13 @@
android:key="swipe_gestures_download_card" android:key="swipe_gestures_download_card"
app:title="@string/swipe_gestures_download_card" /> app:title="@string/swipe_gestures_download_card" />
<SwitchPreferenceCompat
android:widgetLayout="@layout/preferece_material_switch"
app:defaultValue="true"
android:icon="@drawable/baseline_color_lens_24"
android:key="use_code_color_highlighter"
app:title="@string/use_code_highlighter" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:widgetLayout="@layout/preferece_material_switch" android:widgetLayout="@layout/preferece_material_switch"
app:defaultValue="false" app:defaultValue="false"