Java Code Examples for org.telegram.tgnet.TLRPC#TL_fileLocationToBeDeprecated

The following examples show how to use org.telegram.tgnet.TLRPC#TL_fileLocationToBeDeprecated . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileLoader.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void loadFile(final TLRPC.Document document, final SecureDocument secureDocument, final WebFile webDocument, TLRPC.TL_fileLocationToBeDeprecated location, final ImageLocation imageLocation, final Object parentObject, final String locationExt, final int locationSize, final int priority, final int cacheType) {
    String fileName;
    if (location != null) {
        fileName = getAttachFileName(location, locationExt);
    } else if (document != null) {
        fileName = getAttachFileName(document);
    } else if (webDocument != null) {
        fileName = getAttachFileName(webDocument);
    } else {
        fileName = null;
    }
    if (cacheType != 10 && !TextUtils.isEmpty(fileName) && !fileName.contains("" + Integer.MIN_VALUE)) {
        loadOperationPathsUI.put(fileName, true);
    }
    fileLoaderQueue.postRunnable(() -> loadFileInternal(document, secureDocument, webDocument, location, imageLocation, parentObject, locationExt, locationSize, priority, null, 0, false, cacheType));
}
 
Example 2
Source File: FileLoader.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void loadFile(final TLRPC.Document document, final SecureDocument secureDocument, final WebFile webDocument, TLRPC.TL_fileLocationToBeDeprecated location, final ImageLocation imageLocation, final Object parentObject, final String locationExt, final int locationSize, final int priority, final int cacheType) {
    String fileName;
    if (location != null) {
        fileName = getAttachFileName(location, locationExt);
    } else if (document != null) {
        fileName = getAttachFileName(document);
    } else if (webDocument != null) {
        fileName = getAttachFileName(webDocument);
    } else {
        fileName = null;
    }
    if (cacheType != 10 && !TextUtils.isEmpty(fileName) && !fileName.contains("" + Integer.MIN_VALUE)) {
        loadOperationPathsUI.put(fileName, true);
    }
    fileLoaderQueue.postRunnable(() -> loadFileInternal(document, secureDocument, webDocument, location, imageLocation, parentObject, locationExt, locationSize, priority, null, 0, false, cacheType));
}
 
Example 3
Source File: ImageLocation.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static ImageLocation getForLocal(TLRPC.FileLocation location) {
    if (location == null) {
        return null;
    }
    ImageLocation imageLocation = new ImageLocation();
    imageLocation.location = new TLRPC.TL_fileLocationToBeDeprecated();
    imageLocation.location.local_id = location.local_id;
    imageLocation.location.volume_id = location.volume_id;
    imageLocation.location.secret = location.secret;
    imageLocation.location.dc_id = location.dc_id;
    return imageLocation;
}
 
Example 4
Source File: ImageLocation.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static ImageLocation getForPhoto(TLRPC.FileLocation location, int size, TLRPC.Photo photo, TLRPC.Document document, TLRPC.InputPeer photoPeer, boolean photoPeerBig, int dc_id, TLRPC.InputStickerSet stickerSet, String thumbSize) {
    if (location == null || photo == null && photoPeer == null && stickerSet == null && document == null) {
        return null;
    }
    ImageLocation imageLocation = new ImageLocation();
    imageLocation.dc_id = dc_id;
    imageLocation.photo = photo;
    imageLocation.currentSize = size;
    imageLocation.photoPeer = photoPeer;
    imageLocation.photoPeerBig = photoPeerBig;
    imageLocation.stickerSet = stickerSet;
    if (location instanceof TLRPC.TL_fileLocationToBeDeprecated) {
        imageLocation.location = (TLRPC.TL_fileLocationToBeDeprecated) location;
        if (photo != null) {
            imageLocation.file_reference = photo.file_reference;
            imageLocation.access_hash = photo.access_hash;
            imageLocation.photoId = photo.id;
            imageLocation.thumbSize = thumbSize;
        } else if (document != null) {
            imageLocation.file_reference = document.file_reference;
            imageLocation.access_hash = document.access_hash;
            imageLocation.documentId = document.id;
            imageLocation.thumbSize = thumbSize;
        }
    } else {
        imageLocation.location = new TLRPC.TL_fileLocationToBeDeprecated();
        imageLocation.location.local_id = location.local_id;
        imageLocation.location.volume_id = location.volume_id;
        imageLocation.location.secret = location.secret;
        imageLocation.dc_id = location.dc_id;
        imageLocation.file_reference = location.file_reference;
        imageLocation.key = location.key;
        imageLocation.iv = location.iv;
        imageLocation.access_hash = location.secret;
    }
    return imageLocation;
}
 
