Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

full cached users.

  • Loading branch information...
commit 1c110577da5e762d9db8c3efaac1a44e430d9479 1 parent 02416bc
@mariotaku authored
Showing with 516 additions and 391 deletions.
  1. +1 −1  TODOS
  2. +10 −9 res/values-zh-rCN/strings.xml
  3. +1 −1  src/org/mariotaku/twidere/Constants.java
  4. +20 −21 src/org/mariotaku/twidere/activity/ImageViewerActivity.java
  5. +3 −1 src/org/mariotaku/twidere/adapter/AutoCompleteAdapter.java
  6. +1 −1  src/org/mariotaku/twidere/adapter/UsersAdapter.java
  7. +4 −4 src/org/mariotaku/twidere/fragment/StatusFragment.java
  8. +60 −33 src/org/mariotaku/twidere/fragment/UserProfileFragment.java
  9. +1 −2  src/org/mariotaku/twidere/graphic/AlphaPatternDrawable.java
  10. +3 −1 src/org/mariotaku/twidere/loader/Twitter4JStatusLoader.java
  11. +52 −15 src/org/mariotaku/twidere/model/ParcelableUser.java
  12. +3 −1 src/org/mariotaku/twidere/model/PreviewImage.java
  13. +28 −3 src/org/mariotaku/twidere/provider/TweetStore.java
  14. +38 −35 src/org/mariotaku/twidere/util/CacheUsersStatusesTask.java
  15. +8 −0 src/org/mariotaku/twidere/util/ThumbnailUtils.java
  16. +248 −230 src/org/mariotaku/twidere/util/TwitterWrapper.java
  17. +21 −16 src/org/mariotaku/twidere/util/Utils.java
  18. +2 −5 src/org/mariotaku/twidere/view/ImagePreviewView.java
  19. +12 −12 src/org/mariotaku/twidere/view/RoundCorneredImageView.java
