/** {@inheritDoc} */
 @Override
 protected void onUserChanged() {
   mAdapter.clear();
   mAdapter.addAll(Mobeelizer.getDatabase().list(SimpleSyncEntity.class));
   mAdapter.sort(new SimpleSyncEntity());
   mAdapter.notifyDataSetChanged();
 }
  /** {@inheritDoc} */
  @Override
  protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.a_list_with_buttons);
    initTitleBarViews();
    setTitleBarTitle(R.string.titleBarSimpleSync);

    mAddButton = (Button) findViewById(R.id.footerAdd);
    mSyncButton = (Button) findViewById(R.id.footerSync);
    mInfoButton = (ImageButton) findViewById(R.id.footerInfo);
    mList = (ListView) findViewById(android.R.id.list);

    mAddButton.setOnClickListener(getOnAddClickListener());
    mSyncButton.setOnClickListener(getOnSyncClickListener());
    mInfoButton.setOnClickListener(getOnInfoClickListener());

    // clip the add button drawable
    UIUtils.prepareClip(mAddButton);
    // clip the sync button drawable
    UIUtils.prepareClip(mSyncButton);

    boolean initialized = mSharedPrefs.getBoolean(this.getClass().getSimpleName(), false);

    List<SimpleSyncEntity> data = Mobeelizer.getDatabase().list(SimpleSyncEntity.class);
    if (!initialized) {
      showDialog(D_SIMPLE_SYNC);
      mSharedPrefs.edit().putBoolean(this.getClass().getSimpleName(), true).commit();
    }

    mAdapter = new SimpleSyncAdapter(this, data);
    mAdapter.sort(new SimpleSyncEntity());
    mList.setAdapter(mAdapter);
  }
  /** {@inheritDoc} */
  @Override
  public void onSyncFinished(final MobeelizerSyncStatus status) {
    Bundle b = null;
    // If synchronization succeeded show examples list. Otherwise show an error dialog
    switch (status) {
      case FINISHED_WITH_SUCCESS:
        // get newly synchronized items from database
        final List<SimpleSyncEntity> newList =
            Mobeelizer.getDatabase().list(SimpleSyncEntity.class);
        // get old items from list adapter
        final List<SimpleSyncEntity> oldList = mAdapter.getItems();

        // merge new items to old list and mark them as new,
        // find removed items in old list and mark them as such
        mergeLists(oldList, newList);
        mAdapter.sort(new SimpleSyncEntity());
        // refresh the list to display animation
        mAdapter.notifyDataSetChanged();
        mList.setSelection(0);

        break;
      case FINISHED_WITH_FAILURE:
        b = new Bundle();
        b.putBoolean(BaseActivity.IS_INFO, false);
        b.putInt(BaseActivity.TEXT_RES_ID, R.string.e_syncFailed);
        break;
      case NONE:
        b = new Bundle();
        b.putBoolean(BaseActivity.IS_INFO, true);
        b.putInt(BaseActivity.TEXT_RES_ID, R.string.e_syncDisabled);
        break;
    }

    if (mSyncDialog != null) {
      mSyncDialog.dismiss();
    }

    // show dialog with synchronization status
    if (b != null) {
      SimpleSyncActivity.this.showDialog(BaseActivity.D_CUSTOM, b);
    }
  }