OSDN Git Service

301acff11bf095bb946b300baa474f108f3dfa71
[android-x86/packages-apps-Eleven.git] / src / org / lineageos / eleven / utils / ArtistPopupMenuHelper.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 org.lineageos.eleven.utils;
17
18 import android.app.Activity;
19 import android.support.v4.app.FragmentManager;
20
21 import android.view.MenuItem;
22 import org.lineageos.eleven.Config;
23 import org.lineageos.eleven.menu.DeleteDialog;
24 import org.lineageos.eleven.menu.FragmentMenuItems;
25 import org.lineageos.eleven.menu.PhotoSelectionDialog;
26 import org.lineageos.eleven.model.Artist;
27
28 public abstract class ArtistPopupMenuHelper extends PopupMenuHelper {
29     private Artist mArtist;
30
31     public ArtistPopupMenuHelper(Activity activity, FragmentManager fragmentManager) {
32         super(activity, fragmentManager);
33         mType = PopupMenuType.Artist;
34     }
35
36     public abstract Artist getArtist(int position);
37
38     @Override
39     public PopupMenuType onPreparePopupMenu(int position) {
40         mArtist = getArtist(position);
41         return mArtist == null ? null : PopupMenuType.Artist;
42     }
43
44     @Override
45     protected long getSourceId() {
46         return mArtist.mArtistId;
47     }
48
49     @Override
50     protected Config.IdType getSourceType() {
51         return Config.IdType.Artist;
52     }
53
54     @Override
55     protected long[] getIdList() {
56         return MusicUtils.getSongListForArtist(mActivity, mArtist.mArtistId);
57     }
58
59     @Override
60     protected void onDeleteClicked() {
61         final String artist = mArtist.mArtistName;
62         DeleteDialog.newInstance(artist, getIdList(), artist)
63             .show(mFragmentManager, "DeleteDialog");
64     }
65
66     @Override
67     protected String getArtistName() {
68         return mArtist.mArtistName;
69     }
70
71     @Override
72     public boolean onMenuItemClick(MenuItem item) {
73         boolean handled = super.onMenuItemClick(item);
74         if (!handled && item.getGroupId() == getGroupId()) {
75             switch (item.getItemId()) {
76                 case FragmentMenuItems.CHANGE_IMAGE:
77                     PhotoSelectionDialog.newInstance(getArtistName(),
78                             PhotoSelectionDialog.ProfileType.ARTIST, getArtistName())
79                             .show(mFragmentManager, "PhotoSelectionDialog");
80                     return true;
81             }
82         }
83
84         return handled;
85     }
86 }