Skip to content

Commit

Permalink
Preparado - Carro
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianGJ committed Oct 25, 2014
1 parent 7dcd6e3 commit a65baaf
Show file tree
Hide file tree
Showing 12 changed files with 446 additions and 10 deletions.
18 changes: 9 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,21 @@
android:icon="@drawable/ic_launcher"
android:label="Worten"
android:theme="@style/AppTheme" >

<activity
android:name=".Shop"
android:label="Worten - Tienda" >

android:name=".Shop"
android:label="Worten - Tienda" >
</activity>
<activity
android:name=".Scaner"
android:label="Worten - Escáner" >

</activity>
<activity
android:name=".Games"
android:label="Worten - Cazadescuentos" >

</activity>
<activity
android:name=".Login"
android:label="Worten - Inicio de sesión" >

</activity>
<activity
android:name=".Product"
Expand All @@ -41,13 +36,18 @@
android:label="Worten" >
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />

<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".Compra"
android:label="@string/title_activity_compra" >
</activity>
</application>

<uses-feature android:name="android.hardware.camera"
<uses-feature
android:name="android.hardware.camera"
android:required="true" />


</manifest>
33 changes: 33 additions & 0 deletions app/src/main/java/worten/aebd/com/worten/Carro.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package worten.aebd.com.worten;

import java.util.ArrayList;

import worten.aebd.com.worten.products.Producto;

/**
* Created by ASUS on 25/10/2014.
*/
public class Carro {
public static ArrayList<Producto> carro;

public static void add (Producto prod){

if(carro==null)
carro=getCarro();

carro.add(prod);
}

public static int getPrecio (){
int i = 0;
for (Producto pro:carro){
i+=pro.getPrecio();
}
return i;
}
public static ArrayList<Producto> getCarro(){
carro = (carro!=null ? carro : new ArrayList<Producto>());
return carro;
}

}
284 changes: 284 additions & 0 deletions app/src/main/java/worten/aebd/com/worten/Compra.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
package worten.aebd.com.worten;

import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

import worten.aebd.com.worten.products.ListAdapter;
import worten.aebd.com.worten.products.Producto;
import worten.aebd.com.worten.products.Productos;


public class Compra extends Activity
implements NavigationDrawerFragment.NavigationDrawerCallbacks {

/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
*/
private NavigationDrawerFragment mNavigationDrawerFragment;

/**
* Used to store the last screen title. For use in {@link #restoreActionBar()}.
*/
private CharSequence mTitle;


private boolean cambio = false;
private ListView mListView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compra);

mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();

// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout),1);


/*
mListView = (ListView) findViewById(R.id.product_label);
mListView.setAdapter(new ArrayAdapter<String>(getActionBar().getThemedContext(),
android.R.layout.simple_list_item_1, categorias));
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> pariente, View view, int posicion, long id) {
String elegido = (String) pariente.getItemAtPosition(posicion);
CharSequence texto = "Seleccionado: " + elegido;
Toast toast = Toast.makeText(Shop.this, texto, Toast.LENGTH_LONG);
toast.show();
}
});*/

mListView = (ListView) findViewById(R.id.carro_label);


mListView.setAdapter(new ListAdapter(this, R.layout.entrada, Carro.getCarro()){
@Override
public void onEntrada(Object entrada, View view) {
if (entrada != null) {
TextView texto_superior_entrada = (TextView) view.findViewById(R.id.textView_superior);
if (texto_superior_entrada != null)
texto_superior_entrada.setText(((Producto) entrada).get_Nombre());

TextView texto_inferior_entrada = (TextView) view.findViewById(R.id.textView_inferior);
if (texto_inferior_entrada != null)
texto_inferior_entrada.setText(((Producto) entrada).get_textoDebajo());

ImageView imagen_entrada = (ImageView) view.findViewById(R.id.imageView_imagen);
if (imagen_entrada != null)
imagen_entrada.setImageResource(((Producto) entrada).get_idImagen());

TextView texto_precio = (TextView) view.findViewById(R.id.textView_precio);
if (texto_precio != null)
texto_precio.setText(((Producto) entrada).getPrecio()+"€");

TextView precio_total = (TextView) view.findViewById(R.id.precio_layout);
if(precio_total != null)
precio_total.setText("Precio total: "+Carro.getPrecio()+"€");

}
}
});

mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> pariente, View view, int posicion, long id) {
Producto elegido = (Producto) pariente.getItemAtPosition(posicion);

// pariente


Intent mainIntent = new Intent();
mainIntent = new Intent().setClass(
Compra.this, Product.class);
mainIntent.putExtra("producto", elegido.getId());
startActivity(mainIntent);

// CharSequence texto = "Seleccionado: " + elegido.get_textoDebajo();
//Toast toast = Toast.makeText(Shop.this, texto, Toast.LENGTH_LONG);
//toast.show();
}
});


}

@Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
.commit();

}

public void onSectionAttached(int number) {
if(cambio){
Intent mainIntent = new Intent();
if(Session.isLogin()){
switch (number) {
case 1:
mainIntent = new Intent().setClass(
Compra.this, Shop.class);
startActivity(mainIntent);
break;
case 2:
mainIntent = new Intent().setClass(
Compra.this, Scaner.class);
startActivity(mainIntent);
break;
case 3:
mainIntent = new Intent().setClass(
Compra.this, Games.class);
startActivity(mainIntent);
break;
case 4:
mainIntent = new Intent().setClass(
Compra.this, User.class);
startActivity(mainIntent);
break;
case 5:
mainIntent = new Intent().setClass(
Compra.this, Compra.class);
startActivity(mainIntent);
break;
default:break;
}}else{

switch (number) {
case 1:
mainIntent = new Intent().setClass(
Compra.this, Shop.class);
startActivity(mainIntent);
break;
case 2:
mainIntent = new Intent().setClass(
Compra.this, Login.class);
startActivity(mainIntent);
break;
case 3:
mainIntent = new Intent().setClass(
Compra.this, Login.class);
startActivity(mainIntent);
break;
case 4:
mainIntent = new Intent().setClass(
Compra.this, Login.class);
startActivity(mainIntent);
break;
case 5:
mainIntent = new Intent().setClass(
Compra.this, Login.class);
startActivity(mainIntent);
break;
default:break;
}






}}else{
cambio = true;
}
}

public void restoreActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mNavigationDrawerFragment.isDrawerOpen()) {
// Only show items in the action bar relevant to this screen
// if the drawer is not showing. Otherwise, let the drawer
// decide what to show in the action bar.
getMenuInflater().inflate(R.menu.shop, menu);
restoreActionBar();
return true;
}
return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
private static final String ARG_SECTION_NUMBER = "section_number";

/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}

public PlaceholderFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_shop, container, false);
return rootView;
}

@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
((Compra) activity).onSectionAttached(
getArguments().getInt(ARG_SECTION_NUMBER));
}
}

}
10 changes: 10 additions & 0 deletions app/src/main/java/worten/aebd/com/worten/Games.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ public void onSectionAttached(int number) {
Games.this, User.class);
startActivity(mainIntent);
break;
case 5:
mainIntent = new Intent().setClass(
Games.this, Compra.class);
startActivity(mainIntent);
break;
}}else{

switch (number) {
Expand All @@ -172,6 +177,11 @@ public void onSectionAttached(int number) {
Games.this, Login.class);
startActivity(mainIntent);
break;
case 5:
mainIntent = new Intent().setClass(
Games.this, Login.class);
startActivity(mainIntent);
break;
default:break;
}

Expand Down
Loading

0 comments on commit a65baaf

Please sign in to comment.