Esempio n. 1
0
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.AdminDashboard);
            CurrentConsumption = ConsumptionFor.Premises;
            receiver           = new MySampleBroadcastReceiver(this);


            if (!Utils.Utils.IsNetworkEnabled(this))
            {
                RunOnUiThread(() =>
                {
                    Utils.Utils.ShowDialog(this, "Internet not available.");
                });
                StartActivity(new Intent(Application.Context, typeof(LoginActivity)));
                Finish();
            }
            else
            {
                if (PreferenceHandler.GetToken() == string.Empty)
                {
                    await Utils.Utils.GetToken();
                }
                CreateDashboard();
                IsPlayServicesAvailable();
            }
        }
Esempio n. 2
0
        public override void OnBackPressed()
        {
            layoutProgress            = FindViewById <LinearLayout>(Resource.Id.layout_progress);
            layoutProgress.Visibility = ViewStates.Visible;
            layoutProgress.Enabled    = true;
            switch (CurrentConsumption)
            {
            case ConsumptionFor.Buildings:
                CurrentConsumption = ConsumptionFor.Premises;
                GetConsumptionDetails(CurrentConsumption, 0);
                CurrentPremisesId = 0;
                break;

            case ConsumptionFor.Meters:

                CurrentConsumption = ConsumptionFor.Buildings;
                GetConsumptionDetails(CurrentConsumption, CurrentPremisesId);

                break;

            case ConsumptionFor.Premises:
                this.CloseContextMenu();
                layoutProgress.Visibility = ViewStates.Gone;
                break;
            }
        }
Esempio n. 3
0
        private async void GetConsumptionResponse(HttpResponseMessage responseConsumption)
        {
            if (responseConsumption != null && responseConsumption.StatusCode == System.Net.HttpStatusCode.OK && responseConsumption.Content != null)
            {
                string strContent = await responseConsumption.Content.ReadAsStringAsync();

                List <ConsumptionModel> consumptions = GetConsumptionModels(strContent);

                if (consumptions.Count > 0)
                {
                    SetConsumptions(consumptions);
                }
                else
                {
                    Utils.Utils.ShowDialog(this, "No " + CurrentConsumption.ToString() + " found!");
                    switch (CurrentConsumption)
                    {
                    case ConsumptionFor.Buildings:
                        CurrentConsumption = ConsumptionFor.Premises;
                        break;

                    case ConsumptionFor.Meters:
                        CurrentConsumption = ConsumptionFor.Buildings;
                        break;
                    }
                }

                layoutProgress            = FindViewById <LinearLayout>(Resource.Id.layout_progress);
                layoutProgress.Visibility = ViewStates.Gone;
            }
        }
        private async void GetConsumptionResponse(HttpResponseMessage responseConsumption)
        {
            if (responseConsumption != null && responseConsumption.StatusCode == System.Net.HttpStatusCode.OK && responseConsumption.Content != null)
            {
                string strContent = await responseConsumption.Content.ReadAsStringAsync();

                List <ConsumptionModel> consumptions = GetConsumptionModels(strContent);
                if (consumptions.Count > 0)
                {
                    SetConsumptions(consumptions);
                }
                else
                {
                    IOSUtil.ShowMessage("No " + CurrentConsumption.ToString() + " found!", loadingOverlay, this);
                    switch (CurrentConsumption)
                    {
                    case ConsumptionFor.Buildings:
                        CurrentConsumption = ConsumptionFor.Premises;
                        break;

                    case ConsumptionFor.Meters:
                        CurrentConsumption = ConsumptionFor.Buildings;
                        break;
                    }
                }
            }
            else
            {
                await IOSUtil.RefreshToken(this, loadingOverlay);
            }
        }
        public async void GetConsumptionDetails(ConsumptionFor currentConsumption, int Id)
        {
            InvokeOnMainThread(() =>
            {
                // Added for showing loading screen
                var bounds = UIScreen.MainScreen.Bounds;
                // show the loading overlay on the UI thread using the correct orientation sizing
                loadingOverlay = new LoadingOverlay(bounds);
                View.Add(loadingOverlay);
            });

            string url = GetConsumptionURL(currentConsumption);

            if (Id != 0)
            {
                url = url + "/" + Convert.ToString(Id);
            }
            var responseConsumption = await InvokeApi.Invoke(url, string.Empty, HttpMethod.Get, PreferenceHandler.GetToken(), IOSUtil.CurrentStage);

            if (responseConsumption.StatusCode == HttpStatusCode.OK)
            {
                GetConsumptionResponse(responseConsumption);
            }
            else if (responseConsumption.StatusCode == HttpStatusCode.BadRequest || responseConsumption.StatusCode == HttpStatusCode.Unauthorized)
            {
                await IOSUtil.RefreshToken(this, loadingOverlay);
            }
        }
