Exemplo n.º 1
0
		public ViewController06 ()
		{
			Title = "Pretty Refresh";
			SimulateErrors = false;

			_refreshView = new RefreshView (new RectangleF (0, -100, TableView.Frame.Width, 100));
			TableView.AddSubview (_refreshView);

			NavigationItem.LeftBarButtonItem = new UIBarButtonItem (
				UIBarButtonSystemItem.Refresh, delegate {

				StartManualRefresh ();
			}); 
		}
Exemplo n.º 2
0
        public void TestRefreshViewConfigTableNameProperty()
        {
            RefreshView rv = new RefreshView();

            // Verify "vw" is replaced by "TBL"
            rv.ViewName = "vwTest";
            Assert.Equal(rv.TableName, "TBLTest");

            // Verify only first occurrence of "vw" is replaced by "TBL"
            rv.ViewName = "vwVwTestvw";
            Assert.Equal(rv.TableName, "TBLVwTestvw");
            rv.ViewName = "tblVwTest";
            Assert.Equal(rv.TableName, "tblVwTest");

            // Verify case is ignored when matching "vw"
            rv.ViewName = "VWTest";
            Assert.Equal(rv.TableName, "TBLTest");
            rv.ViewName = "VwTest";
            Assert.Equal(rv.TableName, "TBLTest");

            // Verify table name part case is kept
            rv.ViewName = "VWTeStCaSe";
            Assert.Equal(rv.TableName, "TBLTeStCaSe");
        }
