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

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

/***********************************************************************************************************************
 *
 * blueBill Mobile - open source birdwatching
 * ==========================================
 *
 * Copyright (C) 2009, 2010 by Tidalwave s.a.s. (http://www.tidalwave.it)
 * http://bluebill.tidalwave.it/mobile/
 *
 ***********************************************************************************************************************
 *
 * 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.
 *
 ***********************************************************************************************************************
 *
 * $Id: RSSFeedAdapter.java,v d808b6cb5d50 2010/07/10 21:19:33 fabrizio $
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.news;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.inject.Provider;
import java.util.List;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.util.logging.Logger;
import it.tidalwave.netbeans.util.Locator;
import it.tidalwave.mobile.rss.Message;
import it.tidalwave.bluebill.mobile.GeneralPreferences;
import it.tidalwave.bluebill.mobile.news.NewsController;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.content.res.Resources;
import it.tidalwave.bluebill.mobile.android.R;
import static it.tidalwave.mobile.rss.Vocabulary.*;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id: $
 *
 **********************************************************************************************************************/
public class RSSFeedAdapter extends BaseAdapter
  {
    private static final String CLASS = RSSFeedAdapter.class.getName();
    private static final Logger logger = Logger.getLogger(CLASS);

    @Nonnull
    private final Resources resources;

    @Nonnull
    private final List messages;

    @Nonnull
    private final LayoutInflater layoutInflater;

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

    @Nonnull
    private final Provider newsController = Locator.createProviderFor(NewsController.class);

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public RSSFeedAdapter (final @Nonnull Context context, final @Nonnull List messages)
      {
        this.messages = messages;
        this.layoutInflater = LayoutInflater.from(context);
        resources = context.getResources();
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Nonnegative
    public int getCount()
      {
        return messages.size();
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Nonnull
    public Message getItem (final @Nonnegative int index)
      {
        return messages.get(index);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public long getItemId (final @Nonnegative int id)
      {
        return id;
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Nonnull
    public View getView (final @Nonnegative int index,
                         @Nonnull View view,
                         final @Nonnull ViewGroup viewGroup)
      {
        if (view == null)
          {
            view = layoutInflater.inflate(R.layout.news_list_row, null);
//            view.setTag(nameViewHelper = new NameViewHelper(view));
          }
        else
          {
//            nameViewHelper = (NameViewHelper)view.getTag();
          }

      final Message message = getItem(index);

      try
        {
          final String date = preferences.get().formatDateAndTime(message.get(PUB_DATE));
          final TextView tvDate = (TextView)view.findViewById(R.id.tvDate);
          final TextView tvTitle = (TextView)view.findViewById(R.id.tvTitle);
          tvDate.setText(date);
          tvTitle.setText(message.get(TITLE));

          final int icon = newsController.get().isRead(message) ? android.R.drawable.star_off
                                                                : android.R.drawable.star_on;
          ((ImageView)view.findViewById(R.id.ivRead)).setImageResource(icon);
        }
      catch (NotFoundException e)
        {
        }
//        nameViewHelper.set(getItem(index));

        return view;
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy