コード例 #1
0
        public static async Task Fetch()
        {
            if (AppData.auth.CurrentUser == null)
            {
                return;
            }

            AppData.invitationLists = new List <GroceryListClass>();

            foreach (InvitationClass anyInvite in AppData.invitationData)
            {
                var allItems = await AppData.dataNode.Child(anyInvite.Owner.Uid).Child(anyInvite.Name).Child("Items").OnceAsync <ItemClass>();

                List <ItemClass> itemsOfList = new List <ItemClass>();

                foreach (FirebaseObject <ItemClass> any in allItems)
                {
                    itemsOfList.Add(any.Object);
                }

                GroceryListClass thisList = new GroceryListClass
                {
                    Name  = anyInvite.Name,
                    Items = itemsOfList,
                    Owner = anyInvite.Owner
                };

                AppData.invitationLists.Add(thisList);
            }
        }
コード例 #2
0
        public static void Save(GroceryListClass inpList)
        {
            if (AppData.auth.CurrentUser == null)
            {
                return;
            }


            var allItemsDict = new Dictionary <string, object> {
            };

            foreach (ItemClass anyItem in inpList.Items)
            {
                allItemsDict.Add(anyItem.Name, anyItem);
            }

            var mainDict = new Dictionary <string, object>
            {
                { "Items", allItemsDict },
                { "Name", inpList.Name },
                { "Owner", inpList.Owner }
            };

            if (allItemsDict.Count == 0)
            {
                mainDict.Remove("Items");
            }



            AppData.dataNode
            .Child(AppData.currentUser.Uid)
            .Child(inpList.Name)
            .PutAsync(mainDict);
        }
コード例 #3
0
 public static void Delete(GroceryListClass inpList)
 {
     if (AppData.auth.CurrentUser == null)
     {
         return;
     }
     else
     {
         AppData.dataNode.Child(inpList.Owner.Uid).Child(inpList.Name).DeleteAsync();
     }
 }
コード例 #4
0
        public static void Save(ItemClass thisItem, GroceryListClass thisList)
        {
            if (AppData.auth.CurrentUser == null)
            {
                return;
            }

            AppData.dataNode.Child(thisList.Owner.Uid)
            .Child(thisList.Name)
            .Child("Items")
            .Child(thisItem.Name)
            .PutAsync(thisItem);
        }
コード例 #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.ItemsLayout);

            InterfaceBuilder();

            AppData.GetInstance(this);
            int row = this.Intent.Extras.GetInt("row");

            curList = AppData.currentLists[row];
            listNameTextView.Text = curList.Name;

            itemsAdapter          = new ItemRowListAdapter(this, curList.Items);
            itemsListView.Adapter = itemsAdapter;
        }
コード例 #6
0
        public static async Task Invite(Activity thisActivity, GroceryListClass toList, string inputEmailAddress)
        {
            UserClass inviteeUser = null;
            UserClass ownerUser   = toList.Owner;

            var allUserData = await AppData.usersNode.OnceAsync <UserClass>();

            foreach (FirebaseObject <UserClass> any in allUserData)
            {
                if (inputEmailAddress == any.Object.Email)
                {
                    inviteeUser = any.Object;
                    goto UserExists;
                }
            }

            AlertShow.Show(thisActivity, "No Such User", "The email address you have provided, does not have an account");

            return;

UserExists:

            InvitationClass thisInvite = new InvitationClass()
            {
                Name  = toList.Name,
                Owner = ownerUser
            };

            //unique userID and the name of the list
            string invitationTitle = ownerUser.Uid + "|" + toList.Name;

            await AppData.usersNode.Child(inviteeUser.Uid)
            .Child("Invitations")
            .Child(invitationTitle)
            .PutAsync(thisInvite);

            AlertShow.Show(thisActivity, "Success", "You have successfully invited " + inviteeUser.Name + " to this List");
        }
