| @@ -0,0 +1,85 @@ | ||
|
|
||
|
|
||
| /** | ||
| * Created by j2md7_000 on 8/27/2017. | ||
| */ | ||
| package Database; | ||
|
|
||
| import com.example.android.firstapp.Transactions; | ||
|
|
||
| import android.content.pm.PackageInfo; | ||
| import android.database.sqlite.SQLiteDatabase; | ||
| import android.database.sqlite.SQLiteOpenHelper; | ||
| import android.database.Cursor; | ||
| import android.content.Context; | ||
| import android.content.ContentValues; | ||
|
|
||
|
|
||
|
|
||
| public class TransactionDB extends SQLiteOpenHelper{ | ||
|
|
||
|
|
||
| private static final int DATABASE_VERSION = 1; | ||
| private static final String DATABASE_NAME = "transactionData.db"; | ||
|
|
||
| public static final String TABLE_PRODUCTS = "transactions"; | ||
| public static final String COLUMN_ID = "_id"; | ||
| public static final String COLUMN_PRODUCTNAME = "transactionName"; | ||
|
|
||
|
|
||
|
|
||
| public TransactionDB(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) { | ||
| super(context, name, factory, version); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void onCreate(SQLiteDatabase db) { | ||
| String query = "CREATE TABLE" + TABLE_PRODUCTS + "(" + | ||
| COLUMN_ID + " INTEGAR PRIMARY KEY AUTOINCREMENT " + COLUMN_PRODUCTNAME + " TEXT " + | ||
| ");"; | ||
| db.execSQL(query); | ||
| } | ||
|
|
||
| @Override | ||
| public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||
| db.execSQL("DROP TABLE IF EXISTS " + TABLE_PRODUCTS); | ||
| onCreate(db); | ||
|
|
||
| } | ||
|
|
||
| public void addProduct(Product product){ | ||
| ContentValues values = new ContentValues(); | ||
| values.put(COLUMN_PRODUCTNAME, product.get_productname()); | ||
| SQLiteDatabase db = getWritableDatabase(); | ||
| db.insert(TABLE_PRODUCTS,null,values); | ||
| db.close(); | ||
| } | ||
|
|
||
| public void deleteTransaction (String TransactionName){ | ||
| SQLiteDatabase db = getWritableDatabase(); | ||
| db.execSQL("DELETE FROM " + TABLE_PRODUCTS + " WHERE " + COLUMN_PRODUCTNAME +"=\"" + productName + "\";"); | ||
| } | ||
|
|
||
| public String databaseToString(){ | ||
|
|
||
| String dbString = ""; | ||
| SQLiteDatabase db = getWritableDatabase(); | ||
| String query = " SELECT * FROM " + TABLE_PRODUCTS + " WHERE 1"; | ||
|
|
||
| Cursor c = db.rawQuery(query,null); | ||
|
|
||
| c.moveToFirst(); | ||
|
|
||
| while (!c.isAfterLast()){ | ||
| if(c.getString(c.getColumnIndex("productname"))!=null){ | ||
| dbString += c.getString(c.getColumnIndex("productname")); | ||
| dbString += "\n"; | ||
| } | ||
| } | ||
| db.close(); | ||
| return dbString; | ||
| } | ||
| } | ||
|
|
| @@ -0,0 +1,77 @@ | ||
| package com.example.android.firstapp; | ||
|
|
||
| import android.app.Activity; | ||
| import android.content.Context; | ||
| import android.support.annotation.NonNull; | ||
| import android.support.annotation.Nullable; | ||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
| import android.widget.ArrayAdapter; | ||
| import android.widget.ImageView; | ||
| import android.widget.TextView; | ||
|
|
||
| import static com.example.android.firstapp.R.drawable.apple_pie; | ||
|
|
||
| /** | ||
| * Created by j2md7_000 on 8/21/2017. | ||
| */ | ||
|
|
||
| public class TransactionAdapter extends ArrayAdapter<Transactions>{ | ||
|
|
||
| Context context; | ||
| int layoutResourceId; | ||
| Transactions data[]=null; | ||
|
|
||
| public TransactionAdapter(Context context, int layoutResourceId, Transactions[] data) | ||
| { | ||
| super(context, layoutResourceId, data); | ||
| this.layoutResourceId = layoutResourceId; | ||
| this.context = context; | ||
| this.data=data; | ||
| } | ||
|
|
||
| @NonNull | ||
| @Override | ||
| public View getView(int position, View convertView, ViewGroup parent) { | ||
| View row = convertView; | ||
| TransactionHolder holder = null; | ||
|
|
||
| if ( row == null) | ||
| { | ||
| LayoutInflater inflater = ((Activity)context).getLayoutInflater(); | ||
| row = inflater.inflate(layoutResourceId, parent, false); | ||
|
|
||
| holder = new TransactionHolder(); | ||
| holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon); | ||
| // holder.imgIcon.setImageResource(apple_pie); | ||
| holder.txtTitle= (TextView)row.findViewById(R.id.txtTitle); | ||
| holder.txtLine= (TextView)row.findViewById(R.id.amount); | ||
|
|
||
| row.setTag(holder); | ||
|
|
||
|
|
||
| } | ||
| else | ||
| { | ||
| holder = (TransactionHolder)row.getTag(); | ||
|
|
||
| } | ||
|
|
||
| Transactions transact = data[position]; | ||
| holder.txtTitle.setText(transact.name); | ||
| holder.imgIcon.setImageResource(apple_pie); | ||
| double amounts = transact.getAmount(); | ||
| holder.txtLine.setText(""+amounts); | ||
|
|
||
| return row; | ||
| //return super.getView(position, convertView, parent); | ||
| } | ||
|
|
||
| static class TransactionHolder | ||
| { | ||
| TextView txtTitle; | ||
| ImageView imgIcon; | ||
| TextView txtLine; | ||
| } | ||
| } |
| @@ -0,0 +1,48 @@ | ||
| package com.example.android.firstapp; | ||
|
|
||
| /** | ||
| * Created by j2md7_000 on 8/21/2017. | ||
| */ | ||
|
|
||
| public class Transactions { | ||
|
|
||
| public double amount; | ||
| public int date; | ||
| public String name; | ||
|
|
||
| public Transactions() | ||
| { | ||
| super(); | ||
| } | ||
|
|
||
| public Transactions (String name, double amount ) | ||
| { | ||
| super(); | ||
| this.amount = amount; | ||
| this.name = name; | ||
| } | ||
|
|
||
| public double getAmount() { | ||
| return amount; | ||
| } | ||
|
|
||
| public void setAmount(double amount) { | ||
| this.amount = amount; | ||
| } | ||
|
|
||
| public int getDate() { | ||
| return date; | ||
| } | ||
|
|
||
| public void setDate(int date) { | ||
| this.date = date; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public void setName(String name) { | ||
| this.name = name; | ||
| } | ||
| } |
| @@ -0,0 +1,52 @@ | ||
| package com.example.android.firstapp; | ||
|
|
||
| import android.app.Activity; | ||
| import android.support.v7.app.AppCompatActivity; | ||
| import android.os.Bundle; | ||
| import android.view.View; | ||
| import android.widget.ArrayAdapter; | ||
| import android.widget.ListAdapter; | ||
| import android.widget.ListView; | ||
| // extends AppCompatActivity | ||
| public class TransactionsList extends Activity { | ||
|
|
||
|
|
||
| private ListView TransListView; | ||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setContentView(R.layout.main); | ||
|
|
||
| /* | ||
| String[] chores = {"rent", "water","MAgic cards","Open house","Cookies"}; | ||
| ListAdapter simpleadapt = new ArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1,chores); | ||
| ListView ChoresLV = (ListView)findViewById(R.id.listView1); | ||
| ChoresLV.setAdapter(simpleadapt); | ||
| */ | ||
|
|
||
|
|
||
| Transactions Transact_items[]=new Transactions[] | ||
| { | ||
| new Transactions("rent", 700), | ||
| new Transactions("Water", 120), | ||
| new Transactions("gas-car",150), | ||
| new Transactions("food",200), | ||
| new Transactions("other",500) | ||
|
|
||
| }; | ||
|
|
||
|
|
||
| TransactionAdapter adapter = new TransactionAdapter(this, | ||
| R.layout.listview_item_row,Transact_items); | ||
|
|
||
| TransListView = (ListView)findViewById(R.id.listView1); | ||
|
|
||
| View header = | ||
| (View)getLayoutInflater().inflate(R.layout.listview_header_row, null); | ||
| TransListView.addHeaderView(header); | ||
| TransListView.setAdapter(adapter); | ||
|
|
||
|
|
||
| } | ||
| } |
| @@ -0,0 +1,9 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| tools:context="com.example.android.firstapp.TransactionsList"> | ||
|
|
||
| </android.support.constraint.ConstraintLayout> |
| @@ -0,0 +1,21 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:orientation="vertical" android:layout_width="match_parent" | ||
| android:layout_height="match_parent"> | ||
|
|
||
|
|
||
| <TextView android:id="@+id/txtHeader" | ||
| android:layout_width="fill_parent" | ||
| android:layout_height="112dp" | ||
| android:gravity="center_vertical" | ||
| android:layout_alignParentTop="true" | ||
| android:layout_alignParentBottom="true" | ||
| android:textStyle="bold" | ||
| android:textSize="22dp" | ||
| android:textColor="#FFFFFF" | ||
| android:padding="10dp" | ||
| android:text="Stuff" | ||
| android:background="#336699" /> | ||
|
|
||
|
|
||
| </LinearLayout> |
| @@ -0,0 +1,45 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:orientation="vertical" android:layout_width="match_parent" | ||
| android:layout_height="match_parent"> | ||
|
|
||
| <ImageView | ||
| android:id="@+id/imgIcon" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="72dp" | ||
| android:layout_alignParentBottom="true" | ||
| android:layout_alignParentTop="true" | ||
| android:layout_marginBottom="5dp" | ||
| android:layout_marginRight="15dp" | ||
| android:layout_marginTop="5dp" | ||
| android:gravity="center_vertical" /> | ||
|
|
||
| <TextView android:id="@+id/txtTitle" | ||
| android:layout_width="fill_parent" | ||
| android:layout_height="65dp" | ||
| android:gravity="center_vertical" | ||
| android:layout_alignParentTop="true" | ||
| android:layout_alignParentBottom="true" | ||
| android:textStyle="bold" | ||
| android:textSize="22dp" | ||
| android:textColor="#000000" | ||
| android:layout_marginTop="5dp" | ||
| android:layout_marginBottom="5dp" /> | ||
|
|
||
| <TextView android:id="@+id/amount" | ||
| android:layout_width="fill_parent" | ||
| android:layout_height="69dp" | ||
| android:gravity="center_vertical" | ||
| android:layout_alignParentTop="true" | ||
| android:layout_alignParentBottom="true" | ||
| android:textStyle="bold" | ||
| android:textSize="22dp" | ||
| android:textColor="#000000" | ||
| android:layout_marginTop="5dp" | ||
| android:layout_marginBottom="5dp" /> | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| </LinearLayout> |
| @@ -0,0 +1,12 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:orientation="vertical" android:layout_width="match_parent" | ||
| android:layout_height="match_parent"> | ||
|
|
||
| <ListView | ||
| android:id="@+id/listView1" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" /> | ||
|
|
||
|
|
||
| </LinearLayout> |