public static void DeleteInstance()
 {
     if (instance != null)
     {
         instance = null;
     }
 }
        public CustomCameraPage()
        {
            InitializeComponent();
            this.BindingContext = this;
            this.IsBusy         = false;

            MessagingCenter.Subscribe <CustomCameraPage>(this, "StartLoading", async(sender) =>
            {
                this.IsBusy = true;
            });

            MessagingCenter.Subscribe <CustomCameraPage>(this, "StopLoading", async(sender) =>
            {
                this.IsBusy = false;
            });

            MessagingCenter.Subscribe <CustomCameraPage, List <Species> >(this, "StreamSend", async(sender, arg) =>
            {
                //List<Species> speciesList = await CameraHelper.CommonOperationCameraLibPictures(arg);

                IdentifyListPage identifyListPage = new IdentifyListPage();

                //await DisplayAlert(speciesList.Count.ToString(), "NULL", "KKKKKKKKKK");
                if (arg.Any())
                {
                    identifyListPage.Content = new IdentifyListView(arg);
                }

                this.IsBusy = false;

                await Navigation.PushAsync(identifyListPage);
            });
        }
        public static IdentifyListPage getInstance()
        {
            if (instance == null)
            {
                instance = new IdentifyListPage();
            }

            return(instance);
        }
        private async void CommonOperationCameraLibPictures(Stream stream)
        {
            if (stream != null)
            {
                activityIndicator.IsRunning = true;
                //loadingIndicator = true;
                // Photo.Source = ImageSource.FromStream(() => stream);
                byte[] m_Bytes      = ReadToEnd(stream);
                string AIreturnData = await MakePredictionRequest(m_Bytes);

                // loadingIndicator = false;// first step, contact to AI

                if (AIreturnData != null)
                {
                    //  loadingIndicator = true;
                    string[] threeSpecies = new string[6];
                    threeSpecies = getDetailsFromAIreturn(AIreturnData);//get the top 3 possible results

                    AzureDataService azureDataService = new AzureDataService();
                    List <Species>   speciesList      = new List <Species>();

                    try
                    {
                        string name1 = threeSpecies[0];
                        IEnumerable <Species> iEnumerableSpecies1 = await azureDataService.GetSpeciesAsync(name1);

                        Species species1 = iEnumerableSpecies1.First();
                        species1.similarity = System.Convert.ToDouble(threeSpecies[1].Substring(0, 6));//keep it to the fourth decimal place
                        speciesList.Add(species1);

                        string name2 = threeSpecies[2];
                        IEnumerable <Species> iEnumerableSpecies2 = await azureDataService.GetSpeciesAsync(name2);

                        Species species2 = iEnumerableSpecies2.First();
                        species2.similarity = System.Convert.ToDouble(threeSpecies[3].Substring(0, 6));
                        speciesList.Add(species2);

                        string name3 = threeSpecies[4];
                        IEnumerable <Species> iEnumerableSpecies3 = await azureDataService.GetSpeciesAsync(name3);

                        Species species3 = iEnumerableSpecies3.First();
                        species3.similarity = System.Convert.ToDouble(threeSpecies[5].Substring(0, 6));
                        speciesList.Add(species3);
                    }
                    catch (Exception exp)
                    {
                        activityIndicator.IsRunning = false;
                        Debug.WriteLine(@"Sync error: {0}", exp.Message);
                    }
                    activityIndicator.IsRunning = false;
                    //relativeLayout.Children.Remove(relativeLayoutSubset);//remove google map
                    //relativeLayout.Children.Add(new IdentifyListView(speciesList));
                    //relativeLayout.Children.Add(new IdentifyListView(speciesList), Constraint.RelativeToParent((parent) => { return parent.X; }), Constraint.RelativeToParent((parent) => { return parent.Height; }));
                    //relativeLayout.Children.Clear();

                    IdentifyListPage identifyListPage = new IdentifyListPage();
                    Navigation.PushAsync(identifyListPage);

                    identifyListPage.Content = new IdentifyListView(speciesList);

                    //relativeLayout.Children.Add(identifyListView, Constraint.RelativeToParent((parent) => { return parent.X; }),
                    //                                                       Constraint.RelativeToParent((parent) => { return parent.Y; }),
                    //                                                       Constraint.RelativeToParent((parent) => { return parent.Width; }),
                    //                                                       Constraint.RelativeToParent((parent) => { return parent.Height; }));
                    //relativeLayout.Children.Insert(1,new IdentifyListView(speciesList));
                }
                else
                {
                    await DisplayAlert("AI Return Results is ", "NULL", "!!!");
                }
            }
            else
            {
                await DisplayAlert("Photos Stream is ", "NULL", "!!!");
            }
        }