Ejemplo n.º 1
0
  /** * put info on screen for current translator */
  private void updateTranslator() {
    ArrayList<NativeSpeaker> translators = mTargetTranslation.getTranslators();

    if (mCurrentTranslator >= translators.size()) {
      mCurrentTranslator = 0;
    }

    boolean moreThanOne = (translators.size() > 1);
    mContributor.setVisibility(moreThanOne ? View.VISIBLE : View.GONE);

    if (translators.size() > 0) {
      NativeSpeaker trans = translators.get(mCurrentTranslator);
      mNameText.setText(trans.name);
      mEmailText.setText(trans.email);
      mPhoneText.setText(trans.phone);

      if (moreThanOne) {
        mContributorToggle.setText(trans.name);
      }
    } else { // if empty
      mNameText.setText("");
      mEmailText.setText("");
      mPhoneText.setText("");
    }
  }
Ejemplo n.º 2
0
  /**
   * * show specific translator
   *
   * @param name
   */
  private void showTranslator(String name) {

    int pos = mTargetTranslation.getTranslatorByName(name);

    if (pos < 0) {
      pos = 0;
    }

    mCurrentTranslator = pos;
    updateTranslator();
  }
Ejemplo n.º 3
0
 /**
  * * get info about current translator and save it
  *
  * @return
  */
 private NativeSpeaker saveCurrentTranslator() {
   NativeSpeaker translator = getNewTranslatorData();
   mTargetTranslation.addTranslator(translator);
   return translator;
 }
Ejemplo n.º 4
0
  /** Performs the backup if nessesary */
  private void runBackup() {
    boolean backupPerformed = false;
    Translator translator = AppContext.getTranslator();
    TargetTranslation[] targetTranslations = translator.getTargetTranslations();
    for (TargetTranslation t : targetTranslations) {

      // commit pending changes
      try {
        t.commit();
      } catch (Exception e) {
        Logger.e(this.getClass().getName(), "Failed to commit changes before backing up", e);
        continue;
      }

      // run backup if there are translations
      if (t.numTranslated() > 0) {

        // retreive commit hash
        String tag;
        try {
          tag = t.getCommitHash();
        } catch (Exception e) {
          Logger.w(this.getClass().getName(), "Failed to read commit hash", e);
          continue;
        }

        // check if backup is required
        if (tag != null) {
          File primaryBackupDir =
              new File(AppContext.getPublicDirectory(), "backups/" + t.getId() + "/");
          File primaryBackupFile =
              new File(primaryBackupDir, tag + "." + Translator.ARCHIVE_EXTENSION);
          File downloadBackupDir =
              new File(AppContext.getPublicDownloadsDirectory(), "backups/" + t.getId() + "/");
          File downloadBackupFile =
              new File(downloadBackupDir, tag + "." + Translator.ARCHIVE_EXTENSION);
          // e.g. ../../backups/uw-obs-de/[commit hash].tstudio
          if (!downloadBackupFile.exists()) {

            // peform backup
            File archive =
                new File(
                    AppContext.getPublicDownloadsDirectory(),
                    t.getId() + ".temp." + Translator.ARCHIVE_EXTENSION);
            try {
              translator.exportArchive(t, archive);
            } catch (Exception e) {
              Logger.e(
                  this.getClass().getName(),
                  "Failed to export the target translation " + t.getId(),
                  e);
              continue;
            }
            if (archive.exists() && archive.isFile()) {
              // move into backup
              FileUtils.deleteQuietly(downloadBackupDir);
              FileUtils.deleteQuietly(primaryBackupDir);
              downloadBackupDir.mkdirs();
              primaryBackupDir.mkdirs();
              try {
                // backup to downloads directory
                FileUtils.copyFile(archive, downloadBackupFile);
                // backup to a slightly less public area (used for auto restore)
                FileUtils.copyFile(archive, primaryBackupFile);
                backupPerformed = true;
              } catch (IOException e) {
                Logger.e(
                    this.getClass().getName(),
                    "Failed to copy the backup archive for target translation: " + t.getId(),
                    e);
              }
              archive.delete();
            } else {
              Logger.w(
                  this.getClass().getName(),
                  "Failed to export the target translation: " + t.getId());
            }
          }
        } else {
          Logger.w(this.getClass().getName(), "Could not find the commit hash");
        }
      }
    }

    if (backupPerformed) {
      onBackupComplete();
    }
  }