Esempio n. 1
0
        private void ConfigureForRemoval()
        {
            var itemsToRemove = new ObservableRangeCollection <BaseMenuItemViewModel> ();

            // Update each item in the list
            foreach (BaseMenuItemViewModel viewModel in ItemViewModels)
            {
                if (viewModel.MenuItemType == MenuItemType.Added)
                {
                    viewModel.MenuItemType = MenuItemType.Remove;
                }
                else
                {
                    itemsToRemove.Add(viewModel);
                }
            }

            // Remove the items that aren't editable
            if (itemsToRemove.Count > 0)
            {
                foreach (BaseMenuItemViewModel viewModel in itemsToRemove)
                {
                    ItemViewModels.Remove(viewModel);
                }
            }

            // Toggle the visibility of the "All accounts are removed" text
            ShowSubtitle = ItemViewModels.Count == 0;
        }
Esempio n. 2
0
        private async Task DeleteItemsAsync()
        {
            LoggingService.Debug($"{LoggingPrefix}DeleteItemsAsync() - Start ");

            var selectedItemViewModelsList = SelectedItemViewModels.ToList();

            var deletionCount = selectedItemViewModelsList.Count;

            if (deletionCount < 1)
            {
                return;
            }

            var dialogService       = Xamarin.Forms.DependencyService.Get <IDialogService>();
            var deleteStringContent = deletionCount > 1 ? $"{deletionCount}" : selectedItemViewModelsList.First().GetModelDisplayString(selectedItemViewModelsList.First().CurrentItem);
            var answer = await dialogService.ConfirmDeletion(deleteStringContent, deletionCount == 1);

            if (answer != true)
            {
                return;
            }

            await Task.Delay(100);

            lock (this.syncObj)
            {
                foreach (var viewModel in selectedItemViewModelsList)
                {
                    var state    = viewModel.InitialState;
                    var newState = ViewStatesHelper.MoveToState(viewModel.State, ViewStates.Deleting);
                    LoggingService.Debug($"{LoggingPrefix}DeleteItemsAsync() - InitialState: {state}; newState: {newState}. ");
                    LoggingService.Debug($"{LoggingPrefix}DeleteItemsAsync() -  Removing from selectedItemViewModels");

                    if (state != ViewStates.Creating && state != ViewStates.UpdatingCreate)
                    {
                        LoggingService.Debug($"{LoggingPrefix}DeleteItemsAsync() - this is an existing item. continuing. ");
                        viewModel.IsSelected = false;
                        viewModel.State      = newState;
                        continue;
                    }

                    LoggingService.Debug($"{LoggingPrefix}DeleteItemsAsync() - newly created item. can be easely discarded.. Removing from ItemViewModels. ");
                    ItemViewModels.Remove(viewModel);
                }

                LoggingService.Debug($"{LoggingPrefix}DeleteItemsAsync() - End ");
                this.RaisePropertyChanged(nameof(WrappedItemViewModels));
            }
        }
Esempio n. 3
0
        private async void OnListItemSelected(IListItem item)
        {
            var viewModel = item as BaseMenuItemViewModel;

            if (MenuState == MenuState.Remove)
            {
                //	if we're in remove mode, this also means this item has to be removed from the list
                ItemViewModels.Remove(viewModel);
                ShowSubtitle = ItemViewModels.Count == 0;
            }
            else
            {
                // If we're not, then that must mean we just added one
                await viewModel.DidLoad();
            }
            var addedCount = ItemViewModels.Count(vm => ((BaseMenuItemViewModel)vm).MenuItemType == MenuItemType.Added || ((BaseMenuItemViewModel)vm).MenuItemType == MenuItemType.Remove);
            //Title =  (addedCount == 0) ? String.Empty : _homeViewModel.GetName();
        }