Exemple #1
0
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            ISharedPreferences       prefs  = PreferenceManager.GetDefaultSharedPreferences(Android.App.Application.Context);
            ISharedPreferencesEditor editor = prefs.Edit();

            if (prefs.GetString("locale", "") == "")
            {
                editor.PutString("locale", "en");
                editor.Apply();
            }
            string loc    = prefs.GetString("locale", "");
            var    locale = new Java.Util.Locale(loc);

            Java.Util.Locale.Default = locale;
            var config = new Android.Content.Res.Configuration {
                Locale = locale
            };

#pragma warning disable CS0618 // Type or member is obsolete
            BaseContext.Resources.UpdateConfiguration(config, metrics: BaseContext.Resources.DisplayMetrics);
#pragma warning restore CS0618 // Type or member is obsolete
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_settings);

            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab);
            fab.Click += FabOnClick;


            DrawerLayout          drawer = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close);
            drawer.AddDrawerListener(toggle);
            toggle.SyncState();

            NavigationView navigationView = FindViewById <NavigationView>(Resource.Id.nav_view);
            navigationView.SetNavigationItemSelectedListener(this);

            FindLayoutControls();

            apiClient = new APIClient();
            client    = await apiClient.GetClientByIdAsync(0);

            double recomChairValue = await apiClient.CalculateRecommendedChairHeightAsync((int)client.Id);

            double recomTableValue = await apiClient.CalculateRecommendedTableHeightAsync((int)client.Id);

            ManageLayoutData();
            SetControlsClick();

            Button recomTable = FindViewById <Button>(Resource.Id.rec_table);
            recomTable.Click += async(s, arg) => {
                if (client != null)
                {
                    AlertDialog.Builder alert = new AlertDialog.Builder(this);
                    alert.SetTitle("Recommended table height");
                    alert.SetMessage(((int)recomTableValue).ToString());
                    alert.SetPositiveButton("Apply", async(senderAlert, arg1) =>
                    {
                        client.TableHight              = (int)recomTableValue;
                        tableHeightEditText.Text       = client.TableHight.ToString();
                        tableHeightEditText.Visibility = ViewStates.Visible;
                    });

                    alert.SetNegativeButton("Close", (senderAlert, arg1) =>
                    {
                        Toast.MakeText(this, "Cancelled!", ToastLength.Short).Show();
                    });

                    Dialog dialog = alert.Create();
                    dialog.Show();
                }
            };

            Button recomChair = FindViewById <Button>(Resource.Id.rec_chair);
            recomChair.Click += async(s, arg) => {
                if (client != null)
                {
                    AlertDialog.Builder alert = new AlertDialog.Builder(this);
                    alert.SetTitle("Recommended chair height");
                    alert.SetMessage(((int)recomChairValue).ToString());
                    alert.SetPositiveButton("Apply", async(senderAlert, arg1) =>
                    {
                        client.ChairHight              = (int)recomChairValue;
                        chairHeightEditText.Text       = client.ChairHight.ToString();
                        chairHeightEditText.Visibility = ViewStates.Visible;
                    });

                    alert.SetNegativeButton("Close", (senderAlert, arg1) =>
                    {
                        Toast.MakeText(this, "Cancelled!", ToastLength.Short).Show();
                    });

                    Dialog dialog = alert.Create();
                    dialog.Show();
                }
            };
        }