From 7854f75f22d3c74ddbd2c3b53d686737435e0c94 Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Fri, 18 Nov 2016 14:32:53 +0100 Subject: [PATCH] make fragment click listener nullable --- .../simplemobiletools/gallery/fragments/PhotoFragment.kt | 2 +- .../simplemobiletools/gallery/fragments/VideoFragment.kt | 6 +++++- .../gallery/fragments/ViewPagerFragment.kt | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index db6c9fd27..c8154e76a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -66,6 +66,6 @@ class PhotoFragment : ViewPagerFragment(), View.OnClickListener { if (listener == null) listener = activity as ViewPagerFragment.FragmentClickListener - listener.fragmentClicked() + listener?.fragmentClicked() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt index 6c1f9070c..b99a94cf9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -161,7 +161,11 @@ class VideoFragment : ViewPagerFragment(), View.OnClickListener, SurfaceHolder.C else -> { mIsFullscreen = !mIsFullscreen checkFullscreen() - listener.fragmentClicked() + + if (listener == null) + listener = activity as ViewPagerFragment.FragmentClickListener + + listener?.fragmentClicked() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt index 5ad715668..0fcdd8607 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt @@ -3,7 +3,7 @@ package com.simplemobiletools.gallery.fragments import android.support.v4.app.Fragment abstract class ViewPagerFragment : Fragment() { - lateinit var listener: FragmentClickListener + var listener: FragmentClickListener? = null abstract fun itemDragged()