Skip to content

Commit

Permalink
Fix FeedbackBottomSheet rotation bug (#699)
Browse files Browse the repository at this point in the history
* Fix FeedbackBottomSheet rotation bug

* Cleanup per review comments
  • Loading branch information
danesfeder committed Feb 14, 2018
1 parent e3bd67b commit 17f7af7
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 30 deletions.
Expand Up @@ -28,7 +28,8 @@
import com.mapbox.services.android.navigation.ui.v5.R;
import com.mapbox.services.android.navigation.ui.v5.ThemeSwitcher;

public class FeedbackBottomSheet extends BottomSheetDialogFragment implements FeedbackClickListener.ClickCallback {
public class FeedbackBottomSheet extends BottomSheetDialogFragment implements FeedbackClickListener.ClickCallback,
Animator.AnimatorListener {

public static final String TAG = FeedbackBottomSheet.class.getSimpleName();

Expand All @@ -44,6 +45,7 @@ public static FeedbackBottomSheet newInstance(FeedbackBottomSheetListener feedba
FeedbackBottomSheet feedbackBottomSheet = new FeedbackBottomSheet();
feedbackBottomSheet.setFeedbackBottomSheetListener(feedbackBottomSheetListener);
feedbackBottomSheet.setDuration(duration);
feedbackBottomSheet.setRetainInstance(true);
return feedbackBottomSheet;
}

Expand Down Expand Up @@ -86,6 +88,20 @@ public void onShow(DialogInterface dialog) {
return dialog;
}

@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
feedbackBottomSheetListener.onFeedbackDismissed();
}

@Override
public void onDestroyView() {
removeListener();
removeDialogDismissMessage();
cancelCountdownAnimation();
super.onDestroyView();
}

@Override
public void onFeedbackItemClick(int feedbackPosition) {
FeedbackItem feedbackItem = feedbackAdapter.getFeedbackItem(feedbackPosition);
Expand All @@ -94,19 +110,29 @@ public void onFeedbackItemClick(int feedbackPosition) {
}

@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
feedbackBottomSheetListener.onFeedbackDismissed();
public void onAnimationEnd(Animator animation) {
FeedbackBottomSheet.this.dismiss();
}

//region Unused Listener Methods

@Override
public void onAnimationStart(Animator animation) {

}

@Override
public void onStop() {
super.onStop();
if (countdownAnimation != null) {
countdownAnimation.cancel();
}
public void onAnimationCancel(Animator animation) {

}

@Override
public void onAnimationRepeat(Animator animation) {

}

//endregion

public void setFeedbackBottomSheetListener(FeedbackBottomSheetListener feedbackBottomSheetListener) {
this.feedbackBottomSheetListener = feedbackBottomSheetListener;
}
Expand Down Expand Up @@ -141,27 +167,7 @@ private void initCountDownAnimation() {
"progress", 0);
countdownAnimation.setInterpolator(new LinearInterpolator());
countdownAnimation.setDuration(duration);
countdownAnimation.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {

}

@Override
public void onAnimationEnd(Animator animation) {
FeedbackBottomSheet.this.dismiss();
}

@Override
public void onAnimationCancel(Animator animation) {

}

@Override
public void onAnimationRepeat(Animator animation) {

}
});
countdownAnimation.addListener(this);
countdownAnimation.start();
}

Expand All @@ -180,4 +186,22 @@ private void initBackground(View view) {
progressDrawable.setColorFilter(navigationViewSecondaryColor, PorterDuff.Mode.SRC_IN);
}
}

private void removeListener() {
feedbackBottomSheetListener = null;
}

private void removeDialogDismissMessage() {
Dialog dialog = getDialog();
if (dialog != null && getRetainInstance()) {
dialog.setDismissMessage(null);
}
}

private void cancelCountdownAnimation() {
if (countdownAnimation != null) {
countdownAnimation.removeAllListeners();
countdownAnimation.cancel();
}
}
}
Expand Up @@ -12,6 +12,7 @@
import android.support.constraint.ConstraintSet;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.widget.TextViewCompat;
import android.support.v7.widget.DefaultItemAnimator;
Expand Down Expand Up @@ -128,6 +129,12 @@ protected void onFinishInflate() {
initAnimations();
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
addBottomSheetListener();
}

@Override
public void onFeedbackSelected(FeedbackItem feedbackItem) {
navigationViewModel.updateFeedback(feedbackItem);
Expand Down Expand Up @@ -516,6 +523,14 @@ private void initAnimations() {
fadeInSlowOut.addAnimation(fadeOut);
}

private void addBottomSheetListener() {
FragmentManager mgr = ((FragmentActivity) getContext()).getSupportFragmentManager();
FeedbackBottomSheet feedbackBottomSheet = (FeedbackBottomSheet) mgr.findFragmentByTag(FeedbackBottomSheet.TAG);
if (feedbackBottomSheet != null) {
feedbackBottomSheet.setFeedbackBottomSheetListener(this);
}
}

private void initClickListeners() {
if (getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
initLandscapeListListener();
Expand Down

0 comments on commit 17f7af7

Please sign in to comment.