示例#1
0
        private async void SetItemList()
        {
            var metaItemInfo = (await LocalStorageController.GetMetaUserInfo());

            isUserLocal = metaItemInfo == null ? ContentManager.isLocal : metaItemInfo.IsLocal;
            if (isUserLocal)
            {
                itemList = await LocalStorageController.GetTableListAsync <Item>();
            }
            // Check if user is connected before retrieving data from online
            else if (Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.Internet)
            {
                itemList = (await FireBaseController.GetItems()).ToList().ConvertAll(o => o.Object);
            }
        }
示例#2
0
        public override async void PerformFetch(UIApplication application, Action <UIBackgroundFetchResult> completionHandler)
        {
            base.PerformFetch(application, completionHandler);
            Console.WriteLine("APP DELEGATE 114 Perfor Fetch Called  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            var metaItemInfo = (await LocalStorageController.GetMetaUserInfo());
            var itemList     = new List <Item>();
            var isUserLocal  = metaItemInfo == null ? ContentManager.isLocal : metaItemInfo.IsLocal;

            if (isUserLocal)
            {
                itemList = await LocalStorageController.GetTableListAsync <Item>();
            }
            // Check if user is connected before retrieving data from online
            else if (Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.Internet)
            {
                itemList = (await FireBaseController.GetItems()).ToList().ConvertAll(o => o.Object);
            }

            int expItemCount1 = 0;
            int expItemCount3 = 0;
            int expItemCount7 = 0;

            if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
            {
                foreach (var item in itemList)
                {
                    item.SetDaysUntilExpiration();
                    if (item.daysUntilExp < 1 && !item.oneDayWarning && ContentManager.sessionUserProfile.enableOneDayWarning)
                    {
                        expItemCount1++;
                        item.oneDayWarning = true;
                    }
                    else if (item.daysUntilExp < 3 && !item.threeDaysWarning && ContentManager.sessionUserProfile.enableThreeDayWarning)
                    {
                        expItemCount3++;
                        item.threeDaysWarning = true;
                    }
                    else if (item.daysUntilExp < 7 && !item.weekWarning && ContentManager.sessionUserProfile.enableOneWeekWarning)
                    {
                        expItemCount7++;
                        item.weekWarning = true;
                    }

                    if (isUserLocal)
                    {
                        LocalStorageController.UpdateItem(item);
                    }
                    else if (Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.Internet)
                    {
                        FireBaseController.SaveItem(item);
                    }
                }
                NotifyUser(expItemCount1 + " of your items expire in one day!");
                NotifyUser(expItemCount3 + " of your items expire in three days!");
                NotifyUser(expItemCount7 + " of your items expire in one week!");
            }
            else
            {
                foreach (var item in itemList)
                {
                    item.SetDaysUntilExpiration();
                    if (item.daysUntilExp < 1 && !item.oneDayWarning && ContentManager.sessionUserProfile.enableOneDayWarning)
                    {
                        expItemCount1++;
                        item.oneDayWarning = true;
                    }
                    else if (item.daysUntilExp < 3 && !item.threeDaysWarning && ContentManager.sessionUserProfile.enableThreeDayWarning)
                    {
                        expItemCount3++;
                        item.threeDaysWarning = true;
                    }
                    else if (item.daysUntilExp < 7 && !item.weekWarning && ContentManager.sessionUserProfile.enableOneWeekWarning)
                    {
                        expItemCount7++;
                        item.weekWarning = true;
                    }

                    if (isUserLocal)
                    {
                        LocalStorageController.UpdateItem(item);
                    }
                    else if (Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.Internet)
                    {
                        FireBaseController.SaveItem(item);
                    }
                }
                NotifyUserOld(expItemCount1 + " of your items expire in one day!");
                NotifyUserOld(expItemCount3 + " of your items expire in three days!");
                NotifyUserOld(expItemCount7 + " of your items expire in one week!");
            }
            completionHandler(UIBackgroundFetchResult.NewData);
        }