public static User GetCurrentUser(Activity activity) { var sharedPreferences = activity.BaseContext.GetSharedPreferences ("CheckinAppPreferences", FileCreationMode.WorldWriteable); int user_id = sharedPreferences.GetInt ("user_id", 0); if (user_id == 0) { return null; } else { UserDB users = new UserDB (); return users.Get (user_id); } }
public override void OnPageFinished(WebView webView, string url) { base.OnPageFinished (webView, url); Android.Net.Uri uri = Android.Net.Uri.Parse (url); Console.WriteLine ("uri.Path: " + uri.Path); if (uri.Path.StartsWith("/info")) { Console.WriteLine (uri.GetQueryParameter ("token")); var sharedPreferences = activity.BaseContext.GetSharedPreferences ("CheckinAppPreferences", FileCreationMode.WorldWriteable); var editor = sharedPreferences.Edit (); string uid = uri.GetQueryParameter ("uid"); string token = uri.GetQueryParameter ("token"); string secret = uri.GetQueryParameter ("secret"); UserDB userDB = new UserDB (); User user = new User (); int count; int user_id = sharedPreferences.GetInt ("user_id", 0); if (user_id == 0) { Console.WriteLine ("user_id == 0"); if (this.activity.AuthService == "facebook") { count = userDB.All ().Where (u => u.Facebook.Equals (uid)).Count (); if (count == 0) { user.Facebook = uid; } } else if (this.activity.AuthService == "twitter") { count = userDB.All ().Where (u => u.Twitter.Equals (uid)).Count (); if (count == 0) { user.Twitter = uid; } } userDB.Insert (user); } else { Console.WriteLine ("user_id != 0"); user = userDB.Get (user_id); if (this.activity.AuthService == "facebook") { user.Facebook = uid; } else if (this.activity.AuthService == "twitter") { user.Twitter = uid; } userDB.Update (user); } editor.PutInt ("user_id", user.Id); editor.PutString (this.activity.AuthService + ":token", token); editor.PutString (this.activity.AuthService + ":secret", secret); Console.WriteLine ("AuthWebViewClient:user_id: " + user.Id); editor.Commit (); Intent intentToLogin = new Intent (); intentToLogin.PutExtra ("authService", activity.AuthService); intentToLogin.PutExtra ("token", token); intentToLogin.PutExtra ("secret", secret); activity.SetResult (Result.Ok, intentToLogin); activity.Finish (); Console.WriteLine ("Finishing: " + activity.Intent.GetStringExtra("callerActivity")); } }