// IList<PicturePublic> items; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); RequestWindowFeature(WindowFeatures.IndeterminateProgress); SetContentView(Resource.Layout.MyTrophiesLayout); this.ActionBar.Title = "Loading Trophies"; SetProgressBarIndeterminate(true); SetProgressBarIndeterminateVisibility(true); ((POPpicApplication)Application).GetGameRepository(this).ContinueWith(r => { viewModel = new MyTrophiesViewModel(r.Result); viewModel.InitializeAsync().ContinueWith(t => { if (!t.IsFaulted) { var thumbnailsFragment = new MyTrophiesGalleryFragment(this.viewModel.MyBuddyPictures); thumbnailsFragment.ImageSelected += HandleImageSelected; this.DoTransaction(thumbnailsFragment, FragmentTransit.FragmentOpen, false, "My Trophies"); } else { AndroidUtilities.ShowAlert(this, "Loading Failed", "Unable to load your trophies"); } }); }); }
protected void ReloadList(string gameGuidToStart = "") { loadingRelativeLayout.Visibility = ViewStates.Visible; var rootView = FindViewById <LinearLayout> (Resource.Id.rootLinearLayout); rootView.Visibility = ViewStates.Invisible; if (myMoveList == null) { // we need to create the lists myMoveList = Utility.CreateListView("My Turn", rootView, Resources, LayoutInflater); theirMoveList = Utility.CreateListView("Their Turn", rootView, Resources, LayoutInflater); completedList = Utility.CreateListView("Completed", rootView, Resources, LayoutInflater); } RunOnUiThread(() => { // AndHUD.Shared.Show (this, "Loading Your Games", -1, MaskType.Black, null); ((POPpicApplication)Application).GetGameRepository(this).ContinueWith(r => { this.viewModel = new MyGamesViewModel(r.Result); viewModel.InitializeAsync().ContinueWith(t => { if (!t.IsFaulted && t.Result) { myGamesAdapter = new AndroidGameListAdapter(this, this.viewModel, MyGamesViewModel.ListType.MY_TURN); //, this); theirGamesAdapter = new AndroidGameListAdapter(this, this.viewModel, MyGamesViewModel.ListType.THEIR_TURN); //, this); completedAdapter = new AndroidGameListAdapter(this, this.viewModel, MyGamesViewModel.ListType.COMPLETED); //, this); myGamesAdapter.GameSelected += OnGameSelected; theirGamesAdapter.GameSelected += OnGameSelected; theirGamesAdapter.SeeAllClicked += OnSeeAllSelected; completedAdapter.GameSelected += OnGameSelected; completedAdapter.SeeAllClicked += OnSeeAllSelected; myGamesAdapter.CreateNewGameSelected += (object sender, bool e) => { StartCreateGameActivity(); }; myMoveList.Adapter = myGamesAdapter; theirMoveList.Adapter = theirGamesAdapter; completedList.Adapter = completedAdapter; Utility.SetListViewHeightBasedOnChildren2(myMoveList); Utility.SetListViewHeightBasedOnChildren2(theirMoveList); Utility.SetListViewHeightBasedOnChildren2(completedList); } else { AndroidUtilities.ShowAlert(this, "Loading Games Failed", "Sorry, loading your games failed. Please try again later."); } if (!string.IsNullOrEmpty(gameGuidToStart)) { var gameToStart = this.viewModel.GetGameById(gameGuidToStart); if (gameToStart != null) { OnGameSelected(this, gameToStart); } } loadingRelativeLayout.Visibility = ViewStates.Gone; rootView.Visibility = ViewStates.Visible; }, TaskScheduler.FromCurrentSynchronizationContext()); }, TaskScheduler.FromCurrentSynchronizationContext()); }); }
private void AuthThroughBuddy(string fbUserId, string fbUserToken) { //Check to ensure everything's setup right GcmClient.CheckDevice(this); GcmClient.CheckManifest(this); GcmClient.Register(this, GcmBroadcastReceiver.SENDER_IDS); var registrationId = GcmClient.GetRegistrationId(this); FacebookClient fb = new FacebookClient(fbUserToken); fb.AppId = AppId; fb.AppSecret = AppSecret; BuddyClient client = new BuddyClient(BuddyAppName, BuddyAppKey); const string BuddyAccountKey = "BuddyAccount"; const string BuddyAccessTokenKey = "AccessToken"; const string FacebookIDTokenKey = "FacebookIdTokenKey"; var accountStore = AccountStore.Create(this); var savedAccount = accountStore.FindAccountsForService(BuddyAccountKey).LastOrDefault(); Task <AuthenticatedUser> getUserTask; bool saveAccount = false; if (savedAccount != null && savedAccount.Properties.ContainsKey(BuddyAccessTokenKey)) { saveAccount = false; var token = savedAccount.Properties [BuddyAccessTokenKey]; getUserTask = client.LoginAsync(token); } else { saveAccount = true; getUserTask = client.SocialLoginAsync("Facebook", fbUserId, fbUserToken).ContinueWith((u) => { if (u.IsFaulted) { // try again for kicks } return((AuthenticatedUser)u.Result); }); } getUserTask.ContinueWith(r => { Console.WriteLine("Get User Task has happened result is faulted = " + r.IsFaulted.ToString()); if (!r.IsFaulted) { AuthenticatedUser user = r.Result; var successActivity = new Action(() => { var repository = new POPpicLibrary.GameRepository(user, client, fb); Console.WriteLine("Success task is running!"); if (saveAccount) { var properties = new Dictionary <string, string>(); properties[BuddyAccessTokenKey] = user.Token; properties[FacebookIDTokenKey] = fbUserId; Account buddyAccount = new Account(user.ID.ToString(), properties); accountStore.Save(buddyAccount, BuddyAccountKey); } // Finish(); if (progressDialog != null) { progressDialog.Dismiss(); } ((POPpicApplication)Application).SetGameRepository(repository); }); if (string.IsNullOrEmpty(user.ApplicationTag)) { user.PhotoAlbums.CreateAsync(user.ID.ToString(), true, null).ContinueWith(pa => { if (!pa.IsFaulted) { var album = pa.Result; user.VirtualAlbums.CreateAsync(user.ID.ToString(), null).ContinueWith(va => { if (!va.IsFaulted) { var virtualAlbum = va.Result; var extraData = new UserExtraData(); extraData.UploadAlbumId = album.AlbumId; extraData.WinnerAblumVirtualId = virtualAlbum.ID; user.UpdateAsync(null, null, UserGender.Any, 0, null, UserStatus.Any, false, false, JsonConvert.SerializeObject(extraData)).ContinueWith(updateResult => { if (!updateResult.IsFaulted && updateResult.Result) { RunOnUiThread(successActivity); } }); } }); } }); } else { RunOnUiThread(successActivity); } } else { if (progressDialog != null) { progressDialog.Dismiss(); } RunOnUiThread(() => { AndroidUtilities.ShowAlert(this, "Error Getting User Account", r.Exception.Message, "Try Again", (object sender, DialogClickEventArgs e) => { AuthThroughBuddy(); }); }); Console.WriteLine(r.Exception.Message); } }); }