Skip to content

Commit

Permalink
6.8.3 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Sep 29, 2024
1 parent 1684190 commit 89143c6
Show file tree
Hide file tree
Showing 45 changed files with 2,180 additions and 3,838 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 3020257
versionName "6.8.0"
versionCode 3020259
versionName "6.8.2"

applicationId "ac.mdiq.podcini.R"
def commit = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package ac.mdiq.podcini.net.download

class DownloadStatus(@JvmField val state: Int, @JvmField val progress: Int) {
companion object {
const val STATE_QUEUED: Int = 0
const val STATE_COMPLETED: Int = 1 // Both successful and not successful
const val STATE_RUNNING: Int = 2
class DownloadStatus(
@JvmField val state: Int,
@JvmField val progress: Int) {

enum class State {
UNKNOWN,
QUEUED,
RUNNING,
COMPLETED // Both successful and not successful
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ abstract class DownloadServiceInterface {
abstract fun cancelAll(context: Context)

fun isDownloadingEpisode(url: String): Boolean {
return (currentDownloads.containsKey(url) && currentDownloads[url]!!.state != DownloadStatus.STATE_COMPLETED)
return (currentDownloads.containsKey(url) && currentDownloads[url]!!.state != DownloadStatus.State.COMPLETED.ordinal)
}

fun isEpisodeQueued(url: String): Boolean {
return (currentDownloads.containsKey(url) && currentDownloads[url]!!.state == DownloadStatus.STATE_QUEUED)
return (currentDownloads.containsKey(url) && currentDownloads[url]!!.state == DownloadStatus.State.QUEUED.ordinal)
}

fun getProgress(url: String): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import ac.mdiq.podcini.storage.utils.EpisodeUtil
import ac.mdiq.podcini.storage.utils.EpisodeUtil.hasAlmostEnded
import ac.mdiq.podcini.ui.activity.starter.MainActivityStarter
import ac.mdiq.podcini.ui.activity.starter.VideoPlayerActivityStarter
import ac.mdiq.podcini.ui.fragment.AudioPlayerFragment.PlayerDetailsFragment.Companion.media3Controller
import ac.mdiq.podcini.ui.fragment.AudioPlayerFragment.Companion.media3Controller
import ac.mdiq.podcini.ui.utils.NotificationUtils
import ac.mdiq.podcini.ui.widget.WidgetUpdater
import ac.mdiq.podcini.ui.widget.WidgetUpdater.WidgetState
Expand Down Expand Up @@ -1708,7 +1708,7 @@ class PlaybackService : MediaLibraryService() {

when (status) {
PlayerStatus.PLAYING, PlayerStatus.PAUSED, PlayerStatus.PREPARED -> {
Logd(TAG, "seekTo() called $t")
Logd(TAG, "seekTo t: $t")
if (seekLatch != null && seekLatch!!.count > 0) {
try { seekLatch!!.await(3, TimeUnit.SECONDS) } catch (e: InterruptedException) { Log.e(TAG, Log.getStackTraceString(e)) }
}
Expand Down
32 changes: 27 additions & 5 deletions app/src/main/kotlin/ac/mdiq/podcini/storage/model/Episode.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package ac.mdiq.podcini.storage.model

import ac.mdiq.podcini.net.download.DownloadStatus
import ac.mdiq.podcini.playback.base.InTheatre.curQueue
import ac.mdiq.podcini.playback.base.InTheatre.isCurrentlyPlaying
import ac.mdiq.podcini.storage.database.Feeds.getFeed
import ac.mdiq.podcini.storage.database.RealmDB.unmanaged
import ac.mdiq.vista.extractor.Vista
import ac.mdiq.vista.extractor.stream.StreamInfo
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import io.realm.kotlin.ext.realmListOf
import io.realm.kotlin.ext.realmSetOf
import io.realm.kotlin.types.RealmList
Expand Down Expand Up @@ -116,7 +120,7 @@ class Episode : RealmObject {
val imageLocation: String?
get() = when {
imageUrl != null -> imageUrl
media != null && unmanaged(media!!).hasEmbeddedPicture() -> EpisodeMedia.FILENAME_PREFIX_EMBEDDED_COVER + media!!.getLocalMediaUrl()
media != null && media?.hasEmbeddedPicture() == true -> EpisodeMedia.FILENAME_PREFIX_EMBEDDED_COVER + media!!.getLocalMediaUrl()
feed != null -> {
feed!!.imageUrl
}
Expand All @@ -133,6 +137,18 @@ class Episode : RealmObject {
return field
}

@Ignore
val inQueueState = mutableStateOf(curQueue.contains(this))

@Ignore
val isPlayingState = mutableStateOf(isCurrentlyPlaying(media))

@Ignore
val downloadState = mutableIntStateOf(if (media?.downloaded == true) DownloadStatus.State.COMPLETED.ordinal else DownloadStatus.State.UNKNOWN.ordinal)

@Ignore
val stopMonitoring = mutableStateOf(false)

constructor() {
this.playState = PlayState.UNPLAYED.code
}
Expand All @@ -151,6 +167,13 @@ class Episode : RealmObject {
this.feed = feed
}

fun copyStates(other: Episode) {
inQueueState.value = other.inQueueState.value
isPlayingState.value = other.isPlayingState.value
downloadState.value = other.downloadState.value
stopMonitoring.value = other.stopMonitoring.value
}

fun updateFromOther(other: Episode) {
if (other.imageUrl != null) this.imageUrl = other.imageUrl
if (other.title != null) title = other.title
Expand Down Expand Up @@ -256,12 +279,11 @@ class Episode : RealmObject {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Episode) return false
return id == other.id && playState == other.playState
return id == other.id
}

override fun hashCode(): Int {
var result = (id xor (id ushr 32)).toInt()
result = 31 * result + playState.hashCode()
val result = (id xor (id ushr 32)).toInt()
return result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ac.mdiq.podcini.storage.database.RealmDB.unmanaged
import ac.mdiq.podcini.storage.database.RealmDB.upsertBlk
import ac.mdiq.podcini.storage.utils.MediaMetadataRetrieverCompat
import ac.mdiq.podcini.util.Logd
import ac.mdiq.podcini.util.showStackTrace
import android.content.Context
import android.os.Parcel
import android.os.Parcelable
Expand Down Expand Up @@ -208,7 +209,7 @@ class EpisodeMedia: EmbeddedRealmObject, Playable {

fun hasEmbeddedPicture(): Boolean {
// TODO: checkEmbeddedPicture needs to update current copy
if (hasEmbeddedPicture == null) checkEmbeddedPicture()
if (hasEmbeddedPicture == null) unmanaged(this).checkEmbeddedPicture()
return hasEmbeddedPicture ?: false
}

Expand Down Expand Up @@ -303,7 +304,7 @@ class EpisodeMedia: EmbeddedRealmObject, Playable {
override fun getImageLocation(): String? {
return when {
episode != null -> episode!!.imageLocation
unmanaged(this).hasEmbeddedPicture() -> FILENAME_PREFIX_EMBEDDED_COVER + getLocalMediaUrl()
hasEmbeddedPicture() -> FILENAME_PREFIX_EMBEDDED_COVER + getLocalMediaUrl()
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class CancelDownloadActionButton(item: Episode) : EpisodeActionButton(item) {
val item_ = upsertBlk(item) {
it.disableAutoDownload()
}
EventFlow.postEvent(FlowEvent.EpisodeEvent.updated(item_)) }
EventFlow.postEvent(FlowEvent.EpisodeEvent.updated(item_))
}
actionState.value = getLabel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ class DeleteActionButton(item: Episode) : EpisodeActionButton(item) {
}
@UnstableApi override fun onClick(context: Context) {
deleteEpisodesWarnLocal(context, listOf(item))
actionState.value = getLabel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class DownloadActionButton(item: Episode) : EpisodeActionButton(item) {

builder.show()
}
actionState.value = getLabel()
}

private fun shouldNotDownload(media: EpisodeMedia?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,30 @@ abstract class EpisodeActionButton internal constructor(@JvmField var item: Epis

var processing: Float = -1f

val actionState = mutableIntStateOf(0)

abstract fun getLabel(): Int

abstract fun getDrawable(): Int

abstract fun onClick(context: Context)

fun configure(button: View, icon: ImageView, context: Context) {
button.visibility = visibility
button.contentDescription = context.getString(getLabel())
button.setOnClickListener { onClick(context) }
button.setOnLongClickListener {
val composeView = ComposeView(context).apply {
setContent {
val showDialog = remember { mutableStateOf(true) }
CustomTheme(context) { AltActionsDialog(context, showDialog.value, onDismiss = { showDialog.value = false }) }
}
}
(button as? ViewGroup)?.addView(composeView)
true
}
icon.setImageResource(getDrawable())
}
// fun configure(button: View, icon: ImageView, context: Context) {
// button.visibility = visibility
// button.contentDescription = context.getString(getLabel())
// button.setOnClickListener { onClick(context) }
// button.setOnLongClickListener {
// val composeView = ComposeView(context).apply {
// setContent {
// val showDialog = remember { mutableStateOf(true) }
// CustomTheme(context) { AltActionsDialog(context, showDialog.value, onDismiss = { showDialog.value = false }) }
// }
// }
// (button as? ViewGroup)?.addView(composeView)
// true
// }
// icon.setImageResource(getDrawable())
// }

@Composable
fun AltActionsDialog(context: Context, showDialog: Boolean, onDismiss: () -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MarkAsPlayedActionButton(item: Episode) : EpisodeActionButton(item) {

@UnstableApi override fun onClick(context: Context) {
if (!item.isPlayed()) setPlayState(Episode.PlayState.PLAYED.code, true, item)
actionState.value = getLabel()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ class PauseActionButton(item: Episode) : EpisodeActionButton(item) {

if (isCurrentlyPlaying(media)) context.sendBroadcast(createIntent(context, KeyEvent.KEYCODE_MEDIA_PAUSE))
// EventFlow.postEvent(FlowEvent.PlayEvent(item, Action.END))
actionState.value = getLabel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class PlayActionButton(item: Episode) : EpisodeActionButton(item) {
notifyMissingEpisodeMediaFile(context, media)
return
}

if (playbackService?.isServiceReady() == true && InTheatre.isCurMedia(media)) {
playbackService?.mPlayer?.resume()
playbackService?.taskManager?.restartSleepTimer()
Expand All @@ -47,8 +46,8 @@ class PlayActionButton(item: Episode) : EpisodeActionButton(item) {
PlaybackServiceStarter(context, media).callEvenIfRunning(true).start()
EventFlow.postEvent(FlowEvent.PlayEvent(item))
}

playVideoIfNeeded(context, media)
actionState.value = getLabel()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class PlayLocalActionButton(item: Episode) : EpisodeActionButton(item) {
Toast.makeText(context, R.string.no_media_label, Toast.LENGTH_LONG).show()
return
}

if (playbackService?.isServiceReady() == true && InTheatre.isCurMedia(media)) {
playbackService?.mPlayer?.resume()
playbackService?.taskManager?.restartSleepTimer()
Expand All @@ -38,7 +37,7 @@ class PlayLocalActionButton(item: Episode) : EpisodeActionButton(item) {
PlaybackServiceStarter(context, media).callEvenIfRunning(true).start()
EventFlow.postEvent(FlowEvent.PlayEvent(item))
}

if (media.getMediaType() == MediaType.VIDEO) context.startActivity(getPlayerActivityIntent(context, MediaType.VIDEO))
actionState.value = getLabel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class StreamActionButton(item: Episode) : EpisodeActionButton(item) {
return
}
stream(context, media)
actionState.value = getLabel()
}

class StreamingConfirmationDialog(private val context: Context, private val playable: Playable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class TTSActionButton(item: Episode) : EpisodeActionButton(item) {
item.setPlayed(false)
processing = 1f
EventFlow.postEvent(FlowEvent.EpisodeEvent.updated(item))
actionState.value = getLabel()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ class VisitWebsiteActionButton(item: Episode) : EpisodeActionButton(item) {

override fun onClick(context: Context) {
if (!item.link.isNullOrEmpty()) openInBrowser(context, item.link!!)
actionState.value = getLabel()
}
}
Loading

0 comments on commit 89143c6

Please sign in to comment.