/
viewHistory.java
101 lines (86 loc) · 3.35 KB
/
viewHistory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.LDSdudes.Mormon_Tithing_Calculator;
import java.util.Calendar;
import com.LDSdudes.Mormon_Tithing_Calculator.DatabaseHelper.tithingHistory;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class viewHistory extends Activity {
private ListView myList;
private DatabaseHelper db;
private AlertDialog.Builder queryType;
private LayoutInflater inflater;
private View myView;
private RadioGroup group;
private DatePicker date1;
private DatePicker date2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewhistory);
// ---------------objects---------------
myList = (ListView) findViewById(R.id.listView);
db = new DatabaseHelper(viewHistory.this);
inflater = this.getLayoutInflater();
myView = inflater.inflate(R.layout.querytype, null);
group = (RadioGroup) myView.findViewById(R.id.queryradio);
date1 = (DatePicker) myView.findViewById(R.id.date1);
date2 = (DatePicker) myView.findViewById(R.id.date2);
queryType = new AlertDialog.Builder(this);
queryType.setView(myView);
queryType.setPositiveButton("Find", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
int select = group.getCheckedRadioButtonId();
View tmp = group.findViewById(select);
int idx = group.indexOfChild(tmp);
// Toast.makeText(viewHistory.this, "" + idx, Toast.LENGTH_LONG).show();
switch (idx) {
case 0:
allHistory();
break;
case 1:
Calendar temp = Calendar.getInstance();
temp.set(date1.getYear(), date1.getMonth() + 1, date1.getDayOfMonth());
Long temp1 = temp.getTimeInMillis();
temp.set(date2.getYear(), date2.getMonth() + 1, date2.getDayOfMonth());
Long temp2 = temp.getTimeInMillis();
dateHistory(temp1, temp2);
break;
case -1:
Toast.makeText(viewHistory.this, "Please choose an option.", Toast.LENGTH_LONG).show();
}
}
});
queryType.show();
}
public void allHistory() {
String[] columns = { tithingHistory.colDate, tithingHistory.colTotal };
int[] two = { R.id.date, R.id.total };
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(viewHistory.this, R.layout.tithinglistitem,
db.getAllTithing(), columns, two);
myList.setAdapter(mAdapter);
db.close();
}
public void dateHistory(Long sDate, Long eDate) {
if (eDate > sDate) {
String[] columns = { tithingHistory.colDate, tithingHistory.colTotal };
int[] two = { R.id.date, R.id.total };
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(viewHistory.this, R.layout.tithinglistitem,
db.getTithing(sDate, eDate), columns, two);
myList.setAdapter(mAdapter);
db.close();
}
else
Toast.makeText(viewHistory.this, "Error: Starting date greater than ending date", Toast.LENGTH_LONG).show();
}
}