diff --git a/app/src/main/java/com/deniscerri/ytdlnis/database/viewmodel/ResultViewModel.kt b/app/src/main/java/com/deniscerri/ytdlnis/database/viewmodel/ResultViewModel.kt index e993ae0f..4e1bb084 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/database/viewmodel/ResultViewModel.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/database/viewmodel/ResultViewModel.kt @@ -93,12 +93,15 @@ class ResultViewModel(application: Application) : AndroidViewModel(application) else -> res.addAll(repository.getDefault(inputQuery, resetResults)) } } catch (e: Exception) { - uiState.update {it.copy( - processing = false, - errorMessage = Pair(R.string.no_results, e.message.toString()), - actions = mutableListOf(Pair(R.string.copy_log, ResultAction.COPY_LOG)) - )} - Log.e(tag, e.toString()) + if (e !is kotlinx.coroutines.CancellationException){ + uiState.update {it.copy( + processing = false, + errorMessage = Pair(R.string.no_results, e.message.toString()), + actions = mutableListOf(Pair(R.string.copy_log, ResultAction.COPY_LOG)) + )} + Log.e(tag, e.toString()) + } + } } uiState.update {it.copy(processing = false)} diff --git a/app/src/main/java/com/deniscerri/ytdlnis/receiver/ShareActivity.kt b/app/src/main/java/com/deniscerri/ytdlnis/receiver/ShareActivity.kt index 2ec6fc5c..18436b84 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/receiver/ShareActivity.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/receiver/ShareActivity.kt @@ -1,7 +1,6 @@ package com.deniscerri.ytdlnis.receiver import android.Manifest -import android.content.ComponentName import android.content.Context import android.content.DialogInterface import android.content.Intent @@ -17,30 +16,26 @@ import android.util.Log import android.util.Patterns import android.view.WindowManager import androidx.core.app.ActivityCompat -import androidx.core.content.IntentSanitizer import androidx.core.view.ViewCompat import androidx.core.view.WindowCompat import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope import androidx.navigation.NavController import androidx.navigation.NavDestination -import androidx.navigation.findNavController import androidx.navigation.fragment.NavHostFragment import androidx.navigation.fragment.findNavController import androidx.preference.PreferenceManager import com.deniscerri.ytdlnis.MainActivity import com.deniscerri.ytdlnis.R -import com.deniscerri.ytdlnis.database.models.DownloadItem -import com.deniscerri.ytdlnis.database.models.ResultItem import com.deniscerri.ytdlnis.database.viewmodel.CookieViewModel import com.deniscerri.ytdlnis.database.viewmodel.DownloadViewModel import com.deniscerri.ytdlnis.database.viewmodel.ResultViewModel import com.deniscerri.ytdlnis.ui.BaseActivity -import com.deniscerri.ytdlnis.ui.downloadcard.DownloadBottomSheetDialog -import com.deniscerri.ytdlnis.ui.downloadcard.SelectPlaylistItemsDialog import com.deniscerri.ytdlnis.util.ThemeUtil import com.google.android.material.dialog.MaterialAlertDialogBuilder +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -91,29 +86,6 @@ class ShareActivity : BaseActivity() { val intent = intent handleIntents(intent) } - - override fun onResume() { - super.onResume() - navController.addOnDestinationChangedListener(object: NavController.OnDestinationChangedListener{ - override fun onDestinationChanged( - controller: NavController, - destination: NavDestination, - arguments: Bundle? - ) { - if (navController.currentBackStack.value.isEmpty()) return - navController.removeOnDestinationChangedListener(this) - lifecycleScope.launch { - navController.currentBackStack.collectLatest { - if (it.isEmpty()){ - this@ShareActivity.finish() - } - } - } - - } - }) - } - override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) handleIntents(intent) @@ -124,6 +96,22 @@ class ShareActivity : BaseActivity() { val navHostFragment = supportFragmentManager.findFragmentById(R.id.frame_layout) as NavHostFragment navController = navHostFragment.findNavController() + navController.addOnDestinationChangedListener(object: NavController.OnDestinationChangedListener{ + override fun onDestinationChanged( + controller: NavController, + destination: NavDestination, + arguments: Bundle? + ) { + navController.removeOnDestinationChangedListener(this) + CoroutineScope(SupervisorJob()).launch { + navController.currentBackStack.collectLatest { + if (it.isEmpty()){ + this@ShareActivity.finish() + } + } + } + } + }) val action = intent.action Log.e("aa", intent.toString()) diff --git a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloads/HistoryFragment.kt b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloads/HistoryFragment.kt index a97a5f76..d2ccb095 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloads/HistoryFragment.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloads/HistoryFragment.kt @@ -81,7 +81,6 @@ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{ private var historyList: List? = null private var allhistoryList: List? = null private var selectedObjects: ArrayList? = null - private var _binding : FragmentHistoryBinding? = null private var actionMode : ActionMode? = null private lateinit var sortChip: Chip @@ -90,7 +89,6 @@ class HistoryFragment : Fragment(), HistoryAdapter.OnItemClickListener{ inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - _binding = FragmentHistoryBinding.inflate(inflater, container, false) fragmentView = inflater.inflate(R.layout.fragment_history, container, false) activity = getActivity() mainActivity = activity as MainActivity? diff --git a/app/src/main/java/com/deniscerri/ytdlnis/ui/more/downloadLogs/DownloadLogFragment.kt b/app/src/main/java/com/deniscerri/ytdlnis/ui/more/downloadLogs/DownloadLogFragment.kt index 5b311336..9bfbce0b 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/ui/more/downloadLogs/DownloadLogFragment.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/ui/more/downloadLogs/DownloadLogFragment.kt @@ -1,6 +1,7 @@ package com.deniscerri.ytdlnis.ui.more.downloadLogs import android.annotation.SuppressLint +import android.app.ActionBar import android.content.ClipboardManager import android.content.Context.CLIPBOARD_SERVICE import android.graphics.Color @@ -26,6 +27,7 @@ import androidx.lifecycle.lifecycleScope import com.deniscerri.ytdlnis.MainActivity import com.deniscerri.ytdlnis.R import com.deniscerri.ytdlnis.database.viewmodel.LogViewModel +import com.deniscerri.ytdlnis.util.UiUtil.enableTextHighlight import com.google.android.material.appbar.MaterialToolbar import com.google.android.material.bottomappbar.BottomAppBar import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton @@ -70,6 +72,7 @@ class DownloadLogFragment : Fragment() { content = view.findViewById(R.id.content) content.setTextIsSelectable(true) + content.layoutParams!!.width = ActionBar.LayoutParams.WRAP_CONTENT contentScrollView = view.findViewById(R.id.content_scrollview) val bottomAppBar = view.findViewById(R.id.bottomAppBar) @@ -100,41 +103,29 @@ class DownloadLogFragment : Fragment() { topAppBar.title = logItem.title } - //init syntax highlighter - val highlight = Highlight() - val highlightWatcher = HighlightTextWatcher() - - val schemes = listOf( - ColorScheme(Pattern.compile("([\"'])(?:\\\\1|.)*?\\1"), Color.parseColor("#FC8500")), - ColorScheme(Pattern.compile("yt-dlp"), Color.parseColor("#00FF00")), - ColorScheme(Pattern.compile("(https?://(?:www\\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|www\\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|https?://(?:www\\.|(?!www))[a-zA-Z0-9]+\\.[^\\s]{2,}|www\\.[a-zA-Z0-9]+\\.[^\\s]{2,})"), Color.parseColor("#b5942f")), - ColorScheme(Pattern.compile("\\d+(\\.\\d)?%"), Color.parseColor("#43a564")) - ) - - highlight.addScheme( - *schemes.map { it }.toTypedArray() - ) - highlightWatcher.addScheme( - *schemes.map { it }.toTypedArray() - ) - highlight.setSpan(content) content.isFocusable = true - content.addTextChangedListener(highlightWatcher) - content.setHorizontallyScrolling(false) + content.enableTextHighlight() bottomAppBar?.setOnMenuItemClickListener { m: MenuItem -> when(m.itemId){ R.id.wrap -> { - var scrollView = view.findViewById(R.id.horizontalscroll_output) + var scrollView = requireView().findViewById(R.id.horizontalscroll_output) if(scrollView != null){ val parent = (scrollView.parent as ViewGroup) scrollView.removeAllViews() parent.removeView(scrollView) parent.addView(content, 0) + contentScrollView.setPadding(0,0,0, + (requireContext().resources.displayMetrics.density * 150).toInt() + ) }else{ val parent = content.parent as ViewGroup parent.removeView(content) scrollView = HorizontalScrollView(requireContext()) + scrollView.setPadding(0,0,0, + (requireContext().resources.displayMetrics.density * 150).toInt() + ) + contentScrollView.setPadding(0,0,0,0) scrollView.layoutParams = LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT @@ -143,7 +134,6 @@ class DownloadLogFragment : Fragment() { scrollView.id = R.id.horizontalscroll_output parent.addView(scrollView, 0) } - content.setHorizontallyScrolling(!content.canScrollHorizontally(1)) } R.id.scroll_down -> { @@ -162,10 +152,16 @@ class DownloadLogFragment : Fragment() { logViewModel.getLogFlowByID(id!!).observe(viewLifecycleOwner){logItem -> - lifecycleScope.launch { - content.text = logItem.content - content.scrollTo(content.scrollX, content.height) - contentScrollView.fullScroll(View.FOCUS_DOWN) + kotlin.runCatching { + requireActivity().runOnUiThread{ + if (logItem != null){ + if (logItem.content.isNotBlank()) { + content.text = logItem.content + } + content.scrollTo(0, content.height) + contentScrollView.fullScroll(View.FOCUS_DOWN) + } + } } } } diff --git a/app/src/main/java/com/deniscerri/ytdlnis/ui/more/terminal/TerminalFragment.kt b/app/src/main/java/com/deniscerri/ytdlnis/ui/more/terminal/TerminalFragment.kt index 577c52c1..00bf8f43 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/ui/more/terminal/TerminalFragment.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/ui/more/terminal/TerminalFragment.kt @@ -192,7 +192,6 @@ class TerminalFragment : Fragment() { } output = view.findViewById(R.id.custom_command_output) - output!!.movementMethod = ScrollingMovementMethod() output!!.setTextIsSelectable(true) output!!.layoutParams!!.width = LayoutParams.WRAP_CONTENT input!!.requestFocus() @@ -222,7 +221,6 @@ class TerminalFragment : Fragment() { initMenu() input?.enableTextHighlight() - output?.enableTextHighlight() input?.append(bundle?.getString("input") ?: "") input!!.requestFocus() @@ -308,9 +306,7 @@ class TerminalFragment : Fragment() { output?.text = it.log } output?.scrollTo(0, output!!.height) - if (!scrollView!!.canScrollVertically(1) && !scrollView!!.canScrollHorizontally(-1)){ - scrollView?.fullScroll(View.FOCUS_DOWN) - } + scrollView?.fullScroll(View.FOCUS_DOWN) input!!.visibility = View.GONE showCancelFab() } diff --git a/app/src/main/java/com/deniscerri/ytdlnis/util/FileUtil.kt b/app/src/main/java/com/deniscerri/ytdlnis/util/FileUtil.kt index e49256e9..5f4309e0 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/util/FileUtil.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/util/FileUtil.kt @@ -87,7 +87,7 @@ object FileUtil { if (it.isDirectory && it.absolutePath == originDir.absolutePath) return@forEach var destFile: DocumentFile try { - if (it.name.matches("(^config.*.\\.txt\$)|(rList)|(.*.part-Frag)|(.*.live_chat)".toRegex())){ + if (it.name.matches("(^config.*.\\.txt\$)|(rList)|(.*.part-Frag.*)|(.*.live_chat)|(.*.ytdl)".toRegex())){ return@forEach } diff --git a/app/src/main/java/com/deniscerri/ytdlnis/util/InfoUtil.kt b/app/src/main/java/com/deniscerri/ytdlnis/util/InfoUtil.kt index 72eb3393..7460351c 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/util/InfoUtil.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/util/InfoUtil.kt @@ -112,10 +112,12 @@ class InfoUtil(private val context: Context) { val dataArray = res.getJSONArray("relatedStreams") var nextpage = res.getString("nextpage") for (i in 0 until dataArray.length()){ - val obj = dataArray.getJSONObject(i) - val itm = createVideoFromPipedJSON(obj, "https://youtube.com" + obj.getString("url")) - itm?.playlistTitle = res.getString("name") + "[${i+1}]" - items.add(itm) + kotlin.runCatching { + val obj = dataArray.getJSONObject(i) + val itm = createVideoFromPipedJSON(obj, "https://youtube.com" + obj.getString("url")) + itm?.playlistTitle = res.getString("name") + "[${i+1}]" + items.add(itm) + } } if (nextpage == "null") nextpage = "" return PlaylistTuple(nextpage, items) @@ -1398,19 +1400,21 @@ class InfoUtil(private val context: Context) { val audioFormats = resources.getStringArray(R.array.audio_formats) val formats = mutableListOf() val containerPreference = sharedPreferences.getString("audio_format", "") - audioFormats.reversed().forEach { formats.add(Format(it, containerPreference!!,"","", "",0, it)) } - audioFormatIDPreference.forEach { formats.add(Format(it, containerPreference!!,"","", "",1, it)) } + val acodecPreference = sharedPreferences.getString("audio_codec", "m4a|mp4a|aac") + audioFormats.reversed().forEach { formats.add(Format(it, containerPreference!!,"",acodecPreference!!, "",0, it)) } + audioFormatIDPreference.forEach { formats.add(Format(it, containerPreference!!,"",acodecPreference!!, "",1, it)) } return formats } fun getGenericVideoFormats(resources: Resources) : MutableList{ val formatIDPreference = sharedPreferences.getString("format_id", "").toString().split(",").filter { it.isNotEmpty() } - val videoFormats = resources.getStringArray(R.array.video_formats_values) val formats = mutableListOf() val containerPreference = sharedPreferences.getString("video_format", "") - videoFormats.reversed().forEach { formats.add(Format(it, containerPreference!!,"Default","", "",0, it.split("_")[0])) } - formatIDPreference.forEach { formats.add(Format(it, containerPreference!!,"Default","", "",1, it)) } + val acodecPreference = sharedPreferences.getString("audio_codec", "m4a|mp4a|aac") + val vcodecPreference = sharedPreferences.getString("video_codec", "avc|h264")!!.ifEmpty { resources.getString(R.string.defaultValue) } + videoFormats.reversed().forEach { formats.add(Format(it, containerPreference!!,vcodecPreference,acodecPreference!!, "",0, it.split("_")[0])) } + formatIDPreference.forEach { formats.add(Format(it, containerPreference!!,vcodecPreference,acodecPreference!!, "",1, it)) } return formats } diff --git a/app/src/main/java/com/deniscerri/ytdlnis/util/UiUtil.kt b/app/src/main/java/com/deniscerri/ytdlnis/util/UiUtil.kt index de221bdc..fae27a58 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/util/UiUtil.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/util/UiUtil.kt @@ -102,7 +102,7 @@ object UiUtil { val audioFormatsTextView = formatCard.findViewById(R.id.audio_formats) if (!audioFormats.isNullOrEmpty()) { - audioFormatsTextView.text = audioFormats.joinToString("+") { it.format_id } + audioFormatsTextView.text = "id: " + audioFormats.joinToString("+") { it.format_id } audioFormatsTextView.visibility = View.VISIBLE }else{ audioFormatsTextView.visibility = View.GONE diff --git a/app/src/main/res/layout/fragment_download_log.xml b/app/src/main/res/layout/fragment_download_log.xml index 2244e2f7..3d86e803 100644 --- a/app/src/main/res/layout/fragment_download_log.xml +++ b/app/src/main/res/layout/fragment_download_log.xml @@ -23,34 +23,48 @@ - + android:layout_height="match_parent"> - + + + + + + + + + - + diff --git a/app/src/main/res/layout/fragment_history.xml b/app/src/main/res/layout/fragment_history.xml index df3ce7a7..b38d564a 100644 --- a/app/src/main/res/layout/fragment_history.xml +++ b/app/src/main/res/layout/fragment_history.xml @@ -122,7 +122,9 @@ android:visibility="gone" /> - \ No newline at end of file diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 22f30366..95e82d9d 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -308,7 +308,7 @@ 스케쥴 사용자 에이전트 헤더 명령어로 검색 - 건너뜀 + 건너뜀 라이선스 아직도 다운로드하시겠습니까\? 다운로드 카드 수정 diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index ae426640..1882191b 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -308,7 +308,7 @@ Harmonogram Nagłówek User-Agent Szukaj z poleceń - Pomiń + Pomiń Licencja Czy nadal chcesz pobrać\? Modyfikowanie karty pobierania diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 8e7cdc55..d486987b 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -309,7 +309,7 @@ Selecionar o último tipo de download aberto para o item atual Agendar Pesquisar com comandos - Saltar + Saltar Licença Ainda queres descarregar\? Modificar o cartão de descarregamento diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index c13e5c91..ab8d466f 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -116,6 +116,7 @@ fr hi hr + hu in it ja @@ -132,6 +133,7 @@ ru ro sk + sr sq ta te @@ -826,9 +828,9 @@ %(title)s___(string): Video title) %(id)s___(string): Video identifier) %(fulltitle)s___(string): Video title ignoring live timestamp and generic title) - %(ext)s___(string): Video filename extension) + %(alt_title)s___(string): A secondary title of the video) - %(description)s___(string): The description of the video) + %(display_id)s___(string): An alternative identifier for the video) %(license)s___(string): License name the video is licensed under) %(creator)s___(string): The creator of the video) @@ -841,7 +843,7 @@ %(uploader_id)s___(string): Nickname or id of the video uploader) %(channel)s___(string): Full name of the channel the video is uploaded on) %(channel_id)s___(string): Id of the channel) - %(channel_follower_count)s___(numeric): Number of followers of the channel) + %(channel_is_verified)s___(boolean): Whether the channel is verified on the platform) %(location)s___(string): Physical location where the video was filmed) %(duration)s___(numeric): Length of the video in seconds) diff --git a/app/src/main/res/xml/locales_config.xml b/app/src/main/res/xml/locales_config.xml index 5acf8537..aedc970d 100644 --- a/app/src/main/res/xml/locales_config.xml +++ b/app/src/main/res/xml/locales_config.xml @@ -13,6 +13,7 @@ + @@ -29,6 +30,7 @@ +