fixed updating items when downloads cancel and fixed item downloading the same type (again)

This commit is contained in:
Denis Çerri 2022-10-12 22:12:17 +02:00
parent b6f6edb690
commit 83055c0a42
No known key found for this signature in database
GPG key ID: 3F50F14A8E7F7A13
17 changed files with 178 additions and 166 deletions

View file

@ -1,41 +0,0 @@
## FFmpeg for Android
FFmpeg can be built for android using the termux ffmpeg package.
Prerequisites : git, docker
git clone git@github.com:termux/termux-packages.git
cd termux-packages
create a file `build-ffmpeg.sh` with below content
#!/bin/bash
# use i686 for x86
export TERMUX_ARCH=arm
export TERMUX_PREFIX=/data/youtubedl-android/usr
export TERMUX_ANDROID_HOME=/data/youtubedl-android/home
./build-package.sh ffmpeg
Make file executable
chmod +x ./build-ffmpeg.sh
Build Package
./scripts/run-docker.sh ./clean.sh
./scripts/run-docker.sh ./build-ffmpeg.sh
This will create several `.deb` files in `debs/` directory.
`debs/*dev*.deb` debs can be safely removed as we don't need them.
`debs/*static*.deb` debs can be safely removed as we don't need them.
`libicu_66.1-1_arm.deb` can be removed (?)
The ffmpeg zip archive as used in youtubedl-android can be created using the following commands.
cd debs
find . -type f -exec dpkg-deb -xv {} . \;
cd data/youtubedl-android
zip --symlinks -r /tmp/ffmpeg_arm.zip usr/lib

View file

@ -1,50 +0,0 @@
## Python for Android
Python can be built for android using the termux python package.
Prerequisites : git, docker
git clone git@github.com:termux/termux-packages.git
cd termux-packages
create a file `build-python.sh` with below content
#!/bin/bash
# use i686 for x86
export TERMUX_ARCH=arm
export TERMUX_PREFIX=/data/youtubedl-android/usr
export TERMUX_ANDROID_HOME=/data/youtubedl-android/home
./build-package.sh python
Make file executable
chmod +x ./build-python.sh
Build Package
./scripts/run-docker.sh ./clean.sh
./scripts/run-docker.sh ./build-python.sh
This will create several `.deb` files in `debs/` directory.
I have found the following packages to be sufficient for youtube-dl to work.
python_3.7.2-1_arm.deb
libandroid-support_24_arm.deb
libutil_0.4_arm.deb
libffi_3.2.1-2_arm.deb
openssl_1.1.1a_arm.deb
ca-certificates_20180124_all.deb
The python zip archive as used in youtubedl-android can be created using the following commands.
cd debs
dpkg-deb -xv python_3.7.2-1_arm.deb .
dpkg-deb -xv libandroid-support_24_arm.deb .
dpkg-deb -xv libutil_0.4_arm.deb .
dpkg-deb -xv libffi_3.2.1-2_arm.deb .
dpkg-deb -xv openssl_1.1.1a_arm.deb .
dpkg-deb -xv ca-certificates_20180124_all.deb .
cd data/youtubedl-android
zip --symlinks -r /tmp/python3_7_arm.zip usr/lib usr/etc

View file

