Skip to content

Commit 8e442aa

Browse files
committed
fix: history page contents filtered by current playlist
1 parent 5ef9500 commit 8e442aa

File tree

8 files changed

+104
-89
lines changed

8 files changed

+104
-89
lines changed

lib/services/watch_history_service.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:drift/drift.dart';
22
import 'package:iptv_player/database/database.dart';
33
import 'package:iptv_player/models/content_type.dart';
44
import 'package:iptv_player/models/watch_history.dart';
5+
import 'package:iptv_player/services/app_state.dart';
56
import 'package:iptv_player/services/service_locator.dart';
67

78
class WatchHistoryService {
@@ -41,31 +42,37 @@ class WatchHistoryService {
4142
}
4243

4344
Future<List<WatchHistory>> getWatchHistoryByContentType(
44-
ContentType contentType,
45+
ContentType contentType, String playlistId
4546
) async {
4647
final query = _database.select(_database.watchHistories)
47-
..where((tbl) => tbl.contentType.equals(contentType.index))
48+
..where((tbl) => tbl.contentType.equals(contentType.index) & tbl.playlistId.equals(playlistId))
4849
..orderBy([(tbl) => OrderingTerm.desc(tbl.lastWatched)]);
4950

5051
final results = await query.get();
5152
return results.map((data) => WatchHistory.fromDrift(data)).toList();
5253
}
5354

54-
Future<List<WatchHistory>> getRecentlyWatched({int limit = 10}) async {
55+
Future<List<WatchHistory>> getRecentlyWatched(
56+
String playlistId, {
57+
int limit = 10,
58+
}) async {
5559
final query = _database.select(_database.watchHistories)
60+
..where((tbl) => tbl.playlistId.equals(playlistId))
5661
..orderBy([(tbl) => OrderingTerm.desc(tbl.lastWatched)])
5762
..limit(limit);
5863

5964
final results = await query.get();
6065
return results.map((data) => WatchHistory.fromDrift(data)).toList();
6166
}
6267

63-
Future<List<WatchHistory>> getContinueWatching() async {
68+
Future<List<WatchHistory>> getContinueWatching(String playlistId) async {
6469
final query = _database.select(_database.watchHistories)
6570
..where(
66-
(tbl) => tbl.watchDuration.isNotNull() & tbl.totalDuration.isNotNull(),
67-
// tbl.watchDuration * 10 <tbl.totalDuration * 9,
68-
) // %90'dan az
71+
(tbl) =>
72+
tbl.watchDuration.isNotNull() &
73+
tbl.totalDuration.isNotNull() &
74+
tbl.playlistId.equals(playlistId),
75+
)
6976
..orderBy([(tbl) => OrderingTerm.desc(tbl.lastWatched)]);
7077

7178
final results = await query.get();

lib/views/screens/movies/movide_screen.dart

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,12 @@ class _MovieScreenState extends State<MovieScreen> {
1919
child: Column(
2020
crossAxisAlignment: CrossAxisAlignment.stretch,
2121
children: [
22-
// PlayerWidget scroll edilebilir alandan çıkarıldı
2322
PlayerWidget(
2423
contentItem: widget.contentItem,
2524
),
26-
27-
// Expanded widget ile kalan alanı kaplıyor ve scroll edilebilir
2825
Expanded(
2926
child: SingleChildScrollView(
30-
child: Container(
31-
decoration: BoxDecoration(
32-
gradient: LinearGradient(
33-
begin: Alignment.topCenter,
34-
end: Alignment.bottomCenter,
35-
colors: [
36-
Theme.of(context).scaffoldBackgroundColor.withOpacity(0.8),
37-
Theme.of(context).scaffoldBackgroundColor,
38-
],
39-
),
40-
),
41-
child: Padding(
27+
child: Padding(
4228
padding: const EdgeInsets.all(20.0),
4329
child: Column(
4430
crossAxisAlignment: CrossAxisAlignment.start,
@@ -131,7 +117,6 @@ class _MovieScreenState extends State<MovieScreen> {
131117
),
132118
),
133119
),
134-
),
135120
],
136121
),
137122
),

lib/views/screens/series/episode_screen.dart

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
22
import 'package:iptv_player/database/database.dart';
33
import 'package:iptv_player/models/playlist_content_model.dart';
44
import 'package:iptv_player/models/watch_history.dart';
5-
import 'package:iptv_player/services/app_state.dart';
65
import 'package:iptv_player/views/widgets/player_widget.dart';
76

87
class EpisodeScreen extends StatelessWidget {
@@ -28,46 +27,28 @@ class EpisodeScreen extends StatelessWidget {
2827
child: Column(
2928
crossAxisAlignment: CrossAxisAlignment.stretch,
3029
children: [
31-
// PlayerWidget scroll edilebilir alandan çıkarıldı
32-
PlayerWidget(
33-
contentItem: contentItem,
34-
// watchHistory: watchHistory,
35-
),
36-
37-
// Expanded widget ile kalan alanı kaplıyor ve scroll edilebilir
30+
PlayerWidget(contentItem: contentItem),
3831
Expanded(
3932
child: SingleChildScrollView(
40-
child: Container(
41-
decoration: BoxDecoration(
42-
gradient: LinearGradient(
43-
begin: Alignment.topCenter,
44-
end: Alignment.bottomCenter,
45-
colors: [
46-
Theme.of(context).scaffoldBackgroundColor.withOpacity(0.8),
47-
Theme.of(context).scaffoldBackgroundColor,
48-
],
49-
),
50-
),
51-
child: Padding(
52-
padding: const EdgeInsets.all(20.0),
53-
child: Column(
54-
crossAxisAlignment: CrossAxisAlignment.start,
55-
children: [
56-
// Kanal Başlığı
57-
Row(
58-
children: [
59-
Expanded(
60-
child: SelectableText(
61-
contentItem.name,
62-
style: Theme.of(context).textTheme.headlineSmall
63-
?.copyWith(fontWeight: FontWeight.bold),
64-
),
33+
child: Padding(
34+
padding: const EdgeInsets.all(20.0),
35+
child: Column(
36+
crossAxisAlignment: CrossAxisAlignment.start,
37+
children: [
38+
// Kanal Başlığı
39+
Row(
40+
children: [
41+
Expanded(
42+
child: SelectableText(
43+
contentItem.name,
44+
style: Theme.of(context).textTheme.headlineSmall
45+
?.copyWith(fontWeight: FontWeight.bold),
6546
),
66-
],
67-
),
68-
const SizedBox(height: 24),
69-
],
70-
),
47+
),
48+
],
49+
),
50+
const SizedBox(height: 24),
51+
],
7152
),
7253
),
7354
),
@@ -168,4 +149,4 @@ class EpisodeScreen extends StatelessWidget {
168149
// Şu an için sabit bir değer döndürüyorum
169150
return 'HD';
170151
}
171-
}
152+
}

lib/views/screens/watch_history/watch_history_screen.dart

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,23 @@ class _WatchHistoryScreenState extends State<WatchHistoryScreen> {
4646

4747
Future<void> _loadWatchHistory() async {
4848
setState(() => _isLoading = true);
49-
49+
var playlistId = AppState.currentPlaylist!.id;
5050
try {
5151
final futures = await Future.wait([
52-
_historyService.getContinueWatching(),
53-
_historyService.getRecentlyWatched(limit: 20),
54-
_historyService.getWatchHistoryByContentType(ContentType.liveStream),
55-
_historyService.getWatchHistoryByContentType(ContentType.vod),
56-
_historyService.getWatchHistoryByContentType(ContentType.series),
52+
_historyService.getContinueWatching(playlistId),
53+
_historyService.getRecentlyWatched(limit: 20, playlistId),
54+
_historyService.getWatchHistoryByContentType(
55+
ContentType.liveStream,
56+
playlistId,
57+
),
58+
_historyService.getWatchHistoryByContentType(
59+
ContentType.vod,
60+
playlistId,
61+
),
62+
_historyService.getWatchHistoryByContentType(
63+
ContentType.series,
64+
playlistId,
65+
),
5766
]);
5867

5968
setState(() {
@@ -272,7 +281,7 @@ class _WatchHistoryScreenState extends State<WatchHistoryScreen> {
272281
history.title,
273282
history.imagePath ?? '',
274283
history.contentType,
275-
liveStream: liveStream
284+
liveStream: liveStream,
276285
),
277286
);
278287
case ContentType.vod:
@@ -288,7 +297,7 @@ class _WatchHistoryScreenState extends State<WatchHistoryScreen> {
288297
history.imagePath ?? '',
289298
history.contentType,
290299
containerExtension: movie!.containerExtension,
291-
vodStream: movie
300+
vodStream: movie,
292301
),
293302
);
294303
case ContentType.series:

lib/views/widgets/player-buttons/video_title.dart renamed to lib/views/widgets/player-buttons/video_title_widget.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ class _VideoTitleWidgetState extends State<VideoTitleWidget> {
4040
return Text(
4141
videoTitle,
4242
style: TextStyle(
43-
color: Theme.of(context).brightness == Brightness.dark
44-
? Colors.white
45-
: Colors.black,
43+
color: Colors.white,
4644
),
4745
maxLines: 1,
4846
overflow: TextOverflow.clip,

lib/views/widgets/player_widget.dart

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ class _PlayerWidgetState extends State<PlayerWidget>
121121
Future<void> _initializeAudioService() async {
122122
if (!mounted) return;
123123

124-
125124
_audioHandler.setPlayer(_player);
126125
// _audioHandler.setCurrentMediaItem(
127126
// title: contentItem.name,
@@ -286,21 +285,60 @@ class _PlayerWidgetState extends State<PlayerWidget>
286285

287286
@override
288287
Widget build(BuildContext context) {
288+
final screenSize = MediaQuery.of(context).size;
289+
final isTablet = screenSize.shortestSide >= 600;
290+
final isLandscape = screenSize.width > screenSize.height;
291+
double calculateAspectRatio() {
292+
if (widget.aspectRatio != null) return widget.aspectRatio!;
293+
294+
if (isTablet) {
295+
// Tablet için daha küçük player
296+
return isLandscape ? 21 / 9 : 16 / 9;
297+
}
298+
return 16 / 9;
299+
}
300+
301+
// Tablet için maksimum yükseklik belirle
302+
double? calculateMaxHeight() {
303+
if (isTablet) {
304+
if (isLandscape) {
305+
return screenSize.height * 0.6; // Landscape'de ekranın %60'ı
306+
} else {
307+
return screenSize.height * 0.4; // Portrait'te ekranın %40'ı
308+
}
309+
}
310+
return null;
311+
}
312+
313+
314+
Widget playerWidget = AspectRatio(
315+
aspectRatio: calculateAspectRatio(),
316+
child: isLoading
317+
? Container(
318+
color: Colors.black,
319+
child: const Center(
320+
child: CircularProgressIndicator(color: Colors.white),
321+
),
322+
)
323+
: _buildPlayerContent(),
324+
);
325+
326+
// Tablet için maksimum yükseklik uygula
327+
if (isTablet) {
328+
final maxHeight = calculateMaxHeight();
329+
if (maxHeight != null) {
330+
playerWidget = ConstrainedBox(
331+
constraints: BoxConstraints(maxHeight: maxHeight),
332+
child: playerWidget,
333+
);
334+
}
335+
}
336+
289337
return Container(
290338
color: Colors.black,
291339
child: Column(
292340
children: [
293-
AspectRatio(
294-
aspectRatio: widget.aspectRatio ?? 16 / 9,
295-
child: isLoading
296-
? Container(
297-
color: Colors.black,
298-
child: const Center(
299-
child: CircularProgressIndicator(color: Colors.white),
300-
),
301-
)
302-
: _buildPlayerContent(),
303-
),
341+
playerWidget,
304342
],
305343
),
306344
);

lib/views/widgets/video_widget.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:iptv_player/services/player_state.dart';
33
import 'package:iptv_player/views/widgets/player-buttons/back_button_widget.dart';
44
import 'package:iptv_player/views/widgets/player-buttons/video_settings_widget.dart';
5-
import 'package:iptv_player/views/widgets/player-buttons/video_title.dart';
5+
import 'package:iptv_player/views/widgets/player-buttons/video_title_widget.dart';
66
import 'package:media_kit_video/media_kit_video.dart';
77

88
Widget getVideo(BuildContext context, VideoController controller) {

pubspec.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ dependencies:
2929
path: libs/universal/media_kit_libs_video
3030
ref: main
3131

32-
3332
provider: ^6.1.1
3433
drift: ^2.26.1
3534
sqlite3_flutter_libs: ^0.5.34
3635
cupertino_icons: ^1.0.8
3736
http: ^1.4.0
38-
# screen_brightness: ^2.1.4
3937
cached_network_image: ^3.4.1
4038
audio_service: ^0.18.12
4139
just_audio: ^0.10.4
@@ -46,7 +44,6 @@ dependencies:
4644
shared_preferences: ^2.5.3
4745
audio_session: ^0.2.2
4846

49-
# Tüm media-kit paketleri için dependency override
5047
dependency_overrides:
5148
media_kit:
5249
git:

0 commit comments

Comments
 (0)