Example 5
Source File: ImageLocation.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static ImageLocation getForLocal(TLRPC.FileLocation location) {
    if (location == null) {
        return null;
    }
    ImageLocation imageLocation = new ImageLocation();
    imageLocation.location = new TLRPC.TL_fileLocationToBeDeprecated();
    imageLocation.location.local_id = location.local_id;
    imageLocation.location.volume_id = location.volume_id;
    imageLocation.location.secret = location.secret;
    imageLocation.location.dc_id = location.dc_id;
    return imageLocation;
}
 
Example 6
Source File: ImageLocation.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static ImageLocation getForPhoto(TLRPC.FileLocation location, int size, TLRPC.Photo photo, TLRPC.Document document, TLRPC.InputPeer photoPeer, boolean photoPeerBig, int dc_id, TLRPC.InputStickerSet stickerSet, String thumbSize) {
    if (location == null || photo == null && photoPeer == null && stickerSet == null && document == null) {
        return null;
    }
    ImageLocation imageLocation = new ImageLocation();
    imageLocation.dc_id = dc_id;
    imageLocation.photo = photo;
    imageLocation.currentSize = size;
    imageLocation.photoPeer = photoPeer;
    imageLocation.photoPeerBig = photoPeerBig;
    imageLocation.stickerSet = stickerSet;
    if (location instanceof TLRPC.TL_fileLocationToBeDeprecated) {
        imageLocation.location = (TLRPC.TL_fileLocationToBeDeprecated) location;
        if (photo != null) {
            imageLocation.file_reference = photo.file_reference;
            imageLocation.access_hash = photo.access_hash;
            imageLocation.photoId = photo.id;
            imageLocation.thumbSize = thumbSize;
        } else if (document != null) {
            imageLocation.file_reference = document.file_reference;
            imageLocation.access_hash = document.access_hash;
            imageLocation.documentId = document.id;
            imageLocation.thumbSize = thumbSize;
        }
    } else {
        imageLocation.location = new TLRPC.TL_fileLocationToBeDeprecated();
        imageLocation.location.local_id = location.local_id;
        imageLocation.location.volume_id = location.volume_id;
        imageLocation.location.secret = location.secret;
        imageLocation.dc_id = location.dc_id;
        imageLocation.file_reference = location.file_reference;
        imageLocation.key = location.key;
        imageLocation.iv = location.iv;
        imageLocation.access_hash = location.secret;
    }
    return imageLocation;
}
 
