fixed some memory leaks

This commit is contained in:
Mariotaku Lee 2017-04-04 00:53:12 +08:00
parent 5a152a38f9
commit 952dddba03
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
3 changed files with 21 additions and 13 deletions

View File

@ -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<ParcelableLocation, List<Address>, TextView>() {
internal class DisplayPlaceNameTask : AbstractTask<ParcelableLocation, List<Address>,
ComposeActivity>() {
override fun doLongOperation(location: ParcelableLocation): List<Address>? {
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<Address>?) {
textView!!
val preferences = context.preferences
override fun afterExecute(activity: ComposeActivity?, addresses: List<Address>?) {
if (activity == null) return
val textView = activity.locationLabel ?: return
val preferences = activity.preferences
val attachLocation = preferences[attachLocationKey]
val attachPreciseLocation = preferences[attachPreciseLocationKey]
if (attachLocation) {

View File

@ -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 {

View File

@ -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()