Exemplo n.º 1
0
        public void Initialize()
        {
            if (weatherView != null)
            {
                View?.SetBackgroundColor(weatherView.PendingBackground);
                // specify an adapter (see also next example)
                RecyclerView.Adapter adapter = null;

                weatherType = (WeatherListType)Arguments?.GetInt("WeatherListType", 0);

                switch (weatherType)
                {
                default:
                case WeatherListType.Forecast:
                    recyclerView.SetLayoutManager(new WearableLinearLayoutManager(Activity));
                    adapter = new ForecastItemAdapter(weatherView.Forecasts.ToList());
                    break;

                case WeatherListType.HourlyForecast:
                    recyclerView.SetLayoutManager(new WearableLinearLayoutManager(Activity));
                    adapter = new HourlyForecastItemAdapter(weatherView.Extras.HourlyForecast.ToList());
                    break;

                case WeatherListType.Alerts:
                    recyclerView.SetLayoutManager(new LinearLayoutManager(Activity));
                    adapter = new WeatherAlertPanelAdapter(weatherView.Extras.Alerts.ToList());
                    break;
                }

                recyclerView.SetAdapter(adapter);
            }
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Inflate the layout for this fragment
            View view = inflater.Inflate(Resource.Layout.fragment_weather_now, container, false);

            // Setup Actionbar
            HasOptionsMenu = false;

            refreshLayout          = (SwipeRefreshLayout)view;
            mainView               = view.FindViewById <NestedScrollView>(Resource.Id.fragment_weather_now);
            mainView.ScrollChange += ScrollView_ScrollChange;
            bgImageView            = view.FindViewById <ImageView>(Resource.Id.image_view);
            // Condition
            locationName     = view.FindViewById <TextView>(Resource.Id.label_location_name);
            updateTime       = view.FindViewById <TextView>(Resource.Id.label_updatetime);
            weatherIcon      = view.FindViewById <TextView>(Resource.Id.weather_icon);
            weatherCondition = view.FindViewById <TextView>(Resource.Id.weather_condition);
            weatherTemp      = view.FindViewById <TextView>(Resource.Id.weather_temp);
            // Details
            detailsPanel  = view.FindViewById(Resource.Id.details_panel);
            humidity      = view.FindViewById <TextView>(Resource.Id.humidity);
            pressureState = view.FindViewById <TextView>(Resource.Id.pressure_state);
            pressure      = view.FindViewById <TextView>(Resource.Id.pressure);
            visiblity     = view.FindViewById <TextView>(Resource.Id.visibility_val);
            feelslike     = view.FindViewById <TextView>(Resource.Id.feelslike);
            windDirection = view.FindViewById <TextView>(Resource.Id.wind_direction);
            windSpeed     = view.FindViewById <TextView>(Resource.Id.wind_speed);
            sunrise       = view.FindViewById <TextView>(Resource.Id.sunrise_time);
            sunset        = view.FindViewById <TextView>(Resource.Id.sunset_time);
            // Forecast
            forecastPanel            = view.FindViewById <RelativeLayout>(Resource.Id.forecast_panel);
            forecastPanel.Visibility = ViewStates.Invisible;
            forecastView             = view.FindViewById <Android.Support.V7.Widget.RecyclerView>(Resource.Id.forecast_view);
            // Additional Details
            forecastSwitch = view.FindViewById <Switch>(Resource.Id.forecast_switch);
            forecastSwitch.CheckedChange += ForecastSwitch_CheckedChange;
            forecastSwitch.Visibility     = ViewStates.Gone;
            txtForecastView               = view.FindViewById <ViewPager>(Resource.Id.txt_forecast_viewpgr);
            txtForecastView.Adapter       = new TextForecastPagerAdapter(this.Activity, new List <TextForecastItemViewModel>());
            txtForecastView.Visibility    = ViewStates.Gone;
            hrforecastPanel               = view.FindViewById <LinearLayout>(Resource.Id.hourly_forecast_panel);
            hrforecastPanel.Visibility    = ViewStates.Gone;
            hrforecastView                = view.FindViewById <Android.Support.V7.Widget.RecyclerView>(Resource.Id.hourly_forecast_view);
            precipitationPanel            = view.FindViewById <RelativeLayout>(Resource.Id.precipitation_card);
            precipitationPanel.Visibility = ViewStates.Gone;
            chanceLabel     = view.FindViewById <TextView>(Resource.Id.chance_label);
            chance          = view.FindViewById <TextView>(Resource.Id.chance_val);
            cloudinessLabel = view.FindViewById <TextView>(Resource.Id.cloudiness_label);
            cloudiness      = view.FindViewById <TextView>(Resource.Id.cloudiness);
            qpfRain         = view.FindViewById <TextView>(Resource.Id.qpf_rain_val);
            qpfSnow         = view.FindViewById <TextView>(Resource.Id.qpf_snow_val);
            // Alerts
            alertButton        = view.FindViewById(Resource.Id.alert_button);
            alertButton.Click += (sender, e) =>
            {
                // Show Alert Fragment
                if (weatherView.Extras.Alerts.Count > 0)
                {
                    AppCompatActivity.SupportFragmentManager.BeginTransaction()
                    .Add(Resource.Id.fragment_container, WeatherAlertsFragment.NewInstance(location, weatherView))
                    .Hide(this)
                    .AddToBackStack(null)
                    .Commit();
                }
            };
            alertButton.Visibility = ViewStates.Invisible;

            // Cloudiness only supported by OWM
            cloudinessLabel.Visibility = ViewStates.Gone;
            cloudiness.Visibility      = ViewStates.Gone;

            forecastView.HasFixedSize = true;
            forecastAdapter           = new ForecastItemAdapter(new List <ForecastItemViewModel>());
            forecastView.SetAdapter(forecastAdapter);

            hrforecastView.HasFixedSize = true;
            hrforecastAdapter           = new HourlyForecastItemAdapter(new List <HourlyForecastItemViewModel>());
            hrforecastView.SetAdapter(hrforecastAdapter);

            // SwipeRefresh
            refreshLayout.SetColorSchemeColors(ContextCompat.GetColor(Activity, Resource.Color.colorPrimary));
            refreshLayout.Refresh += delegate
            {
                Task.Run(async() =>
                {
                    if (Settings.FollowGPS && await UpdateLocation())
                    {
                        // Setup loader from updated location
                        wLoader = new WeatherDataLoader(this.location, this, this);
                    }

                    await RefreshWeather(true);
                });
            };

            // Nav Header View
            navheader      = Activity.FindViewById <NavigationView>(Resource.Id.nav_view).GetHeaderView(0);
            navLocation    = navheader.FindViewById <TextView>(Resource.Id.nav_location);
            navWeatherTemp = navheader.FindViewById <TextView>(Resource.Id.nav_weathertemp);

            weatherCredit = view.FindViewById <TextView>(Resource.Id.weather_credit);

            loaded = true;
            refreshLayout.Refreshing = true;

            return(view);
        }