public override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); RetainInstance = true; ((MainActivity)Activity).SetTitle("Settings"); AccountStorage.SetContext(this.Activity); // Create your fragment here AddPreferencesFromResource(Resource.Layout.Settings); Preference pf = FindPreference("login_preference"); pf.Summary = "Logged in as : " + AccountStorage.UserId; pf.PreferenceClick += (sender, args) => { try { System.Diagnostics.Debug.WriteLine("We are about to logout"); AccountStorage.ClearStorage(); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } }; }
public override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); RetainInstance = true; _mActivity.SetTitle("Process Dashboard"); AccountStorage.SetContext(this.Activity); }
public async Task <int> CheckCredentials(string datatoken, string userid, string password) { //Check username and password System.Diagnostics.Debug.WriteLine("We are inside the outer task"); ProgressDialog pd = new ProgressDialog(Activity); pd.SetMessage("Checking username and password"); pd.SetCancelable(false); pd.Show(); AlertDialog.Builder builder = new AlertDialog.Builder((Activity)); await Task.Run(() => { Debug.WriteLine("We are checking username"); HttpWebResponse resp; try { DataSetLocationResolver dslr = new DataSetLocationResolver(); dslr.ResolveFromToken(datatoken, out baseurl, out dataset); System.Diagnostics.Debug.WriteLine("Base url :" + baseurl); AccountStorage.SetContext(Activity); AccountStorage.Set(userid, password, baseurl, dataset); var req = WebRequest.CreateHttp(AccountStorage.BaseUrl + "api/v1/datasets/" + AccountStorage.DataSet + "/"); req.Method = "GET"; req.AllowAutoRedirect = false; string credential = userid + ":" + password; req.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(credential))); // req.Get resp = (HttpWebResponse)req.GetResponse(); if (resp.StatusCode == HttpStatusCode.OK) { if (resp.GetResponseStream().CanRead) { Stream data = resp.GetResponseStream(); var reader = new StreamReader(data); string responseStr = reader.ReadToEnd(); Debug.WriteLine(responseStr); if (responseStr.Contains("auth-required")) { Debug.WriteLine("Wrong credentials 2"); AccountStorage.ClearStorage(); Activity.RunOnUiThread(() => { if (pd.IsShowing) { pd.Dismiss(); } builder.SetTitle("Wrong Credentials") .SetMessage("Please check your username and password and try again.") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); Debug.WriteLine("We should have shown the dialog now"); }); } else if (responseStr.Contains("permission-denied")) { Debug.WriteLine("permission issue"); AccountStorage.ClearStorage(); Activity.RunOnUiThread(() => { if (pd.IsShowing) { pd.Dismiss(); } builder.SetTitle("Access Denied") .SetMessage("You donot have access to this dataset") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); }); } else if (responseStr.Contains("dataset")) { Debug.WriteLine("Username and password was correct"); Activity.RunOnUiThread(() => { pd.SetMessage("Getting Account Info"); pd.SetCancelable(false); if (!pd.IsShowing) { pd.Show(); } }); Task.Run(() => { //LOAD METHOD TO GET ACCOUNT INFO Debug.WriteLine("We are going to store the values"); Debug.WriteLine("We have stored the values"); Debug.WriteLine(AccountStorage.BaseUrl); Debug.WriteLine(AccountStorage.DataSet); Debug.WriteLine(AccountStorage.Password); Debug.WriteLine(AccountStorage.UserId); // Switch to next screen //HIDE PROGRESS DIALOG Activity.RunOnUiThread(() => { if (pd.IsShowing) { pd.Dismiss(); } Toast.MakeText(Activity, "Logged in", ToastLength.Short).Show(); ((MainActivity)Activity).FragmentManager.PopBackStack(); ((MainActivity)Activity).SetDrawerState(true); ((MainActivity)Activity).SwitchToFragment( MainActivity.FragmentTypes.Home); }); }); } } } } catch (WebException e) { Debug.WriteLine("We have a problem"); Activity.RunOnUiThread(() => { if (pd.IsShowing) { pd.Dismiss(); } }); using (WebResponse response = e.Response) { HttpWebResponse httpResponse = (HttpWebResponse)response; Console.WriteLine("Error code: {0}", httpResponse.StatusCode); if (httpResponse.StatusCode == HttpStatusCode.Unauthorized) { Debug.WriteLine("Wrong credentials"); AccountStorage.ClearStorage(); Activity.RunOnUiThread(() => { try { builder.SetTitle("Unauthorized") .SetMessage( "Please check your username and password and data token and try again.") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (Exception e2) { Debug.WriteLine("We have hit an error while showing the dialog :" + e2.Message); AccountStorage.ClearStorage(); } }); } } } catch (Exception e) { // Catching any generic exception Debug.WriteLine("We have hit a generic exception :" + e.Message); AccountStorage.ClearStorage(); Activity.RunOnUiThread(() => { AlertDialog.Builder builder2 = new AlertDialog.Builder(Activity); builder2.SetTitle("Error occured") .SetMessage(e.Message + ". Please report this error to the developers. We are sorry for the inconvenience.") .SetNeutralButton("Okay", (sender2, args2) => { builder2.Dispose(); }) .SetCancelable(false); AlertDialog alert2 = builder2.Create(); alert2.Show(); }); } return(true); }); // pd.Dismiss(); System.Diagnostics.Debug.WriteLine("We are done with the outer task"); return(0); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); AccountStorage.SetContext(this); //ase.Set("testing","testing","testing","mock"); //System.Diagnostics.Debug.WriteLine(ase.UserId); //System.Diagnostics.Debug.WriteLine("User id: "+ase.UserId); // Create UI _drawerLayout = FindViewById <DrawerLayout>(Resource.Id.drawer_layout); // Init toolbar _toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); _toolbar.Title = this.Resources.GetString(Resource.String.app_name); SetSupportActionBar(_toolbar); //_toolbar. // Attach item selected handler to navigation view var navigationView = FindViewById <NavigationView>(Resource.Id.nav_view); navigationView.SetCheckedItem(0); navigationView.Menu.GetItem(0).SetChecked(true); navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected; // Create ActionBarDrawerToggle button and add it to the toolbar drawerToggle = new ActionBarDrawerToggle(this, _drawerLayout, _toolbar, Resource.String.open_drawer, Resource.String.close_drawer); _drawerLayout.SetDrawerListener(drawerToggle); //SetDrawerState(true); // drawerToggle.SetHomeAsUpIndicator(null); //drawerToggle.SyncState(); _loginFragment = new Login(); _homeFragment = new Home(); _settingsFragment = new SettingsPage(); _globalTimeLogFragment = new GlobalTimeLogList(); _timeLogDetailFragment = new TimeLogDetail(); _listOfProjectFragment = new ListOfProjects(); _taskDetailFragment = new TaskDetails(); _taskTimeLogDetailFragment = new TaskTimeLogList(); _listOfTasksFragment = new ListProjectTasks(""); _testFragment = new TestFragment(); try { if (AccountStorage.UserId != null) { SetDrawerState(true); _currentFragment = _homeFragment; } else { SetDrawerState(false); _currentFragment = _loginFragment; } } catch (Exception e) { SetDrawerState(false); _currentFragment = _loginFragment; } //for testing //_currentFragment = _testFragment; // if logged in // else //CurrentFragment = ListOfProjectFragment; var fragmentTx = FragmentManager.BeginTransaction(); // The fragment will have the ID of Resource.Id.fragment_container. fragmentTx.Replace(Resource.Id.fragmentContainer, _currentFragment); // Commit the transaction. fragmentTx.Commit(); var apiService = new ApiTypes(); var service = new PDashServices(apiService); Ctrl = new Controller(service); // ... CheckForCrashes(); // checkForUpdates(); // FragmentManager.AddOnBackStackChangedListener(this); // shouldDisplayHomeUp(); }