mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-11-23 15:47:20 +00:00
add history actions
This commit is contained in:
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
|
||||
Reference in new issue
Block a user