public override void DidEnterBackground(UIApplication application)
        {
            Mvx.TaggedTrace(Tag, "DidEnterBackground");

            BackgroundTimeTimer = NSTimer.CreateRepeatingScheduledTimer(1, OnBackgroundTimeTimerAction);
            BackgroundTimeTimer.Fire();
        }
        public override void ChangePresentation(MvxPresentationHint hint)
        {
            if (HandlePresentationChange(hint))
            {
                return;
            }

            if (hint is MvxClosePresentationHint)
            {
                var mainPage = MvxFormsApp.MainPage as MasterDetailPage;

                if (mainPage == null)
                {
                    Mvx.TaggedTrace("MvxFormsPresenter:ChangePresentation()", "Oops! Don't know what to do");
                }
                else
                {
                    // Perform pop on the Detail Page and launch RootContentPageActivated if root has been reached
                    var navPage = mainPage.Detail as NavigationPage;
                    navPage.PopAsync();
                    if (navPage.Navigation.NavigationStack.Count == 1)
                    {
                        RootContentPageActivated();
                    }
                }
            }
        }
示例#3
0
        public async Task <List <Answer> > getAnswersByQuestionID(string question_id)
        {
            var answers = new List <Answer>();

            try
            {
                var res = await BaseClient.GetAsync(string.Format(Constants.SOAnswersByQuestionIDRequest, question_id));

                res.EnsureSuccessStatusCode();

                var json = await res.Content.ReadAsStringAsync();

                if (string.IsNullOrEmpty(json))
                {
                    return(null);
                }

                var so_response = JsonConvert.DeserializeObject <SO_AnswersResponse>(json);


                answers = so_response.items;


                return(answers);
            }
            catch (Exception ex)
            {
                Mvx.TaggedTrace(typeof(StackoverflowDataService).Name,
                                "Ooops! Something went wrong fetching information for question_id: {0}. Exception: {1}", question_id, ex);
                return(null);
            }
        }
示例#4
0
 public override void ViewDidDisappear(bool animated)
 {
     Mvx.TaggedTrace(MvxTraceLevel.Diagnostic, LogTag, "ViewDidDisappear - Start");
     base.ViewDidDisappear(animated);
     LifeCycleViewModel.OnViewHidden();
     UnsubscribeFromMessages();
 }
示例#5
0
        public async Task UpdateAsync(CancellationToken cancellationToken)
        {
            Mvx.TaggedTrace(Tag, "Update requested");

            if (!Outdated)
            {
                Mvx.TaggedTrace(Tag, "All data is up to date, update not required");

                return;
            }

            ClearData();

            var zipCodesGroupping = await LoadZipCodesGroupsAsync(cancellationToken);

            var cities = GetCities(zipCodesGroupping);

            CitiesRepository.AddAll(cities);

            var zipCodes = GetZipCodes(zipCodesGroupping, cities);

            ZipCodesRepository.AddAll(zipCodes);

            UpdateRepository.Updated = DateTime.UtcNow;

            Mvx.TaggedTrace(Tag, "Update completed");
        }
        protected virtual void OnLoggedIn(RequestSecurityTokenResponse requestSecurityTokenResponse)
        {
            if (requestSecurityTokenResponse == null)
            {
                Mvx.TaggedTrace(MvxTraceLevel.Error, "DefaultIdentityProviderCollectionViewModel", "Got an empty response from IdentityProvider");
                if (LoginError != null)
                {
                    LoginError(this, new LoginErrorEventArgs {
                        Message = "Got an empty response from IdentityProvider, try logging in again."
                    });
                }
                return;
            }

            var tokenStore   = Mvx.Resolve <ISimpleWebTokenStore>();
            var tokenFactory = Mvx.Resolve <ISimpleWebToken>();

            var token = tokenFactory.CreateTokenFromRaw(requestSecurityTokenResponse.SecurityToken);

            tokenStore.SimpleWebToken = token;

            if (!CanGoBack)
            {
                ShowProgressAfterLogin = true;
            }

            RaisePropertyChanged(() => IsLoggedIn);
            RaisePropertyChanged(() => LoggedInProvider);

            if (tokenStore.IsValid() && CanGoBack)
            {
                NavigateBackCommand.Execute(null);
            }
        }
示例#7
0
        public void OnConnectionFailed(ConnectionResult result)
        {
            _owner.OnLocationError(ToMvxLocationErrorCode(result));
            Mvx.TaggedTrace(MvxTraceLevel.Diagnostic, "Plugin.Location.Fused", "OnConnectionFailed: {0}", result);

            _client?.Reconnect();
        }
