I have made an android bottom bar in activity and thought i'd use dagger2 to set listener for it. How ever I am confused as to how to get the getSupportFragmentManager() inside the listener class. Here's what i'm trying
public class MainActivity extends AppCompatActivity {
@BindView(R.id.bottomNavigationView)
BottomNavigationView bottomNavigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
BottomBarComponent bottomBarComponent = DaggerBottomBarComponent.builder()
.bottomBarModule(new BottomBarModule(getSupportFragmentManager()))
.build();
}
}
The component part is
@Singleton
@Component(modules = {BottomBarModule.class})
public interface BottomBarComponent {
void inject(BottomNavigationListener listener);
}
The module is
@Module
public class BottomBarModule {
private FragmentManager manager;
public BottomBarModule(FragmentManager context) {
this.manager = context;
}
@Singleton
@Provides
public FragmentManager provideSupportManager(){
return manager;
}
}
And need to get fragmentsupportManager here
public class BottomNavigationListener implements BottomNavigationView.OnNavigationItemSelectedListener{
@Inject
FragmentManager manager;
public void BottomNavigationListener() {
//somehow need to get fragmentSupportManager here
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
return true;
}
}
How do I do this?