public DocumentListPage(string search, string selectedFolderName, string parentName, string updatePath) { ViewModel = new BaseViewModel {}; BindingContext = ViewModel; _updatePath = updatePath; _selectedFolderName = selectedFolderName; Title = string.IsNullOrEmpty(parentName) ? "" : parentName; _documentListView = new DocumentListView(); _documentListView.ItemTapped += async (sender, e) => { try { if (CrossConnectivity.Current.IsConnected == false) { await DisplayAlert("Error", "Please check internet connectivity.", "OK"); return; } if (_documentListView.AcquireTapLock()) { var selectedItem = (Document) e.Item; if (!selectedItem.IsFolder) { int index = selectedItem.Name.LastIndexOf("."); if (index > 0) { var fileExt = selectedItem.Name.Substring(index + 1); if (ImageHelper.SuportedExtension.Contains(fileExt.ToLower())) { await Navigation.PushAsync(new ContentPageXaml(selectedItem, _selectedFolderName, this.Navigation)); } else { await DisplayAlert("Error", "This file type is not suported for preview.", "OK"); } } else { await DisplayAlert("Error", "This file type is not suported for preview.", "OK"); } } else { string tempSelectedFolderName = selectedItem.Name; string path = selectedItem.RelativePath + "/" + selectedItem.Name; await Navigation.PushAsync( new DocumentListPage(path, tempSelectedFolderName, _selectedFolderName, path), true); } _documentListView.ReleaseTapLock(); ((ListView) sender).SelectedItem = null; } } catch (Exception ex) { DisplayAlert("Error", "An exception occurred.", "OK"); } }; _documentListView.Refreshing += async (sender, e) => { try { _documentListView.IsRefreshing = true; lstDocuments = await Task.Run(() => GetUpdatedDocuments(search)); if (lstDocuments.Count > 0) { _documentListView.ItemsSource = null; _documentListView.ItemsSource = lstDocuments; } } catch (Exception ex) { if (ex.Message.ToUpper().Equals(Constants.INVALID_TOKEN_MSG.ToUpper())) { DisplayAlert("Error","Your session has expired,please relogin.", "OK"); Application.Current.MainPage = new LoginPage(); } else { DisplayAlert("Error","An exception occurred.", "OK"); } } finally { _documentListView.EndRefresh(); _documentListView.IsRefreshing = false; } }; Content = GetDocumentPage(_documentListView, ""); Device.BeginInvokeOnMainThread(() => BindList(search)); }
private StackLayout GetDocumentPage(DocumentListView lsDocumentListView, string labelName) { _myLabel = new Label { Text = labelName, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), VerticalOptions = LayoutOptions.Center, XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, }; var activityIndicator = new ActivityIndicator { Color = Color.Black }; activityIndicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy"); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy"); var stack = new StackLayout() { Children = { _myLabel, activityIndicator, lsDocumentListView } }; return stack; }