public static bool Login(Android.Content.Context ctx, string username, string password) { bool isSuccessful = false; User user = User.Login(ctx, username, password); if (user != null) { Common.CurrentDealerID = user.deal_id; isSuccessful = true; PreferencesUtil.Username = username; PreferencesUtil.Password = password; PreferencesUtil.SavePreferences(ctx); } return(isSuccessful); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); AndroidEnvironment.UnhandledExceptionRaiser += (sender, e) => { RetailMobile.Error.LogError(this, e.Exception.Message, e.Exception.StackTrace); }; PreferencesUtil.LoadSettings(this); Sync.GenerateDatabase(this); SetContentView(Resource.Layout.main); pbLoadingLayout = FindViewById <RelativeLayout>(Resource.Id.pbLoadingLayout); RelativeLayout layoutFragment1 = FindViewById <RelativeLayout>(Resource.Id.fragment1); RelativeLayout layoutFragment2 = FindViewById <RelativeLayout>(Resource.Id.fragment2); RelativeLayout layoutFragment3 = FindViewById <RelativeLayout>(Resource.Id.fragment3); LinearLayout layout2 = FindViewById <LinearLayout>(Resource.Id.layout2); mainActionBar = (RetailMobile.Fragments.ItemActionBar)SupportFragmentManager.FindFragmentById(Resource.Id.ActionBar1); bool isLoggedIn = false; if (layoutFragment1 != null) { if (!string.IsNullOrEmpty(PreferencesUtil.Username) && !string.IsNullOrEmpty(PreferencesUtil.Password) && LoginFragment.Login(this, PreferencesUtil.Username, PreferencesUtil.Password)) { isLoggedIn = true; if (layoutFragment2 == null && layoutFragment3 == null) { fragmentInvoice = new InvoiceInfoFragment(); var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.fragment1, fragmentInvoice); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.AddToBackStack("Invoice"); ft.Commit(); } else { fragmentMainMenu = new MainMenuFragment(); var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.fragment1, fragmentMainMenu); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.AddToBackStack("MainMenu"); ft.Commit(); } } else { isLoggedIn = false; LoginFragment fragmentLogin = new LoginFragment(); var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.fragment1, fragmentLogin); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.AddToBackStack("Login"); ft.Commit(); } } if (layoutFragment2 != null && layoutFragment3 != null) { if (isLoggedIn) { layout2.Visibility = ViewStates.Visible; fragmentDetails = DetailsFragment.NewInstance((int)MainMenu.MenuItems.Invoices); var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.fragment2, fragmentDetails); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); fragmentInvoice = InvoiceInfoFragment.NewInstance(0); ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.fragment3, fragmentInvoice); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); } else { layoutFragment3.Visibility = ViewStates.Gone; layoutFragment2.Visibility = ViewStates.Gone; } } if (layoutFragment2 == null && layoutFragment3 == null) { menu = new Com.Jeremyfeinstein.Slidingmenu.Lib.SlidingMenu(this); menu.Mode = 0; menu.TouchModeAbove = SlidingMenu.TouchmodeNone; menu.SetShadowWidthRes(Resource.Dimension.shadow_width); menu.SetShadowDrawable(Resource.Drawable.shadow); menu.SetBehindOffsetRes(Resource.Dimension.slidingmenu_offset); menu.SetFadeDegree(0.35f); menu.AttachToActivity(this, Com.Jeremyfeinstein.Slidingmenu.Lib.SlidingMenu.SlidingContent); menu.SetMenu(Resource.Layout.FragmentMainMenu); } SupportFragmentManager.ExecutePendingTransactions(); System.Threading.Tasks.Task.Factory.StartNew(() => Sync.SyncUsers(this)).ContinueWith(task => this.RunOnUiThread(() => HideProgressBar())); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); /*AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((o,e)=> * { * Android.Util.Log.Debug("e : ",e.ToString() ); * Android.Util.Log.Debug("e.ExceptionObject: ",e.ExceptionObject.ToString() ); * Crashlytics.Android.Crashlytics1.Log(e.ToString()); * Crashlytics.Android.Crashlytics1.Log(e.ExceptionObject.ToString()); * });*/ AndroidEnvironment.UnhandledExceptionRaiser += (sender, e) => { RetailMobile.Error.LogError(this, e.Exception.Message, e.Exception.StackTrace); }; PreferencesUtil.LoadSettings(this); Sync.GenerateDatabase(this); Crashlytics.Android.Crashlytics1.Start(this); SetContentView(Resource.Layout.MainMenu); bool isTablet = Common.isTabletDevice(this); if (isTablet) { myActionBar = (RetailMobile.Fragments.ActionBar)SupportFragmentManager.FindFragmentById(Resource.Id.ActionBarMain); myActionBar.SyncClicked += new Fragments.ActionBar.SyncCLickedDelegate(MyActionBar_SyncClicked); myActionBar.MenuClicked += new RetailMobile.Fragments.ActionBar.MenuClickedDelegate(MenuClicked); myActionBar.SettingsClicked += new RetailMobile.Fragments.ActionBar.SettingsCLickedDelegate(SettingsClicked); ShowProgressBar(); if (Common.isPortrait(this)) { // MainMenuPopup.InitPopupMenu(this, myActionBar.Id); InitPopupMenu(); } } System.Threading.Tasks.Task.Factory.StartNew(() => Sync.SyncUsers(this)).ContinueWith(task => this.RunOnUiThread(() => HideProgressBar())); if (!string.IsNullOrEmpty(PreferencesUtil.Username) && !string.IsNullOrEmpty(PreferencesUtil.Password) && LoginFragment.Login(this, PreferencesUtil.Username, PreferencesUtil.Password)) { if (isTablet) { this.FindViewById <LinearLayout>(Resource.Id.layoutList).Visibility = ViewStates.Visible; this.FindViewById <FrameLayout>(Resource.Id.details_fragment).Visibility = ViewStates.Visible; this.FindViewById <LinearLayout>(Resource.Id.layoutDetails).Visibility = ViewStates.Visible; var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.details_fragment, DetailsFragment.NewInstance((int)MainMenu.MenuItems.Invoices)); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.detailInfo_fragment, InvoiceInfoFragment.NewInstance(0)); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); if (this.Resources.Configuration.Orientation == Android.Content.Res.Orientation.Landscape) { this.FindViewById <LinearLayout>(Resource.Id.LayoutMenu).Visibility = ViewStates.Visible; } else { myActionBar.ButtonMenuVisibility = ViewStates.Visible; myActionBar.ButtonSettingsVisibility = ViewStates.Gone; } } else { // var intent = new Android.Content.Intent(); // intent.SetClass(this, typeof(TransactionFragmentActivity)); // StartActivity(intent); var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.actionbar_phone_fragment, new RetailMobile.Fragments.ItemActionBar(), "ItemActionBar"); ft.Replace(Resource.Id.content_phone_fragment, InvoiceInfoFragment.NewInstance(0)); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); } } else { if (isTablet) { myActionBar.ButtonMenuVisibility = ViewStates.Gone; var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.detailInfo_fragment, new LoginFragment()); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); } else { myActionBar = new RetailMobile.Fragments.ActionBar(); var ft = SupportFragmentManager.BeginTransaction(); ft.Replace(Resource.Id.actionbar_phone_fragment, myActionBar);//new RetailMobile.Fragments.ActionBar() ft.Replace(Resource.Id.content_phone_fragment, new LoginFragment()); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.Commit(); myActionBar.SyncClicked += new Fragments.ActionBar.SyncCLickedDelegate(MyActionBar_SyncClicked); myActionBar.MenuClicked += new RetailMobile.Fragments.ActionBar.MenuClickedDelegate(MenuClicked); myActionBar.SettingsClicked += new RetailMobile.Fragments.ActionBar.SettingsCLickedDelegate(SettingsClicked); ShowProgressBar(); } } }
void ActionBarButtonClicked(int id) { switch (id) { case ControlIds.SETTINGS_MENU_BUTTON: { ((Main)this.Activity).ToggleMenu(); } break; case ControlIds.SETTINGS_BACK_BUTTON: if (Common.CurrentDealerID == 0) { if (this.Activity == null) { return; //? } this.Activity.SupportFragmentManager.PopBackStack(); /*if (Common.isTabletDevice(this.Activity)) * { * var ft = this.Activity.SupportFragmentManager.BeginTransaction(); * ft.Replace(Resource.Id.detailInfo_fragment, new LoginFragment()); * ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); * ft.Commit(); * } * else * { * var intent = new Android.Content.Intent(); * intent.SetClass(this.Activity, typeof(LoginFragmentActivity)); * StartActivity(intent); * }*/ } break; case ControlIds.SETTINGS_SAVE_BUTTON: try { PreferencesUtil.IP = tbIP.Text; PreferencesUtil.Port = int.Parse(tbPort.Text); PreferencesUtil.SyncModel = tbSyncModel.Text; PreferencesUtil.SyncUser = tbSyncUser.Text; PreferencesUtil.SyncPass = tbSyncPass.Text; PreferencesUtil.SavePreferences(this.Activity); Toast.MakeText(this.Activity.ApplicationContext, "Saved", ToastLength.Short).Show(); if (Common.CurrentDealerID == 0) { /*var ft = this.Activity.SupportFragmentManager.BeginTransaction(); * ft.Replace(Resource.Id.fragment1, new LoginFragment()); * ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); * ft.Commit(); */ this.Activity.SupportFragmentManager.PopBackStack(); /*if (Common.isTabletDevice(this.Activity)) * { * var ft = this.Activity.SupportFragmentManager.BeginTransaction(); * ft.Replace(Resource.Id.detailInfo_fragment, new LoginFragment()); * ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); * ft.Commit(); * } * else * { * var intent = new Android.Content.Intent(); * intent.SetClass(this.Activity, typeof(LoginFragmentActivity)); * StartActivity(intent); * }*/ } } catch (Exception ex) { Android.Util.Log.Error("ActionBarButtonClicked SAVE_BUTTON", ex.Message); } break; } }