Skip to content

Commit

Permalink
Add to cart
Browse files Browse the repository at this point in the history
  • Loading branch information
aggarwalcode committed Mar 11, 2018
1 parent d4f92ef commit 98ef717
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainLandingPage">
<activity android:name=".MainLandingPage"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void onCreate(Bundle savedInstanceState) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
setHasOptionsMenu(true);
}

@Override
Expand All @@ -96,12 +97,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
public void onClick(View v) {//!(Arrays.asList(FragmentCart.prodBuyArray).contains(mParam1))
if(!(Arrays.asList(fragmentCart.prodBuyArray).contains(mParam1)))
FragmentCart.keysAddedToCart.add(mParam1);
MainLandingPage.mCartItemCount = FragmentCart.keysAddedToCart.size();
getActivity().invalidateOptionsMenu();
FragmentCart frg = new FragmentCart();
final FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();
return;
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public class MainLandingPage extends AppCompatActivity
AddToCart.OnFragmentInteractionListener,
FragmentCart.OnFragmentInteractionListener {

MainLandingPage(){
//Empty Constructor
}

public static final String TAG = "EcomLanding";
RecyclerView recyclerViewEcom;
ImageAdapter mAdapter;
Expand All @@ -48,7 +52,7 @@ public class MainLandingPage extends AppCompatActivity
ImageButton shopByCatBut;
FragmentCart fragmentCart = FragmentCart.newInstance(null, null);
TextView textCartItemCount;
int mCartItemCount = 10;
static int mCartItemCount = 0;
Toolbar toolbar;


Expand Down Expand Up @@ -131,8 +135,6 @@ public void onCancelled(DatabaseError databaseError) {
}
})
);

mCartItemCount = FragmentCart.keysAddedToCart.size();
}


Expand All @@ -149,14 +151,21 @@ public void onBackPressed() {
}
}

@Override
public void onRestart(){
if(MainLandingPage.mCartItemCount == FragmentCart.keysAddedToCart.size() );
MainLandingPage.mCartItemCount = FragmentCart.keysAddedToCart.size();
super.onRestart();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.ecom_landing, menu);

final MenuItem menuItem = menu.findItem(R.id.action_drawer_cart);

MenuItemCompat.getActionProvider(menuItem);
View actionView = MenuItemCompat.getActionView(menuItem);
textCartItemCount = (TextView) actionView.findViewById(R.id.cart_badge);

Expand Down Expand Up @@ -184,14 +193,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
transaction.commit();
transaction.addToBackStack(null);


/*int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
*/
invalidateOptionsMenu();
return super.onOptionsItemSelected(item);
}

Expand All @@ -207,7 +216,6 @@ private void setupBadge() {
textCartItemCount.setVisibility(View.VISIBLE);
}
}
invalidateOptionsMenu();
}
}

Expand Down

0 comments on commit 98ef717

Please sign in to comment.