protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); try { SetContentView(Resource.Layout.Main); Toolbar toolbar = (Toolbar)FindViewById(Resource.Id.toolbar); TextView toolbar_title = (TextView)FindViewById(Resource.Id.toolbar_title); SetSupportActionBar(toolbar); this.Title = ""; SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_menu_white_24dp); SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetHomeButtonEnabled(true); if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); Window.SetStatusBarColor(new Android.Graphics.Color(Android.Support.V4.Content.ContextCompat.GetColor(this, Resource.Color.primaryDark))); } From = Intent.GetStringExtra("FromEvent"); EventIdRequest = Intent.GetLongExtra("EventRequest", 0); SearchUserId = Intent.GetLongExtra("FromPeople", 0); FriendNotification = Intent.GetStringExtra("FriendNotification"); FromESF = Intent.GetStringExtra("FromESF"); toNotification = Intent.GetStringExtra("ToNotification"); btnEditProfile = (Button)FindViewById(Resource.Id.btnEditProfile); drawerLayout = (DrawerLayout)FindViewById(Resource.Id.drawer_layout); navigationView = (NavigationView)FindViewById(Resource.Id.navigation_view); listDrawerMenu = (ListView)FindViewById(Resource.Id.listDrawerMenu); profile_pic = (ImageView)FindViewById(Resource.Id.profile_pic); tvUsername = (TextView)FindViewById(Resource.Id.tvUsername); profile_pic.Click += Profile_pic_Click; var prefs = Application.Context.GetSharedPreferences("WeClip", FileCreationMode.Private); string strUserName = prefs.GetString("UserName", ""); string strProfilePic = prefs.GetString("ProfilePic", ""); tvUsername.Text = strUserName; if (string.IsNullOrEmpty(strProfilePic)) { profile_pic.SetImageResource(Resource.Drawable.contact_withoutphoto); } else { Picasso.With(this).Load(strProfilePic) .Transform(new CircleTransformation()).Resize(240, 240) .CenterInside().Into(profile_pic); } List <DrawerItemModel> listDrawersItems = new List <DrawerItemModel>(); listDrawersItems.Add(new DrawerItemModel("Home")); listDrawersItems.Add(new DrawerItemModel("Invite friends")); listDrawersItems.Add(new DrawerItemModel("Settings")); listDrawersItems.Add(new DrawerItemModel("Help")); // listDrawersItems.Add(new DrawerItemModel("Change password")); listDrawersItems.Add(new DrawerItemModel("Logout")); listDrawerMenu.Adapter = new DrawerItemAdapter(this, listDrawersItems); listDrawerMenu.ItemClick += ListDrawerMenu_ItemClick; btnEditProfile.Click += BtnEditProfile_Click; if (EventIdRequest != 0) { var eventRequest = new EventRequestFragment(); MainActivity.myBundle.PutLong("EventID", EventIdRequest); Android.Support.V4.App.FragmentManager eventFragmentManager = SupportFragmentManager; eventFragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, eventRequest).Commit(); } else if (!string.IsNullOrEmpty(FriendNotification)) { var notification = new NotificationFragment(); Android.Support.V4.App.FragmentManager eventFragmentManager = SupportFragmentManager; eventFragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, notification).Commit(); } else if (!string.IsNullOrEmpty(toNotification)) { try { var notification = new NotificationFragment(); Android.Support.V4.App.FragmentManager eventFragmentManager = SupportFragmentManager; eventFragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, notification).Commit(); } catch (System.Exception ex) { throw; } } else if (!string.IsNullOrEmpty(FromESF)) { var homeFragment = new EventFragment(); Android.Support.V4.App.FragmentManager eventFragmentManager = SupportFragmentManager; eventFragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, homeFragment).Commit(); } else if (SearchUserId != 0) { var profile = new ProfileFragment(); Bundle b = new Bundle(); long UserId = SearchUserId; b.PutLong("UserId", UserId); profile.Arguments = (b); Android.Support.V4.App.FragmentManager eventFragmentManager = SupportFragmentManager; eventFragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, profile).Commit(); } else if (string.IsNullOrEmpty(From)) { var homeFragment = new HomeFragment(); Android.Support.V4.App.FragmentManager eventFragmentManager = SupportFragmentManager; eventFragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, homeFragment, "home").Commit(); } else { var homeFragment = new EventFragment(); Android.Support.V4.App.FragmentManager eventFragmentManager = SupportFragmentManager; eventFragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, homeFragment, "event").AddToBackStack("event").Commit(); } } catch (Java.Lang.Exception ex) { new CrashReportAsync("MainActivity", "OnCreates", ex.Message + ex.StackTrace + ex.Cause + ex.InnerException).Execute(); } }
private void SelectItem(int position) { Android.Support.V4.App.Fragment fragment = null; string tag = ""; switch (position) { case 0: fragment = new HomeFragment(); tag = "home"; break; case 1: fragment = new InviteContacts(); tag = "invite"; break; case 2: fragment = new SettingFragment(); tag = "setting"; break; //case 4: // fragment = new ChangePasswordFragment(); // tag = "setting"; // break; case 4: drawerLayout.CloseDrawers(); Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this); alert.SetInverseBackgroundForced(true); alert.SetTitle("Logout"); alert.SetMessage("Are you sure?"); alert.SetPositiveButton("YES", (senderAlert, args) => { new LogOutFromWeClip(this).Execute(); }); alert.SetNegativeButton("No", (s, e) => { alert.Dispose(); }); Android.App.Dialog dialog = alert.Create(); dialog.Show(); break; default: fragment = new InviteContacts(); break; } if (fragment != null) { Android.Support.V4.App.Fragment containerFragment = SupportFragmentManager.FindFragmentById(Resource.Id.content_frame); if (containerFragment.Class.Name.Equals(fragment.Class.Name)) { drawerLayout.CloseDrawers(); return; } Android.Support.V4.App.Fragment itemFragement = fragment; Android.Support.V4.App.FragmentManager fragmentManager = SupportFragmentManager; fragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, itemFragement, tag).AddToBackStack("my_fragment").Commit(); drawerLayout.CloseDrawers(); } }