Android Open Source - RssReader Main Activity






From Project

Back to project page RssReader.

License

The source code is released under:

MIT License

If you think the Android project RssReader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.vicmns.rssreader.activities;
//from   w  w w.  j  ava  2  s.  c om
import java.util.List;

import uk.co.senab.actionbarpulltorefresh.extras.actionbarcompat.PullToRefreshLayout;
import uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh;
import uk.co.senab.actionbarpulltorefresh.library.listeners.OnRefreshListener;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.vicmns.rssreader.R;
import com.vicmns.rssreader.adapters.RssItemsAdapter;
import com.vicmns.rssreader.http.GetRssItems;
import com.vicmns.rssreader.interfaces.GetRssItemsCallbacks;
import com.vicmns.rssreader.interfaces.ListOverlayLayoutCallbacks;
import com.vicmns.rssreader.models.RssItem;
import com.vicmns.rssreader.views.ListOverlayLayoutView;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.FrameLayout;
import android.widget.ListView;

public class MainActivity extends ActionBarActivity implements 
  ListOverlayLayoutCallbacks, OnRefreshListener, GetRssItemsCallbacks, OnItemClickListener {
  private ListOverlayLayoutView listOverlayLayoutView;
  private ListView rssItemsListView;
  private PullToRefreshLayout mPullToRefreshLayout;
  
  private RequestQueue queue;
  private GetRssItems getRssItems;
  
  private RssItemsAdapter rssItemsAdapter;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initializeViews();
    getSupportActionBar().setDisplayHomeAsUpEnabled(false);
  }
  
  
  
  @Override
  protected void onStart() {
    super.onStart();
      setPullToRefresh();
      initializeRssDownload();
  }



  private void initializeViews() {
    listOverlayLayoutView = new ListOverlayLayoutView(
        (FrameLayout) findViewById(R.id.list_overlay_layout),
        this);
    mPullToRefreshLayout = (PullToRefreshLayout) findViewById(R.id.ptr_layout);
    rssItemsListView = (ListView) findViewById(R.id.main_list_view);
    
    
    rssItemsListView.setVisibility(View.INVISIBLE);
    rssItemsListView.setOnItemClickListener(this);
    listOverlayLayoutView.showLoadingView();
  }
  
  private void setPullToRefresh() {
    // Now setup the PullToRefreshLayout
      ActionBarPullToRefresh.from(this)
              .theseChildrenArePullable(rssItemsListView)
              .listener(this)
              .setup(mPullToRefreshLayout);
  }
  
  private void initializeRssDownload() {
    getRssItems = new GetRssItems(this, this);
    getRssItems.getNewRssItems();
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
  }

  @Override
  public void onRetryClick() {
    listOverlayLayoutView.showLoadingView();
    listOverlayLayoutView.hideOnConnectionErrorViews();
    initializeRssDownload();
  }

  @Override
  public void onRefreshStarted(View view) {
    initializeRssDownload();
  }

  @Override
  public void onItemsDownloaded(List<RssItem> rssItemList) {
    if(mPullToRefreshLayout.isRefreshing())
      mPullToRefreshLayout.setRefreshComplete();
    
    listOverlayLayoutView.hideOverlayView();
    rssItemsAdapter = new RssItemsAdapter(this, rssItemList);
    rssItemsListView.setAdapter(rssItemsAdapter);
    rssItemsListView.setVisibility(View.VISIBLE);
  }

  @Override
  public void onConnectionError() {
    listOverlayLayoutView.showOnConnectionErrorViews();
  }

  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    RssItem selectedItem = (RssItem) rssItemsAdapter.getItem(position);
    Intent detailsIntent = new Intent(this, RssItemDetailsActivity.class);
    detailsIntent.putExtra("RssItem", selectedItem);
    
    startActivity(detailsIntent);
  }

}




Java Source Code List

com.vicmns.rssreader.activities.MainActivity.java
com.vicmns.rssreader.activities.RssItemDetailsActivity.java
com.vicmns.rssreader.adapters.RssItemsAdapter.java
com.vicmns.rssreader.app.RssReaderApplication.java
com.vicmns.rssreader.http.GetRssItems.java
com.vicmns.rssreader.http.GetWidgetRssItems.java
com.vicmns.rssreader.http.SimpleXmlRequest.java
com.vicmns.rssreader.interfaces.GetRssItemsCallbacks.java
com.vicmns.rssreader.interfaces.HttpConsumerCallbacks.java
com.vicmns.rssreader.interfaces.ListOverlayLayoutCallbacks.java
com.vicmns.rssreader.models.RssItem.java
com.vicmns.rssreader.models.RssItems.java
com.vicmns.rssreader.services.GetRssItemsService.java
com.vicmns.rssreader.views.ListOverlayLayoutView.java
com.vicmns.rssreader.views.SquareImageView.java
com.vicmns.rssreader.widget.WidgetListProvider.java
com.vicmns.rssreader.widget.WidgetProvider.java
com.vicmns.rssreader.widget.WidgetService.java
fr.castorflex.android.smoothprogressbar.ColorsShape.java
fr.castorflex.android.smoothprogressbar.ContentLoadingSmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.SmoothProgressBarUtils.java
fr.castorflex.android.smoothprogressbar.SmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.SmoothProgressDrawable.java
org.robolectric.shadows.ShadowSupportMenuInflater.java