Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3bd6c8c9 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

refactor DownloadSrcController

parent 3bc5c6bb
Loading
Loading
Loading
Loading
+14 −18
Original line number Diff line number Diff line
@@ -19,14 +19,11 @@ package ecorp.easy.installer.controllers.subcontrollers;

import ecorp.easy.installer.AppConstants;
import ecorp.easy.installer.controllers.MainWindowController;
import ecorp.easy.installer.helpers.DeviceHelper;
import ecorp.easy.installer.models.RomSource;
import ecorp.easy.installer.tasks.CommandExecutionTask;
import ecorp.easy.installer.tasks.DownloadTask;
import ecorp.easy.installer.utils.UiUtils;
import java.io.IOException;
import java.net.URL;
import java.text.ParseException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
@@ -61,16 +58,17 @@ public class DownloadSrcController extends AbstractSubController {
    public void initialize(URL location, ResourceBundle resources) {
        super.initialize(location, resources);
        UiUtils.hideNode(restartDownloadBtn);
        currentService = new DownloadService();
    }

    @Override
    public void setParentController(MainWindowController parentController){
        super.setParentController(parentController);
        
        
        //@todo replace with parentController.getPreparationprocess.getSourcesToDownload();
        //Also move the try catch when we load preparationprocess
        sourcesToDownload = parentController.getPhone().getPrepProcess().getSourcesToDownload();
        sourceIterator =  sourcesToDownload.entrySet().iterator();
        /*try{
            
            //sourcesToDownload = DeviceHelper.getSourcesToDownload(parentController.getPhone().getAdbDevice());
@@ -80,24 +78,26 @@ public class DownloadSrcController extends AbstractSubController {
            
            return;
        }*/

        sourceIterator =  sourcesToDownload.entrySet().iterator();
        startNextDownload();

    }
    
    private boolean startNextDownload(){
    /**
     * Start to download a part of the rom
     * or display complete Downloading
     */
    private void startNextDownload(){
        logger.info("startNextDownload()");
        logger.debug("taskIterator has next ? {} "+sourceIterator.hasNext());
        if(sourceIterator.hasNext()){
            HashMap.Entry<String, RomSource> source = sourceIterator.next();
            
            currentService = new DownloadService(source.getValue());
            currentService.setSource(source.getValue());
            bindProgressUIToService(currentService);
            
            currentService.reset();
            currentService.start();
            return true;
        }
        return false;
        }else
            onDownloadsComplete(); //Looks like a side effect...
    }
    
    /**
@@ -183,10 +183,6 @@ public class DownloadSrcController extends AbstractSubController {
        private RomSource source;


        public DownloadService(final RomSource source){
            this.source = source;
        }

        /**
         * Change the source to download to a new one
         * @param source 
@@ -206,7 +202,7 @@ public class DownloadSrcController extends AbstractSubController {
            unbindProgressUI();
            if((Boolean) this.getValue() ){ //This read the "value" (boolean) defined at end of run in DownloadTask
                //So here: it returns true if file is downloaded and checksum verified
                if(! startNextDownload() ) onDownloadsComplete(); //if no more download to do, then preparation is over
                startNextDownload();
            }else{ //either download or checksum checks failed
                displayErrorProgressBar(false);
            }