예제 #1
0
        public LandingViewModel(IGALogger logger, IUserInfoService userInfoService,
                                IHUDProvider hudProvider, IObservationService observationService, ISiteRepository siteRepository,
                                IActivityRepository activityRepository, IIndicatorRepository indicatoryRepository,
                                ISiteIndicatorRepository siteIndicatoryRepository, IObservationRepository observationRepository,
                                IObservationEntryRepository observationEntryRepository, IObservationChangeRepository observationChangeRepository,
                                IObservationCommentRepository observationCommentRepository, IObservationAttachmentRepository observationAttachmentRepository,
                                IIndicatorAgeRepository indicatoryAgeRepository, IDeviceSettings deviceSettings)
        {
            _userInfoService                 = userInfoService;
            _hudProvider                     = hudProvider;
            _observationService              = observationService;
            _siteRepository                  = siteRepository;
            _activityRepository              = activityRepository;
            _indicatorRepository             = indicatoryRepository;
            _siteIndicatorRepository         = siteIndicatoryRepository;
            _observationRepository           = observationRepository;
            _observationEntryRepository      = observationEntryRepository;
            _observationChangeRepository     = observationChangeRepository;
            _observationCommentRepository    = observationCommentRepository;
            _observationAttachmentRepository = observationAttachmentRepository;
            _indicatorAgeRepository          = indicatoryAgeRepository;
            _deviceSettings                  = deviceSettings;

            DownloadText        = AppResources.DownloadText;
            LastInformationText = AppResources.LastInformationText;
            DownloadButtonText  = AppResources.DownloadButtonText;

            var culture = DependencyService.Get <ILocale>().GetCurrentCultureInfo();

            if (culture.TwoLetterISOLanguageName == "fr")
            {
                LanguageId = 2;
            }
            else if (culture.TwoLetterISOLanguageName == "es")
            {
                LanguageId = 3;
            }
            else
            {
                LanguageId = 1;
            }


            //GetUserInfo
            var userInfo = _userInfoService.GetSavedInfo();

            if (!string.IsNullOrEmpty(userInfo.LastDownload))
            {
                try
                {
                    var last = DateTime.Parse(userInfo.LastDownload);
                    var ci   = DependencyService.Get <ILocale>().GetCurrentCultureInfo();
                    LastInformationTextDate = userInfo.LastDownload;                     //string.Format(ci, "{0}", last);
                }
                catch
                {
                    LastInformationText = AppResources.NoDownloadText;
                }
            }
            else
            {
                LastInformationText = AppResources.NoDownloadText;
            }
        }
        public ObservationViewModel(IGALogger logger, IUserInfoService userInfoService, IObservationRepository observationRep,
                                    IHUDProvider hudProvider, IObservationEntryRepository observationEntryRepository,
                                    IObservationChangeRepository observationChangeRepository,
                                    IObservationCommentRepository observationCommentRepository,
                                    IObservationAttachmentRepository observationAttachmentRepository,
                                    IObservationService ObservationService, IDeviceSettings deviceSettings)
        {
            _userInfoService                 = userInfoService;
            _hudProvider                     = hudProvider;
            _observationRep                  = observationRep;
            _observationEntryRepository      = observationEntryRepository;
            _observationChangeRepository     = observationChangeRepository;
            _observationCommentRepository    = observationCommentRepository;
            _observationAttachmentRepository = observationAttachmentRepository;
            _observationService              = ObservationService;
            _deviceSettings                  = deviceSettings;

            TestDate = DateTime.Now;


            MessagingCenter.Subscribe <ObservationChange>(this, "ChangeScreen", (change) =>
            {
                if (Changes == null)
                {
                    Changes = new ObservableCollection <ObservationChange>();
                }
                var item = Changes.Where(m => m == change).FirstOrDefault();
                if (item != null)
                {
                    Changes.Remove(item);
                    Changes.Add(item);
                }
                else
                {
                    Changes.Add(change);
                }
                if (_Navigation.ModalStack.Count != 0)
                {
                    _Navigation.PopModalAsync();
                }
            });

            MessagingCenter.Subscribe <ObservationAttachment>(this, "AttachmentScreen", (attach) =>
            {
                if (Attachments == null)
                {
                    Attachments = new ObservableCollection <ObservationAttachment>();
                }
                var item = Attachments.Where(m => m == attach).FirstOrDefault();
                if (item != null)
                {
                    Attachments.Remove(item);
                    Attachments.Add(item);
                }
                else
                {
                    Attachments.Add(attach);
                }
            });

            MessagingCenter.Subscribe <ObsViewModel>(this, "NumDemUpdate", (change) =>
            {
                RaisePropertyChanged("IndicatorNumCount");
                RaisePropertyChanged("IndicatorDenCount");
                RaisePropertyChanged("IndicatorCount");
                RaisePropertyChanged("IndicatorCountDisplay");
            });



            MessagingCenter.Subscribe <ObservationAttachment>(this, "AttachmentScreenCancel", (change) =>
            {
                if (_Navigation.ModalStack.Count != 0)
                {
                    _Navigation.PopModalAsync();
                }
            });

            MessagingCenter.Subscribe <ObservationChange>(this, "ChangeScreenCancel", (change) =>
            {
                Changes = Changes;
                if (_Navigation.ModalStack.Count != 0)
                {
                    _Navigation.PopModalAsync();
                }
            });

            MessagingCenter.Subscribe <ObservationComment>(this, "CommentScreen", (comment) =>
            {
                var item = Comments.Where(m => m == comment).FirstOrDefault();
                if (item != null)
                {
                    Comments.Remove(item);
                    Comments.Add(item);
                }
                else
                {
                    var i = Comments.Count();
                    Comments.Add(comment);
                }
                if (_Navigation.ModalStack.Count != 0)
                {
                    _Navigation.PopModalAsync();
                }
            });

            MessagingCenter.Subscribe <ObservationComment>(this, "CommentScreenCancel", (change) =>
            {
                Comments = Comments;
                if (_Navigation.ModalStack.Count != 0)
                {
                    _Navigation.PopModalAsync();
                }
            });
        }