Add refresh button to tracker for new profile info (#3828)

* Add refresh button to tracker for new profile info

As-is, allows a user to manually refresh their current user data from
the tracker in order to update Mihon's knowledge of remote settings
(e.g. nickname changes, AL/MB/Kitsu score types, etc.).

* Catch errors to prevent app crashing

Surfaces errors as toasts in the same way library title refreshes do.

* spotless

* [skip ci] Remove leftover debugging logs

* Fix Kitsu user attribute access

* Spotless

* Lowercase Kitsu score type on refresh

Maybe prevent needing another #3887 for this.

* Center tracker vertically name if not logged in

Looks much better than the name being stuck at the top with empty
space below it.

* Don't show Refresh button for Enhanced trackers

* [skip ci] Add changelog entry
This commit is contained in:
MajorTanya
2026-09-19 20:35:25 +02:00
committed by GitHub
parent 504ec2afae
commit 01e3f8c605
18 changed files with 199 additions and 17 deletions
@@ -9,12 +9,14 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.structuralEqualityPolicy
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import eu.kanade.presentation.more.settings.widget.EditTextPreferenceWidget
import eu.kanade.presentation.more.settings.widget.InfoWidget
@@ -26,7 +28,11 @@ import eu.kanade.presentation.more.settings.widget.SwitchPreferenceWidget
import eu.kanade.presentation.more.settings.widget.TextPreferenceWidget
import eu.kanade.presentation.more.settings.widget.TitleFontSize
import eu.kanade.presentation.more.settings.widget.TrackingPreferenceWidget
import eu.kanade.tachiyomi.data.track.RefreshResult
import eu.kanade.tachiyomi.util.system.toast
import kotlinx.coroutines.launch
import tachiyomi.core.common.i18n.stringResource
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.components.BaseSliderItem
import tachiyomi.presentation.core.util.collectAsState
@@ -169,12 +175,28 @@ internal fun PreferenceItem(
)
}
is Preference.PreferenceItem.TrackerPreference -> {
val context = LocalContext.current
LaunchedEffect(item.tracker) {
item.tracker.refreshResultFlow.collect {
when (it) {
RefreshResult.Success -> context.toast(
context.stringResource(MR.strings.refresh_tracker_success, item.tracker.name),
)
is RefreshResult.Error -> context.toast(
context.stringResource(MR.strings.refresh_tracker_error, item.tracker.name, it.msg),
)
}
}
}
val isLoggedIn by item.tracker.let { tracker ->
tracker.isLoggedInFlow.collectAsState(tracker.isLoggedIn)
}
val isRefreshing by item.tracker.isRefreshingFlow.collectAsState()
TrackingPreferenceWidget(
tracker = item.tracker,
isLoggedIn = isLoggedIn,
isRefreshing = isRefreshing,
onClick = { if (isLoggedIn) item.logout() else item.login() },
)
}
@@ -7,10 +7,13 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
@@ -19,9 +22,13 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import eu.kanade.presentation.more.settings.LocalPreferenceHighlighted
import eu.kanade.presentation.track.components.TrackLogoIcon
import eu.kanade.tachiyomi.data.track.EnhancedTracker
import eu.kanade.tachiyomi.data.track.Tracker
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import mihon.icons.materialsymbols.MaterialSymbols
import mihon.icons.materialsymbols.rounded.Done
import mihon.icons.materialsymbols.rounded.Refresh
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.i18n.stringResource
@@ -30,41 +37,75 @@ fun TrackingPreferenceWidget(
modifier: Modifier = Modifier,
tracker: Tracker,
isLoggedIn: Boolean,
isRefreshing: Boolean,
onClick: (() -> Unit)? = null,
) {
val highlighted = LocalPreferenceHighlighted.current
val scope = rememberCoroutineScope { Dispatchers.IO }
Box(modifier = Modifier.highlightBackground(highlighted)) {
Row(
modifier = modifier
.clickable(enabled = onClick != null, onClick = { onClick?.invoke() })
.fillMaxWidth()
.padding(horizontal = PrefsHorizontalPadding, vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
TrackLogoIcon(tracker)
Column(
modifier = Modifier.weight(1f),
Row(
modifier = Modifier
.clickable(
enabled = onClick != null,
onClick = { onClick?.invoke() },
)
.weight(1f),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = tracker.name,
modifier = Modifier.padding(horizontal = 16.dp),
maxLines = 1,
style = MaterialTheme.typography.titleLarge,
fontSize = TitleFontSize,
fontWeight = FontWeight.Medium,
)
val displayName = tracker.getDisplayUsername()
if (isLoggedIn && displayName.isNotBlank()) {
TrackLogoIcon(tracker)
Column(
modifier = Modifier.weight(1f),
) {
Text(
text = displayName,
text = tracker.name,
modifier = Modifier.padding(horizontal = 16.dp),
maxLines = 1,
style = MaterialTheme.typography.bodyMedium,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.titleLarge,
fontSize = TitleFontSize,
fontWeight = FontWeight.Medium,
)
val displayName = tracker.getDisplayUsername()
if (isLoggedIn && displayName.isNotBlank()) {
Text(
text = displayName,
modifier = Modifier.padding(horizontal = 16.dp),
maxLines = 1,
style = MaterialTheme.typography.bodyMedium,
overflow = TextOverflow.Ellipsis,
)
}
}
}
if (isLoggedIn) {
if (tracker !is EnhancedTracker) {
IconButton(
enabled = !isRefreshing,
onClick = {
scope.launch { tracker.refreshUser() }
},
) {
if (!isRefreshing) {
Icon(
imageVector = MaterialSymbols.Rounded.Refresh,
modifier = Modifier
.padding(4.dp)
.size(32.dp),
contentDescription = stringResource(MR.strings.refresh_tracker_profile),
)
} else {
CircularProgressIndicator(
modifier = Modifier.size(24.dp),
strokeWidth = 2.dp,
)
}
}
}
Icon(
imageVector = MaterialSymbols.Rounded.Done,
modifier = Modifier