Skip to content

Commit

Permalink
Fix NPE in PreviewMediaFragment
Browse files Browse the repository at this point in the history
Fragment can be detached before async task finishes.
Detached fragment has no context and getString() fails with NPE.

Fixes #4412

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
  • Loading branch information
ezaquarii committed Sep 28, 2019
1 parent 9a2fc28 commit c660ca7
Showing 1 changed file with 9 additions and 3 deletions.
Expand Up @@ -82,6 +82,7 @@
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.fragment.app.Fragment;


/**
Expand Down Expand Up @@ -552,9 +553,9 @@ protected Uri doInBackground(String... fileId) {

@Override
protected void onPostExecute(Uri uri) {
PreviewMediaFragment previewMediaFragment = previewMediaFragmentWeakReference.get();

if (previewMediaFragment != null) {
final PreviewMediaFragment previewMediaFragment = previewMediaFragmentWeakReference.get();
final Context context = previewMediaFragment != null ? previewMediaFragment.getContext() : null;
if (previewMediaFragment != null && context != null) {
if (uri != null) {
previewMediaFragment.mVideoUri = uri;
previewMediaFragment.mVideoPreview.setVideoURI(uri);
Expand All @@ -568,6 +569,11 @@ protected void onPostExecute(Uri uri) {
Log_OC.e(TAG, "Error streaming file: no previewMediaFragment!");
}
}

private Context context() {
final Fragment fragment = previewMediaFragmentWeakReference.get();

}
}

private class VideoHelper implements OnCompletionListener, OnPreparedListener, OnErrorListener {
Expand Down

0 comments on commit c660ca7

Please sign in to comment.