void Search_Facilities(object sender, EventArgs e) { if (searchedTxt.Text.Trim().Length > 1) { var newList = ViewModel.OriginalFacilities.Where(f => f.Name.ToLower().Contains(searchedTxt.Text.ToLower().Trim()) || f.ClientCode.ToLower().Contains(searchedTxt.Text.ToLower().Trim())); ViewModel.Facilities = new ObservableCollection <Facility>(); foreach (var item in newList) { ViewModel.Facilities.Add(item); } recyclerView.SetAdapter(adapter = new BrowseFacilitiesAdapter(Activity, ViewModel, userId)); refresher.Refreshing = false; refresher.Refresh += Refresher_Refresh; adapter.ItemClick += Adapter_ItemClick; } else { ViewModel.Facilities = new ObservableCollection <Facility>(); foreach (var item in ViewModel.OriginalFacilities) { ViewModel.Facilities.Add(item); } recyclerView.SetAdapter(adapter = new BrowseFacilitiesAdapter(Activity, ViewModel, userId)); refresher.Refreshing = false; refresher.Refresh += Refresher_Refresh; adapter.ItemClick += Adapter_ItemClick; } }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewModel = new FacilitiesViewModel(); ap = new AppPreferences(Application.Context); this.SqlLiteManager = new SqlLiteManager(); userId = Convert.ToInt32(ap.GetUserId()); View view = inflater.Inflate(Resource.Layout.fragment_facility, container, false); recyclerView = view.FindViewById <RecyclerView>(Resource.Id.facilityRecyclerView); searchedTxt = view.FindViewById <EditText>(Resource.Id.searchedTxt); searchedTxt.TextChanged += Search_Facilities; recyclerView.HasFixedSize = true; recyclerView.SetAdapter(adapter = new BrowseFacilitiesAdapter(Activity, ViewModel, userId)); refresher = view.FindViewById <SwipeRefreshLayout>(Resource.Id.refresher); refresher.SetColorSchemeColors(Resource.Color.accent); progress = view.FindViewById <ProgressBar>(Resource.Id.progressbar_loading); progress.Visibility = ViewStates.Gone; return(view); }
public async override void OnStart() { base.OnStart(); if (ViewModel.Facilities.Count == 0) { MessageDialog messageDialog = new MessageDialog(); messageDialog.ShowLoading(); if (ap.IsOnline(Application.Context)) { await ViewModel.ExecuteFacilitiesCommand(userId); // await this.SqlLiteManager.SyncFacilitiesFromAPI(ViewModel.Facilities); } else { //await this.SqlLiteManager.GetLocalFacilities(userId); } if (ViewModel.Facilities.Count == 0) { messageDialog.SendMessage("There are no facilities that are assinged to this profile.", "No Facilities Found"); } recyclerView.SetAdapter(adapter = new BrowseFacilitiesAdapter(Activity, ViewModel, userId)); messageDialog.HideLoading(); } refresher.Refresh += Refresher_Refresh; adapter.ItemClick += Adapter_ItemClick; }
async void Refresher_Refresh(object sender, EventArgs e) { await ViewModel.ExecuteFacilitiesCommand(userId); recyclerView.SetAdapter(adapter = new BrowseFacilitiesAdapter(Activity, ViewModel, userId)); refresher.Refreshing = false; refresher.Refresh += Refresher_Refresh; adapter.ItemClick += Adapter_ItemClick; }