protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); var client = TraktApiHelper.Client; string authUrl = client.OAuth.CreateAuthorizationUrl(); // TODO: Does this make sense at all? var cookieManager = CookieManager.Instance; cookieManager.RemoveAllCookies(null); var webView = new WebView(this); var webViewClient = new AuthorizationWebViewClient(); webViewClient.CodeReceived += async(sender, e) => { var traktAuthorization = await client.OAuth.GetAuthorizationAsync(e.Code); TraktApiHelper.SaveAuthorization(traktAuthorization); Finish(); }; webView.SetWebViewClient(webViewClient); SetContentView(webView); webView.LoadUrl(authUrl); }
protected override async void OnCreate(Bundle bundle) { base.OnCreate(bundle); // TODO: Remove on prod? Or put in Application class? AndroidEnvironment.UnhandledExceptionRaiser += (sender, e) => { Console.WriteLine(e.Exception.Message); Console.WriteLine(e.Exception.StackTrace); }; SetContentView(Resource.Layout.Main); var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.MainToolbar); var drawerLayout = FindViewById <Android.Support.V4.Widget.DrawerLayout>(Resource.Id.MainDrawerLayout); SetSupportActionBar(toolbar); SupportActionBar.Title = "Quick Check In"; SupportActionBar.SetDisplayShowHomeEnabled(true); SupportActionBar.SetDisplayHomeAsUpEnabled(true); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, Resource.String.OpenDrawer, Resource.String.CloseDrawer); drawerToggle.DrawerIndicatorEnabled = true; drawerLayout.AddDrawerListener(drawerToggle); drawerToggle.SyncState(); var drawerListView = FindViewById <ListView>(Resource.Id.DrawerListView); string[] items = { "On Deck", "Trending", "Lists", "History" }; drawerListView.Adapter = new ArrayAdapter <String>(this, Android.Resource.Layout.SimpleListItem1, items); drawerListView.ItemClick += (sender, e) => { Android.Support.V4.App.Fragment fragment = null; // TODO: Improve, don't rely on indices switch (e.Position) { case 0: // On Deck fragment = new OnDeckFragment(); break; case 1: // Trending // TODO: Add TrendingFragment break; case 2: // Lists fragment = new ListOverviewFragment(); break; case 3: // History fragment = new HistoryFragment(); break; } if (fragment != null) { var drawerTransaction = SupportFragmentManager.BeginTransaction(); drawerTransaction.Replace(Resource.Id.MainFrameLayout, fragment); drawerTransaction.AddToBackStack(null); // Name? drawerTransaction.Commit(); drawerLayout.CloseDrawer(FindViewById <LinearLayout>(Resource.Id.DrawerChildLayout)); // Parameter richtig? } }; client = TraktApiHelper.Client; if (!client.Authorization.IsValid || (client.Authorization.IsValid && client.Authorization.IsExpired)) { if (client.Authorization.IsRefreshPossible) { var traktAuthorization = await client.OAuth.RefreshAuthorizationAsync(); TraktApiHelper.SaveAuthorization(traktAuthorization); } else { Intent authorizationIntent = new Intent(this, typeof(AuthorizationActivity)); StartActivity(authorizationIntent); } } var logoutTextView = FindViewById <TextView>(Resource.Id.LogoutTextView); logoutTextView.Click += (sender, e) => { if (client.Authorization == null || !client.Authorization.IsValid) { Intent authorizationIntent = new Intent(this, typeof(AuthorizationActivity)); StartActivity(authorizationIntent); } else { client.Authorization = null; TraktApiHelper.DeleteAuthorization(); logoutTextView.Text = "Login"; var usernameTextView = FindViewById <TextView>(Resource.Id.UsernameTextView); usernameTextView.Visibility = ViewStates.Gone; var currentlyWatchingLayout = FindViewById <LinearLayout>(Resource.Id.CurrentlyWatchingLayout); currentlyWatchingLayout.Visibility = ViewStates.Gone; } }; var transaction = SupportFragmentManager.BeginTransaction(); transaction.Add(Resource.Id.MainFrameLayout, new OnDeckFragment()); transaction.SetTransition((int)FragmentTransit.FragmentOpen); // Do not add this transaction to the back stack because then the app would be empty when the user presses back transaction.Commit(); }