Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network Interceptor for noticeboard mobile #35

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- [@Sparsh1212](https://github.com/Sparsh1212)
- [@just-ary27](https://github.com/just-ary27)
- [@kmrinal19](https://github.com/kmrinal19)
- [@kmrinal19](https://github.com/kmrinal19)
- [@pranavkonidena](https://github.com/pranavkonidena)
2 changes: 1 addition & 1 deletion noticeboard/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>12.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion noticeboard/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
platform :ios, '10.0'
platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
14 changes: 7 additions & 7 deletions noticeboard/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PODS:
- firebase_core (2.24.2):
- Firebase/CoreOnly (= 10.18.0)
- Flutter
- firebase_messaging (14.7.9):
- firebase_messaging (14.7.10):
- Firebase/Messaging (= 10.18.0)
- firebase_core
- Flutter
Expand Down Expand Up @@ -119,23 +119,23 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Firebase: 414ad272f8d02dfbf12662a9d43f4bba9bec2a06
firebase_core: 0af4a2b24f62071f9bf283691c0ee41556dcb3f5
firebase_messaging: 875385354f623750aa03204a028d640108bc3412
firebase_messaging: 90e8a6db84b6e1e876cebce4f30f01dc495e7014
FirebaseCore: 2322423314d92f946219c8791674d2f3345b598f
FirebaseCoreInternal: b444828ea7cfd594fca83046b95db98a2be4f290
FirebaseInstallations: 033d199474164db20c8350736842a94fe717b960
FirebaseMessaging: 9bc34a98d2e0237e1b121915120d4d48ddcf301e
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_secure_storage: 23fc622d89d073675f2eaa109381aefbcf5a49be
GoogleDataTransport: 57c22343ab29bc686febbf7cbb13bad167c2d8fe
GoogleUtilities: 0759d1a57ebb953965c2dfe0ba4c82e95ccc2e34
nanopb: d4d75c12cd1316f4a64e3c6963f879ecd4b5e0d5
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c
PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4
share_plus: c3fef564749587fc939ef86ffb283ceac0baf9f5
uni_links: d97da20c7701486ba192624d99bffaaffcfc298a
url_launcher_ios: bf5ce03e0e2088bad9cc378ea97fa0ed5b49673b
webview_flutter_wkwebview: b7e70ef1ddded7e69c796c7390ee74180182971f
url_launcher_ios: bbd758c6e7f9fd7b5b1d4cde34d2b95fcce5e812
webview_flutter_wkwebview: be0f0d33777f1bfd0c9fdcb594786704dbf65f36

PODFILE CHECKSUM: f3c6bbf2cd440a5be9eae241d089fc1e5c9e4ade
PODFILE CHECKSUM: 7b33e402635c950b38d380dc47108a3f46f265c2

COCOAPODS: 1.14.3
14 changes: 7 additions & 7 deletions noticeboard/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -346,7 +346,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
ONLY_ACTIVE_ARCH = NO;
SDKROOT = iphoneos;
Expand All @@ -372,7 +372,7 @@
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Noticeboard;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.education";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -436,7 +436,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = NO;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -485,7 +485,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -512,7 +512,7 @@
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Noticeboard;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.education";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -546,7 +546,7 @@
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Noticeboard;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.education";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
5 changes: 5 additions & 0 deletions noticeboard/ios/Runner/Runner.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
pranavkonidena marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
pranavkonidena marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
49 changes: 49 additions & 0 deletions noticeboard/lib/bloc/connectivity_status_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:noticeboard/bloc/notice_detail_bloc.dart';
import 'package:noticeboard/enum/connectivity_status_enum.dart';
import 'package:noticeboard/enum/current_widget_enum.dart';

class ConnectivityStatusBloc {
late BuildContext context;
late CurrentWidget currentWidget;
final _eventController = StreamController<ConnectivityStatus>.broadcast();
StreamSink<ConnectivityStatus> get eventSink => _eventController.sink;
Stream<ConnectivityStatus> get _eventStream => _eventController.stream;
ConnectivityStatus previousResult = ConnectivityStatus.connected;

static final ConnectivityStatusBloc _connectivityStatusBloc =
ConnectivityStatusBloc._();

final networkSnackBar =
const SnackBar(content: Text("Please check your internet connection!"));
final backOnlineSnackbar = const SnackBar(content: Text("Back online!"));

factory ConnectivityStatusBloc() => _connectivityStatusBloc;
final NoticeDetailBloc _noticeDetailBloc = NoticeDetailBloc();

ConnectivityStatusBloc._() {
_eventStream.listen((connectivityEvent) {
if (connectivityEvent == ConnectivityStatus.notConnected &&
previousResult == ConnectivityStatus.connected &&
context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(networkSnackBar);
} else if (connectivityEvent == ConnectivityStatus.connected &&
previousResult == ConnectivityStatus.notConnected) {
ScaffoldMessenger.of(context).showSnackBar(backOnlineSnackbar);
if (currentWidget == CurrentWidget.noticeDetail) {
// Add an event in the sink so that notice detail webview can be refetched
_noticeDetailBloc.eventSink.add(CurrentWidget.noticeDetail);
} else {
// User is on list of notices , refetch them
_noticeDetailBloc.eventSink.add(CurrentWidget.listNotices);
}
}
previousResult = connectivityEvent;
});
}

void disposeStream() {
_eventController.close();
}
}
1 change: 0 additions & 1 deletion noticeboard/lib/bloc/list_notices_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ class ListNoticesBloc {
DynamicFetch.fetchInstituteNotices)
filterResult.endpoint =
'api/noticeboard/institute_notices/?start=${filterResult.startDate}&end=${filterResult.endDate}';
// TODO: Add the if condition for Institute Notices case
}
PaginatedInfo paginatedInfo = await _listNoticesRepository
.fetchFilteredNotices(filterResult.endpoint!, page);
Expand Down
12 changes: 12 additions & 0 deletions noticeboard/lib/bloc/notice_detail_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'dart:async';

import 'package:noticeboard/enum/current_widget_enum.dart';

class NoticeDetailBloc {
final _eventController = StreamController<CurrentWidget>.broadcast();
StreamSink<CurrentWidget> get eventSink => _eventController.sink;
Stream<CurrentWidget> get eventStream => _eventController.stream;
static final NoticeDetailBloc _noticeDetailBloc = NoticeDetailBloc._();
factory NoticeDetailBloc() => _noticeDetailBloc;
NoticeDetailBloc._();
}
4 changes: 4 additions & 0 deletions noticeboard/lib/enum/connectivity_status_enum.dart
pranavkonidena marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enum ConnectivityStatus{
connected ,
notConnected
}
4 changes: 4 additions & 0 deletions noticeboard/lib/enum/current_widget_enum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enum CurrentWidget {
pranavkonidena marked this conversation as resolved.
Show resolved Hide resolved
listNotices,
noticeDetail
}
28 changes: 28 additions & 0 deletions noticeboard/lib/global/global_functions.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:noticeboard/bloc/connectivity_status_bloc.dart';
import 'package:noticeboard/enum/connectivity_status_enum.dart';
import 'package:noticeboard/global/global_constants.dart';
import 'package:shimmer/shimmer.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
Expand Down Expand Up @@ -206,3 +211,26 @@ void showGenericError() {
content: Text("Error!"),
));
}

Future<ConnectivityStatus> checkConnectivityStatus() async {
try {
final result = await InternetAddress.lookup("www.example.com");
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
return ConnectivityStatus.connected;
} else {
return ConnectivityStatus.notConnected;
}
} catch (e) {
return ConnectivityStatus.notConnected;
}
}

Timer addConnectivityStatusToSink() {
final ConnectivityStatusBloc _connectivityStatusBloc =
ConnectivityStatusBloc();
Timer _timer = Timer.periodic(Duration(seconds: 15), (timer) async {
ConnectivityStatus connectivityStatus = await checkConnectivityStatus();
_connectivityStatusBloc.eventSink.add(connectivityStatus);
});
return _timer;
}
3 changes: 3 additions & 0 deletions noticeboard/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:noticeboard/bloc/connectivity_status_bloc.dart';
import './routes/routing_constants.dart';
import './routes/routing.dart';
import 'global/global_constants.dart';
Expand All @@ -19,6 +20,8 @@ class _MyAppState extends State<MyApp> {
// This widget is the root of your application.
@override
void initState() {
ConnectivityStatusBloc _connectivityStatusBloc = ConnectivityStatusBloc();
_connectivityStatusBloc.context = context;
super.initState();
}

Expand Down
1 change: 0 additions & 1 deletion noticeboard/lib/routes/routing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import './routing_constants.dart';
import '../screens/login.dart';
import '../screens/list_notices.dart';
import '../screens/launching.dart';
import '../models/notice_intro.dart';
import '../screens/notice_detail.dart';

class MyRouter {
Expand Down
20 changes: 16 additions & 4 deletions noticeboard/lib/screens/bottom_navigation.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:noticeboard/global/global_functions.dart';
import '../enum/dynamic_fetch_enum.dart';
import '../screens/list_notices.dart';
import '../models/notice_intro.dart';
Expand All @@ -14,6 +16,7 @@ class MyBottomNavigationBar extends StatefulWidget {

class _MyBottomNavigationBarState extends State<MyBottomNavigationBar> {
BottomNavigatorBloc _bottomNavigatorBloc = BottomNavigatorBloc();
late Timer _timer;
final widgetOptions = [
ListNotices(
listNoticeMetaData: ListNoticeMetaData(
Expand All @@ -37,24 +40,33 @@ class _MyBottomNavigationBarState extends State<MyBottomNavigationBar> {
_bottomNavigatorBloc.indexSink.add(index);
}

@override
void initState() {
_timer = addConnectivityStatusToSink();
super.initState();
}

@override
void dispose() {
_bottomNavigatorBloc.disposeStreams();
if (_timer.isActive) _timer.cancel();
super.dispose();
}

@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
return PopScope(
canPop: false,
onPopInvoked: (didPop) async {
if (didPop) {
return;
}
await Future.delayed(
Duration(milliseconds: 500),
);
if (Platform.isAndroid) {
SystemNavigator.pop();
return true;
} else {
return false;
}
},
child: StreamBuilder<int>(
Expand Down
2 changes: 1 addition & 1 deletion noticeboard/lib/screens/filters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class _FiltersState extends State<Filters> {
child: GestureDetector(
onTap: () {
_filtersBloc.eventSink.add(FilterEvents.resetGlobalSlug);
WidgetsBinding.instance!.addPostFrameCallback((time) {
WidgetsBinding.instance.addPostFrameCallback((time) {
onFilterClear();
});
},
Expand Down
1 change: 0 additions & 1 deletion noticeboard/lib/screens/launching.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import '../models/notice_intro.dart';
import '../services/api_service/api_service.dart';
import '../services/auth/auth_repository.dart';
import '../global/global_functions.dart';
import '../styles/launching_constants.dart';
import '../styles/login_constants.dart';

class Launcher extends StatefulWidget {
Expand Down
19 changes: 17 additions & 2 deletions noticeboard/lib/screens/list_notices.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:focused_menu/modals.dart';
import 'package:noticeboard/bloc/connectivity_status_bloc.dart';
import 'package:noticeboard/bloc/notice_detail_bloc.dart';
import 'package:noticeboard/enum/current_widget_enum.dart';
import 'package:noticeboard/models/filters_list.dart';
import 'package:noticeboard/models/notice_intro.dart';
import 'package:noticeboard/models/paginated_info.dart';
Expand All @@ -21,18 +26,28 @@ class ListNotices extends StatefulWidget {
}

class _ListNoticesState extends State<ListNotices> {
final ListNoticesBloc _listNoticesBloc = ListNoticesBloc();
final ListNoticesBloc _listNoticesBloc = ListNoticesBloc(); // search
final AuthRepository _authRepository = AuthRepository();
TextEditingController? _controller; // search
final NoticeDetailBloc _noticeDetailBloc = NoticeDetailBloc();
final ConnectivityStatusBloc _connectivityStatusBloc =
ConnectivityStatusBloc();
TextEditingController? _controller;

@override
void initState() {
_controller = TextEditingController(); // search
_listNoticesBloc.context = context;
_connectivityStatusBloc.context = context;
_connectivityStatusBloc.currentWidget = CurrentWidget.listNotices;
_listNoticesBloc.listNoticeMetaData = widget.listNoticeMetaData;
_controller!.addListener(_handleQueryChanges);
_listNoticesBloc.dynamicFetch = widget.listNoticeMetaData!.dynamicFetch;
_listNoticesBloc.dynamicFetchNotices();
_noticeDetailBloc.eventStream.asBroadcastStream().listen((currentWidget) {
if (currentWidget == CurrentWidget.listNotices) {
_listNoticesBloc.dynamicFetchNotices();
}
});
super.initState();
}

Expand Down
Loading
Loading