Search page fully functional for accounts and hashtags. Closes #44

This commit is contained in:
Vavassor 2017-06-19 15:47:53 -04:00
parent 289e2fbbe1
commit 401dd62af7
6 changed files with 78 additions and 31 deletions

View File

@ -82,7 +82,9 @@
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="@style/Base.Theme.AppCompat" />
<activity android:name=".SearchActivity">
<activity
android:name=".SearchActivity"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>

View File

@ -75,6 +75,15 @@ import retrofit2.Response;
public class MainActivity extends BaseActivity {
private static final String TAG = "MainActivity"; // logging tag
protected static int COMPOSE_RESULT = 1;
private static final long DRAWER_ITEM_EDIT_PROFILE = 0;
private static final long DRAWER_ITEM_FAVOURITES = 1;
private static final long DRAWER_ITEM_MUTED_USERS = 2;
private static final long DRAWER_ITEM_BLOCKED_USERS = 3;
private static final long DRAWER_ITEM_SEARCH = 4;
private static final long DRAWER_ITEM_PREFERENCES = 5;
private static final long DRAWER_ITEM_ABOUT = 6;
private static final long DRAWER_ITEM_LOG_OUT = 7;
private static final long DRAWER_ITEM_FOLLOW_REQUESTS = 8;
private String loggedInAccountId;
private String loggedInAccountUsername;
@ -289,15 +298,15 @@ public class MainActivity extends BaseActivity {
.withHasStableIds(true)
.withSelectedItem(-1)
.addDrawerItems(
new PrimaryDrawerItem().withIdentifier(0).withName(getString(R.string.action_edit_profile)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person),
new PrimaryDrawerItem().withIdentifier(1).withName(getString(R.string.action_view_favourites)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_star),
new PrimaryDrawerItem().withIdentifier(2).withName(getString(R.string.action_view_mutes)).withSelectable(false).withIcon(muteDrawable),
new PrimaryDrawerItem().withIdentifier(3).withName(getString(R.string.action_view_blocks)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_block),
new PrimaryDrawerItem().withIdentifier(4).withName(getString(R.string.action_search)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_search),
new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_EDIT_PROFILE).withName(getString(R.string.action_edit_profile)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person),
new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_FAVOURITES).withName(getString(R.string.action_view_favourites)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_star),
new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_MUTED_USERS).withName(getString(R.string.action_view_mutes)).withSelectable(false).withIcon(muteDrawable),
new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_BLOCKED_USERS).withName(getString(R.string.action_view_blocks)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_block),
new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_SEARCH).withName(getString(R.string.action_search)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_search),
new DividerDrawerItem(),
new SecondaryDrawerItem().withIdentifier(5).withName(getString(R.string.action_view_preferences)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_settings),
new SecondaryDrawerItem().withIdentifier(6).withName(getString(R.string.about_title_activity)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_info),
new SecondaryDrawerItem().withIdentifier(7).withName(getString(R.string.action_logout)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_exit_to_app)
new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_PREFERENCES).withName(getString(R.string.action_view_preferences)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_settings),
new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_ABOUT).withName(getString(R.string.about_title_activity)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_info),
new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_LOG_OUT).withName(getString(R.string.action_logout)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_exit_to_app)
)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
@ -305,32 +314,32 @@ public class MainActivity extends BaseActivity {
if (drawerItem != null) {
long drawerItemIdentifier = drawerItem.getIdentifier();
if (drawerItemIdentifier == 0) {
if (drawerItemIdentifier == DRAWER_ITEM_EDIT_PROFILE) {
Intent intent = new Intent(MainActivity.this, EditProfileActivity.class);
startActivity(intent);
} else if (drawerItemIdentifier == 1) {
} else if (drawerItemIdentifier == DRAWER_ITEM_FAVOURITES) {
Intent intent = new Intent(MainActivity.this, FavouritesActivity.class);
startActivity(intent);
} else if (drawerItemIdentifier == 2) {
} else if (drawerItemIdentifier == DRAWER_ITEM_MUTED_USERS) {
Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
intent.putExtra("type", AccountListActivity.Type.MUTES);
startActivity(intent);
} else if (drawerItemIdentifier == 3) {
} else if (drawerItemIdentifier == DRAWER_ITEM_BLOCKED_USERS) {
Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
intent.putExtra("type", AccountListActivity.Type.BLOCKS);
startActivity(intent);
} else if (drawerItemIdentifier == 4) {
} else if (drawerItemIdentifier == DRAWER_ITEM_SEARCH) {
Intent intent = new Intent(MainActivity.this, SearchActivity.class);
startActivity(intent);
} else if (drawerItemIdentifier == 5) {
} else if (drawerItemIdentifier == DRAWER_ITEM_PREFERENCES) {
Intent intent = new Intent(MainActivity.this, PreferencesActivity.class);
startActivity(intent);
} else if (drawerItemIdentifier == 6) {
} else if (drawerItemIdentifier == DRAWER_ITEM_ABOUT) {
Intent intent = new Intent(MainActivity.this, AboutActivity.class);
startActivity(intent);
} else if (drawerItemIdentifier == 7) {
} else if (drawerItemIdentifier == DRAWER_ITEM_LOG_OUT) {
logout();
} else if (drawerItemIdentifier == 8) {
} else if (drawerItemIdentifier == DRAWER_ITEM_FOLLOW_REQUESTS) {
Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
intent.putExtra("type", AccountListActivity.Type.FOLLOW_REQUESTS);
startActivity(intent);
@ -516,7 +525,7 @@ public class MainActivity extends BaseActivity {
// Show follow requests in the menu, if this is a locked account.
if (me.locked) {
PrimaryDrawerItem followRequestsItem = new PrimaryDrawerItem()
.withIdentifier(8)
.withIdentifier(DRAWER_ITEM_FOLLOW_REQUESTS)
.withName(R.string.action_view_follow_requests)
.withSelectable(false)
.withIcon(GoogleMaterial.Icon.gmd_person_add);

View File

@ -35,20 +35,20 @@ import android.widget.TextView;
import com.keylesspalace.tusky.adapter.SearchResultsAdapter;
import com.keylesspalace.tusky.entity.SearchResults;
import com.keylesspalace.tusky.interfaces.LinkListener;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class SearchActivity extends BaseActivity implements SearchView.OnQueryTextListener {
public class SearchActivity extends BaseActivity implements SearchView.OnQueryTextListener,
LinkListener {
private static final String TAG = "SearchActivity"; // logging tag
@BindView(R.id.progress_bar) ProgressBar progressBar;
@BindView(R.id.message_no_results) TextView messageNoResults;
private ProgressBar progressBar;
private TextView messageNoResults;
private SearchResultsAdapter adapter;
private String currentQuery;
@ -56,7 +56,9 @@ public class SearchActivity extends BaseActivity implements SearchView.OnQueryTe
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
ButterKnife.bind(this);
progressBar = (ProgressBar) findViewById(R.id.progress_bar);
messageNoResults = (TextView) findViewById(R.id.message_no_results);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
@ -69,7 +71,7 @@ public class SearchActivity extends BaseActivity implements SearchView.OnQueryTe
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new SearchResultsAdapter();
adapter = new SearchResultsAdapter(this);
recyclerView.setAdapter(adapter);
handleIntent(getIntent());
@ -117,6 +119,20 @@ public class SearchActivity extends BaseActivity implements SearchView.OnQueryTe
return false;
}
@Override
public void onViewAccount(String id) {
Intent intent = new Intent(this, AccountActivity.class);
intent.putExtra("id", id);
startActivity(intent);
}
@Override
public void onViewTag(String tag) {
Intent intent = new Intent(this, ViewTagActivity.class);
intent.putExtra("hashtag", tag);
startActivity(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
currentQuery = intent.getStringExtra(SearchManager.QUERY);

View File

@ -8,6 +8,7 @@ import android.widget.TextView;
import com.keylesspalace.tusky.R;
import com.keylesspalace.tusky.entity.Account;
import com.keylesspalace.tusky.interfaces.AccountActionListener;
import com.keylesspalace.tusky.interfaces.LinkListener;
import com.pkmmte.view.CircularImageView;
import com.squareup.picasso.Picasso;
@ -48,4 +49,13 @@ class AccountViewHolder extends RecyclerView.ViewHolder {
}
});
}
void setupLinkListener(final LinkListener listener) {
container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onViewAccount(id);
}
});
}
}

View File

@ -24,6 +24,7 @@ import android.widget.TextView;
import com.keylesspalace.tusky.R;
import com.keylesspalace.tusky.entity.Account;
import com.keylesspalace.tusky.entity.SearchResults;
import com.keylesspalace.tusky.interfaces.LinkListener;
import java.util.ArrayList;
import java.util.Arrays;
@ -35,11 +36,13 @@ public class SearchResultsAdapter extends RecyclerView.Adapter {
private List<Account> accountList;
private List<String> hashtagList;
private LinkListener linkListener;
public SearchResultsAdapter() {
public SearchResultsAdapter(LinkListener listener) {
super();
accountList = new ArrayList<>();
hashtagList = new ArrayList<>();
linkListener = listener;
}
@Override
@ -64,10 +67,11 @@ public class SearchResultsAdapter extends RecyclerView.Adapter {
if (position < accountList.size()) {
AccountViewHolder holder = (AccountViewHolder) viewHolder;
holder.setupWithAccount(accountList.get(position));
holder.setupLinkListener(linkListener);
} else {
HashtagViewHolder holder = (HashtagViewHolder) viewHolder;
int index = position - accountList.size();
holder.setHashtag(hashtagList.get(index));
holder.setup(hashtagList.get(index), linkListener);
}
}
@ -108,8 +112,14 @@ public class SearchResultsAdapter extends RecyclerView.Adapter {
hashtag = (TextView) itemView.findViewById(R.id.hashtag);
}
void setHashtag(String tag) {
void setup(final String tag, final LinkListener listener) {
hashtag.setText(String.format("#%s", tag));
hashtag.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onViewTag(tag);
}
});
}
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/hashtag"
android:padding="8dp" />
android:padding="16dp" />