update movie, tvshow
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -37,6 +39,13 @@ class Season {
|
|||||||
seasonID: int.parse(json['seasonID']),
|
seasonID: int.parse(json['seasonID']),
|
||||||
state: json['state']);
|
state: json['state']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map toJson() =>
|
||||||
|
{
|
||||||
|
'seasonNumber': seasonNumber.toString(),
|
||||||
|
'seasonID': seasonID.toString(),
|
||||||
|
'state': state,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class TVShow {
|
class TVShow {
|
||||||
|
|||||||
@@ -337,6 +337,58 @@ class TVShowDetailsScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> updateTVShow() async {
|
Future<bool> updateTVShow() async {
|
||||||
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
|
String? dbProtocol = prefs.getString('dbProtocol');
|
||||||
|
String? dbHost = prefs.getString('dbHost');
|
||||||
|
String? dbPath = prefs.getString('dbPath');
|
||||||
|
|
||||||
|
Uri url = Uri(
|
||||||
|
scheme: dbProtocol,
|
||||||
|
host: dbHost,
|
||||||
|
path: dbPath,
|
||||||
|
);
|
||||||
|
|
||||||
|
var seasonState = jsonEncode(tvShowDetails.seasonStatus.map((e) => e.toJson()).toList());
|
||||||
|
|
||||||
|
try {
|
||||||
|
final r = await http.post(
|
||||||
|
url,
|
||||||
|
headers: <String, String>{
|
||||||
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
|
},
|
||||||
|
body: jsonEncode(
|
||||||
|
<String, dynamic>{
|
||||||
|
'module': 'tvshow',
|
||||||
|
'function': 'update',
|
||||||
|
'seriesID': tvShowDetails.seriesID.toString(),
|
||||||
|
'seriesName': tvShowDetails.seriesName,
|
||||||
|
'overview': tvShowDetails.overview,
|
||||||
|
'firstAired':
|
||||||
|
DateFormat('yyyy-MM-dd').format(tvShowDetails.firstAired),
|
||||||
|
'resolution': tvShowDetails.resolution,
|
||||||
|
'cliffhanger': tvShowDetails.cliffhanger.toString(),
|
||||||
|
'status': tvShowDetails.status.toString(),
|
||||||
|
'backdropPath': tvShowDetails.backdropPath,
|
||||||
|
'seriesState': tvShowDetails.seriesState.toString(),
|
||||||
|
'languages': tvShowDetails.languages,
|
||||||
|
'networks': tvShowDetails.networks,
|
||||||
|
'productionCompanies': tvShowDetails.productionCompanies,
|
||||||
|
'voteAverage': tvShowDetails.voteAverage.toString(),
|
||||||
|
'voteCount': tvShowDetails.voteCount.toString(),
|
||||||
|
'cast': tvShowDetails.cast,
|
||||||
|
'crew': tvShowDetails.crew,
|
||||||
|
'genre': tvShowDetails.genre,
|
||||||
|
'download': tvShowDetails.download,
|
||||||
|
'localPath': tvShowDetails.localPath,
|
||||||
|
'seasons': seasonState,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
print(e.toString());
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,8 +403,34 @@ class TVShowDetailsScreen extends StatelessWidget {
|
|||||||
void stateChanged(List<Season> seasonStatus) {
|
void stateChanged(List<Season> seasonStatus) {
|
||||||
tvShowDetails.seasonStatus = seasonStatus;
|
tvShowDetails.seasonStatus = seasonStatus;
|
||||||
|
|
||||||
for (var s in tvShowDetails.seasonStatus) {
|
bool hasInit = false;
|
||||||
print('Season: ${s.seasonNumber}, State: ${s.state}');
|
bool hasProg = false;
|
||||||
|
bool hasDone = false;
|
||||||
|
|
||||||
|
for (var season in tvShowDetails.seasonStatus) {
|
||||||
|
var episodeList = season.state.split(',');
|
||||||
|
|
||||||
|
for (var s in episodeList) {
|
||||||
|
var states = s.split('|');
|
||||||
|
|
||||||
|
if (states[1] == '1') {
|
||||||
|
hasInit = true;
|
||||||
|
}
|
||||||
|
if (states[1] == '2') {
|
||||||
|
hasProg = true;
|
||||||
|
}
|
||||||
|
if (states[1] == '3') {
|
||||||
|
hasDone = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasProg) {
|
||||||
|
tvShowDetails.seriesState = 2;
|
||||||
|
} else if (hasInit) {
|
||||||
|
tvShowDetails.seriesState = 1;
|
||||||
|
} else if (hasDone) {
|
||||||
|
tvShowDetails.seriesState = 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ class TVShowDetailsSeasons extends StatefulWidget {
|
|||||||
final Function(List<Season>) stateChanged;
|
final Function(List<Season>) stateChanged;
|
||||||
|
|
||||||
void stateChanged1(int seasonNumber, String state) {
|
void stateChanged1(int seasonNumber, String state) {
|
||||||
print('start stateChanged1 in seasons ...');
|
|
||||||
for (int seasonID = 0; seasonID < seasonStatus.length; seasonID++) {
|
for (int seasonID = 0; seasonID < seasonStatus.length; seasonID++) {
|
||||||
if (seasonStatus[seasonID].seasonNumber == seasonNumber) {
|
if (seasonStatus[seasonID].seasonNumber == seasonNumber) {
|
||||||
seasonStatus[seasonID].state = state;
|
seasonStatus[seasonID].state = state;
|
||||||
|
|||||||
@@ -15,6 +15,54 @@ import 'package:multimedia/data/tvshows.dart';
|
|||||||
|
|
||||||
import 'package:multimedia/constants.dart';
|
import 'package:multimedia/constants.dart';
|
||||||
|
|
||||||
|
|
||||||
|
String convertState(String state) {
|
||||||
|
List<String> stateList = state.split(',');
|
||||||
|
int maxEpisode = 0;
|
||||||
|
Map stateListMap = {};
|
||||||
|
|
||||||
|
for (var x = 0; x < stateList.length; x++) {
|
||||||
|
List<String> tmp = stateList[x].split('|');
|
||||||
|
stateListMap[tmp[0]] = tmp[1];
|
||||||
|
|
||||||
|
int episode = int.parse(tmp[0]);
|
||||||
|
if (episode > maxEpisode) {
|
||||||
|
maxEpisode = episode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String stateString = "";
|
||||||
|
|
||||||
|
for (int x = 0; x < maxEpisode; x++) {
|
||||||
|
String s = '0';
|
||||||
|
int key = x + 1;
|
||||||
|
|
||||||
|
if (stateListMap.containsKey('$key')) {
|
||||||
|
s = stateListMap['$key'];
|
||||||
|
}
|
||||||
|
|
||||||
|
stateString = stateString + s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return stateString;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<DataGridCell> setSeasonData(int maxSeason, List<Season> seasonList) {
|
||||||
|
List<DataGridCell> dataGridCell = [];
|
||||||
|
int length = seasonList.length;
|
||||||
|
|
||||||
|
for (int x = 1; x <= maxSeason; x++) {
|
||||||
|
String status = '';
|
||||||
|
|
||||||
|
if (x <= length) {
|
||||||
|
status = convertState(seasonList[x - 1].state);
|
||||||
|
}
|
||||||
|
dataGridCell.add(DataGridCell(columnName: 'season$x', value: status));
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataGridCell;
|
||||||
|
}
|
||||||
|
|
||||||
class TVShowsScreen extends StatefulWidget {
|
class TVShowsScreen extends StatefulWidget {
|
||||||
const TVShowsScreen({
|
const TVShowsScreen({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -195,7 +243,7 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
|
|||||||
_columns = getColumns();
|
_columns = getColumns();
|
||||||
}
|
}
|
||||||
|
|
||||||
void showTVShowDetails(int index) {
|
Future<void> showTVShowDetails(int index) async {
|
||||||
List<DataGridCell<dynamic>> cells =
|
List<DataGridCell<dynamic>> cells =
|
||||||
tvshowDataSource.effectiveRows.elementAt(index).getCells();
|
tvshowDataSource.effectiveRows.elementAt(index).getCells();
|
||||||
|
|
||||||
@@ -211,11 +259,43 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
Navigator.push(
|
final t = await Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (ctx) =>
|
builder: (ctx) =>
|
||||||
TVShowDetailsScreen(tvShow: _tvshowsList[tvShowIndex])));
|
TVShowDetailsScreen(tvShow: _tvshowsList[tvShowIndex])));
|
||||||
|
|
||||||
|
if (t != null) {
|
||||||
|
_tvshowsList[tvShowIndex].seriesName = t.seriesName;
|
||||||
|
_tvshowsList[tvShowIndex].download = t.download;
|
||||||
|
_tvshowsList[tvShowIndex].localPath = t.localPath;
|
||||||
|
_tvshowsList[tvShowIndex].resolution = t.resolution;
|
||||||
|
_tvshowsList[tvShowIndex].cliffhanger = t.cliffhanger;
|
||||||
|
_tvshowsList[tvShowIndex].seasonStatus = t.seasonStatus;
|
||||||
|
_tvshowsList[tvShowIndex].seriesState = t.seriesState;
|
||||||
|
TVShow e = _tvshowsList[tvShowIndex];
|
||||||
|
|
||||||
|
tvshowDataSource._tvshowDataGridRows[index] = 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: 'backdropPath', value: e.backdropPath),
|
||||||
|
DataGridCell<String>(columnName: 'overview', value: e.overview),
|
||||||
|
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),
|
||||||
|
...setSeasonData(maxSeason, e.seasonStatus),
|
||||||
|
]);
|
||||||
|
|
||||||
|
for (int i = 0;i < _columns.length;i++) {
|
||||||
|
tvshowDataSource.updateDataGridSource(
|
||||||
|
rowColumnIndex: RowColumnIndex(index, i));
|
||||||
|
}
|
||||||
|
} else {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,53 +355,6 @@ class TVShowDataSource extends DataGridSource {
|
|||||||
buildDataGridRow();
|
buildDataGridRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
String convertState(String state) {
|
|
||||||
List<String> stateList = state.split(',');
|
|
||||||
int maxEpisode = 0;
|
|
||||||
Map stateListMap = {};
|
|
||||||
|
|
||||||
for (var x = 0; x < stateList.length; x++) {
|
|
||||||
List<String> tmp = stateList[x].split('|');
|
|
||||||
stateListMap[tmp[0]] = tmp[1];
|
|
||||||
|
|
||||||
int episode = int.parse(tmp[0]);
|
|
||||||
if (episode > maxEpisode) {
|
|
||||||
maxEpisode = episode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String stateString = "";
|
|
||||||
|
|
||||||
for (int x = 0; x < maxEpisode; x++) {
|
|
||||||
String s = '0';
|
|
||||||
int key = x + 1;
|
|
||||||
|
|
||||||
if (stateListMap.containsKey('$key')) {
|
|
||||||
s = stateListMap['$key'];
|
|
||||||
}
|
|
||||||
|
|
||||||
stateString = stateString + s;
|
|
||||||
}
|
|
||||||
|
|
||||||
return stateString;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<DataGridCell> setSeasonData(int maxSeason, List<Season> seasonList) {
|
|
||||||
List<DataGridCell> dataGridCell = [];
|
|
||||||
int length = seasonList.length;
|
|
||||||
|
|
||||||
for (int x = 1; x <= maxSeason; x++) {
|
|
||||||
String status = '';
|
|
||||||
|
|
||||||
if (x <= length) {
|
|
||||||
status = convertState(seasonList[x - 1].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: [
|
||||||
@@ -466,4 +499,8 @@ class TVShowDataSource extends DataGridSource {
|
|||||||
void updateDataGrid() {
|
void updateDataGrid() {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateDataGridSource({required RowColumnIndex rowColumnIndex}) {
|
||||||
|
notifyDataSourceListeners(rowColumnIndex: rowColumnIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user