コード例 #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            NavigationItem.SetLeftBarButtonItem(
                new UIBarButtonItem(UIImage.FromBundle("menu.png"), UIBarButtonItemStyle.Plain, (s, e) => NavigationController.PopViewController(true)),
                true);

            locations = new AvailableLocations();

            state           = locations.States.ElementAt(0);
            currentSelected = locations.PotentialLocations.Where(loc => loc.State == state).ElementAt(0);

            stateTableSource      = new StateTableSource(locations);
            cityTableSource       = new CityTableSource(locations, locations.States.ElementAt(0));
            StateTableView.Source = stateTableSource;
            CityTableView.Source  = cityTableSource;

            StateTableView.SelectRow(NSIndexPath.FromRowSection(0, 0), false, UITableViewScrollPosition.None);

            stateTableSource.ValueChanged += StateTable_Changed;
            cityTableSource.ValueChange   += CityTable_Changed;

            RecentCitiesButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                var storyboard = UIStoryboard.FromName("Main", null);
                var recentCitiesViewController = (RecentCitiesTableViewController)storyboard.InstantiateViewController("RecentCitiesTableViewController");
                recentCitiesViewController.FromMenu = false;
                this.ShowViewController(recentCitiesViewController, this);
            };
        }
コード例 #2
0
        public override void RowSelected(UITableView tableView, Foundation.NSIndexPath indexPath)
        {
            AvailableLocations allLocations = new AvailableLocations();
            var categoryVC = new CategoryPickerViewController();

            categoryVC.SelectedCity = allLocations.PotentialLocations.Find(x => x.SiteName == recentCities[indexPath.Row].City);

            this.owner.ShowViewController(categoryVC, this);
        }
コード例 #3
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = new ListView(this.Activity);

            recentCities = MainActivity.databaseConnection.GetAllRecentCitiesAsync().Result;
            recentCities.Sort((s1, s2) => s2.Updated.CompareTo(s1.Updated));

            view.Adapter = new RecentCityAdapter(this.Activity, recentCities);

            view.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => {
                var transaction = this.Activity.SupportFragmentManager.BeginTransaction();
                CategoryPickerFragment categoryFragment = new CategoryPickerFragment();

                AvailableLocations allLocations = new AvailableLocations();
                categoryFragment.SelectedLocation = allLocations.PotentialLocations.Find(x => x.SiteName == recentCities[e.Position].City);

                transaction.Replace(Resource.Id.frameLayout, categoryFragment);
                transaction.AddToBackStack(null);
                transaction.Commit();
            };

            return(view);
        }
コード例 #4
0
    public void UpdateLocation()
    {
        if (selectedLocation == AvailableLocations.NewYork)
        {
            try {
                string content = client.DownloadString("https://query.yahooapis.com/v1/public/yql?q=select%20astronomy.sunset%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22newyork%2C%20ny%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys");

                JSONNode newYork = JSON.Parse(content);
                sunset = Utils.GetSunsetTime(newYork);
            }
            catch (WebException e) {
                Debug.Log("<color=red>ERROR: </color>" + e.Message + " RETURNING DEFAULT VALUES");
                sunset           = Utils.GetSunsetTime(Utils.ReadJSONFromFile(Application.dataPath, "default.json"));
                selectedLocation = AvailableLocations.Default;
            }
        }

        if (selectedLocation == AvailableLocations.Hawaii)
        {
            try {
                string content = client.DownloadString("https://query.yahooapis.com/v1/public/yql?q=select%20astronomy.sunset%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22maui%2C%20hi%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys");

                JSONNode hawaii = JSON.Parse(content);
                sunset = Utils.GetSunsetTime(hawaii);
            }
            catch (WebException e) {
                Debug.Log("<color=red>ERROR: </color>" + e.Message + " RETURNING DEFAULT VALUES");
                sunset           = Utils.GetSunsetTime(Utils.ReadJSONFromFile(Application.dataPath, "default.json"));
                selectedLocation = AvailableLocations.Default;
            }
        }

        if (selectedLocation == AvailableLocations.Default)
        {
            sunset = Utils.GetSunsetTime(Utils.ReadJSONFromFile(Application.dataPath, "default.json"));
        }
    }
