mirror of
https://github.com/darkmoonight/Rain.git
synced 2025-06-29 20:50:01 +00:00
fix notlification
This commit is contained in:
parent
df89d6cdaf
commit
55dfc08d2a
4 changed files with 110 additions and 10 deletions
|
@ -8,6 +8,7 @@ import 'package:rain/app/api/api.dart';
|
|||
import 'package:rain/app/data/weather.dart';
|
||||
import 'package:rain/app/services/notification.dart';
|
||||
import 'package:rain/app/widgets/status.dart';
|
||||
import 'package:rain/app/widgets/status_im_fa.dart';
|
||||
import 'package:rain/main.dart';
|
||||
import 'package:timezone/standalone.dart' as tz;
|
||||
import 'package:lat_lng_to_timezone/lat_lng_to_timezone.dart' as tzmap;
|
||||
|
@ -399,12 +400,15 @@ class LocationController extends GetxController {
|
|||
}
|
||||
|
||||
void notlification(MainWeatherCache mainWeatherCache) {
|
||||
for (var i = 0; i < mainWeatherCache.time!.length; i++) {
|
||||
final weatherNotlification = mainWeatherCache.time
|
||||
?.where((element) => DateTime.parse(element).isAfter(DateTime.now()))
|
||||
.toList();
|
||||
for (var i = 0; i < weatherNotlification!.length; i++) {
|
||||
if (DateTime.parse(mainWeatherCache.time![i]).isAfter(DateTime.now())) {
|
||||
NotificationShow().showNotification(
|
||||
UniqueKey().hashCode,
|
||||
'$city: ${mainWeatherCache.temperature2M}°',
|
||||
Status().getText(mainWeatherCache.weathercode![i]),
|
||||
'$city: ${mainWeatherCache.temperature2M![i]}°',
|
||||
'${Status().getText(mainWeatherCache.weathercode![i])} · ${StatusImFa().getTimeFormat(mainWeatherCache.time![i])}',
|
||||
DateTime.parse(mainWeatherCache.time![i]),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ class Settings {
|
|||
bool? theme;
|
||||
bool location = false;
|
||||
bool notifications = false;
|
||||
int timeRange = 1;
|
||||
bool materialColor = false;
|
||||
bool amoledTheme = false;
|
||||
String measurements = 'metric';
|
||||
|
|
|
@ -62,8 +62,13 @@ const SettingsSchema = CollectionSchema(
|
|||
name: r'theme',
|
||||
type: IsarType.bool,
|
||||
),
|
||||
r'timeformat': PropertySchema(
|
||||
r'timeRange': PropertySchema(
|
||||
id: 9,
|
||||
name: r'timeRange',
|
||||
type: IsarType.long,
|
||||
),
|
||||
r'timeformat': PropertySchema(
|
||||
id: 10,
|
||||
name: r'timeformat',
|
||||
type: IsarType.string,
|
||||
)
|
||||
|
@ -115,7 +120,8 @@ void _settingsSerialize(
|
|||
writer.writeBool(offsets[6], object.notifications);
|
||||
writer.writeBool(offsets[7], object.onboard);
|
||||
writer.writeBool(offsets[8], object.theme);
|
||||
writer.writeString(offsets[9], object.timeformat);
|
||||
writer.writeLong(offsets[9], object.timeRange);
|
||||
writer.writeString(offsets[10], object.timeformat);
|
||||
}
|
||||
|
||||
Settings _settingsDeserialize(
|
||||
|
@ -135,7 +141,8 @@ Settings _settingsDeserialize(
|
|||
object.notifications = reader.readBool(offsets[6]);
|
||||
object.onboard = reader.readBool(offsets[7]);
|
||||
object.theme = reader.readBoolOrNull(offsets[8]);
|
||||
object.timeformat = reader.readString(offsets[9]);
|
||||
object.timeRange = reader.readLong(offsets[9]);
|
||||
object.timeformat = reader.readString(offsets[10]);
|
||||
return object;
|
||||
}
|
||||
|
||||
|
@ -165,6 +172,8 @@ P _settingsDeserializeProp<P>(
|
|||
case 8:
|
||||
return (reader.readBoolOrNull(offset)) as P;
|
||||
case 9:
|
||||
return (reader.readLong(offset)) as P;
|
||||
case 10:
|
||||
return (reader.readString(offset)) as P;
|
||||
default:
|
||||
throw IsarError('Unknown property with id $propertyId');
|
||||
|
@ -798,6 +807,59 @@ extension SettingsQueryFilter
|
|||
});
|
||||
}
|
||||
|
||||
QueryBuilder<Settings, Settings, QAfterFilterCondition> timeRangeEqualTo(
|
||||
int value) {
|
||||
return QueryBuilder.apply(this, (query) {
|
||||
return query.addFilterCondition(FilterCondition.equalTo(
|
||||
property: r'timeRange',
|
||||
value: value,
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
QueryBuilder<Settings, Settings, QAfterFilterCondition> timeRangeGreaterThan(
|
||||
int value, {
|
||||
bool include = false,
|
||||
}) {
|
||||
return QueryBuilder.apply(this, (query) {
|
||||
return query.addFilterCondition(FilterCondition.greaterThan(
|
||||
include: include,
|
||||
property: r'timeRange',
|
||||
value: value,
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
QueryBuilder<Settings, Settings, QAfterFilterCondition> timeRangeLessThan(
|
||||
int value, {
|
||||
bool include = false,
|
||||
}) {
|
||||
return QueryBuilder.apply(this, (query) {
|
||||
return query.addFilterCondition(FilterCondition.lessThan(
|
||||
include: include,
|
||||
property: r'timeRange',
|
||||
value: value,
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
QueryBuilder<Settings, Settings, QAfterFilterCondition> timeRangeBetween(
|
||||
int lower,
|
||||
int upper, {
|
||||
bool includeLower = true,
|
||||
bool includeUpper = true,
|
||||
}) {
|
||||
return QueryBuilder.apply(this, (query) {
|
||||
return query.addFilterCondition(FilterCondition.between(
|
||||
property: r'timeRange',
|
||||
lower: lower,
|
||||
includeLower: includeLower,
|
||||
upper: upper,
|
||||
includeUpper: includeUpper,
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
QueryBuilder<Settings, Settings, QAfterFilterCondition> timeformatEqualTo(
|
||||
String value, {
|
||||
bool caseSensitive = true,
|
||||
|
@ -1045,6 +1107,18 @@ extension SettingsQuerySortBy on QueryBuilder<Settings, Settings, QSortBy> {
|
|||
});
|
||||
}
|
||||
|
||||
QueryBuilder<Settings, Settings, QAfterSortBy> sortByTimeRange() {
|
||||
return QueryBuilder.apply(this, (query) {
|
||||
return query.addSortBy(r'timeRange', Sort.asc);
|
||||
});
|
||||
}
|
||||
|
||||
QueryBuilder<Settings, Settings, QAfterSortBy> sortByTimeRangeDesc() {
|
||||
return QueryBuilder.apply(this, (query) {
|
||||
return query.addSortBy(r'timeRange', Sort.desc);
|
||||
});
|
||||
}
|
||||
|
||||
QueryBuilder<Settings, Settings, QAfterSortBy> sortByTimeformat() {
|
||||
return QueryBuilder.apply(this, (query) {
|
||||
return query.addSortBy(r'timeformat', Sort.asc);
|
||||
|
@ -1180,6 +1254,18 @@ extension SettingsQuerySortThenBy
|
|||
});
|
||||
}
|
||||
|
||||
QueryBuilder<Settings, Settings, QAfterSortBy> thenByTimeRange() {
|
||||
return QueryBuilder.apply(this, (query) {
|
||||
return query.addSortBy(r'timeRange', Sort.asc);
|
||||
});
|
||||
}
|
||||
|
||||
QueryBuilder<Settings, Settings, QAfterSortBy> thenByTimeRangeDesc() {
|
||||
return QueryBuilder.apply(this, (query) {
|
||||
return query.addSortBy(r'timeRange', Sort.desc);
|
||||
});
|
||||
}
|
||||
|
||||
QueryBuilder<Settings, Settings, QAfterSortBy> thenByTimeformat() {
|
||||
return QueryBuilder.apply(this, (query) {
|
||||
return query.addSortBy(r'timeformat', Sort.asc);
|
||||
|
@ -1252,6 +1338,12 @@ extension SettingsQueryWhereDistinct
|
|||
});
|
||||
}
|
||||
|
||||
QueryBuilder<Settings, Settings, QDistinct> distinctByTimeRange() {
|
||||
return QueryBuilder.apply(this, (query) {
|
||||
return query.addDistinctBy(r'timeRange');
|
||||
});
|
||||
}
|
||||
|
||||
QueryBuilder<Settings, Settings, QDistinct> distinctByTimeformat(
|
||||
{bool caseSensitive = true}) {
|
||||
return QueryBuilder.apply(this, (query) {
|
||||
|
@ -1322,6 +1414,12 @@ extension SettingsQueryProperty
|
|||
});
|
||||
}
|
||||
|
||||
QueryBuilder<Settings, int, QQueryOperations> timeRangeProperty() {
|
||||
return QueryBuilder.apply(this, (query) {
|
||||
return query.addPropertyName(r'timeRange');
|
||||
});
|
||||
}
|
||||
|
||||
QueryBuilder<Settings, String, QQueryOperations> timeformatProperty() {
|
||||
return QueryBuilder.apply(this, (query) {
|
||||
return query.addPropertyName(r'timeformat');
|
||||
|
|
|
@ -25,12 +25,9 @@ class _WeatherPageState extends State<WeatherPage> {
|
|||
Widget build(BuildContext context) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
await flutterLocalNotificationsPlugin.cancelAll();
|
||||
await locationController.deleteAll(false);
|
||||
await locationController.setLocation();
|
||||
await flutterLocalNotificationsPlugin.cancelAll();
|
||||
if (settings.notifications) {
|
||||
locationController.notlification(locationController.mainWeather);
|
||||
}
|
||||
setState(() {});
|
||||
},
|
||||
child: SafeArea(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue