Android Open Source - lastfm-android-music-discovery Artist Albums Fragment






From Project

Back to project page lastfm-android-music-discovery.

License

The source code is released under:

Apache License

If you think the Android project lastfm-android-music-discovery 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.mikeladze.musicdiscovery.artist.fragment;
// w  w  w  . jav a  2 s  .  c o m
import org.json.JSONArray;
import org.json.JSONException;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.mikeladze.musicdiscovery.album.activity.AlbumActivity;
import com.mikeladze.musicdiscovery.base.fragment.ImageGridViewFragment;
import com.mikeladze.musicdiscovery.http.LastFMResult;
import com.origamilabs.library.views.StaggeredGridView;

/**
 * Displays the albums under a particular artist.
 * 
 * @author Tim Mikeladze
 */
public class ArtistAlbumsFragment extends ImageGridViewFragment {
  
  private static final String TITLE = "Albums";
  
  @Override
  /**
   * Creates the view
   */
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return super.onCreateView(inflater, container, savedInstanceState);
  }
  
  @Override
  public String getTitle() {
    return TITLE;
  }
  
  /**
   * Display albums.
   * 
   * @param albums the albums
   */
  public void displayAlbums(JSONArray albums) {
    try {
      for (int i = 0; i < albums.length(); i++) {
        String image;
        image = albums.getJSONObject(i)
                .getJSONArray("image")
                .getJSONObject(3)
                .getString("#text");
        
        String title = albums.getJSONObject(i)
                    .getString("name");
        String mbid = albums.getJSONObject(i)
                  .getString("mbid");
        String artist = albums.getJSONObject(i)
                    .getJSONObject("artist")
                    .getString("name");
        gridAdapter.add(new LastFMResult(image, title, artist, mbid));
      }
      gridAdapter.notifyDataSetChanged();
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
  
  @Override
  /**
   * Handles click events to an album. Opens AlbumActivity for corresponding album. 
   */
  public void onItemClick(StaggeredGridView parent, View view, int position, long id) {
    Intent intent = new Intent(getActivity(), AlbumActivity.class);
    Bundle b = new Bundle();
    b.putString("mbid", gridAdapter.getItem(position)
                    .getMBID());
    b.putString("name", gridAdapter.getItem(position)
                    .getTitle());
    b.putString("artist", gridAdapter.getItem(position)
                      .getArtist());
    intent.putExtras(b);
    startActivity(intent);
  }
}




Java Source Code List

com.mikeladze.musicdiscovery.album.activity.AlbumActivity.java
com.mikeladze.musicdiscovery.album.adapter.LastFMTrack.java
com.mikeladze.musicdiscovery.album.adapter.OnTrackClickListener.java
com.mikeladze.musicdiscovery.album.adapter.TrackListAdapter.java
com.mikeladze.musicdiscovery.album.fragment.AlbumInfoFragment.java
com.mikeladze.musicdiscovery.album.fragment.AlbumTracksFragment.java
com.mikeladze.musicdiscovery.artist.activity.ArtistActivity.java
com.mikeladze.musicdiscovery.artist.fragment.ArtistAlbumsFragment.java
com.mikeladze.musicdiscovery.artist.fragment.ArtistInfoFragment.java
com.mikeladze.musicdiscovery.artist.fragment.SimilarArtistsFragment.java
com.mikeladze.musicdiscovery.base.activity.BaseFragmentActivity.java
com.mikeladze.musicdiscovery.base.adapter.SectionsPagerAdapter.java
com.mikeladze.musicdiscovery.base.fragment.BaseTabFragment.java
com.mikeladze.musicdiscovery.base.fragment.ImageGridViewFragment.java
com.mikeladze.musicdiscovery.http.LastFMResult.java
com.mikeladze.musicdiscovery.http.RestClient.java
com.mikeladze.musicdiscovery.main.activity.MainActivity.java
com.mikeladze.musicdiscovery.main.fragment.HypedArtistsFragment.java
com.mikeladze.musicdiscovery.main.fragment.TopArtistsFragment.java
com.mikeladze.musicdiscovery.search.activity.SearchResultsActivity.java
com.mikeladze.musicdiscovery.search.adapter.SearchResultsAdapter.java
com.mikeladze.musicdiscovery.util.IntentUtils.java
com.mikeladze.musicdiscovery.view.gridview.DynamicImageView.java
com.mikeladze.musicdiscovery.view.gridview.ImageGridAdapter.java
com.mikeladze.musicdiscovery.view.gridview.loader.FileCache.java
com.mikeladze.musicdiscovery.view.gridview.loader.ImageLoader.java
com.mikeladze.musicdiscovery.view.gridview.loader.MemoryCache.java
com.mikeladze.musicdiscovery.view.gridview.loader.Utils.java