movie and tvshow list

This commit is contained in:
2024-04-02 17:28:37 +02:00
parent 6dbf2b2f31
commit 87aeb70c27
2 changed files with 102 additions and 77 deletions
+40 -50
View File
@@ -3,6 +3,42 @@ import 'package:intl/intl.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart'; import 'package:syncfusion_flutter_datagrid/datagrid.dart';
class EpisodeCount {
int season;
int cnt;
EpisodeCount({
required this.season,
required this.cnt,
});
factory EpisodeCount.fromJson(Map<String, dynamic> json) {
return EpisodeCount(
season: int.parse(json['seasonNumber']),
cnt: int.parse(json['cnt']),
);
}
}
class Season {
int seasonNumber;
int seasonID;
String state;
Season({
required this.seasonNumber,
required this.seasonID,
required this.state,
});
factory Season.fromJson(Map<String, dynamic> json) {
return Season(
seasonNumber: int.parse(json['seasonNumber']),
seasonID: int.parse(json['seasonID']),
state: json['state']);
}
}
class TVShow { class TVShow {
int seriesID; int seriesID;
String seriesName; String seriesName;
@@ -11,6 +47,7 @@ class TVShow {
String resolution; String resolution;
int cliffhanger; int cliffhanger;
String status; String status;
List<Season> seasonStatus;
TVShow({ TVShow({
required this.seriesID, required this.seriesID,
@@ -20,6 +57,7 @@ class TVShow {
required this.resolution, required this.resolution,
required this.cliffhanger, required this.cliffhanger,
required this.status, required this.status,
required this.seasonStatus,
}); });
factory TVShow.fromJson(Map<String, dynamic> json) { factory TVShow.fromJson(Map<String, dynamic> json) {
@@ -56,56 +94,8 @@ class TVShow {
resolution: json['resolution'], resolution: json['resolution'],
status: json['status'], status: json['status'],
cliffhanger: int.parse(json['cliffhanger']), cliffhanger: int.parse(json['cliffhanger']),
seasonStatus:
json['seasons'].map<Season>((json) => Season.fromJson(json)).toList(),
); );
} }
} }
class TVShowDataSource extends DataGridSource {
/// Creates the employee data source class with required details.
TVShowDataSource(this.tvshows) {
buildDataGridRow();
}
void buildDataGridRow() {
_tvshowDataGridRows = tvshows
.map<DataGridRow>((e) => DataGridRow(cells: [
DataGridCell<int>(columnName: 'seriesID', value: e.seriesID),
DataGridCell<int>(
columnName: 'seriesState', value: e.seriesState),
DataGridCell<String>(columnName: 'status', value: e.status),
DataGridCell<int>(
columnName: 'cliffhanger', value: e.cliffhanger),
DataGridCell<String>(
columnName: 'seriesName', value: e.seriesName),
DataGridCell<String>(
columnName: 'firstAired',
value: DateFormat('yyyy-MM-dd').format(e.firstAired)),
DataGridCell<String>(
columnName: 'resolution', value: e.resolution),
]))
.toList();
}
List<TVShow> tvshows = [];
List<DataGridRow> _tvshowDataGridRows = [];
@override
List<DataGridRow> get rows => _tvshowDataGridRows;
@override
DataGridRowAdapter buildRow(DataGridRow row) {
return DataGridRowAdapter(
cells: row.getCells().map<Widget>((e) {
return Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(8.0),
child: Text(e.value.toString()),
);
}).toList());
}
void updateDataGrid() {
notifyListeners();
}
}
+62 -27
View File
@@ -26,9 +26,10 @@ class TVShowsScreen extends StatefulWidget {
class _TVShowsScreenState extends State<TVShowsScreen> { class _TVShowsScreenState extends State<TVShowsScreen> {
final DataGridController _dataGridController = DataGridController(); final DataGridController _dataGridController = DataGridController();
late int maxSeason; late int maxSeason;
late Map<int, int> episodeCount; late List<EpisodeCount> episodeCount;
late TVShowDataSource tvshowDataSource; late TVShowDataSource tvshowDataSource;
List<GridColumn> _columns = []; List<GridColumn> _columns = [];
late bool initDone = false;
Future<List<TVShow>> generateTVShowList() async { Future<List<TVShow>> generateTVShowList() async {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
@@ -37,8 +38,6 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
String? dbHost = prefs.getString('dbHost'); String? dbHost = prefs.getString('dbHost');
String? dbPath = prefs.getString('dbPath'); String? dbPath = prefs.getString('dbPath');
print(dbHost);
Uri url = Uri( Uri url = Uri(
scheme: dbProtocol, scheme: dbProtocol,
host: dbHost, host: dbHost,
@@ -52,27 +51,53 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
final response = await http.get(url); final response = await http.get(url);
bool? error; bool? error;
String? errorMessage; String? errorMessage;
String? mSeason;
Map<String, dynamic> tvshows = json.decode(response.body); Map<String, dynamic> tvshows = json.decode(response.body);
error = tvshows['error']; error = tvshows['error'];
errorMessage = tvshows['errmsg']; errorMessage = tvshows['errmsg'];
var mSeason = tvshows['maxSeason']; mSeason = tvshows['maxSeason'];
var tvshowList = tvshows['tvshows']; var tvshowList = tvshows['tvshows'];
// var episodeList = tvshows['episodeCount']; var episodeList = tvshows['episodeCount'];
//
// for (var episode in episodeList) { if (mSeason != null) {
// episodeCount[episode['seasonNumber']] = episode['cnr']; if (int.tryParse(mSeason!) != null) {
// } maxSeason = int.parse(mSeason);
}
}
List<TVShow> _tvshows = List<TVShow> _tvshows =
await tvshowList.map<TVShow>((json) => TVShow.fromJson(json)).toList(); await tvshowList.map<TVShow>((json) => TVShow.fromJson(json)).toList();
tvshowDataSource = TVShowDataSource(_tvshows); tvshowDataSource = TVShowDataSource(_tvshows, maxSeason);
maxSeason = mSeason; List<EpisodeCount> _episodecount = await episodeList
.map<EpisodeCount>((json) => EpisodeCount.fromJson(json))
.toList();
episodeCount = _episodecount;
if (initDone == false) {
addSeasonColumns(maxSeason);
}
initDone = true;
return _tvshows; return _tvshows;
} }
void addSeasonColumns(int maxSeason) {
for (int x = 1; x <= maxSeason; x++) {
_columns.add(GridColumn(
columnName: 'season$x',
columnWidthMode: ColumnWidthMode.auto,
label: Container(
padding: const EdgeInsets.all(8.0),
alignment: Alignment.centerLeft,
child: Text('Season $x'))));
}
}
List<GridColumn> getColumns() { List<GridColumn> getColumns() {
return <GridColumn>[ return <GridColumn>[
GridColumn( GridColumn(
@@ -128,13 +153,6 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: const Text('Resolution'))), child: const Text('Resolution'))),
GridColumn(
columnName: 'season1',
columnWidthMode: ColumnWidthMode.auto,
label: Container(
padding: const EdgeInsets.all(8.0),
alignment: Alignment.centerLeft,
child: const Text('Season 1'))),
]; ];
} }
@@ -178,10 +196,25 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
class TVShowDataSource extends DataGridSource { class TVShowDataSource extends DataGridSource {
/// Creates the employee data source class with required details. /// Creates the employee data source class with required details.
TVShowDataSource(this.tvshows) { TVShowDataSource(this.tvshows, this.maxSeason) {
buildDataGridRow(); buildDataGridRow();
} }
List<DataGridCell> setSeasonData(int maxSeason, List<Season> seasonList) {
List<DataGridCell> dataGridCell = [];
for (int x = 1; x <= maxSeason; x++) {
String status = '';
if (seasonList.length <= x) {
status = seasonList[x].state;
}
dataGridCell.add(DataGridCell(columnName: 'season$x', value: 'status'));
}
return dataGridCell;
}
void buildDataGridRow() { void buildDataGridRow() {
_tvshowDataGridRows = tvshows _tvshowDataGridRows = tvshows
.map<DataGridRow>((e) => DataGridRow(cells: [ .map<DataGridRow>((e) => DataGridRow(cells: [
@@ -198,12 +231,13 @@ class TVShowDataSource extends DataGridSource {
value: DateFormat('yyyy-MM-dd').format(e.firstAired)), value: DateFormat('yyyy-MM-dd').format(e.firstAired)),
DataGridCell<String>( DataGridCell<String>(
columnName: 'resolution', value: e.resolution), columnName: 'resolution', value: e.resolution),
DataGridCell(columnName: 'season1', value: ''), ...setSeasonData(maxSeason, e.seasonStatus),
])) ]))
.toList(); .toList();
} }
List<TVShow> tvshows = []; List<TVShow> tvshows = [];
int maxSeason;
List<DataGridRow> _tvshowDataGridRows = []; List<DataGridRow> _tvshowDataGridRows = [];
@@ -242,13 +276,14 @@ class TVShowDataSource extends DataGridSource {
} }
} }
// if (e.columnName.startsWith('season')) { if (e.columnName.startsWith('season')) {
// return Container( return Container(
// alignment: Alignment.center, alignment: Alignment.center,
// padding: EdgeInsets.symmetric(horizontal: 16), padding: EdgeInsets.symmetric(horizontal: 16),
// child: Icon(Icons.location_on), child: Icon(Icons.location_on),
// ); );
// } }
return Container( return Container(
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),