コード例 #1
0
ファイル: Step2Activity.cs プロジェクト: mrmelonson/Swell
        public async Task UpdaterAsync(CancellationToken ct)
        {
            string[,] sizesSlugsArr = { { "s-1vcpu-1gb", "5$/month\n1 vCPU : 1GB\n25gb Disk : 1TB Transfer\n"  },
                                        { "s-1vcpu-2gb", "10$/month\n1 vCPU : 2GB\n50gb Disk : 2TB Transfer\n" },
                                        { "s-1vcpu-3gb", "15$/month\n1 vCPU : 3GB\n60gb Disk : 3TB Transfer\n" },
                                        { "s-2vcpu-2gb", "15$/month\n2 vCPU : 2GB\n60gb Disk : 3TB Transfer\n" },
                                        { "s-3vcpu-1gb", "15$/month\n3 vCPU : 1GB\n60gb Disk : 3TB Transfer\n" },
                                        { "s-2vcpu-4gb", "20$/month\n2 vCPU : 4GB\n80gb Disk : 4TB Transfer\n" }, };

            _Loading_Fragment = new Loading_Fragment();
            _Step2_Fragment   = new Step2_Fragment();

            var currentdrops         = new List <DisplayInfo>();
            var regionsslug          = new List <DisplayInfo>();
            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            var api_key = prefs.GetString("api_key", null);

            DigitalOceanClient client = new DigitalOceanClient(api_key);

            var trans = SupportFragmentManager.BeginTransaction();

            trans.Add(Resource.Id.Step2_Frame, _Step2_Fragment, "Fragment");
            trans.Add(Resource.Id.Step2_Frame, _Loading_Fragment, "Fragment");
            trans.Hide(_Step2_Fragment);
            trans.Show(_Loading_Fragment);
            trans.Commit();

            var dropletsizes = await client.Sizes.GetAll();

            var regions = await client.Regions.GetAll();

            var trans2 = SupportFragmentManager.BeginTransaction();

            trans2.Hide(_Loading_Fragment);
            trans2.Show(_Step2_Fragment);
            trans2.Commit();

            RadioGroup rgp = FindViewById <RadioGroup>(Resource.Id.radiogroupplan);
            RadioGroup rgr = FindViewById <RadioGroup>(Resource.Id.radiogroupregion);

            for (int i = 0; i < dropletsizes.Count; i++)
            {
                for (int x = 0; x < sizesSlugsArr.GetLength(0); x++)
                {
                    if (dropletsizes[i].Slug == sizesSlugsArr[x, 0] /*&& dropletsizes[i].Available*/)
                    {
                        RadioButton rdbtn = new RadioButton(this);
                        rdbtn.Text = sizesSlugsArr[x, 1];
                        rdbtn.Id   = View.GenerateViewId();
                        var toadd = new DisplayInfo();
                        toadd.dropindex = i;
                        toadd.radioid   = rdbtn.Id;
                        toadd.slug      = sizesSlugsArr[x, 0];
                        toadd.text      = sizesSlugsArr[x, 1];
                        currentdrops.Add(toadd);
                        rgp.AddView(rdbtn);
                    }
                }
                Console.WriteLine(dropletsizes[i].Slug);
            }

            for (int i = 0; i < regions.Count; i++)
            {
                if (regions[i].Available == true)
                {
                    var x = new DisplayInfo();
                    x.name = regions[i].Name;
                    x.slug = regions[i].Slug;
                    regionsslug.Add(x);
                }
            }

            regionsslug.Sort(new Comparison <DisplayInfo>((x, y) => string.Compare(x.name, y.name)));

            for (int i = 0; i < regionsslug.Count; i++)
            {
                RadioButton rdbtn = new RadioButton(this);
                rdbtn.Text             = regionsslug[i].name;
                rdbtn.Id               = View.GenerateViewId();
                regionsslug[i].radioid = rdbtn.Id;
                rgr.AddView(rdbtn);
            }

            RadioButton checkedrgp = FindViewById <RadioButton>(rgp.CheckedRadioButtonId);
            RadioButton checkedrgr = FindViewById <RadioButton>(rgr.CheckedRadioButtonId);

            rgp.CheckedChange += (o, e) =>
            {
                checkedrgp = FindViewById <RadioButton>(rgp.CheckedRadioButtonId);
                for (int i = 0; i < currentdrops.Count; i++)
                {
                    if (currentdrops[i].radioid == checkedrgp.Id)
                    {
                        createdrop.SizeSlug = currentdrops[i].slug;
                        break;
                    }
                }
            };

            rgr.CheckedChange += (o, e) =>
            {
                checkedrgr = FindViewById <RadioButton>(rgr.CheckedRadioButtonId);
                for (int i = 0; i < regionsslug.Count; i++)
                {
                    if (regionsslug[i].radioid == checkedrgr.Id)
                    {
                        createdrop.RegionSlug = regionsslug[i].slug;
                        break;
                    }
                }
            };

            Button next = FindViewById <Button>(Resource.Id.NextS2);
            Button back = FindViewById <Button>(Resource.Id.BackS2);

            back.Click += (o, e) =>
            {
                var intent = new Intent(this, typeof(Step1Activity));
                StartActivity(intent);
            };

            next.Click += (o, e) =>
            {
                if (checkedrgp == null)
                {
                    Toast.MakeText(this, "Please select plan", ToastLength.Short).Show();
                    return;
                }
                if (checkedrgr == null)
                {
                    Toast.MakeText(this, "Please select region", ToastLength.Short).Show();
                    return;
                }

                var intent = new Intent(this, typeof(Step3Activity));
                intent.PutExtra("DropletName", createdrop.Name);
                intent.PutExtra("DropletDistro", Intent.Extras.GetString("DropletDistro"));
                intent.PutExtra("DropletRegion", createdrop.RegionSlug);
                intent.PutExtra("DropletSize", createdrop.SizeSlug);
                StartActivity(intent);
            };
        }
