Exemplo n.º 1
0
        public static Android.Support.V4.App.Fragment newInstance(Context context)
        {
            MyProfileFragment busrouteFragment = new MyProfileFragment();

            return(busrouteFragment);
        }
        protected override void OnCreate(Bundle bundle)
        {
            try
            {
                base.OnCreate(bundle);
                SetContentView(Resource.Layout.activity_maincontent);

                mToolbar      = FindViewById <SupportToolbar>(Resource.Id.m_toolbar);
                mDrawerLayout = FindViewById <DrawerLayout>(Resource.Id.m_drawer_layout);
                mLeftDrawer   = FindViewById <ListView>(Resource.Id.m_left_drawer);

                dashboardFragment       = new DashboardFragment();
                myFarmDashboardFragment = new MyFarmDashboardFragment();
                myProfileFragment       = new MyProfileFragment();
                addActivityFragment     = new AddActivityFragment();
                activityViewerFragment  = new ActivityViewerFragment();
                askAggieFragment        = new AskAggieFragment();
                settingsFragment        = new SettingsFragment();
                contactFragment         = new ContactFragment();
                chatbotFragment         = new ChatbotFragment();
                chatListManagerFragment = new ChatListManagerFragment();

                mStackFragments = new Stack <SupportFragment>();

                mLeftDrawer.Tag = 0;

                SetSupportActionBar(mToolbar);

                mLeftDataSet = new List <string>();
                mLeftDataSet.Add("My Dashboard");
                mLeftDataSet.Add("My Farm");
                mLeftDataSet.Add("My Profile");
                mLeftDataSet.Add("Add Activitiy");
                mLeftDataSet.Add("View Activities");
                /*mLeftDataSet.Add("Ask an Aggie");*/
                /*mLeftDataSet.Add("Settings");*/

                var objdbTemp = new DBaseOperations();
                var lstux     = objdbTemp.selectTable();
                if (lstux != null && lstux.Count > default(int))
                {
                    var uobj = lstux.FirstOrDefault();
                    if (uobj != null && uobj.IsAdmin > default(int))
                    {
                        mLeftDataSet.Add("Chat Management");
                    }
                    else
                    {
                        mLeftDataSet.Add("Ask an Aggie");
                    }
                }
                else
                {
                    mLeftDataSet.Add("Ask an Aggie");
                }

                mLeftDataSet.Add("Contact Us");
                mLeftAdapter           = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleListItem1, mLeftDataSet);
                mLeftDrawer.Adapter    = mLeftAdapter;
                mLeftDrawer.ItemClick += MenuListView_ItemClick;

                mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, Resource.String.openDrawer, Resource.String.closeDrawer);

                mDrawerLayout.SetDrawerListener(mDrawerToggle);
                SupportActionBar.SetHomeButtonEnabled(true);
                SupportActionBar.SetDisplayShowTitleEnabled(true);
                SupportActionBar.SetDisplayHomeAsUpEnabled(true);
                mDrawerToggle.SyncState();

                if (bundle != null)
                {
                    if (bundle.GetString("DrawerState") == "Opened")
                    {
                        SupportActionBar.SetTitle(Resource.String.openDrawer);
                    }
                    else
                    {
                        SupportActionBar.SetTitle(Resource.String.closeDrawer);
                    }
                }
                else
                {
                    SupportActionBar.SetTitle(Resource.String.closeDrawer);
                }

                try
                {
                    string mStringLoginInfo    = string.Empty;
                    string mStringSessionToken = string.Empty;
                    string mStringGoodName     = string.Empty;
                    circular_imageViewLogo = this.FindViewById <Refractored.Controls.CircleImageView>(Resource.Id.circular_imageViewLogo);
                    imageViewLogo          = this.FindViewById <ImageView>(Resource.Id.imageViewLogo);
                    textView = this.FindViewById <TextView>(Resource.Id.textView);
                    try
                    {
                        objdb = new DBaseOperations();
                        var lstu = objdb.selectTable();
                        if (lstu != null && lstu.Count > default(int))
                        {
                            var uobj = lstu.FirstOrDefault();
                            if (uobj.Password == " ")
                            {
                                throw new Exception("Please login again");
                            }
                            mStringLoginInfo    = uobj.EmailId;
                            mStringSessionToken = uobj.AuthToken;
                            mStringGoodName     = uobj.GoodName;
                            _profilepicbase64   = uobj.ProfilePicture;
                        }
                    }
                    catch { }

                    if (!string.IsNullOrEmpty(_profilepicbase64))
                    {
                        var btmpimg = BitmapHelpers.Base64ToBitmap(_profilepicbase64);
                        circular_imageViewLogo.Visibility = ViewStates.Visible;
                        imageViewLogo.Visibility          = ViewStates.Gone;
                        textView.Text = string.Format("Hello, {0}", mStringGoodName);
                        circular_imageViewLogo.RecycleBitmap();
                        circular_imageViewLogo.SetImageBitmap(btmpimg);
                    }
                    else
                    {
                        circular_imageViewLogo.Visibility = ViewStates.Gone;
                        imageViewLogo.Visibility          = ViewStates.Visible;
                        textView.Text = !string.IsNullOrEmpty(mStringGoodName) ? string.Format("Hello, {0}", mStringGoodName) : "";
                    }
                }
                catch { }

                IList <Android.Support.V4.App.Fragment> fragmentsarray = SupportFragmentManager.Fragments;
                if (fragmentsarray != null && fragmentsarray.Count > default(int))
                {
                    foreach (Android.Support.V4.App.Fragment fragment in fragmentsarray)
                    {
                        string tag = fragment.Tag;
                        Android.Support.V4.App.FragmentTransaction tx = SupportFragmentManager.BeginTransaction();
                        tx.Replace(Resource.Id.m_main, fragment, fragment.Tag);
                        tx.Commit();
                        break;
                    }
                }
                else
                {
                    Android.Support.V4.App.FragmentTransaction tx = SupportFragmentManager.BeginTransaction();
                    tx.Replace(Resource.Id.m_main, dashboardFragment, Constants.dashboard);
                    tx.Commit();
                }
            }
            catch (Exception ex)
            {
                this.RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(this);
                    alertDiag.SetTitle(Resource.String.DialogHeaderError);
                    alertDiag.SetMessage(ex.Message);
                    alertDiag.SetIcon(Resource.Drawable.alert);
                    alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                    {
                        Intent intent = new Intent(this, typeof(MainActivity));
                        StartActivity(intent);
                        this.Finish();
                    });
                    Dialog diag = alertDiag.Create();
                    diag.Show();
                    diag.SetCanceledOnTouchOutside(false);
                });
            }
        }