OSDN Git Service

17fc4d5a2bfc679eb9737ac3ed1f27e46984e0af
[android-x86/packages-apps-Eleven.git] / src / com / cyanogenmod / eleven / utils / SongPopupMenuHelper.java
1 /*
2 * Copyright (C) 2014 The CyanogenMod Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package com.cyanogenmod.eleven.utils;
17
18
19 import android.app.Activity;
20 import android.provider.MediaStore;
21 import android.support.v4.app.FragmentManager;
22
23 import com.cyanogenmod.eleven.menu.DeleteDialog;
24 import com.cyanogenmod.eleven.menu.FragmentMenuItems;
25 import com.cyanogenmod.eleven.model.Song;
26
27 import java.util.TreeSet;
28
29 public abstract class SongPopupMenuHelper extends PopupMenuHelper {
30     protected Song mSong;
31
32     public SongPopupMenuHelper(Activity activity, FragmentManager fragmentManager) {
33         super(activity, fragmentManager);
34     }
35
36     public abstract Song getSong(int position);
37
38     @Override
39     public PopupMenuHelper.PopupMenuType onPreparePopupMenu(int position) {
40         mSong = getSong(position);
41
42         if (mSong == null) {
43             return null;
44         }
45
46         return PopupMenuType.Song;
47     }
48
49     @Override
50     protected void playAlbum() {
51         MusicUtils.playAlbum(mActivity, mSong.mAlbumId, 0, false);
52     }
53
54     @Override
55     protected long[] getIdList() {
56         return new long[] { mSong.mSongId };
57     }
58
59     @Override
60     protected String getArtistName() {
61         return mSong.mArtistName;
62     }
63
64     @Override
65     protected void onDeleteClicked() {
66         DeleteDialog.newInstance(mSong.mSongName, getIdList(), null)
67                 .show(mFragmentManager, "DeleteDialog");
68     }
69
70     @Override
71     protected void updateMenuIds(PopupMenuType type, TreeSet<Integer> set) {
72         super.updateMenuIds(type, set);
73
74         // Don't show more by artist if it is an unknown artist
75         if (MediaStore.UNKNOWN_STRING.equals(mSong.mArtistName)) {
76             set.remove(FragmentMenuItems.MORE_BY_ARTIST);
77         }
78     }
79 }