示例#8
0
        private async Task GetConfigurationIfNeeded(bool force = false)
        {
            if (_tmdbConfiguration != null && !force)
            {
                return;
            }

            try
            {
                var res = await BaseClient.GetAsync(string.Format(Constants.TmdbConfigurationUrl, Constants.TmdbApiKey));

                res.EnsureSuccessStatusCode();

                var json = await res.Content.ReadAsStringAsync();

                if (string.IsNullOrEmpty(json))
                {
                    throw new Exception("Return content was empty :(");
                }

                _tmdbConfiguration = JsonConvert.DeserializeObject <Configuration>(json);
            }
            catch (Exception ex)
            {
                Mvx.TaggedTrace(typeof(TmdbMovieService).Name,
                                "Ooops! Something went wrong fetching the configuration. Exception: {1}", ex);
            }
        }
        public override void WillEnterForeground(UIApplication application)
        {
            Mvx.TaggedTrace(Tag, "WillEnterForeground");

            BackgroundTimeTimer.Invalidate();
            BackgroundTimeTimer.Dispose();
        }
示例#10
0
        public async Task <ObservableCollection <Question> > getQuestionsByTag(string tag)
        {
            //throw new NotImplementedException();
            var questions = new ObservableCollection <Question>();

            try
            {
                var res = await BaseClient.GetAsync(string.Format(Constants.SOQuestionsByTagRequest, tag));

                res.EnsureSuccessStatusCode();

                var json = await res.Content.ReadAsStringAsync();

                if (string.IsNullOrEmpty(json))
                {
                    return(null);
                }

                var so_response = JsonConvert.DeserializeObject <SO_Response>(json);


                questions = new ObservableCollection <Question>(so_response.items);


                return(questions);
            }
            catch (Exception ex)
            {
                Mvx.TaggedTrace(typeof(StackoverflowDataService).Name,
                                "Ooops! Something went wrong fetching information for tag: {0}. Exception: {1}", tag, ex);
                return(null);
            }
        }
示例#11
0
        protected override void OnPause()
        {
            Mvx.TaggedTrace(MvxTraceLevel.Diagnostic, LogTag, "OnPause - Start");
            base.OnPause();

            LifeCycleViewModel.OnViewHidden();
            UnsubscribeFromMessages();
        }
 public void OnViewHidden()
 {
     Mvx.TaggedTrace(MvxTraceLevel.Diagnostic, LogTag, $"{nameof(OnViewHidden)} - Start");
     //View is now hidden, if it was visible before, call HideView
     if (ViewIsVisible)
     {
         HideView();
     }
 }
示例#13
0
        public void Write(string message, LogLevel logLevel)
        {
            if (logLevel < this.Level)
            {
                return;
            }

            Mvx.TaggedTrace(ToLevel(logLevel), "RxLogger", message);
        }
 public async void OnViewShown(CoreNavigationMode navigationMode)
 {
     Mvx.TaggedTrace(MvxTraceLevel.Diagnostic, LogTag,
                     $"{nameof(OnViewShown)} - Start ({nameof(navigationMode)} = {navigationMode})");
     //View is now visible, if it wasn't visible before call ShowView
     if (!ViewIsVisible)
     {
         await ShowView(navigationMode == CoreNavigationMode.Back);
     }
 }
        public override async void Start()
        {
            base.Start();
            Mvx.TaggedTrace(MvxTraceLevel.Diagnostic, LogTag, $"{nameof(Start)} - Start");

            await InitializeViewAsync();

            //Once the view is initialized it can be shown, set ReadyToShow to true, the ShowView loop will then move on to showing the view
            ReadyToShow = true;
        }
示例#16
0
 protected override void OnResume()
 {
     Mvx.TaggedTrace(MvxTraceLevel.Diagnostic, LogTag, "OnResume - Start");
     base.OnResume();
     if (!Subscribed)
     {
         SubscribeToMessages();
     }
     LifeCycleViewModel?.OnViewShown(_navigationMode);
     _navigationMode = CoreNavigationMode.Back;
 }
        private void OnBackgroundTimeTimerAction(NSTimer timer)
        {
            var backgroundTimeRemaining = (int)UIApplication.SharedApplication.BackgroundTimeRemaining;

            if (backgroundTimeRemaining == int.MinValue)
            {
                return;
            }

            Mvx.TaggedTrace(Tag, $"BackgroundTimeRemaining: {backgroundTimeRemaining}");
        }
