Search in sources :

Example 1 with AppointmentsFragment

use of com.hci.carebase.ui.fragments.AppointmentsFragment 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)

Aggregations

Intent (android.content.Intent)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 LocalCacheDb (com.hci.carebase.data.datasource.LocalCacheDb)1 ILocalCache (com.hci.carebase.data.interfaces.ILocalCache)1 Patient (com.hci.carebase.domain.Patient)1 IntroActivity (com.hci.carebase.ui.activities.IntroActivity)1 AppointmentsFragment (com.hci.carebase.ui.fragments.AppointmentsFragment)1