mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-01-31 17:04:59 +01:00
trying to fix compose memory leak
This commit is contained in:
parent
1f5617b003
commit
9d0994153d
@ -160,8 +160,7 @@ public class UserKey implements Comparable<UserKey>, Parcelable {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static UserKey[] arrayOf(@Nullable String str) {
|
||||
if (str == null) return null;
|
||||
public static UserKey[] arrayOf(@NonNull String str) {
|
||||
List<String> split = split(str, ",");
|
||||
UserKey[] keys = new UserKey[split.size()];
|
||||
for (int i = 0, splitLength = split.size(); i < splitLength; i++) {
|
||||
|
@ -110,8 +110,9 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
lateinit var validator: TwidereValidator
|
||||
@Inject
|
||||
lateinit var defaultFeatures: DefaultFeatures
|
||||
@Inject
|
||||
lateinit var locationManager: LocationManager
|
||||
|
||||
private lateinit var locationManager: LocationManager
|
||||
private lateinit var itemTouchHelper: ItemTouchHelper
|
||||
private val supportMenuInflater by lazy { SupportMenuInflater(this) }
|
||||
private var currentTask: AsyncTask<Any, Any, *>? = null
|
||||
@ -229,9 +230,10 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
imageUploaderUsed = !ServicePickerPreference.isNoneValue(preferences.getString(KEY_MEDIA_UPLOADER, null))
|
||||
statusShortenerUsed = !ServicePickerPreference.isNoneValue(preferences.getString(KEY_STATUS_SHORTENER, null))
|
||||
if (preferences[attachLocationKey]) {
|
||||
|
||||
imageUploaderUsed = !ServicePickerPreference.isNoneValue(kPreferences[mediaUploaderKey])
|
||||
statusShortenerUsed = !ServicePickerPreference.isNoneValue(kPreferences[statusShortenerKey])
|
||||
if (kPreferences[attachLocationKey]) {
|
||||
if (checkAnySelfPermissionsGranted(AndroidPermission.ACCESS_COARSE_LOCATION, AndroidPermission.ACCESS_FINE_LOCATION)) {
|
||||
try {
|
||||
startLocationUpdateIfEnabled()
|
||||
@ -480,7 +482,6 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
GeneralComponentHelper.build(this).inject(this)
|
||||
locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||
nameFirst = preferences[nameFirstKey]
|
||||
setContentView(R.layout.activity_compose)
|
||||
|
||||
@ -504,8 +505,8 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
accountSelectorButton.setOnClickListener(this)
|
||||
replyLabel.setOnClickListener(this)
|
||||
locationSwitch.max = LOCATION_OPTIONS.size
|
||||
val attachLocation = preferences[attachLocationKey]
|
||||
val attachPreciseLocation = preferences[attachPreciseLocationKey]
|
||||
val attachLocation = kPreferences[attachLocationKey]
|
||||
val attachPreciseLocation = kPreferences[attachPreciseLocationKey]
|
||||
if (attachLocation) {
|
||||
if (attachPreciseLocation) {
|
||||
locationSwitch.checkedPosition = LOCATION_OPTIONS.indexOf(LOCATION_VALUE_COORDINATE)
|
||||
@ -530,10 +531,10 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
attachPreciseLocationChecked = false
|
||||
}
|
||||
}
|
||||
preferences.edit()
|
||||
.putBoolean(KEY_ATTACH_LOCATION, attachLocationChecked)
|
||||
.putBoolean(KEY_ATTACH_PRECISE_LOCATION, attachPreciseLocationChecked)
|
||||
.apply()
|
||||
kPreferences.edit {
|
||||
this[attachLocationKey] = attachLocationChecked
|
||||
this[attachPreciseLocationKey] = attachPreciseLocationChecked
|
||||
}
|
||||
if (attachLocationChecked) {
|
||||
requestOrUpdateLocation()
|
||||
} else if (locationListener != null) {
|
||||
@ -599,7 +600,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
setLabel(intent)
|
||||
val selectedAccountIds = accountsAdapter.selectedAccountKeys
|
||||
if (ArrayUtils.isEmpty(selectedAccountIds)) {
|
||||
val idsInPrefs: Array<UserKey> = UserKey.arrayOf(preferences.getString(KEY_COMPOSE_ACCOUNTS, null)) ?: emptyArray()
|
||||
val idsInPrefs: Array<UserKey> = kPreferences[composeAccountsKey] ?: emptyArray()
|
||||
val intersection: Array<UserKey> = defaultAccountIds.intersect(listOf(*idsInPrefs)).toTypedArray()
|
||||
|
||||
if (intersection.isEmpty()) {
|
||||
|
@ -10,9 +10,11 @@ import org.mariotaku.twidere.Constants.KEY_DISPLAY_PROFILE_IMAGE
|
||||
import org.mariotaku.twidere.Constants.KEY_NO_CLOSE_AFTER_TWEET_SENT
|
||||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_COMPOSE_ACCOUNTS
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_DISPLAY_SENSITIVE_CONTENTS
|
||||
import org.mariotaku.twidere.extension.getNonEmptyString
|
||||
import org.mariotaku.twidere.model.CustomAPIConfig
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.account.cred.Credentials
|
||||
import org.mariotaku.twidere.model.sync.SyncProviderInfo
|
||||
import org.mariotaku.twidere.preference.ThemeBackgroundPreference
|
||||
@ -188,3 +190,17 @@ object dataSyncProviderInfoKey : KPreferenceKey<SyncProviderInfo?> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object composeAccountsKey : KSimpleKey<Array<UserKey>?>(KEY_COMPOSE_ACCOUNTS, null) {
|
||||
|
||||
override fun read(preferences: SharedPreferences): Array<UserKey>? {
|
||||
val string = preferences.getString(key, null) ?: return null
|
||||
return UserKey.arrayOf(string)
|
||||
}
|
||||
|
||||
override fun write(editor: SharedPreferences.Editor, value: Array<UserKey>?): Boolean {
|
||||
editor.putString(key, value?.joinToString(","))
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
@ -21,6 +21,7 @@ package org.mariotaku.twidere.util.dagger
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.location.LocationManager
|
||||
import android.os.Build
|
||||
import android.os.Looper
|
||||
import android.support.v4.text.BidiFormatter
|
||||
@ -293,6 +294,11 @@ class ApplicationModule(private val application: Application) {
|
||||
return ETagCache(application)
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun locationManager(): LocationManager {
|
||||
return application.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||
}
|
||||
|
||||
private fun createDiskCache(dirName: String, preferences: SharedPreferencesWrapper): DiskCache {
|
||||
val cacheDir = Utils.getExternalCacheDir(application, dirName)
|
||||
val fallbackCacheDir = Utils.getInternalCacheDir(application, dirName)
|
||||
|
Loading…
x
Reference in New Issue
Block a user