Skip to content

Commit

Permalink
6.7.0 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Sep 17, 2024
1 parent 338788a commit 692426d
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 109 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 3020252
versionName "6.6.7"
versionCode 3020253
versionName "6.7.0"

applicationId "ac.mdiq.podcini.R"
def commit = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package ac.mdiq.podcini.net.download.service
import ac.mdiq.podcini.net.utils.UrlChecker.prepareUrl
import ac.mdiq.podcini.storage.model.Feed
import ac.mdiq.podcini.storage.model.EpisodeMedia
import ac.mdiq.podcini.util.Logd
import ac.mdiq.podcini.util.showStackTrace
import android.os.Bundle
import android.os.Parcel
import android.os.Parcelable
Expand Down Expand Up @@ -120,6 +122,8 @@ class DownloadRequest private constructor(
}

fun setLastModified(lastModified: String?): DownloadRequest {
Logd("DownloadRequest", "setLastModified: $lastModified")
// showStackTrace()
this.lastModified = lastModified
return this
}
Expand All @@ -143,7 +147,6 @@ class DownloadRequest private constructor(
this.feedfileId = media.id
this.feedfileType = media.getTypeAsInt()
}

constructor(destination: String, feed: Feed) {
this.destination = destination
this.source = when {
Expand All @@ -156,27 +159,22 @@ class DownloadRequest private constructor(
this.feedfileType = feed.getTypeAsInt()
arguments.putInt(REQUEST_ARG_PAGE_NR, feed.pageNr)
}

fun withInitiatedByUser(initiatedByUser: Boolean): Builder {
this.initiatedByUser = initiatedByUser
return this
}

fun setForce(force: Boolean) {
if (force) lastModified = null
}

fun lastModified(lastModified: String?): Builder {
this.lastModified = lastModified
return this
}

fun withAuthentication(username: String?, password: String?): Builder {
this.username = username
this.password = password
return this
}

fun build(): DownloadRequest {
return DownloadRequest(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ class DownloadServiceInterfaceImpl : DownloadServiceInterface() {
}
progressUpdaterThread.start()
var result: Result
try {
result = performDownload(media, request)
try { result = performDownload(media, request)
} catch (e: Exception) {
e.printStackTrace()
result = Result.failure()
Expand Down Expand Up @@ -170,32 +169,23 @@ class DownloadServiceInterfaceImpl : DownloadServiceInterface() {
}
val dest = File(request.destination)
if (!dest.exists()) {
try {
dest.createNewFile()
} catch (e: IOException) {
Log.e(TAG, "performDownload Unable to create file")
}
try { dest.createNewFile() } catch (e: IOException) { Log.e(TAG, "performDownload Unable to create file") }
}
if (dest.exists()) {
try {
var episode = realm.query(Episode::class).query("id == ${media.id}").first().find()
if (episode != null) {
episode = upsertBlk(episode) {
it.media?.setfileUrlOrNull(request.destination)
}
episode = upsertBlk(episode) { it.media?.setfileUrlOrNull(request.destination) }
EventFlow.postEvent(FlowEvent.EpisodeMediaEvent.updated(episode))
} else Log.e(TAG, "performDownload media.episode is null")
} catch (e: Exception) {
Log.e(TAG, "performDownload Exception in writeFileUrl: " + e.message)
}
} catch (e: Exception) { Log.e(TAG, "performDownload Exception in writeFileUrl: " + e.message) }
}
downloader = DefaultDownloaderFactory().create(request)
if (downloader == null) {
Log.e(TAG, "performDownload Unable to create downloader")
return Result.failure()
}
try {
downloader!!.call()
try { downloader!!.call()
} catch (e: Exception) {
Log.e(TAG, "failed performDownload exception on downloader!!.call() ${e.message}")
LogsAndStats.addDownloadStatus(downloader!!.result)
Expand Down Expand Up @@ -328,8 +318,7 @@ class DownloadServiceInterfaceImpl : DownloadServiceInterface() {
durationStr = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
if (durationStr != null) it.media?.setDuration(durationStr!!.toInt())
}
} catch (e: NumberFormatException) {
Logd(TAG, "Invalid file duration: $durationStr")
} catch (e: NumberFormatException) { Logd(TAG, "Invalid file duration: $durationStr")
} catch (e: Exception) {
Log.e(TAG, "Get duration failed", e)
it.media?.setDuration(30000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ class HttpDownloader(request: DownloadRequest) : Downloader(request) {
@Throws(IOException::class)
private fun newCall(httpReq: Request.Builder): Response {
var httpClient = getHttpClient()
try {
return httpClient.newCall(httpReq.build()).execute()
try { return httpClient.newCall(httpReq.build()).execute()
} catch (e: IOException) {
Log.e(TAG, e.toString())
if (e.message != null && e.message!!.contains("PROTOCOL_ERROR")) {
Expand Down
26 changes: 13 additions & 13 deletions app/src/main/kotlin/ac/mdiq/podcini/net/feed/FeedUpdateManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,25 @@ object FeedUpdateManager {
@UnstableApi
override fun doWork(): Result {
ClientConfigurator.initialize(applicationContext)
val toUpdate: MutableList<Feed>
val feedsToUpdate: MutableList<Feed>
val feedId = inputData.getLong(EXTRA_FEED_ID, -1L)
var allAreLocal = true
var force = false
if (feedId == -1L) { // Update all
toUpdate = Feeds.getFeedList().toMutableList()
val itr = toUpdate.iterator()
feedsToUpdate = Feeds.getFeedList().toMutableList()
val itr = feedsToUpdate.iterator()
while (itr.hasNext()) {
val feed = itr.next()
if (feed.preferences?.keepUpdated == false) itr.remove()
if (!feed.isLocalFeed) allAreLocal = false
}
toUpdate.shuffle() // If the worker gets cancelled early, every feed has a chance to be updated
feedsToUpdate.shuffle() // If the worker gets cancelled early, every feed has a chance to be updated
} else {
val feed = Feeds.getFeed(feedId) ?: return Result.success()
Logd(TAG, "doWork feed.downloadUrl: ${feed.downloadUrl}")
if (!feed.isLocalFeed) allAreLocal = false
toUpdate = ArrayList()
toUpdate.add(feed) // Needs to be updatable, so no singletonList
feedsToUpdate = mutableListOf(feed)
// feedsToUpdate.add(feed) // Needs to be updatable, so no singletonList
force = true
}
if (!inputData.getBoolean(EXTRA_EVEN_ON_MOBILE, false) && !allAreLocal) {
Expand All @@ -175,10 +175,10 @@ object FeedUpdateManager {
return Result.retry()
}
}
refreshFeeds(toUpdate, force)
refreshFeeds(feedsToUpdate, force)
notificationManager.cancel(R.id.notification_updating_feeds)
autodownloadEpisodeMedia(applicationContext, toUpdate.toList())
toUpdate.clear()
autodownloadEpisodeMedia(applicationContext, feedsToUpdate.toList())
feedsToUpdate.clear()
return Result.success()
}
private fun createNotification(toUpdate: List<Feed?>?): Notification {
Expand All @@ -203,7 +203,7 @@ object FeedUpdateManager {
return Futures.immediateFuture(ForegroundInfo(R.id.notification_updating_feeds, createNotification(null)))
}
@UnstableApi
private fun refreshFeeds(toUpdate: MutableList<Feed>, force: Boolean) {
private fun refreshFeeds(feedsToUpdate: MutableList<Feed>, force: Boolean) {
if (Build.VERSION.SDK_INT >= 33 && ActivityCompat.checkSelfPermission(this.applicationContext,
Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
Expand All @@ -219,10 +219,10 @@ object FeedUpdateManager {
return
}
var i = 0
while (i < toUpdate.size) {
while (i < feedsToUpdate.size) {
if (isStopped) return
notificationManager.notify(R.id.notification_updating_feeds, createNotification(toUpdate))
val feed = unmanaged(toUpdate[i++])
notificationManager.notify(R.id.notification_updating_feeds, createNotification(feedsToUpdate))
val feed = unmanaged(feedsToUpdate[i++])
try {
Logd(TAG, "updating local feed? ${feed.isLocalFeed} ${feed.title}")
when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2097,15 +2097,8 @@ class PlaybackService : MediaLibraryService() {
private var positionSaverFuture: ScheduledFuture<*>? = null
private var widgetUpdaterFuture: ScheduledFuture<*>? = null
private var sleepTimerFuture: ScheduledFuture<*>? = null

// @Volatile
// private var chapterLoaderFuture: Disposable? = null

private var sleepTimer: SleepTimer? = null

/**
* Returns true if the sleep timer is currently active.
*/
@get:Synchronized
val isSleepTimerActive: Boolean
get() = sleepTimerFuture?.isCancelled == false && sleepTimerFuture?.isDone == false && (sleepTimer?.getWaitingTime() ?: 0) > 0
Expand All @@ -2124,16 +2117,10 @@ class PlaybackService : MediaLibraryService() {
val isWidgetUpdaterActive: Boolean
get() = widgetUpdaterFuture != null && !widgetUpdaterFuture!!.isCancelled && !widgetUpdaterFuture!!.isDone

/**
* Returns true if the position saver is currently running.
*/
@get:Synchronized
val isPositionSaverActive: Boolean
get() = positionSaverFuture != null && !positionSaverFuture!!.isCancelled && !positionSaverFuture!!.isDone

/**
* Starts the position saver task. If the position saver is already active, nothing will happen.
*/
@Synchronized
fun startPositionSaver() {
if (!isPositionSaverActive) {
Expand All @@ -2145,9 +2132,6 @@ class PlaybackService : MediaLibraryService() {
} else Logd(TAG, "Call to startPositionSaver was ignored.")
}

/**
* Cancels the position saver. If the position saver is not running, nothing will happen.
*/
@Synchronized
fun cancelPositionSaver() {
if (isPositionSaverActive) {
Expand All @@ -2156,9 +2140,6 @@ class PlaybackService : MediaLibraryService() {
}
}

/**
* Starts the widget updater task. If the widget updater is already active, nothing will happen.
*/
@Synchronized
fun startWidgetUpdater() {
if (!isWidgetUpdaterActive && !schedExecutor.isShutdown) {
Expand All @@ -2184,23 +2165,18 @@ class PlaybackService : MediaLibraryService() {
* Starts a new sleep timer with the given waiting time. If another sleep timer is already active, it will be
* cancelled first.
* After waitingTime has elapsed, onSleepTimerExpired() will be called.
*
* @throws java.lang.IllegalArgumentException if waitingTime <= 0
*/
@Synchronized
fun setSleepTimer(waitingTime: Long) {
require(waitingTime > 0) { "Waiting time <= 0" }

Logd(TAG, "Setting sleep timer to $waitingTime milliseconds")
if (isSleepTimerActive) sleepTimerFuture!!.cancel(true)
sleepTimer = SleepTimer(waitingTime)
sleepTimerFuture = schedExecutor.schedule(sleepTimer, 0, TimeUnit.MILLISECONDS)
EventFlow.postEvent(FlowEvent.SleepTimerUpdatedEvent.justEnabled(waitingTime))
}

/**
* Disables the sleep timer. If the sleep timer is not active, nothing will happen.
*/
@Synchronized
fun disableSleepTimer() {
if (isSleepTimerActive) {
Expand All @@ -2209,9 +2185,6 @@ class PlaybackService : MediaLibraryService() {
}
}

/**
* Restarts the sleep timer. If the sleep timer is not active, nothing will happen.
*/
@Synchronized
fun restartSleepTimer() {
if (isSleepTimerActive) {
Expand Down Expand Up @@ -2353,8 +2326,7 @@ class PlaybackService : MediaLibraryService() {
fun onChapterLoaded(media: Playable?)
}

internal class ShakeListener(private val mContext: Context, private val mSleepTimer: SleepTimer) :
SensorEventListener {
internal class ShakeListener(private val mContext: Context, private val mSleepTimer: SleepTimer) : SensorEventListener {
private var mAccelerometer: Sensor? = null
private var mSensorMgr: SensorManager? = null

Expand Down Expand Up @@ -2389,14 +2361,10 @@ class PlaybackService : MediaLibraryService() {
}
}
override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) {}
companion object {
private val TAG: String = ShakeListener::class.simpleName ?: "Anonymous"
}
}

companion object {
private val TAG: String = TaskManager::class.simpleName ?: "Anonymous"

private const val SCHED_EX_POOL_SIZE = 2

private const val SLEEP_TIMER_UPDATE_INTERVAL = 10000L // in millisoconds
Expand Down
Loading

0 comments on commit 692426d

Please sign in to comment.