Options fix
clean up and fixes - Heute gefixt - Code Cleanup NotificationScheduleItemViewModel -fixed NotificationScheduleItemViewModel for Windows compat push implementation Push fixes Push benachrichtungen eingebaut - Status bei push - Push auch in background - Toggle für symtome angepasst push system change exporter update Optionen fix - Optionen aufgeteilt auf 3 tabs - Anpassungen haben jetzt Farbslider Optimierung fix
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using cfs_tracker.Models;
|
||||
using cfs_tracker.Services;
|
||||
using SQLite;
|
||||
using System.Threading;
|
||||
|
||||
namespace cfs_tracker.Data;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ public class HealthEntryRepository
|
||||
public async Task<int> AddQuickEntryAsync(
|
||||
HealthState state,
|
||||
int? activityId = null,
|
||||
int? activityDurationMinutes = null,
|
||||
IEnumerable<int>? symptomIds = null,
|
||||
DateTime? timestamp = null,
|
||||
EntrySource source = EntrySource.App)
|
||||
@@ -23,6 +24,7 @@ public class HealthEntryRepository
|
||||
await _database.InitAsync();
|
||||
|
||||
var effectiveTimestamp = timestamp ?? DateTime.Now;
|
||||
|
||||
var entry = new HealthEntry
|
||||
{
|
||||
EntryDate = effectiveTimestamp.Date,
|
||||
@@ -31,12 +33,14 @@ public class HealthEntryRepository
|
||||
Source = source,
|
||||
DayPart = null,
|
||||
ActivityId = NormalizeActivityId(activityId),
|
||||
ActivityDurationMinutes = NormalizeActivityDuration(activityDurationMinutes),
|
||||
CreatedAt = DateTime.Now,
|
||||
UpdatedAt = DateTime.Now
|
||||
};
|
||||
|
||||
await _database.Connection.InsertAsync(entry);
|
||||
await _symptomRepository.SetSymptomsForEntryAsync(entry.Id, symptomIds);
|
||||
|
||||
return entry.Id;
|
||||
}
|
||||
|
||||
@@ -45,12 +49,14 @@ public class HealthEntryRepository
|
||||
DayPart part = DayPart.Morning,
|
||||
HealthState state = HealthState.Gray,
|
||||
int? activityId = null,
|
||||
int? activityDurationMinutes = null,
|
||||
IEnumerable<int>? symptomIds = null,
|
||||
EntrySource source = EntrySource.Backfill)
|
||||
{
|
||||
await _database.InitAsync();
|
||||
|
||||
var slotTimestamp = BuildBackfillTimestamp(date, part);
|
||||
|
||||
var existing = await _database.Connection.Table<HealthEntry>()
|
||||
.FirstOrDefaultAsync(x => x.Timestamp == slotTimestamp);
|
||||
|
||||
@@ -64,12 +70,14 @@ public class HealthEntryRepository
|
||||
Source = source,
|
||||
DayPart = part,
|
||||
ActivityId = NormalizeActivityId(activityId),
|
||||
ActivityDurationMinutes = NormalizeActivityDuration(activityDurationMinutes),
|
||||
CreatedAt = DateTime.Now,
|
||||
UpdatedAt = DateTime.Now
|
||||
};
|
||||
|
||||
await _database.Connection.InsertAsync(entry);
|
||||
await _symptomRepository.SetSymptomsForEntryAsync(entry.Id, symptomIds);
|
||||
|
||||
return entry.Id;
|
||||
}
|
||||
|
||||
@@ -79,10 +87,12 @@ public class HealthEntryRepository
|
||||
existing.Source = source;
|
||||
existing.DayPart = part;
|
||||
existing.ActivityId = NormalizeActivityId(activityId);
|
||||
existing.ActivityDurationMinutes = NormalizeActivityDuration(activityDurationMinutes);
|
||||
existing.UpdatedAt = DateTime.Now;
|
||||
|
||||
await _database.Connection.UpdateAsync(existing);
|
||||
await _symptomRepository.SetSymptomsForEntryAsync(existing.Id, symptomIds);
|
||||
|
||||
return existing.Id;
|
||||
}
|
||||
|
||||
@@ -91,6 +101,7 @@ public class HealthEntryRepository
|
||||
DateTime date,
|
||||
HealthState state,
|
||||
int? activityId = null,
|
||||
int? activityDurationMinutes = null,
|
||||
IEnumerable<int>? symptomIds = null,
|
||||
DayPart? part = null,
|
||||
EntrySource? source = null)
|
||||
@@ -103,16 +114,23 @@ public class HealthEntryRepository
|
||||
if (entry is null)
|
||||
return;
|
||||
|
||||
var originalTimestamp = entry.Timestamp;
|
||||
|
||||
entry.EntryDate = date.Date;
|
||||
entry.State = state;
|
||||
entry.ActivityId = NormalizeActivityId(activityId);
|
||||
entry.ActivityDurationMinutes = NormalizeActivityDuration(activityDurationMinutes);
|
||||
entry.Source = source ?? entry.Source;
|
||||
entry.DayPart = part;
|
||||
|
||||
if (part.HasValue)
|
||||
{
|
||||
entry.Timestamp = BuildBackfillTimestamp(date, part.Value);
|
||||
else if (date.Date != entry.EntryDate.Date)
|
||||
entry.Timestamp = date.Date + entry.Timestamp.TimeOfDay;
|
||||
}
|
||||
else if (originalTimestamp.Date != date.Date)
|
||||
{
|
||||
entry.Timestamp = date.Date + originalTimestamp.TimeOfDay;
|
||||
}
|
||||
|
||||
entry.UpdatedAt = DateTime.Now;
|
||||
|
||||
@@ -189,5 +207,12 @@ public class HealthEntryRepository
|
||||
};
|
||||
|
||||
private static int? NormalizeActivityId(int? activityId) =>
|
||||
activityId.HasValue && activityId.Value > 0 ? activityId : null;
|
||||
}
|
||||
activityId.HasValue && activityId.Value > 0
|
||||
? activityId
|
||||
: null;
|
||||
|
||||
private static int? NormalizeActivityDuration(int? activityDurationMinutes) =>
|
||||
activityDurationMinutes.HasValue && activityDurationMinutes.Value > 0
|
||||
? activityDurationMinutes
|
||||
: null;
|
||||
}
|
||||
@@ -15,31 +15,160 @@ public class NotificationScheduleRepository
|
||||
{
|
||||
await _database.InitAsync();
|
||||
|
||||
return await _database.Connection.Table<NotificationSchedule>()
|
||||
.OrderBy(x => x.DayOfWeekValue)
|
||||
.ThenBy(x => x.Hour)
|
||||
.ThenBy(x => x.Minute)
|
||||
var list = await _database.Connection.Table<NotificationSchedule>()
|
||||
.ToListAsync();
|
||||
|
||||
return list
|
||||
.OrderBy(x => x.Hour)
|
||||
.ThenBy(x => x.Minute)
|
||||
.ThenBy(x => x.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public async Task ReplaceAllAsync(IEnumerable<NotificationSchedule> schedules)
|
||||
public async Task<NotificationSchedule?> GetByIdAsync(int id)
|
||||
{
|
||||
await _database.InitAsync();
|
||||
|
||||
await _database.Connection.DeleteAllAsync<NotificationSchedule>();
|
||||
|
||||
foreach (var schedule in schedules
|
||||
.OrderBy(x => x.DayOfWeekValue)
|
||||
.ThenBy(x => x.Hour)
|
||||
.ThenBy(x => x.Minute))
|
||||
{
|
||||
await _database.Connection.InsertAsync(new NotificationSchedule
|
||||
{
|
||||
DayOfWeekValue = schedule.DayOfWeekValue,
|
||||
Hour = schedule.Hour,
|
||||
Minute = schedule.Minute,
|
||||
IsEnabled = schedule.IsEnabled
|
||||
});
|
||||
}
|
||||
return await _database.Connection.Table<NotificationSchedule>()
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> AddAsync(
|
||||
int weekdayMask,
|
||||
int hour,
|
||||
int minute,
|
||||
bool isEnabled = true)
|
||||
{
|
||||
await _database.InitAsync();
|
||||
|
||||
var item = new NotificationSchedule
|
||||
{
|
||||
WeekdayMask = NormalizeWeekdayMask(weekdayMask),
|
||||
Hour = NormalizeHour(hour),
|
||||
Minute = NormalizeMinute(minute),
|
||||
IsEnabled = isEnabled
|
||||
};
|
||||
|
||||
await _database.Connection.InsertAsync(item);
|
||||
return item.Id;
|
||||
}
|
||||
|
||||
public async Task SaveAsync(NotificationSchedule item)
|
||||
{
|
||||
await _database.InitAsync();
|
||||
|
||||
if (item is null)
|
||||
return;
|
||||
|
||||
item.WeekdayMask = NormalizeWeekdayMask(item.WeekdayMask);
|
||||
item.Hour = NormalizeHour(item.Hour);
|
||||
item.Minute = NormalizeMinute(item.Minute);
|
||||
|
||||
if (item.Id <= 0)
|
||||
{
|
||||
await _database.Connection.InsertAsync(item);
|
||||
return;
|
||||
}
|
||||
|
||||
var existing = await _database.Connection.Table<NotificationSchedule>()
|
||||
.FirstOrDefaultAsync(x => x.Id == item.Id);
|
||||
|
||||
if (existing is null)
|
||||
{
|
||||
await _database.Connection.InsertAsync(item);
|
||||
return;
|
||||
}
|
||||
|
||||
existing.WeekdayMask = item.WeekdayMask;
|
||||
existing.Hour = item.Hour;
|
||||
existing.Minute = item.Minute;
|
||||
existing.IsEnabled = item.IsEnabled;
|
||||
|
||||
await _database.Connection.UpdateAsync(existing);
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(int id)
|
||||
{
|
||||
await _database.InitAsync();
|
||||
|
||||
var existing = await _database.Connection.Table<NotificationSchedule>()
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (existing is not null)
|
||||
await _database.Connection.DeleteAsync(existing);
|
||||
}
|
||||
|
||||
public async Task DeleteAllAsync()
|
||||
{
|
||||
await _database.InitAsync();
|
||||
await _database.Connection.DeleteAllAsync<NotificationSchedule>();
|
||||
}
|
||||
|
||||
public async Task ReplaceAllAsync(IEnumerable<NotificationSchedule>? items)
|
||||
{
|
||||
await _database.InitAsync();
|
||||
|
||||
var normalized = (items ?? Enumerable.Empty<NotificationSchedule>())
|
||||
.Select(x => new NotificationSchedule
|
||||
{
|
||||
Id = x.Id,
|
||||
WeekdayMask = NormalizeWeekdayMask(x.WeekdayMask),
|
||||
Hour = NormalizeHour(x.Hour),
|
||||
Minute = NormalizeMinute(x.Minute),
|
||||
IsEnabled = x.IsEnabled
|
||||
})
|
||||
.Where(x => x.WeekdayMask != 0)
|
||||
.OrderBy(x => x.Hour)
|
||||
.ThenBy(x => x.Minute)
|
||||
.ThenBy(x => x.Id)
|
||||
.ToList();
|
||||
|
||||
await _database.Connection.RunInTransactionAsync(connection =>
|
||||
{
|
||||
connection.DeleteAll<NotificationSchedule>();
|
||||
|
||||
foreach (var item in normalized)
|
||||
{
|
||||
item.Id = 0;
|
||||
connection.Insert(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static int NormalizeWeekdayMask(int mask)
|
||||
{
|
||||
const int allDaysMask =
|
||||
(int)(
|
||||
NotificationWeekdays.Monday |
|
||||
NotificationWeekdays.Tuesday |
|
||||
NotificationWeekdays.Wednesday |
|
||||
NotificationWeekdays.Thursday |
|
||||
NotificationWeekdays.Friday |
|
||||
NotificationWeekdays.Saturday |
|
||||
NotificationWeekdays.Sunday);
|
||||
|
||||
return mask & allDaysMask;
|
||||
}
|
||||
|
||||
private static int NormalizeHour(int hour)
|
||||
{
|
||||
if (hour < 0)
|
||||
return 0;
|
||||
|
||||
if (hour > 23)
|
||||
return 23;
|
||||
|
||||
return hour;
|
||||
}
|
||||
|
||||
private static int NormalizeMinute(int minute)
|
||||
{
|
||||
if (minute < 0)
|
||||
return 0;
|
||||
|
||||
if (minute > 59)
|
||||
return 59;
|
||||
|
||||
return minute;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using cfs_tracker.Models;
|
||||
using System.Linq;
|
||||
|
||||
namespace cfs_tracker.Data;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user