Clover Coverage Report - Subsonic-Android Coverage Report
Coverage timestamp: ven dic 19 2014 17:57:13 EST
../../../../../img/srcFileCovDistChart9.png 32% of files have more coverage
46   146   12   4,6
2   102   0,26   5
10     1,2  
2    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  SelectPlaylistActivity       Line # 43 45 11 82,1% 0.8214286
  SelectPlaylistActivity.PlaylistAdapter       Line # 141 1 1 100% 1.0
 
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.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   
 
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   
 
50  4 toggle @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    // Title: Playlists
61  4 setTitle(R.string.playlist_label);
62   
63    // Button 1: gone
64  4 ImageButton searchButton = (ImageButton)findViewById(R.id.action_button_1);
65  4 searchButton.setVisibility(View.GONE);
66   
67    // Button 2: refresh
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() {
 
71  0 toggle @Override
72    public void onClick(View view) {
73  0 refresh();
74    }
75    });
76   
77  4 load();
78    }
79   
 
80  0 toggle 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   
 
87  4 toggle private void load() {
88  4 BackgroundTask<List<Playlist>> task = new TabActivityBackgroundTask<List<Playlist>>(this) {
 
89  4 toggle @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   
 
96  4 toggle @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   
 
105  1 toggle @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   
 
111  1 toggle @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   
 
130  1 toggle @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   
 
141    private class PlaylistAdapter extends ArrayAdapter<Playlist> {
 
142  4 toggle public PlaylistAdapter(List<Playlist> playlists) {
143  4 super(SelectPlaylistActivity.this, R.layout.playlist_list_item, playlists);
144    }
145    }
146    }