This commit is contained in:
zaednasr 2023-11-14 21:15:50 +01:00
parent 604ae15055
commit 1451e6755f
No known key found for this signature in database
GPG key ID: 92B1DE23AD3D0E9E
12 changed files with 86 additions and 51 deletions

View file

@ -96,13 +96,12 @@
</activity> </activity>
<activity <activity
android:name=".ui.more.terminal.TerminalActivity" android:name=".ui.more.terminal.TerminalActivity"
android:configChanges="smallestScreenSize|layoutDirection|locale|orientation|screenSize" android:configChanges="smallestScreenSize|layoutDirection|orientation|screenSize"
android:exported="true" android:exported="true"
android:label="@string/terminal" android:label="@string/terminal"
android:parentActivityName=".MainActivity"> android:parentActivityName=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="ytdlnis.TerminalActivity" /> <action android:name="ytdlnis.TerminalActivity" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity>
@ -110,6 +109,7 @@
<activity-alias <activity-alias
android:name=".terminalShareAlias" android:name=".terminalShareAlias"
android:targetActivity=".ui.more.terminal.TerminalActivity" android:targetActivity=".ui.more.terminal.TerminalActivity"
android:configChanges="smallestScreenSize|layoutDirection|orientation|screenSize"
android:enabled="false" android:enabled="false"
android:icon="@mipmap/terminal_icon" android:icon="@mipmap/terminal_icon"
android:roundIcon="@mipmap/terminal_icon_round" android:roundIcon="@mipmap/terminal_icon_round"

View file

