Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ command:
firebase_messaging: ^15.0.0
flex_grid_view: ^0.1.0
flutter_local_notifications: ^18.0.1
injectable: ^2.5.1
http: ^1.1.0
injectable: ^2.5.1
intl: ">=0.18.1 <=0.21.0"
internet_connection_checker_plus: ^2.9.0
jiffy: ^6.3.2
photo_view: ^0.15.0
json_annotation: ^4.9.0
Expand All @@ -46,7 +47,7 @@ command:
shared_preferences: ^2.5.3
state_notifier: ^1.0.0
stream_feeds: ^0.2.0
stream_core: ^0.1.0
stream_core: ^0.2.0
video_player: ^2.10.0
uuid: ^4.5.1

Expand Down
3 changes: 3 additions & 0 deletions packages/stream_feeds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Unreleased
- [BREAKING] Renamed `AppLifecycleStateProvider` to `LifecycleStateProvider` and `AppLifecycleState` to `LifecycleState`.

## 0.2.0
- [BREAKING] Update API client code, specifically the FeedOwnCapability enum.
- Fix unknown enums for `List<FeedOwnCapability>` in `GetOrCreateFeedResponse` to be `FeedOwnCapability.unknown`.
Expand Down
4 changes: 2 additions & 2 deletions packages/stream_feeds/lib/src/client/feeds_client_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class StreamFeedsClientImpl implements StreamFeedsClient {
TokenProvider? tokenProvider,
RetryStrategy? retryStrategy,
NetworkStateProvider? networkStateProvider,
AppLifecycleStateProvider? appLifecycleStateProvider,
LifecycleStateProvider? lifecycleStateProvider,
List<AutomaticReconnectionPolicy>? reconnectionPolicies,
}) {
// TODO: Make this configurable
Expand Down Expand Up @@ -111,7 +111,7 @@ class StreamFeedsClientImpl implements StreamFeedsClient {
client: _ws,
retryStrategy: retryStrategy,
networkStateProvider: networkStateProvider,
appLifecycleStateProvider: appLifecycleStateProvider,
lifecycleStateProvider: lifecycleStateProvider,
policies: reconnectionPolicies,
);

Expand Down
2 changes: 1 addition & 1 deletion packages/stream_feeds/lib/src/feeds_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ abstract interface class StreamFeedsClient {
TokenProvider? tokenProvider,
RetryStrategy? retryStrategy,
NetworkStateProvider? networkStateProvider,
AppLifecycleStateProvider? appLifecycleStateProvider,
LifecycleStateProvider? lifecycleStateProvider,
List<AutomaticReconnectionPolicy>? reconnectionPolicies,
}) = StreamFeedsClientImpl;

Expand Down
2 changes: 1 addition & 1 deletion packages/stream_feeds/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies:
retrofit: ^4.6.0
rxdart: ^0.28.0
state_notifier: ^1.0.0
stream_core: ^0.1.0
stream_core: ^0.2.0
uuid: ^4.5.1

dev_dependencies:
Expand Down
6 changes: 6 additions & 0 deletions sample_app/lib/app/content/auth_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ class AuthController extends ValueNotifier<AuthState> {
this._appPreferences,
@Named('apn') this._iosPushProvider,
@Named('firebase') this._androidPushProvider,
this._networkStateProvider,
this._lifecycleStateProvider,
) : super(const Unauthenticated());

final AppPreferences _appPreferences;
final PushProvider _iosPushProvider;
final PushProvider _androidPushProvider;
final NetworkStateProvider _networkStateProvider;
final LifecycleStateProvider _lifecycleStateProvider;

PushTokenManager? _pushTokenManager;

Expand All @@ -31,6 +35,8 @@ class AuthController extends ValueNotifier<AuthState> {
user: credentials.user,
apiKey: DemoAppConfig.current.apiKey,
tokenProvider: TokenProvider.static(token),
networkStateProvider: _networkStateProvider,
lifecycleStateProvider: _lifecycleStateProvider,
);

final result = await runSafely(client.connect);
Expand Down
4 changes: 4 additions & 0 deletions sample_app/lib/core/di/app_module.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:injectable/injectable.dart';
import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../../firebase_options.dart';
Expand Down Expand Up @@ -30,4 +31,7 @@ abstract class AppModule {

@lazySingleton
LocalNotification get localNotifications => LocalNotification();

@lazySingleton
InternetConnection get internet => InternetConnection.createInstance();
}
15 changes: 13 additions & 2 deletions sample_app/lib/core/di/di_initializer.config.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:injectable/injectable.dart';
import 'package:stream_feeds/stream_feeds.dart';

@LazySingleton(as: LifecycleStateProvider)
class AppLifecycleStateProvider
with Disposable, WidgetsBindingObserver
implements LifecycleStateProvider {
AppLifecycleStateProvider() {
// Start listening to lifecycle changes.
WidgetsBinding.instance.addObserver(this);
}

@override
LifecycleStateEmitter get state => _state;
late final _state = MutableStateEmitter(LifecycleState.foreground);

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
final wasInBackground = _state.value == LifecycleState.background;
final isInBackground = !_isAppInForeground(state);

if (wasInBackground && !isInBackground) {
_state.value = LifecycleState.foreground;
} else if (!wasInBackground && isInBackground) {
_state.value = LifecycleState.background;
}
}

bool _isAppInForeground(AppLifecycleState state) {
return switch (state) {
AppLifecycleState.resumed || AppLifecycleState.inactive => true,
_ => false,
};
}

@override
Future<void> dispose() async {
await _state.close();
WidgetsBinding.instance.removeObserver(this);
return super.dispose();
}
}
38 changes: 38 additions & 0 deletions sample_app/lib/reconnect_providers/network_state_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'dart:async';

import 'package:injectable/injectable.dart';
import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart';
import 'package:stream_feeds/stream_feeds.dart';

@LazySingleton(as: NetworkStateProvider)
final class InternetStateProvider
with Disposable
implements NetworkStateProvider {
InternetStateProvider({
required InternetConnection checker,
}) : _checker = checker {
// Subscribe to the status changes.
_connectionSubscription = _checker.onStatusChange.listen(_onStatusChange);
}

final InternetConnection _checker;

@override
NetworkStateEmitter get state => _state;
late final _state = MutableStateEmitter(NetworkState.unknown);

StreamSubscription<InternetStatus>? _connectionSubscription;
void _onStatusChange(InternetStatus status) {
_state.value = switch (status) {
InternetStatus.connected => NetworkState.connected,
InternetStatus.disconnected => NetworkState.disconnected,
};
}

@override
Future<void> dispose() async {
await _state.close();
await _connectionSubscription?.cancel();
return super.dispose();
}
}
1 change: 1 addition & 0 deletions sample_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies:
get_it: ^8.0.3
google_fonts: ^6.3.0
injectable: ^2.5.1
internet_connection_checker_plus: ^2.9.0
jiffy: ^6.3.2
json_annotation: ^4.9.0
photo_view: ^0.15.0
Expand Down
1 change: 1 addition & 0 deletions sample_app/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus
firebase_core
)

Expand Down