fix search fragment progressbar
This commit is contained in:
parent
5d06e8310d
commit
7bea94144e
2 changed files with 58 additions and 45 deletions
|
@ -15,6 +15,7 @@ import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.schabi.newpipe.ErrorActivity;
|
import org.schabi.newpipe.ErrorActivity;
|
||||||
|
@ -84,6 +85,7 @@ public class SearchInfoItemFragment extends Fragment {
|
||||||
private String searchQuery = "";
|
private String searchQuery = "";
|
||||||
private boolean isLoading = false;
|
private boolean isLoading = false;
|
||||||
|
|
||||||
|
private ProgressBar loadingIndicator = null;
|
||||||
private SearchView searchView = null;
|
private SearchView searchView = null;
|
||||||
private int pageNumber = 0;
|
private int pageNumber = 0;
|
||||||
private SuggestionListAdapter suggestionListAdapter = null;
|
private SuggestionListAdapter suggestionListAdapter = null;
|
||||||
|
@ -135,6 +137,7 @@ public class SearchInfoItemFragment extends Fragment {
|
||||||
public void onResult(SearchResult result) {
|
public void onResult(SearchResult result) {
|
||||||
infoListAdapter.addStreamItemList(result.resultList);
|
infoListAdapter.addStreamItemList(result.resultList);
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
|
loadingIndicator.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -143,6 +146,7 @@ public class SearchInfoItemFragment extends Fragment {
|
||||||
Toast.makeText(getActivity(), getString(stringResource),
|
Toast.makeText(getActivity(), getString(stringResource),
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
|
loadingIndicator.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -151,6 +155,7 @@ public class SearchInfoItemFragment extends Fragment {
|
||||||
Toast.makeText(getActivity(), message,
|
Toast.makeText(getActivity(), message,
|
||||||
Toast.LENGTH_LONG).show();
|
Toast.LENGTH_LONG).show();
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
|
loadingIndicator.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -160,47 +165,44 @@ public class SearchInfoItemFragment extends Fragment {
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_searchinfoitem, container, false);
|
View view = inflater.inflate(R.layout.fragment_searchinfoitem, container, false);
|
||||||
|
|
||||||
// Set the adapter
|
Context context = view.getContext();
|
||||||
if (view instanceof RecyclerView) {
|
loadingIndicator = (ProgressBar) view.findViewById(R.id.progressBar);
|
||||||
Context context = view.getContext();
|
recyclerView = (RecyclerView) view.findViewById(R.id.list);
|
||||||
recyclerView = (RecyclerView) view;
|
streamInfoListLayoutManager = new LinearLayoutManager(context);
|
||||||
streamInfoListLayoutManager = new LinearLayoutManager(context);
|
recyclerView.setLayoutManager(streamInfoListLayoutManager);
|
||||||
recyclerView.setLayoutManager(streamInfoListLayoutManager);
|
|
||||||
|
|
||||||
infoListAdapter = new InfoListAdapter(getActivity(),
|
infoListAdapter = new InfoListAdapter(getActivity(),
|
||||||
getActivity().findViewById(android.R.id.content));
|
getActivity().findViewById(android.R.id.content));
|
||||||
infoListAdapter.setOnItemSelectedListener(new InfoListAdapter.OnItemSelectedListener() {
|
infoListAdapter.setOnItemSelectedListener(new InfoListAdapter.OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void selected(String url) {
|
public void selected(String url) {
|
||||||
Intent i = new Intent(getActivity(), VideoItemDetailActivity.class);
|
Intent i = new Intent(getActivity(), VideoItemDetailActivity.class);
|
||||||
i.putExtra(VideoItemDetailFragment.STREAMING_SERVICE, streamingServiceId);
|
i.putExtra(VideoItemDetailFragment.STREAMING_SERVICE, streamingServiceId);
|
||||||
i.putExtra(VideoItemDetailFragment.VIDEO_URL, url);
|
i.putExtra(VideoItemDetailFragment.VIDEO_URL, url);
|
||||||
getActivity().startActivity(i);
|
getActivity().startActivity(i);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
recyclerView.setAdapter(infoListAdapter);
|
recyclerView.setAdapter(infoListAdapter);
|
||||||
|
|
||||||
|
recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||||
|
int pastVisiblesItems, visibleItemCount, totalItemCount;
|
||||||
|
super.onScrolled(recyclerView, dx, dy);
|
||||||
|
if(dy > 0) //check for scroll down
|
||||||
|
{
|
||||||
|
visibleItemCount = streamInfoListLayoutManager.getChildCount();
|
||||||
|
totalItemCount = streamInfoListLayoutManager.getItemCount();
|
||||||
|
pastVisiblesItems = streamInfoListLayoutManager.findFirstVisibleItemPosition();
|
||||||
|
|
||||||
recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
if ( (visibleItemCount + pastVisiblesItems) >= totalItemCount && !isLoading)
|
||||||
@Override
|
|
||||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
||||||
int pastVisiblesItems, visibleItemCount, totalItemCount;
|
|
||||||
super.onScrolled(recyclerView, dx, dy);
|
|
||||||
if(dy > 0) //check for scroll down
|
|
||||||
{
|
{
|
||||||
visibleItemCount = streamInfoListLayoutManager.getChildCount();
|
pageNumber++;
|
||||||
totalItemCount = streamInfoListLayoutManager.getItemCount();
|
search(searchQuery, pageNumber);
|
||||||
pastVisiblesItems = streamInfoListLayoutManager.findFirstVisibleItemPosition();
|
|
||||||
|
|
||||||
if ( (visibleItemCount + pastVisiblesItems) >= totalItemCount && !isLoading)
|
|
||||||
{
|
|
||||||
pageNumber++;
|
|
||||||
search(searchQuery, pageNumber);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
@ -245,6 +247,7 @@ public class SearchInfoItemFragment extends Fragment {
|
||||||
infoListAdapter.clearSteamItemList();
|
infoListAdapter.clearSteamItemList();
|
||||||
pageNumber = 0;
|
pageNumber = 0;
|
||||||
search(query, pageNumber);
|
search(query, pageNumber);
|
||||||
|
loadingIndicator.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void search(String query, int page) {
|
private void search(String query, int page) {
|
||||||
|
|
|
@ -1,14 +1,24 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/list"
|
|
||||||
android:name="org.schabi.newpipe.SearchInfoItemFragment"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_marginRight="16dp"
|
android:name="org.schabi.newpipe.SearchInfoItemFragment"
|
||||||
app:layoutManager="LinearLayoutManager"
|
tools:context=".search_fragment.SearchInfoItemFragment">
|
||||||
tools:context=".search_fragment.SearchInfoItemFragment"
|
|
||||||
tools:listitem="@layout/video_item"
|
<android.support.v7.widget.RecyclerView
|
||||||
android:scrollbars="vertical"/>
|
android:id="@+id/list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:layoutManager="LinearLayoutManager"
|
||||||
|
tools:listitem="@layout/video_item"
|
||||||
|
android:scrollbars="vertical"/>
|
||||||
|
|
||||||
|
<ProgressBar android:id="@+id/progressBar"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:indeterminate="true"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
</RelativeLayout>
|
||||||
|
|
Loading…
Reference in a new issue