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
|
||||
extension Color {
|
||||
init(hex: String, alpha: Double = 1.0) {
|
||||
@ -62,7 +73,6 @@ struct LockScreenLiveActivityView: View {
|
||||
.font(.body)
|
||||
.bold()
|
||||
.padding(.trailing, 90)
|
||||
|
||||
} else {
|
||||
MultilineTextView(text: "\(context.state.index) \(context.state.title) - \(context.state.subtitle)", limit: 25)
|
||||
.font(.body)
|
||||
@ -84,6 +94,7 @@ struct LockScreenLiveActivityView: View {
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: CGFloat(8), height: CGFloat(8))
|
||||
.foregroundStyle(.secondary)
|
||||
Text("\(context.state.nextSubject) - \(context.state.nextRoom)")
|
||||
.font(.caption)
|
||||
}
|
||||
@ -107,11 +118,15 @@ struct LockScreenLiveActivityView: View {
|
||||
.monospacedDigit()
|
||||
.padding(.trailing)
|
||||
}
|
||||
// .activityBackgroundTint(
|
||||
// context.state.color != "#676767"
|
||||
// ? Color(hex: context.state.color)
|
||||
// : Color.clear
|
||||
// )
|
||||
.activityBackgroundTint(
|
||||
context.state.color != "#676767"
|
||||
? Color(hex: context.state.color)
|
||||
: Color.clear
|
||||
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/helpers/subject.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/week.dart';
|
||||
import 'package:refilc/utils/format.dart';
|
||||
@ -84,11 +85,14 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
Map<String, String> toMap() {
|
||||
print("LIVE ACTIVITY COLOR BELOW:");
|
||||
print(_settings.liveActivityColor.toHexString().substring(2));
|
||||
String color = '#${_settings.liveActivityColor.toHexString().substring(2)}';
|
||||
|
||||
switch (currentState) {
|
||||
case LiveCardState.morning:
|
||||
return {
|
||||
"color":
|
||||
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
||||
"color": color,
|
||||
"icon": nextLesson != null
|
||||
? SubjectIcon.resolveName(subject: nextLesson?.subject)
|
||||
: "book",
|
||||
@ -112,8 +116,7 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
|
||||
case LiveCardState.afternoon:
|
||||
return {
|
||||
"color":
|
||||
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
||||
"color": color,
|
||||
"icon": nextLesson != null
|
||||
? SubjectIcon.resolveName(subject: nextLesson?.subject)
|
||||
: "book",
|
||||
@ -137,8 +140,7 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
|
||||
case LiveCardState.night:
|
||||
return {
|
||||
"color":
|
||||
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
||||
"color": color,
|
||||
"icon": nextLesson != null
|
||||
? SubjectIcon.resolveName(subject: nextLesson?.subject)
|
||||
: "book",
|
||||
@ -162,8 +164,7 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
|
||||
case LiveCardState.duringLesson:
|
||||
return {
|
||||
"color":
|
||||
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
||||
"color": color,
|
||||
"icon": currentLesson != null
|
||||
? SubjectIcon.resolveName(subject: currentLesson?.subject)
|
||||
: "book",
|
||||
@ -174,7 +175,8 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
ShortSubject.resolve(subject: currentLesson?.subject)
|
||||
.capital()
|
||||
: "",
|
||||
"subtitle": "Terem: ${currentLesson?.room.replaceAll("_", " ") ?? ""}",
|
||||
"subtitle":
|
||||
"Terem: ${currentLesson?.room.replaceAll("_", " ") ?? ""}",
|
||||
"description": currentLesson?.description ?? "",
|
||||
"startDate": ((currentLesson?.start.millisecondsSinceEpoch ?? 0) -
|
||||
_delay.inMilliseconds)
|
||||
@ -199,8 +201,7 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
final diff = getFloorDifference();
|
||||
|
||||
return {
|
||||
"color":
|
||||
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
||||
"color": color,
|
||||
"icon": iconFloorMap[diff] ?? "cup.and.saucer",
|
||||
"title": "Szünet",
|
||||
"description": "go $diff".i18n.fill([
|
||||
@ -362,7 +363,11 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
//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) {
|
||||
debugPrint("Több, mint 1 óra van az első óráig. Befejezés...");
|
||||
PlatformChannel.endLiveActivity();
|
||||
|
@ -500,7 +500,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
renameSubjectsItalics: false,
|
||||
renameTeachersEnabled: false,
|
||||
renameTeachersItalics: false,
|
||||
liveActivityColor: const Color(0xFF676767),
|
||||
liveActivityColor: const Color(0x00000000),
|
||||
welcomeMessage: '',
|
||||
appIcon: 'refilc_default',
|
||||
currentThemeId: '',
|
||||
|
@ -922,6 +922,7 @@ class _LiveActivityColorSettingState extends State<LiveActivityColorSetting> {
|
||||
child: Column(children: [
|
||||
MaterialColorPicker(
|
||||
allowShades: false,
|
||||
colors: [...fullMaterialColors],
|
||||
selectedColor: settings.liveActivityColor,
|
||||
onMainColorChange: (k) {
|
||||
if (!Provider.of<PlusProvider>(context, listen: false)
|
||||
|
Loading…
x
Reference in New Issue
Block a user