public MainPageViewModel(INavigationService navigationService,
                                 ISQLiteFactory sqliteFactory,
                                 IUserDialogs userDialogs)
            : base(navigationService)
        {
            Title = "Main Page";

            _sqliteFactory = sqliteFactory;
            _userDialogs   = userDialogs;
            Todos          = new List <TodoItem>();

            this.DownloadSqliteCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                IsDownloading = true;
                // SHOW USER DIALOG TO SHOW DOWNLOAD PROCESS

                using (var dlg = this._userDialogs.Loading("Preparing to download..."))
                {
                    // START DOWNLOAD
                    await _sqliteFactory.DownloadSqlite((status) =>
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            dlg.Title = status;
                        });
                    }).ConfigureAwait(false);

                    Todos = _sqliteFactory.FetchTodoData();
                }

                Device.BeginInvokeOnMainThread(() =>
                {
                    DoesLocalDbExists = true;
                    IsDownloading     = false;
                });
            }, this.WhenAny(
                                                                            x => x.IsDownloading,
                                                                            x => x.DoesLocalDbExists,
                                                                            (isDownloading, doesLocalDbExists) =>
                                                                            isDownloading.GetValue() ||
                                                                            !doesLocalDbExists.GetValue()));

            this.DeleteSqliteCommand = ReactiveCommand.Create(() =>
            {
                Todos = new List <TodoItem>();
                _sqliteFactory.DeleteSqliteFile();
                DoesLocalDbExists = false;
            }, this.WhenAny(
                                                                  x => x.DoesLocalDbExists,
                                                                  (doesLocalDbExists) =>
                                                                  doesLocalDbExists.GetValue()));

            ResfreshCommand = ReactiveCommand.Create(() => { Todos = _sqliteFactory.FetchTodoData(); });
        }
Beispiel #2
0
 public Database(ISQLiteFactory factory) : base(factory, "DoodsSshApp.db")
 {
 }
 public DatabaseService(ISQLiteFactory factory)
 {
     _connection = factory.CreateConnection("quote.db");
     Setup ();
 }
Beispiel #4
0
 public DatabaseService(ISQLiteFactory factory)
 {
     _connection = factory.CreateConnection("quote.db");
     Setup();
 }
Beispiel #5
0
 public SQLiteLink(ISQLiteFactory factory)
 {
     _dbConnection = new SQLiteConnection(factory.Platform(), factory.DatabasePath(), true);
 }
Beispiel #6
0
 protected Database(ISQLiteFactory factory, string dbname)
 {
     AsyncConnection = new SQLiteAsyncConnection(factory.GetDatabasePath(dbname));
 }