Refactored Donate
The Donate activity can now be completely refactored to make use of the Base class.
1. public class Donate extends Base
2. {
3. private RadioGroup paymentMethod;
4. private ProgressBar progressBar;
5. private NumberPicker amountPicker;
6. private TextView amountText;
7. private TextView amountTotal;
9. @Override
10. protected void onCreate(Bundle savedInstanceState)
11. {
12. super.onCreate(savedInstanceState);
13. setContentView(R.layout.activity_donate);
15. paymentMethod = (RadioGroup) findViewById(R.id.paymentMethod);
16. progressBar = (ProgressBar) findViewById(R.id.progressBar);
17. amountPicker = (NumberPicker) findViewById(R.id.amountPicker);
18. amountText = (TextView) findViewById(R.id.amountText);
19. amountTotal = (TextView) findViewById(R.id.amountTotal);
21. amountPicker.setMinValue(0);
22. amountPicker.setMaxValue(1000);
23. progressBar.setMax(target);
24. }
26. public void donateButtonPressed (View view)
27. {
28. String method = paymentMethod.getCheckedRadioButtonId() == R.id.PayPal ? "PayPal" : "Direct";
29. int donatedAmount = amountPicker.getValue();
30. if (donatedAmount == 0)
31. {
32. String text = amountText.getText().toString();
33. if (!text.equals(""))
34. donatedAmount = Integer.parseInt(text);
35. }
36. if (donatedAmount > 0)
37. {
38. newDonation(new Donation(donatedAmount, method));
39. progressBar.setProgress(totalDonated);
40. String totalDonatedStr = "$" + totalDonated;
41. amountTotal.setText(totalDonatedStr);
42. }
43. }
44. }
Replace your version with this and execute it - fix any missing import statements necessary.
Look carefully at the changes to this version over the previous attempt.
