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;
19 import android.view.LayoutInflater;
20 import android.view.View;
21 import android.view.ViewGroup;
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.menu.FragmentMenuItems;
29 import com.cyanogenmod.eleven.model.Song;
30 import com.cyanogenmod.eleven.sectionadapter.SectionCreator;
31 import com.cyanogenmod.eleven.sectionadapter.SectionListContainer;
32 import com.cyanogenmod.eleven.ui.activities.BaseActivity;
33 import com.cyanogenmod.eleven.ui.fragments.profile.SmartPlaylistFragment;
34 import com.cyanogenmod.eleven.utils.MusicUtils;
35 import com.cyanogenmod.eleven.widgets.NoResultsContainer;
37 import java.util.TreeSet;
40 * This class is used to display all of the recently listened to songs by the
43 * @author Andrew Neal (andrewdneal@gmail.com)
45 public class RecentFragment extends SmartPlaylistFragment implements ISetupActionBar {
48 protected SmartPlaylistType getSmartPlaylistType() {
49 return Config.SmartPlaylistType.RecentlyPlayed;
53 protected void updateMenuIds(TreeSet<Integer> set) {
54 set.add(FragmentMenuItems.REMOVE_FROM_RECENT);
61 public Loader<SectionListContainer<Song>> onCreateLoader(final int id, final Bundle args) {
62 // show the loading progress bar
63 mLoadingEmptyContainer.showLoading();
65 TopTracksLoader loader = new TopTracksLoader(getActivity(),
66 TopTracksLoader.QueryType.RecentSongs);
67 return new SectionCreator<Song>(getActivity(), loader, null);
74 public void onMetaChanged() {
75 super.onMetaChanged();
77 // refresh the list since a track playing means it should be recently played
82 public void setupNoResultsContainer(NoResultsContainer empty) {
83 super.setupNoResultsContainer(empty);
85 empty.setMainText(R.string.empty_recent_main);
86 empty.setSecondaryText(R.string.empty_recent);
90 public final View onCreateView(LayoutInflater inflater, ViewGroup container,
91 Bundle savedInstanceState) {
93 return super.onCreateView(inflater, container, savedInstanceState);
97 public void setupActionBar() {
98 ((BaseActivity)getActivity()).setupActionBar(R.string.playlist_recently_played);
99 ((BaseActivity)getActivity()).setActionBarElevation(true);
103 protected long getFragmentSourceId() {
104 return Config.SmartPlaylistType.RecentlyPlayed.mId;
108 protected SongAdapter createAdapter() {
109 return new RecentAdapter(
111 R.layout.list_item_normal,
112 getFragmentSourceId(),
113 getFragmentSourceType()
117 private class RecentAdapter extends SongAdapter {
118 public RecentAdapter(Activity context, int layoutId, long sourceId, Config.IdType sourceType) {
119 super(context, layoutId, sourceId, sourceType);
123 protected boolean showNowPlayingIndicator(Song song, int position) {
124 return position == 0 && super.showNowPlayingIndicator(song, position);
129 protected int getShuffleTitleId() { return R.string.menu_shuffle_recent; }
132 protected int getClearTitleId() { return R.string.clear_recent_title; }
135 protected void clearList() { MusicUtils.clearRecent(getActivity()); }