From c44929d5cb3ab23250248276a326c31db7707c9b Mon Sep 17 00:00:00 2001 From: deniscerri <64997243+deniscerri@users.noreply.github.com> Date: Thu, 27 Jul 2023 23:41:50 +0200 Subject: [PATCH] CHANGELOG Added option to turn off usage of cookies Some fixes with the cut screen Added ability to save command templates as extra commands by default on every downloadcard/AddExtraCommandsDialog fixed app not saving the proper youtube link and having to refetch data unnecessarily removed question mark from settings restore dialog fixed app scrolling in the tablayout in the download queue screen while you are dragging the vertical scrollbar fixed app not destroying active downloads when you terminate the app --- app/build.gradle | 9 +- .../9.json | 21 +-- .../main/java/com/deniscerri/ytdlnis/App.kt | 5 +- .../com/deniscerri/ytdlnis/MainActivity.kt | 49 +++-- .../ytdlnis/adapter/ActiveDownloadAdapter.kt | 10 +- .../ytdlnis/adapter/TemplatesAdapter.kt | 13 +- .../deniscerri/ytdlnis/database/DBManager.kt | 5 +- .../database/dao/CommandTemplateDao.kt | 2 + .../database/models/CommandTemplate.kt | 5 +- .../ytdlnis/database/models/ResultItem.kt | 2 +- .../database/repository/ResultRepository.kt | 2 +- .../database/viewmodel/DownloadViewModel.kt | 28 ++- .../ytdlnis/receiver/ShareActivity.kt | 4 + .../ui/downloadcard/AddExtraCommandsDialog.kt | 169 ++++++++++++++++++ .../downloadcard/CutVideoBottomSheetDialog.kt | 86 +++++---- .../ui/downloadcard/DownloadAudioFragment.kt | 36 +--- .../downloadcard/DownloadCommandFragment.kt | 2 +- .../DownloadMultipleBottomSheetDialog.kt | 10 +- .../ui/downloadcard/DownloadVideoFragment.kt | 35 +--- .../ui/downloads/ActiveDownloadsFragment.kt | 73 ++++---- .../downloads/CancelledDownloadsFragment.kt | 5 + .../ui/downloads/DownloadQueueMainFragment.kt | 2 +- .../ui/downloads/ErroredDownloadsFragment.kt | 4 + .../ui/downloads/QueuedDownloadsFragment.kt | 6 +- .../ui/downloads/SavedDownloadsFragment.kt | 4 + .../ytdlnis/ui/more/CookiesFragment.kt | 18 ++ .../ytdlnis/ui/more/MoreFragment.kt | 41 ++++- .../ytdlnis/ui/more/TerminalActivity.kt | 37 +--- .../ui/more/settings/MainSettingsFragment.kt | 2 - .../com/deniscerri/ytdlnis/util/InfoUtil.kt | 43 +++-- .../com/deniscerri/ytdlnis/util/UiUtil.kt | 54 +++++- .../deniscerri/ytdlnis/work/DownloadWorker.kt | 23 ++- .../res/drawable/baseline_description_24.xml | 5 + app/src/main/res/drawable/thumb.xml | 26 ++- .../main/res/layout/command_template_item.xml | 41 +++-- .../res/layout/create_command_template.xml | 12 ++ app/src/main/res/layout/cut_video_sheet.xml | 4 +- .../layout/extra_commands_bottom_sheet.xml | 161 +++++++++++------ app/src/main/res/layout/fragment_active.xml | 17 +- app/src/main/res/layout/fragment_cookies.xml | 14 +- .../fragment_generic_download_queue.xml | 2 +- app/src/main/res/layout/fragment_history.xml | 2 +- app/src/main/res/layout/fragment_home.xml | 51 +++--- app/src/main/res/layout/fragment_inqueue.xml | 8 +- .../main/res/layout/result_card_details.xml | 6 +- .../main/res/layout/result_card_shimmer.xml | 2 - app/src/main/res/menu/extra_commands_menu.xml | 14 ++ app/src/main/res/values-ar/strings.xml | 4 +- app/src/main/res/values-de/strings.xml | 4 +- app/src/main/res/values-pl/strings.xml | 4 +- app/src/main/res/values-pt-rBR/strings.xml | 1 - app/src/main/res/values-pt/strings.xml | 4 +- app/src/main/res/values-ru/strings.xml | 1 - app/src/main/res/values-th/strings.xml | 4 +- app/src/main/res/values-tr-rTR/strings.xml | 4 +- app/src/main/res/values-uk/strings.xml | 4 +- app/src/main/res/values-zh-rTW/strings.xml | 4 +- app/src/main/res/values/strings.xml | 4 + .../main/res/xml/processing_preferences.xml | 8 + build.gradle | 2 +- 60 files changed, 803 insertions(+), 415 deletions(-) create mode 100644 app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/AddExtraCommandsDialog.kt create mode 100644 app/src/main/res/drawable/baseline_description_24.xml create mode 100644 app/src/main/res/menu/extra_commands_menu.xml diff --git a/app/build.gradle b/app/build.gradle index ffa0a801..8f687d6b 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 = 10 // bump for dogfood builds, public betas, etc. +def versionBuild = 13 // bump for dogfood builds, public betas, etc. def versionExt = "" if (versionBuild > 0){ @@ -152,18 +152,13 @@ dependencies { implementation 'androidx.preference:preference:1.2.0' implementation "androidx.navigation:navigation-fragment-ktx:$navVer" implementation "androidx.navigation:navigation-ui-ktx:$navVer" - implementation 'androidx.core:core-ktx:1.10.0' + implementation 'androidx.core:core-ktx:1.10.1' implementation 'androidx.test.ext:junit-ktx:1.1.5' implementation 'androidx.benchmark:benchmark-macro:1.1.1' testImplementation "junit:junit:$junitVer" androidTestImplementation "junit:junit:$junitVer" androidTestImplementation "androidx.test.ext:junit:$androidJunitVer" androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVer" - androidTestImplementation "androidx.benchmark:benchmark-macro-junit4:1.2.0-alpha16" - androidTestImplementation "androidx.test:runner:1.5.2" - androidTestImplementation "androidx.test:core:1.5.0" - androidTestImplementation "androidx.test:rules:1.5.0" - androidTestImplementation "androidx.navigation:navigation-testing:$navVer" implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' implementation "com.devbrackets.android:exomedia:4.3.0" diff --git a/app/schemas/com.deniscerri.ytdlnis.database.DBManager/9.json b/app/schemas/com.deniscerri.ytdlnis.database.DBManager/9.json index 9ab542b7..b5b2e002 100644 --- a/app/schemas/com.deniscerri.ytdlnis.database.DBManager/9.json +++ b/app/schemas/com.deniscerri.ytdlnis.database.DBManager/9.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 9, - "identityHash": "bcd20f64b54fbc6e470be0d15059a66e", + "identityHash": "d29e09789b7c96b5551b80da253b7330", "entities": [ { "tableName": "results", @@ -180,7 +180,7 @@ }, { "tableName": "downloads", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `url` TEXT NOT NULL, `title` TEXT NOT NULL, `author` TEXT NOT NULL, `thumb` TEXT NOT NULL, `duration` TEXT NOT NULL, `type` TEXT NOT NULL, `format` TEXT NOT NULL, `container` TEXT NOT NULL DEFAULT 'Default', `downloadSections` TEXT NOT NULL DEFAULT '', `allFormats` TEXT NOT NULL, `downloadPath` TEXT NOT NULL, `website` TEXT NOT NULL, `downloadSize` TEXT NOT NULL, `playlistTitle` TEXT NOT NULL, `audioPreferences` TEXT NOT NULL, `videoPreferences` TEXT NOT NULL, `extraCommands` TEXT NOT NULL DEFAULT '', `customFileNameTemplate` TEXT NOT NULL, `SaveThumb` INTEGER NOT NULL, `status` TEXT NOT NULL DEFAULT 'Queued', `downloadStartTime` INTEGER NOT NULL DEFAULT 0, `logID` INTEGER, `workID` BLOB)", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `url` TEXT NOT NULL, `title` TEXT NOT NULL, `author` TEXT NOT NULL, `thumb` TEXT NOT NULL, `duration` TEXT NOT NULL, `type` TEXT NOT NULL, `format` TEXT NOT NULL, `container` TEXT NOT NULL DEFAULT 'Default', `downloadSections` TEXT NOT NULL DEFAULT '', `allFormats` TEXT NOT NULL, `downloadPath` TEXT NOT NULL, `website` TEXT NOT NULL, `downloadSize` TEXT NOT NULL, `playlistTitle` TEXT NOT NULL, `audioPreferences` TEXT NOT NULL, `videoPreferences` TEXT NOT NULL, `extraCommands` TEXT NOT NULL DEFAULT '', `customFileNameTemplate` TEXT NOT NULL, `SaveThumb` INTEGER NOT NULL, `status` TEXT NOT NULL DEFAULT 'Queued', `downloadStartTime` INTEGER NOT NULL DEFAULT 0, `logID` INTEGER)", "fields": [ { "fieldPath": "id", @@ -324,12 +324,6 @@ "columnName": "logID", "affinity": "INTEGER", "notNull": false - }, - { - "fieldPath": "workID", - "columnName": "workID", - "affinity": "BLOB", - "notNull": false } ], "primaryKey": { @@ -343,7 +337,7 @@ }, { "tableName": "commandTemplates", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT NOT NULL, `content` TEXT NOT NULL)", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT NOT NULL, `content` TEXT NOT NULL, `useAsExtraCommand` INTEGER NOT NULL DEFAULT false)", "fields": [ { "fieldPath": "id", @@ -362,6 +356,13 @@ "columnName": "content", "affinity": "TEXT", "notNull": true + }, + { + "fieldPath": "useAsExtraCommand", + "columnName": "useAsExtraCommand", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "false" } ], "primaryKey": { @@ -511,7 +512,7 @@ "views": [], "setupQueries": [ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", - "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'bcd20f64b54fbc6e470be0d15059a66e')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'd29e09789b7c96b5551b80da253b7330')" ] } } \ No newline at end of file diff --git a/app/src/main/java/com/deniscerri/ytdlnis/App.kt b/app/src/main/java/com/deniscerri/ytdlnis/App.kt index 8b5d1f29..958013c7 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/App.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/App.kt @@ -1,6 +1,7 @@ package com.deniscerri.ytdlnis import android.app.Application +import android.os.Looper import android.widget.Toast import androidx.core.content.edit import androidx.preference.PreferenceManager @@ -66,7 +67,9 @@ class App : Application() { ) }catch (e: Exception){ - Toast.makeText(this@App, e.message, Toast.LENGTH_SHORT).show() + Looper.prepare().runCatching { + Toast.makeText(this@App, e.message, Toast.LENGTH_SHORT).show() + } e.printStackTrace() } } diff --git a/app/src/main/java/com/deniscerri/ytdlnis/MainActivity.kt b/app/src/main/java/com/deniscerri/ytdlnis/MainActivity.kt index 7feb2a45..1fbea725 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/MainActivity.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/MainActivity.kt @@ -41,6 +41,7 @@ import androidx.navigation.fragment.findNavController import androidx.navigation.navOptions import androidx.navigation.ui.setupWithNavController import androidx.preference.PreferenceManager +import com.deniscerri.ytdlnis.database.repository.DownloadRepository import com.deniscerri.ytdlnis.database.viewmodel.CookieViewModel import com.deniscerri.ytdlnis.database.viewmodel.DownloadViewModel import com.deniscerri.ytdlnis.database.viewmodel.ResultViewModel @@ -56,7 +57,10 @@ import com.google.android.material.navigation.NavigationBarView import com.google.android.material.navigation.NavigationView import com.google.android.material.navigationrail.NavigationRailView import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withContext import java.io.BufferedReader import java.io.InputStreamReader import java.io.Reader @@ -116,14 +120,14 @@ class MainActivity : BaseActivity() { sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) - val graph = navController.navInflater.inflate(R.navigation.nav_graph) - graph.setStartDestination(R.id.homeFragment) - when(sharedPreferences.getString("start_destination", "")) { - "History" -> graph.setStartDestination(R.id.historyFragment) - "More" -> if (navigationView is NavigationBarView) graph.setStartDestination(R.id.moreFragment) - } - - navController.graph = graph +// val graph = navController.navInflater.inflate(R.navigation.nav_graph) +// graph.setStartDestination(R.id.homeFragment) +// when(sharedPreferences.getString("start_destination", "")) { +// "History" -> graph.setStartDestination(R.id.historyFragment) +// "More" -> if (navigationView is NavigationBarView) graph.setStartDestination(R.id.moreFragment) +// } +// +// navController.graph = graph if (navigationView is NavigationBarView){ (navigationView as NavigationBarView).setupWithNavController(navController) @@ -172,11 +176,24 @@ class MainActivity : BaseActivity() { terminateDialog.setNegativeButton(getString(R.string.cancel)) { dialogInterface: DialogInterface, _: Int -> dialogInterface.cancel() } terminateDialog.setPositiveButton(getString(R.string.ok)) { _: DialogInterface?, _: Int -> - if (doNotShowAgain){ - sharedPreferences.edit().putBoolean("ask_terminate_app", false).apply() + runBlocking { + val job : Job = lifecycleScope.launch(Dispatchers.IO) { + val activeDownloads = downloadViewModel.getActiveDownloads().toMutableList() + activeDownloads.map { it.status = DownloadRepository.Status.Queued.toString() } + activeDownloads.forEach { + downloadViewModel.updateDownload(it) + } + } + runBlocking { + job.join() + if (doNotShowAgain){ + sharedPreferences.edit().putBoolean("ask_terminate_app", false).apply() + } + finishAndRemoveTask() + finishAffinity() + exitProcess(0) + } } - finishAndRemoveTask() - exitProcess(0) } terminateDialog.show() }else{ @@ -216,6 +233,14 @@ class MainActivity : BaseActivity() { } + override fun onSaveInstanceState(savedInstanceState: Bundle) { + super.onSaveInstanceState(savedInstanceState) + savedInstanceState.putBundle("nav_state", navController.saveState()) + } + override fun onRestoreInstanceState(savedInstanceState: Bundle) { + super.onRestoreInstanceState(savedInstanceState) + navController.restoreState(savedInstanceState.getBundle("nav_state")) + } private fun View.visibilityChanged(action: (View) -> Unit) { this.viewTreeObserver.addOnGlobalLayoutListener { diff --git a/app/src/main/java/com/deniscerri/ytdlnis/adapter/ActiveDownloadAdapter.kt b/app/src/main/java/com/deniscerri/ytdlnis/adapter/ActiveDownloadAdapter.kt index 69fde5c5..23c9c942 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/adapter/ActiveDownloadAdapter.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/adapter/ActiveDownloadAdapter.kt @@ -148,16 +148,10 @@ class ActiveDownloadAdapter(onItemClickListener: OnItemClickListener, activity: pauseButton.setOnClickListener { if (pauseButton.tag == ActiveDownloadAction.Pause){ onItemClickListener.onPauseClick(item.id, ActiveDownloadAction.Pause) - pauseButton.icon = ContextCompat.getDrawable(activity, R.drawable.exomedia_ic_play_arrow_white) - if (progressBar.progress == 0) progressBar.isIndeterminate = false - cancelButton.visibility = View.VISIBLE - pauseButton.tag = ActiveDownloadAction.Resume + }else{ onItemClickListener.onPauseClick(item.id, ActiveDownloadAction.Resume) - pauseButton.icon = ContextCompat.getDrawable(activity, R.drawable.exomedia_ic_pause_white) - progressBar.isIndeterminate = true - cancelButton.visibility = View.GONE - pauseButton.tag = ActiveDownloadAction.Pause + } } diff --git a/app/src/main/java/com/deniscerri/ytdlnis/adapter/TemplatesAdapter.kt b/app/src/main/java/com/deniscerri/ytdlnis/adapter/TemplatesAdapter.kt index 245d09f7..9912dbcf 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/adapter/TemplatesAdapter.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/adapter/TemplatesAdapter.kt @@ -1,6 +1,7 @@ package com.deniscerri.ytdlnis.adapter import android.app.Activity +import android.opengl.Visibility import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -46,18 +47,16 @@ class TemplatesAdapter(onItemClickListener: OnItemClickListener, activity: Activ val content = card.findViewById(R.id.content) content.text = item?.content -// val check = card.findViewById