fixed updating items when downloads cancel and fixed item downloading the same type (again)
This commit is contained in:
parent
b6f6edb690
commit
83055c0a42
17 changed files with 178 additions and 166 deletions
|
|
@ -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
|
||||
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -25,6 +25,7 @@ import com.yausername.youtubedl_android.YoutubeDLRequest;
|
|||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
|
@ -149,13 +150,19 @@ public class DownloaderService extends Service {
|
|||
}
|
||||
|
||||
public void updateQueue(ArrayList<Video> queue){
|
||||
downloadQueue.addAll(queue);
|
||||
if (downloadQueue.size() == queue.size()){
|
||||
downloadInfo.setDownloadQueue(downloadQueue);
|
||||
startDownload(downloadQueue);
|
||||
}else{
|
||||
downloadInfo.setDownloadQueue(downloadQueue);
|
||||
Toast.makeText(context, getString(R.string.added_to_queue), Toast.LENGTH_SHORT).show();
|
||||
try{
|
||||
for (int i = 0; i < queue.size(); i++){
|
||||
downloadQueue.add((Video) queue.get(i).clone());
|
||||
}
|
||||
if (downloadQueue.size() == queue.size()){
|
||||
downloadInfo.setDownloadQueue(downloadQueue);
|
||||
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);
|
||||
compositeDisposable.clear();
|
||||
//stopForeground(true);
|
||||
if (cancelAll) onDownloadCancel();
|
||||
else onDownloadEnd();
|
||||
if (cancelAll) onDownloadCancelAll();
|
||||
}catch(Exception err){
|
||||
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 (downloadInfo.getVideo().getURL().equals(video.getURL()) && downloadInfo.getVideo().getDownloadedType().equals(video.getDownloadedType())){
|
||||
cancelDownload(false);
|
||||
|
||||
downloadInfo.setDownloadType(type);
|
||||
onDownloadCancel(downloadInfo);
|
||||
|
||||
downloadQueue.pop();
|
||||
downloadInfo.setDownloadQueue(downloadQueue);
|
||||
startDownload(downloadQueue);
|
||||
}else {
|
||||
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();
|
||||
}
|
||||
|
|
@ -195,24 +211,20 @@ public class DownloaderService extends Service {
|
|||
}
|
||||
});
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}catch (Exception ignored){}
|
||||
}
|
||||
|
||||
private void onDownloadCancel(){
|
||||
private void onDownloadCancelAll(){
|
||||
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(downloadInfo);
|
||||
callback.onDownloadCancelAll(downloadInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}catch (Exception ignored){}
|
||||
}
|
||||
|
||||
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) {
|
||||
Video video;
|
||||
if(videos.size() == 0){
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import android.content.SharedPreferences;
|
|||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
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.service.IDownloaderListener;
|
||||
import com.deniscerri.ytdlnis.service.IDownloaderService;
|
||||
import com.deniscerri.ytdlnis.util.NotificationUtil;
|
||||
import com.deniscerri.ytdlnis.util.UpdateUtil;
|
||||
|
||||
import java.text.DateFormat;
|
||||
|
|
@ -203,6 +205,8 @@ public class MainActivity extends AppCompatActivity{
|
|||
context.getApplicationContext().unbindService(serviceConnection);
|
||||
downloaderService.stopForeground(true);
|
||||
downloaderService.stopSelf();
|
||||
NotificationUtil notificationUtil = new NotificationUtil(context.getApplicationContext());
|
||||
notificationUtil.cancelDownloadNotification(NotificationUtil.DOWNLOAD_NOTIFICATION_ID);
|
||||
isDownloadServiceRunning = false;
|
||||
}
|
||||
|
||||
|
|
@ -212,8 +216,8 @@ public class MainActivity extends AppCompatActivity{
|
|||
stopDownloadService();
|
||||
}
|
||||
|
||||
public void removeItemFromDownloadQueue(Video video){
|
||||
iDownloaderService.removeItemFromDownloadQueue(video);
|
||||
public void removeItemFromDownloadQueue(Video video, String type){
|
||||
iDownloaderService.removeItemFromDownloadQueue(video, type);
|
||||
}
|
||||
|
||||
public boolean isDownloadServiceRunning() {
|
||||
|
|
|
|||
|
|
@ -189,6 +189,7 @@ public class HomeRecyclerViewAdapter extends RecyclerView.Adapter<HomeRecyclerVi
|
|||
|
||||
public void updateVideoListItem(Video v, int position){
|
||||
videoList.set(position, v);
|
||||
notifyItemChanged(position);
|
||||
}
|
||||
|
||||
public void clearCheckedVideos(){
|
||||
|
|
|
|||
|
|
@ -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(){
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
db.execSQL(
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package com.deniscerri.ytdlnis.database;
|
|||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class Video implements Parcelable {
|
||||
public class Video implements Parcelable, Cloneable {
|
||||
private int id;
|
||||
private String videoId;
|
||||
private String title;
|
||||
|
|
@ -247,6 +247,11 @@ public class Video implements Parcelable {
|
|||
this.queuedDownload = queuedDownload;
|
||||
}
|
||||
|
||||
public Object clone() throws CloneNotSupportedException
|
||||
{
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||
import androidx.core.app.ActivityCompat;
|
||||
import com.deniscerri.ytdlnis.R;
|
||||
import com.deniscerri.ytdlnis.DownloaderService;
|
||||
import com.deniscerri.ytdlnis.database.Video;
|
||||
import com.deniscerri.ytdlnis.service.DownloadInfo;
|
||||
import com.deniscerri.ytdlnis.service.IDownloaderListener;
|
||||
import com.deniscerri.ytdlnis.service.IDownloaderService;
|
||||
|
|
@ -99,6 +100,8 @@ public class CustomCommandActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public void onDownloadCancel(DownloadInfo downloadInfo) {}
|
||||
|
||||
@Override
|
||||
public void onDownloadCancelAll(DownloadInfo downloadInfo){}
|
||||
|
||||
public void onDownloadServiceEnd() {
|
||||
stopDownloadService();
|
||||
|
|
|
|||
|
|
@ -169,16 +169,25 @@ public class DownloadsFragment extends Fragment implements DownloadsRecyclerView
|
|||
dbManager.updateHistoryItem(item);
|
||||
dbManager.close();
|
||||
downloadsRecyclerViewAdapter.notifyItemChanged(downloadsObjects.indexOf(item));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}catch(Exception ignored){}
|
||||
}
|
||||
|
||||
@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() {}
|
||||
};
|
||||
|
||||
|
|
@ -383,6 +392,24 @@ public class DownloadsFragment extends Fragment implements DownloadsRecyclerView
|
|||
initCards();
|
||||
});
|
||||
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;
|
||||
});
|
||||
|
|
@ -582,14 +609,15 @@ public class DownloadsFragment extends Fragment implements DownloadsRecyclerView
|
|||
|
||||
@Override
|
||||
public void onButtonClick(int position) {
|
||||
Video vid = downloadsObjects.get(position);
|
||||
try {
|
||||
Video vid = downloadsObjects.get(position);
|
||||
downloadsObjects.remove(position);
|
||||
dbManager = new DBManager(context);
|
||||
dbManager.clearHistoryItem(vid);
|
||||
downloadsRecyclerViewAdapter.setVideoList(downloadsObjects);
|
||||
mainActivity.removeItemFromDownloadQueue(vid);
|
||||
}catch (Exception ignored){}
|
||||
mainActivity.removeItemFromDownloadQueue(vid, vid.getDownloadedType());
|
||||
}catch (Exception e){
|
||||
DownloadInfo info = new DownloadInfo();
|
||||
info.setVideo(vid);
|
||||
info.setDownloadType(vid.getDownloadedType());
|
||||
listener.onDownloadCancel(info);
|
||||
}
|
||||
}
|
||||
|
||||
public Video findVideo(String url, String type) {
|
||||
|
|
|
|||
|
|
@ -83,17 +83,16 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
public IDownloaderListener listener = new IDownloaderListener() {
|
||||
|
||||
public void onDownloadStart(DownloadInfo info) {
|
||||
downloading = true;
|
||||
downloadInfo = info;
|
||||
try{
|
||||
if(downloadInfo != null){
|
||||
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;
|
||||
String url = video.getURL();
|
||||
String type = video.getDownloadedType();
|
||||
video = findVideo(url);
|
||||
recyclerView.smoothScrollToPosition(resultObjects.indexOf(video));
|
||||
updateDownloadingStatusOnResult(video, type, true);
|
||||
progressBar = fragmentView.findViewWithTag(downloadInfo.getVideo().getVideoId()+"##progress");
|
||||
topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(true);
|
||||
}
|
||||
|
|
@ -118,11 +117,11 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
downloadInfo = info;
|
||||
try{
|
||||
Video item = downloadInfo.getVideo();
|
||||
String id = item.getVideoId();
|
||||
String url = item.getURL();
|
||||
String type = item.getDownloadedType();
|
||||
updateDownloadStatusOnResult(item, type, false);
|
||||
|
||||
item = findVideo(id);
|
||||
item = findVideo(url);
|
||||
if (type.equals("audio")) item.setDownloadingAudio(false);
|
||||
else if (type.equals("video")) item.setDownloadingVideo(false);
|
||||
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(item));
|
||||
|
|
@ -135,14 +134,14 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
public void onDownloadEnd(DownloadInfo info) {
|
||||
downloadInfo = info;
|
||||
Video item = downloadInfo.getVideo();
|
||||
String id = item.getVideoId();
|
||||
String url = item.getURL();
|
||||
String type = downloadInfo.getDownloadType();
|
||||
item = findVideo(id);
|
||||
item = findVideo(url);
|
||||
try{
|
||||
updateDownloadingStatusOnResult(item, type, false);
|
||||
if (type.equals("audio")) item.setDownloadedAudio(1);
|
||||
else item.setDownloadedVideo(1);
|
||||
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(findVideo(id)));
|
||||
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(findVideo(url)));
|
||||
updateDownloadStatusOnResult(item, type, true);
|
||||
downloading = false;
|
||||
topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(false);
|
||||
|
|
@ -150,17 +149,26 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
}
|
||||
|
||||
@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;
|
||||
try{
|
||||
while (!info.getDownloadQueue().isEmpty()){
|
||||
Video item = downloadInfo.getDownloadQueue().pop();
|
||||
String id = item.getVideoId();
|
||||
String url = item.getURL();
|
||||
String type = item.getDownloadedType();
|
||||
|
||||
item = findVideo(id);
|
||||
item = findVideo(url);
|
||||
updateDownloadingStatusOnResult(item, type, false);
|
||||
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(item));
|
||||
}
|
||||
|
||||
downloading = false;
|
||||
|
|
@ -258,6 +266,13 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
infoUtil = new InfoUtil(context);
|
||||
resultObjects = infoUtil.getTrending(context);
|
||||
dbManager.addToResults(resultObjects);
|
||||
|
||||
uiHandler.post(() -> {
|
||||
homeRecyclerViewAdapter.setVideoList(resultObjects, true);
|
||||
shimmerCards.stopShimmer();
|
||||
shimmerCards.setVisibility(View.GONE);
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.toString());
|
||||
}
|
||||
|
|
@ -271,6 +286,10 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
updateDownloadingStatusOnResult(tmp, "video", false);
|
||||
}
|
||||
}
|
||||
uiHandler.post(() -> {
|
||||
shimmerCards.stopShimmer();
|
||||
shimmerCards.setVisibility(View.GONE);
|
||||
});
|
||||
}
|
||||
}
|
||||
dbManager.close();
|
||||
|
|
@ -280,12 +299,6 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
uiHandler.post(() -> downloadAllFab.setVisibility(View.VISIBLE));
|
||||
}
|
||||
}
|
||||
|
||||
uiHandler.post(() -> {
|
||||
homeRecyclerViewAdapter.setVideoList(resultObjects, true);
|
||||
shimmerCards.stopShimmer();
|
||||
shimmerCards.setVisibility(View.GONE);
|
||||
});
|
||||
});
|
||||
thread.start();
|
||||
} catch (Exception e) {
|
||||
|
|
@ -356,7 +369,6 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
Video vid = downloadInfo.getDownloadQueue().get(i);
|
||||
String type = vid.getDownloadedType();
|
||||
updateDownloadingStatusOnResult(vid, type, false);
|
||||
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(vid));
|
||||
}
|
||||
downloadQueue = new ArrayList<>();
|
||||
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++) {
|
||||
Video v = resultObjects.get(i);
|
||||
if ((v.getVideoId()).equals(id)) {
|
||||
if ((v.getURL()).equals(url)) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
|
@ -582,16 +594,13 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
if (downloading){
|
||||
try {
|
||||
if (btn.getTag(R.id.cancelDownload).equals("true")){
|
||||
mainActivity.removeItemFromDownloadQueue(vid);
|
||||
updateDownloadingStatusOnResult(vid, type, false);
|
||||
homeRecyclerViewAdapter.notifyItemChanged(position);
|
||||
mainActivity.removeItemFromDownloadQueue(vid, type);
|
||||
return;
|
||||
}
|
||||
}catch (Exception ignored){}
|
||||
}
|
||||
downloadQueue.add(vid);
|
||||
updateDownloadingStatusOnResult(vid, type, true);
|
||||
homeRecyclerViewAdapter.notifyItemChanged(position);
|
||||
if (isStoragePermissionGranted()){
|
||||
mainActivity.startDownloadService(downloadQueue, listener);
|
||||
downloadQueue.clear();
|
||||
|
|
@ -689,11 +698,10 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
|
||||
if (!viewIdName.isEmpty()) {
|
||||
if (viewIdName.contains("audio") || viewIdName.contains("video")) {
|
||||
Log.e(TAG, viewIdName);
|
||||
String[] buttonData = viewIdName.split("##");
|
||||
if (buttonData[0].equals("SELECT")) {
|
||||
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]);
|
||||
updateDownloadingStatusOnResult(vid, buttonData[1], true);
|
||||
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(vid));
|
||||
|
|
@ -716,7 +724,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
if (viewIdName.equals("downloadAll")){
|
||||
//remove previously selected
|
||||
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));
|
||||
}
|
||||
selectedObjects = new ArrayList<>();
|
||||
|
|
@ -767,10 +775,9 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
if (start <= 1) start = 0;
|
||||
|
||||
for (int i = start; i < end; i++){
|
||||
Video vid = findVideo(resultObjects.get(i).getVideoId());
|
||||
Video vid = findVideo(resultObjects.get(i).getURL());
|
||||
vid.setDownloadedType(type);
|
||||
updateDownloadingStatusOnResult(vid, type, true);
|
||||
homeRecyclerViewAdapter.notifyItemChanged(resultObjects.indexOf(vid));
|
||||
downloadQueue.add(vid);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
package com.deniscerri.ytdlnis.service;
|
||||
|
||||
import com.deniscerri.ytdlnis.database.Video;
|
||||
|
||||
public interface IDownloaderListener {
|
||||
void onDownloadStart(DownloadInfo downloadInfo);
|
||||
void onDownloadProgress(DownloadInfo downloadInfo);
|
||||
void onDownloadError(DownloadInfo downloadInfo);
|
||||
void onDownloadEnd(DownloadInfo downloadInfo);
|
||||
void onDownloadCancel(DownloadInfo downloadInfo);
|
||||
void onDownloadCancelAll(DownloadInfo downloadInfo);
|
||||
void onDownloadServiceEnd();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ public interface IDownloaderService {
|
|||
void removeActivity(Activity activity);
|
||||
void updateQueue(ArrayList<Video> queue);
|
||||
void cancelDownload(boolean cancelAll);
|
||||
void removeItemFromDownloadQueue(Video video);
|
||||
void removeItemFromDownloadQueue(Video video, String type);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public class InfoUtil {
|
|||
snippet = fixThumbnail(snippet);
|
||||
Video v = createVideofromJSON(snippet);
|
||||
|
||||
if(v.getThumb().isEmpty()){
|
||||
if(v == null || v.getThumb().isEmpty()){
|
||||
continue;
|
||||
}
|
||||
videos.add(createVideofromJSON(snippet));
|
||||
|
|
@ -139,7 +139,7 @@ public class InfoUtil {
|
|||
snippet = fixThumbnail(snippet);
|
||||
Video v = createVideofromJSON(snippet);
|
||||
|
||||
if(v.getThumb().isEmpty()){
|
||||
if(v == null || v.getThumb().isEmpty()){
|
||||
continue;
|
||||
}else{
|
||||
j++;
|
||||
|
|
@ -185,6 +185,7 @@ public class InfoUtil {
|
|||
|
||||
String duration = obj.getString("duration");
|
||||
String thumb = obj.getString("thumb");
|
||||
|
||||
String url = "https://www.youtube.com/watch?v=" + id;
|
||||
int downloadedAudio = dbManager.checkDownloaded(url, "audio");
|
||||
int downloadedVideo = dbManager.checkDownloaded(url, "video");
|
||||
|
|
@ -358,7 +359,7 @@ public class InfoUtil {
|
|||
snippet = fixThumbnail(snippet);
|
||||
|
||||
Video v = createVideofromJSON(snippet);
|
||||
if(v.getThumb().isEmpty()){
|
||||
if(v == null || v.getThumb().isEmpty()){
|
||||
continue;
|
||||
}
|
||||
v.setPlaylistTitle(context.getString(R.string.trendingPlaylist));
|
||||
|
|
|
|||
|
|
@ -75,10 +75,16 @@ public class NotificationUtil {
|
|||
if (queue > 1) contentText += queue - 1 + " " + context.getString(R.string.items_left) + "\n";
|
||||
contentText += desc.replaceAll("\\[.*?\\] ", "");
|
||||
|
||||
notificationBuilder.setProgress(100, (int) progress, false)
|
||||
.setContentTitle(title)
|
||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(contentText));
|
||||
notificationManager.notify(id, notificationBuilder.build());
|
||||
try {
|
||||
notificationBuilder.setProgress(100, (int) progress, false)
|
||||
.setContentTitle(title)
|
||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(contentText));
|
||||
notificationManager.notify(id, notificationBuilder.build());
|
||||
}catch (Exception ignored){}
|
||||
}
|
||||
|
||||
public void cancelDownloadNotification(int id){
|
||||
notificationManager.cancel(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,5 +28,11 @@
|
|||
android:title="@string/remove_duplicates"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/remove_downloading"
|
||||
android:icon="@drawable/ic_delete_all"
|
||||
android:title="@string/remove_downloading"
|
||||
app:showAsAction="never" />
|
||||
|
||||
</menu>
|
||||
|
||||
|
|
|
|||
|
|
@ -106,4 +106,6 @@
|
|||
<string name="newest_first">Të rejat në fillim</string>
|
||||
<string name="oldest_first">Të vjetrat në fillim</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>
|
||||
|
|
@ -111,4 +111,6 @@
|
|||
<item type="id" name="cancelDownload" />
|
||||
<string name="trendingPlaylist" translatable="false">ytdlnis-TRENDING</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>
|
||||
|
|
|
|||
Loading…
Reference in a new issue