Exemplo n.º 3
0
        /// <summary>
        /// 子線程更新文件
        /// </summary>
        /// <param name="GroupNo">進程號</param>
        private void RunSendFileByThread(object tbGroup)
        {
            DataTable dtList = (DataTable)tbGroup;

            RefreshUI UI = new RefreshUI(ShowProgress); //創建委託實例
            RefreshView UI_View = new RefreshView(UpdateDone); //創建委託實例
            RefreshButton UI_Button = new RefreshButton(EnableButton);

            //開始遠程拷貝程式
            //多臺ap
            CMDCommad Cmd = new CMDCommad();
            XMLReadWrite xml = new XMLReadWrite();
            int RowNum = 0;

            try
            {
                foreach (DataRow _dr in dtList.Rows)
                {
                    string RemoteHost = _dr["ap_name"].ToString();
                    string UserName = _dr["user_name"].ToString();
                    string PassWord = _dr["pwd"].ToString();
                    string RootPath = _dr["root"].ToString();
                    string AllPath = "\\\\" + RemoteHost + "\\" + _dr["ap_dir"].ToString().Trim().Replace(":", "$") + "\\" + RootPath;
                    string curPath = "";
                    if (FileList.Items.Count != 0)
                    {
                        #region 傳送文件

                        this.BeginInvoke(UI_View, new object[] { _dr["ap_seq"].ToString(), "0" });

                        if (Cmd.Connect(RemoteHost, UserName, PassWord))
                        {
                            this.BeginInvoke(UI_View, new object[] { _dr["ap_seq"].ToString(), "1" });

                            for (int j = 0; j < FileList.Items.Count; j++)
                            {
                                FileInfo fi = new FileInfo(FileList.Items[j].ToString());
                                curPath = AllPath;
                                // 取出子目錄
                                if (fi.DirectoryName.Length > fi.DirectoryName.LastIndexOf(FilePath) + FilePath.Length)
                                    curPath = AllPath + "\\" + fi.DirectoryName.Substring(fi.DirectoryName.LastIndexOf(FilePath) + FilePath.Length + 1, fi.DirectoryName.Length - (fi.DirectoryName.LastIndexOf(FilePath) + FilePath.Length + 1));
                                //創建目錄
                                if (Cmd.CreateDir(curPath))
                                {
                                    //xml.WriteXmlRow(LogFile, "Row" + RowNum.ToString().Trim() + string.Format("{0:HHmmssms}", DateTime.Now), "檢查或創建" + AllPath + "目錄成功!", "Y");
                                }
                                else
                                {
                                    //xml.WriteXmlRow(LogFile, "Row" + RowNum.ToString().Trim() + string.Format("{0:HHmmssms}", DateTime.Now), "檢查或創建" + AllPath + "目錄失敗!", "N");
                                    continue;
                                }
                                RowNum = RowNum + 1;
                                //開始拷貝文件
                                try
                                {
                                    File.Copy(FileList.Items[j].ToString(), curPath + "\\" + fi.Name, true);
                                    //xml.WriteXmlRow(LogFile, "Row" + RowNum.ToString().Trim() + string.Format("{0:HHmmssms}", DateTime.Now), "Copy File " + FileList.Items[j].ToString() + " -- " + AllPath + " 成功!", "Y");
                                }
                                catch(Exception ex)
                                {
                                    WriteLog("RunSendFileByThread", "複製文件:" + FileList.Items[j].ToString() + "到" + curPath + "\\" + fi.Name + "時出錯:" + (ex != null ? ex.Message : ""));
                                    //xml.WriteXmlRow(LogFile, "Row" + RowNum.ToString().Trim() + string.Format("{0:HHmmssms}", DateTime.Now), "Copy File " + FileList.Items[j].ToString() + " -- " + AllPath + " 失敗!", "N");
                                    continue;
                                }
                                RowNum = RowNum + 1;
                                this.BeginInvoke(UI);//UI線程上異步調用委託
                                //this.BeginInvoke(new ThreadStart(UI));
                            }
                        }
                        else
                        {
                            //xml.WriteXmlRow(LogFile, "Row" + RowNum.ToString().Trim() + string.Format("{0:HHmmssms}", DateTime.Now), "聯接" + RemoteHost + " AP失敗!", "N");
                            RowNum = RowNum + 1;
                            continue;
                        }
                        #endregion
                    }

                    if (ConfigFiles.Count != 0)
                    {
                        #region "生成配置文件"
                        //ToDoManager.Launcher.exe.config -> [WCF-IP] [LX-IP] [UP-MODE] [AT-MODE] [AD-MODE]
                        //Update.xml -> [UP-IP]
                        //Manifest.ini -> [ROOTDIR] [VERKEY]

                        // 產生當前服務器文件夾
                        string cfPath = ConfigPath + "\\" + _dr["ap_seq"].ToString();
                        if (!Directory.Exists(cfPath))
                        {
                            Directory.CreateDirectory(cfPath);
                        }

                        string cfile = "";

                        #region " 1.處理ToDoManager.Launcher.exe.config "

                        cfile = ConfigFiles.Find(f => f.IndexOf("ToDoManager.Launcher.exe.config") > -1);
                        FileInfo fi = new FileInfo(cfile);
                        //複製到服務器文件夾
                        File.Copy(fi.FullName, cfPath + "\\tmp.config", true);
                        //替換參數
                        string FileContext = "";
                        using (StreamReader reader = new StreamReader(cfPath + "\\tmp.config", Encoding.UTF8))
                        {
                            //[WCF-IP] [LX-IP] [UP-MODE] [AT-MODE] [AD-MODE]
                            FileContext = reader.ReadToEnd();
                            FileContext = FileContext.Replace("[WCF-IP]", _dr["wcf_ip"].ToString());
                            FileContext = FileContext.Replace("[LX-IP]", _dr["lx_ip"].ToString());
                            FileContext = FileContext.Replace("[UP-MODE]", _dr["update_mode"].ToString());
                            FileContext = FileContext.Replace("[AT-MODE]", _dr["attach_mode"].ToString());
                            FileContext = FileContext.Replace("[AD-MODE]", _dr["addin_mode"].ToString());
                        }
                        using (StreamWriter writer = new StreamWriter(cfPath + "\\" + fi.Name, false, Encoding.UTF8))
                        {
                            writer.Write(FileContext);
                            writer.Flush();
                        }
                        //複製到目標
                        //開始拷貝文件
                        try
                        {
                            File.Copy(fi.DirectoryName + "\\" + _dr["ap_seq"].ToString() + "\\" + fi.Name, AllPath + "\\" + fi.Name, true);
                            //xml.WriteXmlRow(LogFile, "Row" + RowNum.ToString().Trim() + string.Format("{0:HHmmssms}", DateTime.Now), "Copy File " + FileList.Items[j].ToString() + " -- " + AllPath + " 成功!", "Y");
                        }
                        catch(Exception ex)
                        {
                            WriteLog("RunSendFileByThread", "複製文件:" + fi.DirectoryName + "\\" + _dr["ap_seq"].ToString() + "\\" + fi.Name + "到" + AllPath + "\\" + fi.Name + "時出錯:" + (ex != null ? ex.Message : ""));
                        }

                        #endregion

                        #region " 2.處理Update.xml "

                        cfile = ConfigFiles.Find(f => f.IndexOf("Update.xml") > -1);
                        fi = new FileInfo(cfile);
                        //複製到服務器文件夾
                        File.Copy(fi.FullName, cfPath + "\\tmp.xml", true);
                        //替換參數
                        FileContext = "";
                        using (StreamReader reader = new StreamReader(cfPath + "\\tmp.xml", Encoding.UTF8))
                        {
                            //[UP-IP]
                            FileContext = reader.ReadToEnd();
                            FileContext = FileContext.Replace("[UP-IP]", _dr["upsrv_ip"].ToString());
                        }
                        using (StreamWriter writer = new StreamWriter(cfPath + "\\" + fi.Name, false, Encoding.UTF8))
                        {
                            writer.Write(FileContext);
                            writer.Flush();
                        }
                        //複製到目標
                        //開始拷貝文件
                        try
                        {
                            File.Copy(fi.DirectoryName + "\\" + _dr["ap_seq"].ToString() + "\\" + fi.Name, AllPath + "\\" + fi.Name, true);
                            //xml.WriteXmlRow(LogFile, "Row" + RowNum.ToString().Trim() + string.Format("{0:HHmmssms}", DateTime.Now), "Copy File " + FileList.Items[j].ToString() + " -- " + AllPath + " 成功!", "Y");
                        }
                        catch (Exception ex)
                        {
                            WriteLog("RunSendFileByThread", "複製文件:" + fi.DirectoryName + "\\" + _dr["ap_seq"].ToString() + "\\" + fi.Name + "到" + AllPath + "\\" + fi.Name + "時出錯:" + (ex != null ? ex.Message : ""));
                        }

                        #endregion

                        #region " 3.處理Manifest.ini "

                        cfile = ConfigFiles.Find(f => f.IndexOf("Manifest.ini") > -1);
                        fi = new FileInfo(cfile);
                        //複製到服務器文件夾
                        string m_path = System.IO.Path.Combine(cfPath, fi.Name);
                        File.Copy(fi.FullName, m_path, true);
                        NativeMethods.WritePrivateProfileString("UpdateRootPath", "VALUE", _dr["root"].ToString() + "/", m_path);
                        NativeMethods.WritePrivateProfileString("GUID", "VALUE", VerKey, m_path);

                        ////替換參數
                        //FileContext = "";
                        //using (StreamReader reader = new StreamReader(cfPath + "\\tmp.ini", Encoding.UTF8))
                        //{
                        //    //[ROOTDIR] [VERKEY]
                        //    FileContext = reader.ReadToEnd();
                        //    FileContext = FileContext.Replace("[ROOTDIR]", _dr["root"].ToString());
                        //    FileContext = FileContext.Replace("[VERKEY]", VerKey);
                        //}
                        //using (StreamWriter writer = new StreamWriter(cfPath + "\\" + fi.Name, false, Encoding.UTF8))
                        //{
                        //    writer.Write(FileContext);
                        //    writer.Flush();
                        //}
                        //複製到目標
                        //開始拷貝文件
                        try
                        {
                            File.Copy(fi.DirectoryName + "\\" + _dr["ap_seq"].ToString() + "\\" + fi.Name, AllPath + "\\" + fi.Name, true);
                            //xml.WriteXmlRow(LogFile, "Row" + RowNum.ToString().Trim() + string.Format("{0:HHmmssms}", DateTime.Now), "Copy File " + FileList.Items[j].ToString() + " -- " + AllPath + " 成功!", "Y");
                        }
                        catch (Exception ex)
                        {
                            WriteLog("RunSendFileByThread", "複製文件:" + fi.DirectoryName + "\\" + _dr["ap_seq"].ToString() + "\\" + fi.Name + "到" + AllPath + "\\" + fi.Name + "時出錯:" + (ex != null ? ex.Message : ""));
                        }

                        #endregion

                        #endregion
                    }

                    this.BeginInvoke(UI_View, new object[] { _dr["ap_seq"].ToString(), "2" });
                }
            }
            catch (Exception ex)
            {
                WriteLog("RunSendFileByThread", "出錯了:" + (ex != null ? ex.Message : ""));
            }
            finally
            {
                // 通知主線程,當前子線程結束
                this.BeginInvoke(UI_Button);

                UI = null;
                UI_View = null;
                UI_Button = null;
            }
        }
