Exemplo n.º 1
0
        private void DeckListViewItemClickEventHandler(DeckInformation deck)
        {
            mainPage.Collection.Deck.Select(deck.Id, false);
            if (deck.NewCards > 0 || deck.DueCards > 0)
            {
                MakesureCleanState();
                mainPage.Collection.Sched.Reset();
                Frame.Navigate(typeof(ReviewPage), mainPage);
            }
            else if (!collection.Deck.IsDyn(deck.Id))
            {
                if (customStudyFlyout == null)
                {
                    InitCustomStudyFlyout();
                }

                customStudyFlyout.InitDeckValue(collection, isNightMode);
                customStudyFlyout.Show();
            }
            else
            {
                var task = mainPage.CurrentDispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    await UIHelper.ShowMessageDialog("This \"Custom Study\" deck has no cards to learn or review. Please delete it.");
                });
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sort a sub-deck into its parent
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="child"></param>
        private void SortIntoSubdeck(DeckInformation parent, DeckInformation child)
        {
            int currentIndex = decks.IndexOf(child);
            int parentIndex  = decks.IndexOf(parent);

            //No need to do anything if it's already next to its parent
            if (currentIndex == parentIndex + 1)
            {
                return;
            }

            Decks.Remove(child);
            int childLevel = child.ChildLevel;

            parentIndex = decks.IndexOf(parent);

            for (int i = parentIndex + 1; i < decks.Count; i++)
            {
                int level = decks[i].ChildLevel;
                if (level > childLevel)
                {
                    continue;
                }

                if ((level < childLevel) || (Compare(child, decks[i]) < 0))
                {
                    Decks.Insert(i, child);
                    return;
                }
            }

            Decks.Add(child);
        }
Exemplo n.º 3
0
        private async void OnDeckDragAnDrop(DeckInformation parent, DeckInformation child)
        {
            try
            {
                deckListViewModel.DragAnDrop(parent, child, decksView);

                UpdateNoticeText();
            }
            catch (DeckRenameException ex)
            {
                if (ex.Error == DeckRenameException.ErrorCode.ALREADY_EXISTS)
                {
                    await UIHelper.ShowMessageDialog("A deck with the same name already exists.");

                    return;
                }
                if (ex.Error == DeckRenameException.ErrorCode.FILTERED_NOSUBDEKCS)
                {
                    await UIHelper.ShowMessageDialog("A \"Custom Study Deck\" can't become a parent deck.");

                    return;
                }
            }
            catch
            {
                await UIHelper.ShowMessageDialog("Unexpected error.");

                return;
            }
        }
Exemplo n.º 4
0
        private int SortBySubDeckLevel(DeckInformation first, DeckInformation second, Comparison <DeckInformation> comarison)
        {
            int firstChildLevel  = first.ChildLevel;
            int secondChildLevel = second.ChildLevel;

            if (firstChildLevel > secondChildLevel)
            {
                return(1);
            }
            else if (firstChildLevel < secondChildLevel)
            {
                return(-1);
            }
            else
            {
                if (firstChildLevel == 1)
                {
                    return(comarison(first, second));
                }
                else // Child deck in reverse so the next sort will put them in the correct order
                {
                    return(-comarison(first, second));
                }
            }
        }
Exemplo n.º 5
0
        public void ToggleChildrenVisibility(DeckInformation parent, IAnkiDecksView decksView)
        {
            var children = GetChildren(parent);

            parent.IsShowChildren = !parent.IsShowChildren;

            foreach (var deck in children.Desks)
            {
                if (parent.IsShowChildren)
                {
                    if (Collection.Deck.IsParent(parent.Name, deck.Name))
                    {
                        deck.Visibility = Visibility.Visible;
                    }
                }
                else
                {
                    deck.Visibility     = Visibility.Collapsed;
                    deck.IsShowChildren = false;
                }
                var item = decksView.GetItemView(deck);
                if (item != null)
                {
                    item.Visibility = deck.Visibility;
                }
            }
        }
Exemplo n.º 6
0
        private void SubtractCardsCountFromTotalIfNotChild(DeckInformation deckInfor)
        {
            if (Collection.Deck.HasParent(deckInfor.Name))
            {
                return;
            }

            TotalNewCards -= deckInfor.NewCards;
            TotalDueCards -= deckInfor.DueCards;
        }
Exemplo n.º 7
0
 public static Windows.UI.Color GetColors(DeckInformation deck)
 {
     if (deck.NewCards + deck.DueCards > 0)
     {
         return(Colors.Orange);
     }
     else
     {
         return(Colors.DodgerBlue);
     }
 }
