fixed loader memory leak
This commit is contained in:
parent
eb805f8f22
commit
4831f3db38
|
@ -38,6 +38,7 @@ import org.mariotaku.twidere.app.TwidereApplication;
|
|||
import org.mariotaku.twidere.model.ListResponse;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.util.JsonSerializer;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.TwidereArrayUtils;
|
||||
import org.mariotaku.twidere.util.TwitterAPIFactory;
|
||||
import org.mariotaku.twidere.util.TwitterContentUtils;
|
||||
|
@ -56,7 +57,6 @@ import javax.inject.Inject;
|
|||
|
||||
public abstract class TwitterAPIStatusesLoader extends ParcelableStatusesLoader {
|
||||
|
||||
private final Context mContext;
|
||||
private final long mAccountId;
|
||||
private final long mMaxId, mSinceId;
|
||||
@Nullable
|
||||
|
@ -64,13 +64,14 @@ public abstract class TwitterAPIStatusesLoader extends ParcelableStatusesLoader
|
|||
private Comparator<ParcelableStatus> mComparator;
|
||||
@Inject
|
||||
DiskCache mFileCache;
|
||||
@Inject
|
||||
SharedPreferencesWrapper mPreferences;
|
||||
|
||||
public TwitterAPIStatusesLoader(final Context context, final long accountId, final long sinceId,
|
||||
final long maxId, final List<ParcelableStatus> data,
|
||||
@Nullable final String[] savedStatusesArgs, final int tabPosition, boolean fromUser) {
|
||||
super(context, data, tabPosition, fromUser);
|
||||
GeneralComponentHelper.build(context).inject(this);
|
||||
mContext = context;
|
||||
mAccountId = accountId;
|
||||
mMaxId = maxId;
|
||||
mSinceId = sinceId;
|
||||
|
@ -193,7 +194,7 @@ public abstract class TwitterAPIStatusesLoader extends ParcelableStatusesLoader
|
|||
|
||||
@Nullable
|
||||
protected final Twitter getTwitter() {
|
||||
return TwitterAPIFactory.getTwitterInstance(mContext, mAccountId, true, true);
|
||||
return TwitterAPIFactory.getTwitterInstance(getContext(), mAccountId, true, true);
|
||||
}
|
||||
|
||||
protected abstract boolean shouldFilterStatus(final SQLiteDatabase database, final ParcelableStatus status);
|
||||
|
@ -223,8 +224,7 @@ public abstract class TwitterAPIStatusesLoader extends ParcelableStatusesLoader
|
|||
private void saveCachedData(final List<ParcelableStatus> data) {
|
||||
final String key = getSerializationKey();
|
||||
if (key == null || data == null) return;
|
||||
final SharedPreferences prefs = mContext.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
final int databaseItemLimit = prefs.getInt(KEY_DATABASE_ITEM_LIMIT, DEFAULT_DATABASE_ITEM_LIMIT);
|
||||
final int databaseItemLimit = mPreferences.getInt(KEY_DATABASE_ITEM_LIMIT, DEFAULT_DATABASE_ITEM_LIMIT);
|
||||
try {
|
||||
final List<ParcelableStatus> statuses = data.subList(0, Math.min(databaseItemLimit, data.size()));
|
||||
final PipedOutputStream pos = new PipedOutputStream();
|
||||
|
|
|
@ -36,17 +36,14 @@ public abstract class TwitterAPIUsersLoader extends ParcelableUsersLoader {
|
|||
|
||||
private final long mAccountId;
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
public TwitterAPIUsersLoader(final Context context, final long accountId, final List<ParcelableUser> data, boolean fromUser) {
|
||||
super(context, data, fromUser);
|
||||
mContext = context;
|
||||
mAccountId = accountId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ParcelableUser> loadInBackground() {
|
||||
final Twitter twitter = TwitterAPIFactory.getTwitterInstance(mContext, mAccountId, true);
|
||||
final Twitter twitter = TwitterAPIFactory.getTwitterInstance(getContext(), mAccountId, true);
|
||||
if (twitter == null) return null;
|
||||
final List<ParcelableUser> data = getData();
|
||||
final List<User> users;
|
||||
|
|
Loading…
Reference in New Issue