Example #1
0
  @Subscribe
  public void onConnectivityChanged(final ConnectivityChangedEvent e) {
    Connectivity connectivity = model.getConnectivity();
    if (!e.isConnected()) {
      connectivity.setInternet(false);
      Events.sync(SyncPath.CONNECTIVITY_INTERNET, false);
      return;
    }
    InetAddress ip = e.getNewIp();
    connectivity.setIp(ip.getHostAddress());

    connectivity.setInternet(true);
    Events.sync(SyncPath.CONNECTIVITY, model.getConnectivity());

    Settings set = model.getSettings();

    if (set.getMode() == null || set.getMode() == Mode.unknown) {
      if (censored.isCensored()) {
        set.setMode(Mode.get);
      } else {
        set.setMode(Mode.give);
      }
    } else if (set.getMode() == Mode.give && censored.isCensored()) {
      // want to set the mode to get now so that we don't mistakenly
      // proxy any more than necessary
      set.setMode(Mode.get);
      log.info("Disconnected; setting giveModeForbidden");
      Events.syncModal(model, Modal.giveModeForbidden);
    }
  }
Example #2
0
  @Subscribe
  public void onLocationChanged(final LocationChangedEvent e) {
    Events.sync(SyncPath.LOCATION, e.getNewLocation());

    if (censored.isCountryCodeCensored(e.getNewCountry())) {
      if (!censored.isCountryCodeCensored(e.getOldCountry())) {
        // moving from uncensored to censored
        if (model.getSettings().getMode() == Mode.give) {
          Events.syncModal(model, Modal.giveModeForbidden);
        }
      }
    }
  }