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

Upgrade connectivity_plus from v5.0.2 to v6.0.5 with updated implementations and tests #2671

Merged
Show file tree
Hide file tree
Changes from 17 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
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
11 changes: 10 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 All @@ -67,4 +75,5 @@ flutter {
dependencies {
implementation 'com.android.support:multidex:1.0.3'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.10"

}
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
2 changes: 1 addition & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.2"
id "com.android.application" version "7.3.0" apply false
id "com.android.application" version "8.3.0" apply false
id "org.jetbrains.kotlin.android" version "1.8.10" apply false
id("com.google.gms.google-services") version "4.4.1" apply false

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
Loading