Esempio n. 6
0
        private async void GetConsumptionDetails(ConsumptionFor currentConsumption, int Id)
        {
            string url = GetConsumptionURL(currentConsumption);

            if (Id != 0)
            {
                url = url + "/" + Convert.ToString(Id);
            }
            var responseConsumption = await InvokeApi.Invoke(url, string.Empty, HttpMethod.Get, PreferenceHandler.GetToken(), Utils.Utils.CurrentStage);

            if (responseConsumption.StatusCode == HttpStatusCode.OK)
            {
                GetConsumptionResponse(responseConsumption);
                layoutProgress.Visibility = ViewStates.Gone;
            }
        }
Esempio n. 7
0
        private string GetConsumptionURL(ConsumptionFor currentConsumption)
        {
            switch (currentConsumption)
            {
            case ConsumptionFor.Premises:
                return(Constants.API_GET_ALLPREMISES);

            case ConsumptionFor.Buildings:
                return(Constants.API_GET_ALLBUILDINGS_BY_PREMISEID);

            case ConsumptionFor.Meters:
                return(Constants.API_GET_ALLMETERS_BY_BUILDINGID);

            default:
                return(string.Empty);
            }
        }
Esempio n. 8
0
        private void GetCurrentConsumption(int position)
        {
            if (CurrentConsumption != ConsumptionFor.Meters)
            {
                layoutProgress            = FindViewById <LinearLayout>(Resource.Id.layout_progress);
                layoutProgress.Visibility = ViewStates.Visible;
                layoutProgress.Enabled    = true;
                switch (CurrentConsumption)
                {
                case ConsumptionFor.Premises:
                    CurrentPremisesId  = position;
                    CurrentConsumption = ConsumptionFor.Buildings;
                    break;

                case ConsumptionFor.Buildings:
                    CurrentConsumption = ConsumptionFor.Meters;
                    break;
                }
                GetConsumptionDetails(CurrentConsumption, position);
            }
        }
Esempio n. 9
0
        void OnItemClick(object sender, int position)
        {
            if (CurrentConsumption != ConsumptionFor.Meters)
            {
                layoutProgress            = FindViewById <LinearLayout>(Resource.Id.layout_progress);
                layoutProgress.Visibility = ViewStates.Visible;
                layoutProgress.Enabled    = true;
                int photoNum = position + 1;
                ConsumptionListAdapter consumptionListAdapter = (ConsumptionListAdapter)sender;
                switch (CurrentConsumption)
                {
                case ConsumptionFor.Premises:
                    CurrentPremisesId  = consumptionListAdapter.mConsumptionModels[position].Id;
                    CurrentConsumption = ConsumptionFor.Buildings;
                    break;

                case ConsumptionFor.Buildings:
                    CurrentConsumption = ConsumptionFor.Meters;
                    break;
                }
                GetConsumptionDetails(CurrentConsumption, consumptionListAdapter.mConsumptionModels[position].Id);
            }
        }
        private void BtnBack_TouchUpInside(object sender, EventArgs e)
        {
            btnBack.Hidden = false;
            switch (CurrentConsumption)
            {
            case ConsumptionFor.Buildings:
                CurrentConsumption = ConsumptionFor.Premises;
                GetConsumptionDetails(CurrentConsumption, 0);
                CurrentPremisesId = 0;
                btnBack.Hidden    = true;
                break;

            case ConsumptionFor.Meters:
                CurrentConsumption = ConsumptionFor.Buildings;
                GetConsumptionDetails(CurrentConsumption, CurrentPremisesId);

                break;

            case ConsumptionFor.Premises:
                btnBack.Hidden = true;
                break;
            }
            lblHeader.Text = CurrentConsumption.ToString();
        }