Exemplo n.º 1
0
        public QuestionsPage(int position = 0) : base()
        {
            InitializeComponent();

            Xamarin.Forms.PlatformConfiguration.iOSSpecific.Page.SetUseSafeArea(this, true);
            BindingContext = new QuestionsViewModel(position);

            var cancel = new ToolbarItem
            {
                Text    = "添加",
                Command = new Command(async() =>
                {
                    if (UserTokenSettings.Current.HasExpiresIn())
                    {
                        MessagingService.Current.SendMessage(MessageKeys.NavigateLogin);
                    }
                    else
                    {
                        await NavigationService.PushAsync(Navigation, new QuestionsEditPage(new Questions(), new Action <Questions>(OnResult)));
                    }
                })
            };

            ToolbarItems.Add(cancel);

            if (Device.Android == Device.RuntimePlatform)
            {
                cancel.Icon = "toolbar_add.png";
            }


            this.QuestionsListView.ItemSelected += async delegate
            {
                var questions = QuestionsListView.SelectedItem as Questions;
                if (questions == null)
                {
                    return;
                }

                var questionsDetails = new QuestionsDetailsPage(questions);

                await NavigationService.PushAsync(Navigation, questionsDetails);

                this.QuestionsListView.SelectedItem = null;
            };
            ViewModel.GetClientQuestionsAsync();
        }
        public QuestionsSearchPage() : base()
        {
            InitializeComponent();
            Xamarin.Forms.PlatformConfiguration.iOSSpecific.Page.SetUseSafeArea(this, true);
            BindingContext = new SearchViewModel(3);
            this.SearchsListView.ItemSelected += async delegate
            {
                var search = SearchsListView.SelectedItem as Portable.Model.Search;
                if (search == null)
                {
                    return;
                }
                var id = 0;
                if (int.TryParse(search.Uri.Substring(search.Uri.TrimEnd('/').LastIndexOf("/") + 1).TrimEnd('/'), out id))
                {
                    var questions = new Questions()
                    {
                        Qid              = id,
                        Title            = search.Title,
                        Content          = search.Content,
                        Award            = 0,
                        QuestionUserInfo = new QuestionUserInfo
                        {
                            UserName = search.UserName,
                            IconName = search.UserAlias
                        },
                        DateAdded   = search.PublishTime,
                        DiggCount   = search.VoteTimes,
                        AnswerCount = search.CommentTimes,
                        ViewCount   = search.ViewTimes
                    };

                    var articlesDetails = new QuestionsDetailsPage(questions);

                    await NavigationService.PushAsync(Navigation, articlesDetails);
                }
                this.SearchsListView.SelectedItem = null;
            };
        }
        public QuestionsSearchPage() : base()
        {
            InitializeComponent();
            BindingContext = new SearchViewModel(3);
            this.SearchsListView.ItemSelected += async delegate
            {
                var search = SearchsListView.SelectedItem as Search;
                if (search == null)
                {
                    return;
                }
                var id        = search.Uri.Substring(search.Uri.LastIndexOf("/") + 1);
                var questions = new Questions()
                {
                    Qid              = int.Parse(id),
                    Title            = search.Title,
                    Content          = search.Content,
                    Award            = 0,
                    QuestionUserInfo = new QuestionUserInfo
                    {
                        UserName = search.UserName,
                        IconName = search.UserAlias
                    },
                    DateAdded   = search.PublishTime,
                    DiggCount   = search.VoteTimes,
                    AnswerCount = search.CommentTimes,
                    ViewCount   = search.ViewTimes
                };

                var articlesDetails = new QuestionsDetailsPage(questions);

                await NavigationService.PushAsync(Navigation, articlesDetails);

                this.SearchsListView.SelectedItem = null;
            };
        }
Exemplo n.º 4
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            if (!hasInitialization)
            {
                BindingContext = new QuestionsViewModel(position);

                var cancel = new ToolbarItem {
                    Text    = "添加",
                    Command = new Command(async() => {
                        if (UserTokenSettings.Current.HasExpiresIn())
                        {
                            MessagingService.Current.SendMessage(MessageKeys.NavigateLogin);
                        }
                        else
                        {
                            await NavigationService.PushAsync(Navigation, new QuestionsEditPage(new Questions(), new Action <Questions>(OnResult)));
                        }
                    }),
                    Icon = "toolbar_add.png"
                };
                ToolbarItems.Add(cancel);

                this.QuestionsListView.HasFloatingView = true;

                this.QuestionsListView.ItemSelected += async delegate {
                    var questions = QuestionsListView.SelectedItem as Questions;
                    this.QuestionsListView.SelectedItem = null;
                    if (questions == null)
                    {
                        return;
                    }

                    var questionsDetails = new QuestionsDetailsPage(questions);

                    await NavigationService.PushAsync(Navigation, questionsDetails);
                };

                var floatingView = new FloatingView();

                this.QuestionsListView.FloatingChanged += delegate(object sender, bool floating) {
                    if (Device.RuntimePlatform == Device.Android)
                    {
                        if (floating)
                        {
                            floatingView.ToggleFloatingView = true;
                        }
                        else
                        {
                            floatingView.ToggleFloatingView = false;
                        }
                    }
                };
                if (Device.RuntimePlatform == Device.Android)
                {
                    floatingView.Image       = "toolbar_add.png";
                    floatingView.ButtonColor = Color.FromHex("#E64A19");
                    AbsoluteLayout.SetLayoutBounds(floatingView, new Rectangle(1, .9, 80, 90));
                    AbsoluteLayout.SetLayoutFlags(floatingView, AbsoluteLayoutFlags.PositionProportional);
                    floatingView.Clicked += async delegate(object sender, EventArgs e) {
                        if (UserTokenSettings.Current.HasExpiresIn())
                        {
                            MessagingService.Current.SendMessage(MessageKeys.NavigateLogin);
                        }
                        else
                        {
                            await NavigationService.PushAsync(this.Navigation, new QuestionsEditPage(new Questions()));
                        }
                    };

                    this.AbsoluteLayout.Children.Add(floatingView);
                }
                ViewModel.GetClientQuestionsAsync();
                hasInitialization = true;
            }
            UpdatePage();
        }