forked from firka/student-legacy
fixed live activity coloring
This commit is contained in:
parent
ee0e724b8a
commit
67649cc5fd
@ -11,6 +11,17 @@ struct Widgets: WidgetBundle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// text contrast background
|
||||||
|
extension Text {
|
||||||
|
func getContrastText(backgroundColor: Color) -> some View {
|
||||||
|
var r, g, b, a: CGFloat
|
||||||
|
(r, g, b, a) = (0, 0, 0, 0)
|
||||||
|
UIColor(backgroundColor).getRed(&r, green: &g, blue: &b, alpha: &a)
|
||||||
|
let luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b
|
||||||
|
return luminance < 0.6 ? self.foregroundColor(.white) : self.foregroundColor(.black)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Color Converter
|
// Color Converter
|
||||||
extension Color {
|
extension Color {
|
||||||
init(hex: String, alpha: Double = 1.0) {
|
init(hex: String, alpha: Double = 1.0) {
|
||||||
@ -62,7 +73,6 @@ struct LockScreenLiveActivityView: View {
|
|||||||
.font(.body)
|
.font(.body)
|
||||||
.bold()
|
.bold()
|
||||||
.padding(.trailing, 90)
|
.padding(.trailing, 90)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
MultilineTextView(text: "\(context.state.index) \(context.state.title) - \(context.state.subtitle)", limit: 25)
|
MultilineTextView(text: "\(context.state.index) \(context.state.title) - \(context.state.subtitle)", limit: 25)
|
||||||
.font(.body)
|
.font(.body)
|
||||||
@ -84,6 +94,7 @@ struct LockScreenLiveActivityView: View {
|
|||||||
.resizable()
|
.resizable()
|
||||||
.aspectRatio(contentMode: .fit)
|
.aspectRatio(contentMode: .fit)
|
||||||
.frame(width: CGFloat(8), height: CGFloat(8))
|
.frame(width: CGFloat(8), height: CGFloat(8))
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
Text("\(context.state.nextSubject) - \(context.state.nextRoom)")
|
Text("\(context.state.nextSubject) - \(context.state.nextRoom)")
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
}
|
}
|
||||||
@ -107,11 +118,15 @@ struct LockScreenLiveActivityView: View {
|
|||||||
.monospacedDigit()
|
.monospacedDigit()
|
||||||
.padding(.trailing)
|
.padding(.trailing)
|
||||||
}
|
}
|
||||||
|
// .activityBackgroundTint(
|
||||||
|
// context.state.color != "#676767"
|
||||||
|
// ? Color(hex: context.state.color)
|
||||||
|
// : Color.clear
|
||||||
|
// )
|
||||||
.activityBackgroundTint(
|
.activityBackgroundTint(
|
||||||
context.state.color != "#676767"
|
Color.clear
|
||||||
? Color(hex: context.state.color)
|
|
||||||
: Color.clear
|
|
||||||
)
|
)
|
||||||
|
.foregroundStyle(Color(hex: context.state.color))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import 'dart:async';
|
|||||||
import 'package:refilc/api/providers/liveactivity/platform_channel.dart';
|
import 'package:refilc/api/providers/liveactivity/platform_channel.dart';
|
||||||
import 'package:refilc/helpers/subject.dart';
|
import 'package:refilc/helpers/subject.dart';
|
||||||
import 'package:refilc/models/settings.dart';
|
import 'package:refilc/models/settings.dart';
|
||||||
|
import 'package:refilc/ui/flutter_colorpicker/utils.dart';
|
||||||
import 'package:refilc_kreta_api/models/lesson.dart';
|
import 'package:refilc_kreta_api/models/lesson.dart';
|
||||||
import 'package:refilc_kreta_api/models/week.dart';
|
import 'package:refilc_kreta_api/models/week.dart';
|
||||||
import 'package:refilc/utils/format.dart';
|
import 'package:refilc/utils/format.dart';
|
||||||
@ -84,11 +85,14 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> toMap() {
|
Map<String, String> toMap() {
|
||||||
|
print("LIVE ACTIVITY COLOR BELOW:");
|
||||||
|
print(_settings.liveActivityColor.toHexString().substring(2));
|
||||||
|
String color = '#${_settings.liveActivityColor.toHexString().substring(2)}';
|
||||||
|
|
||||||
switch (currentState) {
|
switch (currentState) {
|
||||||
case LiveCardState.morning:
|
case LiveCardState.morning:
|
||||||
return {
|
return {
|
||||||
"color":
|
"color": color,
|
||||||
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
|
||||||
"icon": nextLesson != null
|
"icon": nextLesson != null
|
||||||
? SubjectIcon.resolveName(subject: nextLesson?.subject)
|
? SubjectIcon.resolveName(subject: nextLesson?.subject)
|
||||||
: "book",
|
: "book",
|
||||||
@ -97,23 +101,22 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
"description": "",
|
"description": "",
|
||||||
"startDate": storeFirstRunDate != null
|
"startDate": storeFirstRunDate != null
|
||||||
? ((storeFirstRunDate?.millisecondsSinceEpoch ?? 0) -
|
? ((storeFirstRunDate?.millisecondsSinceEpoch ?? 0) -
|
||||||
(_delay.inMilliseconds))
|
(_delay.inMilliseconds))
|
||||||
.toString()
|
.toString()
|
||||||
: "",
|
: "",
|
||||||
"endDate": ((nextLesson?.start.millisecondsSinceEpoch ?? 0) -
|
"endDate": ((nextLesson?.start.millisecondsSinceEpoch ?? 0) -
|
||||||
_delay.inMilliseconds)
|
_delay.inMilliseconds)
|
||||||
.toString(),
|
.toString(),
|
||||||
"nextSubject": nextLesson != null
|
"nextSubject": nextLesson != null
|
||||||
? nextLesson?.subject.renamedTo ??
|
? nextLesson?.subject.renamedTo ??
|
||||||
ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
||||||
: "",
|
: "",
|
||||||
"nextRoom": nextLesson?.room.replaceAll("_", " ") ?? "",
|
"nextRoom": nextLesson?.room.replaceAll("_", " ") ?? "",
|
||||||
};
|
};
|
||||||
|
|
||||||
case LiveCardState.afternoon:
|
case LiveCardState.afternoon:
|
||||||
return {
|
return {
|
||||||
"color":
|
"color": color,
|
||||||
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
|
||||||
"icon": nextLesson != null
|
"icon": nextLesson != null
|
||||||
? SubjectIcon.resolveName(subject: nextLesson?.subject)
|
? SubjectIcon.resolveName(subject: nextLesson?.subject)
|
||||||
: "book",
|
: "book",
|
||||||
@ -122,23 +125,22 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
"description": "",
|
"description": "",
|
||||||
"startDate": storeFirstRunDate != null
|
"startDate": storeFirstRunDate != null
|
||||||
? ((storeFirstRunDate?.millisecondsSinceEpoch ?? 0) -
|
? ((storeFirstRunDate?.millisecondsSinceEpoch ?? 0) -
|
||||||
(_delay.inMilliseconds))
|
(_delay.inMilliseconds))
|
||||||
.toString()
|
.toString()
|
||||||
: "",
|
: "",
|
||||||
"endDate": ((nextLesson?.start.millisecondsSinceEpoch ?? 0) -
|
"endDate": ((nextLesson?.start.millisecondsSinceEpoch ?? 0) -
|
||||||
_delay.inMilliseconds)
|
_delay.inMilliseconds)
|
||||||
.toString(),
|
.toString(),
|
||||||
"nextSubject": nextLesson != null
|
"nextSubject": nextLesson != null
|
||||||
? nextLesson?.subject.renamedTo ??
|
? nextLesson?.subject.renamedTo ??
|
||||||
ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
||||||
: "",
|
: "",
|
||||||
"nextRoom": nextLesson?.room.replaceAll("_", " ") ?? "",
|
"nextRoom": nextLesson?.room.replaceAll("_", " ") ?? "",
|
||||||
};
|
};
|
||||||
|
|
||||||
case LiveCardState.night:
|
case LiveCardState.night:
|
||||||
return {
|
return {
|
||||||
"color":
|
"color": color,
|
||||||
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
|
||||||
"icon": nextLesson != null
|
"icon": nextLesson != null
|
||||||
? SubjectIcon.resolveName(subject: nextLesson?.subject)
|
? SubjectIcon.resolveName(subject: nextLesson?.subject)
|
||||||
: "book",
|
: "book",
|
||||||
@ -147,44 +149,44 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
"description": "",
|
"description": "",
|
||||||
"startDate": storeFirstRunDate != null
|
"startDate": storeFirstRunDate != null
|
||||||
? ((storeFirstRunDate?.millisecondsSinceEpoch ?? 0) -
|
? ((storeFirstRunDate?.millisecondsSinceEpoch ?? 0) -
|
||||||
(_delay.inMilliseconds))
|
(_delay.inMilliseconds))
|
||||||
.toString()
|
.toString()
|
||||||
: "",
|
: "",
|
||||||
"endDate": ((nextLesson?.start.millisecondsSinceEpoch ?? 0) -
|
"endDate": ((nextLesson?.start.millisecondsSinceEpoch ?? 0) -
|
||||||
_delay.inMilliseconds)
|
_delay.inMilliseconds)
|
||||||
.toString(),
|
.toString(),
|
||||||
"nextSubject": nextLesson != null
|
"nextSubject": nextLesson != null
|
||||||
? nextLesson?.subject.renamedTo ??
|
? nextLesson?.subject.renamedTo ??
|
||||||
ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
||||||
: "",
|
: "",
|
||||||
"nextRoom": nextLesson?.room.replaceAll("_", " ") ?? "",
|
"nextRoom": nextLesson?.room.replaceAll("_", " ") ?? "",
|
||||||
};
|
};
|
||||||
|
|
||||||
case LiveCardState.duringLesson:
|
case LiveCardState.duringLesson:
|
||||||
return {
|
return {
|
||||||
"color":
|
"color": color,
|
||||||
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
|
||||||
"icon": currentLesson != null
|
"icon": currentLesson != null
|
||||||
? SubjectIcon.resolveName(subject: currentLesson?.subject)
|
? SubjectIcon.resolveName(subject: currentLesson?.subject)
|
||||||
: "book",
|
: "book",
|
||||||
"index":
|
"index":
|
||||||
currentLesson != null ? '${currentLesson!.lessonIndex}. ' : "",
|
currentLesson != null ? '${currentLesson!.lessonIndex}. ' : "",
|
||||||
"title": currentLesson != null
|
"title": currentLesson != null
|
||||||
? currentLesson?.subject.renamedTo ??
|
? currentLesson?.subject.renamedTo ??
|
||||||
ShortSubject.resolve(subject: currentLesson?.subject)
|
ShortSubject.resolve(subject: currentLesson?.subject)
|
||||||
.capital()
|
.capital()
|
||||||
: "",
|
: "",
|
||||||
"subtitle": "Terem: ${currentLesson?.room.replaceAll("_", " ") ?? ""}",
|
"subtitle":
|
||||||
|
"Terem: ${currentLesson?.room.replaceAll("_", " ") ?? ""}",
|
||||||
"description": currentLesson?.description ?? "",
|
"description": currentLesson?.description ?? "",
|
||||||
"startDate": ((currentLesson?.start.millisecondsSinceEpoch ?? 0) -
|
"startDate": ((currentLesson?.start.millisecondsSinceEpoch ?? 0) -
|
||||||
_delay.inMilliseconds)
|
_delay.inMilliseconds)
|
||||||
.toString(),
|
.toString(),
|
||||||
"endDate": ((currentLesson?.end.millisecondsSinceEpoch ?? 0) -
|
"endDate": ((currentLesson?.end.millisecondsSinceEpoch ?? 0) -
|
||||||
_delay.inMilliseconds)
|
_delay.inMilliseconds)
|
||||||
.toString(),
|
.toString(),
|
||||||
"nextSubject": nextLesson != null
|
"nextSubject": nextLesson != null
|
||||||
? nextLesson?.subject.renamedTo ??
|
? nextLesson?.subject.renamedTo ??
|
||||||
ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
||||||
: "",
|
: "",
|
||||||
"nextRoom": nextLesson?.room.replaceAll("_", " ") ?? "",
|
"nextRoom": nextLesson?.room.replaceAll("_", " ") ?? "",
|
||||||
};
|
};
|
||||||
@ -199,24 +201,23 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
final diff = getFloorDifference();
|
final diff = getFloorDifference();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"color":
|
"color": color,
|
||||||
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
|
||||||
"icon": iconFloorMap[diff] ?? "cup.and.saucer",
|
"icon": iconFloorMap[diff] ?? "cup.and.saucer",
|
||||||
"title": "Szünet",
|
"title": "Szünet",
|
||||||
"description": "go $diff".i18n.fill([
|
"description": "go $diff".i18n.fill([
|
||||||
diff != "to room" ? (nextLesson!.getFloor() ?? 0) : nextLesson!.room
|
diff != "to room" ? (nextLesson!.getFloor() ?? 0) : nextLesson!.room
|
||||||
]),
|
]),
|
||||||
"startDate": ((prevLesson?.end.millisecondsSinceEpoch ?? 0) -
|
"startDate": ((prevLesson?.end.millisecondsSinceEpoch ?? 0) -
|
||||||
_delay.inMilliseconds)
|
_delay.inMilliseconds)
|
||||||
.toString(),
|
.toString(),
|
||||||
"endDate": ((nextLesson?.start.millisecondsSinceEpoch ?? 0) -
|
"endDate": ((nextLesson?.start.millisecondsSinceEpoch ?? 0) -
|
||||||
_delay.inMilliseconds)
|
_delay.inMilliseconds)
|
||||||
.toString(),
|
.toString(),
|
||||||
"nextSubject": (nextLesson != null
|
"nextSubject": (nextLesson != null
|
||||||
? nextLesson?.subject.renamedTo ??
|
? nextLesson?.subject.renamedTo ??
|
||||||
ShortSubject.resolve(subject: nextLesson?.subject)
|
ShortSubject.resolve(subject: nextLesson?.subject)
|
||||||
.capital()
|
.capital()
|
||||||
: "")
|
: "")
|
||||||
.capital(),
|
.capital(),
|
||||||
"nextRoom": nextLesson?.room.replaceAll("_", " ") ?? "",
|
"nextRoom": nextLesson?.room.replaceAll("_", " ") ?? "",
|
||||||
"index": "",
|
"index": "",
|
||||||
@ -243,8 +244,8 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
DateTime now = _now().add(_delay);
|
DateTime now = _now().add(_delay);
|
||||||
|
|
||||||
if ((currentState == LiveCardState.morning ||
|
if ((currentState == LiveCardState.morning ||
|
||||||
currentState == LiveCardState.afternoon ||
|
currentState == LiveCardState.afternoon ||
|
||||||
currentState == LiveCardState.night) &&
|
currentState == LiveCardState.night) &&
|
||||||
storeFirstRunDate == null) {
|
storeFirstRunDate == null) {
|
||||||
storeFirstRunDate = now;
|
storeFirstRunDate = now;
|
||||||
}
|
}
|
||||||
@ -253,9 +254,9 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
// Filter label lessons #128
|
// Filter label lessons #128
|
||||||
today = today
|
today = today
|
||||||
.where((lesson) =>
|
.where((lesson) =>
|
||||||
lesson.status?.name != "Elmaradt" &&
|
lesson.status?.name != "Elmaradt" &&
|
||||||
lesson.subject.id != '' &&
|
lesson.subject.id != '' &&
|
||||||
!lesson.isEmpty)
|
!lesson.isEmpty)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
if (today.isNotEmpty) {
|
if (today.isNotEmpty) {
|
||||||
@ -263,7 +264,7 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
today.sort((a, b) => a.start.compareTo(b.start));
|
today.sort((a, b) => a.start.compareTo(b.start));
|
||||||
|
|
||||||
final _lesson = today.firstWhere(
|
final _lesson = today.firstWhere(
|
||||||
(l) => l.start.isBefore(now) && l.end.isAfter(now),
|
(l) => l.start.isBefore(now) && l.end.isAfter(now),
|
||||||
orElse: () => Lesson.fromJson({}));
|
orElse: () => Lesson.fromJson({}));
|
||||||
|
|
||||||
if (_lesson.start.year != 0) {
|
if (_lesson.start.year != 0) {
|
||||||
@ -328,7 +329,7 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
hasActivityStarted = true;
|
hasActivityStarted = true;
|
||||||
} else if (!hasActivityStarted &&
|
} else if (!hasActivityStarted &&
|
||||||
((currentState == LiveCardState.duringLesson &&
|
((currentState == LiveCardState.duringLesson &&
|
||||||
currentLesson != null) ||
|
currentLesson != null) ||
|
||||||
currentState == LiveCardState.duringBreak)) {
|
currentState == LiveCardState.duringBreak)) {
|
||||||
debugPrint("Óra van, vagy szünet, de nincs LiveActivity. létrehozás...");
|
debugPrint("Óra van, vagy szünet, de nincs LiveActivity. létrehozás...");
|
||||||
PlatformChannel.createLiveActivity(toMap());
|
PlatformChannel.createLiveActivity(toMap());
|
||||||
@ -362,7 +363,11 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//END
|
//END
|
||||||
if ((currentState == LiveCardState.afternoon || currentState == LiveCardState.morning || currentState == LiveCardState.night) && hasActivityStarted && nextLesson != null &&
|
if ((currentState == LiveCardState.afternoon ||
|
||||||
|
currentState == LiveCardState.morning ||
|
||||||
|
currentState == LiveCardState.night) &&
|
||||||
|
hasActivityStarted &&
|
||||||
|
nextLesson != null &&
|
||||||
nextLesson!.start.difference(now).inMinutes > 60) {
|
nextLesson!.start.difference(now).inMinutes > 60) {
|
||||||
debugPrint("Több, mint 1 óra van az első óráig. Befejezés...");
|
debugPrint("Több, mint 1 óra van az első óráig. Befejezés...");
|
||||||
PlatformChannel.endLiveActivity();
|
PlatformChannel.endLiveActivity();
|
||||||
@ -389,4 +394,4 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
List<Lesson> _today(TimetableProvider p) => (p.getWeek(Week.current()) ?? [])
|
List<Lesson> _today(TimetableProvider p) => (p.getWeek(Week.current()) ?? [])
|
||||||
.where((l) => _sameDate(l.date, _now()))
|
.where((l) => _sameDate(l.date, _now()))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
@ -214,7 +214,7 @@ Widget errorBuilder(FlutterErrorDetails details) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return Container();
|
return Container();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,7 +500,7 @@ class SettingsProvider extends ChangeNotifier {
|
|||||||
renameSubjectsItalics: false,
|
renameSubjectsItalics: false,
|
||||||
renameTeachersEnabled: false,
|
renameTeachersEnabled: false,
|
||||||
renameTeachersItalics: false,
|
renameTeachersItalics: false,
|
||||||
liveActivityColor: const Color(0xFF676767),
|
liveActivityColor: const Color(0x00000000),
|
||||||
welcomeMessage: '',
|
welcomeMessage: '',
|
||||||
appIcon: 'refilc_default',
|
appIcon: 'refilc_default',
|
||||||
currentThemeId: '',
|
currentThemeId: '',
|
||||||
|
@ -922,6 +922,7 @@ class _LiveActivityColorSettingState extends State<LiveActivityColorSetting> {
|
|||||||
child: Column(children: [
|
child: Column(children: [
|
||||||
MaterialColorPicker(
|
MaterialColorPicker(
|
||||||
allowShades: false,
|
allowShades: false,
|
||||||
|
colors: [...fullMaterialColors],
|
||||||
selectedColor: settings.liveActivityColor,
|
selectedColor: settings.liveActivityColor,
|
||||||
onMainColorChange: (k) {
|
onMainColorChange: (k) {
|
||||||
if (!Provider.of<PlusProvider>(context, listen: false)
|
if (!Provider.of<PlusProvider>(context, listen: false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user