Exemplo n.º 4
0
 private void UpdateDone(object ap, object flg)
 {
     if (this.apGridView.InvokeRequired)
     {
         RefreshView myUI = new RefreshView(UpdateDone);
         this.apGridView.Invoke(myUI, new object[] { ap, flg });
     }
     else
     {
         string apID = ap.ToString();
         string apFlg = flg.ToString();
         for (int i = 0; i < apGridView.Rows.Count; i++)
         {
             if (apGridView.Rows[i].Cells["colDoUpdate"].Value.ToString() != "是") continue;
             if (apGridView.Rows[i].Cells["colSeq"].Value.ToString() == apID)
             {
                 if (apFlg == "2")
                     apGridView.Rows[i].Cells["colProgress"].Value = "完成";
                 else if (apFlg == "1")
                     apGridView.Rows[i].Cells["colProgress"].Value = "已連接";
                 else
                     apGridView.Rows[i].Cells["colProgress"].Value = "連接中";
                 return;
             }
         }
     }
 }
Exemplo n.º 5
0
        public void StartsEnabled()
        {
            RefreshView refreshView = new RefreshView();

            Assert.IsTrue(refreshView.IsEnabled);
        }
Exemplo n.º 6
0
        public RepositoryPage(RepositoryViewModel repositoryViewModel,
                              IAnalyticsService analyticsService,
                              SortingService sortingService,
                              DeepLinkingService deepLinkingService,
                              IMainThread mainThread,
                              FirstRunService firstRunService,
                              GitHubUserService gitHubUserService) : base(repositoryViewModel, analyticsService, mainThread, PageTitles.RepositoryPage)
        {
            _firstRunService    = firstRunService;
            _gitHubUserService  = gitHubUserService;
            _deepLinkingService = deepLinkingService;

            ViewModel.PullToRefreshFailed += HandlePullToRefreshFailed;
            SearchBarTextChanged          += HandleSearchBarTextChanged;

            var collectionView = new CollectionView
            {
                ItemTemplate    = new RepositoryDataTemplateSelector(sortingService),
                BackgroundColor = Color.Transparent,
                SelectionMode   = SelectionMode.Single,
                AutomationId    = RepositoryPageAutomationIds.CollectionView,
                //Work around for https://github.com/xamarin/Xamarin.Forms/issues/9879
                Header = Device.RuntimePlatform is Device.Android ? new BoxView {
                    HeightRequest = BaseRepositoryDataTemplate.BottomPadding
                } : null,
                Footer = Device.RuntimePlatform is Device.Android ? new BoxView {
                    HeightRequest = BaseRepositoryDataTemplate.TopPadding
                } : null,
                EmptyView = new EmptyDataView("EmptyRepositoriesList", RepositoryPageAutomationIds.EmptyDataView)
                            .Bind <EmptyDataView, bool, bool>(IsVisibleProperty, nameof(RepositoryViewModel.IsRefreshing), convert: isRefreshing => !isRefreshing)
                            .Bind(EmptyDataView.TitleProperty, nameof(RepositoryViewModel.EmptyDataViewTitle))
                            .Bind(EmptyDataView.DescriptionProperty, nameof(RepositoryViewModel.EmptyDataViewDescription))
            };

            collectionView.SelectionChanged += HandleCollectionViewSelectionChanged;
            collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(RepositoryViewModel.VisibleRepositoryList));

            _refreshView = new RefreshView
            {
                AutomationId = RepositoryPageAutomationIds.RefreshView,
                Content      = collectionView
            };
            _refreshView.SetDynamicResource(RefreshView.RefreshColorProperty, nameof(BaseTheme.PullToRefreshColor));
            _refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(RepositoryViewModel.IsRefreshing));
            _refreshView.SetBinding(RefreshView.CommandProperty, nameof(RepositoryViewModel.PullToRefreshCommand));

            var settingsToolbarItem = new ToolbarItem
            {
                Text            = "Settings",
                IconImageSource = Device.RuntimePlatform is Device.iOS ? "Settings" : null,
                Order           = Device.RuntimePlatform is Device.Android ? ToolbarItemOrder.Secondary : ToolbarItemOrder.Default,
                AutomationId    = RepositoryPageAutomationIds.SettingsButton,
                Command         = new AsyncCommand(ExecuteSetttingsToolbarItemCommand)
            };

            ToolbarItems.Add(settingsToolbarItem);

            var sortToolbarItem = new ToolbarItem
            {
                Text            = "Sort",
                Priority        = 1,
                IconImageSource = Device.RuntimePlatform is Device.iOS ? "Sort" : null,
                Order           = Device.RuntimePlatform is Device.Android ? ToolbarItemOrder.Secondary : ToolbarItemOrder.Default,
                AutomationId    = RepositoryPageAutomationIds.SortButton,
                Command         = new AsyncCommand(ExecuteSortToolbarItemCommand)
            };

            ToolbarItems.Add(sortToolbarItem);

            //Work-around to prevent LargeNavigationBar from collapsing when CollectionView is scrolled; prevents janky animation when LargeNavigationBar collapses
            if (Device.RuntimePlatform is Device.iOS)
            {
                Content = new Grid
                {
                    Children =
                    {
                        new BoxView {
                            HeightRequest = 0
                        },
                        _refreshView
                    }
                };
            }
            else
            {
                Content = _refreshView;
            }
        }