Exemplo n.º 8
0
 public static Windows.UI.Color GetColors(DeckInformation deck)
 {
     if (deck.NewCards + deck.DueCards > 0)
     {
         return(UIHelper.DeckWithNewOrDueCardsBrush.Color);
     }
     else
     {
         return(UIHelper.AppDefaultTileBackgroundBrush.Color);
     }
 }
Exemplo n.º 9
0
 private async Task UpdateSecondaryTileIfHas(DeckInformation deck)
 {
     try
     {
         await TilesHelper.UpdateTile(deck.Id.ToString(), deck.NewCards.ToString(), deck.DueCards.ToString());
     }
     catch (Exception e)
     { //App should not crash if any error happen
         Debug.WriteLine("DeckListViewModel.DeleteSecondaryTileIfHas: " + e.Message);
     }
 }
Exemplo n.º 10
0
        private async Task UploadChangedDeckImages(IReadOnlyList <StorageFile> files)
        {
            var remoteItems = await syncInstance.GetChildrenInRemoteFolder(Constant.DEFAULT_DECK_IMAGE_FOLDER_SYNC_PATH);

            var localCacheItems = await deckImageCacheFolder.GetFilesAsync();

            foreach (var file in files)
            {
                if (file.Name == DeckInformation.DEFAULT_IMAGE_NAME)
                {
                    continue;
                }

                var  cacheItem            = DeckInformation.TryGetCacheItem(localCacheItems, file.Name);
                long localFileDateCreated = 0;
                if (cacheItem != null)
                {
                    localFileDateCreated = long.Parse(cacheItem.Name.Split(DeckInformation.IMAGE_NAME_SEPARATOR)[1]);
                }

                bool isHasFile = false;
                foreach (var item in remoteItems)
                {
                    var splitString = item.Name.Split(DeckInformation.IMAGE_NAME_SEPARATOR);
                    if (splitString.Length != 2)
                    {
                        continue;
                    }

                    string name            = splitString[0];
                    long   itemDateCreated = long.Parse(splitString[1]);

                    if (name == file.Name)
                    {
                        if (itemDateCreated < localFileDateCreated)
                        {
                            await syncInstance.DeleteItemWithPathAsync(Constant.DEFAULT_DECK_IMAGE_FOLDER_SYNC_PATH + "/" + item.Name);
                            await UploadDeckImageFile(file, localFileDateCreated);
                        }

                        isHasFile = true;
                        remoteItems.Remove(item);
                        break;
                    }
                }

                if (!isHasFile)
                {
                    await UploadDeckImageFile(file, localFileDateCreated);
                }
            }

            await DeleteUnusedDeckImagesOnServer(remoteItems);
        }
Exemplo n.º 11
0
 private int Compare(DeckInformation comparer, DeckInformation compared)
 {
     if (sortBy == SortBy.Name)
     {
         return(comparer.BaseName.CompareTo(compared.BaseName));
     }
     else
     {
         return(comparer.Id.CompareTo(compared.Id));
     }
 }
