Skip to content

Commit

Permalink
ShowsDiscoverAdapter: fix Trakt features not showing on refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Oct 11, 2024
1 parent cf7fdf3 commit 1e67fe0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Releases marked with 🧪 (or previously with the "beta" suffix) were released o
* 🔨 Consistently style more options menus.
* 🔨 Episodes: can use watched button also after dismissing the popup menu.
* 🔨 Consistently show tooltips for actions.
* 🔨 Discover: after (dis)connecting Trakt, Trakt features get hidden/shown on refresh.
* 📝 Latest user interface translations from Crowdin.

### 2024.4.3 - 2024-09-13 🧪
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import com.battlelancer.seriesguide.R
import com.battlelancer.seriesguide.databinding.ItemDiscoverEmptyBinding
import com.battlelancer.seriesguide.databinding.ItemDiscoverHeaderBinding
import com.battlelancer.seriesguide.databinding.ItemDiscoverLinkBinding
import com.battlelancer.seriesguide.traktapi.TraktCredentials
import com.battlelancer.seriesguide.ui.AutoGridLayoutManager
import com.battlelancer.seriesguide.util.ViewTools

Expand Down Expand Up @@ -50,32 +49,35 @@ class ShowsDiscoverAdapter(
}
}

init {
links.add(DiscoverShowsLink.POPULAR)
if (TraktCredentials.get(context).hasCredentials()) {
links.add(DiscoverShowsLink.WATCHED)
links.add(DiscoverShowsLink.COLLECTION)
links.add(DiscoverShowsLink.WATCHLIST)
}
}

@SuppressLint("NotifyDataSetChanged") // No need for incremental updates/animations.
fun updateSearchResults(
newSearchResults: List<SearchResult>?,
emptyText: String,
hasError: Boolean,
showWatchlistActions: Boolean
enableTraktFeatures: Boolean
) {
searchResults.clear()
if (newSearchResults != null) {
searchResults.addAll(newSearchResults)
}
this.emptyText = emptyText
this.hasError = hasError
this.showWatchlistActions = showWatchlistActions
this.showWatchlistActions = enableTraktFeatures
updateLinks(enableTraktFeatures)
notifyDataSetChanged()
}

private fun updateLinks(enableTraktFeatures: Boolean) {
val links = mutableListOf(DiscoverShowsLink.POPULAR)
if (enableTraktFeatures) {
links.add(DiscoverShowsLink.WATCHED)
links.add(DiscoverShowsLink.COLLECTION)
links.add(DiscoverShowsLink.WATCHLIST)
}
this.links.clear()
this.links.addAll(links)
}

@SuppressLint("NotifyDataSetChanged") // Too much work to track changed positions.
fun setStateForTmdbId(showTmdbId: Int, state: Int) {
// multiple items may have the same TMDB id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ShowsDiscoverFragment : BaseAddShowsFragment() {
it.searchResults,
it.emptyText,
hasError = !it.successful,
showWatchlistActions = TraktCredentials.get(requireContext()).hasCredentials()
enableTraktFeatures = TraktCredentials.get(requireContext()).hasCredentials()
)
}
}
Expand Down

0 comments on commit 1e67fe0

Please sign in to comment.