Skip to content

Commit

Permalink
Rodyti papildomą prekės informaciją
Browse files Browse the repository at this point in the history
  • Loading branch information
ViliusKraujutis committed Mar 29, 2014
1 parent d5656ca commit 6c28fd6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,4 @@ Nuskenuotų prekių sąrašą vis atnaujinti įrašais duomenų bazėje
* Išsaugoti prekės informaciją į DB.
* Atvaizduoti prekės informaciją sąraše. [Pasikeitimai](https://github.com/gdgvilnius/MaistoBankas/commit/6d6b171d3642c0aeb5e6c9ecc5a5b81b1bfa146b)
* Parodyti prekės paveiksliuką. Pasiskaitykite apie [Picasso](http://square.github.io/picasso/).
* Rodyti papildomą prekės informaciją.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.google.common.base.Joiner;
import com.squareup.picasso.Picasso;

import java.sql.SQLException;
Expand Down Expand Up @@ -54,15 +55,27 @@ public View getView(int position, View convertView, ViewGroup parent) {
convertView = LayoutInflater.from(context).inflate(R.layout.row_scanned_item, parent, false);
}

final TextView barcodeView = (TextView) convertView.findViewById(R.id.row_scanned_item_barcode);
final TextView titleView = (TextView) convertView.findViewById(R.id.row_scanned_item_title);
final TextView barcodeView = (TextView) convertView.findViewById(R.id.row_scanned_item_barcode);
final TextView infoView = (TextView) convertView.findViewById(R.id.row_scanned_item_info);
final ImageView photoView = (ImageView) convertView.findViewById(R.id.row_scanned_item_photo);
final ScannedItem scannedItem = getItem(position);
try {
final Item item = dbHelper.getItemDao().queryForId(scannedItem.getBarcode());
if (item != null) {
titleView.setText(item.getTitle());
Picasso.with(context).load(item.getPhotoUrl()).into(photoView);

final double price = item.getPrice();
final double discount = item.getDiscount();
final boolean isDiscount = item.isDiscount();
String[] infoArray = new String[]{
item.getAmount(),
price > 0 ? price + " Lt" : null,
isDiscount ? String.format("-%.2f Lt", discount) : null
};
final String info = Joiner.on("; ").skipNulls().join(infoArray);
infoView.setText(info);
}
} catch (SQLException e) {
e.printStackTrace();
Expand Down
22 changes: 19 additions & 3 deletions app/src/main/res/layout/row_scanned_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,43 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:gravity="center_vertical">

<ImageView
android:id="@+id/row_scanned_item_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="@dimen/image_size"
android:layout_height="@dimen/image_size"
android:scaleType="centerInside"
android:padding="@dimen/padding_smaller"
tools:src="@drawable/ic_launcher" />

<TextView
android:id="@+id/row_scanned_item_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/row_scanned_item_photo"
android:textStyle="bold"
android:padding="@dimen/padding_smaller"
android:textSize="@dimen/text_large"
tools:text="Milka" />

<TextView
android:id="@+id/row_scanned_item_barcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/row_scanned_item_photo"
android:padding="@dimen/padding_smaller"
android:layout_below="@+id/row_scanned_item_title"
tools:text="123412341234" />

<TextView
android:id="@+id/row_scanned_item_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/row_scanned_item_photo"
android:padding="@dimen/padding_smaller"
android:layout_below="@+id/row_scanned_item_barcode"
tools:text="100 g; 2.65 Lt; -0.25 Lt" />

</RelativeLayout>
14 changes: 14 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,19 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>


<dimen name="padding_smaller">4dp</dimen>
<dimen name="padding_small">8dp</dimen>
<dimen name="padding_normal">12dp</dimen>
<dimen name="padding_large">16dp</dimen>
<dimen name="padding_larger">20dp</dimen>

<dimen name="image_size">96dp</dimen>

<dimen name="text_small">10dp</dimen>
<dimen name="text_smaller">12dp</dimen>
<dimen name="text_normal">14dp</dimen>
<dimen name="text_large">18dp</dimen>
<dimen name="text_larger">22dp</dimen>
</resources>

0 comments on commit 6c28fd6

Please sign in to comment.