Exemplo n.º 12
0
        public string GetNewFullName(DeckInformation deck, string newBaseName)
        {
            var split = deck.Name.Split(new string[] { Constant.SUBDECK_SEPERATE }, StringSplitOptions.RemoveEmptyEntries);

            if (split.Length < 2)
            {
                return(newBaseName);
            }

            split[split.Length - 1] = newBaseName;
            return(String.Join(Constant.SUBDECK_SEPERATE, split));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Update total card count (new + review) of a deck
        /// </summary>
        /// <param name="deckId">Id of the updated deck</param>
        /// <param name="deck">If this parameter is null, it will be retrieved by using deckId
        /// which resutls in slower performance.</param>
        public void UpdateCardCountForDeck(long deckId, DeckInformation deck = null)
        {
            if (deck == null)
            {
                deck = GetDeck(deckId);
            }

            SubtractCardsCountFromTotalIfNotChild(deck);
            var deckCardCount = AddNewDeckCardCount(deckId);

            deck.NewCards = deckCardCount.New;
            deck.DueCards = deckCardCount.Due;
        }
Exemplo n.º 14
0
        public void UpdateDeckName(DeckInformation deck, bool isAlsoUpdateChildren = true)
        {
            deck.Name = Collection.Deck.GetDeckName(deck.Id);

            if (isAlsoUpdateChildren)
            {
                var children = GetChildren(deck);
                foreach (var child in children.Desks)
                {
                    child.Name = Collection.Deck.GetDeckName(child.Id);
                }
            }
        }
Exemplo n.º 15
0
 private void Awake()
 {
     if (instance == null)
     {
         DontDestroyOnLoad(this.gameObject);
         instance = this;
     }
     else
     {
         if (instance != this)
         {
             Destroy(this.gameObject);
         }
     }
 }
Exemplo n.º 16
0
 private void ShowDeckContextMenu(DeckInformation deck, UIElement target, Point offset)
 {
     if (deck.IsDynamic)
     {
         if (dynamicDeckMenuFlyout == null)
         {
             dynamicDeckMenuFlyout = Resources["DynamicDeckContextMenu"] as MenuFlyout;
         }
         dynamicDeckMenuFlyout.ShowAt(target, offset);
     }
     else
     {
         deckMenuFlyout.ShowAt(target, offset);
     }
 }
Exemplo n.º 17
0
        private async Task DownloadChangedDeckImages(List <StorageFile> files)
        {
            var remoteItems = await syncInstance.GetChildrenInRemoteFolder(Constant.DEFAULT_DECK_IMAGE_FOLDER_SYNC_PATH);

            var localCacheItems = await deckImageCacheFolder.GetFilesAsync();

            foreach (var item in remoteItems)
            {
                var splitString = item.Name.Split(DeckInformation.IMAGE_NAME_SEPARATOR);
                if (splitString.Length != 2)
                {
                    continue;
                }

                string name        = splitString[0];
                long   dateCreated = long.Parse(splitString[1]);

                bool isHasFile = false;
                foreach (var file in files)
                {
                    if (name == file.Name)
                    {
                        var  cacheFile        = DeckInformation.TryGetCacheItem(localCacheItems, name);
                        long localDateCreated = 0;
                        if (cacheFile != null)
                        {
                            localDateCreated = long.Parse(cacheFile.Name.Split(DeckInformation.IMAGE_NAME_SEPARATOR)[1]);
                        }

                        if (dateCreated > localDateCreated)
                        {
                            await ChangeDeckImage(item, name, dateCreated);
                        }

                        isHasFile = true;
                        files.Remove(file);
                        break;
                    }
                }

                if (!isHasFile)
                {
                    await ChangeDeckImage(item, name, dateCreated);
                }
            }

            await DeleteLocalUnusedDeckImage(files);
        }
Exemplo n.º 18
0
        private async Task DeleteLocalUnusedDeckImage(List <StorageFile> files)
        {
            if (files.Count > 0)
            {
                foreach (var file in files)
                {
                    if (file.Name == DeckInformation.DEFAULT_IMAGE_NAME)
                    {
                        continue;
                    }

                    var deckInfor = new DeckInformation(null, 0, 0, long.Parse(file.Name), false);
                    await deckInfor.ChangeBackToDefaultImage();
                }
            }
        }
Exemplo n.º 19
0
        public void DragAnDrop(DeckInformation parent, DeckInformation child, IAnkiDecksView deckView)
        {
            var oldName         = child.Name;
            var oldParent       = child.ParentName;
            var childrenOfChild = GetChildren(child);

            if (Collection.Deck.IsParent(parent.Name, child.Name))
            {
                RemoveFromSubDeck(child); //Remove from children if child deck is dragged on parent deck
            }
            else
            {
                CreateSubDeck(parent, child);
            }

            //Children name of child must be updated later
            UpdateDeckName(child, false);
            //If name does not change no need to update anything
            if (oldName.Equals(child.Name, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            //Remove children of child first to avoid sorting errors
            RemoveChildrenFromDecks(childrenOfChild);

            if (Collection.Deck.IsParent(parent.Name, child.Name))
            {
                parent.IsParent = true;
                if (!parent.IsShowChildren)
                {
                    ToggleChildrenVisibility(parent, deckView);
                }
                SortIntoSubdeck(parent, child);
            }
            else
            {
                ResortNonSubdeck(child);
            }

            SetInShowChildrenState(child);
            UpdateChildrenPositionAndName(child, childrenOfChild);
            UpdateOldParent(oldParent);

            UpdateCardCountAllDecks();
            Collection.SaveAndCommitAsync();
        }
Exemplo n.º 20
0
        private void ShowContextMenu(DeckInformation deck, UIElement target, Point offset)
        {
            if (decksView.IsDragAndDropEnable)
            {
                return;
            }

            if (deck != null)
            {
                MakeSureNoFlyoutsOpen();
                ShowDeckContextMenu(deck, target, offset);
                deckShowContextMenu = deck;
            }
            else
            {
                ShowCollectionContextMenu(target, offset);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Re-Sort a non-subdeck
        /// </summary>
        /// <param name="deck"></param>
        public void ResortNonSubdeck(DeckInformation deck)
        {
            Decks.Remove(deck);
            for (int i = 0; i < decks.Count; i++)
            {
                if (decks[i].Name.Contains(Constant.SUBDECK_SEPERATE))
                {
                    continue;
                }

                if (Compare(deck, decks[i]) < 0)
                {
                    Decks.Insert(i, deck);
                    return;
                }
            }
            Decks.Add(deck);
        }
Exemplo n.º 22
0
        private SubDecks GetChildren(DeckInformation deck)
        {
            SubDecks children = new SubDecks();

            children.Desks      = new List <DeckInformation>();
            children.StartIndex = decks.IndexOf(deck) + 1;

            var level = deck.ChildLevel;

            for (int i = children.StartIndex; i < decks.Count; i++)
            {
                var childLevel = decks[i].ChildLevel;
                if (level >= childLevel)
                {
                    break;
                }
                children.Desks.Add(decks[i]);
            }
            return(children);
        }
Exemplo n.º 23
0
        private async Task UploadAllDeckImages(IReadOnlyList <StorageFile> files)
        {
            var localCacheItems = await deckImageCacheFolder.GetFilesAsync();

            foreach (var file in files)
            {
                if (file.Name == DeckInformation.DEFAULT_IMAGE_NAME)
                {
                    continue;
                }

                var cacheItem = DeckInformation.TryGetCacheItem(localCacheItems, file.Name);
                if (cacheItem == null)
                {
                    continue;
                }

                long localFileDateCreated = long.Parse(cacheItem.Name.Split(DeckInformation.IMAGE_NAME_SEPARATOR)[1]);

                await UploadDeckImageFile(file, localFileDateCreated);
            }
        }
Exemplo n.º 24
0
        private void UpdateChildrenPositionAndName(DeckInformation parent, SubDecks children)
        {
            if (children.Desks.Count == 0)
            {
                return;
            }

            var newStartIndex = decks.IndexOf(parent) + 1;

            for (int i = 0; i < children.Desks.Count; i++)
            {
                //No need to update children of a child
                //as they will be aslo updated in this for loop
                UpdateDeckName(children.Desks[i], false);
                if (parent.IsShowChildren)
                {
                    children.Desks[i].IsShowChildren = true;
                    children.Desks[i].Visibility     = Visibility.Visible;
                }

                Decks.Insert(newStartIndex + i, children.Desks[i]);
            }
        }
    // Use this for initialization
    void Start()
    {
        Debug.Log("Start Method() Called.");

        textStyle = new GUIStyle();

        _xWindowScale = Screen.width / 1024.0f;
        _yWindowScale = Screen.height / 768.0f;

        textStyle.fontSize = (int)(textStyle.fontSize * _xWindowScale);
        textStyle.normal.textColor = Color.white;

        _CardHelper = (CardHelpMenu)GameObject.FindGameObjectWithTag("DeckEditorManager").GetComponent("CardHelpMenu");
        _CardHelper.bRenderGamePhases = false;

        _DeckSearcher = new DeckSearcher(800.0f, 230.0f, this);
        _DeckInformation = new DeckInformation(342.0f, 0.0f, this);
        _DeckWatcher = new DeckWatcher(342.0f, 85.0f, this);
    }
 public void SetDeckInformation(DeckInformation deckInfo)
 {
     deckInformationRef = deckInfo;
 }
Exemplo n.º 27
0
 private void OnExpandChildrenClick(DeckInformation parent)
 {
     deckListViewModel.ToggleChildrenVisibility(parent, decksView);
 }
Exemplo n.º 28
0
 private static void SetInShowChildrenState(DeckInformation child)
 {
     child.Visibility     = Visibility.Visible;
     child.IsShowChildren = true;
 }
Exemplo n.º 29
0
 private void CreateSubDeck(DeckInformation parent, DeckInformation child)
 {
     Collection.Deck.RenameForDragAndDrop(child.Id, parent.Id);
 }
Exemplo n.º 30
0
 private void RemoveFromSubDeck(DeckInformation child)
 {
     Collection.Deck.RenameForDragAndDrop(child.Id, null);
 }
Exemplo n.º 31
0
 private int DoSortByName(DeckInformation first, DeckInformation second)
 {
     return(SortBySubDeckLevel(first, second, (x, y) => { return x.BaseName.CompareTo(y.BaseName); }));
 }
Exemplo n.º 32
0
 private int DoSortByDate(DeckInformation first, DeckInformation second)
 {
     return(SortBySubDeckLevel(first, second, (x, y) => { return x.Id.CompareTo(y.Id); }));
 }