2 * Copyright (C) 2014 The CyanogenMod Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.lineageos.eleven.utils;
18 import android.app.Activity;
19 import android.support.v4.app.FragmentManager;
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;
28 public abstract class ArtistPopupMenuHelper extends PopupMenuHelper {
29 private Artist mArtist;
31 public ArtistPopupMenuHelper(Activity activity, FragmentManager fragmentManager) {
32 super(activity, fragmentManager);
33 mType = PopupMenuType.Artist;
36 public abstract Artist getArtist(int position);
39 public PopupMenuType onPreparePopupMenu(int position) {
40 mArtist = getArtist(position);
41 return mArtist == null ? null : PopupMenuType.Artist;
45 protected long getSourceId() {
46 return mArtist.mArtistId;
50 protected Config.IdType getSourceType() {
51 return Config.IdType.Artist;
55 protected long[] getIdList() {
56 return MusicUtils.getSongListForArtist(mActivity, mArtist.mArtistId);
60 protected void onDeleteClicked() {
61 final String artist = mArtist.mArtistName;
62 DeleteDialog.newInstance(artist, getIdList(), artist)
63 .show(mFragmentManager, "DeleteDialog");
67 protected String getArtistName() {
68 return mArtist.mArtistName;
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");