Skip to content

Commit

Permalink
6.3.5 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Aug 7, 2024
1 parent 87af1a1 commit 50e9dff
Show file tree
Hide file tree
Showing 25 changed files with 748 additions and 643 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ android {
testApplicationId "ac.mdiq.podcini.tests"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

versionCode 3020228
versionName "6.3.4"
versionCode 3020229
versionName "6.3.5"

applicationId "ac.mdiq.podcini.R"
def commit = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class DownloadServiceInterfaceImpl : DownloadServiceInterface() {
try {
val workInfoList = future.get() // Wait for the completion of the future operation and retrieve the result
workInfoList.forEach { workInfo ->
// TODO: why cancel so many times??
if (workInfo.tags.contains(WORK_DATA_WAS_QUEUED)) {
val item_ = media.episodeOrFetch()
if (item_ != null) Queues.removeFromQueue(item_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class PlaybackService : MediaSessionService() {
}

override fun onMediaChanged(reloadUI: Boolean) {
Logd(TAG, "reloadUI callback reached")
Logd(TAG, "onMediaChanged reloadUI callback reached")
if (reloadUI) sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class MainPreferencesFragment : PreferenceFragmentCompat() {
.addBreadcrumb(getTitleOfPage(R.xml.preferences_autodownload))
config.index(R.xml.preferences_synchronization).addBreadcrumb(getTitleOfPage(R.xml.preferences_synchronization))
config.index(R.xml.preferences_notifications).addBreadcrumb(getTitleOfPage(R.xml.preferences_notifications))
config.index(R.xml.feed_settings).addBreadcrumb(getTitleOfPage(R.xml.feed_settings))
// config.index(R.xml.feed_settings).addBreadcrumb(getTitleOfPage(R.xml.feed_settings))
config.index(R.xml.preferences_swipe)
.addBreadcrumb(getTitleOfPage(R.xml.preferences_user_interface))
.addBreadcrumb(getTitleOfPage(R.xml.preferences_swipe))
Expand Down
31 changes: 20 additions & 11 deletions app/src/main/kotlin/ac/mdiq/podcini/receiver/MediaButtonReceiver.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package ac.mdiq.podcini.receiver

import ac.mdiq.podcini.playback.service.PlaybackService
import ac.mdiq.podcini.playback.service.PlaybackService.Companion
import ac.mdiq.podcini.util.Logd
import ac.mdiq.podcini.util.config.ClientConfigurator
import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
Expand All @@ -12,25 +10,36 @@ import android.util.Log
import android.view.KeyEvent
import androidx.core.content.ContextCompat
import androidx.media3.common.util.UnstableApi
import ac.mdiq.podcini.util.config.ClientConfigurator

/**
* Receives media button events.
*/
class MediaButtonReceiver : BroadcastReceiver() {
@UnstableApi
override fun onReceive(context: Context, intent: Intent) {
Log.d(TAG, "onReceive called with action: ${intent.action}")
if (intent.extras == null) return
Log.d(TAG, "onReceive Received intent: $intent")
Log.d(TAG, "onReceive Action: ${intent.action}")
val extras = intent.extras
Log.d(TAG, "onReceive Extras: $extras")
if (extras == null) return

Log.d(TAG, "onReceive Extras: ${extras.keySet()}")
for (key in extras.keySet()) {
Log.d(TAG, "onReceive Extra[$key] = ${extras[key]}")
}

// val event = extras.getParcelable(Intent.EXTRA_KEY_EVENT, KeyEvent::class.java)
val keyEvent: KeyEvent? = if (Build.VERSION.SDK_INT >= 33) extras.getParcelable(Intent.EXTRA_KEY_EVENT, KeyEvent::class.java)
else extras.getParcelable(Intent.EXTRA_KEY_EVENT) as KeyEvent?
Log.d(TAG, "onReceive keyEvent = $keyEvent" )

val event = intent.extras!![Intent.EXTRA_KEY_EVENT] as? KeyEvent
if (event != null && event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0) {
if (keyEvent != null && keyEvent.action == KeyEvent.ACTION_DOWN && keyEvent.repeatCount == 0) {
ClientConfigurator.initialize(context)
val serviceIntent = Intent(PLAYBACK_SERVICE_INTENT)
serviceIntent.setPackage(context.packageName)
serviceIntent.putExtra(EXTRA_KEYCODE, event.keyCode)
serviceIntent.putExtra(EXTRA_SOURCE, event.source)
serviceIntent.putExtra(EXTRA_HARDWAREBUTTON, event.eventTime > 0 || event.downTime > 0)
serviceIntent.putExtra(EXTRA_KEYCODE, keyEvent.keyCode)
serviceIntent.putExtra(EXTRA_SOURCE, keyEvent.source)
serviceIntent.putExtra(EXTRA_HARDWAREBUTTON, keyEvent.eventTime > 0 || keyEvent.downTime > 0)
try {
ContextCompat.startForegroundService(context, serviceIntent)
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,48 +71,7 @@ object AutoDownloads {
// likely not needed
@UnstableApi
open fun autoDownloadEpisodeMedia(context: Context, feeds: List<Feed>? = null): Runnable? {
return Runnable {
// // true if we should auto download based on network status
//// val networkShouldAutoDl = (isAutoDownloadAllowed)
// val networkShouldAutoDl = (isAutoDownloadAllowed && isEnableAutodownload)
// // true if we should auto download based on power status
// val powerShouldAutoDl = (deviceCharging(context) || isEnableAutodownloadOnBattery)
// Logd(TAG, "prepare autoDownloadUndownloadedItems $networkShouldAutoDl $powerShouldAutoDl")
// // we should only auto download if both network AND power are happy
// if (networkShouldAutoDl && powerShouldAutoDl) {
// Logd(TAG, "Performing auto-dl of undownloaded episodes")
// val queueItems = curQueue.episodes
// val newItems = getEpisodes(0, Int.MAX_VALUE, EpisodeFilter(EpisodeFilter.States.new.name), EpisodeSortOrder.DATE_NEW_OLD)
// Logd(TAG, "newItems: ${newItems.size}")
// val candidates: MutableList<Episode> = ArrayList(queueItems.size + newItems.size)
// candidates.addAll(queueItems)
// for (newItem in newItems) {
// val feedPrefs = newItem.feed!!.preferences
// if (feedPrefs!!.autoDownload && !candidates.contains(newItem) && feedPrefs.autoDownloadFilter!!.shouldAutoDownload(newItem)) candidates.add(newItem)
// }
// // filter items that are not auto downloadable
// val it = candidates.iterator()
// while (it.hasNext()) {
// val item = it.next()
// if (!item.isAutoDownloadEnabled || item.isDownloaded || item.media == null || isCurMedia(item.media) || item.feed?.isLocalFeed == true)
// it.remove()
// }
// val autoDownloadableEpisodes = candidates.size
// val downloadedEpisodes = getEpisodesCount(EpisodeFilter(EpisodeFilter.States.downloaded.name))
// val deletedEpisodes = AutoCleanups.build().makeRoomForEpisodes(context, autoDownloadableEpisodes)
// val cacheIsUnlimited = episodeCacheSize == UserPreferences.EPISODE_CACHE_SIZE_UNLIMITED
// val episodeCacheSize = episodeCacheSize
// val episodeSpaceLeft =
// if (cacheIsUnlimited || episodeCacheSize >= downloadedEpisodes + autoDownloadableEpisodes) autoDownloadableEpisodes
// else episodeCacheSize - (downloadedEpisodes - deletedEpisodes)
// val itemsToDownload: List<Episode> = candidates.subList(0, episodeSpaceLeft)
// if (itemsToDownload.isNotEmpty()) {
// Logd(TAG, "Enqueueing " + itemsToDownload.size + " items for download")
// for (episode in itemsToDownload) DownloadServiceInterface.get()?.download(context, episode)
// }
// }
// else Logd(TAG, "not auto downloaded networkShouldAutoDl: $networkShouldAutoDl powerShouldAutoDl $powerShouldAutoDl")
}
return Runnable {}
}

/**
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/kotlin/ac/mdiq/podcini/storage/database/Feeds.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ac.mdiq.podcini.preferences.UserPreferences.isAutoDelete
import ac.mdiq.podcini.preferences.UserPreferences.isAutoDeleteLocal
import ac.mdiq.podcini.storage.database.Episodes.deleteEpisodes
import ac.mdiq.podcini.storage.database.LogsAndStats.addDownloadStatus
import ac.mdiq.podcini.storage.database.Queues.addToQueueSync
import ac.mdiq.podcini.storage.database.Queues.removeFromAllQueuesQuiet
import ac.mdiq.podcini.storage.database.RealmDB.realm
import ac.mdiq.podcini.storage.database.RealmDB.runOnIOScope
Expand Down Expand Up @@ -284,6 +285,10 @@ object Feeds {
if (pubDate == null || priorMostRecentDate == null || priorMostRecentDate.before(pubDate) || priorMostRecentDate == pubDate) {
Logd(TAG, "Marking episode published on $pubDate new, prior most recent date = $priorMostRecentDate")
episode.setNew()
if (savedFeed.preferences?.autoAddNewToQueue == true) {
val q = savedFeed.preferences?.queue
if (q != null) runOnIOScope { addToQueueSync(false, episode, q) }
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,13 @@ object Queues {
if (queueModified) {
// TODO: handle sorting
applySortOrder(qItems, events)
// curQueue.episodes.clear()
// curQueue.episodes.addAll(qItems)
curQueue = upsert(curQueue) {
it.episodeIds.clear()
it.episodeIds.addAll(qItemIds)
it.update()
}
// curQueue.episodes.addAll(qItems)

for (event in events) EventFlow.postEvent(event)

// EventFlow.postEvent(FlowEvent.EpisodeEvent.updated(updatedItems))
if (markAsUnplayed && markAsUnplayeds.size > 0) setPlayState(Episode.PlayState.UNPLAYED.code, false, *markAsUnplayeds.toTypedArray())
// if (performAutoDownload) autodownloadEpisodeMedia(context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import kotlin.coroutines.ContinuationInterceptor
object RealmDB {
private val TAG: String = RealmDB::class.simpleName ?: "Anonymous"

private const val SCHEMA_VERSION_NUMBER = 18L
private const val SCHEMA_VERSION_NUMBER = 19L

private val ioScope = CoroutineScope(Dispatchers.IO)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ac.mdiq.podcini.storage.model

import ac.mdiq.podcini.R
import ac.mdiq.podcini.playback.base.InTheatre.curQueue
import ac.mdiq.podcini.storage.database.RealmDB.realm
import ac.mdiq.podcini.storage.model.VolumeAdaptionSetting.Companion.fromInteger
Expand Down Expand Up @@ -93,6 +94,8 @@ class FeedPreferences : EmbeddedRealmObject {
}
var queueId: Long = 0L

var autoAddNewToQueue: Boolean = false

@Ignore
var autoDownloadFilter: FeedAutoDownloadFilter? = null
get() = field ?: FeedAutoDownloadFilter(autoDLInclude, autoDLExclude, autoDLMinDuration, markExcludedPlayed)
Expand Down Expand Up @@ -121,10 +124,10 @@ class FeedPreferences : EmbeddedRealmObject {
}
var autoDLPolicyCode: Int = 0

enum class AutoDLPolicy(val code: Int) {
ONLY_NEW(0),
NEWER(1),
OLDER(2);
enum class AutoDLPolicy(val code: Int, val resId: Int) {
ONLY_NEW(0, R.string.feed_auto_download_new),
NEWER(1, R.string.feed_auto_download_newer),
OLDER(2, R.string.feed_auto_download_older);

companion object {
fun fromCode(code: Int): AutoDLPolicy {
Expand Down Expand Up @@ -190,5 +193,6 @@ class FeedPreferences : EmbeddedRealmObject {
const val TAG_SEPARATOR: String = "\u001e"

val FeedAutoDeleteOptions = AutoDeleteAction.values().map { it.tag }

}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package ac.mdiq.podcini.storage.model

enum class VolumeAdaptionSetting(private val value: Int, @JvmField val adaptionFactor: Float) {
OFF(0, 1.0f),
LIGHT_REDUCTION(1, 0.5f),
HEAVY_REDUCTION(2, 0.2f),
LIGHT_BOOST(3, 1.5f),
MEDIUM_BOOST(4, 2f),
HEAVY_BOOST(5, 2.5f);
import ac.mdiq.podcini.R

enum class VolumeAdaptionSetting(private val value: Int, @JvmField val adaptionFactor: Float, val resId: Int) {
OFF(0, 1.0f, R.string.feed_volume_reduction_off),
LIGHT_REDUCTION(1, 0.5f, R.string.feed_volume_reduction_light),
HEAVY_REDUCTION(2, 0.2f, R.string.feed_volume_reduction_heavy),
LIGHT_BOOST(3, 1.5f, R.string.feed_volume_boost_light),
MEDIUM_BOOST(4, 2f, R.string.feed_volume_boost_medium),
HEAVY_BOOST(5, 2.5f, R.string.feed_volume_boost_heavy);

fun toInteger(): Int {
return value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ open class SwipeActions(dragDirs: Int, private val fragment: Fragment, private v
}

@JvmField
val swipeActions: List<SwipeAction> = Collections.unmodifiableList(
listOf(NoActionSwipeAction(), AddToQueueSwipeAction(), StartDownloadSwipeAction(), MarkFavoriteSwipeAction(),
TogglePlaybackStateSwipeAction(), RemoveFromQueueSwipeAction(),
DeleteSwipeAction(), RemoveFromHistorySwipeAction())
)
val swipeActions: List<SwipeAction> = listOf(
NoActionSwipeAction(), AddToQueueSwipeAction(),
StartDownloadSwipeAction(), MarkFavoriteSwipeAction(),
TogglePlaybackStateSwipeAction(), RemoveFromQueueSwipeAction(),
DeleteSwipeAction(), RemoveFromHistorySwipeAction())

private fun getPrefs(tag: String, defaultActions: String): Actions {
val prefsString = prefs!!.getString(KEY_PREFIX_SWIPEACTIONS + tag, defaultActions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ class PreferenceActivity : AppCompatActivity(), SearchPreferenceResultListener {

override fun onSearchResultClicked(result: SearchPreferenceResult) {
when (val screen = result.resourceFile) {
R.xml.feed_settings -> {
val builder = MaterialAlertDialogBuilder(this)
builder.setTitle(R.string.feed_settings_label)
builder.setMessage(R.string.pref_feed_settings_dialog_msg)
builder.setPositiveButton(android.R.string.ok, null)
builder.show()
}
// R.xml.feed_settings -> {
// val builder = MaterialAlertDialogBuilder(this)
// builder.setTitle(R.string.feed_settings_label)
// builder.setMessage(R.string.pref_feed_settings_dialog_msg)
// builder.setPositiveButton(android.R.string.ok, null)
// builder.show()
// }
R.xml.preferences_notifications -> openScreen(screen)
else -> {
val fragment = openScreen(result.resourceFile)
Expand Down Expand Up @@ -197,9 +197,9 @@ class PreferenceActivity : AppCompatActivity(), SearchPreferenceResultListener {
R.xml.preferences_notifications -> {
return R.string.notification_pref_fragment
}
R.xml.feed_settings -> {
return R.string.feed_settings_label
}
// R.xml.feed_settings -> {
// return R.string.feed_settings_label
// }
R.xml.preferences_swipe -> {
return R.string.swipeactions_label
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,19 @@ object SkipPreferenceDialog {
val choices = arrayOfNulls<String>(values.size)
for (i in values.indices) {
if (skipSecs == values[i]) checked = i

choices[i] = String.format(Locale.getDefault(), "%d %s", values[i], context.getString(R.string.time_seconds))
}

val builder = MaterialAlertDialogBuilder(context)
builder.setTitle(if (direction == SkipDirection.SKIP_FORWARD) R.string.pref_fast_forward else R.string.pref_rewind)
builder.setSingleChoiceItems(choices, checked) { dialog: DialogInterface, _: Int ->
val choice = (dialog as AlertDialog).listView.checkedItemPosition
if (choice < 0 || choice >= values.size) {
System.err.printf("Choice in showSkipPreference is out of bounds %d", choice)
} else {
if (choice < 0 || choice >= values.size) System.err.printf("Choice in showSkipPreference is out of bounds %d", choice)
else {
val seconds = values[choice]
if (direction == SkipDirection.SKIP_FORWARD) fastForwardSecs = seconds
else rewindSecs = seconds

if (textView != null) textView.text = NumberFormat.getInstance().format(seconds.toLong())

dialog.dismiss()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TagSettingsDialog : DialogFragment() {
private var _binding: EditTagsDialogBinding? = null
private val binding get() = _binding!!

private var feedList: List<Feed> = mutableListOf()
private var feedList: MutableList<Feed> = mutableListOf()

private lateinit var displayedTags: MutableList<String>
private lateinit var adapter: SimpleChipAdapter
Expand Down Expand Up @@ -100,9 +100,10 @@ class TagSettingsDialog : DialogFragment() {
}

@OptIn(UnstableApi::class) private fun updatePreferencesTags(commonTags: Set<String>) {
for (f in feedList) {
for (i in 0..feedList.size-1) {
val f = feedList[i]
Logd(TAG, "${f.title} $displayedTags")
upsertBlk(f) {
feedList[i] = upsertBlk(f) {
if (it.preferences != null) {
it.preferences!!.tags.removeAll(commonTags)
it.preferences!!.tags.addAll(displayedTags)
Expand All @@ -112,7 +113,7 @@ class TagSettingsDialog : DialogFragment() {
}

private fun setFeedList(feedLst_: List<Feed>) {
feedList = feedLst_
feedList = feedLst_.toMutableList()
}

companion object {
Expand Down
Loading

0 comments on commit 50e9dff

Please sign in to comment.