forked from firka/student-legacy
added theme sharing to providers and api
This commit is contained in:
parent
db7b126bda
commit
991097fa34
13
filcnaplo/ios/Flutter/flutter_export_environment 5.sh
Executable file
13
filcnaplo/ios/Flutter/flutter_export_environment 5.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
# This is a generated file; do not edit or check into version control.
|
||||
export "FLUTTER_ROOT=/Users/kima/src/flutter"
|
||||
export "FLUTTER_APPLICATION_PATH=/Users/kima/Documents/refilc/app/naplo/filcnaplo"
|
||||
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
|
||||
export "FLUTTER_TARGET=lib/main.dart"
|
||||
export "FLUTTER_BUILD_DIR=build"
|
||||
export "FLUTTER_BUILD_NAME=4.2.2"
|
||||
export "FLUTTER_BUILD_NUMBER=222"
|
||||
export "DART_OBFUSCATION=false"
|
||||
export "TRACK_WIDGET_CREATION=true"
|
||||
export "TREE_SHAKE_ICONS=false"
|
||||
export "PACKAGE_CONFIG=.dart_tool/package_config.json"
|
@ -6,6 +6,7 @@ import 'package:filcnaplo/models/config.dart';
|
||||
import 'package:filcnaplo/models/news.dart';
|
||||
import 'package:filcnaplo/models/release.dart';
|
||||
import 'package:filcnaplo/models/settings.dart';
|
||||
import 'package:filcnaplo/models/shared_theme.dart';
|
||||
import 'package:filcnaplo/models/supporter.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/school.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
@ -13,15 +14,18 @@ import 'package:http/http.dart' as http;
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
|
||||
class FilcAPI {
|
||||
// API base
|
||||
static const baseUrl = "https://api.refilc.hu";
|
||||
|
||||
// Public API
|
||||
static const schoolList = "https://api.refilc.hu/v1/public/school-list";
|
||||
static const news = "https://api.refilc.hu/v1/public/news";
|
||||
static const supporters = "https://api.refilc.hu/v1/public/supporters";
|
||||
static const schoolList = "$baseUrl/v1/public/school-list";
|
||||
static const news = "$baseUrl/v1/public/news";
|
||||
static const supporters = "$baseUrl/v1/public/supporters";
|
||||
|
||||
// Private API
|
||||
static const ads = "https://api.refilc.hu/v1/private/ads";
|
||||
static const config = "https://api.refilc.hu/v1/private/config";
|
||||
static const reportApi = "https://api.refilc.hu/v1/private/crash-report";
|
||||
static const ads = "$baseUrl/v1/private/ads";
|
||||
static const config = "$baseUrl/v1/private/config";
|
||||
static const reportApi = "$baseUrl/v1/private/crash-report";
|
||||
static const premiumApi = "https://api.filcnaplo.hu/premium/activate";
|
||||
// static const premiumScopesApi = "https://api.filcnaplo.hu/premium/scopes";
|
||||
|
||||
@ -29,6 +33,9 @@ class FilcAPI {
|
||||
static const repo = "refilc/naplo";
|
||||
static const releases = "https://api.github.com/repos/$repo/releases";
|
||||
|
||||
// Share API
|
||||
static const themeShare = "$baseUrl/v2/shared/theme/add";
|
||||
|
||||
static Future<bool> checkConnectivity() async =>
|
||||
(await Connectivity().checkConnectivity()) != ConnectivityResult.none;
|
||||
|
||||
@ -183,6 +190,20 @@ class FilcAPI {
|
||||
log("ERROR: FilcAPI.sendReport: $error $stacktrace");
|
||||
}
|
||||
}
|
||||
|
||||
// sharing
|
||||
static Future<void> addSharedTheme(SharedTheme theme) async {
|
||||
try {
|
||||
http.Response res =
|
||||
await http.post(Uri.parse(themeShare), body: theme.json);
|
||||
|
||||
if (res.statusCode != 200) {
|
||||
throw "HTTP ${res.statusCode}: ${res.body}";
|
||||
}
|
||||
} on Exception catch (error, stacktrace) {
|
||||
log("ERROR: FilcAPI.addSharedTheme: $error $stacktrace");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ErrorReport {
|
||||
|
@ -313,7 +313,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
bellDelay: 0,
|
||||
gradeOpeningFun: true,
|
||||
iconPack: IconPack.cupertino,
|
||||
customAccentColor: const Color(0xff20AC9B),
|
||||
customAccentColor: const Color(0xff3D7BF4),
|
||||
customBackgroundColor: const Color(0xff000000),
|
||||
customHighlightColor: const Color(0xff222222),
|
||||
premiumScopes: [PremiumScopes.all],
|
||||
|
33
filcnaplo/lib/models/shared_theme.dart
Normal file
33
filcnaplo/lib/models/shared_theme.dart
Normal file
@ -0,0 +1,33 @@
|
||||
import 'dart:ui';
|
||||
|
||||
class SharedTheme {
|
||||
Map json;
|
||||
String id;
|
||||
bool isPublic;
|
||||
String nickname;
|
||||
Color backgroundColor;
|
||||
Color panelsColor;
|
||||
Color accentColor;
|
||||
|
||||
SharedTheme({
|
||||
required this.json,
|
||||
required this.id,
|
||||
this.isPublic = false,
|
||||
this.nickname = 'Anonymous',
|
||||
required this.backgroundColor,
|
||||
required this.panelsColor,
|
||||
required this.accentColor,
|
||||
});
|
||||
|
||||
factory SharedTheme.fromJson(Map json) {
|
||||
return SharedTheme(
|
||||
json: json,
|
||||
id: json['public_id'],
|
||||
isPublic: json['is_public'] ?? false,
|
||||
nickname: json['nickname'] ?? 'Anonymous',
|
||||
backgroundColor: json['background_color'],
|
||||
panelsColor: json['panels_color'],
|
||||
accentColor: json['accent_color'],
|
||||
);
|
||||
}
|
||||
}
|
43
filcnaplo_premium/lib/providers/share_provider.dart
Normal file
43
filcnaplo_premium/lib/providers/share_provider.dart
Normal file
@ -0,0 +1,43 @@
|
||||
import 'package:filcnaplo/api/client.dart';
|
||||
import 'package:filcnaplo/api/providers/user_provider.dart';
|
||||
import 'package:filcnaplo/models/settings.dart';
|
||||
import 'package:filcnaplo/models/shared_theme.dart';
|
||||
// import 'package:filcnaplo/models/shared_theme.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class ShareProvider extends ChangeNotifier {
|
||||
final UserProvider _user;
|
||||
|
||||
ShareProvider({
|
||||
required UserProvider user,
|
||||
}) : _user = user;
|
||||
|
||||
// Future<void> shareTheme({required SharedTheme theme}) async {
|
||||
|
||||
// }
|
||||
Future<void> shareCurrentTheme(BuildContext context,
|
||||
{bool isPublic = false, bool shareNick = true}) async {
|
||||
final SettingsProvider settings = Provider.of<SettingsProvider>(context);
|
||||
|
||||
Map themeJson = {
|
||||
'public_id': const Uuid().v4(),
|
||||
'is_public': isPublic,
|
||||
'nickname': shareNick ? _user.nickname : 'Anonymous',
|
||||
'background_color': (settings.customBackgroundColor ??
|
||||
SettingsProvider.defaultSettings().customBackgroundColor)
|
||||
?.value,
|
||||
'panels_color': (settings.customHighlightColor ??
|
||||
SettingsProvider.defaultSettings().customHighlightColor)
|
||||
?.value,
|
||||
'accent_color': (settings.customAccentColor ??
|
||||
SettingsProvider.defaultSettings().customAccentColor)
|
||||
?.value,
|
||||
};
|
||||
|
||||
SharedTheme theme = SharedTheme.fromJson(themeJson);
|
||||
|
||||
FilcAPI.addSharedTheme(theme);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user