Beispiel #1
0
  private void sendLogAndConfirm() {
    if (!sendButtonEnabled) {
      Dialogs.message(this, R.string.log_post_not_possible);
      return;
    }
    if (CalendarUtils.isFuture(date)) {
      Dialogs.message(this, R.string.log_date_future_not_allowed);
      return;
    }
    if (typeSelected.mustConfirmLog()) {
      Dialogs.confirm(
          this,
          R.string.confirm_log_title,
          res.getString(R.string.confirm_log_message, typeSelected.getL10n()),
          new OnClickListener() {

            @Override
            public void onClick(final DialogInterface dialog, final int which) {
              sendLogInternal();
            }
          });
    } else {
      sendLogInternal();
    }
  }
  @Override
  public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo info) {
    super.onCreateContextMenu(menu, view, info);
    final int viewId = view.getId();

    if (viewId == R.id.type) {
      for (final LogType typeOne : possibleLogTypes) {
        menu.add(viewId, typeOne.id, 0, typeOne.getL10n());
        Log.w("Adding " + typeOne + " " + typeOne.getL10n());
      }
    } else if (viewId == R.id.changebutton) {
      final int textId = ((TextView) findViewById(viewId)).getId();

      menu.setHeaderTitle(res.getString(R.string.log_tb_changeall));
      for (LogTypeTrackable logType : LogTypeTrackable.values()) {
        menu.add(textId, logType.id, 0, res.getString(logType.resourceId));
      }
    } else {
      final int realViewId = ((LinearLayout) findViewById(viewId)).getId();

      for (final cgTrackableLog tb : trackables) {
        if (tb.id == realViewId) {
          menu.setHeaderTitle(tb.name);
        }
      }
      for (LogTypeTrackable logType : LogTypeTrackable.values()) {
        menu.add(realViewId, logType.id, 0, res.getString(logType.resourceId));
      }
    }
  }
Beispiel #3
0
  public void setType(final LogType type) {
    final Button typeButton = ButterKnife.findById(this, R.id.type);

    typeSelected = type;
    typeButton.setText(typeSelected.getL10n());

    updateTweetBox(type);
    updateLogPasswordBox(type);
    initializeFavoriteCheck();
  }
Beispiel #4
0
  public void setType(LogType type) {
    final Button typeButton = (Button) findViewById(R.id.type);

    typeSelected = type;
    typeButton.setText(typeSelected.getL10n());

    if (LogType.FOUND_IT == type && !tbChanged) {
      // TODO: change action
    } else if (LogType.FOUND_IT != type && !tbChanged) {
      // TODO: change action
    }

    updateTweetBox(type);

    updatePostButtonText();
  }
  public void setType(LogType type) {
    final Button typeButton = (Button) findViewById(R.id.type);

    typeSelected = type;
    typeButton.setText(typeSelected.getL10n());

    if (LogType.LOG_FOUND_IT == type && !tbChanged) {
      // TODO: change action
    } else if (LogType.LOG_FOUND_IT != type && !tbChanged) {
      // TODO: change action
    }

    if (type == LogType.LOG_FOUND_IT && Settings.isUseTwitter()) {
      tweetBox.setVisibility(View.VISIBLE);
    } else {
      tweetBox.setVisibility(View.GONE);
    }
    updatePostButtonText();
  }
