Skip to content

Commit

Permalink
Add widget album collection status dialog #112
Browse files Browse the repository at this point in the history
  • Loading branch information
up2code committed Mar 13, 2021
1 parent e023efd commit 10d5eed
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 7 deletions.
19 changes: 15 additions & 4 deletions lib/src/controllers/album_detail_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import 'package:vocadb_app/services.dart';
class AlbumDetailController extends GetxController {
final collectionStatus = AlbumCollectionStatusModel().obs;

final purchaseStatus = "".obs;

final mediaType = "".obs;

final rating = 0.obs;

final initialLoading = true.obs;

final statusLoading = true.obs;
Expand Down Expand Up @@ -51,13 +57,18 @@ class AlbumDetailController extends GetxController {
return Future.value();
}

//TODO: Wait for API backend implementation
return userRepository
.getCurrentUserAlbumCollection(album().id)
.then((AlbumCollectionStatusModel model) {
return (model == null)
? AlbumCollectionStatusModel()
: collectionStatus(model);
if (model == null) {
return AlbumCollectionStatusModel();
}

this.purchaseStatus(model.purchaseStatus);
this.mediaType(model.mediaType);
this.rating(model.rating);

return collectionStatus(model);
})
.then((artist) => debounce(
collectionStatus, (_) => updateAlbumCollection(),
Expand Down
97 changes: 96 additions & 1 deletion lib/src/pages/album_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,19 @@ class AlbumDetailPageView extends StatelessWidget {

void _onSelectTag(TagModel tag) => AppPages.toTagDetailPage(tag);

void _onTapCollectButton() {}
void _onTapCollectButton() {
Get.dialog(Obx(
() => AlbumCollectionStatusDialog(
purchaseStatus: controller.purchaseStatus.value,
mediaType: controller.mediaType.value,
rating: controller.rating.value,
onPurchaseStatusChanged: controller.purchaseStatus,
onMediaTypeChanged: controller.mediaType,
onRatingChanged: (String rating) =>
controller.rating(int.parse(rating)),
),
));
}

Widget _buttonBarBuilder() {
final authService = Get.find<AuthService>();
Expand Down Expand Up @@ -208,3 +220,86 @@ class AlbumDetailPageView extends StatelessWidget {
));
}
}

class AlbumCollectionStatusDialog extends StatelessWidget {
final String purchaseStatus;

final String mediaType;

final int rating;

final Function(String) onPurchaseStatusChanged;

final Function(String) onMediaTypeChanged;

final Function(String) onRatingChanged;

final Function(String, String, String) onSaved;

const AlbumCollectionStatusDialog(
{this.purchaseStatus,
this.mediaType,
this.rating,
this.onPurchaseStatusChanged,
this.onMediaTypeChanged,
this.onRatingChanged,
this.onSaved});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Edit album in collection"),
actions: [
IconButton(
icon: const Icon(Icons.save),
onPressed: () {
this.onSaved(this.purchaseStatus, this.mediaType,
this.rating.toString());
Get.close(0);
})
],
),
body: Container(
child: Column(
children: [
SimpleDropdownInput.fromJsonArray(
label: 'Status',
value: purchaseStatus,
onChanged: this.onPurchaseStatusChanged,
json: [
{'name': 'Nothing'.tr, 'value': ''},
{'name': 'Wishlisted'.tr, 'value': 'Wishlisted'},
{'name': 'Ordered'.tr, 'value': 'Ordered'},
{'name': 'Owned'.tr, 'value': 'Owned'},
],
),
SimpleDropdownInput.fromJsonArray(
label: 'Media type',
value: mediaType,
onChanged: this.onMediaTypeChanged,
json: [
{'name': 'Unspecified'.tr, 'value': ''},
{'name': 'Physical disc'.tr, 'value': 'PhysicalDisc'},
{'name': 'Digital download'.tr, 'value': 'DigitalDownload'},
],
),
SimpleDropdownInput.fromJsonArray(
label: 'Rating',
value: rating.toString(),
onChanged: this.onRatingChanged,
json: [
{'name': 'Nothing'.tr, 'value': '0'},
{'name': '1', 'value': '1'},
{'name': '2', 'value': '2'},
{'name': '3', 'value': '3'},
{'name': '4', 'value': '4'},
{'name': '5', 'value': '5'}
],
),
],
),
),
);
}
}
2 changes: 0 additions & 2 deletions lib/src/repositories/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,3 @@ class UserRepository extends RestApiRepository {
});
}
}

enum PurchaseStatus { Wishlisted, Ordered, Owned, paused }

0 comments on commit 10d5eed

Please sign in to comment.