<commit_before>import 'package:easy_localization/easy_localization.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:onesignal_flutter/onesignal_flutter.dart';
import 'package:quiver/strings.dart';

import 'core/helpers/color_palette_helper.dart';
import 'features/activity/presentation/pages/activity_page.dart';
import 'features/announcements/presentation/pages/announcements_page.dart';
import 'features/changelog/presentation/pages/changelog_page.dart';
import 'features/donate/presentation/pages/donate_page.dart';
import 'features/graphs/presentation/pages/graphs_page.dart';
import 'features/help/presentation/pages/help_page.dart';
import 'features/history/presentation/pages/history_page.dart';
import 'features/libraries/presentation/pages/libraries_page.dart';
import 'features/logging/domain/usecases/logging.dart';
import 'features/logging/presentation/pages/logs_page.dart';
import 'features/onesignal/data/datasources/onesignal_data_source.dart';
import 'features/onesignal/presentation/bloc/onesignal_health_bloc.dart';
import 'features/onesignal/presentation/bloc/onesignal_subscription_bloc.dart';
import 'features/privacy/presentation/pages/privacy_page.dart';
import 'features/recent/presentation/pages/recently_added_page.dart';
import 'features/settings/domain/usecases/register_device.dart';
import 'features/settings/domain/usecases/settings.dart';
import 'features/settings/presentation/bloc/settings_bloc.dart';
import 'features/settings/presentation/pages/advanced_settings_page.dart';
import 'features/settings/presentation/pages/settings_page.dart';
import 'features/statistics/presentation/pages/statistics_page.dart';
import 'features/synced_items/presentation/pages/synced_items_page.dart';
import 'features/translate/presentation/pages/translate_page.dart';
import 'features/users/presentation/pages/users_page.dart';
import 'features/wizard/presentation/pages/wizard_page.dart';
import 'injection_container.dart' as di;

class TautulliRemote extends StatefulWidget {
  final bool showWizard;
  final bool showChangelog;

  const TautulliRemote({
    @required this.showWizard,
    @required this.showChangelog,
    Key key,
  }) : super(key: key);

  @override
  _TautulliRemoteState createState() => _TautulliRemoteState();
}

