Skip to content

Commit

Permalink
feat: Improved anime details screen
Browse files Browse the repository at this point in the history
  • Loading branch information
K3vinb5 committed Jun 28, 2024
1 parent e3ad8bf commit 8315ea3
Show file tree
Hide file tree
Showing 6 changed files with 299 additions and 229 deletions.
33 changes: 33 additions & 0 deletions lib/models/media_content_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'dart:convert';
import 'package:http/http.dart' as http;

const String endpoint = "https://api.ani.zip/mappings?anilist_id=";

class MediaContentModel {
MediaContentModel({required this.anilistId});

void init() async{
var url = Uri.parse("$endpoint$anilistId");
var response = await http.get(url);
if (response.statusCode != 200){
if (attempt < 5){

}
}
Map<String, dynamic> jsonResponse = json.decode(response.body);
Map<String, dynamic> episodes = jsonResponse["episodes"];
imageUrls = episodes.values.map((e) => e["image"] as String?).toList();
titles = episodes.values.map((e) => e["title"]["en"] as String?).toList();
// if (titles != null){
// titles!.addAll(List.filled(10, null));
// }
// if (imageUrls != null){
// imageUrls!.addAll(List.filled(10, null));
// }
}

final int anilistId;
int attempt = 0;
List<String?>? titles;
List<String?>? imageUrls;
}
1 change: 1 addition & 0 deletions lib/models/models.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'anime_model.dart';
export 'manga_model.dart';
export 'user_media_model.dart';
export 'media_content_model.dart';
196 changes: 97 additions & 99 deletions lib/screens/anime_details_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class _AnimeDetailsScreenState extends State<AnimeDetailsScreen> {
void Function() wrongTitleSearchFunction = () {};
TextEditingController wrongTitleSearchController = TextEditingController();
int currentEpisodes = 0;
late MediaContentModel mediaContentModel;

@override
void initState() {
Expand All @@ -79,6 +80,8 @@ class _AnimeDetailsScreenState extends State<AnimeDetailsScreen> {
// };
// addEmbeddedAniyomiExtensions();
animeSources = globalAnimesSources;
mediaContentModel = MediaContentModel(anilistId: widget.currentAnime.id);
mediaContentModel.init();
updateSource(0);
setUserAnimeModel();
}
Expand Down Expand Up @@ -387,9 +390,7 @@ class _AnimeDetailsScreenState extends State<AnimeDetailsScreen> {
});
}
}
if (currentSource == 2) {
print(streamAndCaptions[3]?[source]);
}

String? captions;

