Consolidates the main header and removes the now-unneeded FloatingSearchView library. Closes #67

This commit is contained in:
Vavassor 2017-06-19 20:50:40 -04:00
commit 53e6769d55
8 changed files with 84 additions and 191 deletions

View file

@ -19,7 +19,6 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
@ -31,18 +30,11 @@ import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
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.pager.TimelinePagerAdapter;
import com.keylesspalace.tusky.receiver.TimelineReceiver;
@ -91,8 +83,8 @@ public class MainActivity extends BaseActivity {
private AccountHeader headerResult;
private Drawer drawer;
@BindView(R.id.floating_search_view) FloatingSearchView searchView;
@BindView(R.id.floating_btn) FloatingActionButton floatingBtn;
@BindView(R.id.drawer_toggle) ImageButton drawerToggle;
@BindView(R.id.tab_layout) TabLayout tabLayout;
@BindView(R.id.pager) ViewPager viewPager;
@ -122,7 +114,15 @@ public class MainActivity extends BaseActivity {
});
setupDrawer();
setupSearchView();
// Setup the navigation drawer toggle button.
ThemeUtils.setDrawableTint(this, drawerToggle.getDrawable(), R.attr.toolbar_icon_tint);
drawerToggle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawer.openDrawer();
}
});
/* Fetch user info while we're doing other things. This has to be after setting up the
* drawer, though, because its callback touches the header in the drawer. */
@ -376,93 +376,6 @@ public class MainActivity extends BaseActivity {
.show();
}
private void setupSearchView() {
searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout());
// Setup content descriptions for the different elements in the search view.
final View leftAction = searchView.findViewById(R.id.left_action);
leftAction.setContentDescription(getString(R.string.action_open_drawer));
searchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() {
@Override
public void onFocus() {
leftAction.setContentDescription(getString(R.string.action_close));
}
@Override
public void onFocusCleared() {
leftAction.setContentDescription(getString(R.string.action_open_drawer));
}
});
View clearButton = searchView.findViewById(R.id.clear_btn);
clearButton.setContentDescription(getString(R.string.action_clear));
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) {
if (response.isSuccessful()) {
searchView.swapSuggestions(response.body());
searchView.hideProgress();
} else {
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 StyleSpan(Typeface.BOLD), 0, accountSuggestion.getDisplayName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(str);
textView.setMaxLines(1);
textView.setEllipsize(TextUtils.TruncateAt.END);
}
});
}
private void fetchUserInfo() {
SharedPreferences preferences = getPrivatePreferences();
final String domain = preferences.getString("domain", null);

View file

@ -16,14 +16,14 @@
package com.keylesspalace.tusky.entity;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.Spanned;
import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion;
import com.google.gson.annotations.SerializedName;
import com.keylesspalace.tusky.util.HtmlUtils;
import com.keylesspalace.tusky.json.StringWithEmoji;
public class Account implements SearchSuggestion {
public class Account implements Parcelable {
public String id;
@SerializedName("username")
@ -77,11 +77,6 @@ public class Account implements SearchSuggestion {
return displayName.value;
}
@Override
public String getBody() {
return username;
}
@Override
public int describeContents() {
return 0;
@ -103,9 +98,7 @@ public class Account implements SearchSuggestion {
dest.writeString(statusesCount);
}
public Account() {
}
public Account() {}
protected Account(Parcel in) {
id = in.readString();