2021-03-06 19:55:24 +01:00
|
|
|
package com.darkweb.genesissearchengine.pluginManager;
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import com.darkweb.genesissearchengine.helperManager.localFileDownloader;
|
|
|
|
import com.darkweb.genesissearchengine.helperManager.eventObserver;
|
|
|
|
import com.darkweb.genesissearchengine.helperManager.helperMethod;
|
2021-04-11 21:25:15 +02:00
|
|
|
import java.lang.ref.WeakReference;
|
2021-03-06 19:55:24 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
class downloadManager
|
|
|
|
{
|
|
|
|
/*Private Variables*/
|
|
|
|
|
2021-04-11 21:25:15 +02:00
|
|
|
private WeakReference<AppCompatActivity> mAppContext;
|
2021-04-18 10:37:16 +02:00
|
|
|
private Map<Integer, localFileDownloader> mDownloads = new HashMap<>();
|
2021-03-06 19:55:24 +01:00
|
|
|
|
|
|
|
/*Initializations*/
|
|
|
|
|
2021-04-11 21:25:15 +02:00
|
|
|
downloadManager(WeakReference<AppCompatActivity> pAppContext, eventObserver.eventListener pEvent){
|
2021-03-06 19:55:24 +01:00
|
|
|
this.mAppContext = pAppContext;
|
|
|
|
initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initialize()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private void startDownload(String pPath,String pFile) {
|
|
|
|
int mID = helperMethod.createNotificationID();
|
2021-04-11 21:25:15 +02:00
|
|
|
localFileDownloader mFileDownloader = (localFileDownloader)new localFileDownloader(mAppContext.get().getApplicationContext(),pPath, pFile, mID).execute(pPath);
|
2021-03-06 19:55:24 +01:00
|
|
|
mDownloads.put(mID,mFileDownloader);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void cancelDownload(int pID) {
|
|
|
|
Objects.requireNonNull(mDownloads.get(pID)).onCancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onTriggerDownload(int pID) {
|
|
|
|
Objects.requireNonNull(mDownloads.get(pID)).onTrigger();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*External Triggers*/
|
|
|
|
|
|
|
|
Object onTrigger(List<Object> pData, pluginEnums.eDownloadManager pEventType) {
|
|
|
|
if(pEventType.equals(pluginEnums.eDownloadManager.M_DOWNLOAD_FILE))
|
|
|
|
{
|
|
|
|
startDownload((String) pData.get(0),(String)pData.get(1));
|
|
|
|
}
|
|
|
|
else if(pEventType.equals(pluginEnums.eDownloadManager.M_CANCEL))
|
|
|
|
{
|
|
|
|
cancelDownload((int) pData.get(0));
|
|
|
|
}
|
|
|
|
else if(pEventType.equals(pluginEnums.eDownloadManager.M_TRIGGER))
|
|
|
|
{
|
|
|
|
onTriggerDownload((int) pData.get(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|