コード例 #2
0
ファイル: MainActivity.cs プロジェクト: mrmelonson/Swell
        public async Task UpdaterAsync(CancellationToken ct, int id)
        {
            SetContentView(Resource.Layout.activity_main);
            var trans = SupportFragmentManager.BeginTransaction();

            _Loading_Fragment     = new Loading_Fragment();
            _droplet_Mainfragment = new Droplet_mainfragment();
            _Def_Fragment         = new Def_Fragment();
            _Def_First_Fragment   = new Def_First_Fragment();

            trans.Add(Resource.Id.DropletFragment, _droplet_Mainfragment, "Fragment");
            trans.Add(Resource.Id.DropletFragment, _Loading_Fragment, "Fragment");
            trans.Add(Resource.Id.DropletFragment, _Def_Fragment, "Fragment");
            trans.Add(Resource.Id.DropletFragment, _Def_First_Fragment, "Fragment");

            trans.Show(_Loading_Fragment);
            trans.Hide(_droplet_Mainfragment);
            trans.Hide(_Def_Fragment);
            trans.Hide(_Def_First_Fragment);
            trans.Commit();

            currentDropId = id;
            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            var api_key = prefs.GetString("api_key", null);


            client = new DigitalOceanClient(api_key);

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

            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();

            SwipeRefreshLayout swipe = FindViewById <SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout);

            swipe.Refresh += async(o, e) =>
            {
                trans = SupportFragmentManager.BeginTransaction();
                trans.Show(_Loading_Fragment);
                trans.Hide(_droplet_Mainfragment);
                trans.Commit();

                await UpdateNavMenu();

                if (id > 0)
                {
                    await UpdateInfo(currentDropId);
                }

                trans = SupportFragmentManager.BeginTransaction();
                trans.Hide(_Loading_Fragment);
                trans.Show(_droplet_Mainfragment);
                trans.Commit();
                swipe.Refreshing = false;
            };

            await UpdateNavMenu();

            trans = SupportFragmentManager.BeginTransaction();

            if (id == -1)
            {
                trans.Show(_Def_Fragment);
            }
            else if (id == -2)
            {
                trans.Show(_Def_First_Fragment);
            }

            trans.Hide(_Loading_Fragment);
            trans.Hide(_droplet_Mainfragment);
            trans.Commit();
        }
