private void addProductToCart(String productId) { CartentiaApplication.MY_CART_PRODUCTS.add(productId); AddCartRequest addCartRequest = new AddCartRequest(); addCartRequest.setUserID(PreferenceManager.getUserID()); addCartRequest.setProductID(productId); addCartRequest.setGroupID(PreferenceManager.getGroupID()); addCartRequest.setID(1); String jsnRequest = new Gson().toJson(addCartRequest); Request request = new JsonPostRequestHandler( Request.Method.POST, Constants.Url.ADD_CART, jsnRequest, AddMyCartResponse.class, new Response.Listener<AddMyCartResponse>() { @Override public void onResponse(AddMyCartResponse response) {} }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) {} }); VolleyManager.getInstance().addRequestToQueue(request, "AddCart"); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (!TextUtils.isEmpty(PreferenceManager.getUserID())) { navigateToDashBoardActivity(); return; } setContentView(R.layout.activity_login); initPresenter(); initView(); }
private void initNavDrawer() { drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerToggle = new ActionBarDrawerToggle( this, drawerLayout, toolbar, R.string.app_name, R.string.app_name) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); } @Override public boolean onOptionsItemSelected(MenuItem item) { if (item != null && item.getItemId() == android.R.id.home) { if (drawerLayout.isDrawerOpen(Gravity.LEFT)) { drawerLayout.closeDrawer(Gravity.LEFT); } else drawerLayout.openDrawer(Gravity.LEFT); } return false; } }; drawerLayout.setDrawerListener(drawerToggle); navigationView = (NavigationView) findViewById(R.id.navigation); navigationView .getMenu() .findItem(R.id.my_cart) .setTitle("" + PreferenceManager.getName() + "'s Cart"); navigationView.setNavigationItemSelectedListener( new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { drawerLayout.closeDrawers(); menuItem.setChecked(true); switch (menuItem.getItemId()) { case R.id.my_cart: loadMyCartFragment(); break; case R.id.order_history: break; case R.id.about_us: break; case R.id.logout: logout(); break; } return true; } }); drawerToggle.syncState(); }
private void logout() { PreferenceManager.setUserID(null); Intent loginIntent = new Intent(this, LoginActivity.class); startActivity(loginIntent); finishAffinity(); }