private async void loginUrlAsync() { Login login = new Login() { username = userId.Text, password = password.Text }; try { var uri = BaseURL.Login; var loginData = JsonConvert.SerializeObject(login); using (var client = new HttpClient()) { var jsonContent = new StringContent(loginData, Encoding.UTF8, "application/json"); var response = await client.PostAsync(uri, jsonContent); ISharedPreferencesEditor editor = GetSharedPreferences(BaseURL.MyPrefreance, FileCreationMode.Private).Edit(); if (response.IsSuccessStatusCode) { response.EnsureSuccessStatusCode(); var resultString = await response.Content.ReadAsStringAsync(); var responseData = JsonConvert.DeserializeObject <ResponseData>(resultString); var getDataUrl = new System.Uri(BaseURL.myprofile + responseData.Id.ToString()); var memberResponse = await client.GetStringAsync(getDataUrl); var memberData = JsonConvert.DeserializeObject <UserInfo>(memberResponse); progressDialog.Dismiss(); sessionManagement = new Session_management(this); editor.PutString(BaseURL.KEY_MOBILE, userId.Text); editor.PutString(BaseURL.KEY_PASSWORD, password.Text); editor.Apply(); var memberName = memberData.partyname == null ? string.Empty : memberData.partyname; var memberEmail = memberData.mailid == null ? string.Empty : memberData.mailid; sessionManagement.createLoginSession(memberData.partyid.ToString(), responseData.Id.ToString(), memberEmail, memberName, userId.Text, password.Text); sessionManagement.AddAddress(memberData); Intent intent = new Intent(this, typeof(MainActivity)); StartActivity(intent); } } } catch (Exception ex) { string message = ex.Message; Toast.MakeText(this, "Something went wrong.", ToastLength.Short).Show(); return; } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); SetContentView(Resource.Layout.activity_main); sessionManagement = new Session_management(this); Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); SupportActionBar.SetDisplayShowTitleEnabled(false); //SupportActionBar.SetTitle(Resource.String.app_name); drawer = (DrawerLayout)FindViewById(Resource.Id.drawer_layout); toggle = new ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close); drawer.SetDrawerListener(toggle); toggle.SyncState(); navigationView = (NavigationView)FindViewById(Resource.Id.nav_view); IMenu m = navigationView.Menu; for (int i = 0; i < m.Size(); i++) { IMenuItem mi = m.GetItem(i); //for aapplying a font to subMenu ... ISubMenu subMenu = mi.SubMenu; if (subMenu != null && subMenu.Size() > 0) { for (int j = 0; j < subMenu.Size(); j++) { IMenuItem subMenuItem = subMenu.GetItem(j); } } } View headerView = navigationView.GetHeaderView(0); navigationView.Background.SetColorFilter(Android.Graphics.Color.Rgb(128, 0, 0), PorterDuff.Mode.Multiply); navigationView.SetNavigationItemSelectedListener(this); nav_menu = navigationView.Menu; View header = ((NavigationView)FindViewById(Resource.Id.nav_view)).GetHeaderView(0); viewpa = (LinearLayout)header.FindViewById(Resource.Id.viewpa); if (sessionManagement.isLoggedIn()) { viewpa.Visibility = ViewStates.Visible; } My_Order = (LinearLayout)header.FindViewById(Resource.Id.my_orders); My_Reward = (LinearLayout)header.FindViewById(Resource.Id.my_reward); btn_checkout = (LinearLayout)header.FindViewById(Resource.Id.checkout); My_Cart = (LinearLayout)header.FindViewById(Resource.Id.my_cart); iv_profile = (ImageView)header.FindViewById(Resource.Id.iv_header_img); username = (TextView)header.FindViewById(Resource.Id.tv_header_name); totalBudgetCount = (TextView)FindViewById(Resource.Id.totalBudgetCount); My_Order.Click += delegate { if (sessionManagement.isLoggedIn()) { Intent i = new Intent(this, typeof(My_Order_activity)); StartActivity(i); } else { Intent i = new Intent(this, typeof(LoginActivity)); StartActivity(i); OverridePendingTransition(0, 0); }; }; My_Reward.Click += delegate { if (sessionManagement.isLoggedIn()) { Intent i = new Intent(this, typeof(Reward_fragment)); StartActivity(i); } else { Intent i = new Intent(this, typeof(LoginActivity)); StartActivity(i); OverridePendingTransition(0, 0); }; }; btn_checkout.Click += delegate { if (sessionManagement.isLoggedIn()) { Intent i = new Intent(this, typeof(OrderSummary)); StartActivity(i); } else { Intent i = new Intent(this, typeof(LoginActivity)); StartActivity(i); OverridePendingTransition(0, 0); }; }; My_Cart.Click += delegate { if (sessionManagement.isLoggedIn()) { Intent i = new Intent(this, typeof(CartFragment)); StartActivity(i); } else { Intent i = new Intent(this, typeof(LoginActivity)); StartActivity(i); OverridePendingTransition(0, 0); }; }; iv_profile.Click += delegate { if (sessionManagement.isLoggedIn()) { Edit_profile_fragment fm = new Edit_profile_fragment(); Android.Support.V4.App.FragmentManager fragmentManager = SupportFragmentManager; fragmentManager.BeginTransaction().Replace(Resource.Id.contentPanel, fm) .AddToBackStack(null).Commit(); } else { Intent i = new Intent(this, typeof(LoginActivity)); StartActivity(i); OverridePendingTransition(0, 0); }; }; sideMenu(); if (savedInstanceState == null) { HomeeeFragment fm = new HomeeeFragment(); Android.Support.V4.App.FragmentManager fragmentManager = SupportFragmentManager; fragmentManager.BeginTransaction() .Replace(Resource.Id.contentPanel, fm, "Home_fragment") .SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentOpen) .Commit(); } SupportFragmentManager.BackStackChanged += SupportFragmentManager_BackStackChanged; initComponent(); loadFragment(new HomeeeFragment()); }