Ejemplo n.º 1
0
  public void markFileIsDirty(Boolean dirty, String widgetId) {
    // Need to mark the file as dirty for our cloud services.
    // Read in the saved deviceState from the xml file and put it into a List<>.
    List<KMMDDeviceItem> savedDeviceState = new ArrayList<KMMDDeviceItem>();
    KMMDDeviceItem currentFile = null;
    KMMDDeviceItemParser parser =
        new KMMDDeviceItemParser(KMMDDropboxService.DEVICE_STATE_FILE, this);
    savedDeviceState = parser.parse();

    // Get the correct database
    // If widgetId is 9999, then we are already in the application and need to get the default
    // database.
    // If widgetId is null, then we are coming from a scheduled event for checking schedules of the
    // main app.
    String prefString = null;
    if (widgetId == null) prefString = "Full Path";
    else if (widgetId.equals("9999")) prefString = "currentOpenedDatabase";
    else prefString = "widgetDatabasePath" + String.valueOf(widgetId);

    String path = prefs.getString(prefString, "");
    Log.d(TAG, "Path for the database marked dirty: " + path);

    if (savedDeviceState != null) {
      // Find the correct file in our saved state and mark it as dirty.
      for (KMMDDeviceItem item : savedDeviceState) {
        currentFile = item.findMatch(path);
        if (currentFile != null) break;
        else currentFile = new KMMDDeviceItem(new File(path));
      }
    } else {
      // This is the first time we have run this routine and we only have one file to mark.
      currentFile = new KMMDDeviceItem(new File(path));
    }
    currentFile.setIsDirty(true, KMMDDropboxService.CLOUD_ALL);

    if (savedDeviceState != null) {
      // Replace this in the savedDeviceState list then write it to disk.
      for (int i = 0; i < savedDeviceState.size(); i++) {
        if (savedDeviceState.get(i).equals(currentFile)) {
          savedDeviceState.add(i, currentFile);
          savedDeviceState.remove(i + 1);
          i = savedDeviceState.size() + 1;
        }
      }
    } else {
      savedDeviceState = new ArrayList<KMMDDeviceItem>();
      savedDeviceState.add(currentFile);
    }

    writeDeviceState(savedDeviceState);
  }