Skip to content

Commit

Permalink
Add campaign login bonus to sq table
Browse files Browse the repository at this point in the history
  • Loading branch information
narumi147 committed Aug 11, 2024
1 parent 0df7eaf commit cb7e669
Show file tree
Hide file tree
Showing 22 changed files with 268 additions and 146 deletions.
8 changes: 8 additions & 0 deletions lib/app/api/chaldea.dart
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,14 @@ class ChaldeaWorkerApi {
expireAfter: expireAfter,
);
}

static Future<DailyBonusData?> dailyBonusData({Duration? expireAfter}) async {
return cacheManager.getModel(
HostsX.proxyWorker("https://github.com/chaldea-center/daily-login-data/raw/main/JP_119238492/_stats/data.json"),
(data) => DailyBonusData.fromJson(data)..userPresentBox.sortByList((v) => [v.createdAt, v.presentId]),
expireAfter: expireAfter,
);
}
}

class CachedApi {
Expand Down
32 changes: 14 additions & 18 deletions lib/app/modules/saint_quartz/daily_bonus.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'package:chaldea/app/api/chaldea.dart';
import 'package:chaldea/models/gamedata/daily_bonus.dart';
import 'package:chaldea/models/gamedata/toplogin.dart';
import 'package:chaldea/models/models.dart';
import 'package:chaldea/utils/utils.dart';
Expand All @@ -9,26 +7,22 @@ class DailyBonusTab extends StatefulWidget {
DailyBonusTab({super.key});

@override
State<DailyBonusTab> createState() => _DailyBonusTabState();
State<DailyBonusTab> createState() => DailyBonusTabState();
}

class _DailyBonusTabState extends State<DailyBonusTab> {
DailyBonusData? _dailyBonusData;
class DailyBonusTabState extends State<DailyBonusTab> {
DailyBonusData? get _dailyBonusData => db.runtimeData.dailyBonusData;
bool showDaily = false;
bool showExtra = true;

@override
void initState() {
super.initState();
loadData();
}

Future<void> loadData() async {
_dailyBonusData = await CachedApi.cacheManager.getModel(
HostsX.proxyWorker("https://github.com/chaldea-center/daily-login-data/raw/main/JP_119238492/_stats/data.json"),
(data) => DailyBonusData.fromJson(data),
);
if (mounted) setState(() {});
if (_dailyBonusData == null) {
db.runtimeData.loadDailyBonusData().then((v) {
if (mounted) setState(() {});
});
}
}

@override
Expand Down Expand Up @@ -95,18 +89,20 @@ class _DailyBonusTabState extends State<DailyBonusTab> {
header: key,
children: [
if (showDaily)
for (final present in dailyLogins) buildPresent(present, true),
for (final present in dailyLogins)
buildPresent(
context: context, present: present, tileColor: Theme.of(context).disabledColor.withOpacity(0.1)),
if (showExtra)
for (final present in extraBonus) buildPresent(present, false),
for (final present in extraBonus) buildPresent(context: context, present: present),
],
);
}

Widget buildPresent(UserPresentBoxEntity present, bool isDaily) {
static Widget buildPresent({required BuildContext context, required UserPresentBoxEntity present, Color? tileColor}) {
final flags = present.flags;
return ListTile(
dense: true,
tileColor: isDaily ? Theme.of(context).disabledColor.withOpacity(0.1) : null,
tileColor: tileColor,
leading: Gift(
id: 0,
type: GiftType.fromId(present.giftType),
Expand Down
Loading

0 comments on commit cb7e669

Please sign in to comment.