Skip to content

Commit

Permalink
Minor fixes and indentation fix
Browse files Browse the repository at this point in the history
Minor fixes and indentation fix
  • Loading branch information
sharish committed Jan 10, 2017
1 parent f830665 commit ed20fd4
Showing 1 changed file with 54 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,37 +1,74 @@
package com.cooltechworks.creditcarddesign.sample;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.cooltechworks.checkoutflow.R;
import com.cooltechworks.creditcarddesign.CreditCardView;
import com.cooltechworks.creditcarddesign.CardEditActivity;
import com.cooltechworks.creditcarddesign.CreditCardUtils;
import com.cooltechworks.creditcarddesign.CreditCardView;

/**
* Created by glarencezhao on 10/23/16.
*/

public class MainActivity extends AppCompatActivity {

private final int CREATE_NEW_CARD = 0;

private LinearLayout cardContainer;
private Button addCardButton;

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

initialize();
listeners();
}

findViewById(R.id.add_card).setOnClickListener(new View.OnClickListener() {
private void initialize() {
addCardButton = (Button) findViewById(R.id.add_card);
cardContainer = (LinearLayout) findViewById(R.id.card_container);
// getSupportActionBar().setTitle("Payment");
populate();
}

private void populate() {
CreditCardView sampleCreditCardView = new CreditCardView(this);

String name = "Glarence Zhao";
String cvv = "420";
String expiry = "01/18";
String cardNumber = "4242424242424242";

sampleCreditCardView.setCVV(cvv);
sampleCreditCardView.setCardHolderName(name);
sampleCreditCardView.setCardExpiry(expiry);
sampleCreditCardView.setCardNumber(cardNumber);

cardContainer.addView(sampleCreditCardView);
int index = cardContainer.getChildCount() - 1;
addCardListener(index, sampleCreditCardView);
}

private void listeners() {
addCardButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent intent = new Intent(MainActivity.this, CardEditActivity.class);
startActivityForResult(intent, 0);
startActivityForResult(intent, CREATE_NEW_CARD);
}
});
}

private void initListener(final int index, CreditCardView creditCardView) {


private void addCardListener(final int index, CreditCardView creditCardView) {
creditCardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -40,39 +77,32 @@ public void onClick(View v) {
String cardNumber = creditCardView.getCardNumber();
String expiry = creditCardView.getExpiry();
String cardHolderName = creditCardView.getCardHolderName();
String cvv = creditCardView.getCVV();

Intent intent = new Intent(MainActivity.this, CardEditActivity.class);
intent.putExtra(CreditCardUtils.EXTRA_CARD_HOLDER_NAME, cardHolderName);
intent.putExtra(CreditCardUtils.EXTRA_CARD_NUMBER, cardNumber);
intent.putExtra(CreditCardUtils.EXTRA_CARD_EXPIRY, expiry);
intent.putExtra(CreditCardUtils.EXTRA_CARD_CVV, cvv);
intent.putExtra(CreditCardUtils.EXTRA_CARD_SHOW_CARD_SIDE, CreditCardUtils.CARD_SIDE_FRONT);
intent.putExtra(CreditCardUtils.EXTRA_VALIDATE_EXPIRY_DATE, false);

intent.putExtra(CreditCardUtils.EXTRA_VALIDATE_EXPIRY_DATE, true);

startActivityForResult(intent, index);

}
});

}



public void onActivityResult(int reqCode, int resultCode, Intent data) {

if(resultCode == RESULT_OK) {

LinearLayout cardContainer = (LinearLayout) findViewById(R.id.card_container);

if (resultCode == RESULT_OK) {
// Debug.printToast("Result Code is OK", getApplicationContext());

String name = data.getStringExtra(CreditCardUtils.EXTRA_CARD_HOLDER_NAME);
String cardNumber = data.getStringExtra(CreditCardUtils.EXTRA_CARD_NUMBER);
String expiry = data.getStringExtra(CreditCardUtils.EXTRA_CARD_EXPIRY);
String cvv = data.getStringExtra(CreditCardUtils.EXTRA_CARD_CVV);


if(reqCode == 0) {

if (reqCode == CREATE_NEW_CARD) {

CreditCardView creditCardView = new CreditCardView(this);

Expand All @@ -81,14 +111,11 @@ public void onActivityResult(int reqCode, int resultCode, Intent data) {
creditCardView.setCardExpiry(expiry);
creditCardView.setCardNumber(cardNumber);

int index = cardContainer.getChildCount();
cardContainer.addView(creditCardView);
initListener(index, creditCardView);

int index = cardContainer.getChildCount() - 1;
addCardListener(index, creditCardView);


}
else {
} else {

CreditCardView creditCardView = (CreditCardView) cardContainer.getChildAt(reqCode);

Expand All @@ -100,7 +127,6 @@ public void onActivityResult(int reqCode, int resultCode, Intent data) {
}
}


}

}
}

0 comments on commit ed20fd4

Please sign in to comment.