Beispiel #1
0
        /// <summary>
        /// Create new QR Code object
        /// </summary>
        private void AddNewRecord(string qrCodeId)
        {
            Device.BeginInvokeOnMainThread(async() =>
            {
                var r = await UserDialogs.Instance.PromptAsync(AppResources.qrcode_name, inputType: InputType.Name);
                await Task.Delay(500);

                if (!r.Ok)
                {
                    return;
                }
                var name = r.Text;
                if (string.IsNullOrEmpty(name))
                {
                    return;
                }
                App.ShowToast(AppResources.qrcode_saved + " " + name);
                var qrCode = new QRCodeModel()
                {
                    Id      = qrCodeId,
                    Name    = name,
                    Enabled = true,
                };
                _oListSource.Add(qrCode);
                SaveAndRefresh();
            });
        }
Beispiel #2
0
        bool ConfirmationHandler()
        {
            XamarinDevice.BeginInvokeOnMainThread(() =>
            {
                Current.MainPage.DisplayActionSheet("Crash detected. Send anonymous crash report?", null, null, "Send", "Always Send", "Don't Send").ContinueWith((arg) =>
                {
                    var answer = arg.Result;
                    UserConfirmation userConfirmationSelection;
                    if (answer == "Send")
                    {
                        userConfirmationSelection = UserConfirmation.Send;
                    }
                    else if (answer == "Always Send")
                    {
                        userConfirmationSelection = UserConfirmation.AlwaysSend;
                    }
                    else
                    {
                        userConfirmationSelection = UserConfirmation.DontSend;
                    }
                    AppCenterLog.Debug(LogTag, "User selected confirmation option: \"" + answer + "\"");
                    Crashes.NotifyUserConfirmation(userConfirmationSelection);
                });
            });

            return(true);
        }
Beispiel #3
0
        async void updateProgress(int percent, string status)
        {
            log.Info(status);

            Device.BeginInvokeOnMainThread(() =>
            {
                {
                    var newstatus = status;
                    if (percent >= 0)
                    {
                        newstatus += " " + percent + "%";
                    }

                    if (laststatus != newstatus)
                    {
                        laststatus = newstatus;
                        UserDialogs.Instance.Toast(newstatus, TimeSpan.FromSeconds(10));
                    }
                }

                if (Progress != null)
                {
                    Progress(percent, status);
                }
            });
        }
Beispiel #4
0
        async void ChangeIcon()
        {
            //This is just here for testing purposes. Going to tie into a live setting instead
            var max     = Enum.GetValues(typeof(Usage)).Cast <int> ().Max();
            int current = (int)Settings.CurrentUsage;

            while (true)
            {
                await Task.Delay(1000);

                current++;
                if (current > max)
                {
                    current = 0;
                }
                Settings.CurrentUsage = (Usage)current;
                var nav  = this.Parent as NavigationPage;
                var icon = D.OnPlatform(new FileImageSource {
                    File = Images.GetCachedImagePath(Images.CurrentOverviewImageName, 24)
                }, null, null);
                if (nav != null)
                {
                    nav.Icon = icon;
                }
                else
                {
                    Icon = icon;
                }
            }
        }
Beispiel #5
0
        private async Task <bool> TryHubConnectAsync()
        {
            bool success = true;

            try
            {
                await hubConnection.StartAsync();

                _ = hubConnection.On <string, string>("ReceiveMessage", (a, b) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        //_ = RefreshMatchData(a, b);
                    });
                });
                _ = hubConnection.On <string, string>("ReceiveMatchDetails", (action, matchDetailsJson) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        var matchDetails = JsonConvert.DeserializeObject <MatchDetails>(matchDetailsJson);
                        RefreshMatchData(action, matchDetails);
                    });
                });
            }
            catch (Exception ex)
            {
                success = false;
                Console.WriteLine($"Error: {ex.Message}");
                await Task.Delay(1000);
            }
            return(success);
        }
