private void SetRecyclerViewAdapters() { try { MAdapter = new ArticlesAdapter(Activity, this) { ArticlesList = new ObservableCollection <ArticleObject>() }; LayoutManager = new LinearLayoutManager(Context); MRecycler.SetLayoutManager(LayoutManager); MRecycler.HasFixedSize = true; MRecycler.SetItemViewCacheSize(10); MRecycler.GetLayoutManager().ItemPrefetchEnabled = true; var sizeProvider = new FixedPreloadSizeProvider(10, 10); var preLoader = new RecyclerViewPreloader <ArticleObject>(Activity, MAdapter, sizeProvider, 10); MRecycler.AddOnScrollListener(preLoader); MRecycler.SetAdapter(MAdapter); RecyclerViewOnScrollListener xamarinRecyclerViewOnScrollListener = new RecyclerViewOnScrollListener(LayoutManager); MainScrollEvent = xamarinRecyclerViewOnScrollListener; MainScrollEvent.LoadMoreEvent += MainScrollEventOnLoadMoreEvent; MRecycler.AddOnScrollListener(xamarinRecyclerViewOnScrollListener); MainScrollEvent.IsLoading = false; } catch (Exception e) { Console.WriteLine(e); } }
public override void OnViewCreated(View view, Bundle savedInstanceState) { base.OnViewCreated(view, savedInstanceState); swipeRefreshLayout = view.FindViewById <SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout); swipeRefreshLayout.SetColorSchemeResources(Resource.Color.primary); swipeRefreshLayout.SetOnRefreshListener(this); recyclerView = view.FindViewById <RecyclerView>(Resource.Id.recyclerView); var manager = new LinearLayoutManager(this.Activity); recyclerView.SetLayoutManager(manager); adapter = new ArticlesAdapter(); adapter.SetOnLoadMoreListener(this); recyclerView.SetAdapter(adapter); notDataView = this.Activity.LayoutInflater.Inflate(Resource.Layout.empty_view, (ViewGroup)recyclerView.Parent, false); notDataView.Click += delegate(object sender, EventArgs e) { OnRefresh(); }; errorView = this.Activity.LayoutInflater.Inflate(Resource.Layout.error_view, (ViewGroup)recyclerView.Parent, false); errorView.Click += delegate(object sender, EventArgs e) { OnRefresh(); }; recyclerView.Post(async() => { await articlesPresenter.GetClientArticles(position); }); }
protected async override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); blogApp = Intent.GetStringExtra("blogApp"); blogPresenter = new BlogPresenter(this); handler = new Handler(); coordinatorLayout = FindViewById <CoordinatorLayout>(Resource.Id.coordinatorLayout); appBarLayout = FindViewById <AppBarLayout>(Resource.Id.appbar); linearLayout = FindViewById <LinearLayout>(Resource.Id.linearLayout); toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); toolbar.SetNavigationIcon(Resource.Drawable.back_24dp); SetSupportActionBar(toolbar); SupportActionBar.SetDisplayHomeAsUpEnabled(true); toolbar.SetNavigationOnClickListener(this); StatusBarCompat.SetCollapsingToolbar(this, coordinatorLayout, appBarLayout, linearLayout, toolbar); imgAvatar = FindViewById <ImageView>(Resource.Id.avatar); txtTitle = FindViewById <TextView>(Resource.Id.txtTitle); txtSubTitle = FindViewById <TextView>(Resource.Id.txtSubTitle); user = await SQLiteUtils.Instance().QueryUser(); swipeRefreshLayout = FindViewById <SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout); swipeRefreshLayout.SetColorSchemeResources(Resource.Color.primary); swipeRefreshLayout.SetOnRefreshListener(this); recyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView); var manager = new LinearLayoutManager(this); recyclerView.SetLayoutManager(manager); adapter = new ArticlesAdapter(); adapter.SetOnLoadMoreListener(this); recyclerView.SetAdapter(adapter); notDataView = this.LayoutInflater.Inflate(Resource.Layout.empty_view, (ViewGroup)recyclerView.Parent, false); notDataView.Click += delegate(object sender, EventArgs e) { OnRefresh(); }; errorView = this.LayoutInflater.Inflate(Resource.Layout.error_view, (ViewGroup)recyclerView.Parent, false); errorView.Click += delegate(object sender, EventArgs e) { OnRefresh(); }; recyclerView.Post(async() => { await blogPresenter.GetClientBlog(blogApp); OnRefresh(); }); }
//Event Refresh Data Page private void SwipeRefreshLayoutOnRefresh(object sender, EventArgs e) { try { ArticlesAdapter.Clear(); Get_Articles_Api(); } catch (Exception exception) { Crashes.TrackError(exception); } }
public override void OnViewCreated(View view, Bundle savedInstanceState) { base.OnViewCreated(view, savedInstanceState); swipeRefreshLayout = view.FindViewById <SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout); swipeRefreshLayout.SetColorSchemeResources(Resource.Color.primary); swipeRefreshLayout.SetOnRefreshListener(this); recyclerView = view.FindViewById <RecyclerView>(Resource.Id.recyclerView); recyclerView.SetLayoutManager(new LinearLayoutManager(this.Activity)); adapter = new ArticlesAdapter(); adapter.OnLoadMoreListener = this; recyclerView.SetAdapter(adapter); recyclerView.Post(async() => { await articlesPresenter.GetClientArticles(); }); }
public void Get_Data_local() { try { if (ArticlesAdapter != null) { if (Classes.ListChachedData_Article.Count > 0) { ArticlesAdapter.ArticlesList = Classes.ListChachedData_Article; ArticlesAdapter.BindEnd(); } } Get_Articles_Api(); } catch (Exception e) { Crashes.TrackError(e); } }
private void DestroyBasic() { try { MAdView?.Destroy(); MAdapter = null; SwipeRefreshLayout = null; MRecycler = null; EmptyStateLayout = null; Inflated = null; MainScrollEvent = null; BtnFilter = null; CategoryId = null; UserId = null; MAdView = null; } catch (Exception e) { Console.WriteLine(e); } }
private void DestroyBasic() { try { MAdView?.Destroy(); MAdapter = null !; SwipeRefreshLayout = null !; MRecycler = null !; EmptyStateLayout = null !; Inflated = null !; MainScrollEvent = null !; BtnFilter = null !; CategoryId = null !; UserId = null !; MAdView = null !; } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
private void ArticlesAdapterOnItemClick(object sender, Articles_AdapterClickEventArgs adapterClickEvents) { try { var position = adapterClickEvents.Position; if (position >= 0) { var item = ArticlesAdapter.GetItem(position); if (item != null) { var intent = new Intent(this, typeof(HyberdPostViewer_Activity)); intent.PutExtra("Type", "Article"); intent.PutExtra("Id", item.url); intent.PutExtra("Title", item.title); StartActivity(intent); } } } catch (Exception e) { Crashes.TrackError(e); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.ArticlesList); //get all groups from database //using (var connection = new SQLiteConnection(System.IO.Path.Combine(GlobalVariables.databasePath, "MobileSell.db"))) //{ // var allGroups = connection.Table<Group>(); // groups.AddRange(allGroups); //} var allGroups = DatabaseRequest.GetAllFromTable <Group>(); groups.AddRange(allGroups); //fill in spinner with items spinner = FindViewById <MaterialSpinner>(Resource.Id.spinner); adapter = new ArrayAdapter <Group>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, groups); adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); spinner.Adapter = adapter; spinner.Background = Drawable.CreateFromXml(Resources, Resources.GetXml(Resource.Drawable.material_spinner_border)); //on activity start get all articles allArticles = DatabaseRequest.GetAllFromTable <Article>().Select(x => new ArticleViewModel { Id = x.Id, Group = x.Group, Name = x.Name, SellPrice = x.SellPrice, Quantity = x.Quantity }).ToList(); //create line between recyclerview items DividerItemDecoration itemDecoration = new DividerItemDecoration(this, DividerItemDecoration.Vertical); //pass all articles to the RecyclerView articlesRecyclerView = FindViewById <RecyclerView>(Resource.Id.articlesRecyclerView); articlesRecyclerView.AddItemDecoration(itemDecoration); articlesLayoutManager = new LinearLayoutManager(this); articlesRecyclerView.SetLayoutManager(articlesLayoutManager); articlesAdapter = new ArticlesAdapter(allArticles); articlesAdapter.ItemClick += OnItemClick; articlesRecyclerView.SetAdapter(articlesAdapter); //get all articles from selected group spinner.ItemSelected += (s, e) => { if (e.Position != -1) { var groupId = groups.ElementAt(e.Position).Id; //get all articles from group which is currently selected List <ArticleViewModel> articlesFromGroup = allArticles.Where(x => x.Group == groupId).ToList(); //fill in the RecyclerView with articlesFromGroup; articlesAdapter = new ArticlesAdapter(articlesFromGroup); articlesAdapter.ItemClick += OnItemClick; articlesRecyclerView.SetAdapter(articlesAdapter); } else { //if no group is selected display all articles on screen articlesLayoutManager = new LinearLayoutManager(this); articlesRecyclerView.SetLayoutManager(articlesLayoutManager); articlesAdapter = new ArticlesAdapter(allArticles); articlesAdapter.ItemClick += OnItemClick; articlesRecyclerView.SetAdapter(articlesAdapter); } }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Inventory); //get all groups from database using (var connection = new SQLiteConnection(System.IO.Path.Combine(GlobalVariables.databasePath, "MobileSell.db"))) { var allGroups = connection.Table <Group>(); groups.AddRange(allGroups); } //fill in spinner with items spinner = FindViewById <MaterialSpinner>(Resource.Id.spinner); adapter = new ArrayAdapter <Group>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, groups); adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); spinner.Adapter = adapter; spinner.Background = Drawable.CreateFromXml(Resources, Resources.GetXml(Resource.Drawable.material_spinner_border)); //on activity start get all articles allArticles = DatabaseRequest.GetAllFromTable <Article>().Select(x => new ArticleViewModel { Id = x.Id, Group = x.Group, Name = x.Name, SellPrice = x.SellPrice, Quantity = x.Quantity }).ToList(); //pass all articles to the RecyclerView articlesRecyclerView = FindViewById <RecyclerView>(Resource.Id.articlesRecyclerView); articlesLayoutManager = new LinearLayoutManager(this); articlesRecyclerView.SetLayoutManager(articlesLayoutManager); articlesAdapter = new ArticlesAdapter(allArticles); articlesRecyclerView.SetAdapter(articlesAdapter); TextView totalValue = FindViewById <TextView>(Resource.Id.totalValue); //calculate total sum of all articles in RecyclerView and set it to totalValue TextView decimal totalSumAllArticles = articlesAdapter.listOfArticles.Sum(x => x.Sum); totalValue.Text = String.Format("{0:0.00}", totalSumAllArticles); //get all articles from selected group spinner.ItemSelected += (s, e) => { if (e.Position != -1) { var groupId = groups.ElementAt(e.Position).Id; //get all articles from group which is currently selected List <ArticleViewModel> articlesFromGroup = allArticles.Where(x => x.Group == groupId).ToList(); //fill in the RecyclerView with articlesFromGroup //articlesLayoutManager = new LinearLayoutManager(this); //articlesRecyclerView.SetLayoutManager(articlesLayoutManager); articlesAdapter = new ArticlesAdapter(articlesFromGroup); articlesRecyclerView.SetAdapter(articlesAdapter); //calculate total value of articles //decimal totalSum = 0; //foreach(ArticleViewModel article in articlesFromGroup) //{ // totalSum += article.Sum; //} //calculate total sum of all articles in RecyclerView and set it to totalValue TextView totalSumAllArticles = articlesAdapter.listOfArticles.Sum(x => x.Sum); totalValue.Text = String.Format("{0:0.00}", totalSumAllArticles); } else { //if no group is selected display all articles on screen //articlesLayoutManager = new LinearLayoutManager(this); //articlesRecyclerView.SetLayoutManager(articlesLayoutManager); articlesAdapter = new ArticlesAdapter(allArticles); articlesRecyclerView.SetAdapter(articlesAdapter); //calculate total sum of all articles in RecyclerView and set it to totalValue TextView totalSumAllArticles = articlesAdapter.listOfArticles.Sum(x => x.Sum); totalValue.Text = String.Format("{0:0.00}", totalSumAllArticles); } }; Button btnPrint = FindViewById <Button>(Resource.Id.btnPrint); btnPrint.Click += delegate { StartActivity(typeof(PrintingActivity)); }; }
//Get Articles API public async void Get_Articles_Api(string offset = "") { try { if (!IMethods.CheckConnectivity()) { RunOnUiThread(() => { swipeRefreshLayout.Refreshing = false; }); Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short) .Show(); } else { var(Api_status, Respond) = await Client.Article.Get_Articles("25", offset); if (Api_status == 200) { if (Respond is Get_Users_Articles_Object result) { RunOnUiThread(() => { if (result.articles.Length <= 0) { if (swipeRefreshLayout != null) { swipeRefreshLayout.Refreshing = false; } } else if (result.articles.Length > 0) { if (ArticlesAdapter.ArticlesList.Count <= 0) { ArticlesAdapter.ArticlesList = new ObservableCollection <Get_Users_Articles_Object.Article>( result.articles); ArticlesAdapter.BindEnd(); } else { //Bring new item var listnew = result.articles?.Where(c => !ArticlesAdapter.ArticlesList.Select(fc => fc.id).Contains(c.id)).ToList(); if (listnew.Count > 0) { var lastCountItem = ArticlesAdapter.ItemCount; //Results differ Classes.AddRange(ArticlesAdapter.ArticlesList, listnew); ArticlesAdapter.NotifyItemRangeInserted(lastCountItem, listnew.Count); } if (swipeRefreshLayout.Refreshing) { swipeRefreshLayout.Refreshing = false; } } } }); } } else if (Api_status == 400) { if (Respond is Error_Object error) { var errortext = error._errors.Error_text; //Toast.MakeText(this, errortext, ToastLength.Short).Show(); if (errortext.Contains("Invalid or expired access_token")) { API_Request.Logout(this); } } } else if (Api_status == 404) { var error = Respond.ToString(); //Toast.MakeText(this, error, ToastLength.Short).Show(); } //Show Empty Page //=========================================== RunOnUiThread(() => { if (ArticlesAdapter.ArticlesList.Count > 0) { Articls_Empty.Visibility = ViewStates.Gone; ArticlsRecylerView.Visibility = ViewStates.Visible; } else { Articls_Empty.Visibility = ViewStates.Visible; ArticlsRecylerView.Visibility = ViewStates.Gone; } swipeRefreshLayout.Refreshing = false; //Set Event Scroll if (OnMainScrolEvent == null) { var xamarinRecyclerViewOnScrollListener = new XamarinRecyclerViewOnScrollListener(mLayoutManager, swipeRefreshLayout); OnMainScrolEvent = xamarinRecyclerViewOnScrollListener; OnMainScrolEvent.LoadMoreEvent += Article_OnScroll_OnLoadMoreEvent; ArticlsRecylerView.AddOnScrollListener(OnMainScrolEvent); ArticlsRecylerView.AddOnScrollListener(new ScrollDownDetector()); } else { OnMainScrolEvent.IsLoading = false; } }); } } catch (Exception e) { Crashes.TrackError(e); Get_Articles_Api(offset); } }