improved quick search bar - open user profile of screen name you typed directly, no need to open search screen

added user-friendly error page for protected users
This commit is contained in:
Mariotaku Lee 2015-03-20 04:13:01 +08:00
parent 0c1bbaa04a
commit 7b10cb3372
8 changed files with 67 additions and 2 deletions

View File

@ -417,6 +417,10 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On
return ITEM_VIEW_TYPE;
}
public ParcelableUser getUser() {
return mUser;
}
@Override
public void onItemClick(QuickSearchBarActivity activity, int position) {
Utils.openUserProfile(activity, mUser, null);
@ -440,12 +444,53 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On
final String nick = getUserNickname(context, user.id);
text1.setText(TextUtils.isEmpty(nick) ? user.name : adapter.isNicknameOnly() ? nick :
context.getString(R.string.name_with_nickname, user.name, nick));
text2.setVisibility(View.VISIBLE);
text2.setText("@" + user.screen_name);
icon.clearColorFilter();
loader.displayProfileImage(icon, user.profile_image_url);
}
}
static class UserScreenNameItem extends BaseClickableItem {
static final int ITEM_VIEW_TYPE = 3;
private final String mScreenName;
private final long mAccountId;
public UserScreenNameItem(String screenName, long accountId) {
mScreenName = screenName;
mAccountId = accountId;
}
@Override
public int getItemViewType() {
return ITEM_VIEW_TYPE;
}
@Override
public void onItemClick(QuickSearchBarActivity activity, int position) {
Utils.openUserProfile(activity, mAccountId, -1, mScreenName, null);
activity.finish();
}
@Override
public final int getItemLayoutResource() {
return R.layout.list_item_suggestion_user;
}
@Override
public void bindView(SuggestionsAdapter adapter, View view, int position) {
final ImageLoaderWrapper loader = adapter.getImageLoader();
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('@' + mScreenName);
text2.setVisibility(View.GONE);
icon.setColorFilter(text1.getCurrentTextColor(), Mode.SRC_ATOP);
loader.cancelDisplayTask(icon);
icon.setImageResource(R.drawable.ic_action_user);
}
}
public static class SuggestionsAdapter extends BaseAdapter {
@ -581,9 +626,19 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On
CachedUsers.COLUMNS, selection != null ? selection.getSQL() : null,
selectionArgs, orderBy.getSQL());
final CachedIndices usersIndices = new CachedIndices(usersCursor);
final int screenNamePos = result.size();
boolean hasName = false;
for (int i = 0, j = Math.min(5, usersCursor.getCount()); i < j; i++) {
usersCursor.moveToPosition(i);
result.add(new UserSuggestionItem(usersCursor, usersIndices, mAccountId));
final UserSuggestionItem userSuggestionItem = new UserSuggestionItem(usersCursor, usersIndices, mAccountId);
final ParcelableUser user = userSuggestionItem.getUser();
result.add(userSuggestionItem);
if (user.screen_name.equalsIgnoreCase(mQuery)) {
hasName = true;
}
}
if (!hasName) {
result.add(screenNamePos, new UserScreenNameItem(mQuery, mAccountId));
}
usersCursor.close();
} else {

View File

@ -338,6 +338,13 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
mPagesErrorContainer.setVisibility(View.VISIBLE);
final String displayName = UserColorNameUtils.getDisplayName(getActivity(), user);
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()) {
mPagesErrorContainer.setVisibility(View.VISIBLE);
final String displayName = UserColorNameUtils.getDisplayName(getActivity(), user);
mPagesErrorText.setText(getString(R.string.user_protected_summary, displayName));
mPagesErrorIcon.setImageResource(R.drawable.ic_info_locked);
mPagesContent.setVisibility(View.GONE);
} else {
mPagesErrorContainer.setVisibility(View.GONE);
@ -1147,6 +1154,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
mUuckyFooter = headerView.findViewById(R.id.uucky_footer);
mPagesContent = view.findViewById(R.id.pages_content);
mPagesErrorContainer = view.findViewById(R.id.pages_error_container);
mPagesErrorIcon = (ImageView) view.findViewById(R.id.pages_error_icon);
mPagesErrorText = (TextView) view.findViewById(R.id.pages_error_text);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@ -58,6 +58,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="@dimen/element_spacing_large"
android:orientation="vertical"
android:visibility="gone">

View File

@ -732,5 +732,6 @@
<string name="import_export_settings">Import/Export settings</string>
<string name="usage_statistics_header_summary">Twidere took part in some research project, join these projects will make Twidere and some other application better.</string>
<string name="no_tab">No tab</string>
<string name="user_protected_summary">You need to send follow request to this protected user to see tweets</string>
</resources>