コード例 #3
0
        public async Task UpdaterAsync(CancellationToken ct)
        {
            _Loading_Fragment = new Loading_Fragment();
            _Step3_Fragment   = new Step3_Fragment();



            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            var api_key = prefs.GetString("api_key", null);

            var trans = SupportFragmentManager.BeginTransaction();

            trans.Add(Resource.Id.Step3_Frame, _Step3_Fragment, "Fragment");
            trans.Add(Resource.Id.Step3_Frame, _Loading_Fragment, "Fragment");
            trans.Hide(_Step3_Fragment);
            trans.Show(_Loading_Fragment);
            trans.Commit();

            DigitalOceanClient client = new DigitalOceanClient(api_key);
            var keys = await client.Keys.GetAll();

            trans = SupportFragmentManager.BeginTransaction();
            trans.Hide(_Loading_Fragment);
            trans.Show(_Step3_Fragment);
            trans.Commit();

            List <sshkey> sshkeys = new List <sshkey>();

            RadioGroup lls = FindViewById <RadioGroup>(Resource.Id.sshkeygroup);

            for (int i = 0; i < keys.Count; i++)
            {
                CheckBox cb = new CheckBox(this);
                cb.Text = keys[i].Name;
                cb.Id   = View.GenerateViewId();
                sshkey x = new sshkey();
                x.Id      = keys[i].Id;
                x.Name    = keys[i].Name;
                x.radioid = cb.Id;
                sshkeys.Add(x);
                cb.Click += delegate(object sender, EventArgs e) { CheckBoxOnClick(cb, sshkeys); };
                lls.AddView(cb);
            }

            createdrop.Backups           = false;
            createdrop.Ipv6              = false;
            createdrop.Monitoring        = false;
            createdrop.PrivateNetworking = false;

            CheckBox bcb   = FindViewById <CheckBox>(Resource.Id.checkBoxbackup);
            CheckBox ipbcb = FindViewById <CheckBox>(Resource.Id.checkBoxipv6net);
            CheckBox moncb = FindViewById <CheckBox>(Resource.Id.checkBoxmonitor);
            CheckBox pvcb  = FindViewById <CheckBox>(Resource.Id.checkBoxprivnet);



            bcb.CheckedChange += (o, e) =>
            {
                if (FindViewById <CheckBox>(Resource.Id.checkBoxbackup).Checked)
                {
                    createdrop.Backups = true;
                }
                else
                {
                    createdrop.Backups = false;
                }
            };

            ipbcb.CheckedChange += (o, e) =>
            {
                if (FindViewById <CheckBox>(Resource.Id.checkBoxipv6net).Checked)
                {
                    createdrop.Ipv6 = true;
                }
                else
                {
                    createdrop.Ipv6 = false;
                }
            };

            moncb.CheckedChange += (o, e) =>
            {
                if (FindViewById <CheckBox>(Resource.Id.checkBoxmonitor).Checked)
                {
                    createdrop.Monitoring = true;
                }
                else
                {
                    createdrop.Monitoring = false;
                }
            };

            pvcb.CheckedChange += (o, e) =>
            {
                if (FindViewById <CheckBox>(Resource.Id.checkBoxprivnet).Checked)
                {
                    createdrop.PrivateNetworking = true;
                }
                else
                {
                    createdrop.PrivateNetworking = false;
                }
            };

            Button next = FindViewById <Button>(Resource.Id.NextS3);
            Button back = FindViewById <Button>(Resource.Id.BackS3);

            EditText tagsedit = FindViewById <EditText>(Resource.Id.Tags);


            back.Click += (o, e) =>
            {
                var intent = new Intent(this, typeof(Step2Activity));
                intent.PutExtra("DropletName", createdrop.Name);
                intent.PutExtra("DropletDistro", Intent.Extras.GetString("DropletDistro"));
                StartActivity(intent);
            };

            next.Click += async(o, e) =>
            {
                for (int i = 0; i < sshkeys.Count; i++)
                {
                    if (sshkeys[i].selected)
                    {
                        createdrop.SshIdsOrFingerprints.Add(sshkeys[i].Id);
                    }
                }
                createdrop.UserData = null;
                string[] tags = tagsedit.Text.Split(",");
                if (tags.Length > 0)
                {
                    for (int i = 0; i < tags.Length; i++)
                    {
                        if (tags[i] != "" && tags[i] != null)
                        {
                            createdrop.Tags.Add(tags[i]);
                        }
                    }
                }

                trans = SupportFragmentManager.BeginTransaction();
                trans.Show(_Loading_Fragment);
                trans.Hide(_Step3_Fragment);
                trans.Commit();

                var creationAction = await client.Droplets.Create(createdrop);

                trans = SupportFragmentManager.BeginTransaction();
                trans.Hide(_Loading_Fragment);
                trans.Show(_Step3_Fragment);
                trans.Commit();

                var intent = new Intent(this, typeof(MainActivity));
                StartActivity(intent);
            };
        }