From 0a47a6bb92238c9d581bdf795f8664721ed214c0 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Wed, 13 May 2015 18:54:13 +0800 Subject: [PATCH] added enable/disable retweet feature --- .../api/FriendsFollowersResources.java | 11 +- .../api/twitter/model/FriendshipUpdate.java | 46 +++++ .../api/twitter/model/Relationship.java | 4 + .../twitter/model/impl/RelationshipImpl.java | 14 ++ twidere/build.gradle | 1 + .../spice/Task/SpiceAsyUploadTask.java | 4 +- .../spice/Utilies/SpiceProfilingUtil.java | 4 +- .../edu/ucdavis/earlybird/ProfilingUtil.java | 4 +- .../java/org/mariotaku/twidere/Constants.java | 1 + .../activity/BasePreferenceActivity.java | 3 +- .../twidere/activity/BaseThemedActivity.java | 3 +- .../twidere/activity/MainActivity.java | 4 +- .../support/ThemedAppCompatActivity.java | 3 +- .../support/ThemedFragmentActivity.java | 3 +- .../UserHashtagAutoCompleteAdapter.java | 5 +- .../twidere/app/TwidereApplication.java | 4 +- .../fragment/support/UserFragment.java | 171 ++++++++++-------- .../support/TwitterAPIActivitiesLoader.java | 6 +- .../twidere/provider/TwidereDataProvider.java | 7 +- .../receiver/ConnectivityStateReceiver.java | 4 +- .../twidere/service/RefreshService.java | 12 +- .../twidere/util/AsyncTwitterWrapper.java | 52 +++++- .../twidere/util/PermissionsManager.java | 3 +- .../util/SharedPreferencesWrapper.java | 13 +- .../org/mariotaku/twidere/util/Utils.java | 6 +- .../util/message/FriendshipUpdatedEvent.java | 16 +- .../message/FriendshipUserUpdatedEvent.java | 37 ++++ .../util/net/TwidereHostAddressResolver.java | 14 +- .../src/main/res/menu/menu_user_profile.xml | 39 ++-- twidere/src/main/res/values/ids.xml | 1 + twidere/src/main/res/values/strings.xml | 4 +- 31 files changed, 342 insertions(+), 157 deletions(-) create mode 100644 twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/FriendshipUpdate.java create mode 100644 twidere/src/main/java/org/mariotaku/twidere/util/message/FriendshipUserUpdatedEvent.java diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/api/FriendsFollowersResources.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/api/FriendsFollowersResources.java index d7a6d464d..e625cf389 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/api/FriendsFollowersResources.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/api/FriendsFollowersResources.java @@ -27,6 +27,7 @@ import org.mariotaku.simplerestapi.param.Form; import org.mariotaku.simplerestapi.param.Query; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Friendship; +import org.mariotaku.twidere.api.twitter.model.FriendshipUpdate; import org.mariotaku.twidere.api.twitter.model.IDs; import org.mariotaku.twidere.api.twitter.model.PageableResponseList; import org.mariotaku.twidere.api.twitter.model.Paging; @@ -111,9 +112,11 @@ public interface FriendsFollowersResources { Relationship showFriendship(@Query("source_screen_name") String sourceScreenName, @Query("target_screen_name") String targetScreenName) throws TwitterException; - Relationship updateFriendship(long userId, boolean enableDeviceNotification, boolean retweets) - throws TwitterException; + @POST("/friendships/update.json") + @Body(BodyType.FORM) + Relationship updateFriendship(@Form("user_id") long userId, @Form FriendshipUpdate update) throws TwitterException; - Relationship updateFriendship(String screenName, boolean enableDeviceNotification, boolean retweets) - throws TwitterException; + @POST("/friendships/update.json") + @Body(BodyType.FORM) + Relationship updateFriendship(@Form("screen_name") String screenName, @Form FriendshipUpdate update) throws TwitterException; } diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/FriendshipUpdate.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/FriendshipUpdate.java new file mode 100644 index 000000000..095ecfdfd --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/FriendshipUpdate.java @@ -0,0 +1,46 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2015 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.api.twitter.model; + +import org.mariotaku.simplerestapi.http.SimpleValueMap; + +/** + * Created by mariotaku on 15/5/13. + */ +public class FriendshipUpdate extends SimpleValueMap { + + public void setDeviceNotificationsEnabled(boolean enabled) { + put("device", enabled); + } + + public void setRetweetsEnabled(boolean enabled) { + put("retweets", enabled); + } + + public FriendshipUpdate retweets(boolean enabled) { + setRetweetsEnabled(enabled); + return this; + } + + public FriendshipUpdate deviceNotifications(boolean enabled) { + setDeviceNotificationsEnabled(enabled); + return this; + } +} diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/Relationship.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/Relationship.java index 8ab6aa9e7..fde3fe633 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/Relationship.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/Relationship.java @@ -106,4 +106,8 @@ public interface Relationship extends TwitterResponse { boolean isSourceRequestedFollowingTarget(); boolean isTargetRequestedFollowingSource(); + + boolean isSourceWantRetweetsFromTarget(); + + boolean isSourceNotificationsEnabledForTarget(); } diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/impl/RelationshipImpl.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/impl/RelationshipImpl.java index 3df0e2e1d..c34e93c6f 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/impl/RelationshipImpl.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/impl/RelationshipImpl.java @@ -120,6 +120,16 @@ public class RelationshipImpl extends TwitterResponseImpl implements Relationshi return target.followingRequested; } + @Override + public boolean isSourceWantRetweetsFromTarget() { + return source.wantRetweets; + } + + @Override + public boolean isSourceNotificationsEnabledForTarget() { + return source.notificationsEnabled; + } + @JsonObject static class Target { @JsonField(name = "id") @@ -152,5 +162,9 @@ public class RelationshipImpl extends TwitterResponseImpl implements Relationshi boolean followedBy; @JsonField(name = "following_requested") boolean followingRequested; + @JsonField(name = "want_retweets") + boolean wantRetweets; + @JsonField(name = "notifications_enabled") + boolean notificationsEnabled; } } diff --git a/twidere/build.gradle b/twidere/build.gradle index 6543bbdaf..84bd5fe63 100644 --- a/twidere/build.gradle +++ b/twidere/build.gradle @@ -95,6 +95,7 @@ dependencies { compile 'org.apache.commons:commons-lang3:3.4' compile 'com.bluelinelabs:logansquare:1.0.6' compile 'ch.acra:acra:4.6.2' + compile 'com.github.boxme:AsyncManager:9391ed71d7@aar' googleCompile 'com.google.android.gms:play-services-maps:7.0.0' googleCompile 'com.google.maps.android:android-maps-utils:0.3.4' fdroidCompile 'org.osmdroid:osmdroid-android:4.3' diff --git a/twidere/src/main/java/edu/tsinghua/spice/Task/SpiceAsyUploadTask.java b/twidere/src/main/java/edu/tsinghua/spice/Task/SpiceAsyUploadTask.java index fbdb8e956..667fbcec4 100644 --- a/twidere/src/main/java/edu/tsinghua/spice/Task/SpiceAsyUploadTask.java +++ b/twidere/src/main/java/edu/tsinghua/spice/Task/SpiceAsyUploadTask.java @@ -10,8 +10,8 @@ import org.mariotaku.simplerestapi.http.RestHttpRequest; import org.mariotaku.simplerestapi.http.mime.FileTypedData; import org.mariotaku.simplerestapi.http.mime.MultipartTypedBody; import org.mariotaku.simplerestapi.method.POST; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.util.TwitterAPIUtils; -import org.mariotaku.twidere.util.Utils; import java.io.File; import java.io.FileInputStream; @@ -69,7 +69,7 @@ public class SpiceAsyUploadTask extends AsyncTask { SpiceProfilingUtil.log("server has already received file " + tmp.getName()); tmp.delete(); } catch (Exception e) { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.w(LOGTAG, e); SpiceProfilingUtil.log("server does not receive file " + tmp.getName()); } diff --git a/twidere/src/main/java/edu/tsinghua/spice/Utilies/SpiceProfilingUtil.java b/twidere/src/main/java/edu/tsinghua/spice/Utilies/SpiceProfilingUtil.java index d7e1c7801..0bb2c9bd7 100644 --- a/twidere/src/main/java/edu/tsinghua/spice/Utilies/SpiceProfilingUtil.java +++ b/twidere/src/main/java/edu/tsinghua/spice/Utilies/SpiceProfilingUtil.java @@ -10,8 +10,8 @@ import android.os.Build; import android.text.TextUtils; import android.util.Log; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; -import org.mariotaku.twidere.util.Utils; import java.io.BufferedWriter; import java.io.FileOutputStream; @@ -44,7 +44,7 @@ public class SpiceProfilingUtil { } public static boolean log(final String msg) { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { final StackTraceElement ste = new Throwable().fillInStackTrace().getStackTrace()[1]; final String fullName = ste.getClassName(); final String name = fullName.substring(fullName.lastIndexOf('.')); diff --git a/twidere/src/main/java/edu/ucdavis/earlybird/ProfilingUtil.java b/twidere/src/main/java/edu/ucdavis/earlybird/ProfilingUtil.java index 016a517d7..525cd6e98 100644 --- a/twidere/src/main/java/edu/ucdavis/earlybird/ProfilingUtil.java +++ b/twidere/src/main/java/edu/ucdavis/earlybird/ProfilingUtil.java @@ -7,8 +7,8 @@ import android.content.SharedPreferences; import android.os.BatteryManager; import android.util.Log; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; -import org.mariotaku.twidere.util.Utils; import java.io.BufferedWriter; import java.io.FileOutputStream; @@ -30,7 +30,7 @@ public class ProfilingUtil { } public static boolean log(final Context context, final String msg) { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { final StackTraceElement ste = new Throwable().fillInStackTrace().getStackTrace()[1]; final String fullname = ste.getClassName(); final String name = fullname.substring(fullname.lastIndexOf('.')); diff --git a/twidere/src/main/java/org/mariotaku/twidere/Constants.java b/twidere/src/main/java/org/mariotaku/twidere/Constants.java index 76468c988..25990af99 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/Constants.java +++ b/twidere/src/main/java/org/mariotaku/twidere/Constants.java @@ -116,6 +116,7 @@ public interface Constants extends TwidereConstants { int MENU_INVERSE_SELECTION = R.id.inverse_selection; int MENU_EDIT_MEDIA = R.id.edit_media; int MENU_RESET = R.id.reset; + int MENU_ENABLE_RETWEETS = R.id.enable_retweets; int LINK_ID_STATUS = 1; int LINK_ID_USER = 2; diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/BasePreferenceActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/BasePreferenceActivity.java index 7b3f638b5..ee179c790 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/BasePreferenceActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/BasePreferenceActivity.java @@ -37,6 +37,7 @@ import android.widget.FrameLayout; import com.meizu.flyme.reflect.StatusBarProxy; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.iface.IThemedActivity; @@ -139,7 +140,7 @@ public abstract class BasePreferenceActivity extends AppCompatPreferenceActivity @Override protected void onCreate(final Bundle savedInstanceState) { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { StrictModeUtils.detectAllVmPolicy(); StrictModeUtils.detectAllThreadPolicy(); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/BaseThemedActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/BaseThemedActivity.java index 658ab06ee..cdd4b4baf 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/BaseThemedActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/BaseThemedActivity.java @@ -24,6 +24,7 @@ import android.content.res.Resources; import android.os.Bundle; import android.support.annotation.NonNull; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.activity.iface.IThemedActivity; import org.mariotaku.twidere.util.StrictModeUtils; import org.mariotaku.twidere.util.ThemeUtils; @@ -94,7 +95,7 @@ public abstract class BaseThemedActivity extends Activity implements IThemedActi @Override protected void onCreate(final Bundle savedInstanceState) { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { StrictModeUtils.detectAllVmPolicy(); StrictModeUtils.detectAllThreadPolicy(); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/MainActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/MainActivity.java index 80689d8d0..698c022d8 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/MainActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/MainActivity.java @@ -23,11 +23,11 @@ import android.app.Activity; import android.content.Intent; import android.os.Bundle; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.activity.support.HomeActivity; import org.mariotaku.twidere.util.StrictModeUtils; import org.mariotaku.twidere.util.ThemeUtils; -import org.mariotaku.twidere.util.Utils; public class MainActivity extends Activity implements Constants { @@ -39,7 +39,7 @@ public class MainActivity extends Activity implements Constants { @Override protected void onCreate(final Bundle savedInstanceState) { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { StrictModeUtils.detectAllVmPolicy(); StrictModeUtils.detectAllThreadPolicy(); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedAppCompatActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedAppCompatActivity.java index f7962675b..0bb7ff8cc 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedAppCompatActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedAppCompatActivity.java @@ -28,6 +28,7 @@ import android.support.v7.app.ThemedAppCompatDelegateFactory; import android.support.v7.widget.Toolbar; import android.view.View; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.activity.iface.IThemedActivity; import org.mariotaku.twidere.util.StrictModeUtils; @@ -99,7 +100,7 @@ public abstract class ThemedAppCompatActivity extends AppCompatActivity implemen @Override protected void onCreate(final Bundle savedInstanceState) { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { StrictModeUtils.detectAllVmPolicy(); StrictModeUtils.detectAllThreadPolicy(); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedFragmentActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedFragmentActivity.java index c628bb275..7ff71d545 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedFragmentActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedFragmentActivity.java @@ -31,6 +31,7 @@ import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.activity.iface.IThemedActivity; import org.mariotaku.twidere.app.TwidereApplication; @@ -123,7 +124,7 @@ public abstract class ThemedFragmentActivity extends FragmentActivity implements @Override protected void onCreate(final Bundle savedInstanceState) { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { StrictModeUtils.detectAllVmPolicy(); StrictModeUtils.detectAllThreadPolicy(); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/UserHashtagAutoCompleteAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/UserHashtagAutoCompleteAdapter.java index ee679f687..e6aa67388 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/UserHashtagAutoCompleteAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/UserHashtagAutoCompleteAdapter.java @@ -36,6 +36,7 @@ import org.mariotaku.querybuilder.Columns.Column; import org.mariotaku.querybuilder.Expression; import org.mariotaku.querybuilder.OrderBy; import org.mariotaku.querybuilder.RawItemArray; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.app.TwidereApplication; @@ -180,7 +181,7 @@ public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implemen CachedUsers.NAME}, new boolean[]{false, false, true, true}); final Cursor cursor = mResolver.query(Uri.withAppendedPath(CachedUsers.CONTENT_URI_WITH_SCORE, String.valueOf(mAccountId)), CachedUsers.BASIC_COLUMNS, selection != null ? selection.getSQL() : null, selectionArgs, orderBy.getSQL()); - if (Utils.isDebugBuild() && cursor == null) throw new NullPointerException(); + if (BuildConfig.DEBUG && cursor == null) throw new NullPointerException(); return cursor; } else { final String selection = constraintEscaped != null ? CachedHashtags.NAME + " LIKE ?||'%' ESCAPE '^'" @@ -188,7 +189,7 @@ public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implemen final String[] selectionArgs = constraintEscaped != null ? new String[]{constraintEscaped} : null; final Cursor cursor = mDatabase.query(true, CachedHashtags.TABLE_NAME, CachedHashtags.COLUMNS, selection, selectionArgs, null, null, CachedHashtags.NAME, null); - if (Utils.isDebugBuild() && cursor == null) throw new NullPointerException(); + if (BuildConfig.DEBUG && cursor == null) throw new NullPointerException(); return cursor; } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java b/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java index fd74c3054..72df28461 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java +++ b/twidere/src/main/java/org/mariotaku/twidere/app/TwidereApplication.java @@ -187,7 +187,7 @@ public class TwidereApplication extends MultiDexApplication implements Constants // cb.memoryCache(new ImageMemoryCache(40)); cb.diskCache(getDiskCache()); cb.imageDownloader(getImageDownloader()); - L.writeDebugLogs(Utils.isDebugBuild()); + L.writeDebugLogs(BuildConfig.DEBUG); loader.init(cb.build()); return mImageLoader = loader; } @@ -231,7 +231,7 @@ public class TwidereApplication extends MultiDexApplication implements Constants @Override public void onCreate() { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { StrictModeUtils.detectAllVmPolicy(); } super.onCreate(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java index 7e6f85e5f..acf462566 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java @@ -97,6 +97,7 @@ import org.mariotaku.twidere.activity.support.UserListSelectorActivity; import org.mariotaku.twidere.adapter.support.SupportTabsAdapter; import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; +import org.mariotaku.twidere.api.twitter.model.FriendshipUpdate; import org.mariotaku.twidere.api.twitter.model.Relationship; import org.mariotaku.twidere.app.TwidereApplication; import org.mariotaku.twidere.constant.SharedPreferenceConstants; @@ -133,6 +134,7 @@ import org.mariotaku.twidere.util.UserColorNameManager; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.menu.TwidereMenuInfo; import org.mariotaku.twidere.util.message.FriendshipUpdatedEvent; +import org.mariotaku.twidere.util.message.FriendshipUserUpdatedEvent; import org.mariotaku.twidere.util.message.ProfileUpdatedEvent; import org.mariotaku.twidere.util.message.TaskStateChangedEvent; import org.mariotaku.twidere.util.support.ActivitySupport; @@ -242,80 +244,83 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener mFollowProgress.setVisibility(View.GONE); final ParcelableUser user = getUser(); final Relationship relationship = data.getData(); - mRelationship = relationship; - if (user == null) return; - invalidateOptionsMenu(); - final boolean isMyself = user.account_id == user.id; - if (isMyself) { - mFollowButton.setText(R.string.edit); - mFollowButton.setVisibility(View.VISIBLE); - } else if (relationship != null) { - final int drawableRes; - mFollowButton.setEnabled(!relationship.isSourceBlockedByTarget()); - if (relationship.isSourceBlockedByTarget()) { - mPagesErrorContainer.setVisibility(View.VISIBLE); - final String displayName = mUserColorNameManager.getDisplayName(user, mNameFirst, true); - mPagesErrorText.setText(getString(R.string.blocked_by_user_summary, displayName)); - mPagesErrorIcon.setImageResource(R.drawable.ic_info_error_generic); - mPagesContent.setVisibility(View.GONE); - } else if (!relationship.isSourceFollowingTarget() && user.is_protected) { - mPagesErrorContainer.setVisibility(View.VISIBLE); - final String displayName = mUserColorNameManager.getDisplayName(user, mNameFirst, true); - mPagesErrorText.setText(getString(R.string.user_protected_summary, displayName)); - mPagesErrorIcon.setImageResource(R.drawable.ic_info_locked); - mPagesContent.setVisibility(View.GONE); - } else { - mPagesErrorContainer.setVisibility(View.GONE); - mPagesErrorText.setText(null); - mPagesContent.setVisibility(View.VISIBLE); - } - if (relationship.isSourceBlockingTarget()) { - mFollowButton.setText(R.string.unblock); - drawableRes = R.drawable.ic_follow_blocked; - } else if (relationship.isSourceFollowingTarget()) { - mFollowButton.setText(R.string.unfollow); - if (relationship.isTargetFollowingSource()) { - drawableRes = R.drawable.ic_follow_bidirectional; - } else { - drawableRes = R.drawable.ic_follow_outgoing; - } - } else if (user.is_follow_request_sent) { - mFollowButton.setText(R.string.requested); - if (relationship.isTargetFollowingSource()) { - drawableRes = R.drawable.ic_follow_incoming; - } else { - drawableRes = R.drawable.ic_follow_pending; - } - } else { - mFollowButton.setText(R.string.follow); - if (relationship.isTargetFollowingSource()) { - drawableRes = R.drawable.ic_follow_incoming; - } else { - drawableRes = R.drawable.ic_follow_none; - } - } - final Drawable icon = ResourcesCompat.getDrawable(getResources(), drawableRes, null); - final int iconSize = Math.round(mFollowButton.getTextSize() * 1.4f); - icon.setBounds(0, 0, iconSize, iconSize); - icon.setColorFilter(mFollowButton.getCurrentTextColor(), Mode.SRC_ATOP); - mFollowButton.setCompoundDrawables(icon, null, null, null); - mFollowButton.setCompoundDrawablePadding(Math.round(mFollowButton.getTextSize() * 0.25f)); - - final ContentResolver resolver = getContentResolver(); - final ContentValues cachedValues = ParcelableUser.makeCachedUserContentValues(user); - resolver.insert(CachedUsers.CONTENT_URI, cachedValues); - mFollowButton.setVisibility(View.VISIBLE); - } else { - mFollowButton.setText(null); - mFollowButton.setVisibility(View.GONE); - mPagesErrorContainer.setVisibility(View.GONE); - mPagesContent.setVisibility(View.VISIBLE); -// mFollowingYouIndicator.setVisibility(View.GONE); - } + showRelationship(user, relationship); } }; + private void showRelationship(ParcelableUser user, Relationship relationship) { + mRelationship = relationship; + if (user == null) return; + invalidateOptionsMenu(); + final boolean isMyself = user.account_id == user.id; + if (isMyself) { + mFollowButton.setText(R.string.edit); + mFollowButton.setVisibility(View.VISIBLE); + } else if (relationship != null) { + final int drawableRes; + mFollowButton.setEnabled(!relationship.isSourceBlockedByTarget()); + if (relationship.isSourceBlockedByTarget()) { + mPagesErrorContainer.setVisibility(View.VISIBLE); + final String displayName = mUserColorNameManager.getDisplayName(user, mNameFirst, true); + mPagesErrorText.setText(getString(R.string.blocked_by_user_summary, displayName)); + mPagesErrorIcon.setImageResource(R.drawable.ic_info_error_generic); + mPagesContent.setVisibility(View.GONE); + } else if (!relationship.isSourceFollowingTarget() && user.is_protected) { + mPagesErrorContainer.setVisibility(View.VISIBLE); + final String displayName = mUserColorNameManager.getDisplayName(user, mNameFirst, true); + mPagesErrorText.setText(getString(R.string.user_protected_summary, displayName)); + mPagesErrorIcon.setImageResource(R.drawable.ic_info_locked); + mPagesContent.setVisibility(View.GONE); + } else { + mPagesErrorContainer.setVisibility(View.GONE); + mPagesErrorText.setText(null); + mPagesContent.setVisibility(View.VISIBLE); + } + if (relationship.isSourceBlockingTarget()) { + mFollowButton.setText(R.string.unblock); + drawableRes = R.drawable.ic_follow_blocked; + } else if (relationship.isSourceFollowingTarget()) { + mFollowButton.setText(R.string.unfollow); + if (relationship.isTargetFollowingSource()) { + drawableRes = R.drawable.ic_follow_bidirectional; + } else { + drawableRes = R.drawable.ic_follow_outgoing; + } + } else if (user.is_follow_request_sent) { + mFollowButton.setText(R.string.requested); + if (relationship.isTargetFollowingSource()) { + drawableRes = R.drawable.ic_follow_incoming; + } else { + drawableRes = R.drawable.ic_follow_pending; + } + } else { + mFollowButton.setText(R.string.follow); + if (relationship.isTargetFollowingSource()) { + drawableRes = R.drawable.ic_follow_incoming; + } else { + drawableRes = R.drawable.ic_follow_none; + } + } + final Drawable icon = ResourcesCompat.getDrawable(getResources(), drawableRes, null); + final int iconSize = Math.round(mFollowButton.getTextSize() * 1.4f); + icon.setBounds(0, 0, iconSize, iconSize); + icon.setColorFilter(mFollowButton.getCurrentTextColor(), Mode.SRC_ATOP); + mFollowButton.setCompoundDrawables(icon, null, null, null); + mFollowButton.setCompoundDrawablePadding(Math.round(mFollowButton.getTextSize() * 0.25f)); + + final ContentResolver resolver = getContentResolver(); + final ContentValues cachedValues = ParcelableUser.makeCachedUserContentValues(user); + resolver.insert(CachedUsers.CONTENT_URI, cachedValues); + mFollowButton.setVisibility(View.VISIBLE); + } else { + mFollowButton.setText(null); + mFollowButton.setVisibility(View.GONE); + mPagesErrorContainer.setVisibility(View.GONE); + mPagesContent.setVisibility(View.VISIBLE); + } + } + private final LoaderCallbacks> mUserInfoLoaderCallbacks = new LoaderCallbacks>() { @Override @@ -605,7 +610,15 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener @Subscribe public void notifyFriendshipUpdated(FriendshipUpdatedEvent event) { - if (!event.user.equals(mUser)) return; + final ParcelableUser user = getUser(); + if (user == null || event.accountId != user.account_id || event.userId != user.id) return; + getFriendship(); + } + + @Subscribe + public void notifyFriendshipUserUpdated(FriendshipUserUpdatedEvent event) { + final ParcelableUser user = getUser(); + if (user == null || !event.user.equals(user)) return; getFriendship(); } @@ -796,6 +809,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener public void onStart() { super.onStart(); final Bus bus = TwidereApplication.getInstance(getActivity()).getMessageBus(); + assert bus != null; bus.register(this); } @@ -808,6 +822,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener @Override public void onStop() { final Bus bus = TwidereApplication.getInstance(getActivity()).getMessageBus(); + assert bus != null; bus.unregister(this); super.onStop(); } @@ -877,8 +892,14 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener ActionIconDrawable.setMenuHighlight(filterItem, new TwidereMenuInfo(filtering)); filterItem.setTitle(filtering ? R.string.remove_from_filter : R.string.add_to_filter); } + final MenuItem wantRetweetsItem = menu.findItem(MENU_ENABLE_RETWEETS); + if (wantRetweetsItem != null) { + + wantRetweetsItem.setChecked(relationship.isSourceWantRetweetsFromTarget()); + } } else { MenuUtils.setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false); + MenuUtils.setMenuItemAvailability(menu, MENU_ENABLE_RETWEETS, false); MenuUtils.setMenuItemAvailability(menu, MENU_BLOCK, false); MenuUtils.setMenuItemAvailability(menu, MENU_MUTE_USER, false); MenuUtils.setMenuItemAvailability(menu, MENU_REPORT_SPAM, false); @@ -1011,6 +1032,14 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener } return true; } + case MENU_ENABLE_RETWEETS: { + final boolean newState = !item.isChecked(); + final FriendshipUpdate update = new FriendshipUpdate(); + update.retweets(newState); + twitter.updateFriendship(user.account_id, user.id, update); + item.setChecked(newState); + return true; + } case R.id.muted_users: { Utils.openMutesUsers(getActivity(), user.account_id); return true; diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIActivitiesLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIActivitiesLoader.java index 9e8def605..c4158605e 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIActivitiesLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIActivitiesLoader.java @@ -27,6 +27,7 @@ import android.util.Pair; import com.bluelinelabs.logansquare.LoganSquare; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.Activity; @@ -34,7 +35,6 @@ import org.mariotaku.twidere.api.twitter.model.Paging; import org.mariotaku.twidere.model.ParcelableActivity; import org.mariotaku.twidere.util.LoganSquareWrapper; import org.mariotaku.twidere.util.TwitterAPIUtils; -import org.mariotaku.twidere.util.Utils; import java.io.File; import java.io.FileOutputStream; @@ -153,11 +153,11 @@ public abstract class TwitterAPIActivitiesLoader extends ParcelableActivitiesLoa try { return LoganSquareWrapper.parseList(file, ParcelableActivity.class); } catch (final IOException e) { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.w(LOGTAG, e); } } catch (RuntimeException e) { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { throw e; } Log.e(LOGTAG, "Error unserializing data", e); diff --git a/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java b/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java index 57744fc39..de7d73f47 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java +++ b/twidere/src/main/java/org/mariotaku/twidere/provider/TwidereDataProvider.java @@ -63,6 +63,7 @@ import org.mariotaku.querybuilder.Columns.Column; import org.mariotaku.querybuilder.Expression; import org.mariotaku.querybuilder.RawItemArray; import org.mariotaku.querybuilder.query.SQLSelectQuery; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.support.HomeActivity; @@ -629,7 +630,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta } private Cursor getCachedImageCursor(final String url) { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.d(LOGTAG, String.format("getCachedImageCursor(%s)", url)); } final MatrixCursor c = new MatrixCursor(TwidereDataStore.CachedImages.MATRIX_COLUMNS); @@ -641,7 +642,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta } private ParcelFileDescriptor getCachedImageFd(final String url) throws FileNotFoundException { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.d(LOGTAG, String.format("getCachedImageFd(%s)", url)); } final File file = mImagePreloader.getCachedImageFile(url); @@ -672,7 +673,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta c.addRow(new String[]{host, address.getHostAddress()}); } } catch (final IOException ignore) { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.w(LOGTAG, ignore); } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/receiver/ConnectivityStateReceiver.java b/twidere/src/main/java/org/mariotaku/twidere/receiver/ConnectivityStateReceiver.java index 5c0ea2c5d..a81151324 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/receiver/ConnectivityStateReceiver.java +++ b/twidere/src/main/java/org/mariotaku/twidere/receiver/ConnectivityStateReceiver.java @@ -27,8 +27,8 @@ import android.location.LocationManager; import android.net.ConnectivityManager; import android.util.Log; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; -import org.mariotaku.twidere.util.Utils; import edu.tsinghua.spice.Utilies.NetworkStateUtil; import edu.tsinghua.spice.Utilies.SpiceProfilingUtil; @@ -43,7 +43,7 @@ public class ConnectivityStateReceiver extends BroadcastReceiver implements Cons @Override public void onReceive(final Context context, final Intent intent) { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.d(RECEIVER_LOGTAG, String.format("Received Broadcast %s", intent)); } if (!ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) return; diff --git a/twidere/src/main/java/org/mariotaku/twidere/service/RefreshService.java b/twidere/src/main/java/org/mariotaku/twidere/service/RefreshService.java index b10ca8918..8ff2cbaa8 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/service/RefreshService.java +++ b/twidere/src/main/java/org/mariotaku/twidere/service/RefreshService.java @@ -29,6 +29,7 @@ import android.content.IntentFilter; import android.os.IBinder; import android.util.Log; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.app.TwidereApplication; import org.mariotaku.twidere.model.AccountPreferences; @@ -47,7 +48,6 @@ import static org.mariotaku.twidere.util.Utils.getNewestMessageIdsFromDatabase; import static org.mariotaku.twidere.util.Utils.getNewestStatusIdsFromDatabase; import static org.mariotaku.twidere.util.Utils.hasAutoRefreshAccounts; import static org.mariotaku.twidere.util.Utils.isBatteryOkay; -import static org.mariotaku.twidere.util.Utils.isDebugBuild; import static org.mariotaku.twidere.util.Utils.isNetworkAvailable; import static org.mariotaku.twidere.util.Utils.shouldStopAutoRefreshOnBatteryLow; @@ -65,7 +65,7 @@ public class RefreshService extends Service implements Constants { @Override public void onReceive(final Context context, final Intent intent) { final String action = intent.getAction(); - if (isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.d(LOGTAG, String.format("Refresh service received action %s", action)); } if (BROADCAST_RESCHEDULE_HOME_TIMELINE_REFRESHING.equals(action)) { @@ -82,7 +82,7 @@ public class RefreshService extends Service implements Constants { if (BROADCAST_REFRESH_HOME_TIMELINE.equals(action)) { final long[] refreshIds = getRefreshableIds(accountPrefs, new HomeRefreshableFilter()); final long[] sinceIds = getNewestStatusIdsFromDatabase(context, Statuses.CONTENT_URI, refreshIds); - if (isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.d(LOGTAG, String.format("Auto refreshing home for %s", Arrays.toString(refreshIds))); } if (!isHomeTimelineRefreshing()) { @@ -91,7 +91,7 @@ public class RefreshService extends Service implements Constants { } else if (BROADCAST_REFRESH_MENTIONS.equals(action)) { final long[] refreshIds = getRefreshableIds(accountPrefs, new MentionsRefreshableFilter()); final long[] sinceIds = getNewestStatusIdsFromDatabase(context, Mentions.CONTENT_URI, refreshIds); - if (isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.d(LOGTAG, String.format("Auto refreshing mentions for %s", Arrays.toString(refreshIds))); } if (!isMentionsRefreshing()) { @@ -101,7 +101,7 @@ public class RefreshService extends Service implements Constants { final long[] refreshIds = getRefreshableIds(accountPrefs, new MessagesRefreshableFilter()); final long[] sinceIds = getNewestMessageIdsFromDatabase(context, DirectMessages.Inbox.CONTENT_URI, refreshIds); - if (isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.d(LOGTAG, String.format("Auto refreshing messages for %s", Arrays.toString(refreshIds))); } if (!isReceivedDirectMessagesRefreshing()) { @@ -109,7 +109,7 @@ public class RefreshService extends Service implements Constants { } } else if (BROADCAST_REFRESH_TRENDS.equals(action)) { final long[] refreshIds = getRefreshableIds(accountPrefs, new TrendsRefreshableFilter()); - if (isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.d(LOGTAG, String.format("Auto refreshing trends for %s", Arrays.toString(refreshIds))); } if (!isLocalTrendsRefreshing()) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java b/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java index 12ab1b46d..3b18adb57 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/AsyncTwitterWrapper.java @@ -32,6 +32,9 @@ import android.support.annotation.NonNull; import android.support.v4.util.LongSparseArray; import android.util.Log; +import com.desmond.asyncmanager.AsyncManager; +import com.desmond.asyncmanager.BackgroundTask; +import com.desmond.asyncmanager.TaskRunnable; import com.squareup.otto.Bus; import org.apache.commons.lang3.ArrayUtils; @@ -39,12 +42,15 @@ import org.mariotaku.querybuilder.Columns.Column; import org.mariotaku.querybuilder.Expression; import org.mariotaku.querybuilder.RawItemArray; import org.mariotaku.querybuilder.SQLFunctions; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.R; import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.http.HttpResponseCode; import org.mariotaku.twidere.api.twitter.model.DirectMessage; +import org.mariotaku.twidere.api.twitter.model.FriendshipUpdate; import org.mariotaku.twidere.api.twitter.model.Paging; +import org.mariotaku.twidere.api.twitter.model.Relationship; import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.SavedSearch; import org.mariotaku.twidere.api.twitter.model.Status; @@ -82,6 +88,7 @@ import org.mariotaku.twidere.util.content.ContentResolverUtils; import org.mariotaku.twidere.util.message.FavoriteCreatedEvent; import org.mariotaku.twidere.util.message.FavoriteDestroyedEvent; import org.mariotaku.twidere.util.message.FriendshipUpdatedEvent; +import org.mariotaku.twidere.util.message.FriendshipUserUpdatedEvent; import org.mariotaku.twidere.util.message.GetMessagesTaskEvent; import org.mariotaku.twidere.util.message.GetStatusesTaskEvent; import org.mariotaku.twidere.util.message.ProfileUpdatedEvent; @@ -518,6 +525,33 @@ public class AsyncTwitterWrapper extends TwitterWrapper { return null; } + public BackgroundTask updateFriendship(final long accountId, final long userId, final FriendshipUpdate update) { + final Bus bus = TwidereApplication.getInstance(mContext).getMessageBus(); + if (bus == null) return null; + return AsyncManager.runBackgroundTask(new TaskRunnable, Bus>() { + @Override + public SingleResponse doLongOperation(Object param) throws InterruptedException { + final Twitter twitter = TwitterAPIUtils.getTwitterInstance(mContext, accountId, true); + try { + return SingleResponse.getInstance(twitter.updateFriendship(userId, update)); + } catch (TwitterException e) { + return SingleResponse.getInstance(e); + } + } + + @Override + public void callback(Bus handler, SingleResponse result) { + if (result.hasData()) { + handler.post(new FriendshipUpdatedEvent(accountId, userId, result.getData())); + } else if (result.hasException()) { + if (BuildConfig.DEBUG) { + Log.w(LOGTAG, "Unable to update friendship", result.getException()); + } + } + } + }.setResultHandler(bus)); + } + static class GetSavedSearchesTask extends ManagedAsyncTask> { private final Context mContext; @@ -569,6 +603,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { if (result.hasData()) { showOkMessage(mContext, R.string.profile_banner_image_updated, false); final Bus bus = TwidereApplication.getInstance(mContext).getMessageBus(); + assert bus != null; bus.post(new ProfileUpdatedEvent(result.getData())); } else { showErrorMessage(mContext, R.string.action_updating_profile_banner_image, result.getException(), @@ -834,7 +869,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { manager.getDisplayName(result.getData(), nameFirst, true)); showInfoMessage(mContext, message, false); final Bus bus = application.getMessageBus(); - bus.post(new FriendshipUpdatedEvent(result.getData())); + bus.post(new FriendshipUserUpdatedEvent(result.getData())); } else { showErrorMessage(mContext, R.string.action_blocking, result.getException(), true); } @@ -968,7 +1003,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { } showOkMessage(mContext, message, false); final Bus bus = application.getMessageBus(); - bus.post(new FriendshipUpdatedEvent(result.getData())); + bus.post(new FriendshipUserUpdatedEvent(result.getData())); } else { showErrorMessage(mContext, R.string.action_following, result.getException(), false); } @@ -1072,7 +1107,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { manager.getDisplayName(result.getData(), nameFirst, true)); showInfoMessage(mContext, message, false); final Bus bus = application.getMessageBus(); - bus.post(new FriendshipUpdatedEvent(result.getData())); + bus.post(new FriendshipUserUpdatedEvent(result.getData())); } else { showErrorMessage(mContext, R.string.action_muting, result.getException(), true); } @@ -1354,7 +1389,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { manager.getDisplayName(result.getData(), nameFirst, true)); showInfoMessage(mContext, message, false); final Bus bus = application.getMessageBus(); - bus.post(new FriendshipUpdatedEvent(result.getData())); + bus.post(new FriendshipUserUpdatedEvent(result.getData())); } else { showErrorMessage(mContext, R.string.action_unblocking, result.getException(), true); } @@ -1604,7 +1639,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { manager.getDisplayName(result.getData(), nameFirst, true)); showInfoMessage(mContext, message, false); final Bus bus = application.getMessageBus(); - bus.post(new FriendshipUpdatedEvent(result.getData())); + bus.post(new FriendshipUserUpdatedEvent(result.getData())); } else { showErrorMessage(mContext, R.string.action_unfollowing, result.getException(), true); } @@ -1648,7 +1683,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { manager.getDisplayName(result.getData(), nameFirst, true)); showInfoMessage(mContext, message, false); final Bus bus = application.getMessageBus(); - bus.post(new FriendshipUpdatedEvent(result.getData())); + bus.post(new FriendshipUserUpdatedEvent(result.getData())); } else { showErrorMessage(mContext, R.string.action_unmuting, result.getException(), true); } @@ -1902,7 +1937,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { truncated)); storeMessages(accountId, messages, isOutgoing(), true); } catch (final TwitterException e) { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.w(LOGTAG, e); } result.add(new MessageListResponse(accountId, e)); @@ -2388,7 +2423,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper { } showInfoMessage(mContext, R.string.reported_user_for_spam, false); final Bus bus = TwidereApplication.getInstance(mContext).getMessageBus(); - bus.post(new FriendshipUpdatedEvent(result.getData())); + bus.post(new FriendshipUserUpdatedEvent(result.getData())); } else { showErrorMessage(mContext, R.string.action_reporting_for_spam, result.getException(), true); } @@ -2587,5 +2622,4 @@ public class AsyncTwitterWrapper extends TwitterWrapper { } } - } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/PermissionsManager.java b/twidere/src/main/java/org/mariotaku/twidere/util/PermissionsManager.java index 5915540ce..951ebc2b9 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/PermissionsManager.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/PermissionsManager.java @@ -26,6 +26,7 @@ import android.os.Binder; import android.os.Process; import android.text.TextUtils; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; import java.util.HashMap; @@ -81,7 +82,7 @@ public class PermissionsManager implements Constants { public boolean checkSignature(final String pname) { if (mContext.getPackageName().equals(pname)) return true; - if (Utils.isDebugBuild()) return false; + if (BuildConfig.DEBUG) return false; return mPackageManager.checkSignatures(pname, mContext.getPackageName()) == PackageManager.SIGNATURE_MATCH; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/SharedPreferencesWrapper.java b/twidere/src/main/java/org/mariotaku/twidere/util/SharedPreferencesWrapper.java index d9a4db4a2..cde58d8bb 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/SharedPreferencesWrapper.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/SharedPreferencesWrapper.java @@ -5,6 +5,7 @@ import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.util.Log; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.annotation.Preference; @@ -49,7 +50,7 @@ public class SharedPreferencesWrapper implements Constants { try { return mPreferences.getBoolean(key, defValue); } catch (final ClassCastException e) { - if (Utils.isDebugBuild()) Log.w(LOGTAG, e); + if (BuildConfig.DEBUG) Log.w(LOGTAG, e); mPreferences.edit().remove(key).apply(); return defValue; } @@ -65,7 +66,7 @@ public class SharedPreferencesWrapper implements Constants { try { return mPreferences.getFloat(key, defValue); } catch (final ClassCastException e) { - if (Utils.isDebugBuild()) Log.w(LOGTAG, e); + if (BuildConfig.DEBUG) Log.w(LOGTAG, e); mPreferences.edit().remove(key).apply(); return defValue; } @@ -75,7 +76,7 @@ public class SharedPreferencesWrapper implements Constants { try { return mPreferences.getInt(key, defValue); } catch (final ClassCastException e) { - if (Utils.isDebugBuild()) Log.w(LOGTAG, e); + if (BuildConfig.DEBUG) Log.w(LOGTAG, e); mPreferences.edit().remove(key).apply(); return defValue; } @@ -85,7 +86,7 @@ public class SharedPreferencesWrapper implements Constants { try { return mPreferences.getLong(key, defValue); } catch (final ClassCastException e) { - if (Utils.isDebugBuild()) Log.w(LOGTAG, e); + if (BuildConfig.DEBUG) Log.w(LOGTAG, e); mPreferences.edit().remove(key).apply(); return defValue; } @@ -99,7 +100,7 @@ public class SharedPreferencesWrapper implements Constants { try { return mPreferences.getString(key, defValue); } catch (final ClassCastException e) { - if (Utils.isDebugBuild()) Log.w(LOGTAG, e); + if (BuildConfig.DEBUG) Log.w(LOGTAG, e); mPreferences.edit().remove(key).apply(); return defValue; } @@ -109,7 +110,7 @@ public class SharedPreferencesWrapper implements Constants { try { return mPreferences.getStringSet(key, defValue); } catch (final ClassCastException e) { - if (Utils.isDebugBuild()) Log.w(LOGTAG, e); + if (BuildConfig.DEBUG) Log.w(LOGTAG, e); mPreferences.edit().remove(key).apply(); return defValue; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java index 1309ab828..8c076c1f5 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java @@ -2405,10 +2405,6 @@ public final class Utils implements Constants, TwitterConstants { } } - public static boolean isDebugBuild() { - return BuildConfig.DEBUG; - } - public static boolean isFiltered(final SQLiteDatabase database, final long user_id, final String text_plain, final String text_html, final String source, final long retweeted_by_id) { return isFiltered(database, user_id, text_plain, text_html, source, retweeted_by_id, true); @@ -3507,7 +3503,7 @@ public final class Utils implements Constants, TwitterConstants { @Override public void run() { if (isNetworkAvailable(context) && hasAutoRefreshAccounts(context)) { - if (isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.d(LOGTAG, "Start background refresh service"); } context.startService(refreshServiceIntent); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/FriendshipUpdatedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/util/message/FriendshipUpdatedEvent.java index 756d03652..f9cfbadce 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/message/FriendshipUpdatedEvent.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/message/FriendshipUpdatedEvent.java @@ -1,7 +1,7 @@ /* - * Twidere - Twitter client for Android + * Twidere - Twitter client for Android * - * Copyright (C) 2012-2014 Mariotaku Lee + * Copyright (C) 2012-2015 Mariotaku Lee * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,17 +21,21 @@ package org.mariotaku.twidere.util.message; import android.support.annotation.NonNull; -import org.mariotaku.twidere.model.ParcelableUser; +import org.mariotaku.twidere.api.twitter.model.Relationship; /** * Created by mariotaku on 14/12/7. */ public class FriendshipUpdatedEvent { + public final long accountId; + public final long userId; @NonNull - public final ParcelableUser user; + public final Relationship relationship; - public FriendshipUpdatedEvent(@NonNull ParcelableUser user) { - this.user = user; + public FriendshipUpdatedEvent(long accountId, long userId,@NonNull Relationship relationship) { + this.accountId = accountId; + this.userId = userId; + this.relationship = relationship; } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/FriendshipUserUpdatedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/util/message/FriendshipUserUpdatedEvent.java new file mode 100644 index 000000000..8415eff5e --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/util/message/FriendshipUserUpdatedEvent.java @@ -0,0 +1,37 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2014 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.util.message; + +import android.support.annotation.NonNull; + +import org.mariotaku.twidere.model.ParcelableUser; + +/** + * Created by mariotaku on 14/12/7. + */ +public class FriendshipUserUpdatedEvent { + + @NonNull + public final ParcelableUser user; + + public FriendshipUserUpdatedEvent(@NonNull ParcelableUser user) { + this.user = user; + } +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/net/TwidereHostAddressResolver.java b/twidere/src/main/java/org/mariotaku/twidere/util/net/TwidereHostAddressResolver.java index c53e474ed..2a2eb46dd 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/net/TwidereHostAddressResolver.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/net/TwidereHostAddressResolver.java @@ -28,9 +28,9 @@ import android.util.LruCache; import com.squareup.okhttp.internal.Network; import org.apache.http.conn.util.InetAddressUtils; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.util.HostsFileParser; -import org.mariotaku.twidere.util.Utils; import org.xbill.DNS.AAAARecord; import org.xbill.DNS.ARecord; import org.xbill.DNS.CNAMERecord; @@ -84,7 +84,7 @@ public class TwidereHostAddressResolver implements Constants, Network { // First, I'll try to load address cached. final InetAddress[] cachedHostAddr = mHostCache.get(host); if (cachedHostAddr != null) { - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.d(RESOLVER_LOGTAG, "Got cached " + Arrays.toString(cachedHostAddr)); return cachedHostAddr; } @@ -96,7 +96,7 @@ public class TwidereHostAddressResolver implements Constants, Network { if (mappedAddr != null) { final InetAddress[] hostAddr = fromAddressString(originalHost, mappedAddr); mHostCache.put(originalHost, hostAddr); - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.d(RESOLVER_LOGTAG, "Got mapped " + Arrays.toString(hostAddr)); } return hostAddr; @@ -106,7 +106,7 @@ public class TwidereHostAddressResolver implements Constants, Network { if (mSystemHosts.contains(host)) { final InetAddress[] hostAddr = fromAddressString(originalHost, mSystemHosts.getAddress(host)); mHostCache.put(originalHost, hostAddr); - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.d(RESOLVER_LOGTAG, "Got hosts " + Arrays.toString(hostAddr)); } return hostAddr; @@ -115,7 +115,7 @@ public class TwidereHostAddressResolver implements Constants, Network { if (customMappedHost != null) { final InetAddress[] hostAddr = fromAddressString(originalHost, customMappedHost); mHostCache.put(originalHost, hostAddr); - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.d(RESOLVER_LOGTAG, "Got mapped address " + customMappedHost + " for host " + host); } return hostAddr; @@ -146,7 +146,7 @@ public class TwidereHostAddressResolver implements Constants, Network { if (!resolvedAddresses.isEmpty()) { final InetAddress[] hostAddr = resolvedAddresses.toArray(new InetAddress[resolvedAddresses.size()]); mHostCache.put(originalHost, hostAddr); - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.d(RESOLVER_LOGTAG, "Resolved " + Arrays.toString(hostAddr)); } return hostAddr; @@ -158,7 +158,7 @@ public class TwidereHostAddressResolver implements Constants, Network { return resolveInternal(originalHost, ((CNAMERecord) record).getTarget().toString()); } } - if (Utils.isDebugBuild()) { + if (BuildConfig.DEBUG) { Log.w(RESOLVER_LOGTAG, "Resolve address " + host + " failed, using original host"); } final InetAddress[] defaultAddresses = InetAddress.getAllByName(host); diff --git a/twidere/src/main/res/menu/menu_user_profile.xml b/twidere/src/main/res/menu/menu_user_profile.xml index 59bc4e567..f5638a6c0 100644 --- a/twidere/src/main/res/menu/menu_user_profile.xml +++ b/twidere/src/main/res/menu/menu_user_profile.xml @@ -1,68 +1,73 @@ + xmlns:app="http://schemas.android.com/apk/res-auto"> + android:title="@string/mention_this_user" + app:showAsAction="ifRoom" /> + android:visible="false" /> + android:title="@string/add_to_list" /> + android:title="@string/set_color" /> + android:title="@string/set_nickname" /> + android:title="@string/add_to_filter" /> + + android:title="@string/twitter_mute_user" /> + android:title="@string/block" /> + android:title="@string/report_for_spam" /> + android:title="@string/twitter_muted_users" /> + android:title="@string/blocked_users" /> + android:title="@string/incoming_friendships" /> + android:title="@string/user_mentions" /> + android:title="@string/saved_searches" /> + android:title="@string/open_with_account" /> \ No newline at end of file diff --git a/twidere/src/main/res/values/ids.xml b/twidere/src/main/res/values/ids.xml index dad6ef51d..886bb4138 100644 --- a/twidere/src/main/res/values/ids.xml +++ b/twidere/src/main/res/values/ids.xml @@ -40,6 +40,7 @@ + diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index 98683b42f..aa372c572 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -747,5 +747,7 @@ Delete all messages of this conversation? Display name first Display @screenname first - Comment... + Comment… + Enable retweets + Disable retweets \ No newline at end of file