<commit_before>import rwc from 'random-weighted-choice';
import _ from 'lodash';

function HomeCtrl($location, $cookies, $scope, $interval,
  Analytics, Culture, Word, Config, Level, Books) {
    'ngInject';

    const vm = this;
    $scope.vm = vm;

    vm.isWebView = window.webviewbridge;
    vm.prefix = '';
    // vm.id = 'Jn-14-1';
    const lang = 'en';

    var setupTimer = () => $interval((i) => {
      vm.timer = 5 - i;
      if(i == 5) {
        vm.showClose = true;
      }
    }, 1000, 5, true);

    var setupBridge = () => {

      var loaded = [
          ['com.unity3d.ads.api.Sdk', 'loadComplete', [], 'onLoadComplete']
      ];
      var init = false;

      window.nativebridge = {
          handleCallback: (params) => {
              console.log('handleCallback: ' + JSON.stringify(params));

              _.forEach(params, (paramArray) => {
                  if (paramArray[0] == 'onLoadComplete') {
                      console.log('onLoadComplete invoked: ' + JSON.stringify(paramArray));
                      var config = paramArray[2];
                      $scope.$apply((scope) => {
                          vm.prefix = config[config.length - 1];
                          scope.$root.baseUrl = vm.prefix;
                      });
                  }
              });

              if (!init) {
                  var inited = [
                      ['com.unity3d.ads.api.Sdk', 'initComplete', [], 'onInitComplete']
                  ];
                  window.webviewbridge
                      .handleInvocation(JSON.stringify(inited));
                  var ready = [
                      ['com.unity3d.ads.api.Listener', 'sendReadyEvent', ['defaultVideoAndPictureZone'], 'CALLBACK_01'],
                      ['com.unity3d.ads.api.Placement', 'setDefaultPlacement', ['defaultVideoAndPictureZone'], 'CALLBACK_03'],
                      ['com.unity3d.ads.api.Placement', 'setPlacementState', ['defaultVideoAndPictureZone', 'READY'], 'CALLBACK_02']
                  ];
                  window.webviewbridge
                      .handleInvocation(JSON.stringify(ready));
              }
              init = true;

          },
          handleInvocation: (params) => {
              console.log('handleInvocation', params);
              if (params[0] == 'webview' && params[1] == 'show') {
                  var openAdUnit = [
                      ['com.unity3d.ads.api.AdUnit', 'open', [1, ['webview'], -1], 'CALLBACK_02']
                  ];
                  window.webviewbridge
                      .handleInvocation(JSON.stringify(openAdUnit));
                  console.log('opened adunit');

                  window.webviewbridge
                      .handleCallback(params[2], 'OK', JSON.stringify([]));

                  $scope.$apply((scope) => {
                    scope.close = () => {
                      var closeAdUnit = [
                          ['com.unity3d.ads.api.AdUnit', 'close', [], 'onClosed']
                      ];
                      window.webviewbridge
                        .handleInvocation(JSON.stringify(closeAdUnit));
                      // reset timer
                      vm.showClose = false;
                      delete vm.timer;
                    };

                    vm.pick();
                    setupTimer();
                  });
              }
          },
          handleEvent: (params) => {
              console.log('handleEvent', params);
          }
      };
      window.webviewbridge<commit_msg>reset scroll and timer on close<commit_after>import rwc from 'random-weighted-choice';
import _ from 'lodash';

function HomeCtrl($location, $cookies, $scope, $interval,
  Analytics, Culture, Word, Config, Level, Books) {
    'ngInject';

    const vm = this;
    $scope.vm = vm;

    vm.isWebView = window.webviewbridge;
    vm.prefix = '';
    // vm.id = 'Jn-14-1';
    const lang = 'en';

    var setupTimer = () => $interval((i) => {
      vm.timer = 5 - i;
      if(i == 5) {
        vm.showClose = true;
      }
    }, 1000, 5, true);

    var setupBridge = () => {

      var loaded = [
          ['com.unity3d.ads.api.Sdk', 'loadComplete', [], 'onLoadComplete']
      ];
      var init = false;

      window.nativebridge = {
          handleCallback: (params) => {
              console.log('handleCallback: ' + JSON.stringify(params));

              _.forEach(params, (paramArray) => {
                  if (paramArray[0] == 'onLoadComplete') {
                      console.log('onLoadComplete invoked: ' + JSON.stringify(paramArray));
                      var config = paramArray[2];
                      $scope.$apply((scope) => {
                          vm.prefix = config[config.length - 1];
                          scope.$root.baseUrl = vm.prefix;
                      });
                  }
              });

              if (!init) {
                  var inited = [
                      ['com.unity3d.ads.api.Sdk', 'initComplete', [], 'onInitComplete']
                  ];
                  window.webviewbridge
                      .handleInvocation(JSON.stringify(inited));
                  var ready = [
                      ['com.unity3d.ads.api.Listener', 'sendReadyEvent', ['defaultVideoAndPictureZone'], 'CALLBACK_01'],
                      ['com.unity3d.ads.api.Placement', 'setDefaultPlacement', ['defaultVideoAndPictureZone'], 'CALLBACK_03'],
                      ['com.unity3d.ads.api.Placement', 'setPlacementState', ['defaultVideoAndPictureZone', 'READY'], 'CALLBACK_02']
                  ];
                  window.webviewbridge
                      .handleInvocation(JSON.stringify(ready));
              }
              init = true;

          },
          handleInvocation: (params) => {
              console.log('handleInvocation', params);
              if (params[0] == 'webview' && params[1] == 'show') {
                  var openAdUnit = [
                      ['com.unity3d.ads.api.AdUnit', 'open', [1, ['webview'], -1], 'CALLBACK_02']
                  ];
                  window.webviewbridge
                      .handleInvocation(JSON.stringify(openAdUnit));
                  console.log('opened adunit');

                  window.webviewbridge
                      .handleCallback(params[2], 'OK', JSON.stringify([]));

                  $scope.$apply((scope) => {
                    scope.close = () => {
                      var closeAdUnit = [
                          ['com.unity3d.ads.api.AdUnit', 'close', [], 'onClosed']
                      ];
                      window.webviewbridge
                        .handleInvocation(JSON.stringify(closeAdUnit));
                      // reset timer
                      vm.showClose = false;
                      delete vm.timer;
                      delete vm.word;
                    };

                    vm.pick();
                    setupTimer();
                  });
              }
          },
          handleEvent: (params) => {
              console.log('handleEvent', params);
          }
      };
      window.webviewbridge
{'fraction_non_alphanumeric': 0.136299633905942, 'fraction_numerical': 0.009293156857223317, 'mean_word_length': 1.3099186991869918, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '5900033', 'n_tokens_mistral': 1944, 'n_tokens_neox': 1800, 'n_words': 310}