/// <summary> /// Get the selected simple and Genre tags and determine if there has been any changes /// </summary> private void OnOk(MultiSpinner genreSpinner, Spinner tagSpinner) { // Get the selected record from the Genre spinner. If not all of the items are selected then add an entry for each selected item to a new TagGroup List <TagGroup> selectedGroups = new List <TagGroup>(); if (genreSpinner.SelectionRecord.All(genre => genre) == false) { TagGroup group = new TagGroup() { Name = FilterManagementModel.GenreTags.Name }; selectedGroups.Add(group); // Merge the Spinner's selection record and the Genre tags into a single list and then add to the new group any tags that are selected IEnumerable <Tuple <bool, Tag> > merged = genreSpinner.SelectionRecord.Zip(FilterManagementModel.GenreTags.Tags, (x, y) => Tuple.Create(x, y)); group.Tags.AddRange(merged.Where(t => (t.Item1 == true)).Select(t => t.Item2)); } // Get the simple tag Tag newTag = (tagSpinner.SelectedItemPosition == 0) ? null : Tags.GetTagByName(tagSpinner.SelectedItem.ToString()); // Check for simple or group tag changes if ((newTag != CurrentlySelectedFilter) || (selectedGroups.Count != CurrentlySelectedTagGroups.Count) || (selectedGroups.Any(group => GroupChanged(group)) == true)) { // Update the FilterManagementModel TagGroups with the possibly updated data from the Adapter CurrentlySelectedTagGroups.Clear(); CurrentlySelectedTagGroups.AddRange(selectedGroups); SelectionDelegate?.Invoke(newTag); } }
/// <summary> /// Create the dialogue. When a library is selected pass it to the ScanProgressDialogFragment /// </summary> /// <param name="savedInstanceState"></param> /// <returns></returns> public override Dialog OnCreateDialog(Bundle savedInstanceState) { // Initialise the controls holding the simple Tags and Genres View dialogView = LayoutInflater.From(Context).Inflate(Resource.Layout.filter_selection_dialogue_layout, null); Spinner tagSpinner = dialogView.FindViewById <Spinner>(Resource.Id.simpleTags); MultiSpinner genreSpinner = dialogView.FindViewById <MultiSpinner>(Resource.Id.genreSpinner); InitialiseTagSpinner(tagSpinner); InitialiseGenreSpinner(genreSpinner); return(new AlertDialog.Builder(Context) .SetTitle("Apply filter") .SetView(dialogView) .SetPositiveButton("OK", delegate { OnOk(genreSpinner, tagSpinner); }) .SetNegativeButton("Cancel", delegate { }) .Create()); }
/// <summary> /// Initialise the contents of the Genre spinner /// </summary> /// <param name="genreSpinner"></param> private void InitialiseGenreSpinner(MultiSpinner genreSpinner) { // Get the currently selected Genre items from the CurrentlySelectedTagGroups. // If there is no Genre TagGroup then all the Genre items are selected. // Otherwise only the items in the TagGroup are selected bool[] selected = Enumerable.Repeat(true, FilterManagementModel.GenreTags.Tags.Count).ToArray(); // Is there a Genre TagGroup TagGroup genreGroup = CurrentlySelectedTagGroups.FirstOrDefault(group => (group.Name == FilterManagementModel.GenreTags.Name)); if (genreGroup != null) { // Set the selected flag for each tag according to whether or not it is in the TagGroup for (int genreIndex = 0; genreIndex < FilterManagementModel.GenreTags.Tags.Count; ++genreIndex) { selected[genreIndex] = genreGroup.Tags.Exists(tag => tag.Name == FilterManagementModel.GenreTags.Tags[genreIndex].Name); } } // Display the names of all the genre tags in a multi-select spinner genreSpinner.SetItems(FilterManagementModel.GenreTags.Tags.Select(ta => ta.Name).ToList(), selected, "All"); }