if (streamAndCaptions[1] != null &&
Expand Down Expand Up @@ -1057,17 +1058,19 @@ class _AnimeDetailsScreenState extends State<AnimeDetailsScreen> {
height: 10,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
padding: const EdgeInsets.symmetric(
horizontal: 16.0),
child: Row(
children: [
const Icon(
Icons.star,
color: Color.fromARGB(255, 229, 166, 57),
),
Text(
"${widget.currentAnime.averageScore} %",
" ${widget.currentAnime.averageScore} %",
style: const TextStyle(
color: Color.fromARGB(255, 229, 166, 57)),
color: Color.fromARGB(
255, 229, 166, 57)),
),
const SizedBox(
width: 10,
Expand All @@ -1083,8 +1086,8 @@ class _AnimeDetailsScreenState extends State<AnimeDetailsScreen> {
),
Text(
widget.currentAnime.status != "RELEASING"
? "Finished"
: "Releasing",
? " Finished"
: " Releasing",
style: TextStyle(
color: widget.currentAnime.status !=
"RELEASING"
Expand All @@ -1099,9 +1102,11 @@ class _AnimeDetailsScreenState extends State<AnimeDetailsScreen> {
Icons.tv,
color: Colors.grey,
),
Text("${widget.currentAnime.format}",
style: const TextStyle(
color: Colors.grey),),
Text(
" ${widget.currentAnime.format}",
style:
const TextStyle(color: Colors.grey),
),
const SizedBox(
width: 10,
),
Expand All @@ -1110,9 +1115,10 @@ class _AnimeDetailsScreenState extends State<AnimeDetailsScreen> {
color: Colors.grey,
),
Text(
"${(widget.currentAnime.episodes ?? currentEpisode)} Episodes",
style: const TextStyle(
color: Colors.grey),),
" ${(widget.currentAnime.episodes ?? currentEpisode)} Episodes",
style:
const TextStyle(color: Colors.grey),
),
const SizedBox(
width: 10,
),
Expand All @@ -1129,7 +1135,8 @@ class _AnimeDetailsScreenState extends State<AnimeDetailsScreen> {
widget.currentAnime.description
?.replaceAll("<br>", "\n")
.replaceAll("<i>", "")
.replaceAll("</i>", "") ??
.replaceAll("<b>", "")
.replaceAll("</b>", "") ??
"",
style: const TextStyle(
color: Colors.white,
Expand All @@ -1143,105 +1150,92 @@ class _AnimeDetailsScreenState extends State<AnimeDetailsScreen> {
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: totalHeight * 0.22,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
const Text(
"Episodes:",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 21,
),
),
const SizedBox(
width: 50,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
height: 35,
width: 55,
decoration: BoxDecoration(
// color: Colors.white,
border: Border.all(color: Colors.white),
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(20),
bottomLeft: Radius.circular(20))),
child: InkWell(
child: const Icon(
Icons.navigate_before,
color: Colors.white,
SizedBox(
width: totalWidth * 0.45,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Row(
children: [
Container(
height: 35,
width: 30,
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(20),
bottomLeft: Radius.circular(20))),
child: InkWell(
child: const Icon(
Icons.navigate_before,
color: Colors.white,
),
onTap: () {
if (currentEpisodes < 1) return;
setState(() {
currentEpisodes--;
});
},
),
onTap: () {
if (currentEpisodes < 1) return;
setState(() {
currentEpisodes--;
});
},
),
),
Container(
height: 35,
width: 100,
decoration: const BoxDecoration(
border: Border(
top: BorderSide(color: Colors.white),
bottom: BorderSide(color: Colors.white),
Container(
height: 35,
width: 85,
decoration: const BoxDecoration(
border: Border(
top: BorderSide(color: Colors.white),
bottom: BorderSide(color: Colors.white),
),
),
),
child: Center(
child: Text(
"${currentEpisodes * 30 + 1} - ${min((30 * (currentEpisodes + 1)), (widget.currentAnime.episodes ?? currentEpisode))}",
style: const TextStyle(
color: Colors.white, fontSize: 17, fontWeight: FontWeight.bold),
child: Center(
child: Text(
"${currentEpisodes * 30 + 1} - ${min((30 * (currentEpisodes + 1)), (widget.currentAnime.episodes ?? currentEpisode))}",
style: const TextStyle(
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.normal),
),
),
),
),
Container(
height: 35,
width: 55,
decoration: BoxDecoration(
// color: Colors.,
border: Border.all(color: Colors.white),
borderRadius: const BorderRadius.only(
topRight: Radius.circular(20),
bottomRight: Radius.circular(20))),
child: InkWell(
child: const Icon(
Icons.navigate_next,
color: Colors.white,
Container(
height: 35,
width: 30,
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
borderRadius: const BorderRadius.only(
topRight: Radius.circular(20),
bottomRight: Radius.circular(20))),
child: InkWell(
child: const Icon(
Icons.navigate_next,
color: Colors.white,
),
onTap: () {
if ((currentEpisodes + 1) * 30 >
(widget.currentAnime.episodes ??
currentEpisode)) return;
setState(() {
currentEpisodes++;
});
},
),
onTap: () {
if ((currentEpisodes + 1) * 30 >
(widget.currentAnime.episodes ??
currentEpisode)) return;
setState(() {
currentEpisodes++;
});
},
),
),
],
),
const SizedBox(
width: 32,
),
],
],
),
],
),
),
const SizedBox(
height: 20,
SizedBox(
height: totalHeight * 0.06,
),
SizedBox(
width: totalWidth / 2,
height: totalHeight * 0.59,
height: totalHeight * 0.57,
child: SmoothListView.builder(
duration: const Duration(milliseconds: 200),
itemCount: (widget.currentAnime.episodes ??
Expand Down Expand Up @@ -1270,6 +1264,10 @@ class _AnimeDetailsScreenState extends State<AnimeDetailsScreen> {
(index + 1 + currentEpisodes * 30),
widget.currentAnime.title ?? "");
},
episodeTitle: mediaContentModel.titles?[
(index + currentEpisodes * 30)],
episodeImageUrl: mediaContentModel.imageUrls?[
(index + currentEpisodes * 30)],
);
},
),
Expand Down
Loading

0 comments on commit 8315ea3

Please sign in to comment.