added option to turn new document off, close #387

This commit is contained in:
Mariotaku Lee 2016-03-23 13:27:45 +08:00
parent ad4420abad
commit 2caf013b20
24 changed files with 91 additions and 40 deletions

View File

@ -324,4 +324,6 @@ public interface SharedPreferenceConstants {
String KEY_I_WANT_MY_STARS_BACK = "i_want_my_stars_back";
@Preference(type = STRING, hasDefault = false)
String KEY_EMOJI_SUPPORT = "emoji_support";
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = true)
String KEY_NEW_DOCUMENT_API = "new_document_api";
}

View File

@ -168,14 +168,15 @@ public class QuickSearchBarActivity extends BaseActivity implements OnClickListe
switch (mUsersSearchAdapter.getItemViewType(position)) {
case SuggestionsAdapter.VIEW_TYPE_USER_SUGGESTION_ITEM: {
IntentUtils.openUserProfile(this, getSelectedAccountKey(),
UserKey.valueOf(item.extra_id), item.summary, null, true,
UserKey.valueOf(item.extra_id), item.summary, null,
mPreferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.DIRECT);
finish();
break;
}
case SuggestionsAdapter.VIEW_TYPE_USER_SCREEN_NAME: {
IntentUtils.openUserProfile(this, getSelectedAccountKey(), null, item.title, null, true,
UserFragment.Referral.DIRECT);
IntentUtils.openUserProfile(this, getSelectedAccountKey(), null, item.title, null,
mPreferences.getBoolean(KEY_NEW_DOCUMENT_API), UserFragment.Referral.DIRECT);
finish();
break;
}

View File

@ -28,6 +28,7 @@ import org.mariotaku.twidere.app.TwidereApplication;
import org.mariotaku.twidere.util.MediaLoaderWrapper;
import org.mariotaku.twidere.util.MultiSelectManager;
import org.mariotaku.twidere.util.OnLinkClickHandler;
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
import org.mariotaku.twidere.util.TwidereLinkify;
import org.mariotaku.twidere.util.UserColorNameManager;
import org.mariotaku.twidere.util.Utils;
@ -53,6 +54,8 @@ public class BaseArrayAdapter<T> extends ArrayAdapter<T> implements IBaseAdapter
protected MediaLoaderWrapper mImageLoader;
@Inject
protected MultiSelectManager mMultiSelectManager;
@Inject
protected SharedPreferencesWrapper mPreferences;
public BaseArrayAdapter(final Context context, final int layoutRes) {
this(context, layoutRes, null);
@ -63,7 +66,7 @@ public class BaseArrayAdapter<T> extends ArrayAdapter<T> implements IBaseAdapter
//noinspection unchecked
GeneralComponentHelper.build(context).inject((BaseArrayAdapter<Object>) this);
final TwidereApplication app = TwidereApplication.getInstance(context);
mLinkify = new TwidereLinkify(new OnLinkClickHandler(context, mMultiSelectManager));
mLinkify = new TwidereLinkify(new OnLinkClickHandler(context, mMultiSelectManager, mPreferences));
mNicknamePrefs = context.getSharedPreferences(USER_NICKNAME_PREFERENCES_NAME, Context.MODE_PRIVATE);
mColorPrefs = context.getSharedPreferences(USER_COLOR_PREFERENCES_NAME, Context.MODE_PRIVATE);
mNicknamePrefs.registerOnSharedPreferenceChangeListener(this);

View File

@ -71,7 +71,7 @@ public class MessageConversationAdapter extends BaseRecyclerViewAdapter<ViewHold
public MessageConversationAdapter(final Context context) {
super(context);
mInflater = LayoutInflater.from(context);
mLinkify = new TwidereLinkify(new DirectMessageOnLinkClickHandler(context, null));
mLinkify = new TwidereLinkify(new DirectMessageOnLinkClickHandler(context, null, mPreferences));
mTextSize = mPreferences.getInt(KEY_TEXT_SIZE, context.getResources().getInteger(R.integer.default_text_size));
mDisplayProfileImage = mPreferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true);
mProfileImageStyle = Utils.getProfileImageStyle(mPreferences.getString(KEY_PROFILE_IMAGE_STYLE, null));

View File

@ -87,7 +87,7 @@ public class ParcelableActivitiesAdapter extends LoadMoreSupportAdapter<Recycler
public ParcelableActivitiesAdapter(Context context, boolean compact, boolean byFriends) {
super(context);
mStatusAdapterDelegate = new DummyItemAdapter(context,
new TwidereLinkify(new OnLinkClickHandler(context, null)), this);
new TwidereLinkify(new OnLinkClickHandler(context, null, mPreferences)), this);
mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(context,
ThemeUtils.getThemeBackgroundOption(context),
ThemeUtils.getUserThemeBackgroundAlpha(context));
@ -495,7 +495,8 @@ public class ParcelableActivitiesAdapter extends LoadMoreSupportAdapter<Recycler
final ParcelableStatus status = ParcelableActivityUtils.getActivityStatus(activity);
assert status != null;
IntentUtils.openUserProfile(context, status.account_key, status.user_key,
status.user_screen_name, null, true, UserFragment.Referral.TIMELINE_STATUS);
status.user_screen_name, null, adapter.mPreferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.TIMELINE_STATUS);
}
@Override

