Skip to content

Commit

Permalink
Added Theming + License page.
Browse files Browse the repository at this point in the history
Added the ability to select a Theme. During that process the nav bar was rewritten to ensure it properly uses the theme colors. This is also true for the card with buttons.
Additionally, moved the privacy/impressum to the drawer and added a View Licence Page to the settings.
  • Loading branch information
Clon1998 committed Apr 15, 2022
1 parent 6be5919 commit 827528b
Show file tree
Hide file tree
Showing 42 changed files with 1,047 additions and 370 deletions.
Binary file added assets/images/RR-Icon_Black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/RR-Icon_Green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added google_fonts/NotoSans-Black.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-BlackItalic.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-Bold.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-BoldItalic.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-ExtraBold.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-ExtraBoldItalic.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-ExtraLight.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-ExtraLightItalic.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-Italic.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-Light.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-LightItalic.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-Medium.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-MediumItalic.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-Regular.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-SemiBold.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-SemiBoldItalic.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-Thin.ttf
Binary file not shown.
Binary file added google_fonts/NotoSans-ThinItalic.ttf
Binary file not shown.
93 changes: 93 additions & 0 deletions google_fonts/OFL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Copyright 2015-2021 Google LLC. All Rights Reserved.

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
10 changes: 9 additions & 1 deletion lib/app/app_setup.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:mobileraker/datasource/moonraker_database_client.dart';
import 'package:mobileraker/domain/hive/gcode_macro.dart';
import 'package:mobileraker/domain/hive/macro_group.dart';
import 'package:mobileraker/domain/hive/machine.dart';
import 'package:mobileraker/domain/hive/macro_group.dart';
import 'package:mobileraker/domain/hive/temperature_preset.dart';
import 'package:mobileraker/domain/hive/webcam_setting.dart';
import 'package:mobileraker/repository/machine_hive_repository.dart';
Expand Down Expand Up @@ -113,3 +114,10 @@ Future<void> setupCat() async {
return Purchases.setup('goog_uzbmaMIthLRzhDyQpPsmvOXbaCK');
}
}

setupLicenseRegistry() {
LicenseRegistry.addLicense(() async* {
final license = await rootBundle.loadString('google_fonts/OFL.txt');
yield LicenseEntryWithLineBreaks(['google_fonts'], license);
});
}
46 changes: 26 additions & 20 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import 'package:mobileraker/service/notification_service.dart';
import 'package:mobileraker/ui/components/bottomsheet/setup_bottom_sheet_ui.dart';
import 'package:mobileraker/ui/components/dialog/setup_dialog_ui.dart';
import 'package:mobileraker/ui/components/snackbar/setup_snackbar.dart';
import 'package:mobileraker/ui/components/theme_builder.dart';
import 'package:mobileraker/ui/theme_setup.dart';
import 'package:mobileraker/util/misc.dart';
import 'package:stacked_services/stacked_services.dart';

import 'app/app_setup.router.dart';
import 'service/setting_service.dart';
import 'ui/views/setting/setting_viewmodel.dart';

String? initialRoute;