Exemplo n.º 7
0
 protected virtual void OnRefresh(EventArgs e)
 {
     RefreshView?.Invoke(this, e);
 }
Exemplo n.º 8
0
        public ReferringSitesPage(DeepLinkingService deepLinkingService,
                                  ReferringSitesViewModel referringSitesViewModel,
                                  Repository repository,
                                  AnalyticsService analyticsService,
                                  ThemeService themeService,
                                  ReviewService reviewService) : base(referringSitesViewModel, analyticsService, PageTitles.ReferringSitesPage)
        {
            _deepLinkingService = deepLinkingService;
            _reviewService      = reviewService;

            ViewModel.PullToRefreshFailed += HandlePullToRefreshFailed;
            reviewService.ReviewCompleted += HandleReviewCompleted;

            var collectionView = new CollectionView
            {
                AutomationId    = ReferringSitesPageAutomationIds.CollectionView,
                BackgroundColor = Color.Transparent,
                ItemTemplate    = new ReferringSitesDataTemplate(),
                SelectionMode   = SelectionMode.Single,
                ItemsLayout     = new LinearItemsLayout(ItemsLayoutOrientation.Vertical),
                //Set iOS Header to `new BoxView { HeightRequest = titleRowHeight + titleTopMargin }` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879
                Header = Device.RuntimePlatform is Device.Android ? new BoxView {
                    HeightRequest = ReferringSitesDataTemplate.BottomPadding
                } : null,
                Footer = Device.RuntimePlatform is Device.Android ? new BoxView {
                    HeightRequest = ReferringSitesDataTemplate.TopPadding
                } : null,
                EmptyView = new EmptyDataView("EmptyReferringSitesList", ReferringSitesPageAutomationIds.EmptyDataView)
                            .Bind(IsVisibleProperty, nameof(ReferringSitesViewModel.IsEmptyDataViewEnabled))
                            .Bind(EmptyDataView.TextProperty, nameof(ReferringSitesViewModel.EmptyDataViewText))
            };

            collectionView.SelectionChanged += HandleCollectionViewSelectionChanged;
            collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(ReferringSitesViewModel.MobileReferringSitesList));

            _refreshView = new RefreshView
            {
                AutomationId     = ReferringSitesPageAutomationIds.RefreshView,
                CommandParameter = (repository.OwnerLogin, repository.Name, repository.Url, _refreshViewCancelltionTokenSource.Token),
                Content          = collectionView
            };
            _refreshView.SetDynamicResource(RefreshView.RefreshColorProperty, nameof(BaseTheme.PullToRefreshColor));
            _refreshView.SetBinding(RefreshView.CommandProperty, nameof(ReferringSitesViewModel.RefreshCommand));
            _refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(ReferringSitesViewModel.IsRefreshing));

            var relativeLayout = new RelativeLayout();

            //Add Title and Close Button to UIModalPresentationStyle.FormSheet
            if (Device.RuntimePlatform is Device.iOS)
            {
                const int titleTopMargin = 10;
                const int titleRowHeight = 50;

                var closeButton = new Button
                {
                    Text              = "Close",
                    FontFamily        = FontFamilyConstants.RobotoRegular,
                    HeightRequest     = titleRowHeight * 3 / 5,
                    HorizontalOptions = LayoutOptions.End,
                    VerticalOptions   = LayoutOptions.Center,
                    AutomationId      = ReferringSitesPageAutomationIds.CloseButton,
                    Padding           = new Thickness(5, 0),
                };
                closeButton.Clicked += HandleCloseButtonClicked;
                closeButton.SetDynamicResource(Button.TextColorProperty, nameof(BaseTheme.NavigationBarTextColor));
                closeButton.SetDynamicResource(Button.BorderColorProperty, nameof(BaseTheme.BorderButtonBorderColor));
                closeButton.SetDynamicResource(BackgroundColorProperty, nameof(BaseTheme.NavigationBarBackgroundColor));

                var titleLabel = new Label
                {
                    FontSize   = 30,
                    Text       = PageTitles.ReferringSitesPage,
                    FontFamily = FontFamilyConstants.RobotoMedium,
                }.Center().TextCenterVertical();
                titleLabel.SetDynamicResource(Label.TextColorProperty, nameof(BaseTheme.TextColor));

                closeButton.Margin = titleLabel.Margin = new Thickness(0, titleTopMargin, 0, 0);

                var titleShadow = new BoxView();
                titleShadow.SetDynamicResource(BackgroundColorProperty, nameof(BaseTheme.PageBackgroundColor));

                if (isLightTheme(themeService.Preference))
                {
                    titleShadow.On <iOS>().SetIsShadowEnabled(true)
                    .SetShadowColor(Color.Gray)
                    .SetShadowOffset(new Size(0, 1))
                    .SetShadowOpacity(0.5)
                    .SetShadowRadius(4);
                }


                relativeLayout.Children.Add(_refreshView,
                                            Constraint.Constant(0),
                                            Constraint.Constant(titleRowHeight),                                    //Set to `0` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879
                                            Constraint.RelativeToParent(parent => parent.Width),
                                            Constraint.RelativeToParent(parent => parent.Height - titleRowHeight)); //Set to `parent => parent.Height` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879

                relativeLayout.Children.Add(titleShadow,
                                            Constraint.Constant(0),
                                            Constraint.Constant(0),
                                            Constraint.RelativeToParent(parent => parent.Width),
                                            Constraint.Constant(titleRowHeight));

                relativeLayout.Children.Add(titleLabel,
                                            Constraint.Constant(10),
                                            Constraint.Constant(0));

                relativeLayout.Children.Add(closeButton,
                                            Constraint.RelativeToParent(parent => parent.Width - closeButton.GetWidth(parent) - 10),
                                            Constraint.Constant(0),
                                            Constraint.RelativeToParent(parent => closeButton.GetWidth(parent)));
            }
            else
            {
                relativeLayout.Children.Add(_refreshView,
                                            Constraint.Constant(0),
                                            Constraint.Constant(0),
                                            Constraint.RelativeToParent(parent => parent.Width),
                                            Constraint.RelativeToParent(parent => parent.Height));
            }

            relativeLayout.Children.Add(_storeRatingRequestView,
                                        Constraint.Constant(0),
                                        Constraint.RelativeToParent(parent => parent.Height - _storeRatingRequestView.GetHeight(parent)),
                                        Constraint.RelativeToParent(parent => parent.Width));

            Content = relativeLayout;
