bug fixes

This commit is contained in:
Xilin Jia 2024-02-14 23:11:41 +01:00
parent 82c498c466
commit 9a96130fa7
23 changed files with 125 additions and 130 deletions

View File

@ -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<Any>
get() {
val items: MutableList<FeedItem> = ArrayList<FeedItem>()
val items: MutableList<FeedItem> = ArrayList()
for (i in 0 until itemCount) {
if (isSelected(i)) {
items.add(getItem(i))

View File

@ -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

View File

@ -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 {

View File

@ -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)

View File

@ -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<View>(R.id.message) as TextView?)!!.setTextIsSelectable(true)
(dialog.findViewById<View>(R.id.message) as? TextView)?.setTextIsSelectable(true)
return dialog
}
}

View File

@ -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)

View File

@ -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)

View File

@ -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())

View File

@ -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<DownloadResult>(
Callable {
val feedDownloadLog: List<DownloadResult> = 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<Feed?> { 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<FeedItem> = feed.items!!
val feedItems: MutableList<FeedItem> = 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)
}

View File

@ -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)
}
}

View File

@ -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) }

View File

@ -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<FeedItem>?, List<Feed?>?> {
@UnstableApi private fun performSearch(): Pair<List<FeedItem>?, List<Feed?>?> {
val query = searchView!!.query.toString()
if (query.isEmpty()) {
return Pair<List<FeedItem>?, List<Feed?>?>(emptyList(), emptyList<Feed>())
@ -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)

View File

@ -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 ->

View File

@ -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 ->

View File

@ -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) }

View File

@ -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) }

View File

@ -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() {

View File

@ -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<KeyEvent>(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<KeyEvent>(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

View File

@ -522,6 +522,7 @@ object DBReader {
}
fun getPausedQueue(limit: Int): List<FeedItem> {
Log.d(TAG, "getFeedItemsWithUrl() called ")
val adapter = getInstance()
adapter!!.open()
try {
@ -702,6 +703,7 @@ object DBReader {
}
fun getFeedItemsWithUrl(urls: List<String?>?): List<FeedItem> {
Log.d(TAG, "getFeedItemsWithUrl() called ")
val adapter = getInstance()
adapter!!.open()
try {

View File

@ -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<List<FeedItem>> {
fun searchFeedItems(feedID: Long, query: String): FutureTask<List<FeedItem>> {
return FutureTask(object : QueryTask<List<FeedItem>>() {
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<List<Feed>> {
fun searchFeeds(query: String): FutureTask<List<Feed>> {
return FutureTask(object : QueryTask<List<Feed>>() {
override fun execute(adapter: PodDBAdapter?) {
val cursor = adapter!!.searchFeeds(query!!)
val cursor = adapter!!.searchFeeds(query)
val items: MutableList<Feed> = ArrayList()
if (cursor.moveToFirst()) {
do {

View File

@ -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<FeedItem> {
fun searchFeedItems(query: String, selectedFeed: Long): List<FeedItem> {
try {
val itemSearchTask = searchFeedItems(selectedFeed, query)
itemSearchTask.run()
@ -23,7 +25,7 @@ object FeedSearcher {
}
}
fun searchFeeds(query: String?): List<Feed> {
fun searchFeeds(query: String): List<Feed> {
try {
val feedSearchTask = DBTasks.searchFeeds(query)
feedSearchTask.run()

View File

@ -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?) {

View File

@ -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) {