Beispiel #1
0
        public ScannerPage(INavigation nav)
        {
            _realm    = Realm.GetInstance();
            _currUser = App.pubUser;
            _nav      = nav;
            Title     = "Scan";
            zxing     = new ZXingScannerView()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };

            zxing.OnScanResult += (result) =>
                                  Device.BeginInvokeOnMainThread(async() =>
            {
                // Stop analysis until we navigate away so we don't keep reading barcodes
                zxing.IsAnalyzing = false;
                zxing.IsScanning  = false;
                        #if __ANDROID__
                // Initialize the scanner first so it can track the current context
                MobileBarcodeScanner.Initialize(Application);
                        #endif

                if (result != null)
                {
                    var answer = await UserDialogs.Instance.ConfirmAsync("Would you like to track this barcode?", "Barcode found!", "Yes", "No");
                    if (answer == true)
                    {
                        string[] timeArray = DateTime.Now.ToString().Split(null);
                        _realm.Write(() =>
                        {
                            var newScan     = _realm.CreateObject <RealmDB.ScanResult>();
                            newScan.Date    = timeArray[0];
                            newScan.Time    = timeArray[1] + " " + timeArray[2];
                            newScan.Format  = result.BarcodeFormat.ToString();
                            newScan.Owner   = _currUser;
                            newScan.Content = result.Text;
                        });
                    }
                }
                await _nav.PopAsync();
            });

            overlay = new ZXingDefaultOverlay
            {
                TopText    = "Hold your phone up to the barcode",
                BottomText = "Scanning will happen automatically",
            };

            var grid = new Grid
            {
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            grid.Children.Add(zxing);
            grid.Children.Add(overlay);

            // The root page of your application
            Content = grid;
        }
Beispiel #2
0
        public MasterPage(RealmDB.User user)
        {
            InitializeComponent();

            var masterPageItems = new List <MasterPageItem>();

            masterPageItems.Add(new MasterPageItem
            {
                Title      = "Contacts",
                IconSource = "contacts.png",
                TargetType = typeof(ContactsPage)
            });
            masterPageItems.Add(new MasterPageItem
            {
                Title      = "TodoList",
                IconSource = "todo.png",
                TargetType = typeof(TodoListPage)
            });
            masterPageItems.Add(new MasterPageItem
            {
                Title      = "Reminders",
                IconSource = "reminders.png",
                TargetType = typeof(ReminderPage)
            });

            listView.ItemsSource = masterPageItems;
        }
Beispiel #3
0
 public void PostLogin(RealmDB.User user)
 {
     App.Current.Properties["IsLoggedIn"]   = true;
     App.Current.Properties["LoggedInUser"] = user.username;
     App.Current.SavePropertiesAsync();
     App.pubUser          = user;
     App.Current.MainPage = new NavigationPage(new RootPage());
 }
Beispiel #4
0
        public App()
        {
            InitializeComponent();
            _realm = Realm.GetInstance();
            var    isLoggedIn  = Properties.ContainsKey("IsLoggedIn") ? (bool)Properties["IsLoggedIn"] : false;
            string persistUser = Properties.ContainsKey("LoggedInUser") ? (string)App.Current.Properties["LoggedInUser"] : "******";

            if (isLoggedIn == true)
            {
                pubUser = _realm.All <RealmDB.User>().Where(u => u.username == persistUser).ToList().FirstOrDefault();

                MainPage = new NavigationPage(new RootPage());
            }
            else
            {
                MainPage = new LoginPage();
            }
        }
Beispiel #5
0
        // Method to login the user
        public async void Login(string userParam, string passParam)
        {
            _realm = Realm.GetInstance();
            var currentUser = _realm.All <RealmDB.User>().Where(d => (d.username == userParam)).ToList().FirstOrDefault();

            if (currentUser == null)
            {
                // Give the user opportunity to create a new user
                var answer = await UserDialogs.Instance.ConfirmAsync("User not found, create user " + userParam + "?", "Cancel", "Create");

                if (answer == true)
                {
                    _realm.Write(() =>
                    {
                        var newUser      = _realm.CreateObject <RealmDB.User>();
                        newUser.username = userParam;
                        newUser.password = passParam;
                    });
                    RealmDB.User loginUser = new RealmDB.User();
                    loginUser.username = userParam;
                    loginUser.password = passParam;
                    // Show successful login
                    UserDialogs.Instance.SuccessToast("User created", null, 3000);
                    PostLogin(loginUser);
                }
            }
            else
            {
                // Check if the username & password match
                RealmDB.User loginUser = _realm.All <RealmDB.User>().Where(u => u.username == userParam && u.password == passParam).ToList().FirstOrDefault();
                if (loginUser == null)
                {
                    // Show login failure
                    UserDialogs.Instance.ErrorToast("Login failed", "Username or password incorrect", 3000);
                }
                PostLogin(loginUser);
            }
        }
Beispiel #6
0
 public OptionsPageViewModel(INavigation navigation)
 {
     _nav      = navigation;
     _currUser = App.pubUser;
 }
Beispiel #7
0
 // Populates the HistoryPage listview
 public HistoryPageViewModel(INavigation iNav)
 {
     _user      = App.pubUser;
     Navigation = iNav;
     _realm     = Realm.GetInstance();
 }
Beispiel #8
0
 public MasterPageViewModel(INavigation navigation)
 {
     _nav      = navigation;
     _currUser = App.pubUser;
 }