Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: ac3722bf830b8d24ba6123ca5646b837de017eb7
  • Loading branch information
Madari Developers committed Jan 8, 2025
1 parent 43e8460 commit 2473e0f
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 254 deletions.
13 changes: 10 additions & 3 deletions lib/features/connections/types/stremio/stremio_base.types.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:collection/collection.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:pocketbase/pocketbase.dart';

Expand Down Expand Up @@ -324,9 +325,15 @@ class Meta extends LibraryItem {
}

Video? get currentVideo {
return videos?.firstWhere((episode) {
return nextEpisode == episode.episode && nextSeason == episode.season;
});
if (type == "movie") {
return null;
}

return videos?.firstWhereOrNull(
(episode) {
return nextEpisode == episode.episode && nextSeason == episode.season;
},
);
}

Meta({
Expand Down
31 changes: 26 additions & 5 deletions lib/features/connections/widget/stremio/stremio_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,31 @@ class StremioCard extends StatelessWidget {
child: (backgroundImage == null)
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(meta.name ?? "No name"),
if (meta.description != null) Text(meta.description!),
const Expanded(
child: Center(
child: Icon(
Icons.image_not_supported,
size: 26,
),
),
),
Container(
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
meta.name ?? "No name",
style:
Theme.of(context).textTheme.labelMedium?.copyWith(
color: Colors.black54,
fontWeight: FontWeight.w600,
),
),
),
),
],
),
)
Expand Down Expand Up @@ -331,7 +351,8 @@ class StremioCard extends StatelessWidget {
left: 0,
right: 0,
child: LinearProgressIndicator(
value: meta.progress,
value: meta.progress! / 100,
minHeight: 5,
),
),
if (meta.nextEpisode != null && meta.nextSeason != null)
Expand Down
10 changes: 6 additions & 4 deletions lib/features/doc_viewer/container/video_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,12 @@ class _VideoViewerState extends State<VideoViewer> {
});

final oneMore = player.stream.completed.listen((item) {
TraktService.instance!.stopScrobbling(
meta: widget.meta as types.Meta,
progress: currentProgressInPercentage,
);
if (item && player.state.duration.inSeconds > 10) {
TraktService.instance!.stopScrobbling(
meta: widget.meta as types.Meta,
progress: currentProgressInPercentage,
);
}
});

listener.add(streams);
Expand Down
222 changes: 108 additions & 114 deletions lib/features/trakt/containers/up_next.container.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:cached_query_flutter/cached_query_flutter.dart';
import 'package:flutter/material.dart';
import 'package:madari_client/features/connections/service/base_connection_service.dart';
import 'package:madari_client/features/trakt/service/trakt.service.dart';

import '../../connections/widget/base/render_library_list.dart';
import '../../settings/screen/trakt_integration_screen.dart';
import '../service/trakt_cache.service.dart';

class TraktContainer extends StatefulWidget {
final String loadId;
Expand All @@ -14,43 +14,45 @@ class TraktContainer extends StatefulWidget {
});

@override
State<TraktContainer> createState() => _TraktContainerState();
State<TraktContainer> createState() => TraktContainerState();
}

