use of com.teamplantpower.team_plant_power.Message in project Team-Plant-Power by Alexander1994.
the class MessageBoardActivity method onCreate.
/**
* Called on the creation of the Message Board activity, iniates login listener and display listener
* @param savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message_board);
enterInput = (EditText) findViewById(R.id.EnterName);
nameText = (TextView) findViewById(R.id.Name);
submit = (Button) findViewById(R.id.Submit);
// Load User if signed up
userDbRef.orderByKey().equalTo(User.getId(getApplicationContext())).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot != null && dataSnapshot.getValue() != null) {
String name = dataSnapshot.child(User.getId(getApplicationContext())).getValue(String.class);
u = new User(name);
nameText.setText(u.getName());
enterInput.setText("Enter Message");
loggedIn = true;
} else {
u = null;
nameText.setText(" ");
enterInput.setText("Enter Name");
loggedIn = false;
}
}
public void onCancelled(DatabaseError err) {
}
});
// Populate message list
messageListView = (ListView) findViewById(R.id.List);
// Set up the List View
firebaseAdapter = new FirebaseListAdapter<Message>(this, Message.class, android.R.layout.simple_list_item_1, messageDbRef) {
@Override
protected void populateView(View v, Message model, int position) {
TextView contactName = (TextView) v.findViewById(android.R.id.text1);
String dateStr = firebaseAdapter.getRef(position).getKey();
contactName.setText(model.getFullDisplayMessage(dateStr));
}
};
messageListView.setAdapter(firebaseAdapter);
}
use of com.teamplantpower.team_plant_power.Message in project Team-Plant-Power by Alexander1994.
the class MessageBoardActivity method setInput.
/**
* Sets name for login or message to send depending on whether the user has set a name or not, View param required for generating key attached to name in DB
* @param v
*/
public void setInput(View v) {
String input = enterInput.getText().toString();
Date date = new Date();
if (loggedIn) {
Message m = new Message(u.getName(), input);
messageDbRef.child(Message.createMsgKey()).setValue(m.toMap());
} else {
// add user to DB
userDbRef.child(User.getId(getApplicationContext())).setValue(input);
}
}
Aggregations