Skip to content

Commit

Permalink
6.0.8 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Jul 10, 2024
1 parent 8eee364 commit 0f99aa2
Show file tree
Hide file tree
Showing 66 changed files with 365 additions and 227 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ android {
buildConfig true
}
defaultConfig {
versionCode 3020207
versionName "6.0.7"
versionCode 3020208
versionName "6.0.8"

applicationId "ac.mdiq.podcini.R"
def commit = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DownloadServiceInterfaceImpl : DownloadServiceInterface() {

override fun downloadNow(context: Context, item: Episode, ignoreConstraints: Boolean) {
Logd(TAG, "starting downloadNow")
val workRequest: OneTimeWorkRequest.Builder = getRequest(context, item)
val workRequest: OneTimeWorkRequest.Builder = getRequest(item)
workRequest.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
if (ignoreConstraints) workRequest.setConstraints(Builder().setRequiredNetworkType(NetworkType.CONNECTED).build())
else workRequest.setConstraints(constraints)
Expand All @@ -63,7 +63,7 @@ class DownloadServiceInterfaceImpl : DownloadServiceInterface() {

override fun download(context: Context, item: Episode) {
Logd(TAG, "starting download")
val workRequest: OneTimeWorkRequest.Builder = getRequest(context, item)
val workRequest: OneTimeWorkRequest.Builder = getRequest(item)
workRequest.setConstraints(constraints)
if (item.media?.downloadUrl != null)
WorkManager.getInstance(context).enqueueUniqueWork(item.media!!.downloadUrl!!, ExistingWorkPolicy.KEEP, workRequest.build())
Expand Down Expand Up @@ -108,7 +108,7 @@ class DownloadServiceInterfaceImpl : DownloadServiceInterface() {
return constraints.build()
}

@OptIn(UnstableApi::class) private fun getRequest(context: Context, item: Episode): OneTimeWorkRequest.Builder {
@OptIn(UnstableApi::class) private fun getRequest(item: Episode): OneTimeWorkRequest.Builder {
Logd(TAG, "starting getRequest")
val workRequest: OneTimeWorkRequest.Builder = OneTimeWorkRequest.Builder(EpisodeDownloadWorker::class.java)
.setInitialDelay(0L, TimeUnit.MILLISECONDS)
Expand Down Expand Up @@ -208,7 +208,7 @@ class DownloadServiceInterfaceImpl : DownloadServiceInterface() {

if (dest.exists()) {
try {
media.fileUrl = request.destination
media.setfileUrlOrNull(request.destination)
Episodes.persistEpisodeMedia(media)
} catch (e: Exception) {
Log.e(TAG, "performDownload Exception in writeFileUrl: " + e.message)
Expand Down Expand Up @@ -353,8 +353,10 @@ class DownloadServiceInterfaceImpl : DownloadServiceInterface() {
}
// media.setDownloaded modifies played state
val broadcastUnreadStateUpdate = media.episode != null && media.episode!!.isNew
media.downloaded = true
media.fileUrl = request.destination
// media.downloaded = true
media.setIsDownloaded()
Logd(TAG, "media.episode.isNew: ${media.episode?.isNew} ${media.episode?.playState}")
media.setfileUrlOrNull(request.destination)
if (request.destination != null) media.size = File(request.destination).length()

media.checkEmbeddedPicture() // enforce check
Expand Down Expand Up @@ -388,7 +390,7 @@ class DownloadServiceInterfaceImpl : DownloadServiceInterface() {
// we've received the media, we don't want to autodownload it again
if (item != null) {
item.disableAutoDownload()
Logd(TAG, "persisting episode downloaded ${item.title} ${item.media?.fileUrl} ${item.media?.downloaded}")
Logd(TAG, "persisting episode downloaded ${item.title} ${item.media?.fileUrl} ${item.media?.downloaded} ${item.isNew}")
// setFeedItem() signals that the item has been updated,
// so we do it after the enclosing media has been updated above,
// to ensure subscribers will get the updated EpisodeMedia as well
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,14 @@ class PlaybackService : MediaSessionService() {
}

override fun onDestroy() {
super.onDestroy()
Logd(TAG, "Service is about to be destroyed")

isRunning = false
currentMediaType = MediaType.UNKNOWN
castStateListener.destroy()

currentitem = null

LocalMediaPlayer.cleanup()
mediaSession?.run {
player.release()
Expand All @@ -573,6 +574,8 @@ class PlaybackService : MediaSessionService() {
unregisterReceiver(bluetoothStateUpdated)
unregisterReceiver(audioBecomingNoisy)
taskManager.shutdown()

super.onDestroy()
}

fun isServiceReady(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ class SynchronizationPreferencesFragment : PreferenceFragmentCompat() {
}

override fun onDestroy() {
super.onDestroy()
cancelFlowEvents()
super.onDestroy()
}

@OptIn(UnstableApi::class) override fun onResume() {
Expand Down
13 changes: 7 additions & 6 deletions app/src/main/kotlin/ac/mdiq/podcini/storage/database/Episodes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ object Episodes {
Logd(TAG, String.format(Locale.US, "Requested to delete EpisodeMedia [id=%d, title=%s, downloaded=%s", media.id, media.getEpisodeTitle(), media.downloaded))
var localDelete = false
val url = media.fileUrl
var episode = episode
when {
url != null && url.startsWith("content://") -> {
// Local feed
Expand All @@ -116,8 +117,8 @@ object Episodes {
EventFlow.postEvent(FlowEvent.MessageEvent(context.getString(R.string.delete_local_failed)))
return episode
}
upsertBlk(episode) {
it.media?.fileUrl = null
episode = upsertBlk(episode) {
it.media?.setfileUrlOrNull(null)
if (media.downloadUrl.isNullOrEmpty()) it.media = null
}
localDelete = true
Expand All @@ -131,9 +132,9 @@ object Episodes {
EventFlow.postEvent(evt)
return episode
}
upsertBlk(episode) {
episode = upsertBlk(episode) {
it.media?.downloaded = false
it.media?.fileUrl = null
it.media?.setfileUrlOrNull(null)
it.media?.hasEmbeddedPicture = false
if (media.downloadUrl.isNullOrEmpty()) it.media = null
}
Expand Down Expand Up @@ -209,10 +210,10 @@ object Episodes {
fun persistEpisodeMedia(media: EpisodeMedia) : Job {
Logd(TAG, "persistEpisodeMedia called")
return runOnIOScope {
val episode = media.episode
var episode = media.episode
if (episode != null) {
episode.media = media
upsert(episode) {}
episode = upsert(episode) {}
EventFlow.postEvent(FlowEvent.EpisodeEvent.updated(episode))
} else Log.e(TAG, "persistEpisodeMedia media.episode is null")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object RealmDB {
if (BuildConfig.DEBUG) {
val stackTrace = Thread.currentThread().stackTrace
val caller = if (stackTrace.size > 3) stackTrace[3] else null
Logd(TAG, "${caller?.className}.${caller?.methodName} upsert: ${entity.javaClass.simpleName}")
Logd(TAG, "${caller?.className}.${caller?.methodName} unmanaged: ${entity.javaClass.simpleName}")
}
return if (entity.isManaged()) realm.copyFromRealm(entity) else entity
}
Expand Down
44 changes: 23 additions & 21 deletions app/src/main/kotlin/ac/mdiq/podcini/storage/model/EpisodeMedia.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ class EpisodeMedia: EmbeddedRealmObject, Playable {
var id: Long = 0L // same as the episode id

var fileUrl: String? = null
set(value) {
field = value
if (value == null) downloaded = false
}
// set(value) {
// field = value
// if (value == null) downloaded = false
// }

var downloadUrl: String? = null

var downloaded: Boolean = false
set(value) {
field = value
if (value && episode?.isNew == true) episode!!.setPlayed(false)
}
// set(value) {
// Logd(TAG, "setting downloaded: $value ${episode?.isNew}")
// field = value
// if (value && episode?.isNew == true) episode!!.setPlayed(false)
// }

@get:JvmName("getDurationProperty")
@set:JvmName("setDurationProperty")
Expand Down Expand Up @@ -88,9 +89,8 @@ class EpisodeMedia: EmbeddedRealmObject, Playable {
this.episode = i
this.size = size
this.mimeType = mime_type
fileUrl = null
setfileUrlOrNull(null)
this.downloadUrl = download_url
downloaded = false
}

constructor(id: Long, item: Episode?, duration: Int, position: Int,
Expand All @@ -108,20 +108,12 @@ class EpisodeMedia: EmbeddedRealmObject, Playable {
this.playbackCompletionDate = playbackCompletionDate?.clone() as? Date
this.playbackCompletionTime = playbackCompletionDate?.time ?: 0
this.lastPlayedTime = lastPlayedTime
this.fileUrl = file_url
setfileUrlOrNull(file_url)
this.downloadUrl = download_url
this.downloaded = downloaded
if (downloaded) setIsDownloaded()
else this.downloaded = downloaded
}

// constructor(id: Long, item: Episode?, duration: Int, position: Int,
// size: Long, mime_type: String?, file_url: String?, download_url: String?,
// downloaded: Boolean, playbackCompletionDate: Date?, played_duration: Int,
// hasEmbeddedPicture: Boolean?, lastPlayedTime: Long)
// : this(id, item, duration, position, size, mime_type, file_url, download_url, downloaded, playbackCompletionDate, played_duration, lastPlayedTime) {
//
// this.hasEmbeddedPicture = hasEmbeddedPicture
// }

fun getHumanReadableIdentifier(): String? {
return if (episode?.title != null) episode!!.title else downloadUrl
}
Expand Down Expand Up @@ -158,6 +150,16 @@ class EpisodeMedia: EmbeddedRealmObject, Playable {
return FEEDFILETYPE_FEEDMEDIA
}

fun setIsDownloaded() {
downloaded = true
if (episode?.isNew == true) episode!!.setPlayed(false)
}

fun setfileUrlOrNull(url: String?) {
fileUrl = url
if (url == null) downloaded = false
}

override fun getDuration(): Int {
return duration
}
Expand Down
14 changes: 9 additions & 5 deletions app/src/main/kotlin/ac/mdiq/podcini/storage/model/Feed.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class Feed : RealmObject {
*/
@FullText
var customTitle: String? = null
set(value) {
field = if (value == null || value == eigenTitle) null
else value
}
// set(value) {
// field = if (value == null || value == eigenTitle) null
// else value
// }

var link: String? = null

Expand Down Expand Up @@ -163,7 +163,7 @@ class Feed : RealmObject {
this.fileUrl = fileUrl
this.downloadUrl = downloadUrl
this.eigenTitle = title
this.customTitle = customTitle
setCustomTitle1(customTitle)
this.lastUpdate = lastUpdate
this.link = link
this.description = description
Expand Down Expand Up @@ -210,6 +210,10 @@ class Feed : RealmObject {
preferences = FeedPreferences(0, false, FeedPreferences.AutoDeleteAction.GLOBAL, VolumeAdaptionSetting.OFF, username, password)
}

fun setCustomTitle1(value: String?) {
customTitle = if (value == null || value == eigenTitle) null else value
}

fun getTextIdentifier(): String? {
return when {
!customTitle.isNullOrEmpty() -> customTitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,4 @@ object ChapterUtils {
}
return listOf()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class EpisodeMultiSelectHandler(private val activity: MainActivity, private val
showMessage(R.plurals.marked_unread_batch_label, items.size)
}
R.id.download_batch -> downloadChecked(items)
R.id.delete_batch -> LocalDeleteModal.showLocalFeedDeleteWarningIfNecessary(activity, items) { deleteChecked(items) }
R.id.delete_batch -> deleteChecked(items)
else -> Log.e(TAG, "Unrecognized speed dial action item. Do nothing. id=$actionId")
}
}
Expand All @@ -57,18 +57,6 @@ class EpisodeMultiSelectHandler(private val activity: MainActivity, private val
showMessage(R.plurals.removed_from_queue_batch_label, checkedIds.size)
}

// private fun markedCheckedPlayed(items: List<FeedItem>) {
//// val checkedIds = getSelectedIds(items)
// DBWriter.markItemsPlayed(FeedItem.PLAYED, *items.toTypedArray())
// showMessage(R.plurals.marked_read_batch_label, items.size)
// }
//
// private fun markedCheckedUnplayed(items: List<FeedItem>) {
//// val checkedIds = getSelectedIds(items)
// DBWriter.markItemsPlayed(FeedItem.UNPLAYED, *items.toTypedArray())
// showMessage(R.plurals.marked_unread_batch_label, items.size)
// }

private fun markFavorite(items: List<Episode>, stat: Boolean) {
for (item in items) {
Episodes.setFavorite(item, true)
Expand All @@ -85,14 +73,8 @@ class EpisodeMultiSelectHandler(private val activity: MainActivity, private val
}

private fun deleteChecked(items: List<Episode>) {
var countHasMedia = 0
for (feedItem in items) {
if (feedItem.media != null && feedItem.media!!.downloaded) {
countHasMedia++
deleteMediaOfEpisode(activity, feedItem)
}
}
showMessage(R.plurals.deleted_multi_episode_batch_label, countHasMedia)
LocalDeleteModal.deleteEpisodesWarnLocal(activity, items)
showMessage(R.plurals.deleted_multi_episode_batch_label, items.size)
}

private fun showMessage(@PluralsRes msgId: Int, numItems: Int) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package ac.mdiq.podcini.ui.actions.actionbutton

import android.content.Context
import android.view.View
import ac.mdiq.podcini.R
import ac.mdiq.podcini.storage.database.Episodes.deleteMediaOfEpisode
import ac.mdiq.podcini.storage.model.Episode
import ac.mdiq.podcini.ui.utils.LocalDeleteModal.showLocalFeedDeleteWarningIfNecessary
import ac.mdiq.podcini.ui.utils.LocalDeleteModal.deleteEpisodesWarnLocal
import android.content.Context
import android.view.View
import androidx.media3.common.util.UnstableApi

class DeleteActionButton(item: Episode) : EpisodeActionButton(item) {
Expand All @@ -16,7 +15,7 @@ class DeleteActionButton(item: Episode) : EpisodeActionButton(item) {
return R.drawable.ic_delete
}
@UnstableApi override fun onClick(context: Context) {
showLocalFeedDeleteWarningIfNecessary(context, listOf(item)) { deleteMediaOfEpisode(context, item) }
deleteEpisodesWarnLocal(context, listOf(item))
}

override val visibility: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ class TTSActionButton(item: Episode) : EpisodeActionButton(item) {
Logd(TAG, "saving TTS to file $mFilename")
val media = EpisodeMedia(item, null, 0, "audio/*")
media.fileUrl = mFilename
media.downloaded = true
// media.downloaded = true
media.setIsDownloaded()
item.media = media
// DBWriter.persistFeedMedia(media)
item.setTranscriptIfLonger(readerText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ object EpisodeMenuHandler {
when (menuItemId) {
R.id.skip_episode_item -> context.sendBroadcast(MediaButtonReceiver.createIntent(context, KeyEvent.KEYCODE_MEDIA_NEXT))
R.id.remove_item -> {
LocalDeleteModal.showLocalFeedDeleteWarningIfNecessary(context, listOf(selectedItem)) {
if (selectedItem.media != null) deleteMediaOfEpisode(context, selectedItem)
}
LocalDeleteModal.deleteEpisodesWarnLocal(context, listOf(selectedItem))
}
R.id.mark_read_item -> {
selectedItem.setPlayed(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package ac.mdiq.podcini.ui.actions.swipeactions

import android.content.Context
import androidx.fragment.app.Fragment
import androidx.media3.common.util.UnstableApi
import ac.mdiq.podcini.R
import ac.mdiq.podcini.storage.database.Episodes.deleteMediaOfEpisode
import ac.mdiq.podcini.storage.model.Episode
import ac.mdiq.podcini.storage.model.EpisodeFilter
import ac.mdiq.podcini.ui.utils.LocalDeleteModal.showLocalFeedDeleteWarningIfNecessary
import ac.mdiq.podcini.ui.utils.LocalDeleteModal.deleteEpisodesWarnLocal
import android.content.Context
import androidx.fragment.app.Fragment
import androidx.media3.common.util.UnstableApi

class DeleteSwipeAction : SwipeAction {
override fun getId(): String {
Expand All @@ -29,9 +28,7 @@ class DeleteSwipeAction : SwipeAction {
@UnstableApi override fun performAction(item: Episode, fragment: Fragment, filter: EpisodeFilter) {
if (!item.isDownloaded && item.feed?.isLocalFeed != true) return

showLocalFeedDeleteWarningIfNecessary(fragment.requireContext(), listOf(item)) {
deleteMediaOfEpisode(fragment.requireContext(), item)
}
deleteEpisodesWarnLocal(fragment.requireContext(), listOf(item))
}

override fun willRemove(filter: EpisodeFilter, item: Episode): Boolean {
Expand Down
Loading

0 comments on commit 0f99aa2

Please sign in to comment.