Ejemplo n.º 1
0
  private void renameFile(File oldFile, PictureFile pictureFile, String newGeoname) {

    pictureFile.setGeo_name(newGeoname);

    Double lat = pictureFile.getLat();
    Double lon = pictureFile.getLon();
    String geoname = newGeoname;
    Long time = pictureFile.getTime();

    String oldPath = pictureFile.getFull_path_on_device();
    int indexForSlash = oldPath.lastIndexOf("/");
    String parentPath = oldPath.substring(0, indexForSlash + 1);
    String timestamp = StorageHelper.formatTimeForFilename(time);
    String location = StorageHelper.formatLatLonGeoname(lat, lon, geoname);
    String username = daoHelper.getUserName();
    String newName = StorageHelper.formatFilename(username, location, timestamp);
    String newPath = parentPath + newName;

    pictureFile.setFilename(newName);
    pictureFile.setFull_path_on_device(newPath);

    File newFile = new File(newPath);
    oldFile.renameTo(newFile);

    Log.w(LOG_TAG, "Renamed " + oldPath + " to " + newPath);

    daoHelper.pictureFileDao.update(pictureFile);
    daoHelper.onPictureFilesUpdated();
  }
Ejemplo n.º 2
0
  private void beginUpload(PictureFile pictureFile) {
    String full_path_on_device = pictureFile.getFull_path_on_device();
    Log.w(LOG_TAG, "try start upload file = " + full_path_on_device);
    File fileFromPath = new File(full_path_on_device);
    boolean exists = fileFromPath.exists();
    if (exists) {
      boolean addressExist = isAddressExist(pictureFile);
      Log.w(
          LOG_TAG,
          "file "
              + full_path_on_device
              + " EXIST. Try upload it. Address  exist = "
              + addressExist);

      if (!addressExist) {
        Log.w(LOG_TAG, "file " + full_path_on_device + " don't have geoname, try found it ");
        try {
          String newGeoname = retrieveGeoName(pictureFile);

          if (newGeoname != null && !newGeoname.isEmpty()) {
            renameFile(fileFromPath, pictureFile, newGeoname);
          }

        } catch (IOException e) {
          e.printStackTrace();
        }
        addressExist = isAddressExist(pictureFile);
        full_path_on_device = pictureFile.getFull_path_on_device();
        Log.w(LOG_TAG, "file " + full_path_on_device + " address retrieved  = " + addressExist);
      }

      if (addressExist) {
        File localFile = new File(full_path_on_device);
        String remoteName = pictureFile.getFilename();
        initUpload(pictureFile, localFile, remoteName);
        Log.w(LOG_TAG, "file " + full_path_on_device + " is READY. START UPLOAD AWS id");
      } else {
        Log.e(LOG_TAG, "file " + full_path_on_device + " don't receive geoname, skip it ");
        String filename = pictureFile.getFilename();
        addInFailed(filename);

        uploadCycleFinished();
      }

    } else {
      Log.e(LOG_TAG, "file " + full_path_on_device + " NOT EXIST. Remove it from database");
      PictureFile deletedFile = daoHelper.getFileFromPath(full_path_on_device);
      if (deletedFile != null) {
        daoHelper.pictureFileDao.delete(deletedFile);
        daoHelper.onPictureFilesUpdated();
      }
      Intent intent = new Intent(BroadcastReceiverHelper.ACTION);
      intent.putExtra(BroadcastReceiverHelper.PARAM, BroadcastReceiverHelper.PARAM_DELETED);
      String name = fileFromPath.getName();
      intent.putExtra(BroadcastReceiverHelper.FILENAME, name);
      sendBroadcast(intent);

      uploadCycleFinished();
    }
  }
Ejemplo n.º 3
0
  private void setUpUploadingAgain(PictureFile failedFile) {

    if (failedFile != null) {
      String filename = failedFile.getFilename();
      if (Constants.DEBUG) {
        ToastHelper.showToast(getApplicationContext(), "FAILED " + failedFile.getFilename());
      }
      Log.w(LOG_TAG, "FAILED " + filename);
      failedFile.setStatus(DAOHelper.FILE_STATUS_IN_QUEUE);
      daoHelper.pictureFileDao.update(failedFile);
      daoHelper.onPictureFilesUpdated();
    }
  }
Ejemplo n.º 4
0
  private void onUploadInProgress(PictureFile uploadingFile) {

    if (uploadingFile != null) {
      Integer oldStatus = uploadingFile.getStatus();
      if (oldStatus != DAOHelper.FILE_STATUS_UPLOADING
          && oldStatus != DAOHelper.FILE_STATUS_UPLOADED) {
        Log.w(LOG_TAG, "IN PROGRESS " + uploadingFile.getFilename());
        uploadingFile.setStatus(DAOHelper.FILE_STATUS_UPLOADING);
        daoHelper.pictureFileDao.update(uploadingFile);
        daoHelper.onPictureFilesUpdated();
      }
    }
  }
Ejemplo n.º 5
0
  private void onUploadCompleted(PictureFile uploadedFile) {

    if (uploadedFile != null) {
      if (Constants.DEBUG) {
        ToastHelper.showToast(getApplicationContext(), "COMPLETED " + uploadedFile.getFilename());
      }
      Log.w(LOG_TAG, "COMPLETED " + uploadedFile.getFilename());
      uploadedFile.setStatus(DAOHelper.FILE_STATUS_UPLOADED);
      uploadedFile.setIsDeleted(false);
      daoHelper.pictureFileDao.update(uploadedFile);
      daoHelper.onPictureFilesUpdated();
    }

    uploadCycleFinished();
  }