Search in sources :

Example 1 with SharedDeckDownload

use of com.ichi2.anki.SharedDeckDownload in project Anki-Android by Ramblurr.

the class DownloadManagerService method addIncompleteDownloads.

// It could be part of the AIDL Interface but at the moment no Activity uses it directly
public void addIncompleteDownloads() {
    Log.i(AnkiDroidApp.TAG, "DownloadManagerService - Adding incomplete downloads:");
    File dir = new File(mDestination + "/tmp/");
    File[] fileList = dir.listFiles(new IncompleteDownloadsFilter());
    if (fileList != null) {
        for (File file : fileList) {
            String filename = file.getName();
            Log.i(AnkiDroidApp.TAG, "Filename = " + filename);
            // Personal decks
            if (filename.endsWith(".anki.tmp")) {
                Download download = new Download(filename.substring(0, filename.length() - ".anki.tmp".length()));
                download.setDownloaded(file.length());
                mPersonalDeckDownloads.add(download);
            } else // Shared decks
            if (filename.endsWith(".shared.zip.tmp")) {
                filename = filename.substring(0, filename.length() - ".shared.zip.tmp".length());
                int lastDotPosition = filename.lastIndexOf(".");
                String identifier = filename.substring(lastDotPosition + 1, filename.length());
                String title = filename.substring(0, lastDotPosition);
                SharedDeckDownload download = new SharedDeckDownload(Integer.parseInt(identifier), title);
                download.setDownloaded(file.length());
                mSharedDeckDownloads.add(download);
            } else // Shared but not totally updated decks
            if (filename.endsWith(".anki.updating")) {
                String title = filename.substring(0, filename.length() - ".anki.updating".length());
                SharedDeckDownload download = new SharedDeckDownload(title);
                SharedPreferences pref = AnkiDroidApp.getSharedPrefs(getBaseContext());
                String pausedPref = "paused:" + mDestination + "/tmp/" + download.getFilename() + ".anki.updating";
                if (pref.getBoolean(pausedPref, false)) {
                    download.setStatus(SharedDeckDownload.STATUS_PAUSED);
                } else {
                    download.setStatus(SharedDeckDownload.STATUS_UPDATING);
                }
                mSharedDeckDownloads.add(download);
            }
        }
        notifyObservers();
    }
    // If no decks were added, stop the service
    stopIfFinished();
}
Also used : SharedPreferences(android.content.SharedPreferences) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) SharedDeckDownload(com.ichi2.anki.SharedDeckDownload) Download(com.ichi2.anki.Download) SharedDeckDownload(com.ichi2.anki.SharedDeckDownload)

Example 2 with SharedDeckDownload

use of com.ichi2.anki.SharedDeckDownload in project Anki-Android by Ramblurr.

the class DownloadManagerService method resumeDownload.

// It could be part of the AIDL Interface but at the moment no Activity uses it directly
public void resumeDownload(Download download) {
    // Create tmp folder where the temporal decks are going to be stored
    new File(mDestination + "/tmp/").mkdirs();
    AnkiDroidApp.createNoMediaFileIfMissing(new File(mDestination));
    if (download instanceof SharedDeckDownload) {
        SharedDeckDownload sharedDeckDownload = (SharedDeckDownload) download;
        // numUpdatedCards and numTotalCards to get updated, so that progress is displayed correctly
        if (sharedDeckDownload.getStatus() == SharedDeckDownload.STATUS_PAUSED || sharedDeckDownload.getStatus() == SharedDeckDownload.STATUS_UPDATING) {
            new UpdateDeckTask().execute(new Payload(new Object[] { sharedDeckDownload }));
        } else {
            new DownloadSharedDeckTask().execute(sharedDeckDownload);
        }
    } else {
        // TODO: Check if there is already a deck with the same name, and if that's so
        // add the current milliseconds to the end of the name or notify the user
        new DownloadPersonalDeckTask().execute(download);
    }
}
Also used : Payload(com.ichi2.async.Connection.Payload) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) SharedDeckDownload(com.ichi2.anki.SharedDeckDownload)

Aggregations

SharedDeckDownload (com.ichi2.anki.SharedDeckDownload)2 File (java.io.File)2 RandomAccessFile (java.io.RandomAccessFile)2 SharedPreferences (android.content.SharedPreferences)1 Download (com.ichi2.anki.Download)1 Payload (com.ichi2.async.Connection.Payload)1