View File

@ -102,7 +102,7 @@ public abstract class ParcelableStatusesAdapter extends LoadMoreSupportAdapter<R
mShowCardActions = !mPreferences.getBoolean(KEY_HIDE_CARD_ACTIONS, false);
mUseStarsForLikes = mPreferences.getBoolean(KEY_I_WANT_MY_STARS_BACK);
mShowAbsoluteTime = mPreferences.getBoolean(KEY_SHOW_ABSOLUTE_TIME, false);
mLinkify = new TwidereLinkify(new StatusAdapterLinkClickHandler<>(this));
mLinkify = new TwidereLinkify(new StatusAdapterLinkClickHandler<>(this, mPreferences));
setShowInReplyTo(true);
setHasStableIds(true);
}

View File

@ -421,7 +421,8 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerViewFrag
final FragmentActivity activity = getActivity();
final ParcelableStatus status = getAdapter().getStatus(position);
IntentUtils.openUserProfile(activity, status.account_key, status.user_key,
status.user_screen_name, null, true, UserFragment.Referral.TIMELINE_STATUS);
status.user_screen_name, null, mPreferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.TIMELINE_STATUS);
}
@Override

View File

@ -228,11 +228,13 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo
if (account == null) return;
final FragmentActivity activity = getActivity();
if (account.account_user != null) {
IntentUtils.openUserProfile(activity, account.account_user, null, true,
IntentUtils.openUserProfile(activity, account.account_user, null,
mPreferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.SELF_PROFILE);
} else {
IntentUtils.openUserProfile(activity, account.account_key,
account.account_key, account.screen_name, null, true,
account.account_key, account.screen_name, null,
mPreferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.SELF_PROFILE);
}
break;

View File

@ -155,11 +155,13 @@ public class AccountsManagerFragment extends BaseSupportFragment implements Load
if (context == null) return;
final ParcelableAccount account = mAdapter.getAccount(position);
if (account.account_user != null) {
IntentUtils.openUserProfile(context, account.account_user, null, true,
IntentUtils.openUserProfile(context, account.account_user, null,
mPreferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.SELF_PROFILE);
} else {
IntentUtils.openUserProfile(context, account.account_key, account.account_key,
account.screen_name, null, true, UserFragment.Referral.SELF_PROFILE);
account.screen_name, null, mPreferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.SELF_PROFILE);
}
}

View File

@ -204,7 +204,8 @@ public class DirectMessagesFragment extends AbsContentListRecyclerViewFragment<M
@Override
public void onUserClick(int position, DirectMessageEntry entry) {
IntentUtils.openUserProfile(getActivity(), entry.account_key,
UserKey.valueOf(entry.conversation_id), entry.screen_name, null, true, null);
UserKey.valueOf(entry.conversation_id), entry.screen_name, null,
mPreferences.getBoolean(KEY_NEW_DOCUMENT_API), null);
}
@Subscribe

View File