Expand All @@ -37,7 +36,9 @@ Future<void> main() async {
setupBottomSheetUi();
await FirebaseAnalytics.instance.logAppOpen();
await setupCat();
setupLicenseRegistry();
initialRoute = await selectInitialRoute();

runApp(EasyLocalization(
child: MyApp(),
supportedLocales: [Locale('en'), Locale('de')],
Expand All @@ -48,27 +49,32 @@ Future<void> main() async {
}

class MyApp extends StatelessWidget {

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Mobileraker',
theme: getLightTheme(context),
darkTheme: getDarkTheme(context),
navigatorKey: StackedService.navigatorKey,
onGenerateRoute: StackedRouter().onGenerateRoute,
initialRoute: initialRoute,
localizationsDelegates: [
FormBuilderLocalizations.delegate,
...context.localizationDelegates
],
supportedLocales: context.supportedLocales,
locale: context.locale,
navigatorObservers: [
StackedService.routeObserver,
FirebaseAnalyticsObserver(analytics: FirebaseAnalytics.instance),
],
return ThemeBuilder(
themePacks: getThemePacks(context),
builder: (BuildContext context,ThemeData? regularTheme,ThemeData? darkTheme,ThemeMode? themeMode) {
return MaterialApp(
title: 'Mobileraker',
theme: regularTheme,
darkTheme: darkTheme,
themeMode: themeMode,
navigatorKey: StackedService.navigatorKey,
onGenerateRoute: StackedRouter().onGenerateRoute,
initialRoute: initialRoute,
localizationsDelegates: [
FormBuilderLocalizations.delegate,
...context.localizationDelegates
],
supportedLocales: context.supportedLocales,
locale: context.locale,
navigatorObservers: [
StackedService.routeObserver,
FirebaseAnalyticsObserver(analytics: FirebaseAnalytics.instance),
],
);
},
);
}
}
9 changes: 9 additions & 0 deletions lib/service/setting_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const String emsKey = 'ems_setting';
const String showBabyAlwaysKey = 'always_babystepping_setting';
const String useTextInputForNumKey = 'text_inpt_for_num_fields';
const String startWithOverviewKey = 'start_with_overview';
const String selectedThemePackKey = 'selectedThemePack';

/// Settings related to the App!
class SettingService {
Expand All @@ -16,4 +17,12 @@ class SettingService {
bool readBool(String key, [bool fallback = false]) {
return _boxSettings.get(key) ?? fallback;
}

Future<void> writeInt(String key, int val) {
return _boxSettings.put(key, val);
}

int readInt(String key, [int fallback = 0]) {
return _boxSettings.get(key) ?? fallback;
}
}
55 changes: 55 additions & 0 deletions lib/service/ui/theme_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:mobileraker/app/app_setup.locator.dart';
import 'package:mobileraker/service/setting_service.dart';
import 'package:mobileraker/ui/themes/theme_pack.dart';
import 'package:provider/provider.dart';
import 'package:rxdart/subjects.dart';

class ThemeService {
ThemeService({required this.themePacks}) {
assert(themePacks.isNotEmpty, 'No ThemePacks provided!');
int themeIndex = min(_settingService.readInt(selectedThemePackKey), themePacks.length-1);
_initialTheme = ThemeModel(themePacks[themeIndex], selectedMode);
_themesController = BehaviorSubject.seeded(_initialTheme);
}

final _settingService = locator<SettingService>();

late final ThemeModel _initialTheme;
final List<ThemePack> themePacks;

ThemeModel get initalTheme => _initialTheme;

ThemeMode selectedMode = ThemeMode.system;

Stream<ThemeModel> get themesStream => _themesController.stream;
late BehaviorSubject<ThemeModel> _themesController;

ThemePack get selectedThemePack => _themesController.value.themePack;

ThemeData get selectedTheme => selectedThemePack.lightTheme;

bool get isDarkMode => selectedMode == ThemeMode.dark;

bool get isLightMode => selectedMode == ThemeMode.light;

selectThemePack(ThemePack themePack) {
_themesController.add(ThemeModel(themePack, selectedMode));
_settingService.writeInt(selectedThemePackKey, themePacks.indexOf(themePack));
}
}


extension ThemeServiceContext on BuildContext {
ThemeService get themeService => Provider.of<ThemeService>(this, listen: false);
}

@immutable
class ThemeModel {
ThemeModel(this.themePack, this.themeMode);

final ThemePack themePack;
final ThemeMode themeMode;
}
2 changes: 1 addition & 1 deletion lib/ui/components/bottomsheet/setup_bottom_sheet_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class _NonPrintingBottomSheet
return Container(
padding: const EdgeInsets.fromLTRB(25, 15, 25, 10),
decoration: BoxDecoration(
color: isDark ? themeData.primaryColor : Colors.white,
color: themeData.bottomSheetTheme.modalBackgroundColor,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15), topRight: Radius.circular(15)),
),
Expand Down
43 changes: 33 additions & 10 deletions lib/ui/components/card_with_button.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flex_color_scheme/flex_color_scheme.dart';
import 'package:flutter/material.dart';

class CardWithButton extends StatelessWidget {
Expand All @@ -14,12 +15,21 @@ class CardWithButton extends StatelessWidget {

final double width;
final Color? backgroundColor;
final Widget child;
final Builder child;
final Widget buttonChild;
final VoidCallback? onTap;

@override
Widget build(BuildContext context) {
var themeData = Theme.of(context);
var _backgroundColor =
backgroundColor ?? themeData.colorScheme.surfaceVariant;
var _onBackgroundColor = (ThemeData.estimateBrightnessForColor(_backgroundColor) ==
Brightness.dark
? Colors.white.blendAlpha(themeData.colorScheme.primary.brighten(20), 0)
: Colors.black
.blendAlpha(themeData.colorScheme.primary.brighten(20), 0));

return Container(
width: width,
padding: CardTheme.of(context).margin ?? const EdgeInsets.all(4),
Expand All @@ -29,23 +39,36 @@ class CardWithButton extends StatelessWidget {
Container(
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: backgroundColor ?? Theme.of(context).primaryColorLight,
color: _backgroundColor,
borderRadius:
BorderRadius.vertical(top: Radius.circular(radius))),
child: Padding(
padding: const EdgeInsets.fromLTRB(12, 18, 12, 12),
child: child,
child: Theme(
data: themeData.copyWith(
textTheme: themeData.textTheme.apply(
bodyColor: _onBackgroundColor, displayColor: _onBackgroundColor),
iconTheme:
themeData.iconTheme.copyWith(color: _onBackgroundColor)),
child: DefaultTextStyle(
style: TextStyle(color: _onBackgroundColor),
child: child,
)),
),
),
TextButton(
style: TextButton.styleFrom(
primary: Colors.white,
backgroundColor: Theme.of(context).primaryColor,
minimumSize: const Size.fromHeight(48),
padding: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(bottom: Radius.circular(radius)),
)),
minimumSize: const Size.fromHeight(48),
padding: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.vertical(bottom: Radius.circular(radius)),
),
primary: themeData.colorScheme.onPrimary,
backgroundColor: themeData.colorScheme.primary,
// onPrimary: Theme.of(context).colorScheme.onSecondary,
onSurface: themeData.colorScheme.onPrimary,
),
child: buttonChild,
onPressed: onTap,
)
Expand Down
Loading

0 comments on commit 827528b

Please sign in to comment.