SLAM/mobile/src/main/java/de/vanitasvitae/slam/mvp/view/MainActivity.java

114 lines
3.9 KiB
Java
Raw Normal View History

2018-02-12 02:08:56 +01:00
/*
* Copyright 2018 Paul Schaub
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
2018-02-10 17:34:01 +01:00
package de.vanitasvitae.slam.mvp.view;
2018-01-27 03:33:50 +01:00
import android.os.Bundle;
2018-02-13 21:02:46 +01:00
import android.support.annotation.NonNull;
2018-01-27 03:33:50 +01:00
import android.support.design.widget.NavigationView;
2018-02-13 21:02:46 +01:00
import android.support.v4.app.Fragment;
2018-01-27 03:33:50 +01:00
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
2018-02-13 21:02:46 +01:00
import android.view.MenuItem;
2018-01-31 14:40:01 +01:00
import android.widget.FrameLayout;
2018-02-13 21:02:46 +01:00
import android.widget.Toast;
2018-01-27 03:33:50 +01:00
import butterknife.BindView;
import butterknife.ButterKnife;
import de.vanitasvitae.slam.R;
2018-02-10 17:34:01 +01:00
import de.vanitasvitae.slam.mvp.view.abstr.ThemedAppCompatActivity;
2018-01-27 03:33:50 +01:00
/**
2018-02-10 17:34:01 +01:00
* Main activity that hosts some fragments.
2018-01-27 03:33:50 +01:00
*/
2018-02-13 21:02:46 +01:00
public class MainActivity extends ThemedAppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
2018-01-27 03:33:50 +01:00
2018-01-31 14:40:01 +01:00
public static final String TAG = "Slam!";
2018-01-27 03:33:50 +01:00
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.navigation_view)
NavigationView navigationView;
@BindView(R.id.drawer_layout)
DrawerLayout drawerLayout;
2018-01-31 14:40:01 +01:00
@BindView(R.id.fragment_container)
FrameLayout fragmentContainer;
2018-01-27 03:33:50 +01:00
private ActionBarDrawerToggle drawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
drawerToggle = new ActionBarDrawerToggle(
2018-02-13 21:02:46 +01:00
this, drawerLayout, toolbar, R.string.login__error_incorrect_password, R.string.login__error_invalid_jid);
2018-01-27 03:33:50 +01:00
drawerLayout.addDrawerListener(drawerToggle);
2018-02-13 21:02:46 +01:00
navigationView.setNavigationItemSelectedListener(this);
2018-01-31 14:40:01 +01:00
2018-02-10 17:34:01 +01:00
Fragment chatListFragment = new ConversationListFragment();
2018-02-13 21:02:46 +01:00
getSupportFragmentManager().beginTransaction()
2018-02-12 02:08:56 +01:00
.add(R.id.fragment_container, chatListFragment)
.addToBackStack("conversation_list")
.commit();
2018-01-27 03:33:50 +01:00
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
}
2018-02-13 21:02:46 +01:00
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
drawerLayout.closeDrawers();
switch (item.getItemId()) {
case R.id.navdrawer__item_conversations:
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, new ConversationListFragment())
.commit();
return true;
case R.id.navdrawer__item_contacts:
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, new ContactListFragment())
.commit();
return true;
case R.id.navdrawer__item_bookmarks:
case R.id.navdrawer__item_blogging:
case R.id.navdrawer__item_settings:
Toast.makeText(this, R.string.feature_not_implemented, Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
2018-01-27 03:33:50 +01:00
}