finished download states on home fragment

handled download states through the recyclerview so that they are correct even if the app is killed and reopened
This commit is contained in:
Denis Çerri 2022-10-05 01:46:58 +02:00
parent b93ed7309e
commit e86b44ee51
No known key found for this signature in database
GPG key ID: 3F50F14A8E7F7A13
12 changed files with 216 additions and 98 deletions

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="192.168.1.131:46883" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-10-04T21:20:22.834747800Z" />
</component>
</project>

View file

@ -156,12 +156,13 @@ public class DownloaderService extends Service {
}
}
public void cancelDownload(){
public void cancelDownload(boolean cancelAll){
try{
YoutubeDL.getInstance().destroyProcessById(downloadProcessID);
compositeDisposable.clear();
//stopForeground(true);
onDownloadEnd();
if (cancelAll) onDownloadCancel();
else onDownloadEnd();
}catch(Exception err){
Log.e(TAG, err.getMessage());
}
@ -170,7 +171,7 @@ public class DownloaderService extends Service {
public void removeItemFromDownloadQueue(Video video){
//if its the same video with the same download type as the current downloading one
if (downloadInfo.getVideo().getURL().equals(video.getURL()) && downloadInfo.getVideo().getDownloadedType().equals(video.getDownloadedType())){
cancelDownload();
cancelDownload(false);
downloadQueue.pop();
downloadInfo.setDownloadQueue(downloadQueue);
startDownload(downloadQueue);
@ -194,6 +195,19 @@ public class DownloaderService extends Service {
}
}
private void onDownloadCancel(){
try{
for (Activity activity: activities.keySet()){
activity.runOnUiThread(() -> {
IDownloaderListener callback = activities.get(activity);
callback.onDownloadCancel(downloadInfo);
});
}
}catch (Exception e){
e.printStackTrace();
}
}
private void onDownloadEnd(){
try{
for (Activity activity: activities.keySet()){

View file

@ -186,7 +186,7 @@ public class MainActivity extends AppCompatActivity{
public void cancelDownloadService(){
if(!isDownloadServiceRunning) return;
iDownloaderService.cancelDownload();
iDownloaderService.cancelDownload(true);
stopDownloadService();
}

View file

@ -94,28 +94,42 @@ public class HomeRecyclerViewAdapter extends RecyclerView.Adapter<HomeRecyclerVi
MaterialButton musicBtn = buttonLayout.findViewById(R.id.download_music);
musicBtn.setTag(videoID + "##audio");
musicBtn.setTag(R.id.cancelDownload, "false");
musicBtn.setOnClickListener(view -> onItemClickListener.onButtonClick(position, "audio"));
MaterialButton videoBtn = buttonLayout.findViewById(R.id.download_video);
videoBtn.setTag(videoID + "##video");
videoBtn.setTag(R.id.cancelDownload, "false");
videoBtn.setOnClickListener(view -> onItemClickListener.onButtonClick(position, "video"));
// PROGRESS BAR ----------------------------------------------------
LinearProgressIndicator progressBar = card.findViewById(R.id.download_progress);
progressBar.setVisibility(View.GONE);
progressBar.setTag(videoID + "##progress");
if(video.isAudioDownloaded() == 1){
musicBtn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_music_downloaded));
}else{
musicBtn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_music));
}
if(video.isVideoDownloaded() == 1){
videoBtn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_video_downloaded));
}else{
videoBtn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_video));
if (video.isDownloading()){
progressBar.setVisibility(View.VISIBLE);
if (video.isDownloadingAudio()){
musicBtn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_cancel));
musicBtn.setTag(R.id.cancelDownload, "true");
}else if (video.isDownloadingVideo()){
videoBtn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_cancel));
videoBtn.setTag(R.id.cancelDownload, "true");
}
}else {
progressBar.setVisibility(View.GONE);
progressBar.setIndeterminate(true);
if(video.isAudioDownloaded() == 1){
musicBtn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_music_downloaded));
}else{
musicBtn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_music));
}
if(video.isVideoDownloaded() == 1){
videoBtn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_video_downloaded));
}else{
videoBtn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_video));
}
}
if(checkedVideos.contains(position)){
@ -167,6 +181,10 @@ public class HomeRecyclerViewAdapter extends RecyclerView.Adapter<HomeRecyclerVi
notifyItemRangeInserted(size, videoList.size());
}
public void updateVideoListItem(Video v, int position){
videoList.set(position, v);
}
public void clearCheckedVideos(){
int size = checkedVideos.size();
for (int i = 0; i < size; i++){

View file

@ -10,7 +10,7 @@ import java.util.ArrayList;
public class DBManager extends SQLiteOpenHelper {
public static final String db_name = "ytdlnis_db";
public static final int db_version = 7;
public static final int db_version = 9;
public static final String results_table_name = "results";
public static final String history_table_name = "history";
public static final String id = "id";
@ -27,6 +27,8 @@ public class DBManager extends SQLiteOpenHelper {
public static final String isPlaylistItem = "isPlaylistItem";
public static final String website = "website";
public static final String downloadPath = "downloadPath";
public static final String downloadingAudio = "downloadingAudio";
public static final String downloadingVideo = "downloadingVideo";
public DBManager(Context context){
@ -46,7 +48,9 @@ public class DBManager extends SQLiteOpenHelper {
+ downloadedAudio + " INTEGER,"
+ downloadedVideo + " INTEGER,"
+ isPlaylistItem + " INTENGER,"
+ website + " TEXT)";
+ website + " TEXT,"
+ downloadingAudio + " INTEGER,"
+ downloadingVideo + " INTEGER)";
sqLiteDatabase.execSQL(query);
@ -113,7 +117,7 @@ public class DBManager extends SQLiteOpenHelper {
if(cursor.moveToFirst()){
do {
// on below line we are adding the data from cursor to our array list.
list.add(new Video(cursor.getString(1), //id
list.add(new Video(cursor.getString(1), //videoId
cursor.getString(2), //url
cursor.getString(3), //title
cursor.getString(4), //author
@ -122,7 +126,9 @@ public class DBManager extends SQLiteOpenHelper {
cursor.getInt(7), //downloadedAudio
cursor.getInt(8), //downloadedVideo
cursor.getInt(9), //isPlaylistItem
cursor.getString(10))); //website
cursor.getString(10), //website
cursor.getInt(11), //isDownloadingAudio
cursor.getInt(12))); //isDownloadingVideo
} while (cursor.moveToNext());
}
@ -173,6 +179,8 @@ public class DBManager extends SQLiteOpenHelper {
values.put(downloadedVideo, v.isVideoDownloaded());
values.put(isPlaylistItem, v.getIsPlaylistItem());
values.put(website, v.getWebsite());
values.put(downloadingAudio, 0);
values.put(downloadingVideo, 0);
db.insert(results_table_name, null, values);
}
@ -198,22 +206,34 @@ public class DBManager extends SQLiteOpenHelper {
db.close();
}
public void updateDownloadStatusOnResult(String id, String type){
public void updateDownloadStatusOnResult(String id, String type, boolean downloaded){
SQLiteDatabase db = this.getReadableDatabase();
ContentValues values = new ContentValues();
switch (type){
case "audio":
values.put(downloadedAudio, 1);
if (downloaded) values.put(downloadedAudio, 1);
values.put(downloadingAudio, 0);
break;
case "video":
values.put(downloadedVideo, 1);
if (downloaded) values.put(downloadedVideo, 1);
values.put(downloadingVideo, 0);
break;
}
db.update(results_table_name, values, "videoId = ?", new String[]{id});
}
public void updateDownloadingStatusOnResult(String id, String type, boolean downloading){
SQLiteDatabase db = this.getReadableDatabase();
ContentValues values = new ContentValues();
type = (type.equals("audio")) ? downloadingAudio : downloadingVideo;
int value = (downloading) ? 1 : 0;
values.put(type, value);
db.update(results_table_name, values, "videoId = ?", new String[]{id});
}
public int checkDownloaded(String url, String downloadType){
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM " + history_table_name + " WHERE url='" +

View file

@ -18,10 +18,12 @@ public class Video implements Parcelable {
private int isPlaylistItem;
private String downloadPath;
private String website;
private boolean downloadingAudio;
private boolean downloadingVideo;
// RESULTS OBJECT
public Video(String videoId, String url, String title, String author, String duration, String thumb,
int downloadedAudio, int downloadedVideo, int isPlaylistItem, String website) {
int downloadedAudio, int downloadedVideo, int isPlaylistItem, String website, int downloadingAudio, int downloadingVideo) {
this.videoId = videoId;
this.url = url;
this.title = title;
@ -32,6 +34,8 @@ public class Video implements Parcelable {
this.downloadedAudio = downloadedAudio;
this.isPlaylistItem = isPlaylistItem;
this.website = website;
this.downloadingAudio = intToBoolean(downloadingAudio);
this.downloadingVideo = intToBoolean(downloadingVideo);
}
//HISTORY OBJECT
@ -49,6 +53,9 @@ public class Video implements Parcelable {
this.website = website;
}
private boolean intToBoolean(int i){
return i == 1;
}
protected Video(Parcel in) {
id = in.readInt();
@ -199,6 +206,26 @@ public class Video implements Parcelable {
this.downloadPath = downloadPath;
}
public boolean isDownloadingAudio() {
return downloadingAudio;
}
public void setDownloadingAudio(boolean downloadingAudio) {
this.downloadingAudio = downloadingAudio;
}
public boolean isDownloadingVideo() {
return downloadingVideo;
}
public void setDownloadingVideo(boolean downloadingVideo) {
this.downloadingVideo = downloadingVideo;
}
public boolean isDownloading() {
return this.downloadingAudio || this.downloadingVideo;
}
@Override
public int describeContents() {
return 0;
@ -239,7 +266,8 @@ public class Video implements Parcelable {
", isPlaylistItem=" + isPlaylistItem +
", downloadPath='" + downloadPath + '\'' +
", website='" + website + '\'' +
", downloadingAudio=" + downloadingAudio +
", downloadingVideo=" + downloadingVideo +
'}';
}
}

View file

@ -91,6 +91,9 @@ public class CustomCommandActivity extends AppCompatActivity {
swapFabs();
}
@Override
public void onDownloadCancel(DownloadInfo downloadInfo) {}
public void onDownloadServiceEnd() {
stopDownloadService();
@ -160,7 +163,7 @@ public class CustomCommandActivity extends AppCompatActivity {
public void cancelDownloadService(){
if(!isDownloadServiceRunning) return;
iDownloaderService.cancelDownload();
iDownloaderService.cancelDownload(false);
stopDownloadService();
}

View file

@ -94,6 +94,11 @@ public class HistoryFragment extends Fragment implements HistoryRecyclerViewAdap
}catch(Exception ignored){}
}
@Override
public void onDownloadCancel(DownloadInfo downloadInfo) {
}
public void onDownloadServiceEnd() {}
};

View file

@ -86,18 +86,16 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
downloadInfo = info;
try{
if(downloadInfo != null){
String id = downloadInfo.getVideo().getVideoId();
String type = downloadInfo.getVideo().getDownloadedType();
recyclerView.smoothScrollToPosition(resultObjects.indexOf(findVideo(id)));
MaterialButton clickedButton = recyclerView.findViewWithTag(id +"##"+type);
progressBar = recyclerView.findViewWithTag(id + "##progress");
progressBar.setVisibility(View.VISIBLE);
Video video = downloadInfo.getVideo();
String id = video.getVideoId();
video = findVideo(id);
int index = resultObjects.indexOf(video);
recyclerView.smoothScrollToPosition(index);
updateDownloadingStatusOnResult(video, video.getDownloadedType(), true);
homeRecyclerViewAdapter.notifyItemChanged(index);
downloading = true;
progressBar = fragmentView.findViewWithTag(downloadInfo.getVideo().getVideoId()+"##progress");
topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(true);
clickedButton.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_cancel));
clickedButton.setTag(R.id.cancelDownload, "true");
}
}catch(Exception ignored){}
}
@ -110,14 +108,8 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
int progress = downloadInfo.getProgress();
if (progress > 0) {
progressBar = fragmentView.findViewWithTag(downloadInfo.getVideo().getVideoId()+"##progress");
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgressCompat(progress, true);
}
String id = downloadInfo.getVideo().getVideoId();
String type = downloadInfo.getVideo().getDownloadedType();
MaterialButton clickedButton = recyclerView.findViewWithTag(id + "##"+type);
clickedButton.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_cancel));
clickedButton.setTag(R.id.cancelDownload, "true");
}catch(Exception ignored){}
});
}
@ -125,46 +117,31 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
public void onDownloadError(DownloadInfo info){
downloadInfo = info;
try{
progressBar.setProgress(0);
progressBar.setVisibility(View.GONE);
downloading = false;
topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(false);
Video item = downloadInfo.getVideo();
String id = item.getVideoId();
String type = item.getDownloadedType();
MaterialButton theClickedButton = recyclerView.findViewWithTag(id + "##"+type);
if (theClickedButton != null) {
if (type.equals("audio")) {
theClickedButton.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_music_downloaded));
} else {
theClickedButton.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_video_downloaded));
}
theClickedButton.setTag(R.id.cancelDownload, "false");
}
updateDownloadStatusOnResult(item, type, false);
item = findVideo(id);
if (type.equals("audio")) item.setDownloadingAudio(false);
else if (type.equals("video")) item.setDownloadingVideo(false);
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(item));
downloading = false;
topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(false);
}catch(Exception ignored){}
}
public void onDownloadEnd(DownloadInfo info) {
downloadInfo = info;
try{
progressBar.setProgress(0);
progressBar.setVisibility(View.GONE);
Video item = downloadInfo.getVideo();
String id = item.getVideoId();
String type = item.getDownloadedType();
MaterialButton theClickedButton = recyclerView.findViewWithTag(id + "##"+type);
if (theClickedButton != null) {
if (type.equals("audio")) {
theClickedButton.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_music_downloaded));
} else {
theClickedButton.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_video_downloaded));
}
theClickedButton.setTag(R.id.cancelDownload, "false");
}
item = findVideo(id);
updateDownloadingStatusOnResult(item, type, false);
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(item));
downloading = false;
topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(false);
@ -187,11 +164,31 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
for (int i = 0; i < files.size(); i++) paths[i] = files.get(i).getAbsolutePath();
MediaScannerConnection.scanFile(context, paths, null, null);
addToHistory(item, new Date(), paths);
updateDownloadStatusOnResult(item, type);
updateDownloadStatusOnResult(item, type, true);
mainActivity.updateHistoryFragment();
}catch(Exception ignored){}
}
@Override
public void onDownloadCancel(DownloadInfo info) {
downloadInfo = info;
try{
while (!info.getDownloadQueue().isEmpty()){
Video item = downloadInfo.getDownloadQueue().pop();
String id = item.getVideoId();
String type = item.getDownloadedType();
item = findVideo(id);
updateDownloadingStatusOnResult(item, type, false);
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(item));
}
downloading = false;
topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(false);
}catch(Exception ignored){}
}
public void onDownloadServiceEnd() {
mainActivity.stopDownloadService();
@ -277,10 +274,12 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
try {
infoUtil = new InfoUtil(context);
resultObjects = infoUtil.getTrending(context);
dbManager.addToResults(resultObjects);
} catch (Exception e) {
Log.e(TAG, e.toString());
}
}
dbManager.close();
if (resultObjects != null) {
uiHandler.post(this::scrollToTop);
if (resultObjects.size() > 1 && resultObjects.get(1).getIsPlaylistItem() == 1) {
@ -288,7 +287,6 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
}
}
uiHandler.post(() -> {
homeRecyclerViewAdapter.setVideoList(resultObjects, true);
shimmerCards.stopShimmer();
@ -327,6 +325,8 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
searchView.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
searchView.setQueryHint(getString(R.string.search_hint));
dbManager = new DBManager(context);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
@ -349,6 +349,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
int itemId = m.getItemId();
if(itemId == R.id.delete_results){
dbManager.clearResults();
dbManager.close();
selectedObjects = new ArrayList<>();
downloadAllFab.setVisibility(View.GONE);
downloadFabs.setVisibility(View.GONE);
@ -357,21 +358,14 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
try{
mainActivity.cancelDownloadService();
topAppBar.getMenu().findItem(itemId).setVisible(false);
for (int i = 0; i < downloadInfo.getDownloadQueue().size(); i++){
Video vid = downloadInfo.getDownloadQueue().get(i);
String type = vid.getDownloadedType();
updateDownloadingStatusOnResult(vid, type, false);
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(vid));
}
downloadQueue = new ArrayList<>();
downloading = false;
String id = progressBar.getTag().toString().split("##progress")[0];
progressBar.setVisibility(View.GONE);
String type = findVideo(id).getDownloadedType();
MaterialButton theClickedButton = recyclerView.findViewWithTag(id + "##"+type);
if (theClickedButton != null) {
if (type.equals("audio")) {
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;
@ -431,6 +425,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
}
dbManager.clearResults();
dbManager.addToResults(resultObjects);
dbManager.close();
new Handler(Looper.getMainLooper()).post(() -> {
homeRecyclerViewAdapter.setVideoList(resultObjects, true);
shimmerCards.stopShimmer();
@ -472,7 +467,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
dbManager.clearResults();
dbManager.addToResults(resultObjects);
dbManager.close();
new Handler(Looper.getMainLooper()).post(() -> {
homeRecyclerViewAdapter.setVideoList(resultObjects, true);
shimmerCards.stopShimmer();
@ -497,6 +492,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
try {
String nextPageToken = "";
dbManager.clearResults();
dbManager.close();
resultObjects.clear();
homeRecyclerViewAdapter.setVideoList(new ArrayList<>(), true);
do {
@ -510,6 +506,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
shimmerCards.setVisibility(View.GONE);
});
dbManager.addToResults(tmp_vids);
dbManager.close();
if (tmp_token.isEmpty()) break;
if (tmp_token.equals(nextPageToken)) break;
nextPageToken = tmp_token;
@ -545,6 +542,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
resultObjects.addAll(video);
dbManager.clearResults();
dbManager.addToResults(resultObjects);
dbManager.close();
}
new Handler(Looper.getMainLooper()).post(() -> {
@ -591,16 +589,15 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
try {
if (btn.getTag(R.id.cancelDownload).equals("true")){
mainActivity.removeItemFromDownloadQueue(vid);
int icon = (type.equals("audio")) ? R.drawable.ic_music : R.drawable.ic_video;
btn.setIcon(ContextCompat.getDrawable(activity, icon));
btn.setTag(R.id.cancelDownload, "false");
updateDownloadingStatusOnResult(vid, type, false);
homeRecyclerViewAdapter.notifyItemChanged(position);
return;
}
}catch (Exception ignored){}
}
downloadQueue.add(vid);
btn.setTag(R.id.cancelDownload, "true");
btn.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_cancel));
updateDownloadingStatusOnResult(vid, type, true);
homeRecyclerViewAdapter.notifyItemChanged(position);
if (isStoragePermissionGranted()){
mainActivity.startDownloadService(downloadQueue, listener);
downloadQueue.clear();
@ -643,22 +640,35 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
video.setDownloadedTime(downloadedTime);
video.setDownloadPath(path);
dbManager.addToHistory(video);
dbManager.close();
} catch (Exception ignored) {
}
}
}
public void updateDownloadStatusOnResult(Video v, String type) {
public void updateDownloadStatusOnResult(Video v, String type, boolean downloaded) {
if (v != null) {
dbManager = new DBManager(context);
try {
dbManager.updateDownloadStatusOnResult(v.getVideoId(), type);
dbManager.updateDownloadStatusOnResult(v.getVideoId(), type, downloaded);
dbManager.close();
} catch (Exception ignored) {
}
}
}
public void updateDownloadingStatusOnResult(Video v, String type, boolean downloading) {
if (v != null) {
if (type.equals("audio")) v.setDownloadingAudio(downloading);
else if (type.equals("video")) v.setDownloadingVideo(downloading);
homeRecyclerViewAdapter.updateVideoListItem(v, resultObjects.indexOf(v));
dbManager = new DBManager(context);
try {
dbManager.updateDownloadingStatusOnResult(v.getVideoId(), type, downloading);
dbManager.close();
} catch (Exception ignored) {}
}
}
@Override
public void onCardClick(int position, boolean add) {
@ -693,6 +703,8 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
for (int i = 0; i < selectedObjects.size(); i++) {
Video vid = findVideo(selectedObjects.get(i).getVideoId());
vid.setDownloadedType(buttonData[1]);
updateDownloadingStatusOnResult(vid, buttonData[1], true);
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(vid));
downloadQueue.add(vid);
}
selectedObjects = new ArrayList<>();
@ -765,13 +777,11 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
for (int i = start; i < end; i++){
Video vid = findVideo(resultObjects.get(i).getVideoId());
vid.setDownloadedType(type);
updateDownloadingStatusOnResult(vid, type, true);
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(vid));
downloadQueue.add(vid);
}
if (downloading) {
Toast.makeText(context, R.string.added_to_queue, Toast.LENGTH_LONG).show();
return;
}
if(isStoragePermissionGranted()){
mainActivity.startDownloadService(downloadQueue, listener);
downloadQueue.clear();

View file

@ -5,5 +5,6 @@ public interface IDownloaderListener {
void onDownloadProgress(DownloadInfo downloadInfo);
void onDownloadError(DownloadInfo downloadInfo);
void onDownloadEnd(DownloadInfo downloadInfo);
void onDownloadCancel(DownloadInfo downloadInfo);
void onDownloadServiceEnd();
}

View file

@ -9,6 +9,6 @@ public interface IDownloaderService {
void addActivity(Activity activity, IDownloaderListener callback);
void removeActivity(Activity activity);
void updateQueue(ArrayList<Video> queue);
void cancelDownload();
void cancelDownload(boolean cancelAll);
void removeItemFromDownloadQueue(Video video);
}

View file

@ -193,7 +193,7 @@ public class InfoUtil {
int downloadedVideo = dbManager.checkDownloaded(url, "video");
int isPLaylist = 0;
video = new Video(id, url, title, author, duration, thumb, downloadedAudio, downloadedVideo, isPLaylist, "youtube");
video = new Video(id, url, title, author, duration, thumb, downloadedAudio, downloadedVideo, isPLaylist, "youtube", 0, 0);
}catch(Exception e){
Log.e(TAG, e.toString());
}
@ -319,7 +319,9 @@ public class InfoUtil {
dbManager.checkDownloaded(url, "audio"),
dbManager.checkDownloaded(url, "video"),
isPlaylist,
website)
website,
0,
0)
);
}
}catch(Exception e){