roughike / BottomBar

(Deprecated) A custom view component that mimics the new Material Design Bottom Navigation pattern.
Apache License 2.0
8.41k stars 1.5k forks source link

How to use this BottomBar in abstract BaseActivity #460

Open RethinavelPillai opened 8 years ago

RethinavelPillai commented 8 years ago

Say for ex.. I have 5 tabs. I want to implement this bottom bar in BaseActivity and wish to extend BaseActivity for all the 5 Activities. Here is the code

public abstract class BaseActivity extends AppCompatActivity {

private ProgressDialog mProgressDialog;
private Toolbar toolbar;
private BottomBar bottomBar;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getLayoutResourceId());
    Log.e("Context : ", "" + this.getClass().getName());

}

protected abstract int getLayoutResourceId();

private void setUpToolbar() {
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
}

@Override
public void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    setUpBottomMenuBar();
    setUpToolbar();
}

private void setUpBottomMenuBar() {

    bottomBar = (BottomBar) findViewById(R.id.bottomBar);
    bottomBar.setOnTabSelectListener(new OnTabSelectListener() {

        @Override
        public void onTabSelected(@IdRes int tabId) {

            switch (tabId) {
                case R.id.tab_dashboard:
                    startActivity(new Intent(BaseActivity.this, DashBoard.class));
                    break;
                case R.id.tab_properties:
                    startActivity(new Intent(BaseActivity.this, Properties.class));
                    break;
                case R.id.tab_maintenance:
                    startActivity(new Intent(BaseActivity.this, Maintenance.class));
                    break;
                case R.id.tab_calendar:
                    startActivity(new Intent(BaseActivity.this, Calendar.class));
                    break;
                case R.id.tab_expenses:
                    startActivity(new Intent(BaseActivity.this, Expenses.class));
                    break;
                case R.id.tab_proposal:
                    startActivity(new Intent(BaseActivity.this, Proposal.class));
                    break;
                case R.id.tab_reports:
                    startActivity(new Intent(BaseActivity.this, Reports.class));
                    break;
            }
        }
    });

    bottomBar.setOnTabReselectListener(new OnTabReselectListener() {
        @Override
        public void onTabReSelected(@IdRes int tabId) {
            switch (tabId) {
                case R.id.tab_dashboard:
                    Log.e("tab_dashboard ", " Dashboard Reselected " + R.id.tab_dashboard);
                    break;
                case R.id.tab_properties:
                    Log.e("tab_properties ", " Properties Reselected " + R.id.tab_properties);
                    break;
                case R.id.tab_maintenance:
                    Log.e("tab_maintenance ", " Maintenance Reselected " + R.id.tab_maintenance);

                    break;
                case R.id.tab_calendar:
                    Log.e("tab_calendar ", " Calendar Reselected " + R.id.tab_calendar);

                    break;
                case R.id.tab_expenses:
                    Log.e("tab_expenses ", " Expenses Reselected " + R.id.tab_expenses);

                    break;
                case R.id.tab_proposal:
                    Log.e("tab_proposal ", " Proposal Reselected " + R.id.tab_proposal);

                    break;
                case R.id.tab_reports:
                    Log.e("tab_reports ", " Reports Reselected " + R.id.tab_reports);

                    break;
            }
        }
    });

}

And extended the BaseActivity like this:

public class Expenses extends BaseActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
protected int getLayoutResourceId() {
    return R.layout.act_expenses;
}
}

When ever i click the "Expense" Activity from "Dashboard" The execution moves automatically to Dashboard again from "Expense"

What i am trying to achieve.. Dashboard --> Expense

What i am getting now.. Dashboard --> Expense --- Auto redirects to Dashboard again ---> Dashboard.

How could i solve this issue?

This library works for multiple activities? Or works only one activity with multiple fragments??

josefkorbel commented 8 years ago

You are launching new activities from click on BottomBar Tab? I dont think that is guideline behavior. I have fragment container in activity and im switching them.

Why do you need to launch activities from actionbar?

RethinavelPillai commented 8 years ago

@josefkorbel Yes.. Actually i have to load so many API's (web service) in each BottomBar Tab. Is that good practice to load large data in fragments. Could you please suggest me which is better way to achieve this?