mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-17 04:00:48 +01:00
improved nickname/color performance (hopefully!)
This commit is contained in:
parent
865f42d171
commit
17394ce47d
@ -196,8 +196,11 @@ public interface SharedPreferenceConstants {
|
||||
String KEY_NOTIFICATION_RINGTONE = "notification_ringtone";
|
||||
String KEY_NOTIFICATION_LIGHT_COLOR = "notification_light_color";
|
||||
String KEY_SHARE_FORMAT = "share_format";
|
||||
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = true)
|
||||
String KEY_HOME_REFRESH_MENTIONS = "home_refresh_mentions";
|
||||
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = true)
|
||||
String KEY_HOME_REFRESH_DIRECT_MESSAGES = "home_refresh_direct_messages";
|
||||
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = true)
|
||||
String KEY_HOME_REFRESH_TRENDS = "home_refresh_trends";
|
||||
String KEY_IMAGE_UPLOAD_FORMAT = "image_upload_format";
|
||||
String KEY_STATUS_SHORTENER = "status_shortener";
|
||||
|
@ -120,7 +120,7 @@ import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.TwidereArrayUtils;
|
||||
import org.mariotaku.twidere.util.TwidereValidator;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.view.ActionIconView;
|
||||
import org.mariotaku.twidere.view.BadgeView;
|
||||
@ -1015,26 +1015,26 @@ public class ComposeActivity extends ThemedFragmentActivity implements LocationL
|
||||
|
||||
private boolean setComposeTitle(final Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(this);
|
||||
final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
|
||||
if (INTENT_ACTION_REPLY.equals(action)) {
|
||||
if (mInReplyToStatus == null) return false;
|
||||
final String display_name = UserColorNameUtils.getDisplayName(this, mInReplyToStatus.user_id, mInReplyToStatus.user_name,
|
||||
mInReplyToStatus.user_screen_name);
|
||||
setTitle(getString(R.string.reply_to, display_name));
|
||||
final String displayName = manager.getDisplayName(mInReplyToStatus.user_id, mInReplyToStatus.user_name,
|
||||
mInReplyToStatus.user_screen_name, nameFirst, false);
|
||||
setTitle(getString(R.string.reply_to, displayName));
|
||||
} else if (INTENT_ACTION_QUOTE.equals(action)) {
|
||||
if (mInReplyToStatus == null) return false;
|
||||
final String display_name = UserColorNameUtils.getDisplayName(this, mInReplyToStatus.user_id, mInReplyToStatus.user_name,
|
||||
mInReplyToStatus.user_screen_name);
|
||||
setTitle(getString(R.string.quote_user, display_name));
|
||||
// mSubtitleView.setVisibility(mInReplyToStatus.user_is_protected
|
||||
// && mInReplyToStatus.account_id != mInReplyToStatus.user_id ? View.VISIBLE : View.GONE);
|
||||
final String displayName = manager.getDisplayName(mInReplyToStatus.user_id, mInReplyToStatus.user_name,
|
||||
mInReplyToStatus.user_screen_name, nameFirst, false);
|
||||
setTitle(getString(R.string.quote_user, displayName));
|
||||
} else if (INTENT_ACTION_EDIT_DRAFT.equals(action)) {
|
||||
if (mDraftItem == null) return false;
|
||||
setTitle(R.string.edit_draft);
|
||||
} else if (INTENT_ACTION_MENTION.equals(action)) {
|
||||
if (mMentionUser == null) return false;
|
||||
final String display_name = UserColorNameUtils.getDisplayName(this, mMentionUser.id, mMentionUser.name,
|
||||
mMentionUser.screen_name);
|
||||
setTitle(getString(R.string.mention_user, display_name));
|
||||
final String displayName = manager.getDisplayName(mMentionUser.id, mMentionUser.name,
|
||||
mMentionUser.screen_name, nameFirst, false);
|
||||
setTitle(getString(R.string.mention_user, displayName));
|
||||
} else if (INTENT_ACTION_REPLY_MULTIPLE.equals(action)) {
|
||||
setTitle(R.string.reply);
|
||||
} else if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
|
||||
|
@ -57,6 +57,7 @@ import org.mariotaku.twidere.model.ParcelableUserList;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.ParseUtils;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.Comparator;
|
||||
@ -68,7 +69,6 @@ import static org.mariotaku.twidere.util.CustomTabUtils.findTabIconKey;
|
||||
import static org.mariotaku.twidere.util.CustomTabUtils.getIconMap;
|
||||
import static org.mariotaku.twidere.util.CustomTabUtils.getTabConfiguration;
|
||||
import static org.mariotaku.twidere.util.CustomTabUtils.getTabTypeName;
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.getUserNickname;
|
||||
|
||||
public class CustomTabEditorActivity extends BaseSupportDialogActivity implements OnClickListener {
|
||||
|
||||
@ -219,28 +219,24 @@ public class CustomTabEditorActivity extends BaseSupportDialogActivity implement
|
||||
final ImageView icon = (ImageView) view.findViewById(android.R.id.icon);
|
||||
final boolean displayProfileImage = mPreferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true);
|
||||
final boolean displayName = mPreferences.getBoolean(KEY_NAME_FIRST, true);
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(this);
|
||||
text1.setVisibility(View.VISIBLE);
|
||||
text2.setVisibility(View.VISIBLE);
|
||||
icon.setVisibility(displayProfileImage ? View.VISIBLE : View.GONE);
|
||||
if (value instanceof ParcelableUser) {
|
||||
final ParcelableUser user = (ParcelableUser) value;
|
||||
text1.setText(getUserNickname(this, user.id, user.name));
|
||||
text1.setText(manager.getUserNickname(user.id, user.name, false));
|
||||
text2.setText("@" + user.screen_name);
|
||||
if (displayProfileImage) {
|
||||
mImageLoader.displayProfileImage(icon, user.profile_image_url);
|
||||
}
|
||||
} else if (value instanceof ParcelableUserList) {
|
||||
final ParcelableUserList user_list = (ParcelableUserList) value;
|
||||
final String created_by;
|
||||
if (displayName) {
|
||||
created_by = "@" + user_list.user_screen_name;
|
||||
} else {
|
||||
created_by = getUserNickname(this, user_list.user_id, user_list.user_name);
|
||||
}
|
||||
text1.setText(user_list.name);
|
||||
text2.setText(getString(R.string.created_by, created_by));
|
||||
final ParcelableUserList userList = (ParcelableUserList) value;
|
||||
final String createdBy = manager.getDisplayName(userList, displayName, false);
|
||||
text1.setText(userList.name);
|
||||
text2.setText(getString(R.string.created_by, createdBy));
|
||||
if (displayProfileImage) {
|
||||
mImageLoader.displayProfileImage(icon, user_list.user_profile_image_url);
|
||||
mImageLoader.displayProfileImage(icon, userList.user_profile_image_url);
|
||||
}
|
||||
} else if (value instanceof CharSequence) {
|
||||
text2.setVisibility(View.GONE);
|
||||
|
@ -22,7 +22,6 @@ package org.mariotaku.twidere.activity.support;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.PorterDuff.Mode;
|
||||
import android.graphics.Rect;
|
||||
@ -76,6 +75,7 @@ import org.mariotaku.twidere.util.ParseUtils;
|
||||
import org.mariotaku.twidere.util.SwipeDismissListViewTouchListener;
|
||||
import org.mariotaku.twidere.util.SwipeDismissListViewTouchListener.DismissCallbacks;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.content.ContentResolverUtils;
|
||||
import org.mariotaku.twidere.view.ExtendedRelativeLayout;
|
||||
@ -84,8 +84,6 @@ import org.mariotaku.twidere.view.iface.IExtendedView.OnFitSystemWindowsListener
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.getUserNickname;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/1/6.
|
||||
*/
|
||||
@ -397,12 +395,15 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On
|
||||
private final Context mContext;
|
||||
private final LayoutInflater mInflater;
|
||||
private final MediaLoaderWrapper mImageLoader;
|
||||
private final UserColorNameManager mUserColorNameManager;
|
||||
private List<SuggestionItem> mData;
|
||||
|
||||
SuggestionsAdapter(Context context) {
|
||||
mContext = context;
|
||||
mInflater = LayoutInflater.from(context);
|
||||
mImageLoader = TwidereApplication.getInstance(context).getMediaLoaderWrapper();
|
||||
final TwidereApplication application = TwidereApplication.getInstance(context);
|
||||
mImageLoader = application.getMediaLoaderWrapper();
|
||||
mUserColorNameManager = application.getUserColorNameManager();
|
||||
}
|
||||
|
||||
public boolean canDismiss(int position) {
|
||||
@ -473,6 +474,10 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On
|
||||
mData = data;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public UserColorNameManager getUserColorNameManager() {
|
||||
return mUserColorNameManager;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SuggestionsLoader extends AsyncTaskLoader<List<SuggestionItem>> {
|
||||
@ -502,8 +507,7 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On
|
||||
historyCursor.close();
|
||||
if (!emptyQuery) {
|
||||
final String queryEscaped = mQuery.replace("_", "^_");
|
||||
final SharedPreferences nicknamePrefs = context.getSharedPreferences(
|
||||
USER_NICKNAME_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
final UserColorNameManager nicknamePrefs = UserColorNameManager.getInstance(context);
|
||||
final long[] nicknameIds = Utils.getMatchedNicknameIds(mQuery, nicknamePrefs);
|
||||
final Expression selection = Expression.or(
|
||||
Expression.likeRaw(new Column(CachedUsers.SCREEN_NAME), "?||'%'", "^"),
|
||||
@ -629,13 +633,13 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On
|
||||
@Override
|
||||
public void bindView(SuggestionsAdapter adapter, View view, int position) {
|
||||
final ParcelableUser user = mUser;
|
||||
final Context context = adapter.getContext();
|
||||
final MediaLoaderWrapper loader = adapter.getImageLoader();
|
||||
final UserColorNameManager manager = adapter.getUserColorNameManager();
|
||||
final ImageView icon = (ImageView) view.findViewById(android.R.id.icon);
|
||||
final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
|
||||
final TextView text2 = (TextView) view.findViewById(android.R.id.text2);
|
||||
|
||||
text1.setText(getUserNickname(context, user.id, user.name));
|
||||
text1.setText(manager.getUserNickname(user.id, user.name, false));
|
||||
text2.setVisibility(View.VISIBLE);
|
||||
text2.setText("@" + user.screen_name);
|
||||
icon.clearColorFilter();
|
||||
|
@ -47,6 +47,7 @@ import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.TwidereLinkify;
|
||||
import org.mariotaku.twidere.util.TwidereLinkify.OnLinkClickListener;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.view.holder.ActivityTitleSummaryViewHolder;
|
||||
import org.mariotaku.twidere.view.holder.GapViewHolder;
|
||||
@ -81,6 +82,7 @@ public abstract class AbsActivitiesAdapter<Data> extends Adapter<ViewHolder> imp
|
||||
private final boolean mDisplayProfileImage;
|
||||
private final TwidereLinkify mLinkify;
|
||||
private final DummyStatusHolderAdapter mStatusAdapterDelegate;
|
||||
private final UserColorNameManager mUserColorNameManager;
|
||||
private boolean mLoadMoreSupported;
|
||||
private boolean mLoadMoreIndicatorVisible;
|
||||
private ActivityAdapterListener mActivityAdapterListener;
|
||||
@ -93,6 +95,7 @@ public abstract class AbsActivitiesAdapter<Data> extends Adapter<ViewHolder> imp
|
||||
mImageLoader = app.getMediaLoaderWrapper();
|
||||
mLoadingHandler = new MediaLoadingHandler(R.id.media_preview_progress);
|
||||
mTwitterWrapper = app.getTwitterWrapper();
|
||||
mUserColorNameManager = app.getUserColorNameManager();
|
||||
final SharedPreferencesWrapper preferences = SharedPreferencesWrapper.getInstance(context,
|
||||
SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
mTextSize = preferences.getInt(KEY_TEXT_SIZE, context.getResources().getInteger(R.integer.default_text_size));
|
||||
@ -365,6 +368,11 @@ public abstract class AbsActivitiesAdapter<Data> extends Adapter<ViewHolder> imp
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserColorNameManager getUserColorNameManager() {
|
||||
return mUserColorNameManager;
|
||||
}
|
||||
|
||||
public void setListener(ActivityAdapterListener listener) {
|
||||
mActivityAdapterListener = listener;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import org.mariotaku.twidere.util.StatusAdapterLinkClickHandler;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.TwidereLinkify;
|
||||
import org.mariotaku.twidere.util.TwidereLinkify.HighlightStyle;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.view.CardMediaContainer.PreviewStyle;
|
||||
import org.mariotaku.twidere.view.ShapedImageView.ShapeStyle;
|
||||
@ -43,6 +44,7 @@ public abstract class AbsStatusesAdapter<D> extends LoadMoreSupportAdapter<ViewH
|
||||
private final MediaLoadingHandler mLoadingHandler;
|
||||
private final AsyncTwitterWrapper mTwitterWrapper;
|
||||
private final TwidereLinkify mLinkify;
|
||||
private final UserColorNameManager mUserColorNameManager;
|
||||
|
||||
private StatusAdapterListener mStatusAdapterListener;
|
||||
|
||||
@ -71,6 +73,7 @@ public abstract class AbsStatusesAdapter<D> extends LoadMoreSupportAdapter<ViewH
|
||||
mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(context, ThemeUtils.getThemeBackgroundOption(context), ThemeUtils.getUserThemeBackgroundAlpha(context));
|
||||
mInflater = LayoutInflater.from(context);
|
||||
mMediaLoader = app.getMediaLoaderWrapper();
|
||||
mUserColorNameManager = app.getUserColorNameManager();
|
||||
mLoadingHandler = new MediaLoadingHandler(R.id.media_preview_progress);
|
||||
mTwitterWrapper = app.getTwitterWrapper();
|
||||
final SharedPreferencesWrapper preferences = SharedPreferencesWrapper.getInstance(context,
|
||||
@ -130,6 +133,11 @@ public abstract class AbsStatusesAdapter<D> extends LoadMoreSupportAdapter<ViewH
|
||||
return mTwitterWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserColorNameManager getUserColorNameManager() {
|
||||
return mUserColorNameManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final float getTextSize() {
|
||||
return mTextSize;
|
||||
|
@ -35,6 +35,7 @@ import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.view.holder.LoadIndicatorViewHolder;
|
||||
import org.mariotaku.twidere.view.holder.UserViewHolder;
|
||||
@ -55,12 +56,15 @@ public abstract class AbsUsersAdapter<D> extends LoadMoreSupportAdapter<ViewHold
|
||||
private final AsyncTwitterWrapper mTwitterWrapper;
|
||||
private final boolean mDisplayProfileImage;
|
||||
|
||||
private final UserColorNameManager mUserColorNameManager;
|
||||
|
||||
public AbsUsersAdapter(final Context context, final boolean compact) {
|
||||
final TwidereApplication app = TwidereApplication.getInstance(context);
|
||||
mContext = context;
|
||||
mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(context, ThemeUtils.getThemeBackgroundOption(context), ThemeUtils.getUserThemeBackgroundAlpha(context));
|
||||
mInflater = LayoutInflater.from(context);
|
||||
mMediaLoader = app.getMediaLoaderWrapper();
|
||||
mUserColorNameManager = app.getUserColorNameManager();
|
||||
mTwitterWrapper = app.getTwitterWrapper();
|
||||
final SharedPreferencesWrapper preferences = SharedPreferencesWrapper.getInstance(context,
|
||||
SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
@ -91,6 +95,11 @@ public abstract class AbsUsersAdapter<D> extends LoadMoreSupportAdapter<ViewHold
|
||||
return mTwitterWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserColorNameManager getUserColorNameManager() {
|
||||
return mUserColorNameManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProfileImageEnabled() {
|
||||
return mDisplayProfileImage;
|
||||
|
@ -43,6 +43,7 @@ import org.mariotaku.twidere.util.MultiSelectManager;
|
||||
import org.mariotaku.twidere.util.ReadStateManager;
|
||||
import org.mariotaku.twidere.util.ReadStateManager.OnReadStateChangeListener;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.view.holder.LoadIndicatorViewHolder;
|
||||
import org.mariotaku.twidere.view.holder.MessageEntryViewHolder;
|
||||
@ -62,8 +63,10 @@ public class MessageEntriesAdapter extends Adapter<ViewHolder> implements Consta
|
||||
private final int mMediaPreviewStyle;
|
||||
private final ReadStateManager mReadStateManager;
|
||||
private final OnSharedPreferenceChangeListener mReadStateChangeListener;
|
||||
private final boolean mDisplayProfileImage;
|
||||
private UserColorNameManager mUserColorNameManager;
|
||||
private final AsyncTwitterWrapper mTwitterWrapper;
|
||||
|
||||
private final boolean mDisplayProfileImage;
|
||||
private boolean mLoadMoreSupported;
|
||||
private boolean mLoadMoreIndicatorVisible;
|
||||
private Cursor mCursor;
|
||||
@ -84,6 +87,7 @@ public class MessageEntriesAdapter extends Adapter<ViewHolder> implements Consta
|
||||
mDisplayProfileImage = preferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true);
|
||||
mTextSize = preferences.getInt(KEY_TEXT_SIZE, context.getResources().getInteger(R.integer.default_text_size));
|
||||
mReadStateManager = app.getReadStateManager();
|
||||
mUserColorNameManager = app.getUserColorNameManager();
|
||||
mReadStateChangeListener = new OnSharedPreferenceChangeListener() {
|
||||
|
||||
@Override
|
||||
@ -130,6 +134,11 @@ public class MessageEntriesAdapter extends Adapter<ViewHolder> implements Consta
|
||||
return mImageLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserColorNameManager getUserColorNameManager() {
|
||||
return mUserColorNameManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoadMoreIndicatorVisible() {
|
||||
return mLoadMoreIndicatorVisible;
|
||||
|
@ -32,7 +32,7 @@ import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.model.ParcelableUserList;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.MultiSelectManager;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.view.holder.UserListViewListHolder;
|
||||
|
||||
@ -50,6 +50,7 @@ public class ParcelableUserListsListAdapter extends BaseArrayAdapter<ParcelableU
|
||||
private final MediaLoaderWrapper mImageLoader;
|
||||
private final MultiSelectManager mMultiSelectManager;
|
||||
private final Locale mLocale;
|
||||
private final UserColorNameManager mUserColorNameManager;
|
||||
|
||||
public ParcelableUserListsListAdapter(final Context context) {
|
||||
this(context, Utils.isCompactCards(context));
|
||||
@ -62,6 +63,7 @@ public class ParcelableUserListsListAdapter extends BaseArrayAdapter<ParcelableU
|
||||
final TwidereApplication app = TwidereApplication.getInstance(context);
|
||||
mImageLoader = app.getMediaLoaderWrapper();
|
||||
mMultiSelectManager = app.getMultiSelectManager();
|
||||
mUserColorNameManager = app.getUserColorNameManager();
|
||||
configBaseCardAdapter(context, this);
|
||||
}
|
||||
|
||||
@ -91,8 +93,7 @@ public class ParcelableUserListsListAdapter extends BaseArrayAdapter<ParcelableU
|
||||
holder.position = position;
|
||||
|
||||
final ParcelableUserList userList = getItem(position);
|
||||
final String displayName = UserColorNameUtils.getDisplayName(mContext, userList.user_id, userList.user_name,
|
||||
userList.user_screen_name, isDisplayNameFirst(), false);
|
||||
final String displayName = mUserColorNameManager.getDisplayName(userList, isDisplayNameFirst(), false);
|
||||
holder.setTextSize(getTextSize());
|
||||
holder.name.setText(userList.name);
|
||||
holder.created_by.setText(mContext.getString(R.string.created_by, displayName));
|
||||
|
@ -28,7 +28,7 @@ import org.mariotaku.twidere.adapter.iface.IBaseAdapter;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.model.ParcelableUserList;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.view.holder.TwoLineWithIconViewHolder;
|
||||
|
||||
import java.util.List;
|
||||
@ -39,12 +39,14 @@ public class SimpleParcelableUserListsAdapter extends BaseArrayAdapter<Parcelabl
|
||||
|
||||
private final Context mContext;
|
||||
private final MediaLoaderWrapper mImageLoader;
|
||||
private UserColorNameManager mUserColorNameManager;
|
||||
|
||||
public SimpleParcelableUserListsAdapter(final Context context) {
|
||||
super(context, R.layout.list_item_two_line);
|
||||
mContext = context;
|
||||
final TwidereApplication app = TwidereApplication.getInstance(context);
|
||||
mImageLoader = app.getMediaLoaderWrapper();
|
||||
mUserColorNameManager = app.getUserColorNameManager();
|
||||
configBaseAdapter(context, this);
|
||||
}
|
||||
|
||||
@ -73,8 +75,8 @@ public class SimpleParcelableUserListsAdapter extends BaseArrayAdapter<Parcelabl
|
||||
holder.icon.setImageDrawable(null);
|
||||
|
||||
final ParcelableUserList user_list = getItem(position);
|
||||
final String display_name = UserColorNameUtils.getDisplayName(mContext, user_list.user_id, user_list.user_name,
|
||||
user_list.user_screen_name, isDisplayNameFirst(), false);
|
||||
final String display_name = mUserColorNameManager.getDisplayName(user_list, isDisplayNameFirst(),
|
||||
false);
|
||||
holder.text1.setText(user_list.name);
|
||||
holder.text2.setText(mContext.getString(R.string.created_by, display_name));
|
||||
holder.icon.setVisibility(isProfileImageDisplayed() ? View.VISIBLE : View.GONE);
|
||||
|
@ -28,11 +28,11 @@ import org.mariotaku.twidere.adapter.iface.IBaseAdapter;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.view.holder.TwoLineWithIconViewHolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.getUserNickname;
|
||||
import static org.mariotaku.twidere.util.Utils.configBaseAdapter;
|
||||
import static org.mariotaku.twidere.util.Utils.getUserTypeIconRes;
|
||||
|
||||
@ -40,6 +40,7 @@ public class SimpleParcelableUsersAdapter extends BaseArrayAdapter<ParcelableUse
|
||||
|
||||
private final MediaLoaderWrapper mImageLoader;
|
||||
private final Context mContext;
|
||||
private final UserColorNameManager mUserColorNameManager;
|
||||
|
||||
public SimpleParcelableUsersAdapter(final Context context) {
|
||||
this(context, R.layout.list_item_user);
|
||||
@ -50,6 +51,7 @@ public class SimpleParcelableUsersAdapter extends BaseArrayAdapter<ParcelableUse
|
||||
mContext = context;
|
||||
final TwidereApplication app = TwidereApplication.getInstance(context);
|
||||
mImageLoader = app.getMediaLoaderWrapper();
|
||||
mUserColorNameManager = app.getUserColorNameManager();
|
||||
configBaseAdapter(context, this);
|
||||
}
|
||||
|
||||
@ -74,7 +76,7 @@ public class SimpleParcelableUsersAdapter extends BaseArrayAdapter<ParcelableUse
|
||||
|
||||
holder.text1.setCompoundDrawablesWithIntrinsicBounds(0, 0,
|
||||
getUserTypeIconRes(user.is_verified, user.is_protected), 0);
|
||||
holder.text1.setText(getUserNickname(mContext, user.id, user.name));
|
||||
holder.text1.setText(mUserColorNameManager.getUserNickname(user.id, user.name));
|
||||
holder.text2.setText("@" + user.screen_name);
|
||||
holder.icon.setVisibility(isProfileImageDisplayed() ? View.VISIBLE : View.GONE);
|
||||
if (isProfileImageDisplayed()) {
|
||||
|
@ -21,7 +21,6 @@ package org.mariotaku.twidere.adapter;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.PorterDuff.Mode;
|
||||
@ -46,10 +45,10 @@ import org.mariotaku.twidere.provider.TwidereDataStore.CachedValues;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.ParseUtils;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.view.ShapedImageView;
|
||||
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.getUserNickname;
|
||||
|
||||
public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implements Constants {
|
||||
|
||||
@ -65,7 +64,7 @@ public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implemen
|
||||
@NonNull
|
||||
private final SharedPreferencesWrapper mPreferences;
|
||||
@NonNull
|
||||
private final SharedPreferences mUserNicknamePreferences;
|
||||
private final UserColorNameManager mUserColorNameManager;
|
||||
|
||||
private final EditText mEditText;
|
||||
|
||||
@ -83,10 +82,10 @@ public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implemen
|
||||
public UserHashtagAutoCompleteAdapter(final Context context, final EditText view) {
|
||||
super(context, R.layout.list_item_auto_complete, null, FROM, TO, 0);
|
||||
mEditText = view;
|
||||
mPreferences = SharedPreferencesWrapper.getInstance(context, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
mUserNicknamePreferences = context.getSharedPreferences(USER_NICKNAME_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
mResolver = context.getContentResolver();
|
||||
final TwidereApplication app = TwidereApplication.getInstance(context);
|
||||
mPreferences = SharedPreferencesWrapper.getInstance(context, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
mUserColorNameManager = app.getUserColorNameManager();
|
||||
mResolver = context.getContentResolver();
|
||||
mProfileImageLoader = app.getMediaLoaderWrapper();
|
||||
mDatabase = app.getSQLiteDatabase();
|
||||
mDisplayProfileImage = mPreferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true);
|
||||
@ -108,7 +107,7 @@ public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implemen
|
||||
icon.setImageDrawable(null);
|
||||
|
||||
if (mScreenNameIdx != -1 && mNameIdx != -1 && mUserIdIdx != -1) {
|
||||
text1.setText(getUserNickname(context, cursor.getLong(mUserIdIdx), cursor.getString(mNameIdx)));
|
||||
text1.setText(mUserColorNameManager.getUserNickname(cursor.getLong(mUserIdIdx), cursor.getString(mNameIdx)));
|
||||
text2.setText("@" + cursor.getString(mScreenNameIdx));
|
||||
} else {
|
||||
text1.setText("#" + cursor.getString(mNameIdx));
|
||||
@ -168,7 +167,7 @@ public class UserHashtagAutoCompleteAdapter extends SimpleCursorAdapter implemen
|
||||
final Expression selection;
|
||||
final String[] selectionArgs;
|
||||
if (constraintEscaped != null) {
|
||||
final long[] nicknameIds = Utils.getMatchedNicknameIds(ParseUtils.parseString(constraint), mUserNicknamePreferences);
|
||||
final long[] nicknameIds = Utils.getMatchedNicknameIds(ParseUtils.parseString(constraint), mUserColorNameManager);
|
||||
selection = Expression.or(Expression.likeRaw(new Column(CachedUsers.SCREEN_NAME), "?||'%'", "^"),
|
||||
Expression.likeRaw(new Column(CachedUsers.NAME), "?||'%'", "^"),
|
||||
Expression.in(new Column(CachedUsers.USER_ID), new RawItemArray(nicknameIds)));
|
||||
|
@ -24,6 +24,7 @@ import android.support.annotation.NonNull;
|
||||
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.view.ShapedImageView.ShapeStyle;
|
||||
|
||||
/**
|
||||
@ -32,6 +33,8 @@ import org.mariotaku.twidere.view.ShapedImageView.ShapeStyle;
|
||||
public interface IContentCardAdapter extends ILoadMoreSupportAdapter {
|
||||
Context getContext();
|
||||
|
||||
UserColorNameManager getUserColorNameManager();
|
||||
|
||||
int getItemCount();
|
||||
|
||||
@ShapeStyle
|
||||
|
@ -3,6 +3,7 @@ package org.mariotaku.twidere.adapter.iface;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.util.MediaLoadingHandler;
|
||||
import org.mariotaku.twidere.util.TwidereLinkify;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.view.CardMediaContainer.PreviewStyle;
|
||||
import org.mariotaku.twidere.view.holder.StatusViewHolder.StatusClickListener;
|
||||
|
||||
@ -38,4 +39,5 @@ public interface IStatusesAdapter<Data> extends IContentCardAdapter, StatusClick
|
||||
boolean shouldShowAccountsColor();
|
||||
|
||||
MediaLoadingHandler getMediaLoadingHandler();
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.multidex.MultiDexApplication;
|
||||
|
||||
import com.bluelinelabs.logansquare.LoganSquare;
|
||||
import com.nostra13.universalimageloader.cache.disc.DiskCache;
|
||||
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
@ -56,6 +55,7 @@ import org.mariotaku.twidere.util.MultiSelectManager;
|
||||
import org.mariotaku.twidere.util.ReadStateManager;
|
||||
import org.mariotaku.twidere.util.StrictModeUtils;
|
||||
import org.mariotaku.twidere.util.UserAgentUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.VideoLoader;
|
||||
import org.mariotaku.twidere.util.content.TwidereSQLiteOpenHelper;
|
||||
@ -69,7 +69,6 @@ import edu.tsinghua.spice.SpiceService;
|
||||
import edu.ucdavis.earlybird.UCDService;
|
||||
import twitter4j.http.HostAddressResolver;
|
||||
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.initUserColor;
|
||||
import static org.mariotaku.twidere.util.Utils.getBestCacheDir;
|
||||
import static org.mariotaku.twidere.util.Utils.getInternalCacheDir;
|
||||
import static org.mariotaku.twidere.util.Utils.initAccountColor;
|
||||
@ -99,9 +98,15 @@ public class TwidereApplication extends MultiDexApplication implements Constants
|
||||
private VideoLoader mVideoLoader;
|
||||
private ReadStateManager mReadStateManager;
|
||||
private KeyboardShortcutsHandler mKeyboardShortcutsHandler;
|
||||
private UserColorNameManager mUserColorNameManager;
|
||||
|
||||
private String mDefaultUserAgent;
|
||||
|
||||
@NonNull
|
||||
public static TwidereApplication getInstance(@NonNull final Context context) {
|
||||
return (TwidereApplication) context.getApplicationContext();
|
||||
}
|
||||
|
||||
public AsyncTaskManager getAsyncTaskManager() {
|
||||
if (mAsyncTaskManager != null) return mAsyncTaskManager;
|
||||
return mAsyncTaskManager = AsyncTaskManager.getInstance();
|
||||
@ -121,6 +126,11 @@ public class TwidereApplication extends MultiDexApplication implements Constants
|
||||
return mFullDiskCache = createDiskCache(DIR_NAME_FULL_IMAGE_CACHE);
|
||||
}
|
||||
|
||||
public UserColorNameManager getUserColorNameManager() {
|
||||
if (mUserColorNameManager != null) return mUserColorNameManager;
|
||||
return mUserColorNameManager = new UserColorNameManager(this);
|
||||
}
|
||||
|
||||
public ImageDownloader getFullImageDownloader() {
|
||||
if (mFullImageDownloader != null) return mFullImageDownloader;
|
||||
return mFullImageDownloader = new TwidereImageDownloader(this, true, true);
|
||||
@ -144,8 +154,7 @@ public class TwidereApplication extends MultiDexApplication implements Constants
|
||||
if (mKeyboardShortcutsHandler != null) return mKeyboardShortcutsHandler;
|
||||
mKeyboardShortcutsHandler = new KeyboardShortcutsHandler(this);
|
||||
final SharedPreferences preferences = getSharedPreferences();
|
||||
if (mKeyboardShortcutsHandler.isEmpty()
|
||||
&& !preferences.getBoolean(KEY_KEYBOARD_SHORTCUT_INITIALIZED, false)) {
|
||||
if (!preferences.getBoolean(KEY_KEYBOARD_SHORTCUT_INITIALIZED, false)) {
|
||||
mKeyboardShortcutsHandler.reset();
|
||||
preferences.edit().putBoolean(KEY_KEYBOARD_SHORTCUT_INITIALIZED, true).apply();
|
||||
}
|
||||
@ -183,11 +192,6 @@ public class TwidereApplication extends MultiDexApplication implements Constants
|
||||
return mMediaLoaderWrapper = new MediaLoaderWrapper(getImageLoader(), getVideoLoader());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static TwidereApplication getInstance(@NonNull final Context context) {
|
||||
return (TwidereApplication) context.getApplicationContext();
|
||||
}
|
||||
|
||||
public Bus getMessageBus() {
|
||||
return mMessageBus;
|
||||
}
|
||||
@ -211,7 +215,7 @@ public class TwidereApplication extends MultiDexApplication implements Constants
|
||||
|
||||
public AsyncTwitterWrapper getTwitterWrapper() {
|
||||
if (mTwitterWrapper != null) return mTwitterWrapper;
|
||||
return mTwitterWrapper = AsyncTwitterWrapper.getInstance(this);
|
||||
return mTwitterWrapper = new AsyncTwitterWrapper(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -225,7 +229,6 @@ public class TwidereApplication extends MultiDexApplication implements Constants
|
||||
mMessageBus = new Bus();
|
||||
initializeAsyncTask();
|
||||
initAccountColor(this);
|
||||
initUserColor(this);
|
||||
|
||||
final PackageManager pm = getPackageManager();
|
||||
final ComponentName main = new ComponentName(this, MainActivity.class);
|
||||
|
@ -37,7 +37,7 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
|
||||
public abstract class BaseAccountPreferenceFragment extends PreferenceFragment implements Constants,
|
||||
OnCheckedChangeListener, OnSharedPreferenceChangeListener {
|
||||
@ -57,7 +57,10 @@ public abstract class BaseAccountPreferenceFragment extends PreferenceFragment i
|
||||
final Activity activity = getActivity();
|
||||
final Intent intent = activity.getIntent();
|
||||
if (account != null && intent.hasExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT)) {
|
||||
final String name = UserColorNameUtils.getDisplayName(getActivity(), account.account_id, account.name, account.screen_name);
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(activity);
|
||||
final boolean nameFirst = prefs.getBoolean(KEY_NAME_FIRST, true);
|
||||
final String name = manager.getDisplayName(account.account_id, account.name,
|
||||
account.screen_name, nameFirst, false);
|
||||
activity.setTitle(name);
|
||||
}
|
||||
updatePreferenceScreen();
|
||||
|
@ -61,6 +61,7 @@ import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.activity.support.UserListSelectorActivity;
|
||||
import org.mariotaku.twidere.adapter.SourceAutoCompleteAdapter;
|
||||
import org.mariotaku.twidere.adapter.UserHashtagAutoCompleteAdapter;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.fragment.support.BaseSupportDialogFragment;
|
||||
import org.mariotaku.twidere.fragment.support.BaseSupportListFragment;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
@ -68,7 +69,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Filters;
|
||||
import org.mariotaku.twidere.util.ContentValuesCreator;
|
||||
import org.mariotaku.twidere.util.ParseUtils;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
|
||||
import static org.mariotaku.twidere.util.Utils.getDefaultAccountId;
|
||||
@ -115,6 +116,7 @@ public abstract class BaseFiltersFragment extends BaseSupportListFragment implem
|
||||
@Override
|
||||
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
|
||||
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
assert view != null;
|
||||
final View lv = view.findViewById(android.R.id.list);
|
||||
final Resources res = getResources();
|
||||
final float density = res.getDisplayMetrics().density;
|
||||
@ -391,6 +393,8 @@ public abstract class BaseFiltersFragment extends BaseSupportListFragment implem
|
||||
|
||||
private static final class FilterUsersListAdapter extends SimpleCursorAdapter {
|
||||
|
||||
private final UserColorNameManager mUserColorNameManager;
|
||||
|
||||
private final boolean mNameFirst;
|
||||
private int mUserIdIdx, mNameIdx, mScreenNameIdx;
|
||||
|
||||
@ -399,6 +403,7 @@ public abstract class BaseFiltersFragment extends BaseSupportListFragment implem
|
||||
final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
mNameFirst = prefs.getBoolean(KEY_NAME_FIRST, true);
|
||||
mUserColorNameManager = TwidereApplication.getInstance(context).getUserColorNameManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -408,7 +413,8 @@ public abstract class BaseFiltersFragment extends BaseSupportListFragment implem
|
||||
final long userId = cursor.getLong(mUserIdIdx);
|
||||
final String name = cursor.getString(mNameIdx);
|
||||
final String screenName = cursor.getString(mScreenNameIdx);
|
||||
final String displayName = UserColorNameUtils.getDisplayName(context, userId, name, screenName, mNameFirst);
|
||||
final String displayName = mUserColorNameManager.getDisplayName(userId, name, screenName,
|
||||
mNameFirst, false);
|
||||
text1.setText(displayName);
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentListFragment<A
|
||||
return mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
public abstract int getStatuses(long[] accountIds, long[] maxIds, long[] sinceIds);
|
||||
public abstract boolean getStatuses(long[] accountIds, long[] maxIds, long[] sinceIds);
|
||||
|
||||
@Override
|
||||
public boolean handleKeyboardShortcutSingle(@NonNull KeyboardShortcutsHandler handler, int keyCode, @NonNull KeyEvent event) {
|
||||
|
@ -91,6 +91,7 @@ import org.mariotaku.twidere.activity.support.QuickSearchBarActivity;
|
||||
import org.mariotaku.twidere.activity.support.UserProfileEditorActivity;
|
||||
import org.mariotaku.twidere.adapter.ArrayAdapter;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
|
||||
import org.mariotaku.twidere.menu.SupportAccountActionProvider;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
|
||||
@ -99,9 +100,10 @@ import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
|
||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
|
||||
import org.mariotaku.twidere.util.ListViewUtils;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.TransitionUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.content.SupportFragmentReloadCursorObserver;
|
||||
import org.mariotaku.twidere.view.ShapedImageView;
|
||||
@ -628,10 +630,15 @@ public class AccountsDashboardFragment extends BaseSupportListFragment implement
|
||||
|
||||
private static final class AccountOptionsAdapter extends OptionItemsAdapter {
|
||||
|
||||
private final boolean mNameFirst;
|
||||
private final UserColorNameManager mUserColorNameManager;
|
||||
private ParcelableAccount mSelectedAccount;
|
||||
|
||||
public AccountOptionsAdapter(final Context context) {
|
||||
super(context);
|
||||
mUserColorNameManager = UserColorNameManager.getInstance(context);
|
||||
mNameFirst = SharedPreferencesWrapper.getInstance(context, SHARED_PREFERENCES_NAME,
|
||||
Context.MODE_PRIVATE, SharedPreferenceConstants.class).getBoolean(KEY_NAME_FIRST);
|
||||
}
|
||||
|
||||
public void setSelectedAccount(ParcelableAccount account) {
|
||||
@ -644,8 +651,9 @@ public class AccountsDashboardFragment extends BaseSupportListFragment implement
|
||||
final ParcelableAccount account = mSelectedAccount;
|
||||
if (account != null && option.id == MENU_COMPOSE) {
|
||||
final Context context = getContext();
|
||||
return context.getString(R.string.tweet_from_name,
|
||||
UserColorNameUtils.getDisplayName(context, -1, account.name, account.screen_name));
|
||||
final String displayName = mUserColorNameManager.getDisplayName(-1, account.name,
|
||||
account.screen_name, mNameFirst, false);
|
||||
return context.getString(R.string.tweet_from_name, displayName);
|
||||
}
|
||||
return super.getTitle(position, option);
|
||||
}
|
||||
|
@ -29,19 +29,22 @@ import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.DialogInterface.OnMultiChoiceClickListener;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import com.twitter.Extractor;
|
||||
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.model.ParcelableUserMention;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Filters;
|
||||
import org.mariotaku.twidere.util.ContentValuesCreator;
|
||||
import org.mariotaku.twidere.util.HtmlEscapeHelper;
|
||||
import org.mariotaku.twidere.util.ParseUtils;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@ -167,12 +170,20 @@ public class AddStatusFilterDialogFragment extends BaseSupportDialogFragment imp
|
||||
}
|
||||
|
||||
private String getName(final Object value) {
|
||||
final FragmentActivity activity = getActivity();
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(activity);
|
||||
final SharedPreferencesWrapper prefs = SharedPreferencesWrapper.getInstance(activity,
|
||||
SharedPreferencesWrapper.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE,
|
||||
SharedPreferenceConstants.class);
|
||||
final boolean nameFirst = prefs.getBoolean(KEY_NAME_FIRST);
|
||||
if (value instanceof ParcelableUserMention) {
|
||||
final ParcelableUserMention mention = (ParcelableUserMention) value;
|
||||
return UserColorNameUtils.getDisplayName(getActivity(), mention.id, mention.name, mention.screen_name);
|
||||
return manager.getDisplayName(mention.id, mention.name, mention.screen_name, nameFirst,
|
||||
true);
|
||||
} else if (value instanceof ParcelableStatus) {
|
||||
final ParcelableStatus status = (ParcelableStatus) value;
|
||||
return UserColorNameUtils.getDisplayName(getActivity(), status.user_id, status.user_name, status.user_screen_name);
|
||||
return manager.getDisplayName(status.user_id, status.user_name, status.user_screen_name,
|
||||
nameFirst, true);
|
||||
} else
|
||||
return ParseUtils.parseString(value);
|
||||
}
|
||||
|
@ -25,60 +25,69 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
|
||||
public class CreateUserBlockDialogFragment extends BaseSupportDialogFragment implements DialogInterface.OnClickListener {
|
||||
|
||||
public static final String FRAGMENT_TAG = "create_user_block";
|
||||
public static final String FRAGMENT_TAG = "create_user_block";
|
||||
|
||||
@Override
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
final ParcelableUser user = getUser();
|
||||
final AsyncTwitterWrapper twitter = getTwitterWrapper();
|
||||
if (user == null || twitter == null) return;
|
||||
twitter.createBlockAsync(user.account_id, user.id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
|
||||
final ParcelableUser user = getUser();
|
||||
if (user != null) {
|
||||
final String display_name = UserColorNameUtils.getDisplayName(wrapped, user.id, user.name, user.screen_name);
|
||||
builder.setTitle(getString(R.string.block_user, display_name));
|
||||
builder.setMessage(getString(R.string.block_user_confirm_message, display_name));
|
||||
}
|
||||
builder.setPositiveButton(android.R.string.ok, this);
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
return builder.create();
|
||||
}
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
final ParcelableUser user = getUser();
|
||||
final AsyncTwitterWrapper twitter = getTwitterWrapper();
|
||||
if (user == null || twitter == null) return;
|
||||
twitter.createBlockAsync(user.account_id, user.id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private ParcelableUser getUser() {
|
||||
final Bundle args = getArguments();
|
||||
if (!args.containsKey(EXTRA_USER)) return null;
|
||||
return args.getParcelable(EXTRA_USER);
|
||||
}
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final FragmentActivity activity = getActivity();
|
||||
final Context wrapped = ThemeUtils.getDialogThemedContext(activity);
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
|
||||
final ParcelableUser user = getUser();
|
||||
if (user != null) {
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(activity);
|
||||
final SharedPreferencesWrapper prefs = SharedPreferencesWrapper.getInstance(activity,
|
||||
SharedPreferencesWrapper.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE,
|
||||
SharedPreferenceConstants.class);
|
||||
final boolean nameFirst = prefs.getBoolean(KEY_NAME_FIRST);
|
||||
final String displayName = manager.getDisplayName(user, nameFirst, false);
|
||||
builder.setTitle(getString(R.string.block_user, displayName));
|
||||
builder.setMessage(getString(R.string.block_user_confirm_message, displayName));
|
||||
}
|
||||
builder.setPositiveButton(android.R.string.ok, this);
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
public static CreateUserBlockDialogFragment show(final FragmentManager fm, final ParcelableUser user) {
|
||||
final Bundle args = new Bundle();
|
||||
args.putParcelable(EXTRA_USER, user);
|
||||
final CreateUserBlockDialogFragment f = new CreateUserBlockDialogFragment();
|
||||
f.setArguments(args);
|
||||
f.show(fm, FRAGMENT_TAG);
|
||||
return f;
|
||||
}
|
||||
private ParcelableUser getUser() {
|
||||
final Bundle args = getArguments();
|
||||
if (!args.containsKey(EXTRA_USER)) return null;
|
||||
return args.getParcelable(EXTRA_USER);
|
||||
}
|
||||
|
||||
public static CreateUserBlockDialogFragment show(final FragmentManager fm, final ParcelableUser user) {
|
||||
final Bundle args = new Bundle();
|
||||
args.putParcelable(EXTRA_USER, user);
|
||||
final CreateUserBlockDialogFragment f = new CreateUserBlockDialogFragment();
|
||||
f.setArguments(args);
|
||||
f.show(fm, FRAGMENT_TAG);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
@ -25,13 +25,16 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
|
||||
public class CreateUserMuteDialogFragment extends BaseSupportDialogFragment implements DialogInterface.OnClickListener {
|
||||
|
||||
@ -54,11 +57,17 @@ public class CreateUserMuteDialogFragment extends BaseSupportDialogFragment impl
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
|
||||
final FragmentActivity activity = getActivity();
|
||||
final Context wrapped = ThemeUtils.getDialogThemedContext(activity);
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
|
||||
final ParcelableUser user = getUser();
|
||||
if (user != null) {
|
||||
final String displayName = UserColorNameUtils.getDisplayName(wrapped, user.id, user.name, user.screen_name);
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(activity);
|
||||
final SharedPreferencesWrapper prefs = SharedPreferencesWrapper.getInstance(activity,
|
||||
SharedPreferencesWrapper.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE,
|
||||
SharedPreferenceConstants.class);
|
||||
final boolean nameFirst = prefs.getBoolean(KEY_NAME_FIRST);
|
||||
final String displayName = manager.getDisplayName(user, nameFirst, false);
|
||||
builder.setTitle(getString(R.string.mute_user, displayName));
|
||||
builder.setMessage(getString(R.string.mute_user_confirm_message, displayName));
|
||||
}
|
||||
|
@ -27,86 +27,95 @@ import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.ParcelableUserList;
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
|
||||
public class DeleteUserListMembersDialogFragment extends BaseSupportDialogFragment implements
|
||||
DialogInterface.OnClickListener {
|
||||
DialogInterface.OnClickListener {
|
||||
|
||||
public static final String FRAGMENT_TAG = "destroy_user_list_member";
|
||||
public static final String FRAGMENT_TAG = "destroy_user_list_member";
|
||||
|
||||
@Override
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
final ParcelableUser[] users = getUsers();
|
||||
final ParcelableUserList userList = getUserList();
|
||||
final AsyncTwitterWrapper twitter = getTwitterWrapper();
|
||||
if (users == null || userList == null || twitter == null) return;
|
||||
twitter.deleteUserListMembersAsync(userList.account_id, userList.id, users);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
|
||||
final ParcelableUser[] users = getUsers();
|
||||
final ParcelableUserList userList = getUserList();
|
||||
if (users == null || userList == null) throw new NullPointerException();
|
||||
if (users.length == 1) {
|
||||
final ParcelableUser user = users[0];
|
||||
final String displayName = UserColorNameUtils.getDisplayName(wrapped, user.id, user.name, user.screen_name);
|
||||
builder.setTitle(getString(R.string.delete_user, displayName));
|
||||
builder.setMessage(getString(R.string.delete_user_from_list_confirm, displayName, userList.name));
|
||||
} else {
|
||||
builder.setTitle(R.string.delete_users);
|
||||
final Resources res = getResources();
|
||||
final String message = res.getQuantityString(R.plurals.delete_N_users_from_list_confirm, users.length,
|
||||
users.length, userList.name);
|
||||
builder.setMessage(message);
|
||||
}
|
||||
builder.setPositiveButton(android.R.string.ok, this);
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
return builder.create();
|
||||
}
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
final ParcelableUser[] users = getUsers();
|
||||
final ParcelableUserList userList = getUserList();
|
||||
final AsyncTwitterWrapper twitter = getTwitterWrapper();
|
||||
if (users == null || userList == null || twitter == null) return;
|
||||
twitter.deleteUserListMembersAsync(userList.account_id, userList.id, users);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private ParcelableUserList getUserList() {
|
||||
final Bundle args = getArguments();
|
||||
if (!args.containsKey(EXTRA_USER_LIST)) return null;
|
||||
return args.getParcelable(EXTRA_USER_LIST);
|
||||
}
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final FragmentActivity activity = getActivity();
|
||||
final Context wrapped = ThemeUtils.getDialogThemedContext(activity);
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
|
||||
final ParcelableUser[] users = getUsers();
|
||||
final ParcelableUserList userList = getUserList();
|
||||
if (users == null || userList == null) throw new NullPointerException();
|
||||
if (users.length == 1) {
|
||||
final ParcelableUser user = users[0];
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(activity);
|
||||
final SharedPreferencesWrapper prefs = SharedPreferencesWrapper.getInstance(activity,
|
||||
SharedPreferencesWrapper.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE,
|
||||
SharedPreferenceConstants.class);
|
||||
final boolean nameFirst = prefs.getBoolean(KEY_NAME_FIRST);
|
||||
final String displayName = manager.getDisplayName(user, nameFirst, false);
|
||||
builder.setTitle(getString(R.string.delete_user, displayName));
|
||||
builder.setMessage(getString(R.string.delete_user_from_list_confirm, displayName, userList.name));
|
||||
} else {
|
||||
builder.setTitle(R.string.delete_users);
|
||||
final Resources res = getResources();
|
||||
final String message = res.getQuantityString(R.plurals.delete_N_users_from_list_confirm, users.length,
|
||||
users.length, userList.name);
|
||||
builder.setMessage(message);
|
||||
}
|
||||
builder.setPositiveButton(android.R.string.ok, this);
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
private ParcelableUser[] getUsers() {
|
||||
final Bundle args = getArguments();
|
||||
if (!args.containsKey(EXTRA_USERS)) return null;
|
||||
final Parcelable[] array = args.getParcelableArray(EXTRA_USERS);
|
||||
if (array == null) return null;
|
||||
final ParcelableUser[] users = new ParcelableUser[array.length];
|
||||
for (int i = 0, j = users.length; i < j; i++) {
|
||||
users[i] = (ParcelableUser) array[i];
|
||||
}
|
||||
return users;
|
||||
}
|
||||
private ParcelableUserList getUserList() {
|
||||
final Bundle args = getArguments();
|
||||
if (!args.containsKey(EXTRA_USER_LIST)) return null;
|
||||
return args.getParcelable(EXTRA_USER_LIST);
|
||||
}
|
||||
|
||||
public static DeleteUserListMembersDialogFragment show(final FragmentManager fm, final ParcelableUserList userList,
|
||||
final ParcelableUser... users) {
|
||||
final Bundle args = new Bundle();
|
||||
args.putParcelable(EXTRA_USER_LIST, userList);
|
||||
args.putParcelableArray(EXTRA_USERS, users);
|
||||
final DeleteUserListMembersDialogFragment f = new DeleteUserListMembersDialogFragment();
|
||||
f.setArguments(args);
|
||||
f.show(fm, FRAGMENT_TAG);
|
||||
return f;
|
||||
}
|
||||
private ParcelableUser[] getUsers() {
|
||||
final Bundle args = getArguments();
|
||||
if (!args.containsKey(EXTRA_USERS)) return null;
|
||||
final Parcelable[] array = args.getParcelableArray(EXTRA_USERS);
|
||||
if (array == null) return null;
|
||||
final ParcelableUser[] users = new ParcelableUser[array.length];
|
||||
for (int i = 0, j = users.length; i < j; i++) {
|
||||
users[i] = (ParcelableUser) array[i];
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
||||
public static DeleteUserListMembersDialogFragment show(final FragmentManager fm, final ParcelableUserList userList,
|
||||
final ParcelableUser... users) {
|
||||
final Bundle args = new Bundle();
|
||||
args.putParcelable(EXTRA_USER_LIST, userList);
|
||||
args.putParcelableArray(EXTRA_USERS, users);
|
||||
final DeleteUserListMembersDialogFragment f = new DeleteUserListMembersDialogFragment();
|
||||
f.setArguments(args);
|
||||
f.show(fm, FRAGMENT_TAG);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
@ -25,13 +25,16 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
|
||||
public class DestroyFriendshipDialogFragment extends BaseSupportDialogFragment implements
|
||||
DialogInterface.OnClickListener {
|
||||
@ -55,13 +58,19 @@ public class DestroyFriendshipDialogFragment extends BaseSupportDialogFragment i
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
|
||||
final FragmentActivity activity = getActivity();
|
||||
final Context wrapped = ThemeUtils.getDialogThemedContext(activity);
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
|
||||
final ParcelableUser user = getUser();
|
||||
if (user != null) {
|
||||
final String display_name = UserColorNameUtils.getDisplayName(getActivity(), user.id, user.name, user.screen_name);
|
||||
builder.setTitle(getString(R.string.unfollow_user, display_name));
|
||||
builder.setMessage(getString(R.string.unfollow_user_confirm_message, display_name));
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(activity);
|
||||
final SharedPreferencesWrapper prefs = SharedPreferencesWrapper.getInstance(activity,
|
||||
SharedPreferencesWrapper.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE,
|
||||
SharedPreferenceConstants.class);
|
||||
final boolean nameFirst = prefs.getBoolean(KEY_NAME_FIRST);
|
||||
final String displayName = manager.getDisplayName(user, nameFirst, true);
|
||||
builder.setTitle(getString(R.string.unfollow_user, displayName));
|
||||
builder.setMessage(getString(R.string.unfollow_user_confirm_message, displayName));
|
||||
}
|
||||
builder.setPositiveButton(android.R.string.ok, this);
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
|
@ -58,6 +58,7 @@ import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.activity.iface.IControlBarActivity;
|
||||
import org.mariotaku.twidere.activity.iface.IControlBarActivity.ControlBarOffsetListener;
|
||||
import org.mariotaku.twidere.activity.support.BaseAppCompatActivity;
|
||||
import org.mariotaku.twidere.activity.support.HomeActivity;
|
||||
import org.mariotaku.twidere.adapter.MessageEntriesAdapter;
|
||||
import org.mariotaku.twidere.adapter.MessageEntriesAdapter.DirectMessageEntry;
|
||||
import org.mariotaku.twidere.adapter.MessageEntriesAdapter.MessageEntriesAdapterListener;
|
||||
@ -85,29 +86,35 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.mariotaku.twidere.util.Utils.getActivatedAccountIds;
|
||||
import static org.mariotaku.twidere.util.Utils.openMessageConversation;
|
||||
|
||||
public class DirectMessagesFragment extends BaseSupportFragment implements LoaderCallbacks<Cursor>,
|
||||
RefreshScrollTopInterface, OnRefreshListener, MessageEntriesAdapterListener,
|
||||
ControlBarOffsetListener, ContentListSupport, KeyboardShortcutCallback {
|
||||
|
||||
// Listeners
|
||||
private final SupportFragmentReloadCursorObserver mReloadContentObserver = new SupportFragmentReloadCursorObserver(
|
||||
this, 0, this);
|
||||
private final LongSparseArray<Set<Long>> mUnreadCountsToRemove = new LongSparseArray<>();
|
||||
private final Set<Integer> mReadPositions = Collections.synchronizedSet(new HashSet<Integer>());
|
||||
|
||||
// Utility classes
|
||||
private MultiSelectManager mMultiSelectManager;
|
||||
private SharedPreferences mPreferences;
|
||||
private RecyclerView mRecyclerView;
|
||||
private MessageEntriesAdapter mAdapter;
|
||||
private int mFirstVisibleItem;
|
||||
private RemoveUnreadCountsTask mRemoveUnreadCountsTask;
|
||||
private SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
private View mProgressContainer;
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
private RecyclerViewNavigationHelper mRecyclerViewNavigationHelper;
|
||||
|
||||
// Views
|
||||
private RecyclerView mRecyclerView;
|
||||
private MessageEntriesAdapter mAdapter;
|
||||
private SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
private View mProgressContainer;
|
||||
|
||||
// Data fields
|
||||
private final LongSparseArray<Set<Long>> mUnreadCountsToRemove = new LongSparseArray<>();
|
||||
private final Set<Integer> mReadPositions = Collections.synchronizedSet(new HashSet<Integer>());
|
||||
private Rect mSystemWindowsInsets = new Rect();
|
||||
private int mControlBarOffsetPixels;
|
||||
private int mFirstVisibleItem;
|
||||
|
||||
@Override
|
||||
public MessageEntriesAdapter getAdapter() {
|
||||
@ -142,12 +149,6 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
|
||||
return mUnreadCountsToRemove;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleKeyboardShortcutSingle(@NonNull final KeyboardShortcutsHandler handler,
|
||||
final int keyCode, @NonNull final KeyEvent event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleKeyboardShortcutRepeat(@NonNull final KeyboardShortcutsHandler handler,
|
||||
final int keyCode, final int repeatCount,
|
||||
@ -156,82 +157,9 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
if (activity instanceof IControlBarActivity) {
|
||||
((IControlBarActivity) activity).registerControlBarOffsetListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_recycler_view, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(final Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
final View view = getView();
|
||||
if (view == null) throw new AssertionError();
|
||||
final TwidereApplication application = TwidereApplication.getInstance(getActivity());
|
||||
mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
final Context viewContext = view.getContext();
|
||||
mMultiSelectManager = getMultiSelectManager();
|
||||
mAdapter = new MessageEntriesAdapter(viewContext);
|
||||
mAdapter.setListener(this);
|
||||
mLayoutManager = new FixedLinearLayoutManager(viewContext);
|
||||
mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||
mSwipeRefreshLayout.setColorSchemeColors(ThemeUtils.getUserAccentColor(viewContext));
|
||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
mRecyclerViewNavigationHelper = new RecyclerViewNavigationHelper(mRecyclerView, mLayoutManager, mAdapter);
|
||||
|
||||
final ContentListScrollListener scrollListener = new ContentListScrollListener(this);
|
||||
scrollListener.setTouchSlop(ViewConfiguration.get(viewContext).getScaledTouchSlop());
|
||||
// TODO remove scroll listener
|
||||
mRecyclerView.addOnScrollListener(scrollListener);
|
||||
|
||||
final DividerItemDecoration itemDecoration = new DividerItemDecoration(viewContext, mLayoutManager.getOrientation());
|
||||
final Resources res = viewContext.getResources();
|
||||
final int decorPaddingLeft = res.getDimensionPixelSize(R.dimen.element_spacing_normal) * 3
|
||||
+ res.getDimensionPixelSize(R.dimen.icon_size_status_profile_image);
|
||||
itemDecoration.setPadding(decorPaddingLeft, 0, 0, 0);
|
||||
itemDecoration.setDecorationEndOffset(1);
|
||||
mRecyclerView.addItemDecoration(itemDecoration);
|
||||
getLoaderManager().initLoader(0, null, this);
|
||||
setListShown(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
final ContentResolver resolver = getContentResolver();
|
||||
resolver.registerContentObserver(Accounts.CONTENT_URI, true, mReloadContentObserver);
|
||||
final Bus bus = TwidereApplication.getInstance(getActivity()).getMessageBus();
|
||||
bus.register(this);
|
||||
mAdapter.updateReadState();
|
||||
updateRefreshState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
final Bus bus = TwidereApplication.getInstance(getActivity()).getMessageBus();
|
||||
bus.unregister(this);
|
||||
final ContentResolver resolver = getContentResolver();
|
||||
resolver.unregisterContentObserver(mReloadContentObserver);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case MENU_COMPOSE: {
|
||||
openMessageConversation(getActivity(), -1, -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
public boolean handleKeyboardShortcutSingle(@NonNull final KeyboardShortcutsHandler handler,
|
||||
final int keyCode, @NonNull final KeyEvent event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -242,20 +170,6 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
|
||||
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
final FragmentActivity activity = getActivity();
|
||||
if (activity instanceof IControlBarActivity) {
|
||||
((IControlBarActivity) activity).unregisterControlBarOffsetListener(this);
|
||||
}
|
||||
super.onDetach();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(final boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fitSystemWindows(Rect insets) {
|
||||
super.fitSystemWindows(insets);
|
||||
@ -273,14 +187,13 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
|
||||
final Uri uri = DirectMessages.ConversationEntries.CONTENT_URI;
|
||||
final long account_id = getAccountId();
|
||||
final long[] account_ids = account_id > 0 ? new long[]{account_id} : getActivatedAccountIds(getActivity());
|
||||
final boolean no_account_selected = account_ids.length == 0;
|
||||
final long[] accountIds = getAccountIds();
|
||||
final boolean no_account_selected = accountIds.length == 0;
|
||||
// setEmptyText(no_account_selected ? getString(R.string.no_account_selected) : null);
|
||||
// if (!no_account_selected) {
|
||||
// getListView().setEmptyView(null);
|
||||
// }
|
||||
final Expression account_where = Expression.in(new Column(Statuses.ACCOUNT_ID), new RawItemArray(account_ids));
|
||||
final Expression account_where = Expression.in(new Column(Statuses.ACCOUNT_ID), new RawItemArray(accountIds));
|
||||
return new CursorLoader(getActivity(), uri, null, account_where.getSQL(), null, null);
|
||||
}
|
||||
|
||||
@ -360,11 +273,116 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(final boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
if (activity instanceof IControlBarActivity) {
|
||||
((IControlBarActivity) activity).registerControlBarOffsetListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_recycler_view, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(final Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
final View view = getView();
|
||||
if (view == null) throw new AssertionError();
|
||||
final TwidereApplication application = TwidereApplication.getInstance(getActivity());
|
||||
mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
final Context viewContext = view.getContext();
|
||||
mMultiSelectManager = getMultiSelectManager();
|
||||
mAdapter = new MessageEntriesAdapter(viewContext);
|
||||
mAdapter.setListener(this);
|
||||
mLayoutManager = new FixedLinearLayoutManager(viewContext);
|
||||
mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||
mSwipeRefreshLayout.setColorSchemeColors(ThemeUtils.getUserAccentColor(viewContext));
|
||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
mRecyclerViewNavigationHelper = new RecyclerViewNavigationHelper(mRecyclerView, mLayoutManager, mAdapter);
|
||||
|
||||
final ContentListScrollListener scrollListener = new ContentListScrollListener(this);
|
||||
scrollListener.setTouchSlop(ViewConfiguration.get(viewContext).getScaledTouchSlop());
|
||||
// TODO remove scroll listener
|
||||
mRecyclerView.addOnScrollListener(scrollListener);
|
||||
|
||||
final DividerItemDecoration itemDecoration = new DividerItemDecoration(viewContext, mLayoutManager.getOrientation());
|
||||
final Resources res = viewContext.getResources();
|
||||
final int decorPaddingLeft = res.getDimensionPixelSize(R.dimen.element_spacing_normal) * 3
|
||||
+ res.getDimensionPixelSize(R.dimen.icon_size_status_profile_image);
|
||||
itemDecoration.setPadding(decorPaddingLeft, 0, 0, 0);
|
||||
itemDecoration.setDecorationEndOffset(1);
|
||||
mRecyclerView.addItemDecoration(itemDecoration);
|
||||
getLoaderManager().initLoader(0, null, this);
|
||||
setListShown(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
final ContentResolver resolver = getContentResolver();
|
||||
resolver.registerContentObserver(Accounts.CONTENT_URI, true, mReloadContentObserver);
|
||||
final Bus bus = TwidereApplication.getInstance(getActivity()).getMessageBus();
|
||||
bus.register(this);
|
||||
mAdapter.updateReadState();
|
||||
updateRefreshState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
final Bus bus = TwidereApplication.getInstance(getActivity()).getMessageBus();
|
||||
bus.unregister(this);
|
||||
final ContentResolver resolver = getContentResolver();
|
||||
resolver.unregisterContentObserver(mReloadContentObserver);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
final FragmentActivity activity = getActivity();
|
||||
if (activity instanceof IControlBarActivity) {
|
||||
((IControlBarActivity) activity).unregisterControlBarOffsetListener(this);
|
||||
}
|
||||
super.onDetach();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case MENU_COMPOSE: {
|
||||
openMessageConversation(getActivity(), -1, -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
protected long getAccountId() {
|
||||
final Bundle args = getArguments();
|
||||
return args != null ? args.getLong(EXTRA_ACCOUNT_ID, -1) : -1;
|
||||
}
|
||||
|
||||
protected long[] getAccountIds() {
|
||||
final Bundle args = getArguments();
|
||||
if (args != null && args.getLong(EXTRA_ACCOUNT_ID) > 0) {
|
||||
return new long[]{args.getLong(EXTRA_ACCOUNT_ID)};
|
||||
}
|
||||
final FragmentActivity activity = getActivity();
|
||||
if (activity instanceof HomeActivity) {
|
||||
return ((HomeActivity) activity).getActivatedAccountIds();
|
||||
}
|
||||
return Utils.getActivatedAccountIds(getActivity());
|
||||
}
|
||||
|
||||
protected void updateRefreshState() {
|
||||
final AsyncTwitterWrapper twitter = getTwitterWrapper();
|
||||
setRefreshing(twitter != null && (twitter.isReceivedDirectMessagesRefreshing() || twitter.isSentDirectMessagesRefreshing()));
|
||||
@ -388,7 +406,6 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
private void loadMoreMessages() {
|
||||
if (isRefreshing()) return;
|
||||
mAdapter.setLoadMoreIndicatorVisible(true);
|
||||
|
@ -58,12 +58,10 @@ public class HomeTimelineFragment extends CursorStatusesFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatuses(long[] accountIds, long[] maxIds, long[] sinceIds) {
|
||||
public boolean getStatuses(long[] accountIds, long[] maxIds, long[] sinceIds) {
|
||||
final AsyncTwitterWrapper twitter = getTwitterWrapper();
|
||||
if (twitter == null) return -1;
|
||||
if (maxIds == null) {
|
||||
return twitter.refreshAll(accountIds);
|
||||
}
|
||||
if (twitter == null) return false;
|
||||
if (maxIds == null) return twitter.refreshAll(accountIds);
|
||||
return twitter.getHomeTimelineAsync(accountIds, maxIds, sinceIds);
|
||||
}
|
||||
|
||||
|
@ -69,9 +69,9 @@ public class MentionsTimelineFragment extends CursorStatusesFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatuses(long[] accountIds, long[] maxIds, long[] sinceIds) {
|
||||
public boolean getStatuses(long[] accountIds, long[] maxIds, long[] sinceIds) {
|
||||
final AsyncTwitterWrapper twitter = getTwitterWrapper();
|
||||
if (twitter == null) return -1;
|
||||
if (twitter == null) return false;
|
||||
return twitter.getMentionsTimelineAsync(accountIds, maxIds, sinceIds);
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,7 @@ import org.mariotaku.twidere.adapter.MessageConversationAdapter;
|
||||
import org.mariotaku.twidere.adapter.SimpleParcelableUsersAdapter;
|
||||
import org.mariotaku.twidere.adapter.iface.IBaseCardAdapter.MenuButtonClickListener;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
|
||||
import org.mariotaku.twidere.loader.support.UserSearchLoader;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.ParcelableDirectMessage;
|
||||
@ -101,8 +102,9 @@ import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallb
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.ParseUtils;
|
||||
import org.mariotaku.twidere.util.ReadStateManager;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.TwidereValidator;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.message.TaskStateChangedEvent;
|
||||
import org.mariotaku.twidere.view.StatusComposeEditText;
|
||||
@ -158,10 +160,11 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
||||
// Utility classes
|
||||
private TwidereValidator mValidator;
|
||||
private AsyncTwitterWrapper mTwitterWrapper;
|
||||
private SharedPreferences mPreferences;
|
||||
private SharedPreferencesWrapper mPreferences;
|
||||
private SharedPreferences mMessageDrafts;
|
||||
private ReadStateManager mReadStateManager;
|
||||
private MediaLoaderWrapper mImageLoader;
|
||||
private UserColorNameManager mUserColorNameManager;
|
||||
|
||||
// Views
|
||||
private RecyclerView mMessagesListView;
|
||||
@ -225,7 +228,9 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
final BaseAppCompatActivity activity = (BaseAppCompatActivity) getActivity();
|
||||
mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
mPreferences = SharedPreferencesWrapper.getInstance(activity, SHARED_PREFERENCES_NAME,
|
||||
Context.MODE_PRIVATE, SharedPreferenceConstants.class);
|
||||
mUserColorNameManager = UserColorNameManager.getInstance(activity);
|
||||
mMessageDrafts = getSharedPreferences(MESSAGE_DRAFTS_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
mImageLoader = TwidereApplication.getInstance(activity).getMediaLoaderWrapper();
|
||||
mReadStateManager = getReadStateManager();
|
||||
@ -763,7 +768,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
||||
}
|
||||
final FragmentActivity activity = getActivity();
|
||||
if (mRecipient != null) {
|
||||
activity.setTitle(UserColorNameUtils.getDisplayName(activity, mRecipient));
|
||||
activity.setTitle(mUserColorNameManager.getDisplayName(mRecipient, mPreferences.getBoolean(KEY_NAME_FIRST), true));
|
||||
} else {
|
||||
activity.setTitle(R.string.direct_messages);
|
||||
}
|
||||
@ -833,7 +838,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
||||
final Expression selection;
|
||||
final String[] selectionArgs;
|
||||
if (queryEscaped != null) {
|
||||
final SharedPreferences nicknamePrefs = context.getSharedPreferences(USER_NICKNAME_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
final UserColorNameManager nicknamePrefs = UserColorNameManager.getInstance(context);
|
||||
final long[] nicknameIds = Utils.getMatchedNicknameIds(query, nicknamePrefs);
|
||||
selection = Expression.or(Expression.likeRaw(new Column(CachedUsers.SCREEN_NAME), "?||'%'", "^"),
|
||||
Expression.likeRaw(new Column(CachedUsers.NAME), "?||'%'", "^"),
|
||||
|
@ -65,7 +65,7 @@ public abstract class ParcelableStatusesFragment extends AbsStatusesFragment<Lis
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatuses(long[] accountIds, final long[] maxIds, final long[] sinceIds) {
|
||||
public boolean getStatuses(long[] accountIds, final long[] maxIds, final long[] sinceIds) {
|
||||
final Bundle args = new Bundle(getArguments());
|
||||
if (maxIds != null) {
|
||||
args.putLong(EXTRA_MAX_ID, maxIds[0]);
|
||||
@ -75,7 +75,7 @@ public abstract class ParcelableStatusesFragment extends AbsStatusesFragment<Lis
|
||||
}
|
||||
args.putBoolean(EXTRA_FROM_USER, true);
|
||||
getLoaderManager().restartLoader(0, args, this);
|
||||
return -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,60 +25,69 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
|
||||
public class ReportSpamDialogFragment extends BaseSupportDialogFragment implements DialogInterface.OnClickListener {
|
||||
|
||||
public static final String FRAGMENT_TAG = "create_user_block";
|
||||
public static final String FRAGMENT_TAG = "create_user_block";
|
||||
|
||||
@Override
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
final ParcelableUser user = getUser();
|
||||
final AsyncTwitterWrapper twitter = getTwitterWrapper();
|
||||
if (user == null || twitter == null) return;
|
||||
twitter.reportSpamAsync(user.account_id, user.id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
|
||||
final ParcelableUser user = getUser();
|
||||
if (user != null) {
|
||||
final String display_name = UserColorNameUtils.getDisplayName(getActivity(), user.id, user.name, user.screen_name);
|
||||
builder.setTitle(getString(R.string.report_user, display_name));
|
||||
builder.setMessage(getString(R.string.report_user_confirm_message, display_name));
|
||||
}
|
||||
builder.setPositiveButton(android.R.string.ok, this);
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
return builder.create();
|
||||
}
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
final ParcelableUser user = getUser();
|
||||
final AsyncTwitterWrapper twitter = getTwitterWrapper();
|
||||
if (user == null || twitter == null) return;
|
||||
twitter.reportSpamAsync(user.account_id, user.id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private ParcelableUser getUser() {
|
||||
final Bundle args = getArguments();
|
||||
if (!args.containsKey(EXTRA_USER)) return null;
|
||||
return args.getParcelable(EXTRA_USER);
|
||||
}
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final FragmentActivity activity = getActivity();
|
||||
final Context wrapped = ThemeUtils.getDialogThemedContext(activity);
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
|
||||
final ParcelableUser user = getUser();
|
||||
if (user != null) {
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(activity);
|
||||
final SharedPreferencesWrapper prefs = SharedPreferencesWrapper.getInstance(activity,
|
||||
SharedPreferencesWrapper.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE,
|
||||
SharedPreferenceConstants.class);
|
||||
final boolean nameFirst = prefs.getBoolean(KEY_NAME_FIRST);
|
||||
final String displayName = manager.getDisplayName(user, nameFirst, false);
|
||||
builder.setTitle(getString(R.string.report_user, displayName));
|
||||
builder.setMessage(getString(R.string.report_user_confirm_message, displayName));
|
||||
}
|
||||
builder.setPositiveButton(android.R.string.ok, this);
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
public static ReportSpamDialogFragment show(final FragmentManager fm, final ParcelableUser user) {
|
||||
final Bundle args = new Bundle();
|
||||
args.putParcelable(EXTRA_USER, user);
|
||||
final ReportSpamDialogFragment f = new ReportSpamDialogFragment();
|
||||
f.setArguments(args);
|
||||
f.show(fm, FRAGMENT_TAG);
|
||||
return f;
|
||||
}
|
||||
private ParcelableUser getUser() {
|
||||
final Bundle args = getArguments();
|
||||
if (!args.containsKey(EXTRA_USER)) return null;
|
||||
return args.getParcelable(EXTRA_USER);
|
||||
}
|
||||
|
||||
public static ReportSpamDialogFragment show(final FragmentManager fm, final ParcelableUser user) {
|
||||
final Bundle args = new Bundle();
|
||||
args.putParcelable(EXTRA_USER, user);
|
||||
final ReportSpamDialogFragment f = new ReportSpamDialogFragment();
|
||||
f.setArguments(args);
|
||||
f.show(fm, FRAGMENT_TAG);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
@ -34,71 +34,70 @@ import android.widget.FrameLayout;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.util.ParseUtils;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.clearUserNickname;
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.setUserNickname;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
|
||||
public class SetUserNicknameDialogFragment extends BaseSupportDialogFragment implements OnClickListener {
|
||||
|
||||
private static final String FRAGMENT_TAG_SET_USER_NICKNAME = "set_user_nickname";
|
||||
private EditText mEditText;
|
||||
private static final String FRAGMENT_TAG_SET_USER_NICKNAME = "set_user_nickname";
|
||||
private EditText mEditText;
|
||||
|
||||
@Override
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
final Bundle args = getArguments();
|
||||
final String text = ParseUtils.parseString(mEditText.getText());
|
||||
final long userId = args != null ? args.getLong(EXTRA_USER_ID, -1) : -1;
|
||||
if (userId == -1) return;
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE: {
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
clearUserNickname(getActivity(), userId);
|
||||
} else {
|
||||
setUserNickname(getActivity(), userId, text);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DialogInterface.BUTTON_NEUTRAL: {
|
||||
clearUserNickname(getActivity(), userId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final Bundle args = getArguments();
|
||||
final String nick = args.getString(EXTRA_NAME);
|
||||
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
|
||||
builder.setTitle(R.string.set_nickname);
|
||||
builder.setPositiveButton(android.R.string.ok, this);
|
||||
if (!TextUtils.isEmpty(nick)) {
|
||||
builder.setNeutralButton(R.string.clear, this);
|
||||
}
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
final FrameLayout view = new FrameLayout(wrapped);
|
||||
mEditText = new EditText(wrapped);
|
||||
final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
lp.leftMargin = lp.topMargin = lp.bottomMargin = lp.rightMargin = getResources().getDimensionPixelSize(
|
||||
R.dimen.element_spacing_normal);
|
||||
view.addView(mEditText, lp);
|
||||
builder.setView(view);
|
||||
mEditText.setText(nick);
|
||||
return builder.create();
|
||||
}
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
final Bundle args = getArguments();
|
||||
final String text = ParseUtils.parseString(mEditText.getText());
|
||||
final long userId = args != null ? args.getLong(EXTRA_USER_ID, -1) : -1;
|
||||
if (userId == -1) return;
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(getActivity());
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE: {
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
manager.clearUserNickname(userId);
|
||||
} else {
|
||||
manager.setUserNickname(userId, text);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DialogInterface.BUTTON_NEUTRAL: {
|
||||
manager.clearUserNickname(userId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static SetUserNicknameDialogFragment show(final FragmentManager fm, final long user_id, final String nickname) {
|
||||
final SetUserNicknameDialogFragment f = new SetUserNicknameDialogFragment();
|
||||
final Bundle args = new Bundle();
|
||||
args.putLong(EXTRA_USER_ID, user_id);
|
||||
args.putString(EXTRA_NAME, nickname);
|
||||
f.setArguments(args);
|
||||
f.show(fm, FRAGMENT_TAG_SET_USER_NICKNAME);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final Bundle args = getArguments();
|
||||
final String nick = args.getString(EXTRA_NAME);
|
||||
final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
|
||||
builder.setTitle(R.string.set_nickname);
|
||||
builder.setPositiveButton(android.R.string.ok, this);
|
||||
if (!TextUtils.isEmpty(nick)) {
|
||||
builder.setNeutralButton(R.string.clear, this);
|
||||
}
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
final FrameLayout view = new FrameLayout(wrapped);
|
||||
mEditText = new EditText(wrapped);
|
||||
final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
lp.leftMargin = lp.topMargin = lp.bottomMargin = lp.rightMargin = getResources().getDimensionPixelSize(
|
||||
R.dimen.element_spacing_normal);
|
||||
view.addView(mEditText, lp);
|
||||
builder.setView(view);
|
||||
mEditText.setText(nick);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
public static SetUserNicknameDialogFragment show(final FragmentManager fm, final long user_id, final String nickname) {
|
||||
final SetUserNicknameDialogFragment f = new SetUserNicknameDialogFragment();
|
||||
final Bundle args = new Bundle();
|
||||
args.putLong(EXTRA_USER_ID, user_id);
|
||||
args.putString(EXTRA_NAME, nickname);
|
||||
f.setArguments(args);
|
||||
f.show(fm, FRAGMENT_TAG_SET_USER_NICKNAME);
|
||||
return f;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -86,7 +86,6 @@ import org.mariotaku.twidere.constant.IntentConstants;
|
||||
import org.mariotaku.twidere.loader.support.ParcelableStatusLoader;
|
||||
import org.mariotaku.twidere.loader.support.StatusRepliesLoader;
|
||||
import org.mariotaku.twidere.model.ListResponse;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.ParcelableLocation;
|
||||
import org.mariotaku.twidere.model.ParcelableMedia;
|
||||
@ -111,7 +110,7 @@ import org.mariotaku.twidere.util.StatusLinkClickHandler;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.TwidereLinkify;
|
||||
import org.mariotaku.twidere.util.TwitterCardUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.view.CardMediaContainer;
|
||||
import org.mariotaku.twidere.view.CardMediaContainer.OnMediaClickListener;
|
||||
@ -133,9 +132,6 @@ import edu.tsinghua.spice.Utilies.TypeMappingUtil;
|
||||
import twitter4j.TwitterException;
|
||||
|
||||
import static android.text.TextUtils.isEmpty;
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.clearUserColor;
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.getUserNickname;
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.setUserColor;
|
||||
import static org.mariotaku.twidere.util.Utils.findStatus;
|
||||
import static org.mariotaku.twidere.util.Utils.formatToLongTimeString;
|
||||
import static org.mariotaku.twidere.util.Utils.getLocalizedNumber;
|
||||
@ -218,16 +214,19 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
|
||||
@Override
|
||||
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
|
||||
final FragmentActivity activity = getActivity();
|
||||
if (activity == null) return;
|
||||
switch (requestCode) {
|
||||
case REQUEST_SET_COLOR: {
|
||||
final ParcelableStatus status = mStatusAdapter.getStatus();
|
||||
if (status == null) return;
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(activity);
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (data == null) return;
|
||||
final int color = data.getIntExtra(EXTRA_COLOR, Color.TRANSPARENT);
|
||||
setUserColor(getActivity(), status.user_id, color);
|
||||
manager.setUserColor(status.user_id, color);
|
||||
} else if (resultCode == ColorPickerDialogActivity.RESULT_CLEARED) {
|
||||
clearUserColor(getActivity(), status.user_id);
|
||||
manager.clearUserColor(status.user_id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -237,7 +236,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (data == null || !data.hasExtra(EXTRA_ID)) return;
|
||||
final long accountId = data.getLongExtra(EXTRA_ID, -1);
|
||||
openStatus(getActivity(), accountId, status.id);
|
||||
openStatus(activity, accountId, status.id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -279,8 +278,6 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
mStatusAdapter.setEventListener(this);
|
||||
mRecyclerView.setAdapter(mStatusAdapter);
|
||||
|
||||
final FragmentActivity activity = getActivity();
|
||||
final TwidereApplication application = TwidereApplication.getInstance(activity);
|
||||
mRecyclerViewNavigationHelper = new RecyclerViewNavigationHelper(mRecyclerView, mLayoutManager,
|
||||
mStatusAdapter);
|
||||
|
||||
@ -578,7 +575,9 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
final View firstChild = mLayoutManager.getChildAt(0);
|
||||
final int top = firstChild != null ? firstChild.getTop() : 0;
|
||||
final ParcelableStatus status = data.getData();
|
||||
if (mStatusAdapter.setStatus(status)) {
|
||||
final Bundle dataExtra = data.getExtras();
|
||||
final ParcelableCredentials credentials = dataExtra.getParcelable(EXTRA_ACCOUNT);
|
||||
if (mStatusAdapter.setStatus(credentials, status)) {
|
||||
mLayoutManager.scrollToPositionWithOffset(1, 0);
|
||||
mStatusAdapter.setConversation(null);
|
||||
mStatusAdapter.setReplies(null);
|
||||
@ -624,8 +623,6 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
|
||||
private final StatusAdapter adapter;
|
||||
|
||||
private final CardView cardView;
|
||||
|
||||
private final ActionMenuView menuBar;
|
||||
private final TextView nameView, screenNameView;
|
||||
private final StatusTextView textView;
|
||||
@ -652,14 +649,11 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
private final StatusLinkClickHandler linkClickHandler;
|
||||
private final TwidereLinkify linkify;
|
||||
|
||||
private ParcelableStatus status;
|
||||
|
||||
public DetailStatusViewHolder(StatusAdapter adapter, View itemView) {
|
||||
super(itemView);
|
||||
this.linkClickHandler = new StatusLinkClickHandler(adapter.getContext(), null);
|
||||
this.linkify = new TwidereLinkify(linkClickHandler, false);
|
||||
this.adapter = adapter;
|
||||
cardView = (CardView) itemView.findViewById(R.id.card);
|
||||
menuBar = (ActionMenuView) itemView.findViewById(R.id.menu_bar);
|
||||
nameView = (TextView) itemView.findViewById(R.id.name);
|
||||
screenNameView = (TextView) itemView.findViewById(R.id.screen_name);
|
||||
@ -694,18 +688,17 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
|
||||
public void displayStatus(ParcelableStatus status) {
|
||||
if (status == null) return;
|
||||
this.status = status;
|
||||
final StatusFragment fragment = adapter.getFragment();
|
||||
final Context context = adapter.getContext();
|
||||
final Resources resources = context.getResources();
|
||||
final MediaLoaderWrapper loader = adapter.getMediaLoader();
|
||||
final UserColorNameManager manager = adapter.getUserColorNameManager();
|
||||
final boolean nameFirst = adapter.isNameFirst();
|
||||
|
||||
linkClickHandler.setStatus(status);
|
||||
|
||||
if (status.retweet_id > 0) {
|
||||
final String retweetedBy = UserColorNameUtils.getDisplayName(context, status.retweeted_by_id,
|
||||
status.retweeted_by_name, status.retweeted_by_screen_name, nameFirst);
|
||||
final String retweetedBy = manager.getDisplayName(status.retweeted_by_id,
|
||||
status.retweeted_by_name, status.retweeted_by_screen_name, nameFirst, false);
|
||||
retweetedByView.setText(context.getString(R.string.name_retweeted, retweetedBy));
|
||||
retweetedByContainer.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
@ -719,10 +712,10 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
final long timestamp;
|
||||
final String source;
|
||||
if (status.is_quote) {
|
||||
quotedNameView.setText(getUserNickname(context, status.user_id, status.user_name, true));
|
||||
quotedNameView.setText(manager.getUserNickname(status.user_id, status.user_name, false));
|
||||
quotedScreenNameView.setText("@" + status.user_screen_name);
|
||||
|
||||
nameView.setText(getUserNickname(context, status.quoted_by_user_id, status.quoted_by_user_name, true));
|
||||
nameView.setText(manager.getUserNickname(status.quoted_by_user_id, status.quoted_by_user_name, false));
|
||||
screenNameView.setText("@" + status.quoted_by_user_screen_name);
|
||||
|
||||
final int idx = status.quote_text_unescaped.lastIndexOf(" twitter.com");
|
||||
@ -737,9 +730,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
quoteTextView.setVisibility(View.VISIBLE);
|
||||
quoteIndicator.setVisibility(View.VISIBLE);
|
||||
|
||||
quoteIndicator.setColor(UserColorNameUtils.getUserColor(context, status.user_id));
|
||||
|
||||
profileContainer.drawStart(UserColorNameUtils.getUserColor(context, status.quoted_by_user_id));
|
||||
quoteIndicator.setColor(manager.getUserColor(status.user_id, false));
|
||||
profileContainer.drawStart(manager.getUserColor(status.quoted_by_user_id, false));
|
||||
|
||||
typeIconRes = getUserTypeIconRes(status.quoted_by_user_is_verified, status.quoted_by_user_is_protected);
|
||||
typeDescriptionRes = Utils.getUserTypeDescriptionRes(status.quoted_by_user_is_verified, status.quoted_by_user_is_protected);
|
||||
@ -748,7 +740,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
source = status.quote_source;
|
||||
|
||||
} else {
|
||||
nameView.setText(getUserNickname(context, status.user_id, status.user_name, true));
|
||||
nameView.setText(manager.getUserNickname(status.user_id, status.user_name, false));
|
||||
screenNameView.setText("@" + status.user_screen_name);
|
||||
|
||||
loader.displayProfileImage(profileImageView, status.user_profile_image_url);
|
||||
@ -757,7 +749,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
quoteTextView.setVisibility(View.GONE);
|
||||
quoteIndicator.setVisibility(View.GONE);
|
||||
|
||||
profileContainer.drawStart(UserColorNameUtils.getUserColor(context, status.user_id));
|
||||
profileContainer.drawStart(manager.getUserColor(status.user_id, false));
|
||||
|
||||
typeIconRes = getUserTypeIconRes(status.user_is_verified, status.user_is_protected);
|
||||
typeDescriptionRes = Utils.getUserTypeDescriptionRes(status.user_is_verified, status.user_is_protected);
|
||||
@ -806,6 +798,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
|
||||
retweetsContainer.setVisibility(!status.user_is_protected ? View.VISIBLE : View.GONE);
|
||||
repliesContainer.setVisibility(status.reply_count < 0 ? View.GONE : View.VISIBLE);
|
||||
favoritesContainer.setVisibility(status.favorite_count < 0 ? View.GONE : View.VISIBLE);
|
||||
final Locale locale = context.getResources().getConfiguration().locale;
|
||||
repliesCountView.setText(getLocalizedNumber(locale, status.reply_count));
|
||||
retweetsCountView.setText(getLocalizedNumber(locale, status.retweet_count));
|
||||
@ -932,6 +925,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
mediaPreviewLoad.setOnClickListener(this);
|
||||
profileContainer.setOnClickListener(this);
|
||||
retweetsContainer.setOnClickListener(this);
|
||||
favoritesContainer.setOnClickListener(this);
|
||||
retweetedByContainer.setOnClickListener(this);
|
||||
locationView.setOnClickListener(this);
|
||||
|
||||
@ -1121,11 +1115,13 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
private boolean mLoadMoreSupported;
|
||||
private boolean mLoadMoreIndicatorVisible;
|
||||
|
||||
private boolean mDetailMediaExpanded;
|
||||
|
||||
private ParcelableStatus mStatus;
|
||||
private ParcelableCredentials mStatusAccount;
|
||||
private List<ParcelableStatus> mConversation, mReplies;
|
||||
private boolean mDetailMediaExpanded;
|
||||
private StatusAdapterListener mStatusAdapterListener;
|
||||
private final UserColorNameManager mUserColorNameManager;
|
||||
|
||||
private RecyclerView mRecyclerView;
|
||||
private DetailStatusViewHolder mStatusViewHolder;
|
||||
@ -1140,6 +1136,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
mContext = context;
|
||||
mInflater = LayoutInflater.from(context);
|
||||
mImageLoader = TwidereApplication.getInstance(context).getMediaLoaderWrapper();
|
||||
mUserColorNameManager = TwidereApplication.getInstance(context).getUserColorNameManager();
|
||||
mMediaLoadingHandler = new MediaLoadingHandler(R.id.media_preview_progress);
|
||||
mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(context, ThemeUtils.getThemeBackgroundOption(context), ThemeUtils.getUserThemeBackgroundAlpha(context));
|
||||
mNameFirst = preferences.getBoolean(KEY_NAME_FIRST, true);
|
||||
@ -1286,6 +1283,11 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
return mMediaLoadingHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserColorNameManager getUserColorNameManager() {
|
||||
return mUserColorNameManager;
|
||||
}
|
||||
|
||||
public ParcelableStatus getStatus() {
|
||||
return mStatus;
|
||||
}
|
||||
@ -1537,14 +1539,10 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
updateItemDecoration();
|
||||
}
|
||||
|
||||
public boolean setStatus(ParcelableStatus status) {
|
||||
public boolean setStatus(ParcelableCredentials credentials, ParcelableStatus status) {
|
||||
final ParcelableStatus old = mStatus;
|
||||
mStatus = status;
|
||||
if (status != null) {
|
||||
mStatusAccount = ParcelableAccount.getCredentials(mContext, status.account_id);
|
||||
} else {
|
||||
mStatusAccount = null;
|
||||
}
|
||||
mStatusAccount = credentials;
|
||||
notifyDataSetChanged();
|
||||
updateItemDecoration();
|
||||
return !CompareUtils.objectEquals(old, status);
|
||||
|
@ -94,6 +94,7 @@ import org.mariotaku.twidere.activity.support.UserListSelectorActivity;
|
||||
import org.mariotaku.twidere.activity.support.UserProfileEditorActivity;
|
||||
import org.mariotaku.twidere.adapter.support.SupportTabsAdapter;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
|
||||
import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCallback;
|
||||
import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface;
|
||||
import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback;
|
||||
@ -117,11 +118,12 @@ import org.mariotaku.twidere.util.MathUtils;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.MenuUtils;
|
||||
import org.mariotaku.twidere.util.ParseUtils;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.TwidereColorUtils;
|
||||
import org.mariotaku.twidere.util.TwidereLinkify;
|
||||
import org.mariotaku.twidere.util.TwidereLinkify.OnLinkClickListener;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.ViewUtils;
|
||||
import org.mariotaku.twidere.util.accessor.ActivityAccessor;
|
||||
@ -167,6 +169,10 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||
private static final String TAB_TYPE_MEDIA = "media";
|
||||
private static final String TAB_TYPE_FAVORITES = "favorites";
|
||||
|
||||
private MediaLoaderWrapper mProfileImageLoader;
|
||||
private UserColorNameManager mUserColorNameManager;
|
||||
private SharedPreferencesWrapper mPreferences;
|
||||
|
||||
private ShapedImageView mProfileImageView;
|
||||
private ImageView mProfileTypeView;
|
||||
private ProfileBannerImageView mProfileBannerView;
|
||||
@ -193,7 +199,9 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||
private View mProfileNameBackground;
|
||||
private View mProfileDetailsContainer;
|
||||
|
||||
private MediaLoaderWrapper mProfileImageLoader;
|
||||
|
||||
private ActionBarDrawable mActionBarBackground;
|
||||
private Drawable mActionBarHomeAsUpIndicator;
|
||||
private SupportTabsAdapter mPagerAdapter;
|
||||
|
||||
private ParcelableUser mUser;
|
||||
@ -204,9 +212,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||
private int mCardBackgroundColor;
|
||||
private int mActionBarShadowColor;
|
||||
private int mUserUiColor;
|
||||
|
||||
private ActionBarDrawable mActionBarBackground;
|
||||
private Drawable mActionBarHomeAsUpIndicator;
|
||||
private boolean mNameFirst;
|
||||
|
||||
|
||||
private final LoaderCallbacks<SingleResponse<Relationship>> mFriendshipLoaderCallbacks = new LoaderCallbacks<SingleResponse<Relationship>>() {
|
||||
@ -244,13 +250,13 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||
mFollowButton.setEnabled(!relationship.isSourceBlockedByTarget());
|
||||
if (relationship.isSourceBlockedByTarget()) {
|
||||
mPagesErrorContainer.setVisibility(View.VISIBLE);
|
||||
final String displayName = UserColorNameUtils.getDisplayName(getActivity(), user);
|
||||
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 = UserColorNameUtils.getDisplayName(getActivity(), user);
|
||||
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);
|
||||
@ -484,7 +490,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||
final FragmentActivity activity = getActivity();
|
||||
if (user == null || user.id <= 0 || activity == null) return;
|
||||
final Resources resources = getResources();
|
||||
final Resources res = resources;
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(activity);
|
||||
final LoaderManager lm = getLoaderManager();
|
||||
lm.destroyLoader(LOADER_ID_USER);
|
||||
lm.destroyLoader(LOADER_ID_FRIENDSHIP);
|
||||
@ -493,12 +499,11 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||
mErrorRetryContainer.setVisibility(View.GONE);
|
||||
mProgressContainer.setVisibility(View.GONE);
|
||||
mUser = user;
|
||||
final int userColor = UserColorNameUtils.getUserColor(activity, user.id, true);
|
||||
final int userColor = manager.getUserColor(user.id, true);
|
||||
mProfileImageView.setBorderColor(userColor != 0 ? userColor : Color.WHITE);
|
||||
mProfileNameContainer.drawEnd(Utils.getAccountColor(activity, user.account_id));
|
||||
final String nick = UserColorNameUtils.getUserNickname(activity, user.id, true);
|
||||
mNameView
|
||||
.setText(TextUtils.isEmpty(nick) ? user.name : getString(R.string.name_with_nickname, user.name, nick));
|
||||
final String nick = manager.getUserNickname(user.id, true);
|
||||
mNameView.setText(TextUtils.isEmpty(nick) ? user.name : getString(R.string.name_with_nickname, user.name, nick));
|
||||
final int typeIconRes = Utils.getUserTypeIconRes(user.is_verified, user.is_protected);
|
||||
if (typeIconRes != 0) {
|
||||
mProfileTypeView.setImageResource(typeIconRes);
|
||||
@ -521,7 +526,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||
final String createdAt = Utils.formatToLongTimeString(activity, user.created_at);
|
||||
final float daysSinceCreation = (System.currentTimeMillis() - user.created_at) / 1000 / 60 / 60 / 24;
|
||||
final int dailyTweets = Math.round(user.statuses_count / Math.max(1, daysSinceCreation));
|
||||
mCreatedAtView.setText(res.getQuantityString(R.plurals.created_at_with_N_tweets_per_day, dailyTweets,
|
||||
mCreatedAtView.setText(resources.getQuantityString(R.plurals.created_at_with_N_tweets_per_day, dailyTweets,
|
||||
createdAt, dailyTweets));
|
||||
mListedCount.setText(Utils.getLocalizedNumber(mLocale, user.listed_count));
|
||||
mFollowersCount.setText(Utils.getLocalizedNumber(mLocale, user.followers_count));
|
||||
@ -533,7 +538,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||
} else {
|
||||
setUserUiColor(user.link_color);
|
||||
}
|
||||
final int defWidth = res.getDisplayMetrics().widthPixels;
|
||||
final int defWidth = resources.getDisplayMetrics().widthPixels;
|
||||
final int width = mBannerWidth > 0 ? mBannerWidth : defWidth;
|
||||
mProfileImageLoader.displayProfileBanner(mProfileBannerView, user.profile_banner_url, width);
|
||||
mUuckyFooter.setVisibility(isUucky(user.id, user.screen_name, user) ? View.VISIBLE : View.GONE);
|
||||
@ -541,7 +546,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||
if (relationship == null || relationship.getTargetUserId() != user.id) {
|
||||
getFriendship();
|
||||
}
|
||||
activity.setTitle(UserColorNameUtils.getDisplayName(activity, user, true));
|
||||
activity.setTitle(manager.getDisplayName(user, mNameFirst, true));
|
||||
|
||||
updateTitleAlpha();
|
||||
invalidateOptionsMenu();
|
||||
@ -612,15 +617,16 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||
@Override
|
||||
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
|
||||
final ParcelableUser user = getUser();
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(getActivity());
|
||||
switch (requestCode) {
|
||||
case REQUEST_SET_COLOR: {
|
||||
if (user == null) return;
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (data == null) return;
|
||||
final int color = data.getIntExtra(EXTRA_COLOR, Color.TRANSPARENT);
|
||||
UserColorNameUtils.setUserColor(getActivity(), mUser.id, color);
|
||||
manager.setUserColor(mUser.id, color);
|
||||
} else if (resultCode == ColorPickerDialogActivity.RESULT_CLEARED) {
|
||||
UserColorNameUtils.clearUserColor(getActivity(), mUser.id);
|
||||
manager.clearUserColor(mUser.id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -675,6 +681,9 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||
.registerOnSharedPreferenceChangeListener(this);
|
||||
getSharedPreferences(USER_NICKNAME_PREFERENCES_NAME, Context.MODE_PRIVATE)
|
||||
.registerOnSharedPreferenceChangeListener(this);
|
||||
mUserColorNameManager = UserColorNameManager.getInstance(activity);
|
||||
mPreferences = SharedPreferencesWrapper.getInstance(activity, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE, SharedPreferenceConstants.class);
|
||||
mNameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
|
||||
mLocale = getResources().getConfiguration().locale;
|
||||
mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(activity,
|
||||
ThemeUtils.getThemeBackgroundOption(activity),
|
||||
@ -821,7 +830,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||
final boolean isMyself = user.account_id == user.id;
|
||||
final MenuItem mentionItem = menu.findItem(MENU_MENTION);
|
||||
if (mentionItem != null) {
|
||||
mentionItem.setTitle(getString(R.string.mention_user_name, UserColorNameUtils.getDisplayName(getActivity(), user)));
|
||||
final String displayName = mUserColorNameManager.getDisplayName(user, mNameFirst, true);
|
||||
mentionItem.setTitle(getString(R.string.mention_user_name, displayName));
|
||||
}
|
||||
MenuUtils.setMenuItemAvailability(menu, MENU_MENTION, !isMyself);
|
||||
MenuUtils.setMenuItemAvailability(menu, R.id.incoming_friendships, isMyself);
|
||||
@ -943,18 +953,19 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||
}
|
||||
case MENU_SET_COLOR: {
|
||||
final Intent intent = new Intent(getActivity(), ColorPickerDialogActivity.class);
|
||||
intent.putExtra(EXTRA_COLOR, UserColorNameUtils.getUserColor(getActivity(), user.id, true));
|
||||
intent.putExtra(EXTRA_COLOR, mUserColorNameManager.getUserColor(user.id, true));
|
||||
intent.putExtra(EXTRA_ALPHA_SLIDER, false);
|
||||
intent.putExtra(EXTRA_CLEAR_BUTTON, true);
|
||||
startActivityForResult(intent, REQUEST_SET_COLOR);
|
||||
break;
|
||||
}
|
||||
case MENU_CLEAR_NICKNAME: {
|
||||
UserColorNameUtils.clearUserNickname(getActivity(), user.id);
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(getActivity());
|
||||
manager.clearUserNickname(user.id);
|
||||
break;
|
||||
}
|
||||
case MENU_SET_NICKNAME: {
|
||||
final String nick = UserColorNameUtils.getUserNickname(getActivity(), user.id, true);
|
||||
final String nick = mUserColorNameManager.getUserNickname(user.id, true);
|
||||
SetUserNicknameDialogFragment.show(getFragmentManager(), user.id, nick);
|
||||
break;
|
||||
}
|
||||
|
@ -64,6 +64,8 @@ import org.mariotaku.twidere.activity.iface.IThemedActivity;
|
||||
import org.mariotaku.twidere.activity.support.AccountSelectorActivity;
|
||||
import org.mariotaku.twidere.activity.support.UserListSelectorActivity;
|
||||
import org.mariotaku.twidere.adapter.support.SupportTabsAdapter;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
|
||||
import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCallback;
|
||||
import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
@ -74,9 +76,10 @@ import org.mariotaku.twidere.util.LinkCreator;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.OnLinkClickHandler;
|
||||
import org.mariotaku.twidere.util.ParseUtils;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.TwidereLinkify;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.view.ColorLabelLinearLayout;
|
||||
import org.mariotaku.twidere.view.HeaderDrawerLayout;
|
||||
@ -113,6 +116,9 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
|
||||
private CardView mCardView;
|
||||
|
||||
private SupportTabsAdapter mPagerAdapter;
|
||||
private boolean mUserListLoaderInitialized;
|
||||
private UserColorNameManager mUserColorNameManager;
|
||||
private SharedPreferencesWrapper mPreferences;
|
||||
|
||||
private ParcelableUserList mUserList;
|
||||
private final BroadcastReceiver mStatusReceiver = new BroadcastReceiver() {
|
||||
@ -135,7 +141,6 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
|
||||
}
|
||||
}
|
||||
};
|
||||
private boolean mUserListLoaderInitialized;
|
||||
|
||||
@Override
|
||||
public boolean canScroll(float dy) {
|
||||
@ -197,8 +202,9 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
|
||||
mUserList = userList;
|
||||
mUserListDetails.drawEnd(getAccountColor(getActivity(), userList.account_id));
|
||||
mListNameView.setText(userList.name);
|
||||
final String displayName = UserColorNameUtils.getDisplayName(getActivity(), userList.user_id,
|
||||
userList.user_name, userList.user_screen_name, false);
|
||||
|
||||
final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
|
||||
final String displayName = mUserColorNameManager.getDisplayName(userList, nameFirst, false);
|
||||
mCreatedByView.setText(getString(R.string.created_by, displayName));
|
||||
final String description = userList.description;
|
||||
mDescriptionView.setVisibility(isEmpty(description) ? View.GONE : View.VISIBLE);
|
||||
@ -282,9 +288,16 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
|
||||
@Override
|
||||
public void onActivityCreated(final Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
final FragmentActivity activity = getActivity();
|
||||
final TwidereApplication application = TwidereApplication.getInstance(activity);
|
||||
mTwitterWrapper = application.getTwitterWrapper();
|
||||
mProfileImageLoader = application.getMediaLoaderWrapper();
|
||||
mUserColorNameManager = application.getUserColorNameManager();
|
||||
mPreferences = SharedPreferencesWrapper.getInstance(activity, SHARED_PREFERENCES_NAME,
|
||||
Context.MODE_PRIVATE, SharedPreferenceConstants.class);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
final FragmentActivity activity = getActivity();
|
||||
|
||||
Utils.setNdefPushMessageCallback(activity, new CreateNdefMessageCallback() {
|
||||
|
||||
@ -311,8 +324,6 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
|
||||
|
||||
}
|
||||
|
||||
mTwitterWrapper = getApplication().getTwitterWrapper();
|
||||
mProfileImageLoader = getApplication().getMediaLoaderWrapper();
|
||||
mProfileImageView.setOnClickListener(this);
|
||||
mUserListDetails.setOnClickListener(this);
|
||||
mRetryButton.setOnClickListener(this);
|
||||
|
@ -24,16 +24,18 @@ import android.os.Bundle;
|
||||
import android.support.v4.content.AsyncTaskLoader;
|
||||
|
||||
import org.mariotaku.twidere.constant.IntentConstants;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.model.SingleResponse;
|
||||
|
||||
import twitter4j.TwitterException;
|
||||
|
||||
import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT;
|
||||
import static org.mariotaku.twidere.util.Utils.findStatus;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 14/12/5.
|
||||
*/
|
||||
* Created by mariotaku on 14/12/5.
|
||||
*/
|
||||
public class ParcelableStatusLoader extends AsyncTaskLoader<SingleResponse<ParcelableStatus>> {
|
||||
|
||||
private final boolean mOmitIntentExtra;
|
||||
@ -56,7 +58,12 @@ public class ParcelableStatusLoader extends AsyncTaskLoader<SingleResponse<Parce
|
||||
if (cache != null) return SingleResponse.getInstance(cache);
|
||||
}
|
||||
try {
|
||||
return SingleResponse.getInstance(findStatus(getContext(), mAccountId, mStatusId));
|
||||
final ParcelableStatus status = findStatus(getContext(), mAccountId, mStatusId);
|
||||
final ParcelableAccount.ParcelableCredentials credentials = ParcelableAccount.getCredentials(getContext(), mAccountId);
|
||||
final SingleResponse<ParcelableStatus> response = SingleResponse.getInstance(status);
|
||||
final Bundle extras = response.getExtras();
|
||||
extras.putParcelable(EXTRA_ACCOUNT, credentials);
|
||||
return response;
|
||||
} catch (final TwitterException e) {
|
||||
return SingleResponse.getInstance(e);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
package org.mariotaku.twidere.model;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
public class SingleResponse<Data> {
|
||||
private final Exception exception;
|
||||
@ -48,9 +49,7 @@ public class SingleResponse<Data> {
|
||||
if (exception == null) {
|
||||
if (other.exception != null) return false;
|
||||
} else if (!exception.equals(other.exception)) return false;
|
||||
if (getExtras() == null) {
|
||||
if (other.getExtras() != null) return false;
|
||||
} else if (!getExtras().equals(other.getExtras())) return false;
|
||||
if (!getExtras().equals(other.getExtras())) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -62,6 +61,7 @@ public class SingleResponse<Data> {
|
||||
return exception;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Bundle getExtras() {
|
||||
return extras;
|
||||
}
|
||||
@ -80,7 +80,7 @@ public class SingleResponse<Data> {
|
||||
int result = 1;
|
||||
result = prime * result + (getData() == null ? 0 : getData().hashCode());
|
||||
result = prime * result + (exception == null ? 0 : exception.hashCode());
|
||||
result = prime * result + (getExtras() == null ? 0 : getExtras().hashCode());
|
||||
result = prime * result + (getExtras().hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -27,10 +27,6 @@ import org.mariotaku.twidere.R;
|
||||
|
||||
public class HomeRefreshContentPreference extends MultiSelectListPreference implements Constants {
|
||||
|
||||
public static final boolean DEFAULT_ENABLE_MENTIONS = true;
|
||||
public static final boolean DEFAULT_ENABLE_DIRECT_MESSAGES = true;
|
||||
public static final boolean DEFAULT_ENABLE_TRENDS = true;
|
||||
|
||||
public HomeRefreshContentPreference(final Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
@ -45,7 +41,7 @@ public class HomeRefreshContentPreference extends MultiSelectListPreference impl
|
||||
|
||||
@Override
|
||||
protected boolean[] getDefaults() {
|
||||
return new boolean[] { DEFAULT_ENABLE_MENTIONS, DEFAULT_ENABLE_DIRECT_MESSAGES, DEFAULT_ENABLE_TRENDS };
|
||||
return new boolean[] { true, true, true };
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,7 +93,7 @@ import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.TwidereArrayUtils;
|
||||
import org.mariotaku.twidere.util.TwidereQueryBuilder.CachedUsersQueryBuilder;
|
||||
import org.mariotaku.twidere.util.TwidereQueryBuilder.ConversationQueryBuilder;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.collection.CompactHashSet;
|
||||
import org.mariotaku.twidere.util.message.UnreadCountUpdatedEvent;
|
||||
@ -857,19 +857,20 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
|
||||
statusesCount, statusesCount);
|
||||
final String notificationContent;
|
||||
userCursor.moveToFirst();
|
||||
final String displayName = UserColorNameUtils.getUserNickname(context, userCursor.getLong(idxUserId),
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(context);
|
||||
final String displayName = manager.getUserNickname(userCursor.getLong(idxUserId),
|
||||
mNameFirst ? userCursor.getString(idxUserName) : userCursor.getString(idxUserScreenName));
|
||||
if (usersCount == 1) {
|
||||
notificationContent = context.getString(R.string.from_name, displayName);
|
||||
} else if (usersCount == 2) {
|
||||
userCursor.moveToPosition(1);
|
||||
final String othersName = UserColorNameUtils.getUserNickname(context, userCursor.getLong(idxUserId),
|
||||
final String othersName = manager.getUserNickname(userCursor.getLong(idxUserId),
|
||||
mNameFirst ? userCursor.getString(idxUserName) : userCursor.getString(idxUserScreenName));
|
||||
notificationContent = resources.getQuantityString(R.plurals.from_name_and_N_others,
|
||||
usersCount - 1, othersName, usersCount - 1);
|
||||
} else {
|
||||
userCursor.moveToPosition(1);
|
||||
final String othersName = UserColorNameUtils.getUserNickname(context, userCursor.getLong(idxUserId),
|
||||
final String othersName = manager.getUserNickname(userCursor.getLong(idxUserId),
|
||||
mNameFirst ? userCursor.getString(idxUserName) : userCursor.getString(idxUserScreenName));
|
||||
notificationContent = resources.getString(R.string.from_name_and_N_others, othersName, usersCount - 1);
|
||||
}
|
||||
@ -938,7 +939,8 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
|
||||
statusesCount, statusesCount);
|
||||
final String notificationContent;
|
||||
userCursor.moveToFirst();
|
||||
final String displayName = UserColorNameUtils.getUserNickname(context, userCursor.getLong(idxUserId),
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(context);
|
||||
final String displayName = manager.getUserNickname(userCursor.getLong(idxUserId),
|
||||
mNameFirst ? userCursor.getString(idxUserName) : userCursor.getString(idxUserScreenName));
|
||||
if (usersCount == 1) {
|
||||
notificationContent = context.getString(R.string.notification_mention, displayName);
|
||||
@ -958,7 +960,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
|
||||
statusId = statusCursor.getLong(idxStatusId);
|
||||
}
|
||||
final SpannableStringBuilder sb = new SpannableStringBuilder();
|
||||
sb.append(UserColorNameUtils.getUserNickname(context, statusCursor.getLong(idxUserId),
|
||||
sb.append(manager.getUserNickname(statusCursor.getLong(idxUserId),
|
||||
mNameFirst ? statusCursor.getString(idxStatusUserName) : statusCursor.getString(idxStatusUserScreenName)));
|
||||
sb.setSpan(new StyleSpan(Typeface.BOLD), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
sb.append(' ');
|
||||
@ -1120,7 +1122,8 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
|
||||
messagesCount, messagesCount);
|
||||
final String notificationContent;
|
||||
userCursor.moveToFirst();
|
||||
final String displayName = UserColorNameUtils.getUserNickname(context, userCursor.getLong(idxUserId),
|
||||
final UserColorNameManager manager = UserColorNameManager.getInstance(context);
|
||||
final String displayName = manager.getUserNickname(userCursor.getLong(idxUserId),
|
||||
mNameFirst ? userCursor.getString(idxUserName) : userCursor.getString(idxUserScreenName));
|
||||
if (usersCount == 1) {
|
||||
if (messagesCount == 1) {
|
||||
@ -1144,7 +1147,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
|
||||
}
|
||||
if (i < 5) {
|
||||
final SpannableStringBuilder sb = new SpannableStringBuilder();
|
||||
sb.append(UserColorNameUtils.getUserNickname(context, messageCursor.getLong(idxUserId),
|
||||
sb.append(manager.getUserNickname(messageCursor.getLong(idxUserId),
|
||||
mNameFirst ? messageCursor.getString(idxMessageUserName) : messageCursor.getString(idxMessageUserScreenName)));
|
||||
sb.setSpan(new StyleSpan(Typeface.BOLD), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
sb.append(' ');
|
||||
|
@ -165,7 +165,7 @@ public class RefreshService extends Service implements Constants {
|
||||
return isNetworkAvailable(this) && (isBatteryOkay(this) || !shouldStopAutoRefreshOnBatteryLow(this));
|
||||
}
|
||||
|
||||
private int getHomeTimeline(final long[] accountIds, final long[] maxIds, final long[] sinceIds) {
|
||||
private boolean getHomeTimeline(final long[] accountIds, final long[] maxIds, final long[] sinceIds) {
|
||||
return mTwitterWrapper.getHomeTimelineAsync(accountIds, maxIds, sinceIds);
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ public class RefreshService extends Service implements Constants {
|
||||
return mTwitterWrapper.getLocalTrendsAsync(account_id, woeid);
|
||||
}
|
||||
|
||||
private int getMentions(final long[] accountIds, final long[] maxIds, final long[] sinceIds) {
|
||||
private boolean getMentions(final long[] accountIds, final long[] maxIds, final long[] sinceIds) {
|
||||
return mTwitterWrapper.getMentionsTimelineAsync(accountIds, maxIds, sinceIds);
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,6 @@ import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
@ -42,6 +41,7 @@ import org.mariotaku.querybuilder.RawItemArray;
|
||||
import org.mariotaku.querybuilder.SQLFunctions;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
|
||||
import org.mariotaku.twidere.model.ListResponse;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.ParcelableLocation;
|
||||
@ -52,7 +52,6 @@ import org.mariotaku.twidere.model.ParcelableStatusUpdate;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.ParcelableUserList;
|
||||
import org.mariotaku.twidere.model.SingleResponse;
|
||||
import org.mariotaku.twidere.preference.HomeRefreshContentPreference;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedHashtags;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedTrends;
|
||||
@ -109,7 +108,6 @@ import static org.mariotaku.twidere.util.Utils.getNewestMessageIdsFromDatabase;
|
||||
import static org.mariotaku.twidere.util.Utils.getNewestStatusIdsFromDatabase;
|
||||
import static org.mariotaku.twidere.util.Utils.getStatusCountInDatabase;
|
||||
import static org.mariotaku.twidere.util.Utils.getTwitterInstance;
|
||||
import static org.mariotaku.twidere.util.Utils.getUserName;
|
||||
import static org.mariotaku.twidere.util.Utils.showErrorMessage;
|
||||
import static org.mariotaku.twidere.util.Utils.showInfoMessage;
|
||||
import static org.mariotaku.twidere.util.Utils.showOkMessage;
|
||||
@ -120,11 +118,9 @@ import static org.mariotaku.twidere.util.content.ContentResolverUtils.bulkInsert
|
||||
|
||||
public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
private static AsyncTwitterWrapper sInstance;
|
||||
|
||||
private final Context mContext;
|
||||
private final AsyncTaskManager mAsyncTaskManager;
|
||||
private final SharedPreferences mPreferences;
|
||||
private final SharedPreferencesWrapper mPreferences;
|
||||
private final ContentResolver mResolver;
|
||||
|
||||
private int mGetHomeTimelineTaskId, mGetMentionsTaskId;
|
||||
@ -142,7 +138,8 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
mContext = context;
|
||||
final TwidereApplication app = TwidereApplication.getInstance(context);
|
||||
mAsyncTaskManager = app.getAsyncTaskManager();
|
||||
mPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
mPreferences = SharedPreferencesWrapper.getInstance(context, SHARED_PREFERENCES_NAME,
|
||||
Context.MODE_PRIVATE, SharedPreferenceConstants.class);
|
||||
mResolver = context.getContentResolver();
|
||||
}
|
||||
|
||||
@ -283,15 +280,16 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
return mContext;
|
||||
}
|
||||
|
||||
public int getHomeTimelineAsync(final long[] accountIds, final long[] max_ids, final long[] since_ids) {
|
||||
public boolean getHomeTimelineAsync(final long[] accountIds, final long[] max_ids, final long[] since_ids) {
|
||||
mAsyncTaskManager.cancel(mGetHomeTimelineTaskId);
|
||||
final GetHomeTimelineTask task = new GetHomeTimelineTask(accountIds, max_ids, since_ids);
|
||||
return mGetHomeTimelineTaskId = mAsyncTaskManager.add(task, true);
|
||||
mGetHomeTimelineTaskId = mAsyncTaskManager.add(task, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static AsyncTwitterWrapper getInstance(final Context context) {
|
||||
if (sInstance != null) return sInstance;
|
||||
return sInstance = new AsyncTwitterWrapper(context);
|
||||
final TwidereApplication application = TwidereApplication.getInstance(context);
|
||||
return application.getTwitterWrapper();
|
||||
}
|
||||
|
||||
public int getLocalTrendsAsync(final long accountId, final int woeid) {
|
||||
@ -300,10 +298,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
return mGetLocalTrendsTaskId = mAsyncTaskManager.add(task, true);
|
||||
}
|
||||
|
||||
public int getMentionsTimelineAsync(final long[] accountIds, final long[] max_ids, final long[] since_ids) {
|
||||
public boolean getMentionsTimelineAsync(final long[] accountIds, final long[] max_ids, final long[] since_ids) {
|
||||
mAsyncTaskManager.cancel(mGetMentionsTaskId);
|
||||
final GetMentionsTask task = new GetMentionsTask(accountIds, max_ids, since_ids);
|
||||
return mGetMentionsTaskId = mAsyncTaskManager.add(task, true);
|
||||
mGetMentionsTaskId = mAsyncTaskManager.add(task, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getReceivedDirectMessagesAsync(final long[] accountIds, final long[] max_ids, final long[] since_ids) {
|
||||
@ -336,10 +335,6 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
return mAsyncTaskManager;
|
||||
}
|
||||
|
||||
public boolean hasActivatedTask() {
|
||||
return mAsyncTaskManager.hasRunningTask();
|
||||
}
|
||||
|
||||
public boolean isCreatingFavorite(final long accountId, final long statusId) {
|
||||
return mCreatingFavoriteIds.has(accountId, statusId);
|
||||
}
|
||||
@ -403,31 +398,48 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
return mAsyncTaskManager.hasRunningTasksForTag(TASK_TAG_GET_SENT_DIRECT_MESSAGES);
|
||||
}
|
||||
|
||||
public int refreshAll() {
|
||||
final long[] accountIds = getActivatedAccountIds(mContext);
|
||||
return refreshAll(accountIds);
|
||||
@Deprecated
|
||||
public void refreshAll() {
|
||||
refreshAll(getActivatedAccountIds(mContext));
|
||||
}
|
||||
|
||||
public int refreshAll(final long[] accountIds) {
|
||||
if (mPreferences.getBoolean(KEY_HOME_REFRESH_MENTIONS, HomeRefreshContentPreference.DEFAULT_ENABLE_MENTIONS)) {
|
||||
final long[] sinceIds = getNewestStatusIdsFromDatabase(mContext, Mentions.CONTENT_URI, accountIds);
|
||||
getMentionsTimelineAsync(accountIds, null, sinceIds);
|
||||
}
|
||||
if (mPreferences.getBoolean(KEY_HOME_REFRESH_DIRECT_MESSAGES,
|
||||
HomeRefreshContentPreference.DEFAULT_ENABLE_DIRECT_MESSAGES)) {
|
||||
final long[] sinceIds = getNewestMessageIdsFromDatabase(mContext, DirectMessages.Inbox.CONTENT_URI,
|
||||
accountIds);
|
||||
getReceivedDirectMessagesAsync(accountIds, null, sinceIds);
|
||||
getSentDirectMessagesAsync(accountIds, null, null);
|
||||
}
|
||||
if (mPreferences.getBoolean(KEY_HOME_REFRESH_TRENDS, HomeRefreshContentPreference.DEFAULT_ENABLE_TRENDS)) {
|
||||
final long accountId = getDefaultAccountId(mContext);
|
||||
final int woeId = mPreferences.getInt(KEY_LOCAL_TRENDS_WOEID, 1);
|
||||
getLocalTrendsAsync(accountId, woeId);
|
||||
}
|
||||
getSavedSearchesAsync(accountIds);
|
||||
final long[] statusSinceIds = getNewestStatusIdsFromDatabase(mContext, Statuses.CONTENT_URI, accountIds);
|
||||
return getHomeTimelineAsync(accountIds, null, statusSinceIds);
|
||||
public boolean refreshAll(final long[] accountIds) {
|
||||
AsyncTaskUtils.executeTask(new AsyncTask<long[], Object, Object[]>() {
|
||||
@Override
|
||||
protected Object[] doInBackground(long[][] params) {
|
||||
final Object[] result = new Object[8];
|
||||
result[0] = mPreferences.getBoolean(KEY_HOME_REFRESH_MENTIONS);
|
||||
if (Boolean.TRUE.equals(result[0] = mPreferences.getBoolean(KEY_HOME_REFRESH_MENTIONS))) {
|
||||
result[1] = getNewestStatusIdsFromDatabase(mContext, Mentions.CONTENT_URI, accountIds);
|
||||
}
|
||||
if (Boolean.TRUE.equals(result[2] = mPreferences.getBoolean(KEY_HOME_REFRESH_DIRECT_MESSAGES))) {
|
||||
result[3] = getNewestMessageIdsFromDatabase(mContext, DirectMessages.Inbox.CONTENT_URI, accountIds);
|
||||
}
|
||||
if (Boolean.TRUE.equals(result[4] = mPreferences.getBoolean(KEY_HOME_REFRESH_TRENDS))) {
|
||||
result[5] = getDefaultAccountId(mContext);
|
||||
result[6] = mPreferences.getInt(KEY_LOCAL_TRENDS_WOEID, 1);
|
||||
}
|
||||
result[7] = getNewestStatusIdsFromDatabase(mContext, Statuses.CONTENT_URI, accountIds);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Object[] result) {
|
||||
if (Boolean.TRUE.equals(result[0])) {
|
||||
getMentionsTimelineAsync(accountIds, null, (long[]) result[1]);
|
||||
}
|
||||
if (Boolean.TRUE.equals(result[2])) {
|
||||
getReceivedDirectMessagesAsync(accountIds, null, (long[]) result[3]);
|
||||
getSentDirectMessagesAsync(accountIds, null, null);
|
||||
}
|
||||
if (Boolean.TRUE.equals(result[4])) {
|
||||
getLocalTrendsAsync((Long) result[5], (Integer) result[6]);
|
||||
}
|
||||
getSavedSearchesAsync(accountIds);
|
||||
getHomeTimelineAsync(accountIds, null, (long[]) result[7]);
|
||||
}
|
||||
}, accountIds);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void removeSendingDraftId(long id) {
|
||||
@ -703,8 +715,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
protected void onPostExecute(final SingleResponse<User> result) {
|
||||
if (result.hasData()) {
|
||||
final User user = result.getData();
|
||||
final TwidereApplication application = TwidereApplication.getInstance(mContext);
|
||||
final UserColorNameManager manager = application.getUserColorNameManager();
|
||||
final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
|
||||
final String message = mContext.getString(R.string.accepted_users_follow_request,
|
||||
getUserName(mContext, user));
|
||||
manager.getDisplayName(user, nameFirst, true));
|
||||
showOkMessage(mContext, message, false);
|
||||
} else {
|
||||
showErrorMessage(mContext, R.string.action_accepting_follow_request,
|
||||
@ -755,7 +770,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
final String message;
|
||||
if (users.length == 1) {
|
||||
final ParcelableUser user = users[0];
|
||||
final String displayName = UserColorNameUtils.getDisplayName(mContext, user.id, user.name, user.screen_name);
|
||||
final TwidereApplication application = TwidereApplication.getInstance(mContext);
|
||||
final UserColorNameManager manager = application.getUserColorNameManager();
|
||||
final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
|
||||
final String displayName = manager.getDisplayName(user.id, user.name, user.screen_name, nameFirst, false);
|
||||
message = mContext.getString(R.string.added_user_to_list, displayName, result.getData().name);
|
||||
} else {
|
||||
final Resources res = mContext.getResources();
|
||||
@ -841,10 +859,13 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Override
|
||||
protected void onPostExecute(final SingleResponse<ParcelableUser> result) {
|
||||
if (result.hasData()) {
|
||||
final TwidereApplication application = TwidereApplication.getInstance(mContext);
|
||||
final UserColorNameManager manager = application.getUserColorNameManager();
|
||||
final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
|
||||
final String message = mContext.getString(R.string.blocked_user,
|
||||
getUserName(mContext, result.getData()));
|
||||
manager.getDisplayName(result.getData(), nameFirst, true));
|
||||
showInfoMessage(mContext, message, false);
|
||||
final Bus bus = TwidereApplication.getInstance(mContext).getMessageBus();
|
||||
final Bus bus = application.getMessageBus();
|
||||
bus.post(new FriendshipUpdatedEvent(result.getData()));
|
||||
} else {
|
||||
showErrorMessage(mContext, R.string.action_blocking, result.getException(), true);
|
||||
@ -967,13 +988,18 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
if (result.hasData()) {
|
||||
final ParcelableUser user = result.getData();
|
||||
final String message;
|
||||
final TwidereApplication application = TwidereApplication.getInstance(mContext);
|
||||
final UserColorNameManager manager = application.getUserColorNameManager();
|
||||
final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
|
||||
if (user.is_protected) {
|
||||
message = mContext.getString(R.string.sent_follow_request_to_user, getUserName(mContext, user));
|
||||
message = mContext.getString(R.string.sent_follow_request_to_user,
|
||||
manager.getDisplayName(user, nameFirst, true));
|
||||
} else {
|
||||
message = mContext.getString(R.string.followed_user, getUserName(mContext, user));
|
||||
message = mContext.getString(R.string.followed_user,
|
||||
manager.getDisplayName(user, nameFirst, true));
|
||||
}
|
||||
showOkMessage(mContext, message, false);
|
||||
final Bus bus = TwidereApplication.getInstance(mContext).getMessageBus();
|
||||
final Bus bus = application.getMessageBus();
|
||||
bus.post(new FriendshipUpdatedEvent(result.getData()));
|
||||
} else {
|
||||
showErrorMessage(mContext, R.string.action_following, result.getException(), false);
|
||||
@ -1071,10 +1097,13 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Override
|
||||
protected void onPostExecute(final SingleResponse<ParcelableUser> result) {
|
||||
if (result.hasData()) {
|
||||
final TwidereApplication application = TwidereApplication.getInstance(mContext);
|
||||
final UserColorNameManager manager = application.getUserColorNameManager();
|
||||
final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
|
||||
final String message = mContext.getString(R.string.muted_user,
|
||||
getUserName(mContext, result.getData()));
|
||||
manager.getDisplayName(result.getData(), nameFirst, true));
|
||||
showInfoMessage(mContext, message, false);
|
||||
final Bus bus = TwidereApplication.getInstance(mContext).getMessageBus();
|
||||
final Bus bus = application.getMessageBus();
|
||||
bus.post(new FriendshipUpdatedEvent(result.getData()));
|
||||
} else {
|
||||
showErrorMessage(mContext, R.string.action_muting, result.getException(), true);
|
||||
@ -1242,7 +1271,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
if (succeed) {
|
||||
if (users.length == 1) {
|
||||
final ParcelableUser user = users[0];
|
||||
final String displayName = UserColorNameUtils.getDisplayName(mContext, user.id, user.name, user.screen_name);
|
||||
final TwidereApplication application = TwidereApplication.getInstance(mContext);
|
||||
final UserColorNameManager manager = application.getUserColorNameManager();
|
||||
final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
|
||||
final String displayName = manager.getDisplayName(user.id, user.name, user.screen_name, nameFirst, false);
|
||||
message = mContext.getString(R.string.deleted_user_from_list, displayName, result.getData().name);
|
||||
} else {
|
||||
final Resources res = mContext.getResources();
|
||||
@ -1298,8 +1330,11 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
protected void onPostExecute(final SingleResponse<User> result) {
|
||||
if (result.hasData()) {
|
||||
final User user = result.getData();
|
||||
final TwidereApplication application = TwidereApplication.getInstance(mContext);
|
||||
final UserColorNameManager manager = application.getUserColorNameManager();
|
||||
final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
|
||||
final String message = mContext.getString(R.string.denied_users_follow_request,
|
||||
getUserName(mContext, user));
|
||||
manager.getDisplayName(user, nameFirst, true));
|
||||
showOkMessage(mContext, message, false);
|
||||
} else {
|
||||
showErrorMessage(mContext, R.string.action_denying_follow_request, result.getException(), false);
|
||||
@ -1340,10 +1375,13 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Override
|
||||
protected void onPostExecute(final SingleResponse<ParcelableUser> result) {
|
||||
if (result.hasData()) {
|
||||
final TwidereApplication application = TwidereApplication.getInstance(mContext);
|
||||
final UserColorNameManager manager = application.getUserColorNameManager();
|
||||
final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
|
||||
final String message = mContext.getString(R.string.unblocked_user,
|
||||
getUserName(mContext, result.getData()));
|
||||
manager.getDisplayName(result.getData(), nameFirst, true));
|
||||
showInfoMessage(mContext, message, false);
|
||||
final Bus bus = TwidereApplication.getInstance(mContext).getMessageBus();
|
||||
final Bus bus = application.getMessageBus();
|
||||
bus.post(new FriendshipUpdatedEvent(result.getData()));
|
||||
} else {
|
||||
showErrorMessage(mContext, R.string.action_unblocking, result.getException(), true);
|
||||
@ -1528,10 +1566,13 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Override
|
||||
protected void onPostExecute(final SingleResponse<ParcelableUser> result) {
|
||||
if (result.hasData()) {
|
||||
final TwidereApplication application = TwidereApplication.getInstance(mContext);
|
||||
final UserColorNameManager manager = application.getUserColorNameManager();
|
||||
final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
|
||||
final String message = mContext.getString(R.string.unfollowed_user,
|
||||
getUserName(mContext, result.getData()));
|
||||
manager.getDisplayName(result.getData(), nameFirst, true));
|
||||
showInfoMessage(mContext, message, false);
|
||||
final Bus bus = TwidereApplication.getInstance(mContext).getMessageBus();
|
||||
final Bus bus = application.getMessageBus();
|
||||
bus.post(new FriendshipUpdatedEvent(result.getData()));
|
||||
} else {
|
||||
showErrorMessage(mContext, R.string.action_unfollowing, result.getException(), true);
|
||||
@ -1569,10 +1610,13 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
@Override
|
||||
protected void onPostExecute(final SingleResponse<ParcelableUser> result) {
|
||||
if (result.hasData()) {
|
||||
final TwidereApplication application = TwidereApplication.getInstance(mContext);
|
||||
final UserColorNameManager manager = application.getUserColorNameManager();
|
||||
final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
|
||||
final String message = mContext.getString(R.string.unmuted_user,
|
||||
getUserName(mContext, result.getData()));
|
||||
manager.getDisplayName(result.getData(), nameFirst, true));
|
||||
showInfoMessage(mContext, message, false);
|
||||
final Bus bus = TwidereApplication.getInstance(mContext).getMessageBus();
|
||||
final Bus bus = application.getMessageBus();
|
||||
bus.post(new FriendshipUpdatedEvent(result.getData()));
|
||||
} else {
|
||||
showErrorMessage(mContext, R.string.action_unmuting, result.getException(), true);
|
||||
@ -1788,6 +1832,14 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
protected abstract boolean isOutgoing();
|
||||
|
||||
final boolean isMaxIdsValid() {
|
||||
return max_ids != null && max_ids.length == account_ids.length;
|
||||
}
|
||||
|
||||
final boolean isSinceIdsValid() {
|
||||
return since_ids != null && since_ids.length == account_ids.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<MessageListResponse> doInBackground(final Object... params) {
|
||||
|
||||
@ -1830,14 +1882,6 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
}
|
||||
|
||||
final boolean isMaxIdsValid() {
|
||||
return max_ids != null && max_ids.length == account_ids.length;
|
||||
}
|
||||
|
||||
final boolean isSinceIdsValid() {
|
||||
return since_ids != null && since_ids.length == account_ids.length;
|
||||
}
|
||||
|
||||
private boolean storeMessages(long accountId, List<DirectMessage> messages, boolean isOutgoing, boolean notify) {
|
||||
if (messages == null) return true;
|
||||
final Uri uri = getDatabaseUri();
|
||||
@ -2066,12 +2110,6 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
return mMaxIds != null && mMaxIds.length == mAccountIds.length;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
@Override
|
||||
protected final void onProgressUpdate(TwitterListResponse<twitter4j.Status>... values) {
|
||||
AsyncTaskUtils.executeTask(new CacheUsersStatusesTask(mContext), values);
|
||||
}
|
||||
|
||||
final boolean isSinceIdsValid() {
|
||||
return mSinceIds != null && mSinceIds.length == mAccountIds.length;
|
||||
}
|
||||
@ -2129,6 +2167,13 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
|
||||
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
@Override
|
||||
protected final void onProgressUpdate(TwitterListResponse<twitter4j.Status>... values) {
|
||||
AsyncTaskUtils.executeTask(new CacheUsersStatusesTask(mContext), values);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<StatusListResponse> result) {
|
||||
super.onPostExecute(result);
|
||||
|
@ -20,7 +20,6 @@ import org.mariotaku.twidere.constant.KeyboardShortcutConstants;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class KeyboardShortcutsHandler implements Constants, KeyboardShortcutConstants {
|
||||
|
||||
@ -77,10 +76,6 @@ public class KeyboardShortcutsHandler implements Constants, KeyboardShortcutCons
|
||||
return context.getString(labelRes);
|
||||
}
|
||||
|
||||
public static Set<String> getActions() {
|
||||
return sActionLabelMap.keySet();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getKeyAction(final String contextTag, final int keyCode, final KeyEvent event) {
|
||||
if (!isValidForHotkey(keyCode, event)) return null;
|
||||
@ -171,10 +166,6 @@ public class KeyboardShortcutsHandler implements Constants, KeyboardShortcutCons
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return mPreferences.getAll().isEmpty();
|
||||
}
|
||||
|
||||
public static boolean isValidForHotkey(int keyCode, KeyEvent event) {
|
||||
// These keys must use with modifiers
|
||||
switch (keyCode) {
|
||||
|
@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.util.LongSparseArray;
|
||||
|
||||
import org.mariotaku.twidere.TwidereConstants;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.ParcelableUserList;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import twitter4j.User;
|
||||
|
||||
import static android.text.TextUtils.isEmpty;
|
||||
|
||||
public class UserColorNameManager implements TwidereConstants {
|
||||
|
||||
private final LongSparseArray<Integer> mUserColors = new LongSparseArray<>();
|
||||
private final LongSparseArray<String> mUserNicknames = new LongSparseArray<>();
|
||||
private final SharedPreferences mColorPreferences, mNicknamePreferences;
|
||||
|
||||
public UserColorNameManager(Context context) {
|
||||
mColorPreferences = context.getSharedPreferences(USER_COLOR_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
mNicknamePreferences = context.getSharedPreferences(USER_NICKNAME_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
public static void registerOnUserColorChangedListener(final Context context,
|
||||
final OnUserColorChangedListener listener) {
|
||||
|
||||
final SharedPreferences prefs = context.getSharedPreferences(USER_COLOR_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
prefs.registerOnSharedPreferenceChangeListener(new OnColorPreferenceChangeListener(listener));
|
||||
}
|
||||
|
||||
public static void registerOnUserNicknameChangedListener(final Context context,
|
||||
final OnUserNicknameChangedListener listener) {
|
||||
|
||||
final SharedPreferences prefs = context.getSharedPreferences(USER_NICKNAME_PREFERENCES_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
prefs.registerOnSharedPreferenceChangeListener(new OnNickPreferenceChangeListener(listener));
|
||||
}
|
||||
|
||||
public static UserColorNameManager getInstance(Context context) {
|
||||
final TwidereApplication application = TwidereApplication.getInstance(context);
|
||||
return application.getUserColorNameManager();
|
||||
}
|
||||
|
||||
public void clearUserColor(final long userId) {
|
||||
if (userId < 0) return;
|
||||
mUserColors.remove(userId);
|
||||
final SharedPreferences.Editor editor = mColorPreferences.edit();
|
||||
editor.remove(Long.toString(userId));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public void setUserColor(final long userId, final int color) {
|
||||
if (userId < 0) return;
|
||||
mUserColors.put(userId, color);
|
||||
final SharedPreferences.Editor editor = mColorPreferences.edit();
|
||||
editor.putInt(String.valueOf(userId), color);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public void setUserNickname(final long userId, final String nickname) {
|
||||
if (userId < 0) return;
|
||||
mUserNicknames.put(userId, nickname);
|
||||
final SharedPreferences.Editor editor = mNicknamePreferences.edit();
|
||||
editor.putString(String.valueOf(userId), nickname);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public void clearUserNickname(final long userId) {
|
||||
if (userId < 0) return;
|
||||
mUserNicknames.remove(userId);
|
||||
final SharedPreferences.Editor editor = mNicknamePreferences.edit();
|
||||
editor.remove(Long.toString(userId));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public String getDisplayName(final ParcelableUser user, final boolean nameFirst, final boolean ignoreCache) {
|
||||
return getDisplayName(user.id, user.name, user.screen_name, nameFirst, ignoreCache);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getDisplayName(final User user, final boolean nameFirst, final boolean ignoreCache) {
|
||||
return getDisplayName(user.getId(), user.getName(), user.getScreenName(), nameFirst, ignoreCache);
|
||||
}
|
||||
|
||||
public String getDisplayName(final ParcelableUserList user, final boolean nameFirst, final boolean ignoreCache) {
|
||||
return getDisplayName(user.user_id, user.user_name, user.user_screen_name, nameFirst, ignoreCache);
|
||||
}
|
||||
|
||||
public String getDisplayName(final ParcelableStatus status, final boolean nameFirst, final boolean ignoreCache) {
|
||||
return getDisplayName(status.user_id, status.user_name, status.user_screen_name, nameFirst, ignoreCache);
|
||||
}
|
||||
|
||||
public String getDisplayName(final long userId, final String name,
|
||||
final String screenName, final boolean nameFirst,
|
||||
final boolean ignoreCache) {
|
||||
final String nick = getUserNickname(userId, ignoreCache);
|
||||
if (!isEmpty(nick)) return nick;
|
||||
return nameFirst && !isEmpty(name) ? name : "@" + screenName;
|
||||
}
|
||||
|
||||
public int getUserColor(final long userId, final boolean ignoreCache) {
|
||||
if (userId == -1) return Color.TRANSPARENT;
|
||||
if (!ignoreCache && mUserColors.indexOfKey(userId) >= 0) return mUserColors.get(userId);
|
||||
final int color = mColorPreferences.getInt(Long.toString(userId), Color.TRANSPARENT);
|
||||
mUserColors.put(userId, color);
|
||||
return color;
|
||||
}
|
||||
|
||||
public String getUserNickname(final long userId) {
|
||||
return getUserNickname(userId, false);
|
||||
}
|
||||
|
||||
public String getUserNickname(final long userId, final boolean ignoreCache) {
|
||||
if (userId == -1) return null;
|
||||
if (!ignoreCache && LongSparseArrayUtils.hasKey(mUserNicknames, userId))
|
||||
return mUserNicknames.get(userId);
|
||||
final String nickname = mNicknamePreferences.getString(Long.toString(userId), null);
|
||||
mUserNicknames.put(userId, nickname);
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public String getUserNickname(final long userId, final String name) {
|
||||
return getUserNickname(userId, name, false);
|
||||
}
|
||||
|
||||
public String getUserNickname(final long userId, final String name, final boolean ignoreCache) {
|
||||
final String nick = getUserNickname(userId, ignoreCache);
|
||||
return isEmpty(nick) ? name : nick;
|
||||
}
|
||||
|
||||
public Set<? extends Map.Entry<String, ?>> getNameEntries() {
|
||||
return mNicknamePreferences.getAll().entrySet();
|
||||
}
|
||||
|
||||
public static interface OnUserColorChangedListener {
|
||||
void onUserColorChanged(long userId, int color);
|
||||
}
|
||||
|
||||
public static interface OnUserNicknameChangedListener {
|
||||
void onUserNicknameChanged(long userId, String nick);
|
||||
}
|
||||
|
||||
private static final class OnColorPreferenceChangeListener implements OnSharedPreferenceChangeListener {
|
||||
|
||||
private final OnUserColorChangedListener mListener;
|
||||
|
||||
OnColorPreferenceChangeListener(final OnUserColorChangedListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
|
||||
final long userId = ParseUtils.parseLong(key, -1);
|
||||
if (mListener != null) {
|
||||
mListener.onUserColorChanged(userId, sharedPreferences.getInt(key, 0));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class OnNickPreferenceChangeListener implements OnSharedPreferenceChangeListener {
|
||||
|
||||
private final OnUserNicknameChangedListener mListener;
|
||||
|
||||
OnNickPreferenceChangeListener(final OnUserNicknameChangedListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
|
||||
final long userId = ParseUtils.parseLong(key, -1);
|
||||
if (mListener != null) {
|
||||
mListener.onUserNicknameChanged(userId, sharedPreferences.getString(key, null));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,231 +0,0 @@
|
||||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.util.LongSparseArray;
|
||||
|
||||
import org.mariotaku.twidere.TwidereConstants;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static android.text.TextUtils.isEmpty;
|
||||
|
||||
public class UserColorNameUtils implements TwidereConstants {
|
||||
|
||||
private static final LongSparseArray<Integer> sUserColors = new LongSparseArray<>();
|
||||
private static final LongSparseArray<String> sUserNicknames = new LongSparseArray<>();
|
||||
|
||||
private UserColorNameUtils() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static void clearUserColor(final Context context, final long userId) {
|
||||
if (context == null) return;
|
||||
sUserColors.remove(userId);
|
||||
final SharedPreferences prefs = context.getSharedPreferences(USER_COLOR_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
final SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.remove(Long.toString(userId));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void clearUserNickname(final Context context, final long userId) {
|
||||
if (context == null) return;
|
||||
sUserNicknames.remove(userId);
|
||||
final SharedPreferences prefs = context.getSharedPreferences(USER_NICKNAME_PREFERENCES_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
final SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.remove(Long.toString(userId));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static String getDisplayName(final Context context, final long userId, final String name,
|
||||
final String screenName) {
|
||||
return getDisplayName(context, userId, name, screenName, false);
|
||||
}
|
||||
|
||||
public static String getDisplayName(final Context context, final ParcelableUser user) {
|
||||
return getDisplayName(context, user, false);
|
||||
}
|
||||
|
||||
public static String getDisplayName(final Context context, final ParcelableUser user, final boolean ignoreCache) {
|
||||
return getDisplayName(context, user.id, user.name, user.screen_name, ignoreCache);
|
||||
}
|
||||
|
||||
public static String getDisplayName(final Context context, final long userId, final String name,
|
||||
final String screenName, final boolean ignoreCache) {
|
||||
if (context == null) return null;
|
||||
final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
final boolean nameFirst = prefs.getBoolean(KEY_NAME_FIRST, true);
|
||||
return getDisplayName(context, userId, name, screenName, nameFirst, ignoreCache);
|
||||
}
|
||||
|
||||
public static String getDisplayName(final Context context, final ParcelableUser user,
|
||||
final boolean nameFirst, final boolean ignoreCache) {
|
||||
return getDisplayName(context, user.id, user.name, user.screen_name, nameFirst, ignoreCache);
|
||||
}
|
||||
|
||||
|
||||
public static String getDisplayName(final Context context, final ParcelableStatus status,
|
||||
final boolean nameFirst,
|
||||
final boolean ignoreCache) {
|
||||
return getDisplayName(context, status.user_id, status.user_name, status.user_screen_name,
|
||||
nameFirst, ignoreCache);
|
||||
}
|
||||
|
||||
public static String getDisplayName(final Context context, final long userId, final String name,
|
||||
final String screenName, final boolean nameFirst,
|
||||
final boolean ignoreCache) {
|
||||
if (context == null) return null;
|
||||
final String nick = getUserNickname(context, userId, ignoreCache);
|
||||
final boolean nickAvailable = !isEmpty(nick);
|
||||
if (nickAvailable) return nick;
|
||||
return nameFirst && !isEmpty(name) ? name : "@" + screenName;
|
||||
}
|
||||
|
||||
public static int getUserColor(final Context context, final long user_id) {
|
||||
return getUserColor(context, user_id, false);
|
||||
}
|
||||
|
||||
public static int getUserColor(final Context context, final long userId, final boolean ignoreCache) {
|
||||
if (context == null || userId == -1) return Color.TRANSPARENT;
|
||||
if (!ignoreCache && sUserColors.indexOfKey(userId) >= 0) return sUserColors.get(userId);
|
||||
final SharedPreferences prefs = context.getSharedPreferences(USER_COLOR_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
final int color = prefs.getInt(Long.toString(userId), Color.TRANSPARENT);
|
||||
sUserColors.put(userId, color);
|
||||
return color;
|
||||
}
|
||||
|
||||
public static String getUserNickname(final Context context, final long userId) {
|
||||
return getUserNickname(context, userId, false);
|
||||
}
|
||||
|
||||
public static String getUserNickname(final Context context, final long userId, final boolean ignoreCache) {
|
||||
if (context == null || userId == -1) return null;
|
||||
if (!ignoreCache && LongSparseArrayUtils.hasKey(sUserNicknames, userId))
|
||||
return sUserNicknames.get(userId);
|
||||
final SharedPreferences prefs = context.getSharedPreferences(USER_NICKNAME_PREFERENCES_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
final String nickname = prefs.getString(Long.toString(userId), null);
|
||||
sUserNicknames.put(userId, nickname);
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public static String getUserNickname(final Context context, final long userId, final String name) {
|
||||
return getUserNickname(context, userId, name, false);
|
||||
}
|
||||
|
||||
public static String getUserNickname(final Context context, final long userId, final String name, final boolean ignoreCache) {
|
||||
final String nick = getUserNickname(context, userId, ignoreCache);
|
||||
return isEmpty(nick) ? name : nick;
|
||||
}
|
||||
|
||||
public static void initUserColor(final Context context) {
|
||||
if (context == null) return;
|
||||
final SharedPreferences prefs = context.getSharedPreferences(USER_COLOR_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
for (final Map.Entry<String, ?> entry : prefs.getAll().entrySet()) {
|
||||
sUserColors.put(ParseUtils.parseLong(entry.getKey()),
|
||||
ParseUtils.parseInt(ParseUtils.parseString(entry.getValue())));
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerOnUserColorChangedListener(final Context context,
|
||||
final OnUserColorChangedListener listener) {
|
||||
|
||||
final SharedPreferences prefs = context.getSharedPreferences(USER_COLOR_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
prefs.registerOnSharedPreferenceChangeListener(new OnColorPreferenceChangeListener(listener));
|
||||
}
|
||||
|
||||
public static void registerOnUserNicknameChangedListener(final Context context,
|
||||
final OnUserNicknameChangedListener listener) {
|
||||
|
||||
final SharedPreferences prefs = context.getSharedPreferences(USER_NICKNAME_PREFERENCES_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
prefs.registerOnSharedPreferenceChangeListener(new OnNickPreferenceChangeListener(listener));
|
||||
}
|
||||
|
||||
public static void setUserColor(final Context context, final long user_id, final int color) {
|
||||
if (context == null || user_id == -1) return;
|
||||
sUserColors.put(user_id, color);
|
||||
final SharedPreferences prefs = context.getSharedPreferences(USER_COLOR_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
final SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putInt(String.valueOf(user_id), color);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void setUserNickname(final Context context, final long user_id, final String nickname) {
|
||||
if (context == null || user_id == -1) return;
|
||||
sUserNicknames.put(user_id, nickname);
|
||||
final SharedPreferences prefs = context.getSharedPreferences(USER_NICKNAME_PREFERENCES_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
final SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putString(String.valueOf(user_id), nickname);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static interface OnUserColorChangedListener {
|
||||
void onUserColorChanged(long userId, int color);
|
||||
}
|
||||
|
||||
public static interface OnUserNicknameChangedListener {
|
||||
void onUserNicknameChanged(long userId, String nick);
|
||||
}
|
||||
|
||||
private static final class OnColorPreferenceChangeListener implements OnSharedPreferenceChangeListener {
|
||||
|
||||
private final OnUserColorChangedListener mListener;
|
||||
|
||||
OnColorPreferenceChangeListener(final OnUserColorChangedListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
|
||||
final long userId = ParseUtils.parseLong(key, -1);
|
||||
if (mListener != null) {
|
||||
mListener.onUserColorChanged(userId, sharedPreferences.getInt(key, 0));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class OnNickPreferenceChangeListener implements OnSharedPreferenceChangeListener {
|
||||
|
||||
private final OnUserNicknameChangedListener mListener;
|
||||
|
||||
OnNickPreferenceChangeListener(final OnUserNicknameChangedListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
|
||||
final long userId = ParseUtils.parseLong(key, -1);
|
||||
if (mListener != null) {
|
||||
mListener.onUserNicknameChanged(userId, sharedPreferences.getString(key, null));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -254,7 +254,6 @@ import twitter4j.Twitter;
|
||||
import twitter4j.TwitterConstants;
|
||||
import twitter4j.TwitterException;
|
||||
import twitter4j.TwitterFactory;
|
||||
import twitter4j.User;
|
||||
import twitter4j.UserMentionEntity;
|
||||
import twitter4j.auth.AccessToken;
|
||||
import twitter4j.auth.Authorization;
|
||||
@ -275,9 +274,6 @@ import static org.mariotaku.twidere.provider.TwidereDataStore.DIRECT_MESSAGES_UR
|
||||
import static org.mariotaku.twidere.provider.TwidereDataStore.STATUSES_URIS;
|
||||
import static org.mariotaku.twidere.util.TwidereLinkify.PATTERN_TWITTER_PROFILE_IMAGES;
|
||||
import static org.mariotaku.twidere.util.TwidereLinkify.TWITTER_PROFILE_IMAGES_AVAILABLE_SIZES;
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.clearUserNickname;
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.getUserColor;
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.getUserNickname;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Utils implements Constants, TwitterConstants {
|
||||
@ -1936,10 +1932,10 @@ public final class Utils implements Constants, TwitterConstants {
|
||||
.getConfiguration().locale);
|
||||
}
|
||||
|
||||
public static long[] getMatchedNicknameIds(final String str, SharedPreferences nicknamePrefs) {
|
||||
public static long[] getMatchedNicknameIds(final String str, UserColorNameManager manager) {
|
||||
if (isEmpty(str)) return new long[0];
|
||||
final List<Long> list = new ArrayList<>();
|
||||
for (final Entry<String, ?> entry : nicknamePrefs.getAll().entrySet()) {
|
||||
for (final Entry<String, ?> entry : manager.getNameEntries()) {
|
||||
final String value = ParseUtils.parseString(entry.getValue());
|
||||
final long key = ParseUtils.parseLong(entry.getKey(), -1);
|
||||
if (key == -1 || isEmpty(value)) {
|
||||
@ -2016,6 +2012,12 @@ public final class Utils implements Constants, TwitterConstants {
|
||||
return isEmpty(val) ? def : val;
|
||||
}
|
||||
|
||||
public static String getNonEmptyString(final SharedPreferencesWrapper pref, final String key, final String def) {
|
||||
if (pref == null) return def;
|
||||
final String val = pref.getString(key, def);
|
||||
return isEmpty(val) ? def : val;
|
||||
}
|
||||
|
||||
public static String getNormalTwitterProfileImage(final String url) {
|
||||
return getTwitterProfileImageOfSize(url, "normal");
|
||||
}
|
||||
@ -2598,21 +2600,6 @@ public final class Utils implements Constants, TwitterConstants {
|
||||
return string.replace("&", "&").replace("<", "<").replace(">", ">");
|
||||
}
|
||||
|
||||
public static String getUserName(final Context context, final ParcelableStatus status) {
|
||||
if (context == null || status == null) return null;
|
||||
return UserColorNameUtils.getDisplayName(context, status.user_id, status.user_name, status.user_screen_name);
|
||||
}
|
||||
|
||||
public static String getUserName(final Context context, final ParcelableUser user) {
|
||||
if (context == null || user == null) return null;
|
||||
return UserColorNameUtils.getDisplayName(context, user.id, user.name, user.screen_name);
|
||||
}
|
||||
|
||||
public static String getUserName(final Context context, final User user) {
|
||||
if (context == null || user == null) return null;
|
||||
return UserColorNameUtils.getDisplayName(context, user.getId(), user.getName(), user.getScreenName());
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
public static int getUserTypeIconRes(final boolean isVerified, final boolean isProtected) {
|
||||
if (isVerified)
|
||||
@ -3945,6 +3932,7 @@ public final class Utils implements Constants, TwitterConstants {
|
||||
}
|
||||
|
||||
public static boolean handleMenuItemClick(Context context, Fragment fragment, FragmentManager fm, AsyncTwitterWrapper twitter, ParcelableStatus status, MenuItem item) {
|
||||
final UserColorNameManager colorNameManager = UserColorNameManager.getInstance(context);
|
||||
switch (item.getItemId()) {
|
||||
case MENU_COPY: {
|
||||
if (ClipboardUtils.setText(context, status.text_plain)) {
|
||||
@ -3990,7 +3978,7 @@ public final class Utils implements Constants, TwitterConstants {
|
||||
}
|
||||
case MENU_SET_COLOR: {
|
||||
final Intent intent = new Intent(context, ColorPickerDialogActivity.class);
|
||||
final int color = getUserColor(context, status.user_id, true);
|
||||
final int color = colorNameManager.getUserColor(status.user_id, true);
|
||||
if (color != 0) {
|
||||
intent.putExtra(EXTRA_COLOR, color);
|
||||
}
|
||||
@ -4004,11 +3992,11 @@ public final class Utils implements Constants, TwitterConstants {
|
||||
break;
|
||||
}
|
||||
case MENU_CLEAR_NICKNAME: {
|
||||
clearUserNickname(context, status.user_id);
|
||||
colorNameManager.clearUserNickname(status.user_id);
|
||||
break;
|
||||
}
|
||||
case MENU_SET_NICKNAME: {
|
||||
final String nick = getUserNickname(context, status.user_id, true);
|
||||
final String nick = colorNameManager.getUserNickname(status.user_id, true);
|
||||
SetUserNicknameDialogFragment.show(fm, status.user_id, nick);
|
||||
break;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ import org.mariotaku.twidere.adapter.AbsActivitiesAdapter;
|
||||
import org.mariotaku.twidere.model.ParcelableActivity;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.view.ActionIconView;
|
||||
import org.oshkimaadziig.george.androidutils.SpanFormatter;
|
||||
|
||||
@ -130,8 +130,9 @@ public class ActivityTitleSummaryViewHolder extends ViewHolder {
|
||||
activityTypeView.setColorFilter(activityTypeView.getDefaultColor(), Mode.SRC_ATOP);
|
||||
if (activity.sources.length == 1 && activity.target_object_user_lists != null
|
||||
&& activity.target_object_user_lists.length == 1) {
|
||||
final SpannableString firstDisplayName = new SpannableString(UserColorNameUtils.getDisplayName(context,
|
||||
activity.sources[0]));
|
||||
final UserColorNameManager manager = adapter.getUserColorNameManager();
|
||||
final SpannableString firstDisplayName = new SpannableString(manager.getDisplayName(
|
||||
activity.sources[0], adapter.isNameFirst(), false));
|
||||
final SpannableString listName = new SpannableString(activity.target_object_user_lists[0].name);
|
||||
firstDisplayName.setSpan(new StyleSpan(Typeface.BOLD), 0, firstDisplayName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
listName.setSpan(new StyleSpan(Typeface.BOLD), 0, listName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
@ -192,17 +193,20 @@ public class ActivityTitleSummaryViewHolder extends ViewHolder {
|
||||
private Spanned getTitleStringAboutMe(int stringRes, int stringResMulti, ParcelableUser[] sources) {
|
||||
if (sources == null || sources.length == 0) return null;
|
||||
final Context context = adapter.getContext();
|
||||
final boolean nameFirst = adapter.isNameFirst();
|
||||
final UserColorNameManager manager = adapter.getUserColorNameManager();
|
||||
final Resources resources = context.getResources();
|
||||
final Configuration configuration = resources.getConfiguration();
|
||||
final SpannableString firstDisplayName = new SpannableString(UserColorNameUtils.getDisplayName(context,
|
||||
sources[0]));
|
||||
final SpannableString firstDisplayName = new SpannableString(manager.getDisplayName(sources[0],
|
||||
nameFirst, false));
|
||||
firstDisplayName.setSpan(new StyleSpan(Typeface.BOLD), 0, firstDisplayName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
if (sources.length == 1) {
|
||||
final String format = context.getString(stringRes);
|
||||
return SpanFormatter.format(configuration.locale, format, firstDisplayName);
|
||||
} else if (sources.length == 2) {
|
||||
final String format = context.getString(stringResMulti);
|
||||
final SpannableString secondDisplayName = new SpannableString(UserColorNameUtils.getDisplayName(context, sources[1]));
|
||||
final SpannableString secondDisplayName = new SpannableString(manager.getDisplayName(sources[1],
|
||||
nameFirst, false));
|
||||
secondDisplayName.setSpan(new StyleSpan(Typeface.BOLD), 0, secondDisplayName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
return SpanFormatter.format(configuration.locale, format, firstDisplayName,
|
||||
secondDisplayName);
|
||||
@ -220,18 +224,21 @@ public class ActivityTitleSummaryViewHolder extends ViewHolder {
|
||||
final Context context = adapter.getContext();
|
||||
final Resources resources = context.getResources();
|
||||
final Configuration configuration = resources.getConfiguration();
|
||||
final SpannableString firstSourceName = new SpannableString(UserColorNameUtils.getDisplayName(context,
|
||||
sources[0]));
|
||||
final UserColorNameManager manager = adapter.getUserColorNameManager();
|
||||
final boolean nameFirst = adapter.isNameFirst();
|
||||
final SpannableString firstSourceName = new SpannableString(manager.getDisplayName(
|
||||
sources[0], nameFirst, false));
|
||||
firstSourceName.setSpan(new StyleSpan(Typeface.BOLD), 0, firstSourceName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
final SpannableString firstTargetName = new SpannableString(UserColorNameUtils.getDisplayName(context,
|
||||
targets[0]));
|
||||
final SpannableString firstTargetName = new SpannableString(manager.getDisplayName(
|
||||
targets[0], nameFirst, false));
|
||||
firstTargetName.setSpan(new StyleSpan(Typeface.BOLD), 0, firstTargetName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
if (sources.length == 1) {
|
||||
final String format = context.getString(stringRes);
|
||||
return SpanFormatter.format(configuration.locale, format, firstSourceName, firstTargetName);
|
||||
} else if (sources.length == 2) {
|
||||
final String format = context.getString(stringResMulti);
|
||||
final SpannableString secondSourceName = new SpannableString(UserColorNameUtils.getDisplayName(context, sources[1]));
|
||||
final SpannableString secondSourceName = new SpannableString(manager.getDisplayName(sources[1],
|
||||
nameFirst, false));
|
||||
secondSourceName.setSpan(new StyleSpan(Typeface.BOLD), 0, secondSourceName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
return SpanFormatter.format(configuration.locale, format, firstSourceName,
|
||||
secondSourceName, firstTargetName);
|
||||
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.view.holder;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.view.iface.IColorLabelView;
|
||||
|
||||
public class CardViewHolder extends ViewListHolder {
|
||||
|
||||
public final IColorLabelView content;
|
||||
|
||||
public CardViewHolder(final View view) {
|
||||
super(view);
|
||||
content = (IColorLabelView) view.findViewById(R.id.content);
|
||||
}
|
||||
|
||||
}
|
@ -33,13 +33,12 @@ import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.adapter.MessageEntriesAdapter;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages.ConversationEntries;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.view.ShortTimeView;
|
||||
import org.mariotaku.twidere.view.iface.IColorLabelView;
|
||||
|
||||
import static org.mariotaku.twidere.util.HtmlEscapeHelper.toPlainText;
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.getUserNickname;
|
||||
|
||||
public class MessageEntryViewHolder extends ViewHolder implements OnClickListener {
|
||||
|
||||
@ -68,6 +67,7 @@ public class MessageEntryViewHolder extends ViewHolder implements OnClickListene
|
||||
public void displayMessage(Cursor cursor, boolean isUnread) {
|
||||
final Context context = adapter.getContext();
|
||||
final MediaLoaderWrapper loader = adapter.getMediaLoader();
|
||||
final UserColorNameManager manager = adapter.getUserColorNameManager();
|
||||
|
||||
final long accountId = cursor.getLong(ConversationEntries.IDX_ACCOUNT_ID);
|
||||
final long conversationId = cursor.getLong(ConversationEntries.IDX_CONVERSATION_ID);
|
||||
@ -77,7 +77,7 @@ public class MessageEntryViewHolder extends ViewHolder implements OnClickListene
|
||||
final String name = cursor.getString(ConversationEntries.IDX_NAME);
|
||||
final String screenName = cursor.getString(ConversationEntries.IDX_SCREEN_NAME);
|
||||
|
||||
nameView.setText(getUserNickname(context, conversationId, name));
|
||||
nameView.setText(manager.getUserNickname(conversationId, name, false));
|
||||
screenNameView.setText("@" + screenName);
|
||||
textView.setText(toPlainText(cursor.getString(ConversationEntries.IDX_TEXT)));
|
||||
timeView.setTime(timestamp);
|
||||
@ -92,7 +92,7 @@ public class MessageEntryViewHolder extends ViewHolder implements OnClickListene
|
||||
if (account_color_enabled) {
|
||||
content.drawEnd(Utils.getAccountColor(context, accountId));
|
||||
}
|
||||
content.drawStart(UserColorNameUtils.getUserColor(context, conversationId));
|
||||
content.drawStart(manager.getUserColor(conversationId, false));
|
||||
|
||||
final String profileImage = cursor.getString(ConversationEntries.IDX_PROFILE_IMAGE_URL);
|
||||
loader.displayProfileImage(profileImageView, profileImage);
|
||||
|
@ -30,7 +30,7 @@ import org.mariotaku.twidere.util.MediaLoadingHandler;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.TwidereLinkify;
|
||||
import org.mariotaku.twidere.util.TwitterCardUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameUtils;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.view.CardMediaContainer;
|
||||
import org.mariotaku.twidere.view.CardMediaContainer.OnMediaClickListener;
|
||||
@ -44,7 +44,6 @@ import java.util.Locale;
|
||||
import twitter4j.TranslationResult;
|
||||
|
||||
import static org.mariotaku.twidere.util.HtmlEscapeHelper.toPlainText;
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.getUserNickname;
|
||||
import static org.mariotaku.twidere.util.Utils.getUserTypeIconRes;
|
||||
|
||||
/**
|
||||
@ -108,6 +107,10 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
favoriteCountView = (TextView) itemView.findViewById(R.id.favorite_count);
|
||||
//TODO
|
||||
// profileImageView.setSelectorColor(ThemeUtils.getUserHighlightColor(itemView.getContext()));
|
||||
|
||||
if (adapter.isMediaPreviewEnabled()) {
|
||||
View.inflate(mediaPreview.getContext(), R.layout.layout_card_media_preview, mediaPreview);
|
||||
}
|
||||
}
|
||||
|
||||
public void displaySampleStatus() {
|
||||
@ -137,6 +140,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
final MediaLoaderWrapper loader = adapter.getMediaLoader();
|
||||
final AsyncTwitterWrapper twitter = adapter.getTwitterWrapper();
|
||||
final TwidereLinkify linkify = adapter.getTwidereLinkify();
|
||||
final UserColorNameManager manager = adapter.getUserColorNameManager();
|
||||
final Context context = adapter.getContext();
|
||||
final boolean nameFirst = adapter.isNameFirst();
|
||||
|
||||
@ -145,15 +149,15 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
final long favorite_count;
|
||||
|
||||
if (status.retweet_id > 0) {
|
||||
final String retweetedBy = UserColorNameUtils.getDisplayName(context, status.retweeted_by_id,
|
||||
status.retweeted_by_name, status.retweeted_by_screen_name, nameFirst);
|
||||
final String retweetedBy = manager.getDisplayName(status.retweeted_by_id,
|
||||
status.retweeted_by_name, status.retweeted_by_screen_name, nameFirst, false);
|
||||
replyRetweetView.setText(context.getString(R.string.name_retweeted, retweetedBy));
|
||||
replyRetweetIcon.setImageResource(R.drawable.ic_activity_action_retweet);
|
||||
replyRetweetView.setVisibility(View.VISIBLE);
|
||||
replyRetweetIcon.setVisibility(View.VISIBLE);
|
||||
} else if (status.in_reply_to_status_id > 0 && status.in_reply_to_user_id > 0 && displayInReplyTo) {
|
||||
final String inReplyTo = UserColorNameUtils.getDisplayName(context, status.in_reply_to_user_id,
|
||||
status.in_reply_to_name, status.in_reply_to_screen_name, nameFirst);
|
||||
final String inReplyTo = manager.getDisplayName(status.in_reply_to_user_id,
|
||||
status.in_reply_to_name, status.in_reply_to_screen_name, nameFirst, false);
|
||||
replyRetweetView.setText(context.getString(R.string.in_reply_to_name, inReplyTo));
|
||||
replyRetweetIcon.setImageResource(R.drawable.ic_activity_action_reply);
|
||||
replyRetweetView.setVisibility(View.VISIBLE);
|
||||
@ -166,10 +170,10 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
final int typeIconRes;
|
||||
|
||||
if (status.is_quote) {
|
||||
quotedNameView.setText(getUserNickname(context, status.user_id, status.user_name, true));
|
||||
quotedNameView.setText(manager.getUserNickname(status.user_id, status.user_name, false));
|
||||
quotedScreenNameView.setText("@" + status.user_screen_name);
|
||||
timeView.setTime(status.quote_timestamp);
|
||||
nameView.setText(getUserNickname(context, status.quoted_by_user_id, status.quoted_by_user_name, true));
|
||||
nameView.setText(manager.getUserNickname(status.quoted_by_user_id, status.quoted_by_user_name, false));
|
||||
screenNameView.setText("@" + status.quoted_by_user_screen_name);
|
||||
|
||||
final int idx = status.quote_text_unescaped.lastIndexOf(" twitter.com");
|
||||
@ -188,7 +192,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
quoteTextView.setVisibility(View.VISIBLE);
|
||||
quoteIndicator.setVisibility(View.VISIBLE);
|
||||
|
||||
quoteIndicator.setColor(UserColorNameUtils.getUserColor(context, status.user_id));
|
||||
quoteIndicator.setColor(manager.getUserColor(status.user_id, false));
|
||||
|
||||
if (adapter.isProfileImageEnabled()) {
|
||||
profileTypeView.setVisibility(View.VISIBLE);
|
||||
@ -204,10 +208,10 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
typeIconRes = 0;
|
||||
}
|
||||
|
||||
final int userColor = UserColorNameUtils.getUserColor(context, status.quoted_by_user_id);
|
||||
final int userColor = manager.getUserColor(status.quoted_by_user_id, false);
|
||||
itemContent.drawStart(userColor);
|
||||
} else {
|
||||
nameView.setText(getUserNickname(context, status.user_id, status.user_name, true));
|
||||
nameView.setText(manager.getUserNickname(status.user_id, status.user_name, false));
|
||||
screenNameView.setText("@" + status.user_screen_name);
|
||||
if (status.is_retweet) {
|
||||
timeView.setTime(status.retweet_timestamp);
|
||||
@ -232,7 +236,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
|
||||
typeIconRes = 0;
|
||||
}
|
||||
final int userColor = UserColorNameUtils.getUserColor(context, status.user_id);
|
||||
final int userColor = manager.getUserColor(status.user_id, false);
|
||||
itemContent.drawStart(userColor);
|
||||
}
|
||||
|
||||
@ -322,6 +326,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
final MediaLoaderWrapper loader = adapter.getMediaLoader();
|
||||
final AsyncTwitterWrapper twitter = adapter.getTwitterWrapper();
|
||||
final TwidereLinkify linkify = adapter.getTwidereLinkify();
|
||||
final UserColorNameManager manager = adapter.getUserColorNameManager();
|
||||
final Context context = adapter.getContext();
|
||||
final boolean nameFirst = adapter.isNameFirst();
|
||||
|
||||
@ -351,8 +356,8 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
final long retweeted_by_id = cursor.getLong(indices.retweeted_by_user_id);
|
||||
final String retweeted_by_name = cursor.getString(indices.retweeted_by_user_name);
|
||||
final String retweeted_by_screen_name = cursor.getString(indices.retweeted_by_user_screen_name);
|
||||
final String retweetedBy = UserColorNameUtils.getDisplayName(context, retweeted_by_id,
|
||||
retweeted_by_name, retweeted_by_screen_name, nameFirst);
|
||||
final String retweetedBy = manager.getDisplayName(retweeted_by_id, retweeted_by_name,
|
||||
retweeted_by_screen_name, nameFirst, false);
|
||||
replyRetweetView.setText(context.getString(R.string.name_retweeted, retweetedBy));
|
||||
replyRetweetIcon.setImageResource(R.drawable.ic_activity_action_retweet);
|
||||
replyRetweetView.setVisibility(View.VISIBLE);
|
||||
@ -360,8 +365,8 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
} else if (in_reply_to_status_id > 0 && in_reply_to_user_id > 0 && displayInReplyTo) {
|
||||
final String in_reply_to_name = cursor.getString(indices.in_reply_to_user_name);
|
||||
final String in_reply_to_screen_name = cursor.getString(indices.in_reply_to_user_screen_name);
|
||||
final String inReplyTo = UserColorNameUtils.getDisplayName(context, in_reply_to_user_id,
|
||||
in_reply_to_name, in_reply_to_screen_name, nameFirst);
|
||||
final String inReplyTo = manager.getDisplayName(in_reply_to_user_id, in_reply_to_name,
|
||||
in_reply_to_screen_name, nameFirst, false);
|
||||
replyRetweetView.setText(context.getString(R.string.in_reply_to_name, inReplyTo));
|
||||
replyRetweetIcon.setImageResource(R.drawable.ic_activity_action_reply);
|
||||
replyRetweetView.setVisibility(View.VISIBLE);
|
||||
@ -397,7 +402,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
quoteTextView.setVisibility(View.VISIBLE);
|
||||
quoteIndicator.setVisibility(View.VISIBLE);
|
||||
|
||||
quoteIndicator.setColor(UserColorNameUtils.getUserColor(context, user_id));
|
||||
quoteIndicator.setColor(manager.getUserColor(user_id, false));
|
||||
|
||||
if (adapter.isProfileImageEnabled()) {
|
||||
profileImageView.setVisibility(View.VISIBLE);
|
||||
@ -412,7 +417,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
typeIconRes = 0;
|
||||
}
|
||||
|
||||
final int userColor = UserColorNameUtils.getUserColor(context, cursor.getLong(indices.quoted_by_user_id));
|
||||
final int userColor = manager.getUserColor(cursor.getLong(indices.quoted_by_user_id), false);
|
||||
itemContent.drawStart(userColor);
|
||||
|
||||
} else {
|
||||
@ -442,7 +447,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
|
||||
typeIconRes = 0;
|
||||
}
|
||||
final int userColor = UserColorNameUtils.getUserColor(context, user_id);
|
||||
final int userColor = manager.getUserColor(user_id, false);
|
||||
itemContent.drawStart(userColor);
|
||||
}
|
||||
|
||||
@ -667,6 +672,8 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
private final MediaLoadingHandler handler;
|
||||
private final AsyncTwitterWrapper twitter;
|
||||
private final TwidereLinkify linkify;
|
||||
private final UserColorNameManager manager;
|
||||
|
||||
private int profileImageStyle;
|
||||
private int mediaPreviewStyle;
|
||||
private int textSize;
|
||||
@ -684,6 +691,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
loader = app.getMediaLoaderWrapper();
|
||||
handler = new MediaLoadingHandler(R.id.media_preview_progress);
|
||||
twitter = app.getTwitterWrapper();
|
||||
manager = app.getUserColorNameManager();
|
||||
linkify = new TwidereLinkify(null);
|
||||
updateOptions();
|
||||
}
|
||||
@ -703,6 +711,11 @@ public class StatusViewHolder extends ViewHolder implements Constants, OnClickLi
|
||||
return handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserColorNameManager getUserColorNameManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 0;
|
||||
|
@ -33,13 +33,12 @@ import org.mariotaku.twidere.adapter.iface.ContentCardClickListener;
|
||||
import org.mariotaku.twidere.adapter.iface.IUsersAdapter;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.view.ShapedImageView;
|
||||
import org.mariotaku.twidere.view.iface.IColorLabelView;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.getUserColor;
|
||||
import static org.mariotaku.twidere.util.UserColorNameUtils.getUserNickname;
|
||||
import static org.mariotaku.twidere.util.Utils.getLocalizedNumber;
|
||||
import static org.mariotaku.twidere.util.Utils.getUserTypeIconRes;
|
||||
|
||||
@ -75,9 +74,10 @@ public class UserViewHolder extends ViewHolder implements OnClickListener, OnLon
|
||||
|
||||
final Context context = adapter.getContext();
|
||||
final MediaLoaderWrapper loader = adapter.getMediaLoader();
|
||||
final UserColorNameManager manager = adapter.getUserColorNameManager();
|
||||
|
||||
|
||||
setUserColor(getUserColor(context, user.id));
|
||||
setUserColor(manager.getUserColor(user.id, false));
|
||||
|
||||
final int userTypeRes = getUserTypeIconRes(user.is_verified, user.is_protected);
|
||||
if (userTypeRes != 0) {
|
||||
@ -85,7 +85,7 @@ public class UserViewHolder extends ViewHolder implements OnClickListener, OnLon
|
||||
} else {
|
||||
profileTypeView.setImageDrawable(null);
|
||||
}
|
||||
nameView.setText(getUserNickname(context, user.id, user.name));
|
||||
nameView.setText(manager.getUserNickname(user.id, user.name, false));
|
||||
screenNameView.setText("@" + user.screen_name);
|
||||
descriptionView.setVisibility(TextUtils.isEmpty(user.description_unescaped) ? View.GONE : View.VISIBLE);
|
||||
descriptionView.setText(user.description_unescaped);
|
||||
|
@ -245,9 +245,7 @@
|
||||
android:horizontalSpacing="@dimen/element_spacing_xsmall"
|
||||
android:verticalSpacing="@dimen/element_spacing_xsmall">
|
||||
|
||||
<include
|
||||
layout="@layout/layout_card_media_preview"
|
||||
tools:ignore="DuplicateIncludedIds"/>
|
||||
<!-- Child views will be inflated if media preview enabled in ViewHolder -->
|
||||
|
||||
</org.mariotaku.twidere.view.CardMediaContainer>
|
||||
|
||||
|
@ -217,8 +217,9 @@
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:textAppearanceSmall"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="10sp"
|
||||
tools:text="\@user"/>
|
||||
tools:ignore="SmallSp"
|
||||
tools:text="\@user"
|
||||
tools:textSize="10sp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<org.mariotaku.twidere.view.CardMediaContainer
|
||||
@ -229,10 +230,9 @@
|
||||
android:layout_marginTop="@dimen/element_spacing_small"
|
||||
android:layout_toRightOf="@+id/quote_indicator"
|
||||
android:horizontalSpacing="@dimen/element_spacing_xsmall"
|
||||
android:verticalSpacing="@dimen/element_spacing_xsmall"
|
||||
tools:ignore="DuplicateIncludedIds">
|
||||
android:verticalSpacing="@dimen/element_spacing_xsmall">
|
||||
|
||||
<include layout="@layout/layout_card_media_preview"/>
|
||||
<!-- Child views will be inflated if media preview enabled in ViewHolder -->
|
||||
|
||||
</org.mariotaku.twidere.view.CardMediaContainer>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user