1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package net.sourceforge.subsonic.androidapp.activity; |
21 |
|
|
22 |
|
import android.content.Intent; |
23 |
|
import android.os.Bundle; |
24 |
|
import android.view.ContextMenu; |
25 |
|
import android.view.LayoutInflater; |
26 |
|
import android.view.MenuInflater; |
27 |
|
import android.view.MenuItem; |
28 |
|
import android.view.View; |
29 |
|
import android.widget.AdapterView; |
30 |
|
import android.widget.ImageButton; |
31 |
|
import android.widget.ListView; |
32 |
|
import android.widget.TextView; |
33 |
|
import net.sourceforge.subsonic.androidapp.R; |
34 |
|
import net.sourceforge.subsonic.androidapp.domain.Artist; |
35 |
|
import net.sourceforge.subsonic.androidapp.domain.Indexes; |
36 |
|
import net.sourceforge.subsonic.androidapp.domain.MusicFolder; |
37 |
|
import net.sourceforge.subsonic.androidapp.service.MusicService; |
38 |
|
import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory; |
39 |
|
import net.sourceforge.subsonic.androidapp.util.ArtistAdapter; |
40 |
|
import net.sourceforge.subsonic.androidapp.util.BackgroundTask; |
41 |
|
import net.sourceforge.subsonic.androidapp.util.Constants; |
42 |
|
import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask; |
43 |
|
import net.sourceforge.subsonic.androidapp.util.Util; |
44 |
|
|
45 |
|
import java.util.ArrayList; |
46 |
|
import java.util.List; |
47 |
|
|
|
|
| 41,1% |
Uncovered Elements: 83 (141) |
Complexity: 32 |
Complexity Density: 0,34 |
|
48 |
|
public class SelectArtistActivity extends SubsonicTabActivity implements AdapterView.OnItemClickListener { |
49 |
|
|
50 |
|
private static final int MENU_GROUP_MUSIC_FOLDER = 10; |
51 |
|
|
52 |
|
private ListView artistList; |
53 |
|
private View folderButton; |
54 |
|
private TextView folderName; |
55 |
|
private List<MusicFolder> musicFolders; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 3 |
Complexity Density: 0,17 |
|
60 |
4
|
@Override... |
61 |
|
public void onCreate(Bundle savedInstanceState) { |
62 |
4
|
super.onCreate(savedInstanceState); |
63 |
4
|
setContentView(R.layout.select_artist); |
64 |
|
|
65 |
4
|
artistList = (ListView) findViewById(R.id.select_artist_list); |
66 |
4
|
artistList.setOnItemClickListener(this); |
67 |
|
|
68 |
4
|
folderButton = LayoutInflater.from(this).inflate(R.layout.select_artist_header, artistList, false); |
69 |
4
|
folderName = (TextView) folderButton.findViewById(R.id.select_artist_folder_2); |
70 |
|
|
71 |
4
|
if (!Util.isOffline(this)) { |
72 |
3
|
artistList.addHeaderView(folderButton); |
73 |
|
} |
74 |
|
|
75 |
4
|
registerForContextMenu(artistList); |
76 |
|
|
77 |
4
|
setTitle(Util.isOffline(this) ? R.string.music_library_label_offline : R.string.music_library_label); |
78 |
|
|
79 |
|
|
80 |
4
|
ImageButton shuffleButton = (ImageButton) findViewById(R.id.action_button_1); |
81 |
4
|
shuffleButton.setImageResource(R.drawable.ic_menu_shuffle); |
82 |
4
|
shuffleButton.setOnClickListener(new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
83 |
1
|
@Override... |
84 |
|
public void onClick(View view) { |
85 |
1
|
Intent intent = new Intent(SelectArtistActivity.this, DownloadActivity.class); |
86 |
1
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); |
87 |
1
|
Util.startActivityWithoutTransition(SelectArtistActivity.this, intent); |
88 |
|
} |
89 |
|
}); |
90 |
|
|
91 |
|
|
92 |
4
|
ImageButton refreshButton = (ImageButton) findViewById(R.id.action_button_2); |
93 |
4
|
refreshButton.setImageResource(R.drawable.ic_menu_refresh); |
94 |
4
|
refreshButton.setOnClickListener(new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
1
|
@Override... |
96 |
|
public void onClick(View view) { |
97 |
1
|
refresh(); |
98 |
|
} |
99 |
|
}); |
100 |
|
|
101 |
4
|
musicFolders = null; |
102 |
4
|
load(); |
103 |
|
} |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
105 |
1
|
private void refresh() {... |
106 |
1
|
finish(); |
107 |
1
|
Intent intent = getIntent(); |
108 |
1
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_REFRESH, true); |
109 |
1
|
Util.startActivityWithoutTransition(this, intent); |
110 |
|
} |
111 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
0
|
private void selectFolder() {... |
113 |
0
|
folderButton.showContextMenu(); |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
116 |
4
|
private void load() {... |
117 |
4
|
BackgroundTask<Indexes> task = new TabActivityBackgroundTask<Indexes>(this) { |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
118 |
4
|
@Override... |
119 |
|
protected Indexes doInBackground() throws Throwable { |
120 |
4
|
boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false); |
121 |
4
|
MusicService musicService = MusicServiceFactory.getMusicService(SelectArtistActivity.this); |
122 |
4
|
if (!Util.isOffline(SelectArtistActivity.this)) { |
123 |
3
|
musicFolders = musicService.getMusicFolders(SelectArtistActivity.this, this); |
124 |
|
} |
125 |
4
|
String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this); |
126 |
4
|
return musicService.getIndexes(musicFolderId, refresh, SelectArtistActivity.this, this); |
127 |
|
} |
128 |
|
|
|
|
| 61,1% |
Uncovered Elements: 7 (18) |
Complexity: 4 |
Complexity Density: 0,33 |
|
129 |
4
|
@Override... |
130 |
|
protected void done(Indexes result) { |
131 |
4
|
List<Artist> artists = new ArrayList<Artist>(result.getShortcuts().size() + result.getArtists().size()); |
132 |
4
|
artists.addAll(result.getShortcuts()); |
133 |
4
|
artists.addAll(result.getArtists()); |
134 |
4
|
artistList.setAdapter(new ArtistAdapter(SelectArtistActivity.this, artists)); |
135 |
|
|
136 |
|
|
137 |
4
|
if (musicFolders != null) { |
138 |
3
|
String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this); |
139 |
3
|
if (musicFolderId == null) { |
140 |
3
|
folderName.setText(R.string.select_artist_all_folders); |
141 |
|
} else { |
142 |
0
|
for (MusicFolder musicFolder : musicFolders) { |
143 |
0
|
if (musicFolder.getId().equals(musicFolderId)) { |
144 |
0
|
folderName.setText(musicFolder.getName()); |
145 |
0
|
break; |
146 |
|
} |
147 |
|
} |
148 |
|
} |
149 |
|
} |
150 |
|
} |
151 |
|
}; |
152 |
4
|
task.execute(); |
153 |
|
} |
154 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0,29 |
|
155 |
0
|
@Override... |
156 |
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
157 |
0
|
if (view == folderButton) { |
158 |
0
|
selectFolder(); |
159 |
|
} else { |
160 |
0
|
Artist artist = (Artist) parent.getItemAtPosition(position); |
161 |
0
|
Intent intent = new Intent(this, SelectAlbumActivity.class); |
162 |
0
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); |
163 |
0
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); |
164 |
0
|
Util.startActivityWithoutTransition(this, intent); |
165 |
|
} |
166 |
|
} |
167 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 7 |
Complexity Density: 0,41 |
|
168 |
0
|
@Override... |
169 |
|
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { |
170 |
0
|
super.onCreateContextMenu(menu, view, menuInfo); |
171 |
|
|
172 |
0
|
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; |
173 |
|
|
174 |
0
|
if (artistList.getItemAtPosition(info.position) instanceof Artist) { |
175 |
0
|
MenuInflater inflater = getMenuInflater(); |
176 |
0
|
inflater.inflate(R.menu.select_artist_context, menu); |
177 |
0
|
} else if (info.position == 0) { |
178 |
0
|
String musicFolderId = Util.getSelectedMusicFolderId(this); |
179 |
0
|
MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders); |
180 |
0
|
if (musicFolderId == null) { |
181 |
0
|
menuItem.setChecked(true); |
182 |
|
} |
183 |
0
|
if (musicFolders != null) { |
184 |
0
|
for (int i = 0; i < musicFolders.size(); i++) { |
185 |
0
|
MusicFolder musicFolder = musicFolders.get(i); |
186 |
0
|
menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, i, i + 1, musicFolder.getName()); |
187 |
0
|
if (musicFolder.getId().equals(musicFolderId)) { |
188 |
0
|
menuItem.setChecked(true); |
189 |
|
} |
190 |
|
} |
191 |
|
} |
192 |
0
|
menu.setGroupCheckable(MENU_GROUP_MUSIC_FOLDER, true, true); |
193 |
|
} |
194 |
|
} |
195 |
|
|
|
|
| 0% |
Uncovered Elements: 33 (33) |
Complexity: 9 |
Complexity Density: 0,39 |
|
196 |
0
|
@Override... |
197 |
|
public boolean onContextItemSelected(MenuItem menuItem) { |
198 |
0
|
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); |
199 |
|
|
200 |
0
|
Artist artist = (Artist) artistList.getItemAtPosition(info.position); |
201 |
|
|
202 |
0
|
if (artist != null) { |
203 |
0
|
switch (menuItem.getItemId()) { |
204 |
0
|
case R.id.artist_menu_play_now: |
205 |
0
|
downloadRecursively(artist.getId(), false, false, true); |
206 |
0
|
break; |
207 |
0
|
case R.id.artist_menu_play_last: |
208 |
0
|
downloadRecursively(artist.getId(), false, true, false); |
209 |
0
|
break; |
210 |
0
|
case R.id.artist_menu_pin: |
211 |
0
|
downloadRecursively(artist.getId(), true, true, false); |
212 |
0
|
break; |
213 |
0
|
default: |
214 |
0
|
return super.onContextItemSelected(menuItem); |
215 |
|
} |
216 |
0
|
} else if (info.position == 0) { |
217 |
0
|
MusicFolder selectedFolder = menuItem.getItemId() == -1 ? null : musicFolders.get(menuItem.getItemId()); |
218 |
0
|
String musicFolderId = selectedFolder == null ? null : selectedFolder.getId(); |
219 |
0
|
String musicFolderName = selectedFolder == null ? getString(R.string.select_artist_all_folders) |
220 |
|
: selectedFolder.getName(); |
221 |
0
|
Util.setSelectedMusicFolderId(this, musicFolderId); |
222 |
0
|
folderName.setText(musicFolderName); |
223 |
0
|
refresh(); |
224 |
|
} |
225 |
|
|
226 |
0
|
return true; |
227 |
|
} |
228 |
|
} |