Skip to content

Commit

Permalink
Feature/accessible offline (#111)
Browse files Browse the repository at this point in the history
* Added networking service

* Redirect to dashboard if there is no connectivity and was previously logged in

* Force cache only mode when the user has connectivity issues

* Partially fixed repository tests that now uses the networking service

* Fixed most tests impacted by the networking service

* stubHasConnectivity renamed

* Fixed tests that were crashing due to asynchronous code

* Added tests that ensures data is fetched from cache when user has no connectiviity

* Added no connection toast

* Moved no connection toast to Utils

* Fixed viewmodels tests impacted by the networkingService

* Removed forgotten unused import

* Fixed views related tests

* Changing the behaviour of fromCacheOnly to avoid reloading the cache when not necessary.

* Added network type to github issue

* updated dependencies

* Reordered imports

Co-authored-by: Xavier Chretien <[email protected]>
  • Loading branch information
JonathanDuvalV and apomalyn authored May 9, 2021
1 parent a773a3f commit 7e07d3d
Show file tree
Hide file tree
Showing 29 changed files with 484 additions and 97 deletions.
Binary file added .DS_Store
Binary file not shown.
140 changes: 85 additions & 55 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,50 +1,71 @@
PODS:
- Firebase/Analytics (7.3.0):
- connectivity (0.0.1):
- Flutter
- Reachability
- Firebase/Analytics (7.11.0):
- Firebase/Core
- Firebase/Core (7.3.0):
- Firebase/Core (7.11.0):
- Firebase/CoreOnly
- FirebaseAnalytics (= 7.3.0)
- Firebase/CoreOnly (7.3.0):
- FirebaseCore (= 7.3.0)
- Firebase/Crashlytics (7.3.0):
- FirebaseAnalytics (~> 7.11.0)
- Firebase/CoreOnly (7.11.0):
- FirebaseCore (= 7.11.0)
- Firebase/Crashlytics (7.11.0):
- Firebase/CoreOnly
- FirebaseCrashlytics (~> 7.3.0)
- firebase_analytics (8.0.0):
- Firebase/Analytics (= 7.3.0)
- FirebaseCrashlytics (~> 7.11.0)
- firebase_analytics (8.0.2):
- Firebase/Analytics (= 7.11.0)
- firebase_core
- Flutter
- firebase_core (1.0.3):
- Firebase/CoreOnly (= 7.3.0)
- firebase_core (1.1.0):
- Firebase/CoreOnly (= 7.11.0)
- Flutter
- firebase_crashlytics (2.0.0):
- Firebase/Crashlytics (= 7.3.0)
- firebase_crashlytics (2.0.2):
- Firebase/Crashlytics (= 7.11.0)
- firebase_core
- Flutter
- FirebaseAnalytics (7.3.0):
- FirebaseAnalytics (7.11.0):
- FirebaseAnalytics/AdIdSupport (= 7.11.0)
- FirebaseCore (~> 7.0)
- FirebaseInstallations (~> 7.0)
- GoogleUtilities/AppDelegateSwizzler (~> 7.0)
- GoogleUtilities/MethodSwizzler (~> 7.0)
- GoogleUtilities/Network (~> 7.0)
- "GoogleUtilities/NSData+zlib (~> 7.0)"
- nanopb (~> 2.30908.0)
- FirebaseAnalytics/AdIdSupport (7.11.0):
- FirebaseAnalytics/Base (= 7.11.0)
- FirebaseCore (~> 7.0)
- FirebaseInstallations (~> 7.0)
- GoogleAppMeasurement (= 7.3.0)
- GoogleAppMeasurement/AdIdSupport (= 7.11.0)
- GoogleUtilities/AppDelegateSwizzler (~> 7.0)
- GoogleUtilities/MethodSwizzler (~> 7.0)
- GoogleUtilities/Network (~> 7.0)
- "GoogleUtilities/NSData+zlib (~> 7.0)"
- nanopb (~> 2.30906.0)
- FirebaseCore (7.3.0):
- FirebaseCoreDiagnostics (~> 7.0)
- nanopb (~> 2.30908.0)
- FirebaseAnalytics/Base (7.11.0):
- FirebaseCore (~> 7.0)
- FirebaseInstallations (~> 7.0)
- GoogleUtilities/AppDelegateSwizzler (~> 7.0)
- GoogleUtilities/MethodSwizzler (~> 7.0)
- GoogleUtilities/Network (~> 7.0)
- "GoogleUtilities/NSData+zlib (~> 7.0)"
- nanopb (~> 2.30908.0)
- FirebaseCore (7.11.0):
- FirebaseCoreDiagnostics (~> 7.4)
- GoogleUtilities/Environment (~> 7.0)
- GoogleUtilities/Logger (~> 7.0)
- FirebaseCoreDiagnostics (7.3.0):
- GoogleDataTransport (~> 8.0)
- FirebaseCoreDiagnostics (7.11.0):
- GoogleDataTransport (~> 8.4)
- GoogleUtilities/Environment (~> 7.0)
- GoogleUtilities/Logger (~> 7.0)
- nanopb (~> 2.30906.0)
- FirebaseCrashlytics (7.3.0):
- nanopb (~> 2.30908.0)
- FirebaseCrashlytics (7.11.0):
- FirebaseCore (~> 7.0)
- FirebaseInstallations (~> 7.0)
- GoogleDataTransport (~> 8.0)
- nanopb (~> 2.30906.0)
- GoogleDataTransport (~> 8.4)
- nanopb (~> 2.30908.0)
- PromisesObjC (~> 1.2)
- FirebaseInstallations (7.7.0):
- FirebaseInstallations (7.11.0):
- FirebaseCore (~> 7.0)
- GoogleUtilities/Environment (~> 7.0)
- GoogleUtilities/UserDefaults (~> 7.0)
Expand All @@ -70,49 +91,52 @@ PODS:
- google_maps_flutter (0.0.1):
- Flutter
- GoogleMaps (< 3.10)
- GoogleAppMeasurement (7.3.0):
- GoogleAppMeasurement/AdIdSupport (7.11.0):
- GoogleUtilities/AppDelegateSwizzler (~> 7.0)
- GoogleUtilities/MethodSwizzler (~> 7.0)
- GoogleUtilities/Network (~> 7.0)
- "GoogleUtilities/NSData+zlib (~> 7.0)"
- nanopb (~> 2.30906.0)
- GoogleDataTransport (8.1.0):
- nanopb (~> 2.30906.0)
- nanopb (~> 2.30908.0)
- GoogleDataTransport (8.4.0):
- GoogleUtilities/Environment (~> 7.2)
- nanopb (~> 2.30908.0)
- PromisesObjC (~> 1.2)
- GoogleMaps (3.9.0):
- GoogleMaps/Maps (= 3.9.0)
- GoogleMaps/Base (3.9.0)
- GoogleMaps/Maps (3.9.0):
- GoogleMaps/Base
- GoogleUtilities/AppDelegateSwizzler (7.2.2):
- GoogleUtilities/AppDelegateSwizzler (7.4.0):
- GoogleUtilities/Environment
- GoogleUtilities/Logger
- GoogleUtilities/Network
- GoogleUtilities/Environment (7.2.2):
- GoogleUtilities/Environment (7.4.0):
- PromisesObjC (~> 1.2)
- GoogleUtilities/Logger (7.2.2):
- GoogleUtilities/Logger (7.4.0):
- GoogleUtilities/Environment
- GoogleUtilities/MethodSwizzler (7.2.2):
- GoogleUtilities/MethodSwizzler (7.4.0):
- GoogleUtilities/Logger
- GoogleUtilities/Network (7.2.2):
- GoogleUtilities/Network (7.4.0):
- GoogleUtilities/Logger
- "GoogleUtilities/NSData+zlib"
- GoogleUtilities/Reachability
- "GoogleUtilities/NSData+zlib (7.2.2)"
- GoogleUtilities/Reachability (7.2.2):
- "GoogleUtilities/NSData+zlib (7.4.0)"
- GoogleUtilities/Reachability (7.4.0):
- GoogleUtilities/Logger
- GoogleUtilities/UserDefaults (7.2.2):
- GoogleUtilities/UserDefaults (7.4.0):
- GoogleUtilities/Logger
- nanopb (2.30906.0):
- nanopb/decode (= 2.30906.0)
- nanopb/encode (= 2.30906.0)
- nanopb/decode (2.30906.0)
- nanopb/encode (2.30906.0)
- nanopb (2.30908.0):
- nanopb/decode (= 2.30908.0)
- nanopb/encode (= 2.30908.0)
- nanopb/decode (2.30908.0)
- nanopb/encode (2.30908.0)
- OrderedSet (5.0.0)
- package_info (0.0.1):
- Flutter
- path_provider (0.0.1):
- Flutter
- PromisesObjC (1.2.12)
- Reachability (3.2)
- shared_preferences (0.0.1):
- Flutter
- sqflite (0.0.2):
Expand All @@ -125,6 +149,7 @@ PODS:
- Flutter

DEPENDENCIES:
- connectivity (from `.symlinks/plugins/connectivity/ios`)
- firebase_analytics (from `.symlinks/plugins/firebase_analytics/ios`)
- firebase_core (from `.symlinks/plugins/firebase_core/ios`)
- firebase_crashlytics (from `.symlinks/plugins/firebase_crashlytics/ios`)
Expand Down Expand Up @@ -157,9 +182,12 @@ SPEC REPOS:
- nanopb
- OrderedSet
- PromisesObjC
- Reachability
- Toast

EXTERNAL SOURCES:
connectivity:
:path: ".symlinks/plugins/connectivity/ios"
firebase_analytics:
:path: ".symlinks/plugins/firebase_analytics/ios"
firebase_core:
Expand Down Expand Up @@ -192,31 +220,33 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/webview_flutter/ios"

SPEC CHECKSUMS:
Firebase: 26223c695fe322633274198cb19dca8cb7e54416
firebase_analytics: b0d6f5a3c2208510a14b7e9f5b7f3a03b284a386
firebase_core: b5d81dfd4fb2d6f700e67de34d9a633ae325c4e9
firebase_crashlytics: 3b8018f6c88a59be95f9e2f38f04e5c0f05e0c6a
FirebaseAnalytics: 2580c2d62535ae7b644143d48941fcc239ea897a
FirebaseCore: 4d3c72622ce0e2106aaa07bb4b2935ba2c370972
FirebaseCoreDiagnostics: d50e11039e5984d92c8a512be2395f13df747350
FirebaseCrashlytics: d31325312c92e2cb2f0386d589b9aa44e303d99b
FirebaseInstallations: 42c86e7b02ff75b7f27f85833bf5dcb5f38a9774
connectivity: c4130b2985d4ef6fd26f9702e886bd5260681467
Firebase: c121feb35e4126c0b355e3313fa9b487d47319fd
firebase_analytics: 620e8cc1705feb6b9c40b6127bea9b39e03e3970
firebase_core: 84dcd80ac6d29c3d1039071b7306ee99688eb9c7
firebase_crashlytics: 1bf37e6bace6394a2bab8f316de395f49a836189
FirebaseAnalytics: cd3bd84d722a24a8923918af8af8e5236f615d77
FirebaseCore: 907447d8917a4d3eb0cce2829c5a0ad21d90b432
FirebaseCoreDiagnostics: 68ad972f99206cef818230f3f3179d52ccfb7f8c
FirebaseCrashlytics: 272b675aa9d1e9bae1f9e1449fcc1f2cf6042806
FirebaseInstallations: a58d4f72ec5861840b84df489f2668d970df558a
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
flutter_config: 2226c1df19c78fe34a05eb7f1363445f18e76fc1
flutter_inappwebview: bfd58618f49dc62f2676de690fc6dcda1d6c3721
flutter_secure_storage: 7953c38a04c3fdbb00571bcd87d8e3b5ceb9daec
fluttertoast: 6122fa75143e992b1d3470f61000f591a798cc58
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
google_maps_flutter: c7f9c73576de1fbe152a227bfd6e6c4ae8088619
GoogleAppMeasurement: 8d3c0aeede16ab7764144b5a4ca8e1d4323841b7
GoogleDataTransport: 116c84c4bdeb76be2a7a46de51244368f9794eab
GoogleAppMeasurement: fd19169c3034975cb934e865e5667bfdce59df7f
GoogleDataTransport: cd9db2180fcecd8da1b561aea31e3e56cf834aa7
GoogleMaps: 4b5346bddfe6911bb89155d43c903020170523ac
GoogleUtilities: 31c5b01f978a70c6cff2afc6272b3f1921614b43
nanopb: 1bf24dd71191072e120b83dd02d08f3da0d65e53
GoogleUtilities: 284cddc7fffc14ae1907efb6f78ab95c1fccaedc
nanopb: a0ba3315591a9ae0a16a309ee504766e90db0c96
OrderedSet: aaeb196f7fef5a9edf55d89760da9176ad40b93c
package_info: 873975fc26034f0b863a300ad47e7f1ac6c7ec62
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c
PromisesObjC: 3113f7f76903778cf4a0586bd1ab89329a0b7b97
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d
sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904
Toast: 91b396c56ee72a5790816f40d3a94dd357abc196
Expand Down
34 changes: 26 additions & 8 deletions lib/core/managers/course_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:logger/logger.dart';

// SERVICES
import 'package:notredame/core/services/analytics_service.dart';
import 'package:notredame/core/services/networking_service.dart';
import 'package:notredame/core/services/signets_api.dart';
import 'package:notredame/core/managers/cache_manager.dart';
import 'package:notredame/core/managers/user_repository.dart';
Expand Down Expand Up @@ -51,6 +52,9 @@ class CourseRepository {
/// Cache manager to access and update the cache.
final CacheManager _cacheManager = locator<CacheManager>();

/// Used to verify if the user has connectivity
final NetworkingService _networkingService = locator<NetworkingService>();

/// Student list of courses
List<Course> _courses;

Expand Down Expand Up @@ -82,8 +86,14 @@ class CourseRepository {
/// is updated with the latest version of the activities.
Future<List<CourseActivity>> getCoursesActivities(
{bool fromCacheOnly = false}) async {
// Force fromCacheOnly mode when user has no connectivity
if (!(await _networkingService.hasConnectivity())) {
// ignore: parameter_assignments
fromCacheOnly = true;
}

// Load the activities from the cache if the list doesn't exist
if (_coursesActivities == null) {
if (_coursesActivities == null ) {
_coursesActivities = [];
try {
final List responseCache =
Expand All @@ -96,15 +106,16 @@ class CourseRepository {
.toList();
_logger.d(
"$tag - getCoursesActivities: ${_coursesActivities.length} activities loaded from cache");
if (fromCacheOnly) {
return _coursesActivities;
}
} on CacheException catch (_) {
_logger.e(
"$tag - getCoursesActivities: exception raised will trying to load activities from cache.");
}
}

if (fromCacheOnly) {
return _coursesActivities;
}

final List<CourseActivity> fetchedCoursesActivities = [];

try {
Expand Down Expand Up @@ -205,8 +216,14 @@ class CourseRepository {
/// Get the student's course list. After fetching the courses from [SignetsApi],
/// the [CacheManager] is updated with the latest version of the courses.
Future<List<Course>> getCourses({bool fromCacheOnly = false}) async {
// Force fromCacheOnly mode when user has no connectivity
if (!(await _networkingService.hasConnectivity())) {
// ignore: parameter_assignments
fromCacheOnly = true;
}

// Load the activities from the cache if the list doesn't exist
if (_courses == null || fromCacheOnly) {
if (_courses == null) {
_courses = [];
try {
final List responseCache =
Expand All @@ -219,15 +236,16 @@ class CourseRepository {
.toList();
_logger.d(
"$tag - getCourses: ${_courses.length} courses loaded from cache");
if (fromCacheOnly) {
return _courses;
}
} on CacheException catch (_) {
_logger.e(
"$tag - getCourses: exception raised will trying to load courses from cache.");
}
}

if (fromCacheOnly) {
return _courses;
}

final List<Course> fetchedCourses = [];

try {
Expand Down
Loading

0 comments on commit 7e07d3d

Please sign in to comment.