Implement search
When displaying displayName, fallback to local username
This commit is contained in:
parent
851a92a271
commit
dbed424d6f
8 changed files with 133 additions and 11 deletions
|
@ -180,7 +180,7 @@ public class AccountActivity extends BaseActivity {
|
||||||
getString(R.string.status_username_format), account.username);
|
getString(R.string.status_username_format), account.username);
|
||||||
username.setText(usernameFormatted);
|
username.setText(usernameFormatted);
|
||||||
|
|
||||||
displayName.setText(account.displayName);
|
displayName.setText(account.getDisplayName());
|
||||||
|
|
||||||
note.setText(account.note);
|
note.setText(account.note);
|
||||||
note.setLinksClickable(true);
|
note.setLinksClickable(true);
|
||||||
|
|
|
@ -105,7 +105,7 @@ class BlocksAdapter extends AccountAdapter {
|
||||||
|
|
||||||
void setupWithAccount(Account account) {
|
void setupWithAccount(Account account) {
|
||||||
id = account.id;
|
id = account.id;
|
||||||
displayName.setText(account.displayName);
|
displayName.setText(account.getDisplayName());
|
||||||
String format = username.getContext().getString(R.string.status_username_format);
|
String format = username.getContext().getString(R.string.status_username_format);
|
||||||
String formattedUsername = String.format(format, account.username);
|
String formattedUsername = String.format(format, account.username);
|
||||||
username.setText(formattedUsername);
|
username.setText(formattedUsername);
|
||||||
|
|
|
@ -95,7 +95,7 @@ class FollowAdapter extends AccountAdapter {
|
||||||
String format = username.getContext().getString(R.string.status_username_format);
|
String format = username.getContext().getString(R.string.status_username_format);
|
||||||
String formattedUsername = String.format(format, account.username);
|
String formattedUsername = String.format(format, account.username);
|
||||||
username.setText(formattedUsername);
|
username.setText(formattedUsername);
|
||||||
displayName.setText(account.displayName);
|
displayName.setText(account.getDisplayName());
|
||||||
note.setText(account.note);
|
note.setText(account.note);
|
||||||
Context context = avatar.getContext();
|
Context context = avatar.getContext();
|
||||||
Picasso.with(context)
|
Picasso.with(context)
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
@ -29,10 +30,17 @@ import android.support.design.widget.TabLayout;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.Spanned;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.arlib.floatingsearchview.FloatingSearchView;
|
import com.arlib.floatingsearchview.FloatingSearchView;
|
||||||
|
import com.arlib.floatingsearchview.suggestions.SearchSuggestionsAdapter;
|
||||||
|
import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion;
|
||||||
import com.keylesspalace.tusky.entity.Account;
|
import com.keylesspalace.tusky.entity.Account;
|
||||||
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
||||||
import com.mikepenz.materialdrawer.AccountHeader;
|
import com.mikepenz.materialdrawer.AccountHeader;
|
||||||
|
@ -49,10 +57,12 @@ import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader;
|
||||||
import com.mikepenz.materialdrawer.util.DrawerImageLoader;
|
import com.mikepenz.materialdrawer.util.DrawerImageLoader;
|
||||||
import com.squareup.picasso.Picasso;
|
import com.squareup.picasso.Picasso;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity {
|
public class MainActivity extends BaseActivity {
|
||||||
private static final String TAG = "MainActivity"; // logging tag and Volley request tag
|
private static final String TAG = "MainActivity"; // logging tag and Volley request tag
|
||||||
|
@ -164,6 +174,70 @@ public class MainActivity extends BaseActivity {
|
||||||
|
|
||||||
searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout());
|
searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout());
|
||||||
|
|
||||||
|
searchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onSearchTextChanged(String oldQuery, String newQuery) {
|
||||||
|
if (!oldQuery.equals("") && newQuery.equals("")) {
|
||||||
|
searchView.clearSuggestions();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newQuery.length() < 3) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
searchView.showProgress();
|
||||||
|
|
||||||
|
mastodonAPI.searchAccounts(newQuery, false, 5).enqueue(new Callback<List<Account>>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<List<Account>> call, Response<List<Account>> response) {
|
||||||
|
searchView.swapSuggestions(response.body());
|
||||||
|
searchView.hideProgress();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<List<Account>> call, Throwable t) {
|
||||||
|
searchView.hideProgress();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
searchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {
|
||||||
|
@Override
|
||||||
|
public void onSuggestionClicked(SearchSuggestion searchSuggestion) {
|
||||||
|
Account accountSuggestion = (Account) searchSuggestion;
|
||||||
|
Intent intent = new Intent(MainActivity.this, AccountActivity.class);
|
||||||
|
intent.putExtra("id", accountSuggestion.id);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSearchAction(String currentQuery) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
searchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() {
|
||||||
|
@Override
|
||||||
|
public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView, SearchSuggestion item, int itemPosition) {
|
||||||
|
Account accountSuggestion = ((Account) item);
|
||||||
|
|
||||||
|
Picasso.with(MainActivity.this)
|
||||||
|
.load(accountSuggestion.avatar)
|
||||||
|
.placeholder(R.drawable.avatar_default)
|
||||||
|
.into(leftIcon);
|
||||||
|
|
||||||
|
String searchStr = accountSuggestion.getDisplayName() + " " + accountSuggestion.username;
|
||||||
|
final SpannableStringBuilder str = new SpannableStringBuilder(searchStr);
|
||||||
|
|
||||||
|
str.setSpan(new android.text.style.StyleSpan(Typeface.BOLD), 0, accountSuggestion.getDisplayName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
textView.setText(str);
|
||||||
|
textView.setMaxLines(1);
|
||||||
|
textView.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Setup the tabs and timeline pager.
|
// Setup the tabs and timeline pager.
|
||||||
TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager());
|
TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager());
|
||||||
String[] pageTitles = {
|
String[] pageTitles = {
|
||||||
|
@ -256,12 +330,12 @@ public class MainActivity extends BaseActivity {
|
||||||
|
|
||||||
headerResult.addProfiles(
|
headerResult.addProfiles(
|
||||||
new ProfileDrawerItem()
|
new ProfileDrawerItem()
|
||||||
.withName(me.displayName)
|
.withName(me.getDisplayName())
|
||||||
.withEmail(String.format("%s@%s", me.username, domain))
|
.withEmail(String.format("%s@%s", me.username, domain))
|
||||||
.withIcon(me.avatar)
|
.withIcon(me.avatar)
|
||||||
);
|
);
|
||||||
|
|
||||||
//onFetchUserInfoSuccess(response.body().id, response.body().username);
|
onFetchUserInfoSuccess(me.id, me.username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -96,13 +96,13 @@ class NotificationsAdapter extends RecyclerView.Adapter implements AdapterItemRe
|
||||||
case FAVOURITE:
|
case FAVOURITE:
|
||||||
case REBLOG: {
|
case REBLOG: {
|
||||||
StatusNotificationViewHolder holder = (StatusNotificationViewHolder) viewHolder;
|
StatusNotificationViewHolder holder = (StatusNotificationViewHolder) viewHolder;
|
||||||
holder.setMessage(type, notification.account.displayName,
|
holder.setMessage(type, notification.account.getDisplayName(),
|
||||||
notification.status);
|
notification.status);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FOLLOW: {
|
case FOLLOW: {
|
||||||
FollowViewHolder holder = (FollowViewHolder) viewHolder;
|
FollowViewHolder holder = (FollowViewHolder) viewHolder;
|
||||||
holder.setMessage(notification.account.displayName, notification.account.username,
|
holder.setMessage(notification.account.getDisplayName(), notification.account.username,
|
||||||
notification.account.avatar);
|
notification.account.avatar);
|
||||||
holder.setupButtons(followListener, notification.account.id);
|
holder.setupButtons(followListener, notification.account.id);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -119,7 +119,7 @@ public class PullNotificationService extends IntentService {
|
||||||
if (status != null) {
|
if (status != null) {
|
||||||
MentionResult mention = new MentionResult();
|
MentionResult mention = new MentionResult();
|
||||||
mention.content = status.content.toString();
|
mention.content = status.content.toString();
|
||||||
mention.displayName = notification.account.displayName;
|
mention.displayName = notification.account.getDisplayName();
|
||||||
mention.avatarUrl = status.account.avatar;
|
mention.avatarUrl = status.account.avatar;
|
||||||
mentions.add(mention);
|
mentions.add(mention);
|
||||||
}
|
}
|
||||||
|
|
|
@ -343,14 +343,14 @@ class StatusViewHolder extends RecyclerView.ViewHolder {
|
||||||
void setupWithStatus(Status status, StatusActionListener listener) {
|
void setupWithStatus(Status status, StatusActionListener listener) {
|
||||||
Status realStatus = status.getActionableStatus();
|
Status realStatus = status.getActionableStatus();
|
||||||
|
|
||||||
setDisplayName(realStatus.account.displayName);
|
setDisplayName(realStatus.account.getDisplayName());
|
||||||
setUsername(realStatus.account.username);
|
setUsername(realStatus.account.username);
|
||||||
setCreatedAt(realStatus.createdAt);
|
setCreatedAt(realStatus.createdAt);
|
||||||
setContent(realStatus.content, realStatus.mentions, listener);
|
setContent(realStatus.content, realStatus.mentions, listener);
|
||||||
setAvatar(realStatus.account.avatar);
|
setAvatar(realStatus.account.avatar);
|
||||||
setReblogged(realStatus.reblogged);
|
setReblogged(realStatus.reblogged);
|
||||||
setFavourited(realStatus.favourited);
|
setFavourited(realStatus.favourited);
|
||||||
String rebloggedByDisplayName = status.account.displayName;
|
String rebloggedByDisplayName = status.account.getDisplayName();
|
||||||
if (status.reblog == null) {
|
if (status.reblog == null) {
|
||||||
hideRebloggedByDisplayName();
|
hideRebloggedByDisplayName();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -15,13 +15,18 @@
|
||||||
|
|
||||||
package com.keylesspalace.tusky.entity;
|
package com.keylesspalace.tusky.entity;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
|
|
||||||
|
import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
public class Account {
|
public class Account implements SearchSuggestion {
|
||||||
public String id;
|
public String id;
|
||||||
|
|
||||||
|
@SerializedName("username")
|
||||||
|
public String localUsername;
|
||||||
|
|
||||||
@SerializedName("acct")
|
@SerializedName("acct")
|
||||||
public String username;
|
public String username;
|
||||||
|
|
||||||
|
@ -62,4 +67,47 @@ public class Account {
|
||||||
Account account = (Account) other;
|
Account account = (Account) other;
|
||||||
return account.id.equals(this.id);
|
return account.id.equals(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
if (displayName.length() == 0) {
|
||||||
|
return localUsername;
|
||||||
|
}
|
||||||
|
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBody() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Account() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Account(Parcel in) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<Account> CREATOR = new Creator<Account>() {
|
||||||
|
@Override
|
||||||
|
public Account createFromParcel(Parcel source) {
|
||||||
|
return new Account(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Account[] newArray(int size) {
|
||||||
|
return new Account[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue