private void UpdateFileList(string hash)
 {
     _data.GetDirectoryFiles(hash, list =>
     {
         _list = list;
         Repaint();
     }, this.DisplayError);
 }
        private void OnGUI()
        {
            if (!this.DrawOAuthHeader(_data))
            {
                EditorGUILayout.LabelField("Access Token is Invalid");
                return;
            }

            if (_list == null)
            {
                // GetRoot
                if (GUILayout.Button("GetRoot"))
                {
                    _data.GetDirectoryFiles("root", list => _list = list);
                }
                return;
            }

            if (GUILayout.Button("Back"))
            {
                var parents = _list.files[0].parents;
                if (parents != null && parents.Length > 0)
                {
                    void Load(DriveFile file)
                    {
                        if (file.parents == null || file.parents.Length <= 0)
                        {
                            return;
                        }

                        UpdateFileList(file.parents.First());
                    }

                    _data.LoadFile(parents.First(), Load, this.DisplayError);
                }
            }

            foreach (var file in _list.files)
            {
                if (file.IsFolder)
                {
                    if (GUILayout.Button(file.name))
                    {
                        UpdateFileList(file.id);
                    }
                }
                else
                {
                    GUILayout.Label($"{file.name} ({file.KByte}KB)", GUI.skin.button);
                }
            }
        }
예제 #3
0
        private async Task <List <DisplayItem> > GetNaturalOrderList()
        {
            Dictionary <int, DisplayItem> tempNumeredItemList = new();

            DriveFileList driveFileList = await GetDriveFileList();

            if (!driveFileList.items.Any())
            {
                return(new List <DisplayItem>());
            }

            int itemNum = 0;

            foreach (var driveFile in driveFileList.items.OrderBy(i => i.title))
            {
                if (!driveFile.webContentLink.Contains("&"))
                {
                    continue;
                }

                var link = driveFile.webContentLink.Substring(0, driveFile.webContentLink.IndexOf("&"));

                var displayItemType = driveFile.mimeType.ToLower().Contains("video")
                          ? DisplayItemType.Video
                          : DisplayItemType.Image;

                _ = float.TryParse(driveFile.fileSize, out var fileSize);

                tempNumeredItemList.Add(itemNum, new DisplayItem
                {
                    ItemNumber = itemNum,
                    SourceUrl  = link,
                    ItemType   = displayItemType,
                    Title      = driveFile.title,
                    Height     = driveFile.imageMediaMetadata != null ? driveFile.imageMediaMetadata.height : 0,
                    Width      = driveFile.imageMediaMetadata != null ? driveFile.imageMediaMetadata.width : 0,
                    Rotation   = driveFile.imageMediaMetadata != null ? driveFile.imageMediaMetadata.rotation : 0,
                    FileSize   = fileSize.ToString("#.##")
                });

                itemNum++;
            }

            var items = tempNumeredItemList
                        .Select(d => d.Value);

            return(items.ToList());
        }
예제 #4
0
        private async Task <List <DisplayItem> > GetShuffledList()
        {
            Dictionary <int, DisplayItem> tempNumeredItemList = new();

            DriveFileList driveFileList = await GetDriveFileList();

            if (!driveFileList.items.Any())
            {
                return(new List <DisplayItem>());
            }

            const int randomNumbesQuantityMultiplier = 2;
            int       maxRandomNumber = driveFileList.items.Length * randomNumbesQuantityMultiplier;

            int itemNum = 0;

            foreach (var driveFile in driveFileList.items)
            {
                if (!driveFile.webContentLink.Contains("&"))
                {
                    continue;
                }

                var link = driveFile.webContentLink.Substring(0, driveFile.webContentLink.IndexOf("&"));

                var itemAdded = false;

                while (!itemAdded)
                {
                    Random rnd = new();

                    // Arbitraty random numbers (more that items count) just to set an order.
                    int rndPosition = rnd.Next(1, maxRandomNumber);

                    if (!tempNumeredItemList.ContainsKey(rndPosition))
                    {
                        var displayItemType = driveFile.mimeType.ToLower().Contains("video")
                            ? DisplayItemType.Video
                            : DisplayItemType.Image;

                        _ = float.TryParse(driveFile.fileSize, out var fileSize);

                        try
                        {
                            tempNumeredItemList.Add(rndPosition, new DisplayItem
                            {
                                SourceUrl = link,
                                ItemType  = displayItemType,
                                Title     = driveFile.title,
                                Height    = driveFile.imageMediaMetadata != null ? driveFile.imageMediaMetadata.height : 0,
                                Width     = driveFile.imageMediaMetadata != null ? driveFile.imageMediaMetadata.width : 0,
                                Rotation  = driveFile.imageMediaMetadata != null ? driveFile.imageMediaMetadata.rotation : 0,
                                FileSize  = fileSize.ToString("#.##")
                            });
                        }
                        catch (Exception ex)
                        {
                            throw;
                        }

                        itemAdded = true;
                    }
                }
            }

            var shuffledList = tempNumeredItemList
                               .OrderBy(d => d.Key)
                               .Select(d => d.Value);

            foreach (var item in shuffledList)
            {
                item.ItemNumber = itemNum++;
            }

            return(shuffledList.ToList());
        }