private async Task GetUserActivities()
        {
            if (dbManager == null)
            {
                dbManager = await Storage.GetDatabaseManager().ConfigureAwait(false);
            }

            FeedSection cached = JsonConvert.DeserializeObject <FeedSection>(dbManager.CurrentUser.RemoteCreatedContentJson) ?? new FeedSection();

            activities = cached.Activities ?? new List <LearningActivity>();
            int removed = activities.RemoveAll(act => previouslySelected.Any((rhs) => rhs.Id == act.Id)); //remove previously selected activities

            activities = activities.OrderByDescending(act => act.CreatedAt).ToList();

            if (!activities.Any())
            {
                using (TextView header = FindViewById <TextView>(Resource.Id.headerText))
                {
                    if (removed > 0)
                    {
                        header.SetText(Resource.String.createCollectionAddActivityHeaderNoneLeft);
                    }
                    else
                    {
                        header.SetText(Resource.String.createCollectionAddActivityHeaderNone);
                    }
                }
            }

            SetupAdaptors();

            // TODO enable refresh
        }
Beispiel #2
0
        public override int GetItemViewType(int section, int relativePosition, int absolutePosition)
        {
            FeedItem item = null;

            FeedSection thisSection = Data[section];

            int collsInSection = thisSection.Collections?.Count ?? 0;
            int actsInSection  = thisSection.Activities?.Count ?? 0;

            if (collsInSection > relativePosition)
            {
                item = thisSection.Collections[relativePosition];
            }
            else if ((actsInSection + collsInSection) > relativePosition)
            {
                item = thisSection.Activities[relativePosition - collsInSection];
            }

            if (item != null)
            {
                if (item is LearningActivity)
                {
                    return(Activity);
                }
                if (item is ActivityCollection)
                {
                    return(Collection);
                }
            }

            return(base.GetItemViewType(section, relativePosition, absolutePosition));
        }
Beispiel #3
0
        public bool AddFeed(string rawData, ref List <FeedMs> msFeed, int width, Shared.GetFont tFont, Shared.GetFont dFont, Shared.GetFont bFont)
        {
            char lastChar;
            char nextChar;

            TextBlobHL TextBlobHL = new TextBlobHL(bFont, "label", width);
            FeedMs     feedItem   = null;

            currentFeedSection = FeedSection.keyNone;
            if (rawData.StartsWith("\"" + keyTitle + "\""))
            {
                feedItem = new FeedMs(new Vector2(24, 0), TextBlobHL, tFont, dFont, bFont);
                string[] delimiterChars = { "\":\"", "\",\"" };
                string[] fields         = rawData.Split(delimiterChars, StringSplitOptions.None);
                foreach (string field in fields)
                {
                    nextChar = field[field.Length - 1];
                    if (currentFeedSection != FeedSection.keyNone)
                    {
                        ProcessKey(ref feedItem, field, currentFeedSection);
                        currentFeedSection = FeedSection.keyNone;
                    }
                    else if (field.Contains("\"" + keyTitle))
                    {
                        currentFeedSection = FeedSection.keyTitle;
                    }
                    else if (field.Contains(keyText))
                    {
                        currentFeedSection = FeedSection.keyText;
                    }
                    else if (field.Contains(keyLink))
                    {
                        currentFeedSection = FeedSection.keyLink;
                    }
                    else if (field.Contains(keyTwitter))
                    {
                        currentFeedSection = FeedSection.keyTwitter;
                    }
                    else if (field.Contains(keyDate))
                    {
                        currentFeedSection = FeedSection.keyDate;
                    }
                    lastChar = field[0];
                }
                msFeed.Add(feedItem);
            }


            return(true);
        }
        public override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Load from cached data from the database if available,
            // just in case we can't contact the server
            List <FeedSection> cached = await((MainActivity)Activity).GetCachedContent(false);

            // Check for recently opened activities
            FeedSection recents = await LoadRecent();

            if (recents != null)
            {
                cached.Insert(0, recents);
            }

            var metrics   = Resources.DisplayMetrics;
            var widthInDp = AndroidUtils.ConvertPixelsToDp(metrics.WidthPixels, Activity);

            int cols = Math.Max(widthInDp / 300, 1);

            adapter            = new FeedItemsAdapter(cached, await AndroidUtils.GetDbManager().ConfigureAwait(false));
            adapter.ItemClick += OnItemClick;

            if (savedInstanceState != null)
            {
                adapter.Data = JsonConvert.DeserializeObject <List <FeedSection> >(savedInstanceState.GetString("MAIN_ADAPTER_DATA"));
                adapter.NotifyDataSetChanged();
            }

            layoutManager = new GridLayoutManager(Activity, cols);
            layoutManager.SetSpanSizeLookup(new GridSpanner(adapter, cols));

            if (!AndroidUtils.IsGooglePlayServicesInstalled(Activity) || googleApiClient != null)
            {
                return;
            }

            googleApiClient = new GoogleApiClient.Builder(Activity)
                              .AddConnectionCallbacks(this)
                              .AddOnConnectionFailedListener(this)
                              .AddApi(LocationServices.API)
                              .Build();
            googleApiClient?.Connect();
        }
Beispiel #5
0
        private void ProcessKey(ref FeedMs newsItem, string data, FeedSection key)
        {
            switch (key)
            {
            case FeedSection.keyTitle:
                newsItem.Title = data;
                ; break;

            case FeedSection.keyText:
                newsItem.Body = data;
                break;

            case FeedSection.keyDate:
                newsItem.DateString = data;
                break;

            case FeedSection.keyTwitter:;
                break;

            case FeedSection.keyLink:
                newsItem.CreateHyperlink(HyperlinkType.URL, "\nRead more Here!", data);
                break;
            }
        }