Skip to content

Commit

Permalink
Add null checking to all view visibility changes. Fixes crash #24
Browse files Browse the repository at this point in the history
  • Loading branch information
aphexcx committed Mar 21, 2016
1 parent f2e4a95 commit 677ac4b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import io.givenow.app.helpers.ErrorDialogs;
import io.givenow.app.helpers.RateApp;
import io.givenow.app.helpers.ResourceHelper;
import io.givenow.app.helpers.ViewHelper;
import io.givenow.app.models.DonationCategory;
import io.givenow.app.models.ParseUserHelper;
import io.givenow.app.models.PickupRequest;
Expand Down Expand Up @@ -639,7 +640,7 @@ private Observable<Void> showCategoryLayout() {
tsInfo.setText(getString(R.string.request_pickup_info_select_categories));
actvAddress.setEnabled(false);
btnBottomSubmit.setText(getString(R.string.button_confirm_donation_label));
slidingRLContainer.setVisibility(View.VISIBLE);
ViewHelper.safeVisible(slidingRLContainer);
Animator slideDownFromTop = AnimatorInflater.loadAnimator(getActivity(), R.animator.slide_down_from_top);
slideDownFromTop.setInterpolator(new DecelerateInterpolator());
slideDownFromTop.setTarget(slidingRLContainer);
Expand Down Expand Up @@ -676,7 +677,7 @@ private Observable<Void> hideCategoryLayout() {
slideUpToTop.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
slidingRLContainer.setVisibility(View.INVISIBLE);
ViewHelper.safeInvisible(slidingRLContainer);
actvAddress.setEnabled(true);
mCategoryLayoutShowing = false;
subscriber.onNext(null);
Expand Down Expand Up @@ -738,7 +739,7 @@ private Observable<Void> showCurrentRequestLayout() {
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
btnBottomSubmit.setVisibility(View.GONE);
ViewHelper.safeGone(btnBottomSubmit);
for (DonationCategory item : items) {
item.setSelected(true);
item.setClickable(false);
Expand Down Expand Up @@ -794,7 +795,7 @@ private Observable<Void> hideCurrentRequestLayout() {
public void onAnimationEnd(Animator animation) {
showFab.start();
adaptableGradientRectView.setGradientColorTo(getResources().getColor(R.color.colorPrimaryLight));
rlCurrentRequestContainer.setVisibility(View.GONE);
ViewHelper.safeGone(rlCurrentRequestContainer);
btnBottomSubmit.setEnabled(true);
tsInfo.setText(getString(R.string.request_pickup_choose_location));
mCurrentRequestLayoutShowing = false;
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/java/io/givenow/app/helpers/ViewHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.givenow.app.helpers;

import android.support.annotation.Nullable;
import android.view.View;

/**
* Created by aphex on 3/20/16.
*/
public class ViewHelper {
public static void safeVisible(@Nullable View view) {
safeViewVisibility(view, View.VISIBLE);
}

public static void safeInvisible(@Nullable View view) {
safeViewVisibility(view, View.INVISIBLE);
}

public static void safeGone(@Nullable View view) {
safeViewVisibility(view, View.GONE);
}

private static void safeViewVisibility(@Nullable View view, int visibility) {
if (view != null) {
view.setVisibility(visibility);
}
}
}

0 comments on commit 677ac4b

Please sign in to comment.