OSDN Git Service

Eleven: Add context menus to all top level fragments and playlists
[android-x86/packages-apps-Eleven.git] / src / com / cyngn / eleven / ui / fragments / RecentFragment.java
1 /*
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.
10  */
11
12 package com.cyngn.eleven.ui.fragments;
13
14 import android.os.Bundle;
15 import android.support.v4.content.Loader;
16 import android.view.Menu;
17
18 import com.cyngn.eleven.Config;
19 import com.cyngn.eleven.MusicStateListener;
20 import com.cyngn.eleven.R;
21 import com.cyngn.eleven.loaders.TopTracksLoader;
22 import com.cyngn.eleven.menu.FragmentMenuItems;
23 import com.cyngn.eleven.model.Song;
24 import com.cyngn.eleven.sectionadapter.SectionCreator;
25 import com.cyngn.eleven.sectionadapter.SectionListContainer;
26 import com.cyngn.eleven.ui.fragments.profile.BasicSongFragment;
27 import com.cyngn.eleven.utils.MusicUtils;
28 import com.cyngn.eleven.widgets.NoResultsContainer;
29
30 import java.util.ArrayList;
31
32 /**
33  * This class is used to display all of the recently listened to songs by the
34  * user.
35  *
36  * @author Andrew Neal (andrewdneal@gmail.com)
37  */
38 public class RecentFragment extends BasicSongFragment implements MusicStateListener {
39
40     /**
41      * Used to keep context menu items from bleeding into other fragments
42      */
43     private static final int GROUP_ID = 1;
44
45     /**
46      * LoaderCallbacks identifier
47      */
48     private static final int LOADER = 0;
49
50     @Override
51     protected void getAdditionaIdsForType(ArrayList<Integer> list) {
52         list.add(FragmentMenuItems.REMOVE_FROM_RECENT);
53     }
54
55     /**
56      * {@inheritDoc}
57      */
58     @Override
59     public Loader<SectionListContainer<Song>> onCreateLoader(final int id, final Bundle args) {
60         TopTracksLoader loader = new TopTracksLoader(getActivity(),
61                 TopTracksLoader.QueryType.RecentSongs);
62         return new SectionCreator<Song>(getActivity(), loader, null);
63     }
64
65     /**
66      * {@inheritDoc}
67      */
68     @Override
69     public void onMetaChanged() {
70         // refresh the list since a track playing means it should be recently played
71         getLoaderManager().restartLoader(LOADER, null, this);
72     }
73
74     @Override
75     public int getGroupId() {
76         return GROUP_ID;
77     }
78
79     @Override
80     public int getLoaderId() {
81         return LOADER;
82     }
83
84     @Override
85     public void playAll(int position) {
86         MusicUtils.playSmartPlaylist(getActivity(), position,
87                 Config.SmartPlaylistType.RecentlyPlayed);
88     }
89
90     @Override
91     public void setupNoResultsContainer(NoResultsContainer empty) {
92         super.setupNoResultsContainer(empty);
93
94         empty.setMainText(R.string.empty_recent_main);
95         empty.setSecondaryText(R.string.empty_recent);
96     }
97 }
98