private void RefreshDirectory(object sender, EventArgs e) { if (!R.list_reloader.Refreshing) { R.list_reloader.Refreshing = true; } Task.Run(async() => { 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.IsDirectory && !x.Attributes.HasFlag(FileAttributes.Hidden) && !x.Attributes.HasFlag(FileAttributes.System)) .OrderBy(x => x.Name).ToList(); models.AddRange(items.Select(x => new FileFolder(x))); } catch (HttpRequestException exception) { RunOnUiThread(() => this.ShowAlert(GetString(Resource.String.error_remote), exception.Message)); } catch (Exception exception) { RunOnUiThread(() => this.ShowAlert(GetString(Resource.String.error_folder_title), exception.GetType().Name)); } RunOnUiThread(() => { adapter.UpdateDataSet(models, true); if (R.list_reloader.Refreshing) { R.list_reloader.Refreshing = false; } }); }); }
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.StartNetwork(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.UpdateDataSet(models, true); if (!string.IsNullOrEmpty(title)) { activity.SetActionBarTitle(title); } if (R.list_reloader.Refreshing) { R.list_reloader.Refreshing = false; } Activity.InvalidateOptionsMenu(); }); }); }