diff --git a/app/build.gradle b/app/build.gradle index e91513c4..10911bfb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "com.dar.nclientv2" minSdkVersion 14 targetSdkVersion 29 - versionCode 253 - versionName "2.5.3" + versionCode 254 + versionName "2.5.4" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/com/dar/nclientv2/adapters/LocalAdapter.java b/app/src/main/java/com/dar/nclientv2/adapters/LocalAdapter.java index ed66c81b..982645fa 100644 --- a/app/src/main/java/com/dar/nclientv2/adapters/LocalAdapter.java +++ b/app/src/main/java/com/dar/nclientv2/adapters/LocalAdapter.java @@ -77,7 +77,7 @@ public void triggerEndDownload(GalleryDownloaderV2 downloader) { } @Override - public void triggerStopDownlaod(GalleryDownloaderV2 downloader) { + public void triggerCancelDownload(GalleryDownloaderV2 downloader) { removeDownloader(downloader); } diff --git a/app/src/main/java/com/dar/nclientv2/async/downloader/DownloadGalleryV2.java b/app/src/main/java/com/dar/nclientv2/async/downloader/DownloadGalleryV2.java index f0d1d8c6..015f9f9d 100644 --- a/app/src/main/java/com/dar/nclientv2/async/downloader/DownloadGalleryV2.java +++ b/app/src/main/java/com/dar/nclientv2/async/downloader/DownloadGalleryV2.java @@ -18,6 +18,7 @@ import java.util.List; public class DownloadGalleryV2 extends JobIntentService { + private static final Object lock=new Object(); private static final int JOB_DOWNLOAD_GALLERY_ID=9999; public static void downloadGallery(Context context, GenericGallery gallery){ if(gallery.isValid() && gallery instanceof Gallery)downloadGallery(context,(Gallery) gallery); @@ -43,6 +44,7 @@ private static void downloadGallery(Context context, Gallery gallery,int start,i @Override public int onStartCommand(@Nullable Intent intent, int flags, int startId) { + int startCommand=super.onStartCommand(intent, flags, startId); if(intent!=null){ int id=intent.getIntExtra(getPackageName()+".ID",-1); String mode=intent.getStringExtra(getPackageName()+".MODE"); @@ -62,7 +64,7 @@ public int onStartCommand(@Nullable Intent intent, int flags, int startId) { } } } - return super.onStartCommand(intent, flags, startId); + return startCommand; } public static void loadDownloads(Context context) { @@ -86,14 +88,26 @@ public static void downloadRange(Context context, Gallery gallery, int start, in public static void startWork(@Nullable Context context) { if(context!=null) enqueueWork(context,DownloadGalleryV2.class,JOB_DOWNLOAD_GALLERY_ID,new Intent()); + synchronized (lock) { + lock.notify(); + } } @Override protected void onHandleWork(@NonNull Intent intent) { - while (true){ + for(;;){ obtainData(); GalleryDownloaderManager entry = DownloadQueue.fetch(); - if(entry==null)return; + if(entry==null){ + synchronized (lock) { + try { + lock.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + continue; + } LogUtility.d("Downloading: "+entry.downloader().getId()); if(entry.downloader().downloadGalleryData()){ entry.downloader().download(); diff --git a/app/src/main/java/com/dar/nclientv2/async/downloader/DownloadObserver.java b/app/src/main/java/com/dar/nclientv2/async/downloader/DownloadObserver.java index c525e2d2..8679244e 100644 --- a/app/src/main/java/com/dar/nclientv2/async/downloader/DownloadObserver.java +++ b/app/src/main/java/com/dar/nclientv2/async/downloader/DownloadObserver.java @@ -4,6 +4,6 @@ public interface DownloadObserver{ void triggerStartDownload(GalleryDownloaderV2 downloader); void triggerUpdateProgress(GalleryDownloaderV2 downloader,int reach,int total); void triggerEndDownload(GalleryDownloaderV2 downloader); - void triggerStopDownlaod(GalleryDownloaderV2 downloader); + void triggerCancelDownload(GalleryDownloaderV2 downloader); void triggerPauseDownload(GalleryDownloaderV2 downloader); } diff --git a/app/src/main/java/com/dar/nclientv2/async/downloader/GalleryDownloaderManager.java b/app/src/main/java/com/dar/nclientv2/async/downloader/GalleryDownloaderManager.java index d19145c7..b2e40cd6 100644 --- a/app/src/main/java/com/dar/nclientv2/async/downloader/GalleryDownloaderManager.java +++ b/app/src/main/java/com/dar/nclientv2/async/downloader/GalleryDownloaderManager.java @@ -46,7 +46,7 @@ public void triggerEndDownload(GalleryDownloaderV2 downloader) { } @Override - public void triggerStopDownlaod(GalleryDownloaderV2 downloader) { + public void triggerCancelDownload(GalleryDownloaderV2 downloader) { cancelNotification(); Global.recursiveDelete(downloader.getFolder()); } diff --git a/app/src/main/java/com/dar/nclientv2/async/downloader/GalleryDownloaderV2.java b/app/src/main/java/com/dar/nclientv2/async/downloader/GalleryDownloaderV2.java index e04b86cf..543eaaf3 100644 --- a/app/src/main/java/com/dar/nclientv2/async/downloader/GalleryDownloaderV2.java +++ b/app/src/main/java/com/dar/nclientv2/async/downloader/GalleryDownloaderV2.java @@ -97,7 +97,7 @@ private void onUpdate(){ for(DownloadObserver observer:observers)observer.triggerUpdateProgress(this,reach,total); } private void onCancel(){ - for(DownloadObserver observer:observers)observer.triggerStopDownlaod(this); + for(DownloadObserver observer:observers)observer.triggerCancelDownload(this); } private void onPause(){ for(DownloadObserver observer:observers)observer.triggerPauseDownload(this); diff --git a/app/src/main/java/com/dar/nclientv2/components/views/CustomWebView.java b/app/src/main/java/com/dar/nclientv2/components/views/CustomWebView.java index 9e110662..7ab75ddb 100644 --- a/app/src/main/java/com/dar/nclientv2/components/views/CustomWebView.java +++ b/app/src/main/java/com/dar/nclientv2/components/views/CustomWebView.java @@ -35,6 +35,12 @@ public CustomWebView(Context context, AttributeSet attrs) { initialize(); } + @Override + public void loadUrl(String url) { + LogUtility.d("Loading url: "+url); + super.loadUrl(url); + } + public CustomWebView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); javaScriptInterface=new MyJavaScriptInterface(context.getApplicationContext()); diff --git a/app/src/main/java/com/dar/nclientv2/settings/NotificationSettings.java b/app/src/main/java/com/dar/nclientv2/settings/NotificationSettings.java index 39f2da9b..51d461b9 100644 --- a/app/src/main/java/com/dar/nclientv2/settings/NotificationSettings.java +++ b/app/src/main/java/com/dar/nclientv2/settings/NotificationSettings.java @@ -37,10 +37,10 @@ public static void notify(String channel, int notificationId, Notification notif notificationArray.add(notificationId); trimArray(); LogUtility.d("Notification count: "+notificationArray.size()); - notificationSettings.notificationManager.notify(null,notificationId,notification); + notificationSettings.notificationManager.notify(notificationId,notification); } public static void cancel(String channel, int notificationId){ - notificationSettings.notificationManager.cancel(channel,notificationId); + notificationSettings.notificationManager.cancel(notificationId); notificationArray.remove(Integer.valueOf(notificationId)); } private static void trimArray(){