OSDN Git Service

Eleven: Add Top Tracks smart playlist and rework some look and feel
[android-x86/packages-apps-Eleven.git] / src / com / cyngn / eleven / ui / fragments / profile / TopTracksFragment.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.profile;
13
14 import android.app.Activity;
15 import android.database.Cursor;
16 import android.os.Bundle;
17 import android.support.v4.content.Loader;
18 import android.view.View;
19 import android.view.ViewGroup;
20 import android.widget.TextView;
21
22 import com.cyngn.eleven.R;
23 import com.cyngn.eleven.adapters.SongAdapter;
24 import com.cyngn.eleven.loaders.TopTracksLoader;
25 import com.cyngn.eleven.model.Song;
26 import com.cyngn.eleven.utils.MusicUtils;
27
28 import java.util.List;
29
30 /**
31  * This class is used to display all of the songs the user put on their device
32  * within the last four weeks.
33  *
34  * @author Andrew Neal (andrewdneal@gmail.com)
35  */
36 public class TopTracksFragment extends BasicSongFragment {
37
38     /**
39      * Used to keep context menu items from bleeding into other fragments
40      */
41     private static final int GROUP_ID = 6;
42
43     /**
44      * LoaderCallbacks identifier
45      */
46     private static final int LOADER = 0;
47
48     /**
49      * {@inheritDoc}
50      */
51     @Override
52     public Loader<List<Song>> onCreateLoader(final int id, final Bundle args) {
53         return new TopTracksLoader(getActivity());
54     }
55
56     @Override
57     protected SongAdapter createAdapter() {
58         return new TopTracksAdapter(
59                 getActivity(),
60                 R.layout.list_item_top_tracks
61         );
62     }
63
64     @Override
65     public int getGroupId() {
66         return GROUP_ID;
67     }
68
69     @Override
70     public int getLoaderId() {
71         return LOADER;
72     }
73
74     @Override
75     public void playAll(int position) {
76         Cursor cursor = TopTracksLoader.makeTopTracksCursor(getActivity());
77         final long[] list = MusicUtils.getSongListForCursor(cursor);
78         MusicUtils.playAll(getActivity(), list, position, false);
79         cursor.close();
80         cursor = null;
81     }
82
83     public class TopTracksAdapter extends SongAdapter {
84         public TopTracksAdapter (final Activity context, final int layoutId) {
85             super(context, layoutId);
86         }
87
88         @Override
89         public View getView(int position, View convertView, ViewGroup parent) {
90             View view = super.getView(position, convertView, parent);
91             TextView positionText = (TextView) view.findViewById(R.id.position_number);
92             positionText.setText(String.valueOf(position + 1));
93             return view;
94         }
95     }
96 }