@ -27,6 +27,7 @@ import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavDestination
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
@ -634,7 +635,9 @@ class HomeFragment : Fragment(), HomeAdapter.OnItemClickListener, OnClickListene
resultItem: ResultItem, resultItem: ResultItem,
type: DownloadViewModel.Type type: DownloadViewModel.Type
){ ){
if(findNavController().currentBackStack.value.firstOrNull {it.destination.id == R.id.downloadBottomSheetDialog} == null){ if(findNavController().currentBackStack.value.firstOrNull {it.destination.id == R.id.downloadBottomSheetDialog} == null &&
findNavController().currentDestination?.id == R.id.homeFragment
){
//show the fragment if its not in the backstack //show the fragment if its not in the backstack
val bundle = Bundle() val bundle = Bundle()
bundle.putParcelable("result", resultItem) bundle.putParcelable("result", resultItem)

View file

@ -54,16 +54,17 @@ class ActiveDownloadsFragment : Fragment(), ActiveDownloadAdapter.OnItemClickLis
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
fragmentView = inflater.inflate(R.layout.fragment_active, container, false) fragmentView = inflater.inflate(R.layout.fragment_active, container, false)
activity = getActivity()
notificationUtil = NotificationUtil(requireContext())
downloadViewModel = ViewModelProvider(this)[DownloadViewModel::class.java]
workManager = WorkManager.getInstance(requireContext())
return fragmentView return fragmentView
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
activity = getActivity()
notificationUtil = NotificationUtil(requireContext())
downloadViewModel = ViewModelProvider(this)[DownloadViewModel::class.java]
workManager = WorkManager.getInstance(requireContext())
activeDownloads = activeDownloads =
ActiveDownloadAdapter( ActiveDownloadAdapter(
this, this,
@ -250,7 +251,7 @@ class ActiveDownloadsFragment : Fragment(), ActiveDownloadAdapter.OnItemClickLis
} }
override fun onOutputClick(item: DownloadItem) { override fun onOutputClick(item: DownloadItem) {
if (item.logID != null) { if (item.logID != null && item.logID != 0L) {
val bundle = Bundle() val bundle = Bundle()
bundle.putLong("logID", item.logID!!) bundle.putLong("logID", item.logID!!)
findNavController().navigate( findNavController().navigate(

View file

@ -1,9 +1,13 @@
package com.deniscerri.ytdlnis.ui.downloads package com.deniscerri.ytdlnis.ui.downloads
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.adapter.FragmentStateAdapter
import com.deniscerri.ytdlnis.ui.downloadcard.DownloadAudioFragment
import com.deniscerri.ytdlnis.ui.downloadcard.DownloadCommandFragment
import com.deniscerri.ytdlnis.ui.downloadcard.DownloadVideoFragment
class DownloadListFragmentAdapter ( class DownloadListFragmentAdapter (
fragmentManager : FragmentManager, fragmentManager : FragmentManager,

View file

@ -59,13 +59,6 @@ class GeneralSettingsFragment : BaseSettingsFragment() {
locale = findPreference("locale") locale = findPreference("locale")
showTerminalShareIcon = findPreference("show_terminal") showTerminalShareIcon = findPreference("show_terminal")
val values = resources.getStringArray(R.array.language_values)
val entries = mutableListOf<String>()
values.forEach {
entries.add(Locale(it).getDisplayName(Locale(it)))
}
language!!.entries = entries.toTypedArray()
if(language!!.value == null) language!!.value = Locale.getDefault().language if(language!!.value == null) language!!.value = Locale.getDefault().language
language!!.onPreferenceChangeListener = language!!.onPreferenceChangeListener =

View file

@ -35,15 +35,7 @@ class NotificationUtil(var context: Context) {
private val commandDownloadNotificationBuilder: NotificationCompat.Builder = NotificationCompat.Builder(context, COMMAND_DOWNLOAD_SERVICE_CHANNEL_ID) private val commandDownloadNotificationBuilder: NotificationCompat.Builder = NotificationCompat.Builder(context, COMMAND_DOWNLOAD_SERVICE_CHANNEL_ID)
private val finishedDownloadNotificationBuilder: NotificationCompat.Builder = NotificationCompat.Builder(context, DOWNLOAD_FINISHED_CHANNEL_ID) private val finishedDownloadNotificationBuilder: NotificationCompat.Builder = NotificationCompat.Builder(context, DOWNLOAD_FINISHED_CHANNEL_ID)
private val notificationManager: NotificationManager = context.getSystemService(NotificationManager::class.java) private val notificationManager: NotificationManager = context.getSystemService(NotificationManager::class.java)
private val resources: Resources private val resources: Resources = context.resources
private var sharedPreferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
init {
val confTmp = Configuration(context.resources.configuration)
confTmp.setLocale(Locale(sharedPreferences.getString("app_language", "en")!!))
val metrics = DisplayMetrics()
resources = Resources(context.assets, metrics, confTmp)
}
fun createNotificationChannel() { fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@ -199,16 +191,17 @@ class NotificationUtil(var context: Context) {
fun createDownloadFinished( fun createDownloadFinished(
title: String?, title: String?,
filepath: List<String>? filepath: List<String>?,
res: Resources
) { ) {
val notificationBuilder = getBuilder(DOWNLOAD_FINISHED_CHANNEL_ID) val notificationBuilder = getBuilder(DOWNLOAD_FINISHED_CHANNEL_ID)
notificationBuilder notificationBuilder
.setContentTitle("${resources.getString(R.string.downloaded)} $title") .setContentTitle("${res.getString(R.string.downloaded)} $title")
.setSmallIcon(R.drawable.ic_launcher_foreground_large) .setSmallIcon(R.drawable.ic_launcher_foreground_large)
.setLargeIcon( .setLargeIcon(
BitmapFactory.decodeResource( BitmapFactory.decodeResource(
resources, res,
R.drawable.ic_launcher_foreground_large R.drawable.ic_launcher_foreground_large
) )
) )
@ -259,8 +252,8 @@ class NotificationUtil(var context: Context) {
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
) )
notificationBuilder.addAction(0, resources.getString(R.string.Open_File), openNotificationPendingIntent) notificationBuilder.addAction(0, res.getString(R.string.Open_File), openNotificationPendingIntent)
notificationBuilder.addAction(0, resources.getString(R.string.share), shareNotificationPendingIntent) notificationBuilder.addAction(0, res.getString(R.string.share), shareNotificationPendingIntent)
}catch (_: Exception){} }catch (_: Exception){}
} }
notificationManager.notify(DOWNLOAD_FINISHED_NOTIFICATION_ID, notificationBuilder.build()) notificationManager.notify(DOWNLOAD_FINISHED_NOTIFICATION_ID, notificationBuilder.build())
@ -269,9 +262,9 @@ class NotificationUtil(var context: Context) {
fun createDownloadErrored(title: String?, fun createDownloadErrored(title: String?,
error: String?, error: String?,
logID: Long?, logID: Long?,
channel: String res: Resources
) { ) {
val notificationBuilder = getBuilder(channel) val notificationBuilder = getBuilder(DOWNLOAD_FINISHED_CHANNEL_ID)
val bundle = Bundle() val bundle = Bundle()
if (logID != null){ if (logID != null){
@ -294,12 +287,12 @@ class NotificationUtil(var context: Context) {
.createPendingIntent() .createPendingIntent()
notificationBuilder notificationBuilder
.setContentTitle("${resources.getString(R.string.failed_download)}: $title") .setContentTitle("${res.getString(R.string.failed_download)}: $title")
.setContentText(error) .setContentText(error)
.setSmallIcon(R.drawable.ic_launcher_foreground_large) .setSmallIcon(R.drawable.ic_launcher_foreground_large)
.setLargeIcon( .setLargeIcon(
BitmapFactory.decodeResource( BitmapFactory.decodeResource(
resources, res,
R.drawable.ic_launcher_foreground_large R.drawable.ic_launcher_foreground_large
) )
) )
@ -309,7 +302,7 @@ class NotificationUtil(var context: Context) {
.clearActions() .clearActions()
if (logID != null){ if (logID != null){
notificationBuilder.setContentIntent(errorPendingIntent) notificationBuilder.setContentIntent(errorPendingIntent)
notificationBuilder.addAction(0, resources.getString(R.string.logs), errorPendingIntent) notificationBuilder.addAction(0, res.getString(R.string.logs), errorPendingIntent)
} }
notificationManager.notify(DOWNLOAD_FINISHED_NOTIFICATION_ID, notificationBuilder.build()) notificationManager.notify(DOWNLOAD_FINISHED_NOTIFICATION_ID, notificationBuilder.build())
} }

View file

@ -178,13 +178,6 @@ class UpdateUtil(var context: Context) {
val sharedPreferences = val sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(context) PreferenceManager.getDefaultSharedPreferences(context)
if (updatingYTDL) { if (updatingYTDL) {
withContext(Dispatchers.Main){
Toast.makeText(
context,
context.getString(R.string.ytdl_already_updating),
Toast.LENGTH_LONG
).show()
}
UpdateStatus.ALREADY_UP_TO_DATE UpdateStatus.ALREADY_UP_TO_DATE
} }
updatingYTDL = true updatingYTDL = true

View file

@ -64,7 +64,7 @@ class DownloadWorker(
if (currentWork.count{it.state == WorkInfo.State.RUNNING} > 1) return Result.success() if (currentWork.count{it.state == WorkInfo.State.RUNNING} > 1) return Result.success()
val confTmp = Configuration(context.resources.configuration) val confTmp = Configuration(context.resources.configuration)
val currLang = sharedPreferences.getString("app_language", "en")!!.split("-") val currLang = sharedPreferences.getString("app_language", "")!!.ifEmpty { Locale.getDefault().language }.split("-")
confTmp.setLocale(if (currLang.size == 1) Locale(currLang[0]) else Locale(currLang[0], currLang[1])) confTmp.setLocale(if (currLang.size == 1) Locale(currLang[0]) else Locale(currLang[0], currLang[1]))
val metrics = DisplayMetrics() val metrics = DisplayMetrics()
val resources = Resources(context.assets, metrics, confTmp) val resources = Resources(context.assets, metrics, confTmp)
@ -221,7 +221,7 @@ class DownloadWorker(
notificationUtil.cancelDownloadNotification(downloadItem.id.toInt()) notificationUtil.cancelDownloadNotification(downloadItem.id.toInt())
notificationUtil.createDownloadFinished( notificationUtil.createDownloadFinished(
downloadItem.title, if (finalPaths?.first().equals(context.getString(R.string.unfound_file))) null else finalPaths downloadItem.title, if (finalPaths?.first().equals(context.getString(R.string.unfound_file))) null else finalPaths, resources
) )
if (wasQuickDownloaded){ if (wasQuickDownloaded){
@ -282,7 +282,7 @@ class DownloadWorker(
notificationUtil.createDownloadErrored( notificationUtil.createDownloadErrored(
downloadItem.title.ifEmpty { downloadItem.url }, it.message, downloadItem.title.ifEmpty { downloadItem.url }, it.message,
downloadItem.logID, downloadItem.logID,
NotificationUtil.DOWNLOAD_FINISHED_CHANNEL_ID resources
) )
setProgressAsync(workDataOf("progress" to 100, "output" to it.toString(), "id" to downloadItem.id)) setProgressAsync(workDataOf("progress" to 100, "output" to it.toString(), "id" to downloadItem.id))

View file

@ -48,10 +48,7 @@
android:name="com.deniscerri.ytdlnis.ui.more.MoreFragment" android:name="com.deniscerri.ytdlnis.ui.more.MoreFragment"
android:label="More" android:label="More"
tools:layout="@layout/fragment_more" > tools:layout="@layout/fragment_more" >
<action <action
android:id="@+id/action_moreFragment_to_terminalActivity"
app:destination="@id/terminalActivity" />
<action
android:id="@+id/action_moreFragment_to_settingsActivity2" android:id="@+id/action_moreFragment_to_settingsActivity2"
app:destination="@id/activitySettings" /> app:destination="@id/activitySettings" />
<action <action
@ -69,6 +66,9 @@
<action <action
android:id="@+id/action_moreFragment_to_settingsNav" android:id="@+id/action_moreFragment_to_settingsNav"
app:destination="@id/settingsNav" /> app:destination="@id/settingsNav" />
<action
android:id="@+id/action_moreFragment_to_terminalActivity"
app:destination="@id/terminalActivity" />
</fragment> </fragment>
<activity <activity
android:id="@+id/terminalActivity" android:id="@+id/terminalActivity"
@ -89,7 +89,11 @@
android:id="@+id/downloadQueueMainFragment" android:id="@+id/downloadQueueMainFragment"
android:name="com.deniscerri.ytdlnis.ui.downloads.DownloadQueueMainFragment" android:name="com.deniscerri.ytdlnis.ui.downloads.DownloadQueueMainFragment"
tools:layout="@layout/fragment_download_queue_main_screen" tools:layout="@layout/fragment_download_queue_main_screen"
android:label="DownloadQueueMainFragment" /> android:label="DownloadQueueMainFragment" >
<action
android:id="@+id/action_downloadQueueMainFragment_to_downloadLogFragment"
app:destination="@id/downloadLogFragment" />
</fragment>
<fragment <fragment
android:id="@+id/downloadLogListFragment" android:id="@+id/downloadLogListFragment"
android:name="com.deniscerri.ytdlnis.ui.more.downloadLogs.DownloadLogListFragment" android:name="com.deniscerri.ytdlnis.ui.more.downloadLogs.DownloadLogListFragment"

View file

@ -6,7 +6,7 @@
<fragment <fragment
android:id="@+id/terminalDownloadsListFragment" android:id="@+id/terminalDownloadsListFragment"
android:name="com.deniscerri.ytdlnis.ui.more.terminal.TerminalDownloadsListFragment" android:name="com.deniscerri.ytdlnis.ui.more.terminal.TerminalDownloadsListFragment"
tools:layout="@layout/fragment_terminal_downloadList" tools:layout="@layout/fragment_terminal_download_list"
android:label="TerminalDownloadsListFragment" > android:label="TerminalDownloadsListFragment" >
<action <action
android:id="@+id/action_terminalDownloadsListFragment_to_terminalFragment2" android:id="@+id/action_terminalDownloadsListFragment_to_terminalFragment2"

View file

@ -102,6 +102,50 @@
<item>music_offtopic</item> <item>music_offtopic</item>
</string-array> </string-array>
<string-array name="language_entries">
<item>English</item>
<item>العربية</item>
<item>Azərbaycanca</item>
<item>বাংলা</item>
<item>বাংলা (India)</item>
<item>Босански</item>
<item>Deutsch</item>
<item>Ἑλληνική</item>
<item>Español</item>
<item>فارسی</item>
<item>Français</item>
<item>हिन्दी</item>
<item>Hrvatski</item>
<item>Magyar</item>
<item>Bahasa Indonesia</item>
<item>Italiano</item>
<item>日本語</item>
<item>ꦧꦱꦗꦮ</item>
<item>조선말</item>
<item>latviešu</item>
<item>بهاس ملايو</item>
<item>Norsk Bokmål</item>
<item>Norsk Nynorsk</item>
<item>पंजाबी</item>
<item>polski</item>
<item>Português</item>
<item>Português Brazil</item>
<item>Русский</item>
<item>Română</item>
<item>Slovenčina</item>
<item>Српски</item>
<item>Shqip</item>
<item>தமிழ்</item>
<item>తెలుగు</item>
<item>ภาษาไทย</item>
<item>Türkçe</item>
<item>தமிழ்</item>
<item>Українська</item>
<item>Tiếng Việt Nam</item>
<item>中文</item>
</string-array>
<string-array name="language_values"> <string-array name="language_values">
<item>en</item> <item>en</item>
<item>ar</item> <item>ar</item>

View file

@ -4,7 +4,7 @@
<PreferenceCategory android:title="@string/appearance"> <PreferenceCategory android:title="@string/appearance">
<ListPreference <ListPreference
android:entries="@array/language_values" android:entries="@array/language_entries"
android:entryValues="@array/language_values" android:entryValues="@array/language_values"
android:defaultValue="" android:defaultValue=""
android:icon="@drawable/baseline_translate_24" android:icon="@drawable/baseline_translate_24"