-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatusActivity.java
117 lines (76 loc) · 3.43 KB
/
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
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
package org.colibrisoft.colibri;
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.Menu;
import android.view.MenuItem;
import android.view.View;
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 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 = (Toolbar) findViewById(R.id.status_appBar);
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("Your Status");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
String status_value = getIntent().getStringExtra("status_value");
mStatus = (TextInputLayout) findViewById(R.id.status_input);
mStatus.getEditText().setText(status_value);
mStatus.getEditText().setCursorVisible(true);
mStatus.getEditText().setSelection(mStatus.getEditText().length());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_tick_btn, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
if (item.getItemId() == R.id.action_settings){
mProgress = new ProgressDialog(StatusActivity.this);
mProgress.setMessage("Uploading...");
mProgress.setCanceledOnTouchOutside(false);
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();
} else {
Toast.makeText(getApplicationContext(), "Your changes were not saved. Please try later.", Toast.LENGTH_SHORT).show();
}
}
});
}
return true;
}
}