update movie

main
Herwig Birke 2 years ago
parent 68cba1ef74
commit 140e0bd339

@ -6,6 +6,7 @@ import 'package:syncfusion_flutter_datagrid/datagrid.dart';
class Movie {
int movieID;
String movieTitle;
String originalTitle;
String overview;
DateTime releaseDate;
int state;
@ -24,6 +25,7 @@ class Movie {
Movie({
required this.movieID,
required this.movieTitle,
required this.originalTitle,
required this.overview,
required this.releaseDate,
required this.state,
@ -45,6 +47,7 @@ class Movie {
return Movie(
movieID: int.parse(json['movieID']),
movieTitle: json['movieTitle'] as String,
originalTitle: json['originalTitle'] as String,
overview: json['overview'] as String,
releaseDate: DateTime.parse(json['releaseDate']),
state: int.parse(json['state']),
@ -64,6 +67,7 @@ class Movie {
return Movie(
movieID: int.parse(json['movieID']),
movieTitle: json['movieTitle'] as String,
originalTitle: '',
overview: json['overview'] as String,
releaseDate: DateTime.parse(json['releaseDate']),
state: int.parse(json['state']),

@ -285,9 +285,67 @@ class MovieDetailsScreen extends StatelessWidget {
}
bool save() {
updateMovie();
return true;
}
Future<bool> updateMovie() 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,
);
try {
final r = await http.post(
url,
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(
<String, String>{
'module': 'movie',
'function': 'update',
'movieID': movieDetails.movieID.toString(),
'movieTitle': movieDetails.movieTitle,
'originalTitle': movieDetails.originalTitle,
'overview': movieDetails.overview,
'releaseDate':
DateFormat('yyyy-MM-dd').format(movieDetails.releaseDate),
'resolution': movieDetails.resolution,
'state': movieDetails.state.toString(),
'backdropPath': movieDetails.backdropPath,
'languages': movieDetails.languages,
'productionCountries': movieDetails.productionCountries,
'productionCompanies': movieDetails.productionCompanies,
'voteAverage': movieDetails.voteAverage.toString(),
'voteCount': movieDetails.voteCount.toString(),
'cast': movieDetails.cast,
'crew': movieDetails.crew,
'genre': movieDetails.genre,
'localPath': movieDetails.localPath,
},
),
);
} catch (e) {
print (e.toString());
}
return true;
}
void settingsChanged(String localPath, String resolution, int state) {
movieDetails.localPath = localPath;
movieDetails.resolution = resolution;
movieDetails.state = state;
}
@override
Widget build(BuildContext context) {
String releaseDate = DateFormat('yyyy-MM-dd').format(movie.releaseDate);
@ -300,7 +358,7 @@ class MovieDetailsScreen extends StatelessWidget {
tooltip: 'Save changes',
onPressed: () {
if (save()) {
Navigator.pop(context);
Navigator.pop(context, movieDetails);
}
},
),
@ -308,7 +366,7 @@ class MovieDetailsScreen extends StatelessWidget {
icon: const Icon(Icons.highlight_off),
tooltip: 'Revert changes',
onPressed: () {
Navigator.pop(context);
Navigator.pop(context, null);
},
),
],
@ -323,10 +381,12 @@ class MovieDetailsScreen extends StatelessWidget {
return Stack(children: [
Container(
decoration: BoxDecoration(
image: movieDetails.backdropPath.isNotEmpty ? DecorationImage(
image: NetworkImage(url),
fit: BoxFit.cover,
) : null,
image: movieDetails.backdropPath.isNotEmpty
? DecorationImage(
image: NetworkImage(url),
fit: BoxFit.cover,
)
: null,
),
),
SingleChildScrollView(
@ -355,6 +415,7 @@ class MovieDetailsScreen extends StatelessWidget {
localPath: movieDetails.localPath,
resolution: movieDetails.resolution,
state: movieDetails.state,
settingsChanged: settingsChanged,
),
),
],

@ -6,16 +6,34 @@ import 'package:multimedia/widgets/movies/details/settingsBoxResolution.dart';
import 'package:multimedia/widgets/movies/details/stateBox.dart';
class MovieDetailsSettingsBox extends StatelessWidget {
const MovieDetailsSettingsBox({
MovieDetailsSettingsBox({
super.key,
required this.localPath,
required this.resolution,
required this.state,
required this.settingsChanged,
});
final String localPath;
final String resolution;
final int state;
String localPath;
String resolution;
int state;
final Function(String localPath, String resolution, int state) settingsChanged;
void localPathChanged(String localPath) {
this.localPath = localPath;
settingsChanged(localPath, resolution, state);
}
void resolutionChanged(String resolution) {
this.resolution = resolution;
settingsChanged(localPath, resolution, state);
}
void stateChanged(int state) {
this.state = state;
settingsChanged(localPath, resolution, state);
}
Widget generateInputs(BuildContext context) {
double width = MediaQuery.of(context).size.width;
@ -31,6 +49,7 @@ class MovieDetailsSettingsBox extends StatelessWidget {
children: [
MovieDetailsSettingsBoxResolution(
resolution: resolution,
resolutionChanged: resolutionChanged,
),
],
),
@ -38,6 +57,7 @@ class MovieDetailsSettingsBox extends StatelessWidget {
children: [
MovieDetailsSettingsBoxLocalPath(
localPath: localPath,
localPathChanged: localPathChanged,
),
],
),
@ -45,6 +65,7 @@ class MovieDetailsSettingsBox extends StatelessWidget {
children: [
MovieDetailsSettingsStateBox(
state: state,
stateChanged: stateChanged,
),
],
),
@ -63,12 +84,15 @@ class MovieDetailsSettingsBox extends StatelessWidget {
children: [
MovieDetailsSettingsBoxLocalPath(
localPath: localPath,
localPathChanged: localPathChanged,
),
MovieDetailsSettingsBoxResolution(
resolution: resolution,
resolutionChanged: resolutionChanged,
),
MovieDetailsSettingsStateBox(
state: state,
stateChanged: stateChanged,
),
],
),

@ -1,12 +1,15 @@
import 'package:flutter/material.dart';
class MovieDetailsSettingsBoxLocalPath extends StatelessWidget {
const MovieDetailsSettingsBoxLocalPath({
MovieDetailsSettingsBoxLocalPath({
super.key,
required this.localPath,
required this.localPathChanged,
});
final String localPath;
String localPath;
final Function(String localPath) localPathChanged;
@override
Widget build(BuildContext context) {
@ -31,6 +34,9 @@ class MovieDetailsSettingsBoxLocalPath extends StatelessWidget {
labelText: 'Local Path',
),
initialValue: localPath,
onChanged: (text) {
localPathChanged(text);
},
),
],
),

@ -4,10 +4,13 @@ class MovieDetailsSettingsBoxResolution extends StatefulWidget {
MovieDetailsSettingsBoxResolution({
super.key,
required this.resolution,
required this.resolutionChanged,
});
String resolution;
final Function(String resolution) resolutionChanged;
@override
State<MovieDetailsSettingsBoxResolution> createState() =>
_MovieDetailsSettingsBoxResolutionState();
@ -69,6 +72,7 @@ class _MovieDetailsSettingsBoxResolutionState
onChanged: (String? newValue) {
setState(() {
_curResolution = newValue!;
widget.resolutionChanged(_curResolution);
});
},
),

@ -3,10 +3,16 @@ import 'package:flutter/material.dart';
import 'package:multimedia/constants.dart';
class MovieDetailsSettingsStateBox extends StatefulWidget {
MovieDetailsSettingsStateBox({super.key, required this.state});
MovieDetailsSettingsStateBox({
super.key,
required this.state,
required this.stateChanged,
});
int state;
final Function(int state) stateChanged;
@override
State<MovieDetailsSettingsStateBox> createState() =>
_MovieDetailsSettingsStateBoxState();
@ -60,6 +66,7 @@ class _MovieDetailsSettingsStateBoxState
if (value == true) {
setState(() {
widget.state = 1;
widget.stateChanged(1);
});
}
},
@ -82,6 +89,7 @@ class _MovieDetailsSettingsStateBoxState
if (value == true) {
setState(() {
widget.state = 2;
widget.stateChanged(2);
});
}
},
@ -104,6 +112,7 @@ class _MovieDetailsSettingsStateBoxState
if (value == true) {
setState(() {
widget.state = 3;
widget.stateChanged(3);
});
}
},
@ -117,72 +126,5 @@ class _MovieDetailsSettingsStateBoxState
),
);
// return Row(
// children: [
// SizedBox(
// width: 200,
// child: CheckboxListTile(
// side: MaterialStateBorderSide.resolveWith(
// (states) => const BorderSide(width: 1.0, color: Colors.grey),
// ),
// title: const Text(
// 'initialized',
// textAlign: TextAlign.end,
// style: TextStyle(color: Colors.black),
// ),
// value: widget.state == 1,
// onChanged: (bool? value) {
// if (value == true) {
// setState(() {
// widget.state = 1;
// });
// }
// },
// ),
// ),
// SizedBox(
// width: 200,
// child: CheckboxListTile(
// side: MaterialStateBorderSide.resolveWith(
// (states) => const BorderSide(width: 1.0, color: Colors.grey),
// ),
// title: const Text(
// 'in progress',
// textAlign: TextAlign.end,
// style: TextStyle(color: Colors.black),
// ),
// value: widget.state == 2,
// onChanged: (bool? value) {
// if (value == true) {
// setState(() {
// widget.state = 2;
// });
// }
// },
// ),
// ),
// SizedBox(
// width: 200,
// child: CheckboxListTile(
// side: MaterialStateBorderSide.resolveWith(
// (states) => const BorderSide(width: 1.0, color: Colors.grey),
// ),
// title: const Text(
// 'done',
// textAlign: TextAlign.end,
// style: TextStyle(color: Colors.black),
// ),
// value: widget.state == 3,
// onChanged: (bool? value) {
// if (value == true) {
// setState(() {
// widget.state = 3;
// });
// }
// },
// ),
// ),
// ],
// );
}
}

@ -45,22 +45,28 @@ class _MoviesScreenState extends State<MoviesScreen> {
},
);
final response = await http.get(url);
bool? error;
String? errorMessage;
try {
final response = await http.get(url);
bool? error;
String? errorMessage;
Map<String, dynamic> movies = json.decode(response.body);
error = movies['error'];
errorMessage = movies['errmsg'];
var list = movies['data'];
Map<String, dynamic> movies = json.decode(response.body);
error = movies['error'];
errorMessage = movies['errmsg'];
var list = movies['data'];
List<Movie> _movies =
await list.map<Movie>((json) => Movie.fromJson(json)).toList();
movieDataSource = MovieDataSource(_movies);
List<Movie> _movies =
await list.map<Movie>((json) => Movie.fromJson(json)).toList();
movieDataSource = MovieDataSource(_movies);
_moviesList = _movies;
_moviesList = _movies;
return _movies;
return _movies;
} catch (e) {
print(e.toString());
}
return [];
}
List<GridColumn> getColumns() {
@ -126,7 +132,7 @@ class _MoviesScreenState extends State<MoviesScreen> {
_columns = getColumns();
}
void showMovieDetails(int index) {
Future<void> showMovieDetails(int index) async {
List<DataGridCell<dynamic>> cells =
movieDataSource.effectiveRows.elementAt(index).getCells();
@ -142,11 +148,46 @@ class _MoviesScreenState extends State<MoviesScreen> {
}
if (found) {
Navigator.push(
final m = await Navigator.push(
context,
MaterialPageRoute(
builder: (ctx) =>
MovieDetailsScreen(movie: _moviesList[movieIndex])));
if (m != null) {
_moviesList[movieIndex].movieTitle = m.movieTitle;
_moviesList[movieIndex].localPath = m.localPath;
_moviesList[movieIndex].resolution = m.resolution;
_moviesList[movieIndex].state = m.state;
Movie e = _moviesList[movieIndex];
movieDataSource._movieDataGridRows[index] = DataGridRow(cells: [
DataGridCell<int>(columnName: 'movieID', value: e.movieID),
DataGridCell<int>(columnName: 'state', value: e.state),
DataGridCell<String>(
columnName: 'backdropPath', value: e.backdropPath),
DataGridCell<String>(columnName: 'movieTitle', value: e.movieTitle),
DataGridCell<String>(
columnName: 'releaseDate',
value: DateFormat('yyyy-MM-dd').format(e.releaseDate)),
DataGridCell<String>(columnName: 'resolution', value: e.resolution),
DataGridCell<String>(columnName: 'overview', value: e.overview),
]);
movieDataSource.updateDataGridSource(
rowColumnIndex: RowColumnIndex(index, 0));
movieDataSource.updateDataGridSource(
rowColumnIndex: RowColumnIndex(index, 1));
movieDataSource.updateDataGridSource(
rowColumnIndex: RowColumnIndex(index, 2));
movieDataSource.updateDataGridSource(
rowColumnIndex: RowColumnIndex(index, 3));
movieDataSource.updateDataGridSource(
rowColumnIndex: RowColumnIndex(index, 4));
movieDataSource.updateDataGridSource(
rowColumnIndex: RowColumnIndex(index, 5));
} else {
}
}
}
@ -267,4 +308,8 @@ class MovieDataSource extends DataGridSource {
void updateDataGrid() {
notifyListeners();
}
void updateDataGridSource({required RowColumnIndex rowColumnIndex}) {
notifyDataSourceListeners(rowColumnIndex: rowColumnIndex);
}
}

@ -38,11 +38,6 @@ class TVShowDetailsScreen extends StatelessWidget {
scheme: dbProtocol,
host: dbHost,
path: dbPath,
queryParameters: {
'module': 'tvshow',
'function': 'test',
'data': data,
},
);
print(url.toString());
@ -54,6 +49,8 @@ class TVShowDetailsScreen extends StatelessWidget {
},
body: jsonEncode(
<String, String>{
'module': 'tvshow',
'function': 'test',
'title': data,
},
),
@ -80,6 +77,7 @@ class TVShowDetailsScreen extends StatelessWidget {
},
);
print (url);
final response = await http.get(url);
bool? error;
String? errorMessage;

@ -50,44 +50,50 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
},
);
final response = await http.get(url);
bool? error;
String? errorMessage;
String? mSeason;
Map<String, dynamic> tvshows = json.decode(response.body);
error = tvshows['error'];
errorMessage = tvshows['errmsg'];
mSeason = tvshows['maxSeason'];
var tvshowList = tvshows['tvshows'];
var episodeList = tvshows['episodeCount'];
if (mSeason != null) {
if (int.tryParse(mSeason!) != null) {
maxSeason = int.parse(mSeason);
try {
final response = await http.get(url);
bool? error;
String? errorMessage;
String? mSeason;
Map<String, dynamic> tvshows = json.decode(response.body);
error = tvshows['error'];
errorMessage = tvshows['errmsg'];
mSeason = tvshows['maxSeason'];
var tvshowList = tvshows['tvshows'];
var episodeList = tvshows['episodeCount'];
if (mSeason != null) {
if (int.tryParse(mSeason!) != null) {
maxSeason = int.parse(mSeason);
}
}
}
List<TVShow> _tvshows =
await tvshowList.map<TVShow>((json) => TVShow.fromJson(json)).toList();
tvshowDataSource = TVShowDataSource(_tvshows, maxSeason);
List<TVShow> _tvshows =
await tvshowList.map<TVShow>((json) => TVShow.fromJson(json)).toList();
tvshowDataSource = TVShowDataSource(_tvshows, maxSeason);
List<EpisodeCount> _episodecount = await episodeList
.map<EpisodeCount>((json) => EpisodeCount.fromJson(json))
.toList();
List<EpisodeCount> _episodecount = await episodeList
.map<EpisodeCount>((json) => EpisodeCount.fromJson(json))
.toList();
episodeCount = _episodecount;
episodeCount = _episodecount;
if (initDone == false) {
addSeasonColumns(maxSeason);
}
if (initDone == false) {
addSeasonColumns(maxSeason);
}
initDone = true;
initDone = true;
_tvshowsList = _tvshows;
_tvshowsList = _tvshows;
return _tvshows;
} catch (e) {
print (e.toString());
}
return _tvshows;
return [];
}
void addSeasonColumns(int maxSeason) {
@ -96,7 +102,7 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
columnName: 'season$x',
// columnWidthMode: ColumnWidthMode.auto,
label: Container(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(4.0),
alignment: Alignment.centerLeft,
child: Text('Season $x'))));
}
@ -109,7 +115,7 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
visible: false,
width: 70,
label: Container(
padding: const EdgeInsets.all(16.0),
padding: const EdgeInsets.all(4.0),
alignment: Alignment.centerLeft,
child: const Text('seriesID'),
),
@ -119,7 +125,7 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
visible: false,
width: 70,
label: Container(
padding: const EdgeInsets.all(16.0),
padding: const EdgeInsets.all(4.0),
alignment: Alignment.centerLeft,
child: const Text('seriesState'))),
GridColumn(
@ -127,7 +133,7 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
visible: false,
width: 70,
label: Container(
padding: const EdgeInsets.all(16.0),
padding: const EdgeInsets.all(4.0),
alignment: Alignment.centerLeft,
child: const Text('status'))),
GridColumn(
@ -135,7 +141,7 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
visible: false,
width: 70,
label: Container(
padding: const EdgeInsets.all(16.0),
padding: const EdgeInsets.all(4.0),
alignment: Alignment.centerLeft,
child: const Text('cliffhanger'))),
GridColumn(
@ -143,7 +149,7 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
visible: false,
width: 70,
label: Container(
padding: const EdgeInsets.all(16.0),
padding: const EdgeInsets.all(4.0),
alignment: Alignment.centerLeft,
child: const Text('backdropPath'))),
GridColumn(
@ -151,28 +157,28 @@ class _TVShowsScreenState extends State<TVShowsScreen> {
visible: false,
width: 70,
label: Container(
padding: const EdgeInsets.all(16.0),
padding: const EdgeInsets.all(4.0),
alignment: Alignment.centerLeft,
child: const Text('overview'))),
GridColumn(
columnName: 'seriesName',
// columnWidthMode: ColumnWidthMode.auto,
label: Container(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(4.0),
alignment: Alignment.centerLeft,
child: const Text('Name'))),
GridColumn(
columnName: 'firstAired',
// columnWidthMode: ColumnWidthMode.auto,
label: Container(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(4.0),
alignment: Alignment.centerLeft,
child: const Text('First Aired'))),
GridColumn(
columnName: 'resolution',
// columnWidthMode: ColumnWidthMode.auto,
label: Container(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(4.0),
alignment: Alignment.centerLeft,
child: const Text('Resolution'))),
];
@ -371,7 +377,7 @@ class TVShowDataSource extends DataGridSource {
'1',
style: TextStyle(
fontFamily: 'geometric',
fontSize: 30,
fontSize: 25,
color: col,
),
)),

Loading…
Cancel
Save