Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak the download page (add library size and play episode) #1235

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Podcast(
@JsonIgnore
fun addEpisode(audioTrack:AudioTrack, episode:PodcastEpisode):PodcastEpisode {
val localEpisodeId = "local_ep_" + episode.id
val newEpisode = PodcastEpisode(localEpisodeId,(episodes?.size ?: 0) + 1,episode.episode,episode.episodeType,episode.title,episode.subtitle,episode.description,null,null,null,audioTrack,episode.chapters,audioTrack.duration,0, episode.id, localEpisodeId)
val newEpisode = PodcastEpisode(localEpisodeId,(episodes?.size ?: 0) + 1,episode.episode,episode.episodeType,episode.title,episode.subtitle,episode.description,null,null,null,audioTrack,episode.chapters,audioTrack.duration,episode.size, episode.id, localEpisodeId)
episodes?.add(newEpisode)

var index = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class FolderScanner(var ctx: Context) {
)
localLibraryItem.localFiles.add(localFile)

val trackFileMetadata = FileMetadata(file.name, file.extension, file.absolutePath, file.getBasePath(ctx), file.length())
// Create new audio track
val track = AudioTrack(
audioTrackFromServer.index,
Expand All @@ -78,7 +79,7 @@ class FolderScanner(var ctx: Context) {
localFile.filename ?: "",
localFile.contentUrl,
localFile.mimeType ?: "",
null,
trackFileMetadata,
true,
localFileId,
null,
Expand Down Expand Up @@ -274,7 +275,8 @@ class FolderScanner(var ctx: Context) {
localLibraryItem.localFiles.add(localFile)

// Create new audio track
val track = AudioTrack(audioTrackFromServer.index, audioTrackFromServer.startOffset, audioTrackFromServer.duration, localFile.filename ?: "", localFile.contentUrl, localFile.mimeType ?: "", null, true, localFileId, null, audioTrackFromServer.index)
val trackFileMetadata = FileMetadata(docFile.name ?: "", docFile.extension ?: "", docFile.getAbsolutePath(ctx), docFile.getBasePath(ctx), docFile.length())
val track = AudioTrack(audioTrackFromServer.index, audioTrackFromServer.startOffset, audioTrackFromServer.duration, localFile.filename ?: "", localFile.contentUrl, localFile.mimeType ?: "", trackFileMetadata, true, localFileId, null, audioTrackFromServer.index)
audioTracks.add(track)

Log.d(tag, "scanDownloadItem: Created Audio Track with index ${track.index} from local file ${localFile.absolutePath}")
Expand Down
3 changes: 3 additions & 0 deletions pages/downloads.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
</div>
</template>
</div>
<div v-if="localLibraryItems.length" class="mt-4 text-sm text-fg-muted">
{{ $strings.LabelTotalSize }}: {{ $bytesPretty(localLibraryItems.reduce((acc, item) => acc + item.size, 0)) }}
</div>
</div>
</template>

Expand Down
94 changes: 73 additions & 21 deletions pages/localMedia/item/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

<div class="w-full max-w-full media-item-container overflow-y-auto overflow-x-hidden relative pb-4" :class="{ 'media-order-changed': orderChanged }">
<div v-if="!isPodcast && audioTracksCopy.length" class="w-full py-2">
<p class="text-base mb-2">Audio Tracks ({{ audioTracks.length }})</p>
<div class="flex justify-between items-center mb-2">
<p class="text-base">Audio Tracks ({{ audioTracks.length }})</p>
<p class="text-xs text-fg-muted px-2">{{ $strings.LabelTotalSize }}: {{ $bytesPretty(totalAudioSize) }}</p>
</div>

<draggable v-model="audioTracksCopy" v-bind="dragOptions" handle=".drag-handle" draggable=".item" tag="div" @start="drag = true" @end="drag = false" @update="draggableUpdate" :disabled="isIos">
<transition-group type="transition" :name="!drag ? 'dragtrack' : null">
Expand Down Expand Up @@ -46,7 +49,10 @@
</div>

<div v-if="isPodcast" class="w-full py-2">
<p class="text-base mb-2">Episodes ({{ episodes.length }})</p>
<div class="flex justify-between items-center mb-2">
<p class="text-base">Episodes ({{ episodes.length }})</p>
<p class="text-xs text-fg-muted px-2">{{ $strings.LabelTotalSize }}: {{ $bytesPretty(totalEpisodesSize) }}</p>
</div>
<template v-for="episode in episodes">
<div :key="episode.id" class="flex items-center my-1">
<div class="w-10 h-12 flex items-center justify-center" style="min-width: 48px">
Expand Down Expand Up @@ -83,22 +89,31 @@
</div>
</div>

<p v-if="otherFiles.length" class="text-lg py-2">Other Files</p>
<template v-for="file in otherFiles">
<div :key="file.id" class="flex items-center my-1">
<div class="w-12 h-12 flex items-center justify-center">
<img v-if="(file.mimeType || '').startsWith('image')" :src="getCapImageSrc(file.contentUrl)" class="w-full h-full object-contain" />
<span v-else class="material-icons">music_note</span>
</div>
<div class="flex-grow px-2">
<p class="text-sm">{{ file.filename }}</p>
</div>
<div class="w-24 text-center text-fg-muted" style="min-width: 96px">
<p class="text-xs">{{ file.mimeType }}</p>
<p class="text-sm">{{ $bytesPretty(file.size) }}</p>
</div>
<div v-if="otherFiles.length">
<div class="flex justify-between items-center py-2">
<p class="text-lg">Other Files</p>
<p class="text-xs text-fg-muted px-2">{{ $strings.LabelTotalSize }}: {{ $bytesPretty(totalOtherFilesSize) }}</p>
</div>
</template>
<template v-for="file in otherFiles">
<div :key="file.id" class="flex items-center my-1">
<div class="w-12 h-12 flex items-center justify-center">
<img v-if="(file.mimeType || '').startsWith('image')" :src="getCapImageSrc(file.contentUrl)" class="w-full h-full object-contain" />
<span v-else class="material-icons">music_note</span>
</div>
<div class="flex-grow px-2">
<p class="text-sm">{{ file.filename }}</p>
</div>
<div class="w-24 text-center text-fg-muted" style="min-width: 96px">
<p class="text-xs">{{ file.mimeType }}</p>
<p class="text-sm">{{ $bytesPretty(file.size) }}</p>
</div>
</div>
</template>
</div>

<div class="mt-4 text-sm text-fg-muted">
{{ $strings.LabelTotalSize }}: {{ $bytesPretty(totalLibraryItemSize) }}
</div>
</div>
</div>
<div v-else class="px-2 w-full h-full">
Expand Down Expand Up @@ -218,24 +233,46 @@ export default {
},
dialogItems() {
if (this.selectedAudioTrack || this.selectedEpisode) {
return [
const items = [
{
text: this.$strings.ButtonDeleteLocalFile,
value: 'track-delete'
value: 'track-delete',
icon: 'delete'
}
]
if (this.isPodcast && this.selectedEpisode) {
items.unshift({
text: this.$strings.ButtonPlayEpisode,
value: 'play-episode',
icon: 'play_arrow'
})
}
return items
} else {
return [
{
text: this.$strings.ButtonDeleteLocalItem,
value: 'delete'
value: 'delete',
icon: 'delete'
}
]
}
},
playerIsStartingPlayback() {
// Play has been pressed and waiting for native play response
return this.$store.state.playerIsStartingPlayback
},
totalAudioSize() {
return this.audioTracks.reduce((acc, item) => item.metadata ? acc + item.metadata.size : acc, 0)
},
totalEpisodesSize() {
return this.episodes.reduce((acc, item) => acc + item.size, 0)
},
totalOtherFilesSize() {
return this.otherFiles.reduce((acc, item) => acc + item.size, 0)
},
totalLibraryItemSize() {
return this.localFiles.reduce((acc, item) => acc + item.size, 0)
}
},
methods: {
Expand Down Expand Up @@ -291,6 +328,19 @@ export default {
getCapImageSrc(contentUrl) {
return Capacitor.convertFileSrc(contentUrl)
},
async playEpisode() {
if (!this.selectedEpisode) return
if (this.playerIsStartingPlayback) return
await this.$hapticsImpact()
this.$store.commit('setPlayerIsStartingPlayback', this.selectedEpisode.serverEpisodeId)

this.$eventBus.$emit('play-item', {
libraryItemId: this.localLibraryItemId,
episodeId: this.selectedEpisode.id,
serverLibraryItemId: this.libraryItemId,
serverEpisodeId: this.selectedEpisode.serverEpisodeId
})
},
async dialogAction(action) {
console.log('Dialog action', action)
await this.$hapticsImpact()
Expand All @@ -300,8 +350,10 @@ export default {
} else if (action == 'track-delete') {
if (this.isPodcast) this.deleteEpisode()
else this.deleteTrack()
} else if (action == 'play-episode') {
this.playEpisode()
}
this.showDialog = false
this.showDialog = false;
},
getLocalFileForTrack(localFileId) {
return this.localFiles.find((lf) => lf.id == localFileId)
Expand Down
2 changes: 2 additions & 0 deletions strings/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"ButtonOverride": "Override",
"ButtonPause": "Pause",
"ButtonPlay": "Play",
"ButtonPlayEpisode": "Play Episode",
"ButtonPlaying": "Playing",
"ButtonPlaylists": "Playlists",
"ButtonRead": "Read",
Expand Down Expand Up @@ -232,6 +233,7 @@
"LabelThemeLight": "Light",
"LabelTimeRemaining": "{0} remaining",
"LabelTitle": "Title",
"LabelTotalSize": "Total Size",
"LabelTotalTrack": "Total Track",
"LabelTracks": "Tracks",
"LabelType": "Type",
Expand Down
Loading