2 * Copyright (C) 2012 Andrew Neal Licensed under the Apache License, Version 2.0
3 * (the "License"); you may not use this file except in compliance with the
4 * License. You may obtain a copy of the License at
5 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
6 * or agreed to in writing, software distributed under the License is
7 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 * KIND, either express or implied. See the License for the specific language
9 * governing permissions and limitations under the License.
12 package com.cyngn.eleven.ui.fragments.profile;
14 import android.app.Activity;
15 import android.os.Bundle;
16 import android.support.v4.content.Loader;
17 import android.view.View;
18 import android.view.ViewGroup;
19 import android.widget.TextView;
21 import com.cyngn.eleven.Config;
22 import com.cyngn.eleven.R;
23 import com.cyngn.eleven.adapters.SongAdapter;
24 import com.cyngn.eleven.loaders.TopTracksLoader;
25 import com.cyngn.eleven.model.Song;
26 import com.cyngn.eleven.sectionadapter.SectionAdapter;
27 import com.cyngn.eleven.sectionadapter.SectionCreator;
28 import com.cyngn.eleven.sectionadapter.SectionListContainer;
29 import com.cyngn.eleven.utils.MusicUtils;
30 import com.cyngn.eleven.widgets.NoResultsContainer;
33 * This class is used to display all of the songs the user put on their device
34 * within the last four weeks.
36 * @author Andrew Neal (andrewdneal@gmail.com)
38 public class TopTracksFragment extends BasicSongFragment {
41 * LoaderCallbacks identifier
43 private static final int LOADER = 0;
49 public Loader<SectionListContainer<Song>> onCreateLoader(final int id, final Bundle args) {
50 TopTracksLoader loader = new TopTracksLoader(getActivity(),
51 TopTracksLoader.QueryType.TopTracks);
52 return new SectionCreator<Song>(getActivity(), loader, null);
56 protected SectionAdapter<Song, SongAdapter> createAdapter() {
57 return new SectionAdapter(getActivity(),
60 R.layout.list_item_top_tracks
66 public int getLoaderId() {
71 public void playAll(int position) {
72 MusicUtils.playSmartPlaylist(getActivity(), position,
73 Config.SmartPlaylistType.TopTracks);
76 public class TopTracksAdapter extends SongAdapter {
77 public TopTracksAdapter (final Activity context, final int layoutId) {
78 super(context, layoutId);
82 public View getView(int position, View convertView, ViewGroup parent) {
83 View view = super.getView(position, convertView, parent);
84 TextView positionText = (TextView) view.findViewById(R.id.position_number);
85 positionText.setText(String.valueOf(position + 1));
91 public void setupNoResultsContainer(NoResultsContainer empty) {
92 super.setupNoResultsContainer(empty);
94 empty.setMainText(R.string.empty_top_tracks_main);
95 empty.setSecondaryText(R.string.empty_top_tracks_secondary);