OSDN Git Service

1d7131678db8fe227e838481f0d650cc7f75d121
[android-x86/packages-apps-Eleven.git] / src / com / cyanogenmod / eleven / ui / fragments / profile / TopTracksFragment.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.profile;
15
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;
22 import android.widget.TextView;
23
24 import com.cyanogenmod.eleven.Config;
25 import com.cyanogenmod.eleven.Config.SmartPlaylistType;
26 import com.cyanogenmod.eleven.R;
27 import com.cyanogenmod.eleven.adapters.SongAdapter;
28 import com.cyanogenmod.eleven.loaders.TopTracksLoader;
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.ISetupActionBar;
34 import com.cyanogenmod.eleven.utils.MusicUtils;
35 import com.cyanogenmod.eleven.widgets.NoResultsContainer;
36
37 /**
38  * This class is used to display all of the songs the user put on their device
39  * within the last four weeks.
40  *
41  * @author Andrew Neal (andrewdneal@gmail.com)
42  */
43 public class TopTracksFragment extends SmartPlaylistFragment
44 implements ISetupActionBar {
45
46     @Override
47     protected SmartPlaylistType getSmartPlaylistType() {
48         return Config.SmartPlaylistType.TopTracks;
49     }
50
51     /**
52      * {@inheritDoc}
53      */
54     @Override
55     public Loader<SectionListContainer<Song>> onCreateLoader(final int id, final Bundle args) {
56         // show the loading progress bar
57         mLoadingEmptyContainer.showLoading();
58
59         TopTracksLoader loader = new TopTracksLoader(getActivity(),
60                 TopTracksLoader.QueryType.TopTracks);
61         return new SectionCreator<Song>(getActivity(), loader, null);
62     }
63
64     @Override
65     protected SongAdapter createAdapter() {
66         return new TopTracksAdapter(
67             getActivity(),
68             R.layout.list_item_top_tracks
69         );
70     }
71
72     @Override
73     public final View onCreateView(LayoutInflater inflater, ViewGroup container,
74             Bundle savedInstanceState) {
75         setupActionBar();
76         return super.onCreateView(inflater, container, savedInstanceState);
77     }
78
79     public void setupActionBar() {
80         ((BaseActivity)getActivity()).setupActionBar(R.string.playlist_top_tracks);
81         ((BaseActivity)getActivity()).setActionBarElevation(true);
82     }
83
84     public class TopTracksAdapter extends SongAdapter {
85         public TopTracksAdapter (final Activity context, final int layoutId) {
86             super(context, layoutId, getFragmentSourceId(), getFragmentSourceType());
87         }
88
89         @Override
90         public View getView(int position, View convertView, ViewGroup parent) {
91             View view = super.getView(position, convertView, parent);
92             TextView positionText = (TextView) view.findViewById(R.id.position_number);
93             positionText.setText(String.valueOf(position + 1));
94             return view;
95         }
96     }
97
98     @Override
99     public void setupNoResultsContainer(NoResultsContainer empty) {
100         super.setupNoResultsContainer(empty);
101
102         empty.setMainText(R.string.empty_top_tracks_main);
103         empty.setSecondaryText(R.string.empty_top_tracks_secondary);
104     }
105
106     @Override
107     protected long getFragmentSourceId() {
108         return Config.SmartPlaylistType.TopTracks.mId;
109     }
110
111     protected int getShuffleTitleId() { return R.string.menu_shuffle_top_tracks; }
112
113     @Override
114     protected int getClearTitleId() { return R.string.clear_top_tracks_title; }
115
116     @Override
117     protected void clearList() { MusicUtils.clearTopTracks(getActivity()); }
118 }