Skip to content

Commit

Permalink
Upgrade connectivity_plus from v5.0.2 to v6.0.5 with updated implem…
Browse files Browse the repository at this point in the history
…entations and tests (#2671)

* upgrade connectivity_plus from 5.0.2 to 6.0.5 with necessary adjustments

* added codegov missing test cases.

* covered all test cases

* codegov/patch

* codegov/patch-2

* codegov/patch-3

* implemented codeRabbit changes

* covered all test cases

* covered test all cases 2

* covered all test cases 3

* covered all test cases 4

* covered all test cases 5

* covered all test cases increasing coverage

* covered all lines

* fixed java version in github workflows

* revert changes for android files

* removed whitespace from build.gradle

---------

Co-authored-by: Satyam Jha <[email protected]>
  • Loading branch information
may-tas and Satyam Jha authored Dec 27, 2024
1 parent 3fe1d19 commit b6ddb72
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 80 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: "zulu" # See 'Supported distributions' for available options
java-version: "12.0"
java-version: "17.0"
- uses: subosito/flutter-action@v2
with:
flutter-version: "3.22.3"
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: "zulu" # See 'Supported distributions' for available options
java-version: "12.0"
java-version: "17.0"
- uses: subosito/flutter-action@v2
with:
flutter-version: "3.22.3"
Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: "zulu" # See 'Supported distributions' for available options
java-version: "12.0"
java-version: "17.0"
- uses: subosito/flutter-action@v2
with:
flutter-version: "3.22.3"
Expand Down
10 changes: 9 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
}

compileSdkVersion 34

namespace "com.example.talawa"
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
Expand All @@ -50,6 +50,14 @@ android {
versionName flutterVersionName
multiDexEnabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = '17'
}

buildTypes {
release {
Expand Down
2 changes: 1 addition & 1 deletion lib/locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Future<void> setupLocator() async {

//databaseMutationFunction

locator.registerSingleton(ConnectivityService());
locator.registerSingleton(ConnectivityService(connectivity));

//queries
locator.registerSingleton(Queries());
Expand Down
26 changes: 17 additions & 9 deletions lib/services/third_party_service/connectivity_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ import 'package:talawa/locator.dart';
/// * Handling the device's connectivity status - [handleConnection]
/// * Checking if the device has any type of network connection - [hasConnection]
class ConnectivityService {
ConnectivityService(
this.connectivityInstance,
);

/// dependency injection connectivity.
late final Connectivity connectivityInstance;

/// Stream controller for network status changes.
late StreamController<ConnectivityResult> connectionStatusController;
late StreamController<List<ConnectivityResult>> connectionStatusController;

/// Getter for the stream of connection status changes.
Stream<ConnectivityResult> get connectionStream =>
Stream<List<ConnectivityResult>> get connectionStream =>
connectionStatusController.stream;

/// Checks the current internet connectivity status of the device.
Expand All @@ -27,8 +34,8 @@ class ConnectivityService {
/// None
///
/// **returns**:
/// * `Future<ConnectivityResult>`: indicates if the url is reachable.
Future<ConnectivityResult> getConnectionType() async {
/// * `Future<List<ConnectivityResult>>`: indicates if the url is reachable.
Future<List<ConnectivityResult>> getConnectionType() async {
final result = await connectivity.checkConnectivity();
return result;
}
Expand All @@ -45,7 +52,7 @@ class ConnectivityService {
/// None
Future<void> initConnectivity({required http.Client client}) async {
_client = client;
connectionStatusController = StreamController<ConnectivityResult>();
connectionStatusController = StreamController<List<ConnectivityResult>>();

/// Listen for future changes in connectivity
enableSubscription();
Expand All @@ -59,8 +66,8 @@ class ConnectivityService {
/// **returns**:
/// None
Future<void> enableSubscription() async {
connectivity.onConnectivityChanged.listen(
(ConnectivityResult result) {
connectivityInstance.onConnectivityChanged.listen(
(List<ConnectivityResult> result) {
print(result);
connectionStatusController.add(result);
},
Expand Down Expand Up @@ -107,8 +114,9 @@ class ConnectivityService {
/// * `Future<bool>`: indicating whether the device has a network connection.
Future<bool> hasConnection() async {
try {
final result = await getConnectionType();
return result != ConnectivityResult.none;
final results = await getConnectionType();
return results.isNotEmpty &&
results.any((result) => result != ConnectivityResult.none);
} catch (e) {
return false;
}
Expand Down
17 changes: 10 additions & 7 deletions lib/view_model/connectivity_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import 'package:talawa/view_model/base_view_model.dart';
/// * Triggers the snackbar UI to show online status.: [showSnackbar]
class AppConnectivity extends BaseModel {
/// Stream from [ConnectivityService].
late final Stream<ConnectivityResult> connectivityStream;
late final Stream<List<ConnectivityResult>> connectivityStream;

/// Subscription of the [connectivityStream]
StreamSubscription? _subscription;
Expand Down Expand Up @@ -51,24 +51,27 @@ class AppConnectivity extends BaseModel {
/// None
void enableSubscription() {
try {
_subscription = connectivityStream.listen((ConnectivityResult result) {
_subscription =
connectivityStream.listen((List<ConnectivityResult> result) {
handleConnection(result);
});
} catch (e) {
print("Error subscribing to connectivity stream: $e");
}
}

/// This function handles the device's connectivity status based on the provided [ConnectivityResult].
/// This function handles the device's connectivity status based on the provided [List<ConnectivityResult>].
///
/// **params**:
/// * `result`: A [ConnectivityResult] indicating the current connectivity status.
/// * `result`: A [List<ConnectivityResult>] indicating the current connectivity status.
///
/// **returns**:
/// None
Future<void> handleConnection(ConnectivityResult result) async {
if (![ConnectivityResult.none, ConnectivityResult.bluetooth]
.contains(result)) {
Future<void> handleConnection(List<ConnectivityResult> result) async {
if (result.any(
(r) =>
![ConnectivityResult.none, ConnectivityResult.bluetooth].contains(r),
)) {
handleOnline();
} else {
handleOffline();
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,18 @@ packages:
dependency: "direct main"
description:
name: connectivity_plus
sha256: "224a77051d52a11fbad53dd57827594d3bd24f945af28bd70bab376d68d437f0"
sha256: e0817759ec6d2d8e57eb234e6e57d2173931367a865850c7acea40d4b4f9c27d
url: "https://pub.dev"
source: hosted
version: "5.0.2"
version: "6.0.5"
connectivity_plus_platform_interface:
dependency: transitive
description:
name: connectivity_plus_platform_interface
sha256: cf1d1c28f4416f8c654d7dc3cd638ec586076255d407cef3ddbdaf178272a71a
sha256: "42657c1715d48b167930d5f34d00222ac100475f73d10162ddf43e714932f204"
url: "https://pub.dev"
source: hosted
version: "1.2.4"
version: "2.0.1"
contained_tab_bar_view:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies:
auto_size_text: ^3.0.0
cached_network_image: ^3.4.1
clock: ^1.1.1
connectivity_plus: ^5.0.2
connectivity_plus: ^6.0.5
contained_tab_bar_view: ^0.8.0

crypto: ^3.0.5
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/test_locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void testSetupLocator() {

//databaseMutationFunction

locator.registerSingleton(ConnectivityService());
locator.registerSingleton(ConnectivityService(connectivity));

//queries
locator.registerSingleton(Queries());
Expand Down
Loading

0 comments on commit b6ddb72

Please sign in to comment.