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);

            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;
            layoutManager      = new GridLayoutManager(Activity, cols);
            layoutManager.SetSpanSizeLookup(new GridSpanner(adapter, cols));
        }
Ejemplo n.º 2
0
        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();
        }