Skip to content

Commit

Permalink
Merge pull request #92 from 'release/v1.0.2'
Browse files Browse the repository at this point in the history
Release v1.0.2
  • Loading branch information
0niel authored Sep 8, 2021
2 parents 0ed1ef2 + 7bcf542 commit 7e29a9d
Show file tree
Hide file tree
Showing 66 changed files with 991 additions and 363 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>
Binary file modified assets/icon.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/icon_background.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/icon_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,4 @@
/* End XCConfigurationList section */
};
rootObject = 97C146E61CF9000F007C117D /* Project object */;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 3 additions & 11 deletions lib/common/calendar.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:clock/clock.dart';

class Calendar {
abstract class Calendar {
/// Maximum number of academic weeks per semester
static const int kMaxWeekInSemester = 16;

Expand All @@ -13,15 +13,7 @@ class Calendar {
static int getCurrentWeek(
{DateTime? mCurrentDate, final Clock clock = const Clock()}) {
DateTime currentDate = mCurrentDate ?? clock.now();
int currentYear = currentDate.year;

DateTime startDate;

if (currentDate.month >= DateTime.september) {
startDate = DateTime.utc(currentYear, 9, 1);
} else {
startDate = DateTime.utc(currentYear, 2, 8);
}
DateTime startDate = getSemesterStart(mCurrentDate: currentDate);

int week = 1;
int prevWeekday = startDate.weekday;
Expand Down Expand Up @@ -83,7 +75,7 @@ class Calendar {
}

/// Get the date when the semester begins
class _CurrentSemesterStart {
abstract class _CurrentSemesterStart {
/// Get the first Monday of the month from which the current semester begins
static DateTime _getFirstMondayOfMonth(int year, int month) {
var firstOfMonth = DateTime(year, month, 1);
Expand Down
17 changes: 17 additions & 0 deletions lib/data/datasources/schedule_local.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';

import 'package:rtu_mirea_app/common/errors/exceptions.dart';
import 'package:rtu_mirea_app/data/models/schedule_model.dart';
import 'package:rtu_mirea_app/data/models/schedule_settings_model.dart';
import 'package:shared_preferences/shared_preferences.dart';

abstract class ScheduleLocalData {
Expand Down Expand Up @@ -35,6 +36,9 @@ abstract class ScheduleLocalData {
/// group is already installed, the name of the active group will be
/// overwritten with [group].
Future<void> setActiveGroupToCache(String group);

Future<void> setSettingsToCache(ScheduleSettingsModel settings);
Future<ScheduleSettingsModel> getSettingsFromCache();
}

class ScheduleLocalDataImpl implements ScheduleLocalData {
Expand Down Expand Up @@ -84,4 +88,17 @@ class ScheduleLocalDataImpl implements ScheduleLocalData {
Future<void> setActiveGroupToCache(String group) {
return sharedPreferences.setString('active_group', group);
}

@override
Future<ScheduleSettingsModel> getSettingsFromCache() {
String? settings = sharedPreferences.getString('schedule_settings');
if (settings == null) throw CacheException('The settings are not set');
return Future.value(ScheduleSettingsModel.fromRawJson(settings));
}

@override
Future<void> setSettingsToCache(ScheduleSettingsModel settings) {
return sharedPreferences.setString(
'schedule_settings', settings.toRawJson());
}
}
4 changes: 3 additions & 1 deletion lib/data/datasources/schedule_remote.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class ScheduleRemoteDataImpl implements ScheduleRemoteData {
final response =
await httpClient.get(_API_BASE_URL + 'schedule/$group/full_schedule');
if (response.statusCode == 200) {
return ScheduleModel.fromJson(response.data);
final data = response.data as Map<String, dynamic>;
data["remote"] = true;
return ScheduleModel.fromJson(data);
} else {
throw ServerException('Response status code is $response.statusCode');
}
Expand Down
7 changes: 5 additions & 2 deletions lib/data/models/schedule_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import 'package:rtu_mirea_app/data/models/lesson_model.dart';
import 'package:rtu_mirea_app/domain/entities/schedule.dart';

class ScheduleModel extends Schedule {
ScheduleModel({required this.group, required this.schedule})
: super(group: group, schedule: schedule);
ScheduleModel(
{required this.isRemote, required this.group, required this.schedule})
: super(isRemote: isRemote, group: group, schedule: schedule);

final bool isRemote;
final String group;
final Map<String, ScheduleWeekdayValueModel> schedule;

Expand All @@ -16,6 +18,7 @@ class ScheduleModel extends Schedule {
String toRawJson() => json.encode(toJson());

factory ScheduleModel.fromJson(Map<String, dynamic> json) => ScheduleModel(
isRemote: json.containsKey("remote") ? json["remote"] : false,
group: json["group"],
schedule: Map.from(json["schedule"]).map((k, v) =>
MapEntry<String, ScheduleWeekdayValueModel>(
Expand Down
32 changes: 32 additions & 0 deletions lib/data/models/schedule_settings_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'dart:convert';
import 'package:rtu_mirea_app/domain/entities/schedule_settings.dart';

class ScheduleSettingsModel extends ScheduleSettings {
ScheduleSettingsModel({
required showEmptyLessons,
required showLessonsNumbers,
required calendarFormat,
}) : super(
showEmptyLessons: showEmptyLessons,
showLessonsNumbers: showLessonsNumbers,
calendarFormat: calendarFormat,
);

factory ScheduleSettingsModel.fromRawJson(String str) =>
ScheduleSettingsModel.fromJson(json.decode(str));

String toRawJson() => json.encode(toJson());

factory ScheduleSettingsModel.fromJson(Map<String, dynamic> json) =>
ScheduleSettingsModel(
showEmptyLessons: json["show_empty_lessons"],
showLessonsNumbers: json["show_lessons_numbers"],
calendarFormat: json["calendar_format"],
);

Map<String, dynamic> toJson() => {
"show_empty_lessons": showEmptyLessons,
"show_lessons_numbers": showLessonsNumbers,
"calendar_format": calendarFormat,
};
}
41 changes: 39 additions & 2 deletions lib/data/repositories/schedule_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import 'package:rtu_mirea_app/common/errors/failures.dart';
import 'package:rtu_mirea_app/data/datasources/schedule_local.dart';
import 'package:rtu_mirea_app/data/datasources/schedule_remote.dart';
import 'package:rtu_mirea_app/data/models/schedule_model.dart';
import 'package:rtu_mirea_app/data/models/schedule_settings_model.dart';
import 'package:rtu_mirea_app/domain/entities/schedule.dart';
import 'package:rtu_mirea_app/domain/entities/schedule_settings.dart';
import 'package:rtu_mirea_app/domain/repositories/schedule_repository.dart';

class ScheduleRepositoryImpl implements ScheduleRepository {
Expand All @@ -21,6 +23,7 @@ class ScheduleRepositoryImpl implements ScheduleRepository {

@override
Future<Either<Failure, List<String>>> getAllGroups() async {
connectionChecker.checkInterval = Duration(seconds: 2);
if (await connectionChecker.hasConnection) {
try {
final groupsList = await remoteDataSource.getGroups();
Expand Down Expand Up @@ -54,8 +57,7 @@ class ScheduleRepositoryImpl implements ScheduleRepository {
}
}

@override
Future<Either<Failure, Schedule>> getSchedule(String group) async {
Future<Either<Failure, Schedule>> _tryGetRemoteSchedule(String group) async {
if (await connectionChecker.hasConnection) {
try {
final ScheduleModel schedule =
Expand Down Expand Up @@ -91,6 +93,16 @@ class ScheduleRepositoryImpl implements ScheduleRepository {
}
}

@override
Future<Either<Failure, Schedule>> getSchedule(
String group, bool fromRemote) async {
if (fromRemote) {
return await _tryGetRemoteSchedule(group);
} else {
return await _tryGetLocalSchedule(group);
}
}

@override
Future<Either<Failure, String>> getActiveGroup() async {
try {
Expand Down Expand Up @@ -131,4 +143,29 @@ class ScheduleRepositoryImpl implements ScheduleRepository {
return;
}
}

@override
Future<ScheduleSettings> getSettings() async {
try {
final localSettings = await localDataSource.getSettingsFromCache();
return localSettings;
} on CacheException {
final newLocalSettings = ScheduleSettingsModel(
showEmptyLessons: false,
showLessonsNumbers: false,
calendarFormat: 2,
);
await localDataSource.setSettingsToCache(newLocalSettings);
return newLocalSettings;
}
}

@override
Future<void> setSettings(ScheduleSettings settings) async {
localDataSource.setSettingsToCache(ScheduleSettingsModel(
showEmptyLessons: settings.showEmptyLessons,
showLessonsNumbers: settings.showLessonsNumbers,
calendarFormat: settings.calendarFormat,
));
}
}
4 changes: 3 additions & 1 deletion lib/domain/entities/schedule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import 'lesson.dart';

class Schedule extends Equatable {
const Schedule({
required this.isRemote,
required this.group,
required this.schedule,
});

final bool isRemote;
final String group;
final Map<String, ScheduleWeekdayValue> schedule;

@override
List<Object?> get props => [group, schedule];
List<Object?> get props => [isRemote, group, schedule];
}

class ScheduleWeekdayValue extends Equatable {
Expand Down
16 changes: 16 additions & 0 deletions lib/domain/entities/schedule_settings.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:equatable/equatable.dart';

class ScheduleSettings extends Equatable {
const ScheduleSettings({
required this.showEmptyLessons,
required this.showLessonsNumbers,
required this.calendarFormat,
});

final bool showEmptyLessons;
final bool showLessonsNumbers;
final int calendarFormat;

@override
List<Object?> get props => [showEmptyLessons, showLessonsNumbers];
}
5 changes: 4 additions & 1 deletion lib/domain/repositories/schedule_repository.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import 'package:dartz/dartz.dart';
import 'package:rtu_mirea_app/common/errors/failures.dart';
import 'package:rtu_mirea_app/domain/entities/schedule.dart';
import 'package:rtu_mirea_app/domain/entities/schedule_settings.dart';

abstract class ScheduleRepository {
Future<Either<Failure, Schedule>> getSchedule(String group);
Future<Either<Failure, Schedule>> getSchedule(String group, bool fromRemote);
Future<Either<Failure, List<Schedule>>> getDownloadedSchedules();
Future<Either<Failure, List<String>>> getAllGroups();
Future<Either<Failure, String>> getActiveGroup();
Future<void> setActiveGroup(String group);
Future<void> deleteSchedule(String group);
Future<void> setSettings(ScheduleSettings settings);
Future<ScheduleSettings> getSettings();
}
8 changes: 5 additions & 3 deletions lib/domain/usecases/get_schedule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ class GetSchedule extends UseCase<Schedule, GetScheduleParams> {

@override
Future<Either<Failure, Schedule>> call(GetScheduleParams params) async {
return await scheduleRepository.getSchedule(params.group);
return await scheduleRepository.getSchedule(
params.group, params.fromRemote);
}
}

class GetScheduleParams extends Equatable {
final String group;
final bool fromRemote;

GetScheduleParams({required this.group});
GetScheduleParams({required this.group, required this.fromRemote});

@override
List<Object?> get props => [group];
List<Object?> get props => [group, fromRemote];
}
14 changes: 14 additions & 0 deletions lib/domain/usecases/get_schedule_settings.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:rtu_mirea_app/domain/entities/schedule_settings.dart';
import 'package:rtu_mirea_app/domain/repositories/schedule_repository.dart';
import 'package:rtu_mirea_app/domain/usecases/usecase.dart';

class GetScheduleSettings extends UseCaseRight<ScheduleSettings, void> {
final ScheduleRepository scheduleRepository;

GetScheduleSettings(this.scheduleRepository);

@override
Future<ScheduleSettings> call([_]) async {
return await scheduleRepository.getSettings();
}
}
26 changes: 26 additions & 0 deletions lib/domain/usecases/set_schedule_settings.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:dartz/dartz.dart';
import 'package:equatable/equatable.dart';
import 'package:rtu_mirea_app/common/errors/failures.dart';
import 'package:rtu_mirea_app/domain/entities/schedule_settings.dart';
import 'package:rtu_mirea_app/domain/repositories/schedule_repository.dart';
import 'package:rtu_mirea_app/domain/usecases/usecase.dart';

class SetScheduleSettings extends UseCase<void, SetScheduleSettingsParams> {
final ScheduleRepository scheduleRepository;

SetScheduleSettings(this.scheduleRepository);

@override
Future<Either<Failure, void>> call(SetScheduleSettingsParams params) async {
return Right(scheduleRepository.setSettings(params.settings));
}
}

class SetScheduleSettingsParams extends Equatable {
final ScheduleSettings settings;

SetScheduleSettingsParams(this.settings);

@override
List<Object?> get props => [settings];
}
4 changes: 4 additions & 0 deletions lib/domain/usecases/usecase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ import 'package:rtu_mirea_app/common/errors/failures.dart';
abstract class UseCase<Type, Params> {
Future<Either<Failure, Type>> call(Params params);
}

abstract class UseCaseRight<Type, Params> {
Future<Type> call(Params params);
}
6 changes: 6 additions & 0 deletions lib/presentation/bloc/map_cubit/map_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class MapCubit extends Cubit<MapState> {
/// Number of the floor we show when screen opens
static int initialFloor = 2;

/// Current floor on the map
static int currentFloor = 2;

/// Number of the last floor we are able to show
static int maxFloor = 4;

Expand Down Expand Up @@ -51,6 +54,9 @@ class MapCubit extends Cubit<MapState> {
emit(MapSearchFoundUpdated(floor: state.floor, foundRooms: foundRooms));
}

/// Set map scale to value
void setMapScale (double scale) => emit(MapScaleSet(floor: currentFloor, scale: scale));

/// Open the floor by [index]
void goToFloor(int index) => emit(MapFloorLoaded(floor: index));
}
14 changes: 13 additions & 1 deletion lib/presentation/bloc/map_cubit/map_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,26 @@ abstract class MapState extends Equatable {
}

class MapFloorLoaded extends MapState {
MapFloorLoaded({required this.floor}) : super(floor: floor);
MapFloorLoaded({required this.floor}) : super(floor: floor) {
MapCubit.currentFloor = floor;
}

final int floor;

@override
List<Object> get props => [floor];
}

class MapScaleSet extends MapState {
MapScaleSet({required this.floor, required this.scale}) : super (floor: floor);

final int floor;
final double scale;

@override
List<Object> get props => [floor, scale];
}

class MapSearchFoundUpdated extends MapState {
MapSearchFoundUpdated({required this.floor, required this.foundRooms})
: super(floor: floor);
Expand Down
Loading

0 comments on commit 7e29a9d

Please sign in to comment.