Beispiel #6
0
  public static LogResult postLog(
      final Geocache cache,
      final LogType logType,
      final Calendar date,
      final String log,
      final String logPassword,
      final OCApiConnector connector) {
    final Parameters params = new Parameters("cache_code", cache.getGeocode());
    params.add("logtype", logType.oc_type);
    params.add("comment", log);
    params.add("comment_format", "plaintext");
    params.add("when", LOG_DATE_FORMAT.format(date.getTime()));
    if (logType.equals(LogType.NEEDS_MAINTENANCE)) {
      params.add("needs_maintenance", "true");
    }
    if (logPassword != null) {
      params.add("password", logPassword);
    }

    final ObjectNode data = request(connector, OkapiService.SERVICE_SUBMIT_LOG, params).data;

    if (data == null) {
      return new LogResult(StatusCode.LOG_POST_ERROR, "");
    }

    try {
      if (data.get("success").asBoolean()) {
        return new LogResult(StatusCode.NO_ERROR, data.get("log_uuid").asText());
      }

      return new LogResult(StatusCode.LOG_POST_ERROR, "");
    } catch (final NullPointerException e) {
      Log.e("OkapiClient.postLog", e);
    }
    return new LogResult(StatusCode.LOG_POST_ERROR, "");
  }
  public void init() {
    if (geocode != null) {
      app.setAction(geocode);
    }
    postButton = (Button) findViewById(R.id.post);
    tweetBox = (LinearLayout) findViewById(R.id.tweet_box);
    tweetCheck = (CheckBox) findViewById(R.id.tweet);
    clearButton = (Button) findViewById(R.id.clear);
    saveButton = (Button) findViewById(R.id.save);

    possibleLogTypes = cache.getPossibleLogTypes();

    final cgLog log = app.loadLogOffline(geocode);
    if (log != null) {
      typeSelected = log.type;
      date.setTime(new Date(log.date));
      text = log.log;
      updatePostButtonText();
    } else if (StringUtils.isNotBlank(Settings.getSignature())
        && Settings.isAutoInsertSignature()
        && StringUtils.isBlank(((EditText) findViewById(R.id.log)).getText())) {
      insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), false), false);
    }

    if (!possibleLogTypes.contains(typeSelected)) {
      if (alreadyFound) {
        typeSelected = LogType.LOG_NOTE;
      } else {
        typeSelected = possibleLogTypes.get(0);
      }
      setType(typeSelected);
    }

    final Button typeButton = (Button) findViewById(R.id.type);
    registerForContextMenu(typeButton);
    typeButton.setText(typeSelected.getL10n());
    typeButton.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View view) {
            openContextMenu(view);
          }
        });

    final Button dateButton = (Button) findViewById(R.id.date);
    dateButton.setText(cgBase.formatShortDate(date.getTime().getTime()));
    dateButton.setOnClickListener(new DateListener());

    final EditText logView = (EditText) findViewById(R.id.log);
    if (StringUtils.isBlank(logView.getText()) && StringUtils.isNotBlank(text)) {
      logView.setText(text);
    }

    tweetCheck.setChecked(true);

    final ActivityState lastState = (ActivityState) getLastNonConfigurationInstance();
    if (lastState != null) {
      lastState.restore(this);
    }

    if (cgBase.isEmpty(viewstates)) {
      enablePostButton(false);
      new LoadDataThread().start();
    } else {
      enablePostButton(true);
    }

    saveButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            saveLog(true);
          }
        });

    clearButton.setOnClickListener(new ClearListener());
  }
  @Override
  public boolean onContextItemSelected(MenuItem item) {
    final int group = item.getGroupId();
    final int id = item.getItemId();

    if (group == R.id.type) {
      setType(LogType.getById(id));

      return true;
    } else if (group == R.id.changebutton) {
      try {
        final LogTypeTrackable logType = LogTypeTrackable.findById(id);
        if (logType != null) {
          final LinearLayout inventView = (LinearLayout) findViewById(R.id.inventory);
          for (int count = 0; count < inventView.getChildCount(); count++) {
            final LinearLayout tbView = (LinearLayout) inventView.getChildAt(count);
            if (tbView == null) {
              return false;
            }

            final TextView tbText = (TextView) tbView.findViewById(R.id.action);
            if (tbText == null) {
              return false;
            }
            tbText.setText(res.getString(logType.resourceId) + " ▼");
          }
          for (cgTrackableLog tb : trackables) {
            tb.action = logType;
          }
          tbChanged = true;
          return true;
        }
      } catch (Exception e) {
        Log.e("cgeovisit.onContextItemSelected: " + e.toString());
      }
    } else {
      try {
        final LogTypeTrackable logType = LogTypeTrackable.findById(id);
        if (logType != null) {
          final LinearLayout tbView = (LinearLayout) findViewById(group);
          if (tbView == null) {
            return false;
          }

          final TextView tbText = (TextView) tbView.findViewById(R.id.action);
          if (tbText == null) {
            return false;
          }

          for (cgTrackableLog tb : trackables) {
            if (tb.id == group) {
              tbChanged = true;

              tb.action = logType;
              tbText.setText(res.getString(logType.resourceId) + " ▼");

              Log.i("Trackable " + tb.trackCode + " (" + tb.name + ") has new action: #" + id);
            }
          }

          return true;
        }
      } catch (Exception e) {
        Log.e("cgeovisit.onContextItemSelected: " + e.toString());
      }
    }

    return false;
  }
