fixed some memory leaks
This commit is contained in:
parent
5a152a38f9
commit
952dddba03
|
@ -1372,9 +1372,9 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||||
locationLabel.text = ParcelableLocationUtils.getHumanReadableString(location, 3)
|
locationLabel.text = ParcelableLocationUtils.getHumanReadableString(location, 3)
|
||||||
} else {
|
} else {
|
||||||
if (locationLabel.tag == null || location != recentLocation) {
|
if (locationLabel.tag == null || location != recentLocation) {
|
||||||
val task = DisplayPlaceNameTask(this)
|
val task = DisplayPlaceNameTask()
|
||||||
task.params = location
|
task.params = location
|
||||||
task.callback = locationLabel
|
task.callback = this
|
||||||
TaskStarter.execute(task)
|
TaskStarter.execute(task)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1796,13 +1796,13 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class DisplayPlaceNameTask(
|
internal class DisplayPlaceNameTask : AbstractTask<ParcelableLocation, List<Address>,
|
||||||
private val context: ComposeActivity
|
ComposeActivity>() {
|
||||||
) : AbstractTask<ParcelableLocation, List<Address>, TextView>() {
|
|
||||||
|
|
||||||
override fun doLongOperation(location: ParcelableLocation): List<Address>? {
|
override fun doLongOperation(location: ParcelableLocation): List<Address>? {
|
||||||
val gcd = Geocoder(context, Locale.getDefault())
|
|
||||||
try {
|
try {
|
||||||
|
val activity = callback ?: throw IOException("Interrupted")
|
||||||
|
val gcd = Geocoder(activity, Locale.getDefault())
|
||||||
return gcd.getFromLocation(location.latitude, location.longitude, 1)
|
return gcd.getFromLocation(location.latitude, location.longitude, 1)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
return null
|
return null
|
||||||
|
@ -1812,9 +1812,10 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||||
|
|
||||||
override fun beforeExecute() {
|
override fun beforeExecute() {
|
||||||
val location = params
|
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 attachLocation = preferences[attachLocationKey]
|
||||||
val attachPreciseLocation = preferences[attachPreciseLocationKey]
|
val attachPreciseLocation = preferences[attachPreciseLocationKey]
|
||||||
if (attachLocation) {
|
if (attachLocation) {
|
||||||
|
@ -1836,9 +1837,10 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun afterExecute(textView: TextView?, addresses: List<Address>?) {
|
override fun afterExecute(activity: ComposeActivity?, addresses: List<Address>?) {
|
||||||
textView!!
|
if (activity == null) return
|
||||||
val preferences = context.preferences
|
val textView = activity.locationLabel ?: return
|
||||||
|
val preferences = activity.preferences
|
||||||
val attachLocation = preferences[attachLocationKey]
|
val attachLocation = preferences[attachLocationKey]
|
||||||
val attachPreciseLocation = preferences[attachPreciseLocationKey]
|
val attachPreciseLocation = preferences[attachPreciseLocationKey]
|
||||||
if (attachLocation) {
|
if (attachLocation) {
|
||||||
|
|
|
@ -39,6 +39,7 @@ import org.mariotaku.twidere.util.TwidereMathUtils
|
||||||
import org.mariotaku.twidere.util.UriUtils
|
import org.mariotaku.twidere.util.UriUtils
|
||||||
import org.mariotaku.twidere.util.media.MediaExtra
|
import org.mariotaku.twidere.util.media.MediaExtra
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.lang.ref.WeakReference
|
||||||
|
|
||||||
class ImagePageFragment : SubsampleImageViewerFragment() {
|
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 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 {
|
override fun create(uri: Uri): CacheDownloadLoader.Result {
|
||||||
|
val context = weakContext.get() ?: return CacheDownloadLoader.Result.getInstance(InterruptedException())
|
||||||
val o = BitmapFactory.Options()
|
val o = BitmapFactory.Options()
|
||||||
o.inJustDecodeBounds = true
|
o.inJustDecodeBounds = true
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.mariotaku.ktextension.addOnAccountsUpdatedListenerSafe
|
||||||
import org.mariotaku.ktextension.removeOnAccountsUpdatedListenerSafe
|
import org.mariotaku.ktextension.removeOnAccountsUpdatedListenerSafe
|
||||||
import org.mariotaku.twidere.model.AccountDetails
|
import org.mariotaku.twidere.model.AccountDetails
|
||||||
import org.mariotaku.twidere.model.util.AccountUtils
|
import org.mariotaku.twidere.model.util.AccountUtils
|
||||||
|
import java.lang.ref.WeakReference
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mariotaku on 2016/12/4.
|
* Created by mariotaku on 2016/12/4.
|
||||||
|
@ -42,8 +43,9 @@ class AccountDetailsLoader(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartLoading() {
|
override fun onStartLoading() {
|
||||||
|
val weakThis = WeakReference(this)
|
||||||
accountUpdateListener = OnAccountsUpdateListener {
|
accountUpdateListener = OnAccountsUpdateListener {
|
||||||
onContentChanged()
|
weakThis.get()?.onContentChanged()
|
||||||
}
|
}
|
||||||
if (takeContentChanged()) {
|
if (takeContentChanged()) {
|
||||||
forceLoad()
|
forceLoad()
|
||||||
|
|
Loading…
Reference in New Issue