<commit_before>import React from 'react';
import { Alert, Platform, StatusBar, View, StyleSheet, WebView } from 'react-native';
import { Constants, Notifications } from 'expo';
import {
  registerDeviceToExpo,
  registerExpoTokenToTrustroots,
  unRegisterExpoTokenFromTrustroots,
} from './app/Notifications';
import { sendStat } from './app/Stats';
import * as Settings from './Settings';

console.log('Trustroots mobile app');
console.log('Settings: ', Settings);

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  statusBarUnderlay: {
    height: Constants.statusBarHeight || 24,
    backgroundColor: 'rgba(0, 0, 0, 0.2)',
  },
  webView: {
    marginTop: Constants.statusBarHeight || 20,
  },
});

/**
 * App & device information.
 *
 * This should contain only data which doesn't reveal user identity as it's
 * passed on without user being authenticated.
 *
 * See Expo constants:
 * @link https://docs.expo.io/versions/latest/sdk/constants.html
 */
const appInfo = {
  version: Constants.manifest.version || '0.0.0',
  expoVersion: Constants.expoVersion || '',
  deviceName: Constants.deviceName || '',
  deviceYearClass: Constants.deviceYearClass || '',
  os: Platform.OS || '',
};

// True when during this app runtime notifications are enabled already,
// so that we don't attempt to enable them again.
let notificationsRegistered = false;
let notificationsRegisteringLoading = false;

// JS injected to `WebView`
// Embedded website will change its functionality based on this.
const appInfoJavaScript = 'window.trMobileApp=' + JSON.stringify(appInfo) + ';';

// App wraps trustroots web site and handles notifications.
// Application tries to automaticatically register
// notifications as you load it first time.
export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = { url: Settings.BASE_URL };
  }

  componentWillMount() {
    this._notificationSubscription = Notifications.addListener(this._handleNotification);

    // Send platform stats
    sendStat(appInfo, 'mobileAppInit');
  }

  _handleNotification = notification => {
    if (notification.origin === 'selected') {
      this.setState({ url: notification.data.url || this.state.url });
    }
  };

  async _registerNotifications() {
    console.log('registerNotifications');
    // Do not register multiple times during the app runtime
    if (notificationsRegistered || notificationsRegisteringLoading) {
      return;<commit_msg>Handle hardware back press button<commit_after>import React from 'react';
import { Alert, BackHandler, Platform, StatusBar, View, StyleSheet, WebView } from 'react-native';
import { Constants, Notifications } from 'expo';
import {
  registerDeviceToExpo,
  registerExpoTokenToTrustroots,
  unRegisterExpoTokenFromTrustroots,
} from './app/Notifications';
import { sendStat } from './app/Stats';
import * as Settings from './Settings';

console.log('Trustroots mobile app');
console.log('Settings: ', Settings);

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  statusBarUnderlay: {
    height: Constants.statusBarHeight || 24,
    backgroundColor: 'rgba(0, 0, 0, 0.2)',
  },
  webView: {
    marginTop: Constants.statusBarHeight || 20,
  },
});

/**
 * App & device information.
 *
 * This should contain only data which doesn't reveal user identity as it's
 * passed on without user being authenticated.
 *
 * See Expo constants:
 * @link https://docs.expo.io/versions/latest/sdk/constants.html
 */
const appInfo = {
  version: Constants.manifest.version || '0.0.0',
  expoVersion: Constants.expoVersion || '',
  deviceName: Constants.deviceName || '',
  deviceYearClass: Constants.deviceYearClass || '',
  os: Platform.OS || '',
};

// True when during this app runtime notifications are enabled already,
// so that we don't attempt to enable them again.
let notificationsRegistered = false;
let notificationsRegisteringLoading = false;

// JS injected to `WebView`
// Embedded website will change its functionality based on this.
const appInfoJavaScript = 'window.trMobileApp=' + JSON.stringify(appInfo) + ';';

// App wraps trustroots web site and handles notifications.
// Application tries to automaticatically register
// notifications as you load it first time.
export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = { url: Settings.BASE_URL };
  }

  componentWillMount() {
    this._notificationSubscription = Notifications.addListener(this._handleNotification);

    BackHandler.addEventListener('hardwareBackPress', this._handleHardwareBackPress);

    // Send platform stats
    sendStat(appInfo, 'mobileAppInit');
  }

  _handleHardwareBackPress = () => {
    this.webView.goBack();

    // Prevent the regular handling of the back button.
    // Otherwise we'd just exit the app.
    return true;
  };

  _handleNotification = notification => {
    if (notification.origin === 'selected') {
      this.setState({ url: notification.data.url || this.state.url });
    }
  };

  async _registerNotifications() {
    console.log('registerNotifications');
    // Do not register multiple times during the app runtime
    if (notificationsRegistered || notificationsRegisteringLoading) {
      return;
{'fraction_non_alphanumeric': 0.1177587844254511, 'fraction_numerical': 0.0049382716049382715, 'mean_word_length': 4.112621359223301, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 2, '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': '266452', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1449, 'n_words': 428}