Skip to content

Commit

Permalink
add info bars and thematic icons
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Mar 17, 2024
1 parent de261e2 commit 063af37
Show file tree
Hide file tree
Showing 30 changed files with 176 additions and 124 deletions.
4 changes: 2 additions & 2 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 3020108
versionName "4.2.5"
versionCode 3020109
versionName "4.2.6"

def commit = ""
try {
Expand Down
2 changes: 1 addition & 1 deletion app/src/androidTest/java/ac/test/podcini/ui/UITestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class UITestUtils(private val context: Context) {
adapter.setCompleteFeed(*hostedFeeds.toTypedArray<Feed>())
adapter.setQueue(queue)
adapter.close()
EventBus.getDefault().post(ac.mdiq.podcini.util.event.FeedListUpdateEvent(hostedFeeds))
EventBus.getDefault().post(FeedListUpdateEvent(hostedFeeds))
EventBus.getDefault().post(setQueue(queue))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import org.greenrobot.eventbus.Subscribe
*
*/
class FeedItemEventListener {
private val events: MutableList<ac.mdiq.podcini.util.event.FeedItemEvent> = ArrayList()
private val events: MutableList<FeedItemEvent> = ArrayList()

@Subscribe
fun onEvent(event: ac.mdiq.podcini.util.event.FeedItemEvent) {
fun onEvent(event: FeedItemEvent) {
events.add(event)
}

fun getEvents(): List<ac.mdiq.podcini.util.event.FeedItemEvent> {
fun getEvents(): List<FeedItemEvent> {
return events
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ac.mdiq.podcini.ui.gui.NotificationUtils
import ac.mdiq.podcini.storage.model.playback.Playable
import ac.mdiq.podcini.playback.base.PlayerStatus
import ac.mdiq.podcini.preferences.UserPreferences
import ac.mdiq.podcini.util.Converter
import org.apache.commons.lang3.ArrayUtils
import java.util.concurrent.ExecutionException

Expand Down Expand Up @@ -52,7 +53,7 @@ class PlaybackServiceNotificationBuilder(private val context: Context) {

fun updatePosition(position: Int, speed: Float) {
val converter = TimeSpeedConverter(speed)
this.position = ac.mdiq.podcini.util.Converter.getDurationStringLong(converter.convert(position))
this.position = Converter.getDurationStringLong(converter.convert(position))
}

val isIconCached: Boolean
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/ac/mdiq/podcini/storage/DBTasks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ac.mdiq.podcini.storage.database.PodDBAdapter
import ac.mdiq.podcini.storage.database.PodDBAdapter.Companion.getInstance
import ac.mdiq.podcini.storage.database.mapper.FeedCursorMapper.convert
import ac.mdiq.podcini.preferences.UserPreferences.newEpisodesAction
import ac.mdiq.podcini.util.event.FeedListUpdateEvent
import org.greenrobot.eventbus.EventBus
import java.util.*
import java.util.concurrent.*
Expand Down Expand Up @@ -352,9 +353,9 @@ import java.util.concurrent.*
adapter.close()

if (savedFeed != null) {
EventBus.getDefault().post(ac.mdiq.podcini.util.event.FeedListUpdateEvent(savedFeed))
EventBus.getDefault().post(FeedListUpdateEvent(savedFeed))
} else {
EventBus.getDefault().post(ac.mdiq.podcini.util.event.FeedListUpdateEvent(emptyList()))
EventBus.getDefault().post(FeedListUpdateEvent(emptyList()))
}

return resultFeed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ class SubscriptionsFilter(private val properties: Array<String>) {

if (showIfCounterGreaterZero) {
for (i in result.indices.reversed()) {
if (!feedCounters.containsKey(result[i].id)
|| feedCounters[result[i].id]!! <= 0) {
if (!feedCounters.containsKey(result[i].id) || feedCounters[result[i].id]!! <= 0) {
result.removeAt(i)
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/ac/mdiq/podcini/ui/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import ac.mdiq.podcini.ui.fragment.*
import ac.mdiq.podcini.ui.statistics.StatisticsFragment
import ac.mdiq.podcini.ui.view.LockableBottomSheetBehavior
import ac.mdiq.podcini.util.event.EpisodeDownloadEvent
import ac.mdiq.podcini.util.event.FeedUpdateRunningEvent
import android.Manifest
import android.annotation.SuppressLint
import android.content.Context
Expand Down Expand Up @@ -73,7 +74,6 @@ import kotlin.math.min
*/
@UnstableApi
class MainActivity : CastEnabledActivity() {
// some device doesn't have a drawer
private var drawerLayout: DrawerLayout? = null

private lateinit var binding: MainActivityBinding
Expand Down Expand Up @@ -183,7 +183,7 @@ class MainActivity : CastEnabledActivity() {
}
}
}
EventBus.getDefault().postSticky(ac.mdiq.podcini.util.event.FeedUpdateRunningEvent(isRefreshingFeeds))
EventBus.getDefault().postSticky(FeedUpdateRunningEvent(isRefreshingFeeds))
}
WorkManager.getInstance(this)
.getWorkInfosByTagLiveData(DownloadServiceInterface.WORK_TAG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,6 @@ open class EpisodeItemListAdapter(mainActivity: MainActivity) :
}
}

// 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
// longPressedPosition = holder.bindingAdapterPosition
// false
// }
holder.coverHolder.setOnClickListener {
val activity: MainActivity? = mainActivityRef.get()
if (!inActionMode()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,6 @@ open class SubscriptionsRecyclerAdapter(mainActivity: MainActivity) :
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()) {
// longPressedPosition = holder.bindingAdapterPosition
// selectedItem = drawerItem
// }
// false
// }

holder.itemView.setOnTouchListener { _: View?, e: MotionEvent ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (e.isFromSource(InputDevice.SOURCE_MOUSE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class SubscriptionsFilterDialog : BottomSheetDialogFragment() {
for (item in SubscriptionsFilterGroup.entries) {
val binding = FilterDialogRowBinding.inflate(inflater)
binding.root.addOnButtonCheckedListener { _: MaterialButtonToggleGroup?, _: Int, _: Boolean ->
updateFilter(
filterValues)
updateFilter(filterValues)
}
binding.buttonGroup.weightSum = item.values.size.toFloat()
binding.filterButton1.setText(item.values[0].displayName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ac.mdiq.podcini.storage.DBWriter
import ac.mdiq.podcini.storage.model.feed.FeedPreferences
import ac.mdiq.podcini.ui.adapter.SimpleChipAdapter
import ac.mdiq.podcini.ui.view.ItemOffsetDecoration
import ac.mdiq.podcini.util.event.FeedTagsChangedEvent
import android.app.Dialog
import android.content.DialogInterface
import android.os.Bundle
Expand All @@ -21,6 +22,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import org.greenrobot.eventbus.EventBus
import java.io.Serializable

class TagSettingsDialog : DialogFragment() {
Expand Down Expand Up @@ -79,6 +81,7 @@ class TagSettingsDialog : DialogFragment() {
addTag(viewBinding.newTagEditText.text.toString().trim { it <= ' ' })
updatePreferencesTags(feedPreferencesList, commonTags)
DBReader.buildTags()
EventBus.getDefault().post(FeedTagsChangedEvent())
}
dialog.setNegativeButton(R.string.cancel_label, null)
return dialog.create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class ChaptersFragment : AppCompatDialogFragment() {

fun onCreateView(inflater: LayoutInflater): View {
val viewBinding = SimpleListFragmentBinding.inflate(inflater)
// val root = inflater.inflate(R.layout.simple_list_fragment, null, false)
viewBinding.toolbar.visibility = View.GONE

Log.d(TAG, "fragment onCreateView")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.leinardi.android.speeddial.SpeedDialView
import ac.mdiq.podcini.R
import ac.mdiq.podcini.databinding.MultiSelectSpeedDialBinding
import ac.mdiq.podcini.databinding.SimpleListFragmentBinding
import ac.mdiq.podcini.feed.util.PlaybackSpeedUtils
import ac.mdiq.podcini.ui.adapter.EpisodeItemListAdapter
import ac.mdiq.podcini.ui.adapter.SelectableAdapter
import ac.mdiq.podcini.ui.adapter.actionbutton.DeleteActionButton
Expand All @@ -37,6 +38,9 @@ import ac.mdiq.podcini.ui.view.EmptyViewHandler
import ac.mdiq.podcini.ui.view.EpisodeItemListRecyclerView
import ac.mdiq.podcini.ui.view.LiftOnScrollListener
import ac.mdiq.podcini.ui.view.viewholder.EpisodeItemViewHolder
import ac.mdiq.podcini.util.Converter
import ac.mdiq.podcini.util.event.FeedItemEvent
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SimpleItemAnimator
import io.reactivex.Observable
Expand All @@ -46,14 +50,18 @@ import io.reactivex.schedulers.Schedulers
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashSet

/**
* Displays all completed downloads and provides a button to delete them.
*/
class CompletedDownloadsFragment : Fragment(), SelectableAdapter.OnSelectModeListener, Toolbar.OnMenuItemClickListener {
private var runningDownloads: Set<String>? = HashSet()
private var items: MutableList<FeedItem> = mutableListOf()


private lateinit var infoBar: TextView
private lateinit var adapter: CompletedDownloadsListAdapter
private lateinit var toolbar: MaterialToolbar
private lateinit var recyclerView: EpisodeItemListRecyclerView
Expand All @@ -69,11 +77,10 @@ class CompletedDownloadsFragment : Fragment(), SelectableAdapter.OnSelectModeLis
@UnstableApi override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val viewBinding = SimpleListFragmentBinding.inflate(inflater)
// val root: View = inflater.inflate(R.layout.simple_list_fragment, container, false)
val binding = SimpleListFragmentBinding.inflate(inflater)

Log.d(TAG, "fragment onCreateView")
toolbar = viewBinding.toolbar
toolbar = binding.toolbar
toolbar.setTitle(R.string.downloads_label)
toolbar.inflateMenu(R.menu.downloads_completed)
toolbar.setOnMenuItemClickListener(this)
Expand All @@ -88,12 +95,12 @@ class CompletedDownloadsFragment : Fragment(), SelectableAdapter.OnSelectModeLis
}
(activity as MainActivity).setupToolbarToggle(toolbar, displayUpArrow)

recyclerView = viewBinding.recyclerView
recyclerView = binding.recyclerView
recyclerView.setRecycledViewPool((activity as MainActivity).recycledViewPool)
adapter = CompletedDownloadsListAdapter(activity as MainActivity)
adapter.setOnSelectModeListener(this)
recyclerView.adapter = adapter
recyclerView.addOnScrollListener(LiftOnScrollListener(viewBinding.appbar))
recyclerView.addOnScrollListener(LiftOnScrollListener(binding.appbar))
swipeActions = SwipeActions(this, TAG).attachTo(recyclerView)
swipeActions.setFilter(FeedItemFilter(FeedItemFilter.DOWNLOADED))

Expand All @@ -102,18 +109,19 @@ class CompletedDownloadsFragment : Fragment(), SelectableAdapter.OnSelectModeLis
animator.supportsChangeAnimations = false
}

progressBar = viewBinding.progLoading
progressBar = binding.progLoading
progressBar.visibility = View.VISIBLE

val multiSelectDial = MultiSelectSpeedDialBinding.bind(viewBinding.root)
infoBar = binding.infoBar

val multiSelectDial = MultiSelectSpeedDialBinding.bind(binding.root)
speedDialView = multiSelectDial.fabSD
speedDialView.overlayLayout = multiSelectDial.fabSDOverlay
speedDialView.inflate(R.menu.episodes_apply_action_speeddial)
speedDialView.removeActionItemById(R.id.download_batch)
speedDialView.removeActionItemById(R.id.mark_read_batch)
speedDialView.removeActionItemById(R.id.mark_unread_batch)
speedDialView.removeActionItemById(R.id.remove_from_queue_batch)
// speedDialView.removeActionItemById(R.id.remove_all_inbox_item)
speedDialView.setOnChangeListener(object : SpeedDialView.OnChangeListener {
override fun onMainActionSelected(): Boolean {
return false
Expand Down Expand Up @@ -144,7 +152,7 @@ class CompletedDownloadsFragment : Fragment(), SelectableAdapter.OnSelectModeLis

loadItems()

return viewBinding.root
return binding.root
}

override fun onSaveInstanceState(outState: Bundle) {
Expand Down Expand Up @@ -227,7 +235,7 @@ class CompletedDownloadsFragment : Fragment(), SelectableAdapter.OnSelectModeLis
}

@Subscribe(threadMode = ThreadMode.MAIN)
fun onEventMainThread(event: ac.mdiq.podcini.util.event.FeedItemEvent) {
fun onEventMainThread(event: FeedItemEvent) {
Log.d(TAG, "onEventMainThread() called with: event = [$event]")

var i = 0
Expand All @@ -252,6 +260,7 @@ class CompletedDownloadsFragment : Fragment(), SelectableAdapter.OnSelectModeLis
adapter.setDummyViews(0)
adapter.updateItems(items)
}
refreshInfoBar()
}

@UnstableApi @Subscribe(threadMode = ThreadMode.MAIN)
Expand All @@ -264,6 +273,7 @@ class CompletedDownloadsFragment : Fragment(), SelectableAdapter.OnSelectModeLis
break
}
}
refreshInfoBar()
}

@Subscribe(threadMode = ThreadMode.MAIN)
Expand Down Expand Up @@ -312,13 +322,26 @@ class CompletedDownloadsFragment : Fragment(), SelectableAdapter.OnSelectModeLis
adapter.setDummyViews(0)
progressBar.visibility = View.GONE
adapter.updateItems(result)
refreshInfoBar()
}, { error: Throwable? ->
adapter.setDummyViews(0)
adapter.updateItems(emptyList())
Log.e(TAG, Log.getStackTraceString(error))
})
}

private fun refreshInfoBar() {
var info = String.format(Locale.getDefault(), "%d%s", items.size, getString(R.string.episodes_suffix))
if (items.isNotEmpty()) {
var sizeMB: Long = 0
for (item in items) {
sizeMB += item.media?.size?:0
}
info += "" + getString(R.string.size) + " : " + (sizeMB / 1000000) + " MB"
}
infoBar.text = info
}

override fun onStartSelectMode() {
swipeActions.detach()
speedDialView.visibility = View.VISIBLE
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/ac/mdiq/podcini/ui/fragment/ItemFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import ac.mdiq.podcini.ui.common.CircularProgressBar
import ac.mdiq.podcini.ui.common.ThemeUtils
import ac.mdiq.podcini.ui.gui.ShownotesCleaner
import ac.mdiq.podcini.ui.view.ShownotesWebView
import ac.mdiq.podcini.util.Converter
import ac.mdiq.podcini.util.DateFormatter
import ac.mdiq.podcini.util.PlaybackStatus
import ac.mdiq.podcini.util.event.EpisodeDownloadEvent
import ac.mdiq.podcini.util.event.FeedItemEvent
import ac.mdiq.podcini.util.event.UnreadItemsUpdateEvent
import android.os.Build
import android.os.Bundle
Expand Down Expand Up @@ -277,9 +279,9 @@ class ItemFragment : Fragment() {
} else {
noMediaLabel.visibility = View.GONE
if (media.getDuration() > 0) {
txtvDuration.text = ac.mdiq.podcini.util.Converter.getDurationStringLong(media.getDuration())
txtvDuration.text = Converter.getDurationStringLong(media.getDuration())
txtvDuration.setContentDescription(
ac.mdiq.podcini.util.Converter.getDurationStringLocalized(requireContext(), media.getDuration().toLong()))
Converter.getDurationStringLocalized(requireContext(), media.getDuration().toLong()))
}
if (item != null) {
actionButton1 = if (PlaybackStatus.isCurrentlyPlaying(media)) {
Expand Down Expand Up @@ -329,7 +331,7 @@ class ItemFragment : Fragment() {
}

@UnstableApi @Subscribe(threadMode = ThreadMode.MAIN)
fun onEventMainThread(event: ac.mdiq.podcini.util.event.FeedItemEvent) {
fun onEventMainThread(event: FeedItemEvent) {
Log.d(TAG, "onEventMainThread() called with: event = [$event]")
if (this.item == null) return
for (item in event.items) {
Expand Down
Loading

0 comments on commit 063af37

Please sign in to comment.