-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofileActivity.java
135 lines (95 loc) · 4.27 KB
/
profileActivity.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
package com.example.vinayak.vinu;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class profileActivity extends AppCompatActivity {
private DatabaseReference ref,current_user_db;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private EditText pNameField,pClassField;
private Button pSaveChangeBtn,pHomebtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
pNameField = (EditText)findViewById(R.id.pname_field);
pClassField = (EditText)findViewById(R.id.pclass_field);
pSaveChangeBtn = (Button) findViewById(R.id.psave_change_btn);
pHomebtn = (Button) findViewById(R.id.phome_btn);
ref = FirebaseDatabase.getInstance().getReference().child("Users");
mAuth = FirebaseAuth.getInstance();
/*mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if(firebaseAuth.getCurrentUser() != null)
{
String user_id = mAuth.getCurrentUser().getUid();
current_user_db = ref.child(user_id);
}
}
};
/*protected void onStart()
{
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}*/
pHomebtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(profileActivity.this, AccountActivity.class));
}
});
pSaveChangeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String user_id = mAuth.getCurrentUser().getUid();
current_user_db = ref.child(user_id);
String name, clas;
name = pNameField.getText().toString();
clas = pClassField.getText().toString();
/* if(TextUtils.isEmpty(name))
current_user_db.child("class").setValue(clas);
else if(TextUtils.isEmpty(clas))
current_user_db.child("name").setValue(name);
else
{
current_user_db.child("class").setValue(clas);
current_user_db.child("name").setValue(name);
}*/
if(TextUtils.isEmpty(name) && TextUtils.isEmpty(clas))
{
Toast.makeText(profileActivity.this, "Empty Fields", Toast.LENGTH_SHORT).show();
}
else if(TextUtils.isEmpty(name))
{
current_user_db.child("class").setValue(clas);
Intent mainIntent = new Intent(profileActivity.this, AccountActivity.class);
startActivity(mainIntent);
}
else if(TextUtils.isEmpty(clas))
{
current_user_db.child("name").setValue(name);
Intent mainIntent = new Intent(profileActivity.this, AccountActivity.class);
startActivity(mainIntent);
}
else
{
current_user_db.child("class").setValue(clas);
current_user_db.child("name").setValue(name);
Intent mainIntent = new Intent(profileActivity.this, AccountActivity.class);
startActivity(mainIntent);
}
//Intent mainIntent = new Intent(profileActivity.this, AccountActivity.class);
//startActivity(mainIntent);
}
});
}
}