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.Menu; |
26 |
|
import android.view.MenuItem; |
27 |
|
import android.view.View; |
28 |
|
import android.widget.AdapterView; |
29 |
|
import android.widget.ArrayAdapter; |
30 |
|
import android.widget.ImageButton; |
31 |
|
import android.widget.ListView; |
32 |
|
import net.sourceforge.subsonic.androidapp.R; |
33 |
|
import net.sourceforge.subsonic.androidapp.domain.Playlist; |
34 |
|
import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory; |
35 |
|
import net.sourceforge.subsonic.androidapp.service.MusicService; |
36 |
|
import net.sourceforge.subsonic.androidapp.util.BackgroundTask; |
37 |
|
import net.sourceforge.subsonic.androidapp.util.Constants; |
38 |
|
import net.sourceforge.subsonic.androidapp.util.TabActivityBackgroundTask; |
39 |
|
import net.sourceforge.subsonic.androidapp.util.Util; |
40 |
|
|
41 |
|
import java.util.List; |
42 |
|
|
|
|
| 82,1% |
Uncovered Elements: 10 (56) |
Complexity: 11 |
Complexity Density: 0,24 |
|
43 |
|
public class SelectPlaylistActivity extends SubsonicTabActivity implements AdapterView.OnItemClickListener { |
44 |
|
|
45 |
|
private static final int MENU_ITEM_PLAY_ALL = 1; |
46 |
|
|
47 |
|
private ListView list; |
48 |
|
private View emptyTextView; |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0,08 |
|
50 |
4
|
@Override... |
51 |
|
public void onCreate(Bundle savedInstanceState) { |
52 |
4
|
super.onCreate(savedInstanceState); |
53 |
4
|
setContentView(R.layout.select_playlist); |
54 |
|
|
55 |
4
|
list = (ListView) findViewById(R.id.select_playlist_list); |
56 |
4
|
emptyTextView = findViewById(R.id.select_playlist_empty); |
57 |
4
|
list.setOnItemClickListener(this); |
58 |
4
|
registerForContextMenu(list); |
59 |
|
|
60 |
|
|
61 |
4
|
setTitle(R.string.playlist_label); |
62 |
|
|
63 |
|
|
64 |
4
|
ImageButton searchButton = (ImageButton)findViewById(R.id.action_button_1); |
65 |
4
|
searchButton.setVisibility(View.GONE); |
66 |
|
|
67 |
|
|
68 |
4
|
ImageButton refreshButton = (ImageButton) findViewById(R.id.action_button_2); |
69 |
4
|
refreshButton.setImageResource(R.drawable.ic_menu_refresh); |
70 |
4
|
refreshButton.setOnClickListener(new View.OnClickListener() { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
0
|
@Override... |
72 |
|
public void onClick(View view) { |
73 |
0
|
refresh(); |
74 |
|
} |
75 |
|
}); |
76 |
|
|
77 |
4
|
load(); |
78 |
|
} |
79 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
80 |
0
|
private void refresh() {... |
81 |
0
|
finish(); |
82 |
0
|
Intent intent = new Intent(this, SelectPlaylistActivity.class); |
83 |
0
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_REFRESH, true); |
84 |
0
|
Util.startActivityWithoutTransition(this, intent); |
85 |
|
} |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
87 |
4
|
private void load() {... |
88 |
4
|
BackgroundTask<List<Playlist>> task = new TabActivityBackgroundTask<List<Playlist>>(this) { |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
89 |
4
|
@Override... |
90 |
|
protected List<Playlist> doInBackground() throws Throwable { |
91 |
4
|
MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this); |
92 |
4
|
boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false); |
93 |
4
|
return musicService.getPlaylists(refresh, SelectPlaylistActivity.this, this); |
94 |
|
} |
95 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
96 |
4
|
@Override... |
97 |
|
protected void done(List<Playlist> result) { |
98 |
4
|
list.setAdapter(new PlaylistAdapter(result)); |
99 |
4
|
emptyTextView.setVisibility(result.isEmpty() ? View.VISIBLE : View.GONE); |
100 |
|
} |
101 |
|
}; |
102 |
4
|
task.execute(); |
103 |
|
} |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
105 |
1
|
@Override... |
106 |
|
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { |
107 |
1
|
super.onCreateContextMenu(menu, view, menuInfo); |
108 |
1
|
menu.add(Menu.NONE, MENU_ITEM_PLAY_ALL, MENU_ITEM_PLAY_ALL, R.string.common_play_now); |
109 |
|
} |
110 |
|
|
|
|
| 84,6% |
Uncovered Elements: 2 (13) |
Complexity: 2 |
Complexity Density: 0,15 |
|
111 |
1
|
@Override... |
112 |
|
public boolean onContextItemSelected(MenuItem menuItem) { |
113 |
1
|
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); |
114 |
1
|
Playlist playlist = (Playlist) list.getItemAtPosition(info.position); |
115 |
|
|
116 |
1
|
switch (menuItem.getItemId()) { |
117 |
1
|
case MENU_ITEM_PLAY_ALL: |
118 |
1
|
Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); |
119 |
1
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); |
120 |
1
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); |
121 |
1
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); |
122 |
1
|
Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); |
123 |
1
|
break; |
124 |
0
|
default: |
125 |
0
|
return super.onContextItemSelected(menuItem); |
126 |
|
} |
127 |
1
|
return true; |
128 |
|
} |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
130 |
1
|
@Override... |
131 |
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
132 |
|
|
133 |
1
|
Playlist playlist = (Playlist) parent.getItemAtPosition(position); |
134 |
|
|
135 |
1
|
Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); |
136 |
1
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); |
137 |
1
|
intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); |
138 |
1
|
Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); |
139 |
|
} |
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
141 |
|
private class PlaylistAdapter extends ArrayAdapter<Playlist> { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
142 |
4
|
public PlaylistAdapter(List<Playlist> playlists) {... |
143 |
4
|
super(SelectPlaylistActivity.this, R.layout.playlist_list_item, playlists); |
144 |
|
} |
145 |
|
} |
146 |
|
} |