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.provider.MediaStore;
20 import android.support.v4.app.FragmentManager;
22 import android.view.MenuItem;
23 import org.lineageos.eleven.Config;
24 import org.lineageos.eleven.cache.ImageFetcher;
25 import org.lineageos.eleven.menu.DeleteDialog;
26 import org.lineageos.eleven.menu.FragmentMenuItems;
27 import org.lineageos.eleven.menu.PhotoSelectionDialog;
28 import org.lineageos.eleven.model.Album;
30 import java.util.TreeSet;
32 public abstract class AlbumPopupMenuHelper extends PopupMenuHelper {
33 protected Album mAlbum;
35 public AlbumPopupMenuHelper(Activity activity, FragmentManager fragmentManager) {
36 super(activity, fragmentManager);
37 mType = PopupMenuType.Album;
40 public abstract Album getAlbum(int position);
43 public PopupMenuType onPreparePopupMenu(int position) {
44 mAlbum = getAlbum(position);
50 return PopupMenuType.Album;
54 protected long[] getIdList() {
55 return MusicUtils.getSongListForAlbum(mActivity, mAlbum.mAlbumId);
59 protected long getSourceId() {
60 return mAlbum.mAlbumId;
64 protected Config.IdType getSourceType() {
65 return Config.IdType.Album;
69 protected void onDeleteClicked() {
70 final String album = mAlbum.mAlbumName;
71 DeleteDialog.newInstance(album, getIdList(),
72 ImageFetcher.generateAlbumCacheKey(album, mAlbum.mArtistName))
73 .show(mFragmentManager, "DeleteDialog");
77 protected String getArtistName() {
78 return mAlbum.mArtistName;
82 public boolean onMenuItemClick(MenuItem item) {
83 boolean handled = super.onMenuItemClick(item);
84 if (!handled && item.getGroupId() == getGroupId()) {
85 switch (item.getItemId()) {
86 case FragmentMenuItems.CHANGE_IMAGE:
87 String key = ImageFetcher.generateAlbumCacheKey(mAlbum.mAlbumName,
89 PhotoSelectionDialog.newInstance(mAlbum.mAlbumName,
90 PhotoSelectionDialog.ProfileType.ALBUM, key)
91 .show(mFragmentManager, "PhotoSelectionDialog");
100 protected void updateMenuIds(PopupMenuType type, TreeSet<Integer> set) {
101 super.updateMenuIds(type, set);
103 // Don't show more by artist if it is an unknown artist
104 if (MediaStore.UNKNOWN_STRING.equals(mAlbum.mArtistName)) {
105 set.remove(FragmentMenuItems.MORE_BY_ARTIST);