@Override
 public boolean onOptionsItemSelected(MenuItem item) {
   int id = item.getItemId();
   if (id == R.id.action_reload) {
     ru.ifmo.md.lesson6.RssLoaderService.startActionGetAll(getApplicationContext());
   } else if (id == R.id.action_add) {
     AlertDialog.Builder alert = new AlertDialog.Builder(this);
     final EditText input = new EditText(this);
     input.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
     alert.setView(input);
     String out;
     alert.setPositiveButton(
         R.string.ok,
         new DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
             Editable value = input.getText();
             String url = value.toString();
             try {
               new URL(url);
             } catch (MalformedURLException e) {
               Toast.makeText(
                       MainActivity.this,
                       getString(R.string.invalid_url_entered),
                       Toast.LENGTH_SHORT)
                   .show();
               return;
             }
             ContentValues values = new ContentValues();
             values.put(ru.ifmo.md.lesson6.RssDatabase.Structure.FEEDS_COLUMN_NAME, "Loading...");
             values.put(ru.ifmo.md.lesson6.RssDatabase.Structure.FEEDS_COLUMN_DESCRIPTION, "");
             values.put(ru.ifmo.md.lesson6.RssDatabase.Structure.FEEDS_COLUMN_URL, url);
             Uri uri =
                 getContentResolver()
                     .insert(ru.ifmo.md.lesson6.RssContentProvider.URI_FEED_DIR, values);
             String insertedId = uri.getLastPathSegment();
             getContentResolver()
                 .notifyChange(ru.ifmo.md.lesson6.RssContentProvider.URI_FEED_DIR, null);
             ru.ifmo.md.lesson6.RssLoaderService.startActionGetSingle(
                 getApplicationContext(), (int) Long.parseLong(insertedId));
           }
         });
     alert.setNegativeButton(R.string.cancel, null);
     alert.show();
   }
   return super.onOptionsItemSelected(item);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    getLoaderManager()
        .initLoader(
            0,
            null,
            new LoaderManager.LoaderCallbacks<Cursor>() {
              @Override
              public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
                return new CursorLoader(
                    getApplicationContext(),
                    ru.ifmo.md.lesson6.RssContentProvider.URI_FEED_DIR,
                    new String[] {
                      ru.ifmo.md.lesson6.RssDatabase.Structure.FEEDS_COLUMN_NAME,
                      ru.ifmo.md.lesson6.RssDatabase.Structure.FEEDS_COLUMN_DESCRIPTION,
                      ru.ifmo.md.lesson6.RssDatabase.Structure.FEEDS_COLUMN_URL,
                      ru.ifmo.md.lesson6.RssDatabase.Structure.COLUMN_ROWID,
                      ru.ifmo.md.lesson6.RssDatabase.Structure.COLUMN_ROWID_QUERY
                    },
                    null,
                    null,
                    null);
              }

              @Override
              public void onLoadFinished(Loader<Cursor> objectLoader, Cursor o) {
                ((CursorAdapter) ((ListView) findViewById(R.id.listViewFeeds)).getAdapter())
                    .swapCursor(o);
              }

              @Override
              public void onLoaderReset(Loader<Cursor> objectLoader) {}
            });

    ((ListView) findViewById(R.id.listViewFeeds)).setAdapter(new FeedListAdapter(this, null, true));
    TextView w = new TextView(this);
    w.setText(getString(R.string.no_feeds));
    ((ListView) findViewById(R.id.listViewFeeds)).setEmptyView(w);

    ru.ifmo.md.lesson6.RssLoaderService.startActionGetAll(getApplicationContext());
  }