public async Task <DerpImage> GetDerpImage(string id)
        {
            string orl      = "https://derpibooru.org/api/v1/json/";
            string url      = $"{orl}/images/:{id}";
            var    response = await _client.GetAsync(url);

            if (response.StatusCode != HttpStatusCode.NotFound)
            {
                var content = await response.Content.ReadAsStringAsync();

                try
                {
                    var img = JsonConvert.DeserializeObject <DerpImageCpt>(content);
                    if (img != null)
                    {
                        var derpimg = new DerpImage(img);
                        return(derpimg);
                    }
                }
                catch
                {
                }
            }
            return(null);
        }
 public async Task DeleteDerpImageAsync(DerpImage image)
 {
     if (image == null)
     {
         return;
     }
     await GetConnection().DeleteAsync(image);
 }
        public async Task DeleteInfoAsync(string workid)
        {
            DerpImage image = await GetConnection().Table <DerpImage>().Where(i => i.Id == workid).FirstOrDefaultAsync();

            if (image != null)
            {
                await GetConnection().DeleteAsync(image);
            }
        }
 public async Task InsertDerpImageAsync(DerpImage image)
 {
     if (image == null)
     {
         return;
     }
     (await GetDerpImagesAsync()).Add(image);
     await DeleteDerpImageAsync(image);
     await GetConnection().InsertAsync(image);
 }
 public async Task UpdateImageAsync(DerpImage tag)
 {
     using (var releaser = await myLock.LockAsync())
     {
         if (tag != _derpImage.Find(i => i.Id == tag.Id))
         {
             int i = _derpImage.FindIndex(j => j.Id == tag.Id);
             _derpImage[i] = tag;
         }
         await GetConnection().UpdateAsync(tag);
     }
 }
 public ImagePage(DerpImage image, ImageSource loadingimage)
 {
     InitializeComponent();
     this.image = image;
     if (image.Width < image.Height)
     {
         imageStack.Orientation = StackOrientation.Vertical;
     }
     else
     {
         imageStack.Orientation = StackOrientation.Horizontal;
     }
     imageView.LoadingPlaceholder = loadingimage;
     imageView.Source             = image.ImageUrl;
     BindingContext = this;
     textView.Text  = image.Discription == null || image.Discription.Length == 0 ? "No Description" : image.Discription;
 }
        public async Task <List <DerpImage> > GetDerpFavoriteImages(string userkey)
        {
            List <DerpImage> res = new List <DerpImage>();
            string           orl = "https://derpibooru.org/search.json";
            string           url = $"{orl}?q=my:faves&key={userkey}";
            var response         = await _client.GetAsync(url);

            if (response.StatusCode != HttpStatusCode.NotFound)
            {
                var content = await response.Content.ReadAsStringAsync();

                foreach (DerpImageCpt img in JsonConvert.DeserializeObject <DerpList>(content).Images)
                {
                    var myimg = new DerpImage(img);
                    res.Add(myimg);
                }
            }
            return(res);
        }
        public async Task <List <DerpImage> > GetSearchImage(List <DerpImage> myList, List <CtFileItem> downloadedList, string userkey, string key, int index, DerpSortBy sf, DerpSortOrder sd)
        {
            List <DerpImage> res = new List <DerpImage>();

            try
            {
                string orl      = "https://derpibooru.org/api/v1/json/";
                string url      = $"{orl}search/images?key={userkey}&per_page=50&q={key.Replace(' ', '+').ToLower()}&page={index}&sf={sortbyfieldName[(int)sf]}&sd={sortbyorder[(int)sd]}";
                var    response = await _client.GetAsync(url);

                if (response.StatusCode == HttpStatusCode.NotFound)
                {
                    return(null);
                }

                var content = await response.Content.ReadAsStringAsync();

                var imgs = JsonConvert.DeserializeObject <DerpList>(content).Images;

                foreach (DerpImageCpt img in imgs)
                {
                    DerpImage myimg = new DerpImage(img);
                    if (myList.Exists(i => i.Id == img.Id))
                    {
                        myimg.IsFavorite = true;
                    }
                    if (downloadedList != null && downloadedList.Exists(i => i.Name == img.Id || i.Name.StartsWith(img.Id + "__")))
                    {
                        myimg.IsDownloaded = true;
                    }
                    res.Add(myimg);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(res);
        }
Exemple #9
0
 public async Task DeleteFromMyImageListAsync(DerpImage img)
 {
     MyImages.Remove(img);
     await DerpImageDb.DeleteDerpImageAsync(img);
 }
Exemple #10
0
 public async Task AddToMyImageListAsync(DerpImage img)
 {
     MyImages.Insert(0, img);
     await DerpImageDb.InsertDerpImageAsync(img);
 }