Mark fully played episodes as read

This commit is contained in:
Bart De Vries 2021-04-13 22:11:12 +02:00
parent 2f389e02aa
commit b2ba953a33
3 changed files with 19 additions and 7 deletions

View File

@ -164,9 +164,22 @@ QMediaPlayer::MediaStatus AudioManager::status() const
void AudioManager::setEntry(Entry* entry)
{
if (entry != nullptr) {
// TODO: here is a good spot to check if the previous track was (nearly) finished, so it can be removed if needed
qDebug() << "Going to change source";
d->m_lockPositionSaving = true;
// First check if the previous track needs to be marked as read
// TODO: make grace time a setting in SettingsManager
if (d->m_entry) {
qDebug() << "Checking previous track";
qDebug() << "Left time" << (duration()-position());
qDebug() << "MediaStatus" << d->m_player.mediaStatus();
if (( (duration()-position()) < 15000)
|| (d->m_player.mediaStatus() == QMediaPlayer::EndOfMedia) ) {
qDebug() << "Mark as read:" << d->m_entry->title();
d->m_entry->setRead(true);
d->m_entry->enclosure()->setPlayPosition(0);
}
}
qDebug() << "Going to change source";
d->m_entry = entry;
d->m_player.setMedia(QUrl(QStringLiteral("file://")+d->m_entry->enclosure()->path()));
// save the current playing track in the settingsfile for restoring on startup
@ -324,6 +337,7 @@ void AudioManager::skipBackward()
bool AudioManager::canGoNext() const
{
// TODO: extend with streaming capability
int index = DataManager::instance().getQueue().indexOf(d->m_entry->id());
if (index >= 0) {
// check if there is a next track
@ -342,8 +356,6 @@ bool AudioManager::canGoNext() const
void AudioManager::next()
{
QMediaPlayer::State currentState = playbackState();
// TODO: needs to be more complicated; what if track has not been downloaded and streaming is not allowed; probably needs a canGoNext routine
// go to next track in playlist
int index = DataManager::instance().getQueue().indexOf(d->m_entry->id());
if (canGoNext()) {
setEntry(DataManager::instance().getEntry(DataManager::instance().getQueue()[index+1]));
@ -359,7 +371,7 @@ void AudioManager::mediaStatusChanged()
// File has reached the end and has stopped
if (d->m_player.mediaStatus() == QMediaPlayer::EndOfMedia) {
next();
}
}

View File

@ -145,7 +145,7 @@ void Enclosure::setPlayPosition(const qint64 &position)
qDebug() << "save playPosition" << position << m_entry->title();
// let's only save the play position to the database every 15 seconds
if (abs(m_playposition - m_playposition_dbsave) > 15000) {
if ((abs(m_playposition - m_playposition_dbsave) > 15000) || position == 0) {
qDebug() << "save playPosition to database" << position << m_entry->title();
QSqlQuery query;
query.prepare(QStringLiteral("UPDATE Enclosures SET playposition=:playposition WHERE id=:id AND feed=:feed"));

View File

@ -59,7 +59,7 @@ Kirigami.SwipeListItem {
Layout.fillWidth: true
elide: Text.ElideRight
font.weight: Font.Normal
opacity: 1
opacity: (entry.read) ? 0.6 : 1
}
Loader {
sourceComponent: entry.enclosure && entry.enclosure.status === Enclosure.Downloading ? downloadProgress : subtitle