Пример #1
0
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            switch (item.ItemId)
            {
            case Resource.Id.action_notification:
                Android.Support.V4.App.Fragment fragment = new NotificationFragment();
                var fragmentManager = Activity.SupportFragmentManager;
                Android.Support.V4.App.FragmentTransaction fragmentTransaction = fragmentManager.BeginTransaction();
                fragmentTransaction.Replace(Resource.Id.content_frame, fragment);
                fragmentTransaction.AddToBackStack("HomeFragment");
                fragmentTransaction.Commit();
                return(true);

            case Resource.Id.action_search:
                Activity.StartActivity(typeof(SearchActivity));
                return(true);
            }
            return(false);
        }
Пример #2
0
        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();
            }
        }