/* rescans all the installed courses and reinstalls them, to ensure that
   * the new titles etc are picked up
   */
  protected void upgradeV17() {
    File dir = new File(Storage.getCoursesPath(ctx));
    String[] children = dir.list();
    if (children != null) {
      for (String course : children) {
        publishProgress("checking: " + course);
        String courseXMLPath = "";
        String courseScheduleXMLPath = "";
        String courseTrackerXMLPath = "";
        // check that it's unzipped etc correctly
        try {
          courseXMLPath =
              dir + File.separator + course + File.separator + MobileLearning.COURSE_XML;
          courseScheduleXMLPath =
              dir + File.separator + course + File.separator + MobileLearning.COURSE_SCHEDULE_XML;
          courseTrackerXMLPath =
              dir + File.separator + course + File.separator + MobileLearning.COURSE_TRACKER_XML;
        } catch (ArrayIndexOutOfBoundsException aioobe) {
          FileUtils.cleanUp(dir, Storage.getDownloadPath(ctx) + course);
          break;
        }

        // check a module.xml file exists and is a readable XML file
        CourseXMLReader cxr;
        CourseScheduleXMLReader csxr;
        CourseTrackerXMLReader ctxr;
        try {
          cxr = new CourseXMLReader(courseXMLPath, 0, ctx);
          csxr = new CourseScheduleXMLReader(courseScheduleXMLPath);
          File trackerXML = new File(courseTrackerXMLPath);
          ctxr = new CourseTrackerXMLReader(trackerXML);
        } catch (InvalidXMLException e) {
          e.printStackTrace();
          break;
        }

        Course c = new Course(prefs.getString(PrefsActivity.PREF_STORAGE_LOCATION, ""));
        c.setVersionId(cxr.getVersionId());
        c.setTitles(cxr.getTitles());
        c.setShortname(course);
        c.setImageFile(course + File.separator + cxr.getCourseImage());
        c.setLangs(cxr.getLangs());
        c.setPriority(cxr.getPriority());

        DbHelper db = DbHelper.getInstance(ctx);
        long courseId = db.addOrUpdateCourse(c);

        if (courseId != -1) {
          db.insertActivities(cxr.getActivities(courseId));
          db.insertTrackers(ctxr.getTrackers(courseId, 0));
        }

        // add schedule
        // put this here so even if the course content isn't updated the schedule will be
        db.insertSchedule(csxr.getSchedule());
        db.updateScheduleVersion(courseId, csxr.getScheduleVersion());
      }
    }
  }
    public void onClick(View v) {
      // check video file exists
      boolean exists = Storage.mediaFileExists(QuizWidget.super.getActivity(), mediaFileName);
      if (!exists) {
        Toast.makeText(
                QuizWidget.super.getActivity(),
                QuizWidget.super
                    .getActivity()
                    .getString(R.string.error_media_not_found, mediaFileName),
                Toast.LENGTH_LONG)
            .show();
        return;
      }

      String mimeType =
          FileUtils.getMimeType(
              Storage.getMediaPath(QuizWidget.super.getActivity()) + mediaFileName);
      if (!FileUtils.supportedMediafileType(mimeType)) {
        Toast.makeText(
                QuizWidget.super.getActivity(),
                QuizWidget.super
                    .getActivity()
                    .getString(R.string.error_media_unsupported, mediaFileName),
                Toast.LENGTH_LONG)
            .show();
        return;
      }

      Intent intent = new Intent(QuizWidget.super.getActivity(), VideoPlayerActivity.class);
      Bundle tb = new Bundle();
      tb.putSerializable(VideoPlayerActivity.MEDIA_TAG, mediaFileName);
      tb.putSerializable(Activity.TAG, activity);
      tb.putSerializable(Course.TAG, course);
      intent.putExtras(tb);
      startActivity(intent);
    }