Beispiel #9
0
  @Override
  public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.logcache_activity);

    // Get parameters from intent and basic cache information from database
    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
      cacheid = extras.getString(EXTRAS_ID);
      geocode = extras.getString(EXTRAS_GEOCODE);
    }

    if ((StringUtils.isBlank(cacheid)) && StringUtils.isNotBlank(geocode)) {
      cacheid = cgData.getCacheidForGeocode(geocode);
    }
    if (StringUtils.isBlank(geocode) && StringUtils.isNotBlank(cacheid)) {
      geocode = cgData.getGeocodeForGuid(cacheid);
    }

    cache = cgData.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
    possibleLogTypes = cache.getPossibleLogTypes();

    if (StringUtils.isNotBlank(cache.getName())) {
      setTitle(res.getString(R.string.log_new_log) + ": " + cache.getName());
    } else {
      setTitle(res.getString(R.string.log_new_log) + ": " + cache.getGeocode());
    }

    // Get ids for later use
    postButton = (Button) findViewById(R.id.post);
    tweetBox = (LinearLayout) findViewById(R.id.tweet_box);
    tweetCheck = (CheckBox) findViewById(R.id.tweet);
    logPasswordBox = (LinearLayout) findViewById(R.id.log_password_box);

    // initialize with default values
    setDefaultValues();

    // Restore previous state
    if (savedInstanceState != null) {
      rating = savedInstanceState.getDouble(SAVED_STATE_RATING);
      typeSelected = LogType.getById(savedInstanceState.getInt(SAVED_STATE_TYPE));
      date.setTimeInMillis(savedInstanceState.getLong(SAVED_STATE_DATE));
      imageCaption = savedInstanceState.getString(SAVED_STATE_IMAGE_CAPTION);
      imageDescription = savedInstanceState.getString(SAVED_STATE_IMAGE_DESCRIPTION);
      imageUri = Uri.parse(savedInstanceState.getString(SAVED_STATE_IMAGE_URI));
    } else {
      // If log had been previously saved, load it now, otherwise initialize signature as needed
      final LogEntry log = cgData.loadLogOffline(geocode);
      if (log != null) {
        typeSelected = log.type;
        date.setTime(new Date(log.date));
        text = log.log;
      } else if (StringUtils.isNotBlank(Settings.getSignature())
          && Settings.isAutoInsertSignature()
          && StringUtils.isBlank(currentLogText())) {
        insertIntoLog(
            LogTemplateProvider.applyTemplates(Settings.getSignature(), new LogContext(cache)),
            false);
      }
    }
    updatePostButtonText();
    updateImageButton();
    enablePostButton(false);

    final Button typeButton = (Button) findViewById(R.id.type);
    typeButton.setText(typeSelected.getL10n());
    typeButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View view) {
            selectLogType();
          }
        });

    final Button dateButton = (Button) findViewById(R.id.date);
    setDate(date);
    dateButton.setOnClickListener(new DateListener());

    final EditText logView = (EditText) findViewById(R.id.log);
    if (StringUtils.isBlank(currentLogText()) && StringUtils.isNotBlank(text)) {
      logView.setText(text);
    }

    tweetCheck.setChecked(true);
    updateTweetBox(typeSelected);
    updateLogPasswordBox(typeSelected);

    final Button imageButton = (Button) findViewById(R.id.image_btn);
    imageButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View view) {
            selectImage();
          }
        });

    final Button saveButton = (Button) findViewById(R.id.save);
    saveButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            saveLog(true);
          }
        });

    final Button clearButton = (Button) findViewById(R.id.clear);
    clearButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            clearLog();
          }
        });

    loggingManager = cache.getLoggingManager(this);

    loggingManager.init();
  }