Exemplo n.º 9
0
        protected override void Init()
        {
            Title = "Refresh View Tests";
            var scrollViewContent = new StackLayout();

            Enumerable
            .Range(0, 10)
            .Select(_ => new Label()
            {
                HeightRequest = 200, Text = "Pull me down to refresh me"
            })
            .ForEach(x => scrollViewContent.Children.Add(x));


            bool canExecute = true;

            _refreshCommand = new Command(async(parameter) =>
            {
                if (!_refreshView.IsRefreshing)
                {
                    throw new Exception("IsRefreshing should be true when command executes");
                }

                if (parameter != null && !(bool)parameter)
                {
                    throw new Exception("Refresh command incorrectly firing with disabled parameter");
                }

                await Task.Delay(2000);
                _refreshView.IsRefreshing = false;
            }, (object parameter) =>
            {
                return(parameter != null && canExecute && (bool)parameter);
            });

            _refreshView = new RefreshView()
            {
                Content = new ScrollView()
                {
                    HeightRequest   = 2000,
                    BackgroundColor = Colors.Green,
                    Content         = scrollViewContent,
                    AutomationId    = "LayoutContainer"
                },
                Command          = _refreshCommand,
                CommandParameter = true
            };

            var isRefreshingLabel = new Label();

            var label = new Label {
                BindingContext = _refreshView
            };

            isRefreshingLabel.SetBinding(Label.TextProperty, new Binding("IsRefreshing", stringFormat: "IsRefreshing: {0}", source: _refreshView));

            var commandEnabledLabel = new Label {
                BindingContext = _refreshView
            };

            commandEnabledLabel.SetBinding(Label.TextProperty, new Binding("IsEnabled", stringFormat: "IsEnabled: {0}", source: _refreshView));

            Content = new StackLayout()
            {
                Children =
                {
                    isRefreshingLabel,
                    commandEnabledLabel,
                    new Button()
                    {
                        Text    = "Toggle Refresh",
                        Command = new Command(() =>
                        {
                            _refreshView.IsRefreshing = !_refreshView.IsRefreshing;
                        })
                    },
                    new Button()
                    {
                        Text    = "Toggle Can Execute",
                        Command = new Command(() =>
                        {
                            canExecute = !canExecute;
                            _refreshCommand.ChangeCanExecute();
                        }),
                        AutomationId = "ToggleCanExecute"
                    },
                    new Button()
                    {
                        Text    = "Toggle Can Execute Parameter",
                        Command = new Command(() =>
                        {
                            _refreshView.CommandParameter = !((bool)_refreshView.CommandParameter);
                            _refreshCommand.ChangeCanExecute();
                        }),
                        AutomationId = "ToggleCanExecuteParameter"
                    },
                    new Button()
                    {
                        Text    = "Toggle Command Being Set",
                        Command = new Command(() =>
                        {
                            if (_refreshView.Command != null)
                            {
                                _refreshView.Command = null;
                            }
                            else
                            {
                                _refreshView.Command = _refreshCommand;
                            }
                        }),
                        AutomationId = "ToggleCommandBeingSet"
                    },
                    _refreshView
                }
            };
        }
 public static RefreshView Command(this RefreshView view, ICommand command, object parameter = null)
 {
     view.Command          = command;
     view.CommandParameter = parameter;
     return(view);
 }
        private void dg_Sorting(object sender, DataGridSortingEventArgs e)
        {
            var msg = new RefreshView();

            Messenger.Default.Send <RefreshView>(msg);
        }
 public static RefreshView RefreshColor(this RefreshView view, Color color)
 {
     view.RefreshColor = color;
     return(view);
 }
 public static RefreshView IsRefreshing(this RefreshView view, bool refreshing)
 {
     view.IsRefreshing = refreshing;
     return(view);
 }
