Skip to content

Commit

Permalink
6.15.9 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Dec 13, 2024
1 parent dc775b7 commit d759a89
Show file tree
Hide file tree
Showing 34 changed files with 1,242 additions and 1,486 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ android {
vectorDrawables.useSupportLibrary false
vectorDrawables.generatedDensities = []

versionCode 3020318
versionName "6.15.8"
versionCode 3020319
versionName "6.15.9"

applicationId "ac.mdiq.podcini.R"
def commit = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package ac.mdiq.podcini.net.feed.searcher

import ac.mdiq.podcini.R
import ac.mdiq.podcini.net.download.service.PodciniHttpClient.getHttpClient
import ac.mdiq.podcini.storage.model.Feed
import ac.mdiq.podcini.util.Logd
import android.content.Context
import okhttp3.CacheControl
import okhttp3.OkHttpClient
import okhttp3.Request
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
import java.io.IOException
import java.util.Locale
import java.util.concurrent.TimeUnit

class ItunesTopListLoader(private val context: Context) {

@Throws(JSONException::class, IOException::class)
fun loadToplist(country: String, limit: Int, subscribed: List<Feed>): List<PodcastSearchResult> {
val client = getHttpClient()
val feedString: String
var loadCountry = country
if (COUNTRY_CODE_UNSET == country) loadCountry = Locale.getDefault().country
feedString = try { getTopListFeed(client, loadCountry)
} catch (e: IOException) { if (COUNTRY_CODE_UNSET == country) getTopListFeed(client, "US") else throw e }
return removeSubscribed(parseFeed(feedString), subscribed, limit)
}

@Throws(IOException::class)
private fun getTopListFeed(client: OkHttpClient, country: String): String {
val url = "https://itunes.apple.com/%s/rss/toppodcasts/limit=$NUM_LOADED/explicit=true/json"
Logd(TAG, "Feed URL " + String.format(url, country))
val httpReq: Request.Builder = Request.Builder()
.cacheControl(CacheControl.Builder().maxStale(1, TimeUnit.DAYS).build())
.url(String.format(url, country))
client.newCall(httpReq.build()).execute().use { response ->
if (response.isSuccessful) return response.body!!.string()
if (response.code == 400) throw IOException("iTunes does not have data for the selected country.")
val prefix = context.getString(R.string.error_msg_prefix)
throw IOException(prefix + response)
}
}

@Throws(JSONException::class)
private fun parseFeed(jsonString: String): List<PodcastSearchResult> {
val result = JSONObject(jsonString)
val feed: JSONObject
val entries: JSONArray
try {
feed = result.getJSONObject("feed")
entries = feed.getJSONArray("entry")
} catch (_: JSONException) { return ArrayList() }
val results: MutableList<PodcastSearchResult> = ArrayList()
for (i in 0 until entries.length()) {
val json = entries.getJSONObject(i)
results.add(PodcastSearchResult.fromItunesToplist(json))
}
return results
}

companion object {
private val TAG: String = ItunesTopListLoader::class.simpleName ?: "Anonymous"
const val PREF_KEY_COUNTRY_CODE: String = "country_code"
const val PREF_KEY_HIDDEN_DISCOVERY_COUNTRY: String = "hidden_discovery_country"
const val PREF_KEY_NEEDS_CONFIRM: String = "needs_confirm"
const val PREFS: String = "CountryRegionPrefs"
const val COUNTRY_CODE_UNSET: String = "99"
private const val NUM_LOADED = 25

private fun removeSubscribed(suggestedPodcasts: List<PodcastSearchResult>, subscribedFeeds: List<Feed>, limit: Int): List<PodcastSearchResult> {
val subscribedPodcastsSet: MutableSet<String> = HashSet()
for (subscribedFeed in subscribedFeeds) {
if (subscribedFeed.title != null && subscribedFeed.author != null)
subscribedPodcastsSet.add(subscribedFeed.title!!.trim { it <= ' ' } + " - " + subscribedFeed.author!!.trim { it <= ' ' })
}
val suggestedNotSubscribed: MutableList<PodcastSearchResult> = ArrayList()
for (suggested in suggestedPodcasts) {
if (!subscribedPodcastsSet.contains(suggested.title.trim { it <= ' ' })) suggestedNotSubscribed.add(suggested)
if (suggestedNotSubscribed.size == limit) return suggestedNotSubscribed
}
return suggestedNotSubscribed
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ class LocalMediaPlayer(context: Context, callback: MediaPlayerCallback) : MediaP
} else Logd(TAG, "Call to resume() was ignored because current state of PSMP object is $status")
}

override fun pause(abandonFocus: Boolean, reinit: Boolean) {
override fun pause(reinit: Boolean) {
releaseWifiLockIfNecessary()
if (status == PlayerStatus.PLAYING) {
Logd(TAG, "Pausing playback $abandonFocus $reinit")
Logd(TAG, "Pausing playback $reinit")
exoPlayer?.pause()
setPlayerStatus(PlayerStatus.PAUSED, curMedia, getPosition())
if (curEpisode != null) EventFlow.postEvent(FlowEvent.PlayEvent(curEpisode!!, Action.END))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ abstract class MediaPlayerBase protected constructor(protected val context: Cont
* @param reinit is true if service should reinit after pausing if the media
* file is being streamed
*/
abstract fun pause(abandonFocus: Boolean, reinit: Boolean)
abstract fun pause(reinit: Boolean)

/**
* Prepared media player for playback if the service is in the INITALIZED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import ac.mdiq.podcini.preferences.UserPreferences.fastForwardSecs
import ac.mdiq.podcini.preferences.UserPreferences.isSkipSilence
import ac.mdiq.podcini.preferences.UserPreferences.prefAdaptiveProgressUpdate
import ac.mdiq.podcini.preferences.UserPreferences.rewindSecs
import ac.mdiq.podcini.preferences.UserPreferences.showSkipOnNotification
import ac.mdiq.podcini.receiver.MediaButtonReceiver
import ac.mdiq.podcini.storage.database.Episodes
import ac.mdiq.podcini.storage.database.Episodes.deleteMediaSync
Expand Down Expand Up @@ -213,7 +214,7 @@ class PlaybackService : MediaLibraryService() {
Logd(TAG, "Pausing playback because audio is becoming noisy")
// pauseIfPauseOnDisconnect()
transientPause = (MediaPlayerBase.status == PlayerStatus.PLAYING || MediaPlayerBase.status == PlayerStatus.FALLBACK)
if (isPauseOnHeadsetDisconnect && !isCasting) mPlayer?.pause(!isPersistNotify, false)
if (isPauseOnHeadsetDisconnect && !isCasting) mPlayer?.pause(false)
}
}

Expand Down Expand Up @@ -562,7 +563,7 @@ class PlaybackService : MediaLibraryService() {
when (customCommand.customAction) {
NotificationCustomButton.REWIND.customAction -> mPlayer?.seekDelta(-rewindSecs * 1000)
NotificationCustomButton.FORWARD.customAction -> mPlayer?.seekDelta(fastForwardSecs * 1000)
NotificationCustomButton.SKIP.customAction -> mPlayer?.skip()
NotificationCustomButton.SKIP.customAction -> if (showSkipOnNotification) mPlayer?.skip()
}
return Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
}
Expand Down Expand Up @@ -698,7 +699,7 @@ class PlaybackService : MediaLibraryService() {
var wasPlaying = false
if (mPlayer != null) {
wasPlaying = MediaPlayerBase.status == PlayerStatus.PLAYING || MediaPlayerBase.status == PlayerStatus.FALLBACK
mPlayer!!.pause(abandonFocus = true, reinit = false)
mPlayer!!.pause(reinit = false)
mPlayer!!.shutdown()
}
mPlayer = CastMediaPlayer.getInstanceIfConnected(this, mediaPlayerCallback)
Expand Down Expand Up @@ -897,7 +898,7 @@ class PlaybackService : MediaLibraryService() {
when (keycode) {
KeyEvent.KEYCODE_HEADSETHOOK, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE -> {
when {
status == PlayerStatus.PLAYING -> mPlayer?.pause(!isPersistNotify, false)
status == PlayerStatus.PLAYING -> mPlayer?.pause(false)
status == PlayerStatus.FALLBACK || status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED -> mPlayer?.resume()
status == PlayerStatus.PREPARING -> mPlayer?.startWhenPrepared?.set(!mPlayer!!.startWhenPrepared.get())
status == PlayerStatus.INITIALIZED -> {
Expand Down Expand Up @@ -925,7 +926,7 @@ class PlaybackService : MediaLibraryService() {
}
KeyEvent.KEYCODE_MEDIA_PAUSE -> {
if (status == PlayerStatus.PLAYING) {
mPlayer?.pause(!isPersistNotify, false)
mPlayer?.pause(false)
return true
}
}
Expand Down Expand Up @@ -962,7 +963,7 @@ class PlaybackService : MediaLibraryService() {
}
}
KEYCODE_MEDIA_STOP -> {
if (status == PlayerStatus.FALLBACK || status == PlayerStatus.PLAYING) mPlayer?.pause(abandonFocus = true, reinit = true)
if (status == PlayerStatus.FALLBACK || status == PlayerStatus.PLAYING) mPlayer?.pause(reinit = true)
return true
}
else -> {
Expand Down Expand Up @@ -1026,9 +1027,7 @@ class PlaybackService : MediaLibraryService() {
is FlowEvent.PlayerErrorEvent -> onPlayerError(event)
is FlowEvent.BufferUpdateEvent -> onBufferUpdate(event)
is FlowEvent.SleepTimerUpdatedEvent -> onSleepTimerUpdate(event)
// is FlowEvent.VolumeAdaptionChangedEvent -> onVolumeAdaptionChanged(event)
is FlowEvent.FeedPrefsChangeEvent -> onFeedPrefsChanged(event)
// is FlowEvent.SkipIntroEndingChangedEvent -> skipIntroEndingPresetChanged(event)
is FlowEvent.PlayEvent -> if (event.action != Action.END) currentitem = event.episode
is FlowEvent.EpisodeMediaEvent -> onEpisodeMediaEvent(event)
else -> {}
Expand Down Expand Up @@ -1071,10 +1070,6 @@ class PlaybackService : MediaLibraryService() {
mediaSession?.notifyChildrenChanged("CurQueue", range, null)
}

// private fun onVolumeAdaptionChanged(event: FlowEvent.VolumeAdaptionChangedEvent) {
// if (mPlayer != null) updateVolumeIfNecessary(mPlayer!!, event.feedId, event.volumeAdaptionSetting)
// }

private fun onFeedPrefsChanged(event: FlowEvent.FeedPrefsChangeEvent) {
val item = (curMedia as? EpisodeMedia)?.episodeOrFetch() ?: currentitem
if (item?.feed?.id == event.feed.id) {
Expand All @@ -1089,7 +1084,7 @@ class PlaybackService : MediaLibraryService() {

private fun onPlayerError(event: FlowEvent.PlayerErrorEvent) {
if (MediaPlayerBase.status == PlayerStatus.PLAYING || MediaPlayerBase.status == PlayerStatus.FALLBACK)
mPlayer!!.pause(abandonFocus = true, reinit = false)
mPlayer!!.pause(reinit = false)
}

private fun onBufferUpdate(event: FlowEvent.BufferUpdateEvent) {
Expand All @@ -1105,7 +1100,7 @@ class PlaybackService : MediaLibraryService() {
private fun onSleepTimerUpdate(event: FlowEvent.SleepTimerUpdatedEvent) {
when {
event.isOver -> {
mPlayer?.pause(abandonFocus = true, reinit = true)
mPlayer?.pause(reinit = true)
mPlayer?.setVolume(1.0f, 1.0f)
}
event.getTimeLeft() < TaskManager.NOTIFICATION_THRESHOLD -> {
Expand Down Expand Up @@ -1279,7 +1274,7 @@ class PlaybackService : MediaLibraryService() {
add(NotificationCustomButton.REWIND.commandButton)
add(defaultPlayPauseButton)
add(NotificationCustomButton.FORWARD.commandButton)
add(NotificationCustomButton.SKIP.commandButton)
if (showSkipOnNotification) add(NotificationCustomButton.SKIP.commandButton)
}.build()
/* Fallback option to handle nullability, in case retrieving default play/pause button fails for some reason (should never happen). */
} else mediaButtons
Expand Down Expand Up @@ -1591,7 +1586,7 @@ class PlaybackService : MediaLibraryService() {
/**
* @return `true` if notifications are persistent, `false` otherwise
*/
val isPersistNotify: Boolean by lazy { appPrefs.getBoolean(UserPreferences.Prefs.prefPersistNotify.name, true) }
// val isPersistNotify: Boolean by lazy { appPrefs.getBoolean(UserPreferences.Prefs.prefPersistNotify.name, true) }

val isPauseOnHeadsetDisconnect: Boolean by lazy { appPrefs.getBoolean(UserPreferences.Prefs.prefPauseOnHeadsetDisconnect.name, true) }

Expand Down Expand Up @@ -1679,7 +1674,7 @@ class PlaybackService : MediaLibraryService() {
when (MediaPlayerBase.status) {
PlayerStatus.FALLBACK -> toggleFallbackSpeed(1.0f)
PlayerStatus.PLAYING -> {
playbackService?.mPlayer?.pause(true, reinit = false)
playbackService?.mPlayer?.pause(reinit = false)
playbackService?.isSpeedForward = false
playbackService?.isFallbackSpeed = false
(curMedia as? EpisodeMedia)?.forceVideo = false
Expand All @@ -1705,7 +1700,7 @@ class PlaybackService : MediaLibraryService() {
if (item_?.feed?.id == feedId) {
item_.feed!!.preferences?.volumeAdaptionSetting = volumeAdaptionSetting
if (MediaPlayerBase.status == PlayerStatus.PLAYING) {
mediaPlayer.pause(abandonFocus = false, reinit = false)
mediaPlayer.pause(reinit = false)
mediaPlayer.resume()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class OpmlBackupAgent : BackupAgentHelper() {
private val TAG: String = OpmlBackupAgent::class.simpleName ?: "Anonymous"
private const val OPML_BACKUP_KEY = "opml"

val isOPMLRestared: Boolean
val isOPMLRestored: Boolean
get() = appPrefs.getBoolean(UserPreferences.Prefs.prefOPMLRestore.name, false)

fun performRestore(context: Context) {
Expand Down
48 changes: 3 additions & 45 deletions app/src/main/kotlin/ac/mdiq/podcini/preferences/UserPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,8 @@ object UserPreferences {
val isThemeColorTinted: Boolean
get() = Build.VERSION.SDK_INT >= 31 && appPrefs.getBoolean(Prefs.prefTintedColors.name, false)

// not using this
var hiddenDrawerItems: List<String>
get() {
return listOf()
// val hiddenItems = appPrefs.getString(Prefs.prefHiddenDrawerItems.name, "")
// return hiddenItems?.split(",") ?: listOf()
}
set(items) {
val str = items.joinToString()
appPrefs.edit().putString(Prefs.prefHiddenDrawerItems.name, str).apply()
}

var fullNotificationButtons: List<Int>
get() {
val buttons = appPrefs.getString(Prefs.prefFullNotificationButtons.name, "${NOTIFICATION_BUTTON.SKIP.ordinal},${NOTIFICATION_BUTTON.PLAYBACK_SPEED.ordinal}")?.split(",") ?: listOf()
val notificationButtons: MutableList<Int> = ArrayList()
for (button in buttons) notificationButtons.add(button.toInt())
return notificationButtons
}
set(items) {
val str = items.joinToString()
appPrefs.edit().putString(Prefs.prefFullNotificationButtons.name, str).apply()
}
val showSkipOnNotification: Boolean
get() = appPrefs.getBoolean(Prefs.prefShowSkip.name, true)

val isAutoDelete: Boolean
get() = appPrefs.getBoolean(Prefs.prefAutoDelete.name, false)
Expand Down Expand Up @@ -267,25 +246,17 @@ object UserPreferences {
prefTheme,
prefThemeBlack,
prefTintedColors,
prefHiddenDrawerItems,
// prefDrawerFeedOrder,
// prefDrawerFeedOrderDir,
prefFeedGridLayout,
prefSwipeToRefreshAll,
prefExpandNotify,
prefEpisodeCover,
showTimeLeft,
prefPersistNotify,
prefFullNotificationButtons,
prefShowSkip,
prefShowDownloadReport,
prefDefaultPage,
prefBackButtonOpensDrawer,

prefFeedFilter,

prefQueueKeepSorted,
prefQueueKeepSortedOrder,
prefDownloadSortedOrder,
prefDownloadsFilter,

// Episodes
Expand All @@ -304,11 +275,8 @@ object UserPreferences {
prefFavoriteKeepsEpisode,
prefAutoDelete,
prefAutoDeleteLocal,
// prefSmartMarkAsPlayedSecs,
// prefSmartMarkAsPlayedPercent,
prefPlaybackSpeedArray,
prefFallbackSpeed,
prefPauseForFocusLoss,
prefPlaybackTimeRespectsSpeed,
prefStreamOverDownload,
prefLowQualityOnMobile,
Expand Down Expand Up @@ -336,7 +304,6 @@ object UserPreferences {
pref_gpodnet_notifications,

// Other
// prefDataFolder
prefDeleteRemovesFromQueue,

// Mediaplayer
Expand All @@ -348,15 +315,6 @@ object UserPreferences {
prefVideoPlaybackMode,
}

@Suppress("ClassName")
enum class NOTIFICATION_BUTTON {
REWIND,
FAST_FORWARD,
SKIP,
NEXT_CHAPTER,
PLAYBACK_SPEED,
}

enum class ThemePreference {
LIGHT, DARK, BLACK, SYSTEM
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import ac.mdiq.podcini.storage.database.RealmDB.runOnIOScope
import ac.mdiq.podcini.storage.database.RealmDB.upsert
import ac.mdiq.podcini.storage.database.RealmDB.upsertBlk
import ac.mdiq.podcini.storage.model.Episode
import ac.mdiq.podcini.storage.model.EpisodeFilter
import ac.mdiq.podcini.storage.model.PlayState
import ac.mdiq.podcini.ui.activity.MainActivity
import ac.mdiq.podcini.ui.compose.*
Expand Down Expand Up @@ -622,6 +621,9 @@ class SwipeActions(private val fragment: Fragment, private val tag: String) : De
EpisodesFragment.TAG -> {
forFragment = stringResource(R.string.episodes_label)
}
OnlineEpisodesFragment.TAG -> {
forFragment = stringResource(R.string.online_episodes_label)
}
// DownloadsFragment.TAG -> {
// forFragment = stringResource(R.string.downloads_label)
// keys = keys.filter { a: SwipeAction ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import ac.mdiq.podcini.preferences.ThemeSwitcher.getNoTitleTheme
import ac.mdiq.podcini.preferences.UserPreferences
import ac.mdiq.podcini.preferences.UserPreferences.backButtonOpensDrawer
import ac.mdiq.podcini.preferences.UserPreferences.defaultPage
import ac.mdiq.podcini.preferences.UserPreferences.hiddenDrawerItems
import ac.mdiq.podcini.receiver.MediaButtonReceiver.Companion.createIntent
import ac.mdiq.podcini.storage.database.Feeds.buildTags
import ac.mdiq.podcini.storage.database.Feeds.monitorFeeds
Expand Down Expand Up @@ -561,7 +560,7 @@ class MainActivity : CastEnabledActivity() {
finish()
startActivity(Intent(this, MainActivity::class.java))
}
if (hiddenDrawerItems.contains(NavDrawerFragment.getLastNavFragment())) loadFragment(defaultPage, null)
// if (hiddenDrawerItems.contains(NavDrawerFragment.getLastNavFragment())) loadFragment(defaultPage, null)
}

@Deprecated("Deprecated in Java")
Expand Down
Loading

0 comments on commit d759a89

Please sign in to comment.