private void ToggleEditMode() { // Toggle EditMode EditMode = !EditMode; IMenuItem editMenuBtn = optionsMenu.FindItem(Resource.Id.action_editmode); // Change EditMode button drwble editMenuBtn.SetIcon(EditMode ? Resource.Drawable.ic_done_white_24dp : Resource.Drawable.ic_mode_edit_white_24dp); // Change EditMode button label editMenuBtn.SetTitle(EditMode ? GetString(Resource.String.abc_action_mode_done) : GetString(Resource.String.action_editmode)); // Set Drag & Swipe ability mITHCallback.SetLongPressDragEnabled(EditMode); mITHCallback.SetItemViewSwipeEnabled(EditMode); if (EditMode) { // Unregister events gpsPanel.Click -= OnPanelClick; mAdapter.ItemClick -= OnPanelClick; mAdapter.ItemLongClick -= OnPanelLongClick; } else { // Register events gpsPanel.Click += OnPanelClick; mAdapter.ItemClick += OnPanelClick; mAdapter.ItemLongClick += OnPanelLongClick; } foreach (LocationPanelViewModel view in mAdapter.Dataset) { view.EditMode = EditMode; mAdapter.NotifyItemChanged(mAdapter.Dataset.IndexOf(view)); if (!EditMode && DataChanged) { string query = view.LocationData.query; int pos = mAdapter.Dataset.IndexOf(view); Task.Factory.StartNew(() => Settings.MoveLocation(query, pos)); } } if (!EditMode && HomeChanged) { WeatherWidgetService.EnqueueWork(AppCompatActivity, new Intent(AppCompatActivity, typeof(WeatherWidgetService)) .SetAction(WeatherWidgetService.ACTION_UPDATEWEATHER)); App.Context.StartService( new Intent(App.Context, typeof(WearableDataListenerService)) .SetAction(WearableDataListenerService.ACTION_SENDLOCATIONUPDATE)); App.Context.StartService( new Intent(App.Context, typeof(WearableDataListenerService)) .SetAction(WearableDataListenerService.ACTION_SENDWEATHERUPDATE)); } DataChanged = false; HomeChanged = false; }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.Inflate(Resource.Layout.fragment_locations, container, false); mMainView = view; view.FindViewById(Resource.Id.search_fragment_container).Click += delegate { ExitSearchUi(); }; view.FocusableInTouchMode = true; view.RequestFocus(); view.KeyPress += (sender, e) => { if (e.KeyCode == Keycode.Back && EditMode) { ToggleEditMode(); e.Handled = true; } else { e.Handled = false; } }; // Setup ActionBar HasOptionsMenu = true; mRecyclerView = view.FindViewById <RecyclerView>(Resource.Id.locations_container); addLocationsButton = view.FindViewById <FloatingActionButton>(Resource.Id.locations_add); addLocationsButton.Click += delegate { mActionMode = AppCompatActivity.StartSupportActionMode(mActionModeCallback); }; gpsPanelLayout = view.FindViewById(Resource.Id.gps_follow_layout); gpsPanel = view.FindViewById <LocationPanel>(Resource.Id.gps_panel); gpsPanel.Click += OnPanelClick; // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView mRecyclerView.HasFixedSize = false; // use a linear layout manager mLayoutManager = new LinearLayoutManager(AppCompatActivity); mRecyclerView.SetLayoutManager(mLayoutManager); // specify an adapter (see also next example) mAdapter = new LocationPanelAdapter(Glide.With(this.Context), new List <LocationPanelViewModel>()); mAdapter.ItemClick += OnPanelClick; mAdapter.ItemLongClick += OnPanelLongClick; mAdapter.CollectionChanged += LocationPanels_CollectionChanged; mRecyclerView.SetAdapter(mAdapter); mITHCallback = new ItemTouchHelperCallback(mAdapter); mItemTouchHelper = new ItemTouchHelper(mITHCallback); mItemTouchHelper.AttachToRecyclerView(mRecyclerView); // Turn off by default mITHCallback.SetLongPressDragEnabled(false); mITHCallback.SetItemViewSwipeEnabled(false); Loaded = true; return(view); }