/// <summary> /// Retrieves data from Sign in activity and attempts to sign in user /// to the database. If user has no profile it will start EditProfile Activity /// If user has a profile, HomeActivity will be started /// </summary> /// <param name="sender">The object that invoked the event</param> /// <param name="e">The event arguments</param> public async void signInDialog_mOnSignInComplete(Object sender, OnSignInEventArgs e) { // Retrieves data from SignIn Activity userNameSignIn = e.Username; userPasswordSignIn = e.Password; // Attempts to log in. //If user has no profile, they are notified and EditProfileActivity is started // and users profile object is passed. // Else statement occurs if user has a profile. HomeActivity is started and profile object is passed. if (await TryToLogin(userNameSignIn, userPasswordSignIn)) { var userProfile = await Getter <Profile> .GetObject(serverURL + profile_ext + "/" + userNameSignIn); if (userProfile == default(Profile)) { Toast.MakeText(this, "You don't have a profile to show", ToastLength.Short).Show(); string userGender = null; string userBio = null; Profile myProfile = new Profile(credentials.username, userGender, userBio, credentials.token); if (await Poster.PostObject(myProfile, serverURL + profile_ext)) { // pass profile object to EditProfileActivity Intent intent = new Intent(this, typeof(EditProfileActivity)); var serializedProfile = JsonConvert.SerializeObject(myProfile); intent.PutExtra("UserProfile", serializedProfile); StartActivity(intent); } } else { //Set the variables associated with the user session username = credentials.username; user_token = credentials.token; userProfile.token = credentials.token; //Open the main menu and pass the profile object Intent intent = new Intent(this, typeof(HomeActivity)); var serializedProfile = JsonConvert.SerializeObject(userProfile); intent.PutExtra("UserProfile", serializedProfile); StartActivity(intent); } } else { Toast.MakeText(this, "Login Unsuccessful ", ToastLength.Short).Show(); } }
async protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.view_profile); musernameviewprofile = FindViewById <TextView> (Resource.Id.usernameviewprofile); mbioviewprofile = FindViewById <TextView> (Resource.Id.bioviewprofile); mpositivevoteviewprofile = FindViewById <TextView> (Resource.Id.positivevoteviewprofile); mnegativevoteviewprofile = FindViewById <TextView> (Resource.Id.negativevoteviewprofile); mUpvote = FindViewById <Button> (Resource.Id.upvoteButton); mDownvote = FindViewById <Button> (Resource.Id.downvoteButton); mInvite = FindViewById <Button> (Resource.Id.inviteViewProfileButton); mBlock = FindViewById <Button> (Resource.Id.blockViewProfileButton); mUnblock = FindViewById <Button> (Resource.Id.unblockViewProfileButton); // Passed username userNameFrom = Intent.GetStringExtra("username_from") ?? "Data not available"; // Get the user's profile information profile = await Getter <Profile> .GetObject(URLs.serverURL + URLs.profile + "/" + userNameFrom); string username = profile.username; string bio = profile.bio; int posvote = profile.positive_votes; int negvote = profile.negative_votes; // set username and bio on the display musernameviewprofile.Text = username; mbioviewprofile.Text = bio; mpositivevoteviewprofile.Text = ("" + posvote); mnegativevoteviewprofile.Text = ("" + negvote); mUpvote.Click += MUpvote_Click; mDownvote.Click += MDownvote_Click; mInvite.Click += MInvite_Click; mBlock.Click += MBlock_Click; mUnblock.Click += MUnblock_Click; }