-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddPointsActivity.java
200 lines (178 loc) · 7.89 KB
/
AddPointsActivity.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package com.example.vhl2.bandapp3;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.GridLayout;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
/**
* This activity deals with when an admin wants to add points to certain bandmembers
* and all functions associated with that
*/
public class AddPointsActivity extends AppCompatActivity {
private DataSnapshot dataSnapshot;
private DatabaseReference myRoster;
private List<BandMember> userList;
private List<CheckBox> userUI;
private static String TAG = "AddPointsActivity";
GridLayout gridLayout;
ScrollView scrollView;
Spinner pointSpinner;
EditText otherAmount;
/**
* Deals with when this activity is creted
* @param savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_add_points);
Intent intent = getIntent();
myRoster = FirebaseDatabase.getInstance().getReference("Users");
//This creates the list of users in the form of checkboxes to make it easier
// for the user
myRoster.addValueEventListener(new ValueEventListener() {
GridLayout.Spec rowSpec;
GridLayout.Spec colSpec;
GridLayout.LayoutParams layoutParams;
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
int k = 0;
userList = new ArrayList<>();
userUI = new ArrayList<>();
if(userList.size() == 0 && userUI.size() == 0) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
for(DataSnapshot snapshot : postSnapshot.getChildren()) {
userList.add(snapshot.getValue(BandMember.class));
Log.d(TAG, "onDataChange: " + userList.toString());
userUI.add(new CheckBox(AddPointsActivity.this));
rowSpec = GridLayout.spec(k + 2, GridLayout.FILL);
colSpec = GridLayout.spec(0, 2);
layoutParams = new GridLayout.LayoutParams(rowSpec, colSpec);
userUI.get(k).setLayoutParams(layoutParams);
userUI.get(k).setText(userList.get(k).getName());
gridLayout.addView(userUI.get(k));
k++;
}
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
gridLayout = new GridLayout(this);
gridLayout.setColumnCount(2);
gridLayout.setBackgroundColor(Color.WHITE);
GridLayout.Spec rowSpec = GridLayout.spec(0, GridLayout.FILL);
GridLayout.Spec colSpec = GridLayout.spec(0, GridLayout.FILL);
GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(rowSpec, colSpec);
scrollView = new ScrollView(this);
scrollView.setBackgroundColor(Color.TRANSPARENT);
TextView pointText = new TextView(this);
pointText.setText("Select Point Value");
pointText.setLayoutParams(layoutParams);
pointText.setTextSize(20);
pointText.setTextColor(Color.BLACK);
gridLayout.addView(pointText);
//This creates the dropdown list for what type of point value you are going for
// men's game is 7, women's game is 14, other is an amount you enter yourself
pointSpinner = new Spinner(this);
List<String> pointSpinnerList = new ArrayList<>();
pointSpinnerList.add("Men's Game");
pointSpinnerList.add("Women's Game");
pointSpinnerList.add("Other");
ArrayAdapter<String> pointAdapter = new ArrayAdapter<String>(this, android.R.layout.activity_list_item, android.R.id.text1, pointSpinnerList);
pointSpinner.setAdapter(pointAdapter);
gridLayout.addView(pointSpinner);
TextView otherText = new TextView(this);
otherText.setTextColor(Color.BLACK);
otherText.setText("If Other Enter Amount");
otherText.setTextSize(20);
gridLayout.addView(otherText);
//aformentioned place where you enter the amount for other
otherAmount = new EditText(this);
otherAmount.setHint("# of Points");
otherAmount.setTextColor(Color.BLACK);
otherAmount.setTextSize(20);
rowSpec = GridLayout.spec(1);
colSpec = GridLayout.spec(1, GridLayout.FILL);
layoutParams = new GridLayout.LayoutParams(rowSpec, colSpec);
otherAmount.setLayoutParams(layoutParams);
otherAmount.setInputType(Configuration.KEYBOARD_12KEY);
gridLayout.addView(otherAmount);
scrollView.addView(gridLayout);
setContentView(scrollView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.pointsmenu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int menuId = item.getItemId();
switch (menuId) {
case R.id.selectAll:
//clicking this menu button selects all the users
//causing every member to have thier spot checked
for(int k = 0; k < userUI.size(); k++) {
userUI.get(k).setChecked(true);
}
return true;
case R.id.deSelectAll:
//opposite of the one above this deselects all the members you
// have currently selected
for(int k = 0; k < userUI.size(); k++) {
userUI.get(k).setChecked(false);
}
return true;
case R.id.addPoints:
//When the admin is done selecting who gets points they click this
// button and thus points are added t othe user
int points;
switch(pointSpinner.getSelectedItemPosition()) {
case 0:
points = 7;
break;
case 1:
points = 14;
break;
case 2:
points = Integer.parseInt(otherAmount.getText().toString());
break;
default:
points = 0;
}
for(int k = 0; k < userUI.size(); k++) {
if(userUI.get(k).isChecked()) {
userList.get(k).addPoints(points);
myRoster.child(userList.get(k).getInstrument()).child(userList.get(k).getUserName()).setValue(userList.get(k));
}
}
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}