class _TautulliRemoteState extends State<TautulliRemote> {
  @override
  void initState() {
    super.initState();
    initializeFlutterFire();
    initPlatformState();
    context.read<SettingsBloc>().add(
          SettingsLoad(
            settingsBloc: context.read<SettingsBloc>(),
          ),
        );
    context.read<SettingsBloc>().add(SettingsUpdateLastAppVersion());
    context.read<OneSignalHealthBloc>().add(OneSignalHealthCheck());
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    if (!mounted) return;

    // await OneSignal.shared.setLogLevel(OSLogLevel.verbose, OSLogLevel.none);

    await OneSignal.shared.setLocationShared(false);

    // If OneSignal is reporting an empty ID but we've stored that the user
    // has provided consent trigger a grantConsent.
    // This helps with some oddities when OneSignal updates the SDK.
    if (isEmpty(await di.sl<OneSignalDataSource>().userId)) {
      await di.sl<Settings>().getOneSignalConsented().then((consented) async {
        if (consented) {
          await di.sl<OneSignalDataSource>().grantConsent(true);
        }
      });
    }

    await OneSignal.shared.setRequiresUserPrivacyConsent(true);

    await OneSignal.shared.setAppId("3b4b666a-d557-4b92-acdf-e2c8c4b95357");

    OneSignal.shared.setNotificationWillShowInForegroundHandler((event) {
      // will be called whenever a notification is received
      event.complete(event.notification);
    });

    OneSignal.shared
        .setNotificationOpenedHandler((OSNotificationOpenedResult result) {
      // will be called whenever a notification is opened/button pressed.
    });

    OneSignal.shared<commit_msg>Add logging when re-granting consent.<commit_after>import 'package:easy_localization/easy_localization.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:onesignal_flutter/onesignal_flutter.dart';
import 'package:quiver/strings.dart';

import 'core/helpers/color_palette_helper.dart';
import 'features/activity/presentation/pages/activity_page.dart';
import 'features/announcements/presentation/pages/announcements_page.dart';
import 'features/changelog/presentation/pages/changelog_page.dart';
import 'features/donate/presentation/pages/donate_page.dart';
import 'features/graphs/presentation/pages/graphs_page.dart';
import 'features/help/presentation/pages/help_page.dart';
import 'features/history/presentation/pages/history_page.dart';
import 'features/libraries/presentation/pages/libraries_page.dart';
import 'features/logging/domain/usecases/logging.dart';
import 'features/logging/presentation/pages/logs_page.dart';
import 'features/onesignal/data/datasources/onesignal_data_source.dart';
import 'features/onesignal/presentation/bloc/onesignal_health_bloc.dart';
import 'features/onesignal/presentation/bloc/onesignal_subscription_bloc.dart';
import 'features/privacy/presentation/pages/privacy_page.dart';
import 'features/recent/presentation/pages/recently_added_page.dart';
import 'features/settings/domain/usecases/register_device.dart';
import 'features/settings/domain/usecases/settings.dart';
import 'features/settings/presentation/bloc/settings_bloc.dart';
import 'features/settings/presentation/pages/advanced_settings_page.dart';
import 'features/settings/presentation/pages/settings_page.dart';
import 'features/statistics/presentation/pages/statistics_page.dart';
import 'features/synced_items/presentation/pages/synced_items_page.dart';
import 'features/translate/presentation/pages/translate_page.dart';
import 'features/users/presentation/pages/users_page.dart';
import 'features/wizard/presentation/pages/wizard_page.dart';
import 'injection_container.dart' as di;

class TautulliRemote extends StatefulWidget {
  final bool showWizard;
  final bool showChangelog;

  const TautulliRemote({
    @required this.showWizard,
    @required this.showChangelog,
    Key key,
  }) : super(key: key);

  @override
  _TautulliRemoteState createState() => _TautulliRemoteState();
}

class _TautulliRemoteState extends State<TautulliRemote> {
  @override
  void initState() {
    super.initState();
    initializeFlutterFire();
    initPlatformState();
    context.read<SettingsBloc>().add(
          SettingsLoad(
            settingsBloc: context.read<SettingsBloc>(),
          ),
        );
    context.read<SettingsBloc>().add(SettingsUpdateLastAppVersion());
    context.read<OneSignalHealthBloc>().add(OneSignalHealthCheck());
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    if (!mounted) return;

    // await OneSignal.shared.setLogLevel(OSLogLevel.verbose, OSLogLevel.none);

    await OneSignal.shared.setLocationShared(false);

    // If OneSignal is returns an empty userId and the user has provided
    // then consent trigger a grantConsent.
    if (isEmpty(await di.sl<OneSignalDataSource>().userId)) {
      await di.sl<Settings>().getOneSignalConsented().then((consented) async {
        if (consented) {
          di.sl<Logging>().info(
                'OneSignal: Detected consent mismatch, granting consent.',
              );
          await di.sl<OneSignalDataSource>().grantConsent(true);
        }
      });
    }

    await OneSignal.shared.setRequiresUserPrivacyConsent(true);

    await OneSignal.shared.setAppId("3b4b666a-d557-4b92-acdf-e2c8c4b95357");

    OneSignal.shared.setNotificationWillShowInForegroundHandler((event) {
      // will be called whenever a notification is received
      event.complete(event.notification);
    });

    OneSignal.shared
        .setNotificationOpenedHandler((OSNotificationOpenedResult result) {
      // will be called whenever a notification is opened/button pressed.
    });

    OneSignal.shared
{'fraction_non_alphanumeric': 0.11297071129707113, 'fraction_numerical': 0.004542737597130903, 'mean_word_length': 5.151470588235294, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2725873', 'n_tokens_mistral': 2606, 'n_tokens_neox': 2518, 'n_words': 394}