OSDN Git Service

35f70ff97d251151997f0156b195d5fc4082a8f3
[android-x86/packages-apps-Eleven.git] / src / com / cyanogenmod / eleven / ui / fragments / RecentFragment.java
1 /*
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.
12  */
13
14 package com.cyanogenmod.eleven.ui.fragments;
15
16 import android.app.Activity;
17 import android.os.Bundle;
18 import android.support.v4.content.Loader;
19
20 import com.cyanogenmod.eleven.Config;
21 import com.cyanogenmod.eleven.Config.SmartPlaylistType;
22 import com.cyanogenmod.eleven.R;
23 import com.cyanogenmod.eleven.adapters.SongAdapter;
24 import com.cyanogenmod.eleven.loaders.TopTracksLoader;
25 import com.cyanogenmod.eleven.menu.FragmentMenuItems;
26 import com.cyanogenmod.eleven.model.Song;
27 import com.cyanogenmod.eleven.sectionadapter.SectionCreator;
28 import com.cyanogenmod.eleven.sectionadapter.SectionListContainer;
29 import com.cyanogenmod.eleven.ui.activities.BaseActivity;
30 import com.cyanogenmod.eleven.ui.fragments.profile.SmartPlaylistFragment;
31 import com.cyanogenmod.eleven.utils.MusicUtils;
32 import com.cyanogenmod.eleven.widgets.NoResultsContainer;
33
34 import java.util.TreeSet;
35
36 /**
37  * This class is used to display all of the recently listened to songs by the
38  * user.
39  *
40  * @author Andrew Neal (andrewdneal@gmail.com)
41  */
42 public class RecentFragment extends SmartPlaylistFragment implements ISetupActionBar {
43
44     @Override
45     protected SmartPlaylistType getSmartPlaylistType() {
46         return Config.SmartPlaylistType.RecentlyPlayed;
47     }
48
49     @Override
50     protected void updateMenuIds(TreeSet<Integer> set) {
51         set.add(FragmentMenuItems.REMOVE_FROM_RECENT);
52     }
53
54     /**
55      * {@inheritDoc}
56      */
57     @Override
58     public Loader<SectionListContainer<Song>> onCreateLoader(final int id, final Bundle args) {
59         // show the loading progress bar
60         mLoadingEmptyContainer.showLoading();
61
62         TopTracksLoader loader = new TopTracksLoader(getActivity(),
63                 TopTracksLoader.QueryType.RecentSongs);
64         return new SectionCreator<Song>(getActivity(), loader, null);
65     }
66
67     /**
68      * {@inheritDoc}
69      */
70     @Override
71     public void onMetaChanged() {
72         super.onMetaChanged();
73
74         // refresh the list since a track playing means it should be recently played
75         restartLoader();
76     }
77
78     @Override
79     public void setupNoResultsContainer(NoResultsContainer empty) {
80         super.setupNoResultsContainer(empty);
81
82         empty.setMainText(R.string.empty_recent_main);
83         empty.setSecondaryText(R.string.empty_recent);
84     }
85
86     @Override
87     public void setupActionBar() {
88         ((BaseActivity)getActivity()).setupActionBar(R.string.playlist_recently_played);
89     }
90
91     @Override
92     protected long getFragmentSourceId() {
93         return Config.SmartPlaylistType.RecentlyPlayed.mId;
94     }
95
96     @Override
97     protected SongAdapter createAdapter() {
98         return new RecentAdapter(
99             getActivity(),
100             R.layout.list_item_normal,
101             getFragmentSourceId(),
102             getFragmentSourceType()
103         );
104     }
105
106     private class RecentAdapter extends SongAdapter {
107         public RecentAdapter(Activity context, int layoutId, long sourceId, Config.IdType sourceType) {
108             super(context, layoutId, sourceId, sourceType);
109         }
110
111         @Override
112         protected boolean showNowPlayingIndicator(Song song, int position) {
113             return position == 0 && super.showNowPlayingIndicator(song, position);
114         }
115     }
116
117     @Override
118     protected int getShuffleTitleId() { return R.string.menu_shuffle_recent; }
119
120     @Override
121     protected int getClearTitleId() { return R.string.clear_recent_title; }
122
123     @Override
124     protected void clearList() { MusicUtils.clearRecent(getActivity()); }
125 }