Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Search Result page #85

Merged
merged 59 commits into from
May 2, 2017
Merged

Improve Search Result page #85

merged 59 commits into from
May 2, 2017

Conversation

coryroy
Copy link
Contributor

@coryroy coryroy commented Apr 25, 2017

What

  • Add Baseball style project cards to search
  • Add clearer reference tags
  • Refactor into new style with ViewModels inside ViewHolders

@coryroy coryroy requested a review from luoser April 25, 2017 21:57
@coryroy coryroy requested a review from mbrandonw April 26, 2017 16:21
@coryroy
Copy link
Contributor Author

coryroy commented Apr 28, 2017

device-2017-04-28-121625

Updated layout to top align with padding

Copy link
Contributor

@mbrandonw mbrandonw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woot! think we're done with this one! great job!

@@ -4,6 +4,7 @@
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.util.Pair;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this jazz?

final Intent intent = new Intent(this, ProjectActivity.class)
.putExtra(IntentKey.PROJECT, project)
.putExtra(IntentKey.REF_TAG, RefTag.search());
.putExtra(IntentKey.REF_TAG, didSearch() ? refTags.first : refTags.second);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont wanna put logic here

@@ -27,29 +27,41 @@ public void loadPopularProjects(final @NonNull List<Project> newProjects) {
if (newProjects.size() == 0) {
addSection(Collections.emptyList());
} else {
addSection(Collections.singletonList(null));
addSection(getFeatureProject(newProjects));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor this

this.viewModel.outputs.projectName()
.compose(bindToLifecycle())
.compose(observeForUI())
.subscribe(this::setProjectName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can do .subscribe(this.projectNameTextView::setText);

scheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);
final TestSubscriber<RefTag> projectClicked = new TestSubscriber<>();
viewModel.outputs.searchProjects().map(sp -> sp.get(0)).subscribe(viewModel.inputs::tappedProject);
viewModel.outputs.goToProject().map(p -> p.second).subscribe(projectClicked);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to attach test subscribers immediately and we shouldn't be hitting vm inputs like that

@@ -38,6 +42,8 @@

/** Emits list of projects matching criteria. */
Observable<List<Project>> searchProjects();

Observable<Pair<Project, RefTag>> goToProject();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alpha

@@ -30,6 +32,8 @@

/** Call when text changes in search box. */
void search(final @NonNull String s);

void tappedProject(final @NonNull Project project);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment

Copy link
Contributor

@luoser luoser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few changes and questions


protected @Bind(R.id.search_term_text_view) TextView termTextView;
protected @Bind(R.id.search_term_view) LinearLayout layout;
@Bind(R.id.search_term_text_view) TextView termTextView;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can name this searchTermTextView to match the id

@Bind(R.id.project_name_text_view) TextView projectNameTextView;
@Bind(R.id.project_image_view) ImageView projectImageView;
@Bind(R.id.project_stats_text_view_pct_complete_data) TextView projectStatsPctCompleteDataTextView;
@Bind(R.id.project_stats_text_view_pct_complete_string) TextView projectStatsPctCompleteStringTextView;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious as to what Pct stands for? it's not a very intuitive abbreviation for me

Copy link
Contributor Author

@coryroy coryroy May 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Percent. What would you prefer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it to percent. We can shorten it to something else if you prefer.


((KSApplication) view.getContext().getApplicationContext()).component().inject(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

niiice

this.viewModel.inputs.configureWith(configData);
}

void setProjectImage(final String imageUrl) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can mark this and the following method as private and the param as @NonNull

} else {
projectImageView.setVisibility(View.INVISIBLE);
}
void setProjectStats(final Pair<Integer, Integer> stats) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, private method, nonnull param

android:textColor="@color/gray_black"
tools:text="@string/search_most_popular" />

</LinearLayout>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

@@ -69,6 +69,8 @@
<dimen name="comment_body_padding_x">@dimen/grid_7</dimen>
<dimen name="feed_padding_y">@dimen/grid_5_half</dimen>
<dimen name="feed_padding_x">@dimen/grid_2</dimen>
<dimen name="search_padding_y">@dimen/grid_new_2</dimen>
<dimen name="search_padding_x">@dimen/grid_new_2</dimen>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍

private final TestSubscriber<String> projectName = new TestSubscriber<>();
private final TestSubscriber<Pair<Integer, Integer>> projectStats = new TestSubscriber<>();

@Before
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this annotation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to have it run before each test we do. I have now made it override parent setUp and passing the resulting environment


@Before
public void setUpEnvironment() {
this.vm = new ProjectSearchResultHolderViewModel.ViewModel(environment());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know we have access to the environment within our test files, but it's good practice to pass in the environment in the method in case we need to modify it within each test in the future

KoalaEvent.CLEARED_SEARCH_TERM);
}

void testSearchPagination() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing @Test annotation, and should be marked public

this.popularProjects.asObservable(),
this.searchProjects.asObservable()
this.popularProjects,
this.searchProjects
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh good catch. I did that. didn't know you could merge subjects, thought you had to get into the observable under the hood.

Copy link
Contributor

@luoser luoser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some more small code style things i've mentioned before, but looks good!

@@ -34,7 +34,7 @@ public KSViewHolder(final @NonNull View view) {
*/
@Override
public void onClick(final @NonNull View view) {
Timber.d("Default KSViewHolder onClick event");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't change since it's describing the default value, i.e. not every VH onClick will be a project click


import butterknife.Bind;
import butterknife.BindString;
import butterknife.ButterKnife;

public final class SearchTermViewHolder extends KSViewHolder {
private DiscoveryParams params;
public class PopularSearchTitleViewHolder extends KSViewHolder {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class should be final, in general make sure our classes are final

this.viewModel.inputs.configureWith(configData);
}

private void setProjectImage(@NonNull final String imageUrl) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final @NonNull

} else {
projectImageView.setVisibility(View.INVISIBLE);
}
private void setProjectStats(@NonNull final Pair<Integer, Integer> stats) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here final @NonNull

private final PublishSubject<String> search = PublishSubject.create();

private final BehaviorSubject<List<Project>> popularProjects = BehaviorSubject.create();
private final BehaviorSubject<List<Project>> searchProjects = BehaviorSubject.create();
private final BehaviorSubject<Pair<Project, RefTag>> goToProject = BehaviorSubject.create();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can alphabetize this

@Override public void search(final @NonNull String s) {
this.search.onNext(s);
}

@Override public Observable<Pair<Project, RefTag>> goToProject() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NonNull observable for all these outputs

android:textColor="@color/gray_black"
tools:text="@string/Popular_Projects" />

</LinearLayout>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

import java.util.Collections;
import java.util.List;

public class SearchAdapterTest extends KSRobolectricTestCase implements SearchAdapter.Delegate {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final, but also 🎉 our first adapter test!!

scheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);
viewModel.inputs.projectClicked(projects.get(0));

goToRefTag.assertValues(RefTag.searchFeatured());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so great to have tests for this kind of business logic

scheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);

projectList.assertValueCount(2);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra newline

@coryroy coryroy merged commit ecb0224 into master May 2, 2017
@coryroy coryroy deleted the update_search_result_list branch May 2, 2017 22:21
@luoser luoser mentioned this pull request May 8, 2017
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants