From 7d5bf3ad982da5c3b224312aa609449b1c3b8734 Mon Sep 17 00:00:00 2001 From: Xilin Jia <6257601+XilinJia@users.noreply.github.com> Date: Mon, 19 Feb 2024 15:15:58 +0100 Subject: [PATCH] removed unnecessary net load --- app/build.gradle | 4 +- .../podvinci/fragment/AudioPlayerFragment.kt | 32 +++++++---- .../podvinci/fragment/ChaptersFragment.kt | 32 ++++++++--- .../mdiq/podvinci/fragment/CoverFragment.kt | 41 ++++++++++---- .../fragment/ExternalPlayerFragment.kt | 30 +++++++---- .../podvinci/fragment/FeedItemlistFragment.kt | 6 +-- .../fragment/ItemDescriptionFragment.kt | 53 ++++++++++--------- .../ac/mdiq/podvinci/fragment/ItemFragment.kt | 34 ++++++++---- .../mdiq/podvinci/fragment/QueueFragment.kt | 14 ++--- .../AutoDownloadPreferencesFragment.kt | 2 +- .../DownloadsPreferencesFragment.kt | 4 +- .../ImportExportPreferencesFragment.kt | 2 +- .../preferences/MainPreferencesFragment.kt | 14 ++--- .../NotificationPreferencesFragment.kt | 2 +- .../PlaybackPreferencesFragment.kt | 2 +- .../preferences/SwipePreferencesFragment.kt | 2 +- .../UserInterfacePreferencesFragment.kt | 4 +- .../preferences/about/AboutFragment.kt | 2 +- .../about/ContributorsPagerFragment.kt | 2 +- .../preferences/about/LicensesFragment.kt | 6 +-- .../SynchronizationPreferencesFragment.kt | 8 +-- .../ac/mdiq/podvinci/ui/home/HomeFragment.kt | 3 +- app/src/main/res/layout/home_section.xml | 4 +- .../core/service/playback/PlaybackService.kt | 7 ++- .../PlaybackServiceNotificationBuilder.kt | 8 ++- .../core/storage/APQueueCleanupAlgorithm.kt | 4 +- .../ac/mdiq/podvinci/core/storage/DBReader.kt | 19 ++++--- .../ac/mdiq/podvinci/core/storage/DBTasks.kt | 2 +- .../storage/ExceptFavoriteCleanupAlgorithm.kt | 8 +-- .../mdiq/podvinci/core/util/ChapterUtils.kt | 8 +-- .../podvinci/core/util/FeedItemPermutors.kt | 2 +- .../core/util/playback/PlaybackController.kt | 2 - .../mdiq/podvinci/core/storage/DbTestUtils.kt | 4 +- .../mapper/DownloadResultCursorMapper.kt | 11 ++-- .../statistics/feed/FeedStatisticsFragment.kt | 4 +- 35 files changed, 228 insertions(+), 154 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0cba373e..a1495199 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,8 +22,8 @@ android { // Version code schema: // "1.2.3-beta4" -> 1020304 // "1.2.3" -> 1020395 - versionCode 3020097 - versionName "3.2.2" + versionCode 3020098 + versionName "3.2.3" def commit = "" try { diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/AudioPlayerFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/AudioPlayerFragment.kt index 0d6f41fb..91726998 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/AudioPlayerFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/AudioPlayerFragment.kt @@ -149,9 +149,22 @@ class AudioPlayerFragment : Fragment(), SeekBar.OnSeekBarChangeListener, Toolbar } }) + controller = newPlaybackController() + controller?.init() + loadMediaInfo(false) + EventBus.getDefault().register(this) + return root } + override fun onDestroyView() { + super.onDestroyView() + controller?.release() + controller = null + EventBus.getDefault().unregister(this) + Log.d(TAG, "Fragment destroyed") + } + private fun setChapterDividers(media: Playable?) { if (media == null) { return @@ -241,9 +254,8 @@ class AudioPlayerFragment : Fragment(), SeekBar.OnSeekBarChangeListener, Toolbar } private fun loadMediaInfo(includingChapters: Boolean) { - if (disposable != null) { - disposable!!.dispose() - } + disposable?.dispose() + disposable = Maybe.create { emitter: MaybeEmitter -> val media: Playable? = controller?.getMedia() if (media != null) { @@ -308,20 +320,20 @@ class AudioPlayerFragment : Fragment(), SeekBar.OnSeekBarChangeListener, Toolbar override fun onStart() { super.onStart() - controller = newPlaybackController() - controller?.init() - loadMediaInfo(false) - EventBus.getDefault().register(this) +// controller = newPlaybackController() +// controller?.init() +// loadMediaInfo(false) +// EventBus.getDefault().register(this) txtvRev.text = NumberFormat.getInstance().format(UserPreferences.rewindSecs.toLong()) txtvFF.text = NumberFormat.getInstance().format(UserPreferences.fastForwardSecs.toLong()) } override fun onStop() { super.onStop() - controller?.release() - controller = null +// controller?.release() +// controller = null +// EventBus.getDefault().unregister(this) progressIndicator.visibility = View.GONE // Controller released; we will not receive buffering updates - EventBus.getDefault().unregister(this) disposable?.dispose() } diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/ChaptersFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/ChaptersFragment.kt index d64ab2ab..1f91b642 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/ChaptersFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/ChaptersFragment.kt @@ -91,11 +91,6 @@ class ChaptersFragment : AppCompatDialogFragment() { CoordinatorLayout.LayoutParams.MATCH_PARENT, CoordinatorLayout.LayoutParams.WRAP_CONTENT) recyclerView.layoutParams = wrapHeight - return root - } - - override fun onStart() { - super.onStart() controller = object : PlaybackController(activity) { override fun loadMediaInfo() { this@ChaptersFragment.loadMediaInfo(false) @@ -104,16 +99,37 @@ class ChaptersFragment : AppCompatDialogFragment() { controller?.init() EventBus.getDefault().register(this) loadMediaInfo(false) + + return root } - override fun onStop() { - super.onStop() - disposable?.dispose() + override fun onDestroyView() { + super.onDestroyView() controller?.release() controller = null EventBus.getDefault().unregister(this) } + override fun onStart() { + super.onStart() +// controller = object : PlaybackController(activity) { +// override fun loadMediaInfo() { +// this@ChaptersFragment.loadMediaInfo(false) +// } +// } +// controller?.init() +// EventBus.getDefault().register(this) +// loadMediaInfo(false) + } + + override fun onStop() { + super.onStop() + disposable?.dispose() +// controller?.release() +// controller = null +// EventBus.getDefault().unregister(this) + } + @Subscribe(threadMode = ThreadMode.MAIN) fun onEventMainThread(event: PlaybackPositionEvent) { updateChapterSelection(getCurrentChapter(media), false) diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/CoverFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/CoverFragment.kt index 12ab601f..d6088a61 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/CoverFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/CoverFragment.kt @@ -29,6 +29,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.LinearLayout +import androidx.annotation.OptIn import androidx.core.content.ContextCompat import androidx.core.graphics.BlendModeColorFilterCompat import androidx.core.graphics.BlendModeCompat @@ -78,9 +79,27 @@ class CoverFragment : Fragment() { } viewBinding.butPrevChapter.setOnClickListener { v: View? -> seekToPrevChapter() } viewBinding.butNextChapter.setOnClickListener { v: View? -> seekToNextChapter() } + + controller = object : PlaybackController(activity) { + override fun loadMediaInfo() { + this@CoverFragment.loadMediaInfo(false) + } + } + controller?.init() + loadMediaInfo(false) + EventBus.getDefault().register(this) + return viewBinding.root } + @OptIn(UnstableApi::class) override fun onDestroyView() { + super.onDestroyView() + controller?.release() + controller = null + EventBus.getDefault().unregister(this) + Log.d(TAG, "Fragment destroyed") + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { configureForOrientation(resources.configuration) } @@ -231,22 +250,22 @@ class CoverFragment : Fragment() { @UnstableApi override fun onStart() { super.onStart() - controller = object : PlaybackController(activity) { - override fun loadMediaInfo() { - this@CoverFragment.loadMediaInfo(false) - } - } - controller?.init() - loadMediaInfo(false) - EventBus.getDefault().register(this) +// controller = object : PlaybackController(activity) { +// override fun loadMediaInfo() { +// this@CoverFragment.loadMediaInfo(false) +// } +// } +// controller?.init() +// loadMediaInfo(false) +// EventBus.getDefault().register(this) } @UnstableApi override fun onStop() { super.onStop() disposable?.dispose() - controller?.release() - controller = null - EventBus.getDefault().unregister(this) +// controller?.release() +// controller = null +// EventBus.getDefault().unregister(this) } @Subscribe(threadMode = ThreadMode.MAIN) diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/ExternalPlayerFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/ExternalPlayerFragment.kt index 4bf2a243..1c55150c 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/ExternalPlayerFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/ExternalPlayerFragment.kt @@ -25,6 +25,7 @@ import ac.mdiq.podvinci.model.playback.MediaType import ac.mdiq.podvinci.model.playback.Playable import ac.mdiq.podvinci.playback.base.PlayerStatus import ac.mdiq.podvinci.view.PlayButton +import androidx.annotation.OptIn import io.reactivex.Maybe import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable @@ -68,9 +69,19 @@ class ExternalPlayerFragment : Fragment() { } } } + controller = setupPlaybackController() + controller!!.init() + loadMediaInfo() + EventBus.getDefault().register(this) return root } + @OptIn(UnstableApi::class) override fun onDestroyView() { + super.onDestroyView() + controller?.release() + controller = null + EventBus.getDefault().unregister(this) + } @UnstableApi override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -105,22 +116,20 @@ class ExternalPlayerFragment : Fragment() { } } - @UnstableApi override fun onStart() { super.onStart() - controller = setupPlaybackController() - controller!!.init() - loadMediaInfo() - EventBus.getDefault().register(this) +// controller = setupPlaybackController() +// controller!!.init() +// loadMediaInfo() +// EventBus.getDefault().register(this) } - @UnstableApi override fun onStop() { super.onStop() - controller?.release() - controller = null - - EventBus.getDefault().unregister(this) +// controller?.release() +// controller = null +// +// EventBus.getDefault().unregister(this) } @UnstableApi @@ -146,7 +155,6 @@ class ExternalPlayerFragment : Fragment() { super.onDestroy() Log.d(TAG, "Fragment is about to be destroyed") disposable?.dispose() - } @UnstableApi diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/FeedItemlistFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/FeedItemlistFragment.kt index 6b9b2064..47c69478 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/FeedItemlistFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/FeedItemlistFragment.kt @@ -77,9 +77,9 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba private lateinit var nextPageLoader: MoreContentListFooterUtil private var displayUpArrow = false + private var headerCreated = false private var feedID: Long = 0 private var feed: Feed? = null - private var headerCreated = false private var disposable: Disposable? = null override fun onCreate(savedInstanceState: Bundle?) { @@ -236,8 +236,8 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba } R.id.refresh_complete_item -> { Thread { - feed?.nextPageLink = feed!!.download_url - feed?.pageNr = 0 + feed!!.nextPageLink = feed!!.download_url + feed!!.pageNr = 0 try { DBWriter.resetPagedFeedPage(feed).get() FeedUpdateManager.runOnce(context, feed) diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/ItemDescriptionFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/ItemDescriptionFragment.kt index ea66dd22..79a3d085 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/ItemDescriptionFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/ItemDescriptionFragment.kt @@ -28,6 +28,7 @@ import io.reactivex.schedulers.Schedulers @UnstableApi class ItemDescriptionFragment : Fragment() { private lateinit var webvDescription: ShownotesWebView + private var webViewLoader: Disposable? = null private var controller: PlaybackController? = null @@ -36,9 +37,7 @@ class ItemDescriptionFragment : Fragment() { val root = inflater.inflate(R.layout.item_description_fragment, container, false) webvDescription = root.findViewById(R.id.webview) webvDescription.setTimecodeSelectedListener { time: Int? -> - if (controller != null) { - controller!!.seekTo(time!!) - } + controller?.seekTo(time!!) } webvDescription.setPageFinishedListener { // Restoring the scroll position might not always work @@ -56,11 +55,21 @@ class ItemDescriptionFragment : Fragment() { } }) registerForContextMenu(webvDescription) + controller = object : PlaybackController(activity) { + override fun loadMediaInfo() { + load() + } + } + controller?.init() + + load() return root } - override fun onDestroy() { - super.onDestroy() + override fun onDestroyView() { + super.onDestroyView() + controller?.release() + controller = null Log.d(TAG, "Fragment destroyed") webvDescription.removeAllViews() webvDescription.destroy() @@ -71,13 +80,12 @@ class ItemDescriptionFragment : Fragment() { } @UnstableApi private fun load() { - Log.d(TAG, "load()") - if (webViewLoader != null) { - webViewLoader!!.dispose() - } + Log.d(TAG, "load() called") + webViewLoader?.dispose() + val context = context ?: return webViewLoader = Maybe.create { emitter: MaybeEmitter -> - val media = controller!!.getMedia() + val media = controller?.getMedia() if (media == null) { emitter.onComplete() return@create @@ -112,8 +120,7 @@ class ItemDescriptionFragment : Fragment() { if (controller?.getMedia() != null) { Log.d(TAG, "Saving scroll position: " + webvDescription.scrollY) editor.putInt(PREF_SCROLL_Y, webvDescription.scrollY) - editor.putString(PREF_PLAYABLE_ID, controller!!.getMedia()!!.getIdentifier() - .toString()) + editor.putString(PREF_PLAYABLE_ID, controller!!.getMedia()!!.getIdentifier().toString()) } else { Log.d(TAG, "savePreferences was called while media or webview was null") editor.putInt(PREF_SCROLL_Y, -1) @@ -145,23 +152,21 @@ class ItemDescriptionFragment : Fragment() { override fun onStart() { super.onStart() - controller = object : PlaybackController(activity) { - override fun loadMediaInfo() { - load() - } - } - controller?.init() - load() +// controller = object : PlaybackController(activity) { +// override fun loadMediaInfo() { +// load() +// } +// } +// controller?.init() +// load() } override fun onStop() { super.onStop() - if (webViewLoader != null) { - webViewLoader!!.dispose() - } - controller!!.release() - controller = null + webViewLoader?.dispose() +// controller?.release() +// controller = null } companion object { diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/ItemFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/ItemFragment.kt index 58e65f8b..00a959ce 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/ItemFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/ItemFragment.kt @@ -154,6 +154,16 @@ class ItemFragment : Fragment() { } actionButton2?.onClick(requireContext()) }) + + EventBus.getDefault().register(this) + controller = object : PlaybackController(activity) { + override fun loadMediaInfo() { + // Do nothing + } + } + controller?.init() + load() + return layout } @@ -193,14 +203,14 @@ class ItemFragment : Fragment() { @UnstableApi override fun onStart() { super.onStart() - EventBus.getDefault().register(this) - controller = object : PlaybackController(activity) { - override fun loadMediaInfo() { - // Do nothing - } - } - controller?.init() - load() +// EventBus.getDefault().register(this) +// controller = object : PlaybackController(activity) { +// override fun loadMediaInfo() { +// // Do nothing +// } +// } +// controller?.init() +// load() } @UnstableApi override fun onResume() { @@ -213,12 +223,14 @@ class ItemFragment : Fragment() { @UnstableApi override fun onStop() { super.onStop() - EventBus.getDefault().unregister(this) - controller?.release() +// EventBus.getDefault().unregister(this) +// controller?.release() } - override fun onDestroyView() { + @OptIn(UnstableApi::class) override fun onDestroyView() { super.onDestroyView() + EventBus.getDefault().unregister(this) + controller?.release() disposable?.dispose() root.removeView(webvDescription) webvDescription.destroy() diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/QueueFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/QueueFragment.kt index 2d812153..53b7f4e7 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/QueueFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/QueueFragment.kt @@ -142,8 +142,8 @@ class QueueFragment : Fragment(), Toolbar.OnMenuItemClickListener, SelectableAda speedDialView = root.findViewById(R.id.fabSD) speedDialView.overlayLayout = root.findViewById(R.id.fabSDOverlay) speedDialView.inflate(R.menu.episodes_apply_action_speeddial) - speedDialView.removeActionItemById(R.id.mark_read_batch) - speedDialView.removeActionItemById(R.id.mark_unread_batch) +// speedDialView.removeActionItemById(R.id.mark_read_batch) +// speedDialView.removeActionItemById(R.id.mark_unread_batch) speedDialView.removeActionItemById(R.id.add_to_queue_batch) speedDialView.removeActionItemById(R.id.remove_all_inbox_item) speedDialView.setOnChangeListener(object : SpeedDialView.OnChangeListener { @@ -337,9 +337,7 @@ class QueueFragment : Fragment(), Toolbar.OnMenuItemClickListener, SelectableAda val conDialog: ConfirmationDialog = object : ConfirmationDialog(requireContext(), R.string.clear_queue_label, R.string.clear_queue_confirmation_msg) { - @UnstableApi override fun onConfirmButtonPressed( - dialog: DialogInterface - ) { + @UnstableApi override fun onConfirmButtonPressed(dialog: DialogInterface) { dialog.dismiss() DBWriter.clearQueue() } @@ -512,11 +510,7 @@ class QueueFragment : Fragment(), Toolbar.OnMenuItemClickListener, SelectableAda return view } - override fun onAddItem(title: Int, - ascending: SortOrder, - descending: SortOrder, - ascendingIsDefault: Boolean - ) { + override fun onAddItem(title: Int, ascending: SortOrder, descending: SortOrder, ascendingIsDefault: Boolean) { if (ascending != SortOrder.EPISODE_FILENAME_A_Z && ascending != SortOrder.SIZE_SMALL_LARGE) { super.onAddItem(title, ascending, descending, ascendingIsDefault) } diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/AutoDownloadPreferencesFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/AutoDownloadPreferencesFragment.kt index 74d7762b..f1f369d4 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/AutoDownloadPreferencesFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/AutoDownloadPreferencesFragment.kt @@ -35,7 +35,7 @@ class AutoDownloadPreferencesFragment : PreferenceFragmentCompat() { override fun onStart() { super.onStart() - (activity as PreferenceActivity?)!!.supportActionBar!!.setTitle(R.string.pref_automatic_download_title) + (activity as PreferenceActivity).supportActionBar!!.setTitle(R.string.pref_automatic_download_title) } override fun onResume() { diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/DownloadsPreferencesFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/DownloadsPreferencesFragment.kt index c284bf13..bd85cd7f 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/DownloadsPreferencesFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/DownloadsPreferencesFragment.kt @@ -32,7 +32,7 @@ class DownloadsPreferencesFragment : PreferenceFragmentCompat(), OnSharedPrefere override fun onStart() { super.onStart() - (activity as PreferenceActivity?)!!.supportActionBar!!.setTitle(R.string.downloads_pref) + (activity as PreferenceActivity).supportActionBar!!.setTitle(R.string.downloads_pref) PreferenceManager.getDefaultSharedPreferences(requireContext()).registerOnSharedPreferenceChangeListener( this) } @@ -51,7 +51,7 @@ class DownloadsPreferencesFragment : PreferenceFragmentCompat(), OnSharedPrefere private fun setupNetworkScreen() { findPreference(PREF_SCREEN_AUTODL)!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { preference: Preference? -> - (activity as PreferenceActivity?)!!.openScreen(R.xml.preferences_autodownload) + (activity as PreferenceActivity).openScreen(R.xml.preferences_autodownload) true } // validate and set correct value: number of downloads between 1 and 50 (inclusive) diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/ImportExportPreferencesFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/ImportExportPreferencesFragment.kt index e51b3904..c75ff997 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/ImportExportPreferencesFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/ImportExportPreferencesFragment.kt @@ -75,7 +75,7 @@ class ImportExportPreferencesFragment : PreferenceFragmentCompat() { override fun onStart() { super.onStart() - (activity as PreferenceActivity?)!!.supportActionBar!!.setTitle(R.string.import_export_pref) + (activity as PreferenceActivity).supportActionBar!!.setTitle(R.string.import_export_pref) } override fun onStop() { diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/MainPreferencesFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/MainPreferencesFragment.kt index da39ed8c..6ea20db3 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/MainPreferencesFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/MainPreferencesFragment.kt @@ -54,39 +54,39 @@ class MainPreferencesFragment : PreferenceFragmentCompat() { override fun onStart() { super.onStart() - (activity as PreferenceActivity?)!!.supportActionBar!!.setTitle(R.string.settings_label) + (activity as PreferenceActivity).supportActionBar!!.setTitle(R.string.settings_label) } @SuppressLint("CommitTransaction") private fun setupMainScreen() { findPreference(PREF_SCREEN_USER_INTERFACE)!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { preference: Preference? -> - (activity as PreferenceActivity?)!!.openScreen(R.xml.preferences_user_interface) + (activity as PreferenceActivity).openScreen(R.xml.preferences_user_interface) true } findPreference(PREF_SCREEN_PLAYBACK)!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { preference: Preference? -> - (activity as PreferenceActivity?)!!.openScreen(R.xml.preferences_playback) + (activity as PreferenceActivity).openScreen(R.xml.preferences_playback) true } findPreference(PREF_SCREEN_DOWNLOADS)!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { preference: Preference? -> - (activity as PreferenceActivity?)!!.openScreen(R.xml.preferences_downloads) + (activity as PreferenceActivity).openScreen(R.xml.preferences_downloads) true } findPreference(PREF_SCREEN_SYNCHRONIZATION)!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { preference: Preference? -> - (activity as PreferenceActivity?)!!.openScreen(R.xml.preferences_synchronization) + (activity as PreferenceActivity).openScreen(R.xml.preferences_synchronization) true } findPreference(PREF_SCREEN_IMPORT_EXPORT)!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { preference: Preference? -> - (activity as PreferenceActivity?)!!.openScreen(R.xml.preferences_import_export) + (activity as PreferenceActivity).openScreen(R.xml.preferences_import_export) true } findPreference(PREF_NOTIFICATION)!!.onPreferenceClickListener = Preference.OnPreferenceClickListener { preference: Preference? -> - (activity as PreferenceActivity?)!!.openScreen(R.xml.preferences_notifications) + (activity as PreferenceActivity).openScreen(R.xml.preferences_notifications) true } findPreference(PREF_ABOUT)!!.onPreferenceClickListener = diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/NotificationPreferencesFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/NotificationPreferencesFragment.kt index bfb74293..63d1053f 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/NotificationPreferencesFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/NotificationPreferencesFragment.kt @@ -15,7 +15,7 @@ class NotificationPreferencesFragment : PreferenceFragmentCompat() { override fun onStart() { super.onStart() - (activity as PreferenceActivity?)!!.supportActionBar!!.setTitle(R.string.notification_pref_fragment) + (activity as PreferenceActivity).supportActionBar!!.setTitle(R.string.notification_pref_fragment) } private fun setUpScreen() { diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/PlaybackPreferencesFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/PlaybackPreferencesFragment.kt index 9b2bd880..a60a2e1e 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/PlaybackPreferencesFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/PlaybackPreferencesFragment.kt @@ -27,7 +27,7 @@ class PlaybackPreferencesFragment : PreferenceFragmentCompat() { override fun onStart() { super.onStart() - (activity as PreferenceActivity?)!!.supportActionBar!!.setTitle(R.string.playback_pref) + (activity as PreferenceActivity).supportActionBar!!.setTitle(R.string.playback_pref) } private fun setupPlaybackScreen() { diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/SwipePreferencesFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/SwipePreferencesFragment.kt index 18c4a161..cae5a170 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/SwipePreferencesFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/SwipePreferencesFragment.kt @@ -58,7 +58,7 @@ class SwipePreferencesFragment : PreferenceFragmentCompat() { override fun onStart() { super.onStart() - (activity as PreferenceActivity?)!!.supportActionBar!!.setTitle(R.string.swipeactions_label) + (activity as PreferenceActivity).supportActionBar!!.setTitle(R.string.swipeactions_label) } companion object { diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/UserInterfacePreferencesFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/UserInterfacePreferencesFragment.kt index 5ce5fe7a..5691bc54 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/UserInterfacePreferencesFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/UserInterfacePreferencesFragment.kt @@ -31,7 +31,7 @@ class UserInterfacePreferencesFragment : PreferenceFragmentCompat() { override fun onStart() { super.onStart() - (activity as PreferenceActivity?)!!.supportActionBar!!.setTitle(R.string.user_interface_label) + (activity as PreferenceActivity).supportActionBar!!.setTitle(R.string.user_interface_label) } private fun setupInterfaceScreen() { @@ -78,7 +78,7 @@ class UserInterfacePreferencesFragment : PreferenceFragmentCompat() { }) findPreference(PREF_SWIPE) ?.setOnPreferenceClickListener { preference: Preference? -> - (activity as PreferenceActivity?)!!.openScreen(R.xml.preferences_swipe) + (activity as PreferenceActivity).openScreen(R.xml.preferences_swipe) true } diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/about/AboutFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/about/AboutFragment.kt index 35fb879a..c57fc0dd 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/about/AboutFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/about/AboutFragment.kt @@ -57,6 +57,6 @@ class AboutFragment : PreferenceFragmentCompat() { override fun onStart() { super.onStart() - (activity as PreferenceActivity?)!!.supportActionBar!!.setTitle(R.string.about_pref) + (activity as PreferenceActivity).supportActionBar!!.setTitle(R.string.about_pref) } } diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/about/ContributorsPagerFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/about/ContributorsPagerFragment.kt index 32cf8d56..47849770 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/about/ContributorsPagerFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/about/ContributorsPagerFragment.kt @@ -44,7 +44,7 @@ class ContributorsPagerFragment : Fragment() { override fun onStart() { super.onStart() - (activity as PreferenceActivity?)!!.supportActionBar!!.setTitle(R.string.contributors) + (activity as PreferenceActivity).supportActionBar!!.setTitle(R.string.contributors) } class StatisticsPagerAdapter internal constructor(fragment: Fragment) : FragmentStateAdapter(fragment) { diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/about/LicensesFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/about/LicensesFragment.kt index 5d847382..482fcc6e 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/about/LicensesFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/about/LicensesFragment.kt @@ -98,13 +98,11 @@ class LicensesFragment : ListFragment() { override fun onStop() { super.onStop() - if (licensesLoader != null) { - licensesLoader!!.dispose() - } + licensesLoader?.dispose() } override fun onStart() { super.onStart() - (activity as PreferenceActivity?)!!.supportActionBar!!.setTitle(R.string.licenses) + (activity as PreferenceActivity).supportActionBar!!.setTitle(R.string.licenses) } } diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/synchronization/SynchronizationPreferencesFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/synchronization/SynchronizationPreferencesFragment.kt index 201de764..85905724 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/synchronization/SynchronizationPreferencesFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/preferences/synchronization/SynchronizationPreferencesFragment.kt @@ -37,7 +37,7 @@ class SynchronizationPreferencesFragment : PreferenceFragmentCompat() { override fun onStart() { super.onStart() - (activity as PreferenceActivity?)!!.supportActionBar!!.setTitle(R.string.synchronization_pref) + (activity as PreferenceActivity).supportActionBar!!.setTitle(R.string.synchronization_pref) updateScreen() EventBus.getDefault().register(this) } @@ -45,7 +45,7 @@ class SynchronizationPreferencesFragment : PreferenceFragmentCompat() { override fun onStop() { super.onStop() EventBus.getDefault().unregister(this) - (activity as PreferenceActivity?)!!.supportActionBar!!.subtitle = "" + (activity as PreferenceActivity).supportActionBar!!.subtitle = "" } @Subscribe(threadMode = ThreadMode.MAIN, sticky = true) @@ -59,7 +59,7 @@ class SynchronizationPreferencesFragment : PreferenceFragmentCompat() { updateLastSyncReport(SynchronizationSettings.isLastSyncSuccessful, SynchronizationSettings.lastSyncAttempt) } else { - (activity as PreferenceActivity?)!!.supportActionBar!! + (activity as PreferenceActivity).supportActionBar!! .setSubtitle(event.messageResId) } } @@ -203,7 +203,7 @@ class SynchronizationPreferencesFragment : PreferenceFragmentCompat() { ) R.string.gpodnetsync_pref_report_successful else R.string.gpodnetsync_pref_report_failed), DateUtils.getRelativeDateTimeString(context, lastTime, DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, DateUtils.FORMAT_SHOW_TIME)) - (activity as PreferenceActivity?)!!.supportActionBar!!.subtitle = status + (activity as PreferenceActivity).supportActionBar!!.subtitle = status } companion object { diff --git a/app/src/main/java/ac/mdiq/podvinci/ui/home/HomeFragment.kt b/app/src/main/java/ac/mdiq/podvinci/ui/home/HomeFragment.kt index efce2e89..efae7450 100644 --- a/app/src/main/java/ac/mdiq/podvinci/ui/home/HomeFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/ui/home/HomeFragment.kt @@ -29,6 +29,7 @@ import ac.mdiq.podvinci.storage.preferences.UserPreferences import ac.mdiq.podvinci.ui.echo.EchoActivity import ac.mdiq.podvinci.ui.home.sections.* import ac.mdiq.podvinci.view.LiftOnScrollListener +import androidx.annotation.OptIn import androidx.media3.common.util.UnstableApi import io.reactivex.Observable import io.reactivex.android.schedulers.AndroidSchedulers @@ -68,7 +69,7 @@ class HomeFragment : Fragment(), Toolbar.OnMenuItemClickListener { return viewBinding.root } - private fun populateSectionList() { + @OptIn(UnstableApi::class) private fun populateSectionList() { viewBinding.homeContainer.removeAllViews() val prefs: SharedPreferences = requireContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE) diff --git a/app/src/main/res/layout/home_section.xml b/app/src/main/res/layout/home_section.xml index c1bac5e9..27307041 100644 --- a/app/src/main/res/layout/home_section.xml +++ b/app/src/main/res/layout/home_section.xml @@ -12,7 +12,7 @@ diff --git a/core/src/main/java/ac/mdiq/podvinci/core/service/playback/PlaybackService.kt b/core/src/main/java/ac/mdiq/podvinci/core/service/playback/PlaybackService.kt index d917473e..452987ad 100644 --- a/core/src/main/java/ac/mdiq/podvinci/core/service/playback/PlaybackService.kt +++ b/core/src/main/java/ac/mdiq/podvinci/core/service/playback/PlaybackService.kt @@ -1656,12 +1656,14 @@ class PlaybackService : MediaBrowserServiceCompat() { positionEventTimer = Observable.interval(POSITION_EVENT_INTERVAL, TimeUnit.SECONDS) .observeOn(AndroidSchedulers.mainThread()) .subscribe { number: Long? -> + Log.d(TAG, "notificationBuilder.updatePosition currentPosition: $currentPosition, currentPlaybackSpeed: $currentPlaybackSpeed") EventBus.getDefault().post(PlaybackPositionEvent(currentPosition, duration)) - if (Build.VERSION.SDK_INT < 29) { +// TODO: why set SDK_INT < 29 +// if (Build.VERSION.SDK_INT < 29) { notificationBuilder.updatePosition(currentPosition, currentPlaybackSpeed) val notificationManager = getSystemService(NOTIFICATION_SERVICE) as? NotificationManager notificationManager?.notify(R.id.notification_playing, notificationBuilder.build()) - } +// } skipEndingIfNecessary() } } @@ -1860,6 +1862,7 @@ class PlaybackService : MediaBrowserServiceCompat() { */ private const val TAG = "PlaybackService" +// TODO: need to experiment this value private const val POSITION_EVENT_INTERVAL = 10L const val ACTION_PLAYER_STATUS_CHANGED: String = "action.ac.mdiq.podvinci.core.service.playerStatusChanged" diff --git a/core/src/main/java/ac/mdiq/podvinci/core/service/playback/PlaybackServiceNotificationBuilder.kt b/core/src/main/java/ac/mdiq/podvinci/core/service/playback/PlaybackServiceNotificationBuilder.kt index aa97a01d..f6a3f257 100644 --- a/core/src/main/java/ac/mdiq/podvinci/core/service/playback/PlaybackServiceNotificationBuilder.kt +++ b/core/src/main/java/ac/mdiq/podvinci/core/service/playback/PlaybackServiceNotificationBuilder.kt @@ -176,11 +176,9 @@ class PlaybackServiceNotificationBuilder(private val context: Context) { compactActionList.add(numActions) numActions++ - if (UserPreferences.showNextChapterOnFullNotification() && playable!!.getChapters() != null) { - val nextChapterPendingIntent = getPendingIntentForCustomMediaAction( - PlaybackService.CUSTOM_ACTION_NEXT_CHAPTER, numActions) - notification.addAction(R.drawable.ic_notification_next_chapter, context.getString(R.string.next_chapter), - nextChapterPendingIntent) + if (UserPreferences.showNextChapterOnFullNotification() && playable?.getChapters() != null) { + val nextChapterPendingIntent = getPendingIntentForCustomMediaAction(PlaybackService.CUSTOM_ACTION_NEXT_CHAPTER, numActions) + notification.addAction(R.drawable.ic_notification_next_chapter, context.getString(R.string.next_chapter), nextChapterPendingIntent) numActions++ } diff --git a/core/src/main/java/ac/mdiq/podvinci/core/storage/APQueueCleanupAlgorithm.kt b/core/src/main/java/ac/mdiq/podvinci/core/storage/APQueueCleanupAlgorithm.kt index 8787240a..6d0c716d 100644 --- a/core/src/main/java/ac/mdiq/podvinci/core/storage/APQueueCleanupAlgorithm.kt +++ b/core/src/main/java/ac/mdiq/podvinci/core/storage/APQueueCleanupAlgorithm.kt @@ -22,10 +22,10 @@ class APQueueCleanupAlgorithm : EpisodeCleanupAlgorithm() { } public override fun performCleanup(context: Context?, numberOfEpisodesToDelete: Int): Int { - val candidates = candidates + var candidates = candidates // in the absence of better data, we'll sort by item publication date - Collections.sort(candidates) { lhs: FeedItem, rhs: FeedItem -> + candidates = candidates.sortedWith { lhs: FeedItem, rhs: FeedItem -> var l = lhs.getPubDate() var r = rhs.getPubDate() diff --git a/core/src/main/java/ac/mdiq/podvinci/core/storage/DBReader.kt b/core/src/main/java/ac/mdiq/podvinci/core/storage/DBReader.kt index 2522d338..2253c77a 100644 --- a/core/src/main/java/ac/mdiq/podvinci/core/storage/DBReader.kt +++ b/core/src/main/java/ac/mdiq/podvinci/core/storage/DBReader.kt @@ -342,9 +342,9 @@ object DBReader { i++ } itemCursor = adapter.getFeedItemCursor(itemIds.filterNotNull().toTypedArray()) - val items = extractItemlistFromCursor(adapter, itemCursor) + val items = extractItemlistFromCursor(adapter, itemCursor).toMutableList() loadAdditionalFeedItemListData(items) - Collections.sort(items, PlaybackCompletionDateComparator()) + items.sortWith(PlaybackCompletionDateComparator()) return items } finally { mediaCursor?.close() @@ -378,7 +378,7 @@ object DBReader { while (cursor.moveToNext()) { downloadLog.add(convert(cursor)) } - Collections.sort(downloadLog, DownloadResultComparator()) + downloadLog.sortWith(DownloadResultComparator()) return downloadLog } } finally { @@ -404,7 +404,7 @@ object DBReader { while (cursor.moveToNext()) { downloadLog.add(convert(cursor)) } - Collections.sort(downloadLog, DownloadResultComparator()) + downloadLog.sortWith(DownloadResultComparator()) return downloadLog } } finally { @@ -621,6 +621,11 @@ object DBReader { */ fun loadDescriptionOfFeedItem(item: FeedItem) { Log.d(TAG, "loadDescriptionOfFeedItem() called with: item = [$item]") + // TODO: need to find out who are often calling this +// val stackTraceElements = Thread.currentThread().stackTrace +// stackTraceElements.forEach { element -> +// println(element) +// } val adapter = getInstance() adapter!!.open() try { @@ -712,9 +717,9 @@ object DBReader { adapter!!.open() try { adapter.getFeedItemCursorByUrl(urls!!).use { itemCursor -> - val items = extractItemlistFromCursor(adapter, itemCursor) + val items = extractItemlistFromCursor(adapter, itemCursor).toMutableList() loadAdditionalFeedItemListData(items) - Collections.sort(items, PlaybackCompletionDateComparator()) + items.sortWith(PlaybackCompletionDateComparator()) return items } } finally { @@ -870,7 +875,7 @@ object DBReader { } } - Collections.sort(feeds, comparator) + feeds = feeds.sortedWith(comparator) val queueSize = adapter.queueSize val numNewItems = getTotalEpisodeCount(FeedItemFilter(FeedItemFilter.NEW)) val numDownloadedItems = getTotalEpisodeCount(FeedItemFilter(FeedItemFilter.DOWNLOADED)) diff --git a/core/src/main/java/ac/mdiq/podvinci/core/storage/DBTasks.kt b/core/src/main/java/ac/mdiq/podvinci/core/storage/DBTasks.kt index 3c637521..7e754036 100644 --- a/core/src/main/java/ac/mdiq/podvinci/core/storage/DBTasks.kt +++ b/core/src/main/java/ac/mdiq/podvinci/core/storage/DBTasks.kt @@ -211,7 +211,7 @@ import java.util.concurrent.* } else { Log.d(TAG, "Feed with title " + newFeed.title + " already exists. Syncing new with existing one.") - Collections.sort(newFeed.items, FeedItemPubdateComparator()) + newFeed.items.sortWith(FeedItemPubdateComparator()) if (newFeed.pageNr == savedFeed.pageNr) { if (savedFeed.compareWithOther(newFeed)) { diff --git a/core/src/main/java/ac/mdiq/podvinci/core/storage/ExceptFavoriteCleanupAlgorithm.kt b/core/src/main/java/ac/mdiq/podvinci/core/storage/ExceptFavoriteCleanupAlgorithm.kt index 3590823f..c88ed101 100644 --- a/core/src/main/java/ac/mdiq/podvinci/core/storage/ExceptFavoriteCleanupAlgorithm.kt +++ b/core/src/main/java/ac/mdiq/podvinci/core/storage/ExceptFavoriteCleanupAlgorithm.kt @@ -26,17 +26,17 @@ class ExceptFavoriteCleanupAlgorithm : EpisodeCleanupAlgorithm() { } public override fun performCleanup(context: Context?, numberOfEpisodesToDelete: Int): Int { - val candidates = candidates + var candidates = candidates // in the absence of better data, we'll sort by item publication date - Collections.sort(candidates) { lhs: FeedItem, rhs: FeedItem -> + candidates = candidates.sortedWith { lhs: FeedItem, rhs: FeedItem -> val l = lhs.getPubDate() val r = rhs.getPubDate() if (l != null && r != null) { - return@sort l.compareTo(r) + return@sortedWith l.compareTo(r) } else { // No date - compare by id which should be always incremented - return@sort lhs.id.compareTo(rhs.id) + return@sortedWith lhs.id.compareTo(rhs.id) } } diff --git a/core/src/main/java/ac/mdiq/podvinci/core/util/ChapterUtils.kt b/core/src/main/java/ac/mdiq/podvinci/core/util/ChapterUtils.kt index 7ba669fa..1bf757bb 100644 --- a/core/src/main/java/ac/mdiq/podvinci/core/util/ChapterUtils.kt +++ b/core/src/main/java/ac/mdiq/podvinci/core/util/ChapterUtils.kt @@ -167,8 +167,8 @@ object ChapterUtils { private fun readId3ChaptersFrom(inVal: CountingInputStream): List { val reader = ChapterReader(inVal) reader.readInputStream() - val chapters = reader.getChapters() - Collections.sort(chapters, ChapterStartTimeComparator()) + var chapters = reader.getChapters() + chapters = chapters.sortedWith(ChapterStartTimeComparator()) enumerateEmptyChapterTitles(chapters) if (!chaptersValid(chapters)) { Log.i(TAG, "Chapter data was invalid") @@ -181,8 +181,8 @@ object ChapterUtils { private fun readOggChaptersFromInputStream(input: InputStream): List { val reader = VorbisCommentChapterReader(BufferedInputStream(input)) reader.readInputStream() - val chapters = reader.getChapters() - Collections.sort(chapters, ChapterStartTimeComparator()) + var chapters = reader.getChapters() + chapters = chapters.sortedWith(ChapterStartTimeComparator()) enumerateEmptyChapterTitles(chapters) if (chaptersValid(chapters)) { return chapters diff --git a/core/src/main/java/ac/mdiq/podvinci/core/util/FeedItemPermutors.kt b/core/src/main/java/ac/mdiq/podvinci/core/util/FeedItemPermutors.kt index 72063e60..c89fc5ea 100644 --- a/core/src/main/java/ac/mdiq/podvinci/core/util/FeedItemPermutors.kt +++ b/core/src/main/java/ac/mdiq/podvinci/core/util/FeedItemPermutors.kt @@ -139,7 +139,7 @@ object FeedItemPermutors { val feeds: MutableList> = ArrayList() for ((_, value) in map) { - Collections.sort(value, itemComparator) + value.sortWith(itemComparator) feeds.add(value) } diff --git a/core/src/main/java/ac/mdiq/podvinci/core/util/playback/PlaybackController.kt b/core/src/main/java/ac/mdiq/podvinci/core/util/playback/PlaybackController.kt index b0db8ae4..ee39dc87 100644 --- a/core/src/main/java/ac/mdiq/podvinci/core/util/playback/PlaybackController.kt +++ b/core/src/main/java/ac/mdiq/podvinci/core/util/playback/PlaybackController.kt @@ -19,7 +19,6 @@ import android.os.IBinder import android.util.Log import android.util.Pair import android.view.SurfaceHolder -import androidx.core.content.ContextCompat import androidx.fragment.app.FragmentActivity import androidx.media3.common.util.UnstableApi import org.greenrobot.eventbus.EventBus @@ -73,7 +72,6 @@ abstract class PlaybackController(private val activity: FragmentActivity?) { } initialized = true -// TODO: this shit doesn't work if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { activity?.registerReceiver(statusUpdate, IntentFilter( PlaybackService.ACTION_PLAYER_STATUS_CHANGED), Context.RECEIVER_NOT_EXPORTED) diff --git a/core/src/test/java/ac/mdiq/podvinci/core/storage/DbTestUtils.kt b/core/src/test/java/ac/mdiq/podvinci/core/storage/DbTestUtils.kt index fb2e75db..38dd33cc 100644 --- a/core/src/test/java/ac/mdiq/podvinci/core/storage/DbTestUtils.kt +++ b/core/src/test/java/ac/mdiq/podvinci/core/storage/DbTestUtils.kt @@ -48,9 +48,9 @@ internal object DbTestUtils { "http://example.com", "http://example.com/image.png")) } } - f.items?.add(item) + f.items.add(item) } - Collections.sort(f.items, FeedItemPubdateComparator()) + f.items.sortWith(FeedItemPubdateComparator()) adapter.setCompleteFeed(f) Assert.assertTrue(f.id != 0L) for (item in f.items!!) { diff --git a/storage/database/src/main/java/ac/mdiq/podvinci/storage/database/mapper/DownloadResultCursorMapper.kt b/storage/database/src/main/java/ac/mdiq/podvinci/storage/database/mapper/DownloadResultCursorMapper.kt index d398cde1..081f53fd 100644 --- a/storage/database/src/main/java/ac/mdiq/podvinci/storage/database/mapper/DownloadResultCursorMapper.kt +++ b/storage/database/src/main/java/ac/mdiq/podvinci/storage/database/mapper/DownloadResultCursorMapper.kt @@ -24,10 +24,15 @@ object DownloadResultCursorMapper { val indexCompletionDate = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_COMPLETION_DATE) val indexReasonDetailed = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_REASON_DETAILED) - return DownloadResult(cursor.getLong(indexId), cursor.getString(indexTitle), cursor.getLong(indexFeedFile), - cursor.getInt(indexFileFileType), cursor.getInt(indexSuccessful) > 0, + return DownloadResult( + cursor.getLong(indexId), + cursor.getString(indexTitle), + cursor.getLong(indexFeedFile), + cursor.getInt(indexFileFileType), + cursor.getInt(indexSuccessful) > 0, fromCode(cursor.getInt(indexReason)), Date(cursor.getLong(indexCompletionDate)), - cursor.getString(indexReasonDetailed)) + if (!cursor.isNull(indexReasonDetailed)) cursor.getString(indexReasonDetailed) else "" + ) } } diff --git a/ui/statistics/src/main/java/ac/mdiq/podvinci/ui/statistics/feed/FeedStatisticsFragment.kt b/ui/statistics/src/main/java/ac/mdiq/podvinci/ui/statistics/feed/FeedStatisticsFragment.kt index 30b40369..f364d620 100644 --- a/ui/statistics/src/main/java/ac/mdiq/podvinci/ui/statistics/feed/FeedStatisticsFragment.kt +++ b/ui/statistics/src/main/java/ac/mdiq/podvinci/ui/statistics/feed/FeedStatisticsFragment.kt @@ -44,10 +44,10 @@ class FeedStatisticsFragment : Fragment() { disposable = Observable.fromCallable { val statisticsData = DBReader.getStatistics(true, 0, Long.MAX_VALUE) - Collections.sort(statisticsData.feedTime) { item1: StatisticsItem, item2: StatisticsItem -> + statisticsData.feedTime.sortWith(Comparator { item1: StatisticsItem, item2: StatisticsItem -> java.lang.Long.compare(item2.timePlayed, item1.timePlayed) - } + }) for (statisticsItem in statisticsData.feedTime) { if (statisticsItem.feed.id == feedId) {