Skip to content

Commit

Permalink
Initialize click listeners after presenter / viewmodel is set (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder authored Nov 10, 2017
1 parent c701d44 commit 3d4de96
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 41 deletions.
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

0 comments on commit 3d4de96

Please sign in to comment.