Skip to content

Commit

Permalink
play speed, played mark, swipe icon clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Mar 22, 2024
1 parent 547aa1f commit 0ee4c7a
Show file tree
Hide file tree
Showing 54 changed files with 362 additions and 300 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 3020111
versionName "4.3.0"
versionCode 3020112
versionName "4.3.1"

def commit = ""
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object ImageResourceUtils {
@JvmStatic
fun getFallbackImageLocation(playable: Playable): String? {
if (playable is FeedMedia) {
val item = playable.getItem()
val item = playable.item
return if (item?.feed != null) {
item.feed!!.imageUrl
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ object PlaybackSpeedUtils {
mediaType = media.getMediaType()
playbackSpeed = PlaybackPreferences.currentlyPlayingTemporaryPlaybackSpeed

if (playbackSpeed == FeedPreferences.SPEED_USE_GLOBAL && media is FeedMedia) {
val item = media.getItem()
// if (playbackSpeed == FeedPreferences.SPEED_USE_GLOBAL && media is FeedMedia) {
if (media is FeedMedia) {
val item = media.item
if (item != null) {
val feed = item.feed
if (feed?.preferences != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ object SynchronizationQueueSink {
if (!SynchronizationSettings.isProviderConnected) {
return
}
if (media.getItem()?.feed == null || media.getItem()!!.feed!!.isLocalFeed) {
if (media.item?.feed == null || media.item!!.feed!!.isLocalFeed) {
return
}
if (media.startPosition < 0 || (!completed && media.startPosition >= media.getPosition())) {
return
}
val action = EpisodeAction.Builder(media.getItem()!!, EpisodeAction.PLAY)
val action = EpisodeAction.Builder(media.item!!, EpisodeAction.PLAY)
.currentTimestamp()
.started(media.startPosition / 1000)
.position((if (completed) media.getDuration() else media.getPosition()) / 1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object PlayableUtils {
playable.setLastPlayedTime(timestamp)

if (playable is FeedMedia) {
val item = playable.getItem()
val item = playable.item
if (item != null && item.isNew) {
DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ abstract class PlaybackController(private val activity: FragmentActivity) {
val media = getMedia()
if (media is FeedMedia) {
media.setPosition(time)
DBWriter.setFeedItem(media.getItem())
DBWriter.setFeedItem(media.item)
EventBus.getDefault().post(PlaybackPositionEvent(time, media.getDuration()))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,43 +87,43 @@ class PlaybackPreferences private constructor() : OnSharedPreferenceChangeListen
const val PLAYER_STATUS_OTHER: Int = 3

private var instance: PlaybackPreferences? = null
private var prefs: SharedPreferences? = null
private lateinit var prefs: SharedPreferences

@JvmStatic
fun init(context: Context) {
instance = PlaybackPreferences()
prefs = PreferenceManager.getDefaultSharedPreferences(context)
prefs?.registerOnSharedPreferenceChangeListener(instance)
prefs.registerOnSharedPreferenceChangeListener(instance)
}

@JvmStatic
val currentlyPlayingMediaType: Long
get() = prefs!!.getLong(PREF_CURRENTLY_PLAYING_MEDIA_TYPE, NO_MEDIA_PLAYING)
get() = prefs.getLong(PREF_CURRENTLY_PLAYING_MEDIA_TYPE, NO_MEDIA_PLAYING)

@JvmStatic
val currentlyPlayingFeedMediaId: Long
get() = prefs!!.getLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING)
get() = prefs.getLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING)

@JvmStatic
val currentEpisodeIsVideo: Boolean
get() = prefs!!.getBoolean(PREF_CURRENT_EPISODE_IS_VIDEO, false)
get() = prefs.getBoolean(PREF_CURRENT_EPISODE_IS_VIDEO, false)

@JvmStatic
val currentPlayerStatus: Int
get() = prefs!!.getInt(PREF_CURRENT_PLAYER_STATUS, PLAYER_STATUS_OTHER)
get() = prefs.getInt(PREF_CURRENT_PLAYER_STATUS, PLAYER_STATUS_OTHER)

@JvmStatic
var currentlyPlayingTemporaryPlaybackSpeed: Float
get() = prefs!!.getFloat(PREF_CURRENTLY_PLAYING_TEMPORARY_PLAYBACK_SPEED, FeedPreferences.SPEED_USE_GLOBAL)
get() = prefs.getFloat(PREF_CURRENTLY_PLAYING_TEMPORARY_PLAYBACK_SPEED, FeedPreferences.SPEED_USE_GLOBAL)
set(speed) {
val editor = prefs!!.edit()
val editor = prefs.edit()
editor.putFloat(PREF_CURRENTLY_PLAYING_TEMPORARY_PLAYBACK_SPEED, speed)
editor.apply()
}

@JvmStatic
fun writeNoMediaPlaying() {
val editor = prefs!!.edit()
val editor = prefs.edit()
editor.putLong(PREF_CURRENTLY_PLAYING_MEDIA_TYPE, NO_MEDIA_PLAYING)
editor.putLong(PREF_CURRENTLY_PLAYING_FEED_ID, NO_MEDIA_PLAYING)
editor.putLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, NO_MEDIA_PLAYING)
Expand All @@ -134,15 +134,15 @@ class PlaybackPreferences private constructor() : OnSharedPreferenceChangeListen
@JvmStatic
fun writeMediaPlaying(playable: Playable?, playerStatus: PlayerStatus) {
Log.d(TAG, "Writing playback preferences")
val editor = prefs!!.edit()
val editor = prefs.edit()

if (playable == null) {
writeNoMediaPlaying()
} else {
editor.putLong(PREF_CURRENTLY_PLAYING_MEDIA_TYPE, playable.getPlayableType().toLong())
editor.putBoolean(PREF_CURRENT_EPISODE_IS_VIDEO, playable.getMediaType() == MediaType.VIDEO)
if (playable is FeedMedia) {
val itemId = playable.getItem()?.feed?.id
val itemId = playable.item?.feed?.id
if (itemId != null) editor.putLong(PREF_CURRENTLY_PLAYING_FEED_ID, itemId)
editor.putLong(PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, playable.id)
} else {
Expand All @@ -160,14 +160,14 @@ class PlaybackPreferences private constructor() : OnSharedPreferenceChangeListen
fun writePlayerStatus(playerStatus: PlayerStatus) {
Log.d(TAG, "Writing player status playback preferences")

val editor = prefs!!.edit()
val editor = prefs.edit()
editor.putInt(PREF_CURRENT_PLAYER_STATUS, getCurrentPlayerStatusAsInt(playerStatus))
editor.apply()
}

@JvmStatic
fun clearCurrentlyPlayingTemporaryPlaybackSpeed() {
val editor = prefs!!.edit()
val editor = prefs.edit()
editor.remove(PREF_CURRENTLY_PLAYING_TEMPORARY_PLAYBACK_SPEED)
editor.apply()
}
Expand Down
50 changes: 25 additions & 25 deletions app/src/main/java/ac/mdiq/podcini/preferences/PreferenceUpgrader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object PreferenceUpgrader {
private const val PREF_CONFIGURED_VERSION = "version_code"
private const val PREF_NAME = "app_version"

private var prefs: SharedPreferences? = null
private lateinit var prefs: SharedPreferences

fun checkUpgrades(context: Context) {
prefs = PreferenceManager.getDefaultSharedPreferences(context)
Expand Down Expand Up @@ -60,15 +60,15 @@ object PreferenceUpgrader {
} // else 0 or special negative values, no change needed
}
if (oldVersion < 1070197) {
if (prefs!!.getBoolean("prefMobileUpdate", false)) {
prefs!!.edit().putString("prefMobileUpdateAllowed", "everything").apply()
if (prefs.getBoolean("prefMobileUpdate", false)) {
prefs.edit().putString("prefMobileUpdateAllowed", "everything").apply()
}
}
if (oldVersion < 1070300) {
if (prefs!!.getBoolean("prefEnableAutoDownloadOnMobile", false)) {
if (prefs.getBoolean("prefEnableAutoDownloadOnMobile", false)) {
isAllowMobileAutoDownload = true
}
when (prefs!!.getString("prefMobileUpdateAllowed", "images")) {
when (prefs.getString("prefMobileUpdateAllowed", "images")) {
"everything" -> {
isAllowMobileFeedRefresh = true
isAllowMobileEpisodeDownload = true
Expand All @@ -81,27 +81,27 @@ object PreferenceUpgrader {
if (oldVersion < 1070400) {
val theme = theme
if (theme == UserPreferences.ThemePreference.LIGHT) {
prefs!!.edit().putString(UserPreferences.PREF_THEME, "system").apply()
prefs.edit().putString(UserPreferences.PREF_THEME, "system").apply()
}

isQueueLocked = false
isStreamOverDownload = false

if (!prefs!!.contains(UserPreferences.PREF_ENQUEUE_LOCATION)) {
if (!prefs.contains(UserPreferences.PREF_ENQUEUE_LOCATION)) {
val keyOldPrefEnqueueFront = "prefQueueAddToFront"
val enqueueAtFront = prefs!!.getBoolean(keyOldPrefEnqueueFront, false)
val enqueueAtFront = prefs.getBoolean(keyOldPrefEnqueueFront, false)
val enqueueLocation = if (enqueueAtFront) EnqueueLocation.FRONT else EnqueueLocation.BACK
UserPreferences.enqueueLocation = enqueueLocation
}
}
if (oldVersion < 2010300) {
// Migrate hardware button preferences
if (prefs!!.getBoolean("prefHardwareForwardButtonSkips", false)) {
prefs!!.edit().putString(UserPreferences.PREF_HARDWARE_FORWARD_BUTTON,
if (prefs.getBoolean("prefHardwareForwardButtonSkips", false)) {
prefs.edit().putString(UserPreferences.PREF_HARDWARE_FORWARD_BUTTON,
KeyEvent.KEYCODE_MEDIA_NEXT.toString()).apply()
}
if (prefs!!.getBoolean("prefHardwarePreviousButtonRestarts", false)) {
prefs!!.edit().putString(UserPreferences.PREF_HARDWARE_PREVIOUS_BUTTON,
if (prefs.getBoolean("prefHardwarePreviousButtonRestarts", false)) {
prefs.edit().putString(UserPreferences.PREF_HARDWARE_PREVIOUS_BUTTON,
KeyEvent.KEYCODE_MEDIA_PREVIOUS.toString()).apply()
}
}
Expand All @@ -111,14 +111,14 @@ object PreferenceUpgrader {
SwipeAction.REMOVE_FROM_QUEUE + "," + SwipeAction.REMOVE_FROM_QUEUE).apply()
}
if (oldVersion < 2050000) {
prefs!!.edit().putBoolean(UserPreferences.PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, true).apply()
prefs.edit().putBoolean(UserPreferences.PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, true).apply()
}
if (oldVersion < 2080000) {
// Migrate drawer feed counter setting to reflect removal of
// "unplayed and in inbox" (0), by changing it to "unplayed" (2)
val feedCounterSetting = prefs!!.getString(UserPreferences.PREF_DRAWER_FEED_COUNTER, "2")
val feedCounterSetting = prefs.getString(UserPreferences.PREF_DRAWER_FEED_COUNTER, "2")
if (feedCounterSetting == "0") {
prefs!!.edit().putString(UserPreferences.PREF_DRAWER_FEED_COUNTER, "2").apply()
prefs.edit().putString(UserPreferences.PREF_DRAWER_FEED_COUNTER, "2").apply()
}

val sleepTimerPreferences =
Expand All @@ -128,28 +128,28 @@ object PreferenceUpgrader {
val unit = timeUnits[sleepTimerPreferences.getInt("LastTimeUnit", 1)]
setLastTimer(unit.toMinutes(value).toString())

if (prefs!!.getString(UserPreferences.PREF_EPISODE_CACHE_SIZE, "20")
if (prefs.getString(UserPreferences.PREF_EPISODE_CACHE_SIZE, "20")
== context.getString(R.string.pref_episode_cache_unlimited)) {
prefs!!.edit().putString(UserPreferences.PREF_EPISODE_CACHE_SIZE,
prefs.edit().putString(UserPreferences.PREF_EPISODE_CACHE_SIZE,
"" + UserPreferences.EPISODE_CACHE_SIZE_UNLIMITED).apply()
}
}
if (oldVersion < 3000007) {
if (prefs!!.getString("prefBackButtonBehavior", "") == "drawer") {
prefs!!.edit().putBoolean(UserPreferences.PREF_BACK_OPENS_DRAWER, true).apply()
if (prefs.getString("prefBackButtonBehavior", "") == "drawer") {
prefs.edit().putBoolean(UserPreferences.PREF_BACK_OPENS_DRAWER, true).apply()
}
}
if (oldVersion < 3010000) {
if (prefs!!.getString(UserPreferences.PREF_THEME, "system") == "2") {
prefs!!.edit()
if (prefs.getString(UserPreferences.PREF_THEME, "system") == "2") {
prefs.edit()
.putString(UserPreferences.PREF_THEME, "1")
.putBoolean(UserPreferences.PREF_THEME_BLACK, true)
.apply()
}
isAllowMobileSync = true
if (prefs!!.getString(UserPreferences.PREF_UPDATE_INTERVAL, ":")!!
if (prefs.getString(UserPreferences.PREF_UPDATE_INTERVAL, ":")!!
.contains(":")) { // Unset or "time of day"
prefs!!.edit().putString(UserPreferences.PREF_UPDATE_INTERVAL, "12").apply()
prefs.edit().putString(UserPreferences.PREF_UPDATE_INTERVAL, "12").apply()
}
}
if (oldVersion < 3020000) {
Expand All @@ -161,12 +161,12 @@ object PreferenceUpgrader {
context.getSharedPreferences(AllEpisodesFragment.PREF_NAME, Context.MODE_PRIVATE)
val oldEpisodeSort = allEpisodesPreferences.getString(UserPreferences.PREF_SORT_ALL_EPISODES, "")
if (!StringUtils.isAllEmpty(oldEpisodeSort)) {
prefs!!.edit().putString(UserPreferences.PREF_SORT_ALL_EPISODES, oldEpisodeSort).apply()
prefs.edit().putString(UserPreferences.PREF_SORT_ALL_EPISODES, oldEpisodeSort).apply()
}

val oldEpisodeFilter = allEpisodesPreferences.getString("filter", "")
if (!StringUtils.isAllEmpty(oldEpisodeFilter)) {
prefs!!.edit().putString(UserPreferences.PREF_FILTER_ALL_EPISODES, oldEpisodeFilter).apply()
prefs.edit().putString(UserPreferences.PREF_FILTER_ALL_EPISODES, oldEpisodeFilter).apply()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ object DownloadRequestCreator {
}
Log.d(TAG, "Requesting download media from url " + media.download_url)

val username = if ((media.getItem()?.feed?.preferences != null)) media.getItem()!!.feed!!.preferences!!.username else null
val password = if ((media.getItem()?.feed?.preferences != null)) media.getItem()!!.feed!!.preferences!!.password else null
val username = if ((media.item?.feed?.preferences != null)) media.item!!.feed!!.preferences!!.username else null
val password = if ((media.item?.feed?.preferences != null)) media.item!!.feed!!.preferences!!.password else null

return DownloadRequest.Builder(dest.toString(), media).withAuthentication(username, password)
}
Expand Down Expand Up @@ -87,7 +87,7 @@ object DownloadRequestCreator {
}

private fun getMediafilePath(media: FeedMedia): String {
val title = media.getItem()?.feed?.title?:return ""
val title = media.item?.feed?.title?:return ""
val mediaPath = (MEDIA_DOWNLOADPATH
+ FileNameGenerator.generateFileName(title))
return UserPreferences.getDataFolder(mediaPath).toString() + "/"
Expand All @@ -97,8 +97,8 @@ object DownloadRequestCreator {
var titleBaseFilename = ""

// Try to generate the filename by the item title
if (media.getItem()?.title != null) {
val title = media.getItem()!!.title!!
if (media.item?.title != null) {
val title = media.item!!.title!!
titleBaseFilename = FileNameGenerator.generateFileName(title)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import ac.mdiq.podcini.storage.model.feed.FeedItem
import ac.mdiq.podcini.storage.model.feed.FeedMedia
import ac.mdiq.podcini.net.download.serviceinterface.DownloadServiceInterface
import ac.mdiq.podcini.preferences.UserPreferences
import androidx.annotation.OptIn
import androidx.media3.common.util.UnstableApi
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers
import java.util.concurrent.Future
Expand Down Expand Up @@ -36,7 +38,7 @@ class DownloadServiceInterfaceImpl : DownloadServiceInterface() {
ExistingWorkPolicy.KEEP, workRequest.build())
}

override fun cancel(context: Context, media: FeedMedia) {
@OptIn(UnstableApi::class) override fun cancel(context: Context, media: FeedMedia) {
// This needs to be done here, not in the worker. Reason: The worker might or might not be running.
DBWriter.deleteFeedMediaOfItem(context, media.id) // Remove partially downloaded file
val tag = WORK_TAG_EPISODE_URL + media.download_url
Expand All @@ -48,7 +50,7 @@ class DownloadServiceInterfaceImpl : DownloadServiceInterface() {
{ workInfos: List<WorkInfo> ->
for (info in workInfos) {
if (info.tags.contains(WORK_DATA_WAS_QUEUED)) {
if (media.getItem() != null) DBWriter.removeQueueItem(context, false, media.getItem()!!)
if (media.item != null) DBWriter.removeQueueItem(context, false, media.item!!)
}
}
WorkManager.getInstance(context).cancelAllWorkByTag(tag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ class MediaDownloadedHandler(private val context: Context, var updatedStatus: Do
return
}
// media.setDownloaded modifies played state
val broadcastUnreadStateUpdate = media.getItem() != null && media.getItem()!!.isNew
val broadcastUnreadStateUpdate = media.item != null && media.item!!.isNew
media.setDownloaded(true)
media.file_url = request.destination
if (request.destination != null) media.size = File(request.destination).length()
media.checkEmbeddedPicture() // enforce check

// check if file has chapters
if (media.getItem() != null && !media.getItem()!!.hasChapters()) {
if (media.item != null && !media.item!!.hasChapters()) {
media.setChapters(ChapterUtils.loadChaptersFromMediaFile(media, context))
}

if (media.getItem()?.podcastIndexChapterUrl != null) {
ChapterUtils.loadChaptersFromUrl(media.getItem()!!.podcastIndexChapterUrl!!, false)
if (media.item?.podcastIndexChapterUrl != null) {
ChapterUtils.loadChaptersFromUrl(media.item!!.podcastIndexChapterUrl!!, false)
}
// Get duration
var durationStr: String? = null
Expand All @@ -60,7 +60,7 @@ class MediaDownloadedHandler(private val context: Context, var updatedStatus: Do
Log.e(TAG, "Get duration failed", e)
}

val item = media.getItem()
val item = media.item

try {
DBWriter.setFeedMedia(media).get()
Expand Down
Loading

0 comments on commit 0ee4c7a

Please sign in to comment.