Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
- `Other` - for technical stuff.

## [Unreleased]
### Added
- Added two-way sync for enhanced trackers ([@Secozzi](https://github.com/Secozzi)) ([#137](https://github.com/quickdesh/Animiru/pull/137))

## [v0.19.4.1] - 2026-03-15
### Improved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package eu.kanade.domain.track.interactor

import eu.kanade.domain.track.model.toDbTrack
import eu.kanade.domain.track.model.toDomainTrack
import eu.kanade.tachiyomi.data.track.EnhancedTracker
import eu.kanade.tachiyomi.data.track.Tracker
import eu.kanade.tachiyomi.data.track.TrackerManager
import kotlinx.coroutines.async
Expand All @@ -22,11 +23,19 @@ class RefreshTracks(
*
* @return Failed updates.
*/
suspend fun await(animeId: Long): List<Pair<Tracker?, Throwable>> {
suspend fun await(
animeId: Long,
// AM -->
enhancedOnly: Boolean = false,
// <-- AM
): List<Pair<Tracker?, Throwable>> {
return supervisorScope {
return@supervisorScope getTracks.await(animeId)
.map { it to trackerManager.get(it.trackerId) }
.filter { (_, service) -> service?.isLoggedIn == true }
// AM -->
.filter { (_, service) -> !enhancedOnly || service is EnhancedTracker }
// <-- AM
.map { (track, service) ->
async {
return@async try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class TrackPreferences(
)
// <-- AY

// AM -->
fun syncEnhancedTrackers() = preferenceStore.getBoolean("sync_enhanced_trackers", true)
// <-- AM

fun autoUpdateTrackOnMarkSeen() = preferenceStore.getEnum(
"pref_auto_update_anime_on_mark_seen",
AutoTrackState.ALWAYS,
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/eu/kanade/presentation/anime/AnimeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@ private fun AnimeScreenSmallImpl(
trackingCount = state.trackingCount,
nextUpdate = nextUpdate,
isUserIntervalMode = state.anime.fetchInterval < 0,
// AM -->
isSyncingTrackers = state.isSyncingTrackers,
// <-- AM
onAddToLibraryClicked = onAddToLibraryClicked,
onWebViewClicked = onWebViewClicked,
onWebViewLongClicked = onWebViewLongClicked,
Expand Down Expand Up @@ -916,6 +919,9 @@ fun AnimeScreenLargeImpl(
trackingCount = state.trackingCount,
nextUpdate = nextUpdate,
isUserIntervalMode = state.anime.fetchInterval < 0,
// AM -->
isSyncingTrackers = state.isSyncingTrackers,
// <-- AM
onAddToLibraryClicked = onAddToLibraryClicked,
onWebViewClicked = onWebViewClicked,
onWebViewLongClicked = onWebViewLongClicked,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import androidx.compose.material.icons.outlined.Pause
import androidx.compose.material.icons.outlined.Public
import androidx.compose.material.icons.outlined.Schedule
import androidx.compose.material.icons.outlined.Sync
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.LocalContentColor
Expand Down Expand Up @@ -180,6 +181,9 @@ fun AnimeActionRow(
trackingCount: Int,
nextUpdate: Instant?,
isUserIntervalMode: Boolean,
// AM -->
isSyncingTrackers: Boolean,
// <-- AM
onAddToLibraryClicked: () -> Unit,
onWebViewClicked: (() -> Unit)?,
onWebViewLongClicked: (() -> Unit)?,
Expand Down Expand Up @@ -231,16 +235,31 @@ fun AnimeActionRow(
// AY -->
if (onTrackingClicked != null) {
// <-- AY
AnimeActionButton(
title = if (trackingCount == 0) {
stringResource(MR.strings.manga_tracking_tab)
} else {
pluralStringResource(MR.plurals.num_trackers, count = trackingCount, trackingCount)
},
icon = if (trackingCount == 0) Icons.Outlined.Sync else Icons.Outlined.Done,
color = if (trackingCount == 0) defaultActionButtonColor else MaterialTheme.colorScheme.primary,
onClick = onTrackingClicked,
)
if (isSyncingTrackers) {
// AM -->
AnimeActionButton(
title = stringResource(MR.strings.loading),
color = MaterialTheme.colorScheme.primary,
onClick = onTrackingClicked,
) {
CircularProgressIndicator(
modifier = Modifier.size(20.dp),
strokeWidth = 3.dp,
)
}
// <-- AM
} else {
AnimeActionButton(
title = if (trackingCount == 0) {
stringResource(MR.strings.manga_tracking_tab)
} else {
pluralStringResource(MR.plurals.num_trackers, count = trackingCount, trackingCount)
},
icon = if (trackingCount == 0) Icons.Outlined.Sync else Icons.Outlined.Done,
color = if (trackingCount == 0) defaultActionButtonColor else MaterialTheme.colorScheme.primary,
onClick = onTrackingClicked,
)
}
}
if (onWebViewClicked != null) {
AnimeActionButton(
Expand Down Expand Up @@ -726,26 +745,46 @@ private fun TagsChip(
}
}

// AM -->
@Composable
private fun RowScope.AnimeActionButton(
title: String,
icon: ImageVector,
color: Color,
onClick: () -> Unit,
onLongClick: (() -> Unit)? = null,
) {
AnimeActionButton(
title = title,
color = color,
onClick = onClick,
onLongClick = onLongClick,
) {
Icon(
imageVector = icon,
contentDescription = null,
tint = color,
modifier = Modifier.size(20.dp),
)
}
}
// <-- AM

@Composable
private fun RowScope.AnimeActionButton(
title: String,
color: Color,
onClick: () -> Unit,
onLongClick: (() -> Unit)? = null,
content: @Composable ColumnScope.() -> Unit,
) {
TextButton(
onClick = onClick,
modifier = Modifier.weight(1f),
onLongClick = onLongClick,
) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Icon(
imageVector = icon,
contentDescription = null,
tint = color,
modifier = Modifier.size(20.dp),
)
content()
Spacer(Modifier.height(4.dp))
Text(
text = title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ object SettingsTrackingScreen : SearchableSettings {
title = stringResource(AYMR.strings.pref_show_next_episode_airing_time),
),
// <-- AY
// AM -->
Preference.PreferenceItem.SwitchPreference(
preference = trackPreferences.syncEnhancedTrackers(),
title = stringResource(AMMR.strings.pref_tracking_sync_enhanced),
),
// <-- AM
Preference.PreferenceItem.ListPreference(
preference = trackPreferences.autoUpdateTrackOnMarkSeen(),
entries = AutoTrackState.entries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ class AnimeScreenModel(
// Fetch info-episodes when needed
if (screenModelScope.isActive) {
val fetchFromSourceTasks = listOf(
// AM -->
async { syncTrackers() },
// <-- AM
async { if (needRefreshInfo) fetchAnimeFromSource() },
async {
// AY -->
Expand All @@ -353,6 +356,9 @@ class AnimeScreenModel(
screenModelScope.launch {
updateSuccessState { it.copy(isRefreshingData = true) }
val fetchFromSourceTasks = listOf(
// AM -->
async { syncTrackers() },
// <-- AM
async { fetchAnimeFromSource(manualFetch) },
async { fetchEpisodesAndSeasonsFromSource(manualFetch) },
)
Expand All @@ -364,6 +370,15 @@ class AnimeScreenModel(
}
}

// AM -->
private suspend fun syncTrackers() {
if (!trackPreferences.syncEnhancedTrackers().get()) return
updateSuccessState { it.copy(isSyncingTrackers = true) }
refreshTrackers(enhancedOnly = true)
updateSuccessState { it.copy(isSyncingTrackers = false) }
}
// <-- AM

// Anime info - start

/**
Expand Down Expand Up @@ -1086,8 +1101,11 @@ class AnimeScreenModel(

private suspend fun refreshTrackers(
refreshTracks: RefreshTracks = Injekt.get(),
// AM -->
enhancedOnly: Boolean = false,
// <-- AM
) {
refreshTracks.await(animeId)
refreshTracks.await(animeId, enhancedOnly)
.filter { it.first != null }
.forEach { (track, e) ->
logcat(LogPriority.ERROR, e) {
Expand Down Expand Up @@ -1811,6 +1829,9 @@ class AnimeScreenModel(
val excludedScanlators: Set<String>,
val trackingCount: Int = 0,
val hasLoggedInTrackers: Boolean = false,
// AM -->
val isSyncingTrackers: Boolean = false,
// <-- AM
val isRefreshingData: Boolean = false,
val dialog: Dialog? = null,
val hasPromptedToAddBefore: Boolean = false,
Expand Down
3 changes: 3 additions & 0 deletions i18n-animiru/src/commonMain/moko-resources/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,7 @@
<string name="player_sheets_deband_threshold">Threshold</string>
<string name="player_sheets_deband_range">Range</string>
<string name="player_sheets_deband_grain">Grain</string>

<!-- Tracking -->
<string name="pref_tracking_sync_enhanced">Sync progress from enhanced trackers</string>
</resources>
Loading