Esempio n. 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;
 }
Esempio n. 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();
     }
   }
 }