forked from firka/student-legacy
added grade colors to theme share
This commit is contained in:
parent
a9bd11a4d7
commit
d9bd555e6a
@ -40,6 +40,11 @@ class FilcAPI {
|
|||||||
static const allThemes = "$themeGet/all";
|
static const allThemes = "$themeGet/all";
|
||||||
static const themeByID = "$themeGet/";
|
static const themeByID = "$themeGet/";
|
||||||
|
|
||||||
|
static const gradeColorsShare = "$baseUrl/v2/shared/theme/add";
|
||||||
|
static const gradeColorsGet = "$baseUrl/v2/shared/theme/get";
|
||||||
|
static const allGradeColors = "$gradeColorsGet/all";
|
||||||
|
static const gradeColorsByID = "$gradeColorsGet/";
|
||||||
|
|
||||||
static Future<bool> checkConnectivity() async =>
|
static Future<bool> checkConnectivity() async =>
|
||||||
(await Connectivity().checkConnectivity()) != ConnectivityResult.none;
|
(await Connectivity().checkConnectivity()) != ConnectivityResult.none;
|
||||||
|
|
||||||
@ -235,7 +240,49 @@ class FilcAPI {
|
|||||||
throw "HTTP ${res.statusCode}: ${res.body}";
|
throw "HTTP ${res.statusCode}: ${res.body}";
|
||||||
}
|
}
|
||||||
} on Exception catch (error, stacktrace) {
|
} on Exception catch (error, stacktrace) {
|
||||||
log("ERROR: FilcAPI.addSharedTheme: $error $stacktrace");
|
log("ERROR: FilcAPI.getSharedTheme: $error $stacktrace");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> addSharedGradeColors(
|
||||||
|
SharedGradeColors gradeColors) async {
|
||||||
|
try {
|
||||||
|
gradeColors.json.remove('json');
|
||||||
|
gradeColors.json['is_public'] = gradeColors.isPublic.toString();
|
||||||
|
gradeColors.json['five_color'] = gradeColors.fiveColor.value.toString();
|
||||||
|
gradeColors.json['four_color'] = gradeColors.fourColor.value.toString();
|
||||||
|
gradeColors.json['three_color'] = gradeColors.threeColor.value.toString();
|
||||||
|
gradeColors.json['two_color'] = gradeColors.twoColor.value.toString();
|
||||||
|
gradeColors.json['one_color'] = gradeColors.oneColor.value.toString();
|
||||||
|
|
||||||
|
http.Response res = await http.post(
|
||||||
|
Uri.parse(gradeColorsShare),
|
||||||
|
body: gradeColors.json,
|
||||||
|
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (res.statusCode != 201) {
|
||||||
|
throw "HTTP ${res.statusCode}: ${res.body}";
|
||||||
|
}
|
||||||
|
|
||||||
|
log('Shared grade colors successfully with ID: ${gradeColors.id}');
|
||||||
|
} on Exception catch (error, stacktrace) {
|
||||||
|
log("ERROR: FilcAPI.addSharedGradeColors: $error $stacktrace");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<Map?> getSharedGradeColors(String id) async {
|
||||||
|
try {
|
||||||
|
http.Response res = await http.get(Uri.parse(gradeColorsByID + id));
|
||||||
|
|
||||||
|
if (res.statusCode == 200) {
|
||||||
|
return (jsonDecode(res.body) as Map);
|
||||||
|
} else {
|
||||||
|
throw "HTTP ${res.statusCode}: ${res.body}";
|
||||||
|
}
|
||||||
|
} on Exception catch (error, stacktrace) {
|
||||||
|
log("ERROR: FilcAPI.getSharedGradeColors: $error $stacktrace");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ class SharedTheme {
|
|||||||
Color backgroundColor;
|
Color backgroundColor;
|
||||||
Color panelsColor;
|
Color panelsColor;
|
||||||
Color accentColor;
|
Color accentColor;
|
||||||
|
SharedGradeColors gradeColors;
|
||||||
|
|
||||||
SharedTheme({
|
SharedTheme({
|
||||||
required this.json,
|
required this.json,
|
||||||
@ -17,9 +18,10 @@ class SharedTheme {
|
|||||||
required this.backgroundColor,
|
required this.backgroundColor,
|
||||||
required this.panelsColor,
|
required this.panelsColor,
|
||||||
required this.accentColor,
|
required this.accentColor,
|
||||||
|
required this.gradeColors,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory SharedTheme.fromJson(Map json) {
|
factory SharedTheme.fromJson(Map json, Map gradeColorsJson) {
|
||||||
return SharedTheme(
|
return SharedTheme(
|
||||||
json: json,
|
json: json,
|
||||||
id: json['public_id'],
|
id: json['public_id'],
|
||||||
@ -28,6 +30,48 @@ class SharedTheme {
|
|||||||
backgroundColor: Color(json['background_color']),
|
backgroundColor: Color(json['background_color']),
|
||||||
panelsColor: Color(json['panels_color']),
|
panelsColor: Color(json['panels_color']),
|
||||||
accentColor: Color(json['accent_color']),
|
accentColor: Color(json['accent_color']),
|
||||||
|
gradeColors: SharedGradeColors.fromJson(gradeColorsJson),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SharedGradeColors {
|
||||||
|
Map json;
|
||||||
|
String id;
|
||||||
|
bool isPublic;
|
||||||
|
String nickname;
|
||||||
|
Color fiveColor;
|
||||||
|
Color fourColor;
|
||||||
|
Color threeColor;
|
||||||
|
Color twoColor;
|
||||||
|
Color oneColor;
|
||||||
|
String linkedThemeId;
|
||||||
|
|
||||||
|
SharedGradeColors({
|
||||||
|
required this.json,
|
||||||
|
required this.id,
|
||||||
|
this.isPublic = false,
|
||||||
|
this.nickname = 'Anonymous',
|
||||||
|
required this.fiveColor,
|
||||||
|
required this.fourColor,
|
||||||
|
required this.threeColor,
|
||||||
|
required this.twoColor,
|
||||||
|
required this.oneColor,
|
||||||
|
required this.linkedThemeId,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory SharedGradeColors.fromJson(Map json) {
|
||||||
|
return SharedGradeColors(
|
||||||
|
json: json,
|
||||||
|
id: json['public_id'],
|
||||||
|
isPublic: json['is_public'] ?? false,
|
||||||
|
nickname: json['nickname'] ?? 'Anonymous',
|
||||||
|
fiveColor: Color(json['five_color']),
|
||||||
|
fourColor: Color(json['four_color']),
|
||||||
|
threeColor: Color(json['three_color']),
|
||||||
|
twoColor: Color(json['two_color']),
|
||||||
|
oneColor: Color(json['one_color']),
|
||||||
|
linkedThemeId: json['linked_theme_id'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -648,8 +648,8 @@ class _LiveActivityColorSettingState extends State<LiveActivityColorSetting> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
currentColor = k as Color;
|
currentColor = k as Color;
|
||||||
settings.update(
|
settings.update(
|
||||||
liveActivityColor: currentColor.withAlpha(255));
|
liveActivityColor: currentColor.withAlpha(255));
|
||||||
Navigator.of(context).maybePop();
|
Navigator.of(context).maybePop();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
|
@ -17,8 +17,12 @@ class ShareProvider extends ChangeNotifier {
|
|||||||
// Future<void> shareTheme({required SharedTheme theme}) async {
|
// Future<void> shareTheme({required SharedTheme theme}) async {
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// themes
|
||||||
Future<SharedTheme> shareCurrentTheme(BuildContext context,
|
Future<SharedTheme> shareCurrentTheme(BuildContext context,
|
||||||
{bool isPublic = false, bool shareNick = true}) async {
|
{bool isPublic = false,
|
||||||
|
bool shareNick = true,
|
||||||
|
required SharedGradeColors gradeColors}) async {
|
||||||
final SettingsProvider settings =
|
final SettingsProvider settings =
|
||||||
Provider.of<SettingsProvider>(context, listen: false);
|
Provider.of<SettingsProvider>(context, listen: false);
|
||||||
|
|
||||||
@ -38,7 +42,7 @@ class ShareProvider extends ChangeNotifier {
|
|||||||
const Color(0xFF3D7BF4).value,
|
const Color(0xFF3D7BF4).value,
|
||||||
};
|
};
|
||||||
|
|
||||||
SharedTheme theme = SharedTheme.fromJson(themeJson);
|
SharedTheme theme = SharedTheme.fromJson(themeJson, gradeColors.json);
|
||||||
FilcAPI.addSharedTheme(theme);
|
FilcAPI.addSharedTheme(theme);
|
||||||
|
|
||||||
return theme;
|
return theme;
|
||||||
@ -49,8 +53,52 @@ class ShareProvider extends ChangeNotifier {
|
|||||||
Map? themeJson = await FilcAPI.getSharedTheme(id);
|
Map? themeJson = await FilcAPI.getSharedTheme(id);
|
||||||
|
|
||||||
if (themeJson != null) {
|
if (themeJson != null) {
|
||||||
SharedTheme theme = SharedTheme.fromJson(themeJson);
|
Map? gradeColorsJson =
|
||||||
return theme;
|
await FilcAPI.getSharedGradeColors(themeJson['grade_colors_id']);
|
||||||
|
|
||||||
|
if (gradeColorsJson != null) {
|
||||||
|
SharedTheme theme = SharedTheme.fromJson(themeJson, gradeColorsJson);
|
||||||
|
return theme;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// grade colors
|
||||||
|
Future<SharedGradeColors> shareCurrentGradeColors(
|
||||||
|
BuildContext context, {
|
||||||
|
bool isPublic = false,
|
||||||
|
bool shareNick = true,
|
||||||
|
}) async {
|
||||||
|
final SettingsProvider settings =
|
||||||
|
Provider.of<SettingsProvider>(context, listen: false);
|
||||||
|
|
||||||
|
Map gradeColorsJson = {
|
||||||
|
'public_id': const Uuid().v4(),
|
||||||
|
'is_public': isPublic,
|
||||||
|
'nickname': shareNick ? _user.nickname : 'Anonymous',
|
||||||
|
'five_color': settings.gradeColors[4].value,
|
||||||
|
'four_color': settings.gradeColors[3].value,
|
||||||
|
'three_color': settings.gradeColors[2].value,
|
||||||
|
'two_color': settings.gradeColors[1].value,
|
||||||
|
'one_color': settings.gradeColors[0].value,
|
||||||
|
};
|
||||||
|
|
||||||
|
SharedGradeColors gradeColors = SharedGradeColors.fromJson(gradeColorsJson);
|
||||||
|
FilcAPI.addSharedGradeColors(gradeColors);
|
||||||
|
|
||||||
|
return gradeColors;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<SharedGradeColors?> getGradeColorsById(BuildContext context,
|
||||||
|
{required String id}) async {
|
||||||
|
Map? gradeColorsJson = await FilcAPI.getSharedGradeColors(id);
|
||||||
|
|
||||||
|
if (gradeColorsJson != null) {
|
||||||
|
SharedGradeColors gradeColors =
|
||||||
|
SharedGradeColors.fromJson(gradeColorsJson);
|
||||||
|
return gradeColors;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -283,8 +283,16 @@ class _PremiumCustomAccentColorSettingState
|
|||||||
label: "understand".i18n,
|
label: "understand".i18n,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
SharedTheme theme = await shareProvider
|
|
||||||
.shareCurrentTheme(context);
|
SharedGradeColors gradeColors =
|
||||||
|
await shareProvider
|
||||||
|
.shareCurrentGradeColors(context);
|
||||||
|
SharedTheme theme =
|
||||||
|
await shareProvider.shareCurrentTheme(
|
||||||
|
context,
|
||||||
|
gradeColors: gradeColors,
|
||||||
|
);
|
||||||
|
|
||||||
Share.share(
|
Share.share(
|
||||||
theme.id,
|
theme.id,
|
||||||
subject: 'share_subj_theme'.i18n,
|
subject: 'share_subj_theme'.i18n,
|
||||||
@ -804,6 +812,18 @@ class _PremiumCustomAccentColorSettingState
|
|||||||
setTheme(settings.theme, true);
|
setTheme(settings.theme, true);
|
||||||
},
|
},
|
||||||
onThemeIdProvided: (theme) {
|
onThemeIdProvided: (theme) {
|
||||||
|
// changing grade colors
|
||||||
|
List<Color> colors = [
|
||||||
|
theme.gradeColors.oneColor,
|
||||||
|
theme.gradeColors.twoColor,
|
||||||
|
theme.gradeColors.threeColor,
|
||||||
|
theme.gradeColors.fourColor,
|
||||||
|
theme.gradeColors.fiveColor,
|
||||||
|
];
|
||||||
|
settings.update(
|
||||||
|
gradeColors: colors);
|
||||||
|
|
||||||
|
// changing theme
|
||||||
setState(() {
|
setState(() {
|
||||||
updateCustomColor(
|
updateCustomColor(
|
||||||
null,
|
null,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user