Skip to content

Commit a98154e

Browse files
committed
Clear focus after search & add loading buffer
1 parent 39204cf commit a98154e

File tree

3 files changed

+10
-30
lines changed

3 files changed

+10
-30
lines changed

app/src/main/java/com/spotify/sdk/android/MainActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ protected void onCreate(Bundle savedInstanceState) {
5353
mActionListener.init(token);
5454

5555
// Setup search field
56-
SearchView searchView = (SearchView) findViewById(R.id.search_view);
56+
final SearchView searchView = (SearchView) findViewById(R.id.search_view);
5757
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
5858
@Override
5959
public boolean onQueryTextSubmit(String query) {
6060
mActionListener.search(query);
61+
searchView.clearFocus();
6162
return true;
6263
}
6364

app/src/main/java/com/spotify/sdk/android/ResultListScrollListener.java

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
/*
2-
* Copyright (c) 2015 Spotify AB
3-
*
4-
* Licensed to the Apache Software Foundation (ASF) under one
5-
* or more contributor license agreements. See the NOTICE file
6-
* distributed with this work for additional information
7-
* regarding copyright ownership. The ASF licenses this file
8-
* to you under the Apache License, Version 2.0 (the
9-
* "License"); you may not use this file except in compliance
10-
* with the License. You may obtain a copy of the License at
11-
*
12-
* http://www.apache.org/licenses/LICENSE-2.0
13-
*
14-
* Unless required by applicable law or agreed to in writing,
15-
* software distributed under the License is distributed on an
16-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17-
* KIND, either express or implied. See the License for the
18-
* specific language governing permissions and limitations
19-
* under the License.
20-
*/
21-
22-
231
package com.spotify.sdk.android;
242

253
import android.support.v7.widget.LinearLayoutManager;
@@ -32,7 +10,8 @@ public abstract class ResultListScrollListener extends RecyclerView.OnScrollList
3210

3311
private final LinearLayoutManager mLayoutManager;
3412

35-
private int mItemCount;
13+
private static final int SCROLL_BUFFER = 3;
14+
private int mCurrentItemCount = 0;
3615

3716
private boolean mAwaitingItems = true;
3817

@@ -41,7 +20,7 @@ public ResultListScrollListener(LinearLayoutManager layoutManager) {
4120
}
4221

4322
public void reset() {
44-
mItemCount = 0;
23+
mCurrentItemCount = 0;
4524
}
4625

4726
@Override
@@ -51,14 +30,14 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
5130
int itemCount = mLayoutManager.getItemCount();
5231
int itemPosition = mLayoutManager.findLastVisibleItemPosition();
5332

54-
if (mAwaitingItems && itemCount > mItemCount) {
55-
mItemCount = itemCount;
33+
if (mAwaitingItems && itemCount > mCurrentItemCount) {
34+
mCurrentItemCount = itemCount;
5635
mAwaitingItems = false;
5736
}
5837

59-
Log.d(TAG, String.format("loading %s, item count: %s/%s, itemPosition %s", mAwaitingItems, mItemCount, itemCount, itemPosition));
38+
Log.d(TAG, String.format("loading %s, item count: %s/%s, itemPosition %s", mAwaitingItems, mCurrentItemCount, itemCount, itemPosition));
6039

61-
if (!mAwaitingItems && (itemCount <= itemPosition + 1)) {
40+
if (!mAwaitingItems && itemPosition + 1 >= itemCount - SCROLL_BUFFER) {
6241
mAwaitingItems = true;
6342
onLoadMore();
6443
}

app/src/main/java/com/spotify/sdk/android/SearchPresenter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void onComplete(List<Track> items) {
7676

7777
@Override
7878
public void onError(Throwable error) {
79-
Log.e(TAG, error.getMessage());
79+
logError(error.getMessage());
8080
}
8181
};
8282
mSearchPager.getFirstPage(searchQuery, PAGE_SIZE, mSearchListener);

0 commit comments

Comments
 (0)