Search in sources :

Example 1 with AssetIndexItem

use of net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem in project Osmand by osmandapp.

the class DownloadResources method checkIfItemOutdated.

public boolean checkIfItemOutdated(IndexItem item, java.text.DateFormat format) {
    boolean outdated = false;
    String sfName = item.getTargetFileName();
    String indexActivatedDate = indexActivatedFileNames.get(sfName);
    String indexFilesDate = indexFileNames.get(sfName);
    item.setDownloaded(false);
    item.setOutdated(false);
    if (indexActivatedDate == null && indexFilesDate == null) {
        return false;
    }
    item.setDownloaded(true);
    String date = item.getDate(format);
    boolean parsed = false;
    if (indexActivatedDate != null) {
        try {
            item.setLocalTimestamp(format.parse(indexActivatedDate).getTime());
            parsed = true;
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    if (!parsed && indexFilesDate != null) {
        try {
            item.setLocalTimestamp(format.parse(indexFilesDate).getTime());
            parsed = true;
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    if (date != null && !date.equals(indexActivatedDate) && !date.equals(indexFilesDate)) {
        if ((item.getType() == DownloadActivityType.NORMAL_FILE && !item.extra) || item.getType() == DownloadActivityType.ROADS_FILE || item.getType() == DownloadActivityType.WIKIPEDIA_FILE || item.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE || item.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
            outdated = true;
        } else {
            long itemSize = item.getContentSize();
            long oldItemSize = 0;
            if (item.getType() == DownloadActivityType.VOICE_FILE) {
                if (item instanceof AssetIndexItem) {
                    File file = new File(((AssetIndexItem) item).getDestFile());
                    oldItemSize = file.length();
                } else {
                    File fl = new File(item.getType().getDownloadFolder(app, item), sfName + "/_config.p");
                    if (fl.exists()) {
                        oldItemSize = fl.length();
                        try {
                            InputStream is = app.getAssets().open("voice/" + sfName + "/config.p");
                            if (is != null) {
                                itemSize = is.available();
                                is.close();
                            }
                        } catch (IOException e) {
                        }
                    }
                }
            } else if (item.getType() == DownloadActivityType.FONT_FILE) {
                oldItemSize = new File(app.getAppPath(IndexConstants.FONT_INDEX_DIR), item.getTargetFileName()).length();
            } else {
                oldItemSize = app.getAppPath(item.getTargetFileName()).length();
            }
            if (itemSize != oldItemSize) {
                outdated = true;
            }
        }
    }
    item.setOutdated(outdated);
    return outdated;
}
Also used : AssetIndexItem(net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem) InputStream(java.io.InputStream) ParseException(java.text.ParseException) IOException(java.io.IOException) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ParseException (java.text.ParseException)1 AssetIndexItem (net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem)1