Skip to content

Instantly share code, notes, and snippets.

@UndefinedPotato
Last active June 22, 2018 21:54
Show Gist options
  • Save UndefinedPotato/c9011994d7e8958c50d6b92f7dcbfc37 to your computer and use it in GitHub Desktop.
Save UndefinedPotato/c9011994d7e8958c50d6b92f7dcbfc37 to your computer and use it in GitHub Desktop.
public class MainActivity extends Activity implements MapInteractor {
MapView mapView;
public void onCreate() {
// View A from example
MapFragment mapFragment = MapFragment.newInstance(); // Implements MapView interface
// View B from example
TaskFragment taskFragment = TaskFragment.newInstance();
setTopFragment(mapFragment);
setBottomFragment(taskFragment);
mapView = mapFragment;
}
@Override
public void putTaskOnMap(Task task) {
// sends off to map view which goes to the map presenter to update the model then updates the view
mapView.putTaskOnMap(task);
}
@Override
public void centerMap() {
mapView.centerMap();
}
}
public class TaskFragment extends Fragment implements TaskContract.View {
private MapInteractor mapInteractor;
@Override
public void onAttach(Activity activity) {
mapInteractor = (MapInteractor) activity;
}
@Override
public void putTaskOnMap(Task task) {
mapInteractor.putTaskOnMap(task);
}
@Override
public void centerMap() {
mapInteractor.centerMap();
}
}
// Presenter B from the example
public class TaskPresenter {
void start() {
// TaskPresenter -> view -> activity -> MapView
view.centerMap();
// other ideas
// mapInteractor.centerMap();
// bus.post(centerMapEvent);
// mapView.centerMap();
}
void getData() {
Task task = taskRepository.getTask("id");
view.display(task);
view.putOnMap(task);
// other ideas but doesn't make sense for centering the map
// mapMarkerStore.addMapMarker(task); // MapPresenter would listen for changes and add or remove map makrer
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment