public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Android.OS.Bundle savedInstanceState) { var view = inflater.Inflate(Resource.Layout.fragment_finder, container, false); R = new fragment_finder(view); adapter = new FlexibleAdapter(null, this); adapter.SetAnimationOnForwardScrolling(true); layoutManager = new SmoothScrollLinearLayoutManager(Context); R.list_recycler.SetLayoutManager(layoutManager); R.list_recycler.SetAdapter(adapter); R.list_recycler.AddItemDecoration(new FlexibleItemDecoration(Context).WithDefaultDivider()); R.list_reloader.SetColorSchemeResources(Resource.Color.colorAccent); R.list_reloader.Refresh += RefreshDirectory; EmptyViewHelper.Create(adapter, R.list_empty); adapter.AddScrollableFooterWithDelay(footerItem, 100L, false); workingPath = "/"; fileSystem = Globals.CloudManager.PersonalClouds[0].RootFS; HasOptionsMenu = true; return(view); }
private void RefreshDirectory(object sender, EventArgs e) { if (!R.list_reloader.Refreshing) { R.list_reloader.Refreshing = true; } if (!workingPath.EndsWith(Path.AltDirectorySeparatorChar)) { workingPath += Path.AltDirectorySeparatorChar; } var activity = (MainActivity)Activity; if (workingPath.Length == 1) { activity.SetActionBarTitle(Resource.String.personal_cloud); try { Globals.CloudManager.NetworkMayChanged(false); } catch { } // Ignored. } Task.Run(async() => { string title = null; if (workingPath.Length != 1) { var deviceNameEnd = workingPath.IndexOf(Path.AltDirectorySeparatorChar, 1); if (deviceNameEnd != -1) { title = workingPath.Substring(1, deviceNameEnd).Trim(Path.AltDirectorySeparatorChar); } } var models = new List <IFlexible>(); if (workingPath.Length != 1) { var parentPath = Path.GetFileName(Path.GetDirectoryName(workingPath.TrimEnd(Path.AltDirectorySeparatorChar)).TrimEnd(Path.AltDirectorySeparatorChar)); models.Add(new FolderGoBack(parentPath)); } try { var files = await fileSystem.EnumerateChildrenAsync(workingPath).ConfigureAwait(false); items = files.Where(x => !x.Attributes.HasFlag(FileAttributes.Hidden) && !x.Attributes.HasFlag(FileAttributes.System)) .OrderByDescending(x => x.IsDirectory).ThenBy(x => x.Name).ToList(); models.AddRange(items.Select(x => new FileFolder(x))); } catch (HttpRequestException exception) { items = null; Activity.RunOnUiThread(() => { Activity.ShowAlert(GetString(Resource.String.error_remote), exception.Message); }); } catch (Exception exception) { Activity.RunOnUiThread(() => { Activity.ShowAlert(GetString(Resource.String.error_folder_title), exception.GetType().Name); }); } Activity.RunOnUiThread(() => { adapter.RemoveScrollableFooter(footerItem); adapter.UpdateDataSet(models, true); //adapter.SmoothScrollToPosition(0); adapter.AddScrollableFooterWithDelay(footerItem, 100L, false); if (!string.IsNullOrEmpty(title)) { activity.SetActionBarTitle(title); } if (R.list_reloader.Refreshing) { R.list_reloader.Refreshing = false; } Activity.InvalidateOptionsMenu(); }); }); }