Example 7
Source File: ImageLoader.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private static TLRPC.PhotoSize scaleAndSaveImageInternal(TLRPC.PhotoSize photoSize, Bitmap bitmap, Bitmap.CompressFormat compressFormat, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache, boolean scaleAnyway, boolean forceCacheDir) throws Exception {
    Bitmap scaledBitmap;
    if (scaleFactor > 1 || scaleAnyway) {
        scaledBitmap = Bitmaps.createScaledBitmap(bitmap, w, h, true);
    } else {
        scaledBitmap = bitmap;
    }

    boolean check = photoSize != null;
    TLRPC.TL_fileLocationToBeDeprecated location;
    if (photoSize == null || !(photoSize.location instanceof TLRPC.TL_fileLocationToBeDeprecated)) {
        location = new TLRPC.TL_fileLocationToBeDeprecated();
        location.volume_id = Integer.MIN_VALUE;
        location.dc_id = Integer.MIN_VALUE;
        location.local_id = SharedConfig.getLastLocalId();
        location.file_reference = new byte[0];

        photoSize = new TLRPC.TL_photoSize();
        photoSize.location = location;
        photoSize.w = scaledBitmap.getWidth();
        photoSize.h = scaledBitmap.getHeight();
        if (photoSize.w <= 100 && photoSize.h <= 100) {
            photoSize.type = "s";
        } else if (photoSize.w <= 320 && photoSize.h <= 320) {
            photoSize.type = "m";
        } else if (photoSize.w <= 800 && photoSize.h <= 800) {
            photoSize.type = "x";
        } else if (photoSize.w <= 1280 && photoSize.h <= 1280) {
            photoSize.type = "y";
        } else {
            photoSize.type = "w";
        }
    } else {
        location = (TLRPC.TL_fileLocationToBeDeprecated) photoSize.location;
    }

    String fileName = location.volume_id + "_" + location.local_id + ".jpg";
    File fileDir;
    if (forceCacheDir) {
        fileDir = FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE);
    } else {
        fileDir = location.volume_id != Integer.MIN_VALUE ? FileLoader.getDirectory(FileLoader.MEDIA_DIR_IMAGE) : FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE);
    }
    final File cacheFile = new File(fileDir, fileName);
    FileOutputStream stream = new FileOutputStream(cacheFile);
    scaledBitmap.compress(compressFormat, quality, stream);
    if (cache) {
        ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
        scaledBitmap.compress(compressFormat, quality, stream2);
        photoSize.bytes = stream2.toByteArray();
        photoSize.size = photoSize.bytes.length;
        stream2.close();
    } else {
        photoSize.size = (int) stream.getChannel().size();
    }
    stream.close();
    if (scaledBitmap != bitmap) {
        scaledBitmap.recycle();
    }

    return photoSize;
}
 
Example 8
Source File: ImageLoader.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private static TLRPC.PhotoSize scaleAndSaveImageInternal(TLRPC.PhotoSize photoSize, Bitmap bitmap, Bitmap.CompressFormat compressFormat, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache, boolean scaleAnyway, boolean forceCacheDir) throws Exception {
    Bitmap scaledBitmap;
    if (scaleFactor > 1 || scaleAnyway) {
        scaledBitmap = Bitmaps.createScaledBitmap(bitmap, w, h, true);
    } else {
        scaledBitmap = bitmap;
    }

    boolean check = photoSize != null;
    TLRPC.TL_fileLocationToBeDeprecated location;
    if (photoSize == null || !(photoSize.location instanceof TLRPC.TL_fileLocationToBeDeprecated)) {
        location = new TLRPC.TL_fileLocationToBeDeprecated();
        location.volume_id = Integer.MIN_VALUE;
        location.dc_id = Integer.MIN_VALUE;
        location.local_id = SharedConfig.getLastLocalId();
        location.file_reference = new byte[0];

        photoSize = new TLRPC.TL_photoSize();
        photoSize.location = location;
        photoSize.w = scaledBitmap.getWidth();
        photoSize.h = scaledBitmap.getHeight();
        if (photoSize.w <= 100 && photoSize.h <= 100) {
            photoSize.type = "s";
        } else if (photoSize.w <= 320 && photoSize.h <= 320) {
            photoSize.type = "m";
        } else if (photoSize.w <= 800 && photoSize.h <= 800) {
            photoSize.type = "x";
        } else if (photoSize.w <= 1280 && photoSize.h <= 1280) {
            photoSize.type = "y";
        } else {
            photoSize.type = "w";
        }
    } else {
        location = (TLRPC.TL_fileLocationToBeDeprecated) photoSize.location;
    }

    String fileName = location.volume_id + "_" + location.local_id + ".jpg";
    File fileDir;
    if (forceCacheDir) {
        fileDir = FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE);
    } else {
        fileDir = location.volume_id != Integer.MIN_VALUE ? FileLoader.getDirectory(FileLoader.MEDIA_DIR_IMAGE) : FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE);
    }
    final File cacheFile = new File(fileDir, fileName);
    FileOutputStream stream = new FileOutputStream(cacheFile);
    scaledBitmap.compress(compressFormat, quality, stream);
    if (cache) {
        ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
        scaledBitmap.compress(compressFormat, quality, stream2);
        photoSize.bytes = stream2.toByteArray();
        photoSize.size = photoSize.bytes.length;
        stream2.close();
    } else {
        photoSize.size = (int) stream.getChannel().size();
    }
    stream.close();
    if (scaledBitmap != bitmap) {
        scaledBitmap.recycle();
    }

    return photoSize;
}