Search in sources :

Example 1 with LocalCacheDb

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());
        }
    });
}
Also used : IntroActivity(com.hci.carebase.ui.activities.IntroActivity) Bundle(android.os.Bundle) Patient(com.hci.carebase.domain.Patient) ILocalCache(com.hci.carebase.data.interfaces.ILocalCache) Intent(android.content.Intent) MenuItem(android.view.MenuItem) DataSnapshot(com.google.firebase.database.DataSnapshot) LocalCacheDb(com.hci.carebase.data.datasource.LocalCacheDb) DatabaseError(com.google.firebase.database.DatabaseError) BottomNavigationView(android.support.design.widget.BottomNavigationView) NonNull(android.support.annotation.NonNull) AppointmentsFragment(com.hci.carebase.ui.fragments.AppointmentsFragment) ValueEventListener(com.google.firebase.database.ValueEventListener) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with LocalCacheDb

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();
        }
    });
}
Also used : LocalCacheDb(com.hci.carebase.data.datasource.LocalCacheDb) ILocalCache(com.hci.carebase.data.interfaces.ILocalCache)

Example 3 with LocalCacheDb

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();
            });
        }
    }
}
Also used : LocalCacheDb(com.hci.carebase.data.datasource.LocalCacheDb) Bitmap(android.graphics.Bitmap) PhotoSource(com.hci.carebase.data.interfaces.PhotoSource) ILocalCache(com.hci.carebase.data.interfaces.ILocalCache) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Uri(android.net.Uri)

Example 4 with LocalCacheDb

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
 */
}
Also used : LocalCacheDb(com.hci.carebase.data.datasource.LocalCacheDb)

Example 5 with LocalCacheDb

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);
            }
        });
    }
}
Also used : LocalCacheDb(com.hci.carebase.data.datasource.LocalCacheDb) PhotoSource(com.hci.carebase.data.interfaces.PhotoSource) ILocalCache(com.hci.carebase.data.interfaces.ILocalCache) SimpleDateFormat(java.text.SimpleDateFormat) Uri(android.net.Uri)

Aggregations

LocalCacheDb (com.hci.carebase.data.datasource.LocalCacheDb)5 ILocalCache (com.hci.carebase.data.interfaces.ILocalCache)4 Uri (android.net.Uri)2 PhotoSource (com.hci.carebase.data.interfaces.PhotoSource)2 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 BottomNavigationView (android.support.design.widget.BottomNavigationView)1 Toolbar (android.support.v7.widget.Toolbar)1 MenuItem (android.view.MenuItem)1 DataSnapshot (com.google.firebase.database.DataSnapshot)1 DatabaseError (com.google.firebase.database.DatabaseError)1 ValueEventListener (com.google.firebase.database.ValueEventListener)1 Patient (com.hci.carebase.domain.Patient)1 IntroActivity (com.hci.carebase.ui.activities.IntroActivity)1 AppointmentsFragment (com.hci.carebase.ui.fragments.AppointmentsFragment)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 SimpleDateFormat (java.text.SimpleDateFormat)1