From 30d7f269deabce505b3dba9eb1bd032b49db4802 Mon Sep 17 00:00:00 2001 From: Vavassor Date: Tue, 18 Jul 2017 23:34:07 -0400 Subject: [PATCH] Fixes an intermittent null pointer exception caused by getActivity() returning null in callbacks. --- .../java/com/keylesspalace/tusky/ViewMediaActivity.java | 5 +++++ .../keylesspalace/tusky/fragment/ViewMediaFragment.java | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.java b/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.java index 90b49ae6..ea5426e9 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.java @@ -147,6 +147,11 @@ public class ViewMediaActivity extends BaseActivity implements ViewMediaFragment return true; } + @Override + public void onBringUp() { + supportStartPostponedEnterTransition(); + } + @Override public void onDismiss() { supportFinishAfterTransition(); diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/ViewMediaFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewMediaFragment.java index fa409757..d8ceabb4 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/ViewMediaFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewMediaFragment.java @@ -35,8 +35,8 @@ import com.squareup.picasso.Picasso; public class ViewMediaFragment extends BaseFragment { public interface PhotoActionsListener { + void onBringUp(); void onDismiss(); - void onPhotoTap(); } @@ -45,7 +45,6 @@ public class ViewMediaFragment extends BaseFragment { View rootView; PhotoView photoView; - private static final String ARG_URL = "url"; private static final String ARG_START_POSTPONED_TRANSITION = "startPostponedTransition"; public static ViewMediaFragment newInstance(String url, boolean shouldStartPostponedTransition) { @@ -141,7 +140,8 @@ public class ViewMediaFragment extends BaseFragment { public void onError() { // if there's no image in cache, load from network and start trnasition // immediately. - getActivity().supportStartPostponedEnterTransition(); + photoActionsListener.onBringUp(); + loadImageFromNetwork(url, photoView); } }); @@ -173,6 +173,6 @@ public class ViewMediaFragment extends BaseFragment { private void finishLoadingSuccessfully() { rootView.findViewById(R.id.view_media_progress).setVisibility(View.GONE); attacher.update(); - getActivity().supportStartPostponedEnterTransition(); + photoActionsListener.onBringUp(); } }