Clover Coverage Report - Subsonic-Android Coverage Report
Coverage timestamp: ven dic 19 2014 17:57:13 EST
../../../../../img/srcFileCovDistChart5.png 71% of files have more coverage
94   228   32   8,55
36   175   0,34   11
11     2,91  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  SelectArtistActivity       Line # 48 94 32 41,1% 0.4113475
 
No Tests
 
1    /*
2    This file is part of Subsonic.
3   
4    Subsonic is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8   
9    Subsonic is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12    GNU General Public License for more details.
13   
14    You should have received a copy of the GNU General Public License
15    along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
16   
17    Copyright 2009 (C) Sindre Mehus
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   
 
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    * Called when the activity is first created.
59    */
 
60  4 toggle @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    // Button 1: shuffle
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() {
 
83  1 toggle @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    // Button 2: refresh
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() {
 
95  1 toggle @Override
96    public void onClick(View view) {
97  1 refresh();
98    }
99    });
100   
101  4 musicFolders = null;
102  4 load();
103    }
104   
 
105  1 toggle 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   
 
112  0 toggle private void selectFolder() {
113  0 folderButton.showContextMenu();
114    }
115   
 
116  4 toggle private void load() {
117  4 BackgroundTask<Indexes> task = new TabActivityBackgroundTask<Indexes>(this) {
 
118  4 toggle @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   
 
129  4 toggle @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    // Display selected music folder
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   
 
155  0 toggle @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   
 
168  0 toggle @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   
 
196  0 toggle @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    }