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

Update card view layout #91

Merged
merged 2 commits into from
Feb 12, 2017
Merged
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
64 changes: 41 additions & 23 deletions app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.integration.android.IntentIntegrator;
Expand Down Expand Up @@ -74,9 +75,12 @@ public void onResume()
}
}

final EditText storeField = (EditText) findViewById(R.id.storeName);
final EditText noteField = (EditText) findViewById(R.id.note);
final EditText cardIdField = (EditText) findViewById(R.id.cardId);
final EditText storeFieldEdit = (EditText) findViewById(R.id.storeNameEdit);
final TextView storeFieldView = (TextView) findViewById(R.id.storeNameView);
final EditText noteFieldEdit = (EditText) findViewById(R.id.noteEdit);
final TextView noteFieldView = (TextView) findViewById(R.id.noteView);
final EditText cardIdFieldEdit = (EditText) findViewById(R.id.cardIdEdit);
final TextView cardIdFieldView = (TextView) findViewById(R.id.cardIdView);
final EditText barcodeTypeField = (EditText) findViewById(R.id.barcodeType);
final ImageView barcodeImage = (ImageView) findViewById(R.id.barcode);
final View barcodeIdLayout = findViewById(R.id.barcodeIdLayout);
Expand All @@ -95,35 +99,36 @@ public void onResume()
{
final LoyaltyCard loyaltyCard = db.getLoyaltyCard(loyaltyCardId);

if(storeField.getText().length() == 0)
if(storeFieldEdit.getText().length() == 0)
{
storeField.setText(loyaltyCard.store);
storeFieldEdit.setText(loyaltyCard.store);
storeFieldView.setText(loyaltyCard.store);
}

if(noteField.getText().length() == 0)
if(noteFieldEdit.getText().length() == 0)
{
noteField.setText(loyaltyCard.note);
noteFieldEdit.setText(loyaltyCard.note);
noteFieldView.setText(loyaltyCard.note);
}

if(cardIdField.getText().length() == 0)
if(cardIdFieldEdit.getText().length() == 0)
{
cardIdField.setText(loyaltyCard.cardId);
cardIdFieldEdit.setText(loyaltyCard.cardId);
cardIdFieldView.setText(loyaltyCard.cardId);
}

if(barcodeTypeField.getText().length() == 0)
{
barcodeTypeField.setText(loyaltyCard.barcodeType);
}

if(viewLoyaltyCard)
{
storeField.setEnabled(false);
noteField.setEnabled(false);
}

if(updateLoyaltyCard)
{
setTitle(R.string.editCardTitle);

storeFieldView.setVisibility(View.GONE);
noteFieldView.setVisibility(View.GONE);
cardIdFieldView.setVisibility(View.GONE);
}
else
{
Expand All @@ -132,25 +137,33 @@ public void onResume()
saveButton.setVisibility(View.GONE);
cancelButton.setVisibility(View.GONE);
setTitle(R.string.viewCardTitle);

storeFieldEdit.setVisibility(View.GONE);
noteFieldEdit.setVisibility(View.GONE);
cardIdFieldEdit.setVisibility(View.GONE);
}
}
else
{
setTitle(R.string.addCardTitle);

storeFieldView.setVisibility(View.GONE);
noteFieldView.setVisibility(View.GONE);
cardIdFieldView.setVisibility(View.GONE);
}

if(cardIdField.getText().length() == 0)
if(cardIdFieldEdit.getText().length() == 0)
{
barcodeIdLayout.setVisibility(View.GONE);
}

barcodeTypeLayout.setVisibility(View.GONE);

