Пример #1
0
 @Override
 public void start() {
   publishProgress(-1, "");
   String terms =
       DataStore.pullTerms(mProject.getId(), mLanguage.getId(), mResource.getId(), false, false);
   AppContext.projectManager().loadTerms(terms, mProject);
 }
  /**
   * Displays the frame reader dialog
   *
   * @param p
   */
  protected void showFrameReaderDialog(Project p, FramesListAdapter.DisplayOption option) {
    if (p != null && p.getSelectedChapter() != null) {
      // move other dialogs to backstack
      FragmentTransaction ft = getFragmentManager().beginTransaction();
      Fragment prev = getFragmentManager().findFragmentByTag("dialog");
      if (prev != null) {
        ft.remove(prev);
      }
      ft.addToBackStack(null);

      // Create the dialog
      FramesReaderDialog newFragment = new FramesReaderDialog();
      Bundle args = new Bundle();
      args.putString(FramesReaderDialog.ARG_PROJECT_ID, p.getId());
      args.putString(FramesReaderDialog.ARG_CHAPTER_ID, p.getSelectedChapter().getId());
      args.putInt(
          FramesReaderDialog.ARG_SELECTED_FRAME_INDEX,
          p.getSelectedChapter().getFrameIndex(p.getSelectedChapter().getSelectedFrame()));

      // configure display option
      args.putInt(FramesReaderDialog.ARG_DISPLAY_OPTION_ORDINAL, option.ordinal());

      // display dialog
      newFragment.setArguments(args);
      newFragment.show(ft, "dialog");
    }
  }
 /**
  * Begins a new download if one is not already in progress
  *
  * @param language
  */
 private void connectDownloadTask(SourceLanguage language) {
   String taskId = DOWNLOAD_LANGUAGE_PREFIX + mProject.getId() + "-" + language.getId();
   DownloadLanguageTask task = (DownloadLanguageTask) TaskManager.getTask(taskId);
   if (task == null) {
     // start new download
     task = new DownloadLanguageTask(mProject, language);
     TaskManager.addTask(task, taskId);
     // NOTE: the LibraryLanguageAdapter handles the onProgress and onFinish events
     mAdapter.notifyDataSetChanged();
   }
 }
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_project_library_languages, container, false);

    if (getArguments().containsKey(ProjectLibraryDetailFragment.ARG_ITEM_ID)) {
      String id = getArguments().getString(ProjectLibraryDetailFragment.ARG_ITEM_ID);
      mProject = LibraryTempData.getProject(id);
    }

    mAdapter =
        new LibraryLanguageAdapter(
            AppContext.context(), mProject.getId(), DOWNLOAD_LANGUAGE_PREFIX, false);

    ListView list = (ListView) view.findViewById(R.id.listView);
    list.setAdapter(mAdapter);
    list.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (LibraryTempData.getEnableEditing()) {
              // TODO: place all of this in a task
              SourceLanguage lang = mAdapter.getItem(i);
              AppContext.projectManager().deleteSourceLanguage(mProject.getId(), lang.getId());
              LibraryTempData.organizeProjects();
              mAdapter.notifyDataSetChanged();
              if (!AppContext.projectManager().isProjectDownloaded(mProject.getId())
                  && getActivity() != null
                  && getActivity() instanceof LibraryCallbacks) {
                ((LibraryCallbacks) getActivity()).refreshUI();
              }
            } else {
              SourceLanguage lang = mAdapter.getItem(i);
              connectDownloadTask(lang);
            }
          }
        });

    populateList();

    return view;
  }