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 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 =>
|
||||
(await Connectivity().checkConnectivity()) != ConnectivityResult.none;
|
||||
|
||||
@ -235,7 +240,49 @@ class FilcAPI {
|
||||
throw "HTTP ${res.statusCode}: ${res.body}";
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ class SharedTheme {
|
||||
Color backgroundColor;
|
||||
Color panelsColor;
|
||||
Color accentColor;
|
||||
SharedGradeColors gradeColors;
|
||||
|
||||
SharedTheme({
|
||||
required this.json,
|
||||
@ -17,9 +18,10 @@ class SharedTheme {
|
||||
required this.backgroundColor,
|
||||
required this.panelsColor,
|
||||
required this.accentColor,
|
||||
required this.gradeColors,
|
||||
});
|
||||
|
||||
factory SharedTheme.fromJson(Map json) {
|
||||
factory SharedTheme.fromJson(Map json, Map gradeColorsJson) {
|
||||
return SharedTheme(
|
||||
json: json,
|
||||
id: json['public_id'],
|
||||
@ -28,6 +30,48 @@ class SharedTheme {
|
||||
backgroundColor: Color(json['background_color']),
|
||||
panelsColor: Color(json['panels_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'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -623,7 +623,7 @@ class LiveActivityColorSetting extends StatefulWidget {
|
||||
_LiveActivityColorSettingState();
|
||||
}
|
||||
|
||||
class _LiveActivityColorSettingState extends State<LiveActivityColorSetting> {
|
||||
class _LiveActivityColorSettingState extends State<LiveActivityColorSetting> {
|
||||
late SettingsProvider settings;
|
||||
Color currentColor = const Color(0x00000000);
|
||||
|
||||
@ -648,8 +648,8 @@ class _LiveActivityColorSettingState extends State<LiveActivityColorSetting> {
|
||||
setState(() {
|
||||
currentColor = k as Color;
|
||||
settings.update(
|
||||
liveActivityColor: currentColor.withAlpha(255));
|
||||
Navigator.of(context).maybePop();
|
||||
liveActivityColor: currentColor.withAlpha(255));
|
||||
Navigator.of(context).maybePop();
|
||||
});
|
||||
},
|
||||
elevation: 0,
|
||||
|
@ -17,8 +17,12 @@ class ShareProvider extends ChangeNotifier {
|
||||
// Future<void> shareTheme({required SharedTheme theme}) async {
|
||||
|
||||
// }
|
||||
|
||||
// themes
|
||||
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 =
|
||||
Provider.of<SettingsProvider>(context, listen: false);
|
||||
|
||||
@ -38,7 +42,7 @@ class ShareProvider extends ChangeNotifier {
|
||||
const Color(0xFF3D7BF4).value,
|
||||
};
|
||||
|
||||
SharedTheme theme = SharedTheme.fromJson(themeJson);
|
||||
SharedTheme theme = SharedTheme.fromJson(themeJson, gradeColors.json);
|
||||
FilcAPI.addSharedTheme(theme);
|
||||
|
||||
return theme;
|
||||
@ -49,8 +53,52 @@ class ShareProvider extends ChangeNotifier {
|
||||
Map? themeJson = await FilcAPI.getSharedTheme(id);
|
||||
|
||||
if (themeJson != null) {
|
||||
SharedTheme theme = SharedTheme.fromJson(themeJson);
|
||||
return theme;
|
||||
Map? gradeColorsJson =
|
||||
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;
|
||||
|
@ -283,8 +283,16 @@ class _PremiumCustomAccentColorSettingState
|
||||
label: "understand".i18n,
|
||||
onTap: () async {
|
||||
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(
|
||||
theme.id,
|
||||
subject: 'share_subj_theme'.i18n,
|
||||
@ -804,6 +812,18 @@ class _PremiumCustomAccentColorSettingState
|
||||
setTheme(settings.theme, true);
|
||||
},
|
||||
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(() {
|
||||
updateCustomColor(
|
||||
null,
|
||||
|
Loading…
x
Reference in New Issue
Block a user