if(cardIdField.getText().length() > 0 && barcodeTypeField.getText().length() > 0)
if(cardIdFieldEdit.getText().length() > 0 && barcodeTypeField.getText().length() > 0)
{
String formatString = barcodeTypeField.getText().toString();
final BarcodeFormat format = BarcodeFormat.valueOf(formatString);
final String cardIdString = cardIdField.getText().toString();
final String cardIdString = cardIdFieldEdit.getText().toString();

if(barcodeImage.getHeight() == 0)
{
Expand Down Expand Up @@ -218,9 +231,9 @@ public void onClick(View v)
@Override
public void onClick(final View v)
{
String store = storeField.getText().toString();
String note = noteField.getText().toString();
String cardId = cardIdField.getText().toString();
String store = storeFieldEdit.getText().toString();
String note = noteFieldEdit.getText().toString();
String cardId = cardIdFieldEdit.getText().toString();
String barcodeType = barcodeTypeField.getText().toString();

if(store.isEmpty())
Expand Down Expand Up @@ -364,8 +377,13 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent)
Log.i(TAG, "Read barcode id: " + contents);
Log.i(TAG, "Read format: " + format);

final EditText cardIdField = (EditText) findViewById(R.id.cardId);
cardIdField.setText(contents);
for(TextView view : new TextView[]{
(EditText) findViewById(R.id.cardIdEdit),
(TextView) findViewById(R.id.cardIdView)})
{
view.setText(contents);
}

final EditText barcodeTypeField = (EditText) findViewById(R.id.barcodeType);
barcodeTypeField.setText(format);
onResume();
Expand Down
81 changes: 47 additions & 34 deletions app/src/main/res/layout/loyalty_card_view_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,79 +29,92 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:orientation="horizontal"
android:padding="10.0dip"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:textSize="16.0sp"
<TextView android:textSize="@dimen/text_size_medium"
android:textStyle="bold"
android:layout_gravity="center_vertical"
android:paddingStart="20.0dip"
android:paddingEnd="20.0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="20.0dip"
android:paddingEnd="20.0dip"
android:labelFor="@+id/storeName"
android:text="@string/storeName" />
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText android:id="@+id/storeName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"/>
</LinearLayout>
<EditText android:id="@+id/storeNameEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textSize="@dimen/text_size_medium"/>
<TextView android:id="@+id/storeNameView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:textSize="@dimen/text_size_medium"
android:textIsSelectable="true"/>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:padding="10.0dip"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:textSize="16.0sp"
<TextView android:textSize="@dimen/text_size_medium"
android:textStyle="bold"
android:layout_gravity="center_vertical"
android:paddingStart="20.0dip"
android:paddingEnd="20.0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="20.0dip"
android:paddingEnd="20.0dip"
android:labelFor="@+id/note"
android:text="@string/note" />
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText android:id="@+id/note"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"/>
</LinearLayout>
<EditText android:id="@+id/noteEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textSize="@dimen/text_size_medium"/>
<TextView android:id="@+id/noteView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:textSize="@dimen/text_size_medium"
android:textIsSelectable="true"/>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:padding="10.0dip"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/barcodeIdLayout">
<TextView android:textSize="16.0sp"
<TextView android:textSize="@dimen/text_size_medium"
android:textStyle="bold"
android:layout_gravity="center_vertical"
android:paddingStart="20.0dip"
android:paddingEnd="20.0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="20.0dip"
android:paddingEnd="20.0dip"
android:labelFor="@+id/cardId"
android:text="@string/cardId" />
<EditText android:id="@+id/cardId"
<EditText android:id="@+id/cardIdEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:inputType="text"/>
android:inputType="text"
android:textSize="@dimen/text_size_medium"/>
<TextView android:id="@+id/cardIdView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:textSize="@dimen/text_size_medium"
android:textIsSelectable="true"/>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:padding="10.0dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/barcodeTypeLayout">
<TextView android:textSize="16.0sp"
<TextView android:textSize="@dimen/text_size_medium"
android:textStyle="bold"
android:layout_gravity="center_vertical"
android:paddingStart="20.0dip"
android:paddingEnd="20.0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:labelFor="@+id/barcodeType"
Expand Down
Loading