All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.tidalwave.bluebill.mobile.android.news.AndroidNewsViewController Maven / Gradle / Ivy

/***********************************************************************************************************************
 *
 * blueBill Mobile - Android - open source birding
 * Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
 *
 ***********************************************************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations under the License.
 *
 ***********************************************************************************************************************
 *
 * WWW: http://bluebill.tidalwave.it/mobile
 * SCM: https://kenai.com/hg/bluebill~android-src
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.news;

import java.io.IOException;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.inject.Provider;
import java.util.List;
import it.tidalwave.util.logging.Logger;
import it.tidalwave.netbeans.util.Locator;
import it.tidalwave.mobile.rss.RSSFeed;
import it.tidalwave.bluebill.mobile.GeneralPreferences;
import it.tidalwave.bluebill.mobile.news.DefaultNewsViewController;
import it.tidalwave.semantic.document.Document;
import android.content.Context;
import android.content.Intent;
import static it.tidalwave.mobile.rss.RssVocabulary.*;

/***********************************************************************************************************************
 *
 * @stereotype Controller
 * 
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
public class AndroidNewsViewController extends DefaultNewsViewController
  {
    private static final String CLASS = AndroidNewsViewController.class.getName();
    private static final Logger logger = Logger.getLogger(CLASS);

    @Nonnull
    private final NewsActivity view;
    
    @Nonnull
    private final Provider context = Locator.createProviderFor(Context.class);

    @Nonnull
    private final Provider preferences = Locator.createProviderFor(GeneralPreferences.class);    
    
    @CheckForNull
    private RSSFeedAdapter rssFeedAdapter;

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public AndroidNewsViewController (final @Nonnull NewsActivity view) 
      {
        super(view);
        this.view = view;
      }

    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    @Override
    public void markAllRead (final @Nonnull RSSFeed rssFeed) 
      {
        if (rssFeed != null) // defensive
          {
            try
              {
                super.markAllRead(rssFeed);
                rssFeedAdapter.notifyDataSetInvalidated();
              }
            catch (IOException e)
              {
                logger.warning("Can't mark all read: %s", e);
                logger.throwing(CLASS, "onClick()", e);
              }
          }
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public void readMessage (final @Nonnull Document message) 
      {
        try
          {
            markRead(message);
            rssFeedAdapter.notifyDataSetInvalidated();
            
            final String date = preferences.get().formatDateAndTime(message.get(PUB_DATE));
            final Intent intent = new Intent(context.get(), NewsItemActivity.class);
            intent.putExtra("date", date);
            intent.putExtra("title", message.get(TITLE));
            intent.putExtra("content", message.get(CONTENT));
            view.startActivity(intent);
          }
        catch (Exception e)
          {
            logger.warning("Can't show news item: %s", e);
            logger.throwing(CLASS, "onItemClick()", e);
          }
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Nonnull
    protected RSSFeedAdapter getNewsFeedAdapter (final @Nonnull List messages)
      {
        return rssFeedAdapter = new RSSFeedAdapter(view.getBaseContext(), messages);
      }
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy