import 'dart:async';

import 'package:guru_applifecycle_flutter/lifecycle/app_background_event_notifier.dart';

mixin AppLifecycleCallback {

  StreamSubscription? _appStateSubscription;

  void listenApplifecycle() {
    AppStateEventNotifier.startListening();
    _appStateSubscription = AppStateEventNotifier.appStateStream.listen((event) {
      if (event == AppState.background) {
        onAppBackground();
      } else {
        onAppForeground();
      }
    });
  }

  Future cancelListenApplifecycle() async {
    await _appStateSubscription?.cancel();
  }

  void onAppBackground();
  void onAppForeground();
}