protected override void OnCreate(Bundle savedInstanceState) { try { base.OnCreate(savedInstanceState); IMethods.IApp.FullScreenApp(this); var view = MyContextWrapper.GetContentView(this, Settings.Lang, Resource.Layout.Albums_Layout); if (view != null) { SetContentView(view); } else { SetContentView(Resource.Layout.Albums_Layout); } var data = Intent.GetStringExtra("UserId") ?? "Data not available"; if (data != "Data not available" && !string.IsNullOrEmpty(data)) { S_UserId = data; } var ToolBar = FindViewById <Toolbar>(Resource.Id.toolbar); if (ToolBar != null) { if (S_UserId == UserDetails.User_id) { ToolBar.Title = GetText(Resource.String.Lbl_MyImages); } else { ToolBar.Title = GetText(Resource.String.Lbl_YourImages); } SetSupportActionBar(ToolBar); SupportActionBar.SetDisplayShowCustomEnabled(true); SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetHomeButtonEnabled(true); SupportActionBar.SetDisplayShowHomeEnabled(true); } ImagesRecylerView = (RecyclerView)FindViewById(Resource.Id.RecylerImages); swipeRefreshLayout = FindViewById <SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout); swipeRefreshLayout.SetColorSchemeResources(Android.Resource.Color.HoloBlueLight, Android.Resource.Color.HoloGreenLight, Android.Resource.Color.HoloOrangeLight, Android.Resource.Color.HoloRedLight); swipeRefreshLayout.Refreshing = true; swipeRefreshLayout.Enabled = true; photos_Empty = FindViewById <LinearLayout>(Resource.Id.Albums_LinerEmpty); Icon_photos = FindViewById <TextView>(Resource.Id.Albums_icon); IMethods.Set_TextViewIcon("2", Icon_photos, "\uf03e"); ImagesRecylerView.Visibility = ViewStates.Visible; photos_Empty.Visibility = ViewStates.Gone; photosAdapter = new PhotosAdapter(this); // Check if we're running on Android 5.0 or higher if ((int)Build.VERSION.SdkInt < 23) { mLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.Vertical); ImagesRecylerView.SetLayoutManager(mLayoutManager); } else { mLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.Vertical); ImagesRecylerView.SetLayoutManager(mLayoutManager); } ImagesRecylerView.AddItemDecoration(new GridSpacingItemDecoration(2, 3, true)); ImagesRecylerView.SetAdapter(photosAdapter); ImagesRecylerView.Visibility = ViewStates.Visible; Get_Data_local(); } catch (Exception e) { Crashes.TrackError(e); } }
//Get Photo API public async void Get_AlbumUser_Api(string offset = "") { try { if (!IMethods.CheckConnectivity()) { RunOnUiThread(() => { swipeRefreshLayout.Refreshing = false; }); Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short) .Show(); ImagesRecylerView.Visibility = ViewStates.Visible; photos_Empty.Visibility = ViewStates.Gone; } else { var(Api_status, Respond) = await Client.Album.Get_User_Albums(S_UserId, "35", offset); if (Api_status == 200) { if (Respond is Get_User_Albums_Object result) { RunOnUiThread(() => { if (result.albums.Count <= 0) { if (swipeRefreshLayout != null) { swipeRefreshLayout.Refreshing = false; } } else if (result.albums.Count > 0) { //Bring new groups var listNew = result.albums.Where(c => !photosAdapter.mMyAlbumsList.Select(fc => fc.group_id).Contains(c.group_id)) .ToList(); if (listNew.Count > 0) { //Results differ Classes.AddRange(photosAdapter.mMyAlbumsList, listNew); photosAdapter.BindEnd(); } else { photosAdapter.mMyAlbumsList = new ObservableCollection <Get_User_Albums_Object.Album>(result.albums); photosAdapter.BindEnd(); } } }); } } 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 (photosAdapter.mMyAlbumsList.Count > 0) { ImagesRecylerView.Visibility = ViewStates.Visible; photos_Empty.Visibility = ViewStates.Gone; } else { ImagesRecylerView.Visibility = ViewStates.Gone; photos_Empty.Visibility = ViewStates.Visible; } swipeRefreshLayout.Refreshing = false; //Set Event Scroll if (OnMainScrolEvent == null) { var xamarinRecyclerViewOnScrollListener = new XamarinRecyclerViewOnScrollListener(mLayoutManager, swipeRefreshLayout); OnMainScrolEvent = xamarinRecyclerViewOnScrollListener; OnMainScrolEvent.LoadMoreEvent += MyAlbums_OnScroll_OnLoadMoreEvent; ImagesRecylerView.AddOnScrollListener(OnMainScrolEvent); ImagesRecylerView.AddOnScrollListener(new ScrollDownDetector()); } else { OnMainScrolEvent.IsLoading = false; } }); } catch (Exception e) { Crashes.TrackError(e); Get_AlbumUser_Api(offset); } }