diff --git a/app/src/main/java/ac/mdiq/podvinci/adapter/EpisodeItemListAdapter.kt b/app/src/main/java/ac/mdiq/podvinci/adapter/EpisodeItemListAdapter.kt index 1b499bb2..a253058c 100644 --- a/app/src/main/java/ac/mdiq/podvinci/adapter/EpisodeItemListAdapter.kt +++ b/app/src/main/java/ac/mdiq/podvinci/adapter/EpisodeItemListAdapter.kt @@ -69,7 +69,7 @@ open class EpisodeItemListAdapter(mainActivity: MainActivity) : SelectableAdapte val item: FeedItem = episodes[pos] holder.bind(item) - holder.itemView.setOnClickListener(View.OnClickListener { v: View? -> + holder.itemView.setOnClickListener { v: View? -> val activity: MainActivity? = mainActivityRef.get() if (activity != null && !inActionMode()) { val ids: LongArray = FeedItemUtil.getIds(episodes) @@ -78,13 +78,13 @@ open class EpisodeItemListAdapter(mainActivity: MainActivity) : SelectableAdapte } else { toggleSelection(holder.bindingAdapterPosition) } - }) + } holder.itemView.setOnCreateContextMenuListener(this) - holder.itemView.setOnLongClickListener(View.OnLongClickListener { v: View? -> + holder.itemView.setOnLongClickListener { v: View? -> longPressedItem = item longPressedPosition = holder.bindingAdapterPosition false - }) + } holder.itemView.setOnTouchListener(View.OnTouchListener { v: View?, e: MotionEvent -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (e.isFromSource(InputDevice.SOURCE_MOUSE) @@ -163,7 +163,7 @@ open class EpisodeItemListAdapter(mainActivity: MainActivity) : SelectableAdapte protected val activity: Activity? get() = mainActivityRef.get() - @UnstableApi override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo) { + @UnstableApi override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) { val inflater: MenuInflater = mainActivityRef.get()!!.menuInflater if (inActionMode()) { inflater.inflate(R.menu.multi_select_context_popup, menu) @@ -194,7 +194,7 @@ open class EpisodeItemListAdapter(mainActivity: MainActivity) : SelectableAdapte val selectedItems: List get() { - val items: MutableList = ArrayList() + val items: MutableList = ArrayList() for (i in 0 until itemCount) { if (isSelected(i)) { items.add(getItem(i)) diff --git a/app/src/main/java/ac/mdiq/podvinci/adapter/HorizontalItemListAdapter.kt b/app/src/main/java/ac/mdiq/podvinci/adapter/HorizontalItemListAdapter.kt index 46276cd7..691ce051 100644 --- a/app/src/main/java/ac/mdiq/podvinci/adapter/HorizontalItemListAdapter.kt +++ b/app/src/main/java/ac/mdiq/podvinci/adapter/HorizontalItemListAdapter.kt @@ -106,7 +106,7 @@ open class HorizontalItemListAdapter(mainActivity: MainActivity) : RecyclerView. notifyItemChanged(position, "foo") } - @UnstableApi override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo) { + @UnstableApi override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) { val inflater: MenuInflater = mainActivityRef.get()!!.menuInflater if (longPressedItem == null) { return diff --git a/app/src/main/java/ac/mdiq/podvinci/adapter/NavListAdapter.kt b/app/src/main/java/ac/mdiq/podvinci/adapter/NavListAdapter.kt index 474958ad..4aa7a355 100644 --- a/app/src/main/java/ac/mdiq/podvinci/adapter/NavListAdapter.kt +++ b/app/src/main/java/ac/mdiq/podvinci/adapter/NavListAdapter.kt @@ -352,7 +352,7 @@ class NavListAdapter(private val itemAccess: ItemAccess, context: Activity) : fun onItemLongClick(position: Int): Boolean - override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenuInfo) + override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenuInfo?) } companion object { diff --git a/app/src/main/java/ac/mdiq/podvinci/adapter/QueueRecyclerAdapter.kt b/app/src/main/java/ac/mdiq/podvinci/adapter/QueueRecyclerAdapter.kt index 2f84c055..72fe8e36 100644 --- a/app/src/main/java/ac/mdiq/podvinci/adapter/QueueRecyclerAdapter.kt +++ b/app/src/main/java/ac/mdiq/podvinci/adapter/QueueRecyclerAdapter.kt @@ -67,7 +67,7 @@ open class QueueRecyclerAdapter(mainActivity: MainActivity, swipeActions: SwipeA holder.isInQueue.setVisibility(View.GONE) } - @UnstableApi override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo) { + @UnstableApi override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) { val inflater: MenuInflater = activity!!.getMenuInflater() inflater.inflate(R.menu.queue_context, menu) super.onCreateContextMenu(menu, v, menuInfo) diff --git a/app/src/main/java/ac/mdiq/podvinci/dialog/DownloadLogDetailsDialog.kt b/app/src/main/java/ac/mdiq/podvinci/dialog/DownloadLogDetailsDialog.kt index 453afaa7..cf59776b 100644 --- a/app/src/main/java/ac/mdiq/podvinci/dialog/DownloadLogDetailsDialog.kt +++ b/app/src/main/java/ac/mdiq/podvinci/dialog/DownloadLogDetailsDialog.kt @@ -43,8 +43,7 @@ class DownloadLogDetailsDialog(context: Context, status: DownloadResult) : Mater setMessage(messageFull) setPositiveButton("OK", null) setNeutralButton(R.string.copy_to_clipboard) { dialog, which -> - val clipboard = getContext() - .getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + val clipboard = getContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager val clip = ClipData.newPlainText(context.getString(R.string.download_error_details), messageFull) clipboard.setPrimaryClip(clip) if (Build.VERSION.SDK_INT < 32) { @@ -55,7 +54,7 @@ class DownloadLogDetailsDialog(context: Context, status: DownloadResult) : Mater override fun show(): AlertDialog { val dialog = super.show() - (dialog.findViewById(R.id.message) as TextView?)!!.setTextIsSelectable(true) + (dialog.findViewById(R.id.message) as? TextView)?.setTextIsSelectable(true) return dialog } } diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/CompletedDownloadsFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/CompletedDownloadsFragment.kt index 2468bfb0..cbd5f4db 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/CompletedDownloadsFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/CompletedDownloadsFragment.kt @@ -340,7 +340,7 @@ class CompletedDownloadsFragment : Fragment(), SelectableAdapter.OnSelectModeLis } } - override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo) { + override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) { super.onCreateContextMenu(menu, v, menuInfo) if (!inActionMode()) { menu.findItem(R.id.multi_select).setVisible(true) diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/EpisodesListFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/EpisodesListFragment.kt index 8421dd34..195675e1 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/EpisodesListFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/EpisodesListFragment.kt @@ -169,7 +169,7 @@ abstract class EpisodesListFragment : Fragment(), SelectableAdapter.OnSelectMode } listAdapter = object : EpisodeItemListAdapter(activity as MainActivity) { - override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo) { + override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) { super.onCreateContextMenu(menu, v, menuInfo) if (!inActionMode()) { menu.findItem(R.id.multi_select).setVisible(true) diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/FeedInfoFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/FeedInfoFragment.kt index eaf5c4fc..61f8e068 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/FeedInfoFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/FeedInfoFragment.kt @@ -303,16 +303,14 @@ class FeedInfoFragment : Fragment(), Toolbar.OnMenuItemClickListener { } @UnstableApi private fun reconnectLocalFolder(uri: Uri) { - if (feed == null) { - return - } + if (feed == null) return Completable.fromAction { requireActivity().contentResolver .takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION) val documentFile = DocumentFile.fromTreeUri(requireContext(), uri) requireNotNull(documentFile) { "Unable to retrieve document tree" } - feed?.download_url = Feed.PREFIX_LOCAL_FOLDER + uri.toString() + feed!!.download_url = Feed.PREFIX_LOCAL_FOLDER + uri.toString() DBTasks.updateFeed(requireContext(), feed!!, true) } .subscribeOn(Schedulers.io()) 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 35f6bbad..8f9b6454 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/FeedItemlistFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/FeedItemlistFragment.kt @@ -87,8 +87,8 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba if (args != null) feedID = args.getLong(ARGUMENT_FEED_ID) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? + @UnstableApi override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? ): View { viewBinding = FeedItemListFragmentBinding.inflate(inflater) speedDialBinding = MultiSelectSpeedDialBinding.bind(viewBinding!!.root) @@ -216,7 +216,7 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba horizontalSpacing, viewBinding!!.header.headerContainer.paddingBottom) } - override fun onMenuItemClick(item: MenuItem): Boolean { + @UnstableApi override fun onMenuItemClick(item: MenuItem): Boolean { if (feed == null) { (activity as MainActivity).showSnackbarAbovePlayer( R.string.please_wait_for_data, Toast.LENGTH_LONG) @@ -281,7 +281,7 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba return FeedItemMenuHandler.onMenuItemClicked(this, item.itemId, selectedItem) } - override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) { + @UnstableApi override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) { val activity: MainActivity = activity as MainActivity if (feed != null) { val ids: LongArray = FeedItemUtil.getIds(feed!!.items) @@ -289,7 +289,7 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba } } - @Subscribe(threadMode = ThreadMode.MAIN) + @UnstableApi @Subscribe(threadMode = ThreadMode.MAIN) fun onEvent(event: FeedEvent) { Log.d(TAG, "onEvent() called with: event = [$event]") if (event.feedId == feedID) { @@ -300,14 +300,14 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba @Subscribe(threadMode = ThreadMode.MAIN) fun onEventMainThread(event: FeedItemEvent) { Log.d(TAG, "onEventMainThread() called with: event = [$event]") - if (feed == null || feed!!.items == null) { + if (feed == null || feed!!.items.isEmpty()) { return } var i = 0 val size: Int = event.items.size while (i < size) { val item: FeedItem = event.items[i] - val pos: Int = FeedItemUtil.indexOfItemWithId(feed!!.items!!, item.id) + val pos: Int = FeedItemUtil.indexOfItemWithId(feed!!.items, item.id) if (pos >= 0) { feed?.items?.removeAt(pos) feed?.items?.add(pos, item) @@ -319,11 +319,11 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba @Subscribe(sticky = true, threadMode = ThreadMode.MAIN) fun onEventMainThread(event: EpisodeDownloadEvent) { - if (feed == null || feed!!.items == null) { + if (feed == null || feed!!.items.isEmpty()) { return } for (downloadUrl in event.urls) { - val pos: Int = FeedItemUtil.indexOfItemWithDownloadUrl(feed!!.items!!, downloadUrl) + val pos: Int = FeedItemUtil.indexOfItemWithDownloadUrl(feed!!.items, downloadUrl) if (pos >= 0) { adapter?.notifyItemChangedCompat(pos) } @@ -342,13 +342,15 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba } } - @Subscribe(threadMode = ThreadMode.MAIN) + @UnstableApi @Subscribe(threadMode = ThreadMode.MAIN) fun favoritesChanged(event: FavoritesEvent?) { + Log.d(TAG, "favoritesChanged called") updateUi() } - @Subscribe(threadMode = ThreadMode.MAIN) + @UnstableApi @Subscribe(threadMode = ThreadMode.MAIN) fun onQueueChanged(event: QueueEvent?) { + Log.d(TAG, "onQueueChanged called") updateUi() } @@ -368,23 +370,26 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba swipeActions?.attachTo(viewBinding!!.recyclerView) } - private fun updateUi() { + @UnstableApi private fun updateUi() { loadItems() } - @Subscribe(threadMode = ThreadMode.MAIN) + @UnstableApi @Subscribe(threadMode = ThreadMode.MAIN) fun onPlayerStatusChanged(event: PlayerStatusEvent?) { + Log.d(TAG, "onPlayerStatusChanged called") updateUi() } - @Subscribe(threadMode = ThreadMode.MAIN) + @UnstableApi @Subscribe(threadMode = ThreadMode.MAIN) fun onUnreadItemsChanged(event: UnreadItemsUpdateEvent?) { + Log.d(TAG, "onUnreadItemsChanged called") updateUi() } - @Subscribe(threadMode = ThreadMode.MAIN) + @UnstableApi @Subscribe(threadMode = ThreadMode.MAIN) fun onFeedListChanged(event: FeedListUpdateEvent) { if (feed != null && event.contains(feed!!)) { + Log.d(TAG, "onFeedListChanged called") updateUi() } } @@ -398,7 +403,7 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba viewBinding!!.swipeRefresh.isRefreshing = event.isFeedUpdateRunning } - private fun refreshHeaderView() { + @UnstableApi private fun refreshHeaderView() { setupHeaderView() if (viewBinding == null || feed == null) { Log.e(TAG, "Unable to refresh header view") @@ -439,7 +444,7 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba } } - private fun setupHeaderView() { + @UnstableApi private fun setupHeaderView() { if (feed == null || headerCreated) { return } @@ -465,7 +470,7 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba Maybe.fromCallable( Callable { val feedDownloadLog: List = DBReader.getFeedDownloadLog(feedID) - if (feedDownloadLog.size == 0 || feedDownloadLog[0].isSuccessful) { + if (feedDownloadLog.isEmpty() || feedDownloadLog[0].isSuccessful) { return@Callable null } feedDownloadLog[0] @@ -481,7 +486,7 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba { DownloadLogFragment().show(childFragmentManager, null) }) } - private fun showFeedInfo() { + @UnstableApi private fun showFeedInfo() { if (feed != null) { val fragment = FeedInfoFragment.newInstance(feed!!) (activity as MainActivity).loadChildFragment(fragment, TransitionEffect.SLIDE) @@ -509,7 +514,7 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba .into(viewBinding!!.header.imgvCover) } - private fun loadItems() { + @UnstableApi private fun loadItems() { disposable?.dispose() disposable = Observable.fromCallable { this.loadData() } @@ -522,7 +527,7 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba refreshHeaderView() viewBinding!!.progressBar.visibility = View.GONE adapter?.setDummyViews(0) - if (feed != null && feed!!.items != null) adapter?.updateItems(feed!!.items!!) + if (feed != null && feed!!.items.isNotEmpty()) adapter?.updateItems(feed!!.items) updateToolbar() }, { error: Throwable? -> feed = null @@ -536,10 +541,10 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba private fun loadData(): Feed? { val feed: Feed = DBReader.getFeed(feedID, true) ?: return null - if (feed.items != null) { - DBReader.loadAdditionalFeedItemListData(feed.items!!) + if (feed.items.isNotEmpty()) { + DBReader.loadAdditionalFeedItemListData(feed.items) if (feed.sortOrder != null) { - val feedItems: MutableList = feed.items!! + val feedItems: MutableList = feed.items FeedItemPermutors.getPermutor(feed.sortOrder!!).reorder(feedItems.toMutableList()) feed.items = feedItems } @@ -564,7 +569,7 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba holder.coverHolder.visibility = View.GONE } - @UnstableApi override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo) { + @UnstableApi override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) { super.onCreateContextMenu(menu, v, menuInfo) if (!inActionMode()) { menu.findItem(R.id.multi_select).setVisible(true) @@ -593,7 +598,7 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba } } - override fun onSelectionChanged() { + @UnstableApi override fun onSelectionChanged() { super.onSelectionChanged() DBWriter.setFeedItemSortOrder(requireArguments().getLong(ARG_FEED_ID), sortOrder) } diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/NavDrawerFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/NavDrawerFragment.kt index 40280008..29949df8 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/NavDrawerFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/NavDrawerFragment.kt @@ -356,7 +356,7 @@ class NavDrawerFragment : Fragment(), SharedPreferences.OnSharedPreferenceChange } } - override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo) { + override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) { this@NavDrawerFragment.onCreateContextMenu(menu, v, menuInfo) } } 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 12c4fc27..1e98e9d5 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/QueueFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/QueueFragment.kt @@ -221,14 +221,11 @@ class QueueFragment : Fragment(), Toolbar.OnMenuItemClickListener, SelectableAda override fun onDestroyView() { super.onDestroyView() - if (recyclerAdapter != null) { - recyclerAdapter?.endSelectMode() - } + recyclerAdapter?.endSelectMode() recyclerAdapter = null - if (toolbar != null) { - toolbar?.setOnMenuItemClickListener(null) - toolbar?.setOnLongClickListener(null) - } + + toolbar?.setOnMenuItemClickListener(null) + toolbar?.setOnLongClickListener(null) } private fun refreshToolbarState() { @@ -395,7 +392,7 @@ class QueueFragment : Fragment(), Toolbar.OnMenuItemClickListener, SelectableAda swipeActions?.attachTo(recyclerView) recyclerAdapter = object : QueueRecyclerAdapter(activity as MainActivity, swipeActions!!) { - override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo) { + override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) { super.onCreateContextMenu(menu, v, menuInfo) MenuItemUtils.setOnClickListeners(menu ) { item: MenuItem -> this@QueueFragment.onContextItemSelected(item) } diff --git a/app/src/main/java/ac/mdiq/podvinci/fragment/SearchFragment.kt b/app/src/main/java/ac/mdiq/podvinci/fragment/SearchFragment.kt index e736e794..83f47d42 100644 --- a/app/src/main/java/ac/mdiq/podvinci/fragment/SearchFragment.kt +++ b/app/src/main/java/ac/mdiq/podvinci/fragment/SearchFragment.kt @@ -92,7 +92,7 @@ class SearchFragment : Fragment(), SelectableAdapter.OnSelectModeListener { recyclerView?.setRecycledViewPool((activity as MainActivity).recycledViewPool) registerForContextMenu(recyclerView!!) adapter = object : EpisodeItemListAdapter(activity as MainActivity) { - override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo) { + override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) { super.onCreateContextMenu(menu, v, menuInfo) if (!inActionMode()) { menu.findItem(R.id.multi_select).setVisible(true) @@ -192,13 +192,13 @@ class SearchFragment : Fragment(), SelectableAdapter.OnSelectModeListener { searchView!!.setQuery(requireArguments().getString(ARG_QUERY), true) searchView!!.requestFocus() searchView!!.setOnQueryTextListener(object : SearchView.OnQueryTextListener { - override fun onQueryTextSubmit(s: String): Boolean { + @UnstableApi override fun onQueryTextSubmit(s: String): Boolean { searchView!!.clearFocus() searchWithProgressBar() return true } - override fun onQueryTextChange(s: String): Boolean { + @UnstableApi override fun onQueryTextChange(s: String): Boolean { automaticSearchDebouncer!!.removeCallbacksAndMessages(null) if (s.isEmpty() || s.endsWith(" ") || (lastQueryChange != 0L && System.currentTimeMillis() > lastQueryChange + SEARCH_DEBOUNCE_INTERVAL)) { @@ -243,17 +243,17 @@ class SearchFragment : Fragment(), SelectableAdapter.OnSelectModeListener { return super.onContextItemSelected(item) } - @Subscribe(threadMode = ThreadMode.MAIN) + @UnstableApi @Subscribe(threadMode = ThreadMode.MAIN) fun onFeedListChanged(event: FeedListUpdateEvent?) { search() } - @Subscribe(threadMode = ThreadMode.MAIN) + @UnstableApi @Subscribe(threadMode = ThreadMode.MAIN) fun onUnreadItemsChanged(event: UnreadItemsUpdateEvent?) { search() } - @Subscribe(threadMode = ThreadMode.MAIN) + @UnstableApi @Subscribe(threadMode = ThreadMode.MAIN) fun onEventMainThread(event: FeedItemEvent) { Log.d(TAG, "onEventMainThread() called with: event = [$event]") if (results == null) { @@ -295,7 +295,7 @@ class SearchFragment : Fragment(), SelectableAdapter.OnSelectModeListener { for (i in 0 until adapter!!.itemCount) { val holder: EpisodeItemViewHolder = recyclerView!!.findViewHolderForAdapterPosition(i) as EpisodeItemViewHolder - if (holder != null && holder.isCurrentlyPlayingItem) { + if (holder.isCurrentlyPlayingItem) { holder.notifyPlaybackPositionUpdated(event) break } @@ -303,18 +303,18 @@ class SearchFragment : Fragment(), SelectableAdapter.OnSelectModeListener { } } - @Subscribe(threadMode = ThreadMode.MAIN) + @UnstableApi @Subscribe(threadMode = ThreadMode.MAIN) fun onPlayerStatusChanged(event: PlayerStatusEvent?) { search() } - private fun searchWithProgressBar() { + @UnstableApi private fun searchWithProgressBar() { progressBar?.visibility = View.VISIBLE emptyViewHandler?.hide() search() } - private fun search() { + @UnstableApi private fun search() { disposable?.dispose() adapterFeeds?.setEndButton(R.string.search_online) { this.searchOnline() } @@ -341,7 +341,7 @@ class SearchFragment : Fragment(), SelectableAdapter.OnSelectModeListener { }, { error: Throwable? -> Log.e(TAG, Log.getStackTraceString(error)) }) } - private fun performSearch(): Pair?, List?> { + @UnstableApi private fun performSearch(): Pair?, List?> { val query = searchView!!.query.toString() if (query.isEmpty()) { return Pair?, List?>(emptyList(), emptyList()) @@ -357,7 +357,7 @@ class SearchFragment : Fragment(), SelectableAdapter.OnSelectModeListener { imm.showSoftInput(view, 0) } - private fun searchOnline() { + @UnstableApi private fun searchOnline() { searchView!!.clearFocus() val inVal = requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager inVal.hideSoftInputFromWindow(searchView!!.windowToken, 0) diff --git a/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/DownloadsSection.kt b/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/DownloadsSection.kt index 7b8625e4..34213dbc 100644 --- a/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/DownloadsSection.kt +++ b/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/DownloadsSection.kt @@ -44,7 +44,7 @@ class DownloadsSection : HomeSection() { viewBinding?.recyclerView?.layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false) viewBinding?.recyclerView?.setRecycledViewPool((requireActivity() as MainActivity).recycledViewPool) adapter = object : EpisodeItemListAdapter(requireActivity() as MainActivity) { - override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo) { + override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) { super.onCreateContextMenu(menu, v, menuInfo) MenuItemUtils.setOnClickListeners(menu ) { item: MenuItem -> diff --git a/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/EpisodesSurpriseSection.kt b/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/EpisodesSurpriseSection.kt index e81d0de2..99402a62 100644 --- a/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/EpisodesSurpriseSection.kt +++ b/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/EpisodesSurpriseSection.kt @@ -44,7 +44,7 @@ class EpisodesSurpriseSection : HomeSection() { loadItems() } listAdapter = object : HorizontalItemListAdapter(activity as MainActivity) { - override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo) { + override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) { super.onCreateContextMenu(menu, v, menuInfo) MenuItemUtils.setOnClickListeners(menu ) { item: MenuItem -> diff --git a/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/InboxSection.kt b/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/InboxSection.kt index 6a690be7..8dda016a 100644 --- a/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/InboxSection.kt +++ b/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/InboxSection.kt @@ -45,7 +45,7 @@ class InboxSection : HomeSection() { viewBinding?.recyclerView?.layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false) viewBinding?.recyclerView?.setRecycledViewPool((requireActivity() as MainActivity).recycledViewPool) adapter = object : EpisodeItemListAdapter(requireActivity() as MainActivity) { - override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo) { + override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) { super.onCreateContextMenu(menu, v, menuInfo) MenuItemUtils.setOnClickListeners(menu ) { item: MenuItem -> this@InboxSection.onContextItemSelected(item) } diff --git a/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/QueueSection.kt b/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/QueueSection.kt index 214694dd..4fc10a63 100644 --- a/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/QueueSection.kt +++ b/app/src/main/java/ac/mdiq/podvinci/ui/home/sections/QueueSection.kt @@ -39,7 +39,7 @@ class QueueSection : HomeSection() { ): View { val view: View = super.onCreateView(inflater, container, savedInstanceState) listAdapter = object : HorizontalItemListAdapter(activity as MainActivity) { - override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo) { + override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) { super.onCreateContextMenu(menu, v, menuInfo) MenuItemUtils.setOnClickListeners(menu ) { item: MenuItem -> this@QueueSection.onContextItemSelected(item) } diff --git a/core/src/main/java/ac/mdiq/podvinci/core/service/playback/LocalPSMP.kt b/core/src/main/java/ac/mdiq/podvinci/core/service/playback/LocalPSMP.kt index 6f04bec7..bc9e3c0a 100644 --- a/core/src/main/java/ac/mdiq/podvinci/core/service/playback/LocalPSMP.kt +++ b/core/src/main/java/ac/mdiq/podvinci/core/service/playback/LocalPSMP.kt @@ -175,7 +175,7 @@ class LocalPSMP(context: Context, mediaPlayer!!.setDataSource(media!!.getStreamUrl()!!) } } - } else if (media!!.getLocalMediaUrl() != null && File(media!!.getLocalMediaUrl()).canRead()) { + } else if (media!!.getLocalMediaUrl() != null && File(media!!.getLocalMediaUrl()!!).canRead()) { mediaPlayer!!.setDataSource(media!!.getLocalMediaUrl()!!) } else { throw IOException("Unable to read local file " + media!!.getLocalMediaUrl()) @@ -193,11 +193,11 @@ class LocalPSMP(context: Context, } catch (e: IOException) { e.printStackTrace() setPlayerStatus(PlayerStatus.ERROR, null) - EventBus.getDefault().postSticky(PlayerErrorEvent(e.localizedMessage)) + EventBus.getDefault().postSticky(PlayerErrorEvent(e.localizedMessage?:"")) } catch (e: IllegalStateException) { e.printStackTrace() setPlayerStatus(PlayerStatus.ERROR, null) - EventBus.getDefault().postSticky(PlayerErrorEvent(e.localizedMessage)) + EventBus.getDefault().postSticky(PlayerErrorEvent(e.localizedMessage?:"")) } } @@ -347,7 +347,7 @@ class LocalPSMP(context: Context, t = 0 } - if (t >= getPosition()) { + if (t >= getDuration()) { Log.d(TAG, "Seek reached end of file, skipping to next episode") endPlayback(true, true, true, true) return @@ -503,9 +503,7 @@ class LocalPSMP(context: Context, } override fun setVideoSurface(surface: SurfaceHolder?) { - if (mediaPlayer != null) { - mediaPlayer!!.setDisplay(surface) - } + mediaPlayer?.setDisplay(surface) } override fun resetVideoSurface() { 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 4b7fa55a..e72dce9c 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 @@ -404,7 +404,7 @@ class PlaybackService : MediaBrowserServiceCompat() { } var count = 0 for (feedItem in feedItems) { - if (feedItem!!.media != null && feedItem.media!!.mediaItem != null) { + if (feedItem?.media != null) { mediaItems.add(feedItem.media!!.mediaItem) if (++count >= MAX_ANDROID_AUTO_EPISODES_PER_FEED) { break @@ -758,10 +758,10 @@ class PlaybackService : MediaBrowserServiceCompat() { private val mediaPlayerCallback: PSMPCallback = object : PSMPCallback { override fun statusChanged(newInfo: PSMPInfo?) { - if (mediaPlayer != null) { - currentMediaType = mediaPlayer!!.getCurrentMediaType() + currentMediaType = if (mediaPlayer != null) { + mediaPlayer!!.getCurrentMediaType() } else { - currentMediaType = MediaType.UNKNOWN + MediaType.UNKNOWN } updateMediaSession(newInfo!!.playerStatus) @@ -941,11 +941,10 @@ class PlaybackService : MediaBrowserServiceCompat() { return null } Log.d(TAG, "getNextInQueue()") - val media = currentMedia - if (media.getItem() == null) { - media.setItem(DBReader.getFeedItem(media.itemId)) + if (currentMedia.getItem() == null) { + currentMedia.setItem(DBReader.getFeedItem(currentMedia.itemId)) } - val item = media.getItem() + val item = currentMedia.getItem() if (item == null) { Log.w(TAG, "getNextInQueue() with FeedMedia object whose FeedItem is null") writeNoMediaPlaying() @@ -1335,9 +1334,9 @@ class PlaybackService : MediaBrowserServiceCompat() { if (fromMediaPlayer) { position = currentPosition duration = this.duration - playable = mediaPlayer!!.getPlayable() + playable = mediaPlayer?.getPlayable() } else { - duration = playable!!.getDuration() + duration = playable?.getDuration() ?: Playable.INVALID_TIME } if (position != Playable.INVALID_TIME && duration != Playable.INVALID_TIME && playable != null) { Log.d(TAG, "Saving current position to $position") @@ -1743,7 +1742,7 @@ class PlaybackService : MediaBrowserServiceCompat() { fun onNextChapter() { val chapters = mediaPlayer!!.getPlayable()!!.getChapters() - if (chapters == null) { + if (chapters.isEmpty()) { // No chapters, just fallback to next episode mediaPlayer!!.skip() return @@ -1791,31 +1790,29 @@ class PlaybackService : MediaBrowserServiceCompat() { override fun onMediaButtonEvent(mediaButton: Intent): Boolean { Log.d(TAG, "onMediaButtonEvent($mediaButton)") - if (mediaButton != null) { - val keyEvent = mediaButton.getParcelableExtra(Intent.EXTRA_KEY_EVENT) - if (keyEvent != null && keyEvent.action == KeyEvent.ACTION_DOWN && keyEvent.repeatCount == 0) { - val keyCode = keyEvent.keyCode - if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) { - clickCount++ - clickHandler.removeCallbacksAndMessages(null) - clickHandler.postDelayed({ - when (clickCount) { - 1 -> { - handleKeycode(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, false) - } - 2 -> { - onFastForward() - } - 3 -> { - onRewind() - } + val keyEvent = mediaButton.getParcelableExtra(Intent.EXTRA_KEY_EVENT) + if (keyEvent != null && keyEvent.action == KeyEvent.ACTION_DOWN && keyEvent.repeatCount == 0) { + val keyCode = keyEvent.keyCode + if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) { + clickCount++ + clickHandler.removeCallbacksAndMessages(null) + clickHandler.postDelayed({ + when (clickCount) { + 1 -> { + handleKeycode(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, false) } - clickCount = 0 - }, ViewConfiguration.getDoubleTapTimeout().toLong()) - return true - } else { - return handleKeycode(keyCode, false) - } + 2 -> { + onFastForward() + } + 3 -> { + onRewind() + } + } + clickCount = 0 + }, ViewConfiguration.getDoubleTapTimeout().toLong()) + return true + } else { + return handleKeycode(keyCode, false) } } return false 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 3d01a14a..083755e1 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 @@ -522,6 +522,7 @@ object DBReader { } fun getPausedQueue(limit: Int): List { + Log.d(TAG, "getFeedItemsWithUrl() called ") val adapter = getInstance() adapter!!.open() try { @@ -702,6 +703,7 @@ object DBReader { } fun getFeedItemsWithUrl(urls: List?): List { + Log.d(TAG, "getFeedItemsWithUrl() called ") val adapter = getInstance() adapter!!.open() try { 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 dac8458e..3c637521 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 @@ -235,8 +235,8 @@ import java.util.concurrent.* } // Look for new or updated Items - for (idx in newFeed.items!!.indices) { - val item = newFeed.items!![idx] + for (idx in newFeed.items.indices) { + val item = newFeed.items[idx] val possibleDuplicate = searchFeedItemGuessDuplicate(newFeed.items, item) if (!newFeed.isLocalFeed && possibleDuplicate != null && item !== possibleDuplicate) { @@ -291,10 +291,10 @@ import java.util.concurrent.* Log.d(TAG, "Found new item: " + item.title) item.feed = savedFeed - if (idx >= savedFeed.items!!.size) { - savedFeed.items?.add(item) + if (idx >= savedFeed.items.size) { + savedFeed.items.add(item) } else { - savedFeed.items?.add(idx, item) + savedFeed.items.add(idx, item) } var action = savedFeed.preferences!!.newEpisodesAction @@ -313,7 +313,7 @@ import java.util.concurrent.* // identify items to be removed if (removeUnlistedItems) { - val it = savedFeed.items!!.toMutableList().iterator() + val it = savedFeed.items.toMutableList().iterator() while (it.hasNext()) { val feedItem = it.next() if (searchFeedItemByIdentifyingValue(newFeed.items, feedItem) == null) { @@ -340,7 +340,7 @@ import java.util.concurrent.* DBWriter.setCompleteFeed(savedFeed).get() } if (removeUnlistedItems) { - DBWriter.deleteFeedItems(context!!, unlistedItems).get() + DBWriter.deleteFeedItems(context, unlistedItems).get() } } catch (e: InterruptedException) { e.printStackTrace() @@ -379,10 +379,10 @@ import java.util.concurrent.* * and returns the search result as a List of FeedItems. */ @JvmStatic - fun searchFeedItems(feedID: Long, query: String?): FutureTask> { + fun searchFeedItems(feedID: Long, query: String): FutureTask> { return FutureTask(object : QueryTask>() { override fun execute(adapter: PodDBAdapter?) { - val searchResult = adapter!!.searchItems(feedID, query!!) + val searchResult = adapter!!.searchItems(feedID, query) val items = extractItemlistFromCursor(searchResult) loadAdditionalFeedItemListData(items) setResult(items) @@ -392,10 +392,10 @@ import java.util.concurrent.* } @JvmStatic - fun searchFeeds(query: String?): FutureTask> { + fun searchFeeds(query: String): FutureTask> { return FutureTask(object : QueryTask>() { override fun execute(adapter: PodDBAdapter?) { - val cursor = adapter!!.searchFeeds(query!!) + val cursor = adapter!!.searchFeeds(query) val items: MutableList = ArrayList() if (cursor.moveToFirst()) { do { diff --git a/core/src/main/java/ac/mdiq/podvinci/core/storage/FeedSearcher.kt b/core/src/main/java/ac/mdiq/podvinci/core/storage/FeedSearcher.kt index eef25b97..3ed1f49f 100644 --- a/core/src/main/java/ac/mdiq/podvinci/core/storage/FeedSearcher.kt +++ b/core/src/main/java/ac/mdiq/podvinci/core/storage/FeedSearcher.kt @@ -3,13 +3,15 @@ package ac.mdiq.podvinci.core.storage import ac.mdiq.podvinci.core.storage.DBTasks.searchFeedItems import ac.mdiq.podvinci.model.feed.Feed import ac.mdiq.podvinci.model.feed.FeedItem +import androidx.media3.common.util.UnstableApi import java.util.concurrent.ExecutionException /** * Performs search on Feeds and FeedItems. */ +@UnstableApi object FeedSearcher { - fun searchFeedItems(query: String?, selectedFeed: Long): List { + fun searchFeedItems(query: String, selectedFeed: Long): List { try { val itemSearchTask = searchFeedItems(selectedFeed, query) itemSearchTask.run() @@ -23,7 +25,7 @@ object FeedSearcher { } } - fun searchFeeds(query: String?): List { + fun searchFeeds(query: String): List { try { val feedSearchTask = DBTasks.searchFeeds(query) feedSearchTask.run() diff --git a/model/src/main/java/ac/mdiq/podvinci/model/feed/FeedMedia.kt b/model/src/main/java/ac/mdiq/podvinci/model/feed/FeedMedia.kt index dde2cb33..d7a50624 100644 --- a/model/src/main/java/ac/mdiq/podvinci/model/feed/FeedMedia.kt +++ b/model/src/main/java/ac/mdiq/podvinci/model/feed/FeedMedia.kt @@ -176,10 +176,7 @@ class FeedMedia : FeedFile, Playable { } override fun getDescription(): String? { - if (item != null) { - return item!!.description - } - return null + return item?.description } /** @@ -212,7 +209,7 @@ class FeedMedia : FeedFile, Playable { fun getPlaybackCompletionDate(): Date? { return if (playbackCompletionDate == null) null - else playbackCompletionDate!!.clone() as Date + else playbackCompletionDate?.clone() as Date } fun setPlaybackCompletionDate(playbackCompletionDate: Date?) { diff --git a/playback/base/src/main/java/ac/mdiq/podvinci/playback/base/PlaybackServiceMediaPlayer.kt b/playback/base/src/main/java/ac/mdiq/podvinci/playback/base/PlaybackServiceMediaPlayer.kt index 57df8793..c0263442 100644 --- a/playback/base/src/main/java/ac/mdiq/podvinci/playback/base/PlaybackServiceMediaPlayer.kt +++ b/playback/base/src/main/java/ac/mdiq/podvinci/playback/base/PlaybackServiceMediaPlayer.kt @@ -335,7 +335,7 @@ abstract class PlaybackServiceMediaPlayer protected constructor(protected val co this.oldPlayerStatus = playerStatus this.playerStatus = newStatus - setPlayable(newMedia); + setPlayable(newMedia) if (newMedia != null && newStatus != PlayerStatus.INDETERMINATE) { if (oldPlayerStatus == PlayerStatus.PLAYING && newStatus != PlayerStatus.PLAYING) {