Пример #1
0
  @WorkerThread
  public void getSpecificSection(
      Context context, int sectionPos, OnSectionDetailReadyListener listener) {

    SectionModel section = mTopSections.get(sectionPos);

    String sectionName = section.getName();

    if (CommonUtil.isEmpty(mDetailSections) || !mDetailSections.containsKey(sectionName)) {

      if (CommonUtil.checkInternetConnection(context)) {

        // try downloading data from web

        RawViaplayModel detail = null;

        try {

          detail = getSectionFromWeb(section.getUrl());

          populateSectionDetailCache(section, detail);

          returnSectionDetailToListener(sectionName, listener);

          DatabaseManager.getInstance()
              .saveDataToDb(SectionDetailModel.generateFrom(detail, section));

        } catch (IOException e) {
          Log.e(TAG, "Error while downloading section");
        }
      } else {

        // try retrieving data from db
        SectionDetailModel detail = DatabaseManager.getInstance().getSectionDetailFromDb(section);
        populateSectionDetailCache(section, detail);
        returnSectionDetailToListener(sectionName, listener);
      }

    } else {

      Log.d(TAG, "Retrieving data from cache");
      returnSectionDetailToListener(sectionName, listener);
    }
  }
Пример #2
0
  private void populateSectionDetailCache(SectionModel section, SectionDetailModel detail) {

    if (detail != null) mDetailSections.put(section.getName(), detail);
  }
Пример #3
0
  private void populateSectionDetailCache(SectionModel section, RawViaplayModel rawModel) {

    mDetailSections.put(section.getName(), SectionDetailModel.generateFrom(rawModel, section));
  }
Пример #4
0
  private void populateTopSectionsCache(RawViaplayModel rawModel) {

    for (RawViaplaySectionModel rawSection : rawModel.getSections())
      mTopSections.add(SectionModel.generateFrom(rawSection));
  }