From 444f0cc582e943ed445e377121c10f5225539f3a Mon Sep 17 00:00:00 2001 From: deniscerri <64997243+deniscerri@users.noreply.github.com> Date: Sun, 30 Jul 2023 16:20:09 +0200 Subject: [PATCH] FIXES 1.The videos are not visible on the home screen, but they are visible on the same server in libretube. 2.Open download card late on YouTube. 3.When you enter the end time or a higher value there and confirm, the application is closed and the error.. 4.The home page player and cut player do not open. When the cut player opens, the video often stops 5.The cutting player does not do its work exactly. --- app/build.gradle | 2 +- .../database/viewmodel/DownloadViewModel.kt | 27 +++++++--- .../CancelDownloadNotificationReceiver.kt | 18 ++++--- .../PauseDownloadNotificationReceiver.kt | 12 +++-- .../ui/downloadcard/AddExtraCommandsDialog.kt | 32 ++++++++++-- .../downloadcard/CutVideoBottomSheetDialog.kt | 49 +++++++++---------- .../DownloadMultipleBottomSheetDialog.kt | 6 ++- .../downloadcard/ResultCardDetailsDialog.kt | 38 ++++++++++++-- .../ui/downloads/ActiveDownloadsFragment.kt | 23 +++++++-- .../ui/downloads/QueuedDownloadsFragment.kt | 8 +-- .../ytdlnis/ui/more/TerminalActivity.kt | 2 +- .../com/deniscerri/ytdlnis/util/InfoUtil.kt | 16 +++++- .../ytdlnis/util/NotificationUtil.kt | 6 +++ .../deniscerri/ytdlnis/work/DownloadWorker.kt | 12 ++--- .../ytdlnis/work/UpdateYTDLWorker.kt | 3 ++ app/src/main/res/layout/cut_video_sheet.xml | 2 - .../layout/extra_commands_bottom_sheet.xml | 1 + build.gradle | 2 +- 18 files changed, 185 insertions(+), 74 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7055416b..b4b2222b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,7 +10,7 @@ def properties = new Properties() def versionMajor = 1 def versionMinor = 6 def versionPatch = 3 -def versionBuild = 15 // bump for dogfood builds, public betas, etc. +def versionBuild = 17 // bump for dogfood builds, public betas, etc. def versionExt = "" if (versionBuild > 0){ diff --git a/app/src/main/java/com/deniscerri/ytdlnis/database/viewmodel/DownloadViewModel.kt b/app/src/main/java/com/deniscerri/ytdlnis/database/viewmodel/DownloadViewModel.kt index 7454e6ca..18694455 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/database/viewmodel/DownloadViewModel.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/database/viewmodel/DownloadViewModel.kt @@ -52,7 +52,10 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import java.io.File import java.util.Locale +import java.util.UUID import java.util.concurrent.TimeUnit +import kotlin.random.Random +import kotlin.random.nextInt class DownloadViewModel(application: Application) : AndroidViewModel(application) { @@ -149,7 +152,13 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application } suspend fun updateDownload(item: DownloadItem){ - repository.update(item) + if (sharedPreferences.getBoolean("incognito", false)){ + if (item.status == DownloadRepository.Status.Cancelled.toString() || item.status == DownloadRepository.Status.Error.toString()){ + repository.delete(item) + } + }else{ + repository.update(item) + } } fun getItemByID(id: Long) : DownloadItem { @@ -485,6 +494,8 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application if (it.status != DownloadRepository.Status.Paused.toString()) it.status = DownloadRepository.Status.Queued.toString() if (activeAndQueuedDownloads.firstOrNull{d -> d.id = 0 + d.logID = null + d.customFileNameTemplate = it.customFileNameTemplate d.status = DownloadRepository.Status.Queued.toString() d.toString() == it.toString() } != null) { @@ -506,6 +517,9 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application Toast.makeText(context, context.getString(R.string.download_already_exists), Toast.LENGTH_LONG).show() } } + + val workManager = WorkManager.getInstance(context) + queuedItems.forEach { val currentTime = System.currentTimeMillis() var delay = if (it.downloadStartTime != 0L){ @@ -518,19 +532,20 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application val workRequest = OneTimeWorkRequestBuilder() .setInputData(Data.Builder().putLong("id", it.id).build()) + .addTag(it.id.toString()) .addTag("download") .setConstraints(workConstraints.build()) .setInitialDelay(delay, TimeUnit.SECONDS) .build() - WorkManager.getInstance(context).beginUniqueWork( - it.id.toString(), - ExistingWorkPolicy.KEEP, + workManager.enqueueUniqueWork( + Random.nextInt(1000000000).toString(), + ExistingWorkPolicy.REPLACE, workRequest - ).enqueue() - + ) } + val isCurrentNetworkMetered = (context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).isActiveNetworkMetered if (!allowMeteredNetworks && isCurrentNetworkMetered){ Looper.prepare().run { diff --git a/app/src/main/java/com/deniscerri/ytdlnis/receiver/CancelDownloadNotificationReceiver.kt b/app/src/main/java/com/deniscerri/ytdlnis/receiver/CancelDownloadNotificationReceiver.kt index 2dc7b796..5802d04d 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/receiver/CancelDownloadNotificationReceiver.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/receiver/CancelDownloadNotificationReceiver.kt @@ -17,15 +17,17 @@ class CancelDownloadNotificationReceiver : BroadcastReceiver() { val message = intent.getStringExtra("cancel") val id = intent.getIntExtra("workID", 0) if (message != null) { - val notificationUtil = NotificationUtil(c) - notificationUtil.cancelDownloadNotification(id) - YoutubeDL.getInstance().destroyProcessById(id.toString()) + runCatching { + val notificationUtil = NotificationUtil(c) + notificationUtil.cancelDownloadNotification(id) + YoutubeDL.getInstance().destroyProcessById(id.toString()) - val dbManager = DBManager.getInstance(c) - CoroutineScope(Dispatchers.IO).launch{ - val item = dbManager.downloadDao.getDownloadById(id.toLong()) - item.status = DownloadRepository.Status.Cancelled.toString() - dbManager.downloadDao.update(item) + val dbManager = DBManager.getInstance(c) + CoroutineScope(Dispatchers.IO).launch{ + val item = dbManager.downloadDao.getDownloadById(id.toLong()) + item.status = DownloadRepository.Status.Cancelled.toString() + dbManager.downloadDao.update(item) + } } } diff --git a/app/src/main/java/com/deniscerri/ytdlnis/receiver/PauseDownloadNotificationReceiver.kt b/app/src/main/java/com/deniscerri/ytdlnis/receiver/PauseDownloadNotificationReceiver.kt index f999afb2..bc816fd5 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/receiver/PauseDownloadNotificationReceiver.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/receiver/PauseDownloadNotificationReceiver.kt @@ -10,11 +10,13 @@ class PauseDownloadNotificationReceiver : BroadcastReceiver() { override fun onReceive(c: Context, intent: Intent) { val id = intent.getIntExtra("workID", 0) if (id != 0) { - val title = intent.getStringExtra("title") - val notificationUtil = NotificationUtil(c) - notificationUtil.cancelDownloadNotification(id) - YoutubeDL.getInstance().destroyProcessById(id.toString()) - notificationUtil.createResumeDownload(id, title, NotificationUtil.DOWNLOAD_SERVICE_CHANNEL_ID) + runCatching { + val title = intent.getStringExtra("title") + val notificationUtil = NotificationUtil(c) + notificationUtil.cancelDownloadNotification(id) + YoutubeDL.getInstance().destroyProcessById(id.toString()) + notificationUtil.createResumeDownload(id, title, NotificationUtil.DOWNLOAD_SERVICE_CHANNEL_ID) + } } } } \ No newline at end of file diff --git a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/AddExtraCommandsDialog.kt b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/AddExtraCommandsDialog.kt index 53ff4001..41ee3576 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/AddExtraCommandsDialog.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/AddExtraCommandsDialog.kt @@ -6,6 +6,7 @@ import android.content.Context import android.content.DialogInterface import android.content.Intent import android.content.SharedPreferences +import android.graphics.Color import android.os.Bundle import android.util.DisplayMetrics import android.view.LayoutInflater @@ -26,10 +27,14 @@ import com.deniscerri.ytdlnis.util.UiUtil import com.google.android.material.bottomappbar.BottomAppBar import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import com.neo.highlight.core.Highlight +import com.neo.highlight.util.listener.HighlightTextWatcher +import com.neo.highlight.util.scheme.ColorScheme import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.util.* +import java.util.regex.Pattern class AddExtraCommandsDialog(private val item: DownloadItem, private val callback: ExtraCommandsListener) : BottomSheetDialogFragment() { @@ -81,11 +86,32 @@ class AddExtraCommandsDialog(private val item: DownloadItem, private val callbac val text = view.findViewById(R.id.command) val templates = view.findViewById