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;
14 import android.os.Bundle;
15 import android.support.v4.content.Loader;
17 import com.cyngn.eleven.Config;
18 import com.cyngn.eleven.R;
19 import com.cyngn.eleven.loaders.TopTracksLoader;
20 import com.cyngn.eleven.menu.FragmentMenuItems;
21 import com.cyngn.eleven.model.Song;
22 import com.cyngn.eleven.sectionadapter.SectionCreator;
23 import com.cyngn.eleven.sectionadapter.SectionListContainer;
24 import com.cyngn.eleven.ui.activities.BaseActivity;
25 import com.cyngn.eleven.ui.fragments.profile.BasicSongFragment;
26 import com.cyngn.eleven.utils.MusicUtils;
27 import com.cyngn.eleven.widgets.NoResultsContainer;
29 import java.util.TreeSet;
32 * This class is used to display all of the recently listened to songs by the
35 * @author Andrew Neal (andrewdneal@gmail.com)
37 public class RecentFragment extends BasicSongFragment implements ISetupActionBar {
40 * LoaderCallbacks identifier
42 private static final int LOADER = 0;
45 protected void updateMenuIds(TreeSet<Integer> set) {
46 set.add(FragmentMenuItems.REMOVE_FROM_RECENT);
53 public Loader<SectionListContainer<Song>> onCreateLoader(final int id, final Bundle args) {
54 TopTracksLoader loader = new TopTracksLoader(getActivity(),
55 TopTracksLoader.QueryType.RecentSongs);
56 return new SectionCreator<Song>(getActivity(), loader, null);
63 public void onMetaChanged() {
64 // refresh the list since a track playing means it should be recently played
65 getLoaderManager().restartLoader(LOADER, null, this);
69 public int getLoaderId() {
74 public void playAll(int position) {
75 MusicUtils.playSmartPlaylist(getActivity(), position,
76 Config.SmartPlaylistType.RecentlyPlayed);
80 public void setupNoResultsContainer(NoResultsContainer empty) {
81 super.setupNoResultsContainer(empty);
83 empty.setMainText(R.string.empty_recent_main);
84 empty.setSecondaryText(R.string.empty_recent);
88 public void setupActionBar() {
89 ((BaseActivity)getActivity()).setupActionBar(R.string.playlist_recently_played);