Skip to content

Commit

Permalink
🔒 Add Patreon logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaoz-Topsy committed Sep 23, 2024
1 parent 6bfcadc commit f7b78bb
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ void handlePatreonBottomModalSheetWhenTapped(
bool isPatron, {
required DateTime unlockDate,
required void Function(BuildContext dialogCtx) onTap,
Future<void> Function(BuildContext dialogCtx)? onSettingsTap,
}) {
bool isLocked = isPatreonFeatureLocked(unlockDate, isPatron);
if (isLocked == false) {
Expand All @@ -143,8 +142,11 @@ void handlePatreonBottomModalSheetWhenTapped(
navContext,
hasRoundedCorners: true,
builder: (BuildContext innerContext) => PatreonModalBottomSheet(
onSettingsTap: onSettingsTap,
unlockDate: unlockDate,
onSettingsTap: (navCtx) => getNavigation().navigateAwayFromHomeAsync(
navCtx,
navigateToNamed: Routes.settings,
),
onTap: onTap,
),
);
Expand Down
28 changes: 23 additions & 5 deletions lib/components/tilePresenters/bait_tile_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:assistantapps_flutter_common/assistantapps_flutter_common.dart';
import 'package:flutter/material.dart';

import '../../constants/app_image.dart';
import '../../constants/patreon.dart';
import '../../constants/routes.dart';
import '../../contracts/data/bait_data.dart';
import '../../contracts/fishing/good_guy_free_bait_view_model.dart';
Expand All @@ -10,6 +11,7 @@ import '../../helpers/generic_helper.dart';
import '../../integration/dependency_injection.dart';
import '../../pages/generic/generic_page.dart';
import '../modalBottomSheet/good_guys_free_modal_bottom_sheet.dart';
import 'patreon_tile_presenter.dart';

class BaitDataWithItemDetails {
BaitData bait;
Expand Down Expand Up @@ -331,11 +333,25 @@ Widget ggfBaitTilePresenter(
List<Widget> ggfBaitOnCatalogueTilePresenter(
BuildContext context,
String itemId,
bool isPatronLocked,
) {
return [
var title = getTranslations().fromKey(LocaleKey.fishingBait);
List<Widget> updateWidgets = [
const EmptySpace3x(),
GenericItemText(getTranslations().fromKey(LocaleKey.fishingBait)),
CachedFutureBuilder(
GenericItemText(title),
];

if (isPatronLocked) {
updateWidgets.add(FlatCard(
child: patronFeatureTilePresenter(
context,
title,
Routes.fishingLocations,
PatreonEarlyAccessFeature.fishingDataPage,
),
));
} else {
updateWidgets.add(CachedFutureBuilder(
future: getApiRepo().getGoodGuyFreeBaitForItem(
getTranslations().currentLanguage,
itemId,
Expand Down Expand Up @@ -366,6 +382,8 @@ List<Widget> ggfBaitOnCatalogueTilePresenter(
},
);
},
),
];
));
}

return updateWidgets;
}
48 changes: 20 additions & 28 deletions lib/components/tilePresenters/patreon_tile_presenter.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'package:assistantapps_flutter_common/assistantapps_flutter_common.dart';
import 'package:flutter/material.dart';

import '../../constants/app_image.dart';
import '../../constants/nms_ui_constants.dart';
import '../dialogs/pretty_dialog.dart';
import '../modalBottomSheet/patreon_modal_bottom_sheet.dart';

Widget patronTilePresenter(BuildContext context, PatreonViewModel patron) {
if (patron.url == ExternalUrls.patreon) {
Expand All @@ -27,9 +25,12 @@ Widget patronTilePresenter(BuildContext context, PatreonViewModel patron) {
);
}

Widget patronFeatureTilePresenter(BuildContext context, String featureName,
String navigateToNamed, DateTime unlockDate) {
var isFeatureAvailable = DateTime.now().isAfter(unlockDate);
Widget patronFeatureTilePresenter(
BuildContext context,
String featureName,
String navigateToNamed,
DateTime unlockDate,
) {
var timeDiff =
unlockDate.millisecondsSinceEpoch - DateTime.now().millisecondsSinceEpoch;
var descripText =
Expand All @@ -38,28 +39,19 @@ Widget patronFeatureTilePresenter(BuildContext context, String featureName,
'{0}',
getFriendlyTimeLeft(context, timeDiff),
);
void Function() onTap;
onTap = () {
Future Function() navigateAway;
navigateAway = () => getNavigation().navigateAwayFromHomeAsync(
context,
navigateToNamed: navigateToNamed,
);
if (isFeatureAvailable) {
navigateAway();
return;
}

prettyDialog(
context,
AppImage.patreonFeature,
getTranslations().fromKey(LocaleKey.featureNotAvailable),
descrip,
okButtonText: getTranslations().fromKey(LocaleKey.patreon),
buttonOkColor: HexColor(NMSUIConstants.PatreonHex),
onSuccess: (_) => launchExternalURL(ExternalUrls.patreon),
void Function(BuildContext) onTap;
onTap = (navCtx) {
handlePatreonBottomModalSheetWhenTapped(
navCtx,
false,
unlockDate: unlockDate,
onTap: (innerNavCtx) => getNavigation().navigateAwayFromHomeAsync(
innerNavCtx,
navigateToNamed: navigateToNamed,
),
);
};

return FlatCard(
child: ListTile(
leading: DonationImage.patreon(),
Expand All @@ -76,9 +68,9 @@ Widget patronFeatureTilePresenter(BuildContext context, String featureName,
trailing: IconButton(
icon: const Icon(Icons.help),
iconSize: 32.0,
onPressed: onTap,
onPressed: () => onTap(context),
),
onTap: onTap,
onTap: () => onTap(context),
),
);
}
1 change: 1 addition & 0 deletions lib/constants/patreon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class PatreonEarlyAccessFeature {
static DateTime newMilestonesPage = DateTime(2022, 4, 1);
static DateTime newMajorUpdatesPage = DateTime(2022, 6, 18);
static DateTime syncInventoryPage = DateTime(2022, 12, 24);
static DateTime fishingDataPage = DateTime(2024, 10, 1);
}

bool isPatreonFeatureLocked(DateTime unlockDate, bool isPatron) {
Expand Down
20 changes: 20 additions & 0 deletions lib/contracts/misc/custom_menu.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:assistantapps_flutter_common/assistantapps_flutter_common.dart';
import 'package:flutter/material.dart';

import '../../components/modalBottomSheet/patreon_modal_bottom_sheet.dart';
import '../../constants/app_image.dart';
import '../../constants/patreon.dart';
import '../../constants/routes.dart';
import '../../redux/modules/setting/drawer_settings_view_model.dart';
import '../enum/homepage_type.dart';
Expand Down Expand Up @@ -327,6 +329,24 @@ List<CustomMenu> getMenuOptionsSection3(
drawerIcon: localGetDrawerFromIcon(Icons.phishing),
title: LocaleKey.fishing,
navigateToNamed: Routes.fishing,
isNew: DateTime.now().isBefore(PatreonEarlyAccessFeature.fishingDataPage),
isLocked: isPatreonFeatureLocked(
PatreonEarlyAccessFeature.fishingDataPage,
vm.isPatron,
),
onTap: (tapCtx) {
handlePatreonBottomModalSheetWhenTapped(
tapCtx,
vm.isPatron,
unlockDate: PatreonEarlyAccessFeature.fishingDataPage,
onTap: (navCtx) {
getNavigation().navigateAwayFromHomeAsync(
navCtx,
navigateToNamed: Routes.fishing,
);
},
);
},
),
// CustomMenu(
// icon: const ListTileImage(partialPath:AppImage.techTree, size: imageSize),
Expand Down
6 changes: 3 additions & 3 deletions lib/env/app_version_num.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const appsBuildNum = 342;
const appsBuildName = '2.27.1';
const appsCommit = '8fd62ef90ab7144cad1d016ec4fd3c7a84c2d538';
const appsBuildNum = 343;
const appsBuildName = '2.28.0';
const appsCommit = 'ea0e5d94ca1f08274ffebe3f15679bf56a63c244';
2 changes: 2 additions & 0 deletions lib/helpers/future_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Future<ResultWithValue<GenericPageItem>> genericItemFuture(
context,
String itemId,
int platformIndex,
bool isPatron,
) async {
ResultWithValue<IGenericRepository?> genRepo = getRepoFromId(context, itemId);
if (genRepo.hasFailed) {
Expand Down Expand Up @@ -105,6 +106,7 @@ Future<ResultWithValue<GenericPageItem>> genericItemFuture(
if (usage.contains(UsageKey.hasCreatureHarvest)) {
item.creatureHarvests = await creatureHarvestsFuture(context, itemId);
}

if (usage.contains(UsageKey.hasFishingLocation)) {
item.fishingData = await fishingLocationFuture(context, itemId);
}
Expand Down
10 changes: 10 additions & 0 deletions lib/pages/generic/generic_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import '../../components/tilePresenters/required_item_details_tile_presenter.dar
import '../../components/tilePresenters/required_item_tile_presenter.dart';
import '../../constants/analytics_event.dart';
import '../../constants/nms_ui_constants.dart';
import '../../constants/patreon.dart';
import '../../constants/usage_key.dart';
import '../../contracts/cart/cart_item.dart';
import '../../contracts/charge_by.dart';
Expand Down Expand Up @@ -62,6 +63,7 @@ class GenericPage extends StatelessWidget {
storeCtx,
itemId,
viewModel.platformIndex,
viewModel.isPatron,
),
whileLoading: () => (itemTopContent != null) //
? itemTopContent
Expand Down Expand Up @@ -294,24 +296,32 @@ class GenericPage extends StatelessWidget {

// ---------------------------- Fishing Data -----------------------------

var isFishingLocked = isPatreonFeatureLocked(
PatreonEarlyAccessFeature.fishingDataPage,
vm.isPatron,
);

if (genericItem.fishingData != null) {
widgets.addAll(getFishingLocation(
bodyCtx,
genericItem.fishingData!,
isFishingLocked,
));
}

if (genericItem.fishingBait != null) {
widgets.addAll(getFishingBait(
bodyCtx,
genericItem.fishingBait!,
isFishingLocked,
));
}

if (genericItem.hasGoodGuyFreeBait == true) {
widgets.addAll(ggfBaitOnCatalogueTilePresenter(
bodyCtx,
genericItem.id,
isFishingLocked,
));
}

Expand Down
77 changes: 58 additions & 19 deletions lib/pages/generic/generic_page_components.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:assistantapps_flutter_common/assistantapps_flutter_common.dart';
import 'package:assistantnms_app/components/tilePresenters/fishing_page_tile_presenter.dart';
import 'package:assistantnms_app/constants/patreon.dart';
import 'package:assistantnms_app/contracts/fishing/fishing_data.dart';
import 'package:ff_stars/ff_stars.dart';
import 'package:flutter/material.dart';
Expand All @@ -10,6 +11,7 @@ import '../../components/tilePresenters/creature_harvest_tile_presenter.dart';
import '../../components/tilePresenters/egg_trait_tile_presenter.dart';
import '../../components/tilePresenters/inventory_tile_presenter.dart';
import '../../components/tilePresenters/major_update_tile_presenter.dart';
import '../../components/tilePresenters/patreon_tile_presenter.dart';
import '../../components/tilePresenters/required_item_tile_presenter.dart';
import '../../components/tilePresenters/reward_from_tile_presenter.dart';
import '../../components/tilePresenters/seasonal_expedition_tile_presenter.dart';
Expand Down Expand Up @@ -690,41 +692,78 @@ List<Widget> getFromUpdate(
return updateWidgets;
}

List<Widget> getFishingLocation(BuildContext context, FishingData fishingData) {
List<Widget> getFishingLocation(
BuildContext context,
FishingData fishingData,
bool isPatronLocked,
) {
List<Widget> updateWidgets = List.empty(growable: true);
updateWidgets.add(const EmptySpace3x());
String title = getTranslations().fromKey(LocaleKey.fishingLocation);
updateWidgets.add(GenericItemText(title));
fishingData.icon = AppImage.fishingLocation;
updateWidgets.add(FlatCard(
child: fishingDataTilePresenter(context, fishingData),
));

if (isPatronLocked) {
updateWidgets.add(FlatCard(
child: patronFeatureTilePresenter(
context,
title,
Routes.fishingLocations,
PatreonEarlyAccessFeature.fishingDataPage,
),
));
} else {
fishingData.icon = AppImage.fishingBait;
updateWidgets.add(FlatCard(
child: fishingDataTilePresenter(
context,
fishingData,
onTap: () {
getNavigation().navigateAwayFromHomeAsync(
context,
navigateToNamed: Routes.fishingLocations,
);
},
),
));
}

return updateWidgets;
}

List<Widget> getFishingBait(
BuildContext context,
BaitDataWithItemDetails fishingBait,
bool isPatronLocked,
) {
List<Widget> updateWidgets = List.empty(growable: true);
updateWidgets.add(const EmptySpace3x());
String title = getTranslations().fromKey(LocaleKey.fishingBait);
updateWidgets.add(GenericItemText(title));
fishingBait.itemDetails.icon = AppImage.fishingBait;
updateWidgets.add(FlatCard(
child: baitTilePresenter(
context,
fishingBait,
wrapInCard: false,
onTap: () {
getNavigation().navigateAwayFromHomeAsync(
context,
navigateToNamed: Routes.fishingBait,
);
},
),
));
if (isPatronLocked) {
updateWidgets.add(FlatCard(
child: patronFeatureTilePresenter(
context,
title,
Routes.fishingLocations,
PatreonEarlyAccessFeature.fishingDataPage,
),
));
} else {
fishingBait.itemDetails.icon = AppImage.fishingBait;
updateWidgets.add(FlatCard(
child: baitTilePresenter(
context,
fishingBait,
wrapInCard: false,
onTap: () {
getNavigation().navigateAwayFromHomeAsync(
context,
navigateToNamed: Routes.fishingBait,
);
},
),
));
}

return updateWidgets;
}

0 comments on commit f7b78bb

Please sign in to comment.