Exemplo n.º 14
0
        protected override void Init()
        {
            Title = "Issue 8198";

            var layout = new StackLayout();

            var instructions = new Label
            {
                BackgroundColor = Colors.Black,
                TextColor       = Colors.White,
                Text            = "Scroll the CollectionView to end, lift finger off screen, and then try to scroll up again. If the Refresh Indicator does not appear until it reaches the top, the test has passed."
            };

            _refreshCommand = new Command(async(parameter) =>
            {
                if (!_refreshView.IsRefreshing)
                {
                    throw new Exception("IsRefreshing should be true when command executes");
                }

                if (parameter != null && !(bool)parameter)
                {
                    throw new Exception("Refresh command incorrectly firing with disabled parameter");
                }

                await Task.Delay(2000);
                _refreshView.IsRefreshing = false;
            });

            _refreshView = new RefreshView
            {
                Command = _refreshCommand
            };

            var collectionView = new CollectionView
            {
                ItemTemplate = GetDataTemplate(),
                ItemsSource  = new string[]
                {
                    "Item 1",
                    "Item 2",
                    "Item 3",
                    "Item 4",
                    "Item 5",
                    "item 6",
                    "Item 7",
                    "Item 8",
                    "Item 9",
                    "Item 10",
                    "Item 11",
                    "item 12",
                    "Item 13",
                    "Item 14",
                    "Item 15",
                    "Item 16",
                    "Item 17",
                    "Item 18",
                    "Item 19",
                    "Item 20"
                }
            };

            _refreshView.Content = collectionView;

            layout.Children.Add(instructions);
            layout.Children.Add(_refreshView);

            Content = layout;
        }
