Search in sources :

Example 1 with EmojiPageModel

use of org.thoughtcrime.securesms.components.emoji.EmojiPageModel in project Signal-Android by WhisperSystems.

the class DownloadLatestEmojiDataJob method onRun.

@Override
protected void onRun() throws Exception {
    EmojiFiles.Version version = EmojiFiles.Version.readVersion(context);
    int localVersion = (version != null) ? version.getVersion() : 0;
    int serverVersion = EmojiRemote.getVersion();
    String bucket;
    if (targetVersion == null) {
        ScreenDensity density = ScreenDensity.get(context);
        bucket = getDesiredRemoteBucketForDensity(density);
    } else {
        bucket = targetVersion.getDensity();
    }
    Log.d(TAG, "LocalVersion: " + localVersion + ", ServerVersion: " + serverVersion + ", Bucket: " + bucket);
    if (bucket == null) {
        Log.d(TAG, "This device has too low a display density to download remote emoji.");
    } else if (localVersion == serverVersion) {
        Log.d(TAG, "Already have latest emoji data. Skipping.");
    } else if (serverVersion > localVersion) {
        Log.d(TAG, "New server data detected. Starting download...");
        if (targetVersion == null || targetVersion.getVersion() != serverVersion) {
            targetVersion = new EmojiFiles.Version(serverVersion, UUID.randomUUID(), bucket);
        }
        if (isCanceled()) {
            Log.w(TAG, "Job was cancelled prior to downloading json.");
            return;
        }
        EmojiData emojiData = downloadJson(context, targetVersion);
        List<String> supportedDensities = emojiData.getDensities();
        String format = emojiData.getFormat();
        List<String> imagePaths = Stream.of(emojiData.getDataPages()).map(EmojiPageModel::getSpriteUri).map(Uri::getLastPathSegment).toList();
        String density = resolveDensity(supportedDensities, targetVersion.getDensity());
        targetVersion = new EmojiFiles.Version(targetVersion.getVersion(), targetVersion.getUuid(), density);
        if (isCanceled()) {
            Log.w(TAG, "Job was cancelled after downloading json.");
            return;
        }
        downloadImages(context, targetVersion, imagePaths, format, this::isCanceled);
        if (isCanceled()) {
            Log.w(TAG, "Job was cancelled during or after downloading images.");
            return;
        }
        clearOldEmojiData(context, targetVersion);
        markComplete(targetVersion);
        EmojiSource.refresh();
        JumboEmoji.updateCurrentVersion(context);
    } else {
        Log.d(TAG, "Server has an older version than we do. Skipping.");
    }
}
Also used : ScreenDensity(org.thoughtcrime.securesms.util.ScreenDensity) AutoDownloadEmojiConstraint(org.thoughtcrime.securesms.jobmanager.impl.AutoDownloadEmojiConstraint) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) EmojiPageModel(org.thoughtcrime.securesms.components.emoji.EmojiPageModel) EmojiFiles(org.thoughtcrime.securesms.emoji.EmojiFiles) EmojiData(org.thoughtcrime.securesms.emoji.EmojiData)

Example 2 with EmojiPageModel

use of org.thoughtcrime.securesms.components.emoji.EmojiPageModel in project Signal-Android by signalapp.

the class DownloadLatestEmojiDataJob method onRun.

@Override
protected void onRun() throws Exception {
    EmojiFiles.Version version = EmojiFiles.Version.readVersion(context);
    int localVersion = (version != null) ? version.getVersion() : 0;
    int serverVersion = EmojiRemote.getVersion();
    String bucket;
    if (targetVersion == null) {
        ScreenDensity density = ScreenDensity.get(context);
        bucket = getDesiredRemoteBucketForDensity(density);
    } else {
        bucket = targetVersion.getDensity();
    }
    Log.d(TAG, "LocalVersion: " + localVersion + ", ServerVersion: " + serverVersion + ", Bucket: " + bucket);
    if (bucket == null) {
        Log.d(TAG, "This device has too low a display density to download remote emoji.");
    } else if (localVersion == serverVersion) {
        Log.d(TAG, "Already have latest emoji data. Skipping.");
    } else if (serverVersion > localVersion) {
        Log.d(TAG, "New server data detected. Starting download...");
        if (targetVersion == null || targetVersion.getVersion() != serverVersion) {
            targetVersion = new EmojiFiles.Version(serverVersion, UUID.randomUUID(), bucket);
        }
        if (isCanceled()) {
            Log.w(TAG, "Job was cancelled prior to downloading json.");
            return;
        }
        EmojiData emojiData = downloadJson(context, targetVersion);
        List<String> supportedDensities = emojiData.getDensities();
        String format = emojiData.getFormat();
        List<String> imagePaths = Stream.of(emojiData.getDataPages()).map(EmojiPageModel::getSpriteUri).map(Uri::getLastPathSegment).toList();
        String density = resolveDensity(supportedDensities, targetVersion.getDensity());
        targetVersion = new EmojiFiles.Version(targetVersion.getVersion(), targetVersion.getUuid(), density);
        if (isCanceled()) {
            Log.w(TAG, "Job was cancelled after downloading json.");
            return;
        }
        downloadImages(context, targetVersion, imagePaths, format, this::isCanceled);
        if (isCanceled()) {
            Log.w(TAG, "Job was cancelled during or after downloading images.");
            return;
        }
        clearOldEmojiData(context, targetVersion);
        markComplete(targetVersion);
        EmojiSource.refresh();
        JumboEmoji.updateCurrentVersion(context);
    } else {
        Log.d(TAG, "Server has an older version than we do. Skipping.");
    }
}
Also used : ScreenDensity(org.thoughtcrime.securesms.util.ScreenDensity) AutoDownloadEmojiConstraint(org.thoughtcrime.securesms.jobmanager.impl.AutoDownloadEmojiConstraint) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) EmojiPageModel(org.thoughtcrime.securesms.components.emoji.EmojiPageModel) EmojiFiles(org.thoughtcrime.securesms.emoji.EmojiFiles) EmojiData(org.thoughtcrime.securesms.emoji.EmojiData)

Aggregations

EmojiPageModel (org.thoughtcrime.securesms.components.emoji.EmojiPageModel)2 EmojiData (org.thoughtcrime.securesms.emoji.EmojiData)2 EmojiFiles (org.thoughtcrime.securesms.emoji.EmojiFiles)2 AutoDownloadEmojiConstraint (org.thoughtcrime.securesms.jobmanager.impl.AutoDownloadEmojiConstraint)2 NetworkConstraint (org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint)2 ScreenDensity (org.thoughtcrime.securesms.util.ScreenDensity)2