2 * Copyright (C) 2012 Andrew Neal
3 * Copyright (C) 2014 The CyanogenMod Project
4 * Licensed under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with the
6 * License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
8 * or agreed to in writing, software distributed under the License is
9 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
10 * KIND, either express or implied. See the License for the specific language
11 * governing permissions and limitations under the License.
14 package org.lineageos.eleven.menu;
16 import android.app.AlertDialog;
17 import android.app.Dialog;
18 import android.content.DialogInterface;
19 import android.os.Bundle;
20 import android.support.v4.app.DialogFragment;
21 import android.widget.ArrayAdapter;
22 import android.widget.ListAdapter;
24 import org.lineageos.eleven.Config;
25 import org.lineageos.eleven.R;
26 import org.lineageos.eleven.ui.activities.HomeActivity;
27 import org.lineageos.eleven.utils.Lists;
28 import org.lineageos.eleven.utils.MusicUtils;
30 import java.util.ArrayList;
33 * Used when the user requests to modify Album art or Artist image
34 * It provides an easy interface for them to choose a new image, use the old
35 * image, or search Google for one.
37 * @author Andrew Neal (andrewdneal@gmail.com)
39 public class PhotoSelectionDialog extends DialogFragment {
41 private static final int NEW_PHOTO = 0;
43 private static final int OLD_PHOTO = 1;
45 private final ArrayList<String> mChoices = Lists.newArrayList();
47 private static ProfileType mProfileType;
52 * Empty constructor as per the {@link Fragment} documentation
54 public PhotoSelectionDialog() {
58 * @param title The dialog title.
59 * @param type Either Artist or Album
60 * @param key key to query ImageFetcher
61 * @return A new instance of the dialog.
63 public static PhotoSelectionDialog newInstance(final String title, final ProfileType type,
65 final PhotoSelectionDialog frag = new PhotoSelectionDialog();
66 final Bundle args = new Bundle();
67 args.putString(Config.NAME, title);
68 frag.setArguments(args);
78 public Dialog onCreateDialog(final Bundle savedInstanceState) {
79 final String title = getArguments().getString(Config.NAME);
80 switch (mProfileType) {
93 // Dialog item Adapter
94 final HomeActivity activity = (HomeActivity) getActivity();
95 final ListAdapter adapter = new ArrayAdapter<>(activity,
96 android.R.layout.select_dialog_item, mChoices);
97 return new AlertDialog.Builder(activity).setTitle(title)
98 .setAdapter(adapter, new DialogInterface.OnClickListener() {
101 public void onClick(final DialogInterface dialog, final int which) {
104 activity.selectNewPhoto(mKey);
107 MusicUtils.selectOldPhoto(activity, mKey);
117 * Adds the choices for the artist profile image.
119 private void setArtistChoices() {
120 // Select a photo from the gallery
121 mChoices.add(NEW_PHOTO, getString(R.string.new_photo));
122 /* Disable fetching image until we find a last.fm replacement
123 if (ElevenUtils.isOnline(getActivity())) {
124 // Option to fetch the old artist image
125 mChoices.add(OLD_PHOTO, getString(R.string.context_menu_fetch_artist_image));
130 * Adds the choices for the album profile image.
132 private void setAlbumChoices() {
133 // Select a photo from the gallery
134 mChoices.add(NEW_PHOTO, getString(R.string.new_photo));
135 /* Disable fetching image until we find a last.fm replacement
136 // Option to fetch the old album image
137 if (ElevenUtils.isOnline(getActivity())) {
138 // Option to fetch the old artist image
139 mChoices.add(OLD_PHOTO, getString(R.string.context_menu_fetch_album_art));
144 * Adds the choices for the genre and playlist images.
146 private void setOtherChoices() {
147 // Select a photo from the gallery
148 mChoices.add(NEW_PHOTO, getString(R.string.new_photo));
149 // Disable fetching image until we find a last.fm replacement
150 // Option to use the default image
151 // mChoices.add(OLD_PHOTO, getString(R.string.use_default));
155 * Easily detect the MIME type
157 public enum ProfileType {
158 ARTIST, ALBUM, ProfileType, OTHER