示例#18
0
            public View OnCreateView(View parent, string name, Context context, IAttributeSet attrs)
            {
                if (Debug)
                {
                    Mvx.TaggedTrace(Tag, "... OnCreateView ... {0}", name);
                }

                return(this._factoryPlaceholder.OnViewCreated(
                           this._factory.OnCreateView(name, context, attrs),
                           context, attrs));
            }
示例#19
0
            public View OnCreateView(string name, Context context, IAttributeSet attrs)
            {
                if (Debug)
                {
                    Mvx.TaggedTrace(Tag, "... OnCreateView 2 ... {0}", name);
                }

                return(this._bindingVisitor.OnViewCreated(
                           // The activity's OnCreateView
                           this._factory2.OnCreateView(name, context, attrs),
                           context, attrs));
            }
示例#20
0
        public override void ViewWillAppear(bool animated)
        {
            Mvx.TaggedTrace(MvxTraceLevel.Diagnostic, LogTag, "ViewWillAppear - Start");
            base.ViewWillAppear(animated);

            if (!Subscribed)
            {
                SubscribeToMessages();
            }
            LifeCycleViewModel?.OnViewShown(navigationMode);
            navigationMode = CoreNavigationMode.Back;
        }
示例#21
0
        protected override View OnCreateView(View parent, string name, IAttributeSet attrs)
        {
            if (Debug)
            {
                Mvx.TaggedTrace(Tag, "... OnCreateView 3 ... {0}", name);
            }

            return(this._bindingVisitor.OnViewCreated(
                       base.OnCreateView(parent, name, attrs),
                       this.Context,
                       attrs));
        }
示例#22
0
        protected override View OnCreateView(string name, IAttributeSet attrs)
        {
            if (Debug)
            {
                Mvx.TaggedTrace(Tag, "... OnCreateView 2 ... {0}", name);
            }

            View view = this.AndroidViewFactory.CreateView(null, name, this.Context, attrs) ??
                        this.PhoneLayoutInflaterOnCreateView(name, attrs) ??
                        base.OnCreateView(name, attrs);

            return(this._bindingVisitor.OnViewCreated(view, this.Context, attrs));
        }
        private void DoCancelTaskCommand()
        {
            if (CancellationTokenSource == null)
            {
                return;
            }

            Mvx.TaggedTrace(Tag, "Task will be canceled");

            CancellationTokenSource.Cancel();

            TaskIsRunning = false;
        }
示例#24
0
        public void OnConnected(Bundle connectionHint)
        {
            LocationServices.FusedLocationApi.RequestLocationUpdates(_client, _request, this, Looper.MainLooper);

            var location = LocationServices.FusedLocationApi.GetLastLocation(_client);

            if (location != null)
            {
                _owner.OnLocationUpdated(location);
            }

            Mvx.TaggedTrace(MvxTraceLevel.Diagnostic, "Plugin.Location.Fused", "OnConnected");
        }
        private void ChangePagePresentation()
        {
            var mainPage = FormsApplication.MainPage as NavigationPage;

            if (mainPage == null)
            {
                Mvx.TaggedTrace("MvxFormsPresenter:ChangePresentation()", "Oops! Don't know what to do");
            }
            else
            {
                mainPage.PopAsync();
            }
        }
示例#26
0
        protected View CreateCustomViewInternal(View parent, View view, string name, Context viewContext,
                                                IAttributeSet attrs)
        {
            if (Debug)
            {
                Mvx.TaggedTrace(Tag, "... CreateCustomViewInternal ... {0}", name);
            }

            if (view == null && name.IndexOf('.') > -1)
            {
                // Attempt to inflate with MvvmCross unless we're trying to inflate an internal views
                // since we don't resolve those.
                if (!name.StartsWith("com.android.internal."))
                {
                    view = AndroidViewFactory.CreateView(parent, name, viewContext, attrs);
                }

                if (view == null)
                {
                    if (_constructorArgs == null)
                    {
                        Class layoutInflaterClass = Class.FromType(typeof(LayoutInflater));
                        _constructorArgs            = layoutInflaterClass.GetDeclaredField("mConstructorArgs");
                        _constructorArgs.Accessible = true;
                    }

                    Object[] constructorArgsArr = (Object[])_constructorArgs.Get(this);
                    Object   lastContext        = constructorArgsArr[0];

                    // The LayoutInflater actually finds out the correct context to use. We just need to set
                    // it on the mConstructor for the internal method.
                    // Set the constructor args up for the createView, not sure why we can't pass these in.
                    constructorArgsArr[0] = viewContext;
                    _constructorArgs.Set(this, constructorArgsArr);
                    try
                    {
                        view = CreateView(name, null, attrs);
                    }
                    catch (ClassNotFoundException)
                    {
                    }
                    finally
                    {
                        constructorArgsArr[0] = lastContext;
                        _constructorArgs.Set(this, constructorArgsArr);
                    }
                }
            }
            return(view);
        }