Beispiel #10
0
  @Override
  public void onCreate(final Bundle savedInstanceState) {
    onCreate(savedInstanceState, R.layout.logcache_activity);

    // Get parameters from intent and basic cache information from database
    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
      geocode = extras.getString(Intents.EXTRA_GEOCODE);
      if (StringUtils.isBlank(geocode)) {
        final String cacheid = extras.getString(Intents.EXTRA_ID);
        if (StringUtils.isNotBlank(cacheid)) {
          geocode = DataStore.getGeocodeForGuid(cacheid);
        }
      }
    }

    cache = DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
    invalidateOptionsMenuCompatible();
    possibleLogTypes = cache.getPossibleLogTypes();

    if (StringUtils.isNotBlank(cache.getName())) {
      setTitle(res.getString(R.string.log_new_log) + ": " + cache.getName());
    } else {
      setTitle(res.getString(R.string.log_new_log) + ": " + cache.getGeocode());
    }

    initializeRatingBar();

    // initialize with default values
    setDefaultValues();

    // Restore previous state
    if (savedInstanceState != null) {
      rating = savedInstanceState.getFloat(SAVED_STATE_RATING);
      typeSelected = LogType.getById(savedInstanceState.getInt(SAVED_STATE_TYPE));
      date.setTimeInMillis(savedInstanceState.getLong(SAVED_STATE_DATE));
      image = savedInstanceState.getParcelable(SAVED_STATE_IMAGE);
      premFavPoints = savedInstanceState.getInt(SAVED_STATE_FAVPOINTS);
    } else {
      // If log had been previously saved, load it now, otherwise initialize signature as needed
      loadLogFromDatabase();
    }
    if (image == null) {
      image = Image.NONE;
    }
    enablePostButton(false);

    final Button typeButton = ButterKnife.findById(this, R.id.type);
    typeButton.setText(typeSelected.getL10n());
    typeButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(final View view) {
            selectLogType();
          }
        });

    final Button dateButton = ButterKnife.findById(this, R.id.date);
    setDate(date);
    dateButton.setOnClickListener(new DateListener());

    if (StringUtils.isBlank(currentLogText()) && StringUtils.isNotBlank(text)) {
      setLogText();
    }

    tweetCheck.setChecked(true);
    updateTweetBox(typeSelected);
    updateLogPasswordBox(typeSelected);

    loggingManager = cache.getLoggingManager(this);
    loggingManager.init();

    // Load Generic Trackables
    AppObservable.bindActivity(
            this,
            // Obtain the actives connectors
            Observable.from(ConnectorFactory.getLoggableGenericTrackablesConnectors())
                .flatMap(
                    new Func1<TrackableConnector, Observable<TrackableLog>>() {
                      @Override
                      public Observable<TrackableLog> call(
                          final TrackableConnector trackableConnector) {
                        return Observable.defer(
                                new Func0<Observable<TrackableLog>>() {
                                  @Override
                                  public Observable<TrackableLog> call() {
                                    return trackableConnector.trackableLogInventory();
                                  }
                                })
                            .subscribeOn(AndroidRxUtils.networkScheduler);
                      }
                    })
                .toList())
        .subscribe(
            new Action1<List<TrackableLog>>() {
              @Override
              public void call(final List<TrackableLog> trackableLogs) {
                // Store trackables
                trackables.addAll(trackableLogs);
                // Update the UI
                initializeTrackablesAction();
                updateTrackablesList();
              }
            });

    requestKeyboardForLogging();
  }