Example #1
0
        private async void UnregisterClicked(object obj)
        {
            Preferences.Set("RegisteredToBike", "0");
            RegistrationText = "Not registered";

            FrameNumberStatus fns = new FrameNumberStatus()
            {
                LastUpdateTime     = DateTime.Now,
                Latitude           = 0,
                Longitude          = 0,
                LastUpdateClientID = Xamarin.Essentials.DeviceInfo.Name,
                Status             = (int)FrameNumberStatusType.NotRegistered
            };

            IsBusy = true;
            string uuid  = Preferences.Get("UUID", "");
            string user  = Preferences.Get("Email", "");
            string token = Preferences.Get("Token", "");


            await DataStore.UpdateStatus(user, token, uuid, fns);

            var bikeDetailViewModel = ViewModelLocator.Resolve <BikeDetailViewModel>();

            if (bikeDetailViewModel != null)
            {
                MessagingCenter.Send(bikeDetailViewModel, MessageKeys.UpdateState, 1);
            }
            IsBusy = false;
        }
Example #2
0
        private async void ToDetailsPage()
        {
            MessagingCenter.Unsubscribe <App, Models.NFC.TagRead>(this, "Tag");
            if (Message != "" && Message != "Empty" && Message != "(Empty)")
            {
                Preferences.Set("UUID", Message);
            }
            else
            {
                Preferences.Set("UUID", SerialNumber);
            }

            if (Preferences.Get("UseFakeUUID", "0") == "1" && DataService.Constants.FakeUUID != "")
            {
                Preferences.Set("UUID", DataService.Constants.FakeUUID);
            }

            // Send to details page regardless of registreation/login state..
//            TabParameter tabParameter = new TabParameter() { TabIndex = 2 };
//          await NavigationService.NavigateToAsync<MainViewModel>(tabParameter);

            var mainViewModel = ViewModelLocator.Resolve <MainViewModel>();

            if (mainViewModel != null)
            {
                MessagingCenter.Send(mainViewModel, MessageKeys.ChangeTab, 2);
            }
        }
Example #3
0
 public ViewModelBase()
 {
     DialogService     = ViewModelLocator.Resolve <IDialogService>();
     NavigationService = ViewModelLocator.Resolve <INavigationService>();
     AnalyticsService  = ViewModelLocator.Resolve <IAnalyticsService>();
     DataStore         = ViewModelLocator.Resolve <IDigifyyDataService>();
 }
Example #4
0
        private async void BackButtonClicked(object obj)
        {
            // Update state
            var bikeDetailViewModel = ViewModelLocator.Resolve <BikeDetailViewModel>();

            if (bikeDetailViewModel != null)
            {
                MessagingCenter.Send(bikeDetailViewModel, MessageKeys.UpdateState, 1);
            }
            await NavigationService.GoBackAsync();
        }
