refactor code

This commit is contained in:
Simon Ding
2024-07-31 14:41:57 +08:00
parent 0ea1c040a2
commit 9ba59a7d5a
22 changed files with 728 additions and 325 deletions

View File

@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:ui/providers/APIs.dart';
import 'package:ui/providers/server_response.dart';
import 'package:ui/providers/settings.dart';
var mediaDetailsProvider = AsyncNotifierProvider.autoDispose
.family<SeriesDetailData, SeriesDetails, String>(SeriesDetailData.new);
@@ -61,6 +62,8 @@ class SeriesDetails {
String? resolution;
int? storageId;
String? airDate;
String? mediaType;
Storage? storage;
SeriesDetails(
{this.id,
@@ -73,7 +76,9 @@ class SeriesDetails {
this.resolution,
this.storageId,
this.airDate,
this.episodes});
this.episodes,
this.mediaType,
this.storage});
SeriesDetails.fromJson(Map<String, dynamic> json) {
id = json['id'];
@@ -86,6 +91,8 @@ class SeriesDetails {
resolution = json["resolution"];
storageId = json["storage_id"];
airDate = json["air_date"];
mediaType = json["media_type"];
storage = Storage.fromJson(json["storage"]);
if (json['episodes'] != null) {
episodes = <Episodes>[];
json['episodes'].forEach((v) {
@@ -146,14 +153,12 @@ var mediaTorrentsDataProvider = AsyncNotifierProvider.autoDispose
// }
// }
typedef TorrentQuery =({String mediaId, int seasonNumber, int episodeNumber});
typedef TorrentQuery = ({String mediaId, int seasonNumber, int episodeNumber});
class MediaTorrentResource extends AutoDisposeFamilyAsyncNotifier<
List<TorrentResource>, TorrentQuery> {
@override
FutureOr<List<TorrentResource>> build(TorrentQuery arg) async {
final dio = await APIs.getDio();
var resp = await dio.post(APIs.availableTorrentsUrl, data: {
"id": int.parse(arg.mediaId),

View File

@@ -283,6 +283,8 @@ class Storage {
this.id,
this.name,
this.implementation,
this.tvPath,
this.moviePath,
this.settings,
this.isDefault,
});
@@ -290,6 +292,8 @@ class Storage {
final int? id;
final String? name;
final String? implementation;
final String? tvPath;
final String? moviePath;
final Map<String, dynamic>? settings;
final bool? isDefault;
@@ -298,6 +302,8 @@ class Storage {
id: json1["id"],
name: json1["name"],
implementation: json1["implementation"],
tvPath: json1["tv_path"],
moviePath: json1["movie_path"],
settings: json.decode(json1["settings"]),
isDefault: json1["default"]);
}
@@ -306,6 +312,8 @@ class Storage {
"id": id,
"name": name,
"implementation": implementation,
"tv_path": tvPath,
"movie_path": moviePath,
"settings": settings,
"default": isDefault,
};