Exemplo n.º 1
0
        private async Task SaveCommandExecute()
        {
            LocalDatabaseService database = Ioc.Container.Resolve <LocalDatabaseService>();

            if (string.IsNullOrWhiteSpace(NoteTitle))
            {
                await NavigationService.DisplayAlert("Invalid Note", "You can't leave the title empty", "Ok");
            }
            await database.Insert(new Note
                                  { NoteTitle = NoteTitle, Description = NoteDescription, NoteDateTime = DateTime.Now });

            await NavigationService.PopPageModel(true);
        }
Exemplo n.º 2
0
 protected override void ViewIsAppearing(object sender, EventArgs e)
 {
     Task.Run(async() =>
     {
         _database = Ioc.Container.Resolve <ILocalDatabaseService>() as LocalDatabaseService;
         if (!LocalDatabaseService.DbInitialized)
         {
             await InitializeDb();
         }
         if (_database != null)
         {
             Notes = new ObservableCollection <Note>(await _database.GetAll <Note>());
         }
     });
 }
Exemplo n.º 3
0
        private void InitializeRateViewModel()
        {
            ExchangeRateViewModel = new RatesHostViewModel {
                IsBusy = true
            };
            CalculatorVm = new CalculatorViewModel();

            var rates = LocalDatabaseService.GetRates();

            rates.ContinueWith(x =>
            {
                Debug.WriteLine("MessaginCenter: about to send (GetLocal)");
                MessagingCenter.Send <MainPageViewModel, IEnumerable <Rate> >(this, "GetLocal", x.Result);
            });
        }
Exemplo n.º 4
0
        protected override void OnResume()
        {
            var connection = DependencyService.Get <INetworkConnectionInfo>();

            if (connection.IsOnline())
            {
                MessagingCenter.Send <App, bool>(this, "ShowBusyIndicatorOnResume", true);
            }
            // Handle when your app resumes
            var rates = LocalDatabaseService.GetRates();

            rates.ContinueWith(x =>
            {
                Debug.WriteLine("MessaginCenter: about to send (SyncOnResume)");
                MessagingCenter.Send <App, IEnumerable <Rate> >(this, "SyncOnResume", x.Result);
            });
        }
Exemplo n.º 5
0
        public SettingViewModel()
        {
            DarkModeIsToggled = GlobalVariables.DarkMode;
            CurrentVersion    = AppInfo.VersionString;

            ThemeCommand = new Command(() =>
            {
                GlobalVariables.DarkMode = DarkModeIsToggled;
                Theme theme = GlobalVariables.DarkMode ? Theme.Dark : Theme.Light;

                ICollection <ResourceDictionary> mergedDictionaries = Application.Current.Resources.MergedDictionaries;
                if (mergedDictionaries != null)
                {
                    mergedDictionaries.Clear();

                    switch (theme)
                    {
                    case Theme.Dark:
                        mergedDictionaries.Add(new DarkTheme());
                        break;

                    case Theme.Light:
                    default:
                        mergedDictionaries.Add(new LightTheme());
                        break;
                    }
                }
            }, () => { return(true); });

            ClearCacheCommand = new Command(async() =>
            {
                LocalDatabaseService localDatabaseService = new LocalDatabaseService();
                int total = await localDatabaseService.ClearAllData();
                if (total > 0)
                {
                    CrossToastPopUp.Current.ShowToastSuccess("清理完成,共清理" + total.ToString() + "条数据", ToastLength.Long);
                }
            }, () => { return(true); });

            UpdateCommand = new Command(async() =>
            {
                await CheckAppVersionAsync();
            }, () => { return(true); });
        }
Exemplo n.º 6
0
        public static async Task <IEnumerable <Rate> > SyncRemoteRates(DateTime?lastUpdate)
        {
            List <Rate>    results;
            HttpWebRequest request      = CreateRequest();
            var            responseTask = request.GetResponseAsync();

            using (var response = await responseTask)
            {
                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    var content = reader.ReadToEnd();
                    results = JsonConvert.DeserializeObject <List <Rate> >(content);
                }
            }

            DateTime remoteLastUpdate = (from d in results select d.LastUpdated).Max();

            if (!lastUpdate.HasValue || lastUpdate.Value != remoteLastUpdate)
            {
                await LocalDatabaseService.SyncLocalDatabase(results);
            }
            return(results);
        }