diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIStatusesLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIStatusesLoader.java index c6a121b5f..e1fc6fc97 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIStatusesLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIStatusesLoader.java @@ -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 mComparator; @Inject DiskCache mFileCache; + @Inject + SharedPreferencesWrapper mPreferences; public TwitterAPIStatusesLoader(final Context context, final long accountId, final long sinceId, final long maxId, final List 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 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 statuses = data.subList(0, Math.min(databaseItemLimit, data.size())); final PipedOutputStream pos = new PipedOutputStream(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIUsersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIUsersLoader.java index 4facd0f9d..c1274a82c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIUsersLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIUsersLoader.java @@ -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 data, boolean fromUser) { super(context, data, fromUser); - mContext = context; mAccountId = accountId; } @Override public List loadInBackground() { - final Twitter twitter = TwitterAPIFactory.getTwitterInstance(mContext, mAccountId, true); + final Twitter twitter = TwitterAPIFactory.getTwitterInstance(getContext(), mAccountId, true); if (twitter == null) return null; final List data = getData(); final List users;