1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package net.sourceforge.subsonic.androidapp.activity; |
20 |
|
|
21 |
|
import android.app.AlertDialog; |
22 |
|
import android.content.DialogInterface; |
23 |
|
import android.content.Intent; |
24 |
|
import android.net.Uri; |
25 |
|
import android.os.Bundle; |
26 |
|
import android.util.Log; |
27 |
|
import android.view.ContextMenu; |
28 |
|
import android.view.LayoutInflater; |
29 |
|
import android.view.MenuInflater; |
30 |
|
import android.view.MenuItem; |
31 |
|
import android.view.View; |
32 |
|
import android.widget.AdapterView; |
33 |
|
import android.widget.Button; |
34 |
|
import android.widget.ImageButton; |
35 |
|
import android.widget.ImageView; |
36 |
|
import android.widget.ListView; |
37 |
|
import net.sourceforge.subsonic.androidapp.R; |
38 |
|
import net.sourceforge.subsonic.androidapp.domain.MusicDirectory; |
39 |
|
import net.sourceforge.subsonic.androidapp.service.DownloadFile; |
40 |
|
import net.sourceforge.subsonic.androidapp.service.MusicService; |
41 |
|
import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory; |
42 |
|
import net.sourceforge.subsonic.androidapp.util.Constants; |
43 |
|
import net.sourceforge.subsonic.androidapp.util.EntryAdapter; |
44 |
|
import net.sourceforge.subsonic.androidapp.util.Pair; |
45 |
|
import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask; |
46 |
|
import net.sourceforge.subsonic.androidapp.util.Util; |
47 |
|
|
48 |
|
import java.util.ArrayList; |
49 |
|
import java.util.List; |
50 |
|
|
|
|
| 70,9% |
Uncovered Elements: 103 (354) |
Complexity: 85 |
Complexity Density: 0,35 |
|
51 |
|
public class SelectAlbumActivity extends SubsonicTabActivity { |
52 |
|
|
53 |
|
private static final String TAG = SelectAlbumActivity.class.getSimpleName(); |
54 |
|
|
55 |
|
private ListView entryList; |
56 |
|
private View footer; |
57 |
|
private View emptyView; |
58 |
|
private Button selectButton; |
59 |
|
private Button playNowButton; |
60 |
|
private Button playLastButton; |
61 |
|
private Button pinButton; |
62 |
|
private Button unpinButton; |
63 |
|
private Button deleteButton; |
64 |
|
private Button moreButton; |
65 |
|
private ImageView coverArtView; |
66 |
|
private boolean licenseValid; |
67 |
|
private ImageButton playAllButton; |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (47) |
Complexity: 3 |
Complexity Density: 0,07 |
|
72 |
10
|
@Override... |
73 |
|
public void onCreate(Bundle savedInstanceState) { |
74 |
10
|
super.onCreate(savedInstanceState); |
75 |
10
|
setContentView(R.layout.select_album); |
76 |
|
|
77 |
10
|
entryList = (ListView) findViewById(R.id.select_album_entries); |
78 |
|
|
79 |
10
|
footer = LayoutInflater.from(this).inflate(R.layout.select_album_footer, entryList, false); |
80 |
10
|
entryList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); |
81 |
10
|
entryList.setOnItemClickListener(new AdapterView.OnItemClickListener() { |
|
|
| 81,2% |
Uncovered Elements: 3 (16) |
Complexity: 4 |
Complexity Density: 0,4 |
|
82 |
33
|
@Override... |
83 |
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
84 |
33
|
if (position >= 0) { |
85 |
33
|
MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position); |
86 |
33
|
if (entry.isDirectory()) { |
87 |
3
|
Intent intent = new Intent(SelectAlbumActivity.this, SelectAlbumActivity.class); |
88 |
3
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, entry.getId()); |
89 |
3
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle()); |
90 |
3
|
Util.startActivityWithoutTransition(SelectAlbumActivity.this, intent); |
91 |
30
|
} else if (entry.isVideo()) { |
92 |
0
|
playVideo(entry); |
93 |
|
} else { |
94 |
30
|
enableButtons(); |
95 |
|
} |
96 |
|
} |
97 |
|
} |
98 |
|
}); |
99 |
|
|
100 |
10
|
coverArtView = (ImageView) findViewById(R.id.actionbar_home_icon); |
101 |
10
|
selectButton = (Button) findViewById(R.id.select_album_select); |
102 |
10
|
playNowButton = (Button) findViewById(R.id.select_album_play_now); |
103 |
10
|
playLastButton = (Button) findViewById(R.id.select_album_play_last); |
104 |
10
|
pinButton = (Button) footer.findViewById(R.id.select_album_pin); |
105 |
10
|
unpinButton = (Button) footer.findViewById(R.id.select_album_unpin); |
106 |
10
|
unpinButton = (Button) footer.findViewById(R.id.select_album_unpin); |
107 |
10
|
deleteButton = (Button) footer.findViewById(R.id.select_album_delete); |
108 |
10
|
moreButton = (Button) footer.findViewById(R.id.select_album_more); |
109 |
10
|
emptyView = findViewById(R.id.select_album_empty); |
110 |
|
|
111 |
10
|
selectButton.setOnClickListener(new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
4
|
@Override... |
113 |
|
public void onClick(View view) { |
114 |
4
|
selectAllOrNone(); |
115 |
|
} |
116 |
|
}); |
117 |
10
|
playNowButton.setOnClickListener(new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
118 |
2
|
@Override... |
119 |
|
public void onClick(View view) { |
120 |
2
|
download(false, false, true, false); |
121 |
2
|
selectAll(false, false); |
122 |
|
} |
123 |
|
}); |
124 |
10
|
playLastButton.setOnClickListener(new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
125 |
2
|
@Override... |
126 |
|
public void onClick(View view) { |
127 |
2
|
download(true, false, false, false); |
128 |
2
|
selectAll(false, false); |
129 |
|
} |
130 |
|
}); |
131 |
10
|
pinButton.setOnClickListener(new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
132 |
3
|
@Override... |
133 |
|
public void onClick(View view) { |
134 |
3
|
download(true, true, false, false); |
135 |
3
|
selectAll(false, false); |
136 |
|
} |
137 |
|
}); |
138 |
10
|
unpinButton.setOnClickListener(new View.OnClickListener() { |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
139 |
0
|
@Override... |
140 |
|
public void onClick(View view) { |
141 |
0
|
unpin(); |
142 |
0
|
selectAll(false, false); |
143 |
|
} |
144 |
|
}); |
145 |
10
|
deleteButton.setOnClickListener(new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
146 |
1
|
@Override... |
147 |
|
public void onClick(View view) { |
148 |
1
|
delete(); |
149 |
1
|
selectAll(false, false); |
150 |
|
} |
151 |
|
}); |
152 |
|
|
153 |
10
|
registerForContextMenu(entryList); |
154 |
|
|
155 |
10
|
enableButtons(); |
156 |
|
|
157 |
10
|
String id = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ID); |
158 |
10
|
String name = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_NAME); |
159 |
10
|
String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID); |
160 |
10
|
String playlistName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME); |
161 |
10
|
String albumListType = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE); |
162 |
10
|
int albumListSize = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0); |
163 |
10
|
int albumListOffset = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0); |
164 |
|
|
165 |
10
|
if (playlistId != null) { |
166 |
2
|
getPlaylist(playlistId, playlistName); |
167 |
8
|
} else if (albumListType != null) { |
168 |
3
|
getAlbumList(albumListType, albumListSize, albumListOffset); |
169 |
|
} else { |
170 |
5
|
getMusicDirectory(id, name); |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
10
|
playAllButton = (ImageButton) findViewById(R.id.action_button_1); |
175 |
10
|
playAllButton.setImageResource(R.drawable.ic_menu_play_all); |
176 |
10
|
playAllButton.setVisibility(View.GONE); |
177 |
10
|
playAllButton.setOnClickListener(new View.OnClickListener() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
178 |
1
|
@Override... |
179 |
|
public void onClick(View view) { |
180 |
1
|
playAll(); |
181 |
|
} |
182 |
|
}); |
183 |
|
|
184 |
|
|
185 |
10
|
ImageButton refreshButton = (ImageButton) findViewById(R.id.action_button_2); |
186 |
10
|
refreshButton.setImageResource(R.drawable.ic_menu_refresh); |
187 |
10
|
refreshButton.setOnClickListener(new View.OnClickListener() { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
188 |
0
|
@Override... |
189 |
|
public void onClick(View view) { |
190 |
0
|
refresh(); |
191 |
|
} |
192 |
|
}); |
193 |
|
} |
194 |
|
|
|
|
| 72,2% |
Uncovered Elements: 5 (18) |
Complexity: 6 |
Complexity Density: 0,5 |
|
195 |
2
|
private void playAll() {... |
196 |
2
|
boolean hasSubFolders = false; |
197 |
19
|
for (int i = 0; i < entryList.getCount(); i++) { |
198 |
17
|
MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(i); |
199 |
17
|
if (entry != null && entry.isDirectory()) { |
200 |
0
|
hasSubFolders = true; |
201 |
0
|
break; |
202 |
|
} |
203 |
|
} |
204 |
|
|
205 |
2
|
String id = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ID); |
206 |
2
|
if (hasSubFolders && id != null) { |
207 |
0
|
downloadRecursively(id, false, false, true); |
208 |
|
} else { |
209 |
2
|
selectAll(true, false); |
210 |
2
|
download(false, false, true, false); |
211 |
2
|
selectAll(false, false); |
212 |
|
} |
213 |
|
} |
214 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
215 |
0
|
private void refresh() {... |
216 |
0
|
finish(); |
217 |
0
|
Intent intent = getIntent(); |
218 |
0
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_REFRESH, true); |
219 |
0
|
Util.startActivityWithoutTransition(this, intent); |
220 |
|
} |
221 |
|
|
|
|
| 70% |
Uncovered Elements: 3 (10) |
Complexity: 2 |
Complexity Density: 0,25 |
|
222 |
4
|
@Override... |
223 |
|
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { |
224 |
4
|
super.onCreateContextMenu(menu, view, menuInfo); |
225 |
4
|
AdapterView.AdapterContextMenuInfo info = |
226 |
|
(AdapterView.AdapterContextMenuInfo) menuInfo; |
227 |
|
|
228 |
4
|
MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position); |
229 |
|
|
230 |
4
|
if (entry.isDirectory()) { |
231 |
0
|
MenuInflater inflater = getMenuInflater(); |
232 |
0
|
inflater.inflate(R.menu.select_album_context, menu); |
233 |
|
} else { |
234 |
4
|
MenuInflater inflater = getMenuInflater(); |
235 |
4
|
inflater.inflate(R.menu.select_song_context, menu); |
236 |
|
} |
237 |
|
} |
238 |
|
|
|
|
| 57,7% |
Uncovered Elements: 11 (26) |
Complexity: 7 |
Complexity Density: 0,27 |
|
239 |
4
|
@Override... |
240 |
|
public boolean onContextItemSelected(MenuItem menuItem) { |
241 |
4
|
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); |
242 |
4
|
MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position); |
243 |
4
|
List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>(10); |
244 |
4
|
songs.add((MusicDirectory.Entry) entryList.getItemAtPosition(info.position)); |
245 |
4
|
switch (menuItem.getItemId()) { |
246 |
0
|
case R.id.album_menu_play_now: |
247 |
0
|
downloadRecursively(entry.getId(), false, false, true); |
248 |
0
|
break; |
249 |
0
|
case R.id.album_menu_play_last: |
250 |
0
|
downloadRecursively(entry.getId(), false, true, false); |
251 |
0
|
break; |
252 |
0
|
case R.id.album_menu_pin: |
253 |
0
|
downloadRecursively(entry.getId(), true, true, false); |
254 |
0
|
break; |
255 |
1
|
case R.id.song_menu_play_now: |
256 |
1
|
getDownloadService().download(songs, false, true, true); |
257 |
1
|
break; |
258 |
2
|
case R.id.song_menu_play_next: |
259 |
2
|
getDownloadService().download(songs, false, false, true); |
260 |
2
|
break; |
261 |
1
|
case R.id.song_menu_play_last: |
262 |
1
|
getDownloadService().download(songs, false, false, false); |
263 |
1
|
break; |
264 |
0
|
default: |
265 |
0
|
return super.onContextItemSelected(menuItem); |
266 |
|
} |
267 |
4
|
return true; |
268 |
|
} |
269 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
270 |
5
|
private void getMusicDirectory(final String id, String name) {... |
271 |
5
|
setTitle(name); |
272 |
|
|
273 |
5
|
new LoadTask() { |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
274 |
5
|
@Override... |
275 |
|
protected MusicDirectory load(MusicService service) throws Exception { |
276 |
5
|
boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false); |
277 |
5
|
return service.getMusicDirectory(id, refresh, SelectAlbumActivity.this, this); |
278 |
|
} |
279 |
|
}.execute(); |
280 |
|
} |
281 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
282 |
2
|
private void getPlaylist(final String playlistId, String playlistName) {... |
283 |
2
|
setTitle(playlistName); |
284 |
|
|
285 |
2
|
new LoadTask() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
286 |
2
|
@Override... |
287 |
|
protected MusicDirectory load(MusicService service) throws Exception { |
288 |
2
|
return service.getPlaylist(playlistId, SelectAlbumActivity.this, this); |
289 |
|
} |
290 |
|
}.execute(); |
291 |
|
} |
292 |
|
|
|
|
| 57,1% |
Uncovered Elements: 9 (21) |
Complexity: 6 |
Complexity Density: 0,55 |
|
293 |
3
|
private void getAlbumList(final String albumListType, final int size, final int offset) {... |
294 |
|
|
295 |
3
|
if ("newest".equals(albumListType)) { |
296 |
2
|
setTitle(R.string.main_albums_newest); |
297 |
1
|
} else if ("random".equals(albumListType)) { |
298 |
0
|
setTitle(R.string.main_albums_random); |
299 |
1
|
} else if ("highest".equals(albumListType)) { |
300 |
0
|
setTitle(R.string.main_albums_highest); |
301 |
1
|
} else if ("recent".equals(albumListType)) { |
302 |
1
|
setTitle(R.string.main_albums_recent); |
303 |
0
|
} else if ("frequent".equals(albumListType)) { |
304 |
0
|
setTitle(R.string.main_albums_frequent); |
305 |
|
} |
306 |
|
|
307 |
3
|
new LoadTask() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
308 |
3
|
@Override... |
309 |
|
protected MusicDirectory load(MusicService service) throws Exception { |
310 |
3
|
return service.getAlbumList(albumListType, size, offset, SelectAlbumActivity.this, this); |
311 |
|
} |
312 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0,25 |
|
313 |
3
|
@Override... |
314 |
|
protected void done(Pair<MusicDirectory, Boolean> result) { |
315 |
3
|
if (!result.getFirst().getChildren().isEmpty()) { |
316 |
3
|
pinButton.setVisibility(View.GONE); |
317 |
3
|
unpinButton.setVisibility(View.GONE); |
318 |
3
|
deleteButton.setVisibility(View.GONE); |
319 |
3
|
moreButton.setVisibility(View.VISIBLE); |
320 |
3
|
entryList.addFooterView(footer); |
321 |
|
|
322 |
3
|
moreButton.setOnClickListener(new View.OnClickListener() { |
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
|
323 |
0
|
@Override... |
324 |
|
public void onClick(View view) { |
325 |
0
|
Intent intent = new Intent(SelectAlbumActivity.this, SelectAlbumActivity.class); |
326 |
0
|
String type = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE); |
327 |
0
|
int size = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0); |
328 |
0
|
int offset = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0) + size; |
329 |
|
|
330 |
0
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type); |
331 |
0
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, size); |
332 |
0
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, offset); |
333 |
0
|
Util.startActivityWithoutTransition(SelectAlbumActivity.this, intent); |
334 |
|
} |
335 |
|
}); |
336 |
|
} |
337 |
3
|
super.done(result); |
338 |
|
} |
339 |
|
}.execute(); |
340 |
|
} |
341 |
|
|
|
|
| 90,9% |
Uncovered Elements: 1 (11) |
Complexity: 4 |
Complexity Density: 0,57 |
|
342 |
4
|
private void selectAllOrNone() {... |
343 |
4
|
boolean someUnselected = false; |
344 |
4
|
int count = entryList.getCount(); |
345 |
13
|
for (int i = 0; i < count; i++) { |
346 |
13
|
if (!entryList.isItemChecked(i) && entryList.getItemAtPosition(i) instanceof MusicDirectory.Entry) { |
347 |
4
|
someUnselected = true; |
348 |
4
|
break; |
349 |
|
} |
350 |
|
} |
351 |
4
|
selectAll(someUnselected, true); |
352 |
|
} |
353 |
|
|
|
|
| 94,7% |
Uncovered Elements: 1 (19) |
Complexity: 7 |
Complexity Density: 0,64 |
|
354 |
16
|
private void selectAll(boolean selected, boolean toast) {... |
355 |
16
|
int count = entryList.getCount(); |
356 |
16
|
int selectedCount = 0; |
357 |
152
|
for (int i = 0; i < count; i++) { |
358 |
136
|
MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(i); |
359 |
136
|
if (entry != null && !entry.isDirectory() && !entry.isVideo()) { |
360 |
120
|
entryList.setItemChecked(i, selected); |
361 |
120
|
selectedCount++; |
362 |
|
} |
363 |
|
} |
364 |
|
|
365 |
|
|
366 |
16
|
if (toast) { |
367 |
4
|
int toastResId = selected ? R.string.select_album_n_selected |
368 |
|
: R.string.select_album_n_unselected; |
369 |
4
|
Util.toast(this, getString(toastResId, selectedCount)); |
370 |
|
} |
371 |
|
|
372 |
16
|
enableButtons(); |
373 |
|
} |
374 |
|
|
|
|
| 82,6% |
Uncovered Elements: 4 (23) |
Complexity: 4 |
Complexity Density: 0,24 |
|
375 |
56
|
private void enableButtons() {... |
376 |
56
|
if (getDownloadService() == null) { |
377 |
0
|
return; |
378 |
|
} |
379 |
|
|
380 |
56
|
List<MusicDirectory.Entry> selection = getSelectedSongs(); |
381 |
56
|
boolean enabled = !selection.isEmpty(); |
382 |
56
|
boolean unpinEnabled = false; |
383 |
56
|
boolean deleteEnabled = false; |
384 |
|
|
385 |
56
|
for (MusicDirectory.Entry song : selection) { |
386 |
135
|
DownloadFile downloadFile = getDownloadService().forSong(song); |
387 |
135
|
if (downloadFile.isCompleteFileAvailable()) { |
388 |
7
|
deleteEnabled = true; |
389 |
|
} |
390 |
135
|
if (downloadFile.isSaved()) { |
391 |
0
|
unpinEnabled = true; |
392 |
|
} |
393 |
|
} |
394 |
|
|
395 |
56
|
playNowButton.setEnabled(enabled); |
396 |
56
|
playLastButton.setEnabled(enabled); |
397 |
56
|
pinButton.setEnabled(enabled && !Util.isOffline(this)); |
398 |
56
|
unpinButton.setEnabled(unpinEnabled); |
399 |
56
|
deleteButton.setEnabled(deleteEnabled); |
400 |
|
} |
401 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0,5 |
|
402 |
66
|
private List<MusicDirectory.Entry> getSelectedSongs() {... |
403 |
66
|
List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>(10); |
404 |
66
|
int count = entryList.getCount(); |
405 |
532
|
for (int i = 0; i < count; i++) { |
406 |
466
|
if (entryList.isItemChecked(i)) { |
407 |
183
|
songs.add((MusicDirectory.Entry) entryList.getItemAtPosition(i)); |
408 |
|
} |
409 |
|
} |
410 |
66
|
return songs; |
411 |
|
} |
412 |
|
|
|
|
| 71,4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
413 |
9
|
private void download(final boolean append, final boolean save, final boolean autoplay, final boolean playNext) {... |
414 |
9
|
if (getDownloadService() == null) { |
415 |
0
|
return; |
416 |
|
} |
417 |
|
|
418 |
9
|
final List<MusicDirectory.Entry> songs = getSelectedSongs(); |
419 |
9
|
Runnable onValid = new Runnable() { |
|
|
| 95,7% |
Uncovered Elements: 1 (23) |
Complexity: 6 |
Complexity Density: 0,46 |
|
420 |
9
|
@Override... |
421 |
|
public void run() { |
422 |
9
|
if (!append) { |
423 |
4
|
getDownloadService().clear(); |
424 |
|
} |
425 |
|
|
426 |
9
|
warnIfNetworkOrStorageUnavailable(); |
427 |
9
|
getDownloadService().download(songs, save, autoplay, playNext); |
428 |
9
|
String playlistName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME); |
429 |
9
|
if (playlistName != null) { |
430 |
2
|
getDownloadService().setSuggestedPlaylistName(playlistName); |
431 |
|
} |
432 |
9
|
if (autoplay) { |
433 |
4
|
Util.startActivityWithoutTransition(SelectAlbumActivity.this, DownloadActivity.class); |
434 |
5
|
} else if (save) { |
435 |
3
|
Util.toast(SelectAlbumActivity.this, |
436 |
|
getResources().getQuantityString(R.plurals.select_album_n_songs_downloading, songs.size(), songs.size())); |
437 |
2
|
} else if (append) { |
438 |
2
|
Util.toast(SelectAlbumActivity.this, |
439 |
|
getResources().getQuantityString(R.plurals.select_album_n_songs_added, songs.size(), songs.size())); |
440 |
|
} |
441 |
|
} |
442 |
|
}; |
443 |
|
|
444 |
9
|
checkLicenseAndTrialPeriod(onValid); |
445 |
|
} |
446 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
447 |
1
|
private void delete() {... |
448 |
1
|
if (getDownloadService() != null) { |
449 |
1
|
getDownloadService().delete(getSelectedSongs()); |
450 |
|
} |
451 |
|
} |
452 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
453 |
0
|
private void unpin() {... |
454 |
0
|
if (getDownloadService() != null) { |
455 |
0
|
getDownloadService().unpin(getSelectedSongs()); |
456 |
|
} |
457 |
|
} |
458 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
459 |
0
|
private void playVideo(MusicDirectory.Entry entry) {... |
460 |
0
|
Intent intent = new Intent(Intent.ACTION_VIEW); |
461 |
0
|
intent.setData(Uri.parse(MusicServiceFactory.getMusicService(this).getVideoUrl(this, entry.getId()))); |
462 |
|
|
463 |
0
|
startActivity(intent); |
464 |
|
} |
465 |
|
|
|
|
| 23,5% |
Uncovered Elements: 13 (17) |
Complexity: 4 |
Complexity Density: 0,36 |
|
466 |
9
|
private void checkLicenseAndTrialPeriod(Runnable onValid) {... |
467 |
9
|
if (licenseValid) { |
468 |
9
|
onValid.run(); |
469 |
9
|
return; |
470 |
|
} |
471 |
|
|
472 |
0
|
int trialDaysLeft = Util.getRemainingTrialDays(this); |
473 |
0
|
Log.i(TAG, trialDaysLeft + " trial days left."); |
474 |
|
|
475 |
0
|
if (trialDaysLeft == 0) { |
476 |
0
|
showDonationDialog(trialDaysLeft, null); |
477 |
0
|
} else if (trialDaysLeft < Constants.FREE_TRIAL_DAYS / 2) { |
478 |
0
|
showDonationDialog(trialDaysLeft, onValid); |
479 |
|
} else { |
480 |
0
|
Util.toast(this, getResources().getString(R.string.select_album_not_licensed, trialDaysLeft)); |
481 |
0
|
onValid.run(); |
482 |
|
} |
483 |
|
} |
484 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0,22 |
|
485 |
0
|
private void showDonationDialog(int trialDaysLeft, final Runnable onValid) {... |
486 |
0
|
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
487 |
0
|
builder.setIcon(android.R.drawable.ic_dialog_info); |
488 |
|
|
489 |
0
|
if (trialDaysLeft == 0) { |
490 |
0
|
builder.setTitle(R.string.select_album_donate_dialog_0_trial_days_left); |
491 |
|
} else { |
492 |
0
|
builder.setTitle(getResources().getQuantityString(R.plurals.select_album_donate_dialog_n_trial_days_left, |
493 |
|
trialDaysLeft, trialDaysLeft)); |
494 |
|
} |
495 |
|
|
496 |
0
|
builder.setMessage(R.string.select_album_donate_dialog_message); |
497 |
|
|
498 |
0
|
builder.setPositiveButton(R.string.select_album_donate_dialog_now, |
499 |
|
new DialogInterface.OnClickListener() { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
500 |
0
|
@Override... |
501 |
|
public void onClick(DialogInterface dialogInterface, int i) { |
502 |
0
|
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.DONATION_URL))); |
503 |
|
} |
504 |
|
}); |
505 |
|
|
506 |
0
|
builder.setNegativeButton(R.string.select_album_donate_dialog_later, |
507 |
|
new DialogInterface.OnClickListener() { |
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
508 |
0
|
@Override... |
509 |
|
public void onClick(DialogInterface dialogInterface, int i) { |
510 |
0
|
dialogInterface.dismiss(); |
511 |
0
|
if (onValid != null) { |
512 |
0
|
onValid.run(); |
513 |
|
} |
514 |
|
} |
515 |
|
}); |
516 |
|
|
517 |
0
|
builder.create().show(); |
518 |
|
} |
519 |
|
|
|
|
| 97,3% |
Uncovered Elements: 1 (37) |
Complexity: 10 |
Complexity Density: 0,42 |
|
520 |
|
private abstract class LoadTask extends TabActivityBackgroundTask<Pair<MusicDirectory, Boolean>> { |
521 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
522 |
10
|
public LoadTask() {... |
523 |
10
|
super(SelectAlbumActivity.this); |
524 |
|
} |
525 |
|
|
526 |
|
protected abstract MusicDirectory load(MusicService service) throws Exception; |
527 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
528 |
10
|
@Override... |
529 |
|
protected Pair<MusicDirectory, Boolean> doInBackground() throws Throwable { |
530 |
10
|
MusicService musicService = MusicServiceFactory.getMusicService(SelectAlbumActivity.this); |
531 |
10
|
MusicDirectory dir = load(musicService); |
532 |
10
|
boolean valid = musicService.isLicenseValid(SelectAlbumActivity.this, this); |
533 |
10
|
return new Pair<MusicDirectory, Boolean>(dir, valid); |
534 |
|
} |
535 |
|
|
|
|
| 96,6% |
Uncovered Elements: 1 (29) |
Complexity: 8 |
Complexity Density: 0,42 |
|
536 |
10
|
@Override... |
537 |
|
protected void done(Pair<MusicDirectory, Boolean> result) { |
538 |
10
|
List<MusicDirectory.Entry> entries = result.getFirst().getChildren(); |
539 |
|
|
540 |
10
|
int songCount = 0; |
541 |
10
|
for (MusicDirectory.Entry entry : entries) { |
542 |
116
|
if (!entry.isDirectory()) { |
543 |
56
|
songCount++; |
544 |
|
} |
545 |
|
} |
546 |
|
|
547 |
10
|
if (songCount > 0) { |
548 |
7
|
getImageLoader().loadImage(coverArtView, entries.get(0), false, true); |
549 |
7
|
entryList.addFooterView(footer); |
550 |
7
|
selectButton.setVisibility(View.VISIBLE); |
551 |
7
|
playNowButton.setVisibility(View.VISIBLE); |
552 |
7
|
playLastButton.setVisibility(View.VISIBLE); |
553 |
|
} |
554 |
|
|
555 |
10
|
boolean isAlbumList = getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE); |
556 |
|
|
557 |
10
|
emptyView.setVisibility(entries.isEmpty() ? View.VISIBLE : View.GONE); |
558 |
10
|
playAllButton.setVisibility(isAlbumList || entries.isEmpty() ? View.GONE : View.VISIBLE); |
559 |
10
|
entryList.setAdapter(new EntryAdapter(SelectAlbumActivity.this, getImageLoader(), entries, true)); |
560 |
10
|
licenseValid = result.getSecond(); |
561 |
|
|
562 |
10
|
boolean playAll = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false); |
563 |
10
|
if (playAll && songCount > 0) { |
564 |
1
|
playAll(); |
565 |
|
} |
566 |
|
} |
567 |
|
} |
568 |
|
} |