Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add material design elements #40

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23+'
compile 'com.android.support:appcompat-v7:' + androidSupportLibVersion
compile 'com.android.support:design:' + androidSupportLibVersion
compile project(':core')
}
72 changes: 42 additions & 30 deletions android/src/main/java/org/robovm/store/StoreAppActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,31 @@

package org.robovm.store;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics;
import android.view.MenuItem;

import org.robovm.store.api.RoboVMWebService;
import org.robovm.store.api.RoboVMWebService.ActionWrapper;
import org.robovm.store.fragments.*;
import org.robovm.store.fragments.BasketFragment;
import org.robovm.store.fragments.BragFragment;
import org.robovm.store.fragments.LoginFragment;
import org.robovm.store.fragments.ProductDetailsFragment;
import org.robovm.store.fragments.ProductListFragment;
import org.robovm.store.fragments.ShippingDetailsFragment;
import org.robovm.store.model.Product;
import org.robovm.store.util.Action;
import org.robovm.store.util.ImageCache;
import org.robovm.store.util.Images;

public class StoreAppActivity extends Activity {
public class StoreAppActivity extends AppCompatActivity {
private int baseFragment;
private Toolbar toolbar;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -52,6 +60,8 @@ public <T> void invoke(Action<T> action, T result) {
};

setContentView(R.layout.main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

// Retain fragments so don't set home if state is stored.
if (getFragmentManager().getBackStackEntryCount() == 0) {
Expand All @@ -76,33 +86,33 @@ protected void onRestoreInstanceState(Bundle savedInstanceState) {
}

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.cart_menu_item:
showBasket();
return true;
case android.R.id.home:
// pop full backstack when going home.
getFragmentManager().popBackStack(baseFragment, FragmentManager.POP_BACK_STACK_INCLUSIVE);
setupActionBar();
return true;
case R.id.cart_menu_item:
showBasket();
return true;
case android.R.id.home:
// pop full backstack when going home.
getFragmentManager().popBackStack(baseFragment, FragmentManager.POP_BACK_STACK_INCLUSIVE);
setupActionBar();
return true;
}

return super.onMenuItemSelected(featureId, item);
return super.onOptionsItemSelected(item);
}

@Override
public void onBackPressed() {
super.onBackPressed();
setupActionBar(getFragmentManager().getBackStackEntryCount() != 0);
setupActionBar(getSupportFragmentManager().getBackStackEntryCount() != 0);
}

public int switchScreens(Fragment fragment) {
return switchScreens(fragment, true, false);
}

public int switchScreens(Fragment fragment, boolean animated, boolean isRoot) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

if (animated) {
transaction.setCustomAnimations(getInAnimationForFragment(fragment), getOutAnimationForFragment(fragment));
Expand All @@ -121,12 +131,12 @@ private int getInAnimationForFragment(Fragment fragment) {
int animIn = R.anim.enter;

switch (fragment.getClass().getSimpleName()) {
case "ProductDetailsFragment":
animIn = R.anim.product_detail_in;
break;
case "BasketFragment":
animIn = R.anim.basket_in;
break;
case "ProductDetailsFragment":
animIn = R.anim.product_detail_in;
break;
case "BasketFragment":
animIn = R.anim.basket_in;
break;
}
return animIn;
}
Expand All @@ -135,11 +145,11 @@ private int getOutAnimationForFragment(Fragment fragment) {
int animOut = R.anim.exit;

switch (fragment.getClass().getSimpleName()) {
case "ProductDetailsFragment":
animOut = R.anim.product_detail_out;
break;
case "BasketFragment":
break;
case "ProductDetailsFragment":
animOut = R.anim.product_detail_out;
break;
case "BasketFragment":
break;
}
return animOut;
}
Expand All @@ -148,6 +158,7 @@ public void showProductDetail(Product product, int itemVerticalOffset) {
ProductDetailsFragment productDetails = new ProductDetailsFragment(product, itemVerticalOffset);
productDetails.setAddToBasketListener((order) -> {
RoboVMWebService.getInstance().getBasket().add(order);
onBackPressed();
setupActionBar();
});
switchScreens(productDetails);
Expand All @@ -158,7 +169,8 @@ public void setupActionBar() {
}

public void setupActionBar(boolean showUp) {
getActionBar().setDisplayHomeAsUpEnabled(showUp);
getSupportActionBar().setDisplayHomeAsUpEnabled(showUp);
toolbar.setNavigationOnClickListener(v -> onBackPressed());
}

public void showBasket() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@

package org.robovm.store.fragments;

import android.app.ListFragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import org.robovm.store.R;
import org.robovm.store.api.RoboVMWebService;
import org.robovm.store.model.Basket;
Expand All @@ -31,13 +24,26 @@
import org.robovm.store.views.SwipableListItem;
import org.robovm.store.views.ViewSwipeTouchListener;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class BasketFragment extends ListFragment {
private Basket basket;
private Button checkoutButton;

private Runnable checkoutListener;

public BasketFragment() {}
public BasketFragment() {
}

public BasketFragment(Basket basket) {
this.basket = basket;
Expand All @@ -50,10 +56,11 @@ public void onCreate(Bundle savedInstanceState) {
}

@Override
public android.view.View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
public android.view.View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View shoppingCartView = inflater.inflate(R.layout.basket, container, false);

checkoutButton = (Button) shoppingCartView.findViewById(R.id.checkoutBtn);
checkoutButton = (Button)shoppingCartView.findViewById(R.id.checkoutBtn);
checkoutButton.setOnClickListener((b) -> {
if (checkoutListener != null) {
checkoutListener.run();
Expand All @@ -75,8 +82,8 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
checkoutButton.setVisibility(View.INVISIBLE);
}

basket.addOnBasketChangeListener(
() -> checkoutButton.setVisibility(basket.size() > 0 ? View.VISIBLE : View.INVISIBLE));
basket.addOnBasketChangeListener(() -> checkoutButton
.setVisibility(basket.size() > 0 ? View.VISIBLE : View.INVISIBLE));
}

public static class GroceryListAdapter extends BaseAdapter {
Expand Down Expand Up @@ -110,7 +117,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView; // re-use an existing view, if one is available
if (view == null) {
view = LayoutInflater.from(context).inflate(R.layout.basket_item, parent, false);
ViewSwipeTouchListener swipper = ((SwipableListItem) view).getSwipeListener();
ViewSwipeTouchListener swipper = ((SwipableListItem)view).getSwipeListener();
final View finalView = view;
swipper.addEventListener(new ViewSwipeTouchListener.EventListener() {
@Override
Expand All @@ -129,20 +136,22 @@ public void onItemSwipped() {
if (finalView.getParent() == null) {
return;
}
int p = ((ListView) parent).getPositionForView(finalView);
int p = ((ListView)parent).getPositionForView(finalView);
Basket basket = RoboVMWebService.getInstance().getBasket();
basket.remove(p);
notifyDataSetChanged();
}
});
}

((TextView) view.findViewById(R.id.productTitle)).setText(order.getProduct().getName());
((TextView) view.findViewById(R.id.productPrice)).setText(order.getProduct().getPriceDescription());
((TextView) view.findViewById(R.id.productColor)).setText(order.getColor().getName());
((TextView) view.findViewById(R.id.productSize)).setText(order.getSize().getName());
((TextView)view.findViewById(R.id.productTitle)).setText(order.getProduct().getName());
((TextView)view.findViewById(R.id.productPrice))
.setText(order.getProduct().getPriceDescription());
((TextView)view.findViewById(R.id.productColor)).setText(order.getColor().getName());
((TextView)view.findViewById(R.id.productSize)).setText(order.getSize().getName());
((TextView)view.findViewById(R.id.productQuantity)).setText("x" + order.getQuantity());

ImageView orderImage = (ImageView) view.findViewById(R.id.productImage);
ImageView orderImage = (ImageView)view.findViewById(R.id.productImage);
orderImage.setImageResource(R.drawable.product_image);

Images.setImageFromUrlAsync(orderImage, order.getColor().getImageUrls().get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

package org.robovm.store.fragments;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import org.robovm.store.R;

public class BragFragment extends Fragment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@

package org.robovm.store.fragments;

import android.app.Fragment;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.text.Spanned;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import org.robovm.store.R;
import org.robovm.store.api.RoboVMWebService;
import org.robovm.store.util.Gravatar;
Expand All @@ -45,7 +50,8 @@ public class LoginFragment extends Fragment {
private Button login;
private ImageView imageView;

public LoginFragment() {}
public LoginFragment() {
}

@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down
Loading