Beispiel #6
0
        private async Task Handle_UnhandledException(Exception ex, string title, bool shutdown)
        {
            if (!(ex is null))
            {
                this.sdk.LogService.SaveExceptionDump(title, ex.ToString());
            }

            if (!(ex is null))
            {
                this.sdk.LogService?.LogException(ex, this.GetClassAndMethod(MethodBase.GetCurrentMethod(), title));
            }

            if (shutdown)
            {
                await this.Shutdown(true);
            }

#if DEBUG
            if (!shutdown)
            {
                if (Device.IsInvokeRequired && !(MainPage is null))
                {
                    Device.BeginInvokeOnMainThread(async() => await MainPage.DisplayAlert(title, ex?.ToString(), AppResources.Ok));
                }
                else if (!(MainPage is null))
                {
                    await MainPage.DisplayAlert(title, ex?.ToString(), AppResources.Ok);
                }
            }
#endif
        }
Beispiel #7
0
        public App()
        {
            InitializeComponent();

            Device.SetFlags(new[] { "Shapes_Experimental", "MediaElement_Experimental" });
            MainPage = new SplashScreen();
        }
 public void MessageReceived(string notificationBody, string title)
 {
     Device.BeginInvokeOnMainThread(() =>
     {
         App.Current.MainPage.DisplayAlert(title, notificationBody, "Ok");
     });
 }
 private void ShowLoginModal()
 {
     Device.BeginInvokeOnMainThread(async() =>
     {
         var page = FreshPageModelResolver.ResolvePageModel <LoginViewModel>();
         await _masterDetailNav.PushPage(page, null, true);
     });
 }
 private void _inputView_Unfocused(object sender, FocusEventArgs e)
 {
     caretptr = IntPtr.Zero;
     Device.BeginInvokeOnMainThread(() =>
     {
         _inputView.IsVisible = false;
     });
 }
Beispiel #11
0
 private void TimeOfMatches()
 {
     Device.StartTimer(TimeSpan.FromMilliseconds(300), () =>
     {
         _viewModel.TimeCounter.MatchesTime(_viewModel);
         return(true);
     });
 }
Beispiel #12
0
 // TODO: implement notification logic here
 private void OnMessageReceived(object sender, string msg)
 {
     Device.BeginInvokeOnMainThread(() =>
     {
         var alertService = DependencyService.Get <IAlertService>();
         alertService.ShowYesNoAlert("Notification received", "Ok", "Cancel");
     });
 }
 public OverviewPage()
 {
     InitializeComponent();
     this.BindingContext = new OverviewViewModel();
     Icon = D.OnPlatform(new FileImageSource {
         File = Images.GetCachedImagePath(Images.CurrentOverviewImageName, 24)
     }, null, null);
     ChangeIcon();
 }
Beispiel #14
0
        public App()
        {
            InitializeComponent();

            Instance = this;

            SetupIoC();

            var loginPage               = FreshPageModelResolver.ResolvePageModel <LoginViewModel>();
            var playerCreationPage      = FreshPageModelResolver.ResolvePageModel <PlayerCreationViewModel>();
            var loginContainer          = new FreshNavigationContainer(loginPage, NavigationContainerNames.LoginContainer);
            var playerCreationContainer = new FreshNavigationContainer(playerCreationPage, NavigationContainerNames.PlayerCreationContainer);

            var mainContainer = new BottomBarTabbedFoNavigationContainer("ISII Sports", NavigationContainerNames.MainContainer);

            mainContainer.AddTab <GamesViewModel>("Games", Device.OnPlatform("games.png", "games.png", ""));
            mainContainer.AddTab <TeamsViewModel>("Teams", Device.OnPlatform("teams.png", "teams.png", ""));
            mainContainer.AddTab <InfoViewModel>("Info", Device.OnPlatform("info.png", "info.png", ""));

            var tabs = mainContainer.TabbedPages.ToList();

            tabs[0].SetTabColor((Color)Resources["PurplePrimary"]);
            tabs[1].SetTabColor((Color)Resources["GreenPrimary"]);
            tabs[2].SetTabColor(null);

            //se risulto già loggato
            if (Settings.IsLoggedIn)
            {
                var serializedPlayer = Settings.SerializedPlayer;
                //se non mi sono già registrato come player
                if (string.IsNullOrEmpty(serializedPlayer))
                {
                    MainPage = playerCreationContainer;
                }
                else
                {
                    //se sono già un player
                    var player = JsonConvert.DeserializeObject <Player>(serializedPlayer);
                    if (player.Email == Settings.PlayerEmail)
                    {
                        App.Instance.CurrentPlayer = player;
                        MessagingCenter.Send(App.Instance, Messages.UserLoggedIn);
                        MainPage = mainContainer;
                    }
                    else
                    {
                        //altrimenti devo mostrare la pagina di login
                        MainPage = loginContainer;
                    }
                }
            }
            else
            {
                MainPage = loginContainer;
            }
        }
            private void _inputView_Completed(object sender, EventArgs e)
            {
                var focusctl = Control.FromHandle(_focusWindow);

                focusctl.Text = (sender as Entry)?.Text;
                Device.BeginInvokeOnMainThread(() =>
                {
                    _inputView.IsVisible = false;
                });
            }
        public FormsApp()
        {
            InitializeComponent();

            FormsDevice.SetFlags(new[] {
                "CarouselView_Experimental",
                "IndicatorView_Experimental",
                "SwipeView_Experimental"
            });
        }