@ -25,6 +25,7 @@ import com.yausername.youtubedl_android.YoutubeDLRequest;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map; import java.util.Map;
@ -149,13 +150,19 @@ public class DownloaderService extends Service {
} }
public void updateQueue(ArrayList<Video> queue){ public void updateQueue(ArrayList<Video> queue){
downloadQueue.addAll(queue); try{
if (downloadQueue.size() == queue.size()){ for (int i = 0; i < queue.size(); i++){
downloadInfo.setDownloadQueue(downloadQueue); downloadQueue.add((Video) queue.get(i).clone());
startDownload(downloadQueue); }
}else{ if (downloadQueue.size() == queue.size()){
downloadInfo.setDownloadQueue(downloadQueue); downloadInfo.setDownloadQueue(downloadQueue);
Toast.makeText(context, getString(R.string.added_to_queue), Toast.LENGTH_SHORT).show(); startDownload(downloadQueue);
}else{
downloadInfo.setDownloadQueue(downloadQueue);
Toast.makeText(context, getString(R.string.added_to_queue), Toast.LENGTH_SHORT).show();
}
}catch (Exception e){
Toast.makeText(context, "Couldn't update download queue! :(", Toast.LENGTH_SHORT).show();
} }
} }
@ -164,22 +171,31 @@ public class DownloaderService extends Service {
YoutubeDL.getInstance().destroyProcessById(downloadProcessID); YoutubeDL.getInstance().destroyProcessById(downloadProcessID);
compositeDisposable.clear(); compositeDisposable.clear();
//stopForeground(true); //stopForeground(true);
if (cancelAll) onDownloadCancel(); if (cancelAll) onDownloadCancelAll();
else onDownloadEnd();
}catch(Exception err){ }catch(Exception err){
Log.e(TAG, err.getMessage()); Log.e(TAG, err.getMessage());
} }
} }
public void removeItemFromDownloadQueue(Video video){ public void removeItemFromDownloadQueue(Video video, String type){
//if its the same video with the same download type as the current downloading one //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())){ if (downloadInfo.getVideo().getURL().equals(video.getURL()) && downloadInfo.getVideo().getDownloadedType().equals(video.getDownloadedType())){
cancelDownload(false); cancelDownload(false);
downloadInfo.setDownloadType(type);
onDownloadCancel(downloadInfo);
downloadQueue.pop(); downloadQueue.pop();
downloadInfo.setDownloadQueue(downloadQueue); downloadInfo.setDownloadQueue(downloadQueue);
startDownload(downloadQueue); startDownload(downloadQueue);
}else { }else {
downloadQueue.remove(video); downloadQueue.remove(video);
try{
DownloadInfo info = new DownloadInfo();
info.setVideo(video);
info.setDownloadType(type);
onDownloadCancel(info);
}catch(Exception ignored){}
} }
Toast.makeText(context, video.getTitle() + " " + getString(R.string.removed_from_queue), Toast.LENGTH_SHORT).show(); Toast.makeText(context, video.getTitle() + " " + getString(R.string.removed_from_queue), Toast.LENGTH_SHORT).show();
} }
@ -195,24 +211,20 @@ public class DownloaderService extends Service {
} }
}); });
} }
}catch (Exception e){ }catch (Exception ignored){}
e.printStackTrace();
}
} }
private void onDownloadCancel(){ private void onDownloadCancelAll(){
try{ try{
for (Activity activity: activities.keySet()){ for (Activity activity: activities.keySet()){
activity.runOnUiThread(() -> { activity.runOnUiThread(() -> {
for (int i = 0; i < activities.get(activity).size(); i++){ for (int i = 0; i < activities.get(activity).size(); i++){
IDownloaderListener callback = activities.get(activity).get(i); IDownloaderListener callback = activities.get(activity).get(i);
callback.onDownloadCancel(downloadInfo); callback.onDownloadCancelAll(downloadInfo);
} }
}); });
} }
}catch (Exception e){ }catch (Exception ignored){}
e.printStackTrace();
}
} }
private void onDownloadEnd(){ private void onDownloadEnd(){
@ -230,6 +242,19 @@ public class DownloaderService extends Service {
} }
} }
private void onDownloadCancel(DownloadInfo cancelInfo){
try{
for (Activity activity: activities.keySet()){
activity.runOnUiThread(() -> {
for (int i = 0; i < activities.get(activity).size(); i++){
IDownloaderListener callback = activities.get(activity).get(i);
callback.onDownloadCancel(cancelInfo);
}
});
}
}catch (Exception ignored){}
}
private void startDownload(LinkedList<Video> videos) { private void startDownload(LinkedList<Video> videos) {
Video video; Video video;
if(videos.size() == 0){ if(videos.size() == 0){

View file

@ -10,6 +10,7 @@ import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
@ -24,6 +25,7 @@ import com.deniscerri.ytdlnis.page.MoreFragment;
import com.deniscerri.ytdlnis.page.settings.SettingsActivity; import com.deniscerri.ytdlnis.page.settings.SettingsActivity;
import com.deniscerri.ytdlnis.service.IDownloaderListener; import com.deniscerri.ytdlnis.service.IDownloaderListener;
import com.deniscerri.ytdlnis.service.IDownloaderService; import com.deniscerri.ytdlnis.service.IDownloaderService;
import com.deniscerri.ytdlnis.util.NotificationUtil;
import com.deniscerri.ytdlnis.util.UpdateUtil; import com.deniscerri.ytdlnis.util.UpdateUtil;
import java.text.DateFormat; import java.text.DateFormat;
@ -203,6 +205,8 @@ public class MainActivity extends AppCompatActivity{
context.getApplicationContext().unbindService(serviceConnection); context.getApplicationContext().unbindService(serviceConnection);
downloaderService.stopForeground(true); downloaderService.stopForeground(true);
downloaderService.stopSelf(); downloaderService.stopSelf();
NotificationUtil notificationUtil = new NotificationUtil(context.getApplicationContext());
notificationUtil.cancelDownloadNotification(NotificationUtil.DOWNLOAD_NOTIFICATION_ID);
isDownloadServiceRunning = false; isDownloadServiceRunning = false;
} }
@ -212,8 +216,8 @@ public class MainActivity extends AppCompatActivity{
stopDownloadService(); stopDownloadService();
} }
public void removeItemFromDownloadQueue(Video video){ public void removeItemFromDownloadQueue(Video video, String type){
iDownloaderService.removeItemFromDownloadQueue(video); iDownloaderService.removeItemFromDownloadQueue(video, type);
} }
public boolean isDownloadServiceRunning() { public boolean isDownloadServiceRunning() {

View file

@ -189,6 +189,7 @@ public class HomeRecyclerViewAdapter extends RecyclerView.Adapter<HomeRecyclerVi
public void updateVideoListItem(Video v, int position){ public void updateVideoListItem(Video v, int position){
videoList.set(position, v); videoList.set(position, v);
notifyItemChanged(position);
} }
public void clearCheckedVideos(){ public void clearCheckedVideos(){

View file

@ -119,6 +119,16 @@ public class DBManager extends SQLiteOpenHelper {
} }
} }
public void clearDownloadingHistory(){
ArrayList<Video> videos = getHistory("","","","");
for (int i = 0; i < videos.size(); i++){
Video video = videos.get(i);
if(video.isQueuedDownload()){
clearHistoryItem(video);
}
}
}
public void clearDuplicateHistory(){ public void clearDuplicateHistory(){
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
db.execSQL( db.execSQL(

View file

@ -3,7 +3,7 @@ package com.deniscerri.ytdlnis.database;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
public class Video implements Parcelable { public class Video implements Parcelable, Cloneable {
private int id; private int id;
private String videoId; private String videoId;
private String title; private String title;
@ -247,6 +247,11 @@ public class Video implements Parcelable {
this.queuedDownload = queuedDownload; this.queuedDownload = queuedDownload;
} }
public Object clone() throws CloneNotSupportedException
{
return super.clone();
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;

View file

@ -18,6 +18,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import com.deniscerri.ytdlnis.R; import com.deniscerri.ytdlnis.R;
import com.deniscerri.ytdlnis.DownloaderService; import com.deniscerri.ytdlnis.DownloaderService;
import com.deniscerri.ytdlnis.database.Video;
import com.deniscerri.ytdlnis.service.DownloadInfo; import com.deniscerri.ytdlnis.service.DownloadInfo;
import com.deniscerri.ytdlnis.service.IDownloaderListener; import com.deniscerri.ytdlnis.service.IDownloaderListener;
import com.deniscerri.ytdlnis.service.IDownloaderService; import com.deniscerri.ytdlnis.service.IDownloaderService;
@ -99,6 +100,8 @@ public class CustomCommandActivity extends AppCompatActivity {
@Override @Override
public void onDownloadCancel(DownloadInfo downloadInfo) {} public void onDownloadCancel(DownloadInfo downloadInfo) {}
@Override
public void onDownloadCancelAll(DownloadInfo downloadInfo){}
public void onDownloadServiceEnd() { public void onDownloadServiceEnd() {
stopDownloadService(); stopDownloadService();

View file

@ -169,16 +169,25 @@ public class DownloadsFragment extends Fragment implements DownloadsRecyclerView
dbManager.updateHistoryItem(item); dbManager.updateHistoryItem(item);
dbManager.close(); dbManager.close();
downloadsRecyclerViewAdapter.notifyItemChanged(downloadsObjects.indexOf(item)); downloadsRecyclerViewAdapter.notifyItemChanged(downloadsObjects.indexOf(item));
} catch (Exception ignored) { } catch (Exception ignored) {}
}
}catch(Exception ignored){} }catch(Exception ignored){}
} }
@Override @Override
public void onDownloadCancel(DownloadInfo downloadInfo) { public void onDownloadCancel(DownloadInfo info) {
Video v = info.getVideo();
v = findVideo(v.getURL(), v.getDownloadedType());
try {
downloadsObjects.remove(v);
dbManager = new DBManager(context);
dbManager.clearHistoryItem(v);
downloadsRecyclerViewAdapter.setVideoList(downloadsObjects);
}catch (Exception ignored){}
} }
@Override
public void onDownloadCancelAll(DownloadInfo downloadInfo){}
public void onDownloadServiceEnd() {} public void onDownloadServiceEnd() {}
}; };
@ -383,6 +392,24 @@ public class DownloadsFragment extends Fragment implements DownloadsRecyclerView
initCards(); initCards();
}); });
delete_dialog.show(); delete_dialog.show();
}else if (itemID == R.id.remove_downloading){
if (downloadsObjects.size() == 0) {
Toast.makeText(context, R.string.history_is_empty, Toast.LENGTH_SHORT).show();
return true;
}
MaterialAlertDialogBuilder delete_dialog = new MaterialAlertDialogBuilder(fragmentContext);
delete_dialog.setTitle(getString(R.string.confirm_delete_history));
delete_dialog.setMessage(getString(R.string.confirm_delete_downloading_desc));
delete_dialog.setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
dialogInterface.cancel();
});
delete_dialog.setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> {
dbManager.clearDownloadingHistory();
mainActivity.cancelDownloadService();
initCards();
});
delete_dialog.show();
} }
return true; return true;
}); });
@ -582,14 +609,15 @@ public class DownloadsFragment extends Fragment implements DownloadsRecyclerView
@Override @Override
public void onButtonClick(int position) { public void onButtonClick(int position) {
Video vid = downloadsObjects.get(position);
try { try {
Video vid = downloadsObjects.get(position); mainActivity.removeItemFromDownloadQueue(vid, vid.getDownloadedType());
downloadsObjects.remove(position); }catch (Exception e){
dbManager = new DBManager(context); DownloadInfo info = new DownloadInfo();
dbManager.clearHistoryItem(vid); info.setVideo(vid);
downloadsRecyclerViewAdapter.setVideoList(downloadsObjects); info.setDownloadType(vid.getDownloadedType());
mainActivity.removeItemFromDownloadQueue(vid); listener.onDownloadCancel(info);
}catch (Exception ignored){} }
} }
public Video findVideo(String url, String type) { public Video findVideo(String url, String type) {

View file

@ -83,17 +83,16 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
public IDownloaderListener listener = new IDownloaderListener() { public IDownloaderListener listener = new IDownloaderListener() {
public void onDownloadStart(DownloadInfo info) { public void onDownloadStart(DownloadInfo info) {
downloading = true;
downloadInfo = info; downloadInfo = info;
try{ try{
if(downloadInfo != null){ if(downloadInfo != null){
Video video = downloadInfo.getVideo(); Video video = downloadInfo.getVideo();
String id = video.getVideoId(); String url = video.getURL();
video = findVideo(id); String type = video.getDownloadedType();
int index = resultObjects.indexOf(video); video = findVideo(url);
recyclerView.smoothScrollToPosition(index); recyclerView.smoothScrollToPosition(resultObjects.indexOf(video));
updateDownloadingStatusOnResult(video, video.getDownloadedType(), true); updateDownloadingStatusOnResult(video, type, true);
homeRecyclerViewAdapter.notifyItemChanged(index);
downloading = true;
progressBar = fragmentView.findViewWithTag(downloadInfo.getVideo().getVideoId()+"##progress"); progressBar = fragmentView.findViewWithTag(downloadInfo.getVideo().getVideoId()+"##progress");
topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(true); topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(true);
} }
@ -118,11 +117,11 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
downloadInfo = info; downloadInfo = info;
try{ try{
Video item = downloadInfo.getVideo(); Video item = downloadInfo.getVideo();
String id = item.getVideoId(); String url = item.getURL();
String type = item.getDownloadedType(); String type = item.getDownloadedType();
updateDownloadStatusOnResult(item, type, false); updateDownloadStatusOnResult(item, type, false);
item = findVideo(id); item = findVideo(url);
if (type.equals("audio")) item.setDownloadingAudio(false); if (type.equals("audio")) item.setDownloadingAudio(false);
else if (type.equals("video")) item.setDownloadingVideo(false); else if (type.equals("video")) item.setDownloadingVideo(false);
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(item)); homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(item));
@ -135,14 +134,14 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
public void onDownloadEnd(DownloadInfo info) { public void onDownloadEnd(DownloadInfo info) {
downloadInfo = info; downloadInfo = info;
Video item = downloadInfo.getVideo(); Video item = downloadInfo.getVideo();
String id = item.getVideoId(); String url = item.getURL();
String type = downloadInfo.getDownloadType(); String type = downloadInfo.getDownloadType();
item = findVideo(id); item = findVideo(url);
try{ try{
updateDownloadingStatusOnResult(item, type, false); updateDownloadingStatusOnResult(item, type, false);
if (type.equals("audio")) item.setDownloadedAudio(1); if (type.equals("audio")) item.setDownloadedAudio(1);
else item.setDownloadedVideo(1); else item.setDownloadedVideo(1);
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(findVideo(id))); homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(findVideo(url)));
updateDownloadStatusOnResult(item, type, true); updateDownloadStatusOnResult(item, type, true);
downloading = false; downloading = false;
topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(false); topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(false);
@ -150,17 +149,26 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
} }
@Override @Override
public void onDownloadCancel(DownloadInfo info) { public void onDownloadCancel(DownloadInfo info){
try {
Video video = findVideo(info.getVideo().getURL());
String type = info.getDownloadType();
updateDownloadingStatusOnResult(video, type, false);
}catch (Exception e){
e.printStackTrace();
}
}
@Override
public void onDownloadCancelAll(DownloadInfo info) {
downloadInfo = info; downloadInfo = info;
try{ try{
while (!info.getDownloadQueue().isEmpty()){ while (!info.getDownloadQueue().isEmpty()){
Video item = downloadInfo.getDownloadQueue().pop(); Video item = downloadInfo.getDownloadQueue().pop();
String id = item.getVideoId(); String url = item.getURL();
String type = item.getDownloadedType(); String type = item.getDownloadedType();
item = findVideo(url);
item = findVideo(id);
updateDownloadingStatusOnResult(item, type, false); updateDownloadingStatusOnResult(item, type, false);
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(item));
} }
downloading = false; downloading = false;
@ -258,6 +266,13 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
infoUtil = new InfoUtil(context); infoUtil = new InfoUtil(context);
resultObjects = infoUtil.getTrending(context); resultObjects = infoUtil.getTrending(context);
dbManager.addToResults(resultObjects); dbManager.addToResults(resultObjects);
uiHandler.post(() -> {
homeRecyclerViewAdapter.setVideoList(resultObjects, true);
shimmerCards.stopShimmer();
shimmerCards.setVisibility(View.GONE);
});
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
} }
@ -271,6 +286,10 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
updateDownloadingStatusOnResult(tmp, "video", false); updateDownloadingStatusOnResult(tmp, "video", false);
} }
} }
uiHandler.post(() -> {
shimmerCards.stopShimmer();
shimmerCards.setVisibility(View.GONE);
});
} }
} }
dbManager.close(); dbManager.close();
@ -280,12 +299,6 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
uiHandler.post(() -> downloadAllFab.setVisibility(View.VISIBLE)); uiHandler.post(() -> downloadAllFab.setVisibility(View.VISIBLE));
} }
} }
uiHandler.post(() -> {
homeRecyclerViewAdapter.setVideoList(resultObjects, true);
shimmerCards.stopShimmer();
shimmerCards.setVisibility(View.GONE);
});
}); });
thread.start(); thread.start();
} catch (Exception e) { } catch (Exception e) {
@ -356,7 +369,6 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
Video vid = downloadInfo.getDownloadQueue().get(i); Video vid = downloadInfo.getDownloadQueue().get(i);
String type = vid.getDownloadedType(); String type = vid.getDownloadedType();
updateDownloadingStatusOnResult(vid, type, false); updateDownloadingStatusOnResult(vid, type, false);
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(vid));
} }
downloadQueue = new ArrayList<>(); downloadQueue = new ArrayList<>();
downloading = false; downloading = false;
@ -561,10 +573,10 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
} }
public Video findVideo(String id) { public Video findVideo(String url) {
for (int i = 0; i < resultObjects.size(); i++) { for (int i = 0; i < resultObjects.size(); i++) {
Video v = resultObjects.get(i); Video v = resultObjects.get(i);
if ((v.getVideoId()).equals(id)) { if ((v.getURL()).equals(url)) {
return v; return v;
} }
} }
@ -582,16 +594,13 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
if (downloading){ if (downloading){
try { try {
if (btn.getTag(R.id.cancelDownload).equals("true")){ if (btn.getTag(R.id.cancelDownload).equals("true")){
mainActivity.removeItemFromDownloadQueue(vid); mainActivity.removeItemFromDownloadQueue(vid, type);
updateDownloadingStatusOnResult(vid, type, false);
homeRecyclerViewAdapter.notifyItemChanged(position);
return; return;
} }
}catch (Exception ignored){} }catch (Exception ignored){}
} }
downloadQueue.add(vid); downloadQueue.add(vid);
updateDownloadingStatusOnResult(vid, type, true); updateDownloadingStatusOnResult(vid, type, true);
homeRecyclerViewAdapter.notifyItemChanged(position);
if (isStoragePermissionGranted()){ if (isStoragePermissionGranted()){
mainActivity.startDownloadService(downloadQueue, listener); mainActivity.startDownloadService(downloadQueue, listener);
downloadQueue.clear(); downloadQueue.clear();
@ -689,11 +698,10 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
if (!viewIdName.isEmpty()) { if (!viewIdName.isEmpty()) {
if (viewIdName.contains("audio") || viewIdName.contains("video")) { if (viewIdName.contains("audio") || viewIdName.contains("video")) {
Log.e(TAG, viewIdName);
String[] buttonData = viewIdName.split("##"); String[] buttonData = viewIdName.split("##");
if (buttonData[0].equals("SELECT")) { if (buttonData[0].equals("SELECT")) {
for (int i = 0; i < selectedObjects.size(); i++) { for (int i = 0; i < selectedObjects.size(); i++) {
Video vid = findVideo(selectedObjects.get(i).getVideoId()); Video vid = findVideo(selectedObjects.get(i).getURL());
vid.setDownloadedType(buttonData[1]); vid.setDownloadedType(buttonData[1]);
updateDownloadingStatusOnResult(vid, buttonData[1], true); updateDownloadingStatusOnResult(vid, buttonData[1], true);
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(vid)); homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(vid));
@ -716,7 +724,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
if (viewIdName.equals("downloadAll")){ if (viewIdName.equals("downloadAll")){
//remove previously selected //remove previously selected
for (int i = 0; i < selectedObjects.size(); i++) { for (int i = 0; i < selectedObjects.size(); i++) {
Video vid = findVideo(selectedObjects.get(i).getVideoId()); Video vid = findVideo(selectedObjects.get(i).getURL());
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(vid)); homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(vid));
} }
selectedObjects = new ArrayList<>(); selectedObjects = new ArrayList<>();
@ -767,10 +775,9 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
if (start <= 1) start = 0; if (start <= 1) start = 0;
for (int i = start; i < end; i++){ for (int i = start; i < end; i++){
Video vid = findVideo(resultObjects.get(i).getVideoId()); Video vid = findVideo(resultObjects.get(i).getURL());
vid.setDownloadedType(type); vid.setDownloadedType(type);
updateDownloadingStatusOnResult(vid, type, true); updateDownloadingStatusOnResult(vid, type, true);
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(vid));
downloadQueue.add(vid); downloadQueue.add(vid);
} }

View file

@ -1,10 +1,13 @@
package com.deniscerri.ytdlnis.service; package com.deniscerri.ytdlnis.service;
import com.deniscerri.ytdlnis.database.Video;
public interface IDownloaderListener { public interface IDownloaderListener {
void onDownloadStart(DownloadInfo downloadInfo); void onDownloadStart(DownloadInfo downloadInfo);
void onDownloadProgress(DownloadInfo downloadInfo); void onDownloadProgress(DownloadInfo downloadInfo);
void onDownloadError(DownloadInfo downloadInfo); void onDownloadError(DownloadInfo downloadInfo);
void onDownloadEnd(DownloadInfo downloadInfo); void onDownloadEnd(DownloadInfo downloadInfo);
void onDownloadCancel(DownloadInfo downloadInfo); void onDownloadCancel(DownloadInfo downloadInfo);
void onDownloadCancelAll(DownloadInfo downloadInfo);
void onDownloadServiceEnd(); void onDownloadServiceEnd();
} }

View file

@ -10,5 +10,5 @@ public interface IDownloaderService {
void removeActivity(Activity activity); void removeActivity(Activity activity);
void updateQueue(ArrayList<Video> queue); void updateQueue(ArrayList<Video> queue);
void cancelDownload(boolean cancelAll); void cancelDownload(boolean cancelAll);
void removeItemFromDownloadQueue(Video video); void removeItemFromDownloadQueue(Video video, String type);
} }

View file

@ -94,7 +94,7 @@ public class InfoUtil {
snippet = fixThumbnail(snippet); snippet = fixThumbnail(snippet);
Video v = createVideofromJSON(snippet); Video v = createVideofromJSON(snippet);
if(v.getThumb().isEmpty()){ if(v == null || v.getThumb().isEmpty()){
continue; continue;
} }
videos.add(createVideofromJSON(snippet)); videos.add(createVideofromJSON(snippet));
@ -139,7 +139,7 @@ public class InfoUtil {
snippet = fixThumbnail(snippet); snippet = fixThumbnail(snippet);
Video v = createVideofromJSON(snippet); Video v = createVideofromJSON(snippet);
if(v.getThumb().isEmpty()){ if(v == null || v.getThumb().isEmpty()){
continue; continue;
}else{ }else{
j++; j++;
@ -185,6 +185,7 @@ public class InfoUtil {
String duration = obj.getString("duration"); String duration = obj.getString("duration");
String thumb = obj.getString("thumb"); String thumb = obj.getString("thumb");
String url = "https://www.youtube.com/watch?v=" + id; String url = "https://www.youtube.com/watch?v=" + id;
int downloadedAudio = dbManager.checkDownloaded(url, "audio"); int downloadedAudio = dbManager.checkDownloaded(url, "audio");
int downloadedVideo = dbManager.checkDownloaded(url, "video"); int downloadedVideo = dbManager.checkDownloaded(url, "video");
@ -358,7 +359,7 @@ public class InfoUtil {
snippet = fixThumbnail(snippet); snippet = fixThumbnail(snippet);
Video v = createVideofromJSON(snippet); Video v = createVideofromJSON(snippet);
if(v.getThumb().isEmpty()){ if(v == null || v.getThumb().isEmpty()){
continue; continue;
} }
v.setPlaylistTitle(context.getString(R.string.trendingPlaylist)); v.setPlaylistTitle(context.getString(R.string.trendingPlaylist));

View file

@ -75,10 +75,16 @@ public class NotificationUtil {
if (queue > 1) contentText += queue - 1 + " " + context.getString(R.string.items_left) + "\n"; if (queue > 1) contentText += queue - 1 + " " + context.getString(R.string.items_left) + "\n";
contentText += desc.replaceAll("\\[.*?\\] ", ""); contentText += desc.replaceAll("\\[.*?\\] ", "");
notificationBuilder.setProgress(100, (int) progress, false) try {
.setContentTitle(title) notificationBuilder.setProgress(100, (int) progress, false)
.setStyle(new NotificationCompat.BigTextStyle().bigText(contentText)); .setContentTitle(title)
notificationManager.notify(id, notificationBuilder.build()); .setStyle(new NotificationCompat.BigTextStyle().bigText(contentText));
notificationManager.notify(id, notificationBuilder.build());
}catch (Exception ignored){}
}
public void cancelDownloadNotification(int id){
notificationManager.cancel(id);
} }
} }

View file

@ -28,5 +28,11 @@
android:title="@string/remove_duplicates" android:title="@string/remove_duplicates"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/remove_downloading"
android:icon="@drawable/ic_delete_all"
android:title="@string/remove_downloading"
app:showAsAction="never" />
</menu> </menu>

View file

@ -106,4 +106,6 @@
<string name="newest_first">Të rejat në fillim</string> <string name="newest_first">Të rejat në fillim</string>
<string name="oldest_first">Të vjetrat në fillim</string> <string name="oldest_first">Të vjetrat në fillim</string>
<string name="currently_downloading">Duke Shkarkuar</string> <string name="currently_downloading">Duke Shkarkuar</string>
<string name="remove_downloading">Hiq në shkarkim</string>
<string name="confirm_delete_downloading_desc">Jeni duke hequr të gjithë elementet që kanë gjendje shkarkimi dhe anuluar shërbimin e shkarkimit!</string>
</resources> </resources>

View file

@ -111,4 +111,6 @@
<item type="id" name="cancelDownload" /> <item type="id" name="cancelDownload" />
<string name="trendingPlaylist" translatable="false">ytdlnis-TRENDING</string> <string name="trendingPlaylist" translatable="false">ytdlnis-TRENDING</string>
<string name="currently_downloading">Downloading</string> <string name="currently_downloading">Downloading</string>
<string name="remove_downloading">Remove Downloading</string>
<string name="confirm_delete_downloading_desc">You are going to remove all items that have a downloading state and then cancel the download service!</string>
</resources> </resources>