forked from firka/student-legacy
rounding shits
This commit is contained in:
parent
a435f56f2e
commit
773a8f61e9
@ -60,6 +60,8 @@ const userDataDB = DatabaseStruct("user_data", {
|
||||
"goal_pin_dates": String,
|
||||
// todo and notes
|
||||
"todo_items": String, "self_notes": String,
|
||||
// v5 shit
|
||||
"roundings": String,
|
||||
});
|
||||
|
||||
Future<void> createTable(Database db, DatabaseStruct struct) =>
|
||||
@ -118,7 +120,9 @@ Future<Database> initDB(DatabaseProvider database) async {
|
||||
"goal_befores": "{}",
|
||||
"goal_pin_dates": "{}",
|
||||
// todo and notes
|
||||
"todo_items": "{}", "self_notes": "[]"
|
||||
"todo_items": "{}", "self_notes": "[]",
|
||||
// v5 shit
|
||||
"roundings": "{}",
|
||||
});
|
||||
} catch (error) {
|
||||
print("ERROR: migrateDB: $error");
|
||||
|
@ -305,4 +305,15 @@ class UserDatabaseQuery {
|
||||
.toList();
|
||||
return selfNotes;
|
||||
}
|
||||
|
||||
// v5
|
||||
Future<Map<String, String>> getRoundings({required String userId}) async {
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return {};
|
||||
String? roundingsJson = userData.elementAt(0)["roundings"] as String?;
|
||||
if (roundingsJson == null) return {};
|
||||
return (jsonDecode(roundingsJson) as Map)
|
||||
.map((key, value) => MapEntry(key.toString(), value.toString()));
|
||||
}
|
||||
}
|
||||
|
@ -193,4 +193,12 @@ class UserDatabaseStore {
|
||||
await db.update("user_data", {"self_notes": selfNotesJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
// v5
|
||||
Future<void> storeRoundings(Map<String, String> roundings,
|
||||
{required String userId}) async {
|
||||
String roundingsJson = jsonEncode(roundings);
|
||||
await db.update("user_data", {"roundings": roundingsJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,18 @@ class GradeSubject {
|
||||
Category category;
|
||||
String name;
|
||||
String? renamedTo;
|
||||
double? customRounding;
|
||||
|
||||
bool get isRenamed => renamedTo != null;
|
||||
bool get hasCustomRounding => customRounding != null;
|
||||
|
||||
GradeSubject({
|
||||
required this.id,
|
||||
required this.category,
|
||||
required this.name,
|
||||
this.renamedTo,
|
||||
// v5
|
||||
this.customRounding,
|
||||
});
|
||||
|
||||
factory GradeSubject.fromJson(Map json) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// ignore_for_file: no_leading_underscores_for_local_identifiers
|
||||
// ignore_for_file: no_leading_underscores_for_local_identifiers, use_build_context_synchronously
|
||||
|
||||
import 'package:filcnaplo/api/providers/user_provider.dart';
|
||||
import 'package:filcnaplo/api/providers/database_provider.dart';
|
||||
@ -45,17 +45,21 @@ class AbsenceProvider with ChangeNotifier {
|
||||
(await _database.query.getSettings(_database)).renamedSubjectsEnabled
|
||||
? await _database.userQuery.renamedSubjects(
|
||||
userId:
|
||||
// ignore: use_build_context_synchronously
|
||||
Provider.of<UserProvider>(_context, listen: false).user!.id)
|
||||
: {};
|
||||
Map<String, String> renamedTeachers =
|
||||
(await _database.query.getSettings(_database)).renamedTeachersEnabled
|
||||
? await _database.userQuery.renamedTeachers(
|
||||
userId:
|
||||
// ignore: use_build_context_synchronously
|
||||
Provider.of<UserProvider>(_context, listen: false).user!.id)
|
||||
: {};
|
||||
|
||||
// v5
|
||||
Map<String, String> customRoundings = await _database.userQuery
|
||||
.getRoundings(
|
||||
userId:
|
||||
Provider.of<UserProvider>(_context, listen: false).user!.id);
|
||||
|
||||
for (Absence absence in _absences) {
|
||||
absence.subject.renamedTo = renamedSubjects.isNotEmpty
|
||||
? renamedSubjects[absence.subject.id]
|
||||
@ -63,6 +67,11 @@ class AbsenceProvider with ChangeNotifier {
|
||||
absence.teacher.renamedTo = renamedTeachers.isNotEmpty
|
||||
? renamedTeachers[absence.teacher.id]
|
||||
: null;
|
||||
|
||||
// v5
|
||||
absence.subject.customRounding = customRoundings.isNotEmpty
|
||||
? double.parse(customRoundings[absence.subject.id] ?? '5.0')
|
||||
: null;
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
|
@ -87,6 +87,10 @@ class GradeProvider with ChangeNotifier {
|
||||
? await _database.userQuery.renamedTeachers(userId: _user.user!.id)
|
||||
: {};
|
||||
|
||||
// v5
|
||||
Map<String, String> customRoundings =
|
||||
await _database.userQuery.getRoundings(userId: _user.user!.id);
|
||||
|
||||
for (Grade grade in _grades) {
|
||||
grade.subject.renamedTo =
|
||||
renamedSubjects.isNotEmpty ? renamedSubjects[grade.subject.id] : null;
|
||||
@ -109,6 +113,11 @@ class GradeProvider with ChangeNotifier {
|
||||
""
|
||||
? '${grade.json!["SzovegesErtekelesRovidNev"]}'.i18n
|
||||
: grade.value.valueName;
|
||||
|
||||
// v5
|
||||
grade.subject.customRounding = customRoundings.isNotEmpty
|
||||
? double.parse(customRoundings[grade.subject.id] ?? '5.0')
|
||||
: null;
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
|
@ -45,6 +45,10 @@ class TimetableProvider with ChangeNotifier {
|
||||
? await _database.userQuery.renamedTeachers(userId: _user.id!)
|
||||
: {};
|
||||
|
||||
// v5
|
||||
Map<String, String> customRoundings =
|
||||
await _database.userQuery.getRoundings(userId: _user.user!.id);
|
||||
|
||||
for (Lesson lesson in lessons.values.expand((e) => e)) {
|
||||
lesson.subject.renamedTo = renamedSubjects.isNotEmpty
|
||||
? renamedSubjects[lesson.subject.id]
|
||||
@ -52,6 +56,11 @@ class TimetableProvider with ChangeNotifier {
|
||||
lesson.teacher.renamedTo = renamedTeachers.isNotEmpty
|
||||
? renamedTeachers[lesson.teacher.id]
|
||||
: null;
|
||||
|
||||
// v5
|
||||
lesson.subject.customRounding = customRoundings.isNotEmpty
|
||||
? double.parse(customRoundings[lesson.subject.id] ?? '5.0')
|
||||
: null;
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
|
@ -1,14 +1,19 @@
|
||||
// ignore_for_file: prefer_function_declarations_over_variables, library_private_types_in_public_api
|
||||
// ignore_for_file: prefer_function_declarations_over_variables, library_private_types_in_public_api, use_build_context_synchronously
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:filcnaplo/api/providers/database_provider.dart';
|
||||
import 'package:filcnaplo/api/providers/user_provider.dart';
|
||||
import 'package:filcnaplo/helpers/quick_actions.dart';
|
||||
import 'package:filcnaplo/icons/filc_icons.dart';
|
||||
import 'package:filcnaplo/models/settings.dart';
|
||||
import 'package:filcnaplo/theme/colors/colors.dart';
|
||||
import 'package:filcnaplo/theme/observer.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/grade.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/subject.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/week.dart';
|
||||
import 'package:filcnaplo_kreta_api/providers/absence_provider.dart';
|
||||
import 'package:filcnaplo_kreta_api/providers/grade_provider.dart';
|
||||
import 'package:filcnaplo_kreta_api/providers/timetable_provider.dart';
|
||||
import 'package:filcnaplo_mobile_ui/common/bottom_sheet_menu/bottom_sheet_menu.dart';
|
||||
import 'package:filcnaplo_mobile_ui/common/bottom_sheet_menu/bottom_sheet_menu_item.dart';
|
||||
@ -179,6 +184,18 @@ class SettingsHelper {
|
||||
);
|
||||
}
|
||||
|
||||
// new v5 roundings
|
||||
static void newRoundings(BuildContext context, GradeSubject subject) {
|
||||
showRoundedModalBottomSheet(
|
||||
context,
|
||||
child: RoundingSetting(
|
||||
rounding: subject.customRounding,
|
||||
subjectId: subject.id,
|
||||
),
|
||||
);
|
||||
}
|
||||
// end
|
||||
|
||||
static void theme(BuildContext context) {
|
||||
var settings = Provider.of<SettingsProvider>(context, listen: false);
|
||||
void Function(ThemeMode) setTheme = (mode) {
|
||||
@ -353,7 +370,7 @@ class SettingsHelper {
|
||||
setSystemChrome(context);
|
||||
});
|
||||
},
|
||||
title: Text("add_user"),
|
||||
title: const Text("add_user"),
|
||||
leading: const Icon(FeatherIcons.userPlus),
|
||||
);
|
||||
} else {
|
||||
@ -366,7 +383,10 @@ class SettingsHelper {
|
||||
|
||||
// Rounding modal
|
||||
class RoundingSetting extends StatefulWidget {
|
||||
const RoundingSetting({super.key});
|
||||
const RoundingSetting({super.key, this.rounding, this.subjectId});
|
||||
|
||||
final double? rounding;
|
||||
final String? subjectId;
|
||||
|
||||
@override
|
||||
_RoundingSettingState createState() => _RoundingSettingState();
|
||||
@ -378,12 +398,19 @@ class _RoundingSettingState extends State<RoundingSetting> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
rounding =
|
||||
Provider.of<SettingsProvider>(context, listen: false).rounding / 10;
|
||||
|
||||
rounding = (widget.rounding ??
|
||||
Provider.of<SettingsProvider>(context, listen: false).rounding) /
|
||||
10;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
UserProvider userProvider =
|
||||
Provider.of<UserProvider>(context, listen: false);
|
||||
DatabaseProvider databaseProvider =
|
||||
Provider.of<DatabaseProvider>(context, listen: false);
|
||||
|
||||
int roundingResult;
|
||||
|
||||
if (4.5 >= 4.5.floor() + rounding) {
|
||||
@ -438,10 +465,32 @@ class _RoundingSettingState extends State<RoundingSetting> {
|
||||
padding: const EdgeInsets.only(bottom: 12.0, top: 6.0),
|
||||
child: MaterialActionButton(
|
||||
child: Text(SettingsLocalization("done").i18n),
|
||||
onPressed: () {
|
||||
onPressed: () async {
|
||||
if (widget.rounding == null) {
|
||||
Provider.of<SettingsProvider>(context, listen: false)
|
||||
.update(rounding: (rounding * 10).toInt());
|
||||
Navigator.of(context).maybePop();
|
||||
} else {
|
||||
Map<String, String> roundings = await databaseProvider.userQuery
|
||||
.getRoundings(userId: userProvider.id!);
|
||||
|
||||
roundings[widget.subjectId!] = (rounding * 10).toStringAsFixed(2);
|
||||
|
||||
await databaseProvider.userStore
|
||||
.storeRoundings(roundings, userId: userProvider.id!);
|
||||
|
||||
await Provider.of<GradeProvider>(context, listen: false)
|
||||
.convertBySettings();
|
||||
await Provider.of<TimetableProvider>(context, listen: false)
|
||||
.convertBySettings();
|
||||
await Provider.of<AbsenceProvider>(context, listen: false)
|
||||
.convertBySettings();
|
||||
}
|
||||
|
||||
// ik i'm like a kreta dev, but setstate isn't working, so please don't kill me bye :3
|
||||
// actually it also looks good and it's kinda useful
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
// setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
|
@ -12,7 +12,7 @@ import 'package:filcnaplo_kreta_api/providers/grade_provider.dart';
|
||||
import 'package:filcnaplo_kreta_api/providers/timetable_provider.dart';
|
||||
import 'package:filcnaplo_mobile_ui/common/panel/panel_button.dart';
|
||||
import 'package:filcnaplo_mobile_ui/common/splitted_panel/splitted_panel.dart';
|
||||
import 'package:filcnaplo_mobile_ui/screens/settings/settings_helper.dart';
|
||||
// import 'package:filcnaplo_mobile_ui/screens/settings/settings_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@ -20,8 +20,11 @@ import 'package:provider/provider.dart';
|
||||
import 'edit_subject.i18n.dart';
|
||||
|
||||
class EditSubjectScreen extends StatefulWidget {
|
||||
const EditSubjectScreen(
|
||||
{super.key, required this.subject, required this.teacher});
|
||||
const EditSubjectScreen({
|
||||
super.key,
|
||||
required this.subject,
|
||||
required this.teacher,
|
||||
});
|
||||
|
||||
final GradeSubject subject;
|
||||
final Teacher teacher;
|
||||
@ -139,38 +142,41 @@ class EditSubjectScreenState extends State<EditSubjectScreen> {
|
||||
],
|
||||
),
|
||||
// edit rounding
|
||||
SplittedPanel(
|
||||
padding: const EdgeInsets.only(top: 9.0),
|
||||
cardPadding: const EdgeInsets.all(4.0),
|
||||
isSeparated: true,
|
||||
children: [
|
||||
PanelButton(
|
||||
onPressed: () {
|
||||
SettingsHelper.rounding(context);
|
||||
setState(() {});
|
||||
},
|
||||
title: Text(
|
||||
"rounding".i18n,
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context).text.withOpacity(.95),
|
||||
),
|
||||
),
|
||||
leading: Icon(
|
||||
FeatherIcons.gitCommit,
|
||||
size: 22.0,
|
||||
color: AppColors.of(context).text.withOpacity(.95),
|
||||
),
|
||||
trailing: Text(
|
||||
(settingsProvider.rounding / 10).toStringAsFixed(1),
|
||||
style: const TextStyle(fontSize: 14.0),
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12.0),
|
||||
bottom: Radius.circular(12.0),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
// SplittedPanel(
|
||||
// padding: const EdgeInsets.only(top: 9.0),
|
||||
// cardPadding: const EdgeInsets.all(4.0),
|
||||
// isSeparated: true,
|
||||
// children: [
|
||||
// PanelButton(
|
||||
// onPressed: () {
|
||||
// SettingsHelper.newRoundings(context, widget.subject);
|
||||
// setState(() {});
|
||||
// },
|
||||
// title: Text(
|
||||
// "rounding".i18n,
|
||||
// style: TextStyle(
|
||||
// color: AppColors.of(context).text.withOpacity(.95),
|
||||
// ),
|
||||
// ),
|
||||
// leading: Icon(
|
||||
// FeatherIcons.gitCommit,
|
||||
// size: 22.0,
|
||||
// color: AppColors.of(context).text.withOpacity(.95),
|
||||
// ),
|
||||
// trailing: Text(
|
||||
// ((widget.subject.customRounding ??
|
||||
// settingsProvider.rounding) /
|
||||
// 10)
|
||||
// .toStringAsFixed(1),
|
||||
// style: const TextStyle(fontSize: 14.0),
|
||||
// ),
|
||||
// borderRadius: const BorderRadius.vertical(
|
||||
// top: Radius.circular(12.0),
|
||||
// bottom: Radius.circular(12.0),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -1,6 +1,7 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'package:dropdown_button2/dropdown_button2.dart';
|
||||
import 'package:filcnaplo/api/providers/user_provider.dart';
|
||||
import 'package:filcnaplo/helpers/subject.dart';
|
||||
import 'package:filcnaplo/models/settings.dart';
|
||||
import 'package:filcnaplo/theme/colors/colors.dart';
|
||||
@ -62,6 +63,7 @@ class PersonalizeSettingsScreen extends StatefulWidget {
|
||||
class PersonalizeSettingsScreenState extends State<PersonalizeSettingsScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late SettingsProvider settingsProvider;
|
||||
late UserProvider user;
|
||||
|
||||
late AnimationController _hideContainersController;
|
||||
|
||||
@ -179,6 +181,7 @@ class PersonalizeSettingsScreenState extends State<PersonalizeSettingsScreen>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
settingsProvider = Provider.of<SettingsProvider>(context);
|
||||
user = Provider.of<UserProvider>(context);
|
||||
|
||||
String themeModeText = {
|
||||
ThemeMode.light: "light".i18n,
|
||||
@ -517,7 +520,7 @@ class PersonalizeSettingsScreenState extends State<PersonalizeSettingsScreen>
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
onChanged: (String? v) {
|
||||
onChanged: (String? v) async {
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => EditSubjectScreen(
|
||||
|
Loading…
x
Reference in New Issue
Block a user