@Override
  public void onRefreshEnd() {
    if (!Controller.getInstance().getTTRSSConnector().hasLastError()) {
      mAdapter.notifyDataSetChanged();

      if (mFeedTitle != null) {
        this.setTitle(
            this.getResources().getString(R.string.ApplicationName)
                + " - "
                + mFeedTitle
                + " ("
                + mAdapter.getUnreadCount()
                + ")");
      } else {
        this.setTitle(
            this.getResources().getString(R.string.ApplicationName)
                + " ("
                + mAdapter.getUnreadCount()
                + ")");
      }
    } else {
      openConnectionErrorDialog(Controller.getInstance().getTTRSSConnector().getLastError());
    }

    mProgressDialog.dismiss();
  }
  @Override
  public Cursor createCursor(
      SQLiteDatabase db, boolean overrideDisplayUnread, boolean buildSafeQuery) {
    boolean displayUnread = Controller.getInstance().onlyUnread();
    boolean invertSortFeedCats = Controller.getInstance().invertSortFeedscats();

    if (overrideDisplayUnread) displayUnread = false;

    Cursor cur;
    synchronized (LOCK) {
      memoryDb.delete(MemoryDBOpenHelper.TABLE_NAME, null, null);

      StringBuilder query;
      // Virtual Feeds
      if (Controller.getInstance().showVirtual()) {
        query = new StringBuilder();
        query.append("SELECT _id,title,unread FROM ");
        query.append(DBHelper.TABLE_CATEGORIES);
        query.append(" WHERE _id>=-4 AND _id<0 ORDER BY _id");
        insertValues(db, query.toString());
      }

      // Labels
      query = new StringBuilder();
      query.append("SELECT _id,title,unread FROM ");
      query.append(DBHelper.TABLE_FEEDS);
      query.append(" WHERE _id<-10");
      query.append(displayUnread ? " AND unread>0" : "");
      query.append(" ORDER BY UPPER(title) ASC");
      query.append(" LIMIT 500 ");
      insertValues(db, query.toString());

      // "Uncategorized Feeds"
      query = new StringBuilder();
      query.append("SELECT _id,title,unread FROM ");
      query.append(DBHelper.TABLE_CATEGORIES);
      query.append(" WHERE _id=0");
      insertValues(db, query.toString());

      // Categories
      query = new StringBuilder();
      query.append("SELECT _id,title,unread FROM ");
      query.append(DBHelper.TABLE_CATEGORIES);
      query.append(" WHERE _id>0");
      query.append(displayUnread ? " AND unread>0" : "");
      query.append(" ORDER BY UPPER(title) ");
      query.append(invertSortFeedCats ? "DESC" : "ASC");
      query.append(" LIMIT 500 ");
      insertValues(db, query.toString());

      String[] columns = {"_id", "title", "unread"};
      cur =
          memoryDb.query(
              MemoryDBOpenHelper.TABLE_NAME, columns, null, null, null, null, null, "600");
    }
    return cur;
  }
  private void doRefresh() {

    Controller.getInstance().setRefreshNeeded(false);

    mProgressDialog =
        ProgressDialog.show(
            this, "Refreshing", this.getResources().getString(R.string.Commons_PleaseWait));

    if (mAdapter == null) {
      mAdapter = new FeedHeadlineListAdapter(this, mFeedId);
      mFeedHeadlineListView.setAdapter(mAdapter);
    }
    new Refresher(this, mAdapter);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.feedlist);

    Controller.getInstance().checkAndInitializeController(this);

    mFeedHeadlineListView = getListView();

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      mFeedId = extras.getString(FEED_ID);
      mFeedTitle = extras.getString(FEED_TITLE);
    } else if (savedInstanceState != null) {
      mFeedId = savedInstanceState.getString(FEED_ID);
      mFeedTitle = savedInstanceState.getString(FEED_TITLE);
    } else {
      mFeedId = "-1";
      mFeedTitle = null;
    }
  }