public void updateAll() {
    Cursor c = sourceDB.findAll();
    ManagedCursor mc = new ManagedCursor(c);
    final SourceCache sourceCache = SourceCache.getInstance(indexActivity);
    final List<CachedArticleSource> cachedArticleSources = new ArrayList<CachedArticleSource>();
    mc.each(
        new EachCursor() {
          public void call(Cursor c, int index) {
            String sourceType = c.getString(c.getColumnIndex(Source.KEY_SOURCE_TYPE));
            String sourceContentUrl = c.getString(c.getColumnIndex(Source.KEY_CONTENT_URL));
            String sourceName = c.getString(c.getColumnIndex(Source.KEY_SOURCE_NAME));
            String sourceImage = c.getString(c.getColumnIndex(Source.KEY_IMAGE_URL));
            String sourceID = c.getString(c.getColumnIndex(Source.KEY_SOURCE_ID));

            //                adapter.getItem()
            CachedArticleSource cachedArticleSource = null;
            if (sourceType.equals(Constants.TYPE_RSS)) {
              FeaturedArticleSource featuredArticleSource =
                  new FeaturedArticleSource(
                      indexActivity, sourceContentUrl, sourceName, sourceImage);
              cachedArticleSource =
                  new CachedArticleSource(
                      featuredArticleSource, indexActivity, indexActivity, sourceCache);
            }

            if (cachedArticleSource != null) {
              cachedArticleSources.add(cachedArticleSource);
            }
          }
        });
    this.sourceDB.close();
    //        sourceCache.close();
    for (int i = 0; i < cachedArticleSources.size(); i++) {
      CachedArticleSource cachedArticleSource = cachedArticleSources.get(i);
      cachedArticleSource.loadSourceFromCache();
      cachedArticleSource.checkUpdate();
    }
  }
Beispiel #2
0
  public void reload() {
    currentPageIndex = -1;
    PagingStrategy pagingStrategy = null;
    if (accountType.equals(Constants.TYPE_SINA_WEIBO)
        || accountType.equals(Constants.TYPE_MY_SINA_WEIBO)) {
      //// System.out.println("accountType" + accountType);
      if (isWeiboMode()) pagingStrategy = new WeiboPagingStrategy(this);
      else pagingStrategy = new FixedPagingStrategy(this, 2);

      pagingStrategy.setNoMoreArticleListener(
          new NoMoreArticleListener() {
            public void onNoMoreArticle() throws NoMoreStatusException {
              // Log.d("cache system", "no more articles, refreshing repo");
              repo.refresh(repo.getRefreshingToken());
            }
          });

      repo = new ContentRepo(pagingStrategy, refreshingSemaphore);

      sinaToken = SinaAccountUtil.getToken(PageActivity.this);
      ArticleFilter filter;
      if (isWeiboMode()) filter = new NullArticleFilter();
      else filter = new ContainsLinkFilter(new NullArticleFilter());

      source =
          new SinaArticleSource(
              true, sinaToken.getToken(), sinaToken.getTokenSecret(), sourceId, filter);

    } else if (accountType.equals(Constants.TYPE_RSS)
        || accountType.equals(Constants.TYPE_BAIDUSEARCH)) {
      pagingStrategy = new FixedPagingStrategy(this, 2);
      pagingStrategy.setNoMoreArticleListener(
          new NoMoreArticleListener() {
            public void onNoMoreArticle() throws NoMoreStatusException {
              throw new NoMoreStatusException();
            }
          });

      repo = new ContentRepo(pagingStrategy, refreshingSemaphore);
      cachedArticleSource =
          new CachedArticleSource(
              new FeaturedArticleSource(this, contentUrl, sourceName, sourceImageURL),
              this,
              this,
              SourceCache.getInstance(this));
      cachedArticleSource.loadSourceFromCache();
      source = cachedArticleSource;
    } else if (accountType.equals(Constants.TYPE_GOOGLE_READER)) {

      String sid = preferences.getString(GoogleAccountActivity.GOOGLE_ACCOUNT_SID, "");
      String auth = preferences.getString(GoogleAccountActivity.GOOGLE_ACCOUNT_AUTH, "");

      pagingStrategy = new FixedPagingStrategy(this, 2);
      pagingStrategy.setNoMoreArticleListener(
          new NoMoreArticleListener() {
            public void onNoMoreArticle() throws NoMoreStatusException {
              throw new NoMoreStatusException();
            }
          });
      repo = new ContentRepo(pagingStrategy, refreshingSemaphore);
      source = new GoogleReaderArticleSource(sid, auth);
    } else if (accountType.equals(Constants.TYPE_TAOBAO)) {

      pagingStrategy = new FixedPagingStrategy(this, 2);
      pagingStrategy.setNoMoreArticleListener(
          new NoMoreArticleListener() {
            public void onNoMoreArticle() throws NoMoreStatusException {
              throw new NoMoreStatusException();
            }
          });

      repo = new ContentRepo(pagingStrategy, refreshingSemaphore);
      source = new TaobaoArticleSource(sourceName, this.getApplicationContext());
    }

    repo.setArticleSource(source);

    headerText.setText(sourceName);
    if (sourceImageURL != null && sourceImageURL.length() != 0) {
      headerImageView.setImageUrl(sourceImageURL);
      headerImageView.loadImage();
    } else {
      int maxTitle = 7;

      if (sourceName != null && sourceName.length() >= maxTitle)
        headerImageView.setVisibility(View.GONE);
      else headerImageView.setVisibility(View.INVISIBLE);
    }

    slidingWindows = new PageViewSlidingWindows(10, repo, pageViewFactory, 3);
    current = pageViewFactory.createFirstPage();

    shadow = new LinearLayout(PageActivity.this);
    shadow.setBackgroundColor(Color.parseColor("#10999999"));

    shadow2 = new LinearLayout(PageActivity.this);
    shadow2.setBackgroundColor(Color.parseColor("#FFDDDDDD"));

    shadowParams =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
    pageViewLayoutParamsFront =
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT);
    pageViewLayoutParamsBack = pageViewLayoutParamsFront;
    flipPage(true);
  }