|
|
@@ -3,63 +3,45 @@ package com.example.yiupang.freefoodfinder;
|
|
|
import android.graphics.Color;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.annotation.IdRes;
|
|
|
-import android.support.v7.app.ActionBarActivity;
|
|
|
+import android.support.v4.app.Fragment;
|
|
|
|
|
|
-//CODE SMELLS: following 4 imports are unused
|
|
|
-import android.support.design.widget.FloatingActionButton;
|
|
|
-import android.support.design.widget.Snackbar;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
-import android.support.v7.widget.Toolbar;
|
|
|
-
|
|
|
-import android.view.View;
|
|
|
import android.view.Menu;
|
|
|
import android.view.MenuItem;
|
|
|
-import android.widget.TextView;
|
|
|
|
|
|
import com.roughike.bottombar.BottomBar;
|
|
|
import com.roughike.bottombar.OnMenuTabClickListener;
|
|
|
|
|
|
-//CODE SEMLL: unused import
|
|
|
-import com.roughike.bottombar.BottomBarBadge;
|
|
|
|
|
|
-public class MainActivity extends ActionBarActivity
|
|
|
+public class MainActivity extends AppCompatActivity
|
|
|
{
|
|
|
- static final String RED = "ff0000";
|
|
|
- BottomBar bottomBar;
|
|
|
+ private Fragment getSelectedFragement(int menuItemId)
|
|
|
+ {
|
|
|
+ if(menuItemId == R.id.BottomBarEvents)
|
|
|
+ return new EventsScreen();
|
|
|
+ else if(menuItemId == R.id.BottomBarItemMap)
|
|
|
+ return new MapScreen();
|
|
|
+ else if(menuItemId == R.id.BottomBarItemMyEvent)
|
|
|
+ return new MyEventScreen();
|
|
|
+ else
|
|
|
+ return new AboutUsScreen();
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState)
|
|
|
{
|
|
|
+ BottomBar bottomBar;
|
|
|
super.onCreate(savedInstanceState);
|
|
|
-
|
|
|
setContentView(R.layout.activity_main);
|
|
|
bottomBar = BottomBar.attach(this, savedInstanceState);
|
|
|
- //CODE SMELL: It's complicated
|
|
|
+
|
|
|
bottomBar.setItemsFromMenu(R.menu.menu_main, new OnMenuTabClickListener()
|
|
|
{
|
|
|
@Override
|
|
|
public void onMenuTabSelected(@IdRes int menuItemId)
|
|
|
{
|
|
|
- if(menuItemId == R.id.BottomBarEvents)
|
|
|
- {
|
|
|
- EventsScreen es = new EventsScreen();
|
|
|
- getSupportFragmentManager().beginTransaction().replace(R.id.frame, es).commit();
|
|
|
- }
|
|
|
- else if(menuItemId == R.id.BottomBarItemMap)
|
|
|
- {
|
|
|
- MapScreen es = new MapScreen();
|
|
|
- getSupportFragmentManager().beginTransaction().replace(R.id.frame, es).commit();
|
|
|
- }
|
|
|
- else if(menuItemId == R.id.BottomBarItemMyEvent)
|
|
|
- {
|
|
|
- MyEventScreen es = new MyEventScreen();
|
|
|
- getSupportFragmentManager().beginTransaction().replace(R.id.frame, es).commit();
|
|
|
- }
|
|
|
- else if(menuItemId == R.id.BottomBarItemAboutUs)
|
|
|
- {
|
|
|
- AboutUsScreen es = new AboutUsScreen();
|
|
|
- getSupportFragmentManager().beginTransaction().replace(R.id.frame, es).commit();
|
|
|
- }
|
|
|
+ getSupportFragmentManager().beginTransaction().
|
|
|
+ replace(R.id.frame, getSelectedFragement(menuItemId)).commit();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -88,16 +70,6 @@ public class MainActivity extends ActionBarActivity
|
|
|
// Handle action bar item clicks here. The action bar will
|
|
|
// automatically handle clicks on the Home/Up button, so long
|
|
|
// as you specify a parent activity in AndroidManifest.xml.
|
|
|
- //CODE SMELL AND BUG: useless assignment
|
|
|
- int id = item.getItemId();
|
|
|
-
|
|
|
- //CODE SMELL: remove comment block
|
|
|
- /*
|
|
|
- //noinspection SimplifiableIfStatement
|
|
|
- if (id == R.id.action_settings) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- */
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
}
|
|
|
}
|