private async void OnRenameDialogSubmit(object sender, EditCategoryBottomSheet.EditCategoryEventArgs e) { var dialog = (EditCategoryBottomSheet)sender; if (e.Name == e.InitialName) { dialog.Dismiss(); return; } var category = new Category(e.Name); if (_categorySource.IsDuplicate(category)) { dialog.NameError = GetString(Resource.String.duplicateCategory); return; } await _categorySource.Rename(e.ItemPosition.Value, e.Name); RunOnUiThread(delegate { dialog.Dismiss(); _categoryListAdapter.NotifyItemChanged(e.ItemPosition.Value); }); }
private async void OnRenameDialogSubmit(object sender, EditCategoryBottomSheet.EditCategoryEventArgs e) { var dialog = (EditCategoryBottomSheet)sender; if (e.Name == e.InitialName || e.ItemPosition == null) { dialog.Dismiss(); return; } var category = new Category(e.Name); if (_categorySource.IsDuplicate(category)) { dialog.NameError = GetString(Resource.String.duplicateCategory); return; } try { await _categorySource.Rename(e.ItemPosition.Value, e.Name); } catch { ShowSnackbar(Resource.String.genericError, Snackbar.LengthShort); return; } finally { RunOnUiThread(dialog.Dismiss); } RunOnUiThread(delegate { _categoryListAdapter.NotifyItemChanged(e.ItemPosition.Value); }); }
private async void OnRenameDialogSubmit(object sender, EditCategoryBottomSheet.EditCategoryEventArgs args) { var dialog = (EditCategoryBottomSheet)sender; if (args.Name == args.InitialName || args.Position == -1) { dialog.Dismiss(); return; } var currentId = _categorySource.Get(args.Position).Id; var isDefault = _preferences.DefaultCategory == currentId; var category = new Category(args.Name); if (_categorySource.Exists(category)) { dialog.NameError = GetString(Resource.String.duplicateCategory); return; } try { await _categorySource.Rename(args.Position, args.Name); } catch (Exception e) { Logger.Error(e); ShowSnackbar(Resource.String.genericError, Snackbar.LengthShort); return; } finally { RunOnUiThread(dialog.Dismiss); } if (isDefault) { SetDefaultCategory(category.Id); } RunOnUiThread(delegate { _categoryListAdapter.NotifyItemChanged(args.Position); }); }
private async void RenameDialogPositive(object sender, EventArgs e) { if (_renameDialog.Name.Trim() == "") { _renameDialog.Error = GetString(Resource.String.noCategoryName); return; } var category = new Category(_renameDialog.Name.Truncate(32)); if (_categorySource.IsDuplicate(category)) { _renameDialog.Error = GetString(Resource.String.duplicateCategory); return; } _renameDialog.Dismiss(); await _categorySource.Rename(_renamePosition, _renameDialog.Name); _categoryAdapter.NotifyItemChanged(_renamePosition); }