Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

its taking time to load the image

$
0
0

this is my code

 private async void LoadStusentOrStaffPhoto()
    {
        try
        {
            int initalCount = 0;
            string studentsIDS = "";
            for (int i = 0; i < searchResults.Count; i++)
            {
                studentsIDS += searchResults[i].Id.ToString();
                initalCount++;
                if (initalCount > 9)
                {

                    GetStudentOrStaffPhoto(type, studentsIDS);
                    initalCount = 0;
                    studentsIDS = "";

                }
                else
                    studentsIDS += ",";
            }
        }
        catch (Exception ex)
        {
            CommonHelper.LogException(ex, this);
        }

    }


    async Task GetStudentOrStaffPhoto(string type, string studentStaffId)
    {
        try
        {
            if (Reachability.IsInternetReachable())
            {
                // Create Singleton instance of the account factory class
                SearchFactory searchFactory = SearchFactory.GetInstance;
                // Create appropriate account facade instance 
                var searchFacade = searchFactory.CreateSearchInstance(Entity.Common.SearchTypeEnum.RegularSearch);
                var schlCode = NSUserDefaults.StandardUserDefaults.StringForKey(AppConstants.LastSelSchoolCodeUDKey);

                var studentStaffPhotoResponse = await searchFacade.GetStudentOrStaffPhoto(schlCode, type, studentStaffId);
                if (studentStaffPhotoResponse.IsResponseSuccess)
                {
                    foreach (var item in studentStaffPhotoResponse.Response)
                    {
                        if (item.Image != null)
                        {
                            byte[] sPhoto = Convert.FromBase64String(item.Image);
                            var studentItem = searchResults.FindIndex(x => x.Id == item.Id);
                            if (studentItem != 0)
                            {
                                searchResults[studentItem].Photo = sPhoto;
                            }
                        }
                    }
                }
                else if (studentStaffPhotoResponse.IsUnauthorized)
                {
                    InvokeOnMainThread(() =>
                    {
                        CommonHelper.ShowUnauthorizedAlert(this);
                    });
                }
                else
                {
                    InvokeOnMainThread(() =>
                    {
                        var alert = UIAlertController.Create(NSBundle.MainBundle.GetLocalizedString(AppConstants.NoInternetTitleLKey, ""),
                                            NSBundle.MainBundle.GetLocalizedString(AppConstants.NoInternetMsgLKey, ""),
                                                    UIAlertControllerStyle.Alert);
                        alert.AddAction(UIAlertAction.Create(NSBundle.MainBundle.GetLocalizedString(AppConstants.OKLKey, ""),
                                         UIAlertActionStyle.Cancel, (obj) =>
                                         {
                                             NavigationController.PopViewController(true);
                                         }));
                        PresentViewController(alert, true, null);
                    });
                }
            }

            SearchResultTableView.TableHeaderView = GetTableHeader();
            SearchResultTableView.DataSource = this;
            SearchResultTableView.Delegate = this;
            SearchResultTableView.ReloadData();
            SearchResultTableView.BackgroundView = null;
        }
        catch (Exception ex)
        {
            CommonHelper.LogException(ex, this);
        }
    }

Viewing all articles
Browse latest Browse all 204402


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>