class _TraktContainerState extends State<TraktContainer> {
late Query<List<LibraryItem>> _query;
class TraktContainerState extends State<TraktContainer> {
late final TraktCacheService _cacheService;
List<LibraryItem>? _cachedItems;
bool _isLoading = false;
String? _error;

@override
void initState() {
super.initState();
_cacheService = TraktCacheService();
_loadData();
}

_query = Query(
key: widget.loadId,
config: QueryConfig(
cacheDuration: const Duration(days: 30),
refetchDuration: const Duration(minutes: 10),
storageDuration: const Duration(days: 30),
),
queryFn: () {
switch (widget.loadId) {
case "up_next":
case "up_next_series":
return TraktService.instance!.getUpNextSeries();
case "continue_watching":
return TraktService.instance!.getContinueWatching();
case "upcoming_schedule":
return TraktService.instance!.getUpcomingSchedule();
case "watchlist":
return TraktService.instance!.getWatchlist();
case "show_recommendations":
return TraktService.instance!.getShowRecommendations();
case "movie_recommendations":
return TraktService.instance!.getMovieRecommendations();
default:
throw Exception("Invalid loadId: ${widget.loadId}");
}
},
);
Future<void> _loadData() async {
setState(() {
_isLoading = true;
_error = null;
});

try {
final items = await _cacheService.fetchData(widget.loadId);
setState(() {
_cachedItems = items;
_isLoading = false;
});
} catch (e) {
setState(() {
_error = e.toString();
_isLoading = false;
});
}
}

Future<void> refresh() async {
await _cacheService.refresh(widget.loadId);
await _loadData();
}

String get title {
Expand All @@ -61,97 +63,89 @@ class _TraktContainerState extends State<TraktContainer> {

@override
Widget build(BuildContext context) {
return QueryBuilder(
query: _query,
builder: (context, snapshot) {
final theme = Theme.of(context);
final item = snapshot.data;
final theme = Theme.of(context);

return Container(
margin: const EdgeInsets.only(bottom: 6),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
return Container(
margin: const EdgeInsets.only(bottom: 6),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
title,
style: theme.textTheme.bodyLarge,
),
const Spacer(),
SizedBox(
height: 30,
child: TextButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return Scaffold(
appBar: AppBar(
title: Text("Trakt - $title"),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: RenderListItems(
items: item ?? [],
error: snapshot.error,
hasError:
snapshot.status == QueryStatus.error,
heroPrefix: "trakt_up_next${widget.loadId}",
service: TraktService.stremioService!,
isGrid: true,
isWide: false,
),
),
);
},
),
);
},
child: Text(
"Show more",
style: theme.textTheme.labelMedium?.copyWith(
color: Colors.white70,
),
),
),
),
],
Text(
title,
style: theme.textTheme.bodyLarge,
),
const SizedBox(
height: 8,
),
Stack(
children: [
if ((item ?? []).isEmpty &&
snapshot.status != QueryStatus.loading)
const Positioned.fill(
child: Center(
child: Text("Nothing to see here"),
const Spacer(),
SizedBox(
height: 30,
child: TextButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return Scaffold(
appBar: AppBar(
title: Text("Trakt - $title"),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: RenderListItems(
items: _cachedItems ?? [],
error: _error,
hasError: _error != null,
heroPrefix: "trakt_up_next${widget.loadId}",
service: TraktService.stremioService!,
isGrid: true,
isWide: false,
),
),
);
},
),
);
},
child: Text(
"Show more",
style: theme.textTheme.labelMedium?.copyWith(
color: Colors.white70,
),
SizedBox(
height: getListHeight(context),
child: snapshot.status == QueryStatus.loading
? SpinnerCards(
isWide: widget.loadId == "up_next_series",
)
: RenderListItems(
isWide: widget.loadId == "up_next_series",
items: item ?? [],
error: snapshot.error,
hasError: snapshot.status == QueryStatus.error,
heroPrefix: "trakt_up_next${widget.loadId}",
service: TraktService.stremioService!,
),
),
],
)
),
),
],
),
);
},
const SizedBox(
height: 8,
),
Stack(
children: [
if ((_cachedItems ?? []).isEmpty && !_isLoading)
const Positioned.fill(
child: Center(
child: Text("Nothing to see here"),
),
),
SizedBox(
height: getListHeight(context),
child: _isLoading
? SpinnerCards(
isWide: widget.loadId == "up_next_series",
)
: RenderListItems(
isWide: widget.loadId == "up_next_series",
items: _cachedItems ?? [],
error: _error,
hasError: _error != null,
heroPrefix: "trakt_up_next${widget.loadId}",
service: TraktService.stremioService!,
),
),
],
)
],
),
);
}
}
Loading

0 comments on commit 2473e0f

Please sign in to comment.