Skip to content

Commit

Permalink
fix: Open correct tab from extension update notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
jmir1 committed Jan 17, 2025
1 parent 8185e39 commit 161471d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ExtensionUpdateNotifier(
private val securityPreferences: SecurityPreferences = Injekt.get(),
) {

fun promptUpdates(names: List<String>) {
fun promptUpdates(names: List<String>, anime: Boolean = false) {
context.notify(
Notifications.ID_UPDATES_TO_EXTS,
Notifications.CHANNEL_EXTENSIONS_UPDATE,
Expand All @@ -34,7 +34,11 @@ class ExtensionUpdateNotifier(
setStyle(NotificationCompat.BigTextStyle().bigText(extNames))
}
setSmallIcon(R.drawable.ic_extension_24dp)
setContentIntent(NotificationReceiver.openExtensionsPendingActivity(context))
if (!anime) {
setContentIntent(NotificationReceiver.openExtensionsPendingActivity(context))
} else {
setContentIntent(NotificationReceiver.openAnimeExtensionsPendingActivity(context))
}
setAutoCancel(true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ internal class AnimeExtensionApi {
}

if (extensionsWithUpdate.isNotEmpty()) {
ExtensionUpdateNotifier(context).promptUpdates(extensionsWithUpdate.map { it.name })
ExtensionUpdateNotifier(context).promptUpdates(
names = extensionsWithUpdate.map { it.name },
anime = true,
)
}

return extensionsWithUpdate
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ data object BrowseTab : Tab {
navigator.push(GlobalAnimeSearchScreen())
}

private val switchToExtensionTabChannel = Channel<Unit>(1, BufferOverflow.DROP_OLDEST)
private val switchToTabNumberChannel = Channel<Int>(1, BufferOverflow.DROP_OLDEST)

fun showExtension() {
switchToExtensionTabChannel.trySend(Unit)
switchToTabNumberChannel.trySend(3) // Manga extensions: tab no. 3
}

fun showAnimeExtension() {
switchToTabNumberChannel.trySend(2) // Anime extensions: tab no. 2
}

@Composable
Expand Down Expand Up @@ -92,8 +96,8 @@ data object BrowseTab : Tab {
scrollable = true,
)
LaunchedEffect(Unit) {
switchToExtensionTabChannel.receiveAsFlow()
.collectLatest { state.scrollToPage(1) }
switchToTabNumberChannel.receiveAsFlow()
.collectLatest { state.scrollToPage(it) }
}

LaunchedEffect(Unit) {
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/eu/kanade/tachiyomi/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ object HomeScreen : Screen() {
is Tab.History -> HistoriesTab
is Tab.Browse -> {
if (it.toExtensions) {
BrowseTab.showExtension()
if (!it.anime) {
BrowseTab.showExtension()
} else {
BrowseTab.showAnimeExtension()
}
}
BrowseTab
}
Expand Down Expand Up @@ -333,7 +337,7 @@ object HomeScreen : Screen() {
data class Library(val mangaIdToOpen: Long? = null) : Tab
data object Updates : Tab
data object History : Tab
data class Browse(val toExtensions: Boolean = false) : Tab
data class Browse(val toExtensions: Boolean = false, val anime: Boolean = false) : Tab
data class More(val toDownloads: Boolean) : Tab
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ class MainActivity : BaseActivity() {
Constants.SHORTCUT_UPDATES -> HomeScreen.Tab.Updates
Constants.SHORTCUT_HISTORY -> HomeScreen.Tab.History
Constants.SHORTCUT_SOURCES -> HomeScreen.Tab.Browse(false)
Constants.SHORTCUT_ANIMEEXTENSIONS -> HomeScreen.Tab.Browse(true, true)
Constants.SHORTCUT_EXTENSIONS -> HomeScreen.Tab.Browse(true)
Constants.SHORTCUT_DOWNLOADS -> {
navigator.popUntilRoot()
Expand Down

0 comments on commit 161471d

Please sign in to comment.