private async Task SwipeDown(AndroidConnector android)
        {
            await Task.Delay(250);

            await android.Swipe(1160, 860, 1160, -350, 1000);

            await Task.Delay(250);

            await android.Tap(530, 845); // against overlay

            await Task.Delay(500);
        }
        public async Task <List <ScanResultEquip> > ScanEquip(AndroidConnector android, ScanInfo scanInfo)
        {
            List <ScanResultEquip> result = new List <ScanResultEquip>();


            if (scanInfo.RealName.Contains("[1]"))
            {
                scanInfo.Slots = 1;
            }
            if (scanInfo.RealName.Contains("[2]"))
            {
                scanInfo.Slots = 2;
            }

            if (scanInfo.SearchName.Contains("["))
            {
                scanInfo.SearchName = scanInfo.SearchName.Substring(0, scanInfo.SearchName.IndexOf("[")).Trim();
            }
            scanInfo.Equip = true;

            Program.status.SetSubStatus("Opening search window");
            await CloseSearch(android);
            await ClickSearchButton(android);
            await ClickSearchBox(android);

            await android.Text(scanInfo.SearchName);

            await ClickSearchWindowSearchButton(android); //to close text input
            await ClickSearchWindowSearchButton(android);

            Program.status.SetSubStatus("Scanning search result");
            await android.Screenshot("searchresult.png");

            using (var image = Image.Load <Rgba32>("searchresult.png"))
                using (var cmp = Image.Load <Rgba32>("data/bigerror.png"))
                    if (ImageDistance(image.Clone(c => c.Crop(new Rectangle(650, 150, 700, 200))), cmp) < 100)
                    {
                        Program.Restart = true;
                        return(null);
                    }


            List <int> indices = FindSearchResult("searchresult.png", scanInfo);

            if (indices.Count == 1 && indices[0] == -1)
            {
                await android.Swipe(1100, 863, 1100, 355, 200);

                await Task.Delay(500);

                await android.Screenshot("searchresult.png");

                indices = FindSearchResult("searchresult.png", scanInfo);
            }

            await Task.Delay(500);

            if (indices.Count == 0)
            {
                //TODO: do something with item0.png - item9.png
                Program.status.SetSubStatus("- Error, could not find item");
                await CloseSearch(android);

                return(new List <ScanResultEquip>()
                {
                    ScanResult.BuildError <ScanResultEquip>(scanInfo)
                });
            }
            if (indices[0] != scanInfo.SearchIndex)
            {
                if (scanInfo.SearchIndex != -1)
                {
                    Program.log.Log(scanInfo.RealName, "Warning, search index not correct");
                }
                scanInfo.SearchIndex = indices[0];
            }


            for (int i = 0; i < indices.Count; i++)
            {
                await ClickSearchWindowIndex(android, indices[i]);

                await Task.Delay(2500);

                Program.status.SetSubStatus("Checking for sales");
                await android.Screenshot("shopitems.png");

                using (var image = Image.Load <Rgba32>("shopitems.png"))
                    image.Clone(ctx => ctx.Crop(new Rectangle(975, 505, 368, 64))).Save($"nosale.png");

                bool onSale = true;
                if (GetTextFromImage("nosale.png").ToLower().Contains("currently"))
                {
                    onSale = false;
                    Program.log.Log(scanInfo.RealName, "Currently not for sale");
                    if (i + 1 >= indices.Count)
                    {
                        return new List <ScanResultEquip>()
                               {
                                   new ScanResultEquip()
                                   {
                                       Found    = false,
                                       ScanInfo = scanInfo
                                   }
                               }
                    }
                    ;
                }

                if (onSale)
                {
                    var images  = new List <Image <Rgba32> >();
                    int subPage = 0;
                    while (!Program.CancelScan)
                    {
                        Program.log.Log(scanInfo.RealName, "Scanning page " + subPage);

                        int  foundResults = images.Count;
                        bool done         = await ScanPage(images, android, scanInfo, result);

                        if (foundResults == images.Count)
                        {
                            Program.log.Log(scanInfo.RealName, "No new items found in last sweep, done");
                            break;
                        }
                        if (subPage % 2 == 0)
                        {
                            await SwipeDown(android);
                        }
                        else
                        if (await NextPage(android))
                        {
                            break;
                        }

                        await android.Screenshot("shopitems.png");

                        subPage++;
                    }
                    Program.status.SetSubStatus("done scanning");

                    foreach (var img in images)
                    {
                        img.Dispose();
                    }


                    return(result);
                }
                //this should not happen
                scanInfo.Message = "";
                Console.WriteLine("Item does not match, or not found on exchange with multiple items, trying to rescan it");
                await CloseSearch(android);
                await ClickSearchButton(android);
                await ClickSearchBox(android);

                await android.Text(scanInfo.SearchName);
                await ClickSearchWindowSearchButton(android); //to close text input
                await ClickSearchWindowSearchButton(android);
            }

            return(null);
        }
        public async Task <ScanResultEquip> ParseResultWindowEquip(string fileName, ScanInfo scanInfo, AndroidConnector android)
        {
            ScanResultEquip exchangeInfo = new ScanResultEquip()
            {
                Found    = true,
                ScanInfo = scanInfo
            };

            using (var image = Image.Load <Rgba32>(fileName))
            {
                image.Clone(ctx => ctx.Crop(new Rectangle(996, 159, 549, 66))).Save($"itemname.png");
                string itemName = GetTextFromImage("itemname.png");
                if (itemName.ToLower() != scanInfo.RealName.ToLower())
                {
                    scanInfo.Message = $"Something is wrong, names do NOT match. Expected {scanInfo.RealName.ToLower()} but got {itemName.ToLower()}";
                    return(ScanResult.BuildError <ScanResultEquip>(scanInfo));
                }

                exchangeInfo.Price    = int.Parse(GetPriceEquip(image), CultureInfo.InvariantCulture);
                exchangeInfo.SnapTime = GetSnapTime(image);

                int i = 0;
                //scan for multiple items
                bool enchanted   = false;
                bool foundRefine = false;
                while (!Program.CancelScan)
                {
                    using (var image2 = Image.Load <Rgba32>(fileName))
                        image2.Clone(ctx => ctx.Crop(new Rectangle(383, 261, 553, 453))).Save($"enchant{i}.png");
                    string hasEnchant = GetTextFromImage($"enchant{i}.png");
                    Console.WriteLine($"- Text Read: \n\n{hasEnchant}\n\n");
                    if (hasEnchant.ToLower().Contains("refine ") && !foundRefine && !enchanted && hasEnchant.ToLower().IndexOf("refine ") != hasEnchant.ToLower().IndexOf("refine +6 effective"))
                    {
                        string refine = hasEnchant.ToLower();
                        refine = refine.Replace("\r\n", "\n");
                        while (refine.Contains("\n\n"))
                        {
                            refine = refine.Replace("\n\n", "\n");
                        }
                        refine = refine.Substring(refine.IndexOf("\nrefine ") + 8).Trim();
                        if (refine.IndexOf("\n") > 0)
                        {
                            refine = refine.Substring(0, refine.IndexOf("\n")).Trim();
                        }
                        Console.WriteLine(refine);
                        int refineLevel = 0;
                        if (refine.Contains("/"))
                        {
                            try
                            {
                                refineLevel = int.Parse(refine.Substring(0, refine.IndexOf("/")));
                                foundRefine = true;
                            }
                            catch (FormatException e)
                            {
                                scanInfo.Message = "Something is wrong, error parsing refine level: " + refine;
                                Console.WriteLine(e);
                                return(ScanResult.BuildError <ScanResultEquip>(scanInfo));
                            }
                        }
                        if (refine.Contains("atk+"))
                        {
                            int atk = int.Parse(refine.Substring(refine.IndexOf("atk+") + 4));
                            foundRefine = true;
                            //TODO: check if atk matches refineLevel
                        }
                        exchangeInfo.RefinementLevel = refineLevel;
                    }


                    if (hasEnchant.ToLower().Contains("enchanted"))
                    {
                        enchanted = true;
                    }
                    if (hasEnchant.ToLower().Contains("equipment upgrade"))
                    {
                        if (enchanted)
                        {
                            MemoryStream ms          = new MemoryStream();
                            var          jpegEncoder = new SixLabors.ImageSharp.Formats.Jpeg.JpegEncoder {
                                Quality = 10
                            };
                            using (var image2 = Image.Load <Rgba32>($"enchant{i}.png"))
                                image2.Clone(ctx => ctx.Resize(new ResizeOptions {
                                    Size = image2.Size() / 2
                                })).SaveAsJpeg(ms, jpegEncoder);

                            exchangeInfo.EnchantmentImage = System.Convert.ToBase64String(ms.GetBuffer());
                            if (!hasEnchant.ToLower().Contains("enchanted"))
                            {
                                Console.WriteLine("Scrolled too far");
                                exchangeInfo.Enchantments = new List <string>()
                                {
                                    "scrolled too far"
                                };
                                break;
                            }
                            hasEnchant = hasEnchant.ToLower();
                            hasEnchant = hasEnchant.Replace("\r\n", "\n");
                            while (hasEnchant.Contains("\n\n"))
                            {
                                hasEnchant = hasEnchant.Replace("\n\n", "\n");
                            }
                            hasEnchant = hasEnchant.Substring(hasEnchant.IndexOf("enchanted attribute:") + 20).Trim();
                            hasEnchant = hasEnchant.Substring(0, hasEnchant.IndexOf("equipment upgrade")).Trim();

                            hasEnchant = hasEnchant.Replace("mapr ", "maxhp ");
                            exchangeInfo.Enchantments = hasEnchant.Split("\n", 4).ToList();
                        }
                        break;
                    }
                    if (hasEnchant.ToLower().Contains("exchange price"))
                    {
                        Console.WriteLine("Scrolled wayyyyyy too far");
                        break;
                    }


                    await android.Swipe(555, 500, 555, 300, 500);

                    await Task.Delay(100);

                    await android.Tap(1500, 960);

                    await android.Screenshot(fileName);

                    i++;
                }
                exchangeInfo.Found = true;
            }
            return(exchangeInfo);
        }