Пример #1
0
        private void PopulateFolders()
        {
            if (_project == null)
            {
                return;
            }

            var folders = new Dictionary <string, FolderHolder>();
            var allDocumentsWithPath = _project.Documents.GroupBy(p => MakeFullPath(p.Folders)).OrderBy(k => k.Key).ToArray();

            foreach (var folderGroup in allDocumentsWithPath)
            {
                var          subFolders    = folderGroup.First().Folders;
                var          subFolderPath = new List <string>();
                FolderHolder parentFolder  = null;
                foreach (string subFolderName in subFolders)
                {
                    subFolderPath.Add(subFolderName);
                    string       fullPath = MakeFullPath(subFolderPath);
                    FolderHolder thisFolder;
                    if (!folders.TryGetValue(fullPath, out thisFolder))
                    {
                        thisFolder        = new FolderHolder(subFolderName, fullPath);
                        folders[fullPath] = thisFolder;
                        if (parentFolder != null)
                        {
                            parentFolder.SubFolders.Add(thisFolder);
                        }
                        else
                        {
                            thisFolder.IsRoot = true;
                        }
                    }
                    parentFolder = thisFolder;
                }
                if (parentFolder != null)
                {
                    parentFolder.Documents.AddRange(folderGroup);
                }
            }

            var allRootFolders = folders.Values.Where(f => f.IsRoot).ToArray();
            var rootFolders    = new List <NodeBase>();

            foreach (var rootFolder in allRootFolders)
            {
                rootFolders.Add(rootFolder.ToFolderNode());
            }
            var rootDocuments = allDocumentsWithPath.FirstOrDefault(g => g.Key == "");

            if (rootDocuments != null)
            {
                foreach (var rootDocument in rootDocuments)
                {
                    rootFolders.Add(new DocumentNode(rootDocument));
                }
            }
            ChildNodes = rootFolders.ToArray();
        }
Пример #2
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            if (inflater == null)
            {
                inflater = Preferences.instance.LayoutInflater;
            }
            if (convertView == null)
            {
                convertView = inflater.Inflate(resource, parent, false);
            }
            FolderHolder holder = new FolderHolder(convertView)
            {
                Name = { Text = folders[position].name },
            };

            holder.expandChild.Visibility = ViewStates.Visible;

            if (!folders[position].asChild)
            {
                holder.expandChild.Visibility = ViewStates.Invisible;
            }

            if (folders[position].isExtended)
            {
                holder.expandChild.SetImageResource(Resource.Drawable.ExpandLess);
            }
            else
            {
                holder.expandChild.SetImageResource(Resource.Drawable.ArrowDown);
            }

            convertView.FindViewById <RelativeLayout>(Resource.Id.folderList).SetPadding(folders[position].Padding, 0, 0, 0);

            holder.used.SetTag(Resource.Id.folderUsed, folders[position].uri);
            holder.used.Click  += DownloadFragment.instance.Used_Click;
            holder.used.Checked = position == selectedPosition;
            holder.used.SetTag(Resource.Id.folderName, position);

            return(convertView);
        }