protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            string token = Intent.GetStringExtra("UserToken") ?? "False";

            Console.WriteLine(token);

            var InstagramClient = new InstagramClient(token);

            MediasResponse imageResponse = new MediasResponse();

            imageResponse = await InstagramClient.GetMyUserAsync();

            //Console.WriteLine("this");
        }
Beispiel #2
0
        /// <summary>
        /// Загрузка содержимого url и десериализация в JSON
        /// </summary>
        private async Task <MediasResponse> DownloadMediaResponseAsync(string url)
        {
            MediasResponse res = new MediasResponse();

            using (var client = new WebClient())
            {
                try
                {
                    var result = await client.DownloadDataTaskAsync(url);

                    var response = System.Text.Encoding.Default.GetString(result);

                    res = JsonConvert.DeserializeObject <MediasResponse>(response);
                }
                catch
                {}
            }

            return(res);
        }
Beispiel #3
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            if (IsAuthenticated)
            {
                Content = ActivityIndicator;
                try {
                    MediasResponse imageResponse = new MediasResponse();
                    switch (_FollowType)
                    {
                    case ImageListType.MyFeed:
                        imageResponse = await App.InstagramClient.GetMyFeedAsync();

                        break;

                    case ImageListType.Popular:
                        // fetch my followers
                        imageResponse = await App.InstagramClient.GetPopularAsync();

                        break;

                    case ImageListType.Liked:
                        // fetch who I'm following
                        imageResponse = await App.InstagramClient.GetMyLikedAsync();

                        break;
                    }
                    PopulateImageItems(imageResponse.Data);
                } catch (Exception) {
                    Content = null;
                }
            }
            else
            {
                Content = null;
            }
        }
Beispiel #4
0
        private MediasResponse DownloadMediaResponse(string url)
        {
            MediasResponse res = new MediasResponse();

            using (var client = new WebClient())
            {
                try
                {
                    //****************************************************
                    //********* убрать при комп-ии на сервере ************
                    //****************************************************
                    //client.Proxy = new WebProxy("192.168.116.99", 8080);
                    var result   = client.DownloadData(url);
                    var response = System.Text.Encoding.Default.GetString(result);

                    res = JsonConvert.DeserializeObject <MediasResponse>(response);
                }
                catch
                { }
            }

            return(res);
        }
        protected async Task <IEnumerable <MediaModel> > FetchImagesAndConvertToASCII(MediasResponse instaResp)
        {
            var imageToAsciiConverter = new ImageToAsciiConverter();
            var hhtpClient            = new HttpClient();

            var list = new List <MediaModel>();

            foreach (var media in instaResp.Data)
            {
                var stream = await hhtpClient.GetStreamAsync(media.Images.StandardResolution.Url);

                var instaMedia = new MediaModel
                {
                    Media = media,
                    Data  = imageToAsciiConverter.GetArrayImage(new Bitmap(stream), 100)
                };
                list.Add(instaMedia);
            }
            return(list);
        }
Beispiel #6
0
        protected async override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            RequestWindowFeature(WindowFeatures.NoTitle);
            Weather weather = await Core.GetWeather("51.0144", "114.1288");

            tagName = weather.Visibility.ToLower();
            token   = Intent.GetStringExtra("UserToken") ?? "";
            if (token != "")
            {
                InstagramClient client = new InstagramClient(token);
                MediasResponse  media  = await client.GetRecentMediaByTagName(tagName);

                var datas = media.Data;
                if (datas.Count > 0)
                {
                    Random rand        = new Random();
                    int    index       = rand.Next(0, media.Data.Count);
                    Bitmap imageBitmap = null;
                    String replacement = "p1080x1080";
                    Regex  rgx         = new Regex(@"(s|p)\d\d\dx\d\d\d");
                    String url         = media.Data.ElementAt <Media>(index).Images.StandardResolution.Url.ToString();
                    url = rgx.Replace(url, replacement);
                    using (var webClient = new WebClient())
                    {
                        var imageBytes = webClient.DownloadData(url);
                        if (imageBytes != null && imageBytes.Length > 0)
                        {
                            imageBitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
                        }
                    }

                    SetContentView(Resource.Layout.weatherAPI);
                    ImageView image = FindViewById <ImageView>(Resource.Id.imgAbsolute);
                    image.SetImageBitmap(imageBitmap);
                    image.SetScaleType(ScaleType.CenterCrop);
                    runWeather("51.0114", "114.1288");
                    getGreeting();
                }
                ImageButton demo = FindViewById <ImageButton>(Resource.Id.demoMenu);
                demo.Click += delegate
                {
                    Intent intent = new Intent(this.ApplicationContext, typeof(DemoMenuActivity));
                    intent.SetFlags(ActivityFlags.NewTask);
                    StartActivity(intent);
                };
            }
            else
            {
                //TODO:pull image from database for criteria

                SetContentView(Resource.Layout.weatherAPI);
                ImageView image = FindViewById <ImageView>(Resource.Id.imgAbsolute);
                image.SetImageResource(Resource.Drawable.main);
                image.SetScaleType(ScaleType.CenterCrop);
                runWeather("51.0114", "114.1288");
            }



            // Set our view from the "main" layout resource
            //SetContentView(Resource.Layout.weatherAPI);


            // Get our button from the layout resource,
            // and attach an event to it
            //Button button = FindViewById<Button>(Resource.Id.weatherBtn);

            //button.Click += Button_Click;
        }