diff options
Diffstat (limited to 'app/src/main/java/org/marcinzelent/liberavem/MainActivity.java')
-rw-r--r-- | app/src/main/java/org/marcinzelent/liberavem/MainActivity.java | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/app/src/main/java/org/marcinzelent/liberavem/MainActivity.java b/app/src/main/java/org/marcinzelent/liberavem/MainActivity.java index 9986b81..2b8cc38 100644 --- a/app/src/main/java/org/marcinzelent/liberavem/MainActivity.java +++ b/app/src/main/java/org/marcinzelent/liberavem/MainActivity.java @@ -1,9 +1,13 @@ package org.marcinzelent.liberavem; +import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.view.View; import android.support.design.widget.NavigationView; import android.support.v4.view.GravityCompat; @@ -15,7 +19,9 @@ import android.view.Menu; import android.view.MenuItem; public class MainActivity extends AppCompatActivity - implements NavigationView.OnNavigationItemSelectedListener { + implements NavigationView.OnNavigationItemSelectedListener, + ObservationsFragment.OnFragmentInteractionListener, + AtlasFragment.OnFragmentInteractionListener { @Override protected void onCreate(Bundle savedInstanceState) { @@ -24,14 +30,17 @@ public class MainActivity extends AppCompatActivity Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); - FloatingActionButton fab = findViewById(R.id.fab); - fab.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); - } - }); + Fragment fragment = null; + Class fragmentClass = null; + fragmentClass = ObservationsFragment.class; + try { + fragment = (Fragment) fragmentClass.newInstance(); + } catch (Exception e) { + e.printStackTrace(); + } + + FragmentManager fragmentManager = getSupportFragmentManager(); + fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit(); DrawerLayout drawer = findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( @@ -68,7 +77,7 @@ public class MainActivity extends AppCompatActivity int id = item.getItemId(); //noinspection SimplifiableIfStatement - if (id == R.id.action_settings) { + if (id == R.id.action_search) { return true; } @@ -80,19 +89,36 @@ public class MainActivity extends AppCompatActivity public boolean onNavigationItemSelected(@NonNull MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); + Fragment fragment = null; + Class fragmentClass = null; if (id == R.id.nav_observations) { - // Handle the camera action + fragmentClass = ObservationsFragment.class; } else if (id == R.id.nav_atlas) { - + fragmentClass = AtlasFragment.class; } else if (id == R.id.nav_settings) { - + Intent settingsIntent = new Intent(this, SettingsActivity.class); + startActivity(settingsIntent); } else if (id == R.id.nav_about) { } + if (fragmentClass != null) { + try { + fragment = (Fragment) fragmentClass.newInstance(); + } catch (Exception e) { + e.printStackTrace(); + } + FragmentManager fragmentManager = getSupportFragmentManager(); + fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit(); + } DrawerLayout drawer = findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } + + @Override + public void onFragmentInteraction(Uri uri) { + + } } |