diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt index 90495df97..00017186c 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt @@ -1372,9 +1372,9 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener locationLabel.text = ParcelableLocationUtils.getHumanReadableString(location, 3) } else { if (locationLabel.tag == null || location != recentLocation) { - val task = DisplayPlaceNameTask(this) + val task = DisplayPlaceNameTask() task.params = location - task.callback = locationLabel + task.callback = this TaskStarter.execute(task) } } @@ -1796,13 +1796,13 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener } } - internal class DisplayPlaceNameTask( - private val context: ComposeActivity - ) : AbstractTask, TextView>() { + internal class DisplayPlaceNameTask : AbstractTask, + ComposeActivity>() { override fun doLongOperation(location: ParcelableLocation): List
? { - val gcd = Geocoder(context, Locale.getDefault()) try { + val activity = callback ?: throw IOException("Interrupted") + val gcd = Geocoder(activity, Locale.getDefault()) return gcd.getFromLocation(location.latitude, location.longitude, 1) } catch (e: IOException) { return null @@ -1812,9 +1812,10 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener override fun beforeExecute() { val location = params - val textView = callback ?: return + val activity = callback ?: return + val textView = activity.locationLabel ?: return - val preferences = context.preferences + val preferences = activity.preferences val attachLocation = preferences[attachLocationKey] val attachPreciseLocation = preferences[attachPreciseLocationKey] if (attachLocation) { @@ -1836,9 +1837,10 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener } } - override fun afterExecute(textView: TextView?, addresses: List
?) { - textView!! - val preferences = context.preferences + override fun afterExecute(activity: ComposeActivity?, addresses: List
?) { + if (activity == null) return + val textView = activity.locationLabel ?: return + val preferences = activity.preferences val attachLocation = preferences[attachLocationKey] val attachPreciseLocation = preferences[attachPreciseLocationKey] if (attachLocation) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/media/ImagePageFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/media/ImagePageFragment.kt index 0885a8841..773a52907 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/media/ImagePageFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/media/ImagePageFragment.kt @@ -39,6 +39,7 @@ import org.mariotaku.twidere.util.TwidereMathUtils import org.mariotaku.twidere.util.UriUtils import org.mariotaku.twidere.util.media.MediaExtra import java.io.IOException +import java.lang.ref.WeakReference class ImagePageFragment : SubsampleImageViewerFragment() { @@ -145,9 +146,12 @@ class ImagePageFragment : SubsampleImageViewerFragment() { internal class SizedResult(cacheUri: Uri, val width: Int, val height: Int) : CacheDownloadLoader.Result(cacheUri, null) - internal class SizedResultCreator(private val context: Context) : CacheDownloadLoader.ResultCreator { + internal class SizedResultCreator(context: Context) : CacheDownloadLoader.ResultCreator { + + private val weakContext = WeakReference(context) override fun create(uri: Uri): CacheDownloadLoader.Result { + val context = weakContext.get() ?: return CacheDownloadLoader.Result.getInstance(InterruptedException()) val o = BitmapFactory.Options() o.inJustDecodeBounds = true try { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/AccountDetailsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/AccountDetailsLoader.kt index 68e3a6feb..6298597de 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/AccountDetailsLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/AccountDetailsLoader.kt @@ -8,6 +8,7 @@ import org.mariotaku.ktextension.addOnAccountsUpdatedListenerSafe import org.mariotaku.ktextension.removeOnAccountsUpdatedListenerSafe import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.util.AccountUtils +import java.lang.ref.WeakReference /** * Created by mariotaku on 2016/12/4. @@ -42,8 +43,9 @@ class AccountDetailsLoader( } override fun onStartLoading() { + val weakThis = WeakReference(this) accountUpdateListener = OnAccountsUpdateListener { - onContentChanged() + weakThis.get()?.onContentChanged() } if (takeContentChanged()) { forceLoad()