コード例 #7
0
        public static async Task Read()
        {
            AppData.onlineLists = new List <GroceryListClass>();

            if (AppData.auth.CurrentUser == null)
            {
                return;
            }


            ChildQuery listsNode = AppData.dataNode.Child(AppData.currentUser.Uid);

            var allListsData = await listsNode.OnceAsync <TempGroceryListClass>();

            foreach (FirebaseObject <TempGroceryListClass> any in allListsData)
            {
                List <ItemClass> itemsOfList = new List <ItemClass>();

                ChildQuery thisListNode = listsNode.Child(any.Object.Name);

                var readItems = await thisListNode.Child("Items").OnceAsync <ItemClass>();

                foreach (FirebaseObject <ItemClass> anyItem in readItems)
                {
                    itemsOfList.Add(anyItem.Object);
                }

                GroceryListClass thisList = new GroceryListClass
                {
                    Name  = any.Object.Name,
                    Items = itemsOfList,
                    Owner = any.Object.Owner
                };

                AppData.onlineLists.Add(thisList);
            }
        }
コード例 #8
0
        public static List <GroceryListClass> Compare(List <GroceryListClass> listA, List <GroceryListClass> listB)
        {
            List <GroceryListClass> combinedListsLST = new List <GroceryListClass>();

            //first, if there is a list in one that is not in the other, just copy it
            foreach (GroceryListClass a in listA)
            {
                foreach (GroceryListClass anyList in listB)
                {
                    if (a.Name == anyList.Name)
                    {
                        goto ContinueLoop;
                    }
                }
                combinedListsLST.Add(a);
                ContinueLoop :;
            }

            foreach (GroceryListClass b in listB)
            {
                foreach (GroceryListClass anyList in listA)
                {
                    if (b.Name == anyList.Name)
                    {
                        goto ContinueLoop;
                    }
                }
                combinedListsLST.Add(b);
                ContinueLoop :;
            }

            //if added unique lists, remove them
            foreach (GroceryListClass any in combinedListsLST)
            {
                if (listA.Contains(any))
                {
                    listA.Remove(any);
                }
                if (listB.Contains(any))
                {
                    listB.Remove(any);
                }
            }

            //comparing similar lists with eachother
            foreach (GroceryListClass anyListA in listA)
            {
                List <ItemClass> thisListResultItems = new List <ItemClass>();

                GroceryListClass counterPartList = new GroceryListClass();
                DateTime         combinedTime    = DateTime.UtcNow;

                //checking the deleted status
                foreach (GroceryListClass anyListB in listB)
                {
                    if (anyListB.Name == anyListA.Name)
                    {
                        counterPartList = anyListB;
                        break;
                    }
                }

                //checking the items
                foreach (ItemClass anyItem in anyListA.Items)
                {
                    //compare items from one list to another
                    foreach (ItemClass counterItem in counterPartList.Items)
                    {
                        if (anyItem.Name == counterItem.Name)
                        {
                            //if item exists both sides, we decide which to add based on the one with the latest timestamp on it
                            if (DateTime.Parse(anyItem.Time) > DateTime.Parse(counterItem.Time))
                            {
                                thisListResultItems.Add(anyItem);
                            }
                            else
                            {
                                thisListResultItems.Add(counterItem);
                            }
                            goto ContinueHere;
                        }
                    }
                    //if this is reached where none of the names have matched we then add the item
                    thisListResultItems.Add(anyItem);
                    ContinueHere :;
                }

                //all items of this list should be done, now for counterpart
                foreach (ItemClass anyCounterItem in counterPartList.Items)
                {
                    //compare items from counter to main
                    foreach (ItemClass anyItem in anyListA.Items)
                    {
                        if (anyCounterItem.Name == anyItem.Name)
                        {
                            //items exists on both sides, drop out
                            goto ContinueHere;
                        }
                    }
                    //same again if no item names have matched
                    thisListResultItems.Add(anyCounterItem);
                    ContinueHere :;
                }

                //shopping class cotains all similar and unique lists and items
                combinedListsLST.Add(new GroceryListClass
                {
                    Name  = anyListA.Name,
                    Owner = anyListA.Owner,
                    Items = thisListResultItems
                });
            }
            return(combinedListsLST);
        }