-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_java_com_example_harsh_freechat_StatusActivity.java
78 lines (66 loc) · 3.01 KB
/
main_java_com_example_harsh_freechat_StatusActivity.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
package com.example.harsh.freechat;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class StatusActivity extends AppCompatActivity {
private Toolbar mToolbar;
private TextInputLayout mStatus;
private Button mSaveBtn;
private DatabaseReference mStatusDatabase;
private FirebaseUser mCurrentUser;
private ProgressDialog mProgress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_status);
mCurrentUser= FirebaseAuth.getInstance().getCurrentUser();
String current_uid=mCurrentUser.getUid();
mStatusDatabase= FirebaseDatabase.getInstance().getReference().child("Users").child(current_uid);
mToolbar=findViewById(R.id.status_appBar);
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("Account Status");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
String status_value=getIntent().getStringExtra("status value");
mStatus=findViewById(R.id.status_input);
mSaveBtn=findViewById(R.id.update_stat_btn);
mStatus.getEditText().setText(status_value);
mSaveBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mProgress=new ProgressDialog(StatusActivity.this);
mProgress.setTitle("Saving Changes");
mProgress.setMessage("Please wait while we save the changes");
mProgress.show();
String status=mStatus.getEditText().getText().toString();
mStatusDatabase.child("status").setValue(status).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful())
{
mProgress.dismiss();
Intent SettingActivity=new Intent(StatusActivity.this,SettingsActivity.class);
startActivity(SettingActivity);
}
else
{
Toast.makeText(getApplicationContext(),"There was some error in saving changes !", Toast.LENGTH_LONG).show();
}
}
});
}
});
}
}