public override void OnAttachFragment(Fragment fragment)
 {
     if (fragment is LocationSearchFragment locationSearchFragment)
     {
         mSearchFragment = locationSearchFragment;
         SetupSearchUi();
     }
 }
Ejemplo n.º 2
0
        public override void OnAttachFragment(Fragment childFragment)
        {
            if (childFragment is LocationSearchFragment)
            {
                mSearchFragment = childFragment as LocationSearchFragment;

                if (inSearchUI)
                {
                    SetupSearchUi();
                }
            }
        }
        private void ExitSearchUi()
        {
            searchView.Text = String.Empty;

            if (mSearchFragment != null)
            {
                mSearchFragment.UserVisibleHint = false;

                var transaction = SupportFragmentManager.BeginTransaction();
                transaction.Remove(mSearchFragment);
                mSearchFragment = null;
                transaction.CommitAllowingStateLoss();
            }

            HideInputMethod(CurrentFocus);
            searchView.ClearFocus();
            mActionMode.Finish();
            inSearchUI = false;
        }
Ejemplo n.º 4
0
        private void ExitSearchUi()
        {
            searchView.Text = String.Empty;

            if (mSearchFragment != null)
            {
                mSearchFragment.UserVisibleHint = false;

                FragmentTransaction transaction = ChildFragmentManager
                                                  .BeginTransaction();
                transaction.Remove(mSearchFragment);
                mSearchFragment = null;
                transaction.CommitAllowingStateLoss();
            }

            HideInputMethod(AppCompatActivity?.CurrentFocus);
            searchView?.ClearFocus();
            mActionMode?.Finish();
            mMainView?.RequestFocus();
            inSearchUI = false;
        }
        private void AddSearchFragment()
        {
            if (mSearchFragment != null)
            {
                return;
            }
            var      ft             = SupportFragmentManager.BeginTransaction();
            Fragment searchFragment = new LocationSearchFragment()
            {
                UserVisibleHint = false
            };

            // Add AppWidgetId to fragment args
            if (mAppWidgetId != AppWidgetManager.InvalidAppwidgetId)
            {
                Bundle args = new Bundle();
                args.PutInt(AppWidgetManager.ExtraAppwidgetId, mAppWidgetId);
                searchFragment.Arguments = args;
            }

            ft.Add(Resource.Id.search_fragment_container, searchFragment);
            ft.CommitAllowingStateLoss();
        }
Ejemplo n.º 6
0
        private void AddSearchFragment()
        {
            if (mSearchFragment != null)
            {
                return;
            }

            FragmentTransaction    ft             = ChildFragmentManager.BeginTransaction();
            LocationSearchFragment searchFragment = new LocationSearchFragment();

            searchFragment.SetClickListener(async(object sender, RecyclerClickEventArgs e) =>
            {
                if (mSearchFragment == null)
                {
                    return;
                }

                LocationQueryAdapter adapter = sender as LocationQueryAdapter;
                LocationQuery v = (LocationQuery)e.View;
                LocationQueryViewModel query_vm = null;

                try
                {
                    if (!String.IsNullOrEmpty(adapter.Dataset[e.Position].LocationQuery))
                    {
                        query_vm = adapter.Dataset[e.Position];
                    }
                }
                catch (Exception)
                {
                    query_vm = null;
                }
                finally
                {
                    if (query_vm == null)
                    {
                        query_vm = new LocationQueryViewModel();
                    }
                }

                if (String.IsNullOrWhiteSpace(query_vm.LocationQuery))
                {
                    // Stop since there is no valid query
                    return;
                }

                // Cancel other tasks
                mSearchFragment.CtsCancel();
                var ctsToken = mSearchFragment.GetCancellationTokenSource().Token;

                ShowLoading(true);

                if (ctsToken.IsCancellationRequested)
                {
                    ShowLoading(false);
                    return;
                }

                // Check if location already exists
                var locData = await Settings.GetLocationData();
                if (locData.Exists(l => l.query == query_vm.LocationQuery))
                {
                    ShowLoading(false);
                    ExitSearchUi();
                    return;
                }

                if (ctsToken.IsCancellationRequested)
                {
                    ShowLoading(false);
                    return;
                }

                var location = new LocationData(query_vm);
                if (!location.IsValid())
                {
                    Toast.MakeText(App.Context, App.Context.GetString(Resource.String.werror_noweather), ToastLength.Short).Show();
                    ShowLoading(false);
                    return;
                }
                Weather weather = await Settings.GetWeatherData(location.query);
                if (weather == null)
                {
                    try
                    {
                        weather = await wm.GetWeather(location);
                    }
                    catch (WeatherException wEx)
                    {
                        weather = null;
                        Toast.MakeText(App.Context, wEx.Message, ToastLength.Short).Show();
                    }
                }

                if (weather == null)
                {
                    ShowLoading(false);
                    return;
                }

                // We got our data so disable controls just in case
                mAdapter.Dataset.Clear();
                mAdapter.NotifyDataSetChanged();

                if (mSearchFragment?.View != null &&
                    mSearchFragment?.View?.FindViewById(Resource.Id.recycler_view) is RecyclerView recyclerView)
                {
                    recyclerView.Enabled = false;
                }

                // Save data
                await Settings.AddLocation(location);
                if (wm.SupportsAlerts && weather.weather_alerts != null)
                {
                    await Settings.SaveWeatherAlerts(location, weather.weather_alerts);
                }
                await Settings.SaveWeatherData(weather);

                var panel = new LocationPanelViewModel(weather)
                {
                    LocationData = location
                };

                // Set properties if necessary
                if (EditMode)
                {
                    panel.EditMode = true;
                }

                int index = mAdapter.Dataset.Count;
                mAdapter.Add(panel);

                // Update shortcuts
                Task.Run(Shortcuts.ShortcutCreator.UpdateShortcuts);

                // Hide dialog
                ShowLoading(false);
                ExitSearchUi();
            });
            searchFragment.UserVisibleHint = false;
            ft.Add(Resource.Id.search_fragment_container, searchFragment);
            ft.CommitAllowingStateLoss();
        }