コード例 #5
0
        /// <summary>
        /// Moves a chosen location to a new position within the ordered list of all locations.
        /// </summary>
        /// <param name="name">The id of the chosen location.</param>
        /// <remarks>
        /// Each time a location is chosen it is moved up in the rank of all known locations:
        /// <list type="text">
        /// <item>
        /// If this is the first time the location is chosen, it is moved to the bottom of the list
        /// of previously chosen locations.
        /// </item>
        /// <item>
        /// Each subesequent use of the location will move it up the list by approximately 1/2 its
        /// "distance" to the top of the list.
        /// </item>
        /// </list>
        /// </remarks>
        internal void UpdateQueuing(string name)
        {
            var originalLocation = AvailableLocations[FindIndex(name, AvailableLocations)];
            var originalQueueing = originalLocation.Queueing;
            var maxQueueing      = AvailableLocations[0].Queueing;

            var finalQueueing = (originalQueueing == 0) ? 1 : Math.Min(maxQueueing, maxQueueing - (maxQueueing - originalQueueing) / 2 + 1);

            if (finalQueueing == originalQueueing)
            {
                $"Requeueing {originalLocation.LocationName} from {originalQueueing}: no change".Debug();
                return;
            }

            $"Requeueing {originalLocation.LocationName} from {originalQueueing} to {finalQueueing} ".Debug();
            originalLocation.Queueing       = finalQueueing;
            originalLocation.File.IsChanged = true;
            _allLocations.Sort(CompareLocations);

            int nextQueueing = 0;

            for (int index = _allLocations.Count - 1; index >= 0; index--)
            {
                var currentQueueing = _allLocations[index].Queueing;
                if (currentQueueing != 0)
                {
                    _allLocations[index].Queueing       = ++nextQueueing;
                    _allLocations[index].File.IsChanged = (currentQueueing != nextQueueing);
                }
            }

            IsChanged = true;
            Save();

            AvailableLocations.Sort(CompareLocations);
        }
コード例 #6
0
        void Initialize()
        {
            this.WeightSum   = 1;
            this.Orientation = Orientation.Vertical;
            LayoutParams       p         = new LayoutParams(0, ViewGroup.LayoutParams.MatchParent, 0.5f);
            AvailableLocations locations = new AvailableLocations();

            state = locations.States.ElementAt(0);

            LinearLayout headerHolder = new LinearLayout(context);

            headerHolder.LayoutParameters = new ViewGroup.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent);
            headerHolder.Orientation      = Orientation.Horizontal;
            headerHolder.SetBackgroundResource(Resource.Color.headerColor);

            TextView stateHeader = new TextView(context)
            {
                Text = "State"
            };

            stateHeader.LayoutParameters = p;
            stateHeader.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.50f);
            stateHeader.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), (int)(rowHeight * 0.1), (int)(rowHeight * 0.15));
            headerHolder.AddView(stateHeader);

            TextView cityHeader = new TextView(context)
            {
                Text = "City"
            };

            cityHeader.LayoutParameters = p;
            cityHeader.SetTextSize(Android.Util.ComplexUnitType.Px, rowHeight * 0.50f);
            cityHeader.SetPadding((int)(rowHeight * 0.1), (int)(rowHeight * 0.15), (int)(rowHeight * 0.1), (int)(rowHeight * 0.15));
            headerHolder.AddView(cityHeader);

            AddView(headerHolder);

            LinearLayout pickerHolder = new LinearLayout(context);

            pickerHolder.LayoutParameters = new ViewGroup.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent);
            pickerHolder.Orientation      = Orientation.Horizontal;

            state_picker = new ListView(context);
            state_picker.LayoutParameters = p;
            state_picker.Adapter          = new StateListAdapter(context, locations.States);
            pickerHolder.AddView(state_picker);

            city_picker = new ListView(context);
            city_picker.LayoutParameters = p;
            cityAdapter         = new CityListAdapter(context, locations.PotentialLocations.Where(loc => loc.State == state).OrderBy(x => x.SiteName));
            city_picker.Adapter = cityAdapter;
            pickerHolder.AddView(city_picker);

            AddView(pickerHolder);

            state_picker.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) =>
            {
                state = locations.States.ElementAt(e.Position);
                cityAdapter.Cities = locations.PotentialLocations.Where(l => l.State.Equals(state));
                cityAdapter.NotifyDataSetChanged();
            };

            city_picker.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) =>
            {
                Location selected = locations.PotentialLocations.Where(loc => loc.State == state).ElementAt(e.Position);

                var transaction = ((AppCompatActivity)context).SupportFragmentManager.BeginTransaction();
                CategoryPickerFragment categoryFragment = new CategoryPickerFragment();
                categoryFragment.SelectedLocation = selected;
                transaction.Replace(Resource.Id.frameLayout, categoryFragment)
                .AddToBackStack(null)
                .Commit();

                Task.Run(async() =>
                {
                    await MainActivity.databaseConnection.AddNewRecentCityAsync(selected.SiteName, selected.Url).ConfigureAwait(true);

                    if (MainActivity.databaseConnection.GetAllRecentCitiesAsync().Result.Count > 5)
                    {
                        await MainActivity.databaseConnection.DeleteOldestCityAsync().ConfigureAwait(true);
                    }
                });
            };
        }
