-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from synyx/material3
Material 3
- Loading branch information
Showing
31 changed files
with
1,023 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:hydrated_bloc/hydrated_bloc.dart'; | ||
|
||
class ThemeModeCubit extends HydratedCubit<ThemeMode> { | ||
ThemeModeCubit() : super(ThemeMode.system); | ||
|
||
bool? get isDark => switch (state) { | ||
ThemeMode.dark => true, | ||
ThemeMode.light => false, | ||
ThemeMode.system => null, | ||
}; | ||
|
||
set dark(bool? dark) => emit(switch (dark) { | ||
true => ThemeMode.dark, | ||
false => ThemeMode.light, | ||
null => ThemeMode.system, | ||
}); | ||
|
||
@override | ||
ThemeMode fromJson(Map<String, dynamic> json) => switch (json['version']) { | ||
<= 1 => switch (json['themeMode']) { | ||
'dark' => ThemeMode.dark, | ||
'light' => ThemeMode.light, | ||
_ => ThemeMode.system, | ||
}, | ||
_ => ThemeMode.system, | ||
}; | ||
|
||
@override | ||
Map<String, dynamic>? toJson(ThemeMode state) { | ||
final themeMode = switch (state) { | ||
ThemeMode.dark => 'dark', | ||
ThemeMode.light => 'light', | ||
_ => 'system', | ||
}; | ||
|
||
return { | ||
'version': 1, | ||
'themeMode': themeMode, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
library time_entries_filter; | ||
|
||
import 'package:built_collection/built_collection.dart'; | ||
import 'package:built_value/built_value.dart'; | ||
import 'package:built_value/json_object.dart'; | ||
import 'package:built_value/serializer.dart'; | ||
import 'package:syntrack/model/common/task.dart'; | ||
|
||
part 'time_entries_filter.g.dart'; | ||
|
||
abstract class TimeEntriesFilter implements Built<TimeEntriesFilter, TimeEntriesFilterBuilder> { | ||
String? get query; | ||
DateTime? get filterStart; | ||
DateTime? get filterEnd; | ||
Duration? get filterDuration; | ||
bool? get filterBooked; | ||
Set<int?> get filterWeekday; | ||
Task? get filterTask; | ||
Set<String?> get filterWorkInterfaceId; | ||
Set<String?> get filterActivityNames; | ||
|
||
TimeEntriesFilter._(); | ||
|
||
factory TimeEntriesFilter([void Function(TimeEntriesFilterBuilder) updates]) = _$TimeEntriesFilter; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import 'package:easy_debounce/easy_debounce.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:syntrack/cubit/time_entries_filter.dart'; | ||
import 'package:syntrack/model/common/time_entry.dart'; | ||
import 'package:syntrack/util/date_time_extension.dart'; | ||
|
||
class TimeEntriesFilterCubit extends Cubit<TimeEntriesFilter> { | ||
TimeEntriesFilterCubit() | ||
: super((TimeEntriesFilterBuilder() | ||
..filterActivityNames = {} | ||
..filterWorkInterfaceId = {} | ||
..filterWeekday = {}) | ||
.build()); | ||
|
||
Iterable<TimeEntry> filter(List<TimeEntry> timeEntries) { | ||
final TimeEntriesFilter( | ||
query: query, | ||
filterActivityNames: filterActivityNames, | ||
filterBooked: filterBooked, | ||
filterTask: filterTask, | ||
filterDuration: filterDuration, | ||
filterWeekday: filterWeekday, | ||
filterWorkInterfaceId: filterWorkInterfaceId, | ||
filterStart: filterStart, | ||
filterEnd: filterEnd, | ||
) = state; | ||
|
||
if (query == null && | ||
filterActivityNames.isEmpty && | ||
filterBooked == null && | ||
filterTask == null && | ||
filterDuration == null && | ||
filterWeekday.isEmpty && | ||
filterWorkInterfaceId.isEmpty && | ||
filterStart == null && | ||
filterEnd == null) { | ||
return timeEntries; | ||
} | ||
|
||
return timeEntries | ||
.where( | ||
(element) => query != null | ||
? '${element.comment.trim()}${element.task?.name ?? '<NO TASK>'}${element.activity?.name ?? '<NO ACTIVITY>'}' | ||
.toLowerCase() | ||
.contains(query.trim().toLowerCase()) | ||
: true, | ||
) | ||
.where( | ||
(element) => filterActivityNames.isNotEmpty ? filterActivityNames.contains(element.activity?.name) : true, | ||
) | ||
.where( | ||
(element) => filterBooked != null | ||
? filterBooked | ||
? element.bookingId != null | ||
: element.bookingId == null | ||
: true, | ||
) | ||
.where( | ||
(element) => filterTask != null ? element.task?.id == filterTask.id : true, | ||
) | ||
.where( | ||
(element) => filterWeekday.isNotEmpty ? filterWeekday.contains(element.start.weekday) : true, | ||
) | ||
.where( | ||
(element) => | ||
filterWorkInterfaceId.isNotEmpty ? filterWorkInterfaceId.contains(element.task?.workInterfaceId) : true, | ||
) | ||
.where( | ||
(element) => filterStart != null ? element.start.startOfDay == filterStart.startOfDay : true, | ||
) | ||
.where( | ||
(element) => filterEnd != null ? element.end.startOfDay == filterEnd.startOfDay : true, | ||
) | ||
.where( | ||
(element) => filterDuration != null ? filterDuration.inSeconds <= element.duration.inSeconds : true, | ||
); | ||
} | ||
|
||
void debouncedFilters(Function(TimeEntriesFilterBuilder) updates) { | ||
EasyDebounce.debounce('time_entries_filter_cubit.debouncedFilters', const Duration(milliseconds: 500), () { | ||
setFilters(updates); | ||
}); | ||
} | ||
|
||
void setFilters(Function(TimeEntriesFilterBuilder) updates) { | ||
emit(state.rebuild(updates)); | ||
} | ||
|
||
void clearFilters() { | ||
emit(state.rebuild((p0) => p0 | ||
..filterActivityNames = const {} | ||
..filterBooked = null | ||
..filterTask = null | ||
..filterDuration = null | ||
..filterWeekday = const {} | ||
..filterWorkInterfaceId = const {} | ||
..filterStart = null | ||
..filterEnd = null)); | ||
} | ||
|
||
void debouncedQuery(String? query) { | ||
EasyDebounce.debounce( | ||
'time_entries_filter_cubit.debouncedQuery', | ||
const Duration(milliseconds: 750), | ||
() { | ||
immediateQuery(query); | ||
}, | ||
); | ||
} | ||
|
||
void immediateQuery(String? query) { | ||
emit(state.rebuild((state) => state..query = query)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.