Ejemplo n.º 1
0
        public async Task UpdateLiveMedicineList()
        {
            var list = await _cacheService.GetListOnCache();

            List <MedicineItemGroupedModel> orderedList = new List <MedicineItemGroupedModel>();

            if (list != null)
            {
                list.ForEach(y =>
                {
                    var newGroup = new MedicineItemGroupedModel();
                    y.OrderBy(z => z.IlacTarihi.date).ForEach(item =>
                    {
                        newGroup.Add(item);
                        newGroup.Date = item.IlacTarihi.date;
                        if (EquelsNowMinute(newGroup.Date) && haveScrollAction)
                        {
                            currentlyItems.Add(item);
                            CurrentMedicineAction?.Invoke(item);
                            haveScrollAction = false;
                        }
                    });
                    orderedList.Add(newGroup);
                });
            }
            if (orderedList != null && orderedList.Any())
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    LiveMedicineList = new ObservableCollection <MedicineItemGroupedModel>(orderedList.OrderBy(x => x.Date));
                });
            }
        }
        public LiveMedicineListPage()
        {
            InitializeComponent();
            App.CurrentNavigation = Navigation;
            var bindingContext = BindingContext as MedicineListPageViewModel;

            bindingContext.CurrentMedicineAction = (itemModel) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    MedicineItemModel medicineItemModel             = null;
                    MedicineItemGroupedModel medicineItemGroupModel = null;
                    bindingContext.LiveMedicineList?.ForEach(i =>
                    {
                        var ds = i.Where(j => j.IlacTarihi.date.Equals(itemModel.IlacTarihi.date));
                        if (ds.Any())
                        {
                            medicineItemModel      = ds.Last();
                            medicineItemGroupModel = i;
                            return;
                        }
                    });
                    if (medicineItemModel != null && medicineItemGroupModel != null)
                    {
                        medicineList.ScrollTo(medicineItemModel, medicineItemGroupModel, ScrollToPosition.Start, true);
                    }
                });
            };
        }
Ejemplo n.º 3
0
 public async void SaveDataItem(MedicineItemGroupedModel medicineItemModel, string key = null)
 {
     if (string.IsNullOrEmpty(key))
     {
         key = ToMedicineItemKey(medicineItemModel);
     }
     var cacheModel = new MedicineItemCacheModel(medicineItemModel);
     await LocalMachineCache.InsertObject(key, cacheModel);
 }
Ejemplo n.º 4
0
 public async Task FetchMedicineList()
 {
     IsBusy           = true;
     haveScrollAction = true;
     if (Connectivity.NetworkAccess == NetworkAccess.Internet)
     {
         Device.BeginInvokeOnMainThread(async() =>
         {
             var response = await _api.GetList();
             if (!response.isError)
             {
                 var listData = response.value;
                 MedicineList = new ObservableCollection <MedicineItemGroupedModel>();
                 listData.GroupBy(x => x.IlacTarihi.date.Date).ForEach((y) =>
                 {
                     var group = new MedicineItemGroupedModel()
                     {
                         Date = y.Key
                     };
                     y.ForEach((m) =>
                     {
                         group.Add(m);
                     });
                     MedicineList.Add(group);
                 });
                 if (MedicineList != null)
                 {
                     _cacheService.SaveDataItems(MedicineList.OrderBy(x => x.Date));
                 }
             }
             else
             {
                 //return err msg...
             }
             IsBusy = false;
         });
     }
     else
     {
         IsBusy = false;
     }
 }
Ejemplo n.º 5
0
 private string ToMedicineItemKey(MedicineItemGroupedModel model)
 {
     return(model.Date.Date.Ticks.ToString("X2"));
 }