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