My app has one activity and two fragments. The activity is just used as a fragment container. One of the fragment show data as text. The second fragment shows the same data as a chart. This data come from a remote JSON API. As in MVP we have to replicate the same structure for each view (module, model, presenter, repository...) my app request the data from the JSON API for every fragment, so two times. How can i do to have a more efficient architecture allowing me to respect the MVP ?
See below the code implemented for my both fragments :
Module
@Module
public class PollutionLevelsModule {
@Provides
public PollutionLevelsFragmentMVP.Presenter providePollutionLevelsFragmentPresenter(PollutionLevelsFragmentMVP.Model pollutionLevelsModel) {
return new PollutionLevelsPresenter(pollutionLevelsModel);
}
@Provides
public PollutionLevelsFragmentMVP.Model providePollutionLevelsFragmentModel(Repository repository) {
return new PollutionLevelsModel(repository);
}
@Singleton
@Provides
public Repository provideRepo(PollutionApiService pollutionApiService) {
return new PollutionLevelsRepository(pollutionApiService);
}
}
Repository
public class PollutionLevelsRepository implements Repository {
private PollutionApiService pollutionApiService;
public PollutionLevelsRepository(PollutionApiService pollutionApiService) {
this.pollutionApiService = pollutionApiService;
}
@Override
public Observable<Aqicn> getDataFromNetwork(String city, String authToken) {
Observable<Aqicn> aqicn = pollutionApiService.getPollutionObservable(city, authToken);
return aqicn;
}
}