示例#27
0
        public void StartUpdates()
        {
            // TODO: should be bool RequestValue? compare iOS API for commonality
            var successful = false;

            //if (CanRead)
            //{
            //    Console.WriteLine("Characteristic.RequestValue, PropertyType = Read, requesting updates");
            //    successful = this._gatt.ReadCharacteristic(this._nativeCharacteristic);
            //}

            if (CanUpdate)
            {
                Console.WriteLine("Characteristic.RequestValue, PropertyType = Notify, requesting updates");

                if (_gattCallback != null)
                {
                    // wire up the characteristic value updating on the gattcallback for event forwarding
                    _gattCallback.CharacteristicValueUpdated += OnCharacteristicValueChanged;
                }

                successful = _gatt.SetCharacteristicNotification(_nativeCharacteristic, true);

                // [TO20131211@1634] It seems that setting the notification above isn't enough. You have to set the NOTIFY
                // descriptor as well, otherwise the receiver will never get the updates. I just grabbed the first (and only)
                // descriptor that is associated with the characteristic, which is the NOTIFY descriptor. This seems like a really
                // odd way to do things to me, but I'm a Bluetooth newbie. Google has a example here (but ono real explaination as
                // to what is going on):
                // http://developer.android.com/guide/topics/connectivity/bluetooth-le.html#notification
                //
                // HACK: further detail, in the Forms client this only seems to work with a breakpoint on it
                // (ie. it probably needs to wait until the above 'SetCharacteristicNofication' is done before doing this...?????? [CD]
                Thread.Sleep(100);
                // HACK: did i mention this was a hack?????????? [CD] 50ms was too short, 100ms seems to work

                if (_nativeCharacteristic.Descriptors.Count > 0)
                {
                    var descriptor = _nativeCharacteristic.Descriptors[0];
                    descriptor.SetValue(BluetoothGattDescriptor.EnableNotificationValue.ToArray());
                    successful &= _gatt.WriteDescriptor(descriptor);
                }
                else
                {
                    Console.WriteLine("RequestValue, FAILED: _nativeCharacteristic.Descriptors was empty, not sure why");
                }
            }

            Mvx.TaggedTrace("StartUpdates", "RequestValue, Succesful: {0}", successful);
        }
示例#28
0
            public View OnCreateView(View parent, string name, Context context, IAttributeSet attrs)
            {
                if (Debug)
                {
                    Mvx.TaggedTrace(Tag, "... OnCreateView 3 ... {0}", name);
                }

                return(this._bindingVisitor.OnViewCreated(
                           this._inflater.CreateCustomViewInternal(
                               parent,
                               // The activity's OnCreateView
                               this._factory2.OnCreateView(parent, name, context, attrs),
                               name, context, attrs),
                           context, attrs));
            }
示例#29
0
        private void HandleLocationChanged(object sender, LocationUpdatedEventArgs e)
        {
            // Handle foreground updates
            var location = e.Location;

            Altitude  = location.Altitude;
            Longitude = location.Longitude;
            Latitude  = location.Latitude;
            Course    = location.Course;
            Speed     = location.Speed;

            Mvx.TaggedTrace("LocationChanged", "LocationChanged", location);

            //Console.WriteLine("foreground updated");
        }
        /// <summary>
        /// Called from OnViewShown
        /// </summary>
        public virtual async Task ShowView(bool backNavigation)
        {
            Mvx.TaggedTrace(MvxTraceLevel.Diagnostic, LogTag, $"{nameof(ShowView)} - Start");
            //Wait until ReadyToShow = true
            var delay = TimeSpan.FromMilliseconds(50);

            while (!ReadyToShow)
            {
                Mvx.TaggedTrace(MvxTraceLevel.Diagnostic, LogTag,
                                $"{nameof(ShowView)} - Waiting for the view to be ready to show");
                await Task.Delay(delay);
            }
            Mvx.TaggedTrace(MvxTraceLevel.Diagnostic, LogTag, $"{nameof(ShowView)} - Now ready to show");
            SubscribeToEvents();
            ViewIsVisible = true;
        }