Ejemplo n.º 1
0
        protected override void BindModelFull()
        {
            if (string.IsNullOrEmpty(ViewModel.Data.Poster.MalUser.ImgUrl))
            {
                ForumTopicPageItemAuthorImage.Visibility = ViewStates.Gone;
            }
            else
            {
                if (ForumTopicPageItemAuthorImage.Tag == null || (string)ForumTopicPageItemAuthorImage.Tag != ViewModel.Data.Poster.MalUser.ImgUrl)
                {
                    ForumTopicPageItemAuthorImage.Into(ViewModel.Data.Poster.MalUser.ImgUrl);
                }
            }
            ForumTopicPageItemWebView.Visibility = ViewStates.Visible;


            _bindings.Add(this.SetBinding(() => ViewModel.Data).WhenSourceChanges(() =>
            {
                var tag = ForumTopicPageItemWebView.Tag.Unwrap <WebViewTag>();
                if (tag.ContentHash == 0 || tag.ContentHash != ViewModel.Data.HtmlContent.GetHashCode())
                {
                    ForumTopicPageItemWebView.LoadDataWithBaseURL(null, ResourceLocator.CssManager.WrapWithCss(ViewModel.Data.HtmlContent), "text/html; charset=utf-8", "UTF-8", null);
                    tag.ContentHash = ViewModel.Data.HtmlContent.GetHashCode();
                    ForumTopicPageItemWebView.Tag = tag.Wrap();
                }
            }));

            _bindings.Add(this.SetBinding(() => ViewModel.ComputedHtmlHeight).WhenSourceChanges(() =>
            {
                if (ForumTopicPageItemWebView.Height < ViewModel.ComputedHtmlHeight)
                {
                    UpdateViewWithNewHeight(ForumTopicPageItemWebView, (int)ViewModel.ComputedHtmlHeight);
                }
                else
                {
                    UpdateViewWithNewHeight(ForumTopicPageItemWebView, DimensionsHelper.DpToPx(200));
                }
            }));

            _bindings.Add(this.SetBinding(() => ViewModel.Loading).WhenSourceChanges(() =>
            {
                if (ViewModel.Loading)
                {
                    ForumTopicPageItemLoadingOverlay.Visibility = ViewStates.Gone;
                }
                else
                {
                    ForumTopicPageItemLoadingOverlay.Visibility = ViewStates.Gone;
                }
            }));
        }
Ejemplo n.º 2
0
        protected override void BindModelFling()
        {
            if (!ForumTopicPageItemAuthorImage.IntoIfLoaded(ViewModel.Data.Poster.MalUser.ImgUrl))
            {
                ForumTopicPageItemAuthorImage.Visibility = ViewStates.Gone;
            }


            if (double.IsNaN(ViewModel.ComputedHtmlHeight))
            {
                UpdateViewWithNewHeight(ForumTopicPageItemWebView, DimensionsHelper.DpToPx(200));
                ForumTopicPageItemWebView.Visibility = ViewStates.Invisible;
            }
            else
            {
                var tag = ForumTopicPageItemWebView.Tag.Unwrap <WebViewTag>();
                if (tag.ContentHash == 0 || tag.ContentHash != ViewModel.Data.HtmlContent.GetHashCode())
                {
                    ForumTopicPageItemWebView.LoadDataWithBaseURL(null, ResourceLocator.CssManager.WrapWithCss(ViewModel.Data.HtmlContent), "text/html; charset=utf-8", "UTF-8", null);
                    tag.ContentHash = ViewModel.Data.HtmlContent.GetHashCode();
                    ForumTopicPageItemWebView.Tag = tag.Wrap();
                }
            }
        }
Ejemplo n.º 3
0
        protected override void RootContainerInit()
        {
            var jsInterface = new DataJavascriptInterface(Context);

            ForumTopicPageItemWebView.Settings.JavaScriptEnabled = true;
            _client = new ListenableWebClient();
            _client.NavigationInterceptOpportunity = NavigationInterceptOpportunity;
            ForumTopicPageItemWebView.SetWebViewClient(_client);
            ForumTopicPageItemWebView.AddJavascriptInterface(jsInterface, "android");
            ForumTopicPageItemWebView.Tag = new WebViewTag(jsInterface).Wrap();
            ForumTopicPageItemWebView.VerticalScrollBarEnabled        = false;
            ForumTopicPageItemWebView.ScrollbarFadingEnabled          = true;
            ForumTopicPageItemWebView.HorizontalScrollBarEnabled      = false;
            ForumTopicPageItemWebView.ScrollBarDefaultDelayBeforeFade = 0;
            ForumTopicPageItemWebView.SetBackgroundColor(Color.Transparent);
            _dataJavascriptInterface = jsInterface;

            _dataJavascriptInterface.NewResponse += DataJavascriptInterfaceOnNewResponse;

            ForumTopicPageItemEditButton.SetOnClickListener(new OnClickListener(async view =>
            {
                await ViewModel.StartEdit();
                var str = await TextInputDialogBuilder.BuildForumPostTextInputDialog(Context, TextInputDialogBuilder.ForumPostTextInputContext.Edit, ViewModel.BBcodeContent);
                if (!string.IsNullOrEmpty(str))
                {
                    ViewModel.BBcodeContent = str;
                    ViewModel.SubmitEditCommand.Execute(null);
                }
            }));

            ForumTopicPageItemQuoteButton.SetOnClickListener(new OnClickListener(async view =>
            {
                var semaphore = new SemaphoreSlim(0);
                var vm        = ViewModelLocator.ForumsTopic;
                var deleg     = new PropertyChangedEventHandler((sender, args) =>
                {
                    if (args.PropertyName == nameof(vm.ReplyMessage))
                    {
                        semaphore.Release();
                    }
                });
                vm.ReplyMessage     = string.Empty;
                vm.PropertyChanged += deleg;
                ViewModel.QuoteCommand.Execute(null);
                await semaphore.WaitAsync();
                vm.PropertyChanged -= deleg;
                var str             = await TextInputDialogBuilder.BuildForumPostTextInputDialog(Context, TextInputDialogBuilder.ForumPostTextInputContext.Reply, vm.ReplyMessage);
                if (!string.IsNullOrEmpty(str))
                {
                    vm.ReplyMessage = str;
                    vm.CreateReplyCommand.Execute(null);
                }
            }));

            ForumTopicPageItemDeleteButton.SetOnClickListener(new OnClickListener(view =>
            {
                ViewModel.DeleteCommand.Execute(null);
            }));

            ForumTopicPageItemSendMessageButton.SetOnClickListener(new OnClickListener(view =>
            {
                ViewModelLocator.ForumsTopic.NavigateMessagingCommand.Execute(ViewModel.Data.Poster.MalUser);
            }));

            ForumTopicPageItemSeeOtherPostsButton.SetOnClickListener(new OnClickListener(view =>
            {
                ViewModel.GoToPostersOtherPosts.Execute(null);
            }));

            var listener = new OnClickListener(view => ViewModelLocator.ForumsTopic.NavigateProfileCommand.Execute(ViewModel.Data.Poster.MalUser));

            ForumTopicPageItemPostAuthor.SetOnClickListener(listener);
            ForumTopicPageItemAuthorImage.SetOnClickListener(listener);
        }