use of com.google.firebase.database.DatabaseException in project iosched by google.
the class SessionDetailModel method initReservationListeners.
public void initReservationListeners() {
FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
if (currentUser != null) {
mQueueReference = getQueueReference(currentUser.getUid());
mSessionReservationStatusReference = getReservationStatusReference(currentUser.getUid(), mSessionId);
mSessionReservationResultReference = getReservationResultsReference(currentUser.getUid(), mSessionId);
mSeatAvailabilityReference = getSeatAvailabilityReference(mSessionId);
mSessionReservationStatusEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
try {
String reservationStatus = dataSnapshot.getValue(String.class);
if (reservationStatus != null) {
mReservationStatus = reservationStatus;
mSessionsHelper.setReservationStatus(mSessionUri, ScheduleContract.MyReservations.fromFirebaseString(mReservationStatus), mTitle);
final DataQueryCallback<SessionDetailQueryEnum> reservationStatusCallback = mDataQueryCallbacks.get(RESERVATION_STATUS);
reservationStatusCallback.onModelUpdated(SessionDetailModel.this, RESERVATION_STATUS);
}
} catch (DatabaseException e) {
LOGE(TAG, e.getMessage());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
LOGE(TAG, databaseError.getMessage());
}
};
mSessionReservationResultEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
try {
String reservationResult = dataSnapshot.getValue(String.class);
if (reservationResult != null) {
mReservationResult = reservationResult;
DataQueryCallback<SessionDetailQueryEnum> reservationResultCallback = mDataQueryCallbacks.get(RESERVATION_RESULT);
reservationResultCallback.onModelUpdated(SessionDetailModel.this, RESERVATION_RESULT);
mSessionReservationResultReference.removeEventListener(this);
}
} catch (DatabaseException e) {
LOGE(TAG, e.getMessage());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
LOGE(TAG, databaseError.getMessage());
}
};
mQueueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
try {
DataQueryCallback<SessionDetailQueryEnum> reservationPendingCallback = mDataQueryCallbacks.get(RESERVATION_PENDING);
QueueAction queueAction = dataSnapshot.getValue(QueueAction.class);
if (queueAction == null) {
LOGD(TAG, "Exit queue");
mReturnPending = false;
mReservationPending = false;
mQueueReference.removeEventListener(this);
reservationPendingCallback.onModelUpdated(SessionDetailModel.this, RESERVATION_PENDING);
}
} catch (DatabaseException e) {
LOGE(TAG, e.getMessage());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
LOGE(TAG, databaseError.getMessage());
}
};
mSeatAvailabilityEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
DataQueryCallback<SessionDetailQueryEnum> seatAvailabilityCallback = mDataQueryCallbacks.get(RESERVATION_SEAT_AVAILABILITY);
Boolean seatsAvailable = dataSnapshot.getValue(Boolean.class);
if (seatsAvailable != null) {
mSeatsAvailable = seatsAvailable;
seatAvailabilityCallback.onModelUpdated(SessionDetailModel.this, RESERVATION_SEAT_AVAILABILITY);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
LOGE(TAG, databaseError.getMessage());
}
};
mSessionReservationStatusReference.addValueEventListener(mSessionReservationStatusEventListener);
mSeatAvailabilityReference.addValueEventListener(mSeatAvailabilityEventListener);
} else {
LOGD(TAG, "Not signed in.");
invalidateReservationCache();
DataQueryCallback<SessionDetailQueryEnum> authCallback = mDataQueryCallbacks.get(AUTH_REGISTRATION);
authCallback.onModelUpdated(SessionDetailModel.this, AUTH_REGISTRATION);
}
}
use of com.google.firebase.database.DatabaseException in project BloodHub by kazijehangir.
the class RequestDetail method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_request_detail);
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
setTitle("Donate blood");
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if (extras == null) {
request = null;
} else {
request = extras.getString("request");
}
}
db = FirebaseDatabase.getInstance().getReference().child("donations");
if (request != null && !request.isEmpty()) {
FirebaseDatabase.getInstance().getReference().child("bloodrequests").child(request).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
BloodRequest data = dataSnapshot.getValue(BloodRequest.class);
TextView mName = (TextView) findViewById(R.id.request_detail_name);
mName.setText(data.name);
TextView mNeeds = (TextView) findViewById(R.id.request_detail_needs);
mNeeds.setText(data.quantity + " bags of " + data.blood_group);
TextView mLocation = (TextView) findViewById(R.id.request_detail_location);
mLocation.setText(data.location);
TextView mWhen = (TextView) findViewById(R.id.request_detail_when);
String date = DateFormat.getDateInstance().format(new Date(data.date));
mWhen.setText(date);
if (date.equals(DateFormat.getDateInstance().format(new Date()))) {
mWhen.setText("URGENT");
mWhen.setTextColor(0xFFFF0000);
}
TextView mDiagnosis = (TextView) findViewById(R.id.request_detail_diagnosis);
mDiagnosis.setText(data.diagnosis);
TextView mTransport = (TextView) findViewById(R.id.request_detail_transport);
if (data.transport) {
mTransport.setText("Available");
} else {
mTransport.setText("Not Available");
}
if (user.getUid().equals(data.userid)) {
isOwnRequest = true;
setTitle("Request Info");
Button donate = (Button) findViewById(R.id.request_detail_donate_button);
donate.setText("Open in My Requests");
donate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), MyRequestDetail.class);
intent.putExtra("request", request);
view.getContext().startActivity(intent);
}
});
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else {
Toast.makeText(getApplicationContext(), "Error loading request", Toast.LENGTH_SHORT).show();
finish();
}
Button donate = (Button) findViewById(R.id.request_detail_donate_button);
if (!isOwnRequest) {
donate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Context context = getApplicationContext();
Donation donation = new Donation(user.getUid(), request);
try {
db.push().setValue(donation);
dialog = new Dialog(RequestDetail.this);
dialog.setTitle("Donation Confirmed");
dialog.setContentView(R.layout.popup_request_detail);
dialog.show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
final Button submit = (Button) dialog.findViewById(R.id.request_detail_dialog_ok);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
} catch (DatabaseException e) {
Toast.makeText(context, "Error occurred", Toast.LENGTH_SHORT).show();
}
}
});
}
}
use of com.google.firebase.database.DatabaseException in project BloodHub by kazijehangir.
the class AddDonorActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
mEmail = user.getEmail();
// INITIALIZE FIREBASE DB
db = FirebaseDatabase.getInstance().getReference().child("donors");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_donor);
setTitle("Add Donor");
name = (AutoCompleteTextView) findViewById(R.id.name);
bloodgroup = (Spinner) findViewById(R.id.spin);
age = (EditText) findViewById(R.id.age);
number = (EditText) findViewById(R.id.editText2);
address = (EditText) findViewById(R.id.editText3);
donorOrigin = (EditText) findViewById(R.id.editText4);
lastDonated = (EditText) findViewById(R.id.editText);
final EditText set = (EditText) findViewById(R.id.editText);
set.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(AddDonorActivity.this);
builder.setTitle("Last donated");
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (options[which] == "Set date") {
final Dialog dialog1;
dialog1 = new Dialog(AddDonorActivity.this);
dialog1.setTitle("Set Date and Time");
dialog1.setContentView(R.layout.set_date);
dialog1.show();
final Button setDate = (Button) dialog1.findViewById(R.id.set_date);
final DatePicker datePicker = (DatePicker) dialog1.findViewById(R.id.datePicker);
setDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
date = datePicker.getDayOfMonth();
month = datePicker.getMonth();
year = datePicker.getYear();
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, date);
pdate = calendar.getTime();
String date = DateFormat.getDateInstance().format(pdate);
set.setText(date);
dialog1.cancel();
}
});
} else {
set.setText("Never");
}
}
});
builder.show();
}
});
Button addDonor = (Button) findViewById(R.id.add_donor);
addDonor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Context context = getApplicationContext();
dName = name.getText().toString();
dBloodgroup = bloodgroup.getSelectedItem().toString();
dAge = age.getText().toString();
dNumber = number.getText().toString();
dAddress = address.getText().toString();
ddonorOrigin = donorOrigin.getText().toString();
dLastDonated = lastDonated.getText().toString();
View focusView = null;
if (TextUtils.isEmpty(dName)) {
name.setError("Name cannot be empty");
focusView = name;
} else if (TextUtils.isEmpty(dNumber)) {
number.setError("Number cannot be empty");
} else {
Donor donor = new Donor(user.getUid(), dName, dBloodgroup, dNumber, dAddress, dLastDonated, ddonorOrigin, dAge);
try {
db.push().setValue(donor);
dialog = new Dialog(AddDonorActivity.this);
dialog.setTitle("Add Donor");
dialog.setContentView(R.layout.popup_donor);
dialog.show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
final Button submit = (Button) dialog.findViewById(R.id.button_ok);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(AddDonorActivity.this, MainActivityOrg.class);
startActivity(intent);
}
});
} catch (DatabaseException e) {
Toast.makeText(context, "Error occurred", Toast.LENGTH_SHORT).show();
}
}
// else if(dBloodgroup) {
// bloodgroup.setError("Blood group can not be empty");
// }
}
});
}
use of com.google.firebase.database.DatabaseException in project BloodHub by kazijehangir.
the class AddPatientActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
mEmail = user.getEmail();
// INITIALIZE FIREBASE DB
db = FirebaseDatabase.getInstance().getReference().child("patients");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_patient);
setTitle("Add Patient");
name = (AutoCompleteTextView) findViewById(R.id.name);
age = (EditText) findViewById(R.id.age);
bloodgroup = (Spinner) findViewById(R.id.spin);
number = (EditText) findViewById(R.id.contact_num);
diagnosis = (Spinner) findViewById(R.id.diagnosis);
Button submit = (Button) findViewById(R.id.add_patient);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Context context = getApplicationContext();
pname = name.getText().toString();
a = age.getText().toString();
bgroup = bloodgroup.getSelectedItem().toString();
diag = diagnosis.getSelectedItem().toString();
num = number.getText().toString();
Patient pat = new Patient(user.getUid(), pname, a, bgroup, num, diag);
try {
db.push().setValue(pat);
dialog = new Dialog(AddPatientActivity.this);
dialog.setTitle("Add Patient");
dialog.setContentView(R.layout.popup_patient);
dialog.show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
final Button submit = (Button) dialog.findViewById(R.id.button_ok);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(AddPatientActivity.this, MainActivityOrg.class);
startActivity(intent);
}
});
} catch (DatabaseException e) {
Toast.makeText(context, "Error occurred", Toast.LENGTH_SHORT).show();
}
}
});
}
use of com.google.firebase.database.DatabaseException in project iosched by google.
the class FeedPresenter method initializeDataListener.
@Override
public void initializeDataListener(DatabaseReference databaseReference) {
if (mEventListener == null) {
mEventListener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
try {
FeedMessage feedMessage = dataSnapshot.getValue(FeedMessage.class);
mView.addFeedMessage(feedMessage);
} catch (DatabaseException e) {
mView.showErrorMessage();
LOGE(TAG, "Firebase error - " + e);
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
try {
FeedMessage feedMessage = dataSnapshot.getValue(FeedMessage.class);
mView.updateFeedMessage(feedMessage);
} catch (DatabaseException e) {
mView.showErrorMessage();
LOGE(TAG, "Firebase error - " + e);
}
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
try {
FeedMessage feedMessage = dataSnapshot.getValue(FeedMessage.class);
mView.removeFeedMessage(feedMessage);
} catch (DatabaseException e) {
mView.showErrorMessage();
LOGE(TAG, "Firebase error - " + e);
}
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
try {
FeedMessage feedMessage = dataSnapshot.getValue(FeedMessage.class);
mView.updateFeedMessage(feedMessage);
} catch (DatabaseException e) {
mView.showErrorMessage();
LOGE(TAG, "Firebase error - " + e);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
mView.showErrorMessage();
}
};
}
databaseReference.addChildEventListener(mEventListener);
}
Aggregations