Пример #1
0
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   AdapterView.AdapterContextMenuInfo info =
       (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
   Playlist playlist = adapter.getItem(info.position);
   int menuItemIndex = item.getItemId();
   switch (menuItemIndex) {
     case 0:
       Intent intent = new Intent(this, EditPlaylistScreen.class);
       intent.putExtra(DatabaseHelper.FIELD_ID, playlist.getId());
       startActivityForResult(intent, EDIT_PLAYLIST_REQUEST_CODE);
       break;
     case 1:
       if (playlist.isSelected() && playlists.size() > 1) {
         Toast.makeText(this, R.string.playlist_is_selected, Toast.LENGTH_SHORT).show();
       } else {
         dbManager.deletePlaylist(playlist);
         playlists = dbManager.getPlaylists();
         adapter.setPlaylists(playlists);
         adapter.notifyDataSetChanged();
         if (playlists == null || playlists.isEmpty()) {
           preferences.putString(Preferences.KEY_PLAYLIST, Preferences.DEFAULT_PLAYLIST);
           setResult(RESULT_OK);
           finish();
         }
       }
       break;
   }
   return true;
 }
Пример #2
0
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (resultCode == RESULT_OK) {
     if (requestCode == ADD_PLAYLIST_REQUEST_CODE || requestCode == EDIT_PLAYLIST_REQUEST_CODE) {
       playlists = dbManager.getPlaylists();
       adapter.setPlaylists(playlists);
       adapter.notifyDataSetChanged();
     }
   }
 }
Пример #3
0
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   Playlist playlist = adapter.getItem(position);
   dbManager.setSelectedPlaylist(playlist);
   preferences.putString(Preferences.KEY_PLAYLIST, playlist.getName());
   setResult(RESULT_OK);
   finish();
 }
Пример #4
0
 @Override
 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
   if (v.getId() == R.id.list) {
     AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
     Playlist playlist = adapter.getItem(info.position);
     menu.setHeaderTitle(playlist.getName());
     String[] menuItems = {getString(R.string.edit), getString(R.string.delete)};
     for (int i = 0; i < menuItems.length; i++) {
       menu.add(Menu.NONE, i, i, menuItems[i]);
     }
   }
 }