예제 #1
0
        void AddRowToLayout(SearchRow item)
        {
            var row = new LinearLayout(context)
            {
                Orientation = Orientation.Horizontal
            };

            row.LayoutParameters = new ViewGroup.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent);
            row.WeightSum        = 1;

            row.SetMinimumHeight(PixelConverter.DpToPixels(30));

            LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MatchParent, 0.5f);
            LinearLayout.LayoutParams f = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
            var entryHolder             = new LinearLayout(context);

            entryHolder.Orientation = Orientation.Horizontal;
            entryHolder.SetHorizontalGravity(GravityFlags.Right);
            entryHolder.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
            entryHolder.ShowDividers     = ShowDividers.Middle;
            entryHolder.DividerPadding   = 20;
            entryHolder.SetPadding(PixelConverter.DpToPixels(10), 0, 0, 0);

            switch (item.RowType)
            {
            case SearchRowTypes.Heading:
                row.AddView(Heading(item));

                break;

            case SearchRowTypes.SearchTerms:
                EditText searchfield = new EditText(context);
                searchfield.LayoutParameters = f;
                searchfield.Hint             = string.Format("Search {0}:", this.category.Value);
                searchfield.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                searchfield.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), (int)(rowHeight * 0.1), (int)(rowHeight * 0.15));
                searchfield.SetSingleLine(true);
                searchfield.InputType = InputTypes.ClassText;
                row.AddView(searchfield);

                searchfield.TextChanged += (object sender, TextChangedEventArgs e) =>
                {
                    AddSearchItem(item.QueryPrefix, e.Text.ToString());
                };

                break;

            case SearchRowTypes.PriceDoubleEntry:
                row.AddView(Title(item));

                EditText minPricefield = new EditText(context);
                minPricefield.LayoutParameters = p;
                minPricefield.Hint             = "min";
                minPricefield.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                minPricefield.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), (int)(rowHeight * 0.1), (int)(rowHeight * 0.15));
                minPricefield.SetSingleLine(true);
                minPricefield.InputType = InputTypes.ClassNumber;
                entryHolder.AddView(minPricefield);

                EditText maxPricefield = new EditText(context);
                maxPricefield.LayoutParameters = p;
                maxPricefield.Hint             = "max";
                maxPricefield.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                maxPricefield.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), (int)(rowHeight * 0.1), (int)(rowHeight * 0.15));
                maxPricefield.SetSingleLine(true);
                maxPricefield.InputType = InputTypes.ClassNumber;
                entryHolder.AddView(maxPricefield);

                minPricefield.TextChanged += (object sender, TextChangedEventArgs e) =>
                {
                    //TODO: Get this text masking to work correctly
                    //string text = minPricefield.Text;
                    //if (text.Length > 0 && text.Substring(0, 1) == "$")
                    //    minPricefield.Text = text;
                    //else
                    //    minPricefield.Text = "$" + text;

                    AddSearchItem(item.QueryPrefix, e.Text.ToString());
                };

                maxPricefield.TextChanged += (object sender, TextChangedEventArgs e) =>
                {
                    //string text = maxPricefield.Text;
                    //if (text.Length > 0 && text.Substring(0, 1) == "$")
                    //    maxPricefield.SetText(text, null);
                    //else
                    //    maxPricefield.Text = "$" + text;

                    AddSearchItem(item.SecondQueryPrefix, e.Text.ToString());
                };

                row.AddView(entryHolder);
                break;

            case SearchRowTypes.DoubleEntry:
                row.AddView(Title(item));

                EditText minfield = new EditText(context);
                minfield.LayoutParameters = p;

                minfield.Hint = "min";
                minfield.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                minfield.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), (int)(rowHeight * 0.1), (int)(rowHeight * 0.15));
                minfield.SetSingleLine(true);
                minfield.InputType = InputTypes.ClassNumber;
                entryHolder.AddView(minfield);

                EditText maxfield = new EditText(context);
                maxfield.LayoutParameters = p;
                maxfield.Hint             = "max";
                maxfield.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                maxfield.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), (int)(rowHeight * 0.1), (int)(rowHeight * 0.15));
                maxfield.SetSingleLine(true);
                maxfield.InputType = InputTypes.ClassNumber;
                entryHolder.AddView(maxfield);

                minfield.TextChanged += (object sender, TextChangedEventArgs e) =>
                {
                    AddSearchItem(item.QueryPrefix, e.Text.ToString());
                };

                maxfield.TextChanged += (object sender, TextChangedEventArgs e) =>
                {
                    AddSearchItem(item.SecondQueryPrefix, e.Text.ToString());
                };

                row.AddView(entryHolder);

                break;

            case SearchRowTypes.SingleEntryLabel:
                row.AddView(Title(item));

                EditText inputField = new EditText(context);
                inputField.LayoutParameters = f;

                inputField.Hint = "make / model";
                inputField.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                inputField.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), (int)(rowHeight * 0.1), (int)(rowHeight * 0.15));
                inputField.SetSingleLine(true);
                entryHolder.AddView(inputField);

                inputField.TextChanged += (object sender, TextChangedEventArgs e) =>
                {
                    AddSearchItem(item.QueryPrefix, e.Text.ToString());
                };

                row.AddView(entryHolder);
                break;

            case SearchRowTypes.SinglePicker:
                row.AddView(Title(item));

                TextView display = new TextView(context);
                display.LayoutParameters = f;
                display.Gravity          = GravityFlags.Right;
                display.Text             = "Any";
                display.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                display.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), PixelConverter.DpToPixels(50), (int)(rowHeight * 0.15));

                var dialog = new NumberPickerDialogFragment(context, item.Title, item.NumberPickerOptions, item.QueryPrefix);
                display.Click += (object sender, EventArgs e) =>
                {
                    dialog.Show(((Activity)context).FragmentManager, "number");
                };

                dialog.NumberChanged += (object sender, NumberPickerDialogFragment.NumberPickerValueChanged e) =>
                {
                    display.Text = e.Value.ToString() + item.NumberPickerOptions.DisplaySuffix;
                    AddSearchItem(e.CallerKey, e.Value.ToString());
                };

                row.AddView(display);

                break;

            case SearchRowTypes.ComboPicker:
                row.AddView(Title(item));

                TextView comboLabel = new TextView(context);
                comboLabel.LayoutParameters = f;
                comboLabel.Gravity          = GravityFlags.Right;
                comboLabel.Text             = "Any";
                comboLabel.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                comboLabel.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), PixelConverter.DpToPixels(50), (int)(rowHeight * 0.15));

                var comboDialog = new ComboPickerDialogFragment(context, item.Title, item.ComboPickerOptions);

                comboLabel.Click += (object sender, EventArgs e) =>
                {
                    var selectedKeys = (from kvp in Conditions where (string)kvp.Value.Key == item.QueryPrefix select(string) kvp.Key).ToList();
                    comboDialog._selectedKeys = selectedKeys;
                    comboDialog.Show(((Activity)context).FragmentManager, "combo");
                };

                comboDialog.ItemChanged += (object sender, ComboPickerItemChangedEventArgs e) =>
                {
                    if (e.InitialArgs.IsChecked)
                    {
                        Conditions.Add(e.Item.Key, new KeyValuePair <object, object>(item.QueryPrefix, e.Item.Value));
                        Console.WriteLine("Added Key: " + e.Item.Key + ", Value: " + e.Item.Value + " with prefix: " + item.QueryPrefix);
                    }
                    else
                    {
                        Conditions.Remove(e.Item.Key);
                        Console.WriteLine("Removed Key: " + e.Item.Key + ", Value: " + e.Item.Value);
                    }

                    var keys = (from kvp in Conditions where (string)kvp.Value.Key == item.QueryPrefix select(string) kvp.Key).ToList();
                    var text = keys.Count > 0 ? string.Join(", ", keys.ToArray()) : "Any";
                    comboLabel.Text = text;
                };

                row.AddView(comboLabel);

                break;

            case SearchRowTypes.SubCatPicker:
                row.AddView(Title(item));

                TextView catLabel = new TextView(context);
                catLabel.LayoutParameters = f;
                catLabel.Gravity          = GravityFlags.Right;
                catLabel.Text             = (string)item.ComboPickerOptions.First().Key;

                catLabel.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                catLabel.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), PixelConverter.DpToPixels(50), (int)(rowHeight * 0.15));

                if (item.Title == "Sub Category")
                {
                    SubCategory = item.ComboPickerOptions.First();
                }

                var categoryDialog = new SingleStringDialogFragment(context, item.Title, item.ComboPickerOptions);

                catLabel.Click += (object sender, EventArgs e) =>
                {
                    categoryDialog.Show(((Activity)context).FragmentManager, "stringPick");
                };

                categoryDialog.CatPicked += (object sender, SubCatSelectedEventArgs e) =>
                {
                    categoryDialog.Dismiss();

                    if (item.Title != "Posted Date" && item.Title != "Max Listings")
                    {
                        SubCategory = e.SubCatPicked;
                    }
                    else if (item.Title == "Posted Date")
                    {
                        WeeksOld = (int?)e.SubCatPicked.Value;
                    }
                    else if (item.Title == "Max Listings")
                    {
                        MaxListings = (int)e.SubCatPicked.Value;
                    }

                    catLabel.Text = (string)e.SubCatPicked.Key;
                };

                row.AddView(catLabel);
                break;

            case SearchRowTypes.Space:
                View strut = new View(context);
                strut.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent,
                                                                    PixelConverter.DpToPixels(25));
                row.ShowDividers = ShowDividers.None;
                row.AddView(strut);
                break;

            default:
                row.AddView(Title(item));

                break;
            }

            AddView(row);
        }
        void AddRowToLayout(SearchRow item)
        {
            var row = new LinearLayout(context) { Orientation = Orientation.Horizontal };
            row.LayoutParameters = new ViewGroup.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent);
            row.WeightSum = 1;

            row.SetMinimumHeight(PixelConverter.DpToPixels(30));

            LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MatchParent, 0.5f);
            LinearLayout.LayoutParams f = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
            var entryHolder = new LinearLayout(context);
            entryHolder.Orientation = Orientation.Horizontal;
            entryHolder.SetHorizontalGravity(GravityFlags.Right);
            entryHolder.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
            entryHolder.ShowDividers = ShowDividers.Middle;
            entryHolder.DividerPadding = 20;
            entryHolder.SetPadding(PixelConverter.DpToPixels(10), 0, 0, 0);

            switch (item.RowType)
            {
                case SearchRowTypes.Heading:
                    row.AddView(Heading(item));

                    break;
                case SearchRowTypes.SearchTerms:
                    EditText searchfield = new EditText(context);
                    searchfield.LayoutParameters = f;
                    searchfield.Hint = string.Format("Search {0}:", this.category.Value);
                    searchfield.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                    searchfield.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), (int)(rowHeight * 0.1), (int)(rowHeight * 0.15));
                    searchfield.SetSingleLine(true);
                    searchfield.InputType = InputTypes.ClassText;
                    row.AddView(searchfield);

                    searchfield.TextChanged += (object sender, TextChangedEventArgs e) =>
                    {
                        AddSearchItem(item.QueryPrefix, e.Text.ToString());
                    };

                    break;
                case SearchRowTypes.PriceDoubleEntry:
                    row.AddView(Title(item));

                    EditText minPricefield = new EditText(context);
                    minPricefield.LayoutParameters = p;
                    minPricefield.Hint = "min";
                    minPricefield.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                    minPricefield.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), (int)(rowHeight * 0.1), (int)(rowHeight * 0.15));
                    minPricefield.SetSingleLine(true);
                    minPricefield.InputType = InputTypes.ClassNumber;
                    entryHolder.AddView(minPricefield);

                    EditText maxPricefield = new EditText(context);
                    maxPricefield.LayoutParameters = p;
                    maxPricefield.Hint = "max";
                    maxPricefield.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                    maxPricefield.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), (int)(rowHeight * 0.1), (int)(rowHeight * 0.15));
                    maxPricefield.SetSingleLine(true);
                    maxPricefield.InputType = InputTypes.ClassNumber;
                    entryHolder.AddView(maxPricefield);

                    minPricefield.TextChanged += (object sender, TextChangedEventArgs e) =>
                    {
                        //TODO: Get this text masking to work correctly
                        //string text = minPricefield.Text;
                        //if (text.Length > 0 && text.Substring(0, 1) == "$")
                        //    minPricefield.Text = text;
                        //else
                        //    minPricefield.Text = "$" + text;

                        AddSearchItem(item.QueryPrefix, e.Text.ToString());
                    };

                    maxPricefield.TextChanged += (object sender, TextChangedEventArgs e) =>
                    {
                        //string text = maxPricefield.Text;
                        //if (text.Length > 0 && text.Substring(0, 1) == "$")
                        //    maxPricefield.SetText(text, null);
                        //else
                        //    maxPricefield.Text = "$" + text;

                        AddSearchItem(item.SecondQueryPrefix, e.Text.ToString());
                    };

                    row.AddView(entryHolder);
                    break;

                case SearchRowTypes.DoubleEntry:
                    row.AddView(Title(item));

                    EditText minfield = new EditText(context);
                    minfield.LayoutParameters = p;

                    minfield.Hint = "min";
                    minfield.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                    minfield.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), (int)(rowHeight * 0.1), (int)(rowHeight * 0.15));
                    minfield.SetSingleLine(true);
                    minfield.InputType = InputTypes.ClassNumber;
                    entryHolder.AddView(minfield);

                    EditText maxfield = new EditText(context);
                    maxfield.LayoutParameters = p;
                    maxfield.Hint = "max";
                    maxfield.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                    maxfield.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), (int)(rowHeight * 0.1), (int)(rowHeight * 0.15));
                    maxfield.SetSingleLine(true);
                    maxfield.InputType = InputTypes.ClassNumber;
                    entryHolder.AddView(maxfield);

                    minfield.TextChanged += (object sender, TextChangedEventArgs e) =>
                    {
                        AddSearchItem(item.QueryPrefix, e.Text.ToString());
                    };

                    maxfield.TextChanged += (object sender, TextChangedEventArgs e) =>
                    {
                        AddSearchItem(item.SecondQueryPrefix, e.Text.ToString());
                    };

                    row.AddView(entryHolder);

                    break;
                case SearchRowTypes.SingleEntryLabel:
                    row.AddView(Title(item));

                    EditText inputField = new EditText(context);
                    inputField.LayoutParameters = f;

                    inputField.Hint = "make / model";
                    inputField.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                    inputField.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), (int)(rowHeight * 0.1), (int)(rowHeight * 0.15));
                    inputField.SetSingleLine(true);
                    entryHolder.AddView(inputField);

                    inputField.TextChanged += (object sender, TextChangedEventArgs e) =>
                    {
                        AddSearchItem(item.QueryPrefix, e.Text.ToString());
                    };

                    row.AddView(entryHolder);
                    break;
                case SearchRowTypes.SinglePicker:
                    row.AddView(Title(item));

                    TextView display = new TextView(context);
                    display.LayoutParameters = f;
                    display.Gravity = GravityFlags.Right;
                    display.Text = "Any";
                    display.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                    display.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), PixelConverter.DpToPixels(50), (int)(rowHeight * 0.15));

                    var dialog = new NumberPickerDialogFragment(context, item.Title, item.NumberPickerOptions, item.QueryPrefix);
                    display.Click += (object sender, EventArgs e) =>
                    {
                        dialog.Show(((Activity)context).FragmentManager, "number");
                    };

                    dialog.NumberChanged += (object sender, NumberPickerDialogFragment.NumberPickerValueChanged e) =>
                    {
                        display.Text = e.Value.ToString() + item.NumberPickerOptions.DisplaySuffix;
                        AddSearchItem(e.CallerKey, e.Value.ToString());
                    };

                    row.AddView(display);

                    break;
                case SearchRowTypes.ComboPicker:
                    row.AddView(Title(item));

                    TextView comboLabel = new TextView(context);
                    comboLabel.LayoutParameters = f;
                    comboLabel.Gravity = GravityFlags.Right;
                    comboLabel.Text = "Any";
                    comboLabel.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                    comboLabel.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), PixelConverter.DpToPixels(50), (int)(rowHeight * 0.15));

                    var comboDialog = new ComboPickerDialogFragment(context, item.Title, item.ComboPickerOptions);

                    comboLabel.Click += (object sender, EventArgs e) =>
                    {
                        var selectedKeys = (from kvp in Conditions where (string)kvp.Value.Key == item.QueryPrefix select (string)kvp.Key).ToList();
                        comboDialog._selectedKeys = selectedKeys;
                        comboDialog.Show(((Activity)context).FragmentManager, "combo");
                    };

                    comboDialog.ItemChanged += (object sender, ComboPickerItemChangedEventArgs e) =>
                    {
                        if (e.InitialArgs.IsChecked)
                        {
                            Conditions.Add(e.Item.Key, new KeyValuePair<object, object>(item.QueryPrefix, e.Item.Value));
                            Console.WriteLine("Added Key: " + e.Item.Key + ", Value: " + e.Item.Value + " with prefix: " + item.QueryPrefix);
                        }
                        else
                        {
                            Conditions.Remove(e.Item.Key);
                            Console.WriteLine("Removed Key: " + e.Item.Key + ", Value: " + e.Item.Value);
                        }

                        var keys = (from kvp in Conditions where (string)kvp.Value.Key == item.QueryPrefix select (string)kvp.Key).ToList();
                        var text = keys.Count > 0 ? string.Join(", ", keys.ToArray()) : "Any";
                        comboLabel.Text = text;
                    };

                    row.AddView(comboLabel);

                    break;
                case SearchRowTypes.SubCatPicker:
                    row.AddView(Title(item));

                    TextView catLabel = new TextView(context);
                    catLabel.LayoutParameters = f;
                    catLabel.Gravity = GravityFlags.Right;
                    catLabel.Text = (string)item.ComboPickerOptions.First().Key;

                    catLabel.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.40f);
                    catLabel.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), PixelConverter.DpToPixels(50), (int)(rowHeight * 0.15));

                    if (item.Title == "Sub Category")
                        SubCategory = item.ComboPickerOptions.First();

                    var categoryDialog = new SingleStringDialogFragment(context, item.Title, item.ComboPickerOptions);

                    catLabel.Click += (object sender, EventArgs e) =>
                    {
                        categoryDialog.Show(((Activity)context).FragmentManager, "stringPick");
                    };

                    categoryDialog.CatPicked += (object sender, SubCatSelectedEventArgs e) =>
                    {
                        categoryDialog.Dismiss();

                        if (item.Title != "Posted Date" && item.Title != "Max Listings")
                        {
                            SubCategory = e.SubCatPicked;
                        }
                        else if (item.Title == "Posted Date")
                        {
                            WeeksOld = (int?)e.SubCatPicked.Value;
                        }
                        else if (item.Title == "Max Listings")
                        {
                            MaxListings = (int)e.SubCatPicked.Value;
                        }

                        catLabel.Text = (string)e.SubCatPicked.Key;
                    };

                    row.AddView(catLabel);
                    break;
                case SearchRowTypes.Space:
                    View strut = new View(context);
                    strut.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent,
                                                                        PixelConverter.DpToPixels(25));
                    row.ShowDividers = ShowDividers.None;
                    row.AddView(strut);
                    break;
                default:
                    row.AddView(Title(item));

                    break;
            }

            AddView(row);
        }