From abb073657999d4a0d39f309e926861c6551f03c5 Mon Sep 17 00:00:00 2001 From: Xilin Jia <6257601+XilinJia@users.noreply.github.com> Date: Sun, 14 Jul 2024 10:20:30 +0100 Subject: [PATCH] 6.0.11 commit --- app/build.gradle | 4 ++-- .../service/DownloadServiceInterfaceImpl.kt | 4 ++-- .../ImportExportPreferencesFragment.kt | 20 +++++++++++++++---- .../mdiq/podcini/storage/database/Episodes.kt | 6 ++++++ .../ui/fragment/PlayerDetailsFragment.kt | 2 +- .../res/xml/preferences_import_export.xml | 10 +++++----- changelog.md | 4 ++++ migrationTo6.md | 2 +- 8 files changed, 37 insertions(+), 15 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 335b740d..ffb88ec2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -126,8 +126,8 @@ android { buildConfig true } defaultConfig { - versionCode 3020210 - versionName "6.0.10" + versionCode 3020211 + versionName "6.0.11" applicationId "ac.mdiq.podcini.R" def commit = "" diff --git a/app/src/main/kotlin/ac/mdiq/podcini/net/download/service/DownloadServiceInterfaceImpl.kt b/app/src/main/kotlin/ac/mdiq/podcini/net/download/service/DownloadServiceInterfaceImpl.kt index 9df8b801..573d41bc 100644 --- a/app/src/main/kotlin/ac/mdiq/podcini/net/download/service/DownloadServiceInterfaceImpl.kt +++ b/app/src/main/kotlin/ac/mdiq/podcini/net/download/service/DownloadServiceInterfaceImpl.kt @@ -130,7 +130,7 @@ class DownloadServiceInterfaceImpl : DownloadServiceInterface() { override fun doWork(): Result { Logd(TAG, "starting doWork") ClientConfigurator.initialize(applicationContext) - val mediaId = inputData.getLong(DownloadServiceInterface.WORK_DATA_MEDIA_ID, 0) + val mediaId = inputData.getLong(WORK_DATA_MEDIA_ID, 0) val media = Episodes.getEpisodeMedia(mediaId) if (media == null) { Log.e(TAG, "media is null for mediaId: $mediaId") @@ -146,7 +146,7 @@ class DownloadServiceInterfaceImpl : DownloadServiceInterface() { if (isInterrupted) return notificationProgress.put(media.getEpisodeTitle(), request.progressPercent) } - setProgressAsync(Data.Builder().putInt(DownloadServiceInterface.WORK_DATA_PROGRESS, request.progressPercent).build()).get() + setProgressAsync(Data.Builder().putInt(WORK_DATA_PROGRESS, request.progressPercent).build()).get() val nm = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager nm.notify(R.id.notification_downloading, generateProgressNotification()) sleep(1000) diff --git a/app/src/main/kotlin/ac/mdiq/podcini/preferences/fragments/ImportExportPreferencesFragment.kt b/app/src/main/kotlin/ac/mdiq/podcini/preferences/fragments/ImportExportPreferencesFragment.kt index d18ca84a..980d10f8 100644 --- a/app/src/main/kotlin/ac/mdiq/podcini/preferences/fragments/ImportExportPreferencesFragment.kt +++ b/app/src/main/kotlin/ac/mdiq/podcini/preferences/fragments/ImportExportPreferencesFragment.kt @@ -17,6 +17,7 @@ import ac.mdiq.podcini.storage.database.RealmDB.upsertBlk import ac.mdiq.podcini.storage.model.Episode import ac.mdiq.podcini.storage.model.Feed import ac.mdiq.podcini.preferences.OpmlTransporter.* +import ac.mdiq.podcini.storage.database.Episodes.getEpisodeByTitle import ac.mdiq.podcini.storage.model.EpisodeFilter import ac.mdiq.podcini.storage.utils.EpisodeUtil.hasAlmostEnded import ac.mdiq.podcini.storage.model.EpisodeSortOrder @@ -167,7 +168,7 @@ class ImportExportPreferencesFragment : PreferenceFragmentCompat() { exportPreferences() true } - findPreference(PREF_MEDIAFILES_IMPORT)!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { + findPreference(PREF_MEDIAFILES_IMPORT)?.onPreferenceClickListener = Preference.OnPreferenceClickListener { importMediaFiles() true } @@ -750,15 +751,26 @@ class ImportExportPreferencesFragment : PreferenceFragmentCompat() { } } private fun copyRecursive(context: Context, srcFile: DocumentFile, srcRootDir: DocumentFile, destRootDir: File) { - val relativePath = srcFile.uri.path?.substring(srcRootDir.uri.path!!.length) ?: return - val destFile = File(destRootDir, relativePath) + val relativePath = srcFile.uri.path?.substring(srcRootDir.uri.path!!.length+1) ?: return if (srcFile.isDirectory) { + val destFile = File(destRootDir, relativePath) if (!destFile.exists()) destFile.mkdirs() srcFile.listFiles().forEach { file -> copyRecursive(context, file, srcFile, destFile) } } else { - if (!destFile.exists()) copyFile(srcFile, destFile, context) + val nameParts = relativePath.split(".") + if (nameParts.size < 3) return + val ext = nameParts[nameParts.size-1] + val title = nameParts.dropLast(2).joinToString(".") + Logd(TAG, "copyRecursive title: $title") + val episode = getEpisodeByTitle(title) ?: return + val destName = "$title.${episode.id}.$ext" + val destFile = File(destRootDir, destName) + if (!destFile.exists()) { + copyFile(srcFile, destFile, context) + upsertBlk(episode) { it.media?.setfileUrlOrNull(destFile.name)} + } } } private fun copyFile(sourceFile: DocumentFile, destFile: File, context: Context) { diff --git a/app/src/main/kotlin/ac/mdiq/podcini/storage/database/Episodes.kt b/app/src/main/kotlin/ac/mdiq/podcini/storage/database/Episodes.kt index 7af11979..42be2f49 100644 --- a/app/src/main/kotlin/ac/mdiq/podcini/storage/database/Episodes.kt +++ b/app/src/main/kotlin/ac/mdiq/podcini/storage/database/Episodes.kt @@ -84,6 +84,12 @@ object Episodes { return if (episode != null) realm.copyFromRealm(episode) else null } + fun getEpisodeByTitle(title: String): Episode? { + Logd(TAG, "getEpisodeByTitle called $title ") + val episode = realm.query(Episode::class).query("title == $0", title).first().find() + return if (episode != null) realm.copyFromRealm(episode) else null + } + fun getEpisodeMedia(mediaId: Long): EpisodeMedia? { Logd(TAG, "getEpisodeMedia called $mediaId") val media = realm.query(EpisodeMedia::class).query("id == $0", mediaId).first().find() diff --git a/app/src/main/kotlin/ac/mdiq/podcini/ui/fragment/PlayerDetailsFragment.kt b/app/src/main/kotlin/ac/mdiq/podcini/ui/fragment/PlayerDetailsFragment.kt index ce35ff34..173178d1 100644 --- a/app/src/main/kotlin/ac/mdiq/podcini/ui/fragment/PlayerDetailsFragment.kt +++ b/app/src/main/kotlin/ac/mdiq/podcini/ui/fragment/PlayerDetailsFragment.kt @@ -369,7 +369,7 @@ class PlayerDetailsFragment : Fragment() { @UnstableApi private fun savePreference() { Logd(TAG, "Saving preferences") - val editor = prefs!!.edit() + val editor = prefs?.edit() ?: return if (curMedia != null) { Logd(TAG, "Saving scroll position: " + binding.itemDescriptionFragment.scrollY) editor.putInt(PREF_SCROLL_Y, binding.itemDescriptionFragment.scrollY) diff --git a/app/src/main/res/xml/preferences_import_export.xml b/app/src/main/res/xml/preferences_import_export.xml index 3822b50a..18aa644d 100644 --- a/app/src/main/res/xml/preferences_import_export.xml +++ b/app/src/main/res/xml/preferences_import_export.xml @@ -22,11 +22,11 @@ search:keywords="@string/import_export_search_keywords" android:title="@string/media_files_export_label" android:summary="@string/media_files_export_summary"/> - + + + + + diff --git a/changelog.md b/changelog.md index 09f8496e..3dbf8864 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +# 6.0.11 + +* This is a minor release of subtraction: import of downloaded media files is temporarily disabled as it's more complicated than I thought. Although it works on files exported from Podcini.R, file names from earlier versions aren't easily recognizable. + # 6.0.10 * for better migrating from version 5, added export/import of downloaded media files: inter-operable with Podcini 5.5.4 diff --git a/migrationTo6.md b/migrationTo6.md index 8d148798..4e5fed3e 100644 --- a/migrationTo6.md +++ b/migrationTo6.md @@ -13,7 +13,7 @@ the following can be imported to it from Settings -> Import/Export: * preferences files * OPML file * json file of episodes progress -* downloaded media files (5.5.4 only) +* downloaded media files (5.5.4 only, but currently not enabled for import) An OPML file should be imported before importing episodes progress, but you can always re-do any of the above