use of com.google.firebase.database.DatabaseReference in project iNGAGE by davis123123.
the class ChatFragment method onUpvoteClick.
@Override
public void onUpvoteClick(int p) {
// Log.d("vote" , "up : ");
// get correct chat msg with ith key from chatmessage helper
ChatMessageHelper chatMessageHelper = (ChatMessageHelper) chatAdapter.getItem(p);
String chat_key = chatMessageHelper.getMessageID();
DatabaseReference message_root = currPageData.child(chat_key);
// get upvote data
DatabaseReference upvote_count = message_root.child("upvotes");
upvote_count.runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(MutableData currentData) {
Log.d("Data", String.valueOf(currentData));
if (currentData.getValue() == null) {
currentData.setValue(1);
} else {
currentData.setValue((Long) currentData.getValue() + 1);
}
// we can also abort by calling Transaction.abort()
return Transaction.success(currentData);
}
// TODO:Error handle here
@Override
public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
}
});
}
use of com.google.firebase.database.DatabaseReference in project iNGAGE by davis123123.
the class ChatFragment method removeUpvote.
@Override
public void removeUpvote(int p) {
ChatMessageHelper chatMessageHelper = (ChatMessageHelper) chatAdapter.getItem(p);
String chat_key = chatMessageHelper.getMessageID();
DatabaseReference message_root = currPageData.child(chat_key);
// get upvote data
DatabaseReference upvote_count = message_root.child("upvotes");
upvote_count.runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(MutableData currentData) {
Log.d("Data", String.valueOf(currentData));
if (currentData.getValue() == null) {
currentData.setValue(0);
} else {
currentData.setValue((Long) currentData.getValue() - 1);
}
// we can also abort by calling Transaction.abort()
return Transaction.success(currentData);
}
// TODO:Error handle here
@Override
public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
}
});
}
use of com.google.firebase.database.DatabaseReference in project iNGAGE by davis123123.
the class ChatActivity method insertComment.
private void insertComment(final String messageBy, final String messageText) {
Log.d("PAGELIMIT", " " + page_root);
temp_key = page_root.push().getKey();
DatabaseReference message_root = page_root.child(temp_key);
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
Map<String, Object> map_message = new HashMap<String, Object>();
map_message.put("Username", messageBy);
map_message.put("Msg", messageText);
map_message.put("Side", user_side);
map_message.put("upvotes", 0);
map_message.put("downvotes", 0);
map_message.put("TimeStamp", currentDateTimeString);
message_root.updateChildren(map_message);
}
use of com.google.firebase.database.DatabaseReference in project priend by TakoJ.
the class disease_detail method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_disease_detail);
TextView name = (TextView) findViewById(R.id.disease_name);
final TextView define = (TextView) findViewById(R.id.define);
final TextView condition = (TextView) findViewById(R.id.condition);
final TextView cause = (TextView) findViewById(R.id.cause);
Intent intent = getIntent();
name.setText(intent.getStringExtra("name"));
final String names = name.getText().toString();
for (int i = 1; i < 40; i++) {
final String num = Integer.toString(i);
FirebaseDatabase database = FirebaseDatabase.getInstance();
final DatabaseReference myRef = database.getReference().child("diseases").child(num);
myRef.child("diease_name").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
String disease_name = dataSnapshot.getValue().toString();
if (disease_name.equals(names)) {
myRef.child("define").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String disease_define = dataSnapshot.getValue().toString();
define.setText(disease_define);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
myRef.child("condition").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String disease_condition1 = dataSnapshot.getValue().toString();
String disease_condition2 = disease_condition1.replace("[", "");
String disease_condition3 = disease_condition2.replace("],", "\n");
String disease_condition = disease_condition3.replace("]]", "");
condition.setText(disease_condition);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
myRef.child("cause").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String disease_cause = dataSnapshot.getValue().toString();
cause.setText(disease_cause);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return;
}
;
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
use of com.google.firebase.database.DatabaseReference in project priend by TakoJ.
the class disease_listActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_disease_list);
ArrayList<String> getserver = getIntent().getExtras().getStringArrayList("selects");
final ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1);
listview = (ListView) findViewById(R.id.diseaseView);
listview.setAdapter(adapter);
DatabaseReference database = FirebaseDatabase.getInstance().getReference();
for (final String str : getserver) {
for (int i = 0; i < 40; i++) {
final String num = Integer.toString(i);
final DatabaseReference mDatabase = database.child("diseases").child(num);
mDatabase.child("condition").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
String disease_condition = dataSnapshot.getValue().toString();
if (disease_condition.contains(str)) {
mDatabase.child("diease_name").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String name = dataSnapshot.getValue().toString();
adapter.add(name);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// listview의 item클릭시 detail로 넘어가기
Intent intent = new Intent(getApplicationContext(), disease_detail.class);
// intent객체에 데이터를 실어서 보내기
String disease_name = ((TextView) view).getText().toString();
intent.putExtra("name", disease_name);
startActivity(intent);
}
});
}
Aggregations