Skip to content

Commit

Permalink
Merge pull request #1210 from mfcar/mf/limitCellularData
Browse files Browse the repository at this point in the history
Add settings to limit Cellular Data (Download/Streaming)
  • Loading branch information
advplyr authored Jun 4, 2024
2 parents c7c3ef5 + b6824cf commit f91b0c9
Show file tree
Hide file tree
Showing 35 changed files with 479 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ enum class ShakeSensitivitySetting {
VERY_LOW, LOW, MEDIUM, HIGH, VERY_HIGH
}

enum class DownloadUsingCellularSetting {
ASK, ALWAYS, NEVER
}

enum class StreamingUsingCellularSetting {
ASK, ALWAYS, NEVER
}

data class ServerConnectionConfig(
var id:String,
var index:Int,
Expand Down Expand Up @@ -123,7 +131,9 @@ data class DeviceSettings(
var sleepTimerLength: Long, // Time in milliseconds
var disableSleepTimerFadeOut: Boolean,
var disableSleepTimerResetFeedback: Boolean,
var languageCode: String
var languageCode: String,
var downloadUsingCellular: DownloadUsingCellularSetting,
var streamingUsingCellular: StreamingUsingCellularSetting
) {
companion object {
// Static method to get default device settings
Expand All @@ -147,7 +157,9 @@ data class DeviceSettings(
autoSleepTimerAutoRewindTime = 300000L, // 5 minutes
disableSleepTimerFadeOut = false,
disableSleepTimerResetFeedback = false,
languageCode = "en-us"
languageCode = "en-us",
downloadUsingCellular = DownloadUsingCellularSetting.ALWAYS,
streamingUsingCellular = StreamingUsingCellularSetting.ALWAYS
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ object DeviceManager {
if (deviceData.deviceSettings?.languageCode == null) {
deviceData.deviceSettings?.languageCode = "en-us"
}

if (deviceData.deviceSettings?.downloadUsingCellular == null) {
deviceData.deviceSettings?.downloadUsingCellular = DownloadUsingCellularSetting.ALWAYS
}

if (deviceData.deviceSettings?.streamingUsingCellular == null) {
deviceData.deviceSettings?.streamingUsingCellular = StreamingUsingCellularSetting.ALWAYS
}
}

fun getBase64Id(id:String):String {
Expand Down
15 changes: 13 additions & 2 deletions components/app/AudioPlayerContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script>
import { AbsAudioPlayer } from '@/plugins/capacitor'
import { Dialog } from '@capacitor/dialog'
import CellularPermissionHelpers from '@/mixins/cellularPermissionHelpers'
export default {
data() {
Expand Down Expand Up @@ -39,6 +40,7 @@ export default {
serverEpisodeId: null
}
},
mixins: [CellularPermissionHelpers],
computed: {
bookmarks() {
if (!this.serverLibraryItemId) return []
Expand Down Expand Up @@ -193,12 +195,21 @@ export default {
const startTime = payload.startTime
const startWhenReady = !payload.paused
const isLocal = libraryItemId.startsWith('local')
if (!isLocal) {
const hasPermission = await this.checkCellularPermission('streaming')
if (!hasPermission) {
this.$store.commit('setPlayerDoneStartingPlayback')
return
}
}
// When playing local library item and can also play this item from the server
// then store the server library item id so it can be used if a cast is made
const serverLibraryItemId = payload.serverLibraryItemId || null
const serverEpisodeId = payload.serverEpisodeId || null
if (libraryItemId.startsWith('local') && this.$store.state.isCasting) {
if (isLocal && this.$store.state.isCasting) {
const { value } = await Dialog.confirm({
title: 'Warning',
message: `Cannot cast downloaded media items. Confirm to close cast and play on your device.`
Expand Down Expand Up @@ -373,4 +384,4 @@ export default {
this.$eventBus.$off('device-focus-update', this.deviceFocused)
}
}
</script>
</script>
5 changes: 5 additions & 0 deletions components/tables/podcast/EpisodeRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

<script>
import { AbsFileSystem, AbsDownloader } from '@/plugins/capacitor'
import cellularPermissionHelpers from '@/mixins/cellularPermissionHelpers'
export default {
props: {
Expand All @@ -73,6 +74,7 @@ export default {
},
isLocal: Boolean
},
mixins: [cellularPermissionHelpers],
data() {
return {
isProcessingReadUpdate: false,
Expand Down Expand Up @@ -180,6 +182,9 @@ export default {
async downloadClick() {
if (this.downloadItem || this.startingDownload) return
const hasPermission = await this.checkCellularPermission('download')
if (!hasPermission) return
this.startingDownload = true
setTimeout(() => {
this.startingDownload = false
Expand Down
13 changes: 11 additions & 2 deletions components/tables/podcast/LatestEpisodeRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

<script>
import { AbsFileSystem, AbsDownloader } from '@/plugins/capacitor'
import CellularPermissionHelpers from '@/mixins/cellularPermissionHelpers'
export default {
props: {
Expand All @@ -83,6 +84,7 @@ export default {
processing: false
}
},
mixins: [CellularPermissionHelpers],
computed: {
bookCoverAspectRatio() {
return this.$store.getters['libraries/getBookCoverAspectRatio']
Expand Down Expand Up @@ -187,6 +189,10 @@ export default {
},
async downloadClick() {
if (this.downloadItem || this.pendingDownload) return
const hasPermission = await this.checkCellularPermission('download')
if (!hasPermission) return
this.pendingDownload = true
await this.$hapticsImpact()
if (this.isIos) {
Expand Down Expand Up @@ -262,7 +268,6 @@ export default {
if (this.localEpisode && this.localLibraryItemId) {
console.log('Play local episode', this.localEpisode.id, this.localLibraryItemId)
this.$eventBus.$emit('play-item', {
libraryItemId: this.localLibraryItemId,
episodeId: this.localEpisode.id,
Expand All @@ -285,7 +290,11 @@ export default {
const isFinished = !this.userIsFinished
const localLibraryItemId = this.isLocal ? this.libraryItemId : this.localLibraryItemId
const localEpisodeId = this.isLocal ? this.episode.id : this.localEpisode.id
const payload = await this.$db.updateLocalMediaProgressFinished({ localLibraryItemId, localEpisodeId, isFinished })
const payload = await this.$db.updateLocalMediaProgressFinished({
localLibraryItemId,
localEpisodeId,
isFinished
})
console.log('toggleFinished payload', JSON.stringify(payload))
if (payload?.error) {
this.$toast.error(payload?.error || 'Unknown error')
Expand Down
9 changes: 8 additions & 1 deletion ios/App/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Override point for customization after application launch.

let configuration = Realm.Configuration(
schemaVersion: 17,
schemaVersion: 18,
migrationBlock: { [weak self] migration, oldSchemaVersion in
if (oldSchemaVersion < 1) {
self?.logger.log("Realm schema version was \(oldSchemaVersion)")
Expand Down Expand Up @@ -54,6 +54,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
newObject?["chapterTrack"] = false
}
}
if (oldSchemaVersion < 17) {
self?.logger.log("Realm schema version was \(oldSchemaVersion)... Adding downloadUsingCellular and streamingUsingCellular settings")
migration.enumerateObjects(ofType: PlayerSettings.className()) { oldObject, newObject in
newObject?["downloadUsingCellular"] = "ALWAYS"
newObject?["streamingUsingCellular"] = "ALWAYS"
}
}

}
)
Expand Down
Loading

0 comments on commit f91b0c9

Please sign in to comment.