use of com.hci.carebase.data.datasource.LocalCacheDb in project Carebase by robertsimoes.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/**
* Set Toolbar
*/
Toolbar myToolbar = (Toolbar) findViewById(R.id.general_fragments_toolbar);
setSupportActionBar(myToolbar);
ILocalCache cache = new LocalCacheDb(this);
String userId = cache.getUserId();
boolean isFirstInstall = cache.isFirstInstall();
if (isFirstInstall) {
cache.setFirstInstall(false);
startActivity(new Intent(this, IntroActivity.class));
}
/* Get Patient Info */
src.getPatient(userId, new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Toast.makeText(MainActivity.this, "Welcome Back!", Toast.LENGTH_SHORT).show();
Log.d("TAG", "SUCCESS \n\n\n\n ------");
Patient p = dataSnapshot.getValue(Patient.class);
fragmentArgs = new Bundle();
fragmentArgs.putSerializable(Const.BUNDLE_KEY_PATIENT, p);
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.main_bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch(item.getItemId()) {
case R.id.action_inbox:
invalidateOptionsMenu();
selectedFragment = InboxFragment.newInstance(fragmentArgs);
currentFragment = Frag.INBOX;
break;
case R.id.action_appointments:
invalidateOptionsMenu();
AppointmentsFragment f = AppointmentsFragment.newInstance(fragmentArgs);
f.setCallback(MainActivity.this);
selectedFragment = f;
currentFragment = Frag.APPOINTMENTS;
break;
case R.id.action_rx:
invalidateOptionsMenu();
selectedFragment = RxFragment.newInstance(fragmentArgs);
currentFragment = Frag.RX;
break;
case R.id.action_profile:
invalidateOptionsMenu();
selectedFragment = ProfileFragment.newInstance(fragmentArgs);
currentFragment = Frag.PROFILE_EDIT;
break;
}
refreshFragmentUI(selectedFragment);
return true;
}
});
// Before the application or user has picked anything to display
// Let's just display the inbox fragment by default so that when the app loads up
// we pick that.
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.e("ERR", "Could not load patient snapshot" + databaseError.getDetails());
}
});
}
use of com.hci.carebase.data.datasource.LocalCacheDb in project Carebase by robertsimoes.
the class MainActivity method onSave.
@Override
public void onSave(Patient p) {
ILocalCache cache = new LocalCacheDb(MainActivity.this);
String pId = cache.getUserId();
src.updatePatient(pId, p, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(getApplicationContext(), "Complete", Toast.LENGTH_SHORT).show();
}
});
}
use of com.hci.carebase.data.datasource.LocalCacheDb in project Carebase by robertsimoes.
the class AppointmentsFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Const.REQUEST_CODE_CAPTURE_IMAGE_ACTIVITY) {
if (resultCode == Activity.RESULT_OK) {
Bitmap bmp = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
// convert byte array to Bitmap
Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
imgViewPatientAttachment.setImageBitmap(bitmap);
Uri uri = Commons.saveTmpAndGetUri(getContext(), bmp);
PhotoSource s = CollectionsProvider.photos();
ILocalCache cache = new LocalCacheDb(getContext());
String userId = cache.getUserId();
// dlg.setCancelable(true);
// dlg.show(getContext(),"Please wait..","Attaching image..");
s.uploadAppointmentPhoto(userId, uri, currentAppointment.getDateFor(), taskSnapshot -> {
// dlg.dismiss();
currentAppointment.setHasImageAttachment(true);
int indexUpcoming = Commons.getMostUpcomingAppointmentIndex(p);
p.getAppointments().set(indexUpcoming, currentAppointment);
callback.onSave(p);
Toast.makeText(getContext(), "Saved image.", Toast.LENGTH_SHORT).show();
});
}
}
}
use of com.hci.carebase.data.datasource.LocalCacheDb in project Carebase by robertsimoes.
the class LoginRegisterActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_register);
ButterKnife.bind(this);
fauth = FirebaseAuth.getInstance();
cache = new LocalCacheDb(this);
// TODO remove this:
// onExecLoginButtonClick(new View(this));
/**
* This is set to loggout by default
*/
}
use of com.hci.carebase.data.datasource.LocalCacheDb in project Carebase by robertsimoes.
the class AppointmentsFragment method refreshUI.
private void refreshUI(Appointment mostUpcomingAppointment) {
SimpleDateFormat f = new SimpleDateFormat("EEE, MMM d, yyyy");
String date = f.format(mostUpcomingAppointment.getDateFor());
String hospital = mostUpcomingAppointment.getHospitalLocation() == "" ? "N/A please contact physician." : mostUpcomingAppointment.getHospitalLocation();
String doctor = mostUpcomingAppointment.getDoctor().getFirstName() + " " + mostUpcomingAppointment.getDoctor().getLastName();
String prep = mostUpcomingAppointment.getPreparations() == "" ? "N/A" : mostUpcomingAppointment.getPreparations();
String comments = mostUpcomingAppointment.getPatientComments() == "" ? "N/A" : mostUpcomingAppointment.getPatientComments();
tvAppointmentDoctor.setText(doctor);
tvAppointmentPrep.setText(prep);
tvAppointmentHospital.setText(hospital);
tvAppointmentTime.setText(date);
tvPatientComments.setText(comments);
if (mostUpcomingAppointment.hasImageAttachment()) {
PhotoSource s = CollectionsProvider.photos();
ILocalCache cache = new LocalCacheDb(getContext());
s.getAppointmentPhoto(cache.getUserId(), mostUpcomingAppointment.getDateFor(), new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
Glide.with(getContext()).load(uri).into(imgViewPatientAttachment);
}
});
}
}
Aggregations