Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize Click listeners after Presenter / ViewModels #481

Merged
merged 1 commit into from
Nov 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ public void onStyleLoaded(String style) {
initLocationLayer();
initLifecycleObservers();
initNavigationPresenter();
initClickListeners();
initSummaryBottomSheet();
subscribeViews();
navigationListener.onNavigationReady();
}
Expand Down Expand Up @@ -292,8 +294,6 @@ private void init() {
inflate(getContext(), R.layout.navigation_view_layout, this);
bind();
initViewModels();
initClickListeners();
initSummaryBottomSheet();
}

/**
Expand All @@ -317,44 +317,6 @@ private void initViewModels() {
}
}

/**
* Sets click listeners to all views that need them.
*/
private void initClickListeners() {
cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
navigationPresenter.onCancelBtnClick();
}
});
recenterBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
navigationPresenter.onRecenterClick();
}
});
}

/**
* Initializes the {@link BottomSheetBehavior} for {@link SummaryBottomSheet}.
*/
private void initSummaryBottomSheet() {
summaryBehavior = BottomSheetBehavior.from(summaryBottomSheet);
summaryBehavior.setHideable(false);
summaryBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_HIDDEN) {
navigationPresenter.onSummaryBottomSheetHidden();
}
}

@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
}

/**
* Sets the {@link BottomSheetBehavior} based on the last state stored
* in {@link Bundle} savedInstanceState.
Expand Down Expand Up @@ -414,6 +376,44 @@ private void initNavigationPresenter() {
navigationPresenter = new NavigationPresenter(this);
}

/**
* Sets click listeners to all views that need them.
*/
private void initClickListeners() {
cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
navigationPresenter.onCancelBtnClick();
}
});
recenterBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
navigationPresenter.onRecenterClick();
}
});
}

/**
* Initializes the {@link BottomSheetBehavior} for {@link SummaryBottomSheet}.
*/
private void initSummaryBottomSheet() {
summaryBehavior = BottomSheetBehavior.from(summaryBottomSheet);
summaryBehavior.setHideable(false);
summaryBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_HIDDEN) {
navigationPresenter.onSummaryBottomSheetHidden();
}
}

@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
}

/**
* Initiate observing of ViewModels by Views.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ protected void onFinishInflate() {
initDirectionsRecyclerView();
initDecimalFormat();
initAnimations();
initClickListeners();
}

@Override
Expand Down Expand Up @@ -179,6 +178,9 @@ public void onChanged(@Nullable Boolean isOffRoute) {
}
}
});

// ViewModel set - click listeners can be set now
initClickListeners();
}

/**
Expand Down