Skip to content

Commit

Permalink
Added room location style preference
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolONEOfficial committed Mar 15, 2019
1 parent 773be9a commit 64690cb
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 45 deletions.
27 changes: 26 additions & 1 deletion lib/l10n/intl_messages.arb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"@@last_modified": "2019-03-13T23:12:47.891535",
"@@last_modified": "2019-03-15T11:23:20.377340",
"title": "RANEPA (Timetable)",
"@title": {
"type": "text",
Expand Down Expand Up @@ -395,6 +395,31 @@
"type": "text",
"placeholders": {}
},
"roomLocationStyleTitle": "Room location style",
"@roomLocationStyleTitle": {
"type": "text",
"placeholders": {}
},
"roomLocationStyleDescriptionIcon": "Icon showing the location of the room",
"@roomLocationStyleDescriptionIcon": {
"type": "text",
"placeholders": {}
},
"roomLocationStyleDescriptionText": "Text showing the location of the room",
"@roomLocationStyleDescriptionText": {
"type": "text",
"placeholders": {}
},
"roomLocationStyleIcon": "Icon",
"@roomLocationStyleIcon": {
"type": "text",
"placeholders": {}
},
"roomLocationStyleText": "Text",
"@roomLocationStyleText": {
"type": "text",
"placeholders": {}
},
"themeDark": "Dark",
"@themeDark": {
"type": "text",
Expand Down
25 changes: 25 additions & 0 deletions lib/l10n/intl_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,31 @@
"type": "text",
"placeholders": {}
},
"roomLocationStyleTitle": "Отображение аудиторий",
"@roomLocationStyleTitle": {
"type": "text",
"placeholders": {}
},
"roomLocationStyleDescriptionIcon": "Иконка отображающая корпус",
"@roomLocationStyleDescriptionIcon": {
"type": "text",
"placeholders": {}
},
"roomLocationStyleDescriptionText": "Текст отображающий корпус",
"@roomLocationStyleDescriptionText": {
"type": "text",
"placeholders": {}
},
"roomLocationStyleIcon": "Иконка",
"@roomLocationStyleIcon": {
"type": "text",
"placeholders": {}
},
"roomLocationStyleText": "Текст",
"@roomLocationStyleText": {
"type": "text",
"placeholders": {}
},
"themeDark": "Темная",
"@themeDark": {
"type": "text",
Expand Down
5 changes: 5 additions & 0 deletions lib/l10n/messages_messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class MessageLookup extends MessageLookupByLibrary {
"roomLocationAcademy" : MessageLookupByLibrary.simpleMessage("Academy"),
"roomLocationHotel" : MessageLookupByLibrary.simpleMessage("Hotel (St. Pushkin, 8)"),
"roomLocationStudyHostel" : MessageLookupByLibrary.simpleMessage("Study hostel"),
"roomLocationStyleDescriptionIcon" : MessageLookupByLibrary.simpleMessage("Icon showing the location of the room"),
"roomLocationStyleDescriptionText" : MessageLookupByLibrary.simpleMessage("Text showing the location of the room"),
"roomLocationStyleIcon" : MessageLookupByLibrary.simpleMessage("Icon"),
"roomLocationStyleText" : MessageLookupByLibrary.simpleMessage("Text"),
"roomLocationStyleTitle" : MessageLookupByLibrary.simpleMessage("Room location style"),
"saturday" : MessageLookupByLibrary.simpleMessage("Sa"),
"searchResults" : MessageLookupByLibrary.simpleMessage("Web search results"),
"searchTip" : MessageLookupByLibrary.simpleMessage("Search"),
Expand Down
5 changes: 5 additions & 0 deletions lib/l10n/messages_ru.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class MessageLookup extends MessageLookupByLibrary {
"roomLocationAcademy" : MessageLookupByLibrary.simpleMessage("Академия"),
"roomLocationHotel" : MessageLookupByLibrary.simpleMessage("Гостиница (ул. Пушкина, 8)"),
"roomLocationStudyHostel" : MessageLookupByLibrary.simpleMessage("Студенческое общежитие"),
"roomLocationStyleDescriptionIcon" : MessageLookupByLibrary.simpleMessage("Иконка отображающая корпус"),
"roomLocationStyleDescriptionText" : MessageLookupByLibrary.simpleMessage("Текст отображающий корпус"),
"roomLocationStyleIcon" : MessageLookupByLibrary.simpleMessage("Иконка"),
"roomLocationStyleText" : MessageLookupByLibrary.simpleMessage("Текст"),
"roomLocationStyleTitle" : MessageLookupByLibrary.simpleMessage("Отображение аудиторий"),
"saturday" : MessageLookupByLibrary.simpleMessage("Сб"),
"searchResults" : MessageLookupByLibrary.simpleMessage("Результаты веб-поиска"),
"searchTip" : MessageLookupByLibrary.simpleMessage("Поиск"),
Expand Down
35 changes: 35 additions & 0 deletions lib/localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,41 @@ class AppLocalizations {
);
}

String get roomLocationStyleTitle {
return Intl.message(
'Room location style',
name: 'roomLocationStyleTitle',
);
}

String get roomLocationStyleDescriptionIcon {
return Intl.message(
'Icon showing the location of the room',
name: 'roomLocationStyleDescriptionIcon',
);
}

String get roomLocationStyleDescriptionText {
return Intl.message(
'Text showing the location of the room',
name: 'roomLocationStyleDescriptionText',
);
}

String get roomLocationStyleIcon {
return Intl.message(
'Icon',
name: 'roomLocationStyleIcon',
);
}

String get roomLocationStyleText {
return Intl.message(
'Text',
name: 'roomLocationStyleText',
);
}

// Themes titles

String get themeDark {
Expand Down
67 changes: 53 additions & 14 deletions lib/prefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:ranepa_timetable/localizations.dart';
import 'package:ranepa_timetable/main.dart';
import 'package:ranepa_timetable/platform_channels.dart';
import 'package:ranepa_timetable/search.dart';
import 'package:ranepa_timetable/timeline_models.dart';
import 'package:ranepa_timetable/timetable.dart';
import 'package:ranepa_timetable/widget_templates.dart';
import 'package:shared_preferences/shared_preferences.dart';
Expand All @@ -18,6 +19,7 @@ import 'package:flutter_material_color_picker/flutter_material_color_picker.dart

class PrefsIds {
static const LAST_UPDATE = "last_update",
ROOM_LOCATION_STYLE = "room_location_style",
WIDGET_TRANSLUCENT = "widget_translucent",
THEME_PRIMARY = "theme_primary",
THEME_ACCENT = "theme_accent",
Expand Down Expand Up @@ -111,10 +113,10 @@ void showMaterialColorPicker(BuildContext ctx) => showDialog(
class Prefs extends StatelessWidget {
static const ROUTE = "/prefs";

final widgetTranslucent = StreamController<bool>();
final widgetTranslucentBloc = StreamController<bool>();
final roomLocationStyleBloc = StreamController<RoomLocationStyle>();

Widget _buildThemePreferenceButton(
BuildContext ctx, SharedPreferences prefs) =>
Widget _buildThemePreference(BuildContext ctx, SharedPreferences prefs) =>
WidgetTemplates.buildPreferenceButton(
ctx,
title: AppLocalizations.of(ctx).themeTitle,
Expand All @@ -126,7 +128,7 @@ class Prefs extends StatelessWidget {
),
);

Widget _buildThemeAccentPreferenceButton(
Widget _buildThemeAccentPreference(
BuildContext ctx, SharedPreferences prefs) =>
WidgetTemplates.buildPreferenceButton(
ctx,
Expand All @@ -145,11 +147,11 @@ class Prefs extends StatelessWidget {
),
);

Widget _buildWidgetTranslucentPreferenceButton(
Widget _buildWidgetTranslucentPreference(
BuildContext ctx, SharedPreferences prefs) =>
StreamBuilder<bool>(
initialData: prefs.getBool(PrefsIds.WIDGET_TRANSLUCENT) ?? true,
stream: widgetTranslucent.stream,
stream: widgetTranslucentBloc.stream,
builder: (ctx, snapshot) => WidgetTemplates.buildPreferenceButton(
ctx,
title: AppLocalizations.of(ctx).widgetTranslucentTitle,
Expand All @@ -158,7 +160,7 @@ class Prefs extends StatelessWidget {
rightWidget: Checkbox(
value: snapshot.data,
onChanged: (value) {
widgetTranslucent.add(value);
widgetTranslucentBloc.add(value);
prefs.setBool(PrefsIds.WIDGET_TRANSLUCENT, value).then(
(_) => PlatformChannels.refreshWidget(),
);
Expand All @@ -184,7 +186,7 @@ class Prefs extends StatelessWidget {
return duration;
});

Widget _buildBeforeAlarmClockPreferenceButton(
Widget _buildBeforeAlarmClockPreference(
BuildContext ctx, SharedPreferences prefs) =>
WidgetTemplates.buildPreferenceButton(
ctx,
Expand All @@ -209,7 +211,7 @@ class Prefs extends StatelessWidget {
),
);

Widget _buildSearchItemPreferenceButton(
Widget _buildSearchItemPreference(
BuildContext ctx, SharedPreferences prefs) =>
WidgetTemplates.buildPreferenceButton(
ctx,
Expand All @@ -228,6 +230,41 @@ class Prefs extends StatelessWidget {
),
);

Widget _buildRoomLocationStylePreference(
BuildContext ctx, SharedPreferences prefs) =>
StreamBuilder<RoomLocationStyle>(
initialData: RoomLocationStyle
.values[prefs.getInt(PrefsIds.ROOM_LOCATION_STYLE) ?? 0],
stream: roomLocationStyleBloc.stream,
builder: (ctx, snapshot) => WidgetTemplates.buildPreferenceButton(
ctx,
title: AppLocalizations.of(ctx).widgetTranslucentTitle,
description: snapshot.data == RoomLocationStyle.Icon
? AppLocalizations.of(ctx).roomLocationStyleDescriptionIcon
: AppLocalizations.of(ctx).roomLocationStyleDescriptionText,
rightWidget: Row(
children: <Widget>[
Text(AppLocalizations.of(ctx).roomLocationStyleText),
Switch(
value: snapshot.data == RoomLocationStyle.Icon,
onChanged: (value) {
var rlStyle = value
? RoomLocationStyle.Icon
: RoomLocationStyle.Text;
roomLocationStyleBloc.add(rlStyle);
prefs
.setInt(PrefsIds.ROOM_LOCATION_STYLE, rlStyle.index)
.then(
(_) => PlatformChannels.refreshWidget(),
);
},
),
Text(AppLocalizations.of(ctx).roomLocationStyleIcon),
],
),
),
);

@override
Widget build(BuildContext ctx) => Scaffold(
appBar: AppBar(
Expand All @@ -239,15 +276,17 @@ class Prefs extends StatelessWidget {
),
body: ListView(
children: <Widget>[
_buildThemePreferenceButton(ctx, prefs),
_buildThemePreference(ctx, prefs),
Divider(height: 0),
_buildThemeAccentPreference(ctx, prefs),
Divider(height: 0),
_buildThemeAccentPreferenceButton(ctx, prefs),
_buildSearchItemPreference(ctx, prefs),
Divider(height: 0),
_buildSearchItemPreferenceButton(ctx, prefs),
_buildBeforeAlarmClockPreference(ctx, prefs),
Divider(height: 0),
_buildBeforeAlarmClockPreferenceButton(ctx, prefs),
_buildWidgetTranslucentPreference(ctx, prefs),
Divider(height: 0),
_buildWidgetTranslucentPreferenceButton(ctx, prefs),
_buildRoomLocationStylePreference(ctx, prefs),
Divider(height: 0),
],
),
Expand Down
44 changes: 38 additions & 6 deletions lib/timeline_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TimelineElement extends StatelessWidget {
Widget _buildLine(BuildContext ctx) => SizedBox.expand(
child: Container(
child: CustomPaint(
painter: TimelinePainter(ctx, model),
painter: TimelinePainter(ctx, model, prefs),
),
),
);
Expand Down Expand Up @@ -80,10 +80,34 @@ class TimelineElement extends StatelessWidget {
),
);

Widget _buildRoomLocation(BuildContext ctx) => Text(
model.room.number,
style: Theme.of(ctx).textTheme.subtitle,
);
Widget _buildRoomLocation(BuildContext ctx) {
String prefix;
switch (model.room.location) {
case RoomLocation.Academy:
prefix = "";
break;
case RoomLocation.StudyHostel:
prefix = "СО-";
break;
case RoomLocation.Hotel:
prefix = "П8-";
break;
}

return Text(
RoomLocationStyle
.values[prefs.getInt(PrefsIds.ROOM_LOCATION_STYLE) ?? 0] ==
RoomLocationStyle.Text
? prefix + model.room.number
: model.room.number,
style: Theme.of(ctx).textTheme.subtitle,
textAlign: RoomLocationStyle
.values[prefs.getInt(PrefsIds.ROOM_LOCATION_STYLE) ?? 0] ==
RoomLocationStyle.Text
? TextAlign.center
: TextAlign.start,
);
}

static const innerPadding = 4.0;

Expand All @@ -104,7 +128,15 @@ class TimelineElement extends StatelessWidget {
],
),
Padding(
padding: const EdgeInsets.only(left: 22, bottom: 2, top: 8),
padding: EdgeInsets.only(
left: RoomLocationStyle.values[
prefs.getInt(PrefsIds.ROOM_LOCATION_STYLE) ??
0] ==
RoomLocationStyle.Icon
? 22
: 2,
bottom: 2,
top: 8),
child: _buildRoomLocation(ctx),
),
],
Expand Down
2 changes: 2 additions & 0 deletions lib/timeline_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class TimelineModel {
Map<String, dynamic> toJson() => _$TimelineModelToJson(this);
}

enum RoomLocationStyle { Text, Icon }

enum RoomLocation { Academy, Hotel, StudyHostel }

class RoomLocationsTitles {
Expand Down
Loading

0 comments on commit 64690cb

Please sign in to comment.