View
2  TODOS
@@ -3,4 +3,4 @@
2012-12-14
* option to enable/disable full image preview.
2012-12-15
- * full user caching (store in cached_users tab)
+ [FINISHED] full user caching (store in cached_users table)
View
19 res/values-zh-rCN/strings.xml
@@ -212,10 +212,6 @@
<string name="lists_following_user">关注这个用户的列表</string>
<string name="Ntweets_quantity_one">你有一条新推文</string>
<string name="Ntweets_quantity_other">你有 <xliff:g id="items">%d</xliff:g> 条新推文</string>
-
-
-
-
<string name="item_1_minute">1分钟</string>
<string name="item_3_minutes">3分钟</string>
<string name="item_5_minutes">5分钟</string>
@@ -229,7 +225,7 @@
<string name="solid_color_background">纯色背景</string>
<string name="solid_color_background_summary">如果你的设备是AMOLED屏幕的话,启用这个会有所帮助</string>
<string name="following_you">正在关注你</string>
- <string name="user_list">用户列表</string>
+ <string name="user_list">列表</string>
<string name="trends_location">本地趋势的位置</string>
<string name="trends_location_summary">设定位置,以显示本地趋势</string>
<string name="trends">话题</string>
@@ -241,12 +237,12 @@
<string name="add_member">添加成员</string>
<string name="add_successfully">添加成功</string>
<string name="create_successfully">创建成功</string>
- <string name="new_user_list">新用户列表</string>
+ <string name="new_user_list">新列表</string>
<string name="is_public">公开</string>
<string name="send_direct_message">发送私信</string>
<string name="extensions">扩展</string>
<string name="open_with_extensions">使用扩展打开</string>
- <string name="view_user_list">查看用户列表</string>
+ <string name="view_user_list">查看列表</string>
<string name="uninstall">卸载</string>
<string name="users_retweeted_this">转推了这条推文的用户</string>
<string name="saved_searches">已保存的搜索</string>
@@ -263,7 +259,7 @@
<string name="invalid_settings">发现无效设定</string>
<string name="icon">图标</string>
<string name="pick_file">选取文件</string>
- <string name="user_timeline">用户时间线</string>
+ <string name="user_timeline">时间线</string>
<string name="notification_ringtone">铃声</string>
<string name="notification_light_color">灯光颜色</string>
<string name="share_format">分享格式</string>
@@ -375,5 +371,10 @@
<string name="pull_to_load_conversation_release_label">释放加载对话…</string>
<string name="text_copied">文本已复制到剪贴板</string>
<string name="load_from_here">从这里加载</string>
+ <string name="amount_usd">总额(美元)</string>
+ <string name="donate">捐助</string>
+ <string name="hashtag">话题标签</string>
+ <string name="links">链接</string>
+ <string name="edit_profile">编辑个人资料</string>
-</resources>
+</resources>
View
2  src/org/mariotaku/twidere/Constants.java
@@ -49,7 +49,7 @@
public static final String PERMISSION_PREFERENCES_NAME = "permissions";
public static final String DATABASES_NAME = "twidere.sqlite";
- public static final int DATABASES_VERSION = 33;
+ public static final int DATABASES_VERSION = 34;
// The following 4 constants are not included in source code, you'd better
// use your own.
View
41 src/org/mariotaku/twidere/activity/ImageViewerActivity.java
@@ -58,7 +58,6 @@
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
-import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
@@ -316,7 +315,7 @@ private Bitmap decodeFile(final File f) {
if (o.outHeight <= 0) return null;
final BitmapFactory.Options o1 = new BitmapFactory.Options();
final double size = Math.max(o.outWidth, o.outHeight);
- o1.inSampleSize = (size > max_texture_size) ? (int) Math.round(size / max_texture_size) + 1: 1;
+ o1.inSampleSize = size > max_texture_size ? (int) Math.round(size / max_texture_size) + 1 : 1;
Bitmap bitmap = null;
while (bitmap == null) {
try {
@@ -335,23 +334,36 @@ private Bitmap decodeFile(final File f) {
return null;
}
+ private String getURLFilename(final String url) {
+ if (url == null) return null;
+ return url.replaceFirst("https?:\\/\\/", "").replaceAll("[^a-zA-Z0-9]", "_");
+ }
+
+ private void init() {
+ /* Find the dir to save cached images. */
+ mCacheDir = getBestCacheDir(mContext, CACHE_DIR_NAME);
+ if (mCacheDir != null && !mCacheDir.exists()) {
+ mCacheDir.mkdirs();
+ }
+ }
+
public static int getMaximumTextureSize() {
- EGL10 egl = (EGL10) EGLContext.getEGL();
- EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
+ final EGL10 egl = (EGL10) EGLContext.getEGL();
+ final EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
// Initialise
- int[] version = new int[2];
+ final int[] version = new int[2];
egl.eglInitialize(display, version);
// Query total number of configurations
- int[] totalConfigurations = new int[1];
+ final int[] totalConfigurations = new int[1];
egl.eglGetConfigs(display, null, 0, totalConfigurations);
// Query actual list configurations
- EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
+ final EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);
- int[] textureSize = new int[1];
+ final int[] textureSize = new int[1];
int maximumTextureSize = 0;
// Iterate through all the configurations to located the maximum
@@ -373,19 +385,6 @@ public static int getMaximumTextureSize() {
return maximumTextureSize;
}
- private String getURLFilename(final String url) {
- if (url == null) return null;
- return url.replaceFirst("https?:\\/\\/", "").replaceAll("[^a-zA-Z0-9]", "_");
- }
-
- private void init() {
- /* Find the dir to save cached images. */
- mCacheDir = getBestCacheDir(mContext, CACHE_DIR_NAME);
- if (mCacheDir != null && !mCacheDir.exists()) {
- mCacheDir.mkdirs();
- }
- }
-
public static class Result {
public final Bitmap bitmap;
public final File file;
View
4 src/org/mariotaku/twidere/adapter/AutoCompleteAdapter.java
@@ -42,6 +42,8 @@
private static final String[] FROM = new String[0];
private static final int[] TO = new int[0];
+ private static final String[] CACHED_USERS_COLUMNS = new String[] { CachedUsers._ID, CachedUsers.NAME,
+ CachedUsers.SCREEN_NAME, CachedUsers.PROFILE_IMAGE_URL };
private final ContentResolver mResolver;
private final LazyImageLoader mProfileImageLoader;
@@ -149,7 +151,7 @@ public Cursor runQueryOnBackgroundThread(final CharSequence constraint) {
where.append(CachedUsers.SCREEN_NAME + " LIKE '" + constraint_escaped + "%' ESCAPE '^'");
where.append(" OR ");
where.append(CachedUsers.NAME + " LIKE '" + constraint_escaped + "%' ESCAPE '^'");
- return mResolver.query(CachedUsers.CONTENT_URI, CachedUsers.COLUMNS,
+ return mResolver.query(CachedUsers.CONTENT_URI, CACHED_USERS_COLUMNS,
constraint_escaped != null ? where.toString() : null, null, null);
} else {
final String where = CachedHashtags.NAME + " LIKE '" + constraint_escaped + "%' ESCAPE '^'";
View
2  src/org/mariotaku/twidere/adapter/UsersAdapter.java
@@ -114,7 +114,7 @@ public View getView(final int position, final View convertView, final ViewGroup
holder.description.setText(user.description);
holder.profile_image.setVisibility(mDisplayProfileImage ? View.VISIBLE : View.GONE);
if (mDisplayProfileImage) {
- mProfileImageLoader.displayImage(user.profile_image_url_string, holder.profile_image);
+ mProfileImageLoader.displayImage(user.profile_image_url, holder.profile_image);
}
return view;
View
8 src/org/mariotaku/twidere/fragment/StatusFragment.java
@@ -112,24 +112,25 @@
OnImageClickListener {
private static final int LOADER_ID_STATUS = 1;
-
private static final int LOADER_ID_FOLLOW = 2;
private static final int LOADER_ID_LOCATION = 3;
private static final int LOADER_ID_CONVERSATION = 4;
+
private long mAccountId, mStatusId;
+ private ParcelableStatus mStatus;
private boolean mLoadMoreAutomatically;
private boolean mFollowInfoDisplayed, mLocationInfoDisplayed;
private boolean mStatusLoaderInitialized, mLocationLoaderInitialized, mConversationLoaderInitialized;
private boolean mFollowInfoLoaderInitialized;;
private boolean mShouldScroll;
- private SharedPreferences mPreferences;
+ private SharedPreferences mPreferences;
private TwitterWrapper mTwitterWrapper;
private LazyImageLoader mProfileImageLoader;
+
private TextView mNameView, mScreenNameView, mTextView, mTimeAndSourceView, mInReplyToView, mLocationView,
mRetweetedStatusView;
-
private ImageView mProfileImageView;
private Button mFollowButton;
private View mMainContent, mFollowIndicator, mImagePreviewContainer;
@@ -141,7 +142,6 @@
private View mLoadImagesIndicator;
private ExtendedFrameLayout mStatusContainer;
private ListView mListView;
- private ParcelableStatus mStatus;
private final BroadcastReceiver mStatusReceiver = new BroadcastReceiver() {
View
93 src/org/mariotaku/twidere/fragment/UserProfileFragment.java
@@ -38,6 +38,7 @@
import static org.mariotaku.twidere.util.Utils.getUserColor;
import static org.mariotaku.twidere.util.Utils.getUserTypeIconRes;
import static org.mariotaku.twidere.util.Utils.isMyAccount;
+import static org.mariotaku.twidere.util.Utils.makeCachedUserContentValues;
import static org.mariotaku.twidere.util.Utils.openIncomingFriendships;
import static org.mariotaku.twidere.util.Utils.openSavedSearches;
import static org.mariotaku.twidere.util.Utils.openTweetSearch;
@@ -81,19 +82,18 @@
import twitter4j.Relationship;
import twitter4j.Twitter;
import twitter4j.TwitterException;
+import twitter4j.User;
import twitter4j.http.HostAddressResolver;
import twitter4j.http.HttpClientWrapper;
import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
+import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
@@ -104,24 +104,20 @@
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
-import android.support.v4.app.DialogFragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
-import android.text.InputFilter;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
-import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
-import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
@@ -150,7 +146,7 @@
private ColorLabelRelativeLayout mProfileNameContainer;
private ListView mListView;
private View mHeaderView;
-
+
private ListActionAdapter mAdapter;
private long mAccountId;
@@ -206,11 +202,12 @@ public void onReceive(final Context context, final Intent intent) {
mErrorRetryContainer.setVisibility(View.GONE);
mErrorMessageView.setText(null);
mErrorMessageView.setVisibility(View.GONE);
- setListShown(false);
+ setListShown(mUser != null
+ && (mUserId == mUser.user_id || mScreenName != null && mScreenName.equals(mUser.screen_name)));
setProgressBarIndeterminateVisibility(true);
final boolean omit_intent_extra = args != null ? args.getBoolean(INTENT_KEY_OMIT_INTENT_EXTRA, true) : true;
return new UserInfoLoader(getActivity(), mAccountId, mUserId, mScreenName, getArguments(),
- omit_intent_extra);
+ omit_intent_extra, mUser);
}
@Override
@@ -225,6 +222,9 @@ public void onLoadFinished(final Loader<Response<ParcelableUser>> loader, final
setListShown(true);
displayUser(data.value);
mErrorRetryContainer.setVisibility(View.GONE);
+ if (data.value.is_cache) {
+ getLoaderManager().restartLoader(LOADER_ID_USER, null, this);
+ }
} else {
if (data.exception != null) {
mErrorMessageView.setText(data.exception.getMessage());
@@ -353,23 +353,23 @@ public void displayUser(final ParcelableUser user) {
final String location = user.location;
mLocationContainer.setVisibility(user_is_me || !isEmpty(location) ? View.VISIBLE : View.GONE);
mLocationView.setText(location);
- mURLContainer.setVisibility(user_is_me || !isEmpty(user.url_string) ? View.VISIBLE : View.GONE);
- mURLView.setText(user.url_string);
+ mURLContainer.setVisibility(user_is_me || !isEmpty(user.url) ? View.VISIBLE : View.GONE);
+ mURLView.setText(user.url);
mURLView.setMovementMethod(null);
mCreatedAtView.setText(formatToLongTimeString(getActivity(), user.created_at));
mTweetCount.setText(String.valueOf(user.statuses_count));
mFollowersCount.setText(String.valueOf(user.followers_count));
mFriendsCount.setText(String.valueOf(user.friends_count));
if (mPreferences.getBoolean(PREFERENCE_KEY_DISPLAY_PROFILE_IMAGE, true)) {
- mProfileImageLoader.displayImage(user.profile_image_url_string, mProfileImageView);
+ mProfileImageLoader.displayImage(user.profile_image_url, mProfileImageView);
} else {
mProfileImageView.setImageResource(R.drawable.ic_profile_image_default);
}
if (isMyAccount(getActivity(), user.user_id)) {
final ContentResolver resolver = getContentResolver();
final ContentValues values = new ContentValues();
- if (user.profile_image_url_string != null) {
- values.put(Accounts.PROFILE_IMAGE_URL, user.profile_image_url_string);
+ if (user.profile_image_url != null) {
+ values.put(Accounts.PROFILE_IMAGE_URL, user.profile_image_url);
}
values.put(Accounts.NAME, user.name);
values.put(Accounts.SCREEN_NAME, user.screen_name);
@@ -412,7 +412,6 @@ public void getUserInfo(final long account_id, final long user_id, final String
} else {
lm.restartLoader(LOADER_ID_USER, args, mUserInfoLoaderCallbacks);
}
-
if (account_id == -1 || user_id == -1 && screen_name == null) {
mListContainer.setVisibility(View.GONE);
mErrorRetryContainer.setVisibility(View.GONE);
@@ -530,7 +529,7 @@ public boolean onMenuItemClick(final MenuItem item) {
break;
}
case R.id.profile_image_container: {
- final Uri uri = Uri.parse(getOriginalTwitterProfileImage(mUser.profile_image_url_string));
+ final Uri uri = Uri.parse(getOriginalTwitterProfileImage(mUser.profile_image_url));
final Intent intent = new Intent(INTENT_ACTION_VIEW_IMAGE, uri);
intent.setPackage(getActivity().getPackageName());
startActivity(intent);
@@ -875,9 +874,9 @@ public BannerImageLoader(final Context context, final ParcelableUser user, final
@Override
public Bitmap loadInBackground() {
- if (user == null || user.profile_banner_url_string == null) return null;
+ if (user == null || user.profile_banner_url == null) return null;
try {
- final String url = user.profile_banner_url_string + "/" + getBestBannerType(width);
+ final String url = user.profile_banner_url + "/" + getBestBannerType(width);
final File cache_dir = getImageCacheDir();
final File cache_file = cache_dir != null && cache_dir.isDirectory() ? new File(cache_dir,
getURLFilename(url)) : null;
@@ -978,6 +977,7 @@ protected void onStartLoading() {
private Response<Relationship> getFriendship() {
if (account_id == user_id) return new Response<Relationship>(null, null);
final Twitter twitter = getTwitterInstance(context, account_id, false);
+ if (twitter == null) return new Response<Relationship>(null, null);
try {
final Relationship result = twitter.showFriendship(account_id, user_id);
return new Response<Relationship>(result, null);
@@ -1010,8 +1010,8 @@ public void onClick() {
public final T value;
public final Exception exception;
- public Response(final T value1, final Exception exception) {
- this.value = value1;
+ public Response(final T value, final Exception exception) {
+ this.value = value;
this.exception = exception;
}
}
@@ -1057,18 +1057,22 @@ public void onClick() {
static final class UserInfoLoader extends AsyncTaskLoader<Response<ParcelableUser>> {
private final Twitter twitter;
- private final boolean omit_intent_extra;
+ private final ContentResolver resolver;
+ private final boolean omit_intent_extra, hires_profile_image;
private final Bundle extras;
private final long account_id, user_id;
private final String screen_name;
- private final boolean hires_profile_image;
+ private final ParcelableUser user;
private UserInfoLoader(final Context context, final long account_id, final long user_id,
- final String screen_name, final Bundle extras, final boolean omit_intent_extra) {
+ final String screen_name, final Bundle extras, final boolean omit_intent_extra,
+ final ParcelableUser user) {
super(context);
+ resolver = context.getContentResolver();
twitter = getTwitterInstance(context, account_id, true);
- this.omit_intent_extra = omit_intent_extra;
hires_profile_image = context.getResources().getBoolean(R.bool.hires_profile_image);
+ this.omit_intent_extra = omit_intent_extra;
+ this.user = user;
this.extras = extras;
this.account_id = account_id;
this.user_id = user_id;
@@ -1079,20 +1083,43 @@ private UserInfoLoader(final Context context, final long account_id, final long
public Response<ParcelableUser> loadInBackground() {
if (!omit_intent_extra && extras != null) {
final ParcelableUser user = extras.getParcelable(INTENT_KEY_USER);
- if (user != null) return new Response<ParcelableUser>(user, null);
+ if (user != null) {
+ final ContentValues values = ParcelableUser.makeCachedUserContentValues(user);
+ resolver.delete(CachedUsers.CONTENT_URI, CachedUsers.USER_ID + " = " + user.user_id, null);
+ resolver.insert(CachedUsers.CONTENT_URI, values);
+ return new Response<ParcelableUser>(user, null);
+ }
}
if (twitter == null) return new Response<ParcelableUser>(null, null);
+ if (user == null || !user.is_cache) {
+ final String where = CachedUsers.USER_ID + " = " + user_id + " OR " + CachedUsers.SCREEN_NAME + " = '"
+ + screen_name + "'";
+ final Cursor cur = resolver.query(CachedUsers.CONTENT_URI, CachedUsers.COLUMNS, where, null, null);
+ final int count = cur.getCount();
+ try {
+ if (count > 0) {
+ cur.moveToFirst();
+ return new Response<ParcelableUser>(new ParcelableUser(cur, account_id), null);
+ }
+ } finally {
+ cur.close();
+ }
+ }
try {
- if (user_id != -1)
- return new Response<ParcelableUser>(new ParcelableUser(twitter.showUser(user_id), account_id,
- hires_profile_image), null);
- else if (screen_name != null)
- return new Response<ParcelableUser>(new ParcelableUser(twitter.showUser(screen_name), account_id,
- hires_profile_image), null);
+ final User user;
+ if (user_id != -1) {
+ user = twitter.showUser(user_id);
+ } else if (screen_name != null) {
+ user = twitter.showUser(screen_name);
+ } else
+ return new Response<ParcelableUser>(null, null);
+ final ContentValues values = makeCachedUserContentValues(user, hires_profile_image);
+ resolver.delete(CachedUsers.CONTENT_URI, CachedUsers.USER_ID + " = " + user.getId(), null);
+ resolver.insert(CachedUsers.CONTENT_URI, values);
+ return new Response<ParcelableUser>(new ParcelableUser(user, account_id, hires_profile_image), null);
} catch (final TwitterException e) {
return new Response<ParcelableUser>(null, e);
}
- return new Response<ParcelableUser>(null, null);
}
@Override
View
3  src/org/mariotaku/twidere/graphic/AlphaPatternDrawable.java
@@ -96,9 +96,8 @@ protected void onBoundsChange(final Rect bounds) {
numRectanglesHorizontal = (int) Math.ceil(width / mRectangleSize);
numRectanglesVertical = (int) Math.ceil(height / mRectangleSize);
- this.invalidateSelf();
+ invalidateSelf();
}
-
}
View
4 src/org/mariotaku/twidere/loader/Twitter4JStatusLoader.java
@@ -27,6 +27,7 @@
import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.util.CacheUsersStatusesTask;
import org.mariotaku.twidere.util.SynchronizedStateSavedList;
+import org.mariotaku.twidere.util.TwitterWrapper.StatusListResponse;
import twitter4j.Paging;
import twitter4j.Status;
@@ -76,7 +77,8 @@ public Twitter4JStatusLoader(final Context context, final long account_id, final
final Status min_status = statuses.size() > 0 ? Collections.min(statuses) : null;
final long min_status_id = min_status != null ? min_status.getId() : -1;
if (context instanceof Activity) {
- ((Activity) context).runOnUiThread(CacheUsersStatusesTask.getRunnable(context, statuses, mAccountId));
+ ((Activity) context).runOnUiThread(CacheUsersStatusesTask.getRunnable(context, new StatusListResponse(
+ mAccountId, statuses)));
}
for (final Status status : statuses) {
final long id = status.getId();
View
67 src/org/mariotaku/twidere/model/ParcelableUser.java
@@ -29,6 +29,7 @@
import twitter4j.User;
import android.content.ContentValues;
+import android.database.Cursor;
import android.os.Parcel;
import android.os.Parcelable;
@@ -52,11 +53,34 @@ public ParcelableUser createFromParcel(final Parcel in) {
public final boolean is_protected, is_verified, is_follow_request_sent;
- public final String description, name, screen_name, location, profile_image_url_string, profile_banner_url_string,
- url_string;
+ public final String description, name, screen_name, location, profile_image_url, profile_banner_url, url;
public final int followers_count, friends_count, statuses_count, favorites_count;
+ public final boolean is_cache;
+
+ public ParcelableUser(final Cursor cursor, final long account_id) {
+ this.account_id = account_id;
+ position = -1;
+ is_follow_request_sent = false;
+ user_id = cursor.getLong(cursor.getColumnIndex(CachedUsers.USER_ID));
+ name = cursor.getString(cursor.getColumnIndex(CachedUsers.NAME));
+ screen_name = cursor.getString(cursor.getColumnIndex(CachedUsers.SCREEN_NAME));
+ profile_image_url = cursor.getString(cursor.getColumnIndex(CachedUsers.PROFILE_IMAGE_URL));
+ created_at = cursor.getLong(cursor.getColumnIndex(CachedUsers.CREATED_AT));
+ is_protected = cursor.getInt(cursor.getColumnIndex(CachedUsers.IS_PROTECTED)) == 1;
+ is_verified = cursor.getInt(cursor.getColumnIndex(CachedUsers.IS_VERIFIED)) == 1;
+ favorites_count = cursor.getInt(cursor.getColumnIndex(CachedUsers.FAVORITES_COUNT));
+ followers_count = cursor.getInt(cursor.getColumnIndex(CachedUsers.FOLLOWERS_COUNT));
+ friends_count = cursor.getInt(cursor.getColumnIndex(CachedUsers.FRIENDS_COUNT));
+ statuses_count = cursor.getInt(cursor.getColumnIndex(CachedUsers.STATUSES_COUNT));
+ location = cursor.getString(cursor.getColumnIndex(CachedUsers.LOCATION));
+ description = cursor.getString(cursor.getColumnIndex(CachedUsers.DESCRIPTION));
+ url = cursor.getString(cursor.getColumnIndex(CachedUsers.URL));
+ profile_banner_url = cursor.getString(cursor.getColumnIndex(CachedUsers.PROFILE_BANNER_URL));
+ is_cache = true;
+ }
+
public ParcelableUser(final Parcel in) {
position = in.readLong();
account_id = in.readLong();
@@ -68,14 +92,15 @@ public ParcelableUser(final Parcel in) {
screen_name = in.readString();
description = in.readString();
location = in.readString();
- profile_image_url_string = in.readString();
- profile_banner_url_string = in.readString();
- url_string = in.readString();
+ profile_image_url = in.readString();
+ profile_banner_url = in.readString();
+ url = in.readString();
is_follow_request_sent = in.readInt() == 1;
followers_count = in.readInt();
friends_count = in.readInt();
statuses_count = in.readInt();
favorites_count = in.readInt();
+ is_cache = in.readInt() == 1;
}
public ParcelableUser(final User user, final long account_id, final boolean large_profile_image) {
@@ -94,15 +119,16 @@ public ParcelableUser(final User user, final long account_id, final long positio
screen_name = user.getScreenName();
description = user.getDescription();
location = user.getLocation();
- profile_image_url_string = large_profile_image ? getBiggerTwitterProfileImage(profile_image_url_orig)
+ profile_image_url = large_profile_image ? getBiggerTwitterProfileImage(profile_image_url_orig)
: profile_image_url_orig;
- profile_banner_url_string = user.getProfileBannerImageUrl();
- url_string = parseString(user.getURL());
+ profile_banner_url = user.getProfileBannerImageUrl();
+ url = parseString(user.getURL());
is_follow_request_sent = user.isFollowRequestSent();
followers_count = user.getFollowersCount();
friends_count = user.getFriendsCount();
statuses_count = user.getStatusesCount();
favorites_count = user.getFavouritesCount();
+ is_cache = false;
}
@Override
@@ -144,9 +170,9 @@ public String toString() {
+ ", position=" + position + ", is_protected=" + is_protected + ", is_verified=" + is_verified
+ ", is_follow_request_sent=" + is_follow_request_sent + ", description=" + description + ", name="
+ name + ", screen_name=" + screen_name + ", location=" + location + ", profile_image_url_string="
- + profile_image_url_string + ", profile_banner_url_string=" + profile_banner_url_string
- + ", url_string=" + url_string + ", followers_count=" + followers_count + ", friends_count="
- + friends_count + ", statuses_count=" + statuses_count + ", favorites_count=" + favorites_count + "}";
+ + profile_image_url + ", profile_banner_url_string=" + profile_banner_url + ", url_string=" + url
+ + ", followers_count=" + followers_count + ", friends_count=" + friends_count + ", statuses_count="
+ + statuses_count + ", favorites_count=" + favorites_count + "}";
}
@Override
@@ -161,9 +187,9 @@ public void writeToParcel(final Parcel out, final int flags) {
out.writeString(screen_name);
out.writeString(description);
out.writeString(location);
- out.writeString(profile_image_url_string);
- out.writeString(profile_banner_url_string);
- out.writeString(url_string);
+ out.writeString(profile_image_url);
+ out.writeString(profile_banner_url);
+ out.writeString(url);
out.writeInt(is_follow_request_sent ? 1 : 0);
out.writeInt(followers_count);
out.writeInt(friends_count);
@@ -181,7 +207,18 @@ public static ContentValues makeCachedUserContentValues(final ParcelableUser use
values.put(CachedUsers.USER_ID, user.user_id);
values.put(CachedUsers.NAME, user.name);
values.put(CachedUsers.SCREEN_NAME, user.screen_name);
- values.put(CachedUsers.PROFILE_IMAGE_URL, user.profile_banner_url_string);
+ values.put(CachedUsers.PROFILE_IMAGE_URL, user.profile_image_url);
+ values.put(CachedUsers.CREATED_AT, user.created_at);
+ values.put(CachedUsers.IS_PROTECTED, user.is_protected ? 1 : 0);
+ values.put(CachedUsers.IS_VERIFIED, user.is_verified ? 1 : 0);
+ values.put(CachedUsers.FAVORITES_COUNT, user.favorites_count);
+ values.put(CachedUsers.FOLLOWERS_COUNT, user.followers_count);
+ values.put(CachedUsers.FRIENDS_COUNT, user.friends_count);
+ values.put(CachedUsers.STATUSES_COUNT, user.statuses_count);
+ values.put(CachedUsers.LOCATION, user.location);
+ values.put(CachedUsers.DESCRIPTION, user.description);
+ values.put(CachedUsers.URL, user.url);
+ values.put(CachedUsers.PROFILE_BANNER_URL, user.profile_banner_url);
return values;
}
}
View
4 src/org/mariotaku/twidere/model/PreviewImage.java
@@ -19,6 +19,8 @@
package org.mariotaku.twidere.model;
+import static android.text.TextUtils.isEmpty;
+
public class PreviewImage {
public final boolean has_image;
public final String matched_url, orig_url;
@@ -30,7 +32,7 @@ public PreviewImage(final boolean has_image, final String matched_url, final Str
}
public PreviewImage(final ImageSpec spec, final String orig_url) {
- this(spec != null && spec.preview_image_link != null, spec.preview_image_link, orig_url);
+ this(spec != null && !isEmpty(spec.preview_image_link), spec.preview_image_link, orig_url);
}
@Override
View
31 src/org/mariotaku/twidere/provider/TweetStore.java
@@ -190,6 +190,28 @@
*/
public static final String USER_ID = "user_id";
+ public static final String CREATED_AT = "created_at";
+
+ public static final String IS_PROTECTED = "is_protected";
+
+ public static final String IS_VERIFIED = "is_verified";
+
+ public static final String DESCRIPTION = "description";
+
+ public static final String LOCATION = "location";
+
+ public static final String URL = "url";
+
+ public static final String PROFILE_BANNER_URL = "profile_banner_url";
+
+ public static final String FOLLOWERS_COUNT = "followers_count";
+
+ public static final String FRIENDS_COUNT = "friends_count";
+
+ public static final String STATUSES_COUNT = "statuses_count";
+
+ public static final String FAVORITES_COUNT = "favorites_count";
+
/**
* User's screen name of the status.<br>
* Type: TEXT
@@ -202,10 +224,13 @@
*/
public static final String PROFILE_IMAGE_URL = "profile_image_url";
- public static final String[] COLUMNS = new String[] { _ID, USER_ID, NAME, SCREEN_NAME, PROFILE_IMAGE_URL };
+ public static final String[] COLUMNS = new String[] { _ID, USER_ID, CREATED_AT, NAME, SCREEN_NAME, DESCRIPTION,
+ LOCATION, URL, PROFILE_IMAGE_URL, PROFILE_BANNER_URL, IS_PROTECTED, IS_VERIFIED, FOLLOWERS_COUNT,
+ FRIENDS_COUNT, STATUSES_COUNT, FAVORITES_COUNT };
- public static final String[] TYPES = new String[] { TYPE_PRIMARY_KEY, TYPE_INT_UNIQUE, TYPE_TEXT, TYPE_TEXT,
- TYPE_TEXT };
+ public static final String[] TYPES = new String[] { TYPE_PRIMARY_KEY, TYPE_INT_UNIQUE, TYPE_INT, TYPE_TEXT,
+ TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_BOOLEAN, TYPE_BOOLEAN, TYPE_INT,
+ TYPE_INT, TYPE_INT, TYPE_INT };
}
View
73 src/org/mariotaku/twidere/util/CacheUsersStatusesTask.java
@@ -29,8 +29,9 @@
import org.mariotaku.twidere.provider.TweetStore.CachedHashtags;
import org.mariotaku.twidere.provider.TweetStore.CachedStatuses;
import org.mariotaku.twidere.provider.TweetStore.CachedUsers;
-import org.mariotaku.twidere.provider.TweetStore.Statuses;
+import org.mariotaku.twidere.util.TwitterWrapper.TwitterListResponse;
+import twitter4j.User;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
@@ -39,44 +40,47 @@
public class CacheUsersStatusesTask extends AsyncTask<Void, Void, Void> {
- private final ArrayList<ContentValues> all_statuses;
+ private final TwitterListResponse<twitter4j.Status>[] all_statuses;
private final ContentResolver resolver;
private final boolean large_profile_image;
- public CacheUsersStatusesTask(final Context context, final ArrayList<ContentValues> all_statuses) {
+ public CacheUsersStatusesTask(final Context context, final TwitterListResponse<twitter4j.Status>... all_statuses) {
resolver = context.getContentResolver();
this.all_statuses = all_statuses;
large_profile_image = context.getResources().getBoolean(R.bool.hires_profile_image);
}
- public CacheUsersStatusesTask(final Context context, final List<twitter4j.Status> statuses, final long account_id) {
- resolver = context.getContentResolver();
- all_statuses = new ArrayList<ContentValues>();
- large_profile_image = context.getResources().getBoolean(R.bool.hires_profile_image);
- for (final twitter4j.Status status : statuses) {
- all_statuses.add(makeStatusContentValues(status, account_id, large_profile_image));
- }
- }
-
@Override
protected Void doInBackground(final Void... args) {
- final List<ContentValues> cached_users_list = new ArrayList<ContentValues>();
- final List<Long> user_ids = new ArrayList<Long>(), status_ids = new ArrayList<Long>();
- final Extractor extractor = new Extractor();
+ if (all_statuses == null || all_statuses.length == 0) return null;
+ final ArrayList<ContentValues> cached_users_values = new ArrayList<ContentValues>();
+ final ArrayList<ContentValues> cached_statuses_values = new ArrayList<ContentValues>();
final ArrayList<ContentValues> hashtag_values = new ArrayList<ContentValues>();
+ final ArrayList<Long> user_ids = new ArrayList<Long>(), status_ids = new ArrayList<Long>();
+ final Extractor extractor = new Extractor();
+
final ArrayList<String> hashtags = new ArrayList<String>();
- for (final ContentValues values : all_statuses) {
- if (values == null) {
+ for (final TwitterListResponse<twitter4j.Status> values : all_statuses) {
+ if (values == null || values.list == null) {
continue;
}
- final long user_id = values.getAsLong(Statuses.USER_ID);
- status_ids.add(values.getAsLong(Statuses.STATUS_ID));
- if (!user_ids.contains(user_id)) {
- user_ids.add(user_id);
- cached_users_list.add(makeCachedUserContentValues(values));
+ final List<twitter4j.Status> list = values.list;
+ for (final twitter4j.Status status : list) {
+ final twitter4j.Status retweeted_status = status.getRetweetedStatus();
+ final User user = retweeted_status == null ? status.getUser() : retweeted_status.getUser();
+ if (user == null) {
+ continue;
+ }
+ final long user_id = user.getId();
+ status_ids.add(status.getId());
+ if (!user_ids.contains(user_id)) {
+ user_ids.add(user_id);
+ cached_users_values.add(makeCachedUserContentValues(user, large_profile_image));
+ cached_statuses_values.add(makeStatusContentValues(status, values.account_id, large_profile_image));
+ }
+ hashtags.addAll(extractor.extractHashtags(status.getText()));
}
- hashtags.addAll(extractor.extractHashtags(values.getAsString(Statuses.TEXT_PLAIN)));
}
for (final String hashtag : hashtags) {
final ContentValues hashtag_value = new ContentValues();
@@ -86,10 +90,11 @@ protected Void doInBackground(final Void... args) {
resolver.delete(CachedUsers.CONTENT_URI,
CachedUsers.USER_ID + " IN (" + ListUtils.toString(user_ids, ',', true) + " )", null);
resolver.bulkInsert(CachedUsers.CONTENT_URI,
- cached_users_list.toArray(new ContentValues[cached_users_list.size()]));
+ cached_users_values.toArray(new ContentValues[cached_users_values.size()]));
resolver.delete(CachedStatuses.CONTENT_URI,
CachedStatuses.STATUS_ID + " IN (" + ListUtils.toString(status_ids, ',', true) + " )", null);
- resolver.bulkInsert(CachedStatuses.CONTENT_URI, all_statuses.toArray(new ContentValues[all_statuses.size()]));
+ resolver.bulkInsert(CachedStatuses.CONTENT_URI,
+ cached_statuses_values.toArray(new ContentValues[cached_statuses_values.size()]));
resolver.delete(CachedHashtags.CONTENT_URI,
CachedHashtags.NAME + " IN (" + ListUtils.toStringForSQL(hashtags.size()) + ")",
hashtags.toArray(new String[hashtags.size()]));
@@ -98,27 +103,25 @@ protected Void doInBackground(final Void... args) {
return null;
}
- public static Runnable getRunnable(final Context context, final List<twitter4j.Status> statuses,
- final long account_id) {
- return new ExecuteCacheUserStatusesTaskRunnable(context, statuses, account_id);
+ public static Runnable getRunnable(final Context context,
+ final TwitterListResponse<twitter4j.Status>... all_statuses) {
+ return new ExecuteCacheUserStatusesTaskRunnable(context, all_statuses);
}
static class ExecuteCacheUserStatusesTaskRunnable implements Runnable {
final Context context;
- final List<twitter4j.Status> statuses;
- final long account_id;
+ final TwitterListResponse<twitter4j.Status>[] all_statuses;
- ExecuteCacheUserStatusesTaskRunnable(final Context context, final List<twitter4j.Status> statuses,
- final long account_id) {
+ ExecuteCacheUserStatusesTaskRunnable(final Context context,
+ final TwitterListResponse<twitter4j.Status>... all_statuses) {
this.context = context;
- this.statuses = statuses;
- this.account_id = account_id;
+ this.all_statuses = all_statuses;
}
@Override
public void run() {
- new CacheUsersStatusesTask(context, statuses, account_id).execute();
+ new CacheUsersStatusesTask(context, all_statuses).execute();
}
}
}
View
8 src/org/mariotaku/twidere/util/ThumbnailUtils.java
@@ -0,0 +1,8 @@
+package org.mariotaku.twidere.util;
+
+public class ThumbnailUtils {
+
+ public static interface Patterns {
+
+ }
+}
View
478 src/org/mariotaku/twidere/util/TwitterWrapper.java
@@ -59,6 +59,7 @@
import twitter4j.DirectMessage;
import twitter4j.Paging;
import twitter4j.ResponseList;
+import twitter4j.Status;
import twitter4j.StatusUpdate;
import twitter4j.Trends;
import twitter4j.Twitter;
@@ -89,7 +90,7 @@
private static TwitterWrapper sInstance;
- private final Context context;
+ private final Context mContext;
private final AsyncTaskManager mAsyncTaskManager;
private final SharedPreferences mPreferences;
private final NotificationManager mNotificationManager;
@@ -103,7 +104,7 @@
private int mGetLocalTrendsTaskId;
public TwitterWrapper(final Context context) {
- this.context = context;
+ mContext = context;
mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mAsyncTaskManager = TwidereApplication.getInstance(context).getAsyncTaskManager();
mPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
@@ -253,17 +254,17 @@ public boolean isSentDirectMessagesRefreshing() {
}
public int refreshAll() {
- final long[] account_ids = getActivatedAccountIds(context);
+ final long[] account_ids = getActivatedAccountIds(mContext);
if (mPreferences.getBoolean(PREFERENCE_KEY_HOME_REFRESH_MENTIONS, false)) {
- final long[] since_ids = getNewestStatusIdsFromDatabase(context, Mentions.CONTENT_URI);
+ final long[] since_ids = getNewestStatusIdsFromDatabase(mContext, Mentions.CONTENT_URI);
getMentions(account_ids, null, since_ids);
}
if (mPreferences.getBoolean(PREFERENCE_KEY_HOME_REFRESH_DIRECT_MESSAGES, false)) {
- final long[] since_ids = getNewestMessageIdsFromDatabase(context, DirectMessages.Inbox.CONTENT_URI);
+ final long[] since_ids = getNewestMessageIdsFromDatabase(mContext, DirectMessages.Inbox.CONTENT_URI);
getReceivedDirectMessages(account_ids, null, since_ids);
getSentDirectMessages(account_ids, null, null);
}
- final long[] since_ids = getNewestStatusIdsFromDatabase(context, Statuses.CONTENT_URI);
+ final long[] since_ids = getNewestStatusIdsFromDatabase(mContext, Statuses.CONTENT_URI);
return getHomeTimeline(account_ids, null, since_ids);
}
@@ -290,7 +291,8 @@ public int sendDirectMessage(final long account_id, final String screen_name, fi
public int updateProfile(final long account_id, final String name, final String url, final String location,
final String description) {
- final UpdateProfileTask task = new UpdateProfileTask(account_id, name, url, location, description);
+ final UpdateProfileTask task = new UpdateProfileTask(mContext, mAsyncTaskManager, account_id, name, url,
+ location, description);
return mAsyncTaskManager.add(task, true);
}
@@ -320,7 +322,7 @@ public int updateUserListDetails(final long account_id, final int list_id, final
private Notification buildNotification(final String title, final String message, final int icon,
final Intent content_intent, final Intent delete_intent) {
- final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
+ final NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
builder.setTicker(message);
builder.setContentTitle(title);
builder.setContentText(message);
@@ -328,11 +330,11 @@ private Notification buildNotification(final String title, final String message,
builder.setWhen(System.currentTimeMillis());
builder.setSmallIcon(icon);
if (delete_intent != null) {
- builder.setDeleteIntent(PendingIntent.getBroadcast(context, 0, delete_intent,
+ builder.setDeleteIntent(PendingIntent.getBroadcast(mContext, 0, delete_intent,
PendingIntent.FLAG_UPDATE_CURRENT));
}
if (content_intent != null) {
- builder.setContentIntent(PendingIntent.getActivity(context, 0, content_intent,
+ builder.setContentIntent(PendingIntent.getActivity(mContext, 0, content_intent,
PendingIntent.FLAG_UPDATE_CURRENT));
}
int defaults = 0;
@@ -353,7 +355,7 @@ private Notification buildNotification(final String title, final String message,
}
private void showErrorToast(final int action_res, final Exception e, final boolean long_message) {
- Utils.showErrorToast(context, context.getString(action_res), e, long_message);
+ Utils.showErrorToast(mContext, mContext.getString(action_res), e, long_message);
}
public static TwitterWrapper getInstance(final Context context) {
@@ -361,6 +363,82 @@ public static TwitterWrapper getInstance(final Context context) {
return sInstance = new TwitterWrapper(context);
}
+ public static final class StatusListResponse extends TwitterListResponse<Status> {
+
+ public StatusListResponse(final long account_id, final List<Status> list) {
+ super(account_id, -1, -1, -1, list, null);
+ }
+
+ public StatusListResponse(final long account_id, final long max_id, final long since_id,
+ final int load_item_limit, final List<Status> list, final Exception exception) {
+ super(account_id, max_id, since_id, load_item_limit, list, exception);
+ }
+
+ }
+
+ public static class TwitterListResponse<Data> extends ListResponse<Data> {
+
+ public final long max_id, since_id;
+ public final int load_item_limit;
+
+ public TwitterListResponse(final long account_id, final long max_id, final long since_id,
+ final int load_item_limit, final List<Data> list, final Exception exception) {
+ super(account_id, list, exception);
+ this.max_id = max_id;
+ this.since_id = since_id;
+ this.load_item_limit = load_item_limit;
+ }
+
+ }
+
+ public static class UpdateProfileTask extends ManagedAsyncTask<Void, Void, SingleResponse<User>> {
+
+ private final long account_id;
+ private final String name, url, location, description;
+ private final Context context;
+
+ public UpdateProfileTask(final Context context, final AsyncTaskManager manager, final long account_id,
+ final String name, final String url, final String location, final String description) {
+ super(context, manager);
+ this.context = context;
+ this.account_id = account_id;
+ this.name = name;
+ this.url = url;
+ this.location = location;
+ this.description = description;
+ }
+
+ @Override
+ protected SingleResponse<User> doInBackground(final Void... params) {
+
+ final Twitter twitter = getTwitterInstance(context, account_id, false);
+ if (twitter != null) {
+ try {
+ final User user = twitter.updateProfile(name, url, location, description);
+ return new SingleResponse<User>(account_id, user, null);
+ } catch (final TwitterException e) {
+ return new SingleResponse<User>(account_id, null, e);
+ }
+ }
+ return new SingleResponse<User>(account_id, null, null);
+ }
+
+ @Override
+ protected void onPostExecute(final SingleResponse<User> result) {
+ if (result != null && result.data != null) {
+ Toast.makeText(context, R.string.profile_update_successfully, Toast.LENGTH_SHORT).show();
+ } else {
+ Utils.showErrorToast(context, context.getString(R.string.updating_profile), result.exception, true);
+ }
+ final Intent intent = new Intent(BROADCAST_PROFILE_UPDATED);
+ intent.putExtra(INTENT_KEY_USER_ID, account_id);
+ intent.putExtra(INTENT_KEY_SUCCEED, result != null && result.data != null);
+ context.sendBroadcast(intent);
+ super.onPostExecute(result);
+ }
+
+ }
+
class AddUserListMemberTask extends ManagedAsyncTask<Void, Void, SingleResponse<UserList>> {
private final long account_id, user_id;
@@ -369,7 +447,7 @@ public static TwitterWrapper getInstance(final Context context) {
public AddUserListMemberTask(final long account_id, final int list_id, final long user_id,
final String screen_name) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.list_id = list_id;
this.user_id = user_id;
@@ -379,7 +457,7 @@ public AddUserListMemberTask(final long account_id, final int list_id, final lon
@Override
protected SingleResponse<UserList> doInBackground(final Void... params) {
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
if (user_id > 0) {
@@ -403,7 +481,7 @@ public AddUserListMemberTask(final long account_id, final int list_id, final lon
protected void onPostExecute(final SingleResponse<UserList> result) {
final boolean succeed = result != null && result.data != null && result.data.getId() > 0;
if (succeed) {
- Toast.makeText(context, R.string.add_successfully, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.add_successfully, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.adding_member, result.exception, true);
}
@@ -411,7 +489,7 @@ protected void onPostExecute(final SingleResponse<UserList> result) {
intent.putExtra(INTENT_KEY_USER_ID, user_id);
intent.putExtra(INTENT_KEY_LIST_ID, list_id);
intent.putExtra(INTENT_KEY_SUCCEED, succeed);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPostExecute(result);
}
@@ -422,7 +500,7 @@ protected void onPostExecute(final SingleResponse<UserList> result) {
private final long account_id, user_id;
public CreateBlockTask(final long account_id, final long user_id) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.user_id = user_id;
}
@@ -430,7 +508,7 @@ public CreateBlockTask(final long account_id, final long user_id) {
@Override
protected SingleResponse<User> doInBackground(final Void... params) {
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
final User user = twitter.createBlock(user_id);
@@ -455,14 +533,14 @@ protected void onPostExecute(final SingleResponse<User> result) {
// list.
final String where = CachedUsers.USER_ID + " = " + user_id;
mResolver.delete(CachedUsers.CONTENT_URI, where, null);
- Toast.makeText(context, R.string.user_blocked, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.user_blocked, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.blocking, result.exception, true);
}
final Intent intent = new Intent(BROADCAST_BLOCKSTATE_CHANGED);
intent.putExtra(INTENT_KEY_USER_ID, user_id);
intent.putExtra(INTENT_KEY_SUCCEED, result != null && result.data != null);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPostExecute(result);
}
@@ -473,7 +551,7 @@ protected void onPostExecute(final SingleResponse<User> result) {
private final long account_id, status_id;
public CreateFavoriteTask(final long account_id, final long status_id) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.status_id = status_id;
}
@@ -483,7 +561,7 @@ public CreateFavoriteTask(final long account_id, final long status_id) {
if (account_id < 0) return new SingleResponse<twitter4j.Status>(account_id, null, null);
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
final twitter4j.Status status = twitter.createFavorite(status_id);
@@ -516,8 +594,8 @@ protected void onPostExecute(final SingleResponse<twitter4j.Status> result) {
final Intent intent = new Intent(BROADCAST_FAVORITE_CHANGED);
intent.putExtra(INTENT_KEY_STATUS_ID, status_id);
intent.putExtra(INTENT_KEY_FAVORITED, true);
- context.sendBroadcast(intent);
- Toast.makeText(context, R.string.favorite_successfully, Toast.LENGTH_SHORT).show();
+ mContext.sendBroadcast(intent);
+ Toast.makeText(mContext, R.string.favorite_successfully, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.favoriting, result.exception, true);
}
@@ -532,7 +610,7 @@ protected void onPostExecute(final SingleResponse<twitter4j.Status> result) {
private final long user_id;
public CreateFriendshipTask(final long account_id, final long user_id) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.user_id = user_id;
}
@@ -540,7 +618,7 @@ public CreateFriendshipTask(final long account_id, final long user_id) {
@Override
protected SingleResponse<User> doInBackground(final Void... params) {
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
final User user = twitter.createFriendship(user_id);
@@ -555,14 +633,14 @@ public CreateFriendshipTask(final long account_id, final long user_id) {
@Override
protected void onPostExecute(final SingleResponse<User> result) {
if (result != null && result.data != null) {
- Toast.makeText(context, R.string.follow_successfully, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.follow_successfully, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.following, result.exception, true);
}
final Intent intent = new Intent(BROADCAST_FRIENDSHIP_CHANGED);
intent.putExtra(INTENT_KEY_USER_ID, user_id);
intent.putExtra(INTENT_KEY_SUCCEED, result != null && result.data != null);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPostExecute(result);
}
@@ -574,7 +652,7 @@ protected void onPostExecute(final SingleResponse<User> result) {
private final long[] user_ids;
public CreateMultiBlockTask(final long account_id, final long[] user_ids) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.user_ids = user_ids;
}
@@ -583,7 +661,7 @@ public CreateMultiBlockTask(final long account_id, final long[] user_ids) {
protected ListResponse<Long> doInBackground(final Void... params) {
final List<Long> blocked_users = new ArrayList<Long>();
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
for (final long user_id : user_ids) {
try {
@@ -613,14 +691,14 @@ protected void onPostExecute(final ListResponse<Long> result) {
// list.
final String where = CachedUsers.USER_ID + " IN (" + user_ids + ")";
mResolver.delete(CachedUsers.CONTENT_URI, where, null);
- Toast.makeText(context, R.string.users_blocked, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.users_blocked, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.blocking, result.exception, true);
}
final Intent intent = new Intent(BROADCAST_MULTI_BLOCKSTATE_CHANGED);
intent.putExtra(INTENT_KEY_USER_ID, user_ids);
intent.putExtra(INTENT_KEY_SUCCEED, result.list != null);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPostExecute(result);
}
@@ -632,7 +710,7 @@ protected void onPostExecute(final ListResponse<Long> result) {
private final int list_id;
public CreateUserListSubscriptionTask(final long account_id, final int list_id) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.list_id = list_id;
}
@@ -640,7 +718,7 @@ public CreateUserListSubscriptionTask(final long account_id, final int list_id)
@Override
protected SingleResponse<UserList> doInBackground(final Void... params) {
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
final UserList list = twitter.createUserListSubscription(list_id);
@@ -656,14 +734,14 @@ public CreateUserListSubscriptionTask(final long account_id, final int list_id)
protected void onPostExecute(final SingleResponse<UserList> result) {
final boolean succeed = result != null && result.data != null && result.data.getId() > 0;
if (succeed) {
- Toast.makeText(context, R.string.follow_successfully, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.follow_successfully, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.following, result.exception, true);
}
final Intent intent = new Intent(BROADCAST_USER_LIST_SUBSCRIPTION_CHANGED);
intent.putExtra(INTENT_KEY_LIST_ID, list_id);
intent.putExtra(INTENT_KEY_SUCCEED, succeed);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPostExecute(result);
}
@@ -677,7 +755,7 @@ protected void onPostExecute(final SingleResponse<UserList> result) {
public CreateUserListTask(final long account_id, final String list_name, final boolean is_public,
final String description) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.list_name = list_name;
this.description = description;
@@ -687,7 +765,7 @@ public CreateUserListTask(final long account_id, final String list_name, final b
@Override
protected SingleResponse<UserList> doInBackground(final Void... params) {
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
if (list_name != null) {
@@ -705,13 +783,13 @@ public CreateUserListTask(final long account_id, final String list_name, final b
protected void onPostExecute(final SingleResponse<UserList> result) {
final boolean succeed = result != null && result.data != null && result.data.getId() > 0;
if (succeed) {
- Toast.makeText(context, R.string.create_successfully, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.create_successfully, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.creating_list, result.exception, true);
}
final Intent intent = new Intent(BROADCAST_USER_LIST_CREATED);
intent.putExtra(INTENT_KEY_SUCCEED, succeed);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPostExecute(result);
}
@@ -723,7 +801,7 @@ protected void onPostExecute(final SingleResponse<UserList> result) {
private final int list_id;
public DeleteUserListMemberTask(final long account_id, final int list_id, final long user_id) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.list_id = list_id;
this.user_id = user_id;
@@ -732,7 +810,7 @@ public DeleteUserListMemberTask(final long account_id, final int list_id, final
@Override
protected SingleResponse<UserList> doInBackground(final Void... params) {
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
final UserList list = twitter.deleteUserListMember(list_id, user_id);
@@ -748,7 +826,7 @@ public DeleteUserListMemberTask(final long account_id, final int list_id, final
protected void onPostExecute(final SingleResponse<UserList> result) {
final boolean succeed = result != null && result.data != null && result.data.getId() > 0;
if (succeed) {
- Toast.makeText(context, R.string.delete_successfully, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.delete_successfully, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.deleting, result.exception, true);
}
@@ -756,7 +834,7 @@ protected void onPostExecute(final SingleResponse<UserList> result) {
intent.putExtra(INTENT_KEY_USER_ID, user_id);
intent.putExtra(INTENT_KEY_LIST_ID, list_id);
intent.putExtra(INTENT_KEY_SUCCEED, succeed);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPostExecute(result);
}
@@ -768,7 +846,7 @@ protected void onPostExecute(final SingleResponse<UserList> result) {
private final long user_id;
public DestroyBlockTask(final long account_id, final long user_id) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.user_id = user_id;
}
@@ -776,7 +854,7 @@ public DestroyBlockTask(final long account_id, final long user_id) {
@Override
protected SingleResponse<User> doInBackground(final Void... params) {
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
final User user = twitter.destroyBlock(user_id);
@@ -791,14 +869,14 @@ public DestroyBlockTask(final long account_id, final long user_id) {
@Override
protected void onPostExecute(final SingleResponse<User> result) {
if (result != null && result.data != null) {
- Toast.makeText(context, R.string.user_unblocked, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.user_unblocked, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.unblocking, result.exception, true);
}
final Intent intent = new Intent(BROADCAST_BLOCKSTATE_CHANGED);
intent.putExtra(INTENT_KEY_USER_ID, user_id);
intent.putExtra(INTENT_KEY_SUCCEED, result != null && result.data != null);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPostExecute(result);
}
@@ -811,8 +889,8 @@ protected void onPostExecute(final SingleResponse<User> result) {
private final long account_id;
public DestroyDirectMessageTask(final long account_id, final long message_id) {
- super(context, mAsyncTaskManager);
- twitter = getTwitterInstance(context, account_id, false);
+ super(mContext, mAsyncTaskManager);
+ twitter = getTwitterInstance(mContext, account_id, false);
this.account_id = account_id;
this.message_id = message_id;
}
@@ -832,7 +910,7 @@ protected void onPostExecute(final SingleResponse<DirectMessage> result) {
super.onPostExecute(result);
if (result == null) return;
if (result.data != null && result.data.getId() > 0) {
- Toast.makeText(context, R.string.delete_successfully, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.delete_successfully, Toast.LENGTH_SHORT).show();
final String where = DirectMessages.MESSAGE_ID + " = " + message_id;
mResolver.delete(DirectMessages.Inbox.CONTENT_URI, where, null);
mResolver.delete(DirectMessages.Outbox.CONTENT_URI, where, null);
@@ -850,7 +928,7 @@ protected void onPostExecute(final SingleResponse<DirectMessage> result) {
private final long status_id;
public DestroyFavoriteTask(final long account_id, final long status_id) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.status_id = status_id;
}
@@ -862,7 +940,7 @@ public DestroyFavoriteTask(final long account_id, final long status_id) {
new SingleResponse<twitter4j.Status>(account_id, null, null);
}
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
final twitter4j.Status status = twitter.destroyFavorite(status_id);
@@ -896,8 +974,8 @@ protected void onPostExecute(final SingleResponse<twitter4j.Status> result) {
intent.putExtra(INTENT_KEY_USER_ID, account_id);
intent.putExtra(INTENT_KEY_STATUS_ID, status_id);
intent.putExtra(INTENT_KEY_FAVORITED, false);
- context.sendBroadcast(intent);
- Toast.makeText(context, R.string.unfavorite_successfully, Toast.LENGTH_SHORT).show();
+ mContext.sendBroadcast(intent);
+ Toast.makeText(mContext, R.string.unfavorite_successfully, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.unfavoriting, result.exception, true);
@@ -913,7 +991,7 @@ protected void onPostExecute(final SingleResponse<twitter4j.Status> result) {
private final long user_id;
public DestroyFriendshipTask(final long account_id, final long user_id) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.user_id = user_id;
}
@@ -921,7 +999,7 @@ public DestroyFriendshipTask(final long account_id, final long user_id) {
@Override
protected SingleResponse<User> doInBackground(final Void... params) {
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
final User user = twitter.destroyFriendship(user_id);
@@ -936,14 +1014,14 @@ public DestroyFriendshipTask(final long account_id, final long user_id) {
@Override
protected void onPostExecute(final SingleResponse<User> result) {
if (result != null && result.data != null) {
- Toast.makeText(context, R.string.unfollow_successfully, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.unfollow_successfully, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.unfollowing, result.exception, true);
}
final Intent intent = new Intent(BROADCAST_FRIENDSHIP_CHANGED);
intent.putExtra(INTENT_KEY_USER_ID, user_id);
intent.putExtra(INTENT_KEY_SUCCEED, result != null && result.data != null);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPostExecute(result);
}
@@ -956,7 +1034,7 @@ protected void onPostExecute(final SingleResponse<User> result) {
private final long status_id;
public DestroyStatusTask(final long account_id, final long status_id) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.status_id = status_id;
}
@@ -964,7 +1042,7 @@ public DestroyStatusTask(final long account_id, final long status_id) {
@Override
protected SingleResponse<twitter4j.Status> doInBackground(final Void... params) {
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
final twitter4j.Status status = twitter.destroyStatus(status_id);
@@ -989,11 +1067,11 @@ protected void onPostExecute(final SingleResponse<twitter4j.Status> result) {
}
intent.putExtra(INTENT_KEY_STATUS_ID, status_id);
intent.putExtra(INTENT_KEY_SUCCEED, true);
- Toast.makeText(context, R.string.delete_successfully, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.delete_successfully, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.deleting, result.exception, true);
}
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPostExecute(result);
}
@@ -1005,7 +1083,7 @@ protected void onPostExecute(final SingleResponse<twitter4j.Status> result) {
private final int list_id;
public DestroyUserListSubscriptionTask(final long account_id, final int list_id) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.list_id = list_id;
}
@@ -1013,7 +1091,7 @@ public DestroyUserListSubscriptionTask(final long account_id, final int list_id)
@Override
protected SingleResponse<UserList> doInBackground(final Void... params) {
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
final UserList list = twitter.destroyUserListSubscription(list_id);
@@ -1029,14 +1107,14 @@ public DestroyUserListSubscriptionTask(final long account_id, final int list_id)
protected void onPostExecute(final SingleResponse<UserList> result) {
final boolean succeed = result != null && result.data != null && result.data.getId() > 0;
if (succeed) {
- Toast.makeText(context, R.string.unfollow_successfully, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.unfollow_successfully, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.unfollowing, result.exception, true);
}
final Intent intent = new Intent(BROADCAST_USER_LIST_SUBSCRIPTION_CHANGED);
intent.putExtra(INTENT_KEY_LIST_ID, list_id);
intent.putExtra(INTENT_KEY_SUCCEED, succeed);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPostExecute(result);
}
@@ -1048,7 +1126,7 @@ protected void onPostExecute(final SingleResponse<UserList> result) {
private final int list_id;
public DestroyUserListTask(final long account_id, final int list_id) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.list_id = list_id;
}
@@ -1056,7 +1134,7 @@ public DestroyUserListTask(final long account_id, final int list_id) {
@Override
protected SingleResponse<UserList> doInBackground(final Void... params) {
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
if (list_id > 0) {
@@ -1074,27 +1152,26 @@ public DestroyUserListTask(final long account_id, final int list_id) {
protected void onPostExecute(final SingleResponse<UserList> result) {
final boolean succeed = result != null && result.data != null && result.data.getId() > 0;
if (succeed) {
- Toast.makeText(context, R.string.delete_successfully, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.delete_successfully, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.deleting, result.exception, true);
}
final Intent intent = new Intent(BROADCAST_USER_LIST_DELETED);
intent.putExtra(INTENT_KEY_SUCCEED, succeed);
intent.putExtra(INTENT_KEY_LIST_ID, list_id);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPostExecute(result);
}
}
- abstract class GetDirectMessagesTask extends
- ManagedAsyncTask<Void, Void, List<StatusesListResponse<DirectMessage>>> {
+ abstract class GetDirectMessagesTask extends ManagedAsyncTask<Void, Void, List<TwitterListResponse<DirectMessage>>> {
private final long[] account_ids, max_ids, since_ids;
public GetDirectMessagesTask(final long[] account_ids, final long[] max_ids, final long[] since_ids,
final String tag) {
- super(context, mAsyncTaskManager, tag);
+ super(mContext, mAsyncTaskManager, tag);
this.account_ids = account_ids;
this.max_ids = max_ids;
this.since_ids = since_ids;
@@ -1104,9 +1181,9 @@ public GetDirectMessagesTask(final long[] account_ids, final long[] max_ids, fin
throws TwitterException;
@Override
- protected List<StatusesListResponse<DirectMessage>> doInBackground(final Void... params) {
+ protected List<TwitterListResponse<DirectMessage>> doInBackground(final Void... params) {
- final List<StatusesListResponse<DirectMessage>> result = new ArrayList<StatusesListResponse<DirectMessage>>();
+ final List<TwitterListResponse<DirectMessage>> result = new ArrayList<TwitterListResponse<DirectMessage>>();
if (account_ids == null) return result;
@@ -1114,7 +1191,7 @@ public GetDirectMessagesTask(final long[] account_ids, final long[] max_ids, fin
final int load_item_limit = mPreferences.getInt(PREFERENCE_KEY_LOAD_ITEM_LIMIT,
PREFERENCE_DEFAULT_LOAD_ITEM_LIMIT);
for (final long account_id : account_ids) {
- final Twitter twitter = getTwitterInstance(context, account_id, true);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, true);
if (twitter != null) {
try {
final Paging paging = new Paging();
@@ -1131,11 +1208,11 @@ public GetDirectMessagesTask(final long[] account_ids, final long[] max_ids, fin
final ResponseList<DirectMessage> statuses = getDirectMessages(twitter, paging);
if (statuses != null) {
- result.add(new StatusesListResponse<DirectMessage>(account_id, max_id, since_id,
+ result.add(new TwitterListResponse<DirectMessage>(account_id, max_id, since_id,
load_item_limit, statuses, null));
}
} catch (final TwitterException e) {
- result.add(new StatusesListResponse<DirectMessage>(account_id, -1, -1, load_item_limit, null, e));
+ result.add(new TwitterListResponse<DirectMessage>(account_id, -1, -1, load_item_limit, null, e));
}
}
idx++;
@@ -1145,9 +1222,9 @@ public GetDirectMessagesTask(final long[] account_ids, final long[] max_ids, fin
}
@Override
- protected void onPostExecute(final List<StatusesListResponse<DirectMessage>> result) {
+ protected void onPostExecute(final List<TwitterListResponse<DirectMessage>> result) {
super.onPostExecute(result);
- for (final StatusesListResponse<DirectMessage> response : result) {
+ for (final TwitterListResponse<DirectMessage> response : result) {
if (response.list == null) {
showErrorToast(R.string.refreshing_direct_messages, response.exception, true);
}
@@ -1178,11 +1255,11 @@ public GetHomeTimelineTask(final long[] account_ids, final long[] max_ids, final
@Override
public Twitter getTwitter(final long account_id) {
- return getTwitterInstance(context, account_id, true);
+ return getTwitterInstance(mContext, account_id, true);
}
@Override
- protected void onPostExecute(final List<StatusesListResponse<twitter4j.Status>> responses) {
+ protected void onPostExecute(final List<StatusListResponse> responses) {
super.onPostExecute(responses);
mAsyncTaskManager.add(new StoreHomeTimelineTask(responses, shouldSetMinId(), !isMaxIdsValid()), true);
mGetHomeTimelineTaskId = -1;
@@ -1191,7 +1268,7 @@ protected void onPostExecute(final List<StatusesListResponse<twitter4j.Status>>
@Override
protected void onPreExecute() {
final Intent intent = new Intent(BROADCAST_RESCHEDULE_HOME_TIMELINE_REFRESHING);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPreExecute();
}
@@ -1238,11 +1315,11 @@ public GetMentionsTask(final long[] account_ids, final long[] max_ids, final lon
@Override
public Twitter getTwitter(final long account_id) {
- return getTwitterInstance(context, account_id, true);
+ return getTwitterInstance(mContext, account_id, true);
}
@Override
- protected void onPostExecute(final List<StatusesListResponse<twitter4j.Status>> responses) {
+ protected void onPostExecute(final List<StatusListResponse> responses) {
super.onPostExecute(responses);
mAsyncTaskManager.add(new StoreMentionsTask(responses, shouldSetMinId(), !isMaxIdsValid()), true);
mGetMentionsTaskId = -1;
@@ -1252,7 +1329,7 @@ protected void onPostExecute(final List<StatusesListResponse<twitter4j.Status>>
protected void onPreExecute() {
final Intent intent = new Intent(BROADCAST_RESCHEDULE_MENTIONS_REFRESHING);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPreExecute();
}
@@ -1271,7 +1348,7 @@ public GetReceivedDirectMessagesTask(final long[] account_ids, final long[] max_
}
@Override
- protected void onPostExecute(final List<StatusesListResponse<DirectMessage>> responses) {
+ protected void onPostExecute(final List<TwitterListResponse<DirectMessage>> responses) {
super.onPostExecute(responses);
mAsyncTaskManager.add(new StoreReceivedDirectMessagesTask(responses, !isMaxIdsValid()), true);
mGetReceivedDirectMessagesTaskId = -1;
@@ -1280,7 +1357,7 @@ protected void onPostExecute(final List<StatusesListResponse<DirectMessage>> res
@Override
protected void onPreExecute() {
final Intent intent = new Intent(BROADCAST_RESCHEDULE_DIRECT_MESSAGES_REFRESHING);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPreExecute();
}
@@ -1299,7 +1376,7 @@ public GetSentDirectMessagesTask(final long[] account_ids, final long[] max_ids,
}
@Override
- protected void onPostExecute(final List<StatusesListResponse<DirectMessage>> responses) {
+ protected void onPostExecute(final List<TwitterListResponse<DirectMessage>> responses) {
super.onPostExecute(responses);
mAsyncTaskManager.add(new StoreSentDirectMessagesTask(responses, !isMaxIdsValid()), true);
mGetSentDirectMessagesTaskId = -1;
@@ -1307,12 +1384,12 @@ protected void onPostExecute(final List<StatusesListResponse<DirectMessage>> res
}
- abstract class GetStatusesTask extends ManagedAsyncTask<Void, Void, List<StatusesListResponse<twitter4j.Status>>> {
+ abstract class GetStatusesTask extends ManagedAsyncTask<Void, Void, List<StatusListResponse>> {
private final long[] account_ids, max_ids, since_ids;
public GetStatusesTask(final long[] account_ids, final long[] max_ids, final long[] since_ids, final String tag) {
- super(context, mAsyncTaskManager, tag);
+ super(mContext, mAsyncTaskManager, tag);
this.account_ids = account_ids;
this.max_ids = max_ids;
this.since_ids = since_ids;
@@ -1324,9 +1401,9 @@ public GetStatusesTask(final long[] account_ids, final long[] max_ids, final lon
public abstract Twitter getTwitter(long account_id);
@Override
- protected List<StatusesListResponse<twitter4j.Status>> doInBackground(final Void... params) {
+ protected List<StatusListResponse> doInBackground(final Void... params) {
- final List<StatusesListResponse<twitter4j.Status>> result = new ArrayList<StatusesListResponse<twitter4j.Status>>();
+ final List<StatusListResponse> result = new ArrayList<StatusListResponse>();
if (account_ids == null) return result;
@@ -1350,12 +1427,11 @@ public GetStatusesTask(final long[] account_ids, final long[] max_ids, final lon
}
final ResponseList<twitter4j.Status> statuses = getStatuses(twitter, paging);
if (statuses != null) {
- result.add(new StatusesListResponse<twitter4j.Status>(account_id, max_id, since_id,
- load_item_limit, statuses, null));
+ result.add(new StatusListResponse(account_id, max_id, since_id, load_item_limit, statuses,
+ null));
}
} catch (final TwitterException e) {
- result.add(new StatusesListResponse<twitter4j.Status>(account_id, -1, -1, load_item_limit,
- null, e));
+ result.add(new StatusListResponse(account_id, -1, -1, load_item_limit, null, e));
}
}
idx++;
@@ -1364,9 +1440,9 @@ public GetStatusesTask(final long[] account_ids, final long[] max_ids, final lon
}
@Override
- protected void onPostExecute(final List<StatusesListResponse<twitter4j.Status>> result) {
+ protected void onPostExecute(final List<StatusListResponse> result) {
super.onPostExecute(result);
- for (final StatusesListResponse<twitter4j.Status> response : result) {
+ for (final StatusListResponse response : result) {
if (response.list == null) {
showErrorToast(R.string.refreshing_timelines, response.exception, true);
}
@@ -1392,7 +1468,7 @@ final boolean shouldSetMinId() {
private final long account_id;
public GetTrendsTask(final long account_id) {
- super(context, mAsyncTaskManager, TASK_TAG_GET_TRENDS);
+ super(mContext, mAsyncTaskManager, TASK_TAG_GET_TRENDS);
this.account_id = account_id;
}
@@ -1400,7 +1476,7 @@ public GetTrendsTask(final long account_id) {
@Override
protected ListResponse<Trends> doInBackground(final Void... params) {
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
return new ListResponse<Trends>(account_id, getTrends(twitter), null);
@@ -1419,7 +1495,7 @@ public GetTrendsTask(final long account_id) {
private final long[] user_ids;
public ReportMultiSpamTask(final long account_id, final long[] user_ids) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.user_ids = user_ids;
}
@@ -1428,7 +1504,7 @@ public ReportMultiSpamTask(final long account_id, final long[] user_ids) {
protected ListResponse<Long> doInBackground(final Void... params) {
final List<Long> reported_users = new ArrayList<Long>();
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
for (final long user_id : user_ids) {
try {
@@ -1454,13 +1530,13 @@ protected void onPostExecute(final ListResponse<Long> result) {
+ " IN (" + user_id_where + ")";
mResolver.delete(uri, where, null);
}
- Toast.makeText(context, R.string.reported_users_for_spam, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.reported_users_for_spam, Toast.LENGTH_SHORT).show();
}
final Intent intent = new Intent(BROADCAST_MULTI_BLOCKSTATE_CHANGED);
intent.putExtra(INTENT_KEY_USER_IDS, user_ids);
intent.putExtra(INTENT_KEY_ACCOUNT_ID, account_id);
intent.putExtra(INTENT_KEY_SUCCEED, result != null);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPostExecute(result);
}
@@ -1472,7 +1548,7 @@ protected void onPostExecute(final ListResponse<Long> result) {
private final long user_id;
public ReportSpamTask(final long account_id, final long user_id) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.user_id = user_id;
}
@@ -1480,7 +1556,7 @@ public ReportSpamTask(final long account_id, final long user_id) {
@Override
protected SingleResponse<User> doInBackground(final Void... params) {
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
final User user = twitter.reportSpam(user_id);
@@ -1500,14 +1576,14 @@ protected void onPostExecute(final SingleResponse<User> result) {
+ user_id;
mResolver.delete(uri, where, null);
}
- Toast.makeText(context, R.string.reported_user_for_spam, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.reported_user_for_spam, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.reporting_for_spam, result.exception, true);
}
final Intent intent = new Intent(BROADCAST_BLOCKSTATE_CHANGED);
intent.putExtra(INTENT_KEY_USER_ID, user_id);
intent.putExtra(INTENT_KEY_SUCCEED, result != null && result.data != null);
- context.sendBroadcast(intent);
+ mContext.sendBroadcast(intent);
super.onPostExecute(result);
}
@@ -1520,7 +1596,7 @@ protected void onPostExecute(final SingleResponse<User> result) {
private final long status_id;
public RetweetStatusTask(final long account_id, final long status_id) {
- super(context, mAsyncTaskManager);
+ super(mContext, mAsyncTaskManager);
this.account_id = account_id;
this.status_id = status_id;
}
@@ -1530,7 +1606,7 @@ public RetweetStatusTask(final long account_id, final long status_id) {
if (account_id < 0) return new SingleResponse<twitter4j.Status>(account_id, null, null);
- final Twitter twitter = getTwitterInstance(context, account_id, false);
+ final Twitter twitter = getTwitterInstance(mContext, account_id, false);
if (twitter != null) {
try {
final twitter4j.Status status = twitter.retweetStatus(status_id);
@@ -1548,14 +1624,16 @@ protected void onPostExecute(final SingleResponse<twitter4j.Status> result) {
if (result.data != null && result.data.getId() > 0) {
final ContentValues values = new ContentValues();
values.put(Statuses.MY_RETWEET_ID, result.data.getId());
+ final String where = Statuses.STATUS_ID + " = " + status_id + " OR " + Statuses.RETWEET_ID + " = "
+ + status_id;
for (final Uri uri : STATUSES_URIS) {
- mResolver.update(uri, values, Statuses.STATUS_ID + " = " + status_id, null);
+ mResolver.update(uri, values, where, null);
}
final Intent intent = new Intent(BROADCAST_RETWEET_CHANGED);
intent.putExtra(INTENT_KEY_STATUS_ID, status_id);
intent.putExtra(INTENT_KEY_RETWEETED, true);
- context.sendBroadcast(intent);
- Toast.makeText(context, R.string.retweet_successfully, Toast.LENGTH_SHORT).show();
+ mContext.sendBroadcast(intent);
+ Toast.makeText(mContext, R.string.retweet_successfully, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.retweeting, result.exception, true);
}
@@ -1575,8 +1653,8 @@ protected void onPostExecute(final SingleResponse<twitter4j.Status> result) {
public SendDirectMessageTask(final long account_id, final String screen_name, final long user_id,
final String message) {
- super(context, mAsyncTaskManager);
- twitter = getTwitterInstance(context, account_id, true);
+ super(mContext, mAsyncTaskManager);
+ twitter = getTwitterInstance(mContext, account_id, true);
this.account_id = account_id;
this.user_id = user_id;
this.screen_name = screen_name;
@@ -1607,7 +1685,7 @@ protected void onPostExecute(final SingleResponse<DirectMessage> result) {
final ContentValues values = makeDirectMessageContentValues(result.data, account_id, true,
large_profile_image);
mResolver.insert(DirectMessages.Outbox.CONTENT_URI, values);
- Toast.makeText(context, R.string.send_successfully, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mContext, R.string.send_successfully, Toast.LENGTH_SHORT).show();
} else {
showErrorToast(R.string.sending_direct_message, result.exception, true);
}
@@ -1615,29 +1693,14 @@ protected void onPostExecute(final SingleResponse<DirectMessage> result) {
}
- static final class StatusesListResponse<Data> extends ListResponse<Data> {
-
- public final long max_id, since_id;
- public final int load_item_limit;
-
- public StatusesListResponse(final long account_id, final long max_id, final long since_id,
- final int load_item_limit, final List<Data> list, final Exception exception) {
- super(account_id, list, exception);
- this.max_id = max_id;
- this.since_id = since_id;
- this.load_item_limit = load_item_limit;
- }
-
- }
-
abstract class StoreDirectMessagesTask extends ManagedAsyncTask<Void, Void, SingleResponse<Bundle>> {
- private final List<StatusesListResponse<DirectMessage>> responses;
+ private final List<TwitterListResponse<DirectMessage>> responses;
private final Uri uri;
- public StoreDirectMessagesTask(final List<StatusesListResponse<DirectMessage>> result, final Uri uri,
+ public StoreDirectMessagesTask(final List<TwitterListResponse<DirectMessage>> result, final Uri uri,
final boolean notify, final String tag) {
- super(context, mAsyncTaskManager, tag);
+ super(mContext, mAsyncTaskManager, tag);
responses = result;
this.uri = uri.buildUpon().appendQueryParameter(QUERY_PARAM_NOTIFY, String.valueOf(notify)).build();
}
@@ -1692,8 +1755,8 @@ public StoreDirectMessagesTask(final List<StatusesListResponse<DirectMessage>> r
class StoreHomeTimelineTask extends StoreStatusesTask {
- public StoreHomeTimelineTask(final List<StatusesListResponse<twitter4j.Status>> result,
- final boolean should_set_min_id, final boolean notify) {
+ public StoreHomeTimelineTask(final List<StatusListResponse> result, final boolean should_set_min_id,
+ final boolean notify) {
super(result, Statuses.CONTENT_URI, should_set_min_id, notify, TASK_TAG_STORE_HOME_TIMELINE);
}
@@ -1709,7 +1772,7 @@ protected void onPostExecute(final SingleResponse<Bundle> response) {
extras.putLong(INTENT_KEY_MIN_ID, min_id);
mPreferences.edit().putLong(PREFERENCE_KEY_SAVED_HOME_TIMELINE_ID, min_id).commit();
}
- context.sendBroadcast(new Intent(BROADCAST_HOME_TIMELINE_REFRESHED).putExtras(extras));
+ mContext.sendBroadcast(new Intent(BROADCAST_HOME_TIMELINE_REFRESHED).putExtras(extras));
super.onPostExecute(response);
}