Beispiel #1
0
        public CameraClosedCategoryElement(CategoryJSON inCategory)
        {
            category = inCategory;

            PropertyInfo o = GlobalSingletonHelpers.GetProperty(this, "categoryName");

            o.SetValue(this, category.description);
        }
 public void switchToCategoryImgView(CategoryJSON category)
 {
     eventCategoryImgsView.ActiveCategory = category;
     //Content = eventCategoryImgsView.Content;
     historyView.IsVisible           = false;
     eventView.IsVisible             = false;
     eventCategoryImgsView.IsVisible = true;
 }
Beispiel #3
0
 public void OnRowTapped(object sender, SelectedItemChangedEventArgs args)
 {
     if (args.SelectedItem is string)
     {
         //cameraPage.eventDrillDown((CameraEventTitleElement)args.SelectedItem);
         CategoryJSON theCat = GlobalSingletonHelpers.getCategoryByDescription(categories, (string)args.SelectedItem);
         if (theCat != null)
         {
             callingPage.switchToCategoryImgView(theCat);
         }
     }
     eventCategories.SelectedItem = null;
 }
Beispiel #4
0
        public void switchToCategoryImgView(CategoryJSON category)
        {
            eventCategoryImgsView.ActiveCategory = category;
            //Content = eventCategoryImgsView.Content;
            selectionView.IsVisible         = false;
            submitView.IsVisible            = false;
            createView.IsVisible            = false;
            eventView.IsVisible             = false;
            eventCategoryImgsView.IsVisible = true;

            MasterPage mp = ((MasterPage)Application.Current.MainPage);

            mp.deactivateBackCaret();
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="theList"></param>
        /// <param name="description"></param>
        /// <returns>Null if category description is not present.</returns>
        public static CategoryJSON getCategoryByDescription(IList <CategoryJSON> theList, string description)
        {
            CategoryJSON result = null;

            foreach (CategoryJSON category in theList)
            {
                if (category.description.Equals(description))
                {
                    result = category;
                    break;
                }
            }
            return(result);
        }
Beispiel #6
0
        /*
         * public static string getUploadingCategoryDesc() {
         *  string categoryDesc = "";
         *  if (GlobalStatusSingleton.uploadingCategories.Count > 0) {
         *      categoryDesc = GlobalStatusSingleton.uploadingCategories[0].description;
         *  }
         *  return categoryDesc;
         * }*/

        public static bool listContainsCategory(IList <CategoryJSON> theList, CategoryJSON theCategory)
        {
            bool found = false;

            foreach (CategoryJSON category in theList)
            {
                if (category.categoryId == theCategory.categoryId)
                {
                    found = true;
                    break;
                }
            }
            return(found);
        }
Beispiel #7
0
        /*
         * private Task<IList<Image>> buildLeaderboardImagesForCategory(CategoryJSON category) {
         *  Debug.WriteLine("DHB:LeaderboardPage:buildLeaderboardImagesForCategory begin");
         *  IList<Image> images = new List<Image>();
         *  if ((listOfLeaderboards != null) && (listOfLeaderboards.Count > 0) && listOfLeaderboards.ContainsKey(category)) {
         *      foreach (LeaderboardJSON leader in listOfLeaderboards[category]) {
         *          Image img = GlobalSingletonHelpers.buildFixedRotationImageFromBytes(leader.imgStr);
         *          if (img != null) {
         *              images.Add(img);
         *          }
         *      }
         *  }
         *  Debug.WriteLine("DHB:LeaderboardPage:buildLeaderboardImagesForCategory end");
         *  //return images;
         *  return new Task<IList<Image>>(() => images);
         * }
         */

        /*
         * //private void drawLeaderImagesActual(ref IList<Image> pImgs, ref IList<Image> lImgs) {
         * private void drawLeaderImagesActual(ref IList<Image> pImgs, CategoryJSON category) {
         *  Debug.WriteLine("DHB:LeaderboardPage:drawLeaderImagesActual begin");
         *
         *  if ((listOfLeaderboards != null) && (listOfLeaderboards.Count > 0) && listOfLeaderboards.ContainsKey(category)) {
         *      foreach (LeaderboardJSON leader in listOfLeaderboards[category]) {
         *          IList<Image> images = GlobalSingletonHelpers.buildTwoFixedRotationImageFromBytes(leader.imgStr, (ExifOrientation)leader.orientation);
         *          pImgs.Add(images[0]);
         *          //lImgs.Add(images[1]);
         *      }
         *  }
         *  Debug.WriteLine("DHB:LeaderboardPage:drawLeaderImagesActual end");
         * }
         */

        /// <summary>
        /// Removes by oldest leaderboard by enddate, not last load timestamp.
        /// </summary>
        private void removeOldestLeaderboard()
        {
            if (listOfLeaderboards.Count > 0)
            {
                CategoryJSON oldestKey = listOfLeaderboards.ElementAt(0).Key;
                foreach (KeyValuePair <CategoryJSON, IList <LeaderboardJSON> > leaderboard in listOfLeaderboards)
                {
                    if (leaderboard.Key.end < oldestKey.end)
                    {
                        oldestKey = leaderboard.Key;
                    }
                }
                listOfLeaderboards.Remove(oldestKey);
            }
        }
Beispiel #8
0
        public static bool removeCategoryFromList(IList <CategoryJSON> theList, CategoryJSON theCategory)
        {
            bool         removed  = false;
            CategoryJSON foundCat = null;

            foreach (CategoryJSON category in theList)
            {
                if (category.categoryId == theCategory.categoryId)
                {
                    removed  = true;
                    foundCat = category;
                    break;
                }
            }
            theList.Remove(foundCat);
            return(removed);
        }
Beispiel #9
0
        /// <summary>
        /// Helper for Button.OnClicked that makes the decision whether to request an update from the server
        /// for this leaderboard.
        /// Also a Helper for managePersisedLeaderboard to determine on startup if updates are needed...
        /// No longer have button.clicked.  This is now tested against whenever the user enters the leaderboard page
        /// and fires the reload for any category that is still active and has last reload > MIN_TIME_BETWEEN_RELOADS away
        /// If updating, triggers a leaderboardRequest.
        /// </summary>
        private void reloadAnalysis(CategoryJSON category)
        {
            DateTime timeOfRequest = DateTime.Now;

            if (leaderboardUpdateTimestamps.ContainsKey(category))
            {
                if ((timeOfRequest - leaderboardUpdateTimestamps[category]) > MIN_TIME_BETWEEN_RELOADS)
                {
                    // before firing request, check that this leaderboard is not already in the closed state.
                    if ((category.end > timeOfRequest) && (leaderboardUpdateTimestamps[category] < category.end))
                    {
                        // ending is still in the future and last load was before the category ended.
                        // hmm. if I"m called by managePersistedLeaderboard, this can occur before I have an authToken...
                        // so... check for auth token. if I don't have one, the OnCategoryLoad process catches calls here.
                        if (GlobalStatusSingleton.authToken != null)
                        {
                            RequestLeaderboardEventArgs evtArgs = new RequestLeaderboardEventArgs {
                                Category = category,
                            };
                            if (RequestLeaderboard != null)
                            {
                                RequestLeaderboard(this, evtArgs);
                            }
                        }
                    }
#if DEBUG
                    else
                    {
                        Debug.WriteLine("DHB:LeaderboardPage:reloadAnalysis Hit the closed category no reload case");
                    }
#endif
                }
            }
            else
            {
                // no timestamp info. fire a load.  Request takes care of setting the timestamp.
                RequestLeaderboardEventArgs evtArgs = new RequestLeaderboardEventArgs {
                    Category = category,
                };
                if (RequestLeaderboard != null)
                {
                    RequestLeaderboard(this, evtArgs);
                }
            }
        }
Beispiel #10
0
        private void loadLeaderboards()
        {
            IDictionary <string, object> properties = Application.Current.Properties;

            // this gets called before the leaderboard page is instantiated. so we set it in GlobalStatusSingleton for later retrieval.
            if (Properties.ContainsKey(PROPERTY_LEADERBOARD_CATEGORY_LIST_SIZE))
            {
                //string sanityCheck = Properties[PROPERTY_LEADERBOARD_CATEGORY_LIST_SIZE] as string;
                //object sanityCheck2 = Properties[PROPERTY_LEADERBOARD_CATEGORY_LIST_SIZE];
                //int sanityCheck2 = (int)Properties[PROPERTY_LEADERBOARD_CATEGORY_LIST_SIZE];
                //int listSize = Convert.ToInt32(Properties[PROPERTY_LEADERBOARD_CATEGORY_LIST_SIZE] as string);
                //int listSize2 = Convert.ToInt32(properties[PROPERTY_LEADERBOARD_CATEGORY_LIST_SIZE] as string);
                // most of the above failed. The reason is I wasn't converting the property to a string. this works though, so I'm not seeing a need to convert.
                int listSize = (int)Properties[PROPERTY_LEADERBOARD_CATEGORY_LIST_SIZE];
                IDictionary <CategoryJSON, IList <LeaderboardJSON> > boards = new Dictionary <CategoryJSON, IList <LeaderboardJSON> >(listSize);
                IDictionary <CategoryJSON, DateTime> timeStamps             = new Dictionary <CategoryJSON, DateTime>(listSize);
                for (int i = 0; i < listSize; i++)
                {
                    //if (Properties.ContainsKey(PROPERTY_LEADERBOARD_CATEGORY_LIST+"_"+i)) {
                    //boards.Add(JsonHelper.DeserializeToList<LeaderboardJSON>(
                    //  Properties[PROPERTY_LEADERBOARD_CATEGORY_LIST + "_" + i] as string));
                    //}
                    bool hasLeaderboardKey       = Properties.ContainsKey(PROPERTY_LEADERBOARD_CATEGORY_LIST_KEY + "_" + i);
                    bool hasLeaderboardValue     = Properties.ContainsKey(PROPERTY_LEADERBOARD_CATEGORY_LIST_VALUE + "_" + i);
                    bool hasLeaderboardTimestamp = Properties.ContainsKey(PROPERTY_LEADERBOARD_TIMESTAMP + "_" + i);
                    if ((hasLeaderboardKey) && (hasLeaderboardValue) && (hasLeaderboardTimestamp))
                    {
                        CategoryJSON            key   = JsonConvert.DeserializeObject <CategoryJSON>(Properties[PROPERTY_LEADERBOARD_CATEGORY_LIST_KEY + "_" + i] as string);
                        IList <LeaderboardJSON> value =
                            JsonHelper.DeserializeToList <LeaderboardJSON>(Properties[PROPERTY_LEADERBOARD_CATEGORY_LIST_VALUE + "_" + i] as string);
                        boards.Add(key, value);

                        DateTime stamp;
                        bool     readSuccess = DateTime.TryParse(Properties[PROPERTY_LEADERBOARD_TIMESTAMP + "_" + i] as string, out stamp);
                        if (readSuccess)
                        {
                            timeStamps[key] = stamp;
                        }
                    }
                }
                GlobalStatusSingleton.persistedLeaderboards          = boards;
                GlobalStatusSingleton.persistedLeaderboardTimestamps = timeStamps;
            }
        }
Beispiel #11
0
        protected LeaderboardElement buildLeaderboardElement(CategoryJSON category, IList <LeaderboardJSON> leaderboard)
        {
            LeaderboardElement le      = null;
            List <SKBitmap>    bitmaps = new List <SKBitmap>();

            if (leaderboard.Count > 0)    // only build leaderboards with images.
            {
                foreach (LeaderboardJSON leader in leaderboard)
                {
                    SKBitmap bitmap = GlobalSingletonHelpers.SKBitmapFromBytes(leader.imgStr);
                    if (bitmap != null)
                    {
                        bitmaps.Add(bitmap);
                    }
                }
                le = new LeaderboardElement(category.description, category.categoryId, bitmaps, leaderboard);
#if DEBUG
                le.title = le.title + " - " + le.categoryId;
#endif
            }
            return(le);
        }
Beispiel #12
0
        protected async virtual void OnRequestLeaderboard(object sender, EventArgs e)
        {
            // the current category command does not send back a category in leaderboard state.
            // for now, the system is only going to support Yesterday's and Today's leaderboard.

            Debug.WriteLine("DHB:LeaderboardPage:OnRequestLeaderboard start");
            long   loadCategory = ((RequestLeaderboardEventArgs)e).Category.categoryId;
            string categoryName = ((RequestLeaderboardEventArgs)e).Category.description;

            string result = await requestLeaderboardAsync(loadCategory);

            if (result.Equals(LOAD_FAILURE))
            {
                //leaderboardLabelP.Text = "Connection failed. Please check connection";
                while (result.Equals(LOAD_FAILURE))
                {
                    await Task.Delay(3000);

                    Debug.WriteLine("DHB:LeaderboardPage:OnRequestLeaderboard sending re-request.");
                    result = await requestLeaderboardAsync(loadCategory);
                }
            }
            // fix labels, connection is back...
            //leaderboardLabelP.Text = "BEST OF: ";

            // process successful leaderboard result string
            IList <LeaderboardJSON> newLeaderBoard = JsonHelper.DeserializeToList <LeaderboardJSON>(result);

            // may have been added already. this approach throws an exception if key exists
            //listOfLeaderboards.Add(((RequestLeaderboardEventArgs)e).Category, newLeaderBoard);
            // this one resets the value:
            CategoryJSON category = (((RequestLeaderboardEventArgs)e).Category);

            listOfLeaderboards[category]          = newLeaderBoard;
            leaderboardUpdateTimestamps[category] = DateTime.Now;

            // create a new leaderrow and insert or replace.
            LeaderboardElement le = buildLeaderboardElement(category, newLeaderBoard);

            if (le != null)
            {
                // actually need to determine where to put this, and whether to remove another leaderboard...
                // and can this happen in an async func?
                int leaderboardStatus = leaderboardAlreadyDrawn(category.categoryId);
                Device.BeginInvokeOnMainThread(() =>
                {
                    if (leaderboardStatus == -1)
                    {
                        leaderboards.Add(le);
                        //leaderboards.OrderByDescending(a => a.categoryId);
                        GlobalSingletonHelpers.SortAndReverse(leaderboards);
                        //printOrder();
                    }
                    else
                    {
                        leaderboards.RemoveAt(leaderboardStatus);
                        leaderboards.Insert(leaderboardStatus, le);
                    }
                });
            }

            //drawLeaderImages(((RequestLeaderboardEventArgs)e).Category);  // this happens async... so build afterwards is meaningless...
            // I do need to update the ui now...
            // this should fix with the switch to listview...
            //buildUI();

            Debug.WriteLine("DHB:LeaderboardPage:OnRequestLeaderboard UI Change");
#if DEBUG
            // will be null if everything went ok.
            if (JsonHelper.InvalidJsonElements != null)
            {
                // ignore this error. do we have a debug compiler directive??
                throw new Exception("Invalid leaderboard parse from server in Leaderboard get.");
            }
#endif // DEBUG

            Debug.WriteLine("DHB:LeaderboardPage:OnRequestLeaderboard end");
        }