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:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user