+ // Disable the options `MenuItems`.
+ deleteMenuItem.setEnabled(false);
+ deleteMenuItem.setIcon(R.drawable.delete_blue);
+ saveMenuItem.setEnabled(false);
+
+ // Display a `Snackbar`.
+ Snackbar.make(domainsListView, R.string.domain_deleted, Snackbar.LENGTH_LONG)
+ .setAction(R.string.undo, new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ // Do nothing because everything will be handled by `onDismissed()` below.
+ }
+ })
+ .addCallback(new Snackbar.Callback() {
+ @Override
+ public void onDismissed(Snackbar snackbar, int event) {
+ switch (event) {
+ // The user pushed the `Undo` button.
+ case Snackbar.Callback.DISMISS_EVENT_ACTION:
+ // Get a `Cursor` with the current contents of the domains database.
+ Cursor undoDeleteDomainsCursor = domainsDatabaseHelper.getDomainNameCursorOrderedByDomain();
+
+ // Setup `domainsCursorAdapter` with `this` context. `false` disables `autoRequery`.
+ CursorAdapter undoDeleteDomainsCursorAdapter = new CursorAdapter(context, undoDeleteDomainsCursor, false) {
+ @Override
+ public View newView(Context context, Cursor cursor, ViewGroup parent) {
+ // Inflate the individual item layout. `false` does not attach it to the root.
+ return getLayoutInflater().inflate(R.layout.domain_name_linearlayout, parent, false);
+ }
+
+ @Override
+ public void bindView(View view, Context context, Cursor cursor) {
+ // Set the domain name.
+ String domainNameString = cursor.getString(cursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME));
+ TextView domainNameTextView = (TextView) view.findViewById(R.id.domain_name_textview);
+ domainNameTextView.setText(domainNameString);
+ }
+ };
+
+ // Update the `ListView`.
+ domainsListView.setAdapter(undoDeleteDomainsCursorAdapter);
+
+ // Select the entry in the domain list at `currentPosition`.
+ domainsListView.setItemChecked(currentPosition, true);
+
+ // Store `databaseId` in `argumentsBundle`.
+ Bundle argumentsBundle = new Bundle();
+ argumentsBundle.putInt(DomainSettingsFragment.DATABASE_ID, databaseId);
+
+ // Add `argumentsBundle` to `domainSettingsFragment`.
+ DomainSettingsFragment domainSettingsFragment = new DomainSettingsFragment();
+ domainSettingsFragment.setArguments(argumentsBundle);
+
+ // Display `domainSettingsFragment`.
+ getSupportFragmentManager().beginTransaction().replace(R.id.domain_settings_scrollview, domainSettingsFragment).commit();
+
+ // Enable the options `MenuItems`.
+ deleteMenuItem.setEnabled(true);
+ deleteMenuItem.setIcon(R.drawable.delete);
+ saveMenuItem.setEnabled(true);
+ break;
+
+ // The `Snackbar` was dismissed without the `Undo` button being pushed.
+ default:
+ // Delete the selected domain.
+ domainsDatabaseHelper.deleteDomain(databaseId);
+ break;
+ }
+ }
+ })
+ .show();