Beispiel #17
0
 private void SetupGeolocator()
 {
     Device.BeginInvokeOnMainThread(async() =>
     {
         if (await CoordinateHelper.HasGeolocationAccess())
         {
             await CrossGeolocator.Current.StartListeningAsync(50, 100);
             CrossGeolocator.Current.PositionChanged += CurrentOnPositionChanged;
         }
     });
 }
Beispiel #18
0
        public async Task <bool> RefreshPageData()
        {
            bool connected = await _viewModel.GetPageData();

            Device.BeginInvokeOnMainThread(() =>
            {
                PopulatePageView(true);
            });
            _viewModel.IsLoading = false;
            return(connected);
        }
Beispiel #19
0
        public async void PushOperationAsync(Operation operation, bool isAlarm = true)
        {
            await DependencyService.Get <IDataStore <Operation> >().AddItemAsync(operation);

            MessagingCenter.Send(this, Constants.MessageNewOperation);

            Device.BeginInvokeOnMainThread(async() =>
            {
                MainPage = new NavigationPage(new OperationsPage());
                await MainPage.Navigation.PushAsync(new OperationTabPage(operation, isAlarm));
            });
        }
        public App()
        {
            Device.SetFlags(new string[] { "Shapes_Experimental" });

            InitializeComponent();

            MainPage = new NavigationPage(new MainPage())
            {
                BarBackgroundColor = (Color)Resources["Primary"],
                BarTextColor       = Color.White
            };
        }
Beispiel #21
0
 static void PrintNotification(object sender, PushNotificationReceivedEventArgs e)
 {
     XamarinDevice.BeginInvokeOnMainThread(() =>
     {
         var message = e.Message;
         if (e.CustomData != null)
         {
             message += "\nCustom data = {" + string.Join(",", e.CustomData.Select(kv => kv.Key + "=" + kv.Value)) + "}";
         }
         Current.MainPage.DisplayAlert(e.Title, message, "OK");
     });
 }
Beispiel #22
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        protected MainViewModel(INavigationService navigationService)
        {
            _navigationService = navigationService;

            //current location updates
            GeolocationManager.instance.LocationUpdatesEvent += OnLocationUpdates;

            //Event handlers when app starts, sleeps, or resumes
            ((App)Application.Current).AppStart  += OnForegroundWork;
            ((App)Application.Current).AppSleep  += OnBackgroundWork;
            ((App)Application.Current).AppResume += OnForegroundWork;

            Messenger.Default.Register <string>(this, PublishedData.MemberLocationNotification, async(memberId) =>
            {
                Location location = await ServerCommunicator.Instance.GetLocationAsync(memberId);
                Device.BeginInvokeOnMainThread(() =>
                {
                    if (Members == null)
                    {
                        Members = new Dictionary <string, Location>();
                    }

                    if (Members.Keys.Contains(memberId))
                    {
                        Members[memberId] = location;
                    }
                    else
                    {
                        Members.Add(memberId, location);
                    }

                    RaisePropertyChanged("Members");
                });
            });

            Messenger.Default.Register <string>(this, PublishedData.GroupIdNotification, async(leaderId) =>
            {
                if (leaderId != null)
                {
                    var location = await ServerCommunicator.Instance.GetLocationAsync(leaderId);
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        LeaderLocation = location;
                    });
                }
                if (!_hasSent)
                {
                    await ServerCommunicator.Instance.SendLocationAsync(MyLocation);
                    _hasSent = true;
                }
            });
        }