Exemplo n.º 15
0
        public ReferringSitesPage(ReferringSitesViewModel referringSitesViewModel,
                                  Repository repository,
                                  AnalyticsService analyticsService) : base(PageTitles.ReferringSitesPage, referringSitesViewModel, analyticsService)
        {
            const int titleRowHeight = 50;
            const int titleTopMargin = 15;

            var collectionView = new CollectionView
            {
                AutomationId  = ReferringSitesPageAutomationIds.CollectionView,
                ItemTemplate  = new ReferringSitesDataTemplateSelector(),
                SelectionMode = SelectionMode.Single
            };

            collectionView.SelectionChanged += HandleCollectionViewSelectionChanged;
            collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(ReferringSitesViewModel.MobileReferringSitesList));

            _refreshView = new RefreshView
            {
                AutomationId     = ReferringSitesPageAutomationIds.RefreshView,
                CommandParameter = (repository.OwnerLogin, repository.Name),
                Content          = collectionView
            };
            _refreshView.SetDynamicResource(RefreshView.RefreshColorProperty, nameof(BaseTheme.RefreshControlColor));
            _refreshView.SetBinding(RefreshView.CommandProperty, nameof(ReferringSitesViewModel.RefreshCommand));
            _refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(ReferringSitesViewModel.IsRefreshing));

            //Add Title and Back Button to UIModalPresentationStyle.FormSheet
            if (Device.RuntimePlatform is Device.iOS)
            {
                var closeButton = new Button
                {
                    AutomationId      = ReferringSitesPageAutomationIds.CloseButton,
                    Text              = "Close",
                    HorizontalOptions = LayoutOptions.End,
                    VerticalOptions   = LayoutOptions.Center,
                    HeightRequest     = titleRowHeight * 3 / 5,
                    Padding           = new Thickness(5, 0)
                };
                closeButton.Clicked += HandleCloseButtonClicked;
                closeButton.SetDynamicResource(Button.TextColorProperty, nameof(BaseTheme.NavigationBarTextColor));
                closeButton.SetDynamicResource(Button.BorderColorProperty, nameof(BaseTheme.SettingsButtonBorderColor));
                closeButton.SetDynamicResource(Button.BackgroundColorProperty, nameof(BaseTheme.NavigationBarBackgroundColor));


                var titleRowBlurView = new BoxView {
                    Opacity = 0.5
                };
                titleRowBlurView.SetDynamicResource(BackgroundColorProperty, nameof(BaseTheme.PageBackgroundColor));

                collectionView.Header = new BoxView {
                    HeightRequest = titleRowHeight + titleTopMargin
                };

                var titleLabel = new Label
                {
                    FontAttributes = FontAttributes.Bold,
                    Text           = PageTitles.ReferringSitesPage,
                    FontSize       = 30
                };
                titleLabel.SetDynamicResource(Label.TextColorProperty, nameof(BaseTheme.TextColor));

                closeButton.Margin = titleLabel.Margin = new Thickness(0, titleTopMargin, 0, 0);

                var activityIndicator = new ActivityIndicator
                {
                    AutomationId = ReferringSitesPageAutomationIds.ActivityIndicator,
                };
                activityIndicator.SetDynamicResource(ActivityIndicator.ColorProperty, nameof(BaseTheme.RefreshControlColor));
                activityIndicator.SetBinding(IsVisibleProperty, nameof(ReferringSitesViewModel.IsActivityIndicatorVisible));
                activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(ReferringSitesViewModel.IsActivityIndicatorVisible));

                var relativeLayout = new RelativeLayout();

                relativeLayout.Children.Add(_refreshView,
                                            Constraint.Constant(0),
                                            Constraint.Constant(0),
                                            Constraint.RelativeToParent(parent => parent.Width),
                                            Constraint.RelativeToParent(parent => parent.Height));

                relativeLayout.Children.Add(titleRowBlurView,
                                            Constraint.Constant(0),
                                            Constraint.Constant(0),
                                            Constraint.RelativeToParent(parent => parent.Width),
                                            Constraint.Constant(titleRowHeight));

                relativeLayout.Children.Add(titleLabel,
                                            Constraint.Constant(10),
                                            Constraint.Constant(0));

                relativeLayout.Children.Add(closeButton,
                                            Constraint.RelativeToParent(parent => parent.Width - GetWidth(parent, closeButton) - 10),
                                            Constraint.Constant(0),
                                            Constraint.RelativeToParent(parent => GetWidth(parent, closeButton)));

                relativeLayout.Children.Add(activityIndicator,
                                            Constraint.RelativeToParent(parent => parent.Width / 2 - GetWidth(parent, activityIndicator) / 2),
                                            Constraint.RelativeToParent(parent => parent.Height / 2 - GetHeight(parent, activityIndicator) / 2));

                Content = relativeLayout;
            }
            else
            {
                Content = _refreshView;
            }
        }
