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;
16 import android.app.Activity;
17 import android.os.Bundle;
18 import android.support.v4.content.Loader;
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;
34 import java.util.TreeSet;
37 * This class is used to display all of the recently listened to songs by the
40 * @author Andrew Neal (andrewdneal@gmail.com)
42 public class RecentFragment extends SmartPlaylistFragment implements ISetupActionBar {
45 protected SmartPlaylistType getSmartPlaylistType() {
46 return Config.SmartPlaylistType.RecentlyPlayed;
50 protected void updateMenuIds(TreeSet<Integer> set) {
51 set.add(FragmentMenuItems.REMOVE_FROM_RECENT);
58 public Loader<SectionListContainer<Song>> onCreateLoader(final int id, final Bundle args) {
59 // show the loading progress bar
60 mLoadingEmptyContainer.showLoading();
62 TopTracksLoader loader = new TopTracksLoader(getActivity(),
63 TopTracksLoader.QueryType.RecentSongs);
64 return new SectionCreator<Song>(getActivity(), loader, null);
71 public void onMetaChanged() {
72 super.onMetaChanged();
74 // refresh the list since a track playing means it should be recently played
79 public void setupNoResultsContainer(NoResultsContainer empty) {
80 super.setupNoResultsContainer(empty);
82 empty.setMainText(R.string.empty_recent_main);
83 empty.setSecondaryText(R.string.empty_recent);
87 public void setupActionBar() {
88 ((BaseActivity)getActivity()).setupActionBar(R.string.playlist_recently_played);
92 protected long getFragmentSourceId() {
93 return Config.SmartPlaylistType.RecentlyPlayed.mId;
97 protected SongAdapter createAdapter() {
98 return new RecentAdapter(
100 R.layout.list_item_normal,
101 getFragmentSourceId(),
102 getFragmentSourceType()
106 private class RecentAdapter extends SongAdapter {
107 public RecentAdapter(Activity context, int layoutId, long sourceId, Config.IdType sourceType) {
108 super(context, layoutId, sourceId, sourceType);
112 protected boolean showNowPlayingIndicator(Song song, int position) {
113 return position == 0 && super.showNowPlayingIndicator(song, position);
118 protected int getShuffleTitleId() { return R.string.menu_shuffle_recent; }
121 protected int getClearTitleId() { return R.string.clear_recent_title; }
124 protected void clearList() { MusicUtils.clearRecent(getActivity()); }