예제 #1
0
        async public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            HasOptionsMenu = true;
            container      = TinyIoC.TinyIoCContainer.Current;
            //TODO: Add TinyIOC and move these to app start
            webService = container.Resolve <WlcWebService> ();
            var parser = new WlcHtmlParse();

            var prefs = Activity.GetSharedPreferences("wlcPrefs", FileCreationMode.Private);

            myStatsUrl = prefs.GetString("statsUrl", "");
            csrfToken  = prefs.GetString("csrfToken", "");
            var challengeProfile = prefs.GetString("challengeProfile", "");

            adapter = new StatsBarAdapter(this.Activity);

            fadeinAnimation  = AnimationUtils.LoadAnimation(this.Activity, Resource.Animation.abc_fade_in);
            fadeoutAnimation = AnimationUtils.LoadAnimation(this.Activity, Resource.Animation.abc_fade_out);

            // Get the data here
            try {
                profile = Newtonsoft.Json.JsonConvert.DeserializeObject <ChallengeProfile> (challengeProfile, new Newtonsoft.Json.JsonSerializerSettings()
                {
                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                });
                today = await webService.GetRecord(StoredCookies, "today.json", csrfToken);

                yesterday = await webService.GetRecord(StoredCookies, "yesterday.json", csrfToken);

                var contentStr = await webService.GetStats(StoredCookies, "/profiles/" + profile.id.ToString() + "/stats_calendar");

                myStats = parser.GetStats(contentStr);

                if (today != null)
                {
                    byte[] imageBytes = await webService.GetProfileImage(profile.user.photo);

                    // IBitmap is a type that provides basic image information such as dimensions
                    profileImage = await BitmapLoader.Current.Load(new MemoryStream(imageBytes), null /* Use original width */, null /* Use original height */);
                }

                ((StatsBarAdapter)adapter).Stats = myStats.OrderByDescending(x => x.StatDate).ToList();
                if (!Activity.IsFinishing)
                {
                    updateView();
                    if (loading != null)
                    {
                        loading.Visibility  = ViewStates.Gone;
                        listView.Visibility = ViewStates.Visible;
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }

            actionBarBackgroundDrawable = new Android.Graphics.Drawables.ColorDrawable(Android.Graphics.Color.MediumAquamarine);
            actionBarBackgroundDrawable.SetAlpha(0);
            Activity.ActionBar.SetBackgroundDrawable(actionBarBackgroundDrawable);
        }
        async public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            webService = new WlcWebService();

            var prefs            = Activity.GetSharedPreferences("wlcPrefs", FileCreationMode.Private);
            var myStatsUrl       = prefs.GetString("statsUrl", "");
            var challengeProfile = prefs.GetString("challengeProfile", "");

            csrfToken = prefs.GetString("csrfToken", "");
            adapter   = new StatsColorBarAdapter(Activity);

            try {
                profile = Newtonsoft.Json.JsonConvert.DeserializeObject <ChallengeProfile> (challengeProfile, new Newtonsoft.Json.JsonSerializerSettings()
                {
                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                });

                var contentStr = await webService.GetStats(StoredCookies, "/profiles/" + profile.id.ToString() + "/stats_calendar");

                myStats = WlcHelpers.GetStats(contentStr);
                ((StatsColorBarAdapter)adapter).Stats = myStats.OrderByDescending(x => x.StatDate).ToList();
//				today = await webService.GetRecord(StoredCookies, "today.json", csrfToken);
                if (!Activity.IsFinishing)
                {
                    UpdateView();
                }
            } catch (Exception ex) {
            }
        }
예제 #3
0
        async public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            webService = new WlcWebService();

            var prefs            = Activity.GetSharedPreferences("wlcPrefs", FileCreationMode.Private);
            var myStatsUrl       = prefs.GetString("statsUrl", "");
            var challengeProfile = prefs.GetString("challengeProfile", "");

            csrfToken = prefs.GetString("csrfToken", "");
            adapter   = new ReflectionAdapter(Activity);
            try {
                profile = Newtonsoft.Json.JsonConvert.DeserializeObject <ChallengeProfile> (challengeProfile, new Newtonsoft.Json.JsonSerializerSettings()
                {
                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                });

                client = new RestClient("https://game.wholelifechallenge.com");
                client.CookieContainer = StoredCookies;
                client.FollowRedirects = true;
                //TODO: parametrize the team id!
                postsReq = new RestRequest("api/frontend/current_user/teams/7569/posts.json", Method.GET);
                postsReq.AddHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
                postsReq.AddHeader("X-CSRF-TOKEN", csrfToken);
                postsReq.AddHeader("Referer", "https://game.wholelifechallenge.com/wlcmay15/hub");
                postsReq.AddParameter("per", 10);
                var resp = await client.ExecuteGetTaskAsync(postsReq);

                var content = resp.Content;
                serializerSettings = new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore,
                    DateParseHandling = DateParseHandling.None
                };
                //_record = JsonConvert.DeserializeObject<DailyRecord> (contentStr.Result);

                int teamId = profile.teams.Select(x => x.id).First();

                adapter.ReflectionFeed = JsonConvert.DeserializeObject <Feed> (content, serializerSettings);
//				adapter.ReflectionFeed = await webService.GetReflections(teamId, 0, 10, StoredCookies, csrfToken);
                if (!Activity.IsFinishing)
                {
                    UpdateView();
                }
            } catch (Exception ex) {
            }
        }