コード例 #7
0
 public CityTableSource(AvailableLocations locations, string state)
 {
     citiesInState = locations.PotentialLocations.Where(l => l.State.Equals(state)).OrderBy(l => l.SiteName).ToList();
 }
コード例 #8
0
 public StateTableSource(AvailableLocations locations)
 {
     this.locations = locations;
 }
コード例 #9
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            locations       = new AvailableLocations();
            state           = locations.States.ElementAt((int)StatePickerView.SelectedRowInComponent(0));
            currentSelected = locations.PotentialLocations.Where(loc => loc.State == state).ElementAt(0);

            cityModel            = new LocationPickerModel(locations, state);
            CityPickerView.Model = cityModel;

            stateModel            = new StatePickerModel(locations);
            StatePickerView.Model = stateModel;

            cityModel.ValueChange += cityPickerChanged;

            CurrentStateLabel.AllTouchEvents += (sender, e) => {
                ShowStatePickerOnly();
            };

            CurrentCityLabel.AllTouchEvents += (sender, e) => {
                ShowCityPickerOnly();
            };

            CurrentStateLabel.ShouldReturn += delegate {
                return(false);
            };

            ProceedButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                var storyboard           = UIStoryboard.FromName("Main", null);
                var searchViewController = (SearchViewController)storyboard.InstantiateViewController("SearchViewController");

                Console.WriteLine(currentSelected.SiteName);
                searchViewController.Url  = currentSelected.Url;
                searchViewController.City = currentSelected.SiteName;

                System.Threading.Tasks.Task.Run(async() => {
                    await AppDelegate.databaseConnection.AddNewRecentCityAsync(currentSelected.SiteName, currentSelected.Url);

                    if (AppDelegate.databaseConnection.GetAllRecentCitiesAsync().Result.Count > 5)
                    {
                        await AppDelegate.databaseConnection.DeleteOldestCityAsync();
                    }
                });

//                    this.ShowViewController(searchViewController, this);
            };

            RecentCitiesButton.TouchUpInside += (object sender, EventArgs e) => {
                var storyboard = UIStoryboard.FromName("Main", null);
                var recentCitiesViewController = (RecentCitiesTableViewController)storyboard.InstantiateViewController("RecentCitiesTableViewController");
//                this.ShowViewController(recentCitiesViewController, this);
            };

            stateModel.ValueChanged += (object sender, EventArgs e) =>
            {
                state = stateModel.SelectedItem;
                CityPickerView.Select(0, 0, false);

                currentSelected      = locations.PotentialLocations.Where(loc => loc.State == state).ElementAt(0);
                cityModel            = new LocationPickerModel(locations, stateModel.SelectedItem);
                CityPickerView.Model = cityModel;

                cityModel.ValueChange += cityPickerChanged;
                CurrentStateLabel.Text = state;
//                    ShowCityPickerOnly();
            };
        }
コード例 #10
0
 public LocationPickerModel(AvailableLocations locations, string state)
 {
     this.locations = locations;
     this.state     = state;
 }
コード例 #11
0
 public StatePickerModel(AvailableLocations locations)
 {
     this.locations = locations;
 }