@ -53,7 +53,8 @@ public class ItemsListFragment extends AbsContentListRecyclerViewFragment<Variou
public void onUserClick(UserViewHolder holder, int position) {
final ParcelableUser user = dummyItemAdapter.getUser(position);
if (user == null) return;
IntentUtils.openUserProfile(getContext(), user, null, true,
IntentUtils.openUserProfile(getContext(), user, null,
mPreferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.TIMELINE_STATUS);
}
});

View File

@ -167,7 +167,8 @@ public abstract class ParcelableUsersFragment extends AbsContentListRecyclerView
final ParcelableUser user = getAdapter().getUser(position);
final FragmentActivity activity = getActivity();
if (UserKeyUtils.isSameHost(user.account_key, user.key)) {
IntentUtils.openUserProfile(activity, user, null, true, getUserReferral());
IntentUtils.openUserProfile(activity, user, null,
mPreferences.getBoolean(KEY_NEW_DOCUMENT_API), getUserReferral());
} else if (user.extras != null && user.extras.statusnet_profile_url != null) {
final Uri uri = Uri.parse(user.extras.statusnet_profile_url);
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);

View File

@ -147,6 +147,7 @@ import org.mariotaku.twidere.util.Nullables;
import org.mariotaku.twidere.util.RecyclerViewNavigationHelper;
import org.mariotaku.twidere.util.RecyclerViewScrollHandler;
import org.mariotaku.twidere.util.RecyclerViewUtils;
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
import org.mariotaku.twidere.util.StatusActionModeCallback;
import org.mariotaku.twidere.util.StatusAdapterLinkClickHandler;
import org.mariotaku.twidere.util.StatusLinkClickHandler;
@ -211,6 +212,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
// Data fields
private boolean mConversationLoaderInitialized;
private boolean mActivityLoaderInitialized;
private boolean mHasMoreConversation = true;
private TweetEvent mStatusEvent;
// Listeners
@ -478,7 +480,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
final FragmentActivity activity = getActivity();
final ParcelableStatus status = mStatusAdapter.getStatus(position);
IntentUtils.openUserProfile(activity, status.account_key, status.user_key,
status.user_screen_name, null, true, UserFragment.Referral.TIMELINE_STATUS);
status.user_screen_name, null, mPreferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.TIMELINE_STATUS);
}
@Override
@ -640,6 +643,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
}
private void setConversation(List<ParcelableStatus> data) {
mHasMoreConversation = data != null && !data.isEmpty();
final ReadPosition readPosition = saveReadPosition();
mStatusAdapter.setData(data);
restoreReadPosition(readPosition);
@ -656,6 +660,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
@Override
public void onLoadMoreContents(@IndicatorPosition int position) {
if (!mHasMoreConversation) return;
if ((position & IndicatorPosition.START) != 0) {
final int start = mStatusAdapter.getIndexStart(StatusAdapter.ITEM_IDX_CONVERSATION);
final ParcelableStatus status = mStatusAdapter.getStatus(start);
@ -957,7 +962,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
public DetailStatusViewHolder(final StatusAdapter adapter, View itemView) {
super(itemView);
this.adapter = adapter;
this.linkClickHandler = new DetailStatusLinkClickHandler(adapter.getContext(), null, adapter);
this.linkClickHandler = new DetailStatusLinkClickHandler(adapter.getContext(), null,
adapter, adapter.getPreferences());
this.linkify = new TwidereLinkify(linkClickHandler);
menuBar = (ActionMenuView) itemView.findViewById(R.id.menu_bar);
nameView = (NameView) itemView.findViewById(R.id.name);
@ -1205,6 +1211,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
final ParcelableStatus status = adapter.getStatus(getLayoutPosition());
final StatusFragment fragment = adapter.getFragment();
if (status == null || fragment == null) return;
final SharedPreferencesWrapper preferences = fragment.mPreferences;
switch (v.getId()) {
case R.id.media_preview_load: {
if (adapter.isSensitiveContentEnabled() || !status.is_possibly_sensitive) {
@ -1218,14 +1225,16 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
case R.id.profile_container: {
final FragmentActivity activity = fragment.getActivity();
IntentUtils.openUserProfile(activity, status.account_key, status.user_key,
status.user_screen_name, null, true, UserFragment.Referral.STATUS);
status.user_screen_name, null, preferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.STATUS);
break;
}
case R.id.retweeted_by: {
if (status.retweet_id != null) {
IntentUtils.openUserProfile(adapter.getContext(), status.account_key,
status.retweeted_by_user_key, status.retweeted_by_user_screen_name,
null, true, UserFragment.Referral.STATUS);
null, preferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.STATUS);
}
break;
}
@ -1238,7 +1247,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
case R.id.quoted_name: {
IntentUtils.openUserProfile(adapter.getContext(), status.account_key,
status.quoted_user_key, status.quoted_user_screen_name, null,
true, UserFragment.Referral.STATUS);
preferences.getBoolean(KEY_NEW_DOCUMENT_API), UserFragment.Referral.STATUS);
break;
}
case R.id.quote_original_link: {
@ -1607,8 +1616,10 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
private static class DetailStatusLinkClickHandler extends StatusLinkClickHandler {
private final StatusAdapter adapter;
public DetailStatusLinkClickHandler(Context context, MultiSelectManager manager, StatusAdapter adapter) {
super(context, manager);
public DetailStatusLinkClickHandler(Context context, MultiSelectManager manager,
StatusAdapter adapter,
SharedPreferencesWrapper preferences) {
super(context, manager, preferences);
this.adapter = adapter;
}
@ -1761,7 +1772,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
} else {
mCardLayoutResource = R.layout.card_item_status;
}
mTwidereLinkify = new TwidereLinkify(new StatusAdapterLinkClickHandler<>(this));
mTwidereLinkify = new TwidereLinkify(new StatusAdapterLinkClickHandler<>(this,
mPreferences));
}
public int findPositionById(long itemId) {

View File

@ -700,7 +700,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
@Referral
final String referral = getArguments().getString(EXTRA_REFERRAL);
IntentUtils.openUserProfile(getActivity(), accountKey, user.key,
user.screen_name, null, true, referral);
user.screen_name, null, mPreferences.getBoolean(KEY_NEW_DOCUMENT_API),
referral);
}
break;
}
@ -1382,8 +1383,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
if (user == null) return;
switch (type) {
case TwidereLinkify.LINK_TYPE_MENTION: {
IntentUtils.openUserProfile(getActivity(), user.account_key, null, link, null, true,
Referral.USER_MENTION);
IntentUtils.openUserProfile(getActivity(), user.account_key, null, link, null,
mPreferences.getBoolean(KEY_NEW_DOCUMENT_API), Referral.USER_MENTION);
break;
}
case TwidereLinkify.LINK_TYPE_HASHTAG: {

View File

@ -336,7 +336,8 @@ public class UserListFragment extends AbsToolbarTabPagesFragment implements OnCl
final ParcelableUserList userList = mUserList;
if (userList == null) return;
IntentUtils.openUserProfile(getActivity(), userList.account_key,
userList.user_key, userList.user_screen_name, null, true, null);
userList.user_key, userList.user_screen_name, null,
mPreferences.getBoolean(KEY_NEW_DOCUMENT_API), null);
break;
}
}

View File

@ -94,7 +94,6 @@ public class UserProfileEditorFragment extends BaseSupportFragment implements On
private AsyncTask<Object, Object, ?> mTask;
private ImageView mProfileImageView;
private ImageView mProfileBannerView;
private MaterialEditText mEditScreenName;
private MaterialEditText mEditName;
private MaterialEditText mEditDescription;
private MaterialEditText mEditLocation;
@ -277,7 +276,6 @@ public class UserProfileEditorFragment extends BaseSupportFragment implements On
mEditProfileContent = view.findViewById(R.id.edit_profile_content);
mProfileBannerView = (ImageView) view.findViewById(R.id.profile_banner);
mProfileImageView = (ImageView) view.findViewById(R.id.profile_image);
mEditScreenName = (MaterialEditText) view.findViewById(R.id.screen_name);
mEditName = (MaterialEditText) view.findViewById(R.id.name);
mEditDescription = (MaterialEditText) view.findViewById(R.id.description);
mEditLocation = (MaterialEditText) view.findViewById(R.id.location);

View File

@ -34,8 +34,9 @@ public class DirectMessageOnLinkClickHandler extends OnLinkClickHandler {
private static final String[] SHORT_LINK_SERVICES = new String[]{"bit.ly", "ow.ly", "tinyurl.com", "goo.gl",
"k6.kz", "is.gd", "tr.im", "x.co", "weepp.ru"};
public DirectMessageOnLinkClickHandler(final Context context, final MultiSelectManager manager) {
super(context, manager);
public DirectMessageOnLinkClickHandler(final Context context, final MultiSelectManager manager,
SharedPreferencesWrapper preferences) {
super(context, manager, preferences);
}
@Override

View File

@ -44,10 +44,14 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants {
protected final Context context;
@Nullable
protected final MultiSelectManager manager;
@NonNull
protected final SharedPreferencesWrapper preferences;
public OnLinkClickHandler(@NonNull final Context context, @Nullable final MultiSelectManager manager) {
public OnLinkClickHandler(@NonNull final Context context, @Nullable final MultiSelectManager manager,
@NonNull SharedPreferencesWrapper preferences) {
this.context = context;
this.manager = manager;
this.preferences = preferences;
}
@Override
@ -64,7 +68,8 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants {
switch (type) {
case TwidereLinkify.LINK_TYPE_MENTION: {
IntentUtils.openUserProfile(context, accountKey, null, link, null, true,
IntentUtils.openUserProfile(context, accountKey, null, link, null,
preferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.USER_MENTION);
break;
}
@ -98,7 +103,8 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants {
}
final String screenName = orig.substring(1, length);
IntentUtils.openUserProfile(context, accountKey, UserKey.valueOf(id),
screenName, null, true, UserFragment.Referral.USER_MENTION);
screenName, null, preferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.USER_MENTION);
break;
}
} else if (TwidereLinkify.isHashSymbol(ch) &&
@ -126,7 +132,8 @@ public class OnLinkClickHandler implements OnLinkClickListener, Constants {
}
case TwidereLinkify.LINK_TYPE_USER_ID: {
IntentUtils.openUserProfile(context, accountKey, UserKey.valueOf(link), null, null,
true, UserFragment.Referral.USER_MENTION);
preferences.getBoolean(KEY_NEW_DOCUMENT_API),
UserFragment.Referral.USER_MENTION);
break;
}
case TwidereLinkify.LINK_TYPE_STATUS: {

View File

@ -33,8 +33,9 @@ public class StatusAdapterLinkClickHandler<D> extends OnLinkClickHandler {
private final IStatusesAdapter<D> adapter;
public StatusAdapterLinkClickHandler(IStatusesAdapter<D> adapter) {
super(adapter.getContext(), null);
public StatusAdapterLinkClickHandler(IStatusesAdapter<D> adapter,
SharedPreferencesWrapper preferences) {
super(adapter.getContext(), null, preferences);
this.adapter = adapter;
}

View File

@ -57,7 +57,7 @@ public class StatusLinkClickHandler extends OnLinkClickHandler {
mStatus = status;
}
public StatusLinkClickHandler(Context context, MultiSelectManager manager) {
super(context, manager);
public StatusLinkClickHandler(Context context, MultiSelectManager manager, SharedPreferencesWrapper preferences) {
super(context, manager, preferences);
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="support_new_document_intent">true</bool>
</resources>

View File

@ -2,6 +2,7 @@
<resources>
<bool name="default_display_tab_label">false</bool>
<bool name="support_new_document_intent">false</bool>
<bool name="home_display_icon">false</bool>
<bool name="has_font_family">false</bool>
<bool name="relative_behind_width">false</bool>

View File

@ -767,4 +767,6 @@
<string name="provider_default">Twidere</string>
<!-- Fanfou is a Chinese micro blogging website http://fanfou.com/ -->
<string name="provider_fanfou">Fanfou</string>
<string name="new_document_api">New Document API</string>
<string name="new_document_api_summary">Open profile and media in new task</string>
</resources>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!--suppress AndroidElementNotAllowed -->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
@ -69,6 +70,13 @@
android:summary="%s"
android:title="@string/timeline_sync_service"/>
<SwitchPreferenceCompat
android:defaultValue="true"
android:enabled="@bool/support_new_document_intent"
android:key="new_document_api"
android:summary="@string/new_document_api_summary"
android:title="@string/new_document_api"/>
</PreferenceCategory>
<PreferenceCategory