add history actions

This commit is contained in:
Ida Delphine authored and Aayush Gupta committed 2026-10-27 18:26:48 +08:00
1 parent 50d490b782
commit 12e7ddc1bc
4 files changed
+107

No files matched your search

@@ -0,0 +1,45 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package net.newpipe.app.platform
import android.content.Context
import co.touchlab.kermit.Logger
import org.koin.core.annotation.Singleton
/**
* Forwards every history action to a bridge supplied by the host app.
*/
@Singleton(binds = [HistoryActions::class])
class AndroidHistoryActions(context: Context) : HistoryActions {
private val host: HistoryActions = loadHost(context)
override fun wipeMetadataCache() = host.wipeMetadataCache()
override suspend fun clearWatchHistory() = host.clearWatchHistory()
override suspend fun clearPlaybackStates() = host.clearPlaybackStates()
override suspend fun clearSearchHistory() = host.clearSearchHistory()
override fun clearRecaptchaCookies() = host.clearRecaptchaCookies()
private fun loadHost(context: Context): HistoryActions = runCatching {
Class.forName(HOST_CLASS)
.getDeclaredConstructor(Context::class.java)
.newInstance(context) as HistoryActions
}.getOrElse { error ->
Logger.w(
messageString = "No host history actions found, falling back to no-op",
throwable = error
)
NoOpHistoryActions
}
private companion object {
const val HOST_CLASS = "org.schabi.newpipe.settings.ComposeHistoryActions"
}
}
@@ -0,0 +1,40 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package net.newpipe.app.platform
import co.touchlab.kermit.Logger
/**
* Platform-specific actions triggered from the History and cache settings screen.
*/
interface HistoryActions {
fun wipeMetadataCache()
suspend fun clearWatchHistory(): Boolean
suspend fun clearPlaybackStates(): Boolean
suspend fun clearSearchHistory(): Boolean
fun clearRecaptchaCookies()
}
internal object NoOpHistoryActions : HistoryActions {
override fun wipeMetadataCache() = logUnsupported("wipeMetadataCache")
override suspend fun clearWatchHistory() = logUnsupportedAndFail("clearWatchHistory")
override suspend fun clearPlaybackStates() = logUnsupportedAndFail("clearPlaybackStates")
override suspend fun clearSearchHistory() = logUnsupportedAndFail("clearSearchHistory")
override fun clearRecaptchaCookies() = logUnsupported("clearRecaptchaCookies")
private fun logUnsupported(action: String) = Logger.w(messageString = "History action '$action' is unsupported on this platform")
private fun logUnsupportedAndFail(action: String): Boolean {
logUnsupported(action)
return false
}
}
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package net.newpipe.app.platform
import org.koin.core.annotation.Singleton
@Singleton(binds = [HistoryActions::class])
class IOSHistoryActions : HistoryActions by NoOpHistoryActions
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package net.newpipe.app.platform
import org.koin.core.annotation.Singleton
@Singleton(binds = [HistoryActions::class])
class JVMHistoryActions : HistoryActions by NoOpHistoryActions