Skip to content

Commit

Permalink
change on click operations
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Mar 16, 2024
1 parent e835100 commit de261e2
Show file tree
Hide file tree
Showing 16 changed files with 164 additions and 85 deletions.
10 changes: 2 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ android {
// Version code schema (not used):
// "1.2.3-beta4" -> 1020304
// "1.2.3" -> 1020395
versionCode 3020107
versionName "4.2.4"
versionCode 3020108
versionName "4.2.5"

def commit = ""
try {
Expand All @@ -164,12 +164,6 @@ android {
}
buildConfigField "String", "COMMIT_HASH", ('"' + (commit.isEmpty() ? "Unknown commit" : commit) + '"')

// javaCompileOptions {
// annotationProcessorOptions {
// arguments = [eventBusIndex: 'ac.mdiq.podcini.ApEventBusIndex']
// }
// }

if (project.hasProperty("podcastindexApiKey")) {
buildConfigField "String", "PODCASTINDEX_API_KEY", '"' + podcastindexApiKey + '"'
buildConfigField "String", "PODCASTINDEX_API_SECRET", '"' + podcastindexApiSecret + '"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,34 @@ open class EpisodeItemListAdapter(mainActivity: MainActivity) :
val item: FeedItem = episodes[pos]
holder.bind(item)

holder.infoCard.setOnCreateContextMenuListener(this)
// holder.infoCard.setOnCreateContextMenuListener(this)
holder.infoCard.setOnLongClickListener {
longPressedItem = item
longPressedPosition = holder.bindingAdapterPosition
startSelectMode(longPressedPosition)
false
true
}
holder.infoCard.setOnClickListener {
if (inActionMode()) {
toggleSelection(holder.bindingAdapterPosition)
val activity: MainActivity? = mainActivityRef.get()
if (!inActionMode()) {
val ids: LongArray = FeedItemUtil.getIds(episodes)
val position = ArrayUtils.indexOf(ids, item.id)
activity?.loadChildFragment(ItemPagerFragment.newInstance(ids, position))
} else {
longPressedItem = item
longPressedPosition = holder.bindingAdapterPosition
it.showContextMenu()
toggleSelection(holder.bindingAdapterPosition)
}
}

// holder.infoCard.setOnClickListener {
// if (inActionMode()) {
// toggleSelection(holder.bindingAdapterPosition)
// } else {
// longPressedItem = item
// longPressedPosition = holder.bindingAdapterPosition
// it.showContextMenu()
// }
// }

// holder.infoCard.setOnCreateContextMenuListener(this)
// holder.infoCard.setOnLongClickListener {
// longPressedItem = item
Expand Down Expand Up @@ -180,11 +191,10 @@ open class EpisodeItemListAdapter(mainActivity: MainActivity) :
@UnstableApi override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) {
val inflater: MenuInflater = activity!!.menuInflater
if (inActionMode()) {
inflater.inflate(R.menu.multi_select_context_popup, menu)
// inflater.inflate(R.menu.multi_select_context_popup, menu)
} else {
if (longPressedItem == null) {
return
}
if (longPressedItem == null) return

inflater.inflate(R.menu.feeditemlist_context, menu)
menu.setHeaderTitle(longPressedItem!!.title)
FeedItemMenuHandler.onPrepareMenu(menu, longPressedItem, R.id.skip_episode_item)
Expand Down
37 changes: 29 additions & 8 deletions app/src/main/java/ac/mdiq/podcini/ui/adapter/SelectableAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,27 @@ abstract class SelectableAdapter<T : RecyclerView.ViewHolder?>(private val activ
}

override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
if (item.itemId == R.id.select_toggle) {
val selectAll = selectedIds.size != itemCount
shouldSelectLazyLoadedItems = selectAll
setSelected(0, itemCount, selectAll)
toggleSelectAllIcon(item, selectAll)
updateTitle()
return true
when (item.itemId) {
R.id.select_toggle -> {
val selectAll = selectedIds.size != itemCount
shouldSelectLazyLoadedItems = selectAll
setSelected(0, itemCount, selectAll)
toggleSelectAllIcon(item, selectAll)
updateTitle()
return true
}
R.id.select_all_above -> {
shouldSelectLazyLoadedItems = true
toggleSelected(0, pos)
return true
}
R.id.select_all_below -> {
shouldSelectLazyLoadedItems = true
toggleSelected(pos + 1, itemCount)
return true
}
else -> return false
}
return false
}

override fun onDestroyActionMode(mode: ActionMode) {
Expand Down Expand Up @@ -113,6 +125,15 @@ abstract class SelectableAdapter<T : RecyclerView.ViewHolder?>(private val activ
notifyItemRangeChanged(startPos, (endPos - startPos))
}

fun toggleSelected(startPos: Int, endPos: Int) {
var i = startPos
while (i < endPos && i < itemCount) {
toggleSelection(i)
i++
}
notifyItemRangeChanged(startPos, (endPos - startPos))
}

protected fun toggleSelection(pos: Int) {
setSelected(pos, !isSelected(pos))
notifyItemChanged(pos)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,31 @@ open class SubscriptionsRecyclerAdapter(mainActivity: MainActivity) :
holder.coverImage.alpha = 1.0f
}

holder.infoCard.setOnCreateContextMenuListener(this)
holder.infoCard.setOnLongClickListener {
longPressedPosition = holder.bindingAdapterPosition
selectedItem = drawerItem
startSelectMode(longPressedPosition)
false
}
holder.infoCard.setOnClickListener {
if (inActionMode()) {
holder.selectCheckbox.setChecked(!isSelected(holder.bindingAdapterPosition))
} else {
longPressedPosition = holder.bindingAdapterPosition
selectedItem = drawerItem
it.showContextMenu()
val fragment: Fragment = FeedItemlistFragment.newInstance(drawerItem.feed.id)
mainActivityRef.get()?.loadChildFragment(fragment)
}
}
// holder.infoCard.setOnCreateContextMenuListener(this)
holder.infoCard.setOnLongClickListener {
longPressedPosition = holder.bindingAdapterPosition
selectedItem = drawerItem
startSelectMode(longPressedPosition)
true
}

// holder.infoCard.setOnClickListener {
// if (inActionMode()) {
// holder.selectCheckbox.setChecked(!isSelected(holder.bindingAdapterPosition))
// } else {
// longPressedPosition = holder.bindingAdapterPosition
// selectedItem = drawerItem
// it.showContextMenu()
// }
// }
// holder.infoCard.setOnCreateContextMenuListener(this)
// holder.infoCard.setOnLongClickListener {
// if (!inActionMode()) {
Expand Down Expand Up @@ -128,12 +137,11 @@ open class SubscriptionsRecyclerAdapter(mainActivity: MainActivity) :
}

override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) {
if (selectedItem == null) {
return
}
val inflater: MenuInflater = mainActivityRef.get()!!.menuInflater
if (selectedItem == null) return
val mainActRef = mainActivityRef.get() ?: return
val inflater: MenuInflater = mainActRef.menuInflater
if (inActionMode()) {
inflater.inflate(R.menu.multi_select_context_popup, menu)
// inflater.inflate(R.menu.multi_select_context_popup, menu)
// menu.findItem(R.id.multi_select).setVisible(true)
} else {
inflater.inflate(R.menu.nav_feed_context, menu)
Expand Down Expand Up @@ -197,16 +205,18 @@ open class SubscriptionsRecyclerAdapter(mainActivity: MainActivity) :
count.visibility = View.GONE
}

val coverLoader = CoverLoader(mainActivityRef.get()!!)
val mainActRef = mainActivityRef.get() ?: return

val coverLoader = CoverLoader(mainActRef)
val feed: Feed = drawerItem.feed
coverLoader.withUri(feed.imageUrl)
errorIcon.visibility = if (feed.hasLastUpdateFailed()) View.VISIBLE else View.GONE

coverLoader.withCoverView(coverImage)
coverLoader.load()

val density: Float = mainActivityRef.get()!!.resources.displayMetrics.density
card.setCardBackgroundColor(SurfaceColors.getColorForElevation(mainActivityRef.get()!!, 1 * density))
val density: Float = mainActRef.resources.displayMetrics.density
card.setCardBackgroundColor(SurfaceColors.getColorForElevation(mainActRef, 1 * density))

val textHPadding = 20
val textVPadding = 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,24 @@ abstract class EpisodesListFragment : Fragment(), SelectableAdapter.OnSelectMode

override fun onContextItemSelected(item: MenuItem): Boolean {
Log.d(TAG, "onContextItemSelected() called with: item = [$item]")
if (!userVisibleHint || !isVisible || !isMenuVisible) {
// The method is called on all fragments in a ViewPager, so this needs to be ignored in invisible ones.
// Apparently, none of the visibility check method works reliably on its own, so we just use all.
return false
} else if (listAdapter.longPressedItem == null) {
Log.i(TAG, "Selected item or listAdapter was null, ignoring selection")
return super.onContextItemSelected(item)
} else if (listAdapter.onContextItemSelected(item)) {
return true
when {
!userVisibleHint || !isVisible || !isMenuVisible -> {
// The method is called on all fragments in a ViewPager, so this needs to be ignored in invisible ones.
// Apparently, none of the visibility check method works reliably on its own, so we just use all.
return false
}
listAdapter.longPressedItem == null -> {
Log.i(TAG, "Selected item or listAdapter was null, ignoring selection")
return super.onContextItemSelected(item)
}
listAdapter.onContextItemSelected(item) -> {
return true
}
else -> {
val selectedItem: FeedItem = listAdapter.longPressedItem ?: return false
return FeedItemMenuHandler.onMenuItemClicked(this, item.itemId, selectedItem)
}
}
val selectedItem: FeedItem = listAdapter.longPressedItem ?: return false
return FeedItemMenuHandler.onMenuItemClicked(this, item.itemId, selectedItem)
}

@UnstableApi override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class EpisodeMultiSelectActionHandler(private val activity: MainActivity, privat

fun handleAction(items: List<FeedItem>) {
when (actionId) {
R.id.add_to_favorite_batch -> {
markFavorite(items)
}
R.id.add_to_queue_batch -> {
queueChecked(items)
}
R.id.remove_from_queue_batch -> {
removeFromQueueChecked(items)
}
// R.id.remove_from_inbox_batch -> {
// removeFromInboxChecked(items)
// }
R.id.mark_read_batch -> {
markedCheckedPlayed(items)
}
Expand Down Expand Up @@ -64,17 +64,6 @@ class EpisodeMultiSelectActionHandler(private val activity: MainActivity, privat
showMessage(R.plurals.removed_from_queue_batch_label, checkedIds.size)
}

// private fun removeFromInboxChecked(items: List<FeedItem>) {
// val markUnplayed = LongList()
// for (episode in items) {
// if (episode.isNew) {
// markUnplayed.add(episode.id)
// }
// }
// DBWriter.markItemPlayed(FeedItem.UNPLAYED, *markUnplayed.toArray())
// showMessage(R.plurals.removed_from_inbox_batch_label, markUnplayed.size())
// }

private fun markedCheckedPlayed(items: List<FeedItem>) {
val checkedIds = getSelectedIds(items)
DBWriter.markItemPlayed(FeedItem.PLAYED, *checkedIds)
Expand All @@ -87,6 +76,13 @@ class EpisodeMultiSelectActionHandler(private val activity: MainActivity, privat
showMessage(R.plurals.marked_unread_batch_label, checkedIds.size)
}

private fun markFavorite(items: List<FeedItem>) {
for (item in items) {
DBWriter.addFavoriteItem(item)
}
showMessage(R.plurals.marked_favorite_batch_label, items.size)
}

private fun downloadChecked(items: List<FeedItem>) {
// download the check episodes in the same order as they are currently displayed
for (episode in items) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ interface SwipeAction {

companion object {
const val ADD_TO_QUEUE: String = "ADD_TO_QUEUE"
// const val REMOVE_FROM_INBOX: String = "REMOVE_FROM_INBOX"
const val START_DOWNLOAD: String = "START_DOWNLOAD"
const val MARK_FAV: String = "MARK_FAV"
const val TOGGLE_PLAYED: String = "MARK_PLAYED"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,22 @@ class EpisodeItemViewHolder(private val activity: MainActivity, parent: ViewGrou
secondaryActionProgress.setIndeterminate(false)
}

duration.text = ac.mdiq.podcini.util.Converter.getDurationStringLong(media.getDuration())
duration.text = Converter.getDurationStringLong(media.getDuration())
duration.setContentDescription(activity.getString(R.string.chapter_duration,
ac.mdiq.podcini.util.Converter.getDurationStringLocalized(activity, media.getDuration().toLong())))
Converter.getDurationStringLocalized(activity, media.getDuration().toLong())))
if (PlaybackStatus.isPlaying(item?.media) || item?.isInProgress == true) {
val progress: Int = (100.0 * media.getPosition() / media.getDuration()).toInt()
val remainingTime = max((media.getDuration() - media.getPosition()).toDouble(), 0.0).toInt()
progressBar.progress = progress
position.text = ac.mdiq.podcini.util.Converter.getDurationStringLong(media.getPosition())
position.text = Converter.getDurationStringLong(media.getPosition())
position.setContentDescription(activity.getString(R.string.position,
ac.mdiq.podcini.util.Converter.getDurationStringLocalized(activity, media.getPosition().toLong())))
Converter.getDurationStringLocalized(activity, media.getPosition().toLong())))
progressBar.visibility = View.VISIBLE
position.visibility = View.VISIBLE
if (UserPreferences.shouldShowRemainingTime()) {
duration.text = (if ((remainingTime > 0)) "-" else "") + ac.mdiq.podcini.util.Converter.getDurationStringLong(remainingTime)
duration.text = (if ((remainingTime > 0)) "-" else "") + Converter.getDurationStringLong(remainingTime)
duration.setContentDescription(activity.getString(R.string.chapter_duration,
ac.mdiq.podcini.util.Converter.getDurationStringLocalized(activity, (media.getDuration() - media.getPosition()).toLong())))
Converter.getDurationStringLocalized(activity, (media.getDuration() - media.getPosition()).toLong())))
}
} else {
progressBar.visibility = View.GONE
Expand Down Expand Up @@ -264,7 +264,7 @@ class EpisodeItemViewHolder(private val activity: MainActivity, parent: ViewGrou

fun notifyPlaybackPositionUpdated(event: PlaybackPositionEvent) {
progressBar.progress = (100.0 * event.position / event.duration).toInt()
position.text = ac.mdiq.podcini.util.Converter.getDurationStringLong(event.position)
position.text = Converter.getDurationStringLong(event.position)
updateDuration(event)
duration.visibility = View.VISIBLE // Even if the duration was previously unknown, it is now known
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_arrow_downward_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_arrow_upward_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M4,12l1.41,1.41L11,7.83V20h2V7.83l5.58,5.59L20,12l-8,-8 -8,8z"/>
</vector>
3 changes: 1 addition & 2 deletions app/src/main/res/layout/feed_item_list_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:scrimAnimationDuration="200"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
app:scrimAnimationDuration="200">

<ImageView
android:id="@+id/imgvBackground"
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/menu/episodes_apply_action_speeddial.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
android:icon="@drawable/ic_playlist_play"
android:title="@string/add_to_queue_label" />

<!-- <item-->
<!-- android:id="@+id/remove_from_inbox_batch"-->
<!-- android:icon="@drawable/ic_check"-->
<!-- android:title="@string/remove_inbox_label" />-->
<item
android:id="@+id/add_to_favorite_batch"
android:icon="@drawable/ic_star"
android:title="@string/add_to_favorite_label" />

</menu>
10 changes: 10 additions & 0 deletions app/src/main/res/menu/multi_select_options.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/select_all_above"
android:title="@string/select_all_above"
android:icon="@drawable/baseline_arrow_upward_24"
app:showAsAction="always"/>
<item
android:id="@+id/select_all_below"
android:title="@string/select_all_below"
android:icon="@drawable/baseline_arrow_downward_24"
app:showAsAction="always"/>
<item
android:id="@+id/select_toggle"
android:title="@string/select_all_label"
Expand Down
Loading

0 comments on commit de261e2

Please sign in to comment.