Beispiel #23
0
        public App()
        {
            InitializeComponent();

            // Enable currently experimental features
            Device.SetFlags(new string[] { "MediaElement_Experimental" });

            VersionTracking.Track();

            MainPage = new NavigationPage(new HomePage());

            AppActions.OnAppAction += AppActions_OnAppAction;
        }
        public static async Task <Plugin.Permissions.Abstractions.PermissionStatus> CheckLocationServices()
        {
            try
            {
                Plugin.Permissions.Abstractions.PermissionStatus status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

                Plugin.Permissions.Abstractions.PermissionStatus status2 = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.LocationWhenInUse);

                Plugin.Permissions.Abstractions.PermissionStatus status3 = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.LocationAlways);

                Console.WriteLine("Location Permissions: Location: " + status.ToString() + ", When In Use: " + status2.ToString() + ", Always: " + status3.ToString());
                if (status3 != Plugin.Permissions.Abstractions.PermissionStatus.Granted)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if (Device.RuntimePlatform == Device.iOS)
                        {
                            ILocationManager manager = DependencyService.Get <ILocationManager>();
                            manager.RequestBackgroundLocation();
                        }
                    });
                }
                else
                {
                    try
                    {
                        var request  = new GeolocationRequest(GeolocationAccuracy.Lowest, new TimeSpan(0, 0, 0, 0, 100));
                        var location = await Geolocation.GetLocationAsync(request);

                        if (location != null)
                        {
                            Console.WriteLine($"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}");
                        }
                    }
                    catch (FeatureNotSupportedException)
                    {
                        return(Plugin.Permissions.Abstractions.PermissionStatus.Denied);
                    }
                    catch (FeatureNotEnabledException)
                    {
                        return(Plugin.Permissions.Abstractions.PermissionStatus.Denied);
                    }
                }
                return(status3);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                return(Plugin.Permissions.Abstractions.PermissionStatus.Denied);
            }
        }
Beispiel #25
0
        protected override async void OnStart()
        {
            AppCenter.Start("android=8cdf0827-a552-4ecb-88f7-c35c58a58dc9;", typeof(Analytics), typeof(Crashes));

            // Handle when your app starts
            IEFSERVICE = new EfService();
            var ihelper = DependencyService.Get <IHelper>();
            var config  = new Config();

            APPCONFIG   = config.GetAppConfig();
            APP_VERSION = ihelper.AppVersion;
            bool   hasUpdate = false;
            string urlUpdateApp;
            var    userService = new UserService();

            USER = IEFSERVICE.GetUser();
            if (USER != null)
            {
                USER.RoleMenus = USER.Roles.Split(',').Select(int.Parse).ToList();
                APPCONFIG.Api  = APPCONFIG.GetApiByEnv(USER.Enviroment);
                TOKEN          = userService.GetToken(APPCONFIG.UserApi, APPCONFIG.PassApi);

                MainPage = new MainPage();
            }
            else
            {
                MainPage = new Login();
            }

            if (Device.RuntimePlatform == Device.iOS)
            {
                urlUpdateApp = APPCONFIG.StoreIos;
                hasUpdate    = !APP_VERSION.Equals(APPCONFIG.IosVersion);
            }
            else
            {
                urlUpdateApp = APPCONFIG.StoreAndroid;
                hasUpdate    = !APP_VERSION.Equals(APPCONFIG.AndroidVersion);
            }

            if (hasUpdate)
            {
                var result = await Current.MainPage.DisplayAlert("Cập nhật phiên bản mới", "Đã có phiên bản cập nhật. Bạn có muốn cập nhật không ?", "Ok", "Cancel"); // since we are using async, we should specify the DisplayAlert as awaiting.

                if (result)                                                                                                                                           // if it's equal to Ok
                {
                    Device.OpenUri(new Uri(urlUpdateApp));
                }
            }
        }
 /// <inheritdoc />
 protected override void OnStart()
 {
     base.OnStart();
     if (Device.RuntimePlatform == Device.Windows)
     {
         Device.StartTimer(
             TimeSpan.FromSeconds(3),
             () =>
         {
             m_dialogs.Alert(
                 "");
             return(false);
         });
     }
 }
        protected override async void OnInitialized()
        {
            DeviceXforms.SetFlags(new[] { "Shapes_Experimental", "Brush_Experimental" });
            InitializeComponent();
            XF.Material.Forms.Material.Init(this);

            AppCenter.Start(
                "ios=58700844-1f8b-4af7-b72c-5b5d043c4873;" + "android=48a21bd8-5bfc-4cf8-86d6-e694520f7b32",
                typeof(Analytics),
                typeof(Crashes));
#if DEBUG
            HotReloader.Current.Run(this);
#endif

            await NavigationService.NavigateAsync("NavigationPage/MainPage");
        }
