import 'package:flutter/material.dart';
import 'package:loopin/IM/im_service.dart';

class LifecycleHandler with WidgetsBindingObserver {
  static bool isInForeground = true;
  static DateTime appBecameActiveTime = DateTime.now();

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    switch (state) {
      case AppLifecycleState.resumed:
        isInForeground = true;
        appBecameActiveTime = DateTime.now();
        logger.i("App 回到前台：$appBecameActiveTime");
        break;
      case AppLifecycleState.inactive:
        logger.i("App 进入非活跃状态 (inactive)");
        break;
      case AppLifecycleState.paused:
        isInForeground = false;
        logger.i("App 进入后台 (paused)");
        break;
      case AppLifecycleState.detached:
        isInForeground = false;
        logger.i("App 被分离 (detached)");
        break;
      case AppLifecycleState.hidden:
        isInForeground = false;
        logger.i("App 被隐藏 (hidden)");
        break;
    }
  }
}
