Skip to content

Commit

Permalink
fix: notify
Browse files Browse the repository at this point in the history
  • Loading branch information
whes1015 committed Sep 8, 2024
1 parent e2a7240 commit 6210c51
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
14 changes: 0 additions & 14 deletions lib/api/exptech.dart
Original file line number Diff line number Diff line change
Expand Up @@ -471,20 +471,6 @@ class ExpTech {
}
}

Future<String> sendNotifyTest(String token, String sound, String lat, String lng) async {
final requestUrl = Route.notifyTest(token, sound, lat, lng);

var res = await get(requestUrl);

if (res.statusCode == 200) {
return res.body;
} else if (res.statusCode == 204) {
return "${res.statusCode} $requestUrl";
} else {
throw HttpException("The server returned a status of ${res.statusCode}", uri: requestUrl);
}
}

Future<MeteorStation> getMeteorStation(String id) async {
final requestUrl = Route.meteorStation(id);

Expand Down
3 changes: 0 additions & 3 deletions lib/api/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,4 @@ class Route {

static Uri monitor(String token, String status) => Uri.parse(
"https://api-1.exptech.dev/api/v1/notify/setting/$token/$status/${DateTime.now().millisecondsSinceEpoch}");

static Uri notifyTest(String token, String sound, String lat, String lng) => Uri.parse(
"https://api-1.exptech.dev/api/v1/notify/test/${Global.packageInfo.version}/${Platform.isIOS ? 1 : 0}/$lat,$lng/$token/$sound/${DateTime.now().millisecondsSinceEpoch}");
}
30 changes: 14 additions & 16 deletions lib/widget/settings/sound/sound_list_tile.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import "dart:io";

import "package:dpip/api/exptech.dart";
import "package:awesome_notifications/awesome_notifications.dart";
import "package:dpip/core/ios_get_location.dart";
import "package:dpip/global.dart";
import "package:dpip/util/extension/build_context.dart";
import "package:dpip/util/need_location.dart";
import "package:dpip/util/speed_limit.dart";
import "package:flutter/material.dart";
import "package:material_symbols_icons/symbols.dart";

Expand Down Expand Up @@ -52,20 +51,19 @@ class SoundListTileState extends State<SoundListTile> {
if (!isUserLocationValid && !(Global.preference.getBool("auto-location") ?? false)) {
await showLocationDialog(context);
} else {
String token = Global.preference.getString("fcm-token") ?? "";
if (token != "") {
int limit = Global.preference.getInt("limit-sound-test") ?? 0;
int now = DateTime.now().millisecondsSinceEpoch;
if (now - limit < 10000) {
showLimitDialog(context);
} else {
Global.preference.setInt("limit-sound-test", now);
await ExpTech().sendNotifyTest(token, widget.type, userLat.toString(), userLon.toString());
}
} else {
context.scaffoldMessenger.showSnackBar(
SnackBar(
content: Text(context.i18n.error_fcm_token),
int limit = Global.preference.getInt("limit-sound-test") ?? 0;
int now = DateTime.now().millisecondsSinceEpoch;
if (now - limit > 1000) {
Global.preference.setInt("limit-sound-test", now);
print("test");
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 10,
channelKey: 'eew_alert-important',
title: '重大通知',
body: '這是一個包含重大通知的重要訊息。',
notificationLayout: NotificationLayout.BigText,
criticalAlert: true,
),
);
}
Expand Down

0 comments on commit 6210c51

Please sign in to comment.