Beispiel #28
0
 private async void OnLocationUpdates(object sender, Location location)
 {
     //Hover on customized "CompareTo" to see how two locations compared.
     if ((MyLocation == null) || (MyLocation.CompareTo(location) != 0))
     {
         Device.BeginInvokeOnMainThread(() =>
         {
             MyLocation = location;
         });
         if (ServerCommunicator.Instance.GroupID != null)
         {
             //TODO: why SendLocationAsync(MyLocation) throwing exception
             await ServerCommunicator.Instance.SendLocationAsync(location);
         }
     }
 }
Beispiel #29
0
        private void RefreshMatchData(string action, MatchDetails matchDetails)
        {
            try
            {
                Match match = matchDetails?.Match;
                if (match != null)
                {
                    Match findMatch = _viewModel.AllMatches?.FirstOrDefault(x => x.MatchID == match.MatchID);
                    if (findMatch != null)
                    {
                        int findMatchIndex = _viewModel.AllMatches.IndexOf(findMatch);
                        _viewModel.AllMatches?.Insert(findMatchIndex, match);
                        _viewModel.AllMatches?.Remove(findMatch);
                    }
                    else
                    {
                        _viewModel.AllMatches?.Add(match);
                    }

                    //if (match.StatusID != findMatch?.StatusID)
                    //{
                    //    await _viewModel.GetStandingsAsync();
                    //}
                    bool isSelectedMatch = _viewModel.SelectedLiveMatch.MatchID == match.MatchID;
                    if (isSelectedMatch)
                    {
                        Match selectedMatch = matchDetails.Match;
                        selectedMatch.PlayersOfMatch          = new ObservableCollection <PlayerOfMatch>(matchDetails.PlayersOfMatch);
                        selectedMatch.EventsOfMatch           = new ObservableCollection <EventOfMatch>(matchDetails.EventsOfMatch);
                        _viewModel.SelectedLiveMatch          = selectedMatch;
                        _viewModel.SelectedLiveMatch.LiveTime = selectedMatch.LiveTime;
                        _viewModel.TimeCounter.MatchesTime(_viewModel, new ObservableCollection <Match>());
                        _viewModel.SetMatchAdditionalDetails();
                        _viewModel.SelectedLiveMatch.IsLoadingSelectedMatch = false;
                    }

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        PopulatePageView(false);
                    });
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
Beispiel #30
0
 /// <inheritdoc />
 protected override void OnStart()
 {
     base.OnStart();
     if (Device.RuntimePlatform == Device.Windows)
     {
         Device.StartTimer(
             TimeSpan.FromSeconds(3),
             () =>
         {
             m_dialogs.Alert(
                 "The UWP API can listen for advertisements but is not yet able to connect to devices.",
                 "Quick Note",
                 "Aww, ok");
             return(false);
         });
     }
 }