fixed cards not reseting properly when clearing results
This commit is contained in:
parent
570dcfc94e
commit
21b6847a23
3 changed files with 26 additions and 19 deletions
|
|
@ -156,7 +156,6 @@ public class HomeRecyclerViewAdapter extends RecyclerView.Adapter<HomeRecyclerVi
|
|||
public void setVideoList(ArrayList<Video> list, boolean reset){
|
||||
int size = videoList.size();
|
||||
if(reset || size == 0) clear();
|
||||
Log.e("TAG", String.valueOf(videoList.size()));
|
||||
videoList.addAll(list);
|
||||
notifyItemRangeInserted(size, videoList.size());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -252,6 +252,8 @@ public class YoutubeAPIManager {
|
|||
}
|
||||
|
||||
public ArrayList<Video> getTrending(Context context) throws JSONException{
|
||||
videos = new ArrayList<>();
|
||||
|
||||
String url = "https://www.googleapis.com/youtube/v3/videos?part=snippet&chart=mostPopular&videoCategoryId=10®ionCode="+countryCODE+"&maxResults=25&key="+key;
|
||||
//short data
|
||||
JSONObject res = genericRequest(url);
|
||||
|
|
@ -277,7 +279,6 @@ public class YoutubeAPIManager {
|
|||
}
|
||||
videos.add(v);
|
||||
}
|
||||
|
||||
return videos;
|
||||
}
|
||||
|
||||
|
|
@ -366,7 +367,7 @@ public class YoutubeAPIManager {
|
|||
// return searchHints;
|
||||
// }
|
||||
|
||||
public class PlaylistTuple {
|
||||
public static class PlaylistTuple {
|
||||
String nextPageToken;
|
||||
ArrayList<Video> videos;
|
||||
|
||||
|
|
|
|||
|
|
@ -181,9 +181,9 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
|
||||
|
||||
private void initCards() {
|
||||
homeRecyclerViewAdapter.clear();
|
||||
shimmerCards.startShimmer();
|
||||
shimmerCards.setVisibility(View.VISIBLE);
|
||||
homeRecyclerViewAdapter.clear();
|
||||
try {
|
||||
Thread thread = new Thread(() -> {
|
||||
Handler uiHandler = new Handler(Looper.getMainLooper());
|
||||
|
|
@ -204,6 +204,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
uiHandler.post(() -> {
|
||||
homeRecyclerViewAdapter.setVideoList(resultObjects, true);
|
||||
shimmerCards.stopShimmer();
|
||||
|
|
@ -233,6 +234,10 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
}
|
||||
};
|
||||
|
||||
if(mainActivity.isDownloadServiceRunning()){
|
||||
topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(true);
|
||||
}
|
||||
|
||||
topAppBar.getMenu().findItem(R.id.search).setOnActionExpandListener(onActionExpandListener);
|
||||
SearchView searchView = (SearchView) topAppBar.getMenu().findItem(R.id.search).getActionView();
|
||||
searchView.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
|
||||
|
|
@ -260,28 +265,30 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
int itemId = m.getItemId();
|
||||
if(itemId == R.id.delete_results){
|
||||
dbManager.clearResults();
|
||||
recyclerView.removeAllViews();
|
||||
selectedObjects = new ArrayList<>();
|
||||
downloadAllFab.setVisibility(View.GONE);
|
||||
downloadFabs.setVisibility(View.GONE);
|
||||
initCards();
|
||||
}else if(itemId == R.id.cancel_download){
|
||||
compositeDisposable.clear();
|
||||
mainActivity.stopDownloadService();
|
||||
topAppBar.getMenu().findItem(itemId).setVisible(false);
|
||||
downloadQueue = new LinkedList<>();
|
||||
downloading = false;
|
||||
try{
|
||||
compositeDisposable.clear();
|
||||
mainActivity.stopDownloadService();
|
||||
topAppBar.getMenu().findItem(itemId).setVisible(false);
|
||||
downloadQueue = new LinkedList<>();
|
||||
downloading = false;
|
||||
|
||||
String id = progressBar.getTag().toString().split("##progress")[0];
|
||||
String type = findVideo(id).getDownloadedType();
|
||||
MaterialButton theClickedButton = recyclerView.findViewWithTag(id + "##"+type);
|
||||
String id = progressBar.getTag().toString().split("##progress")[0];
|
||||
String type = findVideo(id).getDownloadedType();
|
||||
MaterialButton theClickedButton = recyclerView.findViewWithTag(id + "##"+type);
|
||||
|
||||
if (theClickedButton != null) {
|
||||
if (type.equals("mp3")) {
|
||||
theClickedButton.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_music_stopped));
|
||||
} else {
|
||||
theClickedButton.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_video_stopped));
|
||||
if (theClickedButton != null) {
|
||||
if (type.equals("mp3")) {
|
||||
theClickedButton.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_music_stopped));
|
||||
} else {
|
||||
theClickedButton.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_video_stopped));
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(Exception ignored){}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue