-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsActivity.java
More file actions
115 lines (105 loc) · 4.6 KB
/
SettingsActivity.java
File metadata and controls
115 lines (105 loc) · 4.6 KB
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
package com.example.vhl2.bandapp3;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
/**
* Settings Activity focuses on the UI around the settings tab in the
* app which allows the user to change thier profile such as change there
* name and instrument
*/
public class SettingsActivity extends AppCompatActivity {
private BandMember editMember;
/**
* Method called on the creation of the activity setting it up before
* the user can interact with it
* @param savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
Intent intent = getIntent();
editMember = (BandMember) intent.getSerializableExtra("currentMember");
final EditText editName = (EditText) findViewById(R.id.EditNameText);
final EditText newPassword = (EditText) findViewById(R.id.EditPasswordText);
final EditText repeatPassword = (EditText) findViewById(R.id.EditRepeatPasswordText);
final Spinner sectionSpinner = (Spinner) findViewById(R.id.sectionSpinner);
final Spinner classSpinner = (Spinner) findViewById(R.id.classSpinner);
Button finishButton = findViewById(R.id.updateSettingsButton);
//sets the userName textBox to what they currently have thier name as
editName.setText(editMember.getName());
//sets the instrument spinner to what the user's current instrument is
switch(editMember.getInstrument()) {
case "saxophone":
sectionSpinner.setSelection(0);
break;
case "trumpet":
sectionSpinner.setSelection(1);
break;
case "percussion":
sectionSpinner.setSelection(2);
break;
case "flute":
sectionSpinner.setSelection(3);
break;
case "clarinet":
sectionSpinner.setSelection(4);
break;
case "trombone":
sectionSpinner.setSelection(5);
break;
case "bass":
sectionSpinner.setSelection(6);
break;
case "sousaphone":
sectionSpinner.setSelection(7);
}
//Sets the year spinner to what the user's current year is
switch (editMember.getYear()) {
case "freshman":
classSpinner.setSelection(0);
break;
case "sophomore":
classSpinner.setSelection(1);
break;
case "junior":
classSpinner.setSelection(2);
break;
case "senior":
classSpinner.setSelection(3);
break;
case "director":
classSpinner.setSelection(4);
}
finishButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// this if statement checks if the user edited the password at all and if
// they did edit the password textbox make sure the password and repeatpassword
// boxes are the same. if tha tis the case then change the password
if(!newPassword.getText().toString().equals("")) {
if(!newPassword.getText().toString().equals(repeatPassword.getText().toString())) {
Toast.makeText(SettingsActivity.this, "Passwords do not match",
Toast.LENGTH_SHORT).show();
} else {
editMember.setPassword(newPassword.getText().toString());
}
}
// the rest of this program just updates the profile with the new information
editMember.setName(editName.getText().toString());
editMember.setInstrument(sectionSpinner.getSelectedItem().toString());
editMember.setYear(classSpinner.getSelectedItem().toString());
Intent settingsIntent = new Intent();
settingsIntent.putExtra("changedInfoMember", editMember);
setResult(Activity.RESULT_OK, settingsIntent);
finish();
}
});
}
}