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

Show 'mark as unwatched' in video options sheet if already watched #3925

Merged
merged 1 commit into from
Jun 4, 2023
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 @@ -6,12 +6,16 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.github.libretube.db.obj.WatchHistoryItem
import com.github.libretube.db.obj.WatchPosition

@Dao
interface WatchHistoryDao {
@Query("SELECT * FROM watchHistoryItem")
suspend fun getAll(): List<WatchHistoryItem>

@Query("SELECT * FROM watchHistoryItem WHERE videoId LIKE :videoId LIMIT 1")
suspend fun findById(videoId: String): WatchHistoryItem?

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(watchHistoryItem: WatchHistoryItem)

Expand All @@ -21,6 +25,9 @@ interface WatchHistoryDao {
@Delete
suspend fun delete(watchHistoryItem: WatchHistoryItem)

@Query("DELETE FROM watchHistoryItem WHERE videoId = :id")
fun deleteByVideoId(id: String)

@Query("DELETE FROM watchHistoryItem")
suspend fun deleteAll()
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ interface WatchPositionDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(watchPositions: List<WatchPosition>)

@Query("DELETE FROM watchPosition WHERE videoId = :id")
fun deleteByVideoId(id: String)

@Query("DELETE FROM watchPosition")
suspend fun deleteAll()
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.github.libretube.ui.dialogs.ShareDialog
import com.github.libretube.ui.fragments.SubscriptionsFragment
import com.github.libretube.util.PlayingQueue
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext

/**
Expand Down Expand Up @@ -47,9 +48,17 @@ class VideoOptionsBottomSheet(
optionsList += getString(R.string.add_to_queue)
}

// show the mark as watched option if watch positions are enabled
if (PlayerHelper.watchPositionsVideo) {
optionsList += getString(R.string.mark_as_watched)
// show the mark as watched or unwatched option if watch positions are enabled
if (PlayerHelper.watchPositionsVideo || PlayerHelper.watchHistoryEnabled) {
val watchPositionEntry = runBlocking(Dispatchers.IO) {
DatabaseHolder.Database.watchPositionDao().findById(videoId)
}
val watchHistoryEntry = runBlocking(Dispatchers.IO) {
DatabaseHolder.Database.watchHistoryDao().findById(videoId)
}
optionsList += if (watchHistoryEntry != null || watchPositionEntry != null) {
getString(R.string.mark_as_unwatched)
} else getString(R.string.mark_as_watched)
}

setSimpleItems(optionsList) { which ->
Expand Down Expand Up @@ -116,6 +125,12 @@ class VideoOptionsBottomSheet(
)
}
}
getString(R.string.mark_as_unwatched) -> {
withContext(Dispatchers.IO) {
DatabaseHolder.Database.watchPositionDao().deleteByVideoId(videoId)
DatabaseHolder.Database.watchHistoryDao().deleteByVideoId(videoId)
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@
<string name="creation_date_reversed">Creation date (reversed)</string>
<string name="alphabetic">Alphabetic</string>
<string name="alphabetic_reversed">Alphabetic (reversed)</string>
<string name="mark_as_unwatched">Mark as unwatched</string>

<!-- Backup & Restore Settings -->
<string name="import_subscriptions_from">Import subscriptions from</string>
Expand Down