Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Feb 14, 2024
1 parent 82c498c commit 9a96130
Show file tree
Hide file tree
Showing 23 changed files with 125 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
57 changes: 31 additions & 26 deletions app/src/main/java/ac/mdiq/podvinci/fragment/FeedItemlistFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -281,15 +281,15 @@ 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)
activity.loadChildFragment(ItemPagerFragment.newInstance(ids, position))
}
}

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

Expand All @@ -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()
}
}
Expand All @@ -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")
Expand Down Expand Up @@ -439,7 +444,7 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba
}
}

private fun setupHeaderView() {
@UnstableApi private fun setupHeaderView() {
if (feed == null || headerCreated) {
return
}
Expand All @@ -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]
Expand All @@ -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)
Expand Down Expand Up @@ -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() }
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
13 changes: 5 additions & 8 deletions app/src/main/java/ac/mdiq/podvinci/fragment/QueueFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) }
Expand Down
Loading

0 comments on commit 9a96130

Please sign in to comment.