2 * Copyright (C) 2012 Andrew Neal
3 * Copyright (C) 2014 The CyanogenMod Project
4 * Licensed under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with the
6 * License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
8 * or agreed to in writing, software distributed under the License is
9 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
10 * KIND, either express or implied. See the License for the specific language
11 * governing permissions and limitations under the License.
14 package com.cyanogenmod.eleven.ui.fragments.profile;
16 import android.app.Activity;
17 import android.os.Bundle;
18 import android.support.v4.content.Loader;
19 import android.view.View;
20 import android.view.ViewGroup;
21 import android.widget.TextView;
23 import com.cyanogenmod.eleven.Config;
24 import com.cyanogenmod.eleven.Config.SmartPlaylistType;
25 import com.cyanogenmod.eleven.R;
26 import com.cyanogenmod.eleven.adapters.SongAdapter;
27 import com.cyanogenmod.eleven.loaders.TopTracksLoader;
28 import com.cyanogenmod.eleven.model.Song;
29 import com.cyanogenmod.eleven.sectionadapter.SectionCreator;
30 import com.cyanogenmod.eleven.sectionadapter.SectionListContainer;
31 import com.cyanogenmod.eleven.ui.activities.BaseActivity;
32 import com.cyanogenmod.eleven.ui.fragments.ISetupActionBar;
33 import com.cyanogenmod.eleven.utils.MusicUtils;
34 import com.cyanogenmod.eleven.widgets.NoResultsContainer;
37 * This class is used to display all of the songs the user put on their device
38 * within the last four weeks.
40 * @author Andrew Neal (andrewdneal@gmail.com)
42 public class TopTracksFragment extends SmartPlaylistFragment
43 implements ISetupActionBar {
46 protected SmartPlaylistType getSmartPlaylistType() {
47 return Config.SmartPlaylistType.TopTracks;
54 public Loader<SectionListContainer<Song>> onCreateLoader(final int id, final Bundle args) {
55 // show the loading progress bar
56 mLoadingEmptyContainer.showLoading();
58 TopTracksLoader loader = new TopTracksLoader(getActivity(),
59 TopTracksLoader.QueryType.TopTracks);
60 return new SectionCreator<Song>(getActivity(), loader, null);
64 protected SongAdapter createAdapter() {
65 return new TopTracksAdapter(
67 R.layout.list_item_top_tracks
72 public void setupActionBar() {
73 ((BaseActivity)getActivity()).setupActionBar(R.string.playlist_top_tracks);
76 public class TopTracksAdapter extends SongAdapter {
77 public TopTracksAdapter (final Activity context, final int layoutId) {
78 super(context, layoutId, getFragmentSourceId(), getFragmentSourceType());
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);
99 protected long getFragmentSourceId() {
100 return Config.SmartPlaylistType.TopTracks.mId;
103 protected int getShuffleTitleId() { return R.string.menu_shuffle_top_tracks; }
106 protected int getClearTitleId() { return R.string.clear_top_tracks_title; }
109 protected void clearList() { MusicUtils.clearTopTracks(getActivity()); }