Пример #1
0
        public static EditTagsDialogFragment NewInstance()
        {
            EditTagsDialogFragment.editTagsListAdaptor = null;
            var fragment = new EditTagsDialogFragment();

            return(fragment);
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            Dialog.RequestWindowFeature((int)WindowFeatures.NoTitle);
            Dialog.SetCanceledOnTouchOutside(true);

            var vwDialog = inflater.Inflate(Resource.Layout.annotation_newtag_popup, container);

            etTagName = vwDialog.FindViewById <EditText>(Resource.Id.etTagName);

            ivTagColors[0] = vwDialog.FindViewById <ImageView>(Resource.Id.ivTagColor0);
            ivTagColors[1] = vwDialog.FindViewById <ImageView>(Resource.Id.ivTagColor1);
            ivTagColors[2] = vwDialog.FindViewById <ImageView>(Resource.Id.ivTagColor2);
            ivTagColors[3] = vwDialog.FindViewById <ImageView>(Resource.Id.ivTagColor3);
            ivTagColors[4] = vwDialog.FindViewById <ImageView>(Resource.Id.ivTagColor4);
            ivTagColors[5] = vwDialog.FindViewById <ImageView>(Resource.Id.ivTagColor5);

            ivTagColors[6]  = vwDialog.FindViewById <ImageView>(Resource.Id.ivTagColor6);
            ivTagColors[7]  = vwDialog.FindViewById <ImageView>(Resource.Id.ivTagColor7);
            ivTagColors[8]  = vwDialog.FindViewById <ImageView>(Resource.Id.ivTagColor8);
            ivTagColors[9]  = vwDialog.FindViewById <ImageView>(Resource.Id.ivTagColor9);
            ivTagColors[10] = vwDialog.FindViewById <ImageView>(Resource.Id.ivTagColor10);
            ivTagColors[11] = vwDialog.FindViewById <ImageView>(Resource.Id.ivTagColor11);

            vwDialog.FindViewById <Button>(Resource.Id.btnCancel).Click += delegate
            {
                Dismiss();

                EditTagsDialogFragment.NewInstance().Show(
                    Activity.SupportFragmentManager.BeginTransaction(),
                    EditTagsDialogFragment.EditTagsDialogFragmentTag);
            };

            vwDialog.FindViewById <Button>(Resource.Id.btnOk).Click += delegate
            {
                if (string.IsNullOrEmpty(etTagName.Text))
                {
                    Toast.MakeText(
                        Activity,
                        Resource.String.AnnotationNewTagPage_PleaseInputTagName,
                        ToastLength.Short).Show();
                    return;
                }

                var tagId = Arguments.GetString(TagIdKey);
                if (string.IsNullOrEmpty(tagId))
                {
                    AnnCategoryTagUtil.Instance.AddTag(
                        etTagName.Text,
                        AnnCategoryTagUtil.Instance.GetTagColors()[GetSelectedTagColorIndex()].ColorValue);
                }
                else
                {
                    AnnCategoryTagUtil.Instance.UpdateTag(
                        Guid.Parse(tagId),
                        etTagName.Text,
                        AnnCategoryTagUtil.Instance.GetTagColors()[GetSelectedTagColorIndex()].ColorValue);
                }

                Dismiss();

                // Notify Activity to update tag list
                var updateListener = Activity as ITagListUpdateListener;
                if (updateListener != null)
                {
                    updateListener.OnTagListUpdated();
                }

                EditTagsDialogFragment.NewInstance().Show(
                    Activity.SupportFragmentManager.BeginTransaction(),
                    EditTagsDialogFragment.EditTagsDialogFragmentTag);
            };

            for (int i = 0; i < ivTagColors.Length; ++i)
            {
                ivTagColors[i].Click += delegate(object sender, EventArgs e)
                {
                    var id    = ((View)sender).Id;
                    var index = 0;
                    for (int j = 0; j < ivTagColors.Length; ++j)
                    {
                        if (id == ivTagColors[j].Id)
                        {
                            index = j;
                        }
                    }

                    SetSelectedTagColorIndex(index);
                    UpdateTagColors();
                };
            }

            var tagName = Arguments.GetString(TagNameKey);

            if (!string.IsNullOrEmpty(tagName))
            {
                vwDialog.FindViewById <TextView>(Resource.Id.tvTitle).Text =
                    MainApp.ThisApp.Resources.GetString(Resource.String.AnnotationNewTagPage_EditTag);
                etTagName.Text = tagName;
                var color = Color.ParseColor(Arguments.GetString(TagColorKey));
                for (int i = 0; i < TagColors.Length; ++i)
                {
                    if (TagColors[i] == color)
                    {
                        SetSelectedTagColorIndex(i);
                        break;
                    }
                }
            }

            UpdateTagColors();

            return(vwDialog);
        }