Example #5
0
        private async void ScanNFC()
        {
            // TabParameter tabParameter = new TabParameter() { TabIndex = 1 };
            // await NavigationService.NavigateToAsync<MainViewModel>(tabParameter);

            var mainViewModel = ViewModelLocator.Resolve <MainViewModel>();

            if (mainViewModel != null)
            {
                MessagingCenter.Send(mainViewModel, MessageKeys.ChangeTab, 1);
            }
        }
        private async void LookupBikeInfo()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            string uuid  = Preferences.Get("UUID", "");
            string user  = Preferences.Get("Email", "");
            string token = Preferences.Get("Token", "");



            if (user != "" && token == "")
            {
                user = "";
            }
            bool isMyBike = false;

            if (uuid != "")
            {
                try
                {
                    UIDInfo result = await DataStore.GetInfo(user, token, uuid);

                    if (result.FrameNumber == null)
                    {
                        await DialogService.Show("UUID unknown", $"The scanned UUID {uuid} is unknown", "Ok");

                        Status = (int)FrameNumberStatusType.UIDNotRegistered;
                        Preferences.Set("UUID", "");
                        UUID           = uuid;
                        Brand          = "";
                        Model          = "";
                        ProductionYear = "";
                    }
                    else
                    {
                        if (result.Owner != null && token != "" && user != "")
                        {
                            if (string.Equals(result.Owner.Email, user, StringComparison.InvariantCultureIgnoreCase))
                            {
                                isMyBike = true;
                            }
                        }

                        Brand = result.FrameNumber.Manufacturer;
                        string model = result.FrameNumber.Model + " ";
                        if (result.FrameNumber.Frame != "")
                        {
                            model += result.FrameNumber.Frame;
                        }

                        Model  = model;
                        UUID   = result.FrameNumber.UID;
                        Status = result.FrameNumberStatus.Status;

                        Preferences.Set("BrandModel", Brand + " " + Model);

                        Stolen = (Status == (int)FrameNumberStatusValue.Stolen);

                        Registered = isMyBike && (Status != (int)FrameNumberStatusValue.Unregistered && Status != (int)FrameNumberStatusValue.Unknown);

                        Preferences.Set("RegisteredToBike", Registered ? "1" : "0");
                        NotRegistered = !Registered;

                        // Make sure we show 'stolen'
                        if (Stolen)
                        {
                            NotRegistered = false;
                        }


                        FrameNumberStatus = result.FrameNumberStatus;
                        ProductionYear    = result.FrameNumber.ProductionDate.Year > 0 ? result.FrameNumber.ProductionDate.Year.ToString() : "";

                        if (result.FrameNumberExtras != null)
                        {
                            FrameNumberExtras = result.FrameNumberExtras;
                        }

                        /* string extras = "";
                         * if (result.FrameNumberExtras != null)
                         * {
                         *   foreach (FrameNumberExtra ext in result.FrameNumberExtras)
                         *   {
                         *       if (extras != "")
                         *           extras += ", ";
                         *       string thisExtra = "";
                         *       if (ext.ExtraBrand != "")
                         *           thisExtra += " ";
                         *       if (ext.ExtraModel != "")
                         *           thisExtra = ext.ExtraModel + " ";
                         *       if (ext.ExtraType != "")
                         *           thisExtra = ext.ExtraType;
                         *       extras += thisExtra.Trim();
                         *   }
                         *   Extras = extras;
                         * }*/

                        DocumentCount = result.FrameNumberDocuments != null ? result.FrameNumberDocuments.Count : 0;
                        Documents     = result.FrameNumberDocuments ?? new List <FrameNumberDocument>();
                        MessageCount  = result.NumberOfMessages;

                        var messageViewModel = ViewModelLocator.Resolve <MessagesViewModel>();

                        if (messageViewModel != null)
                        {
                            MessagingCenter.Send(messageViewModel, MessageKeys.UpdateMessageCount, MessageCount);
                        }



                        if (NotRegistered)
                        {
                            ImagePath = Constants.DefaultProfileImage;
                        }
                        else if (result.ProfileImage != "")
                        {
                            ImagePath = result.ProfileImage;
                            Preferences.Set("ProfileImage", ImagePath);
                        }
                    }
                    IsBusy = false;
                }
                catch (Exception e)
                {
                    AnalyticsService.TrackError(e, new Dictionary <string, string>
                    {
                        { "Method", "BikeDetailViewModel.LookupBikeInfo" }
                    });
                }
            }
            else
            {
                if (hasShowWarning == false)
                {
                    await DialogService.Show("No scans", "No bike has been scanned. Please scan a bike..", "Ok");
                }
                hasShowWarning = true;
                Status         = (int)FrameNumberStatusType.UIDNotRegistered;
                UUID           = uuid;
                Brand          = "";
                Model          = "";

                TabParameter tabParameter = new TabParameter()
                {
                    TabIndex = 1
                };
                await NavigationService.NavigateToAsync <MainViewModel>(tabParameter);
            }
            IsBusy = false;
        }
Example #7
0
        private async void UsePhotoClicked(object obj)
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;
            string url = await Helpers.Utils.UploadFileS3(FileName);

            if (url != "")
            {
                var    bikeDetailViewModel = ViewModelLocator.Resolve <BikeDetailViewModel>();
                string uuid  = Preferences.Get("UUID", "");
                string user  = Preferences.Get("Email", "");
                string token = Preferences.Get("Token", "");


                if (imageType != (int)ImageTypes.Invoice)
                {
                    FrameNumberImage frameNumberImage = new FrameNumberImage()
                    {
                        ImageTitle = "Receipt", ImageType = imageType, ImageUrl = url
                    };
                    var result = await DataStore.RegisterImage(user, token, uuid, frameNumberImage, false);

                    if (result != null && result.ImageUrl != "")
                    {
                        Preferences.Set("ProfileImage", result.ImageUrl);
                        if (bikeDetailViewModel != null)
                        {
                            MessagingCenter.Send(bikeDetailViewModel, MessageKeys.UpdateState, 0);
                        }
                        await NavigationService.GoBackAsync();
                    }
                }
                else // if (imageType == (int)ImageTypes.Invoice)
                {
                    // Upload invoice picture as document.

                    FrameNumberDocument frameNumberDocument = new FrameNumberDocument()
                    {
                        DocumentTitle = "Receipt", DocumentType = imageType, DocumentUrl = url
                    };
                    var result = await DataStore.RegisterDocument(user, token, uuid, frameNumberDocument, false);

                    if (result != null && result.DocumentUrl != "")
                    {
                        FrameNumberStatus fns = new FrameNumberStatus()
                        {
                            LastUpdateTime     = DateTime.Now,
                            Latitude           = 0,
                            Longitude          = 0,
                            LastUpdateClientID = DeviceInfo.Name,
                            Status             = (int)FrameNumberStatusType.Registered
                        };

                        // Now set status to 'registered'

                        if (await DataStore.UpdateStatus(user, token, uuid, fns))
                        {
                            if (Preferences.Get("IsLoggedIn", "0") == "1")
                            {
                                Preferences.Set("RegisteredToBike", "1");
                            }
                        }
                    }
                    IsBusy = false;

                    // Update state
                    if (bikeDetailViewModel != null)
                    {
                        MessagingCenter.Send(bikeDetailViewModel, MessageKeys.UpdateState, 1);
                    }

                    //await NavigationService.GoBackAsync();
                    await NavigationService.NavigateToAsync <MainViewModel>(2);
                }
            }
            IsBusy = false;
        }