@Override public void onDialogPositiveClick(DialogFragment dialog) { Dialog dialogView = dialog.getDialog(); String stringName = ((EditText) dialogView.findViewById(R.id.dialog_store_name)).getText().toString(); if (editIndex == -1) { if (!stringName.isEmpty()) { Store store = new Store(stringName); long rowId = mStoreDbAdapter.insertStore(store); store.setId(rowId); mStoreList.add(store); } } else { mStoreList.get(editIndex).setName(stringName); mStoreDbAdapter.updateStore(mStoreList.get(editIndex)); editIndex = -1; } if (!stringName.isEmpty()) { mStoreAdaptor.notifyDataSetChanged(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_store); Toolbar toolbar = (Toolbar) findViewById(R.id.store_toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Utils.showDialog(StoreListActivity.this, Constants.STORE_INPUT_DIALOG, null); } }); mStoreDbAdapter = StoreDbAdapter.getInstance(); getSupportLoaderManager().initLoader(LOADER_ID, null, this).forceLoad(); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { String stringName; super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case Constants.RESULT_SPEECH_OUTPUT: if (resultCode == RESULT_OK && data != null) { ArrayList<String> text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); stringName = text.get(0); if (stringName != null && !stringName.isEmpty()) { Store store = new Store(stringName); long rowId = mStoreDbAdapter.insertStore(store); Log.d(LOG_TAG, "Insert ret val: " + rowId); store.setId(rowId); mStoreList.add(store); mStoreAdaptor.notifyDataSetChanged(); } } break; default: Log.w(LOG_TAG, "Not handled speech resultCode"); break; } }
@Override public List<Store> loadInBackground() { return (StoreDbAdapter.getInstance().getStoreCount() == 0) ? new ArrayList<Store>() : (ArrayList<Store>) StoreDbAdapter.getInstance().getAllStore(); }