Skip to content

Commit

Permalink
Merge pull request #9 from ajxv/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
ajxv authored Dec 31, 2023
2 parents f4eb712 + 221f082 commit ce83cc7
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 38 deletions.
27 changes: 18 additions & 9 deletions lib/providers/entry_status_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import 'package:fluttertoast/fluttertoast.dart';
import '../services/mal_services.dart';

class EntryStatusProvider extends ChangeNotifier {
String initialStatus = '';
String _initialStatus = '';
int _totalCount = 0;

final _myListStatus = {};

get myListStatus => _myListStatus;
Expand All @@ -21,7 +23,9 @@ class EntryStatusProvider extends ChangeNotifier {

// load status from myliststatus object
void loadListStatus(isAnime, myListStatus, totalCount) {
initialStatus = myListStatus.status;
_initialStatus = myListStatus.status;
_totalCount = totalCount;

setMyListStatus(
status: myListStatus.status,
score: myListStatus.score,
Expand All @@ -34,6 +38,11 @@ class EntryStatusProvider extends ChangeNotifier {

// update status
void updateStatus(entryId, isAnime, refreshFunction) {
// if all episodes watched / chapters read, automatically mark as completed
if (_totalCount != 0 && _myListStatus['completed'] == _totalCount) {
_myListStatus['status'] = 'completed';
}

if (isAnime) {
MyAnimelistApi()
.updateListAnime(
Expand All @@ -47,9 +56,9 @@ class EntryStatusProvider extends ChangeNotifier {
Fluttertoast.showToast(msg: "Updated");

// refresh lists
if (initialStatus.isNotEmpty &&
initialStatus != _myListStatus['status']) {
refreshFunction(initialStatus);
if (_initialStatus.isNotEmpty &&
_initialStatus != _myListStatus['status']) {
refreshFunction(_initialStatus);
}

refreshFunction(_myListStatus['status']);
Expand All @@ -71,8 +80,8 @@ class EntryStatusProvider extends ChangeNotifier {
Fluttertoast.showToast(msg: "Updated");

// refresh lists
if (initialStatus != _myListStatus['status']) {
refreshFunction(initialStatus);
if (_initialStatus != _myListStatus['status']) {
refreshFunction(_initialStatus);
}

refreshFunction(_myListStatus['status']);
Expand All @@ -89,7 +98,7 @@ class EntryStatusProvider extends ChangeNotifier {
if (isAnime) {
MyAnimelistApi().removeListAnime(animeId: entryId).then((value) {
// refresh list
refreshFunction(initialStatus);
refreshFunction(_initialStatus);
// show toast
Fluttertoast.showToast(msg: "Removed from List");
}).catchError((error) {
Expand All @@ -98,7 +107,7 @@ class EntryStatusProvider extends ChangeNotifier {
} else {
MyAnimelistApi().removeListManga(mangaId: entryId).then((value) {
// refresh list
refreshFunction(initialStatus);
refreshFunction(_initialStatus);
// show toast
Fluttertoast.showToast(msg: "Removed from List");
}).catchError((error) {
Expand Down
10 changes: 5 additions & 5 deletions lib/screens/entry_details_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class _EntryDetailPageState extends State<EntryDetailPage> {
// basic details
BasicDetailSection(
imageUrl: entryDetails.mainPicture.large,
animeTitle: entryDetails.title,
title: entryDetails.title,
mediaType: entryDetails.mediaType,
airingStatus: entryDetails.status,
meanScore: entryDetails.mean,
Expand Down Expand Up @@ -480,7 +480,7 @@ class _EntryDetailPageState extends State<EntryDetailPage> {

class BasicDetailSection extends StatelessWidget {
final String imageUrl;
final String animeTitle;
final String title;
final String mediaType;
final String airingStatus;
final double meanScore;
Expand All @@ -490,7 +490,7 @@ class BasicDetailSection extends StatelessWidget {
const BasicDetailSection({
super.key,
required this.imageUrl,
required this.animeTitle,
required this.title,
required this.mediaType,
required this.airingStatus,
required this.meanScore,
Expand Down Expand Up @@ -530,11 +530,11 @@ class BasicDetailSection extends StatelessWidget {
children: [
GestureDetector(
onLongPress: () async {
await Clipboard.setData(ClipboardData(text: animeTitle));
await Clipboard.setData(ClipboardData(text: title));
Fluttertoast.showToast(msg: "Title copied to clipboard");
},
child: Text(
animeTitle,
title,
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
Expand Down
24 changes: 14 additions & 10 deletions lib/screens/homepage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ class _HomePageState extends State<HomePage> {
),
);
},
icon: CircleAvatar(
radius: 15,
backgroundImage: Provider.of<SessionProvider>(context)
.user
.picture
.isNotEmpty
? CachedNetworkImageProvider(
context.read<SessionProvider>().user.picture)
: const AssetImage("assets/images/profile_placeholder.jpeg")
as ImageProvider)),
icon: Hero(
tag: "profileImage",
child: CircleAvatar(
radius: 15,
backgroundImage: Provider.of<SessionProvider>(context)
.user
.picture
.isNotEmpty
? CachedNetworkImageProvider(
context.read<SessionProvider>().user.picture)
: const AssetImage(
"assets/images/profile_placeholder.jpeg")
as ImageProvider),
)),
title: Text(
"ฅᨐฅ",
style: TextStyle(
Expand Down
30 changes: 18 additions & 12 deletions lib/screens/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class Profile extends StatelessWidget {
),
);
},
icon: const Icon(Icons.settings),
icon: const Hero(
tag: "settings",
child: Icon(Icons.settings),
),
)
],
),
Expand All @@ -46,19 +49,22 @@ class Profile extends StatelessWidget {
padding: const EdgeInsets.all(10),
children: [
const SizedBox(height: 20),
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: value.user.picture.isNotEmpty
? CachedNetworkImageProvider(value.user.picture)
: const AssetImage(
"assets/images/profile_placeholder.jpeg")
as ImageProvider,
fit: BoxFit.contain,
Hero(
tag: "profileImage",
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: value.user.picture.isNotEmpty
? CachedNetworkImageProvider(value.user.picture)
: const AssetImage(
"assets/images/profile_placeholder.jpeg")
as ImageProvider,
fit: BoxFit.contain,
),
shape: BoxShape.circle,
),
shape: BoxShape.circle,
height: 150,
),
height: 150,
),
const SizedBox(height: 15),
Text(
Expand Down
5 changes: 4 additions & 1 deletion lib/screens/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ class SettingsPage extends StatelessWidget {
backgroundColor: Theme.of(context).colorScheme.background,
leading: IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: const Icon(Icons.chevron_left),
icon: Hero(
tag: "settings",
child: const Icon(Icons.chevron_left),
),
),
title: const Text(
"Settings",
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.2+1
version: 1.1.0+1

environment:
sdk: '>=3.0.5 <4.0.0'
Expand Down

0 comments on commit ce83cc7

Please sign in to comment.