use of com.google.firebase.database.DatabaseReference in project iNGAGE by davis123123.
the class ChatFragment method removeDownvote.
@Override
public void removeDownvote(int p) {
ChatMessageHelper chatMessageHelper = (ChatMessageHelper) chatAdapter.getItem(p);
String chat_key = chatMessageHelper.getMessageID();
DatabaseReference message_root = currPageData.child(chat_key);
// get upvote data
DatabaseReference downvote_count = message_root.child("downvotes");
downvote_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 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 priend by TakoJ.
the class ProfileActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
firebaseAuth = FirebaseAuth.getInstance();
FirebaseUser user = firebaseAuth.getCurrentUser();
mStorageRef = FirebaseStorage.getInstance().getReference();
SharedPreferences sharedPreferences = getSharedPreferences("email", Context.MODE_PRIVATE);
// 유저 uid받기
userUid = sharedPreferences.getString("uid", user.getUid());
// 유저 email(아이디)받기
userEmail = sharedPreferences.getString("email", user.getEmail());
username = usernameFromEmail(user.getEmail());
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference();
if (firebaseAuth.getCurrentUser() == null) {
finish();
startActivity(new Intent(this, LoginActivity.class));
}
// 이 activity가 켜졌을 때 권한설정 물어보기
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.READ_EXTERNAL_STORAGE)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE }, 1);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
// butterknife: view binder , list adapter 할때도 간편한 코드 구현가능
petImage = (ImageView) findViewById(R.id.petImage);
btn_UploadPicture = (Button) findViewById(R.id.btn_UploadPicture);
textViewUserEmail = (TextView) findViewById(R.id.textViewUserEmail);
textViewUserEmail.setText(user.getEmail() + "님의 반려동물");
buttonLogout = (Button) findViewById(R.id.buttonLogout);
buttonLogout.setOnClickListener(this);
petImage = (ImageView) findViewById(R.id.petImage);
btn_UploadPicture = (Button) findViewById(R.id.btn_UploadPicture);
petName = (EditText) findViewById(R.id.petName);
petAge = (EditText) findViewById(R.id.petAge);
radiogroup_gender = (RadioGroup) findViewById(R.id.radiogroup_gender);
radioGender_male = (RadioButton) findViewById(R.id.radioGender_male);
radioGender_female = (RadioButton) findViewById(R.id.radioGender_female);
radiogroup_type = (RadioGroup) findViewById(R.id.radiogroup_type);
radio_dog = (RadioButton) findViewById(R.id.radio_dog);
radio_cat = (RadioButton) findViewById(R.id.radio_cat);
radiogroup_size = (RadioGroup) findViewById(R.id.radiogroup_size);
radioSize_small = (RadioButton) findViewById(R.id.radioSize_small);
radioSize_middle = (RadioButton) findViewById(R.id.radioSize_middle);
radioSize_large = (RadioButton) findViewById(R.id.radioSize_large);
btn_profilefinish = (Button) findViewById(R.id.btn_profilefinish);
btn_UploadPicture.setOnClickListener(this);
btn_profilefinish.setOnClickListener(this);
loadSavedPreferences();
// 원래 사진받아오는 자리
new DownloadImage().execute();
}
use of com.google.firebase.database.DatabaseReference in project priend by TakoJ.
the class disease_searchActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_disease_search);
search = (EditText) findViewById(R.id.search);
final ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1);
listview = (ListView) findViewById(R.id.listview1);
listview.setAdapter(adapter);
for (int i = 1; i < 40; i++) {
// 일단 질병 40개만 받음.
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 name = dataSnapshot.getValue().toString();
adapter.add(name);
} else {
System.out.println("없음");
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
search.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
// text가 바뀔때 수행되는 함수
String filterText = s.toString();
if (filterText.length() > 0) {
// 글자 입력시
listview.setFilterText(filterText);
} else {
listview.clearTextFilter();
}
}
});
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);
}
});
}
use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.
the class UserInformationEditActivity method updateDatabase.
/**
* This method updates the UserInformation object in Firebase associated
* with the user currently logged in.
*/
private void updateDatabase() {
FirebaseDatabase db = FirebaseDatabase.getInstance();
DatabaseReference myRef = db.getReference(getString(R.string.activity_user_information_firebase, user.getUsername()));
myRef.setValue(info);
}
Aggregations