Search in sources :

Example 1 with CustomAdapter

use of de.bahnhoefe.deutschlands.bahnhofsfotos.db.CustomAdapter in project RSAndroidApp by RailwayStations.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    BaseApplication baseApplication = (BaseApplication) getApplication();
    dbAdapter = baseApplication.getDbAdapter();
    firstAppStart = baseApplication.getFirstAppStart();
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + getString(R.string.fab_email)));
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.fab_subject));
            startActivity(Intent.createChooser(emailIntent, getString(R.string.fab_chooser_title)));
        }
    });
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    handleGalleryNavItem();
    View header = navigationView.getHeaderView(0);
    TextView tvUpdate = (TextView) header.findViewById(R.id.tvUpdate);
    if (firstAppStart == false) {
        Intent introSliderIntent = new Intent(MainActivity.this, IntroSliderActivity.class);
        startActivity(introSliderIntent);
        finish();
    }
    try {
        lastUpdateDate = loadUpdateDateFromFile("updatedate.txt");
    } catch (Exception e) {
        Log.e(TAG, "Cannot load last update", e);
    }
    if (!lastUpdateDate.equals("")) {
        tvUpdate.setText("Letzte Aktualisierung am: " + lastUpdateDate);
    } else {
        disableNavItem();
        tvUpdate.setText(R.string.no_stations_in_database);
    }
    cursor = dbAdapter.getStationsList(false);
    customAdapter = new CustomAdapter(this, cursor, 0);
    ListView listView = (ListView) findViewById(R.id.lstStations);
    assert listView != null;
    listView.setAdapter(customAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> listview, View view, int position, long id) {
            Bahnhof bahnhof = dbAdapter.fetchBahnhofByRowId(id);
            Class cls = DetailsActivity.class;
            Intent intentDetails = new Intent(MainActivity.this, cls);
            intentDetails.putExtra(DetailsActivity.EXTRA_BAHNHOF, bahnhof);
            startActivity(intentDetails);
            finish();
        }
    });
    // Initialize FirebaseAuth
    mFirebaseAuth = FirebaseAuth.getInstance();
    Intent searchIntent = getIntent();
    if (Intent.ACTION_SEARCH.equals(searchIntent.getAction())) {
        String query = searchIntent.getStringExtra(SearchManager.QUERY);
        Toast.makeText(MainActivity.this, query, Toast.LENGTH_SHORT).show();
    }
    bindToStatus();
}
Also used : ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) Intent(android.content.Intent) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) CustomAdapter(de.bahnhoefe.deutschlands.bahnhofsfotos.db.CustomAdapter) ListView(android.widget.ListView) Bahnhof(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof) FloatingActionButton(android.support.design.widget.FloatingActionButton) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) DrawerLayout(android.support.v4.widget.DrawerLayout) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Intent (android.content.Intent)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 NavigationView (android.support.design.widget.NavigationView)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 SearchView (android.support.v7.widget.SearchView)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 CustomAdapter (de.bahnhoefe.deutschlands.bahnhofsfotos.db.CustomAdapter)1 Bahnhof (de.bahnhoefe.deutschlands.bahnhofsfotos.model.Bahnhof)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1