Exemplo n.º 16
0
        public ReactiveUiSearch()
        {
            Title = "Rx - Search";

            this.ViewModel = new ViewModels.SearchViewModel();

            Content = new StackLayout
            {
                Padding  = new Thickness(8d),
                Children =
                {
                    (_textEntry            = new Entry             {
                        Placeholder        = "Enter Search Terms"
                    }),
                    (_search               = new Button            {
                        Text               = "Search"
                    }),
                    (_loading              = new ActivityIndicator {
                    }),
                    (_pullToRefresh        =
                         new RefreshView
                    {
                        Content            =
                            _searchResults =
                                new ListView(ListViewCachingStrategy.RecycleElement)
                        {
                            ItemTemplate   = new DataTemplate(typeof(DuckDuckGoResultCell))
                        },
                        HorizontalOptions  = LayoutOptions.FillAndExpand,
                        VerticalOptions    = LayoutOptions.FillAndExpand,
                    }),
                }
            };

            this.WhenActivated(
                (CompositeDisposable disposables) =>
            {
                _searchErrorDisposable?.Dispose();
                _searchErrorDisposable = new SerialDisposable();

                //TODO: RxSUI - Item 1 - Here we are just setting up bindings to our UI Elements
                //This is a two-way bind
                this.Bind(ViewModel, x => x.SearchQuery, c => c._textEntry.Text)
                .DisposeWith(disposables);

                this.BindCommand(ViewModel, x => x.Search, c => c._search, this.WhenAnyValue(x => x.ViewModel.SearchQuery))
                .DisposeWith(disposables);

                //Once this event is fired off, it will start the refresh
                Observable
                .FromEventPattern(
                    x => _pullToRefresh.Refreshing += x,
                    x => _pullToRefresh.Refreshing -= x)
                .Select(_ => this.WhenAnyValue(x => x.ViewModel.SearchQuery).Take(1))
                .Switch()
                .InvokeCommand(this, x => x.ViewModel.Search)
                .DisposeWith(disposables);

                //This will only trigger when the search command completes
                this.WhenAnyObservable(x => x.ViewModel.Search)
                .Select(_ => false)
                .ObserveOn(RxApp.MainThreadScheduler)
                .BindTo(this, ui => ui._pullToRefresh.IsRefreshing)
                .DisposeWith(disposables);

                //This is a one-way bind
                this.OneWayBind(ViewModel, x => x.SearchResults, c => c._searchResults.ItemsSource)
                .DisposeWith(disposables);

                //TODO: RxSUI - Item 2 - User error allows us to interact with our users and get feedback on how to handle an exception
                this.WhenAnyValue(x => x.ViewModel.SearchError)
                .Where(x => x != null)
                .Subscribe(searchError =>
                {
                    _searchErrorDisposable.Disposable =
                        searchError
                        .RegisterHandler(async interaction =>
                    {
                        var result = await this.DisplayAlert("Error", $"{interaction.Input}{Environment.NewLine}Would you like to retry?", "Retry", "Cancel");
                        interaction.SetOutput(result);
                    });
                })
                .DisposeWith(disposables);

                _searchErrorDisposable
                .DisposeWith(disposables);
            });
        }