/**
  * Merges chunks found in the target translation projects that do not exist in the source
  * translation to a sibling chunk so that no data is lost.
  *
  * @param library
  * @param targetTranslations target translations to merge
  * @return
  */
 public static boolean migrateChunkChanges(
     final Library library, final TargetTranslation[] targetTranslations) {
   boolean mergeSuccess = true;
   for (TargetTranslation targetTranslation : targetTranslations) {
     boolean success = migrateChunkChanges(AppContext.getLibrary(), targetTranslation);
     mergeSuccess = mergeSuccess && success;
   }
   return mergeSuccess;
 }
Example #2
0
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_publish_profile, container, false);

    Bundle args = getArguments();
    String targetTranslationId = args.getString(PublishActivity.EXTRA_TARGET_TRANSLATION_ID);
    Translator translator = AppContext.getTranslator();
    mTargetTranslation = translator.getTargetTranslation(targetTranslationId);

    mNameText = (EditText) rootView.findViewById(R.id.name_edittext);
    mEmailText = (EditText) rootView.findViewById(R.id.email_edittext);
    mPhoneText = (EditText) rootView.findViewById(R.id.phone_edittext);

    // buttons
    ImageButton nameInfoButton = (ImageButton) rootView.findViewById(R.id.name_info_button);
    ViewUtil.tintViewDrawable(nameInfoButton, getResources().getColor(R.color.dark_secondary_text));
    ImageButton emailInfoButton = (ImageButton) rootView.findViewById(R.id.email_info_button);
    ViewUtil.tintViewDrawable(
        emailInfoButton, getResources().getColor(R.color.dark_secondary_text));
    ImageButton phoneInfoButton = (ImageButton) rootView.findViewById(R.id.phone_info_button);
    ViewUtil.tintViewDrawable(
        phoneInfoButton, getResources().getColor(R.color.dark_secondary_text));

    mContributor = (View) rootView.findViewById(R.id.contributor_button);
    mContributorToggle = (TextView) rootView.findViewById(R.id.toggle_contributor);

    mContributorToggle.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            getNextTranslator();
          }
        });

    nameInfoButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            showPrivacyNotice(rootView, true);
          }
        });
    emailInfoButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            showPrivacyNotice(rootView, true);
          }
        });
    phoneInfoButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            showPrivacyNotice(rootView, true);
          }
        });

    Button addContributorButton = (Button) rootView.findViewById(R.id.add_contributor_button);
    addContributorButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            NativeSpeaker translator = saveCurrentTranslator();
            showTranslator(translator.name);
          }
        });

    addContributorButton.setVisibility(
        View.GONE); // TODO remove to re-enable support for multiple contributors

    ImageButton deleteContributorButton =
        (ImageButton) rootView.findViewById(R.id.delete_contributor_button);
    deleteContributorButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {

            final CustomAlertDialog dlg = CustomAlertDialog.Create(getActivity());
            dlg.setTitle(R.string.delete_translator_title)
                .setMessageHtml(R.string.confirm_delete_translator)
                .setPositiveButton(
                    R.string.confirm,
                    new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {

                        String name = mContributorToggle.getText().toString();
                        mTargetTranslation.removeTranslator(name);
                        updateTranslator();

                        dlg.dismiss();
                      }
                    })
                .setNegativeButton(R.string.title_cancel, null)
                .show("DeleteTrans");
          }
        });

    Button nextButton = (Button) rootView.findViewById(R.id.next_button);
    nextButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (mNameText.getText().toString().isEmpty()
                || mEmailText.getText().toString().isEmpty()) {
              Snackbar snack =
                  Snackbar.make(
                      getActivity().findViewById(android.R.id.content),
                      R.string.complete_required_fields,
                      Snackbar.LENGTH_SHORT);
              ViewUtil.setSnackBarTextColor(
                  snack, getResources().getColor(R.color.light_primary_text));
              snack.show();
            } else {
              showPrivacyNotice(rootView, false);
            }
          }
        });

    updateTranslator();

    return rootView;
  }
Example #3
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();
    }
  }