@Override protected List<TwitterWrapper.StatusListResponse> doInBackground(final Object... params) { final List<TwitterWrapper.StatusListResponse> result = new ArrayList<>(); if (accountIds == null) return result; int idx = 0; final SharedPreferencesWrapper preferences = twitterWrapper.getPreferences(); final Context context = twitterWrapper.getContext(); final ErrorInfoStore errorInfoStore = twitterWrapper.getErrorInfoStore(); final int loadItemLimit = preferences.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT); for (final long accountId : accountIds) { final Twitter twitter = TwitterAPIFactory.getTwitterInstance(context, accountId, true); if (twitter == null) continue; try { final Paging paging = new Paging(); paging.count(loadItemLimit); final long maxId, sinceId; if (maxIds != null && maxIds[idx] > 0) { maxId = maxIds[idx]; paging.maxId(maxId); } else { maxId = -1; } if (sinceIds != null && sinceIds[idx] > 0) { sinceId = sinceIds[idx]; paging.sinceId(sinceId - 1); if (maxIds == null || sinceIds[idx] <= 0) { paging.setLatestResults(true); } } else { sinceId = -1; } final List<org.mariotaku.twidere.api.twitter.model.Status> statuses = getStatuses(twitter, paging); TwitterContentUtils.getStatusesWithQuoteData(twitter, statuses); storeStatus(accountId, statuses, sinceId, maxId, true, loadItemLimit); publishProgress(new TwitterWrapper.StatusListResponse(accountId, statuses)); errorInfoStore.remove(getErrorInfoKey(), accountId); } catch (final TwitterException e) { if (BuildConfig.DEBUG) { Log.w(LOGTAG, e); } if (e.isCausedByNetworkIssue()) { errorInfoStore.put(getErrorInfoKey(), accountId, ErrorInfoStore.CODE_NETWORK_ERROR); } result.add(new TwitterWrapper.StatusListResponse(accountId, e)); } idx++; } return result; }
@Provides @Singleton public SharedPreferencesWrapper sharedPreferences() { return SharedPreferencesWrapper.getInstance( application, Constants.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE, SharedPreferenceConstants.class); }
FilterUsersListAdapter(final Context context) { super( context, android.R.layout.simple_list_item_activated_1, null, new String[0], new int[0], 0); GeneralComponentHelper.build(context).inject(this); mNameFirst = mPreferences.getBoolean(KEY_NAME_FIRST, true); }
private DiskCache createDiskCache(final String dirName, SharedPreferencesWrapper preferences) { final File cacheDir = Utils.getExternalCacheDir(application, dirName); final File fallbackCacheDir = getInternalCacheDir(application, dirName); final URLFileNameGenerator fileNameGenerator = new URLFileNameGenerator(); final int cacheSize = TwidereMathUtils.clamp(preferences.getInt(KEY_CACHE_SIZE_LIMIT, 300), 100, 500); try { final int cacheMaxSizeBytes = cacheSize * 1024 * 1024; if (cacheDir != null) return new LruDiskCache( cacheDir, fallbackCacheDir, fileNameGenerator, cacheMaxSizeBytes, 0); return new LruDiskCache(fallbackCacheDir, null, fileNameGenerator, cacheMaxSizeBytes, 0); } catch (IOException e) { return new ReadOnlyDiskLRUNameCache(cacheDir, fallbackCacheDir, fileNameGenerator); } }